Example #1
0
        /// <summary>
        /// Check for and download the latest version of the game files.
        /// </summary>
        /// <returns>True if a download was made.</returns>
        public static bool InstallLatestVersion()
        {
            Launcher.UpdateStatus("Checking for new versions...");

            VersionGameFiles mostRecent = VersionGameFiles.GetMostRecentVersion();

            if (mostRecent != null && mostRecent.GreaterThan(Config.CurrentVersion))
            {
                DialogResult result = MessageBox.Show($"New version found: {mostRecent.Channel} {mostRecent.Number}\nDownload and install this update?", "Update Found", MessageBoxButtons.YesNo);

                if (result == DialogResult.Yes)
                {
                    DownloadVersion(mostRecent);
                    return(true);
                }
            }

            VersionAudio mostRecentAudio = VersionAudio.GetMostRecentVersion();

            if (!Config.DisableAudioDownload && mostRecentAudio.GreaterThan(Config.CurrentAudioVersion))
            {
                DialogResult result = MessageBox.Show($"New audio version found: {mostRecentAudio}.\nDownload and install this update?\n(Note, audio updates are often large downloads)", "Audio Update Found", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    DownloadVersion(mostRecentAudio);
                }
            }

            Launcher.UpdateStatus("No new version found.");
            return(false);
        }
        private bool PatchDownload(IDownloadable download, string destination)
        {
            try {
                if (download is VersionGameFiles)
                {
                    VersionGameFiles vgf = download as VersionGameFiles;
                    if (vgf.IsPatch)
                    {
                        UpdateProgressText("Patching...");
                        string versionpath = Path.Combine(Config.InstallPath, "Versions", download.Prerequisite.ToString());
                        RecursiveCopy(versionpath, destination, false);
                    }
                }
                else if (download is VersionAudio)
                {
                    VersionAudio va          = download as VersionAudio;
                    string       versionpath = Path.Combine(Config.InstallPath, "Versions", mostRecent.ToString());
                    RecursiveCopy(destination, versionpath, true);
                }
            } catch (DirectoryNotFoundException) {
                MessageBox.Show(
                    $"Could not find download{Environment.NewLine}{destination}{Environment.NewLine}The file appears to be missing. It may have been quarantined by your antivirus software. Please check your antivirus settings and retry. If the issue persists, please report this error.",
                    "Apex Launcher Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);
                return(false);
            }

            if (download == mostRecent && !(download is VersionAudio))
            {
                bool downloadingNewAudio = false;
                foreach (IDownloadable d in downloadQueue)
                {
                    if (d is VersionAudio)
                    {
                        downloadingNewAudio = true;
                        break;
                    }
                }

                if (!downloadingNewAudio)
                {
                    string versionpath      = Path.Combine(Config.InstallPath, "Versions", mostRecent.ToString());
                    string audioversionpath = Path.Combine(Config.InstallPath, "Versions", VersionAudio.GetMostRecentVersion().ToString());
                    RecursiveCopy(audioversionpath, versionpath, true);
                }
            }

            try {
                File.Delete(currentFilepath);
            } catch (IOException e) {
                MessageBox.Show($"Error encountered when trying to delete {currentFilepath} after patching. You may need to delete the file manually, but the program should otherwise work correctly. Details:{Environment.NewLine}{e.Message}");
            }

            return(true);
        }