2024-03-07 21:04:59 +08:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.IO.Compression;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Zerolauncher.Manager
|
|
|
|
|
|
{
|
|
|
|
|
|
class DataStream
|
|
|
|
|
|
{
|
|
|
|
|
|
private const string path = "user.data";
|
|
|
|
|
|
public static Data dataStream;
|
|
|
|
|
|
|
|
|
|
|
|
public static void Load()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (File.Exists(path))
|
|
|
|
|
|
{
|
|
|
|
|
|
dataStream = JsonConvert.DeserializeObject<Data>(Encoding.UTF8.GetString(Decompress(File.ReadAllBytes(path))));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
dataStream = JsonConvert.DeserializeObject<Data>(
|
2024-03-18 22:59:51 +08:00
|
|
|
|
"{\"teamIndex\":0,\"Groups\":[{\"Name\":\"队伍1\", \"Accounts\": [{\"providerId\":0,\"userName\":\"test\",\"userPWD\":\"test\",\"nickName\":\"测试账号\",\"serverId\":\"1\"}]}], \"ecs\": \"\"}");
|
2024-03-07 21:04:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void write()
|
|
|
|
|
|
{
|
|
|
|
|
|
string? data = JsonConvert.SerializeObject(dataStream);
|
2024-03-18 22:59:51 +08:00
|
|
|
|
//Trace.WriteLine(data);
|
2024-03-07 21:04:59 +08:00
|
|
|
|
if (data == null) return;
|
|
|
|
|
|
File.WriteAllBytes(path, CompressBytes(Encoding.UTF8.GetBytes(data)));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//压缩字节
|
|
|
|
|
|
//1.创建压缩的数据流
|
|
|
|
|
|
//2.设定compressStream为存放被压缩的文件流,并设定为压缩模式
|
|
|
|
|
|
//3.将需要压缩的字节写到被压缩的文件流
|
|
|
|
|
|
public static byte[] CompressBytes(byte[] bytes)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (MemoryStream compressStream = new MemoryStream())
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var zipStream = new GZipStream(compressStream, CompressionMode.Compress))
|
|
|
|
|
|
zipStream.Write(bytes, 0, bytes.Length);
|
|
|
|
|
|
return compressStream.ToArray();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//解压缩字节
|
|
|
|
|
|
//1.创建被压缩的数据流
|
|
|
|
|
|
//2.创建zipStream对象,并传入解压的文件流
|
|
|
|
|
|
//3.创建目标流
|
|
|
|
|
|
//4.zipStream拷贝到目标流
|
|
|
|
|
|
//5.返回目标流输出字节
|
|
|
|
|
|
public static byte[] Decompress(byte[] bytes)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var compressStream = new MemoryStream(bytes))
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var zipStream = new GZipStream(compressStream, CompressionMode.Decompress))
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var resultStream = new MemoryStream())
|
|
|
|
|
|
{
|
|
|
|
|
|
zipStream.CopyTo(resultStream);
|
|
|
|
|
|
return resultStream.ToArray();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class Account
|
|
|
|
|
|
{
|
2024-05-12 16:43:07 +08:00
|
|
|
|
public int providerId, serverId;
|
|
|
|
|
|
public string userName, userPWD, nickName;
|
2024-03-07 21:04:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Group
|
|
|
|
|
|
{
|
|
|
|
|
|
public string Name;
|
|
|
|
|
|
public List<Account> Accounts;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct Data
|
|
|
|
|
|
{
|
|
|
|
|
|
public int teamIndex;
|
|
|
|
|
|
public List<Group> Groups;
|
2024-03-18 22:59:51 +08:00
|
|
|
|
public string ecs;
|
2024-03-07 21:04:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|