| @@ -1,6 +1,8 @@ | |||
| using System.ComponentModel; | |||
| using System; | |||
| using System.Windows.Input; | |||
| using System.Globalization; | |||
| using System.Windows.Data; | |||
| namespace starter.viewmodel.common | |||
| { | |||
| @@ -66,4 +68,34 @@ namespace starter.viewmodel.common | |||
| } | |||
| } | |||
| } | |||
| public class RadioConverter : IValueConverter | |||
| { | |||
| public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | |||
| { | |||
| if (value == null || parameter == null) | |||
| { | |||
| return false; | |||
| } | |||
| 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) | |||
| { | |||
| if (value == null || parameter == null) | |||
| { | |||
| return null; | |||
| } | |||
| if ((bool)value) | |||
| { | |||
| return parameter.ToString(); | |||
| } | |||
| return null; | |||
| } | |||
| } | |||
| } | |||
| @@ -3,9 +3,12 @@ | |||
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |||
| xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |||
| xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |||
| xmlns:local="clr-namespace:Installer" | |||
| xmlns:local="clr-namespace:Installer" xmlns:c="clr-namespace:starter.viewmodel.common" | |||
| mc:Ignorable="d" | |||
| Title="Installer" Window.SizeToContent="WidthAndHeight"> | |||
| <Window.Resources> | |||
| <c:RadioConverter x:Key="RadioConverter"/> | |||
| </Window.Resources> | |||
| <Grid> | |||
| <Grid.ColumnDefinitions> | |||
| <ColumnDefinition Width="40" /> | |||
| @@ -34,14 +37,14 @@ | |||
| <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="6" Name="GetRouteBtn" Content="选择文件夹" Command="{Binding ClickBrowseCommand}" Visibility="{Binding RouteBoxVis}" /> | |||
| <Button Grid.Row="3" Grid.Column="7" Name="SetBtm" Content="确认并安装" 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}" /> | |||
| <TextBlock Grid.Row="4" Grid.Column="2" Text="{Binding UpdateInfo}" 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="5" Grid.Column="2" Grid.ColumnSpan="2" Name="MoveBtn" Content="移动文件" Command="{Binding ClickMoveCommand}" Visibility="{Binding MenuVis}" /> | |||
| <Button Grid.Row="6" Grid.Column="2" Grid.ColumnSpan="2" Name="UninstBtn" Content="UnInstall" Command="{Binding ClickUninstCommand}" Visibility="{Binding MenuVis}" /> | |||
| <Button Grid.Row="6" Grid.Column="2" Grid.ColumnSpan="2" Name="UninstBtn" Content="卸载选手包" Command="{Binding ClickUninstCommand}" Visibility="{Binding MenuVis}" /> | |||
| <Button Grid.Row="7" Grid.Column="2" Grid.ColumnSpan="2" Name="MenuBackBtn" Content="回到登陆界面" Command="{Binding ClickBackCommand}" Visibility="{Binding MenuVis}" /> | |||
| <TextBlock Grid.Row="3" Grid.Column="4" Text="Processing" Grid.ColumnSpan="2" Visibility="{Binding ProgressVis}"/> | |||
| @@ -50,27 +53,40 @@ | |||
| <TextBlock Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="4" Text="操作完成!你可以继续操作或退出" Visibility="{Binding CompleteVis}"/> | |||
| <Button Grid.Row="6" Grid.Column="1" Name="BackBtn" Content="返回" Command="{Binding ClickBackCommand}" Visibility="{Binding CompleteVis}" Click="BackBtn_Click"/> | |||
| <Button Grid.Row="6" Grid.Column="4" Grid.ColumnSpan="2" Name="ExitBtn" Content="退出" Command="{Binding ClickExitCommand}" Visibility="{Binding CompleteVis}"/> | |||
| <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}" /> | |||
| <StackPanel Grid.Row="2" Grid.Column="1" Grid.RowSpan="5" Grid.ColumnSpan="5"> | |||
| <Grid> | |||
| <Grid.RowDefinitions> | |||
| <RowDefinition Height="10"/> | |||
| <RowDefinition Height="20"/> | |||
| <RowDefinition Height="10"/> | |||
| <RowDefinition Height="20"/> | |||
| <RowDefinition Height="10"/> | |||
| <RowDefinition Height="15"/> | |||
| <RowDefinition Height="*"/> | |||
| </Grid.RowDefinitions> | |||
| <Grid.ColumnDefinitions> | |||
| <ColumnDefinition Width="60"/> | |||
| <ColumnDefinition Width="*"/> | |||
| </Grid.ColumnDefinitions> | |||
| <TextBlock Grid.Row="1" Grid.Column="0" Text="账号:" Visibility="{Binding LoginVis}" /> | |||
| <TextBlock Grid.Row="3" Grid.Column="0" Text="密码:" Visibility="{Binding LoginVis}" /> | |||
| <TextBox Grid.Row="1" Grid.Column="1" Name="Username" Visibility="{Binding LoginVis}" Text="{Binding Username}" /> | |||
| <TextBox Grid.Row="3" Grid.Column="1" Name="Password" Visibility="{Binding LoginVis}" Text="{Binding Password}" /> | |||
| <!--<CheckBox Grid.Row="5" Grid.Column="0" Visibility="{Binding LoginVis}">记住我</CheckBox>--> | |||
| <TextBlock Grid.Row="5" Grid.Column="1" Foreground="Red" Text=" 用户名或密码错误!" Visibility="{Binding LoginFailVis}"/> | |||
| </Grid> | |||
| </StackPanel> | |||
| <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}"/> | |||
| <TextBlock Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" Text="你有已完成的比赛!" Visibility="{Binding MatchFinishedVis}"/> | |||
| <Button Grid.Row="3" Grid.Column="1" Name ="Upload" Content="{Binding UploadBtnCont}" Command="{Binding ClickUploadCommand}" Visibility="{Binding WebVis}"/> | |||
| <TextBlock Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2" Text="{Binding CodeName}" Visibility="{Binding UploadReadyVis}" /> | |||
| <Button Grid.Row="3" Grid.Column="2" Name="ReUpload" Content="重新选择代码" Command="{Binding ReselectCommand}" Visibility="{Binding UploadReadyVis}" /> | |||
| <Button Grid.Row="3" Grid.Column="2" Name="ReUpload" Content="放弃上传" Command="{Binding ClickReselectCommand}" Visibility="{Binding UploadReadyVis}" /> | |||
| <Button Grid.Row="6" Grid.Column="3" Grid.ColumnSpan="2" Content="退出登录" Command="{Binding ClickBackCommand}" Visibility="{Binding WebVis}" /> | |||
| <!--objects below are not enabled--> | |||
| <Button Grid.Row="5" Grid.Column="1" Name="Download" Content="下载回放" IsEnabled="False" Command="{Binding ClickDownloadCommand}" Visibility="{Binding CoverVis}" /> | |||
| <Button Grid.Row="7" Grid.Column="1" Name="Replay" Content="打开回放" IsEnabled="False" Command="{Binding ClickReplayCommand}" Visibility="{Binding CoverVis}" /> | |||
| <Button Grid.Row="3" Grid.Column="3" Grid.ColumnSpan="2" Content="申请对战" IsEnabled="False" Command="{Binding ClickRequestCommand}" Visibility="{Binding WebVis}" /> | |||
| <TextBox Grid.Row="4" Grid.Column="3" Grid.ColumnSpan="2" Text="暂不支持" IsEnabled="False" Visibility="{Binding WebVis}" /> | |||
| <StackPanel Grid.Row="5" Grid.Column="1" Grid.RowSpan="3" Grid.ColumnSpan="2"> | |||
| <Grid> | |||
| <Grid.RowDefinitions> | |||
| @@ -79,11 +95,18 @@ | |||
| <RowDefinition Height="15"/> | |||
| <RowDefinition Height="15"/> | |||
| </Grid.RowDefinitions> | |||
| <RadioButton GroupName="playerNum" Grid.Row="0" Visibility="{Binding UploadReadyVis}">玩家1</RadioButton> | |||
| <RadioButton GroupName="playerNum" Grid.Row="1" Visibility="{Binding UploadReadyVis}">玩家2</RadioButton> | |||
| <RadioButton GroupName="playerNum" Grid.Row="2" Visibility="{Binding UploadReadyVis}">玩家3</RadioButton> | |||
| <RadioButton GroupName="playerNum" Grid.Row="3" Visibility="{Binding UploadReadyVis}">玩家4</RadioButton> | |||
| <RadioButton GroupName="playerNum" Grid.Row="0" Visibility="{Binding UploadReadyVis}" IsChecked="{Binding PlayerNum,Mode=TwoWay,Converter={StaticResource RadioConverter},ConverterParameter=1}">玩家1</RadioButton> | |||
| <RadioButton GroupName="playerNum" Grid.Row="1" Visibility="{Binding UploadReadyVis}" IsChecked="{Binding PlayerNum,Mode=TwoWay,Converter={StaticResource RadioConverter},ConverterParameter=2}">玩家2</RadioButton> | |||
| <RadioButton GroupName="playerNum" Grid.Row="2" Visibility="{Binding UploadReadyVis}" IsChecked="{Binding PlayerNum,Mode=TwoWay,Converter={StaticResource RadioConverter},ConverterParameter=3}">玩家3</RadioButton> | |||
| <RadioButton GroupName="playerNum" Grid.Row="3" Visibility="{Binding UploadReadyVis}" IsChecked="{Binding PlayerNum,Mode=TwoWay,Converter={StaticResource RadioConverter},ConverterParameter=4}">玩家4</RadioButton> | |||
| </Grid> | |||
| </StackPanel> | |||
| <!--objects below are not enabled--> | |||
| <Button Grid.Row="5" Grid.Column="1" Name="Download" Content="下载回放" IsEnabled="False" Command="{Binding ClickDownloadCommand}" Visibility="{Binding CoverVis}" /> | |||
| <Button Grid.Row="7" Grid.Column="1" Name="Replay" Content="打开回放" IsEnabled="False" Command="{Binding ClickReplayCommand}" Visibility="{Binding CoverVis}" /> | |||
| <Button Grid.Row="3" Grid.Column="3" Grid.ColumnSpan="2" Content="申请对战" IsEnabled="False" Command="{Binding ClickRequestCommand}" Visibility="{Binding WebVis}" /> | |||
| <TextBox Grid.Row="4" Grid.Column="3" Grid.ColumnSpan="2" Text="暂不支持" IsEnabled="False" Visibility="{Binding WebVis}" /> | |||
| </Grid> | |||
| </Window> | |||
| @@ -49,6 +49,7 @@ namespace starter.viewmodel.settings | |||
| Password = ""; | |||
| updates = ""; | |||
| CodeRoute = ""; | |||
| PlayerNum = "nSelect"; | |||
| UploadReady = false; | |||
| LoginFailed = false; | |||
| } | |||
| @@ -166,7 +167,9 @@ namespace starter.viewmodel.settings | |||
| default: | |||
| return -8; | |||
| } | |||
| return await web.UploadFiles(client, CodeRoute, Language, "player_1"); | |||
| if (PlayerNum.Equals("nSelect")) | |||
| return -9; | |||
| return await web.UploadFiles(client, CodeRoute, Language, PlayerNum); | |||
| } | |||
| /// <summary> | |||
| /// Route of files | |||
| @@ -394,8 +397,8 @@ namespace Downloader | |||
| .Build(); // 创建 CosXmlConfig 对象 | |||
| // 永久密钥访问凭证 | |||
| string secretId = "***"; //"云 API 密钥 SecretId"; | |||
| string secretKey = "***"; //"云 API 密钥 SecretKey"; | |||
| string secretId = "***"; //"云 API 密钥 SecretId"; | |||
| string secretKey = "***"; //"云 API 密钥 SecretKey"; | |||
| long durationSecond = 1000; // 每次请求签名有效时长,单位为秒 | |||
| QCloudCredentialProvider cosCredentialProvider = new DefaultQCloudCredentialProvider( | |||
| @@ -1119,7 +1122,8 @@ namespace WebConnect | |||
| using FileStream fs = new FileStream(tarfile, FileMode.Open, FileAccess.Read); | |||
| using StreamReader sr = new StreamReader(fs); | |||
| content = sr.ReadToEnd(); | |||
| using (var response = await client.GetAsync($"https://api.eesast.com/static/player?team_id={await GetTeamId()}")) | |||
| string targetUrl = $"https://api.eesast.com/static/player?team_id={await GetTeamId()}"; | |||
| using (var response = await client.GetAsync(targetUrl)) | |||
| { | |||
| switch (response.StatusCode) | |||
| { | |||
| @@ -6,6 +6,7 @@ using System.Windows.Forms; | |||
| using Downloader; | |||
| using MessageBox = System.Windows.MessageBox; | |||
| using System.Configuration; | |||
| using System.Drawing.Design; | |||
| namespace starter.viewmodel.settings | |||
| { | |||
| @@ -133,6 +134,46 @@ namespace starter.viewmodel.settings | |||
| } | |||
| } | |||
| } | |||
| public int PlayerNum | |||
| { | |||
| get | |||
| { | |||
| int ans; | |||
| if (obj.PlayerNum.Equals("player_1")) | |||
| ans = 1; | |||
| else if (obj.PlayerNum.Equals("player_2")) | |||
| ans = 2; | |||
| else if (obj.PlayerNum.Equals("player_3")) | |||
| ans = 3; | |||
| else if (obj.PlayerNum.Equals("player_4")) | |||
| ans = 4; | |||
| else | |||
| ans = 0; | |||
| return ans; | |||
| } | |||
| set | |||
| { | |||
| switch (value) | |||
| { | |||
| case 1: | |||
| obj.PlayerNum = "player_1"; | |||
| break; | |||
| case 2: | |||
| obj.PlayerNum = "player_2"; | |||
| break; | |||
| case 3: | |||
| obj.PlayerNum = "player_3"; | |||
| break; | |||
| case 4: | |||
| obj.PlayerNum = "player_4"; | |||
| break; | |||
| default: | |||
| obj.PlayerNum = "nSelect"; | |||
| break; | |||
| } | |||
| this.RaisePropertyChanged("PlayerNum"); | |||
| } | |||
| } | |||
| public string Route | |||
| { | |||
| @@ -240,7 +281,7 @@ namespace starter.viewmodel.settings | |||
| { | |||
| get | |||
| { | |||
| return obj.UpdatePlanned ? "Update" : "Check Updates"; | |||
| return obj.UpdatePlanned ? "更新" : "检查更新"; | |||
| } | |||
| } | |||
| public string UpdateInfo | |||
| @@ -446,7 +487,9 @@ namespace starter.viewmodel.settings | |||
| } | |||
| else | |||
| { | |||
| obj.LoginFailed = false; | |||
| Status = SettingsModel.Status.web; | |||
| this.RaisePropertyChanged("CoverVis"); | |||
| } | |||
| this.RaisePropertyChanged("LoginFailVis"); | |||
| })); | |||
| @@ -528,38 +571,46 @@ namespace starter.viewmodel.settings | |||
| { | |||
| if (obj.UploadReady) | |||
| { | |||
| switch (await obj.Upload()) | |||
| if (obj.PlayerNum.Equals("nSelect")) | |||
| { | |||
| case -1: | |||
| MessageBox.Show("Token失效!", "", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); | |||
| break; | |||
| case -2: | |||
| MessageBox.Show("目标路径不存在!", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK); | |||
| break; | |||
| case -3: | |||
| MessageBox.Show("服务器错误", "", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); | |||
| break; | |||
| case -4: | |||
| MessageBox.Show("您未登录或登录失效", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK); | |||
| Status = SettingsModel.Status.login; | |||
| break; | |||
| case -5: | |||
| MessageBox.Show("您未报名THUAI!", "", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); | |||
| break; | |||
| case -6: | |||
| MessageBox.Show("读取文件失败,请确认文件是否被占用", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK); | |||
| break; | |||
| case -7: | |||
| MessageBox.Show("网络错误,请检查你的网络", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK); | |||
| break; | |||
| case -8: | |||
| MessageBox.Show("不是c++或python源文件", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK); | |||
| break; | |||
| MessageBox.Show("您还没有选择要上传的玩家身份", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK); | |||
| } | |||
| else | |||
| { | |||
| switch (await obj.Upload()) | |||
| { | |||
| case -1: | |||
| MessageBox.Show("Token失效!", "", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); | |||
| break; | |||
| case -2: | |||
| MessageBox.Show("目标路径不存在!", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK); | |||
| break; | |||
| case -3: | |||
| MessageBox.Show("服务器错误", "", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); | |||
| break; | |||
| case -4: | |||
| MessageBox.Show("您未登录或登录失效", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK); | |||
| Status = SettingsModel.Status.login; | |||
| break; | |||
| case -5: | |||
| MessageBox.Show("您未报名THUAI!", "", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); | |||
| break; | |||
| case -6: | |||
| MessageBox.Show("读取文件失败,请确认文件是否被占用", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK); | |||
| break; | |||
| case -7: | |||
| MessageBox.Show("网络错误,请检查你的网络", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK); | |||
| break; | |||
| case -8: | |||
| MessageBox.Show("不是c++或python源文件", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK); | |||
| break; | |||
| } | |||
| obj.CodeRoute = ""; | |||
| obj.UploadReady = false; | |||
| this.RaisePropertyChanged("UploadBtnCont"); | |||
| this.RaisePropertyChanged("UploadReadyVis"); | |||
| this.RaisePropertyChanged("CoverVis"); | |||
| } | |||
| obj.CodeRoute = ""; | |||
| obj.UploadReady = false; | |||
| this.RaisePropertyChanged("UploadBtnCont"); | |||
| this.RaisePropertyChanged("UploadReadyVis"); | |||
| } | |||
| else | |||
| { | |||
| @@ -570,6 +621,7 @@ namespace starter.viewmodel.settings | |||
| this.RaisePropertyChanged("UploadBtnCont"); | |||
| this.RaisePropertyChanged("UploadReadyVis"); | |||
| this.RaisePropertyChanged("CodeName"); | |||
| this.RaisePropertyChanged("CoverVis"); | |||
| } | |||
| else | |||
| { | |||
| @@ -581,6 +633,26 @@ namespace starter.viewmodel.settings | |||
| return clickUploadCommand; | |||
| } | |||
| } | |||
| private BaseCommand clickReselectCommand; | |||
| public BaseCommand ClickReselectCommand | |||
| { | |||
| get | |||
| { | |||
| if (clickReselectCommand == null) | |||
| { | |||
| clickReselectCommand = new BaseCommand(new Action<object>(o => | |||
| { | |||
| obj.CodeRoute = ""; | |||
| obj.UploadReady = false; | |||
| this.RaisePropertyChanged("UploadBtnCont"); | |||
| this.RaisePropertyChanged("UploadReadyVis"); | |||
| this.RaisePropertyChanged("CodeName"); | |||
| this.RaisePropertyChanged("CoverVis"); | |||
| })); | |||
| } | |||
| return clickReselectCommand; | |||
| } | |||
| } | |||
| } | |||
| } | |||