Ejemplo n.º 1
0
        public MainForm()
        {
            InitializeComponent();

            Config.Initialize();

            MessageLabel.Text          = LocalizationCatalog.GetString("idleString");
            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.CanConnectToFTP())
            {
                MessageBox.Show(
                    this,
                    LocalizationCatalog.GetString("ftpConnectionFailureMessage"),
                    LocalizationCatalog.GetString("ftpConnectionFailureString"),
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error,
                    MessageBoxDefaultButton.Button1);

                MessageLabel.Text     = LocalizationCatalog.GetString("ftpConnectionFailureString");
                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("initialStartupMessage"), ConfigHandler.GetLocalDir()),
                        LocalizationCatalog.GetString("infoTitle"),
                        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 (bSendAnonStats)
                {
                    StatsHandler.SendUsageStats();
                }
                else
                {
                    Stream iconStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Launchpad.Launcher.Resources.RocketIcon.ico");
                    if (iconStream != null)
                    {
                        NotifyIcon noUsageStatsNotification = new NotifyIcon();
                        noUsageStatsNotification.Icon    = new System.Drawing.Icon(iconStream);
                        noUsageStatsNotification.Visible = true;

                        noUsageStatsNotification.BalloonTipTitle = LocalizationCatalog.GetString("infoTitle");
                        noUsageStatsNotification.BalloonTipText  = LocalizationCatalog.GetString("usageTitle");

                        noUsageStatsNotification.ShowBalloonTip(10000);
                    }
                }

                //load the changelog from the server
                Launcher.ChangelogDownloadFinished += OnChangelogDownloadFinished;
                Launcher.LoadChangelog();

                //Does the launcher need an update?
                if (!Checks.IsLauncherOutdated())
                {
                    if (Checks.IsManifestOutdated())
                    {
                        Launcher.DownloadManifest();
                    }

                    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.º 2
0
        private void InstallGameAsync()
        {
            //This value is filled with either a path to the last downloaded file, or with an exception message
            //this message is used in the main UI to determine how it responds to a failed download.
            string fileReturn = "";

            try
            {
                FTPHandler           FTP             = new FTPHandler();
                ManifestHandler      manifestHandler = new ManifestHandler();
                List <ManifestEntry> Manifest        = manifestHandler.Manifest;

                //create the .install file to mark that an installation has begun
                //if it exists, do nothing.
                ConfigHandler.CreateInstallCookie();


                //raise the progress changed event by binding to the
                //event in the FTP class
                FTP.FileProgressChanged += OnDownloadProgressChanged;

                //in order to be able to resume downloading, we check if there is an entry
                //stored in the install cookie.
                ManifestEntry lastDownloadedFile = null;
                string        installCookiePath  = ConfigHandler.GetInstallCookiePath();

                //attempt to parse whatever is inside the install cookie
                if (ManifestEntry.TryParse(File.ReadAllText(installCookiePath), out lastDownloadedFile))
                {
                    //loop through all the entries in the manifest until we encounter
                    //an entry which matches the one in the install cookie

                    foreach (ManifestEntry Entry in Manifest)
                    {
                        if (lastDownloadedFile == Entry)
                        {
                            //remove all entries before the one we were last at.
                            Manifest.RemoveRange(0, Manifest.IndexOf(Entry));
                        }
                    }
                }

                //then, start downloading the entries that remain in the manifest.
                foreach (ManifestEntry Entry in Manifest)
                {
                    string RemotePath = String.Format("{0}{1}",
                                                      Config.GetGameURL(true),
                                                      Entry.RelativePath);

                    string LocalPath = String.Format("{0}{1}{2}",
                                                     Config.GetGamePath(true),
                                                     System.IO.Path.DirectorySeparatorChar,
                                                     Entry.RelativePath);

                    //make sure we have a game directory to put files in
                    Directory.CreateDirectory(Path.GetDirectoryName(LocalPath));

                    //write the current file progress to the install cookie
                    TextWriter textWriterProgress = new StreamWriter(ConfigHandler.GetInstallCookiePath());
                    textWriterProgress.WriteLine(Entry.ToString());
                    textWriterProgress.Close();

                    if (File.Exists(LocalPath))
                    {
                        FileInfo fileInfo = new FileInfo(LocalPath);
                        if (fileInfo.Length != Entry.Size)
                        {
                            //Resume the download of this partial file.
                            OnProgressChanged();
                            fileReturn = FTP.DownloadFTPFile(RemotePath, LocalPath, fileInfo.Length, false);

                            //Now verify the file
                            string localHash = MD5Handler.GetFileHash(File.OpenRead(LocalPath));

                            if (localHash != Entry.Hash)
                            {
                                Console.WriteLine("InstallGameAsync: Resumed file hash was invalid, downloading fresh copy from server.");
                                OnProgressChanged();
                                fileReturn = FTP.DownloadFTPFile(RemotePath, LocalPath, false);
                            }
                        }
                    }
                    else
                    {
                        //no file, download it
                        OnProgressChanged();
                        fileReturn = FTP.DownloadFTPFile(RemotePath, LocalPath, false);
                    }

                    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.GetFileNameWithoutExtension(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);

                //raise the finished event
                OnGameDownloadFinished();

                //clear out the event handler
                FTP.FileProgressChanged -= OnDownloadProgressChanged;
            }
            catch (IOException ioex)
            {
                Console.WriteLine("IOException in InstallGameAsync(): " + ioex.Message);

                DownloadFailedArgs.Result     = "1";
                DownloadFailedArgs.ResultType = "Install";
                DownloadFinishedArgs.Metadata = fileReturn;

                OnGameDownloadFailed();
            }
        }
Ejemplo n.º 3
0
        private void RepairGameAsync()
        {
            //This value is filled with either a path to the last downloaded file, or with an exception message
            //this message is used in the main UI to determine how it responds to a failed download.
            string repairMetadata = "";

            try
            {
                //check all local file MD5s against latest manifest. Resume partial files, download broken files.
                FTPHandler FTP = new FTPHandler();

                //bind event handlers
                FTP.FileProgressChanged += OnDownloadProgressChanged;

                //first, verify that the manifest is correct.
                string LocalManifestHash  = MD5Handler.GetFileHash(File.OpenRead(ConfigHandler.GetManifestPath()));
                string RemoteManifestHash = FTP.GetRemoteManifestChecksum();

                //if it is not, download a new copy.
                if (!(LocalManifestHash == RemoteManifestHash))
                {
                    LauncherHandler Launcher = new LauncherHandler();
                    Launcher.DownloadManifest();
                }

                //then, begin repairing the game
                ManifestHandler      manifestHandler = new ManifestHandler();
                List <ManifestEntry> Manifest        = manifestHandler.Manifest;

                ProgressArgs.TotalFiles = Manifest.Count;

                int i = 0;
                foreach (ManifestEntry Entry in Manifest)
                {
                    string RemotePath = String.Format("{0}{1}",
                                                      Config.GetGameURL(true),
                                                      Entry.RelativePath);

                    string LocalPath = String.Format("{0}{1}",
                                                     Config.GetGamePath(true),
                                                     Entry.RelativePath);

                    ProgressArgs.FileName = Path.GetFileName(LocalPath);

                    //make sure the directory for the file exists
                    Directory.CreateDirectory(Directory.GetParent(LocalPath).ToString());

                    if (File.Exists(LocalPath))
                    {
                        FileInfo fileInfo = new FileInfo(LocalPath);
                        if (fileInfo.Length != Entry.Size)
                        {
                            //Resume the download of this partial file.
                            OnProgressChanged();
                            repairMetadata = FTP.DownloadFTPFile(RemotePath, LocalPath, fileInfo.Length, false);

                            //Now verify the file
                            string localHash = MD5Handler.GetFileHash(File.OpenRead(LocalPath));

                            if (localHash != Entry.Hash)
                            {
                                Console.WriteLine("RepairGameAsync: Resumed file hash was invalid, downloading fresh copy from server.");

                                //download the file, since it was broken
                                OnProgressChanged();
                                repairMetadata = FTP.DownloadFTPFile(RemotePath, LocalPath, false);
                            }
                        }
                    }
                    else
                    {
                        //download the file, since it was missing
                        OnProgressChanged();
                        repairMetadata = FTP.DownloadFTPFile(RemotePath, LocalPath, false);
                    }

                    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.GetFileNameWithoutExtension(LocalPath) == gameName);
                        if (bFileIsGameExecutable)
                        {
                            //set the execute bits.
                            UnixHandler.MakeExecutable(LocalPath);
                        }
                    }

                    ++i;
                    ProgressArgs.DownloadedFiles = i;
                    OnProgressChanged();
                }

                OnGameRepairFinished();

                //clear out the event handler
                FTP.FileProgressChanged -= OnDownloadProgressChanged;
            }
            catch (IOException ioex)
            {
                Console.WriteLine("IOException in RepairGameAsync(): " + ioex.Message);

                DownloadFailedArgs.Result     = "1";
                DownloadFailedArgs.ResultType = "Repair";
                DownloadFailedArgs.Metadata   = repairMetadata;

                OnGameRepairFailed();
            }
        }
