Ejemplo n.º 1
0
        public MainWindow()
        {
            var wi = WindowsIdentity.GetCurrent();
            var wp = new WindowsPrincipal(wi);

            bool runAsAdmin = wp.IsInRole(WindowsBuiltInRole.Administrator);

            if (!runAsAdmin)
            {
                var processInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase);

                processInfo.UseShellExecute = true;
                processInfo.Verb            = "runas";

                // Start the new process
                try
                {
                    Process.Start(processInfo);
                }
                catch (Exception)
                {
                    var dialog = new ErrorPrompt("Failed to auto start as admin, please launch with administrator rights.");
                    dialog.ShowDialog();
                }

                // Shut down the current process
                Environment.Exit(0);
            }

            InitializeComponent();

            string      CultureName = Thread.CurrentThread.CurrentCulture.Name;
            CultureInfo ci          = new CultureInfo(CultureName);

            if (ci.NumberFormat.NumberDecimalSeparator != ".")
            {
                // Forcing use of decimal separator for numerical values
                ci.NumberFormat.NumberDecimalSeparator = ".";
                Thread.CurrentThread.CurrentCulture    = ci;
                Thread.CurrentThread.CurrentUICulture  = ci;
            }

            //Construct our taskbar icon
            taskBar.Icon                  = Properties.Resources.AppIcon;
            taskBar.ToolTipText           = "BnS Multi Tool";
            taskBar.TrayMouseDoubleClick += new RoutedEventHandler(OnNotifyDoubleClick);
            taskBar.Visibility            = Visibility.Hidden;

            UpdateButtonObj = MultiTool_UPDATE;

            this.MouseDown += delegate { try { DragMove(); } catch (Exception) { } };

            try
            {
                const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";
                using (var ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey))
                {
                    if ((int)ndpKey.GetValue("Release") < 461808)
                    {
                        var dialog = new ErrorPrompt("It seems you do not have .NET Framework 4.7.2 or higher, this is required for certain features to work properly.\nPlease install it and try launching again.");
                        dialog.ShowDialog();
                        Environment.Exit(0);
                    }
                }

                if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "BnS", "multitool_qol.xml")))
                {
                    File.WriteAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "BnS", "multitool_qol.xml"), Properties.Resources.multitool_qol);
                }

                qol_xml = XDocument.Load(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "BnS", "multitool_qol.xml"));
            }
            catch (Exception) { }

            if (File.Exists("BnS-Multi-Tool-Updater.exe"))
            {
                File.Delete("BnS-Multi-Tool-Updater.exe");
            }

            if (String.IsNullOrEmpty(SystemConfig.SYS.BNS_DIR) || !Directory.Exists(Path.Combine(SystemConfig.SYS.BNS_DIR, "bin")))
            {
                //First check the registry, see if we can find the correct path, if not prompt the user when catching the error.
                try
                {
                    RegistryKey BNS_REGISTRY = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\NCWest\BnS");

                    if (BNS_REGISTRY != null)
                    {
                        SystemConfig.SYS.BNS_DIR = BNS_REGISTRY.GetValue("BaseDir").ToString();
                        //This is a slight correction for some systems, for whatever reason they are not registering the path correctly so I have to force this backslash onto it.
                        if (SystemConfig.SYS.BNS_DIR.Last() != '\\')
                        {
                            SystemConfig.SYS.BNS_DIR += "\\";
                        }
                    }
                    else
                    {
                        BNS_REGISTRY = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\plaync\BNS_KOR");

                        if (BNS_REGISTRY == null)
                        {
                            throw new Exception("No registry entries for client");
                        }

                        SystemConfig.SYS.BNS_DIR = BNS_REGISTRY.GetValue("BaseDir").ToString();
                        if (SystemConfig.SYS.BNS_DIR.Last() != '\\')
                        {
                            SystemConfig.SYS.BNS_DIR += "\\";
                        }

                        ACCOUNT_CONFIG.ACCOUNTS.REGION   = (int)Globals.BnS_Region.KR;
                        ACCOUNT_CONFIG.ACCOUNTS.LANGUAGE = 5;
                    }

                    SystemConfig.appendChangesToConfig();

                    if (!Directory.Exists(SystemConfig.SYS.BNS_DIR + @"\contents\"))
                    {
                        throw new Exception("Directory doesn't eixst");
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("The path for Blade and Soul is not valid, please set the proper path for your game installation", "INVALID PATH");
                    using (var FOLDER = new System.Windows.Forms.FolderBrowserDialog())
                    {
                        System.Windows.Forms.DialogResult RESULT = FOLDER.ShowDialog();

                        if (RESULT == System.Windows.Forms.DialogResult.OK && !string.IsNullOrWhiteSpace(FOLDER.SelectedPath))
                        {
                            SystemConfig.SYS.BNS_DIR = FOLDER.SelectedPath + "\\";
                            SystemConfig.appendChangesToConfig();
                        }
                    }
                }
            }

            lstBoxUpdaterThreads.SelectedIndex = SystemConfig.SYS.UPDATER_THREADS;
            lstBoxNewGame.SelectedIndex        = SystemConfig.SYS.NEW_GAME_OPTION;
            lstBoxLauncherX.SelectedIndex      = SystemConfig.SYS.MINIMZE_ACTION;
            DeltaPatching_Checkbox.IsChecked   = (SystemConfig.SYS.DELTA_PATCHING == 1) ? true : false;
            PingCheckTick.IsChecked            = (SystemConfig.SYS.PING_CHECK == 1) ? true : false;
            BNS_LOCATION_BOX.Text = SystemConfig.SYS.BNS_DIR;
        }