public void DeleteAddon(LauncherConfJsonItem lcji) { string AddonFolderName = lcji.FolderName; string targetFolder = Path.Combine(MainForm.launcherDir, "VERSIONS", lc.Version, AddonFolderName); if (Directory.Exists(targetFolder)) { string CustomPackage = null; if (lcji.IsAddon) { CustomPackage = "This addon is a Custom Package\n\n"; } if (MessageBox.Show(CustomPackage + "Deleting this addon will also wipe the configuration and temporary files that it contains.\n\nDo you want to continue?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { return; } } try { if (lcji.IsAddon) { string ImageFilename = Path.Combine(MainForm.launcherDir, "VERSIONS", "Launcher", lcji.ImageName); if (File.Exists(lcji.ConfigFilename)) { File.Delete(lcji.ConfigFilename); } if (File.Exists(ImageFilename)) { File.Delete(ImageFilename); } } if (Directory.Exists(targetFolder)) { Directory.Delete(targetFolder, true); } } catch (Exception ex) { var result = MessageBox.Show($"Could not delete addon {AddonFolderName} because of the following error:\n{ex.ToString()}", "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); if (result == DialogResult.Retry) { DeleteAddon(lcji); return; } } MainForm.mf.RefreshKeepSelectedVersion(); //MainForm.mf.RefreshInterface(); }
private void btnBatchfile_Click(object sender, EventArgs e) { Button currentButton = (Button)sender; var lcji = (LauncherConfJsonItem)currentButton.Tag; if (!String.IsNullOrEmpty(lcji.FolderName) && !Directory.Exists(Path.Combine(lc.VersionLocation, lcji.FolderName))) { LauncherConfJson lcCandidateForPull = getFolderFromPreviousVersion(lcji.DownloadVersion); if (lcCandidateForPull != null) { var resultAskPull = MessageBox.Show($"The component {lcji.FolderName} could be imported from {lcCandidateForPull.Version}\nDo you wish import it?", "Import candidate found", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (resultAskPull == DialogResult.Yes) { LauncherConfJsonItem candidate = lcCandidateForPull.Items.FirstOrDefault(it => it.DownloadVersion == lcji.DownloadVersion); //handle it here try { RTC_Extensions.RecursiveCopyNukeReadOnly(new DirectoryInfo(Path.Combine(lcCandidateForPull.VersionLocation, candidate.FolderName)), new DirectoryInfo(Path.Combine(lc.VersionLocation, lcji.FolderName))); RTC_Extensions.RecursiveDeleteNukeReadOnly(new DirectoryInfo(Path.Combine(lcCandidateForPull.VersionLocation, candidate.FolderName))); MainForm.mf.RefreshKeepSelectedVersion(); } catch (Exception ex) { MessageBox.Show($"Couldn't copy {Path.Combine(lcCandidateForPull.VersionLocation, candidate?.FolderName ?? "NULL") ?? "NULL"} to {lcji.FolderName}.\nIs the file in use?\nException:{ex.Message}"); try { RTC_Extensions.RecursiveDeleteNukeReadOnly(new DirectoryInfo(Path.Combine(lc.VersionLocation, lcji.FolderName))); } catch (Exception _ex) //f { Console.WriteLine(_ex); } } return; } } var result = MessageBox.Show($"The following component is missing: {lcji.FolderName}\nDo you wish to download it?", "Additional download required", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { string downloadUrl = $"{MainForm.webRessourceDomain}/rtc/addons/" + lcji.DownloadVersion + ".zip"; string downloadedFile = Path.Combine(MainForm.launcherDir, "PACKAGES", lcji.DownloadVersion + ".zip"); string extractDirectory = Path.Combine(lc.VersionLocation, lcji.FolderName); MainForm.mf.DownloadFile(downloadUrl, downloadedFile, extractDirectory); } return; } lcji.Execute(); }
private LauncherConfJson getFolderFromPreviousVersion(string downloadVersion) { foreach (string ver in MainForm.mf.lbVersions.Items.Cast <string>()) { if (downloadVersion == ver) { continue; } var _lc = new LauncherConfJson(ver); LauncherConfJsonItem lcji = _lc.Items.FirstOrDefault(it => it.DownloadVersion == downloadVersion); if (lcji != null) { if (Directory.Exists(Path.Combine(_lc.VersionLocation, lcji.FolderName))) { return(_lc); } } } return(null); }