コード例 #1
0
ファイル: formMain.cs プロジェクト: Healix/Gw2Launcher
        private async void CheckBuild()
        {
            int build = await Tools.Gw2Build.GetBuildAsync();
            if (Settings.CheckForNewBuilds && Settings.LastKnownBuild.Value != build)
            {
                //ask to update if nothing else is happening
                if (activeWindows == 0 && Client.Launcher.GetPendingLaunchCount() == 0 && Client.Launcher.GetActiveProcessCount() == 0)
                {
                    HashSet<Settings.IDatFile> dats = new HashSet<Settings.IDatFile>();
                    List<Settings.IAccount> accounts = new List<Settings.IAccount>();

                    //only accounts with a unique dat file need to be updated

                    foreach (ushort uid in Settings.Accounts.GetKeys())
                    {
                        var a = Settings.Accounts[uid];
                        if (a.HasValue && (a.Value.DatFile == null || dats.Add(a.Value.DatFile)))
                        {
                            accounts.Add(a.Value);
                        }
                    }

                    if (accounts.Count > 0)
                    {
                        try
                        {
                            BeforeShowDialog();
                            activeWindows++;

                            if (MessageBox.Show(this, "A new build is available for Guild Wars 2.\n\nWould you like to update now?", "New build available", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                try
                                {
                                    Client.Launcher.CancelPendingLaunches();
                                    Client.Launcher.KillAllActiveProcesses();
                                }
                                catch { }

                                using (formUpdating f = new formUpdating(accounts))
                                {
                                    if (f.ShowDialog(this) == DialogResult.OK)
                                        Settings.LastKnownBuild.Value = build;
                                }
                            }
                        }
                        finally
                        {
                            activeWindows--;
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: formMain.cs プロジェクト: Healix/Gw2Launcher
        void Launcher_BuildUpdated(Client.Launcher.BuildUpdatedEventArgs e)
        {
            HashSet<Settings.IDatFile> dats = new HashSet<Settings.IDatFile>();
            List<Settings.IAccount> accounts = new List<Settings.IAccount>();

            //only accounts with a unique dat file need to be updated

            foreach (ushort uid in Settings.Accounts.GetKeys())
            {
                var a = Settings.Accounts[uid];
                if (a.HasValue && (a.Value.DatFile == null || dats.Add(a.Value.DatFile)))
                {
                    accounts.Add(a.Value);
                }
            }

            if (accounts.Count > 0)
            {
                System.Threading.CancellationTokenSource cancel = new System.Threading.CancellationTokenSource(3000);

                try
                {
                    this.BeginInvoke(new MethodInvoker(
                        delegate
                        {
                            BeforeShowDialog();
                            try
                            {
                                activeWindows++;
                                using (formUpdating f = new formUpdating(accounts, true, true))
                                {
                                    f.Shown += delegate
                                    {
                                        cancel.Cancel();
                                    };
                                    f.ShowDialog(this);
                                }
                            }
                            finally
                            {
                                activeWindows--;
                            }
                        }));
                }
                catch { }

                try
                {
                    cancel.Token.WaitHandle.WaitOne();
                }
                catch (Exception ex)
                {
                    ex = ex;
                }

                e.Update(accounts);
            }
        }
コード例 #3
0
ファイル: formMain.cs プロジェクト: Healix/Gw2Launcher
        private void UpdateAccounts(IEnumerable<AccountGridButton> buttons)
        {
            List<Settings.IAccount> accounts = null;

            foreach (var button in buttons)
            {
                var account = button.AccountData;
                if (account != null)
                {
                    if (accounts == null)
                    {
                        accounts = new List<Settings.IAccount>();

                        while (Client.Launcher.GetActiveProcessCount() > 0)
                        {
                            BeforeShowDialog();
                            if (MessageBox.Show(this, "Guild Wars 2 cannot be updated while allowing multiple clients to be opened.\n\nClose all clients to continue.", "Close GW2 to continue", MessageBoxButtons.RetryCancel, MessageBoxIcon.Exclamation) == DialogResult.Retry)
                            {
                                int killed = Client.Launcher.KillAllActiveProcesses();
                                if (killed > 0)
                                {
                                    Client.Launcher.Scan();
                                    System.Threading.Thread.Sleep(500);
                                }
                            }
                            else
                                return;
                        }
                    }

                    accounts.Add(account);
                }
            }

            if (accounts != null)
            {
                try
                {
                    BeforeShowDialog();
                    activeWindows++;
                    using (formUpdating f = new formUpdating(accounts))
                    {
                        f.ShowDialog(this);
                    }
                }
                finally
                {
                    activeWindows--;
                }
            }
        }