Skip to content

Commit 6b15a0b

Browse files
committed
fix duplicate account when add accounts
1 parent 4588023 commit 6b15a0b

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

TbsCore/Database/DbRepository.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,12 @@ public static void RemoveAccount(Account acc)
5151
{
5252
using (var context = new TbsContext())
5353
{
54-
context.DbAccount.Remove(FindDbAccount(acc, context));
55-
context.SaveChanges();
54+
var account = FindDbAccount(acc, context);
55+
if (account != null)
56+
{
57+
context.DbAccount.Remove(account);
58+
context.SaveChanges();
59+
}
5660
}
5761
}
5862

TbsCore/Helpers/IoHelperCore.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,16 @@ public static void RemoveCache(Account acc)
135135
var userCacheFolder = UserCachePath(acc.AccInfo.Nickname, acc.AccInfo.ServerUrl);
136136
if (!UserDataExists(acc.AccInfo.Nickname, acc.AccInfo.ServerUrl)) return;
137137

138-
var removeFolders = Directory.GetDirectories(userCacheFolder);
139-
140-
for (int i = 0; i < removeFolders.Count(); i++)
138+
try
141139
{
142-
Directory.Delete(removeFolders[i], true);
140+
var removeFolders = Directory.GetDirectories(userCacheFolder);
141+
142+
for (int i = 0; i < removeFolders.Count(); i++)
143+
{
144+
Directory.Delete(removeFolders[i], true);
145+
}
143146
}
147+
catch { }
144148
}
145149

146150
/// <summary>

TravBotSharp/Forms/AddAccounts.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ private void richTextBox1_TextChanged(object sender, EventArgs e)
3131
var strArr = richTextBox1.Text.Split('\n');
3232
richTextBox2.Text = "";
3333

34+
accounts.Clear();
3435
foreach (var str in strArr)
3536
{
3637
var account = ParserAccout(str);
@@ -41,17 +42,17 @@ private void richTextBox1_TextChanged(object sender, EventArgs e)
4142
{
4243
if (!string.IsNullOrEmpty(account.Proxy.ProxyUsername))
4344
{
44-
richTextBox2.AppendText($"{account.Server} {account.Username} {account.Proxy.Password} {account.Proxy.Proxy} {account.Proxy.ProxyPort} {account.Proxy.ProxyUsername} {account.Proxy.ProxyPassword}\n");
45+
richTextBox2.AppendText($"[{account.Server}] [{account.Username}] [{account.Proxy.Password}] [{account.Proxy.Proxy}] [{account.Proxy.ProxyPort}] [{account.Proxy.ProxyUsername}] [{account.Proxy.ProxyPassword}]\n");
4546

4647
}
4748
else
4849
{
49-
richTextBox2.AppendText($"{account.Server} {account.Username} {account.Proxy.Password} {account.Proxy.Proxy} {account.Proxy.ProxyPort}\n");
50+
richTextBox2.AppendText($"[{account.Server}] [{account.Username}] [{account.Proxy.Password}] [{account.Proxy.Proxy}] [{account.Proxy.ProxyPort}]\n");
5051
}
5152
}
5253
else
5354
{
54-
richTextBox2.AppendText($"{account.Server} {account.Username} {account.Proxy.Password} \n");
55+
richTextBox2.AppendText($"[{account.Server}] [{account.Username}] [{account.Proxy.Password}]\n");
5556
}
5657
}
5758
}

0 commit comments

Comments
 (0)