Beispiel #1
0
        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();
        }
Beispiel #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);
        }