Skip to content

Commit

Permalink
Merge branch 'dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
GuoWQ222 authored Mar 17, 2024
2 parents 103fb0f + 70c2b88 commit 4cfc0c2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 17 deletions.
3 changes: 2 additions & 1 deletion installer/Model/Downloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,10 @@ public void UpdateMD5()
/// <summary>
/// 全新安装
/// </summary>
public void Install()
public void Install(string? path = null)
{
Data.Installed = false;
Data.InstallPath = path ?? Data.InstallPath;
UpdateMD5();
if (Status == UpdateStatus.error) return;

Expand Down
63 changes: 47 additions & 16 deletions installer/Model/Local_Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,46 @@

namespace installer.Model
{
public record VersionID
{
public VersionID(int major, int minor, int build, int revision)
{
(Major, Minor, Build, Revision) = (major, minor, build, revision);
}
public int Major, Minor, Build, Revision;
public static bool operator >(VersionID left, VersionID right)
{
return (left.Major > right.Major) |
(left.Major == right.Major && left.Minor > right.Minor) |
(left.Major == right.Major && left.Minor == right.Minor && left.Build > right.Build) |
(left.Major == right.Major && left.Minor == right.Minor && left.Build == right.Build && left.Revision > right.Revision);
}
public static bool operator <(VersionID left, VersionID right)
{
return (left.Major < right.Major) |
(left.Major == right.Major && left.Minor < right.Minor) |
(left.Major == right.Major && left.Minor == right.Minor && left.Build < right.Build) |
(left.Major == right.Major && left.Minor == right.Minor && left.Build == right.Build && left.Revision < right.Revision);
}
}
public class MD5DataFile
{
public Dictionary<string, string> Data { get; set; } = new Dictionary<string, string>();
public (int, int, int, int) Version = (1, 0, 0, 0);
public string Description { get; set; }
= "The Description of the current version.";
public string BugFixed { get; set; }
= "Bugs had been fixed.";
public string BugGenerated { get; set; }
= "New bugs found in the new version.";
}

public class Local_Data
{
public string ConfigPath; // 标记路径记录文件THUAI7.json的路径
public string MD5DataPath; // 标记MD5本地缓存文件的路径
public string UserCodePostfix; // 用户文件后缀(.cpp/.py)
public string UserCodePostfix = "cpp"; // 用户文件后缀(.cpp/.py)
public MD5DataFile FileData = new MD5DataFile();
public string UserCodePath
{
get => Path.Combine(InstallPath,
Expand Down Expand Up @@ -221,36 +256,30 @@ public void SaveConfig()

public void ReadMD5Data()
{
Dictionary<string, string> newMD5Data;
FileData = new MD5DataFile();
StreamReader r = new StreamReader(MD5DataPath);
try
{
string json = r.ReadToEnd();
if (json is null || json == "")
{
newMD5Data = new Dictionary<string, string>();
}
else
if (!string.IsNullOrEmpty(json))
{
newMD5Data = JsonSerializer.Deserialize<Dictionary<string, string>>(json) ?? new Dictionary<string, string>();
FileData = JsonSerializer.Deserialize<MD5DataFile>(json) ?? new MD5DataFile();
}
r.Close(); r.Dispose();
}
catch (JsonException e)

Check warning on line 270 in installer/Model/Local_Data.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-install

The variable 'e' is declared but never used
{
// Json反序列化失败,考虑重新创建MD5数据库
newMD5Data = new Dictionary<string, string>();
r.Close(); r.Dispose();
File.Delete(MD5DataPath);
File.Create(MD5DataPath);
}
catch (Exception e)
{
Exceptions.Push(e);
newMD5Data = new Dictionary<string, string>();
r.Close(); r.Dispose();
}
foreach (var item in newMD5Data)
foreach (var item in FileData.Data)
{
var key = item.Key.Replace('/', Path.DirectorySeparatorChar);
MD5Data.AddOrUpdate(key, (k) =>
Expand All @@ -276,7 +305,8 @@ public void SaveMD5Data()
fs.SetLength(0);
var exp1 = from i in MD5Data
select new KeyValuePair<string, string>(i.Key.Replace(Path.DirectorySeparatorChar, '/'), i.Value);
sw.Write(JsonSerializer.Serialize(exp1.ToDictionary<string, string>()));
FileData.Data = exp1.ToDictionary();
sw.Write(JsonSerializer.Serialize(FileData));
sw.Flush();
}
}
Expand Down Expand Up @@ -362,14 +392,15 @@ public static bool IsUserFile(string filename)
return false;
}

public static int CountFile(string folder)
public static int CountFile(string folder, string? root = null)
{
int result = (from f in Directory.EnumerateDirectories(folder)
where !IsUserFile(f)
int result = (from f in Directory.EnumerateFiles(folder)
let t = Helper.ConvertAbsToRel(root ?? folder, f)
where !IsUserFile(t)
select f).Count();
foreach (var d in Directory.EnumerateDirectories(folder))
{
result += CountFile(d);
result += CountFile(d, root ?? folder);
}
return result;
}
Expand Down

0 comments on commit 4cfc0c2

Please sign in to comment.