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

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