Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new <see cref="Changelog"/> object, and adds the visible changelog widget to the provided
        /// parent container.
        /// </summary>
        /// <param name="parentContainer">The parent GTK container where the changelog should be added.</param>
        public Changelog(Container parentContainer)
        {
            if (!ChecksHandler.IsRunningOnUnix())
            {
                this.windowsBrowser = new WindowsBrowser(parentContainer);
                this.WidgetHandle   = windowsBrowser.WidgetHandle;

                this.windowsBrowser.browser.Navigating += OnWindowsBrowserNavigating;
            }
            else
            {
                this.unixBrowser  = new WebView();
                this.WidgetHandle = this.unixBrowser;
                this.unixBrowser.NavigationRequested += OnUnixBrowserNavigating;

                parentContainer.Add(WidgetHandle);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes the UI of the launcher, performing varying checks against the patching server.
        /// </summary>
        /// <returns>A task that must be awaited.</returns>
        public Task InitializeAsync()
        {
            if (this.IsInitialized)
            {
                return(Task.CompletedTask);
            }

            // First of all, check if we can connect to the patching service.
            if (!this.Checks.CanPatch())
            {
                var dialog = new MessageDialog
                             (
                    this,
                    DialogFlags.Modal,
                    MessageType.Warning,
                    ButtonsType.Ok,
                    LocalizationCatalog.GetString("Failed to connect to the patch server. Please check your settings.")
                             );

                dialog.Run();

                dialog.Destroy();
                this.StatusLabel.Text         = LocalizationCatalog.GetString("Could not connect to server.");
                this.MenuRepairItem.Sensitive = false;
            }
            else
            {
                LoadBanner();

                LoadChangelog();

                // If we can connect, proceed with the rest of our checks.
                if (ChecksHandler.IsInitialStartup())
                {
                    DisplayInitialStartupDialog();
                }

                // If the launcher does not need an update at this point, we can continue checks for the game
                if (!this.Checks.IsLauncherOutdated())
                {
                    if (!this.Checks.IsPlatformAvailable(this.Configuration.SystemTarget))
                    {
                        Log.Info
                        (
                            $"The server does not provide files for platform \"{PlatformHelpers.GetCurrentPlatform()}\". " +
                            "A .provides file must be present in the platforms' root directory."
                        );

                        SetLauncherMode(ELauncherMode.Inactive, false);
                    }
                    else
                    {
                        if (!this.Checks.IsGameInstalled())
                        {
                            // If the game is not installed, offer to install it
                            Log.Info("The game has not yet been installed.");
                            SetLauncherMode(ELauncherMode.Install, false);

                            // Since the game has not yet been installed, disallow manual repairs
                            this.MenuRepairItem.Sensitive = false;

                            // and reinstalls
                            this.MenuReinstallItem.Sensitive = false;
                        }
                        else
                        {
                            // If the game is installed (which it should be at this point), check if it needs to be updated
                            if (this.Checks.IsGameOutdated())
                            {
                                // If it does, offer to update it
                                Log.Info("The game is outdated.");
                                SetLauncherMode(ELauncherMode.Update, false);
                            }
                            else
                            {
                                // All checks passed, so we can offer to launch the game.
                                Log.Info("All checks passed. Game can be launched.");
                                SetLauncherMode(ELauncherMode.Launch, false);
                            }
                        }
                    }
                }
                else
                {
                    // The launcher was outdated.
                    Log.Info($"The launcher is outdated. \n\tLocal version: {this.LocalVersionService.GetLocalLauncherVersion()}");
                    SetLauncherMode(ELauncherMode.Update, false);
                }
            }

            this.IsInitialized = true;
            return(Task.CompletedTask);
        }
Ejemplo n.º 3
0
        public MainWindow()
            : base(WindowType.Toplevel)
        {
            //Initialize the config files and check values.
            Config.Initialize();

            // The config must be initialized before the handlers can be instantiated
            Checks   = new ChecksHandler();
            Launcher = new LauncherHandler();
            Game     = new GameHandler();

            //Initialize the GTK UI
            this.Build();

            // Set the initial launcher mode
            SetLauncherMode(ELauncherMode.Inactive, false);

            //set the window title
            Title = "Launchpad - " + Config.GetGameName();

            ScrolledBrowserWindow.Add(Browser);
            ScrolledBrowserWindow.ShowAll();

            IndicatorLabel.Text = LocalizationCatalog.GetString("Idle");

            //First of all, check if we can connect to the FTP server.
            if (!Checks.CanPatch())
            {
                MessageDialog dialog = new MessageDialog(
                    null,
                    DialogFlags.Modal,
                    MessageType.Warning,
                    ButtonsType.Ok,
                    LocalizationCatalog.GetString("Failed to connect to the patch server. Please check your settings."));

                dialog.Run();
                dialog.Destroy();
                IndicatorLabel.Text      = LocalizationCatalog.GetString("Could not connect to server.");
                refreshAction1.Sensitive = false;
            }
            else
            {
                //if we can connect, proceed with the rest of our checks.
                if (ChecksHandler.IsInitialStartup())
                {
                    MessageDialog shouldInstallHereDialog = new MessageDialog(
                        null,
                        DialogFlags.Modal,
                        MessageType.Question,
                        ButtonsType.OkCancel,
                        String.Format(LocalizationCatalog.GetString(
                                          "This appears to be the first time you're starting the launcher.\n" +
                                          "Is this the location where you would like to install the game?" +
                                          "\n\n{0}"), ConfigHandler.GetLocalDir()
                                      ));

                    if (shouldInstallHereDialog.Run() == (int)ResponseType.Ok)
                    {
                        shouldInstallHereDialog.Destroy();
                        //yes, install here
                        Console.WriteLine("Installing in current directory.");
                        ConfigHandler.CreateUpdateCookie();
                    }
                    else
                    {
                        shouldInstallHereDialog.Destroy();
                        //no, don't install here
                        Console.WriteLine("Exiting...");
                        Environment.Exit(0);
                    }
                }

                if (Config.ShouldAllowAnonymousStats())
                {
                    StatsHandler.SendUsageStats();
                }

                // Load the changelog. Try a direct URL first, and a protocol-specific
                // implementation after.
                if (Launcher.CanAccessStandardChangelog())
                {
                    Browser.Open(Config.GetChangelogURL());
                }
                else
                {
                    Launcher.ChangelogDownloadFinished += OnChangelogDownloadFinished;
                    Launcher.LoadFallbackChangelog();
                }

                // If the launcher does not need an update at this point, we can continue checks for the game
                if (!Checks.IsLauncherOutdated())
                {
                    if (!Checks.IsGameInstalled())
                    {
                        //if the game is not installed, offer to install it
                        Console.WriteLine("Not installed.");
                        SetLauncherMode(ELauncherMode.Install, false);
                    }
                    else
                    {
                        //if the game is installed (which it should be at this point), check if it needs to be updated
                        if (Checks.IsGameOutdated())
                        {
                            //if it does, offer to update it
                            Console.WriteLine("Game is outdated or not installed");
                            SetLauncherMode(ELauncherMode.Update, false);
                        }
                        else
                        {
                            //if not, enable launching the game
                            SetLauncherMode(ELauncherMode.Launch, false);
                        }
                    }
                }
                else
                {
                    //the launcher was outdated.
                    SetLauncherMode(ELauncherMode.Update, false);
                }
            }
        }
Ejemplo n.º 4
0
        public MainForm()
        {
            InitializeComponent();

            Config.Initialize();

            // The config must be initialized before the handlers can be instantiated
            Checks   = new ChecksHandler();
            Launcher = new LauncherHandler();
            Game     = new GameHandler();

            SetLauncherMode(ELauncherMode.Inactive, false);
            MessageLabel.Text = LocalizationCatalog.GetString("Idle");

            downloadProgressLabel.Text = String.Empty;

            //set the window text to match the game name
            this.Text = "Launchpad - " + Config.GetGameName();

            //first of all, check if we can connect to the FTP server.
            if (!Checks.CanPatch())
            {
                MessageBox.Show(
                    this,
                    LocalizationCatalog.GetString("Failed to connect to the patch server. Please check your settings."),
                    LocalizationCatalog.GetString("Could not connect to server."),
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error,
                    MessageBoxDefaultButton.Button1);

                MessageLabel.Text     = LocalizationCatalog.GetString("Could not connect to server.");
                PrimaryButton.Text    = ":(";
                PrimaryButton.Enabled = false;
            }
            else
            {
                //if we can connect, proceed with the rest of our checks.
                if (ChecksHandler.IsInitialStartup())
                {
                    DialogResult shouldInstallHere = MessageBox.Show(
                        this,
                        String.Format(
                            LocalizationCatalog.GetString("This appears to be the first time you're starting the launcher.\n" +
                                                          "Is this the location where you would like to install the game?" +
                                                          "\n\n{0}"), ConfigHandler.GetLocalDir()),
                        LocalizationCatalog.GetString("Initial startup"),
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Question,
                        MessageBoxDefaultButton.Button1);

                    if (shouldInstallHere == DialogResult.Yes)
                    {
                        //yes, install here
                        ConfigHandler.CreateUpdateCookie();
                    }
                    else
                    {
                        //no, don't install here
                        Environment.Exit(2);
                    }
                }


                if (Config.ShouldAllowAnonymousStats())
                {
                    StatsHandler.SendUsageStats();
                }

                // Load the changelog. Try a direct URL first, and a protocol-specific
                // implementation after.
                if (Launcher.CanAccessStandardChangelog())
                {
                    changelogBrowser.Navigate(Config.GetChangelogURL());
                }
                else
                {
                    Launcher.ChangelogDownloadFinished += OnChangelogDownloadFinished;
                    Launcher.LoadFallbackChangelog();
                }

                //Does the launcher need an update?
                if (!Checks.IsLauncherOutdated())
                {
                    if (!Checks.IsGameInstalled())
                    {
                        SetLauncherMode(ELauncherMode.Install, false);
                    }
                    else
                    {
                        if (Checks.IsGameOutdated())
                        {
                            SetLauncherMode(ELauncherMode.Update, false);
                        }
                        else
                        {
                            SetLauncherMode(ELauncherMode.Launch, false);
                        }
                    }
                }
                else
                {
                    SetLauncherMode(ELauncherMode.Update, false);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a new instance of the <see cref="MainWindow"/> class.
        /// </summary>
        public MainWindow()
            : base(Gtk.WindowType.Toplevel)
        {
            // Initialize the GTK UI
            this.Build();

            // Bind the handler events
            Game.ProgressChanged  += OnModuleInstallationProgressChanged;
            Game.DownloadFinished += OnGameDownloadFinished;
            Game.DownloadFailed   += OnGameDownloadFailed;
            Game.LaunchFailed     += OnGameLaunchFailed;
            Game.GameExited       += OnGameExited;

            Launcher.LauncherDownloadProgressChanged += OnModuleInstallationProgressChanged;
            Launcher.LauncherDownloadFinished        += OnLauncherDownloadFinished;
            Launcher.ChangelogDownloadFinished       += OnChangelogDownloadFinished;

            // Set the initial launcher mode
            SetLauncherMode(ELauncherMode.Inactive, false);

            // Set the window title
            Title = LocalizationCatalog.GetString("Launchpad - {0}", Config.GetGameName());

            // Create a new changelog widget, and add it to the scrolled window
            this.Browser = new Changelog(this.browserWindow);
            browserWindow.ShowAll();

            indicatorLabel.Text = LocalizationCatalog.GetString("Idle");

            // First of all, check if we can connect to the patching service.
            if (!Checks.CanPatch())
            {
                MessageDialog dialog = new MessageDialog(
                    null,
                    DialogFlags.Modal,
                    MessageType.Warning,
                    ButtonsType.Ok,
                    LocalizationCatalog.GetString("Failed to connect to the patch server. Please check your settings."));

                dialog.Run();

                dialog.Destroy();
                indicatorLabel.Text        = LocalizationCatalog.GetString("Could not connect to server.");
                repairGameAction.Sensitive = false;
            }
            else
            {
                // TODO: Load this asynchronously
                // Load the game banner (if there is one)
                if (Config.GetPatchProtocol().CanProvideBanner())
                {
                    using (MemoryStream bannerStream = new MemoryStream())
                    {
                        // Fetch the banner from the server
                        Config.GetPatchProtocol().GetBanner().Save(bannerStream, ImageFormat.Png);

                        // Load the image into a pixel buffer
                        bannerStream.Position  = 0;
                        this.gameBanner.Pixbuf = new Pixbuf(bannerStream);
                    }
                }

                // If we can connect, proceed with the rest of our checks.
                if (ChecksHandler.IsInitialStartup())
                {
                    Log.Info("This instance is the first start of the application in this folder.");

                    MessageDialog shouldInstallHereDialog = new MessageDialog(
                        null,
                        DialogFlags.Modal,
                        MessageType.Question,
                        ButtonsType.OkCancel,
                        LocalizationCatalog.GetString(
                            "This appears to be the first time you're starting the launcher.\n" +
                            "Is this the location where you would like to install the game?") +
                        $"\n\n{ConfigHandler.GetLocalDir()}"
                        );

                    if (shouldInstallHereDialog.Run() == (int)ResponseType.Ok)
                    {
                        shouldInstallHereDialog.Destroy();

                        // Yes, install here
                        Log.Info("User accepted installation in this directory. Installing in current directory.");

                        ConfigHandler.CreateLauncherCookie();
                    }
                    else
                    {
                        shouldInstallHereDialog.Destroy();

                        // No, don't install here
                        Log.Info("User declined installation in this directory. Exiting...");
                        Environment.Exit(2);
                    }
                }

                if (Config.ShouldAllowAnonymousStats())
                {
                    StatsHandler.SendUsageStats();
                }

                // Load the changelog. Try a direct URL first, and a protocol-specific
                // implementation after.
                if (LauncherHandler.CanAccessStandardChangelog())
                {
                    Browser.Navigate(Config.GetChangelogURL());
                }
                else
                {
                    Launcher.LoadFallbackChangelog();
                }

                // If the launcher does not need an update at this point, we can continue checks for the game
                if (!Checks.IsLauncherOutdated())
                {
                    if (!Checks.IsPlatformAvailable(Config.GetSystemTarget()))
                    {
                        Log.Info($"The server does not provide files for platform \"{ConfigHandler.GetCurrentPlatform()}\". " +
                                 "A .provides file must be present in the platforms' root directory.");

                        SetLauncherMode(ELauncherMode.Inactive, false);
                    }
                    else
                    {
                        if (!Checks.IsGameInstalled())
                        {
                            // If the game is not installed, offer to install it
                            Log.Info("The game has not yet been installed.");
                            SetLauncherMode(ELauncherMode.Install, false);

                            // Since the game has not yet been installed, disallow manual repairs
                            this.repairGameAction.Sensitive = false;

                            // and reinstalls
                            this.reinstallGameAction.Sensitive = false;
                        }
                        else
                        {
                            // If the game is installed (which it should be at this point), check if it needs to be updated
                            if (Checks.IsGameOutdated())
                            {
                                // If it does, offer to update it
                                Log.Info($"The game is outdated. \n\tLocal version: {Config.GetLocalGameVersion()}");
                                SetLauncherMode(ELauncherMode.Update, false);
                            }
                            else
                            {
                                // All checks passed, so we can offer to launch the game.
                                Log.Info("All checks passed. Game can be launched.");
                                SetLauncherMode(ELauncherMode.Launch, false);
                            }
                        }
                    }
                }
                else
                {
                    // The launcher was outdated.
                    Log.Info($"The launcher is outdated. \n\tLocal version: {Config.GetLocalLauncherVersion()}");
                    SetLauncherMode(ELauncherMode.Update, false);
                }
            }
        }
Ejemplo n.º 6
0
        public MainForm()
        {
            InitializeComponent();
            InitializeLocalizedStrings();

            // Bind the handler events
            Game.ProgressChanged      += OnModuleInstallationProgressChanged;
            Game.GameDownloadFinished += OnGameDownloadFinished;
            Game.GameDownloadFailed   += OnGameDownloadFailed;
            Game.GameLaunchFailed     += OnGameLaunchFailed;
            Game.GameExited           += OnGameExited;

            Launcher.LauncherDownloadProgressChanged += OnModuleInstallationProgressChanged;
            Launcher.LauncherDownloadFinished        += OnLauncherDownloadFinished;
            Launcher.ChangelogDownloadFinished       += OnChangelogDownloadFinished;

            SetLauncherMode(ELauncherMode.Inactive, false);
            MessageLabel.Text = LocalizationCatalog.GetString("Idle");

            downloadProgressLabel.Text = string.Empty;

            // Set the window text to match the game name
            this.Text = LocalizationCatalog.GetString("Launchpad - ") + Config.GetGameName();

            // First of all, check if we can connect to the FTP server.
            if (!Checks.CanPatch())
            {
                MessageBox.Show(
                    this,
                    LocalizationCatalog.GetString("Failed to connect to the patch server. Please check your settings."),
                    LocalizationCatalog.GetString("Could not connect to server."),
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error,
                    MessageBoxDefaultButton.Button1);

                MessageLabel.Text     = LocalizationCatalog.GetString("Could not connect to server.");
                PrimaryButton.Text    = LocalizationCatalog.GetString("Inactive");
                PrimaryButton.Enabled = false;
            }
            else
            {
                // If we can connect, proceed with the rest of our checks.
                if (ChecksHandler.IsInitialStartup())
                {
                    Log.Info("This instance is the first start of the application in this folder.");

                    DialogResult shouldInstallHere = MessageBox.Show(
                        this,
                        string.Format(
                            LocalizationCatalog.GetString("This appears to be the first time you're starting the launcher.\n" +
                                                          "Is this the location where you would like to install the game?" +
                                                          "\n\n{0}"), ConfigHandler.GetLocalDir()),
                        LocalizationCatalog.GetString("Initial startup"),
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Question,
                        MessageBoxDefaultButton.Button1);

                    if (shouldInstallHere == DialogResult.Yes)
                    {
                        // Yes, install here
                        Log.Info("User accepted installation in this directory. Installing in current directory.");

                        ConfigHandler.CreateUpdateCookie();
                    }
                    else
                    {
                        // No, don't install here
                        Log.Info("User declined installation in this directory. Exiting...");
                        Environment.Exit(2);
                    }
                }


                if (Config.ShouldAllowAnonymousStats())
                {
                    StatsHandler.SendUsageStats();
                }

                // Load the changelog. Try a direct URL first, and a protocol-specific
                // implementation after.
                if (Launcher.CanAccessStandardChangelog())
                {
                    changelogBrowser.Navigate(Config.GetChangelogURL());
                }
                else
                {
                    Launcher.LoadFallbackChangelog();
                }

                // Does the launcher need an update?
                if (!Checks.IsLauncherOutdated())
                {
                    if (!Checks.IsGameInstalled())
                    {
                        Log.Info("The game has not yet been installed.");
                        SetLauncherMode(ELauncherMode.Install, false);
                    }
                    else
                    {
                        if (Checks.IsGameOutdated())
                        {
                            Log.Info($"The game is outdated. \n\tLocal version: {Config.GetLocalGameVersion()}");
                            SetLauncherMode(ELauncherMode.Update, false);
                        }
                        else
                        {
                            Log.Info("All checks passed. Game can be launched.");
                            SetLauncherMode(ELauncherMode.Launch, false);
                        }
                    }
                }
                else
                {
                    Log.Info($"The launcher is outdated. \n\tLocal version: {Config.GetLocalLauncherVersion()}");
                    SetLauncherMode(ELauncherMode.Update, false);
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Downloads the provided manifest entry.
        /// This function resumes incomplete files, verifies downloaded files and
        /// downloads missing files.
        /// </summary>
        /// <param name="Entry">The entry to download.</param>
        /// <param name="Module">The module to download the file for. Determines download location.</param>
        private void DownloadEntry(ManifestEntry Entry, EModule Module)
        {
            ModuleDownloadProgressArgs.Module = Module;

            string baseRemotePath;
            string baseLocalPath;

            if (Module == EModule.Game)
            {
                baseRemotePath = Config.GetGameURL();
                baseLocalPath  = Config.GetGamePath();
            }
            else
            {
                baseRemotePath = Config.GetLauncherBinariesURL();
                baseLocalPath  = ConfigHandler.GetTempLauncherDownloadPath();
            }

            string RemotePath = String.Format("{0}{1}",
                                              baseRemotePath,
                                              Entry.RelativePath);

            string LocalPath = String.Format("{0}{1}{2}",
                                             baseLocalPath,
                                             Path.DirectorySeparatorChar,
                                             Entry.RelativePath);

            // Make sure we have a directory to put the file in
            Directory.CreateDirectory(Path.GetDirectoryName(LocalPath));

            // Reset the cookie
            File.WriteAllText(ConfigHandler.GetInstallCookiePath(), String.Empty);

            // Write the current file progress to the install cookie
            using (TextWriter textWriterProgress = new StreamWriter(ConfigHandler.GetInstallCookiePath()))
            {
                textWriterProgress.WriteLine(Entry);
                textWriterProgress.Flush();
            }

            if (File.Exists(LocalPath))
            {
                FileInfo fileInfo = new FileInfo(LocalPath);
                if (fileInfo.Length != Entry.Size)
                {
                    // If the file is partial, resume the download.
                    if (fileInfo.Length < Entry.Size)
                    {
                        DownloadRemoteFile(RemotePath, LocalPath, fileInfo.Length);
                    }
                    else
                    {
                        // If it's larger than expected, toss it in the bin and try again.
                        File.Delete(LocalPath);
                        DownloadRemoteFile(RemotePath, LocalPath);
                    }
                }
                else
                {
                    string LocalHash;
                    using (FileStream fs = File.OpenRead(LocalPath))
                    {
                        LocalHash = MD5Handler.GetStreamHash(fs);
                    }

                    if (LocalHash != Entry.Hash)
                    {
                        File.Delete(LocalPath);
                        DownloadRemoteFile(RemotePath, LocalPath);
                    }
                }
            }
            else
            {
                //no file, download it
                DownloadRemoteFile(RemotePath, LocalPath);
            }

            if (ChecksHandler.IsRunningOnUnix())
            {
                //if we're dealing with a file that should be executable,
                string gameName = Config.GetGameName();
                bool   bFileIsGameExecutable = (Path.GetFileName(LocalPath).EndsWith(".exe")) || (Path.GetFileName(LocalPath) == gameName);
                if (bFileIsGameExecutable)
                {
                    //set the execute bits
                    UnixHandler.MakeExecutable(LocalPath);
                }
            }

            // We've finished the download, so empty the cookie
            File.WriteAllText(ConfigHandler.GetInstallCookiePath(), String.Empty);
        }
        protected virtual void DownloadManifestEntry(ManifestEntry Entry, EModule Module)
        {
            ModuleDownloadProgressArgs.Module = Module;

            string baseRemoteURL;
            string baseLocalPath;

            switch (Module)
            {
            case EModule.Launcher:
            {
                baseRemoteURL = Config.GetLauncherBinariesURL();
                baseLocalPath = ConfigHandler.GetTempLauncherDownloadPath();
                break;
            }

            case EModule.Game:
            {
                baseRemoteURL = Config.GetGameURL();
                baseLocalPath = Config.GetGamePath();
                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException(nameof(Module), Module, "The module passed to DownloadManifestEntry was invalid.");
            }
            }

            // Build the access strings
            string remoteURL = $"{baseRemoteURL}{Entry.RelativePath}";
            string localPath = $"{baseLocalPath}{Path.DirectorySeparatorChar}{Entry.RelativePath}";

            // Make sure we have a directory to put the file in
            if (Path.GetDirectoryName(localPath) != null)
            {
                Directory.CreateDirectory(Path.GetDirectoryName(localPath));
            }
            else
            {
                throw new ArgumentNullException(nameof(localPath), "The local path was null.");
            }

            // Reset the cookie
            File.WriteAllText(ConfigHandler.GetInstallCookiePath(), string.Empty);

            // Write the current file progress to the install cookie
            using (TextWriter textWriterProgress = new StreamWriter(ConfigHandler.GetInstallCookiePath()))
            {
                textWriterProgress.WriteLine(Entry);
                textWriterProgress.Flush();
            }

            if (File.Exists(localPath))
            {
                FileInfo fileInfo = new FileInfo(localPath);
                if (fileInfo.Length != Entry.Size)
                {
                    // If the file is partial, resume the download.
                    if (fileInfo.Length < Entry.Size)
                    {
                        Log.Info($"Resuming interrupted file \"{Path.GetFileNameWithoutExtension(Entry.RelativePath)}\" at byte {fileInfo.Length}.");
                        DownloadRemoteFile(remoteURL, localPath, Entry.Size, fileInfo.Length);
                    }
                    else
                    {
                        // If it's larger than expected, toss it in the bin and try again.
                        Log.Info($"Restarting interrupted file \"{Path.GetFileNameWithoutExtension(Entry.RelativePath)}\": File bigger than expected.");

                        File.Delete(localPath);
                        DownloadRemoteFile(remoteURL, localPath, Entry.Size);
                    }
                }
                else
                {
                    string localHash;
                    using (FileStream fs = File.OpenRead(localPath))
                    {
                        localHash = MD5Handler.GetStreamHash(fs);
                    }

                    if (localHash != Entry.Hash)
                    {
                        // If the hash doesn't match, toss it in the bin and try again.
                        Log.Info($"Redownloading file \"{Path.GetFileNameWithoutExtension(Entry.RelativePath)}\": " +
                                 $"Hash sum mismatch. Local: {localHash}, Expected: {Entry.Hash}");

                        File.Delete(localPath);
                        DownloadRemoteFile(remoteURL, localPath, Entry.Size);
                    }
                }
            }
            else
            {
                // No file, download it
                DownloadRemoteFile(remoteURL, localPath, Entry.Size);
            }

            if (ChecksHandler.IsRunningOnUnix())
            {
                // If we're dealing with a file that should be executable,
                string gameName = Config.GetGameName();
                bool   bFileIsGameExecutable = (Path.GetFileName(localPath).EndsWith(".exe")) || (Path.GetFileName(localPath) == gameName);
                if (bFileIsGameExecutable)
                {
                    // Set the execute bits
                    UnixHandler.MakeExecutable(localPath);
                }
            }

            // We've finished the download, so empty the cookie
            File.WriteAllText(ConfigHandler.GetInstallCookiePath(), string.Empty);
        }
Ejemplo n.º 9
0
 public ValidationChecks()
 {
     checks += ExpressionCheck;
     checks += BracketsCheck;
     checks += AllowedCharactersCheck;
 }
        private void Build()
        {
            Gui.Initialize(this);

            // Widget Launchpad.Launcher.Interface.MainWindow
            this.UIManager = new UIManager();
            ActionGroup mainActionGroup = new ActionGroup("Default");

            this.menuAction = new Action("menuAction", LocalizationCatalog.GetString("Menu"), null, null)
            {
                ShortLabel = LocalizationCatalog.GetString("Menu")
            };
            mainActionGroup.Add(this.menuAction, null);

            this.repairGameAction = new Action(
                "repairGameAction",
                LocalizationCatalog.GetString("Repair Game"),
                LocalizationCatalog.GetString("Starts a repair process for the installed game."),
                "gtk-refresh")
            {
                ShortLabel = LocalizationCatalog.GetString("Repair Game")
            };
            mainActionGroup.Add(this.repairGameAction, null);

            this.reinstallGameAction = new Action(
                "reinstallGameAction",
                LocalizationCatalog.GetString("Reinstall Game"),
                LocalizationCatalog.GetString("Reinstalls the installed game."),
                "gtk-refresh")
            {
                ShortLabel = LocalizationCatalog.GetString("Reinstall Game")
            };
            mainActionGroup.Add(this.reinstallGameAction, null);

            this.UIManager.InsertActionGroup(mainActionGroup, 0);
            this.AddAccelGroup(this.UIManager.AccelGroup);
            this.Name  = "Launchpad.Launcher.Interface.MainWindow";
            this.Title = LocalizationCatalog.GetString("Launchpad - {0}");

            if (ChecksHandler.IsRunningOnUnix())
            {
                this.Icon = Pixbuf.LoadFromResource("Launchpad.Launcher.Resources.RocketIcon.ico");
            }
            else
            {
                this.Icon = Pixbuf.LoadFromResource("Launchpad.Launcher.Resources.RocketIcon_Grey.ico");
            }

            this.WindowPosition = (WindowPosition)4;
            this.DefaultWidth   = 745;
            this.DefaultHeight  = 415;
            this.Resizable      = false;

            // Container child Launchpad.Launcher.Interface.MainWindow.Gtk.Container+ContainerChild
            this.vbox1 = new VBox
            {
                Name    = "vbox1",
                Spacing = 6
            };

            // Container child vbox1.Gtk.Box+BoxChild
            this.UIManager.AddUiFromString
            (
                "<ui>" +
                "<menubar name='menuBar'>" +
                "<menu name='menuAction' action='menuAction'>" +
                "<menuitem name='repairGameAction' action='repairGameAction'/>" +
                "<separator/>" +
                "<menuitem name='reinstallGameAction' action='reinstallGameAction'/>" +
                "</menu>" +
                "</menubar>" +
                "</ui>"
            );
            this.menuBar      = (MenuBar)this.UIManager.GetWidget("/menuBar");
            this.menuBar.Name = "menuBar";
            this.vbox1.Add(this.menuBar);

            Box.BoxChild w2 = (Box.BoxChild) this.vbox1 [this.menuBar];
            w2.Position = 0;
            w2.Expand   = false;
            w2.Fill     = false;

            // Container child vbox1.Gtk.Box+BoxChild
            this.hbox2 = new HBox
            {
                Name        = "hbox2",
                Spacing     = 6,
                BorderWidth = 4
            };

            // Container child hbox2.Gtk.Box+BoxChild
            this.browserContainer = new VBox
            {
                Name    = "browserContainer",
                Spacing = 6
            };

            // Container child browserContainer.Gtk.Box+BoxChild
            this.alignment2 = new Alignment(0.5F, 0.5F, 1F, 1F)
            {
                WidthRequest = 310,
                Name         = "alignment2"
            };

            // Container child alignment2.Gtk.Container+ContainerChild
            this.browserWindow = new ScrolledWindow
            {
                CanFocus   = true,
                Name       = "browserWindow",
                ShadowType = ShadowType.In
            };
            this.alignment2.Add(this.browserWindow);
            this.browserContainer.Add(this.alignment2);

            Box.BoxChild w4 = (Box.BoxChild) this.browserContainer [this.alignment2];
            w4.Position = 0;
            this.hbox2.Add(this.browserContainer);

            Box.BoxChild w5 = (Box.BoxChild) this.hbox2 [this.browserContainer];
            w5.Position = 0;
            w5.Expand   = false;

            // Container child hbox2.Gtk.Box+BoxChild
            this.alignment5 = new Alignment(0.5F, 0.5F, 1F, 1F)
            {
                Name = "alignment5"
            };

            // Container child alignment5.Gtk.Container+ContainerChild
            this.gameBanner = new Image
            {
                WidthRequest  = 450,
                HeightRequest = 300,
                Name          = "gameBanner",
                Pixbuf        = Pixbuf.LoadFromResource("Launchpad.Launcher.Resources.RocketIcon.ico")
            };
            this.alignment5.Add(this.gameBanner);
            this.hbox2.Add(this.alignment5);

            Box.BoxChild w7 = (Box.BoxChild) this.hbox2 [this.alignment5];
            w7.Position = 1;
            this.vbox1.Add(this.hbox2);

            Box.BoxChild w8 = (Box.BoxChild) this.vbox1 [this.hbox2];
            w8.Position = 1;
            w8.Expand   = false;
            w8.Fill     = false;

            // Container child vbox1.Gtk.Box+BoxChild
            this.alignment1 = new Alignment(0.5F, 0.5F, 1F, 1F)
            {
                Name        = "alignment1",
                LeftPadding = 6
            };

            // Container child alignment1.Gtk.Container+ContainerChild
            this.indicatorLabel = new Label
            {
                Name      = "indicatorLabel",
                Xalign    = 0F,
                LabelProp = LocalizationCatalog.GetString("Idle")
            };
            this.alignment1.Add(this.indicatorLabel);
            this.vbox1.Add(this.alignment1);

            Box.BoxChild w10 = (Box.BoxChild) this.vbox1 [this.alignment1];
            w10.Position = 2;
            w10.Expand   = false;
            w10.Fill     = false;

            // Container child vbox1.Gtk.Box+BoxChild
            this.hbox3 = new HBox
            {
                Name        = "hbox3",
                Spacing     = 6,
                BorderWidth = 4
            };

            // Container child hbox3.Gtk.Box+BoxChild
            this.alignment4 = new Alignment(0.5F, 0.5F, 1F, 1F)
            {
                Name = "alignment4"
            };

            // Container child alignment4.Gtk.Container+ContainerChild
            this.mainProgressBar = new ProgressBar
            {
                Name = "mainProgressBar"
            };
            this.alignment4.Add(this.mainProgressBar);
            this.hbox3.Add(this.alignment4);

            Box.BoxChild w12 = (Box.BoxChild) this.hbox3 [this.alignment4];
            w12.Position = 0;

            // Container child hbox3.Gtk.Box+BoxChild
            this.hbox4 = new HBox
            {
                Name    = "hbox4",
                Spacing = 6
            };

            // Container child hbox4.Gtk.Box+BoxChild
            this.alignment3 = new Alignment(0.5F, 0.5F, 1F, 1F)
            {
                WidthRequest = 100,
                Name         = "alignment3"
            };

            // Container child alignment3.Gtk.Container+ContainerChild
            this.primaryButton = new Button
            {
                Sensitive    = false,
                CanDefault   = true,
                CanFocus     = true,
                Name         = "primaryButton",
                UseUnderline = true,
                Label        = LocalizationCatalog.GetString("Inactive")
            };
            this.alignment3.Add(this.primaryButton);
            this.hbox4.Add(this.alignment3);

            Box.BoxChild w14 = (Box.BoxChild) this.hbox4 [this.alignment3];
            w14.Position = 0;
            this.hbox3.Add(this.hbox4);

            Box.BoxChild w15 = (Box.BoxChild) this.hbox3 [this.hbox4];
            w15.Position = 1;
            w15.Expand   = false;
            w15.Fill     = false;
            this.vbox1.Add(this.hbox3);

            Box.BoxChild w16 = (Box.BoxChild) this.vbox1 [this.hbox3];
            w16.Position = 3;
            w16.Expand   = true;
            w16.Fill     = false;

            this.Add(this.vbox1);
            if ((this.Child != null))
            {
                this.Child.ShowAll();
            }

            this.primaryButton.HasDefault = true;
            this.Show();
            this.DeleteEvent += OnDeleteEvent;
            this.repairGameAction.Activated    += this.OnRepairGameActionActivated;
            this.reinstallGameAction.Activated += this.OnReinstallGameActionActivated;
            this.primaryButton.Clicked         += this.OnPrimaryButtonClicked;
        }