Example #1
0
        private void CheckForUpdate_Work(object sender, DoWorkEventArgs e)
        {
            e.Result = false;

            WebClient webClient = new WebClient();

            string gameDirectory = Properties.Settings.Default.GameInstallDirectory;
            string localManifest = gameDirectory + Path.DirectorySeparatorChar + LocalManifestFilename;

            if (!File.Exists(localManifest))
            {
                //We don't have the game downloaded.  Need to update.

                e.Result = true;
            }
            else
            {
                string ManifestURL = Properties.Settings.Default.ManifestURL;

                string manifest = webClient.DownloadString(ManifestURL);

                LauncherManifest RemoteManifest = JsonConvert.DeserializeObject <LauncherManifest>(manifest);



                LauncherManifest LocalManifest = JsonConvert.DeserializeObject <LauncherManifest>(File.ReadAllText(localManifest));

                if (RemoteManifest.Build > LocalManifest.Build)
                {
                    e.Result = true;;
                }
            }
        }
        public static void BuildManifest(string directory, int build, string executable, string gameURL)
        {
            LauncherManifest manifest = new LauncherManifest();

            manifest.Build       = build;
            manifest.Executable  = executable;
            manifest.ProjectRoot = gameURL;



            md5 = MD5.Create();

            RecursiveBuildManifest(directory, "", manifest);

            SaveFileDialog dialog = new SaveFileDialog();

            dialog.InitialDirectory = Environment.CurrentDirectory;
            dialog.FileName         = "Manifest.txt";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                File.WriteAllText(dialog.FileName, JsonConvert.SerializeObject(manifest, Formatting.Indented));
            }

            Properties.Settings.Default.Builder_LastBuildNumber = build + 1;
            Properties.Settings.Default.Builder_LastDirectory   = directory;
            Properties.Settings.Default.Builder_LastExecutable  = executable;
            Properties.Settings.Default.Builder_LastURL         = gameURL;
        }
        public static void BuildManifest(string directory, int build, string gameURL)
        {
            LauncherManifest manifest = new LauncherManifest();
            manifest.Build = build;
            manifest.ProjectRoot = gameURL;

            md5 = MD5.Create();

            RecursiveBuildManifest(directory, "", manifest);
            


            SaveFileDialog dialog = new SaveFileDialog();
            dialog.InitialDirectory = Environment.CurrentDirectory;
            dialog.FileName = "Manifest.txt";
            if(dialog.ShowDialog() == DialogResult.OK)
            {
                File.WriteAllText(dialog.FileName, JsonConvert.SerializeObject(manifest, Formatting.Indented));
            }

            Properties.Settings.Default.Builder_LastBuildNumber = build + 1;
            Properties.Settings.Default.Builder_LastDirectory = directory;
            Properties.Settings.Default.Builder_LastURL = gameURL;


        }
        private static void RecursiveBuildManifest(string projectRoot, string dir, LauncherManifest manifest)
        {
            string path = projectRoot + dir;

            foreach (string file in Directory.GetFiles(path))
            {
                string localPath = ToLocalPath(projectRoot, file);
                string hash      = Util.ComputeMD5(file);

                manifest.Files[localPath] = hash;
            }

            foreach (string nextDir in Directory.GetDirectories(path))
            {
                RecursiveBuildManifest(projectRoot, ToLocalPath(projectRoot, nextDir), manifest);
            }
        }
        private static void RecursiveBuildManifest(string projectRoot, string dir, LauncherManifest manifest)
        {
            string path = projectRoot + dir;

            foreach(string file in Directory.GetFiles(path))
            {
                string localPath = ToLocalPath(projectRoot, file);
                string hash = Util.ComputeMD5(file);

                manifest.Files[localPath] = hash;
            }

            foreach(string nextDir in Directory.GetDirectories(path))
            {
                RecursiveBuildManifest(projectRoot, ToLocalPath(projectRoot, nextDir), manifest);
            }
        }
Example #6
0
        private void LaunchGame()
        {
            string gameDirectory = Properties.Settings.Default.GameInstallDirectory;
            string localManifest = gameDirectory + Path.DirectorySeparatorChar + LocalManifestFilename;

            LauncherManifest LocalManifest  = JsonConvert.DeserializeObject <LauncherManifest>(File.ReadAllText(localManifest));
            string           gameInstallDir = Properties.Settings.Default.GameInstallDirectory;

            ProcessStartInfo psi = new ProcessStartInfo();

            psi.FileName         = LocalManifest.Executable;
            psi.WorkingDirectory = Path.GetFullPath(gameInstallDir);
            psi.UseShellExecute  = true;



            this.WindowState = FormWindowState.Minimized;
            Process process = Process.Start(psi);

            process.Exited += process_Exited;
        }
