Exemple #1
0
        public void DownloadFile(string downloadURL, string downloadedFile, string extractDirectory)
        {
            MainForm.mf.clearAnchorRight();

            MainForm.dForm = new DownloadForm(downloadURL, downloadedFile, extractDirectory);

            MainForm.mf.pnLeftSide.Visible = false;

            MainForm.mf.btnVersionDownloader.Enabled = false;

            MainForm.dForm.TopLevel = false;
            MainForm.dForm.Location = new Point(0, 0);
            MainForm.dForm.Dock     = DockStyle.Fill;
            MainForm.mf.Controls.Add(MainForm.dForm);
            MainForm.dForm.Show();
            MainForm.dForm.Focus();
            MainForm.dForm.BringToFront();
        }
Exemple #2
0
        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();
            }
        }
Exemple #3
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();
            }
        }