Exemplo n.º 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);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VersionGameFiles"/> class.
 /// </summary>
 /// <param name="channel">Release channel.</param>
 /// <param name="number">Version number.</param>
 /// <param name="location">Remote download location.</param>
 /// <param name="audioVersion">Audio version.</param>
 /// <param name="ispatch">Whether this version is a patch only.</param>
 public VersionGameFiles(Channel channel, double number, string location, VersionAudio audioVersion, bool ispatch = false)
 {
     Channel             = channel;
     Number              = number;
     Location            = location;
     IsPatch             = ispatch;
     MinimumAudioVersion = audioVersion;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Gets all versions from the Version Manifest.
        /// </summary>
        /// <returns>List of all version objects.</returns>
        public static List <VersionGameFiles> GetAllVersions()
        {
            List <VersionGameFiles> versions = new List <VersionGameFiles>();

            XmlDocument doc = new XmlDocument();

            doc.Load(Path.Combine(Config.InstallPath, "Versions", "VersionManifest.xml"));

            foreach (XmlNode node in doc.GetElementsByTagName("version"))
            {
                Channel      channel      = Channel.NONE;
                double       number       = 0.0;
                string       location     = string.Empty;
                bool         patch        = false;
                VersionAudio audioversion = null;

                foreach (XmlNode prop in node.ChildNodes)
                {
                    switch (prop.Name.ToLower(Program.Culture))
                    {
                    case "channel":
                        channel = prop.InnerText[0] switch
                        {
                            'a' => Channel.ALPHA,
                            'b' => Channel.BETA,
                            'r' => Channel.RELEASE,
                            _ => Channel.NONE,
                        };
                        break;

                    case "number":
                        try {
                            number = Convert.ToDouble(prop.InnerText, Program.Culture);
                        } catch (FormatException) {
                            number = 0.0;
                        }

                        break;

                    case "location":
                        location = prop.InnerText;
                        break;

                    case "patch":
                        patch = Convert.ToBoolean(prop.InnerText, Program.Culture);
                        break;

                    case "audioversion":
                        audioversion = VersionAudio.FromNumber(Convert.ToInt32(prop.InnerText));
                        break;
                    }
                }

                versions.Add(new VersionGameFiles(channel, number, location, audioversion, patch));
            }

            return(versions);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the most recent version from the version manifest.
        /// </summary>
        /// <returns>Most recent version object.</returns>
        public static VersionAudio GetMostRecentVersion()
        {
            VersionAudio mostRecent = null;

            foreach (VersionAudio va in GetAllVersions())
            {
                if (mostRecent == null || va.GreaterThan(mostRecent))
                {
                    mostRecent = va;
                }
            }

            return(mostRecent);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Load underlying configuration file to memory.
        /// </summary>
        public static void LoadConfig()
        {
            if (!File.Exists(Filepath))
            {
                CreateConfig();
            }
            foreach (string line in File.ReadAllLines(Filepath))
            {
                if (line.Length == 0 || new[] { '\n', ' ', '#' }.Contains(line[0]) || !line.Contains('='))
                {
                    continue;
                }
                string[] split = line.Split('=');
                string   param = split[0].Trim();
                string   value = split[1].Trim();

                foreach (PropertyInfo pi in typeof(Config).GetProperties())
                {
                    if (pi.Name.ToLower(Program.Culture) == param.ToLower(Program.Culture))
                    {
                        try {
                            object v = null;
                            if (pi.PropertyType.GetInterfaces().Contains(typeof(IDownloadable)))
                            {
                                if (pi.PropertyType == typeof(VersionGameFiles))
                                {
                                    v = VersionGameFiles.FromString(value);
                                }
                                if (pi.PropertyType == typeof(VersionAudio))
                                {
                                    v = VersionAudio.FromString(value);
                                }
                            }
                            else
                            {
                                v = Convert.ChangeType(value, pi.PropertyType);
                            }

                            pi.SetValue(null, v);
                        } catch (FormatException) {
                            pi.SetValue(null, default);
                        }

                        break;
                    }
                }
            }

            loaded = true;
        }
Exemplo n.º 7
0
        /// <inheritdoc/>
        public override bool Equals(object other)
        {
            if (!(other is VersionAudio))
            {
                return(false);
            }
            if (other is null)
            {
                return(false);
            }
            VersionAudio o = other as VersionAudio;

            if (this == o)
            {
                return(true);
            }
            if (o.ToString().Equals(ToString()))
            {
                return(true);
            }
            return(false);
        }