Esempio n. 1
0
        public void DoModNetJob()
        {
            /* Disable Any Buttons */
            ServerDropDownList.Enabled = false;
            ButtonLogin.Enabled        = false;
            ButtonRegister.Enabled     = false;
            ForgotPassLink.Enabled     = false;

            if (Directory.Exists("modules"))
            {
                Directory.Delete("modules", true);
            }
            if (!Directory.Exists("scripts"))
            {
                Directory.CreateDirectory("scripts");
            }

            String[] RemoveAllFiles = new string[] { "modules/udpcrc.soapbox.module", "modules/udpcrypt1.soapbox.module", "modules/udpcrypt2.soapbox.module",
                                                     "modules/xmppsubject.soapbox.module", "scripts/global.ini", "lightfx.dll", "PocoFoundation.dll", "PocoNet.dll", "ModManager.dat" };

            foreach (string file in RemoveAllFiles)
            {
                if (File.Exists(file))
                {
                    try {
                        File.Delete(file);
                    } catch {
                        MessageBox.Show($"File {file} cannot be deleted.", "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }

            String jsonModNet = ModNetReloaded.ModNetSupported(ServerDropDownList.SelectedValue.ToString());

            if (jsonModNet != String.Empty)
            {
                actionText.Text = "Detecting ModNetSupport for " + ServerDropDownList.SelectedItem.ToString();

                try
                {
                    try { if (File.Exists("lightfx.dll"))
                          {
                              File.Delete("lightfx.dll");
                          }
                    } catch { }

                    /* Get Remote ModNet list to process for checking required ModNet files are present and current */
                    String   modules          = new WebClient().DownloadString(URLs.modnetserver + "/launcher-modules/modules.json");
                    string[] modules_newlines = modules.Split(new string[] { "\n" }, StringSplitOptions.None);

                    foreach (String modules_newline in modules_newlines)
                    {
                        if (modules_newline.Trim() == "{" || modules_newline.Trim() == "}")
                        {
                            continue;
                        }

                        String   trim_modules_newline = modules_newline.Trim();
                        String[] modules_files        = trim_modules_newline.Split(new char[] { ':' });

                        String ModNetList = modules_files[0].Replace("\"", "").Trim();
                        String ModNetSHA  = modules_files[1].Replace("\"", "").Replace(",", "").Trim();

                        if (SHATwoFiveSix.HashFile(AppDomain.CurrentDomain.BaseDirectory + "\\" + ModNetList).ToLower() != ModNetSHA || !File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\" + ModNetList))
                        {
                            actionText.Text = ("ModNet: Downloading " + ModNetList).ToUpper();

                            if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\" + ModNetList))
                            {
                                File.Delete(AppDomain.CurrentDomain.BaseDirectory + "\\" + ModNetList);
                            }

                            WebClient newModNetFilesDownload = new WebClient();
                            newModNetFilesDownload.DownloadFile(URLs.modnetserver + "/launcher-modules/" + ModNetList, AppDomain.CurrentDomain.BaseDirectory + "/" + ModNetList);
                        }
                        else
                        {
                            actionText.Text = ("ModNet: Up to Date " + ModNetList).ToUpper();
                        }

                        Application.DoEvents();
                    }

                    JSONNode MainJson = JSON.Parse(jsonModNet);

                    Uri    newIndexFile = new Uri(MainJson["basePath"] + "/index.json");
                    String jsonindex    = new WebClient().DownloadString(newIndexFile);

                    JSONNode IndexJson = JSON.Parse(jsonindex);


                    String path = Path.Combine("MODS", MDFive.HashPassword(MainJson["serverID"]).ToLower());
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    /* new */
                    foreach (JSONNode modfile in IndexJson["entries"])
                    {
                        if (SHA.HashFile(path + "/" + modfile["Name"]).ToLower() != modfile["Checksum"])
                        {
                            modFilesDownloadUrls.Enqueue(new Uri(MainJson["basePath"] + "/" + modfile["Name"]));
                            TotalModFileCount++;

                            if (File.Exists(path + "/" + modfile["Name"]))
                            {
                                File.Delete(path + "/" + modfile["Name"]);
                            }
                        }
                    }

                    if (modFilesDownloadUrls.Count != 0)
                    {
                        this.DownloadModNetFilesRightNow(path);
                    }
                    else
                    {
                        actionText.Text = "Launching game...";
                        LaunchGame();
                    }
                } catch (Exception ex) {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                //Yikes from me Coders - DavidCarbon
                actionText.Text = "Launching game...";
                LaunchGame();
            }
        }
Esempio n. 2
0
        public void DoModNetJob()
        {
            File.Delete("ModManager.dat");

            if (!Directory.Exists("modules"))
            {
                Directory.CreateDirectory("modules");
            }
            if (!Directory.Exists("scripts"))
            {
                Directory.CreateDirectory("scripts");
            }
            String[] GlobalFiles         = new string[] { "dinput8.dll", "global.ini" };
            String[] ModNetReloadedFiles = new string[] { "7z.dll", "PocoFoundation.dll", "PocoNet.dll", "ModLoader.asi" };
            String[] ModNetLegacyFiles   = new string[] { "modules/udpcrc.soapbox.module", "modules/udpcrypt1.soapbox.module", "modules/udpcrypt2.soapbox.module", "modules/xmppsubject.soapbox.module",
                                                          "scripts/global.ini", "lightfx.dll", "ModManager.asi", "global.ini" };

            String[] RemoveAllFiles = GlobalFiles.Concat(ModNetReloadedFiles).Concat(ModNetLegacyFiles).ToArray();

            foreach (string file in RemoveAllFiles)
            {
                if (File.Exists(file))
                {
                    try {
                        File.Delete(file);
                    } catch {
                        MessageBox.Show($"File {file} cannot be deleted.", "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }

            actionText.Text = "Detecting ModNetSupport for " + serverText.SelectedItem.ToString();
            String jsonModNet = ModNetReloaded.ModNetSupported(serverText.SelectedValue.ToString());

            if (jsonModNet != String.Empty)
            {
                actionText.Text = "ModNetReloaded support detected, downloading required files...";

                string[] newFiles = GlobalFiles.Concat(ModNetReloadedFiles).ToArray();
                try {
                    try { if (File.Exists("lightfx.dll"))
                          {
                              File.Delete("lightfx.dll");
                          }
                    } catch { }

                    WebClientWithTimeout newModNetFilesDownload = new WebClientWithTimeout();
                    foreach (string file in newFiles)
                    {
                        actionText.Text = "Fetching ModNetReloaded Files: " + file;
                        Application.DoEvents();
                        newModNetFilesDownload.DownloadFile("https://cdn.soapboxrace.world/modules/" + file, file);
                    }

                    try {
                        newModNetFilesDownload.DownloadFile("https://launcher.worldunited.gg/legacy/global.ini", "global.ini");
                    }
                    catch { }

                    SimpleJSON.JSONNode MainJson = SimpleJSON.JSON.Parse(jsonModNet);

                    Uri    newIndexFile = new Uri(MainJson["basePath"] + "/index.json");
                    String jsonindex    = new WebClientWithTimeout().DownloadString(newIndexFile);

                    SimpleJSON.JSONNode IndexJson = SimpleJSON.JSON.Parse(jsonindex);

                    CountFilesTotal = IndexJson["entries"].Count;

                    String path = Path.Combine("MODS", MDFive.HashPassword(MainJson["serverID"]).ToLower());
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    foreach (JSONNode modfile in IndexJson["entries"])
                    {
                        if (SHA.HashFile(path + "/" + modfile["Name"]).ToLower() != modfile["Checksum"])
                        {
                            WebClientWithTimeout client2 = new WebClientWithTimeout();
                            client2.DownloadFileAsync(new Uri(MainJson["basePath"] + "/" + modfile["Name"]), path + "/" + modfile["Name"]);

                            client2.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
                            client2.DownloadFileCompleted   += (test, stuff) => {
                                if (SHA.HashFile(path + "/" + modfile["Name"]).ToLower() == modfile["Checksum"])
                                {
                                    CountFiles++;

                                    if (CountFiles == CountFilesTotal)
                                    {
                                        launchGame();
                                    }
                                }
                                else
                                {
                                    File.Delete(path + "/" + modfile["Name"]);
                                    Console.WriteLine(modfile["Name"] + " must be removed.");
                                    DoModNetJob();
                                }
                            };
                        }
                        else
                        {
                            CountFiles++;

                            if (CountFiles == CountFilesTotal)
                            {
                                launchGame();
                            }
                        }
                    }
                } catch (Exception ex) {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                string[] newFiles = GlobalFiles.Concat(ModNetLegacyFiles).ToArray();

                WebClientWithTimeout newModNetFilesDownload = new WebClientWithTimeout();
                foreach (string file in newFiles)
                {
                    actionText.Text = "Fetching LegacyModnet Files: " + file;
                    Application.DoEvents();
                    newModNetFilesDownload.DownloadFile("http://launcher.worldunited.gg/legacy/" + file, file);
                }

                if (result["modsUrl"] != null)
                {
                    actionText.Text = "Electron support detected, checking mods...";

                    Uri    newIndexFile           = new Uri(result["modsUrl"] + "/index.json");
                    String jsonindex              = new WebClientWithTimeout().DownloadString(newIndexFile);
                    SimpleJSON.JSONNode IndexJson = SimpleJSON.JSON.Parse(jsonindex);

                    CountFilesTotal = IndexJson.Count;

                    String electronpath = (new Uri(serverText.SelectedValue.ToString()).Host).Replace(".", "-");
                    String path         = Path.Combine("MODS", electronpath);
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    File.WriteAllText(path + ".json", jsonindex);

                    using (var fs = new FileStream("ModManager.dat", FileMode.Create))
                        using (var bw = new BinaryWriter(fs)) {
                            bw.Write(CountFilesTotal);

                            foreach (JSONNode file in IndexJson)
                            {
                                var originalPath = Path.Combine(file["file"]).Replace("/", "\\").ToUpper();
                                var modPath      = Path.Combine(path, file["file"]).Replace("/", "\\").ToUpper();

                                bw.Write(originalPath.Length);
                                bw.Write(originalPath.ToCharArray());
                                bw.Write(modPath.Length);
                                bw.Write(modPath.ToCharArray());
                            }
                        }

                    foreach (JSONNode modfile in IndexJson)
                    {
                        String directorycreate = Path.GetDirectoryName(path + "/" + modfile["file"]);
                        Directory.CreateDirectory(directorycreate);

                        if (ElectronModNet.calculateHash(path + "/" + modfile["file"]) != modfile["hash"])
                        {
                            WebClientWithTimeout client2 = new WebClientWithTimeout();
                            client2.DownloadFileAsync(new Uri(result["modsUrl"] + "/" + modfile["file"]), path + "/" + modfile["file"]);

                            client2.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
                            client2.DownloadFileCompleted   += (test, stuff) => {
                                if (ElectronModNet.calculateHash(path + "/" + modfile["file"]) == modfile["hash"])
                                {
                                    CountFiles++;

                                    if (CountFiles == CountFilesTotal)
                                    {
                                        launchGame();
                                    }
                                }
                                else
                                {
                                    File.Delete(path + "/" + modfile["file"]);
                                    Console.WriteLine(modfile["file"] + " must be removed.");
                                    DoModNetJob();
                                }
                            };
                        }
                        else
                        {
                            CountFiles++;

                            if (CountFiles == CountFilesTotal)
                            {
                                launchGame();
                            }
                        }
                    }
                }
                else if ((bool)result["rwacallow"] == true)
                {
                    actionText.Text = "RWAC support detected, checking mods...";

                    String rwacpath   = MDFive.HashPassword(new Uri(serverText.SelectedValue.ToString()).Host);
                    String path       = Path.Combine("MODS", rwacpath);
                    Uri    rwac_wev2  = new Uri(result["homePageUrl"] + "/rwac/fileschecker_sbrw.xml");
                    String getcontent = new WebClient().DownloadString(rwac_wev2);

                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml(getcontent);
                    var nodes = xmlDoc.SelectNodes("rwac/files/file");

                    CountFilesTotal = nodes.Count;

                    //ModManager.dat
                    using (var fs = new FileStream("ModManager.dat", FileMode.Create))
                        using (var bw = new BinaryWriter(fs)) {
                            bw.Write(nodes.Count);

                            foreach (XmlNode files in nodes)
                            {
                                string realfilepath    = Path.Combine(files.Attributes["path"].Value, files.Attributes["name"].Value);
                                String directorycreate = Path.GetDirectoryName(path + "/" + realfilepath);

                                var originalPath = Path.Combine(realfilepath).Replace("/", "\\").ToUpper();
                                var modPath      = Path.Combine(path, realfilepath).Replace("/", "\\").ToUpper();

                                bw.Write(originalPath.Length);
                                bw.Write(originalPath.ToCharArray());
                                bw.Write(modPath.Length);
                                bw.Write(modPath.ToCharArray());

                                Directory.CreateDirectory(directorycreate);
                                if (files.Attributes["download"].Value != String.Empty)
                                {
                                    if (MDFive.HashFile(path + "/" + realfilepath).ToLower() != files.InnerText)
                                    {
                                        WebClientWithTimeout client2 = new WebClientWithTimeout();
                                        client2.DownloadFileAsync(new Uri(files.Attributes["download"].Value), path + "/" + realfilepath);

                                        client2.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
                                        client2.DownloadFileCompleted   += (test, stuff) => {
                                            if (MDFive.HashFile(path + "/" + realfilepath).ToLower() == files.InnerText)
                                            {
                                                CountFiles++;

                                                if (CountFiles == CountFilesTotal)
                                                {
                                                    launchGame();
                                                }
                                            }
                                            else
                                            {
                                                File.Delete(path + "/" + realfilepath);
                                                Console.WriteLine(realfilepath + " must be removed.");
                                                DoModNetJob();
                                            }
                                        };
                                    }
                                    else
                                    {
                                        CountFiles++;

                                        if (CountFiles == CountFilesTotal)
                                        {
                                            launchGame();
                                        }
                                    }
                                }
                                else
                                {
                                    CountFiles++;

                                    if (CountFiles == CountFilesTotal)
                                    {
                                        launchGame();
                                    }
                                }
                            }
                        }
                }
                else
                {
                    actionText.Text = "Deprecated modnet detected. Aborting...";
                    launchGame();
                }
            }
        }