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 16 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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. //TODO: Thread will be taken by process working and window will not refresh.
  87. this.RaisePropertyChanged("CompleteVis");
  88. this.RaisePropertyChanged("WindowWidth");
  89. this.RaisePropertyChanged("WebVis");
  90. }
  91. }
  92. public string Intro
  93. {
  94. get
  95. {
  96. switch (Status)
  97. {
  98. case SettingsModel.Status.newUser:
  99. return "欢迎使用选手包,请选择你想要安装选手包的位置:";
  100. case SettingsModel.Status.menu:
  101. return "你已经安装了选手包,请选择想要进行的操作:";
  102. case SettingsModel.Status.login:
  103. return "使用EESAST账号登录";
  104. case SettingsModel.Status.web:
  105. return "THUAI6 赛场:";
  106. case SettingsModel.Status.disconnected:
  107. return "你可能没有连接到网络,无法下载/更新选手包";
  108. case SettingsModel.Status.error:
  109. return "我们遇到了一些问题,请向[]反馈";
  110. default:
  111. return "";
  112. }
  113. }
  114. }
  115. public string RouteBoxIntro
  116. {
  117. get
  118. {
  119. switch (Status)
  120. {
  121. case SettingsModel.Status.newUser:
  122. return "将主体程序安装在:";
  123. case SettingsModel.Status.move:
  124. return "将主体程序移动到:";
  125. default:
  126. return "";
  127. }
  128. }
  129. }
  130. public string Route
  131. {
  132. get
  133. {
  134. return obj.Route;
  135. }
  136. set
  137. {
  138. obj.Route = value;
  139. this.RaisePropertyChanged("Route");
  140. }
  141. }
  142. public string Username
  143. {
  144. get
  145. {
  146. return obj.Username;
  147. }
  148. set
  149. {
  150. obj.Username = value;
  151. this.RaisePropertyChanged("Username");
  152. }
  153. }
  154. public string Password
  155. {
  156. get { return obj.Password; }
  157. set
  158. {
  159. obj.Password = value;
  160. this.RaisePropertyChanged("Password");
  161. }
  162. }
  163. public Visibility MenuVis
  164. {
  165. get
  166. {
  167. return Status == SettingsModel.Status.menu ? Visibility.Visible : Visibility.Collapsed;
  168. }
  169. }
  170. public Visibility RouteBoxVis
  171. {
  172. get
  173. {
  174. return (Status == SettingsModel.Status.newUser || Status == SettingsModel.Status.move) ? Visibility.Visible : Visibility.Collapsed;
  175. }
  176. }
  177. public Visibility LoginVis
  178. {
  179. get
  180. {
  181. return Status == SettingsModel.Status.login ? Visibility.Visible : Visibility.Collapsed;
  182. }
  183. }
  184. public Visibility ProgressVis
  185. {
  186. get
  187. {
  188. return Status == SettingsModel.Status.working ? Visibility.Visible : Visibility.Collapsed;
  189. }
  190. }
  191. public Visibility CompleteVis
  192. {
  193. get
  194. {
  195. return Status == SettingsModel.Status.successful ? Visibility.Visible : Visibility.Collapsed;
  196. }
  197. }
  198. public Visibility WebVis
  199. {
  200. get
  201. {
  202. return Status == SettingsModel.Status.web ? Visibility.Visible : Visibility.Collapsed;
  203. }
  204. }
  205. public Visibility LoginFailVis
  206. {
  207. get
  208. {
  209. return obj.LoginFailed ? Visibility.Visible : Visibility.Collapsed;
  210. }
  211. }
  212. public Visibility MatchFinishedVis
  213. {
  214. get
  215. {
  216. return obj.CombatCompleted ? Visibility.Visible : Visibility.Collapsed;
  217. }
  218. }
  219. public string UpdateBtnCont
  220. {
  221. get
  222. {
  223. return obj.UpdatePlanned ? "Update" : "Check Updates";
  224. }
  225. }
  226. public string UpdateInfo
  227. {
  228. get
  229. {
  230. if (obj.UpdatePlanned)
  231. return obj.Updates;
  232. else
  233. return "";
  234. }
  235. }
  236. public string LaunchBtnCont
  237. {
  238. get
  239. {
  240. return obj.UpdatePlanned ? "更新" : "启动";
  241. }
  242. }
  243. private BaseCommand clickBrowseCommand;
  244. public BaseCommand ClickBrowseCommand
  245. {
  246. get
  247. {
  248. if (clickBrowseCommand == null)
  249. {
  250. clickBrowseCommand = new BaseCommand(new Action<object>(o =>
  251. {
  252. using (FolderBrowserDialog dialog = new FolderBrowserDialog())
  253. {
  254. _ = dialog.ShowDialog();
  255. if (dialog.SelectedPath != String.Empty)
  256. Route = dialog.SelectedPath;
  257. }
  258. }));
  259. }
  260. return clickBrowseCommand;
  261. }
  262. }
  263. private BaseCommand clickConfirmCommand;
  264. public BaseCommand ClickConfirmCommand
  265. {
  266. get
  267. {
  268. if (clickConfirmCommand == null)
  269. {
  270. clickConfirmCommand = new BaseCommand(new Action<object>(o =>
  271. {
  272. if (Status == SettingsModel.Status.newUser)
  273. {
  274. Status = SettingsModel.Status.working;
  275. this.RaisePropertyChanged("ProgressVis");
  276. if (obj.install())
  277. {
  278. Status = SettingsModel.Status.successful;
  279. }
  280. }
  281. else if (Status == SettingsModel.Status.move)
  282. {
  283. Status = SettingsModel.Status.working;
  284. this.RaisePropertyChanged("ProgressVis");
  285. switch (obj.move())
  286. {
  287. case -1:
  288. MessageBox.Show("文件已打开或者目标路径下有同名文件!", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK);
  289. break;
  290. case -2:
  291. Status = SettingsModel.Status.error;
  292. break;
  293. }
  294. Status = SettingsModel.Status.successful;
  295. }
  296. }));
  297. }
  298. return clickConfirmCommand;
  299. }
  300. }
  301. private BaseCommand clickUpdateCommand;
  302. public BaseCommand ClickUpdateCommand
  303. {
  304. get
  305. {
  306. if (clickUpdateCommand == null)
  307. {
  308. clickUpdateCommand = new BaseCommand(new Action<object>(o =>
  309. {
  310. if (obj.UpdatePlanned)
  311. {
  312. Status = SettingsModel.Status.working;
  313. this.RaisePropertyChanged("ProgressVis");
  314. if (obj.Update())
  315. {
  316. Status = SettingsModel.Status.successful;
  317. this.RaisePropertyChanged("UpdateBtnCont");
  318. this.RaisePropertyChanged("UpdateInfo");
  319. }
  320. else
  321. Status = SettingsModel.Status.error;
  322. }
  323. else
  324. {
  325. Status = SettingsModel.Status.working;
  326. this.RaisePropertyChanged("ProgressVis");
  327. Status = obj.checkUpdate();
  328. this.RaisePropertyChanged("UpdateBtnCont");
  329. this.RaisePropertyChanged("UpdateInfo");
  330. }
  331. }));
  332. }
  333. return clickUpdateCommand;
  334. }
  335. }
  336. private BaseCommand clickMoveCommand;
  337. public BaseCommand ClickMoveCommand
  338. {
  339. get
  340. {
  341. if (clickMoveCommand == null)
  342. {
  343. clickMoveCommand = new BaseCommand(new Action<object>(o =>
  344. {
  345. Status = SettingsModel.Status.move;
  346. }));
  347. }
  348. return clickMoveCommand;
  349. }
  350. }
  351. private BaseCommand clickUninstCommand;
  352. public BaseCommand ClickUninstCommand
  353. {
  354. get
  355. {
  356. if (clickUninstCommand == null)
  357. {
  358. clickUninstCommand = new BaseCommand(new Action<object>(o =>
  359. {
  360. Status = SettingsModel.Status.working;
  361. this.RaisePropertyChanged("ProgressVis");
  362. switch (obj.Uninst())
  363. {
  364. case -1:
  365. Status = SettingsModel.Status.menu;
  366. MessageBox.Show("文件已经打开,请关闭后再删除", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK);
  367. break;
  368. case 0:
  369. Status = SettingsModel.Status.successful;
  370. break;
  371. default:
  372. Status = SettingsModel.Status.error;
  373. break;
  374. }
  375. }));
  376. }
  377. return clickUninstCommand;
  378. }
  379. }
  380. private BaseCommand clickLoginCommand;
  381. public BaseCommand ClickLoginCommand
  382. {
  383. get
  384. {
  385. if (clickLoginCommand == null)
  386. {
  387. clickLoginCommand = new BaseCommand(new Action<object>(o =>
  388. {
  389. obj.Login();
  390. this.RaisePropertyChanged("LoginFailVis");
  391. }));
  392. }
  393. return clickLoginCommand;
  394. }
  395. }
  396. private BaseCommand clickLaunchCommand;
  397. public BaseCommand ClickLaunchCommand
  398. {
  399. get
  400. {
  401. if (clickLaunchCommand == null)
  402. {
  403. clickLaunchCommand = new BaseCommand(new Action<object>(o =>
  404. {
  405. if (obj.UpdatePlanned)
  406. {
  407. Status = SettingsModel.Status.working;
  408. this.RaisePropertyChanged("ProgressVis");
  409. if (obj.Update())
  410. {
  411. this.RaisePropertyChanged("UpdateBtnCont");
  412. this.RaisePropertyChanged("LaunchBtnCont");
  413. Status = SettingsModel.Status.login;
  414. this.RaisePropertyChanged("UpdateInfo");
  415. }
  416. else
  417. Status = SettingsModel.Status.error;
  418. }
  419. else if (!obj.Launch())
  420. {
  421. Status = SettingsModel.Status.menu;
  422. }
  423. }));
  424. }
  425. return clickLaunchCommand;
  426. }
  427. }
  428. private BaseCommand clickEditCommand;
  429. public BaseCommand ClickEditCommand
  430. {
  431. get
  432. {
  433. if (clickEditCommand == null)
  434. {
  435. clickEditCommand = new BaseCommand(new Action<object>(o =>
  436. {
  437. Status = SettingsModel.Status.menu;
  438. }));
  439. }
  440. return clickEditCommand;
  441. }
  442. }
  443. private BaseCommand clickBackCommand;
  444. public BaseCommand ClickBackCommand
  445. {
  446. get
  447. {
  448. if (clickBackCommand == null)
  449. {
  450. clickBackCommand = new BaseCommand(new Action<object>(o =>
  451. {
  452. Status = SettingsModel.Status.login;
  453. }));
  454. }
  455. return clickBackCommand;
  456. }
  457. }
  458. }
  459. }