コード例 #1
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            string dat = null,
                   gfx = null;

            if (panelDat.Visible)
            {
                if (radioDatNew.Checked)
                {
                    dat = Path.GetTempFileName();
                }
                else
                {
                    var defaultFile = Client.FileManager.GetDefaultPath(Client.FileManager.FileType.Dat);

                    if (radioDatCopyDefault.Checked)
                    {
                        var tmp = Path.GetTempFileName();

                        try
                        {
                            File.Copy(defaultFile, tmp, true);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(this, "Unable to copy the default Local.dat file:\n\n" + ex.Message, "Unable to copy Local.dat", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }

                        dat = tmp;
                    }
                    else if (radioDatShareDefault.Checked)
                    {
                        var f = Client.FileManager.FindFile(Client.FileManager.FileType.Dat, defaultFile);
                        if (f != null)
                        {
                            this.DatFile = (Settings.IDatFile)f;
                        }
                        else if (File.Exists(defaultFile))
                        {
                            dat = defaultFile;
                        }
                        else
                        {
                            MessageBox.Show(this, "Unable to share the default Local.dat file, it does not exist", "Local.dat not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                }
            }

            if (panelGfx.Visible)
            {
                if (radioGfxNew.Checked)
                {
                    gfx = Path.GetTempFileName();
                }
                else
                {
                    var defaultFile = Client.FileManager.GetDefaultPath(Client.FileManager.FileType.Gfx);

                    if (radioGfxCopyDefault.Checked)
                    {
                        var tmp = Path.GetTempFileName();

                        try
                        {
                            File.Copy(defaultFile, tmp, true);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(this, "Unable to copy the default GFXSettings.xml file:\n\n" + ex.Message, "Unable to copy GFXSettings.xml", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }

                        gfx = tmp;
                    }
                    else if (radioGfxShareDefault.Checked)
                    {
                        var f = Client.FileManager.FindFile(Client.FileManager.FileType.Gfx, defaultFile);
                        if (f != null)
                        {
                            this.GfxFile = (Settings.IGfxFile)f;
                        }
                        else if (File.Exists(defaultFile))
                        {
                            gfx = defaultFile;
                        }
                        else
                        {
                            MessageBox.Show(this, "Unable to share the default GFXSettings.xml file, it does not exist", "GFXSettings.xml not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                }
            }

            if (dat != null)
            {
                this.DatFile      = Settings.CreateDatFile();
                this.DatFile.Path = dat;
            }

            if (gfx != null)
            {
                this.GfxFile      = Settings.CreateGfxFile();
                this.GfxFile.Path = gfx;
            }

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }
コード例 #2
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            const int INDEX_DEFAULT = 0;
            const int INDEX_SHARED  = 1;

            var accounts = GetAccounts();

            byte[] gfxfile     = null;
            var    manualcount = 0;

            var dats     = new Settings.IDatFile[2];
            var gfxs     = new Settings.IGfxFile[2];
            var checkDat = new bool[] { true, true };
            var checkGfx = new bool[] { true, true };

            if (textGw2Path.TextLength > 0 && File.Exists(textGw2Path.Text))
            {
                try
                {
                    var bits = Util.FileUtil.GetExecutableBits(textGw2Path.Text);

                    if (Environment.Is64BitOperatingSystem && bits == 32)
                    {
                        if (Settings.GuildWars2.Arguments.HasValue)
                        {
                            Settings.GuildWars2.Arguments.Value = Util.Args.AddOrReplace(Settings.GuildWars2.Arguments.Value, "32", "-32");
                        }
                        else
                        {
                            Settings.GuildWars2.Arguments.Value = "-32";
                        }
                    }

                    Settings.GuildWars2.Path.Value = textGw2Path.Text;
                }
                catch { }
            }

            checkGfx[INDEX_DEFAULT] = Settings.GuildWars2.Path.HasValue;

            foreach (var a in accounts)
            {
                if (!a.HasCredentials)
                {
                    ++manualcount;
                }
            }

            foreach (var a in accounts)
            {
                var _account = (Settings.IGw2Account)Settings.CreateAccount(Settings.AccountType.GuildWars2);
                var dat      = INDEX_DEFAULT;
                var gfx      = INDEX_DEFAULT;

                _account.Name = a.Name;

                if (a.HasCredentials)
                {
                    _account.Email            = a.Email;
                    _account.Password         = Settings.PasswordString.Create(a.Password);
                    _account.AutologinOptions = Settings.AutologinOptions.Login | Settings.AutologinOptions.Play;

                    dat = INDEX_SHARED;
                }
                else if (panelLogin.Enabled)
                {
                    if (radioLoginRemembered.Checked)
                    {
                        _account.AutomaticRememberedLogin = true;

                        dat = -1;
                    }
                }

                if (panelGraphics.Enabled)
                {
                    if (radioGraphicsShared.Checked)
                    {
                        gfx = INDEX_SHARED;
                    }
                    else
                    {
                        gfx = -1;
                    }
                }

                if (dat == -1 || checkDat[dat] && dats[dat] == null)
                {
                    if (dat != -1)
                    {
                        checkDat[dat] = false;
                    }

                    if (dat == INDEX_DEFAULT)
                    {
                        var path = Client.FileManager.GetDefaultPath(Client.FileManager.FileType.Dat);
                        var f    = dats[dat] = (Settings.IDatFile)Client.FileManager.FindFile(Client.FileManager.FileType.Dat, path);

                        if (f == null && File.Exists(path))
                        {
                            dats[dat] = f = Settings.CreateDatFile();
                            f.Path    = path;
                        }

                        _account.DatFile = dats[dat];
                    }
                    else
                    {
                        var path = CreateTempFile();

                        if (!string.IsNullOrEmpty(path))
                        {
                            var f = Settings.CreateDatFile();
                            f.Path = path;
                            if (dat != -1)
                            {
                                dats[dat] = f;
                            }
                            _account.DatFile = f;
                        }
                    }
                }
                else
                {
                    _account.DatFile = dats[dat];
                }

                if (gfx == -1 || checkGfx[gfx] && gfxs[gfx] == null)
                {
                    if (gfx != -1)
                    {
                        checkGfx[gfx] = false;
                    }

                    if (gfx == INDEX_DEFAULT)
                    {
                        var path = Client.FileManager.GetDefaultPath(Client.FileManager.FileType.Gfx);
                        var f    = gfxs[gfx] = (Settings.IGfxFile)Client.FileManager.FindFile(Client.FileManager.FileType.Gfx, path);

                        if (f == null && File.Exists(path))
                        {
                            gfxs[gfx] = f = Settings.CreateGfxFile();
                            f.Path    = path;
                        }

                        _account.GfxFile = gfxs[gfx];
                    }
                    else
                    {
                        var path = CreateTempFile();

                        if (!string.IsNullOrEmpty(path))
                        {
                            if (gfxfile == null)
                            {
                                gfxfile = ReadGfxData();
                            }

                            if (gfxfile.Length > 0)
                            {
                                try
                                {
                                    File.WriteAllBytes(path, gfxfile);
                                }
                                catch { }
                            }

                            var f = Settings.CreateGfxFile();
                            f.Path = path;
                            if (gfx != -1)
                            {
                                gfxs[gfx] = f;
                            }
                            _account.GfxFile = f;
                        }
                    }
                }
                else
                {
                    _account.GfxFile = gfxs[gfx];
                }

                //note some accounts may be given null dat/gfx files - these will be automatically set on launch to the default files used by gw2
            }

            if (radioAddonsAuto.Checked || radioAddonsManual.Checked)
            {
                var o = Settings.LocalizeAccountExecutionOptions.Enabled;

                if (panelDirectUpdates.Enabled && radioDirectUpdateYes.Checked)
                {
                    o |= Settings.LocalizeAccountExecutionOptions.OnlyIncludeBinFolders;
                }
                if (radioAddonsAuto.Checked)
                {
                    o |= Settings.LocalizeAccountExecutionOptions.AutoSync | Settings.LocalizeAccountExecutionOptions.AutoSyncDeleteUnknowns;
                }

                Settings.GuildWars2.LocalizeAccountExecution.Value = o;
            }

            if (panelDirectUpdates.Enabled && radioDirectUpdateYes.Checked)
            {
                Settings.GuildWars2.DatUpdaterEnabled.Value = true;
                Settings.GuildWars2.UseCustomGw2Cache.Value = true;
            }

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }