You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.6 KiB
C#
58 lines
1.6 KiB
C#
using System.Text.Json;
|
|
using Lagrange.Core.Common;
|
|
using RoBot.Start.ConstValue;
|
|
|
|
namespace RoBot.Start.Keystore
|
|
{
|
|
/// <summary>
|
|
/// 账号登录信息
|
|
/// </summary>
|
|
public class KeystoreConfig
|
|
{
|
|
/// <summary>
|
|
/// 获取账号登录信息
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static async Task<KeystoreInfo> GetBotKeystore()
|
|
{
|
|
KeystoreInfo result = new()
|
|
{
|
|
ReLogin = false
|
|
};
|
|
var botKeystore = File.Exists(Consts.KeystoreConfig)
|
|
? JsonSerializer.Deserialize<BotKeystore>(await File.ReadAllTextAsync(Consts.KeystoreConfig)) ?? new()
|
|
: new();
|
|
result.BotKeystore = botKeystore;
|
|
if (botKeystore.Session.TempPassword?.Length > 0)
|
|
{
|
|
result.ReLogin = true;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存登录信息
|
|
/// </summary>
|
|
/// <param name="botKeystore"></param>
|
|
/// <returns></returns>
|
|
public static async Task SaveBotKeystore(BotKeystore botKeystore)
|
|
{
|
|
string keystoreJson = JsonSerializer.Serialize(botKeystore);
|
|
await File.WriteAllTextAsync(Consts.KeystoreConfig, keystoreJson);
|
|
}
|
|
}
|
|
|
|
public class KeystoreInfo
|
|
{
|
|
/// <summary>
|
|
/// BotKeystore
|
|
/// </summary>
|
|
public BotKeystore BotKeystore { get; set; }
|
|
|
|
/// <summary>
|
|
/// 是否需要重新登录
|
|
/// </summary>
|
|
public bool ReLogin { get; set; }
|
|
}
|
|
}
|