private void HandleCreate(RSAccountForm account) { var settings = MainWindow.Settings; var accountModel = DataProvider.GetAccounts().FirstOrDefault(x => x.Username == account.Email); if (accountModel is null) { accountModel = new AccountModel("New Account") { Username = account.Email, Password = account.Password }; } if (accountModel.World is null || accountModel.World == 0) { if (settings.AccountDefaultUseRandomWorld) { accountModel.World = Worlds.GetRandom(); } else if (settings.AccountDefaultWorld > 0) { int world = settings.AccountDefaultWorld; if (world > 0 && (world >= 301 && world <= 525)) { accountModel.World = world; } } } if (string.IsNullOrEmpty(accountModel.ProxyName) && settings.CreateAccountUseProxy && !string.IsNullOrEmpty(settings.CreateAccountProxyName)) { accountModel.ProxyEnabled = 1; accountModel.ProxyName = settings.CreateAccountProxyName; } if (string.IsNullOrEmpty(accountModel.Script) && !string.IsNullOrEmpty(settings.AccountDefaultScript)) { accountModel.Script = settings.AccountDefaultScript; } if (!accountModel.GroupId.HasValue && settings.AccountDefaultGroupId > 0) { accountModel.GroupId = settings.AccountDefaultGroupId; } if (accountModel.Id == 0) { if (DataProvider.SaveAccount(accountModel)) { accountModel = DataProvider.GetAccounts().FirstOrDefault(x => x.Username == accountModel.Username); if (accountModel != null) { Host.AddAccountToList(accountModel); MainWindow.AccountCreatedCallback?.Invoke(accountModel); } } } else { accountModel.Temporary = 0; if (DataProvider.UpdateAccount(accountModel)) { Invoke(() => { var item = Host.accountsListItems.FirstOrDefault(x => x.Username == accountModel.Username); if (item != null) { Util.UpdateObjByProps(accountModel, item, false); AccountsImportList.Refresh(); Host.AccountsListItems.Refresh(); } }); } } if (settings.LaunchAccountOnCreate) { var item = MainWindow.GetAccountsHandler().FirstOrDefault (x => x.Id == accountModel.Id); if (item != null) { item.AutoLaunched = true; MainWindow.AccountManager.QueueAccount(item); } } }