Пример #1
0
        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;
        }
Пример #2
0
        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
            }
        }