コード例 #1
0
ファイル: MainForm.cs プロジェクト: scowalt/RTCV
        public void DeleteSelected()
        {
            if (sideversionForm.lbVersions.SelectedIndex == -1)
            {
                return;
            }

            Directory.SetCurrentDirectory(launcherDir); //Move our working dir back
            string version = sideversionForm.lbVersions.SelectedItem.ToString();

            if (File.Exists(launcherDir + Path.DirectorySeparatorChar + "PACKAGES" + Path.DirectorySeparatorChar + version + ".zip"))
            {
                File.Delete(launcherDir + Path.DirectorySeparatorChar + "PACKAGES" + Path.DirectorySeparatorChar + version + ".zip");
            }

            if (Directory.Exists((launcherDir + Path.DirectorySeparatorChar + "VERSIONS" + Path.DirectorySeparatorChar + version)))
            {
            }

            {
                var failed = RTC_Extensions.RecursiveDeleteNukeReadOnly(launcherDir + Path.DirectorySeparatorChar + "VERSIONS" + Path.DirectorySeparatorChar + version);
                if (failed.Count > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (var l in failed)
                    {
                        sb.AppendLine(Path.GetFileName(l));
                    }

                    MessageBox.Show($"Failed to delete some files!\nSomething may be locking them (is the RTC still running?)\n\nList of failed files:\n{sb.ToString()}");
                }
            }
            RefreshInterface();
        }
