コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }