示例#1
0
        private void onlineUsers_Tick(object sender, EventArgs e)
        {
            WebClient client      = new WebClient();
            int       usersOnline = 0;

            Debug.WriteLine("Getting Tick");
            try
            {
                string stringnumber = client.DownloadString(String.Format("http://tonic.pw/files/bnsmultitool/usersOnline.php?UID={0}", SystemConfig.SYS.FINGERPRINT));
                if (!(int.TryParse(stringnumber, out usersOnline)))
                {
                    usersOnline = 0;
                }
            }
            catch (WebException ex)
            {
                Debug.WriteLine(ex.Message);
            }
            finally
            {
                client.Dispose();
            }

            Dispatchers.labelContent(usersOnlineLbl, String.Format("Users Online: {0}", (usersOnline != 0) ? usersOnline.ToString() : "Error"));
        }
        private void refreshSomeShit()
        {
            //Get the file info and display version for pluginloader
            pluginloader = new pluginFileInfo(SystemConfig.SYS.BNS_DIR + @"\bin\" + "winmm.dll");
            Dispatchers.labelContent(pluginloaderLabel, String.Format("Current: {0}", (pluginloader != null) ? pluginloader.modificationTime.ToString("MM-dd-yy") : "Not Installed"));

            bnspatchPlugin = new pluginFileInfo(SystemConfig.SYS.BNS_DIR + plugins_x86 + "bnspatch.dll");
            Dispatchers.labelContent(bnspatchLabel, String.Format("Current: {0}", (bnspatchPlugin != null) ? bnspatchPlugin.modificationTime.ToString("MM-dd-yy") : "Not Installed"));
        }
示例#3
0
        private async Task checkOnlineVersion()
        {
            loginhelperPlugin = null;
            if (loginHelper_installed)
            {
                loginhelperPlugin = new Modpolice.pluginFileInfo(Path.Combine(plugins_x86, "loginhelper.dll"));
            }

            charselectPlugin = null;
            if (charselect_installed)
            {
                charselectPlugin = new Modpolice.pluginFileInfo(Path.Combine(plugins_x86, "charselect.dll"));
            }

            //Hotfix for missing use-ingame-login.xml
            if (loginHelper_installed && !File.Exists(login_xml))
            {
                File.WriteAllText(login_xml, Properties.Resources.use_ingame_login);
            }

            Dispatchers.labelContent(loginhelperLocalLbl, String.Format("Current: {0}", (loginhelperPlugin != null) ? loginhelperPlugin.modificationTime.ToString("MM-dd-yy") : "Not Installed"));
            Dispatchers.labelContent(charSelectLocalLbl, String.Format("Current: {0}", (charselectPlugin != null) ? charselectPlugin.modificationTime.ToString("MM-dd-yy") : "Not Installed"));

            try
            {
                var client = new MegaApiClient();
                await client.LoginAnonymousAsync();

                if (!client.IsLoggedIn)
                {
                    throw new Exception("Timed out"); //Throw exception for not logging in anonymously
                }
                IEnumerable <INode> nodes = await client.GetNodesFromLinkAsync(new Uri("https://mega.nz/folder/4EUF2IhL#Ci1Y-sbbyw7nwwMGvHV2_w"));

                INode loginhelper_node = nodes.Where(x => x.Type == NodeType.File && x.Name.Contains("loginhelper")).OrderByDescending(t => t.ModificationDate).FirstOrDefault();
                INode charselect_node  = nodes.Where(x => x.Type == NodeType.File && x.Name.Contains("charselect")).OrderByDescending(t => t.ModificationDate).FirstOrDefault();

                if (loginhelper_node != null)
                {
                    Dispatchers.labelContent(loginhelperOnlineLbl, String.Format("Online: {0}", loginhelper_node.ModificationDate.Value.ToString("MM-dd-yy")));
                }

                if (charselect_node != null)
                {
                    Dispatchers.labelContent(charSelectOnlineLbl, String.Format("Online: {0}", charselect_node.ModificationDate.Value.ToString("MM-dd-yy")));
                }
            }
            catch (Exception ex)
            {
                Dispatchers.labelContent(loginhelperOnlineLbl, ex.Message == "Timed out" ? "Online: " + ex.Message : "Online: Error!");
                Dispatchers.labelContent(charSelectOnlineLbl, ex.Message == "Timed out" ? "Online: " + ex.Message : "Online: Error!");
            }
        }
示例#4
0
        private static void checkForUpdate()
        {
            WebClient client = new WebClient();

            try
            {
                var json = client.DownloadString("http://tonic.pw/files/bnsmultitool/version.json");
                onlineJson = JsonConvert.DeserializeObject <MainWindow.ONLINE_VERSION_STRUCT>(json);

                if (onlineJson.VERSION != MainWindow.FileVersion())
                {
                    Application.Current.Dispatcher.BeginInvoke((Action) delegate
                    {
                        var dialog = new ErrorPrompt("Update available, please be sure to read the change log for any critical changes.\r\rOnline Version: " + onlineJson.VERSION + "\rLocal: " + SystemConfig.SYS.VERSION, true);
                        dialog.ShowDialog();
                    });

                    SystemConfig.SYS.VERSION = MainWindow.FileVersion();
                    SystemConfig.appendChangesToConfig();

                    Dispatchers.buttonVisibility(MainWindow.UpdateButtonObj, Visibility.Visible);
                }
            } catch (WebException ex)
            {
                onlineJson           = new MainWindow.ONLINE_VERSION_STRUCT();
                onlineJson.CHANGELOG = new List <MainWindow.CHANGELOG_STRUCT>();
                onlineJson.CHANGELOG.Add(new MainWindow.CHANGELOG_STRUCT()
                {
                    VERSION = "ERROR", NOTES = ex.Message
                });
            }
            finally
            {
                client.Dispose();
            }
        }
        private void PatchGame(object sender, DoWorkEventArgs e)
        {
            string FileInfoStr  = ((Globals.BnS_Region)ACCOUNT_CONFIG.ACCOUNTS.REGION == Globals.BnS_Region.KR) ? "FileInfoMap_BNS_KOR.dat" : "FileInfoMap_BnS.dat";
            string PatchInfoStr = ((Globals.BnS_Region)ACCOUNT_CONFIG.ACCOUNTS.REGION == Globals.BnS_Region.KR) ? "PatchFileInfo_BNS_KOR.dat" : "PatchFileInfo_BnS.dat";

            string FileInfoMap_URL = String.Format(@"{0}{1}/Patch/{2}_{1}.dat.zip", BASE_URL, onlineVersion, FileInfoStr.Substring(0, FileInfoStr.Length - 4));
            string PatchInfo_URL   = String.Format(@"{0}{1}/Patch/{2}_{1}.dat.zip", BASE_URL, onlineVersion, PatchInfoStr.Substring(0, PatchInfoStr.Length - 4));

            totalBytes   = 0L;
            currentBytes = 0L;

            //We'll need this later
            string[] effectandanimations;
            effectandanimations = SystemConfig.SYS.CLASSES.SelectMany(entries => entries.ANIMATIONS).ToArray();
            effectandanimations = effectandanimations.Concat(SystemConfig.SYS.CLASSES.SelectMany(entries => entries.EFFECTS)).ToArray();
            effectandanimations = effectandanimations.Concat(SystemConfig.SYS.MAIN_UPKS).ToArray();

            BnSInfoMap = new List <BnSFileInfo>();

            //We need to make sure the version difference is not greater than 1, if it is that's a whole mess I can't be bothered to code.
            bool canDeltaPatch = ((int.Parse(onlineVersion) - int.Parse(localVersion)) < 2) && SystemConfig.SYS.DELTA_PATCHING == 1 && onlineVersion != localVersion;

            if (canDeltaPatch)
            {
                DltPLbl.Dispatcher.BeginInvoke(new Action(() => { DltPLbl.Visibility = Visibility.Visible; }));
            }
            else
            {
                DltPLbl.Dispatcher.BeginInvoke(new Action(() => { DltPLbl.Visibility = Visibility.Hidden; }));
            }
            try
            {
                if (!RemoteFileExists(PatchInfo_URL))
                {
                    throw new Exception("Patch: " + onlineVersion + " does not exist");
                }

                //Check if our patch manager directory exists, if not create it.
                if (!Directory.Exists(BNS_PATH + @"PatchManager\" + onlineVersion))
                {
                    Directory.CreateDirectory(BNS_PATH + @"PatchManager\" + onlineVersion);
                }

                Dispatchers.textBlock(ProgressBlock, "Fetching FileInfoMap_BnS_" + onlineVersion + ".dat");
                if (!DownloadContents(FileInfoMap_URL, Path.Combine(BNS_PATH, "PatchManager", onlineVersion, FileInfoStr + ".zip")))
                {
                    throw new Exception("Failed to download FileInfoMap_BnS.dat.zip");
                }

                Dispatchers.textBlock(ProgressBlock, "Fetching PatchFileInfo_BnS_" + onlineVersion + ".dat");
                if (!DownloadContents(PatchInfo_URL, Path.Combine(BNS_PATH, "PatchManager", onlineVersion, PatchInfoStr + ".zip")))
                {
                    throw new Exception("Failed to downlooad PatchFileInfo_BnS.dat.zip");
                }

                Dispatchers.textBlock(ProgressBlock, "Decompressing file maps");
                DecompressFileLZMA(Path.Combine(BNS_PATH, "PatchManager", onlineVersion, FileInfoStr + ".zip"), Path.Combine(BNS_PATH, "PatchManager", onlineVersion, FileInfoStr));
                DecompressFileLZMA(Path.Combine(BNS_PATH, "PatchManager", onlineVersion, PatchInfoStr + ".zip"), Path.Combine(BNS_PATH, "PatchManager", onlineVersion, PatchInfoStr));

                Dispatchers.textBlock(ProgressBlock, String.Format("Parsing {0}", (SystemConfig.SYS.DELTA_PATCHING == 1) ? "PatchFileInfo" : "FileMapInfo"));
                Thread.Sleep(100);

                string configDat = (canDeltaPatch) ? PatchInfoStr : FileInfoStr;

                List <string> InfoMapLines   = File.ReadLines(Path.Combine(BNS_PATH, "PatchManager", onlineVersion, configDat)).ToList <string>();
                int           totalFiles     = InfoMapLines.Count <string>();
                int           processedFiles = 0;
                //long totalBytes = 0L;
                int threadCount = SystemConfig.SYS.UPDATER_THREADS + 4;

                Parallel.ForEach <string>(InfoMapLines, new ParallelOptions {
                    MaxDegreeOfParallelism = threadCount
                }, delegate(string line)
                {
                    string[] lineData = line.Split(new char[] { ':' });
                    string FilePath   = lineData[0];
                    string FileSize   = lineData[1];
                    string FileHash   = lineData[2];
                    string FileFlag   = lineData[3];
                    string currentFilePath;
                    if (canDeltaPatch)
                    {
                        currentFilePath = FilePath.Substring(4, FilePath.Contains(".dlt") ? FilePath.Length - 12 : FilePath.Length - 8);
                    }
                    else
                    {
                        currentFilePath = FilePath;
                    }

                    FileInfo fInfo = new FileInfo(Path.Combine(BNS_PATH, currentFilePath));

                    //Check if the file is an animation or effect animation and reset the path if it is so they're updated.
                    if (!fInfo.Exists && effectandanimations.Contains(Path.GetFileName(currentFilePath)))
                    {
                        currentFilePath = String.Format(@"contents\bns\backup\{0}", Path.GetFileName(currentFilePath));
                        fInfo           = new FileInfo(Path.Combine(BNS_PATH, currentFilePath));
                    }

                    if (canDeltaPatch)
                    {
                        //Various checks to verify that local.dat is the original and not a modified dat.
                        if (Path.GetFileName(currentFilePath).Contains("local") && fInfo.Length < 5000000)
                        {
                            FilePath = Path.Combine("Zip", FilePath.Substring(4, FilePath.Length - 4));
                            FileFlag = "5";
                        }

                        if (FileFlag == "3")
                        {
                            if (!Directory.Exists(Path.GetDirectoryName(Path.Combine(BNS_PATH, "PatchManager", onlineVersion, FilePath))))
                            {
                                Directory.CreateDirectory(Path.GetDirectoryName(Path.Combine(BNS_PATH, "PatchManager", onlineVersion, FilePath)));
                            }

                            if (fInfo.Exists)
                            {
                                BnSInfoMap.Add(new BnSFileInfo()
                                {
                                    path = FilePath, size = FileSize, hash = FileHash, flag = FileFlag
                                });
                                Interlocked.Add(ref totalBytes, long.Parse(FileSize));
                            }
                        }
                        else if (FileFlag == "5")
                        {
                            if (!Directory.Exists(Path.GetDirectoryName(Path.Combine(BNS_PATH, "PatchManager", onlineVersion, FilePath))))
                            {
                                Directory.CreateDirectory(Path.GetDirectoryName(Path.Combine(BNS_PATH, "PatchManager", onlineVersion, FilePath)));
                            }

                            BnSInfoMap.Add(new BnSFileInfo()
                            {
                                path = FilePath, size = FileSize, hash = FileHash, flag = FileFlag
                            });
                            Interlocked.Add(ref totalBytes, long.Parse(FileSize));
                        }
                    }
                    else
                    {
                        //This section (Non-Delta-Patching) acts more of a file repair than an actual game updater / patcher.
                        if (fInfo.Exists)
                        {
                            if (!Directory.Exists(Path.GetDirectoryName(Path.Combine(BNS_PATH, "PatchManager", onlineVersion, FilePath))))
                            {
                                Directory.CreateDirectory(Path.GetDirectoryName(Path.Combine(BNS_PATH, "PatchManager", onlineVersion, FilePath)));
                            }

                            //Make sure the directory is not the web font directory, for whatever reason this is read-only
                            if (!FilePath.Contains(@"\web"))
                            {
                                if (fInfo.Length.ToString() != FileSize)
                                {
                                    BnSInfoMap.Add(new BnSFileInfo()
                                    {
                                        path = FilePath, size = FileSize, hash = FileHash, flag = FileFlag
                                    });
                                    Interlocked.Add(ref totalBytes, long.Parse(FileSize));
                                }
                                else if (FileHash != SHA1HASH(Path.Combine(BNS_PATH, currentFilePath)))
                                {
                                    BnSInfoMap.Add(new BnSFileInfo()
                                    {
                                        path = FilePath, size = FileSize, hash = FileHash, flag = FileFlag
                                    });
                                    Interlocked.Add(ref totalBytes, long.Parse(FileSize));
                                }
                            }
                        }
                        else
                        {
                            BnSInfoMap.Add(new BnSFileInfo()
                            {
                                path = FilePath, size = FileSize, hash = FileHash, flag = FileFlag
                            });
                            Interlocked.Add(ref totalBytes, long.Parse(FileSize));
                        }
                    }

                    Interlocked.Increment(ref processedFiles);
                    if (!canDeltaPatch)
                    {
                        FilesProcessed((int)((double)processedFiles / totalFiles * 100));
                        Dispatchers.textBlock(ProgressBlock, String.Format("{0} / {1} Scanned", processedFiles, totalFiles));
                    }
                });

                Debug.WriteLine(String.Format("Download Size: {0} ({1}) files", SizeSuffix(totalBytes, 2), BnSInfoMap.Count()));
                Dispatchers.textBlock(ProgressBlock, String.Format("Download Size: {0} ({1}) files", SizeSuffix(totalBytes, 2), BnSInfoMap.Count()));

                totalFiles     = BnSInfoMap.Count();
                processedFiles = 0;
                PatchingLabel.Dispatcher.BeginInvoke(new Action(() => { PatchingLabel.Visibility = Visibility.Visible; }));

                FilesProcessed(0);

                Dispatchers.labelContent(PatchingLabel, "Downloading...");

                Parallel.ForEach <BnSFileInfo>(BnSInfoMap, new ParallelOptions {
                    MaxDegreeOfParallelism = threadCount
                }, delegate(BnSFileInfo file)
                {
                    string fpath = Path.Combine(BNS_PATH, "PatchManager", onlineVersion, file.path);
                    if (!canDeltaPatch)
                    {
                        fpath += ".zip";
                    }

                    string currentFilePath;
                    if (canDeltaPatch)
                    {
                        currentFilePath = file.path.Substring(4, file.path.Contains(".dlt") ? file.path.Length - 12 : file.path.Length - 8);
                    }
                    else
                    {
                        currentFilePath = file.path;
                    }

                    FileInfo fInfo = new FileInfo(Path.Combine(BNS_PATH, currentFilePath));
                    if (!fInfo.Exists && effectandanimations.Contains(Path.GetFileName(currentFilePath)))
                    {
                        currentFilePath = (File.Exists(Path.Combine(BNS_PATH, String.Format(@"contents\bns\backup\{0}", Path.GetFileName(currentFilePath))))) ? String.Format(@"contents\bns\backup\{0}", Path.GetFileName(currentFilePath)) : currentFilePath;

                        if (File.Exists(Path.Combine(BNS_PATH, currentFilePath)))
                        {
                            fInfo = new FileInfo(Path.Combine(BNS_PATH, currentFilePath));
                        }
                    }

                    try
                    {
                        if (File.Exists(fpath))
                        {
                            File.Delete(fpath);
                        }

                        downloadComplete = new TaskCompletionSource <bool>();
                        if (DownloadContents(String.Format(@"{0}{1}/Patch/{2}", BASE_URL, onlineVersion, (canDeltaPatch) ? file.path : @"/Zip/" + file.path + ".zip"), fpath))
                        {
                            processedFiles++;
                        }

                        Debug.WriteLine("{0}", file.path);
                        FilesProcessed((int)((double)processedFiles / totalFiles * 100));
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                });

                bool taskIsDone = false;
                //Create a task
                Task.Run(new Action(async() =>
                {
                    FilesProcessed(0);
                    processedFiles = 0;
                    await Task.Delay(1000);

                    Dispatchers.labelContent(PatchingLabel, "Patching");

                    Parallel.ForEach <BnSFileInfo>(BnSInfoMap, new ParallelOptions {
                        MaxDegreeOfParallelism = threadCount
                    }, delegate(BnSFileInfo file)
                    {
                        string fpath = Path.Combine(BNS_PATH, "PatchManager", onlineVersion, file.path);
                        if (!canDeltaPatch)
                        {
                            fpath += ".zip";
                        }

                        string currentFilePath;
                        if (canDeltaPatch)
                        {
                            currentFilePath = file.path.Substring(4, file.path.Contains(".dlt") ? file.path.Length - 12 : file.path.Length - 8);
                        }
                        else
                        {
                            currentFilePath = file.path;
                        }

                        FileInfo fInfo = new FileInfo(Path.Combine(BNS_PATH, currentFilePath));
                        if (!fInfo.Exists && effectandanimations.Contains(Path.GetFileName(currentFilePath)))
                        {
                            currentFilePath = (File.Exists(Path.Combine(BNS_PATH, String.Format(@"contents\bns\backup\{0}", Path.GetFileName(currentFilePath))))) ? String.Format(@"contents\bns\backup\{0}", Path.GetFileName(currentFilePath)) : currentFilePath;

                            if (File.Exists(Path.Combine(BNS_PATH, currentFilePath)))
                            {
                                fInfo = new FileInfo(Path.Combine(BNS_PATH, currentFilePath));
                            }
                        }

                        //Various checks to verify that local.dat is the original and not a modified dat.
                        if (file.flag == "3" && Path.GetFileName(currentFilePath).Contains("local") && fInfo.Length < 5000000)
                        {
                            if (File.Exists(Path.Combine(Path.GetDirectoryName(currentFilePath), Path.GetFileName(currentFilePath) + ".bk")))
                            {
                                Debug.WriteLine("Local dat detected, changing to bk");
                                currentFilePath = Path.Combine(Path.GetDirectoryName(currentFilePath), Path.GetFileName(currentFilePath) + ".bk");
                                fInfo           = new FileInfo(Path.Combine(BNS_PATH, currentFilePath));
                            }
                        }

                        try
                        {
                            DecompressFileLZMA(fpath, fpath.Substring(0, fpath.Length - 4));
                            File.Delete(fpath);
                            fpath = fpath.Substring(0, fpath.Length - 4);

                            //Delta Patch
                            if (canDeltaPatch && file.flag == "3")
                            {
                                if (DeltaPatch(Path.Combine(BNS_PATH, currentFilePath), fpath))
                                {
                                    File.Delete(fpath);

                                    if (File.Exists(Path.Combine(BNS_PATH, currentFilePath)))
                                    {
                                        File.Delete(Path.Combine(BNS_PATH, currentFilePath));
                                    }

                                    File.Move(fpath.Substring(0, fpath.Length - 4), Path.Combine(BNS_PATH, currentFilePath));
                                }
                            }
                            else
                            {
                                if (fInfo.Exists)
                                {
                                    fInfo.Delete();
                                }

                                File.Move(fpath, Path.Combine(BNS_PATH, currentFilePath));
                            }
                            processedFiles++;
                            FilesProcessed((int)((double)processedFiles / totalFiles * 100));
                            Dispatchers.textBlock(ProgressBlock, String.Format("{0} ({1}%)", SizeSuffix(totalBytes, 2), (int)((double)processedFiles / totalFiles * 100)));
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.Message);
                        }
                    });

                    Dispatchers.labelContent(PatchingLabel, "Finishing up..");
                    taskIsDone = true;
                }));

                while (!taskIsDone)
                {
                    Thread.Sleep(2000);
                }

                if (File.Exists(Path.Combine(BNS_PATH, FileInfoStr)))
                {
                    File.Delete(Path.Combine(BNS_PATH, FileInfoStr));
                }

                File.Move(Path.Combine(BNS_PATH, "PatchManager", onlineVersion, FileInfoStr), Path.Combine(BNS_PATH, FileInfoStr));

                IniHandler hIni = new IniHandler(Path.Combine(SystemConfig.SYS.BNS_DIR, (Globals.BnS_Region)ACCOUNT_CONFIG.ACCOUNTS.REGION == Globals.BnS_Region.KR ? "VersionInfo_BNS_KOR.ini" : "VersionInfo_BnS.ini"));
                hIni.Write("VersionInfo", "GlobalVersion", onlineVersion);
                Directory.Delete(Path.Combine(BNS_PATH, "PatchManager", onlineVersion), true);

                //onlineVersion = "165";
            } catch (Exception ex)
            {
                Dispatchers.textBlock(ProgressBlock, ex.Message);
            }
            Thread.Sleep(2500);
        }
        private async Task checkOnlineVersions()
        {
            #region pluginloader
            if ((File.Exists(SystemConfig.SYS.BNS_DIR + @"\bin\winmm.dll") && File.Exists(SystemConfig.SYS.BNS_DIR + @"\bin64\winmm.dll")))
            {
                pluginloader = new pluginFileInfo(SystemConfig.SYS.BNS_DIR + @"\bin\winmm.dll");
            }
            else
            {
                pluginloader = null;
            }

            Dispatchers.labelContent(pluginloaderLabel, String.Format("Current: {0}", (pluginloader != null) ? pluginloader.modificationTime.ToString("MM-dd-yy") : "Not Installed"));
            #endregion

            #region bnspatch
            if ((File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x86 + "bnspatch.dll") && File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x64 + "bnspatch.dll")))
            {
                bnspatchPlugin = new pluginFileInfo(SystemConfig.SYS.BNS_DIR + plugins_x86 + "bnspatch.dll");
            }
            else
            {
                bnspatchPlugin = null;
            }

            Dispatchers.labelContent(bnspatchLabel, String.Format("Current: {0}", (bnspatchPlugin != null) ? bnspatchPlugin.modificationTime.ToString("MM-dd-yy") : "Not Installed"));
            #endregion

            #region bnsnogg
            if ((File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x86 + "bnsnogg.dll") && File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x64 + "bnsnogg.dll")))
            {
                bnsnoggPlugin = new pluginFileInfo(SystemConfig.SYS.BNS_DIR + plugins_x64 + "bnsnogg.dll");
            }
            else
            {
                bnsnoggPlugin = null;
            }

            Dispatchers.labelContent(bnsnogglocalLabel, String.Format("Current: {0}", (bnsnoggPlugin != null) ? bnsnoggPlugin.modificationTime.ToString("MM-dd-yy") : "Not Installed"));
            #endregion

            #region lessloadingscreen
            Dispatchers.btnIsEnabled(lessloadingInstall, false);
            if ((File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x86 + "lessloadingscreens.dll") && File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x64 + "lessloadingscreens.dll")))
            {
                lessLoadingScreen = new pluginFileInfo(SystemConfig.SYS.BNS_DIR + plugins_x86 + "lessloadingscreens.dll");
                Dispatchers.toggleIsChecked(lessloadingToggle, true);
            }
            else if ((File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x86 + "lessloadingscreens.dll.off") && File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x64 + "lessloadingscreens.dll.off")))
            {
                lessLoadingScreen = new pluginFileInfo(SystemConfig.SYS.BNS_DIR + plugins_x86 + "lessloadingscreens.dll.off");
            }

            Dispatchers.labelContent(lessloadingCurrentLbl, String.Format("Current: {0}", (lessLoadingScreen != null) ? lessLoadingScreen.modificationTime.ToString("MM-dd-yy") : "Not Installed"));
            #endregion

            #region simplemodetrainingroom
            Dispatchers.btnIsEnabled(simplemodeInstall, false);
            if ((File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x86 + "simplemodetrainingroom.dll") && File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x64 + "simplemodetrainingroom.dll")))
            {
                simplemodeTraining = new pluginFileInfo(SystemConfig.SYS.BNS_DIR + plugins_x86 + "simplemodetrainingroom.dll");
                Dispatchers.toggleIsChecked(simplemodeToggle, true);
            }
            else if ((File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x86 + "simplemodetrainingroom.dll.off") && File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x64 + "simplemodetrainingroom.dll.off")))
            {
                simplemodeTraining = new pluginFileInfo(SystemConfig.SYS.BNS_DIR + plugins_x86 + "simplemodetrainingroom.dll.off");
            }

            Dispatchers.labelContent(SimplemodeCurrentLbl, String.Format("Current: {0}", (simplemodeTraining != null) ? simplemodeTraining.modificationTime.ToString("MM-dd-yy") : "Not Installed"));
            #endregion

            #region highpriorityplugin
            Dispatchers.btnIsEnabled(HighpriorityInstall, false);
            if ((File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x86 + "highpriority.dll") && File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x64 + "highpriority.dll")))
            {
                highpriorityplugin = new pluginFileInfo(SystemConfig.SYS.BNS_DIR + plugins_x86 + "highpriority.dll");
                Dispatchers.toggleIsChecked(HighpriorityToggle, true);
            }
            else if ((File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x86 + "highpriority.dll.off") && File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x64 + "highpriority.dll.off")))
            {
                highpriorityplugin = new pluginFileInfo(SystemConfig.SYS.BNS_DIR + plugins_x86 + "highpriority.dll.off");
            }

            Dispatchers.labelContent(HighpriorityCurrentLbl, String.Format("Current: {0}", (highpriorityplugin != null) ? highpriorityplugin.modificationTime.ToString("MM-dd-yy") : "Not Installed"));
            #endregion

            try
            {
                var client = new MegaApiClient();
                await client.LoginAnonymousAsync();

                IEnumerable <INode> nodes = await client.GetNodesFromLinkAsync(new Uri("https://mega.nz/folder/WXhzUZ7Y#XzlqkPa8DU4X8xrILQDdZA"));

                INode lessloading_node  = nodes.Where(x => x.Type == NodeType.File && x.Name.Contains("lessloadingscreens")).OrderByDescending(t => t.ModificationDate).FirstOrDefault();
                INode simplemode_node   = nodes.Where(x => x.Type == NodeType.File && x.Name.Contains("simplemodetrainingroom")).OrderByDescending(t => t.ModificationDate).FirstOrDefault();
                INode highpriority_node = nodes.Where(x => x.Type == NodeType.File && x.Name.Contains("highpriority")).OrderByDescending(t => t.ModificationDate).FirstOrDefault();
                INode bnspatch_node     = nodes.Where(x => x.Type == NodeType.File && x.Name.Contains("bnspatch")).OrderByDescending(t => t.ModificationDate).FirstOrDefault();
                INode pluginloader_node = nodes.Where(x => x.Type == NodeType.File && x.Name.Contains("pluginloader")).OrderByDescending(t => t.ModificationDate).FirstOrDefault();
                INode bnsnogg_node      = nodes.Where(x => x.Type == NodeType.File && x.Name.Contains("bnsnogg")).OrderByDescending(t => t.ModificationDate).FirstOrDefault();

                //This seems dumb but yeah
                Regex    pattern           = new Regex(@"^(?<fileName>[\w\\.]+)_(?<date>[\w\\.]{10})(?<ext>[\w\\.]+)");
                DateTime highpriority_date = DateTime.Parse(pattern.Match(highpriority_node.Name).Groups["date"].Value);
                DateTime lessloading_date  = DateTime.Parse(pattern.Match(lessloading_node.Name).Groups["date"].Value);
                DateTime simplemode_date   = DateTime.Parse(pattern.Match(simplemode_node.Name).Groups["date"].Value);
                DateTime pluginloader_date = DateTime.Parse(pattern.Match(pluginloader_node.Name).Groups["date"].Value);
                DateTime bnspatch_date     = DateTime.Parse(pattern.Match(bnspatch_node.Name).Groups["date"].Value);
                DateTime bnsnogg_date      = DateTime.Parse(pattern.Match(bnsnogg_node.Name).Groups["date"].Value);

                #region checkforlessloadingscreens
                if (lessLoadingScreen != null)
                {
                    if (lessLoadingScreen.modificationTime < lessloading_date)
                    {
                        Dispatchers.btnIsEnabled(lessloadingInstall, true);
                    }
                    else
                    {
                        Dispatchers.btnIsEnabled(lessloadingInstall, false);
                    }
                }
                else
                {
                    Dispatchers.btnIsEnabled(lessloadingInstall, true);
                }
                #endregion
                #region checkforsimplemode
                if (simplemodeTraining != null)
                {
                    if (simplemodeTraining.modificationTime < simplemode_date)
                    {
                        Dispatchers.btnIsEnabled(simplemodeInstall, true);
                    }
                    else
                    {
                        Dispatchers.btnIsEnabled(simplemodeInstall, false);
                    }
                }
                else
                {
                    Dispatchers.btnIsEnabled(simplemodeInstall, true);
                }
                #endregion
                #region checkforhighpriority
                if (highpriorityplugin != null)
                {
                    if (highpriorityplugin.modificationTime < highpriority_date)
                    {
                        Dispatchers.btnIsEnabled(HighpriorityInstall, true);
                    }
                    else
                    {
                        Dispatchers.btnIsEnabled(HighpriorityInstall, false);
                    }
                }
                else
                {
                    Dispatchers.btnIsEnabled(HighpriorityInstall, true);
                }
                #endregion

                Dispatchers.labelContent(lessloadingOnlineLbl, String.Format("Online: {0}", lessloading_date.ToString("MM-dd-yy")));
                Dispatchers.labelContent(SimplemodeOnlineLbl, String.Format("Online: {0}", simplemode_date.ToString("MM-dd-yy")));
                Dispatchers.labelContent(HighpriorityOnlineLbl, String.Format("Online: {0}", highpriority_date.ToString("MM-dd-yy")));
                Dispatchers.labelContent(bnspatchOnlineLbl, String.Format("Online: {0}", bnspatch_date.ToString("MM-dd-yy")));
                Dispatchers.labelContent(pluginloaderOnlineLbl, String.Format("Online: {0}", pluginloader_date.ToString("MM-dd-yy")));
                Dispatchers.labelContent(bnsnoggOnlineLabel, String.Format("Online: {0}", bnsnogg_date.ToString("MM-dd-yy")));
            } catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            toggleControl = true;
        }
        private async void installBNSNOGG(object sender, RoutedEventArgs e)
        {
            _progressControl        = new ProgressControl();
            ProgressGrid.Visibility = Visibility.Visible;
            MainGrid.Visibility     = Visibility.Collapsed;
            ProgressPanel.Children.Add(_progressControl);

            try
            {
                ProgressControl.updateProgressLabel("Logging into Mega anonymously...");
                var client = new MegaApiClient();
                await client.LoginAnonymousAsync();

                if (!Directory.Exists("modpolice"))
                {
                    Directory.CreateDirectory("modpolice");
                }

                ProgressControl.updateProgressLabel("Retrieving file list...");
                IEnumerable <INode> nodes = await client.GetNodesFromLinkAsync(new Uri("https://mega.nz/folder/WXhzUZ7Y#XzlqkPa8DU4X8xrILQDdZA"));

                INode currentNode           = null;
                IProgress <double> progress = new Progress <double>(x => ProgressControl.updateProgressLabel(String.Format("Downloading: {0} ({1}%)", currentNode.Name, Math.Round(x))));

                //Find our latest nodes for download
                INode bnsnogg_node = nodes.Where(x => x.Type == NodeType.File && x.Name.Contains("bnsnogg")).OrderByDescending(t => t.ModificationDate).FirstOrDefault();

                if (bnsnogg_node == null)
                {
                    ProgressControl.errorSadPeepo(Visibility.Visible);
                    ProgressControl.updateProgressLabel("Error retrieving pluginloader");
                }
                else
                {
                    currentNode = bnsnogg_node;
                    if (File.Exists(@"modpolice\" + bnsnogg_node.Name))
                    {
                        File.Delete(@"modpolice\" + bnsnogg_node.Name);
                    }

                    ProgressControl.errorSadPeepo(Visibility.Hidden);
                    await client.DownloadFileAsync(currentNode, @"modpolice\" + bnsnogg_node.Name, progress);
                }

                ProgressControl.updateProgressLabel("All done, logging out...");

                string _BNSNOGG_VERSION = Directory.EnumerateFiles(Environment.CurrentDirectory + @"\modpolice\").Select(x => Path.GetFileName(x))
                                          .Where(Name => Path.GetExtension(Name) == ".zip" && Name.Contains("bnsnogg"))
                                          .OrderByDescending(d => new FileInfo(d).Name)
                                          .Select(Name => Path.GetFileNameWithoutExtension(Name)).First().ToString();

                ProgressControl.updateProgressLabel("Unzipping " + _BNSNOGG_VERSION);
                ExtractZipFileToDirectory(@".\modpolice\" + _BNSNOGG_VERSION + ".zip", @".\modpolice", true);

                //pluginloader x86
                if (File.Exists(SystemConfig.SYS.BNS_DIR + bin_x86 + "version.dll"))
                {
                    File.Delete(SystemConfig.SYS.BNS_DIR + bin_x86 + "version.dll");
                }

                ProgressControl.updateProgressLabel("Installing bnsnogg x86");
                await Task.Delay(750);

                File.Move(@".\modpolice\bin\version.dll", SystemConfig.SYS.BNS_DIR + bin_x86 + "version.dll");

                //pluginloader x64
                if (File.Exists(SystemConfig.SYS.BNS_DIR + bin_x64 + "version.dll"))
                {
                    File.Delete(SystemConfig.SYS.BNS_DIR + bin_x64 + "version.dll");
                }

                ProgressControl.updateProgressLabel("Installing bnsnogg x64");
                await Task.Delay(750);

                File.Move(@".\modpolice\bin64\version.dll", SystemConfig.SYS.BNS_DIR + bin_x64 + "version.dll");

                if (!Directory.Exists(SystemConfig.SYS.BNS_DIR + plugins_x86))
                {
                    Directory.CreateDirectory(SystemConfig.SYS.BNS_DIR + plugins_x86);
                }

                if (File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x86 + "bnsnogg.dll"))
                {
                    File.Delete(SystemConfig.SYS.BNS_DIR + plugins_x86 + "bnsnogg.dll");
                }

                File.Move(@".\modpolice\bin\plugins\bnsnogg.dll", SystemConfig.SYS.BNS_DIR + plugins_x86 + "bnsnogg.dll");

                if (!Directory.Exists(SystemConfig.SYS.BNS_DIR + plugins_x64))
                {
                    Directory.CreateDirectory(SystemConfig.SYS.BNS_DIR + plugins_x64);
                }

                if (File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x64 + "bnsnogg.dll"))
                {
                    File.Delete(SystemConfig.SYS.BNS_DIR + plugins_x64 + "bnsnogg.dll");
                }

                File.Move(@".\modpolice\bin64\plugins\bnsnogg.dll", SystemConfig.SYS.BNS_DIR + plugins_x64 + "bnsnogg.dll");

                ProgressControl.updateProgressLabel("bnsnogg successfully installed");
                await Task.Delay(2000);
            }
            catch (Exception ex)
            {
                ProgressControl.errorSadPeepo(Visibility.Visible);
                ProgressControl.updateProgressLabel(ex.Message);
                await Task.Delay(7000);
            }

            try
            {
                ProgressGrid.Visibility = Visibility.Hidden;
                MainGrid.Visibility     = Visibility.Visible;
                ProgressPanel.Children.Clear();
                _progressControl = null;

                bnsnoggPlugin = new pluginFileInfo(SystemConfig.SYS.BNS_DIR + plugins_x64 + "bnsnogg.dll");
                Dispatchers.labelContent(bnsnogglocalLabel, String.Format("Current: {0}", (bnsnoggPlugin != null) ? bnsnoggPlugin.modificationTime.ToString("MM-dd-yy") : "Not Installed"));
            }
            catch (Exception)
            {
                //Why are we here, is it just to suffer?
            }
        }
        private async void installModPolice(object sender, RoutedEventArgs e)
        {
            _progressControl        = new ProgressControl();
            ProgressGrid.Visibility = Visibility.Visible;
            MainGrid.Visibility     = Visibility.Collapsed;
            ProgressPanel.Children.Add(_progressControl);

            if (((Button)sender).Name == "installOnline")
            {
                try
                {
                    ProgressControl.updateProgressLabel("Logging into Mega anonymously...");
                    var client = new MegaApiClient();
                    await client.LoginAnonymousAsync();

                    if (!Directory.Exists("modpolice"))
                    {
                        Directory.CreateDirectory("modpolice");
                    }

                    ProgressControl.updateProgressLabel("Retrieving file list...");
                    IEnumerable <INode> nodes = await client.GetNodesFromLinkAsync(new Uri("https://mega.nz/folder/WXhzUZ7Y#XzlqkPa8DU4X8xrILQDdZA"));

                    INode currentNode           = null;
                    IProgress <double> progress = new Progress <double>(x => ProgressControl.updateProgressLabel(String.Format("Downloading: {0} ({1}%)", currentNode.Name, Math.Round(x))));

                    //Find our latest nodes for download
                    INode bnspatch_node     = nodes.Where(x => x.Type == NodeType.File && x.Name.Contains("bnspatch")).OrderByDescending(t => t.ModificationDate).FirstOrDefault();
                    INode pluginloader_node = nodes.Where(x => x.Type == NodeType.File && x.Name.Contains("pluginloader")).OrderByDescending(t => t.ModificationDate).FirstOrDefault();

                    if (pluginloader_node == null)
                    {
                        ProgressControl.errorSadPeepo(Visibility.Visible);
                        ProgressControl.updateProgressLabel("Error retrieving pluginloader");
                    }
                    else
                    {
                        currentNode = pluginloader_node;
                        if (File.Exists(@"modpolice\" + pluginloader_node.Name))
                        {
                            File.Delete(@"modpolice\" + pluginloader_node.Name);
                        }

                        ProgressControl.errorSadPeepo(Visibility.Hidden);
                        await client.DownloadFileAsync(currentNode, @"modpolice\" + pluginloader_node.Name, progress);
                    }

                    if (pluginloader_node == null)
                    {
                        ProgressControl.errorSadPeepo(Visibility.Visible);
                        ProgressControl.updateProgressLabel("Error retrieving pluginloader");
                    }
                    else
                    {
                        currentNode = bnspatch_node;
                        if (File.Exists(@"modpolice\" + bnspatch_node.Name))
                        {
                            File.Delete(@"modpolice\" + bnspatch_node.Name);
                        }

                        ProgressControl.errorSadPeepo(Visibility.Hidden);
                        await client.DownloadFileAsync(currentNode, @"modpolice\" + bnspatch_node.Name, progress);
                    }

                    ProgressControl.updateProgressLabel("All done, logging out...");
                }
                catch (Exception ex)
                {
                    ProgressControl.errorSadPeepo(Visibility.Visible);
                    ProgressControl.updateProgressLabel(ex.Message);
                    await Task.Delay(3000);
                }
            }

            try
            {
                string _BNSPATCH_VERSION = Directory.EnumerateFiles(Environment.CurrentDirectory + @"\modpolice\").Select(x => Path.GetFileName(x))
                                           .Where(Name => Path.GetExtension(Name) == ".zip" && Name.Contains("bnspatch"))
                                           .OrderByDescending(d => new FileInfo(d).Name)
                                           .Select(Name => Path.GetFileNameWithoutExtension(Name)).First().ToString();

                string _PLUGINLOADER_VERSION = Directory.EnumerateFiles(Environment.CurrentDirectory + @"\modpolice\").Select(x => Path.GetFileName(x))
                                               .Where(Name => Path.GetExtension(Name) == ".zip" && Name.Contains("pluginloader"))
                                               .OrderByDescending(d => new FileInfo(d).Name)
                                               .Select(Name => Path.GetFileNameWithoutExtension(Name)).First().ToString();

                ProgressControl.updateProgressLabel("Unzipping " + _PLUGINLOADER_VERSION);
                ExtractZipFileToDirectory(@".\modpolice\" + _PLUGINLOADER_VERSION + ".zip", @".\modpolice", true);

                await Task.Delay(750);

                ProgressControl.updateProgressLabel("Unzipping " + _BNSPATCH_VERSION);
                ExtractZipFileToDirectory(@".\modpolice\" + _BNSPATCH_VERSION + ".zip", @".\modpolice", true);

                //pluginloader x86
                if (File.Exists(SystemConfig.SYS.BNS_DIR + bin_x86 + "winmm.dll"))
                {
                    File.Delete(SystemConfig.SYS.BNS_DIR + bin_x86 + "winmm.dll");
                }

                ProgressControl.updateProgressLabel("Installing pluginloader x86");
                await Task.Delay(750);

                File.Move(@".\modpolice\bin\winmm.dll", SystemConfig.SYS.BNS_DIR + bin_x86 + "winmm.dll");

                //pluginloader x64
                if (File.Exists(SystemConfig.SYS.BNS_DIR + bin_x64 + "winmm.dll"))
                {
                    File.Delete(SystemConfig.SYS.BNS_DIR + bin_x64 + "winmm.dll");
                }

                ProgressControl.updateProgressLabel("Installing pluginloader x64");
                await Task.Delay(750);

                File.Move(@".\modpolice\bin64\winmm.dll", SystemConfig.SYS.BNS_DIR + bin_x64 + "winmm.dll");

                //bnspatch x86
                ProgressControl.updateProgressLabel("Checking if plugins folder exists for x86");
                await Task.Delay(500);

                if (!Directory.Exists(SystemConfig.SYS.BNS_DIR + plugins_x86))
                {
                    Directory.CreateDirectory(SystemConfig.SYS.BNS_DIR + plugins_x86);
                }

                ProgressControl.updateProgressLabel("Installing bnspatch x86");
                if (File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x86 + "bnspatch.dll"))
                {
                    File.Delete(SystemConfig.SYS.BNS_DIR + plugins_x86 + "bnspatch.dll");
                }

                File.Move(@".\modpolice\bin\plugins\bnspatch.dll", SystemConfig.SYS.BNS_DIR + plugins_x86 + "bnspatch.dll");

                //bnspatch x64
                ProgressControl.updateProgressLabel("Checking if plugins folder exists for x64");
                await Task.Delay(500);

                if (!Directory.Exists(SystemConfig.SYS.BNS_DIR + plugins_x64))
                {
                    Directory.CreateDirectory(SystemConfig.SYS.BNS_DIR + plugins_x64);
                }

                ProgressControl.updateProgressLabel("Installing bnspatch x64");
                if (File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x64 + "bnspatch.dll"))
                {
                    File.Delete(SystemConfig.SYS.BNS_DIR + plugins_x64 + "bnspatch.dll");
                }

                File.Move(@".\modpolice\bin64\plugins\bnspatch.dll", SystemConfig.SYS.BNS_DIR + plugins_x64 + "bnspatch.dll");

                ProgressControl.updateProgressLabel("Searching for patches.xml");
                await Task.Delay(500);

                if (!File.Exists(patches_xml))
                {
                    ProgressControl.updateProgressLabel("patches.xml not found, installing...");
                    File.WriteAllText(patches_xml, Properties.Resources.patches);
                }

                ProgressControl.updateProgressLabel("pluginloader & bnspatch successfully installed");
                await Task.Delay(2000);
            } catch (Exception ex)
            {
                ProgressControl.errorSadPeepo(Visibility.Visible);
                ProgressControl.updateProgressLabel(ex.Message);
                await Task.Delay(7000);
            }

            try
            {
                ProgressGrid.Visibility = Visibility.Hidden;
                MainGrid.Visibility     = Visibility.Visible;
                ProgressPanel.Children.Clear();
                _progressControl = null;

                //Get the file info and display version for pluginloader
                pluginloader = new pluginFileInfo(SystemConfig.SYS.BNS_DIR + @"\bin\" + "winmm.dll");
                Dispatchers.labelContent(pluginloaderLabel, String.Format("Current: {0}", (pluginloader != null) ? pluginloader.modificationTime.ToString("MM-dd-yy") : "Not Installed"));

                bnspatchPlugin = new pluginFileInfo(SystemConfig.SYS.BNS_DIR + plugins_x86 + "bnspatch.dll");
                Dispatchers.labelContent(bnspatchLabel, String.Format("Current: {0}", (bnspatchPlugin != null) ? bnspatchPlugin.modificationTime.ToString("MM-dd-yy") : "Not Installed"));
            } catch (Exception)
            {
                //Why are we here, is it just to suffer?
            }
            //refreshSomeShit();
        }
        private async void installAdditional(object sender, RoutedEventArgs e)
        {
            string pluginName;

            switch (((Button)sender).Name)
            {
            case "simplemodeInstall":
                pluginName = "simplemodetrainingroom";
                break;

            case "lessloadingInstall":
                pluginName = "lessloadingscreens";
                break;

            default:
                pluginName = "highpriority";
                break;
            }

            toggleControl           = false;
            _progressControl        = new ProgressControl();
            ProgressGrid.Visibility = Visibility.Visible;
            MainGrid.Visibility     = Visibility.Collapsed;
            ProgressPanel.Children.Add(_progressControl);

            try
            {
                if (!Directory.Exists("modpolice"))
                {
                    Directory.CreateDirectory("modpolice");
                }

                ProgressControl.updateProgressLabel("Logging into Mega");
                var client = new MegaApiClient();
                await client.LoginAnonymousAsync();

                ProgressControl.updateProgressLabel("Retrieving file list...");
                IEnumerable <INode> nodes = await client.GetNodesFromLinkAsync(new Uri("https://mega.nz/folder/WXhzUZ7Y#XzlqkPa8DU4X8xrILQDdZA"));

                INode currentNode           = null;
                IProgress <double> progress = new Progress <double>(x => ProgressControl.updateProgressLabel(String.Format("Downloading: {0} ({1}%)", currentNode.Name, Math.Round(x))));
                INode pluginNode            = nodes.Where(x => x.Type == NodeType.File && x.Name.Contains(pluginName)).OrderByDescending(t => t.ModificationDate).FirstOrDefault();

                if (pluginNode == null)
                {
                    ProgressControl.errorSadPeepo(Visibility.Visible);
                    ProgressControl.updateProgressLabel("Something went wrong getting the node");
                    await Task.Delay(5000);

                    toggleControl = true;
                    return;
                }

                if (File.Exists(@"modpolice\" + pluginNode.Name))
                {
                    File.Delete(@"modpolice\" + pluginNode.Name);
                }

                currentNode = pluginNode;
                await client.DownloadFileAsync(currentNode, @"modpolice\" + pluginNode.Name, progress);

                ProgressControl.updateProgressLabel("Unzipping: " + pluginNode.Name);
                await Task.Delay(750);

                Modpolice.ExtractZipFileToDirectory(@".\modpolice\" + pluginNode.Name, @".\modpolice", true);

                ProgressControl.updateProgressLabel("Installing " + pluginName + " x86");
                await Task.Delay(750);

                if (!Directory.Exists(SystemConfig.SYS.BNS_DIR + plugins_x86))
                {
                    Directory.CreateDirectory(SystemConfig.SYS.BNS_DIR + plugins_x86);
                }

                //Delete the current plugin dll
                if (File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x86 + pluginName + ".dll"))
                {
                    File.Delete(SystemConfig.SYS.BNS_DIR + plugins_x86 + pluginName + ".dll");
                }

                //Make sure there isn't a plugin dll that is in an off state
                if (File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x86 + pluginName + ".dll.off"))
                {
                    File.Delete(SystemConfig.SYS.BNS_DIR + plugins_x86 + pluginName + ".dll.off");
                }

                File.Move(@".\modpolice\bin\plugins\" + pluginName + ".dll", SystemConfig.SYS.BNS_DIR + plugins_x86 + pluginName + ".dll");

                ProgressControl.updateProgressLabel("Installing " + pluginName + " x64");
                await Task.Delay(750);

                if (!Directory.Exists(SystemConfig.SYS.BNS_DIR + plugins_x64))
                {
                    Directory.CreateDirectory(SystemConfig.SYS.BNS_DIR + plugins_x64);
                }

                //Delete the current plugin dll
                if (File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x64 + pluginName + ".dll"))
                {
                    File.Delete(SystemConfig.SYS.BNS_DIR + plugins_x64 + pluginName + ".dll");
                }

                //Make sure there isn't a plugin dll that is in an off state
                if (File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x64 + pluginName + ".dll.off"))
                {
                    File.Delete(SystemConfig.SYS.BNS_DIR + plugins_x64 + pluginName + ".dll.off");
                }

                File.Move(@".\modpolice\bin64\plugins\" + pluginName + ".dll", SystemConfig.SYS.BNS_DIR + plugins_x64 + pluginName + ".dll");

                ProgressControl.updateProgressLabel("All done");
                await Task.Delay(750);

                await client.LogoutAsync();
            } catch (Exception ex)
            {
                ProgressControl.errorSadPeepo(Visibility.Visible);
                ProgressControl.updateProgressLabel(ex.Message);
                await Task.Delay(7000);
            }
            try
            {
                ProgressGrid.Visibility = Visibility.Hidden;
                MainGrid.Visibility     = Visibility.Visible;
                ProgressPanel.Children.Clear();
                _progressControl = null;
                toggleControl    = true;

                if (pluginName == "simplemodetrainingroom")
                {
                    simplemodeTraining = new pluginFileInfo(SystemConfig.SYS.BNS_DIR + plugins_x86 + "simplemodetrainingroom.dll");
                    Dispatchers.toggleIsChecked(simplemodeToggle, true);
                    Dispatchers.labelContent(SimplemodeCurrentLbl, String.Format("Current: {0}", (simplemodeTraining != null) ? simplemodeTraining.modificationTime.ToString("MM-dd-yy") : "Not Installed"));
                }
                else if (pluginName == "lessloadingscreens")
                {
                    lessLoadingScreen = new pluginFileInfo(SystemConfig.SYS.BNS_DIR + plugins_x86 + "lessloadingscreens.dll");
                    Dispatchers.toggleIsChecked(lessloadingToggle, true);
                    Dispatchers.labelContent(lessloadingCurrentLbl, String.Format("Current: {0}", (lessLoadingScreen != null) ? lessLoadingScreen.modificationTime.ToString("MM-dd-yy") : "Not Installed"));
                }
                else
                {
                    highpriorityplugin = new pluginFileInfo(SystemConfig.SYS.BNS_DIR + plugins_x86 + "highpriority.dll");
                    Dispatchers.toggleIsChecked(HighpriorityToggle, true);
                    Dispatchers.labelContent(HighpriorityCurrentLbl, String.Format("Current: {0}", (highpriorityplugin != null) ? highpriorityplugin.modificationTime.ToString("MM-dd-yy") : "Not Installed"));
                }

                Dispatchers.btnIsEnabled((Button)sender, false);
            } catch (Exception)
            {
                //F**K ASS C**T
            }
        }
示例#10
0
        private async void handleToggleChange(object sender, RoutedEventArgs e)
        {
            try
            {
                HorizontalToggleSwitch currentToggle = (HorizontalToggleSwitch)sender;

                if (!_isInitialized)
                {
                    return;
                }

                if (Process.GetProcessesByName("Client").Length >= 1)
                {
                    peepoWtfText.Text = "You can't do that when Blade & Soul is already running!";
                    ((Storyboard)FindResource("animate")).Begin(ErrorPromptGrid);
                    return;
                }

                string sourceDirectory;
                string destinationDirectory;

                //Check if it is an individual class toggle
                if (systemToggles.Any(toggle => toggle.animToggle == currentToggle || toggle.fxToggle == currentToggle))
                {
                    string[]     upkfiles;
                    toggleStruct sysToggle;

                    if (currentToggle.Name.Contains("_fx_"))
                    {
                        sysToggle = systemToggles.Where(x => x.fxToggle.Name == currentToggle.Name).FirstOrDefault();
                        upkfiles  = SystemConfig.SYS.CLASSES.Where(x => x.CLASS == sysToggle.className).Select(upk => upk.EFFECTS).FirstOrDefault();
                    }
                    else
                    {
                        sysToggle = systemToggles.Where(x => x.animToggle.Name == currentToggle.Name).FirstOrDefault();
                        upkfiles  = SystemConfig.SYS.CLASSES.Where(x => x.CLASS == sysToggle.className).Select(upk => upk.ANIMATIONS).FirstOrDefault();
                    }

                    //We're restoring
                    if (currentToggle.IsChecked)
                    {
                        sourceDirectory      = backupLocation;
                        destinationDirectory = SystemConfig.SYS.BNS_DIR + @"\contents\bns\CookedPC\";
                    }
                    else
                    {
                        sourceDirectory      = SystemConfig.SYS.BNS_DIR + @"\contents\bns\CookedPC\";
                        destinationDirectory = backupLocation;
                    }

                    // _isInitialized = false;
                    if (upkfiles.Count() > 0)
                    {
                        foreach (string file in upkfiles)
                        {
                            try
                            {
                                //Move our target file to our new destination
                                if (File.Exists(sourceDirectory + file))
                                {
                                    if (!File.Exists(destinationDirectory + file))
                                    {
                                        File.Move(sourceDirectory + file, destinationDirectory + file);
                                    }
                                    else
                                    {
                                        File.Delete(sourceDirectory + file);
                                    }
                                }
                            }
                            catch (Exception)
                            {
                                //ProgressControl.updateProgressLabel(ex.Message);
                            }
                        }
                    }

                    //_isInitialized = true;
                    Dispatchers.labelContent(classLabel, String.Format("{0} {1}", sysToggle.className, (currentToggle.IsChecked) ? "Restored" : "Removed"));
                    ((Storyboard)FindResource("animate")).Begin(classLabel);
                    ((Storyboard)FindResource("animate")).Begin(successStatePicture);
                }
                else
                {
                    string[] upkFiles;
                    upkFiles = SystemConfig.SYS.MAIN_UPKS;

                    _progressControl = new ProgressControl();
                    MainWindow.mainWindowFrame.RemoveBackEntry();
                    ProgressGrid.Visibility = Visibility.Visible;
                    MainGrid.Visibility     = Visibility.Collapsed;

                    ProgressPanel.Children.Add(_progressControl);

                    //Turning whatever the f**k it is on
                    if (currentToggle.IsChecked)
                    {
                        ProgressControl.errorSadPeepo(Visibility.Hidden);
                        ProgressControl.updateProgressLabel("Restoring files");
                        await Task.Delay(150);

                        sourceDirectory      = backupLocation;
                        destinationDirectory = SystemConfig.SYS.BNS_DIR + @"\contents\bns\CookedPC\";
                    }
                    else
                    {
                        ProgressControl.errorSadPeepo(Visibility.Hidden);
                        ProgressControl.updateProgressLabel("Removing files");
                        await Task.Delay(150);

                        sourceDirectory      = SystemConfig.SYS.BNS_DIR + @"\contents\bns\CookedPC\";
                        destinationDirectory = backupLocation;
                    }

                    if (upkFiles.Count() > 0)
                    {
                        foreach (string file in upkFiles)
                        {
                            try
                            {
                                ProgressControl.updateProgressLabel(String.Format("Checking for {0}", file));
                                await Task.Delay(25);

                                //Move our target file to our new destination
                                if (File.Exists(sourceDirectory + file))
                                {
                                    ProgressControl.updateProgressLabel(String.Format("{0} {1}", (currentToggle.IsChecked) ? "Restoring" : "Removing", file));
                                    if (!File.Exists(destinationDirectory + file))
                                    {
                                        File.Move(sourceDirectory + file, destinationDirectory + file);
                                    }
                                    else
                                    {
                                        File.Delete(sourceDirectory + file);
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                ProgressControl.updateProgressLabel(ex.Message);
                                await Task.Delay(500);
                            }
                            await Task.Delay(50);
                        }
                    }

                    ProgressGrid.Visibility = Visibility.Hidden;
                    MainGrid.Visibility     = Visibility.Visible;
                    ProgressPanel.Children.Clear();
                    _progressControl = null;
                }
            } catch (Exception ex)
            {
                var dialog = new ErrorPrompt("Something went wrong, \r\rAddition information: \r" + ex.Message);
                dialog.ShowDialog();
            }

            GC.WaitForPendingFinalizers();
        }