Ejemplo n.º 1
0
        /// <summary>
        /// Downloads the launchpad manifest.
        /// </summary>
        private void DownloadLaunchpadManifest()
        {
            try
            {
                string RemoteURL    = manifestHandler.GetLaunchpadManifestURL();
                string LocalPath    = ManifestHandler.GetLaunchpadManifestPath();
                string OldLocalPath = ManifestHandler.GetOldLaunchpadManifestPath();

                if (File.Exists(LocalPath))
                {
                    // Create a backup of the old manifest so that we can compare them when updating the game
                    if (File.Exists(OldLocalPath))
                    {
                        File.Delete(OldLocalPath);
                    }

                    File.Move(LocalPath, OldLocalPath);
                }

                DownloadRemoteFile(RemoteURL, LocalPath);
            }
            catch (IOException ioex)
            {
                Console.WriteLine("IOException in DownloadLaunchpadManifest(): " + ioex.Message);
            }
        }
        /// <summary>
        /// Downloads the manifest for the specified module, and backs up the old copy of the manifest.
        /// </summary>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Will be thrown if the <see cref="EModule"/> passed to the function is not a valid value.
        /// </exception>
        protected virtual void DownloadModuleManifest(EModule module)
        {
            string remoteURL;
            string localPath;
            string oldLocalPath;

            switch (module)
            {
            case EModule.Launcher:
            {
                remoteURL    = ManifestHandler.GetLaunchpadManifestURL();
                localPath    = ManifestHandler.GetLaunchpadManifestPath();
                oldLocalPath = ManifestHandler.GetOldLaunchpadManifestPath();

                break;
            }

            case EModule.Game:
            {
                remoteURL    = FileManifestHandler.GetGameManifestURL();
                localPath    = ManifestHandler.GetGameManifestPath();
                oldLocalPath = ManifestHandler.GetOldGameManifestPath();

                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException(nameof(module), module,
                                                      "An invalid module value was passed to DownloadModuleManifest");
            }
            }

            try
            {
                // Delete the old backup (if there is one)
                if (File.Exists(oldLocalPath))
                {
                    File.Delete(oldLocalPath);
                }

                // Create a backup of the old manifest so that we can compare them when updating the game
                File.Move(localPath, oldLocalPath);
            }
            catch (IOException ioex)
            {
                Log.Warn("Failed to back up the old launcher manifest (IOException): " + ioex.Message);
            }

            DownloadRemoteFile(remoteURL, localPath);
        }