Пример #1
0
        public static void AddToIgnoreList()
        {
            Util.GetIgnoreManifest(true); //let's verify we have a ignore list from the start

            string           IgnorePath     = curDir + Path.DirectorySeparatorChar + "customignore.list";
            string           IgnoreString   = File.ReadAllText(IgnorePath);
            LauncherManifest IgnoreManifest = JsonConvert.DeserializeObject <LauncherManifest>(IgnoreString);// then get it

            var dialog = new System.Windows.Forms.OpenFileDialog();

            dialog.InitialDirectory = NSFolder;
            dialog.Multiselect      = true;

            dialog.Title = "Please indicate what file(s) to add in the ignore list !";

            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                foreach (string file in dialog.FileNames)
                {
                    string localPath = Util.ToLocalPath(NSFolder, file);
                    IgnoreManifest.Files[localPath] = "1"; //we using the launchermanifest but set "1" to ignore verify and update ("0" is ignore only update)
                }

                File.WriteAllText(IgnorePath, JsonConvert.SerializeObject(IgnoreManifest, Formatting.Indented));
            }
        }
Пример #2
0
        public static LauncherManifest GetIgnoreManifest(bool isVerification)
        {
            // we first get the ignore.list used by dev
            string           IgnorePath  = Launcher.curDir + Path.DirectorySeparatorChar + "ignore.list";
            LauncherManifest NewManifest = new LauncherManifest();

            if (File.Exists(IgnorePath) && isVerification) //then we can use the one in the folder. That's ok
            {
                string IgnoreString = File.ReadAllText(IgnorePath);
                NewManifest = JsonConvert.DeserializeObject <LauncherManifest>(IgnoreString);
            }
            else
            {
                try
                {
                    using (WebClient webClient = new WebClient()) // yeah I know it's brutal :D
                    {
                        webClient.DownloadFile(new Uri(Properties.Settings.Default.IndexURL + "/ignore.list"), IgnorePath);
                    }

                    string IgnoreString = File.ReadAllText(IgnorePath);
                    NewManifest = JsonConvert.DeserializeObject <LauncherManifest>(IgnoreString);
                }
                catch (Exception exception)
                {
                    /*MessageBoxResult AlertBox = System.Windows.MessageBox.Show("Could not retrieve a new ignore manifest file, Creating a void one...");
                     * NewManifest.Files["/config.cfg"] = "";*/
                    Util.PlaySoundFX("error");
                    MessageBoxResult AlertBox = System.Windows.MessageBox.Show("Launcher couldn't find a correct ignore.list from online source, please verify you internet connection..."
                                                                               , "Alert", MessageBoxButton.OK, MessageBoxImage.Error);

                    App.SendReport(exception, "Launcher couldn't find a correct ignore.list from online source, please verify you internet connection...");
                }
            }
            // then we read the custom one on the disk
            string           CustomIgnorePath     = Launcher.curDir + Path.DirectorySeparatorChar + "customignore.list";
            LauncherManifest CustomignoreManifest = new LauncherManifest();

            if (File.Exists(CustomIgnorePath))
            {
                string IgnoreString = File.ReadAllText(CustomIgnorePath);
                CustomignoreManifest = JsonConvert.DeserializeObject <LauncherManifest>(IgnoreString);
            }
            else
            {
                CustomignoreManifest.Files["/exemple.xpl"] = "1";

                File.WriteAllText(CustomIgnorePath, JsonConvert.SerializeObject(CustomignoreManifest, Formatting.Indented)); //write the new voidy ignore manifest
            }

            // then we add both manifest to return the ignore list
            foreach (KeyValuePair <string, string> kv in CustomignoreManifest.Files)
            {
                NewManifest.Files.Add(kv.Key, kv.Value);
            }

            return(NewManifest);
        }
Пример #3
0
 private static void UpdateCryptoManifest()
 {
     using (WebClient webClient = new WebClient())
     {
         Console.WriteLine("Downloading the CryptoManifest");
         string dasManifest = webClient.DownloadString(new Uri(manifestUrl));
         CryptoManifest = JsonConvert.DeserializeObject <LauncherManifest>(dasManifest);
         NumberOfFiles  = CryptoManifest.Files.Count;
     }
 }
Пример #4
0
        // This function is here to compare the general "standard" ns install with the advanced "NlPack" install version
        // If the user is using the NLPack then the manifest has to be updated consequently.
        public static LauncherManifest CleanManifestWithOptions(LauncherManifest GeneralManifest, LauncherManifest NLManifest)
        {
            //string value = "";
            foreach (KeyValuePair <string, string> kv in NLManifest.Files)
            {
                if (GeneralManifest.Files.ContainsKey(kv.Key))
                {
                    // we should delete, not to verify this. Then a second period of the updater check changed with the nl folder and its own manifest.
                    // the following code is in case you want to change the value (commented)

                    /*NLManifest.Files.TryGetValue(kv.Key, out value);
                     * GeneralManifest.Files[kv.Key] = value; */

                    GeneralManifest.Files.Remove(kv.Key);
                }
            }

            return(GeneralManifest);
        }
