public static void Authenticate(Settings.IAccount account, Tools.ArenaAccount session) { if (session.RequiresAuthentication && NetworkAuthorizationRequired != null) { try { NetworkAuthorizationRequired(null, new NetworkAuthorizationRequiredEventsArgs(account, session)); } catch (Exception e) { Util.Logging.Log(e); } } var v = Settings.NetworkAuthorization.Value; if (session.RequiresAuthentication) { var t = Complete(session, false); if (v.HasFlag(Settings.NetworkAuthorizationFlags.AbortLaunchingOnFail)) { throw new Exception("Unable to authorize the current network"); } } else { var t = Complete(session, v.HasFlag(Settings.NetworkAuthorizationFlags.RemovePreviouslyAuthorized)); if (account.NetworkAuthorizationState != Settings.NetworkAuthorizationState.Disabled) { account.NetworkAuthorizationState = Settings.NetworkAuthorizationState.OK; } } }
public void AddAccount(Settings.IAccount account) { this.total += 2; this.remaining += 2; progressUpdating.Maximum = total; if (!this.accounts.ContainsKey(account)) { this.accounts[account] = new AccountItem(account); } if (cancelDelayedComplete != null) { cancelDelayedComplete.Cancel(); cancelDelayedComplete.Dispose(); cancelDelayedComplete = null; } if (isComplete) { isComplete = false; labelAbort.Enabled = true; labelAbort.ForeColor = Color.FromArgb(49, 121, 242); labelName.Text = "Waiting..."; label1.ForeColor = SystemColors.ControlText; } }
public static void Verify(Settings.IAccount account, Tools.ArenaAccount session) { if (Verify(account, false, session, out session) == VerifyResult.Required) { Authenticate(account, session); } }
private static void Authenticate(Settings.IAccount account, ISession session) { var s = ((Session)session).ArenaSession.Session; if (s.RequiresAuthentication && NetworkAuthorizationRequired != null) { try { NetworkAuthorizationRequired(null, new NetworkAuthorizationRequiredEventsArgs(account, session)); } catch (Exception e) { Util.Logging.Log(e); } } var v = Settings.NetworkAuthorization.Value; if (s.RequiresAuthentication) { if (v.HasFlag(Settings.NetworkAuthorizationFlags.AbortLaunchingOnFail)) { throw new Exception("Unable to authorize the current network"); } } else { if (account.NetworkAuthorizationState != Settings.NetworkAuthorizationState.Disabled) { account.NetworkAuthorizationState = v.HasFlag(Settings.NetworkAuthorizationFlags.RemoveAll) ? Settings.NetworkAuthorizationState.Unknown : Settings.NetworkAuthorizationState.OK; } } }
private void Remove(Settings.IAccount account, Process p) { lock (accounts) { Process existing; if (accounts.TryGetValue(account, out existing)) { if (p == null || existing == p) { p = existing; if (accounts.Remove(account) && accounts.Count == 0) { Client.Launcher.AccountWindowEvent -= Launcher_AccountWindowEvent; Client.Launcher.AccountProcessExited -= Launcher_AccountProcessExited; } } } } if (p != null) { try { p.EnableRaisingEvents = false; p.Kill(); } catch { } } }
void Launcher_AccountProcessActivated(Settings.IAccount account, Process e) { if (activeAccount != account) { return; } if (this.InvokeRequired) { try { this.BeginInvoke(new MethodInvoker( delegate { Launcher_AccountProcessActivated(account, e); })); } catch (Exception ex) { Util.Logging.Log(ex); } return; } activeProcess = e; OnProcessChanged(); }
private static FileInfo GetLink(Settings.IAccount account, Launcher.ProcessOptions options) { var path = Path.Combine(DataPath.AppDataAccountData, "pl", account.UID.ToString()); string name; if ((name = _fileDescription) == null) { try { _fileDescription = name = FileVersionInfo.GetVersionInfo(options.FileName).FileDescription; if (string.IsNullOrWhiteSpace(name)) { throw new NotSupportedException(); } return(new FileInfo(Path.Combine(path, name + ".lnk"))); } catch { _fileDescription = name = "Guild Wars 2"; } } return(new FileInfo(Path.Combine(path, name + ".lnk"))); }
private void OnAccountAdded(Settings.ISettingValue <Settings.IAccount> v, Settings.IAccount account) { v.ValueCleared += Account_ValueCleared; account.NameChanged += account_NameChanged; account.LastUsedUtcChanged += account_LastUsedUtcChanged; account.JumpListPinningChanged += account_JumpListPinningChanged; }
public DataEventArgs(QueuedAccountApi source, Settings.IAccount account, Api.Account response, Api.Account responsePrevious, byte attempt, DateTime dateScheduled, DateTime dateRequested, object data) { this.source = source; this.Account = account; this.Response = response; this.ResponsePreviousAttempt = responsePrevious; this.Attempt = attempt; this.Date = dateRequested; this.DateScheduled = dateScheduled; this.Data = data; }
private void OnLinkedProcessAdded(Settings.IAccount account, ProcessInfo pi) { try { pi.process.PriorityClass = ProcessPriorityClass.High; } catch (Exception e) { Util.Logging.Log(e); } }
public formAccount(Settings.IAccount account) : this() { this.account = account; if (account.TotalUses == 1) { labelLaunchCount.Text = "once"; labelLaunchCountEnd.Visible = false; } else labelLaunchCount.Text = account.TotalUses.ToString(); if (account.LastUsedUtc != DateTime.MinValue) { var local = account.LastUsedUtc.ToLocalTime(); labelLastLaunch.Text = local.ToLongDateString() + " " + local.ToLongTimeString(); } if (account.CreatedUtc != DateTime.MinValue) { var local = account.CreatedUtc.ToLocalTime(); labelCreatedDate.Text = local.ToLongDateString() + " " + local.ToLongTimeString(); } labelAccountId.Text = account.UID.ToString(); labelExportRecordedLaunch.Visible = File.Exists(Path.Combine(DataPath.AppData, "statistics.dat")); checkRecordLaunch.Checked = account.RecordLaunches; checkAutomaticLogin.Checked=account.AutomaticLogin; if (account.AutomaticLogin) { textAutoLoginEmail.Text = account.AutomaticLoginEmail; textAutoLoginPassword.Text = account.AutomaticLoginPassword; } textAccountName.Text = account.Name; textWindowsAccount.Text = account.WindowsAccount; textArguments.Text = account.Arguments; checkWindowed.Checked = account.Windowed; textWindowed.Text = ToString(account.WindowBounds); checkShowDaily.Checked = account.ShowDaily; if (account.DatFile != null) { textLocalDat.Text = account.DatFile.Path; textLocalDat.Select(textLocalDat.TextLength, 0); } else textLocalDat.Text = ""; }
/// <summary> /// The account will be queued to use the API after the specified amount of time. /// Adding an account that is already queued will overwrite it, unless it has a unique data object attached. /// </summary> /// <param name="data">Optional data that will be returned with the response</param> public void Schedule(Settings.IAccount account, object data, int millisDelay) { var now = DateTime.UtcNow; var q = new QueuedAccount(account) { ticks = now.Ticks / 10000 + millisDelay, date = now, data = data, }; Schedule(q, millisDelay == 0); }
private void buttonOK_Click(object sender, EventArgs e) { var accounts = Selected = new List <Settings.IAccount>(); foreach (DataGridViewRow row in gridAccounts.Rows) { if ((bool)row.Cells[columnCheck.Index].Value == true) { Settings.IAccount account = ((AccountCell)row.Cells[columnName.Index].Value).account; accounts.Add(account); } } this.DialogResult = DialogResult.OK; }
private void OnAccountRemoved(Settings.ISettingValue <Settings.IAccount> v, Settings.IAccount account) { if (v != null) { v.ValueCleared -= Account_ValueCleared; } if (account != null) { account.NameChanged -= account_NameChanged; account.LastUsedUtcChanged -= account_LastUsedUtcChanged; account.JumpListPinningChanged -= account_JumpListPinningChanged; } }
private async void LoadAccount(Settings.IAccount account) { var notes = account.Notes; if (notes == null || notes.Count == 0) { strings = new Dictionary <ushort, string>(); } else { strings = await GetStringsAsync(notes); } SetupControls(); }
public void Remove(Settings.IAccount account) { lock (queue) { queue.Enqueue(new QueueItem() { type = QueueItem.QueueType.Remove, account = account, }); if (task == null || task.IsCompleted) { task = DoProcesses(); } } }
void Launcher_AccountLaunched(Settings.IAccount account) { lock (this) { JumpItem j; if (accounts.TryGetValue(account.UID, out j)) { j.IsActive = true; if (j.Visible != IsEnabled(j)) { RefreshAsync(); } } } }
public void Add(Settings.IAccount account, Process p) { lock (queue) { queue.Enqueue(new QueueItem() { type = QueueItem.QueueType.Add, process = p, account = account, }); if (task == null || task.IsCompleted) { task = DoProcesses(); } } }
void Launcher_AccountWindowEvent(Settings.IAccount account, Launcher.AccountWindowEventEventArgs e) { if (e.Type == Launcher.AccountWindowEventEventArgs.EventType.BoundsChanged) { lock (accounts) { Process p; if (accounts.TryGetValue(account, out p)) { var h = Windows.FindWindow.Find(p); if (h != IntPtr.Zero) { NativeMethods.SetWindowPos(h, IntPtr.Zero, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE | SetWindowPosFlags.SWP_ASYNCWINDOWPOS | SetWindowPosFlags.SWP_NOZORDER); } } } } }
void Launcher_AccountProcessActivated(Settings.IAccount account, Process e) { if (activeAccount != account) { return; } if (Util.Invoke.IfRequiredAsync(this, delegate { Launcher_AccountProcessActivated(account, e); })) { return; } activeProcess = e; OnProcessChanged(); }
public formNotes(Settings.IAccount account) { InitializeComponent(); _ExpiredCount = _MessageCount = -1; this.Opacity = 0; panelContainer.MouseWheel += panelContainer_MouseWheel; panelContent.SizeChanged += panelContent_SizeChanged; labelAccountName.Text = account.Name; this.account = account; buttonMessages.Selected = true; selectedTab = buttonMessages; LoadAccount(account); }
public static ISession Verify(Settings.IAccount account, Action onAuthenticationRequired) { ISession session; if (Verify(account, out session, false, onAuthenticationRequired) == VerifyResult.Required) { try { Authenticate(account, session); } catch { if (session != null) { session.Release(); } throw; } } return(session); }
public void Add(Settings.IAccount account, Process p, IntPtr window) { Process existing, current; lock (accounts) { if (accounts.Count == 0) { existing = null; Client.Launcher.AccountWindowEvent += Launcher_AccountWindowEvent; Client.Launcher.AccountProcessExited += Launcher_AccountProcessExited; } else { accounts.TryGetValue(account, out existing); } EnableFlags flags; if (!account.WindowOptions.HasFlag(Settings.WindowOptions.DisableTitleBarButtons)) { flags = EnableFlags.EnableClose | EnableFlags.EnableMinimize; } else { flags = EnableFlags.None; } try { accounts[account] = current = Util.ProcessUtil.ShowWindowMask(p, window, flags); } catch { Remove(account); return; } try { current.Exited += process_Exited; current.EnableRaisingEvents = true; if (current.HasExited) { throw new Exception("Exited"); } } catch { Remove(account, current); } } if (existing != null) { try { existing.EnableRaisingEvents = false; existing.Kill(); } catch { } } }
void Launcher_AccountProcessExited(Settings.IAccount account, Process e) { Remove(account, null); }
public void Remove(Settings.IAccount account) { Remove(account, null); }
public static VerifyResult Verify(Settings.IAccount account, bool force, Tools.ArenaAccount sessionExisting, out Tools.ArenaAccount session) { var v = Settings.NetworkAuthorization.Value; bool doCheck, update = false; session = sessionExisting; switch (account.NetworkAuthorizationState) { case Settings.NetworkAuthorizationState.Unknown: doCheck = true; break; case Settings.NetworkAuthorizationState.OK: if (force) { doCheck = true; break; } switch (v & Settings.NetworkAuthorizationFlags.VerificationModes) { case Settings.NetworkAuthorizationFlags.Automatic: var now = DateTime.UtcNow; if (doCheck = now > nextNetworkCheck && Launcher.GetActiveProcessCount() == 0) { update = true; } break; case Settings.NetworkAuthorizationFlags.Always: doCheck = true; break; default: return(VerifyResult.None); } break; case Settings.NetworkAuthorizationState.Disabled: default: return(VerifyResult.None); } if (!doCheck || !account.HasCredentials) { return(VerifyResult.None); } try { if (session == null) { using (var t = Tools.ArenaAccount.LoginAccount(account.Email, account.Password)) { t.Wait(); session = t.Result; } if (session == null) { return(VerifyResult.None); } if (update) { nextNetworkCheck = DateTime.UtcNow.AddMinutes(10); } } if (!session.RequiresAuthentication) { if (account.NetworkAuthorizationState != Settings.NetworkAuthorizationState.Disabled) { account.NetworkAuthorizationState = Settings.NetworkAuthorizationState.OK; } var t = Complete(session, false); return(VerifyResult.OK); } } catch (Exception e) { Util.Logging.Log(e); session = null; if (e.InnerException is Tools.ArenaAccount.UnexpectedResponseException) { if (update) { nextNetworkCheck = DateTime.UtcNow.AddMinutes(10); } } } if (session == null) { return(VerifyResult.None); } if (account.NetworkAuthorizationState == Settings.NetworkAuthorizationState.OK) { //account was previously authorized, assuming IP was changed - flag all accounts foreach (var uid in Settings.Accounts.GetKeys()) { var _a = Settings.Accounts[uid]; if (_a.HasValue && _a.Value.NetworkAuthorizationState == Settings.NetworkAuthorizationState.OK) { _a.Value.NetworkAuthorizationState = Settings.NetworkAuthorizationState.Unknown; } } } switch (session.Authentication) { case Tools.ArenaAccount.AuthenticationType.Email: case Tools.ArenaAccount.AuthenticationType.SMS: break; case Tools.ArenaAccount.AuthenticationType.TOTP: if (account.TotpKey != null) { var now = DateTime.UtcNow.Ticks; byte retry = 0; do { try { if (retry > 0) { //authorizing can only be attempted once per session using (var t = session.Login(account.Email, account.Password)) { t.Wait(); if (t.Result) { if (!session.RequiresAuthentication || session.Authentication != Tools.ArenaAccount.AuthenticationType.TOTP) { break; } } else { break; } } if (retry > 1) { break; } //retrying using the server's time now = session.Date.Ticks; if (now <= 0) { now = DateTime.UtcNow.Ticks; } } var key = Tools.Totp.Generate(account.TotpKey, now); using (var t = session.Authenticate(new string(key))) { t.Wait(); } } catch (Exception e) { Util.Logging.Log(e); if (e.InnerException != null) { if (retry == 0 && e.InnerException is Tools.ArenaAccount.AuthenticationException) { retry++; continue; } } retry += 2; } break; }while (true); } break; default: return(VerifyResult.None); } if (session.RequiresAuthentication) { return(VerifyResult.Required); } else { var t = Complete(session, v.HasFlag(Settings.NetworkAuthorizationFlags.RemovePreviouslyAuthorized)); if (account.NetworkAuthorizationState != Settings.NetworkAuthorizationState.Disabled) { account.NetworkAuthorizationState = Settings.NetworkAuthorizationState.OK; } return(VerifyResult.Completed); } }
private void buttonOK_Click(object sender, EventArgs e) { if (textAccountName.Text.Length == 0) { buttonGeneral.Selected = true; MessageBox.Show(this, "An identifier / account or display name is required", "Identifier / name required", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } Rectangle windowBounds; if (checkWindowed.Checked) { Rectangle r = ParseWindowSize(textWindowed.Text); windowBounds = FixSize(r); } else windowBounds = Rectangle.Empty; Settings.IDatFile datFile; try { datFile = GetDatFile(); selectedFile = null; } catch (Exception ex) { MessageBox.Show(this, "An error occured while handling Local.dat.\n\n" + ex.Message, "Failed handling Local.dat", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (this.account == null) { this.account = Settings.CreateAccount(); this.account.LastUsedUtc = DateTime.MinValue; this.account.CreatedUtc = DateTime.UtcNow; } this.account.Windowed = checkWindowed.Checked; this.account.Name = textAccountName.Text; this.account.WindowsAccount = textWindowsAccount.Text; this.account.Arguments = textArguments.Text; this.account.ShowDaily = checkShowDaily.Checked; this.account.DatFile = datFile; this.account.WindowBounds = windowBounds; this.account.RecordLaunches = checkRecordLaunch.Checked; if (checkAutomaticLogin.Checked && textAutoLoginEmail.TextLength > 0 && textAutoLoginPassword.TextLength > 0) { this.account.AutomaticLoginEmail = textAutoLoginEmail.Text; this.account.AutomaticLoginPassword = textAutoLoginPassword.Text; } else { this.account.AutomaticLoginEmail = null; this.account.AutomaticLoginPassword = null; } this.DialogResult = System.Windows.Forms.DialogResult.OK; }
void Launcher_AccountStateChanged(ushort uid, Client.Launcher.AccountState state, Client.Launcher.AccountState previousState, object data) { if (this.InvokeRequired) { try { this.Invoke(new MethodInvoker( delegate { Launcher_AccountStateChanged(uid, state, previousState, data); })); } catch { } return; } AccountItem item; if (accounts.TryGetValue(uid,out item)) { timeout = Environment.TickCount; OnTimeoutChanged(); switch (state) { case Client.Launcher.AccountState.Active: case Client.Launcher.AccountState.UpdatingVisible: case Client.Launcher.AccountState.Updating: if (item.State == 0) { if (state == Client.Launcher.AccountState.UpdatingVisible) { activeAccount = item.Account; activeProcess = data as Process; OnProcessChanged(); } labelName.Text = "Updating " + item.Account.Name; item.State = 1; remaining--; progressUpdating.Value = total - remaining; } break; case Client.Launcher.AccountState.Error: case Client.Launcher.AccountState.None: if (activeAccount == item.Account) { activeAccount = null; if (activeProcess != null) { activeProcess = null; OnProcessChanged(); } } if (item.State < 2) { if (item.State == 0) remaining--; item.State = 2; remaining--; progressUpdating.Value = total - remaining; if (this.remaining == 0) { if (cancelWatch != null) cancelWatch.Cancel(); OnComplete(); } } break; } } }
public Account(Settings.IAccount settings) { this.Settings = settings; this.Process = new LinkedProcess(this); }
public formBrowseLocalDat(Client.FileManager.FileType type, Settings.IAccount account) { InitializeComponent(); var scale = this.CurrentAutoScaleDimensions.Width / 96f; if (scale != 1) { foreach (DataGridViewColumn col in gridAccounts.Columns) { if (col.AutoSizeMode != DataGridViewAutoSizeColumnMode.Fill) { col.Width = (int)(col.Width * scale + 0.5f); } } } radioAccountShare.Enabled = Client.FileManager.IsDataLinkingSupported; this.fileType = type; string fileName; if (type == Client.FileManager.FileType.Gfx) { fileName = "GFXSettings.xml"; } else { fileName = "Local.dat"; } label5.Text = string.Format(label5.Text, fileName); radioCreateNew.Text = string.Format(radioCreateNew.Text, fileName); int _space = buttonOK.Location.X - buttonCancel.Bounds.Right; buttonCancel.Location = new Point(this.ClientSize.Width / 2 - (buttonOK.Bounds.Right - buttonCancel.Bounds.Left) / 2, buttonCancel.Location.Y); buttonOK.Location = new Point(buttonCancel.Bounds.Right + _space, buttonCancel.Location.Y); var shared = new Dictionary <string, KeyValuePair <int, List <DataGridViewRow> > >(); var hiddenRows = 0; foreach (var uid in Settings.Accounts.GetKeys()) { var _account = Settings.Accounts[uid]; if (_account.HasValue) { Settings.IFile file; switch (type) { case Client.FileManager.FileType.Dat: file = _account.Value.DatFile; break; case Client.FileManager.FileType.Gfx: file = _account.Value.GfxFile; break; default: file = null; break; } if (file != null && !string.IsNullOrEmpty(file.Path)) { var row = gridAccounts.Rows[gridAccounts.Rows.Add()]; row.Tag = _account.Value; string user = _account.Value.WindowsAccount; if (string.IsNullOrEmpty(user)) { user = "******"; } row.Cells[columnName.Index].Value = _account.Value.Name; row.Cells[columnUser.Index].Value = user; KeyValuePair <int, List <DataGridViewRow> > sharedWith; if (shared.TryGetValue(file.Path, out sharedWith)) { row.Cells[columnShared.Index].Value = sharedWith.Key; row.Cells[columnShared.Index].Tag = sharedWith.Value; if (sharedWith.Value.Count == 1) { sharedWith.Value[0].Cells[columnShared.Index].Value = sharedWith.Key; sharedWith.Value[0].Cells[columnShared.Index].Tag = sharedWith.Value; } } else { shared[file.Path] = sharedWith = new KeyValuePair <int, List <DataGridViewRow> >(shared.Count + 1, new List <DataGridViewRow>()); } if (account != null && uid == account.UID) { row.Visible = false; hiddenRows++; } sharedWith.Value.Add(row); } } } if (gridAccounts.Rows.Count - hiddenRows == 0) { gridAccounts.SelectionChanged += delegate { gridAccounts.ClearSelection(); }; gridAccounts.Enabled = false; var row = gridAccounts.Rows[gridAccounts.Rows.Add()]; row.Cells[columnName.Index].Value = "None available"; row.DefaultCellStyle.ForeColor = Color.Gray; gridAccounts.ClearSelection(); radioAccountCopy.Enabled = false; radioAccountShare.Enabled = false; radioFileCopy.Checked = true; } }
public static string Export(Settings.IAccount account) { List <QueuedRecord> l = new List <QueuedRecord>(); ushort uid = account.UID; DateTime programExit = DateTime.MinValue; DateTime launch = DateTime.MinValue; try { using (BinaryReader reader = new BinaryReader(File.Open(Path.Combine(DataPath.AppData, FILE_NAME), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))) { while (true) { ushort id = reader.ReadUInt16(); RecordType type = (RecordType)reader.ReadByte(); DateTime time = DateTime.FromBinary(reader.ReadInt64()); if (id == uid && account.CreatedUtc <= time) { if (type == RecordType.Launched) { if (launch != DateTime.MinValue && programExit > launch) { l.Add(new QueuedRecord(RecordType.Exited, 0, programExit)); } l.Add(new QueuedRecord(type, id, time)); launch = time; programExit = DateTime.MinValue; } else if (type == RecordType.Exited && launch != DateTime.MinValue) { l.Add(new QueuedRecord(type, id, time)); launch = DateTime.MinValue; } } if (id == 0) { if (type == RecordType.Exited && time > launch && programExit == DateTime.MinValue) { programExit = time; } } } } } catch (Exception ex) { Util.Logging.Log(ex); } if (launch != DateTime.MinValue && programExit > launch) { l.Add(new QueuedRecord(RecordType.Exited, 0, programExit)); } if (l.Count == 0) { return(null); } string path = Path.GetTempFileName(); try { using (StreamWriter writer = new StreamWriter(File.Create(path))) { writer.WriteLine("# " + account.Name); writer.WriteLine("# event_type, UTC date (yyyy-MM-ddTHH:mm:ss)"); writer.WriteLine(); foreach (var q in l) { string type; if (q.uid == 0) { switch (q.type) { case RecordType.Exited: type = "app_exit"; break; case RecordType.Launched: type = "app_start"; break; default: type = ""; break; } } else { switch (q.type) { case RecordType.Exited: type = "gw2_exit"; break; case RecordType.Launched: type = "gw2_launch"; break; default: type = ""; break; } } writer.WriteLine(type + ", " + q.time.ToString("s")); } } } catch (Exception e) { Util.Logging.Log(e); try { File.Delete(path); } catch (Exception ex) { Util.Logging.Log(ex); } return(null); } return(path); }
public DataSource(Settings.IAccount account, Process process) { this.Account = account; this.Process = process; }
public NetworkAuthorizationRequiredEventsArgs(Settings.IAccount account, Tools.ArenaAccount arena) { this.account = arena; this.Account = account; }