Skip to content

Commit b728f8c

Browse files
authored
Merge branch 'dev' into dev
2 parents a51e6ec + cdfee3f commit b728f8c

File tree

19 files changed

+257
-334
lines changed

19 files changed

+257
-334
lines changed

CAPI/python/PyAPI/API.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(self, logic: ILogic) -> None:
1111
self.__pool = ThreadPoolExecutor(20)
1212

1313
def Move(self, timeInMilliseconds: int, angle: float) -> Future[bool]:
14-
return self.__pool.submit(self.__logic.move, timeInMilliseconds, angle)
14+
return self.__pool.submit(self.__logic.Move, timeInMilliseconds, angle)
1515

1616
def MoveRight(self, timeInMilliseconds: int) -> Future[bool]:
1717
return self.Move(timeInMilliseconds, pi * 0.5)

CAPI/python/PyAPI/logic.py

Lines changed: 69 additions & 69 deletions
Large diffs are not rendered by default.

dependency/proto/Protos.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</ItemGroup>-->
1515

1616
<ItemGroup>
17-
<PackageReference Include="Google.Protobuf" Version="3.26.0" />
17+
<PackageReference Include="Google.Protobuf" Version="3.26.1" />
1818
<PackageReference Include="Google.Protobuf.Tools" Version="3.25.3" />
1919
<PackageReference Include="Grpc" Version="2.46.6" />
2020
<PackageReference Include="Grpc.Core" Version="2.46.6" />

installer/Data/ConfigFileData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ public LanguageOption Language
171171
}
172172
}
173173

174-
175174
public int LaunchID
176175
{
177176
get => file.LaunchID;
@@ -363,6 +362,7 @@ public Command Commands
363362
com = value;
364363
if (temp != value)
365364
OnMemoryChanged?.Invoke(this, new EventArgs());
365+
com.OnMemoryChanged += (_, _) => OnMemoryChanged?.Invoke(this, new EventArgs());
366366
}
367367
}
368368
}

installer/Data/MD5FileData.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@
66

77
namespace installer.Data
88
{
9-
public class MD5FileData
9+
public class MD5DataFile
1010
{
11-
// TO DO: 将Local_Data中与MD5FileData相关部分移动到本文件下并建立引用
11+
public Dictionary<string, string> Data { get; set; } = new Dictionary<string, string>();
12+
public Version Version = new Version(1, 0, 0, 0);
13+
public string Description { get; set; }
14+
= "The Description of the current version.";
15+
public string BugFixed { get; set; }
16+
= "Bugs had been fixed.";
17+
public string BugGenerated { get; set; }
18+
= "New bugs found in the new version.";
1219
}
1320
}

installer/Model/Downloader.cs

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.IO.Compression;
1010
using System.Formats.Tar;
1111
using installer.Data;
12+
using installer.Services;
1213

