| @@ -5,16 +5,17 @@ | |||||
| xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||||
| xmlns:local="clr-namespace:Installer" | xmlns:local="clr-namespace:Installer" | ||||
| mc:Ignorable="d" | mc:Ignorable="d" | ||||
| Title="Installer" Height="450" Width="800"> | |||||
| Title="Installer" Height="200" Window.SizeToContent="Width"> | |||||
| <Grid> | <Grid> | ||||
| <Grid.ColumnDefinitions> | <Grid.ColumnDefinitions> | ||||
| <ColumnDefinition Width="40" /> | <ColumnDefinition Width="40" /> | ||||
| <ColumnDefinition Width="75" /> | <ColumnDefinition Width="75" /> | ||||
| <ColumnDefinition Width="75" /> | <ColumnDefinition Width="75" /> | ||||
| <ColumnDefinition Width="250" /> | |||||
| <ColumnDefinition Width="75" /> | |||||
| <ColumnDefinition Width="75" /> | |||||
| <ColumnDefinition Width="*" /> | |||||
| <ColumnDefinition Width="50" /> | |||||
| <ColumnDefinition Width="25" /> | |||||
| <ColumnDefinition Width="50" /> | |||||
| <ColumnDefinition Width="1*" /> | |||||
| <ColumnDefinition Width="1*" /> | |||||
| <ColumnDefinition Width="40" /> | <ColumnDefinition Width="40" /> | ||||
| </Grid.ColumnDefinitions> | </Grid.ColumnDefinitions> | ||||
| <Grid.RowDefinitions> | <Grid.RowDefinitions> | ||||
| @@ -26,22 +27,44 @@ | |||||
| <RowDefinition Height="20" /> | <RowDefinition Height="20" /> | ||||
| <RowDefinition Height="20" /> | <RowDefinition Height="20" /> | ||||
| <RowDefinition Height="20" /> | <RowDefinition Height="20" /> | ||||
| <RowDefinition Height="*" /> | |||||
| <RowDefinition Height="20" /> | <RowDefinition Height="20" /> | ||||
| </Grid.RowDefinitions> | </Grid.RowDefinitions> | ||||
| <TextBlock Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" Text="欢迎使用选手包" Visibility="{Binding InstIntroVis}"/> | |||||
| <TextBlock Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" Text="你已经安装了选手包,请选择你要进行的操作" Visibility="{Binding EditIntroVis}"/> | |||||
| <TextBlock Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="5" Text="{Binding Intro}" /> | |||||
| <TextBlock Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="5" Text="{Binding RouteBoxIntro}"/> | |||||
| <TextBox Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="5" Name="RouteTxtBox" Text="{Binding Route}" Visibility="{Binding RouteBoxVis}"/> | |||||
| <Button Grid.Row="3" Grid.Column="6" Name="GetRouteBtn" Content="Browse..." Command="{Binding ClickBrowseCommand}" Visibility="{Binding RouteBoxVis}" /> | |||||
| <Button Grid.Row="3" Grid.Column="7" Name="SetBtm" Content="Confirm" Command="{Binding ClickConfirmCommand}" Visibility="{Binding RouteBoxVis}"/> | |||||
| <Button Grid.Row="3" Grid.Column="2" Grid.ColumnSpan="2" Name="UpdateBtn" Content="{Binding UpdateBtnCont}" Command="{Binding ClickUpdateCommand}" Visibility="{Binding MenuVis}" /> | |||||
| <Button Grid.Row="5" Grid.Column="2" Grid.ColumnSpan="2" Name="MoveBtn" Content="Move" Command="{Binding ClickMoveCommand}" Visibility="{Binding MenuVis}" /> | |||||
| <Button Grid.Row="7" Grid.Column="2" Grid.ColumnSpan="2" Name="UninstBtn" Content="UnInstall" Command="{Binding ClickUninstCommand}" Visibility="{Binding MenuVis}" /> | |||||
| <TextBlock Grid.Row="3" Grid.Column="4" Text="Processing" Grid.ColumnSpan="2" Visibility="{Binding ProgressVis}"/> | |||||
| <ProgressBar Grid.Row="5" Grid.Column="2" Grid.ColumnSpan="6" Minimum="0" Maximum="100" Name="Progress" Visibility="{Binding ProgressVis}" IsIndeterminate="True"/> | |||||
| <TextBlock Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="3" Text="将主体程序安装在:" Visibility="{Binding InstIntroVis}"/> | |||||
| <TextBlock Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="3" Text="将主体程序移动到:" Visibility="{Binding MoveIntroVis}"/> | |||||
| <TextBlock Grid.Row="4" Grid.Column="2" Grid.ColumnSpan="4" Text="操作完成!你可以继续操作或退出" Visibility="{Binding CompleteVis}"/> | |||||
| <Button Grid.Row="6" Grid.Column="2" Name="BackBtn" Content="返回" Command="{Binding ClickBackCommand}" Visibility="{Binding CompleteVis}"/> | |||||
| <Button Grid.Row="6" Grid.Column="4" Grid.ColumnSpan="2" Name="ExitBtn" Content="退出" Command="{Binding ClickExitCommand}" Visibility="{Binding CompleteVis}"/> | |||||
| <TextBox Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="3" Name="RouteTxtBox" Text="{Binding Route}" Visibility="{Binding RouteBoxVis}"/> | |||||
| <Button Grid.Row="3" Grid.Column="4" Name="GetRouteBtn" Content="Browse..." Command="{Binding ClickBrowseCommand}" Visibility="{Binding RouteBoxVis}" /> | |||||
| <Button Grid.Row="3" Grid.Column="5" Name="SetBtm" Content="Confirm" Command="{Binding ClickConfirmCommand}" Visibility="{Binding RouteBoxVis}"/> | |||||
| <Button Grid.Row="3" Grid.Column="2" Name="UpdateBtn" Content="Update" Command="{Binding ClickUpdateCommand}" Visibility="{Binding EditIntroVis}" /> | |||||
| <TextBlock Grid.Row="3" Grid.Column="1" Text="账号:" Visibility="{Binding LoginVis}" /> | |||||
| <TextBlock Grid.Row="5" Grid.Column="1" Text="密码:" Visibility="{Binding LoginVis}" /> | |||||
| <TextBox Grid.Row="3" Grid.Column="2" Grid.ColumnSpan="4" Name="Username" Visibility="{Binding LoginVis}" Text="{Binding Username}" /> | |||||
| <TextBox Grid.Row="5" Grid.Column="2" Grid.ColumnSpan="4" Name="Password" Visibility="{Binding LoginVis}" Text="{Binding Password}" /> | |||||
| <Button Grid.Row="7" Grid.Column="1" Name="Login" Content="登录" Command="{Binding ClickLoginCommand}" Visibility="{Binding LoginVis}"/> | |||||
| <Button Grid.Row="7" Grid.Column="2" Name="Launch" Content="{Binding LaunchBtnCont}" Command="{Binding ClickLaunchCommand}" Visibility="{Binding LoginVis}"/> | |||||
| <Button Grid.Row="7" Grid.Column="4" Grid.ColumnSpan="2" Name="Edit" Content="修改文件" Command="{Binding ClickEditCommand}" Visibility="{Binding LoginVis}"/> | |||||
| <TextBlock Grid.Row="6" Grid.Column="1" Text="用户名或密码错误!" Visibility="{Binding LoginFailVis}"/> | |||||
| <Button Grid.Row="5" Grid.Column="2" Name="MoveBtn" Content="Move" Command="{Binding ClickMoveCommand}" Visibility="{Binding EditIntroVis}" /> | |||||
| <TextBlock Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" Text="你有已完成的比赛!" Visibility="{Binding MatchFinishedVis}"/> | |||||
| <Button Grid.Row="3" Grid.Column="1" Name ="Upload" Content="上传代码" Command="{Binding ClickUploadCommand}" Visibility="{Binding WebVis}"/> | |||||
| <Button Grid.Row="5" Grid.Column="1" Name="Download" Content="下载回放" Command="{Binding ClickDownloadCommand}" Visibility="{Binding WebVis}" /> | |||||
| <Button Grid.Row="7" Grid.Column="1" Name="Replay" Content="打开回放" Command="{Binding ClickReplayCommand}" Visibility="{Binding WebVis}" /> | |||||
| <Button Grid.Row="3" Grid.Column="3" Grid.ColumnSpan="2" Content="申请对战" Command="{Binding ClickRequestCommand}" Visibility="{Binding WebVis}" /> | |||||
| <TextBox Grid.Row="4" Grid.Column="3" Grid.ColumnSpan="2" Text="{Binding Enemy}" Visibility="{Binding WebVis}" /> | |||||
| <Button Grid.Row="6" Grid.Column="3" Grid.ColumnSpan="2" Content="退出登录" Command="{Binding ClickLogoutCommand}" Visibility="{Binding WebVis}" /> | |||||
| <Button Grid.Row="7" Grid.Column="2" Name="UninstBtn" Content="UnInst" Command="{Binding ClickUninstCommand}" Visibility="{Binding EditIntroVis}" /> | |||||
| </Grid> | </Grid> | ||||
| </Window> | </Window> | ||||
| @@ -22,6 +22,9 @@ using System.Windows; | |||||
| using System.Windows.Shapes; | using System.Windows.Shapes; | ||||
| //using System.Windows.Forms; | //using System.Windows.Forms; | ||||
| using MessageBox = System.Windows.MessageBox; | |||||
| using Downloader; | |||||
| namespace starter.viewmodel.settings | namespace starter.viewmodel.settings | ||||
| { | { | ||||
| /// <summary> | /// <summary> | ||||
| @@ -32,27 +35,25 @@ namespace starter.viewmodel.settings | |||||
| /// <summary> | /// <summary> | ||||
| /// downloader function | /// downloader function | ||||
| /// </summary> | /// </summary> | ||||
| private Downloader.Program.Data configData = new Downloader.Program.Data(""); | |||||
| private Downloader.Program.Tencent_cos_download cloud = new Downloader.Program.Tencent_cos_download(); | |||||
| private Data configData = new Data(""); | |||||
| private Tencent_cos_download cloud = new Tencent_cos_download(); | |||||
| private HttpClient client = new HttpClient(); | |||||
| private WebConnect.Web web = new WebConnect.Web(); | |||||
| /// <summary> | /// <summary> | ||||
| /// save settings | /// save settings | ||||
| /// </summary> | /// </summary> | ||||
| public bool install() | public bool install() | ||||
| { | { | ||||
| if (Downloader.Program.Tencent_cos_download.CheckAlreadyDownload()) | |||||
| if (Tencent_cos_download.CheckAlreadyDownload()) | |||||
| { | { | ||||
| MessageBoxResult repeatOption = MessageBox.Show($"文件已存在于{Downloader.Program.Data.FilePath},是否移动到新位置?", "重复安装", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning, MessageBoxResult.Cancel); | |||||
| MessageBoxResult repeatOption = MessageBox.Show($"文件已存在于{Downloader.Program.Data.FilePath},是否移动到新位置?", "重复安装", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No); | |||||
| // ask if abort install, with warning sign, defalut no; | // ask if abort install, with warning sign, defalut no; | ||||
| if (repeatOption == MessageBoxResult.Cancel) | |||||
| if (repeatOption == MessageBoxResult.No) | |||||
| { | { | ||||
| return false; // 回到选择地址界面 | return false; // 回到选择地址界面 | ||||
| } | } | ||||
| else if (repeatOption == MessageBoxResult.No) | |||||
| { | |||||
| System.Environment.Exit(0); | |||||
| return false; | |||||
| } | |||||
| else | else | ||||
| { | { | ||||
| Downloader.Program.Tencent_cos_download.MoveProgram(Route); | Downloader.Program.Tencent_cos_download.MoveProgram(Route); | ||||
| @@ -61,11 +62,76 @@ namespace starter.viewmodel.settings | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| Downloader.Program.Data.ResetFilepath(Route); | |||||
| Downloader.Program.Tencent_cos_download.DownloadAll(); | |||||
| Data.ResetFilepath(Route); | |||||
| Tencent_cos_download.DownloadAll(); | |||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| public int move() | |||||
| { | |||||
| return Tencent_cos_download.MoveProgram(Route); | |||||
| } | |||||
| ///<summary> | |||||
| ///check for update | |||||
| /// </summary> | |||||
| static bool ProfileAvailable | |||||
| { | |||||
| get; set; | |||||
| } | |||||
| /// <summary> | |||||
| /// 检查更新 | |||||
| /// </summary> | |||||
| /// <returns></returns> | |||||
| public Status checkUpdate() | |||||
| { | |||||
| UpdateInfo updateInfo = Tencent_cos_download.Check(); | |||||
| if (updateInfo.newFileCount == -1) | |||||
| { | |||||
| if (updateInfo.changedFileCount == -1) | |||||
| { | |||||
| return Status.error; | |||||
| } | |||||
| else | |||||
| { | |||||
| return Status.disconnected; | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| if (updateInfo.changedFileCount != 0 || updateInfo.newFileCount != 0) | |||||
| { | |||||
| Updates = "发现新版本" + updateInfo.status; | |||||
| } | |||||
| return Status.menu; | |||||
| } | |||||
| } | |||||
| public void Login() | |||||
| { | |||||
| _ = web.LoginToEEsast(client, Username, Password); | |||||
| } | |||||
| public bool Update() | |||||
| { | |||||
| return Tencent_cos_download.Update(); | |||||
| } | |||||
| public int Uninst() | |||||
| { | |||||
| return Tencent_cos_download.DeleteAll(); | |||||
| } | |||||
| public bool Launch() | |||||
| { | |||||
| if (Tencent_cos_download.CheckAlreadyDownload()) | |||||
| { | |||||
| Process.Start(System.IO.Path.Combine(Data.FilePath, startName)); | |||||
| return true; | |||||
| } | |||||
| else | |||||
| { | |||||
| MessageBox.Show($"文件还不存在,请安装主体文件", "文件不存在", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK); | |||||
| return false; | |||||
| } | |||||
| } | |||||
| /// <summary> | /// <summary> | ||||
| /// Route of files | /// Route of files | ||||
| /// </summary> | /// </summary> | ||||
| @@ -73,24 +139,69 @@ namespace starter.viewmodel.settings | |||||
| { | { | ||||
| get | get | ||||
| { | { | ||||
| return Downloader.Program.Data.FilePath; | |||||
| return Data.FilePath; | |||||
| } | } | ||||
| set | set | ||||
| { | { | ||||
| Downloader.Program.Data.FilePath = value; | |||||
| Data.FilePath = value; | |||||
| } | } | ||||
| } | } | ||||
| public string Username | |||||
| { | |||||
| get; set; | |||||
| } | |||||
| public string Password | |||||
| { | |||||
| get; set; | |||||
| } | |||||
| /// <summary> | /// <summary> | ||||
| /// if the route was set or is under editing | |||||
| /// 关于更新的屏幕显示信息 | |||||
| /// </summary> | /// </summary> | ||||
| public bool EditingRoute | |||||
| private string updates; | |||||
| public string Updates | |||||
| { | |||||
| get | |||||
| { | |||||
| return updates; | |||||
| } | |||||
| set | |||||
| { | |||||
| updates = value; | |||||
| } | |||||
| } | |||||
| /// <summary> | |||||
| /// 关于介绍的屏幕显示信息 | |||||
| /// </summary> | |||||
| public enum Status { newUser, menu, move, working, disconnected, error, successful, login, web }; | |||||
| public Status status | |||||
| { | |||||
| get; set; | |||||
| } | |||||
| public bool Working | |||||
| { | { | ||||
| get; set; | get; set; | ||||
| } | } | ||||
| ///< summary> | |||||
| /// if already installed | |||||
| /// </summary> | |||||
| public bool installed | |||||
| /// <summary> | |||||
| /// if an update is planned | |||||
| /// </summary> | |||||
| public bool UpdatePlanned | |||||
| { | |||||
| get | |||||
| { | |||||
| return Program.UpdatePlanned; | |||||
| } | |||||
| } | |||||
| public bool CombatCompleted | |||||
| { | |||||
| get | |||||
| { | |||||
| return false; | |||||
| } | |||||
| } | |||||
| public bool LoginFailed | |||||
| { | { | ||||
| get; set; | get; set; | ||||
| } | } | ||||
| @@ -102,9 +213,21 @@ namespace Downloader | |||||
| { | { | ||||
| static List<string> newFileName = new List<string>(); // 新文件名 | static List<string> newFileName = new List<string>(); // 新文件名 | ||||
| static List<string> updateFileName = new List<string>(); // 更新文件名 | static List<string> updateFileName = new List<string>(); // 更新文件名 | ||||
| static string ProgramName = "THUAI6"; // 要运行或下载的程序名称 | |||||
| static string playerFolder = "player"; // 选手代码保存文件夹路径 | |||||
| static string startName = "maintest.exe"; // 启动的程序名 | |||||
| public static string ProgramName = "THUAI6"; // 要运行或下载的程序名称 | |||||
| public static string playerFolder = "player"; // 选手代码保存文件夹路径 | |||||
| public static string startName = "maintest.exe"; // 启动的程序名 | |||||
| public struct UpdateInfo // 更新信息,包括新版本版本号、更改文件数和新文件数 | |||||
| { | |||||
| public string status; | |||||
| public int changedFileCount; | |||||
| public int newFileCount; | |||||
| } | |||||
| public static bool UpdatePlanned | |||||
| { | |||||
| get; set; | |||||
| } | |||||
| static int filenum = 0; // 总文件个数 | static int filenum = 0; // 总文件个数 | ||||
| public class Data | public class Data | ||||
| @@ -283,13 +406,14 @@ namespace Downloader | |||||
| } | } | ||||
| } | } | ||||
| private static void Check() | |||||
| public static UpdateInfo Check() | |||||
| { | { | ||||
| string json, MD5, jsonName; | string json, MD5, jsonName; | ||||
| int newFile = 0, updateFile = 0; | int newFile = 0, updateFile = 0; | ||||
| newFileName.Clear(); | newFileName.Clear(); | ||||
| updateFileName.Clear(); | updateFileName.Clear(); | ||||
| jsonName = "hash.json"; | jsonName = "hash.json"; | ||||
| UpdateInfo updateInfo; | |||||
| Tencent_cos_download Downloader = new Tencent_cos_download(); | Tencent_cos_download Downloader = new Tencent_cos_download(); | ||||
| try | try | ||||
| @@ -308,14 +432,18 @@ namespace Downloader | |||||
| catch (CosClientException clientEx) | catch (CosClientException clientEx) | ||||
| { | { | ||||
| // 请求失败 | // 请求失败 | ||||
| Console.WriteLine("CosClientException: " + clientEx.ToString() + Environment.NewLine); | |||||
| return; | |||||
| updateInfo.status = "ClientEx: " + clientEx.ToString(); | |||||
| updateInfo.newFileCount = -1; | |||||
| updateInfo.changedFileCount = 0; | |||||
| return updateInfo; | |||||
| } | } | ||||
| catch (CosServerException serverEx) | catch (CosServerException serverEx) | ||||
| { | { | ||||
| // 请求失败 | // 请求失败 | ||||
| Console.WriteLine("CosClientException: " + serverEx.ToString() + Environment.NewLine); | |||||
| return; | |||||
| updateInfo.status = "ServerEx: " + serverEx.ToString(); | |||||
| updateInfo.newFileCount = -1; | |||||
| updateInfo.changedFileCount = 0; | |||||
| return updateInfo; | |||||
| } | } | ||||
| using (StreamReader r = new StreamReader(System.IO.Path.Combine(Data.FilePath, jsonName))) | using (StreamReader r = new StreamReader(System.IO.Path.Combine(Data.FilePath, jsonName))) | ||||
| @@ -334,22 +462,29 @@ namespace Downloader | |||||
| newFile = newFileName.Count; | newFile = newFileName.Count; | ||||
| updateFile = updateFileName.Count; | updateFile = updateFileName.Count; | ||||
| filenum = newFile + updateFile; | filenum = newFile + updateFile; | ||||
| Console.WriteLine("----------------------" + Environment.NewLine); | |||||
| //Console.WriteLine("----------------------" + Environment.NewLine); | |||||
| if (newFile + updateFile == 0) | if (newFile + updateFile == 0) | ||||
| { | { | ||||
| Console.WriteLine("当前平台已是最新版本!" + Environment.NewLine); | |||||
| updateInfo.status = "latest"; | |||||
| updateInfo.newFileCount = 0; | |||||
| updateInfo.changedFileCount = 0; | |||||
| newFileName.Clear(); | newFileName.Clear(); | ||||
| updateFileName.Clear(); | updateFileName.Clear(); | ||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| Console.WriteLine($"发现{newFile}个新文件" + Environment.NewLine); | |||||
| updateInfo.status = "old"; | |||||
| //TODO:获取版本号 | |||||
| updateInfo.newFileCount = newFile; | |||||
| /* | |||||
| foreach (string filename in newFileName) | foreach (string filename in newFileName) | ||||
| { | { | ||||
| Console.WriteLine(filename); | Console.WriteLine(filename); | ||||
| } | } | ||||
| Console.WriteLine(Environment.NewLine + $"发现{updateFile}个文件更新" + Environment.NewLine); | |||||
| */ | |||||
| updateInfo.changedFileCount = updateFile; | |||||
| /* | |||||
| foreach (string filename in updateFileName) | foreach (string filename in updateFileName) | ||||
| { | { | ||||
| Console.WriteLine(filename); | Console.WriteLine(filename); | ||||
| @@ -359,8 +494,23 @@ namespace Downloader | |||||
| Console.WriteLine("下载取消!"); | Console.WriteLine("下载取消!"); | ||||
| else | else | ||||
| Download(); | Download(); | ||||
| */ | |||||
| UpdatePlanned = true; | |||||
| } | |||||
| return updateInfo; | |||||
| } | |||||
| public static bool Update() | |||||
| { | |||||
| if (UpdatePlanned) | |||||
| { | |||||
| Download(); | |||||
| UpdatePlanned = false; | |||||
| return true; | |||||
| } | } | ||||
| return false; | |||||
| } | } | ||||
| private static void Download() | private static void Download() | ||||
| { | { | ||||
| Tencent_cos_download Downloader = new Tencent_cos_download(); | Tencent_cos_download Downloader = new Tencent_cos_download(); | ||||
| @@ -592,7 +742,7 @@ namespace Downloader | |||||
| } | } | ||||
| } | } | ||||
| public static void DeleteAll() | |||||
| public static int DeleteAll() | |||||
| { | { | ||||
| DirectoryInfo di = new DirectoryInfo(Data.FilePath); | DirectoryInfo di = new DirectoryInfo(Data.FilePath); | ||||
| DirectoryInfo player = new DirectoryInfo(System.IO.Path.GetFullPath(System.IO.Path.Combine(Data.FilePath, playerFolder))); | DirectoryInfo player = new DirectoryInfo(System.IO.Path.GetFullPath(System.IO.Path.Combine(Data.FilePath, playerFolder))); | ||||
| @@ -619,17 +769,17 @@ namespace Downloader | |||||
| catch (UnauthorizedAccessException) | catch (UnauthorizedAccessException) | ||||
| { | { | ||||
| Console.WriteLine("权限不足,无法删除!"); | Console.WriteLine("权限不足,无法删除!"); | ||||
| return; | |||||
| return -2; | |||||
| } | } | ||||
| catch (DirectoryNotFoundException) | catch (DirectoryNotFoundException) | ||||
| { | { | ||||
| Console.WriteLine("文件夹没有找到,请检查是否已经手动更改路径"); | Console.WriteLine("文件夹没有找到,请检查是否已经手动更改路径"); | ||||
| return; | |||||
| return -3; | |||||
| } | } | ||||
| catch (IOException) | catch (IOException) | ||||
| { | { | ||||
| Console.WriteLine("文件已经打开,请关闭后再删除"); | Console.WriteLine("文件已经打开,请关闭后再删除"); | ||||
| return; | |||||
| return -1; | |||||
| } | } | ||||
| string json2; | string json2; | ||||
| @@ -665,19 +815,20 @@ namespace Downloader | |||||
| catch (UnauthorizedAccessException) | catch (UnauthorizedAccessException) | ||||
| { | { | ||||
| Console.WriteLine("权限不足,无法删除!"); | Console.WriteLine("权限不足,无法删除!"); | ||||
| return; | |||||
| return -2; | |||||
| } | } | ||||
| catch (DirectoryNotFoundException) | catch (DirectoryNotFoundException) | ||||
| { | { | ||||
| Console.WriteLine("文件夹没有找到,请检查是否已经手动更改路径"); | Console.WriteLine("文件夹没有找到,请检查是否已经手动更改路径"); | ||||
| return; | |||||
| return -3; | |||||
| } | } | ||||
| catch (IOException) | catch (IOException) | ||||
| { | { | ||||
| Console.WriteLine("文件已经打开,请关闭后再删除"); | Console.WriteLine("文件已经打开,请关闭后再删除"); | ||||
| return; | |||||
| return -1; | |||||
| } | } | ||||
| Console.WriteLine($"删除成功!player文件夹中的文件已经放在{ProgramName}的根目录下"); | Console.WriteLine($"删除成功!player文件夹中的文件已经放在{ProgramName}的根目录下"); | ||||
| return 0; | |||||
| } | } | ||||
| public static void OverwriteHash(Dictionary<string, string> jsonDict) | public static void OverwriteHash(Dictionary<string, string> jsonDict) | ||||
| @@ -687,7 +838,7 @@ namespace Downloader | |||||
| File.WriteAllText(@System.IO.Path.Combine(Data.FilePath, "hash.json"), Contentjson); | File.WriteAllText(@System.IO.Path.Combine(Data.FilePath, "hash.json"), Contentjson); | ||||
| } | } | ||||
| public static void MoveProgram(string newPath) | |||||
| public static int MoveProgram(string newPath) | |||||
| { | { | ||||
| DirectoryInfo newdi = new DirectoryInfo(newPath); | DirectoryInfo newdi = new DirectoryInfo(newPath); | ||||
| DirectoryInfo olddi = new DirectoryInfo(Data.FilePath); | DirectoryInfo olddi = new DirectoryInfo(Data.FilePath); | ||||
| @@ -714,6 +865,7 @@ namespace Downloader | |||||
| file.MoveTo(System.IO.Path.Combine(Data.FilePath, file.Name)); | file.MoveTo(System.IO.Path.Combine(Data.FilePath, file.Name)); | ||||
| } | } | ||||
| Console.WriteLine("移动失败!"); | Console.WriteLine("移动失败!"); | ||||
| return -2; | |||||
| } | } | ||||
| catch (IOException) | catch (IOException) | ||||
| { | { | ||||
| @@ -727,9 +879,11 @@ namespace Downloader | |||||
| file.MoveTo(System.IO.Path.Combine(Data.FilePath, file.Name)); | file.MoveTo(System.IO.Path.Combine(Data.FilePath, file.Name)); | ||||
| } | } | ||||
| Console.WriteLine("移动失败!"); | Console.WriteLine("移动失败!"); | ||||
| return -1; | |||||
| } | } | ||||
| Data.ResetFilepath(newPath); | Data.ResetFilepath(newPath); | ||||
| Console.WriteLine("更改路径成功!"); | Console.WriteLine("更改路径成功!"); | ||||
| return 0; | |||||
| } | } | ||||
| public static async Task main(string[] args) | public static async Task main(string[] args) | ||||
| { | { | ||||
| @@ -3,6 +3,9 @@ using starter.viewmodel.common; | |||||
| using System; | using System; | ||||
| using System.Windows; | using System.Windows; | ||||
| using System.Windows.Forms; | using System.Windows.Forms; | ||||
| using Downloader; | |||||
| using MessageBox = System.Windows.MessageBox; | |||||
| using System.Configuration; | |||||
| namespace starter.viewmodel.settings | namespace starter.viewmodel.settings | ||||
| { | { | ||||
| @@ -19,12 +22,111 @@ namespace starter.viewmodel.settings | |||||
| { | { | ||||
| if (Downloader.Program.Tencent_cos_download.CheckAlreadyDownload()) | if (Downloader.Program.Tencent_cos_download.CheckAlreadyDownload()) | ||||
| { | { | ||||
| Installed = true; | |||||
| obj.checkUpdate(); | |||||
| Status = SettingsModel.Status.login; | |||||
| this.RaisePropertyChanged("WindowWidth"); | |||||
| //TODO:在启动时立刻检查更新,确保选手启动最新版选手包 | |||||
| //TODO:若有更新,将启动键改为更新键; | |||||
| //TODO:相应地,使用login界面启动; | |||||
| //TODO:结构:上方为登录框架,下方有“修改选手包”按钮 | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| Route = Environment.GetEnvironmentVariable("USERPROFILE") + "\\THUAI6"; | Route = Environment.GetEnvironmentVariable("USERPROFILE") + "\\THUAI6"; | ||||
| EditingRoute = true; | |||||
| Status = SettingsModel.Status.newUser; | |||||
| this.RaisePropertyChanged("WindowWidth"); | |||||
| } | |||||
| } | |||||
| //TODO:参赛界面:包括上传参赛代码、申请对战 | |||||
| //TODO:界面中应包含上次对战完成提示及下载回放按钮 | |||||
| public int ExtraColumn | |||||
| { | |||||
| get | |||||
| { | |||||
| if (Status == SettingsModel.Status.newUser || Status == SettingsModel.Status.move) | |||||
| return 75; | |||||
| else | |||||
| return 0; | |||||
| } | |||||
| } | |||||
| public int WindowWidth | |||||
| { | |||||
| get | |||||
| { | |||||
| switch (Status) | |||||
| { | |||||
| case SettingsModel.Status.newUser: | |||||
| return 505; | |||||
| case SettingsModel.Status.move: | |||||
| return 505; | |||||
| case SettingsModel.Status.working: | |||||
| return 435; | |||||
| case SettingsModel.Status.successful: | |||||
| return 435; | |||||
| default: | |||||
| return 355; | |||||
| } | |||||
| } | |||||
| } | |||||
| public SettingsModel.Status Status | |||||
| { | |||||
| get | |||||
| { | |||||
| return obj.status; | |||||
| } | |||||
| set | |||||
| { | |||||
| obj.status = value; | |||||
| this.RaisePropertyChanged("ExtraColumn"); | |||||
| this.RaisePropertyChanged("Intro"); | |||||
| this.RaisePropertyChanged("RouteBoxIntro"); | |||||
| this.RaisePropertyChanged("LoginVis"); | |||||
| this.RaisePropertyChanged("MenuVis"); | |||||
| this.RaisePropertyChanged("RouteBoxVis"); | |||||
| this.RaisePropertyChanged("ProgressVis"); | |||||
| this.RaisePropertyChanged("CompleteVis"); | |||||
| } | |||||
| } | |||||
| public string Intro | |||||
| { | |||||
| get | |||||
| { | |||||
| switch (Status) | |||||
| { | |||||
| case SettingsModel.Status.newUser: | |||||
| return "欢迎使用选手包,请选择你想要安装选手包的位置:"; | |||||
| case SettingsModel.Status.menu: | |||||
| return "你已经安装了选手包,请选择想要进行的操作:"; | |||||
| case SettingsModel.Status.login: | |||||
| return "使用EESAST账号登录"; | |||||
| case SettingsModel.Status.web: | |||||
| return "THUAI6 赛场:"; | |||||
| case SettingsModel.Status.disconnected: | |||||
| return "你可能没有连接到网络,无法下载/更新选手包"; | |||||
| case SettingsModel.Status.error: | |||||
| return "我们遇到了一些问题,请向[]反馈"; | |||||
| default: | |||||
| return ""; | |||||
| } | |||||
| } | |||||
| } | |||||
| public string RouteBoxIntro | |||||
| { | |||||
| get | |||||
| { | |||||
| switch (Status) | |||||
| { | |||||
| case SettingsModel.Status.newUser: | |||||
| return "将主体程序安装在:"; | |||||
| case SettingsModel.Status.move: | |||||
| return "将主体程序移动到:"; | |||||
| default: | |||||
| return ""; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -40,67 +142,106 @@ namespace starter.viewmodel.settings | |||||
| this.RaisePropertyChanged("Route"); | this.RaisePropertyChanged("Route"); | ||||
| } | } | ||||
| } | } | ||||
| public bool Installed | |||||
| public string Username | |||||
| { | { | ||||
| get | get | ||||
| { | { | ||||
| return obj.installed; | |||||
| return obj.Username; | |||||
| } | } | ||||
| set | set | ||||
| { | { | ||||
| obj.installed = value; | |||||
| this.RaisePropertyChanged("Installed"); | |||||
| this.RaisePropertyChanged("InstIntroVis"); | |||||
| this.RaisePropertyChanged("EditIntroVis"); | |||||
| this.RaisePropertyChanged("MoveIntroVis"); | |||||
| obj.Username = value; | |||||
| this.RaisePropertyChanged("Username"); | |||||
| } | } | ||||
| } | } | ||||
| public bool EditingRoute | |||||
| public string Password | |||||
| { | |||||
| get { return obj.Password; } | |||||
| set | |||||
| { | |||||
| obj.Password = value; | |||||
| this.RaisePropertyChanged("Password"); | |||||
| } | |||||
| } | |||||
| public Visibility MenuVis | |||||
| { | { | ||||
| get | get | ||||
| { | { | ||||
| return obj.EditingRoute; | |||||
| return Status == SettingsModel.Status.menu ? Visibility.Visible : Visibility.Collapsed; | |||||
| } | } | ||||
| set | |||||
| } | |||||
| public Visibility RouteBoxVis | |||||
| { | |||||
| get | |||||
| { | { | ||||
| obj.EditingRoute = value; | |||||
| this.RaisePropertyChanged("EditingRoute"); | |||||
| this.RaisePropertyChanged("MoveIntroVis"); | |||||
| this.RaisePropertyChanged("RouteBoxVis"); | |||||
| return (Status == SettingsModel.Status.newUser || Status == SettingsModel.Status.move) ? Visibility.Visible : Visibility.Collapsed; | |||||
| } | } | ||||
| } | } | ||||
| public Visibility RouteBoxVis // if the route editing textbox is visible | |||||
| public Visibility LoginVis | |||||
| { | { | ||||
| get | get | ||||
| { | { | ||||
| return obj.EditingRoute ? Visibility.Visible : Visibility.Collapsed; | |||||
| return Status == SettingsModel.Status.login ? Visibility.Visible : Visibility.Collapsed; | |||||
| } | } | ||||
| } | } | ||||
| /// <summary> | |||||
| /// if the install/edit instruction can be seen | |||||
| /// </summary> | |||||
| public Visibility InstIntroVis | |||||
| public Visibility ProgressVis | |||||
| { | |||||
| get | |||||
| { | |||||
| return Status == SettingsModel.Status.working ? Visibility.Visible : Visibility.Collapsed; | |||||
| } | |||||
| } | |||||
| public Visibility CompleteVis | |||||
| { | { | ||||
| get | get | ||||
| { | { | ||||
| return obj.installed ? Visibility.Collapsed : Visibility.Visible; | |||||
| return Status == SettingsModel.Status.successful ? Visibility.Visible : Visibility.Collapsed; | |||||
| } | } | ||||
| } | } | ||||
| public Visibility EditIntroVis | |||||
| public Visibility WebVis | |||||
| { | { | ||||
| get | get | ||||
| { | { | ||||
| return obj.installed ? Visibility.Visible : Visibility.Collapsed; | |||||
| return Status == SettingsModel.Status.web ? Visibility.Visible : Visibility.Collapsed; | |||||
| } | } | ||||
| } | } | ||||
| public Visibility MoveIntroVis | |||||
| public Visibility LoginFailVis | |||||
| { | { | ||||
| get | get | ||||
| { | { | ||||
| if (obj.installed == true && obj.EditingRoute == true) | |||||
| return Visibility.Visible; | |||||
| return obj.LoginFailed ? Visibility.Visible : Visibility.Collapsed; | |||||
| } | |||||
| } | |||||
| public Visibility MatchFinishedVis | |||||
| { | |||||
| get | |||||
| { | |||||
| return obj.CombatCompleted ? Visibility.Visible : Visibility.Collapsed; | |||||
| } | |||||
| } | |||||
| public string UpdateBtnCont | |||||
| { | |||||
| get | |||||
| { | |||||
| return obj.UpdatePlanned ? "Update" : "Check Updates"; | |||||
| } | |||||
| } | |||||
| public string UpdateInfo | |||||
| { | |||||
| get | |||||
| { | |||||
| if (obj.UpdatePlanned) | |||||
| return obj.Updates; | |||||
| else | else | ||||
| return Visibility.Collapsed; | |||||
| return ""; | |||||
| } | |||||
| } | |||||
| public string LaunchBtnCont | |||||
| { | |||||
| get | |||||
| { | |||||
| return obj.UpdatePlanned ? "更新" : "启动"; | |||||
| } | } | ||||
| } | } | ||||
| @@ -133,15 +274,175 @@ namespace starter.viewmodel.settings | |||||
| { | { | ||||
| clickConfirmCommand = new BaseCommand(new Action<object>(o => | clickConfirmCommand = new BaseCommand(new Action<object>(o => | ||||
| { | { | ||||
| if (obj.install()) | |||||
| if (Status == SettingsModel.Status.newUser) | |||||
| { | { | ||||
| EditingRoute = false; | |||||
| Installed = true; | |||||
| Status = SettingsModel.Status.working; | |||||
| if (obj.install()) | |||||
| { | |||||
| Status = SettingsModel.Status.menu; | |||||
| } | |||||
| } | |||||
| else if (Status == SettingsModel.Status.move) | |||||
| { | |||||
| Status = SettingsModel.Status.working; | |||||
| switch (obj.move()) | |||||
| { | |||||
| case -1: | |||||
| MessageBox.Show("文件已打开或者目标路径下有同名文件!", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK); | |||||
| break; | |||||
| case -2: | |||||
| Status = SettingsModel.Status.error; | |||||
| break; | |||||
| } | |||||
| } | } | ||||
| })); | })); | ||||
| } | } | ||||
| return clickConfirmCommand; | return clickConfirmCommand; | ||||
| } | } | ||||
| } | } | ||||
| private BaseCommand clickUpdateCommand; | |||||
| public BaseCommand ClickUpdateCommand | |||||
| { | |||||
| get | |||||
| { | |||||
| if (clickUpdateCommand == null) | |||||
| { | |||||
| clickUpdateCommand = new BaseCommand(new Action<object>(o => | |||||
| { | |||||
| if (obj.UpdatePlanned) | |||||
| { | |||||
| Status = SettingsModel.Status.working; | |||||
| if (obj.Update()) | |||||
| { | |||||
| Status = SettingsModel.Status.successful; | |||||
| this.RaisePropertyChanged("UpdateButtonCont"); | |||||
| } | |||||
| else | |||||
| Status = SettingsModel.Status.error; | |||||
| } | |||||
| else | |||||
| { | |||||
| Status = SettingsModel.Status.working; | |||||
| Status = obj.checkUpdate(); | |||||
| this.RaisePropertyChanged("UpdateButtonCont"); | |||||
| } | |||||
| })); | |||||
| } | |||||
| return clickUpdateCommand; | |||||
| } | |||||
| } | |||||
| private BaseCommand clickMoveCommand; | |||||
| public BaseCommand ClickMoveCommand | |||||
| { | |||||
| get | |||||
| { | |||||
| if (clickMoveCommand == null) | |||||
| { | |||||
| clickMoveCommand = new BaseCommand(new Action<object>(o => | |||||
| { | |||||
| Status = SettingsModel.Status.move; | |||||
| })); | |||||
| } | |||||
| return clickMoveCommand; | |||||
| } | |||||
| } | |||||
| private BaseCommand clickUninstCommand; | |||||
| public BaseCommand ClickUninstCommand | |||||
| { | |||||
| get | |||||
| { | |||||
| if (clickUninstCommand == null) | |||||
| { | |||||
| clickUninstCommand = new BaseCommand(new Action<object>(o => | |||||
| { | |||||
| Status = SettingsModel.Status.working; | |||||
| switch (obj.Uninst()) | |||||
| { | |||||
| case -1: | |||||
| Status = SettingsModel.Status.menu; | |||||
| MessageBox.Show("文件已经打开,请关闭后再删除", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK); | |||||
| break; | |||||
| case 0: | |||||
| Status = SettingsModel.Status.successful; | |||||
| break; | |||||
| default: | |||||
| Status = SettingsModel.Status.error; | |||||
| break; | |||||
| } | |||||
| })); | |||||
| } | |||||
| return clickUninstCommand; | |||||
| } | |||||
| } | |||||
| private BaseCommand clickLoginCommand; | |||||
| public BaseCommand ClickLoginCommand | |||||
| { | |||||
| get | |||||
| { | |||||
| if (clickLoginCommand == null) | |||||
| { | |||||
| clickLoginCommand = new BaseCommand(new Action<object>(o => | |||||
| { | |||||
| obj.Login(); | |||||
| this.RaisePropertyChanged("LoginFailVis"); | |||||
| })); | |||||
| } | |||||
| return clickLoginCommand; | |||||
| } | |||||
| } | |||||
| private BaseCommand clickLaunchCommand; | |||||
| public BaseCommand ClickLaunchCommand | |||||
| { | |||||
| get | |||||
| { | |||||
| if (clickLaunchCommand == null) | |||||
| { | |||||
| clickLaunchCommand = new BaseCommand(new Action<object>(o => | |||||
| { | |||||
| if (!obj.Launch()) | |||||
| { | |||||
| Status = SettingsModel.Status.menu; | |||||
| } | |||||
| })); | |||||
| } | |||||
| return clickLaunchCommand; | |||||
| } | |||||
| } | |||||
| private BaseCommand clickEditCommand; | |||||
| public BaseCommand ClickEditCommand | |||||
| { | |||||
| get | |||||
| { | |||||
| if (clickEditCommand == null) | |||||
| { | |||||
| clickEditCommand = new BaseCommand(new Action<object>(o => | |||||
| { | |||||
| Status = SettingsModel.Status.menu; | |||||
| })); | |||||
| } | |||||
| return clickEditCommand; | |||||
| } | |||||
| } | |||||
| private BaseCommand clickLogoutCommand; | |||||
| public BaseCommand ClickLogoutCommand | |||||
| { | |||||
| get | |||||
| { | |||||
| if (clickLogoutCommand == null) | |||||
| { | |||||
| clickLogoutCommand = new BaseCommand(new Action<object>(o => | |||||
| { | |||||
| Status = SettingsModel.Status.login; | |||||
| })); | |||||
| } | |||||
| return clickLogoutCommand; | |||||
| } | |||||
| } | |||||
| } | } | ||||
| } | } | ||||