You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ViewModel.cs 15 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. 
  2. using starter.viewmodel.common;
  3. using System;
  4. using System.Windows;
  5. using System.Windows.Forms;
  6. using Downloader;
  7. using MessageBox = System.Windows.MessageBox;
  8. using System.Configuration;
  9. namespace starter.viewmodel.settings
  10. {
  11. public class SettingsViewModel : NotificationObject
  12. {
  13. /// <summary>
  14. /// Model object
  15. /// </summary>
  16. private SettingsModel obj = new SettingsModel();
  17. /// <summary>
  18. /// initializer
  19. /// </summary>
  20. public SettingsViewModel()
  21. {
  22. if (Downloader.Program.Tencent_cos_download.CheckAlreadyDownload())
  23. {
  24. obj.checkUpdate();
  25. Status = SettingsModel.Status.login;
  26. this.RaisePropertyChanged("WindowWidth");
  27. //TODO:在启动时立刻检查更新,确保选手启动最新版选手包
  28. //TODO:若有更新,将启动键改为更新键;
  29. //TODO:相应地,使用login界面启动;
  30. //TODO:结构:上方为登录框架,下方有“修改选手包”按钮
  31. }
  32. else
  33. {
  34. Route = Environment.GetEnvironmentVariable("USERPROFILE") + "\\THUAI6";
  35. Status = SettingsModel.Status.newUser;
  36. this.RaisePropertyChanged("WindowWidth");
  37. }
  38. }
  39. //TODO:参赛界面:包括上传参赛代码、申请对战
  40. //TODO:界面中应包含上次对战完成提示及下载回放按钮
  41. public int ExtraColumn
  42. {
  43. get
  44. {
  45. if (Status == SettingsModel.Status.newUser || Status == SettingsModel.Status.move)
  46. return 75;
  47. else
  48. return 0;
  49. }
  50. }
  51. public int WindowWidth
  52. {
  53. get
  54. {
  55. switch (Status)
  56. {
  57. case SettingsModel.Status.newUser:
  58. return 505;
  59. case SettingsModel.Status.move:
  60. return 505;
  61. case SettingsModel.Status.working:
  62. return 435;
  63. case SettingsModel.Status.successful:
  64. return 435;
  65. default:
  66. return 355;
  67. }
  68. }
  69. }
  70. public SettingsModel.Status Status
  71. {
  72. get
  73. {
  74. return obj.status;
  75. }
  76. set
  77. {
  78. obj.status = value;
  79. this.RaisePropertyChanged("ExtraColumn");
  80. this.RaisePropertyChanged("Intro");
  81. this.RaisePropertyChanged("RouteBoxIntro");
  82. this.RaisePropertyChanged("LoginVis");
  83. this.RaisePropertyChanged("MenuVis");
  84. this.RaisePropertyChanged("RouteBoxVis");
  85. this.RaisePropertyChanged("ProgressVis");
  86. this.RaisePropertyChanged("CompleteVis");
  87. }
  88. }
  89. public string Intro
  90. {
  91. get
  92. {
  93. switch (Status)
  94. {
  95. case SettingsModel.Status.newUser:
  96. return "欢迎使用选手包,请选择你想要安装选手包的位置:";
  97. case SettingsModel.Status.menu:
  98. return "你已经安装了选手包,请选择想要进行的操作:";
  99. case SettingsModel.Status.login:
  100. return "使用EESAST账号登录";
  101. case SettingsModel.Status.web:
  102. return "THUAI6 赛场:";
  103. case SettingsModel.Status.disconnected:
  104. return "你可能没有连接到网络,无法下载/更新选手包";
  105. case SettingsModel.Status.error:
  106. return "我们遇到了一些问题,请向[]反馈";
  107. default:
  108. return "";
  109. }
  110. }
  111. }
  112. public string RouteBoxIntro
  113. {
  114. get
  115. {
  116. switch (Status)
  117. {
  118. case SettingsModel.Status.newUser:
  119. return "将主体程序安装在:";
  120. case SettingsModel.Status.move:
  121. return "将主体程序移动到:";
  122. default:
  123. return "";
  124. }
  125. }
  126. }
  127. public string Route
  128. {
  129. get
  130. {
  131. return obj.Route;
  132. }
  133. set
  134. {
  135. obj.Route = value;
  136. this.RaisePropertyChanged("Route");
  137. }
  138. }
  139. public string Username
  140. {
  141. get
  142. {
  143. return obj.Username;
  144. }
  145. set
  146. {
  147. obj.Username = value;
  148. this.RaisePropertyChanged("Username");
  149. }
  150. }
  151. public string Password
  152. {
  153. get { return obj.Password; }
  154. set
  155. {
  156. obj.Password = value;
  157. this.RaisePropertyChanged("Password");
  158. }
  159. }
  160. public Visibility MenuVis
  161. {
  162. get
  163. {
  164. return Status == SettingsModel.Status.menu ? Visibility.Visible : Visibility.Collapsed;
  165. }
  166. }
  167. public Visibility RouteBoxVis
  168. {
  169. get
  170. {
  171. return (Status == SettingsModel.Status.newUser || Status == SettingsModel.Status.move) ? Visibility.Visible : Visibility.Collapsed;
  172. }
  173. }
  174. public Visibility LoginVis
  175. {
  176. get
  177. {
  178. return Status == SettingsModel.Status.login ? Visibility.Visible : Visibility.Collapsed;
  179. }
  180. }
  181. public Visibility ProgressVis
  182. {
  183. get
  184. {
  185. return Status == SettingsModel.Status.working ? Visibility.Visible : Visibility.Collapsed;
  186. }
  187. }
  188. public Visibility CompleteVis
  189. {
  190. get
  191. {
  192. return Status == SettingsModel.Status.successful ? Visibility.Visible : Visibility.Collapsed;
  193. }
  194. }
  195. public Visibility WebVis
  196. {
  197. get
  198. {
  199. return Status == SettingsModel.Status.web ? Visibility.Visible : Visibility.Collapsed;
  200. }
  201. }
  202. public Visibility LoginFailVis
  203. {
  204. get
  205. {
  206. return obj.LoginFailed ? Visibility.Visible : Visibility.Collapsed;
  207. }
  208. }
  209. public Visibility MatchFinishedVis
  210. {
  211. get
  212. {
  213. return obj.CombatCompleted ? Visibility.Visible : Visibility.Collapsed;
  214. }
  215. }
  216. public string UpdateBtnCont
  217. {
  218. get
  219. {
  220. return obj.UpdatePlanned ? "Update" : "Check Updates";
  221. }
  222. }
  223. public string UpdateInfo
  224. {
  225. get
  226. {
  227. if (obj.UpdatePlanned)
  228. return obj.Updates;
  229. else
  230. return "";
  231. }
  232. }
  233. public string LaunchBtnCont
  234. {
  235. get
  236. {
  237. return obj.UpdatePlanned ? "更新" : "启动";
  238. }
  239. }
  240. private BaseCommand clickBrowseCommand;
  241. public BaseCommand ClickBrowseCommand
  242. {
  243. get
  244. {
  245. if (clickBrowseCommand == null)
  246. {
  247. clickBrowseCommand = new BaseCommand(new Action<object>(o =>
  248. {
  249. using (FolderBrowserDialog dialog = new FolderBrowserDialog())
  250. {
  251. _ = dialog.ShowDialog();
  252. if (dialog.SelectedPath != String.Empty)
  253. Route = dialog.SelectedPath;
  254. }
  255. }));
  256. }
  257. return clickBrowseCommand;
  258. }
  259. }
  260. private BaseCommand clickConfirmCommand;
  261. public BaseCommand ClickConfirmCommand
  262. {
  263. get
  264. {
  265. if (clickConfirmCommand == null)
  266. {
  267. clickConfirmCommand = new BaseCommand(new Action<object>(o =>
  268. {
  269. if (Status == SettingsModel.Status.newUser)
  270. {
  271. Status = SettingsModel.Status.working;
  272. if (obj.install())
  273. {
  274. Status = SettingsModel.Status.menu;
  275. }
  276. }
  277. else if (Status == SettingsModel.Status.move)
  278. {
  279. Status = SettingsModel.Status.working;
  280. switch (obj.move())
  281. {
  282. case -1:
  283. MessageBox.Show("文件已打开或者目标路径下有同名文件!", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK);
  284. break;
  285. case -2:
  286. Status = SettingsModel.Status.error;
  287. break;
  288. }
  289. }
  290. }));
  291. }
  292. return clickConfirmCommand;
  293. }
  294. }
  295. private BaseCommand clickUpdateCommand;
  296. public BaseCommand ClickUpdateCommand
  297. {
  298. get
  299. {
  300. if (clickUpdateCommand == null)
  301. {
  302. clickUpdateCommand = new BaseCommand(new Action<object>(o =>
  303. {
  304. if (obj.UpdatePlanned)
  305. {
  306. Status = SettingsModel.Status.working;
  307. if (obj.Update())
  308. {
  309. Status = SettingsModel.Status.successful;
  310. this.RaisePropertyChanged("UpdateButtonCont");
  311. }
  312. else
  313. Status = SettingsModel.Status.error;
  314. }
  315. else
  316. {
  317. Status = SettingsModel.Status.working;
  318. Status = obj.checkUpdate();
  319. this.RaisePropertyChanged("UpdateButtonCont");
  320. }
  321. }));
  322. }
  323. return clickUpdateCommand;
  324. }
  325. }
  326. private BaseCommand clickMoveCommand;
  327. public BaseCommand ClickMoveCommand
  328. {
  329. get
  330. {
  331. if (clickMoveCommand == null)
  332. {
  333. clickMoveCommand = new BaseCommand(new Action<object>(o =>
  334. {
  335. Status = SettingsModel.Status.move;
  336. }));
  337. }
  338. return clickMoveCommand;
  339. }
  340. }
  341. private BaseCommand clickUninstCommand;
  342. public BaseCommand ClickUninstCommand
  343. {
  344. get
  345. {
  346. if (clickUninstCommand == null)
  347. {
  348. clickUninstCommand = new BaseCommand(new Action<object>(o =>
  349. {
  350. Status = SettingsModel.Status.working;
  351. switch (obj.Uninst())
  352. {
  353. case -1:
  354. Status = SettingsModel.Status.menu;
  355. MessageBox.Show("文件已经打开,请关闭后再删除", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK);
  356. break;
  357. case 0:
  358. Status = SettingsModel.Status.successful;
  359. break;
  360. default:
  361. Status = SettingsModel.Status.error;
  362. break;
  363. }
  364. }));
  365. }
  366. return clickUninstCommand;
  367. }
  368. }
  369. private BaseCommand clickLoginCommand;
  370. public BaseCommand ClickLoginCommand
  371. {
  372. get
  373. {
  374. if (clickLoginCommand == null)
  375. {
  376. clickLoginCommand = new BaseCommand(new Action<object>(o =>
  377. {
  378. obj.Login();
  379. this.RaisePropertyChanged("LoginFailVis");
  380. }));
  381. }
  382. return clickLoginCommand;
  383. }
  384. }
  385. private BaseCommand clickLaunchCommand;
  386. public BaseCommand ClickLaunchCommand
  387. {
  388. get
  389. {
  390. if (clickLaunchCommand == null)
  391. {
  392. clickLaunchCommand = new BaseCommand(new Action<object>(o =>
  393. {
  394. if (!obj.Launch())
  395. {
  396. Status = SettingsModel.Status.menu;
  397. }
  398. }));
  399. }
  400. return clickLaunchCommand;
  401. }
  402. }
  403. private BaseCommand clickEditCommand;
  404. public BaseCommand ClickEditCommand
  405. {
  406. get
  407. {
  408. if (clickEditCommand == null)
  409. {
  410. clickEditCommand = new BaseCommand(new Action<object>(o =>
  411. {
  412. Status = SettingsModel.Status.menu;
  413. }));
  414. }
  415. return clickEditCommand;
  416. }
  417. }
  418. private BaseCommand clickLogoutCommand;
  419. public BaseCommand ClickLogoutCommand
  420. {
  421. get
  422. {
  423. if (clickLogoutCommand == null)
  424. {
  425. clickLogoutCommand = new BaseCommand(new Action<object>(o =>
  426. {
  427. Status = SettingsModel.Status.login;
  428. }));
  429. }
  430. return clickLogoutCommand;
  431. }
  432. }
  433. }
  434. }