1314
namespace installer.Model
1415
{
@@ -31,6 +32,7 @@ public class UserInfo
3132
public string StartName = "maintest.exe"; // 启动的程序名
3233
public Local_Data Data; // 本地文件管理器
3334
public Tencent_Cos Cloud; // THUAI7 Cos桶
35+
public Version CurrentVersion { get => Data.CurrentVersion; set => Data.CurrentVersion = value; }
3436

3537
public HttpClient Client = new HttpClient();
3638
public EEsast Web; // EEsast服务器
@@ -50,10 +52,10 @@ public enum UpdateStatus
5052
public string UserEmail { get => Web.Email; }
5153
public Data.Command Commands
5254
{
53-
get => Data.FileHashData.Command;
55+
get => Data.Config.Commands;
5456
set
5557
{
56-
Data.FileHashData.Command = value;
58+
Data.Config.Commands = value;
5759
}
5860
}
5961
public enum UsingOS { Win, Linux, OSX };
@@ -122,7 +124,6 @@ public Downloader()
122124
Web.Token_Changed += SaveToken;
123125
LoggerBinding();
124126

125-
string? temp;
126127
if (Data.Config.Remembered)
127128
{
128129
Username = Data.Config.UserName;
@@ -291,16 +292,67 @@ public bool CheckUpdate()
291292
Status = UpdateStatus.hash_computing;
292293
Data.ScanDir();
293294
Status = UpdateStatus.success;
294-
return Data.MD5Update.Count != 0;
295+
return Data.MD5Update.Count != 0 || CurrentVersion < Data.FileHashData.Version;
295296
}
296297

297298
/// <summary>
298299
/// 更新文件
299300
/// </summary>
300-
public void Update()
301+
public int Update()
301302
{
303+
int result = 0;
302304
if (CheckUpdate())
303305
{
306+
// 处理AI.cpp/AI.py合并问题
307+
if (CurrentVersion < Data.FileHashData.Version)
308+
{
309+
var c = CurrentVersion;
310+
var v = Data.FileHashData.Version;
311+
Status = UpdateStatus.downloading;
312+
var p = Path.Combine(Data.Config.InstallPath, "Templates");
313+
var tocpp = Cloud.DownloadFileAsync(Path.Combine(p, $"v{c}.cpp.t"),
314+
$"./Template/v{c}.cpp.t");
315+
var topy = Cloud.DownloadFileAsync(Path.Combine(p, $"v{c}.py.t"),
316+
$"./Template/v{c}.py.t");
317+
var tncpp = Cloud.DownloadFileAsync(Path.Combine(p, $"v{v}.cpp.t"),
318+
$"./Template/v{v}.cpp.t");
319+
var tnpy = Cloud.DownloadFileAsync(Path.Combine(p, $"v{v}.py.t"),
320+
$"./Template/v{v}.py.t");
321+
Task.WaitAll(tocpp, topy, tncpp, tnpy);
322+
if (Directory.GetFiles(p).Count() == 4)
323+
{
324+
if (Data.LangEnabled[LanguageOption.cpp].Item1)
325+
{
326+
var so = FileService.ReadToEnd(Path.Combine(p, $"v{c}.cpp.t"));
327+
var sn = FileService.ReadToEnd(Path.Combine(p, $"v{v}.cpp.t"));
328+
var sa = FileService.ReadToEnd(Data.LangEnabled[LanguageOption.cpp].Item2);
329+
var s = FileService.MergeUserCode(sa, so, sn);
330+
using (var f = new FileStream(Data.LangEnabled[LanguageOption.cpp].Item2 + ".temp", FileMode.Create))
331+
using (var w = new StreamWriter(f))
332+
{
333+
w.Write(s);
334+
w.Flush();
335+
}
336+
result |= 1;
337+
}
338+
if (Data.LangEnabled[LanguageOption.python].Item1)
339+
{
340+
var so = FileService.ReadToEnd(Path.Combine(p, $"v{c}.py.t"));
341+
var sn = FileService.ReadToEnd(Path.Combine(p, $"v{v}.py.t"));
342+
var sa = FileService.ReadToEnd(Data.LangEnabled[LanguageOption.python].Item2);
343+
var s = FileService.MergeUserCode(sa, so, sn);
344+
using (var f = new FileStream(Data.LangEnabled[LanguageOption.python].Item2 + ".temp", FileMode.Create))
345+
using (var w = new StreamWriter(f))
346+
{
347+
w.Write(s);
348+
w.Flush();
349+
}
350+
result |= 2;
351+
}
352+
}
353+
}
354+
downloadFailed.Clear();
355+
304356
Status = UpdateStatus.downloading;
305357
Cloud.DownloadQueueAsync(Data.Config.InstallPath,
306358
from item in Data.MD5Update where item.state != System.Data.DataRowState.Added select item.name,
@@ -320,16 +372,17 @@ public void Update()
320372
if (Data.MD5Update.Count == 0)
321373
{
322374
Status = UpdateStatus.success;
323-
return;
375+
return result;
324376
}
325377
}
326378
}
327379
else
328380
{
329381
Status = UpdateStatus.success;
330-
return;
382+
return result;
331383
}
332384
Status = UpdateStatus.error;
385+
return result;
333386
}
334387

335388
/// <summary>
@@ -388,7 +441,7 @@ public void UploadFiles(int player_id)
388441
lang = "unknown";
389442
break;
390443
}
391-
Web.UploadFiles(Client, Path.Combine(Data.Config.InstallPath, Data.UserCodePath), lang, $"player_{player_id}").Wait();
444+
Web.UploadFiles(Client, Data.LangEnabled[Commands.Language].Item2, lang, $"player_{player_id}").Wait();
392445
}
393446
#endregion
394447
}