コード例 #2
0
        private static void CheckForNeededLauncherUpdate(string extractDirectory)
        {
            if (File.Exists(Path.Combine(extractDirectory, "Launcher", "ver.ini")))
            {
                var newVer = Convert.ToInt32(File.ReadAllText(Path.Combine(extractDirectory, "Launcher", "ver.ini")));
                if (newVer > launcherVer)
                {
                    if (File.Exists(Path.Combine(extractDirectory, "Launcher", "minver.ini")) &&                                   //Do we have minver
                        Convert.ToInt32(File.ReadAllText(Path.Combine(extractDirectory, "Launcher", "minver.ini"))) > launcherVer) //Is minver > launcherVer
                    {
                        if (MessageBox.Show("A mandatory launcher update is required to use this version. Click \"OK\" to update the launcher.",
                                            "Launcher update required",
                                            MessageBoxButtons.OKCancel,
                                            MessageBoxIcon.Exclamation,
                                            MessageBoxDefaultButton.Button1,
                                            MessageBoxOptions.DefaultDesktopOnly) == DialogResult.OK)
                        {
                            UpdateLauncher(extractDirectory);
                        }
                        else
                        {
                            MessageBox.Show("Launcher update is required. Cancelling.");
                            RTC_Extensions.RecursiveDeleteNukeReadOnly(extractDirectory);
                            throw new LauncherUpdateRequiredException();
                        }
                    }

                    if (MessageBox.Show("The downloaded package contains a new launcher update.\n\nDo you want to update the Launcher?", "Launcher update", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        UpdateLauncher(extractDirectory);
                    }
                }
            }
        }
コード例 #3
0
        private static void ValidateExtractedFiles(string downloadedFile, string extractDirectory)
        {
            //This checks every extracted files against the contents of the zip file
            using (ZipArchive za = ZipFile.OpenRead(downloadedFile))
            {
                var foundLockBefore = false; //this flag prompts a message to skip all
                var skipLock        = false; //file locked messages and sents the flag below

                foreach (ZipArchiveEntry entry in za.Entries.Where(it => !it.FullName.EndsWith("/")))
                {
                    var targetFile = Path.Combine(extractDirectory, entry.FullName.Replace("/", "\\"));
                    if (File.Exists(targetFile))
                    {
                        var ext = entry.FullName.ToUpper().Substring(entry.FullName.Length - 3);
                        if (ext == "EXE" || ext == "DLL")
                        {
                            FileStream readCheck = null;
                            try
                            {
                                readCheck       = File.OpenRead(targetFile); //test if file can be read
                                foundLockBefore = true;
                            }
                            catch
                            {
                                if (!skipLock)
                                {
                                    if (foundLockBefore)
                                    {
                                        if (MessageBox.Show($"Another file has been found locked/inaccessible.\nThere might be many more messages like this coming up.\n\nWould you like skip any remaining lock messages?", "Error",
                                                            MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                                        {
                                            skipLock = true;
                                        }
                                    }
                                }

                                if (!skipLock)
                                {
                                    MessageBox.Show($"An error occurred during extraction,\n\nThe file \"targetFile\" seems to have been locked/made inaccessible by an external program. It might be caused by your antivirus.", "Error",
                                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }

                            readCheck?.Close(); //close file immediately
                        }
                    }
                    else
                    {
                        MessageBox.Show($"An error occurred during extraction, rolling back changes.\n\nThe file \"{targetFile}\" could not be found. It might have been deleted by your antivirus.", "Error", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);

                        if (Directory.Exists(extractDirectory))
                        {
                            RTC_Extensions.RecursiveDeleteNukeReadOnly(extractDirectory);
                        }
                    }
                }
            }
        }
コード例 #4
0
ファイル: LaunchPanelV3.cs プロジェクト: DrTexx/RTCV
        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();
        }
コード例 #5
0
        public void DeleteSelected(string version = null)
        {
            if (version == null && sideversionForm.lbVersions.SelectedIndex != -1)
            {
                version = sideversionForm.lbVersions.SelectedItem.ToString();
            }

            if (version == null)
            {
                return;
            }

            DialogResult result = MessageBox.Show($"Are you sure you want to delete version {version}?", "Build Deletion", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);

            if (result == DialogResult.Cancel)
            {
                return;
            }

            Directory.SetCurrentDirectory(launcherDir); //Move our working dir back

            if (File.Exists(launcherDir + Path.DirectorySeparatorChar + "PACKAGES" + Path.DirectorySeparatorChar + version + ".zip"))
            {
                File.Delete(launcherDir + Path.DirectorySeparatorChar + "PACKAGES" + Path.DirectorySeparatorChar + version + ".zip");
            }

            if (Directory.Exists(launcherDir + Path.DirectorySeparatorChar + "VERSIONS" + Path.DirectorySeparatorChar + version))
            {
                List <string> failed = RTC_Extensions.RecursiveDeleteNukeReadOnly(launcherDir + Path.DirectorySeparatorChar + "VERSIONS" + Path.DirectorySeparatorChar + version);
                if (failed.Count > 0)
                {
                    var sb = new StringBuilder();
                    foreach (var l in failed)
                    {
                        sb.AppendLine(Path.GetFileName(l));
                    }

                    MessageBox.Show($"Failed to delete some files!\nSomething may be locking them (is the RTC still running?)\n\nList of failed files:\n{sb}");
                }
            }

            RefreshInterface();
        }
コード例 #6
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);
        }
コード例 #7
0
ファイル: MainForm.cs プロジェクト: scowalt/RTCV
        public void DownloadComplete(string downloadedFile, string extractDirectory)
        {
            try
            {
                if (!Directory.Exists(extractDirectory))
                {
                    Directory.CreateDirectory(extractDirectory);
                }

                try
                {
                    System.IO.Compression.ZipFile.ExtractToDirectory(downloadedFile, extractDirectory);
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"An error occurred during extraction, rolling back changes.\n\n{ex}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    if (Directory.Exists(extractDirectory))
                    {
                        RTC_Extensions.RecursiveDeleteNukeReadOnly(extractDirectory);
                    }
                    return;
                }


                //This checks every extracted files against the contents of the zip file
                using (ZipArchive za = System.IO.Compression.ZipFile.OpenRead(downloadedFile))
                {
                    bool foundLockBefore = false; //this flag prompts a message to skip all
                    bool skipLock        = false; //file locked messages and sents the flag below

                    foreach (var entry in za.Entries.Where(it => !it.FullName.EndsWith("/")))
                    {
                        string targetFile = Path.Combine(extractDirectory, entry.FullName.Replace("/", "\\"));
                        if (File.Exists(targetFile))
                        {
                            string ext = entry.FullName.ToUpper().Substring(entry.FullName.Length - 3);
                            if (ext == "EXE" || ext == "DLL")
                            {
                                FileStream readCheck = null;
                                try
                                {
                                    readCheck       = File.OpenRead(targetFile); //test if file can be read
                                    foundLockBefore = true;
                                }
                                catch
                                {
                                    if (!skipLock)
                                    {
                                        if (foundLockBefore)
                                        {
                                            if (MessageBox.Show($"Another file has been found locked/inaccessible.\nThere might be many more messages like this coming up.\n\nWould you like skip any remaining lock messages?", "Error",
                                                                MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                                            {
                                                skipLock = true;
                                            }
                                        }
                                    }

                                    if (!skipLock)
                                    {
                                        MessageBox.Show($"An error occurred during extraction,\n\nThe file \"targetFile\" seems to have been locked/made inaccessible by an external program. It might be caused by your antivirus.", "Error",
                                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    }
                                }

                                readCheck?.Close(); //close file immediately
                            }
                        }
                        else
                        {
                            MessageBox.Show($"An error occurred during extraction, rolling back changes.\n\nThe file \"{targetFile}\" could not be found. It might have been deleted by your antivirus.", "Error", MessageBoxButtons.OK,
                                            MessageBoxIcon.Error);

                            if (Directory.Exists(extractDirectory))
                            {
                                RTC_Extensions.RecursiveDeleteNukeReadOnly(extractDirectory);
                            }
                        }
                    }
                }

                //check if files are all present here

                if (File.Exists(downloadedFile))
                {
                    File.Delete(downloadedFile);
                }


                var preReqChecker = Path.Combine(extractDirectory, "Launcher", "PrereqChecker.exe");
                if (File.Exists(preReqChecker))
                {
                    ProcessStartInfo psi = new ProcessStartInfo();
                    psi.FileName         = Path.GetFileName(preReqChecker);
                    psi.WorkingDirectory = Path.GetDirectoryName(preReqChecker);
                    Process.Start(psi)?.WaitForExit();
                }

                if (File.Exists(Path.Combine(extractDirectory, "Launcher", "ver.ini")))
                {
                    int newVer = Convert.ToInt32(File.ReadAllText(Path.Combine(extractDirectory, "Launcher", "ver.ini")));
                    if (newVer > launcherVer)
                    {
                        if (File.Exists(Path.Combine(extractDirectory, "Launcher", "minver.ini")) &&                                   //Do we have minver
                            Convert.ToInt32(File.ReadAllText(Path.Combine(extractDirectory, "Launcher", "minver.ini"))) > launcherVer) //Is minver > launcherVer
                        {
                            if (MessageBox.Show("A mandatory launcher update is required to use this version. Click \"OK\" to update the launcher.",
                                                "Launcher update required",
                                                MessageBoxButtons.OKCancel,
                                                MessageBoxIcon.Exclamation,
                                                MessageBoxDefaultButton.Button1,
                                                MessageBoxOptions.DefaultDesktopOnly) == DialogResult.OK)
                            {
                                UpdateLauncher(extractDirectory);
                            }
                            else
                            {
                                MessageBox.Show("Launcher update is required. Cancelling.");
                                RTC_Extensions.RecursiveDeleteNukeReadOnly(extractDirectory);
                                return;
                            }
                        }

                        if (MessageBox.Show("The downloaded package contains a new launcher update.\n\nDo you want to update the Launcher?", "Launcher update", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            UpdateLauncher(extractDirectory);
                        }
                    }
                }
            }
            finally
            {
                sideversionForm.lbVersions.SelectedIndex = -1;

                RefreshInstalledVersions();

                MainForm.mf.pnLeftSide.Visible = true;

                if (MainForm.vdppForm != null)
                {
                    MainForm.vdppForm.lbOnlineVersions.SelectedIndex = -1;
                    MainForm.vdppForm.btnDownloadVersion.Visible     = false;
                }


                dForm.Close();
                dForm = null;

                RefreshKeepSelectedVersion();
            }
        }
コード例 #8
0
        internal void DownloadComplete(string downloadedFile, string extractDirectory)
        {
            try
            {
                if (!Directory.Exists(extractDirectory))
                {
                    Directory.CreateDirectory(extractDirectory);
                }

                try
                {
                    ZipFile.ExtractToDirectory(downloadedFile, extractDirectory);
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"An error occurred during extraction, rolling back changes.\n\n{ex}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    if (Directory.Exists(extractDirectory))
                    {
                        RTC_Extensions.RecursiveDeleteNukeReadOnly(extractDirectory);
                    }

                    return;
                }

                ValidateExtractedFiles(downloadedFile, extractDirectory);

                if (File.Exists(downloadedFile))
                {
                    File.Delete(downloadedFile);
                }

                LaunchPrereqCheckerIfPresent(extractDirectory);

                try
                {
                    CheckForNeededLauncherUpdate(extractDirectory);
                }
                catch (LauncherUpdateRequiredException)
                {
                    return;
                }
            }
            finally
            {
                sideversionForm.lbVersions.SelectedIndex = -1;

                RefreshInstalledVersions();

                mf.pnLeftSide.Visible = true;

                if (vdppForm != null)
                {
                    vdppForm.lbOnlineVersions.SelectedIndex = -1;
                    vdppForm.btnDownloadVersion.Visible     = false;
                }

                dForm.Close();
                dForm = null;

                RefreshKeepSelectedVersion();
            }
        }