public LaunchPanelV2() { InitializeComponent(); lbSelectedVersion.Visible = false; lc = new LauncherConf(MainForm.SelectedVersion); }
public LauncherConfItem(LauncherConf lc, string _line) { line = _line; lineItems = _line.Split('|'); imageLocation = Path.Combine(lc.launcherAssetLocation, lineItems[0]); batchName = lineItems[1]; batchLocation = Path.Combine(lc.batchFilesLocation, batchName); folderName = lineItems[2]; folderLocation = Path.Combine(lc.batchFilesLocation, folderName); downloadVersion = lineItems[3]; }
private LauncherConf getFolderFromPreviousVersion(string downloadVersion) { foreach (string ver in MainForm.mf.lbVersions.Items.Cast <string>()) { if (downloadVersion == ver) { continue; } var lc = new LauncherConf(ver); LauncherConfItem lci = lc.items.FirstOrDefault(it => it.downloadVersion == downloadVersion); if (lci != null) { if (Directory.Exists(lci.folderLocation)) { return(lc); } } } return(null); }
private void btnBatchfile_Click(object sender, EventArgs e) { Button currentButton = (Button)sender; string line = (string)currentButton.Tag; LauncherConfItem lci = new LauncherConfItem(lc, line); if (!Directory.Exists(lci.folderLocation)) { if (string.IsNullOrWhiteSpace(lci.downloadVersion)) { MessageBox.Show($"A required folder is missing: {lci.downloadVersion}\nNo download location was provided", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } LauncherConf lcCandidateForPull = getFolderFromPreviousVersion(lci.downloadVersion); if (lcCandidateForPull != null) { var resultAskPull = MessageBox.Show($"The component {lci.folderName} could be imported from {lcCandidateForPull.version}\nDo you wish import it?", "Import candidate found", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (resultAskPull == DialogResult.Yes) { LauncherConfItem candidate = lcCandidateForPull.items.FirstOrDefault(it => it.downloadVersion == lci.downloadVersion); //handle it here try { RTC_Extensions.RecursiveCopyNukeReadOnly(new DirectoryInfo(candidate.folderLocation), new DirectoryInfo(lci.folderLocation)); RTC_Extensions.RecursiveDeleteNukeReadOnly(new DirectoryInfo(candidate.folderLocation)); MainForm.mf.RefreshKeepSelectedVersion(); } catch (Exception ex) { MessageBox.Show($"Couldn't copy {candidate.folderLocation ?? "NULL"} to {lci.folderLocation}.\nIs the file in use?\nException:{ex.Message}"); try { RTC_Extensions.RecursiveDeleteNukeReadOnly(new DirectoryInfo(lci.folderLocation)); } catch (Exception _ex) //f { Console.WriteLine(_ex); } } return; } } var result = MessageBox.Show($"The following component is missing: {lci.folderName}\nDo you wish to download it?", "Additional download required", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { string downloadUrl = $"{MainForm.webRessourceDomain}/rtc/addons/" + lci.downloadVersion + ".zip"; string downloadedFile = Path.Combine(MainForm.launcherDir, "PACKAGES", lci.downloadVersion + ".zip"); string extractDirectory = lci.folderLocation; MainForm.mf.DownloadFile(downloadUrl, downloadedFile, extractDirectory); } return; } if (lci.batchLocation.Contains("http")) { Process.Start(lci.batchName); return; } ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = Path.GetFileName(lci.batchLocation); psi.WorkingDirectory = Path.GetDirectoryName(lci.batchLocation); Process.Start(psi); }