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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028
  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. using System.Drawing.Design;
  10. using Application = System.Windows.Application;
  11. using System.ComponentModel;
  12. using Installer;
  13. using static System.Windows.Forms.VisualStyles.VisualStyleElement;
  14. using System.IO;
  15. using System.Windows.Automation.Provider;
  16. using System.Diagnostics;
  17. namespace starter.viewmodel.settings
  18. {
  19. public class SettingsViewModel : NotificationObject
  20. {
  21. //定义BackgroundWorker
  22. BackgroundWorker asyncDownloader;
  23. BackgroundWorker asyncUpdater;
  24. /// <summary>
  25. /// Model object
  26. /// </summary>
  27. private SettingsModel obj = new SettingsModel();
  28. /// <summary>
  29. /// initializer
  30. /// </summary>
  31. public SettingsViewModel()
  32. {
  33. //Program.Tencent_cos_download.UpdateHash();
  34. Status = SettingsModel.Status.working;
  35. switch (Program.Tencent_cos_download.CheckSelfVersion())
  36. {
  37. case 1:
  38. if (MessageBoxResult.Yes == MessageBox.Show("下载器需要更新,是否现在更新", "需要更新", MessageBoxButton.YesNo))
  39. {
  40. Process.Start(Path.Combine(Directory.GetCurrentDirectory(), "InstallerUpdater.exe"));
  41. Environment.Exit(0);
  42. }
  43. break;
  44. case -1:
  45. MessageBox.Show("下载器更新检查出错,将继续启动现有下载器");
  46. break;
  47. }
  48. //实例化BackgroundWorker
  49. asyncDownloader = new BackgroundWorker();
  50. asyncUpdater = new BackgroundWorker();
  51. //指示BackgroundWorker是否可以报告进度更新
  52. //当该属性值为True是,将可以成功调用ReportProgress方法,否则将引发InvalidOperationException异常。
  53. asyncDownloader.WorkerReportsProgress = true;
  54. asyncUpdater.WorkerReportsProgress = true;
  55. //挂载方法:
  56. asyncDownloader.DoWork += AsyncDownloader_DoWork;
  57. asyncUpdater.DoWork += AsyncUpdater_DoWork;
  58. //完成通知器:
  59. asyncDownloader.RunWorkerCompleted += AsyncDownloader_RunWorkerCompleted;
  60. asyncUpdater.RunWorkerCompleted += AsyncUpdater_RunWorkerCompleted;
  61. UpdateInfoVis = Visibility.Collapsed;
  62. if (Downloader.Program.Tencent_cos_download.CheckAlreadyDownload())
  63. {
  64. obj.checkUpdate();
  65. Status = SettingsModel.Status.login;
  66. this.RaisePropertyChanged("WindowWidth");
  67. this.RaisePropertyChanged("LaunchVis");
  68. if (obj.RecallUser())
  69. RememberMe = true;
  70. else
  71. RememberMe = false;
  72. this.RaisePropertyChanged("RememberMe");
  73. //在启动时立刻检查更新,确保选手启动最新版选手包
  74. //若有更新,将启动键改为更新键;
  75. //相应地,使用login界面启动;
  76. //结构:上方为登录框架,下方有“修改选手包”按钮
  77. }
  78. else
  79. {
  80. Route = Environment.GetEnvironmentVariable("USERPROFILE") + "\\THUAI6";
  81. Status = SettingsModel.Status.newUser;
  82. this.RaisePropertyChanged("WindowWidth");
  83. }
  84. }
  85. private void AsyncDownloader_RunWorkerCompleted(object? sender, RunWorkerCompletedEventArgs e)
  86. {
  87. if (e.Result == null)
  88. {
  89. Status = SettingsModel.Status.error;
  90. }
  91. else if ((bool)e.Result)
  92. {
  93. Status = SettingsModel.Status.successful;
  94. }
  95. else
  96. {
  97. Status = SettingsModel.Status.newUser;
  98. }
  99. }
  100. private void AsyncUpdater_RunWorkerCompleted(object? sender, RunWorkerCompletedEventArgs e)
  101. {
  102. if (e.Result == null)
  103. {
  104. Status = SettingsModel.Status.error;
  105. }
  106. else
  107. {
  108. this.RaisePropertyChanged("LaunchVis");
  109. if ((int)e.Result == 1)
  110. {
  111. Status = SettingsModel.Status.successful;
  112. this.RaisePropertyChanged("UpdateBtnCont");
  113. this.RaisePropertyChanged("UpdateInfo");
  114. this.RaisePropertyChanged("LaunchBtnCont");
  115. }
  116. else if ((int)e.Result == 2)
  117. {
  118. Status = SettingsModel.Status.login;
  119. this.RaisePropertyChanged("UpdateBtnCont");
  120. this.RaisePropertyChanged("LaunchBtnCont");
  121. this.RaisePropertyChanged("UpdateInfo");
  122. }
  123. else
  124. {
  125. string updateFailList = "";
  126. foreach (var Filename in Program.UpdateFailed)
  127. {
  128. updateFailList += Filename + "\n";
  129. }
  130. MessageBox.Show($"以下文件因被占用而未能成功更新:\n{updateFailList}请关闭它们,并再试一次");
  131. Program.ResetUpdateFailedInfo();
  132. Status = SettingsModel.Status.successful;
  133. this.RaisePropertyChanged("UpdateBtnCont");
  134. this.RaisePropertyChanged("UpdateInfo");
  135. this.RaisePropertyChanged("LaunchBtnCont");
  136. }
  137. }
  138. }
  139. private void AsyncUpdater_DoWork(object? sender, DoWorkEventArgs e)
  140. {
  141. if (asyncUpdater.CancellationPending)
  142. {
  143. e.Cancel = true;
  144. return;
  145. }
  146. else
  147. {
  148. if (obj.Update())
  149. if (e.Argument.ToString().Equals("Manual"))
  150. {
  151. e.Result = 1;
  152. }
  153. else
  154. e.Result = 2;
  155. else
  156. e.Result = -1;
  157. }
  158. }
  159. private void AsyncDownloader_DoWork(object? sender, DoWorkEventArgs e)
  160. {
  161. if (asyncDownloader.CancellationPending)
  162. {
  163. e.Cancel = true;
  164. return;
  165. }
  166. else
  167. {
  168. if (obj.install())
  169. e.Result = true;
  170. else
  171. e.Result = false;
  172. }
  173. }
  174. //TODO:参赛界面:包括上传参赛代码、申请对战
  175. //TODO:界面中应包含上次对战完成提示及下载回放按钮
  176. public int ExtraColumn
  177. {
  178. get
  179. {
  180. if (Status == SettingsModel.Status.newUser || Status == SettingsModel.Status.move)
  181. return 75;
  182. else
  183. return 0;
  184. }
  185. }
  186. public int WindowWidth
  187. {
  188. get
  189. {
  190. switch (Status)
  191. {
  192. case SettingsModel.Status.newUser:
  193. return 505;
  194. case SettingsModel.Status.move:
  195. return 505;
  196. case SettingsModel.Status.working:
  197. return 435;
  198. case SettingsModel.Status.successful:
  199. return 435;
  200. default:
  201. return 355;
  202. }
  203. }
  204. }
  205. public SettingsModel.Status Status
  206. {
  207. get
  208. {
  209. return obj.status;
  210. }
  211. set
  212. {
  213. obj.status = value;
  214. this.RaisePropertyChanged("ExtraColumn");
  215. this.RaisePropertyChanged("Intro");
  216. this.RaisePropertyChanged("RouteBoxIntro");
  217. this.RaisePropertyChanged("LoginVis");
  218. this.RaisePropertyChanged("MenuVis");
  219. this.RaisePropertyChanged("RouteBoxVis");
  220. this.RaisePropertyChanged("ProgressVis");
  221. //TODO: Thread will be taken by process working and window will not refresh.
  222. this.RaisePropertyChanged("CompleteVis");
  223. this.RaisePropertyChanged("WindowWidth");
  224. this.RaisePropertyChanged("WebVis");
  225. this.RaisePropertyChanged("CoverVis");
  226. this.RaisePropertyChanged("LaunchVis");
  227. this.RaisePropertyChanged("NewUserVis");
  228. this.RaisePropertyChanged("ConfirmBtnCont");
  229. }
  230. }
  231. public string Intro
  232. {
  233. get
  234. {
  235. switch (Status)
  236. {
  237. case SettingsModel.Status.newUser:
  238. return "欢迎使用选手包,请选择你想要安装选手包的位置:";
  239. case SettingsModel.Status.menu:
  240. return "你已经安装了选手包,请选择想要进行的操作:";
  241. case SettingsModel.Status.login:
  242. return "使用EESAST账号登录";
  243. case SettingsModel.Status.web:
  244. return "THUAI6 赛场:";
  245. case SettingsModel.Status.disconnected:
  246. return "你可能没有连接到网络,无法下载/更新选手包";
  247. case SettingsModel.Status.error:
  248. return "我们遇到了一些问题,请向[]反馈";
  249. default:
  250. return "";
  251. }
  252. }
  253. }
  254. public string RouteBoxIntro
  255. {
  256. get
  257. {
  258. switch (Status)
  259. {
  260. case SettingsModel.Status.newUser:
  261. return "将选手包安装在(将创建THUAI6文件夹):";
  262. case SettingsModel.Status.move:
  263. return "将选手包移动到(THUAI6文件夹将会被整体移动):";
  264. default:
  265. return "";
  266. }
  267. }
  268. }
  269. public string AbortOrSelLanguage
  270. {
  271. get
  272. {
  273. string ans = "";
  274. if (obj.UploadReady)
  275. ans = "放弃上传";
  276. else if (obj.launchLanguage == SettingsModel.LaunchLanguage.cpp)
  277. ans = "语言:c++";
  278. else if (obj.launchLanguage == SettingsModel.LaunchLanguage.python)
  279. ans = "语言:python";
  280. return ans;
  281. }
  282. }
  283. public int PlayerNum
  284. {
  285. get
  286. {
  287. int ans;
  288. if (obj.PlayerNum.Equals("player_1"))
  289. ans = 1;
  290. else if (obj.PlayerNum.Equals("player_2"))
  291. ans = 2;
  292. else if (obj.PlayerNum.Equals("player_3"))
  293. ans = 3;
  294. else if (obj.PlayerNum.Equals("player_4"))
  295. ans = 4;
  296. else
  297. ans = 0;
  298. return ans;
  299. }
  300. set
  301. {
  302. switch (value)
  303. {
  304. case 1:
  305. obj.PlayerNum = "player_1";
  306. break;
  307. case 2:
  308. obj.PlayerNum = "player_2";
  309. break;
  310. case 3:
  311. obj.PlayerNum = "player_3";
  312. break;
  313. case 4:
  314. obj.PlayerNum = "player_4";
  315. break;
  316. default:
  317. obj.PlayerNum = "nSelect";
  318. break;
  319. }
  320. this.RaisePropertyChanged("PlayerNum");
  321. }
  322. }
  323. public string Route
  324. {
  325. get
  326. {
  327. return obj.Route;
  328. }
  329. set
  330. {
  331. obj.Route = value;
  332. this.RaisePropertyChanged("Route");
  333. }
  334. }
  335. public string Username
  336. {
  337. get => obj.Username;
  338. set
  339. {
  340. obj.Username = value;
  341. this.RaisePropertyChanged("Username");
  342. }
  343. }
  344. public string Password
  345. {
  346. get => obj.Password;
  347. set
  348. {
  349. obj.Password = value;
  350. this.RaisePropertyChanged("Password");
  351. }
  352. }
  353. public string CodeName
  354. {
  355. get
  356. {
  357. return obj.CodeRoute.Substring(obj.CodeRoute.LastIndexOf('/') == -1 ? obj.CodeRoute.LastIndexOf('\\') + 1 : obj.CodeRoute.LastIndexOf('/') + 1);
  358. }
  359. }
  360. public bool RememberMe
  361. {
  362. get
  363. {
  364. return obj.RememberMe;
  365. }
  366. set
  367. {
  368. obj.RememberMe = value;
  369. this.RaisePropertyChanged("RememberMe");
  370. }
  371. }
  372. public Visibility NewUserVis
  373. {
  374. get
  375. {
  376. return Status == SettingsModel.Status.newUser ? Visibility.Visible : Visibility.Collapsed;
  377. }
  378. }
  379. public Visibility MenuVis
  380. {
  381. get
  382. {
  383. return Status == SettingsModel.Status.menu ? Visibility.Visible : Visibility.Collapsed;
  384. }
  385. }
  386. public Visibility RouteBoxVis
  387. {
  388. get
  389. {
  390. return (Status == SettingsModel.Status.newUser || Status == SettingsModel.Status.move) ? Visibility.Visible : Visibility.Collapsed;
  391. }
  392. }
  393. public Visibility LoginVis
  394. {
  395. get
  396. {
  397. return Status == SettingsModel.Status.login ? Visibility.Visible : Visibility.Collapsed;
  398. }
  399. }
  400. public Visibility ProgressVis
  401. {
  402. get
  403. {
  404. return Status == SettingsModel.Status.working ? Visibility.Visible : Visibility.Collapsed;
  405. }
  406. }
  407. public Visibility CompleteVis
  408. {
  409. get
  410. {
  411. return Status == SettingsModel.Status.successful ? Visibility.Visible : Visibility.Collapsed;
  412. }
  413. }
  414. public Visibility WebVis
  415. {
  416. get
  417. {
  418. return Status == SettingsModel.Status.web ? Visibility.Visible : Visibility.Collapsed;
  419. }
  420. }
  421. public Visibility CoverVis
  422. {
  423. get
  424. {
  425. return Status == SettingsModel.Status.web && !obj.UploadReady ? Visibility.Visible : Visibility.Collapsed;
  426. }
  427. }
  428. public Visibility LoginFailVis
  429. {
  430. get
  431. {
  432. return obj.LoginFailed ? Visibility.Visible : Visibility.Collapsed;
  433. }
  434. }
  435. public Visibility MatchFinishedVis
  436. {
  437. get
  438. {
  439. return obj.CombatCompleted ? Visibility.Visible : Visibility.Collapsed;
  440. }
  441. }
  442. public Visibility UploadReadyVis
  443. {
  444. get { return obj.UploadReady ? Visibility.Visible : Visibility.Collapsed; }
  445. }
  446. public Visibility UpdateInfoVis
  447. {
  448. get; set;
  449. }
  450. public Visibility LaunchVis
  451. {
  452. get
  453. {
  454. return obj.status == SettingsModel.Status.login && (!obj.UpdatePlanned) ? Visibility.Visible : Visibility.Collapsed;
  455. }
  456. }
  457. public string UpdateBtnCont
  458. {
  459. get
  460. {
  461. return obj.UpdatePlanned ? "更新" : "检查更新";
  462. }
  463. }
  464. public string UpdateInfo
  465. {
  466. get
  467. {
  468. if (obj.UpdatePlanned)
  469. return obj.Updates;
  470. else
  471. return "已是最新版本";
  472. }
  473. }
  474. public string LaunchBtnCont
  475. {
  476. get
  477. {
  478. string ans;
  479. if (obj.UpdatePlanned)
  480. ans = "更新";
  481. else if (obj.launchLanguage == SettingsModel.LaunchLanguage.cpp)
  482. ans = "启动c++包";
  483. else
  484. ans = "启动python包";
  485. return ans;
  486. }
  487. }
  488. public string UploadBtnCont
  489. {
  490. get
  491. {
  492. return obj.UploadReady ? "上传代码" : "选择代码上传";
  493. }
  494. }
  495. public string ShiftLanguageBtnCont
  496. {
  497. get
  498. {
  499. return obj.launchLanguage == SettingsModel.LaunchLanguage.cpp ? "改为python" : "改为c++";
  500. }
  501. }
  502. public string ConfirmBtnCont
  503. {
  504. get
  505. {
  506. switch (Status)
  507. {
  508. case SettingsModel.Status.newUser:
  509. return "确认并安装";
  510. case SettingsModel.Status.move:
  511. return "确认并移动";
  512. default:
  513. return "";
  514. }
  515. }
  516. }
  517. public string RouteSelectWindow(string type)
  518. {
  519. if (type == "Folder")
  520. {
  521. using (FolderBrowserDialog dialog = new FolderBrowserDialog())
  522. {
  523. _ = dialog.ShowDialog();
  524. if (dialog.SelectedPath != String.Empty)
  525. return dialog.SelectedPath;
  526. }
  527. }
  528. else if (type == "File")
  529. {
  530. var openFileDialog = new Microsoft.Win32.OpenFileDialog();
  531. if (obj.launchLanguage == SettingsModel.LaunchLanguage.cpp)
  532. {
  533. openFileDialog.InitialDirectory = (Route + "/THUAI6/win/CAPI/cpp/API/src/").Replace("/", "\\");
  534. openFileDialog.Filter = "c++ Source Files (.cpp)|*.cpp|c++ Header File (.h)|*.h|python Source File (.py)|*.py";
  535. }
  536. else if (obj.launchLanguage == SettingsModel.LaunchLanguage.python)
  537. {
  538. openFileDialog.InitialDirectory = (Route + "/THUAI6/win/CAPI/python/PyAPI/").Replace("/", "\\");
  539. openFileDialog.Filter = "python Source File (.py)|*.py|c++ Source Files (.cpp)|*.cpp|c++ Header File (.h)|*.h";
  540. }
  541. var result = openFileDialog.ShowDialog();
  542. if (result == true)
  543. {
  544. return openFileDialog.FileName;
  545. }
  546. }
  547. return "";
  548. }
  549. private BaseCommand clickBrowseCommand;
  550. public BaseCommand ClickBrowseCommand
  551. {
  552. get
  553. {
  554. if (clickBrowseCommand == null)
  555. {
  556. clickBrowseCommand = new BaseCommand(new Action<object>(o =>
  557. {
  558. Route = RouteSelectWindow("Folder");
  559. }));
  560. }
  561. return clickBrowseCommand;
  562. }
  563. }
  564. private BaseCommand clickConfirmCommand;
  565. public BaseCommand ClickConfirmCommand
  566. {
  567. get
  568. {
  569. if (clickConfirmCommand == null)
  570. {
  571. clickConfirmCommand = new BaseCommand(new Action<object>(o =>
  572. {
  573. if (Status == SettingsModel.Status.newUser)
  574. {
  575. if (Directory.Exists(Route))
  576. {
  577. Status = SettingsModel.Status.working;
  578. this.RaisePropertyChanged("ProgressVis");
  579. /*if (obj.install())
  580. {
  581. Status = SettingsModel.Status.successful;
  582. }*/
  583. if (asyncDownloader.IsBusy)
  584. return;
  585. else
  586. {
  587. asyncDownloader.RunWorkerAsync();
  588. }
  589. }
  590. else
  591. {
  592. MessageBox.Show("所选的路径不存在,请重新选择", "路径不存在", MessageBoxButton.OK, MessageBoxImage.Warning);
  593. }
  594. }
  595. else if (Status == SettingsModel.Status.move)
  596. {
  597. //Status = SettingsModel.Status.working;
  598. //this.RaisePropertyChanged("ProgressVis");
  599. if (Directory.Exists(Route))
  600. {
  601. switch (obj.move())
  602. {
  603. case -1:
  604. MessageBox.Show("文件已打开或者目标路径下有同名文件!", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK);
  605. break;
  606. case -2:
  607. Status = SettingsModel.Status.error;
  608. break;
  609. }
  610. Status = SettingsModel.Status.successful;
  611. }
  612. else
  613. {
  614. MessageBox.Show("所选的路径不存在,请重新选择", "路径不存在", MessageBoxButton.OK, MessageBoxImage.Warning);
  615. }
  616. }
  617. }));
  618. }
  619. return clickConfirmCommand;
  620. }
  621. }
  622. private BaseCommand clickUpdateCommand;
  623. public BaseCommand ClickUpdateCommand
  624. {
  625. get
  626. {
  627. if (clickUpdateCommand == null)
  628. {
  629. clickUpdateCommand = new BaseCommand(new Action<object>(o =>
  630. {
  631. this.RaisePropertyChanged("UpdateInfoVis");
  632. if (obj.UpdatePlanned)
  633. {
  634. UpdateInfoVis = Visibility.Collapsed;
  635. this.RaisePropertyChanged("UpdateInfoVis");
  636. Status = SettingsModel.Status.working;
  637. this.RaisePropertyChanged("ProgressVis");
  638. /*if (obj.Update())
  639. {
  640. Status = SettingsModel.Status.successful;
  641. this.RaisePropertyChanged("UpdateBtnCont");
  642. this.RaisePropertyChanged("UpdateInfo");
  643. }
  644. else
  645. Status = SettingsModel.Status.error;*/
  646. if (asyncUpdater.IsBusy)
  647. return;
  648. else
  649. asyncUpdater.RunWorkerAsync("Manual");
  650. }
  651. else
  652. {
  653. UpdateInfoVis = Visibility.Visible;
  654. this.RaisePropertyChanged("UpdateInfoVis");
  655. //Status = SettingsModel.Status.working;
  656. //this.RaisePropertyChanged("ProgressVis");
  657. Status = obj.checkUpdate();
  658. this.RaisePropertyChanged("UpdateBtnCont");
  659. this.RaisePropertyChanged("UpdateInfo");
  660. this.RaisePropertyChanged("LaunchVis");
  661. }
  662. }));
  663. }
  664. return clickUpdateCommand;
  665. }
  666. }
  667. private BaseCommand clickMoveCommand;
  668. public BaseCommand ClickMoveCommand
  669. {
  670. get
  671. {
  672. if (clickMoveCommand == null)
  673. {
  674. clickMoveCommand = new BaseCommand(new Action<object>(o =>
  675. {
  676. Status = SettingsModel.Status.move;
  677. }));
  678. }
  679. return clickMoveCommand;
  680. }
  681. }
  682. private BaseCommand clickUninstCommand;
  683. public BaseCommand ClickUninstCommand
  684. {
  685. get
  686. {
  687. if (clickUninstCommand == null)
  688. {
  689. clickUninstCommand = new BaseCommand(new Action<object>(o =>
  690. {
  691. UpdateInfoVis = Visibility.Collapsed;
  692. this.RaisePropertyChanged("UpdateInfoVis");
  693. switch (obj.Uninst())
  694. {
  695. case -1:
  696. Status = SettingsModel.Status.menu;
  697. MessageBox.Show("文件已经打开,请关闭后再删除", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK);
  698. break;
  699. case 0:
  700. Status = SettingsModel.Status.newUser;
  701. MessageBox.Show($"删除成功!player文件夹中的文件已经放在{Downloader.Program.Data.FilePath}/{Downloader.Program.ProgramName}的根目录下", "", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);
  702. break;
  703. default:
  704. Status = SettingsModel.Status.error;
  705. break;
  706. }
  707. }));
  708. }
  709. return clickUninstCommand;
  710. }
  711. }
  712. private BaseCommand clickLoginCommand;
  713. public BaseCommand ClickLoginCommand
  714. {
  715. get
  716. {
  717. if (clickLoginCommand == null)
  718. {
  719. clickLoginCommand = new BaseCommand(new Action<object>(async o =>
  720. {
  721. switch (await obj.Login())
  722. {
  723. case -1:
  724. obj.LoginFailed = true;
  725. break;
  726. case 0:
  727. obj.LoginFailed = false;
  728. Status = SettingsModel.Status.web;
  729. if (obj.RememberMe)
  730. {
  731. obj.RememberUser();
  732. RememberMe = true;
  733. this.RaisePropertyChanged("RememberMe");
  734. }
  735. else
  736. {
  737. obj.ForgetUser();
  738. RememberMe = false;
  739. this.RaisePropertyChanged("RememberMe");
  740. Username = "";
  741. Password = "";
  742. this.RaisePropertyChanged("Username");
  743. this.RaisePropertyChanged("Password");
  744. }
  745. this.RaisePropertyChanged("CoverVis");
  746. break;
  747. case -2:
  748. MessageBox.Show("无法连接服务器,请检查网络情况", "网络错误", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK);
  749. break;
  750. }
  751. this.RaisePropertyChanged("LoginFailVis");
  752. }));
  753. }
  754. return clickLoginCommand;
  755. }
  756. }
  757. private BaseCommand clickLaunchCommand;
  758. public BaseCommand ClickLaunchCommand
  759. {
  760. get
  761. {
  762. if (clickLaunchCommand == null)
  763. {
  764. clickLaunchCommand = new BaseCommand(new Action<object>(o =>
  765. {
  766. if (obj.UpdatePlanned)
  767. {
  768. Status = SettingsModel.Status.working;
  769. this.RaisePropertyChanged("ProgressVis");
  770. if (asyncUpdater.IsBusy)
  771. return;
  772. else
  773. asyncUpdater.RunWorkerAsync("Auto");
  774. }
  775. else if (!obj.Launch())
  776. {
  777. Status = SettingsModel.Status.menu;
  778. }
  779. }));
  780. }
  781. return clickLaunchCommand;
  782. }
  783. }
  784. private BaseCommand clickEditCommand;
  785. public BaseCommand ClickEditCommand
  786. {
  787. get
  788. {
  789. if (clickEditCommand == null)
  790. {
  791. clickEditCommand = new BaseCommand(new Action<object>(o =>
  792. {
  793. Status = SettingsModel.Status.menu;
  794. if (obj.UpdatePlanned)
  795. UpdateInfoVis = Visibility.Visible;
  796. this.RaisePropertyChanged("UpdateInfoVis");
  797. }));
  798. }
  799. return clickEditCommand;
  800. }
  801. }
  802. private BaseCommand clickBackCommand;
  803. public BaseCommand ClickBackCommand
  804. {
  805. get
  806. {
  807. if (clickBackCommand == null)
  808. {
  809. clickBackCommand = new BaseCommand(new Action<object>(o =>
  810. {
  811. UpdateInfoVis = Visibility.Collapsed;
  812. this.RaisePropertyChanged("UpdateInfoVis");
  813. if (Downloader.Program.Tencent_cos_download.CheckAlreadyDownload())
  814. Status = SettingsModel.Status.login;
  815. else
  816. Status = SettingsModel.Status.newUser;
  817. }));
  818. }
  819. return clickBackCommand;
  820. }
  821. }
  822. private BaseCommand clickUploadCommand;
  823. public BaseCommand ClickUploadCommand
  824. {
  825. get
  826. {
  827. if (clickUploadCommand == null)
  828. {
  829. clickUploadCommand = new BaseCommand(new Action<object>(async o =>
  830. {
  831. if (obj.UploadReady)
  832. {
  833. if (obj.PlayerNum.Equals("nSelect"))
  834. {
  835. MessageBox.Show("您还没有选择要上传的玩家身份", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK);
  836. }
  837. else
  838. {
  839. switch (await obj.Upload())
  840. {
  841. case -1:
  842. MessageBox.Show("Token失效!", "", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
  843. break;
  844. case -2:
  845. MessageBox.Show("目标路径不存在!", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK);
  846. break;
  847. case -3:
  848. MessageBox.Show("服务器错误", "", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
  849. break;
  850. case -4:
  851. MessageBox.Show("您未登录或登录失效", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK);
  852. Status = SettingsModel.Status.login;
  853. break;
  854. case -5:
  855. MessageBox.Show("您未报名THUAI!", "", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
  856. break;
  857. case -6:
  858. MessageBox.Show("读取文件失败,请确认文件是否被占用", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK);
  859. break;
  860. case -7:
  861. MessageBox.Show("网络错误,请检查你的网络", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK);
  862. break;
  863. case -8:
  864. MessageBox.Show("不是c++或python源文件", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK);
  865. break;
  866. }
  867. obj.CodeRoute = "";
  868. obj.UploadReady = false;
  869. this.RaisePropertyChanged("UploadBtnCont");
  870. this.RaisePropertyChanged("UploadReadyVis");
  871. this.RaisePropertyChanged("CoverVis");
  872. this.RaisePropertyChanged("AbortOrSelLanguage");
  873. }
  874. }
  875. else
  876. {
  877. obj.CodeRoute = RouteSelectWindow("File");
  878. if (obj.CodeRoute != "")
  879. {
  880. obj.UploadReady = true;
  881. this.RaisePropertyChanged("UploadBtnCont");
  882. this.RaisePropertyChanged("UploadReadyVis");
  883. this.RaisePropertyChanged("CodeName");
  884. this.RaisePropertyChanged("CoverVis");
  885. this.RaisePropertyChanged("AbortOrSelLanguage");
  886. }
  887. else
  888. {
  889. MessageBox.Show("未选择代码,请重新选择!", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK);
  890. }
  891. }
  892. }));
  893. }
  894. return clickUploadCommand;
  895. }
  896. }
  897. private BaseCommand clickAboutUploadCommand;
  898. public BaseCommand ClickAboutUploadCommand
  899. {
  900. get
  901. {
  902. if (clickAboutUploadCommand == null)
  903. {
  904. clickAboutUploadCommand = new BaseCommand(new Action<object>(o =>
  905. {
  906. if (obj.UploadReady)
  907. {
  908. obj.CodeRoute = "";
  909. obj.UploadReady = false;
  910. this.RaisePropertyChanged("UploadBtnCont");
  911. this.RaisePropertyChanged("UploadReadyVis");
  912. this.RaisePropertyChanged("CodeName");
  913. this.RaisePropertyChanged("CoverVis");
  914. this.RaisePropertyChanged("AbortOrSelLanguage");
  915. }
  916. else
  917. {
  918. if (obj.launchLanguage == SettingsModel.LaunchLanguage.cpp)
  919. obj.launchLanguage = SettingsModel.LaunchLanguage.python;
  920. else
  921. obj.launchLanguage = SettingsModel.LaunchLanguage.cpp;
  922. this.RaisePropertyChanged("AbortOrSelLanguage");
  923. this.RaisePropertyChanged("ShiftLanguageBtnCont");
  924. this.RaisePropertyChanged("LaunchBtnCont");
  925. }
  926. }));
  927. }
  928. return clickAboutUploadCommand;
  929. }
  930. }
  931. private BaseCommand clickExitCommand;
  932. public BaseCommand ClickExitCommand
  933. {
  934. get
  935. {
  936. if (clickExitCommand == null)
  937. {
  938. clickExitCommand = new BaseCommand(new Action<object>(o =>
  939. {
  940. Application.Current.Shutdown();
  941. }));
  942. }
  943. return clickExitCommand;
  944. }
  945. }
  946. private BaseCommand clickShiftLanguageCommand;
  947. public BaseCommand ClickShiftLanguageCommand
  948. {
  949. get
  950. {
  951. if (clickShiftLanguageCommand == null)
  952. {
  953. clickShiftLanguageCommand = new BaseCommand(new Action<object>(o =>
  954. {
  955. if (obj.launchLanguage == SettingsModel.LaunchLanguage.cpp)
  956. obj.launchLanguage = SettingsModel.LaunchLanguage.python;
  957. else
  958. obj.launchLanguage = SettingsModel.LaunchLanguage.cpp;
  959. this.RaisePropertyChanged("ShiftLanguageBtnCont");
  960. this.RaisePropertyChanged("LaunchBtnCont");
  961. this.RaisePropertyChanged("AbortOrSelLanguage");
  962. }));
  963. }
  964. return clickShiftLanguageCommand;
  965. }
  966. }
  967. private BaseCommand clickReadCommand;
  968. public BaseCommand ClickReadCommand
  969. {
  970. get
  971. {
  972. if (clickReadCommand == null)
  973. {
  974. clickReadCommand = new BaseCommand(new Action<object>(o =>
  975. {
  976. if (!Directory.Exists(Route + "/THUAI6/win"))
  977. {
  978. if (Directory.Exists(Route.Substring(0, Route.Length - 7) + "/THUAI6/win"))
  979. Route = Route.Substring(0, Route.Length - 7);
  980. else
  981. {
  982. MessageBox.Show("请选择名为THUAI6的完整选手包文件夹,这可能意味着你需要对选手包文件夹进行重命名");
  983. return;
  984. }
  985. }
  986. Program.Data.ResetFilepath(Route);
  987. if (Program.Tencent_cos_download.CheckAlreadyDownload())
  988. Status = SettingsModel.Status.login;
  989. }));
  990. }
  991. return clickReadCommand;
  992. }
  993. }
  994. }
  995. }