ZeroLauncher/Manager/AccountManager.cs

122 lines
3.3 KiB
C#
Raw Normal View History

2024-03-07 21:04:59 +08:00

2024-06-23 10:04:00 +08:00
using System.Diagnostics;
2024-03-07 21:04:59 +08:00
namespace Zerolauncher.Manager
{
internal class AccountManager
{
2024-06-23 10:04:00 +08:00
static int teamId=0;
2024-03-07 21:04:59 +08:00
public static string teamName = "";
2024-06-23 10:04:00 +08:00
public static List<AccountNew>? accountsList;
2024-03-07 21:04:59 +08:00
public static void initLoadData()
{
2024-06-23 10:04:00 +08:00
teamId = AccountData.teamIndex;
foreach (var pair in GroupsData.data)
2024-03-07 21:04:59 +08:00
{
2024-06-23 10:04:00 +08:00
Trace.WriteLine(pair.Key, pair.Value);
2024-03-07 21:04:59 +08:00
}
2024-06-23 10:04:00 +08:00
teamName = GroupsData.data[teamId];
accountsList = AccountData.data[teamId];
2024-03-07 21:04:59 +08:00
}
2024-06-23 10:04:00 +08:00
public static void ChangeTeam(int index)
2024-03-07 21:04:59 +08:00
{
2024-06-23 10:04:00 +08:00
teamId = TeamManager.Index2Key(index);
teamId = AccountData.teamIndex;
teamName = GroupsData.data[teamId];
accountsList = AccountData.data[teamId];
}
2024-03-07 21:04:59 +08:00
public static void saveEdit()
{
2024-06-23 10:04:00 +08:00
DataStreamNew.Save();
2024-03-07 21:04:59 +08:00
MainWindow.Instance.ReloadBtn();
}
2024-06-23 10:04:00 +08:00
public static bool AddAccount(AccountNew account)
2024-03-07 21:04:59 +08:00
{
2024-06-23 10:04:00 +08:00
account.groupId = teamId;
AccountData.AddAccount(account);
DataStreamNew.Save();
2024-03-07 21:04:59 +08:00
MainWindow.Instance.ReloadBtn();
return true;
}
2024-06-23 10:04:00 +08:00
public static bool AddAccounts(AccountNew account)
2024-03-07 21:04:59 +08:00
{
2024-06-23 10:04:00 +08:00
account.groupId = teamId;
AccountData.AddAccount(account);
2024-03-07 21:04:59 +08:00
return true;
}
public static void MoveAccount(int memberId, int newIndex)
{
2024-06-23 10:04:00 +08:00
var group_id = TeamManager.Index2Key(newIndex);
var acc = accountsList[memberId];
accountsList.RemoveAt(memberId);
AccountData.CheckGroup(group_id);
AccountData.data[group_id].Add(acc);
DataStreamNew.Save();
2024-03-07 21:04:59 +08:00
MainWindow.Instance.ReloadBtn();
}
public static void DeleteAccount(int index) {
2024-06-23 10:04:00 +08:00
var nick = accountsList[index].nickName;
accountsList.RemoveAt(index);
AccountData.dict.Remove(nick);
DataStreamNew.Save();
2024-03-07 21:04:59 +08:00
MainWindow.Instance.ReloadBtn();
}
public static void editTeamName(string teamName0)
{
teamName = teamName0;
2024-06-23 10:04:00 +08:00
GroupsData.data[teamId] = teamName;
DataStreamNew.Save();
2024-03-07 21:04:59 +08:00
}
public static bool DeleteTeam()
{
2024-06-23 10:04:00 +08:00
if (GroupsData.data.Keys.Count == 1)
2024-03-07 21:04:59 +08:00
{
return false;
}
2024-06-23 10:04:00 +08:00
AccountData.RemoveGroup();
ChangeTeam(GroupsData.data.Keys.First());
DataStreamNew.Save();
2024-03-07 21:04:59 +08:00
MainWindow.Instance.ReloadBtn();
return true;
}
}
internal class TeamManager
{
2024-06-23 10:04:00 +08:00
public static int Index2Key(int index) { return GroupsData.data.ElementAt(index).Key; }
2024-03-07 21:04:59 +08:00
public static string[] GetAllTeamName()
{
2024-06-23 10:04:00 +08:00
return GroupsData.data.Values.ToArray();
2024-03-07 21:04:59 +08:00
}
public static void addTeam(string teamName)
{
2024-06-23 10:04:00 +08:00
GroupsData.data.Add(GroupsData.data.Keys.LastOrDefault() + 1, teamName);
DataStreamNew.Save();
2024-03-07 21:04:59 +08:00
}
//运行时才能决定是否执行内联
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
2024-06-23 10:04:00 +08:00
public static AccountNew? Nick2Acc(string nickName)
2024-03-07 21:04:59 +08:00
{
2024-06-23 10:04:00 +08:00
return AccountData.dict.ContainsKey(nickName)? AccountData.dict[nickName]:null;
2024-03-07 21:04:59 +08:00
}
}
}