Example #1
0
        private void btnDownloadInstall_Click(object sender, EventArgs e)
        {
            string downloadUrl = LauncherSettings.GetWebValue(LauncherSettings.INSTALLER_URL);
            string filename    = downloadUrl.Substring(downloadUrl.LastIndexOf('/') + 1);
            string tempPath    = Path.Combine(LauncherSettings.TempDir, filename);

            KillProcess(filename);

            DownloadForm.DownloadFile(downloadUrl, tempPath, null);
        }
Example #2
0
        public void DownloadFile(string downloadURL, string downloadedFile, string extractDirectory)
        {
            MainForm.dForm = new DownloadForm(downloadURL, downloadedFile, extractDirectory);


            MainForm.dForm.TopLevel = false;
            MainForm.dForm.Location = new Point(0, 0);
            MainForm.dForm.Dock     = DockStyle.Fill;
            this.Controls.Add(MainForm.dForm);
            MainForm.dForm.Show();
            MainForm.dForm.Focus();
            MainForm.dForm.BringToFront();
        }
Example #3
0
        private void btnInstallPatch_Click(object sender, EventArgs e)
        {
            if (lbPatches.SelectedIndex == -1)
            {
                return;
            }


            string patchname    = lbPatches.SelectedItem.ToString();
            string patchPackUrl = $"{LauncherSettings.GetValue(LauncherSettings.PATCH_SERVER_ROOT)}/{patchname}/pack.zip";
            string tempFilename = Path.Combine(LauncherSettings.TempDir, "pack.zip");
            string ms2Folder    = tbGameDirectory.Text;

            DownloadForm.DownloadFile(patchPackUrl, tempFilename, ms2Folder);
        }
Example #4
0
        public void DownloadComplete(string downloadedFile, string extractDirectory)
        {
            try
            {
                if (extractDirectory != null)
                {
                    if (!Directory.Exists(extractDirectory))
                    {
                        Directory.CreateDirectory(extractDirectory);
                    }

                    try
                    {
                        //System.IO.Compression.ZipFile.ExtractToDirectory(downloadedFile, extractDirectory);

                        using (ZipArchive archive = ZipFile.OpenRead(downloadedFile))
                        {
                            foreach (var entry in archive.Entries)
                            {
                                var entryPath = Path.Combine(extractDirectory, entry.FullName).Replace("/", "\\");

                                if (entryPath.EndsWith("\\"))
                                {
                                    if (!Directory.Exists(entryPath))
                                    {
                                        Directory.CreateDirectory(entryPath);
                                    }
                                }
                                else
                                {
                                    entry.ExtractToFile(entryPath, true);
                                }
                            }
                        }

                        MessageBox.Show("Patch installed successfully");

                        string patchname    = lbPatches.SelectedItem.ToString();
                        string patchDateUrl = $"{LauncherSettings.GetValue(LauncherSettings.PATCH_SERVER_ROOT)}/{patchname}/patchdate.php";

                        string serverPatchDate = null;

                        try
                        {
                            WebClient wc = new WebClient();
                            serverPatchDate = wc.DownloadString(patchDateUrl);
                        }
                        catch { return; } //eat it

                        LauncherSettings.SetValue(patchname, serverPatchDate);

                        lbPatches_SelectedIndexChanged(null, null);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show($"An error occurred during extraction\n\n{ex}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                        return;
                    }


                    if (File.Exists(downloadedFile))
                    {
                        File.Delete(downloadedFile);
                    }
                }
                else
                {
                    Process.Start(downloadedFile);
                }
            }
            finally
            {
                dForm.Close();
                dForm = null;
            }
        }