installer/Model/Local_Data.cs

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,53 +14,14 @@
1414

1515
namespace installer.Model
1616
{
17-
public record VersionID
18-
{
19-
public VersionID(int major, int minor, int build, int revision)
20-
{
21-
(Major, Minor, Build, Revision) = (major, minor, build, revision);
22-
}
23-
public int Major, Minor, Build, Revision;
24-
public static bool operator >(VersionID left, VersionID right)
25-
{
26-
return (left.Major > right.Major) |
27-
(left.Major == right.Major && left.Minor > right.Minor) |
28-
(left.Major == right.Major && left.Minor == right.Minor && left.Build > right.Build) |
29-
(left.Major == right.Major && left.Minor == right.Minor && left.Build == right.Build && left.Revision > right.Revision);
30-
}
31-
public static bool operator <(VersionID left, VersionID right)
32-
{
33-
return (left.Major < right.Major) |
34-
(left.Major == right.Major && left.Minor < right.Minor) |
35-
(left.Major == right.Major && left.Minor == right.Minor && left.Build < right.Build) |
36-
(left.Major == right.Major && left.Minor == right.Minor && left.Build == right.Build && left.Revision < right.Revision);
37-
}
38-
}
39-
public class MD5DataFile
40-
{
41-
public Dictionary<string, string> Data { get; set; } = new Dictionary<string, string>();
42-
public Command Command { get; set; } = new Command();
43-
public VersionID Version = new VersionID(1, 0, 0, 0);
44-
public string Description { get; set; }
45-
= "The Description of the current version.";
46-
public string BugFixed { get; set; }
47-
= "Bugs had been fixed.";
48-
public string BugGenerated { get; set; }
49-
= "New bugs found in the new version.";
50-
}
51-
5217
public class Local_Data
5318
{
5419
public string ConfigPath; // 标记路径记录文件THUAI7.json的路径
5520
public string MD5DataPath; // 标记MD5本地缓存文件的路径
56-
public string UserCodePostfix = "cpp"; // 用户文件后缀(.cpp/.py)
5721
public MD5DataFile FileHashData = new MD5DataFile();
5822
public ConfigData Config;
59-
public string UserCodePath
60-
{
61-
get => Path.Combine(Config.InstallPath,
62-
$"???{Path.DirectorySeparatorChar}AI{UserCodePostfix}");
63-
}
23+
public Version CurrentVersion;
24+
public Dictionary<LanguageOption, (bool, string)> LangEnabled;
6425
public string LogPath { get => Path.Combine(Config.InstallPath, "Logs"); }
6526
public ConcurrentDictionary<string, string> MD5Data
6627
{
@@ -96,12 +57,14 @@ public Local_Data()
9657
if (!File.Exists(MD5DataPath))
9758
SaveMD5Data();
9859
ReadMD5Data();
60+
CurrentVersion = FileHashData.Version;
9961
MD5Update.Clear();
10062
}
10163
else
10264
{
10365
MD5DataPath = Path.Combine(Config.InstallPath, $".{Path.DirectorySeparatorChar}hash.json");
10466
Config.MD5DataPath = $".{Path.DirectorySeparatorChar}hash.json";
67+
CurrentVersion = FileHashData.Version;
10568
SaveMD5Data();
10669
}
10770
RememberMe = (Config.Remembered && Convert.ToBoolean(Config.Remembered));
@@ -114,6 +77,7 @@ public Local_Data()
11477
Config.MD5DataPath = Config.InstallPath;
11578
MD5DataPath = Path.Combine(Config.InstallPath, $".{Path.DirectorySeparatorChar}hash.json");
11679
Config.MD5DataPath = $".{Path.DirectorySeparatorChar}hash.json";
80+
CurrentVersion = FileHashData.Version;
11781
SaveMD5Data();
11882
}
11983
}
@@ -123,6 +87,7 @@ public Local_Data()
12387
var dir = Directory.CreateDirectory(Path.Combine(AppContext.BaseDirectory, "THUAI7"));
12488
Config.InstallPath = dir.FullName;
12589
MD5DataPath = Path.Combine(Config.InstallPath, $".{Path.DirectorySeparatorChar}hash.json");
90+
CurrentVersion = FileHashData.Version;
12691
Config.MD5DataPath = $".{Path.DirectorySeparatorChar}hash.json";
12792
SaveMD5Data();
12893
}
@@ -139,6 +104,11 @@ public Local_Data()
139104
Log = LoggerProvider.FromFile(Path.Combine(LogPath, "LocalData.log"));
140105
LogError = LoggerProvider.FromFile(Path.Combine(LogPath, "LocalData.error.log"));
141106
Exceptions = new ExceptionStack(LogError, this);
107+
LangEnabled = new Dictionary<LanguageOption, (bool, string)>();
108+
foreach (var a in typeof(LanguageOption).GetEnumValues())
109+
{
110+
LangEnabled.Add((LanguageOption)a, (false, string.Empty));
111+
}
142112
}
143113

