diff --git a/dependency/proto/Services.proto b/dependency/proto/Services.proto
index 5385004..7104849 100755
--- a/dependency/proto/Services.proto
+++ b/dependency/proto/Services.proto
@@ -20,8 +20,8 @@ service AvailableService
rpc SendMessage (SendMsg) returns (BoolRes);
// rpc GetMessage (IDMsg) returns (stream MsgRes);
rpc StartLearning (IDMsg) returns (BoolRes); // 开始修理机器
- rpc StartRescueMate (TreatAndRescueMsg) returns (BoolRes); // 开始救人
- rpc StartTreatMate (TreatAndRescueMsg) returns (BoolRes);
+ rpc StartRescueMate (IDMsg) returns (BoolRes); // 开始救人
+ rpc StartTreatMate (IDMsg) returns (BoolRes); // 开始治疗
rpc Attack (AttackMsg) returns (BoolRes); // 攻击
rpc Graduate (IDMsg) returns (BoolRes); // 相当于逃跑
rpc OpenDoor (IDMsg) returns (BoolRes); // 开门
diff --git a/installer/Installer/MainWindow.xaml b/installer/Installer/MainWindow.xaml
index 957889f..3f54032 100644
--- a/installer/Installer/MainWindow.xaml
+++ b/installer/Installer/MainWindow.xaml
@@ -5,16 +5,17 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Installer"
mc:Ignorable="d"
- Title="Installer" Height="450" Width="800">
+ Title="Installer" Height="200" Window.SizeToContent="Width">
-
-
-
-
+
+
+
+
+
@@ -26,22 +27,44 @@
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
-
diff --git a/installer/Installer/Model.cs b/installer/Installer/Model.cs
index 2545693..bef2386 100644
--- a/installer/Installer/Model.cs
+++ b/installer/Installer/Model.cs
@@ -22,6 +22,9 @@ using System.Windows;
using System.Windows.Shapes;
//using System.Windows.Forms;
+using MessageBox = System.Windows.MessageBox;
+using Downloader;
+
namespace starter.viewmodel.settings
{
///
@@ -32,27 +35,25 @@ namespace starter.viewmodel.settings
///
/// downloader function
///
- 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();
///
/// save settings
///
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;
- if (repeatOption == MessageBoxResult.Cancel)
+ if (repeatOption == MessageBoxResult.No)
{
return false; // 回到选择地址界面
}
- else if (repeatOption == MessageBoxResult.No)
- {
- System.Environment.Exit(0);
- return false;
- }
else
{
Downloader.Program.Tencent_cos_download.MoveProgram(Route);
@@ -61,11 +62,76 @@ namespace starter.viewmodel.settings
}
else
{
- Downloader.Program.Data.ResetFilepath(Route);
- Downloader.Program.Tencent_cos_download.DownloadAll();
+ Data.ResetFilepath(Route);
+ Tencent_cos_download.DownloadAll();
return true;
}
}
+ public int move()
+ {
+ return Tencent_cos_download.MoveProgram(Route);
+ }
+ ///
+ ///check for update
+ ///
+ static bool ProfileAvailable
+ {
+ get; set;
+ }
+ ///
+ /// 检查更新
+ ///
+ ///
+ 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;
+ }
+ }
///
/// Route of files
///
@@ -73,24 +139,69 @@ namespace starter.viewmodel.settings
{
get
{
- return Downloader.Program.Data.FilePath;
+ return Data.FilePath;
}
set
{
- Downloader.Program.Data.FilePath = value;
+ Data.FilePath = value;
}
}
+
+ public string Username
+ {
+ get; set;
+ }
+ public string Password
+ {
+ get; set;
+ }
///
- /// if the route was set or is under editing
+ /// 关于更新的屏幕显示信息
///
- public bool EditingRoute
+ private string updates;
+ public string Updates
+ {
+ get
+ {
+ return updates;
+ }
+ set
+ {
+ updates = value;
+ }
+ }
+ ///
+ /// 关于介绍的屏幕显示信息
+ ///
+ public enum Status { newUser, menu, move, working, disconnected, error, successful, login, web };
+ public Status status
+ {
+ get; set;
+ }
+ public bool Working
{
get; set;
}
- ///< summary>
- /// if already installed
- ///
- public bool installed
+ ///
+ /// if an update is planned
+ ///
+ public bool UpdatePlanned
+ {
+ get
+ {
+ return Program.UpdatePlanned;
+ }
+ }
+
+ public bool CombatCompleted
+ {
+ get
+ {
+ return false;
+ }
+ }
+
+ public bool LoginFailed
{
get; set;
}
@@ -102,9 +213,21 @@ namespace Downloader
{
static List newFileName = new List(); // 新文件名
static List updateFileName = new List(); // 更新文件名
- 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; // 总文件个数
public class Data
@@ -283,13 +406,14 @@ namespace Downloader
}
}
- private static void Check()
+ public static UpdateInfo Check()
{
string json, MD5, jsonName;
int newFile = 0, updateFile = 0;
newFileName.Clear();
updateFileName.Clear();
jsonName = "hash.json";
+ UpdateInfo updateInfo;
Tencent_cos_download Downloader = new Tencent_cos_download();
try
@@ -308,14 +432,18 @@ namespace Downloader
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)
{
// 请求失败
- 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)))
@@ -334,22 +462,29 @@ namespace Downloader
newFile = newFileName.Count;
updateFile = updateFileName.Count;
filenum = newFile + updateFile;
- Console.WriteLine("----------------------" + Environment.NewLine);
+ //Console.WriteLine("----------------------" + Environment.NewLine);
if (newFile + updateFile == 0)
{
- Console.WriteLine("当前平台已是最新版本!" + Environment.NewLine);
+ updateInfo.status = "latest";
+ updateInfo.newFileCount = 0;
+ updateInfo.changedFileCount = 0;
newFileName.Clear();
updateFileName.Clear();
}
else
{
- Console.WriteLine($"发现{newFile}个新文件" + Environment.NewLine);
+ updateInfo.status = "old";
+ //TODO:获取版本号
+ updateInfo.newFileCount = newFile;
+ /*
foreach (string filename in newFileName)
{
Console.WriteLine(filename);
}
- Console.WriteLine(Environment.NewLine + $"发现{updateFile}个文件更新" + Environment.NewLine);
+ */
+ updateInfo.changedFileCount = updateFile;
+ /*
foreach (string filename in updateFileName)
{
Console.WriteLine(filename);
@@ -359,8 +494,23 @@ namespace Downloader
Console.WriteLine("下载取消!");
else
Download();
+ */
+ UpdatePlanned = true;
+ }
+ return updateInfo;
+ }
+
+ public static bool Update()
+ {
+ if (UpdatePlanned)
+ {
+ Download();
+ UpdatePlanned = false;
+ return true;
}
+ return false;
}
+
private static void 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 player = new DirectoryInfo(System.IO.Path.GetFullPath(System.IO.Path.Combine(Data.FilePath, playerFolder)));
@@ -619,17 +769,17 @@ namespace Downloader
catch (UnauthorizedAccessException)
{
Console.WriteLine("权限不足,无法删除!");
- return;
+ return -2;
}
catch (DirectoryNotFoundException)
{
Console.WriteLine("文件夹没有找到,请检查是否已经手动更改路径");
- return;
+ return -3;
}
catch (IOException)
{
Console.WriteLine("文件已经打开,请关闭后再删除");
- return;
+ return -1;
}
string json2;
@@ -665,19 +815,20 @@ namespace Downloader
catch (UnauthorizedAccessException)
{
Console.WriteLine("权限不足,无法删除!");
- return;
+ return -2;
}
catch (DirectoryNotFoundException)
{
Console.WriteLine("文件夹没有找到,请检查是否已经手动更改路径");
- return;
+ return -3;
}
catch (IOException)
{
Console.WriteLine("文件已经打开,请关闭后再删除");
- return;
+ return -1;
}
Console.WriteLine($"删除成功!player文件夹中的文件已经放在{ProgramName}的根目录下");
+ return 0;
}
public static void OverwriteHash(Dictionary jsonDict)
@@ -687,7 +838,7 @@ namespace Downloader
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 olddi = new DirectoryInfo(Data.FilePath);
@@ -714,6 +865,7 @@ namespace Downloader
file.MoveTo(System.IO.Path.Combine(Data.FilePath, file.Name));
}
Console.WriteLine("移动失败!");
+ return -2;
}
catch (IOException)
{
@@ -727,9 +879,11 @@ namespace Downloader
file.MoveTo(System.IO.Path.Combine(Data.FilePath, file.Name));
}
Console.WriteLine("移动失败!");
+ return -1;
}
Data.ResetFilepath(newPath);
Console.WriteLine("更改路径成功!");
+ return 0;
}
public static async Task main(string[] args)
{
diff --git a/installer/Installer/ViewModel.cs b/installer/Installer/ViewModel.cs
index 0bff2cd..ea6226c 100644
--- a/installer/Installer/ViewModel.cs
+++ b/installer/Installer/ViewModel.cs
@@ -3,6 +3,9 @@ using starter.viewmodel.common;
using System;
using System.Windows;
using System.Windows.Forms;
+using Downloader;
+using MessageBox = System.Windows.MessageBox;
+using System.Configuration;
namespace starter.viewmodel.settings
{
@@ -19,12 +22,111 @@ namespace starter.viewmodel.settings
{
if (Downloader.Program.Tencent_cos_download.CheckAlreadyDownload())
{
- Installed = true;
+ obj.checkUpdate();
+ Status = SettingsModel.Status.login;
+ this.RaisePropertyChanged("WindowWidth");
+ //TODO:在启动时立刻检查更新,确保选手启动最新版选手包
+ //TODO:若有更新,将启动键改为更新键;
+ //TODO:相应地,使用login界面启动;
+ //TODO:结构:上方为登录框架,下方有“修改选手包”按钮
}
else
{
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");
}
}
- public bool Installed
+ public string Username
{
get
{
- return obj.installed;
+ return obj.Username;
}
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
{
- 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
{
- return obj.EditingRoute ? Visibility.Visible : Visibility.Collapsed;
+ return Status == SettingsModel.Status.login ? Visibility.Visible : Visibility.Collapsed;
}
}
- ///
- /// if the install/edit instruction can be seen
- ///
- public Visibility InstIntroVis
+ public Visibility ProgressVis
+ {
+ get
+ {
+ return Status == SettingsModel.Status.working ? Visibility.Visible : Visibility.Collapsed;
+ }
+ }
+ public Visibility CompleteVis
{
get
{
- return obj.installed ? Visibility.Collapsed : Visibility.Visible;
+ return Status == SettingsModel.Status.successful ? Visibility.Visible : Visibility.Collapsed;
}
}
- public Visibility EditIntroVis
+ public Visibility WebVis
{
get
{
- return obj.installed ? Visibility.Visible : Visibility.Collapsed;
+ return Status == SettingsModel.Status.web ? Visibility.Visible : Visibility.Collapsed;
}
}
- public Visibility MoveIntroVis
+ public Visibility LoginFailVis
{
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
- return Visibility.Collapsed;
+ return "";
+ }
+ }
+ public string LaunchBtnCont
+ {
+ get
+ {
+ return obj.UpdatePlanned ? "更新" : "启动";
}
}
@@ -133,15 +274,175 @@ namespace starter.viewmodel.settings
{
clickConfirmCommand = new BaseCommand(new Action