Browse Source

Merge pull request #465 from Timothy-Liuxf/fix/installer

fix(client): 🚨 fix window size and remove compiler warnings
tags/0.1.0
shangfengh GitHub 2 years ago
parent
commit
efb7b3ba36
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 142 additions and 122 deletions
  1. +16
    -16
      installer/Installer/Common.cs
  2. +3
    -1
      installer/Installer/MainWindow.xaml
  3. +71
    -60
      installer/Installer/Model.cs
  4. +35
    -34
      installer/Installer/ViewModel.cs
  5. +3
    -1
      installer/InstallerUpdater/MainWindow.xaml
  6. +14
    -10
      installer/InstallerUpdater/Program.cs

+ 16
- 16
installer/Installer/Common.cs View File

@@ -10,7 +10,7 @@ namespace starter.viewmodel.common
{
public abstract class NotificationObject : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public event PropertyChangedEventHandler? PropertyChanged;
///< summary>
/// announce notification
/// </summary>
@@ -25,21 +25,21 @@ namespace starter.viewmodel.common
/// </summary>
public class BaseCommand : ICommand
{
private Func<object, bool> _canExecute;
private Action<object> _execute;
private Func<object?, bool>? _canExecute;
private Action<object?> _execute;

public BaseCommand(Func<object, bool> canExecute, Action<object> execute)
public BaseCommand(Func<object?, bool>? canExecute, Action<object?> execute)
{
_canExecute = canExecute;
_execute = execute;
}

public BaseCommand(Action<object> execute) :
public BaseCommand(Action<object?> execute) :
this(null, execute)
{
}

public event EventHandler CanExecuteChanged
public event EventHandler? CanExecuteChanged
{
add
{
@@ -57,12 +57,12 @@ namespace starter.viewmodel.common
}
}

public bool CanExecute(object parameter)
public bool CanExecute(object? parameter)
{
return _canExecute == null ? true : _canExecute(parameter);
}

public void Execute(object parameter)
public void Execute(object? parameter)
{
if (_execute != null && CanExecute(parameter))
{
@@ -79,15 +79,15 @@ namespace starter.viewmodel.common
{
return false;
}
string checkvalue = value.ToString();
string targetvalue = parameter.ToString();
string checkvalue = value.ToString() ?? "";
string targetvalue = parameter.ToString() ?? "";
bool r = checkvalue.Equals(targetvalue);
return r;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value == null || parameter == null)
if (value is null || parameter is null)
{
return null;
}
@@ -132,22 +132,22 @@ namespace starter.viewmodel.common
static bool _isUpdating = false;
private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
PasswordBox pb = d as PasswordBox;
PasswordBox pb = (d as PasswordBox)!;
pb.PasswordChanged -= Pb_PasswordChanged;
if (!_isUpdating)
(d as PasswordBox).Password = e.NewValue.ToString();
(d as PasswordBox)!.Password = e.NewValue.ToString();
pb.PasswordChanged += Pb_PasswordChanged;
}

private static void OnAttachChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
PasswordBox pb = d as PasswordBox;
PasswordBox pb = (d as PasswordBox)!;
pb.PasswordChanged += Pb_PasswordChanged;
}

private static void Pb_PasswordChanged(object sender, RoutedEventArgs e)
{
PasswordBox pb = sender as PasswordBox;
PasswordBox pb = (sender as PasswordBox)!;
_isUpdating = true;
SetPassword(pb, pb.Password);
_isUpdating = false;


+ 3
- 1
installer/Installer/MainWindow.xaml View File

@@ -5,7 +5,9 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Installer" xmlns:c="clr-namespace:starter.viewmodel.common"
mc:Ignorable="d"
Title="Installer" Window.SizeToContent="WidthAndHeight">
Title="Installer" Window.SizeToContent="WidthAndHeight"
ResizeMode="CanMinimize"
>
<Window.Resources>
<c:RadioConverter x:Key="RadioConverter"/>
</Window.Resources>


+ 71
- 60
installer/Installer/Model.cs View File

@@ -21,7 +21,6 @@ using System.Net.Http;
using System.Windows;
using System.Windows.Shapes;
//using System.Windows.Forms;
using System.Threading.Tasks;
using System.Threading;

using MessageBox = System.Windows.MessageBox;
@@ -153,18 +152,22 @@ namespace starter.viewmodel.settings
}
public bool RecallUser()
{
Username = Web.ReadJson("email");
if (Username == null || Username.Equals(""))
var username = Web.ReadJson("email");
if (username == null || username.Equals(""))
{
Username = "";
return false;
}
Password = Web.ReadJson("password");
if (Password == null || Username.Equals(""))
Username = username;

var password = Web.ReadJson("password");
if (password == null || password.Equals(""))
{
Password = "";
return false;
}
Password = password;

return true;
}
public bool ForgetUser()
@@ -210,8 +213,6 @@ namespace starter.viewmodel.settings
switch (CodeRoute.Substring(CodeRoute.LastIndexOf('.') + 1))
{
case "cpp":
Language = "cpp";
break;
case "h":
Language = "cpp";
break;
@@ -244,15 +245,12 @@ namespace starter.viewmodel.settings
}
public UsingOS ReadUsingOS()
{
string OS = Web.ReadJson("OS");
if (OS == null)
return UsingOS.Win;
else if (OS.Equals("linux"))
return UsingOS.Linux;
else if (OS.Equals("osx"))
return UsingOS.OSX;
else
return UsingOS.Win;
return Web.ReadJson("OS") switch
{
"linux" => UsingOS.Linux,
"osx" => UsingOS.OSX,
_ => UsingOS.Win,
};
}
/// <summary>
/// Route of files
@@ -274,7 +272,7 @@ namespace starter.viewmodel.settings
{
get; set;
}
public string Language
public string? Language
{
get; set;
}
@@ -411,7 +409,7 @@ namespace Downloader
{
json += @"{""THUAI6""" + ":" + @"""2023""}";
}
dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
dict = Utils.DeserializeJson<Dictionary<string, string>>(json);
if (dict != null && dict.ContainsKey("installpath"))
{
FilePath = dict["installpath"].Replace('\\', '/');
@@ -425,11 +423,12 @@ namespace Downloader
}
else
{
FilePath = System.IO.Path.GetDirectoryName(@path);
FilePath = System.IO.Path.GetDirectoryName(@path)
?? throw new Exception("Fail to find the path of the file");

//将dat文件写入程序运行路径
string json;
Dictionary<string, string> dict = new Dictionary<string, string>();
Dictionary<string, string>? dict;
using FileStream fs = new FileStream(Data.path, FileMode.Create, FileAccess.ReadWrite);
using (StreamReader r = new StreamReader(fs))
{
@@ -438,7 +437,7 @@ namespace Downloader
{
json += @"{""THUAI6""" + ":" + @"""2023""}";
}
dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
dict = Utils.DeserializeJson<Dictionary<string, string>>(json);
dict?.Add("installpath", path);
}
using FileStream fs2 = new FileStream(Data.path, FileMode.Create, FileAccess.ReadWrite);
@@ -451,7 +450,7 @@ namespace Downloader
public static void ResetFilepath(string newPath)
{
string json;
Dictionary<string, string> dict = new Dictionary<string, string>();
Dictionary<string, string>? dict;
FilePath = newPath.Replace('\\', '/');
path = System.IO.Path.Combine(dataPath, "THUAI6.json");
using FileStream fs = new FileStream(Data.path, FileMode.Create, FileAccess.ReadWrite);
@@ -462,14 +461,14 @@ namespace Downloader
{
json += @"{""THUAI6""" + ":" + @"""2023""}";
}
dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
dict = Utils.DeserializeJson<Dictionary<string, string>>(json);
if (dict != null && dict.ContainsKey("installpath"))
{
dict["installpath"] = newPath;
}
else
{
dict.Add("installpath", newPath);
dict?.Add("installpath", newPath);
}
if (dict == null || !dict.ContainsKey("download"))
{
@@ -517,9 +516,10 @@ namespace Downloader
// 创建存储桶
try
{
string bucket = "thuai6-1314234950"; // 格式:BucketName-APPID
string localDir = System.IO.Path.GetDirectoryName(download_dir); // 本地文件夹
string localFileName = System.IO.Path.GetFileName(download_dir); // 指定本地保存的文件名
string bucket = "thuai6-1314234950"; // 格式:BucketName-APPID
string localDir = System.IO.Path.GetDirectoryName(download_dir) // 本地文件夹
?? throw new Exception("本地文件夹路径获取失败");
string localFileName = System.IO.Path.GetFileName(download_dir); // 指定本地保存的文件名
GetObjectRequest request = new GetObjectRequest(bucket, key, localDir, localFileName);

Dictionary<string, string> test = request.GetRequestHeaders();
@@ -553,7 +553,7 @@ namespace Downloader

public static string GetFileMd5Hash(string strFileFullPath)
{
FileStream fst = null;
FileStream? fst = null;
try
{
fst = new FileStream(strFileFullPath, FileMode.Open, FileAccess.Read);
@@ -634,7 +634,7 @@ namespace Downloader
using (StreamReader r = new StreamReader(System.IO.Path.Combine(Data.FilePath, jsonName)))
json = r.ReadToEnd();
json = json.Replace("\r", string.Empty).Replace("\n", string.Empty);
Dictionary<string, string> jsonDict = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
Dictionary<string, string> jsonDict = Utils.DeserializeJson<Dictionary<string, string>>(json);
string updatingFolder = "";
switch (OS)
{
@@ -815,7 +815,7 @@ namespace Downloader
{
json += @"{""THUAI6""" + ":" + @"""2023""}";
}
var dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
var dict = Utils.DeserializeJson<Dictionary<string, string>>(json);
if (dict == null || !dict.ContainsKey("download") || "false" == dict["download"])
{
return false;
@@ -865,15 +865,15 @@ namespace Downloader
using (StreamReader r = new StreamReader(System.IO.Path.Combine(Data.FilePath, jsonName)))
json = r.ReadToEnd();
json = json.Replace("\r", string.Empty).Replace("\n", string.Empty);
Dictionary<string, string> jsonDict = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
Dictionary<string, string> jsonDict = Utils.DeserializeJson<Dictionary<string, string>>(json);

newFileName.Clear();
updateFileName.Clear();
newFileName.Add("THUAI6.tar.gz");
Download();
Stream inStream = null;
Stream gzipStream = null;
TarArchive tarArchive = null;
Stream? inStream = null;
Stream? gzipStream = null;
TarArchive? tarArchive = null;
try
{
using (inStream = File.OpenRead(System.IO.Path.Combine(Data.FilePath, "THUAI6.tar.gz")))
@@ -886,7 +886,7 @@ namespace Downloader
}
}
}
catch (Exception ex)
catch
{
//出错
}
@@ -909,7 +909,7 @@ namespace Downloader
{
json2 += @"{""THUAI6""" + ":" + @"""2023""}";
}
dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(json2);
dict = Utils.DeserializeJson<Dictionary<string, string>>(json2);
if (dict == null || !dict.ContainsKey("download"))
{
dict?.Add("download", "true");
@@ -1000,7 +1000,7 @@ namespace Downloader
using (StreamReader r = new StreamReader(System.IO.Path.Combine(Data.FilePath, "hash.json")))
json = r.ReadToEnd();
json = json.Replace("\r", string.Empty).Replace("\n", string.Empty).Replace("/", @"\\");
Dictionary<string, string> jsonDict = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
Dictionary<string, string> jsonDict = Utils.DeserializeJson<Dictionary<string, string>>(json);
Change_all_hash(Data.FilePath, jsonDict);
OverwriteHash(jsonDict);
break;
@@ -1008,7 +1008,7 @@ namespace Downloader
else
{
Console.WriteLine("读取路径失败!请重新输入文件路径:");
Data.ResetFilepath(Console.ReadLine());
Data.ResetFilepath(Console.ReadLine() ?? "");
}
}
}
@@ -1068,7 +1068,7 @@ namespace Downloader
{
json2 += @"{""THUAI6""" + ":" + @"""2023""}";
}
dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(json2);
dict = Utils.DeserializeJson<Dictionary<string, string>>(json2);
if (dict == null || !dict.ContainsKey("download"))
{
dict?.Add("download", "false");
@@ -1189,7 +1189,7 @@ namespace Downloader
while (true)
{
Console.WriteLine($"1. 更新hash.json 2. 检查更新 3.下载{ProgramName} 4.删除{ProgramName} 5.启动进程 6.移动{ProgramName}到其它路径");
string choose = Console.ReadLine();
string choose = Console.ReadLine() ?? "";
if (choose == "1")
{
if (!CheckAlreadyDownload())
@@ -1216,7 +1216,7 @@ namespace Downloader
else
{
Console.WriteLine("读取路径失败!请重新输入文件路径:");
Data.ResetFilepath(Console.ReadLine());
Data.ResetFilepath(Console.ReadLine() ?? "");
}
}
}
@@ -1230,7 +1230,7 @@ namespace Downloader
{
string newpath;
Console.WriteLine("请输入下载路径:");
newpath = Console.ReadLine();
newpath = Console.ReadLine() ?? "";
Data.ResetFilepath(newpath);
DownloadAll();
}
@@ -1253,15 +1253,15 @@ namespace Downloader
else if (choose == "6")
{
string newPath;
newPath = Console.ReadLine();
newPath = Console.ReadLine() ?? "";
MoveProgram(newPath);
}
else if (choose == "7")
{
Console.WriteLine("请输入email:");
string username = Console.ReadLine();
string username = Console.ReadLine() ?? "";
Console.WriteLine("请输入密码:");
string password = Console.ReadLine();
string password = Console.ReadLine() ?? "";

await web.LoginToEEsast(client, username, password);
}
@@ -1285,7 +1285,8 @@ namespace Downloader
string keyHead = "Installer/";
Tencent_cos_download downloader = new Tencent_cos_download();
string hashName = "installerHash.json";
string dir = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
string dir = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule?.FileName)
?? throw new Exception("Failed to get current directory");
int result = 0;
try
{
@@ -1301,7 +1302,7 @@ namespace Downloader
using (StreamReader r = new StreamReader(System.IO.Path.Combine(dir, hashName)))
json = r.ReadToEnd();
json = json.Replace("\r", string.Empty).Replace("\n", string.Empty);
Dictionary<string, string> jsonDict = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
Dictionary<string, string> jsonDict = Utils.DeserializeJson<Dictionary<string, string>>(json);
string md5 = "";
List<string> awaitUpdate = new List<string>();
if (jsonDict != null)
@@ -1343,7 +1344,8 @@ namespace Downloader
static public bool SelfUpdateDismissed()
{
string json;
string dir = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
string dir = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule?.FileName)
?? throw new Exception("Failed to get directory!");
if (!File.Exists(System.IO.Path.Combine(dir, "updateList.json")))
return false;
using (StreamReader r = new StreamReader(System.IO.Path.Combine(dir, "updateList.json")))
@@ -1351,7 +1353,7 @@ namespace Downloader
json = json.Replace("\r", string.Empty).Replace("\n", string.Empty);
List<string> jsonList;
if (json != null)
jsonList = JsonConvert.DeserializeObject<List<string>>(json);
jsonList = Utils.DeserializeJson<List<string>>(json);
else
return false;
if (jsonList != null && jsonList.Contains("Dismiss"))
@@ -1403,7 +1405,7 @@ namespace WebConnect
throw new Exception("no token!");
logintoken = token;
SaveToken();
var info = JsonConvert.DeserializeObject<Dictionary<string, string>>(await response.Content.ReadAsStringAsync());
var info = Utils.DeserializeJson<Dictionary<string, string>>(await response.Content.ReadAsStringAsync());
Downloader.UserInfo._id = info["_id"];
Downloader.UserInfo.email = info["email"];
break;
@@ -1459,7 +1461,7 @@ namespace WebConnect
{
case System.Net.HttpStatusCode.OK:

var res = JsonConvert.DeserializeObject<Dictionary<string, string>>(await response.Content.ReadAsStringAsync());
var res = Utils.DeserializeJson<Dictionary<string, string>>(await response.Content.ReadAsStringAsync());
string appid = "1255334966"; // 设置腾讯云账户的账户标识(APPID)
string region = "ap-beijing"; // 设置一个默认的存储桶地域
CosXmlConfig config = new CosXmlConfig.Builder()
@@ -1584,12 +1586,12 @@ namespace WebConnect
{
json += @"{""THUAI6""" + ":" + @"""2023""}";
}
dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
dict = Utils.DeserializeJson<Dictionary<string, string>>(json);
if (dict.ContainsKey("token"))
{
dict.Remove("token");
}
dict?.Add("token", logintoken);
dict.Add("token", logintoken);
}
using FileStream fs2 = new FileStream(savepath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
using StreamWriter sw = new StreamWriter(fs2);
@@ -1627,7 +1629,7 @@ namespace WebConnect
json += @"{""THUAI6""" + ":" + @"""2023""}";
}
Dictionary<string, string> dict = new Dictionary<string, string>();
dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
dict = Utils.DeserializeJson<Dictionary<string, string>>(json);
if (!dict.ContainsKey(key))
{
dict.Add(key, data);
@@ -1651,7 +1653,7 @@ namespace WebConnect
}
}

public static string ReadJson(string key)
public static string? ReadJson(string key)
{
try
{
@@ -1664,7 +1666,7 @@ namespace WebConnect
{
json += @"{""THUAI6""" + ":" + @"""2023""}";
}
dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
dict = Utils.DeserializeJson<Dictionary<string, string>>(json);
fs.Close();
sr.Close();
return dict[key];
@@ -1691,7 +1693,7 @@ namespace WebConnect
{
json += @"{""THUAI6""" + ":" + @"""2023""}";
}
dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
dict = Utils.DeserializeJson<Dictionary<string, string>>(json);
if (!dict.ContainsKey("token"))
{
return false;
@@ -1745,9 +1747,9 @@ namespace WebConnect
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
var info = await response.Content.ReadAsStringAsync();
var s1 = JsonConvert.DeserializeObject<Dictionary<string, object>>(info)["data"];
var s2 = JsonConvert.DeserializeObject<Dictionary<string, List<object>>>(s1.ToString())["contest_team_member"];
var sres = JsonConvert.DeserializeObject<Dictionary<string, string>>(s2[0].ToString())["team_id"];
var s1 = Utils.DeserializeJson<Dictionary<string, object>>(info)["data"];
var s2 = Utils.DeserializeJson<Dictionary<string, List<object>>>(s1.ToString() ?? "")["contest_team_member"];
var sres = Utils.DeserializeJson<Dictionary<string, string>>(s2[0].ToString() ?? "")["team_id"];
return sres;
}
async public Task<string> GetUserId(string learnNumber)
@@ -1773,4 +1775,13 @@ namespace WebConnect
public string Token { get; set; } = "";
}

internal static class Utils
{
public static T DeserializeJson<T>(string json)
{
return JsonConvert.DeserializeObject<T>(json)
?? throw new Exception("Failed to deserialize json.");
}
}

}

+ 35
- 34
installer/Installer/ViewModel.cs View File

@@ -36,14 +36,15 @@ namespace starter.viewmodel.settings
//Program.Tencent_cos_download.UpdateHash();

Status = SettingsModel.Status.working;
string CurrentDirectory = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
string currentDirectory = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule?.FileName)
?? throw new Exception("Fail to get current directory");
//MessageBox.Show("更新器工作正常");
if (!Program.Tencent_cos_download.SelfUpdateDismissed())
{
switch (Program.Tencent_cos_download.CheckSelfVersion())
{
case 1:
Process.Start(System.IO.Path.Combine(CurrentDirectory, "InstallerUpdater.exe"));
Process.Start(System.IO.Path.Combine(currentDirectory, "InstallerUpdater.exe"));
Environment.Exit(0);
break;
case -1:
@@ -156,7 +157,7 @@ namespace starter.viewmodel.settings
{
e.Cancel = true;
MessageBox.Show("下载取消");
if (e.Argument.ToString().Equals("Manual"))
if (e.Argument?.ToString()?.Equals("Manual") ?? false)
{
Status = SettingsModel.Status.menu;
}
@@ -167,7 +168,7 @@ namespace starter.viewmodel.settings
else
{
if (obj.Update())
if (e.Argument.ToString().Equals("Manual"))
if (e.Argument?.ToString()?.Equals("Manual") ?? false)
{
e.Result = 1;
}
@@ -598,14 +599,14 @@ namespace starter.viewmodel.settings
return "";
}

private BaseCommand clickBrowseCommand;
private BaseCommand? clickBrowseCommand;
public BaseCommand ClickBrowseCommand
{
get
{
if (clickBrowseCommand == null)
{
clickBrowseCommand = new BaseCommand(new Action<object>(o =>
clickBrowseCommand = new BaseCommand(new Action<object?>(o =>
{
Route = RouteSelectWindow("Folder");
}));
@@ -613,14 +614,14 @@ namespace starter.viewmodel.settings
return clickBrowseCommand;
}
}
private BaseCommand clickConfirmCommand;
private BaseCommand? clickConfirmCommand;
public BaseCommand ClickConfirmCommand
{
get
{
if (clickConfirmCommand == null)
{
clickConfirmCommand = new BaseCommand(new Action<object>(o =>
clickConfirmCommand = new BaseCommand(new Action<object?>(o =>
{
if (Status == SettingsModel.Status.newUser)
{
@@ -672,14 +673,14 @@ namespace starter.viewmodel.settings
return clickConfirmCommand;
}
}
private BaseCommand clickUpdateCommand;
private BaseCommand? clickUpdateCommand;
public BaseCommand ClickUpdateCommand
{
get
{
if (clickUpdateCommand == null)
{
clickUpdateCommand = new BaseCommand(new Action<object>(o =>
clickUpdateCommand = new BaseCommand(new Action<object?>(o =>
{
this.RaisePropertyChanged("UpdateInfoVis");
if (obj.UpdatePlanned)
@@ -719,14 +720,14 @@ namespace starter.viewmodel.settings
return clickUpdateCommand;
}
}
private BaseCommand clickMoveCommand;
private BaseCommand? clickMoveCommand;
public BaseCommand ClickMoveCommand
{
get
{
if (clickMoveCommand == null)
{
clickMoveCommand = new BaseCommand(new Action<object>(o =>
clickMoveCommand = new BaseCommand(new Action<object?>(o =>
{
Status = SettingsModel.Status.move;
}));
@@ -734,14 +735,14 @@ namespace starter.viewmodel.settings
return clickMoveCommand;
}
}
private BaseCommand clickUninstCommand;
private BaseCommand? clickUninstCommand;
public BaseCommand ClickUninstCommand
{
get
{
if (clickUninstCommand == null)
{
clickUninstCommand = new BaseCommand(new Action<object>(o =>
clickUninstCommand = new BaseCommand(new Action<object?>(o =>
{
UpdateInfoVis = Visibility.Collapsed;
this.RaisePropertyChanged("UpdateInfoVis");
@@ -767,14 +768,14 @@ namespace starter.viewmodel.settings
}
}

private BaseCommand clickLoginCommand;
private BaseCommand? clickLoginCommand;
public BaseCommand ClickLoginCommand
{
get
{
if (clickLoginCommand == null)
{
clickLoginCommand = new BaseCommand(new Action<object>(async o =>
clickLoginCommand = new BaseCommand(new Action<object?>(async o =>
{
switch (await obj.Login())
{
@@ -813,14 +814,14 @@ namespace starter.viewmodel.settings
}
}

private BaseCommand clickLaunchCommand;
private BaseCommand? clickLaunchCommand;
public BaseCommand ClickLaunchCommand
{
get
{
if (clickLaunchCommand == null)
{
clickLaunchCommand = new BaseCommand(new Action<object>(o =>
clickLaunchCommand = new BaseCommand(new Action<object?>(o =>
{
if (obj.UpdatePlanned)
{
@@ -840,14 +841,14 @@ namespace starter.viewmodel.settings
return clickLaunchCommand;
}
}
private BaseCommand clickEditCommand;
private BaseCommand? clickEditCommand;
public BaseCommand ClickEditCommand
{
get
{
if (clickEditCommand == null)
{
clickEditCommand = new BaseCommand(new Action<object>(o =>
clickEditCommand = new BaseCommand(new Action<object?>(o =>
{
Status = SettingsModel.Status.menu;
if (obj.UpdatePlanned)
@@ -858,14 +859,14 @@ namespace starter.viewmodel.settings
return clickEditCommand;
}
}
private BaseCommand clickBackCommand;
private BaseCommand? clickBackCommand;
public BaseCommand ClickBackCommand
{
get
{
if (clickBackCommand == null)
{
clickBackCommand = new BaseCommand(new Action<object>(o =>
clickBackCommand = new BaseCommand(new Action<object?>(o =>
{
UpdateInfoVis = Visibility.Collapsed;
this.RaisePropertyChanged("UpdateInfoVis");
@@ -878,14 +879,14 @@ namespace starter.viewmodel.settings
return clickBackCommand;
}
}
private BaseCommand clickUploadCommand;
private BaseCommand? clickUploadCommand;
public BaseCommand ClickUploadCommand
{
get
{
if (clickUploadCommand == null)
{
clickUploadCommand = new BaseCommand(new Action<object>(async o =>
clickUploadCommand = new BaseCommand(new Action<object?>(async o =>
{
if (obj.UploadReady)
{
@@ -953,14 +954,14 @@ namespace starter.viewmodel.settings
return clickUploadCommand;
}
}
private BaseCommand clickAboutUploadCommand;
private BaseCommand? clickAboutUploadCommand;
public BaseCommand ClickAboutUploadCommand
{
get
{
if (clickAboutUploadCommand == null)
{
clickAboutUploadCommand = new BaseCommand(new Action<object>(o =>
clickAboutUploadCommand = new BaseCommand(new Action<object?>(o =>
{
if (obj.UploadReady)
{
@@ -987,14 +988,14 @@ namespace starter.viewmodel.settings
return clickAboutUploadCommand;
}
}
private BaseCommand clickExitCommand;
private BaseCommand? clickExitCommand;
public BaseCommand ClickExitCommand
{
get
{
if (clickExitCommand == null)
{
clickExitCommand = new BaseCommand(new Action<object>(o =>
clickExitCommand = new BaseCommand(new Action<object?>(o =>
{
Application.Current.Shutdown();
}));
@@ -1002,14 +1003,14 @@ namespace starter.viewmodel.settings
return clickExitCommand;
}
}
private BaseCommand clickShiftLanguageCommand;
private BaseCommand? clickShiftLanguageCommand;
public BaseCommand ClickShiftLanguageCommand
{
get
{
if (clickShiftLanguageCommand == null)
{
clickShiftLanguageCommand = new BaseCommand(new Action<object>(o =>
clickShiftLanguageCommand = new BaseCommand(new Action<object?>(o =>
{
if (obj.launchLanguage == SettingsModel.LaunchLanguage.cpp)
obj.launchLanguage = SettingsModel.LaunchLanguage.python;
@@ -1023,14 +1024,14 @@ namespace starter.viewmodel.settings
return clickShiftLanguageCommand;
}
}
private BaseCommand clickReadCommand;
private BaseCommand? clickReadCommand;
public BaseCommand ClickReadCommand
{
get
{
if (clickReadCommand == null)
{
clickReadCommand = new BaseCommand(new Action<object>(o =>
clickReadCommand = new BaseCommand(new Action<object?>(o =>
{
if (!Directory.Exists(Route + "/THUAI6/win"))
{
@@ -1050,14 +1051,14 @@ namespace starter.viewmodel.settings
return clickReadCommand;
}
}
private BaseCommand clickSwitchOSCommand;
private BaseCommand? clickSwitchOSCommand;
public BaseCommand ClickSwitchOSCommand
{
get
{
if (clickSwitchOSCommand == null)
{
clickSwitchOSCommand = new BaseCommand(new Action<object>(o =>
clickSwitchOSCommand = new BaseCommand(new Action<object?>(o =>
{
switch (obj.usingOS)
{


+ 3
- 1
installer/InstallerUpdater/MainWindow.xaml View File

@@ -5,7 +5,9 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:InstallerUpdater"
mc:Ignorable="d"
Title="MainWindow" Height="180" Width="300">
Title="MainWindow" Height="180" Width="300"
ResizeMode="CanMinimize"
>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="40"/>


+ 14
- 10
installer/InstallerUpdater/Program.cs View File

@@ -18,7 +18,8 @@ namespace Program
{
class Updater
{
public static string Dir = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
public static string Dir = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule?.FileName)
?? throw new Exception("Cannot get current directory");
public static string InstallerName = "Installer.exe";
public static string jsonKey = "installerHash.json";
public static string KeyHead = "Installer/";
@@ -31,7 +32,8 @@ namespace Program
using (StreamReader r = new StreamReader(System.IO.Path.Combine(Dir, "updateList.json")))
json = r.ReadToEnd();
json = json.Replace("\r", string.Empty).Replace("\n", string.Empty);
List<string> jsonList = JsonConvert.DeserializeObject<List<string>>(json);
List<string> jsonList = JsonConvert.DeserializeObject<List<string>>(json)
?? throw new Exception("Failed to deserialize json!");
foreach (string todo in jsonList)
{
if (!todo.Equals("None"))
@@ -41,14 +43,14 @@ namespace Program
}
}
}
catch (IOException)
catch (IOException ex)
{
MessageBox.Show("下载器本体未能成功关闭");
MessageBox.Show($"下载器本体未能成功关闭:\n{ex}");
return false;
}
catch
catch (Exception ex)
{
MessageBox.Show("尝试下载时出现问题");
MessageBox.Show($"尝试下载时出现问题:\n{ex}\n{ex.StackTrace}");
return false;
}
return true;
@@ -67,7 +69,8 @@ namespace Program
json += @"{""None""}";
}
List<string> ls = new List<string>();
ls = JsonConvert.DeserializeObject<List<string>>(json);
ls = JsonConvert.DeserializeObject<List<string>>(json)
?? throw new Exception("Failed to deserialize json!");
if (!ls.Contains("Dismiss"))
{
ls.Add("Dismiss");
@@ -114,9 +117,10 @@ namespace Program
// 创建存储桶
try
{
string bucket = "thuai6-1314234950"; // 格式:BucketName-APPID
string localDir = System.IO.Path.GetDirectoryName(download_dir); // 本地文件夹
string localFileName = System.IO.Path.GetFileName(download_dir); // 指定本地保存的文件名
string bucket = "thuai6-1314234950"; // 格式:BucketName-APPID
string localDir = System.IO.Path.GetDirectoryName(download_dir) // 本地文件夹
?? throw new Exception("Failed to get directory name!");
string localFileName = System.IO.Path.GetFileName(download_dir); // 指定本地保存的文件名
GetObjectRequest request = new GetObjectRequest(bucket, key, localDir, localFileName);

Dictionary<string, string> test = request.GetRequestHeaders();


Loading…
Cancel
Save