Пример #5
0
        public static void BuildManifest(string directory)
        {
            LauncherManifest manifest = new LauncherManifest();

            md5 = MD5.Create();

            RecursiveBuildManifest(directory, "", manifest);

            /*SaveFileDialog dialog = new SaveFileDialog(); // commented but needed when you want to save a manifest somewhere else (could be usefull for a manifest builder console app
             * dialog.InitialDirectory = Environment.CurrentDirectory;
             * dialog.FileName = "Manifest.txt";
             * if (dialog.ShowDialog() == DialogResult.OK)
             * {
             *  File.WriteAllText(dialog.FileName, JsonConvert.SerializeObject(manifest, Formatting.Indented));
             * }*/

            string ManifestPath = Launcher.curDir + Path.DirectorySeparatorChar + Launcher.ManifestName;

            File.WriteAllText(ManifestPath, JsonConvert.SerializeObject(manifest, Formatting.Indented));
        }
Пример #6
0
        private static void RecursiveBuildManifest(string projectRoot, string dir, LauncherManifest manifest)
        {
            string path = projectRoot + dir;

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

                if (!localPath.EndsWith("_.cfg") && localPath != "/Manifest.txt" && localPath != "/ManifestBuilder.exe" &&
                    localPath != "/Newtonsoft.Json.dll")    //we don't want  cfg files to get updated here cept config.cfg which is in ignore.list
                {
                    manifest.Files[localPath] = hash;
                }
            }

            foreach (string nextDir in Directory.GetDirectories(path))
            {
                RecursiveBuildManifest(projectRoot, Util.ToLocalPath(projectRoot, nextDir), manifest);
            }
        }
        private void DownloadFile(int curFile, int totalFiles, KeyValuePair <string, string> kv, LauncherManifest RemoteManifest, string gameFilePath, string folderURL, WebClient webClient)
        {
            int progress = (int)(((float)curFile / (float)totalFiles) * 100);

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

            UpdateLog.WriteLine(Util.GetShortTimeString() + "Downloading file: " + kv.Key);

            backgroundWorker.ReportProgress(progress, status);

            string remoteFile = (folderURL + "/" + kv.Key.Substring(1));

            Directory.CreateDirectory(Path.GetDirectoryName(gameFilePath));
            if (File.Exists(gameFilePath))
            {
                UpdateLog.WriteLine(Util.GetShortTimeString() + "File exist, deleting old file");
                File.Delete(gameFilePath);
            }

            try
            {
                webClient.DownloadFileAsync(new Uri(remoteFile), gameFilePath, status);
            }
            catch (Exception e)
            {
                MessageBoxResult AlertBox = System.Windows.MessageBox.Show("new file not found");
                UpdateLog.WriteLine(Util.GetShortTimeString() + "Failed Downloading file: " + kv.Key + "with message : " + e.Message);
                backgroundWorker.CancelAsync();
            }

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

            string ManifestURL = Launcher.MainPageURL.AbsoluteUri + Launcher.ManifestName;

            WebClient webClient = new WebClient();

            webClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
            webClient.DownloadProgressChanged += webClient_DownloadProgressChanged;
            webClient.DownloadFileCompleted   += webClient_DownloadFileCompleted;

            string           manifest          = webClient.DownloadString(ManifestURL);
            LauncherManifest RemoteManifest    = JsonConvert.DeserializeObject <LauncherManifest>(manifest);
            string           UrlToDownloadGame = Properties.Settings.Default.GameUrl;

            if (Launcher.isExperimental)
            {
                try
                {
                    string           XPManifestURL = Launcher.MainPageURL.AbsoluteUri + Launcher.XPManifestName;
                    string           XPmanifest    = webClient.DownloadString(XPManifestURL);
                    LauncherManifest XPManifest    = JsonConvert.DeserializeObject <LauncherManifest>(XPmanifest);

                    //RemoteManifest = Util.CleanManifestWithOptions(RemoteManifest, XPManifest); //cleaning the manifest hash consequently
                    RemoteManifest    = XPManifest;
                    UrlToDownloadGame = Properties.Settings.Default.NsXpURL;
                }
                catch
                {
                    MessageBoxResult AlertBox = System.Windows.MessageBox.Show("Couldn't find the experimental manifest online, downloading normal version instead"
                                                                               , "Alert", MessageBoxButton.OK, MessageBoxImage.Exclamation); //not true anymore
                    RemoteManifest    = JsonConvert.DeserializeObject <LauncherManifest>(manifest);
                    UrlToDownloadGame = Properties.Settings.Default.GameUrl;
                }
            }

            LauncherManifest IgnoreManifest = Util.GetIgnoreManifest(IsVerification); //attention, might not exist, if so it has to be downloaded, if not let's use it !

            string gameInstallDir = Launcher.NSFolder;

            UpdateLog.WriteLine(Util.GetShortTimeString() + "Install Directory located in : " + gameInstallDir);
            UpdateLog.WriteLine(Util.GetShortTimeString() + "Is Experimental : " + Launcher.isExperimental.ToString());
            UpdateLog.WriteLine(Util.GetShortTimeString() + "Distant Manifest located at : " + ManifestURL);

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

            UpdateLog.WriteLine(Util.GetShortTimeString() + "Total file to update : " + totalFiles);

            int curFile = 0;

            // Update the standard files
            foreach (KeyValuePair <string, string> kv in RemoteManifest.Files)
            {
                bool   ShouldDownload = false;
                string gameFilePath   = gameInstallDir + kv.Key.Replace("/", Path.DirectorySeparatorChar.ToString());
                IgnoreManifest.Files.TryGetValue(kv.Key, out string IgnoreValue);                                                                 //get the ignore file value in manifest ("0" ignore only verif, "1" ignore verif + update)

                bool Condition1 = File.Exists(gameFilePath) && IgnoreManifest.Files.ContainsKey(kv.Key) == false;                                 //if the file exists and not in the ignore manifest, let's have it !
                bool Condition2 = File.Exists(gameFilePath) && IgnoreManifest.Files.ContainsKey(kv.Key) && IgnoreValue == "0" && !IsVerification; //if the file exists, is in the ignore manifest, but is updatable and... it's update time !

                if (Condition1 || Condition2)
                {
                    int progress = (int)(((float)curFile / (float)totalFiles) * 100);
                    backgroundWorker.ReportProgress(progress, "(" + (curFile) + " / " + totalFiles + ") Checking " + kv.Key);

                    //Check its md5 hash
                    using (var stream = File.OpenRead(gameFilePath))
                    {
                        var hash = Util.ComputeMD5(gameFilePath);

                        if (hash != kv.Value)
                        {
                            UpdateLog.WriteLine(Util.GetShortTimeString() + gameFilePath + " needs to be updated");
                            ShouldDownload = true;
                        }
                    }
                }
                if (!File.Exists(gameFilePath))
                {
                    UpdateLog.WriteLine(Util.GetShortTimeString() + gameFilePath + " not existing, needs downloading");
                    ShouldDownload = true;
                }
                if (File.Exists(gameFilePath) && Launcher.keepCustomFiles && (kv.Key.EndsWith(".wav") || kv.Key.EndsWith(".mp3") || kv.Key.EndsWith(".spr") || kv.Key.EndsWith(".tga")))
                {
                    UpdateLog.WriteLine(Util.GetShortTimeString() + gameFilePath + " Keeping custom files");
                    ShouldDownload = false;
                }
                if (File.Exists(gameFilePath) && IgnoreManifest.Files.ContainsKey(kv.Key) && IgnoreValue == "1") // ignore everything
                {
                    UpdateLog.WriteLine(Util.GetShortTimeString() + gameFilePath + " Is Ignored for update, not checking");
                    ShouldDownload = false;
                }
                if (File.Exists(gameFilePath) && IgnoreManifest.Files.ContainsKey(kv.Key) && IsVerification && IgnoreValue == "0") //if we need to ignore update and it's verification, we ignore !
                {
                    UpdateLog.WriteLine(Util.GetShortTimeString() + gameFilePath + " Is Ignored for verifications, not checking");
                    ShouldDownload = false;
                }


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

                    var hash = Util.ComputeMD5(gameFilePath);

                    if (hash != kv.Value)
                    {
                        //MessageBox.Show("Failed Validating " + kv.Key + " : Redownloading"); //problem with double validation, is it too soon in the chain of event ?
                        UpdateLog.WriteLine(Util.GetShortTimeString() + "failed to verify newly downloaded file, redownloading");
                        DownloadFile(curFile, totalFiles, kv, RemoteManifest, gameFilePath, UrlToDownloadGame, webClient);
                    }
                    UpdateLog.WriteLine(Util.GetShortTimeString() + "Download complete for file: " + kv.Key + " with new hash :" + hash + " for manifest hash : " + kv.Value);
                }
                if (backgroundWorker.CancellationPending)
                {
                    UpdateLog.WriteLine(Util.GetShortTimeString() + "Update cancelled");
                    return;
                }

                curFile++;
            }

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

            /* string manifestDirectory = Launcher.curDir + Path.DirectorySeparatorChar + Launcher.ManifestName;
             *
             * File.WriteAllText(manifestDirectory, manifest); // replace all with function in util */
        }