Ejemplo 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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DownloadForm"/> class.
        /// </summary>
        /// <param name="downloads">List of files to download.</param>
        public DownloadForm(List <IDownloadable> downloads)
        {
            if (downloads is null)
            {
                throw new ArgumentNullException(nameof(downloads));
            }
            InitializeComponent();
            downloadQueue = new List <IDownloadable>();
            foreach (IDownloadable d in downloads)
            {
                if (d.Prerequisite != null && d.Prerequisite.NewerThanDownloaded())
                {
                    downloadQueue.Add(d.Prerequisite);
                }

                downloadQueue.Add(d);

                if (d is VersionGameFiles)
                {
                    VersionGameFiles vgf = d as VersionGameFiles;
                    if (mostRecent is null || d.GreaterThan(mostRecent))
                    {
                        mostRecent = vgf;
                    }
                }
            }

            Aborted       += DownloadForm_Aborted;
            QueueComplete += DownloadForm_QueueComplete;
            Disposed      += DownloadForm_Disposed;
        }
Ejemplo n.º 3
0
        private static void Initialize()
        {
            Config.LoadConfig();

            if (GithubBridge.CheckForLauncherUpdate())
            {
                Application.Exit();
                return;
            }

            if (!Directory.Exists(Path.Combine(Config.InstallPath, "Versions")))
            {
                Directory.CreateDirectory(Path.Combine(Config.InstallPath, "Versions"));
                if (Config.CurrentVersion?.ToString().Equals("ALPHA 0.0") != false)
                {
                    Config.CurrentVersion = VersionGameFiles.FromString("ALPHA 0.0");
                }
            }

            try {
                NetworkConnected = DownloadVersionManifests();
            } catch (WebException) {
                NetworkConnected = false;
            }

            return;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Download a specific version.
        /// </summary>
        /// <param name="v">Version to download.</param>
        public static void DownloadVersion(IDownloadable v)
        {
            if (v is null)
            {
                throw new ArgumentNullException(nameof(v));
            }
            List <IDownloadable> queue = new List <IDownloadable>(new[] { v });

            if (v is VersionGameFiles)
            {
                VersionGameFiles vgf = v as VersionGameFiles;
                if (!Config.DisableAudioDownload && vgf?.MinimumAudioVersion != null && vgf.MinimumAudioVersion.GreaterThan(Config.CurrentVersion))
                {
                    DialogResult result = MessageBox.Show($"New audio version found: {vgf.MinimumAudioVersion}.\nDownload and install this update?\n(Note, audio updates are often large downloads)", "Audio Update Found", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        queue.Add(vgf.MinimumAudioVersion);
                    }
                }
            }

            downloadForm = new DownloadForm(queue);
            downloadForm.Show();
            downloadForm.StartDownload();
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets most recent version of game files.
        /// </summary>
        /// <returns>The most recent version object.</returns>
        public static VersionGameFiles GetMostRecentVersion()
        {
            VersionGameFiles mostRecent = Config.CurrentVersion;

            foreach (VersionGameFiles v in GetAllVersions())
            {
                if (mostRecent == null || v.GreaterThan(mostRecent) || v.Equals(mostRecent))
                {
                    mostRecent = v;
                }
            }
            return(mostRecent);
        }
Ejemplo n.º 7
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;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets the version before this one.
        /// </summary>
        /// <param name="fullVersionOnly">If true, only checks full versions and not patches.</param>
        /// <returns>A version of the game before this one, if found, else null.</returns>
        public VersionGameFiles GetPreviousVersion(bool fullVersionOnly = false)
        {
            VersionGameFiles mostRecentPrevious = null;

            foreach (VersionGameFiles v in GetAllVersions())
            {
                if ((GreaterThan(v) && fullVersionOnly && !v.IsPatch) || (!fullVersionOnly && (mostRecentPrevious == null || v.GreaterThan(mostRecentPrevious))))
                {
                    mostRecentPrevious = v;
                }
            }

            return(mostRecentPrevious);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Sets the current game version text.
 /// </summary>
 /// <param name="v">Version to set.</param>
 public void SetGameVersion(VersionGameFiles v)
 {
     if (v is null)
     {
         throw new ArgumentNullException(nameof(v));
     }
     if (GameVersionLabel.InvokeRequired)
     {
         SGV d = SetGameVersion;
         Invoke(d, new object[] { v });
     }
     else
     {
         GameVersionLabel.Text = "Build: " + v.ToString();
     }
 }
Ejemplo n.º 10
0
        /// <inheritdoc/>
        public bool GreaterThan(IDownloadable other)
        {
            if (other == null)
            {
                return(true);
            }
            VersionGameFiles v = other as VersionGameFiles;

            if (Channel == v.Channel)
            {
                return(Number > v.Number);
            }
            else
            {
                return(Channel > v.Channel);
            }
        }
Ejemplo n.º 11
0
        private void Launcher_Shown(object sender, EventArgs e)
        {
            TumblrBrowser.IsWebBrowserContextMenuEnabled = false;
            WikiBrowser.IsWebBrowserContextMenuEnabled   = false;
            ForumBrowser.IsWebBrowserContextMenuEnabled  = false;
            VersionGameFiles vgf = Config.CurrentVersion;

            if (vgf != null)
            {
                SetGameVersion(vgf);
            }
            LauncherVersionLabel.Text = "Launcher v" + Program.GetLauncherVersion();
            if (Program.NetworkConnected)
            {
                try {
                    Program.InstallLatestVersion();
                } catch (WebException) {
                    Program.NetworkConnected = false;
                }
            }

            EnableLaunch();
        }
Ejemplo n.º 12
0
        private void LaunchButton_Click(object sender, EventArgs e)
        {
            if (Program.Downloading)
            {
                MessageBox.Show("A download is currently in progress. Please cancel your download or wait until it finishes.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            VersionGameFiles currentVersion = Config.CurrentVersion;

            if (currentVersion is null)
            {
                if (MessageBox.Show("No installed version found. Would you like to download now?", "No Version Found", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
                {
                    return;
                }

                Program.InstallLatestVersion();
                return;
            }

            string launchpath = Path.Combine(Config.InstallPath, "Versions", currentVersion.ToString(), "Game.exe");

            if (Program.ForceUpdate)
            {
                string path = Path.Combine(Config.InstallPath, "Versions", currentVersion.ToString());
                if (File.Exists(path + ".zip"))
                {
                    File.Delete(path + ".zip");
                }
                if (Directory.Exists(path))
                {
                    Directory.Delete(path, true);
                }
                if (currentVersion.IsPatch)
                {
                    string previousPath = Path.Combine(Config.InstallPath, "Versions", currentVersion.Prerequisite.ToString());
                    if (File.Exists(previousPath + ".zip"))
                    {
                        File.Delete(previousPath + ".zip");
                    }
                    if (Directory.Exists(previousPath))
                    {
                        Directory.Delete(previousPath, true);
                    }
                    Config.CurrentVersion = VersionGameFiles.FromString("ALPHA 0.0");
                }

                Program.DownloadVersion(VersionGameFiles.GetMostRecentVersion());
                Program.ForceUpdate = false;
            }
            else if (!File.Exists(launchpath))
            {
                DialogResult res = MessageBox.Show(
                    $"Cannot find the game in your install path. It might be moved or deleted.\nCheck \n{launchpath}\nfor your files, or redownload them.\nWould you like to redownload?",
                    "Game not found",
                    MessageBoxButtons.YesNo);
                if (res == DialogResult.Yes)
                {
                    Program.InstallLatestVersion();
                }
                else
                {
                    return;
                }
            }

            if (File.Exists(launchpath))
            {
                Process.Start(launchpath);
                if (!Config.KeepLauncherOpen)
                {
                    Close();
                }
            }
        }