144114
~Local_Data()
@@ -219,7 +189,7 @@ public void ReadMD5Data()
219189
}
220190
r.Close(); r.Dispose();
221191
}
222-
catch (JsonException e)
192+
catch (JsonException)
223193
{
224194
// Json反序列化失败,考虑重新创建MD5数据库
225195
r.Close(); r.Dispose();
@@ -251,6 +221,7 @@ public void SaveMD5Data()
251221
{
252222
try
253223
{
224+
FileHashData.Version = CurrentVersion;
254225
using (FileStream fs = new FileStream(MD5DataPath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
255226
using (StreamWriter sw = new StreamWriter(fs))
256227
{
@@ -289,7 +260,7 @@ public void ScanDir()
289260
{
290261
string cur = stack.Pop();
291262
files.AddRange(from f in Directory.GetFiles(cur)
292-
where !IsUserFile(f)
263+
where !IsUserFile(f, LangEnabled)
293264
select f);
294265
foreach (var d in Directory.GetDirectories(cur))
295266
stack.Push(d);
@@ -326,7 +297,6 @@ public void ScanDir()
326297
SaveMD5Data();
327298
}
328299

329-
330300
public static bool IsUserFile(string filename)
331301
{
332302
if (filename.Contains("git") || filename.Contains("bin") || filename.Contains("obj"))
@@ -344,6 +314,14 @@ public static bool IsUserFile(string filename)
344314
return false;
345315
}
346316

317+
public static bool IsUserFile(string filename, Dictionary<LanguageOption, (bool, string)> dict)
318+
{
319+
if (filename.Contains("AI.cpp"))
320+
dict[LanguageOption.cpp] = (true, filename);
321+
if (filename.Contains("AI.py"))
322+
dict[LanguageOption.python] = (true, filename);
323+
return IsUserFile(filename);
324+
}
347325
public static int CountFile(string folder, string? root = null)
348326
{
349327
int result = (from f in Directory.EnumerateFiles(folder)

0 commit comments

Comments
 (0)