chore: designed new gui for editing configurationtags/0.1.0
| @@ -9,21 +9,39 @@ | |||||
| <Grid> | <Grid> | ||||
| <Grid.ColumnDefinitions> | <Grid.ColumnDefinitions> | ||||
| <ColumnDefinition Width="40" /> | <ColumnDefinition Width="40" /> | ||||
| <ColumnDefinition Width="400" /> | |||||
| <ColumnDefinition Width="75" /> | <ColumnDefinition Width="75" /> | ||||
| <ColumnDefinition Width="75" /> | <ColumnDefinition Width="75" /> | ||||
| <ColumnDefinition Width="*"/> | |||||
| <ColumnDefinition Width="250" /> | |||||
| <ColumnDefinition Width="75" /> | |||||
| <ColumnDefinition Width="75" /> | |||||
| <ColumnDefinition Width="*" /> | |||||
| <ColumnDefinition Width="40" /> | |||||
| </Grid.ColumnDefinitions> | </Grid.ColumnDefinitions> | ||||
| <Grid.RowDefinitions> | <Grid.RowDefinitions> | ||||
| <RowDefinition Height="20" /> | |||||
| <RowDefinition Height="20" /> | |||||
| <RowDefinition Height="20" /> | |||||
| <RowDefinition Height="20" /> | |||||
| <RowDefinition Height="20" /> | |||||
| <RowDefinition Height="20" /> | <RowDefinition Height="20" /> | ||||
| <RowDefinition Height="20" /> | <RowDefinition Height="20" /> | ||||
| <RowDefinition Height="20" /> | <RowDefinition Height="20" /> | ||||
| <RowDefinition Height="*" /> | <RowDefinition Height="*" /> | ||||
| <RowDefinition Height="20" /> | <RowDefinition Height="20" /> | ||||
| </Grid.RowDefinitions> | </Grid.RowDefinitions> | ||||
| <TextBlock Grid.Row="1" Grid.Column="1" Text="将主体程序安装在:" /> | |||||
| <TextBox Grid.Row="2" Grid.Column="1" Name="RouteTxtBox" Text="{Binding Route}" IsEnabled="{Binding CanEditRoute}" /> | |||||
| <Button Grid.Row="2" Grid.Column="2" Name="GetRouteBtn" Content="Browse..." Command="{Binding ClickBrowseCommand}" IsEnabled="{Binding CanEditRoute}" /> | |||||
| <Button Grid.Row="2" Grid.Column="3" Name="SetBtm" Content="Confirm" Command="{Binding ClickConfirmCommand}" /> | |||||
| <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="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}"/> | |||||
| <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}" /> | |||||
| <Button Grid.Row="5" Grid.Column="2" Name="MoveBtn" Content="Move" Command="{Binding ClickMoveCommand}" Visibility="{Binding EditIntroVis}" /> | |||||
| <Button Grid.Row="7" Grid.Column="2" Name="UninstBtn" Content="UnInst" Command="{Binding ClickUninstCommand}" Visibility="{Binding EditIntroVis}" /> | |||||
| </Grid> | </Grid> | ||||
| </Window> | </Window> | ||||
| @@ -18,6 +18,7 @@ using System.Xml.Schema; | |||||
| using static Downloader.Program; | using static Downloader.Program; | ||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| using System.Net.Http; | using System.Net.Http; | ||||
| using System.Windows; | |||||
| namespace starter.viewmodel.settings | namespace starter.viewmodel.settings | ||||
| { | { | ||||
| @@ -26,34 +27,71 @@ namespace starter.viewmodel.settings | |||||
| /// </summary> | /// </summary> | ||||
| public class SettingsModel | public class SettingsModel | ||||
| { | { | ||||
| /// <summary> | |||||
| /// downloader function | |||||
| /// </summary> | |||||
| private Downloader.Program.Data configData = new Downloader.Program.Data(""); | |||||
| private Downloader.Program.Tencent_cos_download cloud = new Downloader.Program.Tencent_cos_download(); | |||||
| /// <summary> | /// <summary> | ||||
| /// save settings | /// save settings | ||||
| /// </summary> | /// </summary> | ||||
| public void install() | |||||
| public bool install() | |||||
| { | { | ||||
| if (Downloader.Program.Tencent_cos_download.CheckAlreadyDownload()) | |||||
| { | |||||
| MessageBoxResult repeatOption = MessageBox.Show($"文件已存在于{Downloader.Program.Data.FilePath},是否移动到新位置?", "重复安装", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning, MessageBoxResult.Cancel); | |||||
| //ask if abort install, with warning sign, defalut no; | |||||
| if (repeatOption == MessageBoxResult.Cancel) | |||||
| { | |||||
| return false; //回到选择地址界面 | |||||
| } | |||||
| else if (repeatOption == MessageBoxResult.No) | |||||
| { | |||||
| System.Environment.Exit(0); | |||||
| return false; | |||||
| } | |||||
| else | |||||
| { | |||||
| Downloader.Program.Tencent_cos_download.MoveProgram(Route); | |||||
| return true; | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| Downloader.Program.Data.ResetFilepath(Route); | |||||
| Downloader.Program.Tencent_cos_download.DownloadAll(); | |||||
| return true; | |||||
| } | |||||
| } | } | ||||
| /// <summary> | /// <summary> | ||||
| /// Route of files | /// Route of files | ||||
| /// </summary> | /// </summary> | ||||
| public string Route | public string Route | ||||
| { | { | ||||
| get; set; | |||||
| get | |||||
| { | |||||
| return Downloader.Program.Data.FilePath; | |||||
| } | |||||
| set | |||||
| { | |||||
| Downloader.Program.Data.FilePath = value; | |||||
| } | |||||
| } | } | ||||
| /// <summary> | /// <summary> | ||||
| /// if the route was set or is under editing | /// if the route was set or is under editing | ||||
| /// </summary> | /// </summary> | ||||
| public bool HaveRoute | |||||
| public bool EditingRoute | |||||
| { | { | ||||
| get; set; | get; set; | ||||
| } | } | ||||
| public bool EditingRoute | |||||
| ///<summary> | |||||
| ///if already installed | |||||
| /// </summary> | |||||
| public bool installed | |||||
| { | { | ||||
| get; set; | get; set; | ||||
| } | } | ||||
| /// <summary> | |||||
| /// downloader function | |||||
| /// </summary> | |||||
| private Downloader.Program downloader = new Downloader.Program(); | |||||
| } | } | ||||
| } | } | ||||
| namespace Downloader | namespace Downloader | ||||
| @@ -572,9 +610,8 @@ 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() | |||||
| public static void MoveProgram(string newPath) | |||||
| { | { | ||||
| string newPath = Console.ReadLine(); | |||||
| DirectoryInfo newdi = new DirectoryInfo(newPath); | DirectoryInfo newdi = new DirectoryInfo(newPath); | ||||
| DirectoryInfo olddi = new DirectoryInfo(Data.FilePath); | DirectoryInfo olddi = new DirectoryInfo(Data.FilePath); | ||||
| try | try | ||||
| @@ -688,7 +725,9 @@ namespace Downloader | |||||
| } | } | ||||
| else if (choose == "6") | else if (choose == "6") | ||||
| { | { | ||||
| MoveProgram(); | |||||
| string newPath; | |||||
| newPath = Console.ReadLine(); | |||||
| MoveProgram(newPath); | |||||
| } | } | ||||
| else if (choose == "7") | else if (choose == "7") | ||||
| { | { | ||||
| @@ -1,6 +1,7 @@ | |||||
| | | ||||
| using starter.viewmodel.common; | using starter.viewmodel.common; | ||||
| using System; | using System; | ||||
| using System.Windows; | |||||
| using System.Windows.Forms; | using System.Windows.Forms; | ||||
| namespace starter.viewmodel.settings | namespace starter.viewmodel.settings | ||||
| @@ -16,8 +17,15 @@ namespace starter.viewmodel.settings | |||||
| /// </summary> | /// </summary> | ||||
| public SettingsViewModel() | public SettingsViewModel() | ||||
| { | { | ||||
| Route = Environment.GetEnvironmentVariable("USERPROFILE") + "\\THUAI6"; | |||||
| CanEditRoute = true; | |||||
| if (Downloader.Program.Tencent_cos_download.CheckAlreadyDownload()) | |||||
| { | |||||
| Installed = true; | |||||
| } | |||||
| else | |||||
| { | |||||
| Route = Environment.GetEnvironmentVariable("USERPROFILE") + "\\THUAI6"; | |||||
| EditingRoute = true; | |||||
| } | |||||
| } | } | ||||
| public string Route | public string Route | ||||
| @@ -32,18 +40,67 @@ namespace starter.viewmodel.settings | |||||
| this.RaisePropertyChanged("Route"); | this.RaisePropertyChanged("Route"); | ||||
| } | } | ||||
| } | } | ||||
| public bool CanEditRoute // if the user can still edit install route | |||||
| public bool Installed | |||||
| { | { | ||||
| get | get | ||||
| { | { | ||||
| return !obj.HaveRoute; | |||||
| return obj.installed; | |||||
| } | |||||
| set | |||||
| { | |||||
| obj.installed = value; | |||||
| this.RaisePropertyChanged("Installed"); | |||||
| this.RaisePropertyChanged("InstIntroVis"); | |||||
| this.RaisePropertyChanged("EditIntroVis"); | |||||
| this.RaisePropertyChanged("MoveIntroVis"); | |||||
| } | |||||
| } | |||||
| public bool EditingRoute | |||||
| { | |||||
| get | |||||
| { | |||||
| return obj.EditingRoute; | |||||
| } | } | ||||
| set | set | ||||
| { | { | ||||
| obj.HaveRoute = !value; | |||||
| obj.EditingRoute = value; | obj.EditingRoute = value; | ||||
| this.RaisePropertyChanged("CanEditRoute"); | |||||
| this.RaisePropertyChanged("EditingRoute"); | |||||
| this.RaisePropertyChanged("MoveIntroVis"); | |||||
| this.RaisePropertyChanged("RouteBoxVis"); | |||||
| } | |||||
| } | |||||
| public Visibility RouteBoxVis //if the route editing textbox is visible | |||||
| { | |||||
| get | |||||
| { | |||||
| return obj.EditingRoute ? Visibility.Visible : Visibility.Collapsed; | |||||
| } | |||||
| } | |||||
| /// <summary> | |||||
| /// if the install/edit instruction can be seen | |||||
| /// </summary> | |||||
| public Visibility InstIntroVis | |||||
| { | |||||
| get | |||||
| { | |||||
| return obj.installed ? Visibility.Collapsed : Visibility.Visible; | |||||
| } | |||||
| } | |||||
| public Visibility EditIntroVis | |||||
| { | |||||
| get | |||||
| { | |||||
| return obj.installed ? Visibility.Visible : Visibility.Collapsed; | |||||
| } | |||||
| } | |||||
| public Visibility MoveIntroVis | |||||
| { | |||||
| get | |||||
| { | |||||
| if (obj.installed == true && obj.EditingRoute == true) | |||||
| return Visibility.Visible; | |||||
| else | |||||
| return Visibility.Collapsed; | |||||
| } | } | ||||
| } | } | ||||
| @@ -76,8 +133,11 @@ namespace starter.viewmodel.settings | |||||
| { | { | ||||
| clickConfirmCommand = new BaseCommand(new Action<object>(o => | clickConfirmCommand = new BaseCommand(new Action<object>(o => | ||||
| { | { | ||||
| CanEditRoute = false; | |||||
| obj.install(); | |||||
| if (obj.install()) | |||||
| { | |||||
| EditingRoute = false; | |||||
| Installed = true; | |||||
| } | |||||
| })); | })); | ||||
| } | } | ||||
| return clickConfirmCommand; | return clickConfirmCommand; | ||||