1414
1515namespace 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