Example #7
0
        private void DownloadFile(int curFile, int totalFiles, KeyValuePair <string, string> kv, LauncherManifest RemoteManifest, string gameFilePath, WebClient webClient)
        {
            int progress = (int)(((float)curFile / (float)totalFiles) * 100);

            string status = "(" + (curFile) + " / " + totalFiles + ") Downloading: " + kv.Key;

            backgroundWorker1.ReportProgress(progress, status);

            string remoteFile = (RemoteManifest.ProjectRoot + kv.Key.Substring(1));

            Directory.CreateDirectory(Path.GetDirectoryName(gameFilePath));
            if (File.Exists(gameFilePath))
            {
                File.Delete(gameFilePath);
            }

            webClient.DownloadFileAsync(new Uri(remoteFile), gameFilePath, status);

            while (webClient.IsBusy)
            {
                Thread.Sleep(1);
            }
        }
Example #8
0
        void UpdateGame_Worker(object sender, DoWorkEventArgs e)
        {
            backgroundWorker1.ReportProgress(0, "Downloading Manifest...");


            string    ManifestURL = Properties.Settings.Default.ManifestURL;
            WebClient webClient   = new WebClient();

            webClient.DownloadProgressChanged += webClient_DownloadProgressChanged;
            webClient.DownloadFileCompleted   += webClient_DownloadFileCompleted;

            string           manifest       = webClient.DownloadString(ManifestURL);
            LauncherManifest RemoteManifest = JsonConvert.DeserializeObject <LauncherManifest>(manifest);


            string gameInstallDir = Properties.Settings.Default.GameInstallDirectory;

            var md5        = MD5.Create();
            int totalFiles = RemoteManifest.Files.Count;

            int curFile = 0;

            foreach (KeyValuePair <string, string> kv in RemoteManifest.Files)
            {
                bool   ShouldDownload = false;
                string gameFilePath   = gameInstallDir + kv.Key.Replace("/", Path.DirectorySeparatorChar.ToString());
                if (File.Exists(gameFilePath))
                {
                    int progress = (int)(((float)curFile / (float)totalFiles) * 100);
                    backgroundWorker1.ReportProgress(progress, "(" + (curFile) + " / " + totalFiles + ") Checking " + kv.Key);
                    //Check it's md5 hash
                    using (var stream = File.OpenRead(gameFilePath))
                    {
                        var hash = Util.ComputeMD5(gameFilePath);

                        if (hash != kv.Value)
                        {
                            ShouldDownload = true;
                        }
                    }
                }
                else
                {
                    ShouldDownload = true;
                }


                if (ShouldDownload)
                {
                    DownloadFile(curFile, totalFiles, kv, RemoteManifest, gameFilePath, webClient);

                    var hash = Util.ComputeMD5(gameFilePath);

                    if (hash != kv.Value)
                    {
                        MessageBox.Show("Failed Validating " + kv.Key);
                        DownloadFile(curFile, totalFiles, kv, RemoteManifest, gameFilePath, webClient);
                    }
                }
                if (backgroundWorker1.CancellationPending)
                {
                    return;
                }
                curFile++;
            }

            backgroundWorker1.ReportProgress(100, "Writing Local Manifest");

            string gameDirectory = Properties.Settings.Default.GameInstallDirectory;
            string localManifest = gameDirectory + Path.DirectorySeparatorChar + LocalManifestFilename;

            File.WriteAllText(localManifest, manifest);
        }
        private void RecursiveRemoveFiles(string projectRoot, string dir, string modpackRoot, LauncherManifest manifest)
        {

            string path = projectRoot + dir;

            foreach (string file in Directory.GetFiles(path))
            {
                string localPath = ToFilePath(projectRoot, file);
                string jsonPath = ToJsonPath(projectRoot, file);
                
                if(!manifest.Files.ContainsKey(modpackRoot + jsonPath))
                {
                    System.IO.File.Delete(localPath);
                } else {
                }
            }

            foreach (string nextDir in Directory.GetDirectories(path))
            {
                RecursiveRemoveFiles(projectRoot, ToJsonPath(projectRoot, nextDir), modpackRoot, manifest);
            }

        }
        private void DownloadFile(int curFile, int totalFiles, KeyValuePair<string, string> kv, LauncherManifest RemoteManifest, string gameFilePath, WebClient webClient)
        {
            int progress = (int)(((float)curFile / (float)totalFiles) * 100);

            string status = "(" + (curFile) + " / " + totalFiles + ") Downloading: " + kv.Key;

            backgroundWorker1.ReportProgress(progress, status);

            string remoteFile = (Properties.Settings.Default.ContentURL + RemoteManifest.ProjectRoot + kv.Key.Substring(1));

            Directory.CreateDirectory(Path.GetDirectoryName(gameFilePath));
            if (File.Exists(gameFilePath))
            {
                File.Delete(gameFilePath);
            }

            webClient.DownloadFileAsync(new Uri(remoteFile), gameFilePath, status);

            while (webClient.IsBusy)
            {
                Thread.Sleep(1);
            }
        }