Skip to content

Commit

Permalink
Merge branch 'dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ONLOX authored Mar 9, 2024
2 parents aa05ce6 + 5557774 commit 0bfa3e9
Show file tree
Hide file tree
Showing 11 changed files with 231 additions and 103 deletions.
13 changes: 12 additions & 1 deletion installer/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using Microsoft.Extensions.Logging;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using CommunityToolkit.Maui;
using CommunityToolkit.Maui.Core;
using CommunityToolkit.Maui.Storage;
using installer.ViewModel;
using System.Runtime.CompilerServices;
using installer.Model;

namespace installer
Expand All @@ -18,6 +19,16 @@ public static class MauiProgram
public static string SecretKey = "***";
public static MauiApp CreateMauiApp()
{

// read SecretID & SecretKey from filePath for debug
var filePath = @"D:\SecretKey.csv";
var lines = File.ReadAllLines(filePath);
if (lines.Length > 0)
{
SecretID = lines[1];
SecretKey = lines[2];
}

var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
Expand Down
16 changes: 8 additions & 8 deletions installer/Model/Downloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ public void UpdateMD5()
/// </summary>
public void Install()
{
Data.Installed = false;
UpdateMD5();
if (Status == UpdateStatus.error) return;

Expand All @@ -215,14 +216,6 @@ public void Install()
action = deleteTask;
deleteTask(new DirectoryInfo(Data.InstallPath));

Data.Installed = false;
string zp = Path.Combine(Data.InstallPath, "THUAI7.tar.gz");
Status = UpdateStatus.downloading;
Cloud.DownloadFileAsync(zp, "THUAI7.tar.gz").Wait();
Status = UpdateStatus.unarchieving;
Cloud.ArchieveUnzip(zp, Data.InstallPath);
File.Delete(zp);

Data.ResetInstallPath(Data.InstallPath);
Cloud.Log = LoggerProvider.FromFile(Path.Combine(Data.LogPath, "TencentCos.log"));
Cloud.LogError = LoggerProvider.FromFile(Path.Combine(Data.LogPath, "TencentCos.error.log"));
Expand All @@ -235,6 +228,13 @@ public void Install()
Exceptions = new ExceptionStack(LogError, this);
LoggerBinding();

string zp = Path.Combine(Data.InstallPath, "THUAI7.tar.gz");
Status = UpdateStatus.downloading;
Cloud.DownloadFileAsync(zp, "THUAI7.tar.gz").Wait();
Status = UpdateStatus.unarchieving;
Cloud.ArchieveUnzip(zp, Data.InstallPath);
File.Delete(zp);

Status = UpdateStatus.hash_computing;
Data.ScanDir();
if (Data.MD5Update.Count != 0)
Expand Down
47 changes: 30 additions & 17 deletions installer/Model/Local_Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,23 +183,6 @@ public void ResetInstallPath(string newPath)
}
}

public static bool IsUserFile(string filename)
{
if (filename.Contains("git") || filename.Contains("bin") || filename.Contains("obj"))
return true;
if (filename.EndsWith("sh") || filename.EndsWith("cmd"))
return true;
if (filename.EndsWith("gz"))
return true;
if (filename.Contains("AI.cpp") || filename.Contains("AI.py"))
return true;
if (filename.Contains("hash.json"))
return true;
if (filename.EndsWith("log"))
return true;
return false;
}

public void ReadConfig()
{
try
Expand Down Expand Up @@ -360,5 +343,35 @@ public void ScanDir()
});
SaveMD5Data();
}


public static bool IsUserFile(string filename)
{
if (filename.Contains("git") || filename.Contains("bin") || filename.Contains("obj"))
return true;
if (filename.EndsWith("sh") || filename.EndsWith("cmd"))
return true;
if (filename.EndsWith("gz"))
return true;
if (filename.Contains("AI.cpp") || filename.Contains("AI.py"))
return true;
if (filename.Contains("hash.json"))
return true;
if (filename.EndsWith("log"))
return true;
return false;
}

public static int CountFile(string folder)
{
int result = (from f in Directory.EnumerateDirectories(folder)
where !IsUserFile(f)
select f).Count();
foreach (var d in Directory.EnumerateDirectories(folder))
{
result += CountFile(d);
}
return result;
}
}
}
52 changes: 33 additions & 19 deletions installer/Page/InstallPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,7 @@
<VerticalStackLayout
HorizontalOptions="Center"
WidthRequest="600">
<HorizontalStackLayout>
<Button
WidthRequest="400"
Text="下载"
IsEnabled="{Binding InstallEnabled}"
Command="{Binding DownloadBtnClickedCommand}"
BackgroundColor="{Binding ConstBackgroundColor}"
FontSize="{Binding ConstFontSize}"
TextColor="{Binding ConstTextColor}"/>
<Button
WidthRequest="200"
Text="检查更新"
IsEnabled="{Binding CheckEnabled}"
Command="{Binding CheckUpdBtnClickedCommand}"
BackgroundColor="{Binding ConstBackgroundColor}"
FontSize="{Binding ConstFontSize}"
TextColor="{Binding ConstTextColor}"/>
</HorizontalStackLayout>

<HorizontalStackLayout>
<Label
WidthRequest="100"
Expand All @@ -39,13 +22,44 @@
ReturnCommand="{Binding DownloadBtnClickedCommand}"
FontSize="16"/>
<Button
WidthRequest="100"
Text="选择文件夹"
Command="{Binding BrowseBtnClickedCommand}"
IsEnabled="{Binding BrowseEnabled}"
BackgroundColor="{Binding ConstBackgroundColor}"
TextColor="{Binding ConstTextColor}"/>
</HorizontalStackLayout>
<Button
Text="下载"
Command="{Binding DownloadBtnClickedCommand}"
IsEnabled="{Binding DownloadEnabled}"
BackgroundColor="{Binding ConstBackgroundColor}"
FontSize="{Binding ConstFontSize}"
TextColor="{Binding ConstTextColor}"/>
<HorizontalStackLayout>
<Button
WidthRequest="200"
Text="检查更新"
Command="{Binding CheckUpdBtnClickedCommand}"
IsEnabled="{Binding CheckEnabled}"
BackgroundColor="{Binding ConstBackgroundColor}"
FontSize="{Binding ConstFontSize}"
TextColor="{Binding ConstTextColor}"/>
<Button
WidthRequest="400"
Text="更新"
Command="{Binding UpdateBtnClickedCommand}"
IsEnabled="{Binding UpdateEnabled}"
BackgroundColor="{Binding ConstBackgroundColor}"
FontSize="{Binding ConstFontSize}"
TextColor="{Binding ConstTextColor}"/>
</HorizontalStackLayout>
<Label
Text="{Binding DebugAlert1}"/>
<Label
Text="{Binding DebugAlert2}"/>
<Label
Text="{Binding DebugAlert}"/>
Text="{Binding DebugAlert3}"/>
</VerticalStackLayout>

</ContentPage>
3 changes: 2 additions & 1 deletion installer/Page/LaunchPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
<Label
Text="敬请期待"
VerticalOptions="Center"
HorizontalOptions="Center"/>
HorizontalOptions="Center"
FontSize="24"/>
</VerticalStackLayout>

</ContentPage>
Loading

0 comments on commit 0bfa3e9

Please sign in to comment.