Ejemplo n.º 4
0
        public MainWindow() :
            base(WindowType.Toplevel)
        {
            //initialize localization
            Mono.Unix.Catalog.Init("Launchpad", "./locale");

            //Initialize the config files and check values.
            Config.Initialize();

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

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

            // Configure the WebView for our changelog
            Browser.SetSizeRequest(290, 300);

            scrolledwindow2.Add(Browser);
            scrolledwindow2.ShowAll();

            MessageLabel.Text = Mono.Unix.Catalog.GetString("Idle");

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

                dialog.Run();
                dialog.Destroy();
                MessageLabel.Text = Mono.Unix.Catalog.GetString("Could not connect to server.");
            }
            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(Mono.Unix.Catalog.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 (bSendAnonStats)
                {
                    StatsHandler.SendUsageStats();
                }
                else
                {
                    Notification noUsageStatsNotification = new Notification();

                    noUsageStatsNotification.IconName = Stock.DialogWarning;
                    noUsageStatsNotification.Urgency  = Urgency.Normal;
                    noUsageStatsNotification.Summary  = Mono.Unix.Catalog.GetString("Launchpad - Warning");
                    noUsageStatsNotification.Body     = Mono.Unix.Catalog.GetString("Anonymous useage stats are not enabled.");

                    noUsageStatsNotification.Show();
                }


                //Start loading the changelog asynchronously
                Launcher.ChangelogDownloadFinished += OnChangelogDownloadFinished;
                Launcher.LoadChangelog();

                //if the launcher does not need an update at this point, we can continue checks for the game
                if (!Checks.IsLauncherOutdated())
                {
                    if (Checks.IsManifestOutdated())
                    {
                        Launcher.DownloadManifest();
                    }

                    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);
                }
            }
        }