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.

Model.cs 30 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. using COSXML.Auth;
  2. using COSXML.CosException;
  3. using COSXML.Model.Object;
  4. using COSXML;
  5. using Newtonsoft.Json;
  6. using System.Collections.Generic;
  7. using System.Diagnostics;
  8. using System.IO;
  9. using System.Security.Cryptography;
  10. using System.Text;
  11. using System;
  12. namespace starter.viewmodel.settings
  13. {
  14. /// <summary>
  15. /// Settings Window Model
  16. /// </summary>
  17. public class SettingsModel
  18. {
  19. /// <summary>
  20. /// save settings
  21. /// </summary>
  22. public void install()
  23. {
  24. }
  25. /// <summary>
  26. /// Route of files
  27. /// </summary>
  28. public string Route
  29. {
  30. get; set;
  31. }
  32. /// <summary>
  33. /// if the route was set or is under editing
  34. /// </summary>
  35. public bool HaveRoute
  36. {
  37. get; set;
  38. }
  39. public bool EditingRoute
  40. {
  41. get; set;
  42. }
  43. /// <summary>
  44. /// downloader function
  45. /// </summary>
  46. private Downloader.Program downloader = new Downloader.Program();
  47. }
  48. }
  49. namespace Downloader
  50. {
  51. class Program
  52. {
  53. static List<string> newFileName = new List<string>(); // 新文件名
  54. static List<string> updateFileName = new List<string>(); // 更新文件名
  55. static string ProgramName = "THUAI6"; // 要运行或下载的程序名称
  56. static string playerFolder = "player"; // 选手代码保存文件夹路径
  57. static string startName = "maintest.exe"; // 启动的程序名
  58. public class Data
  59. {
  60. public static string path = ""; // 标记路径记录文件THUAI6.dat的路径
  61. public static string FilePath = ""; // 最后一级为THUAI6文件夹所在目录
  62. public static string dataPath = ""; // C盘的文档文件夹
  63. public Data(string path)
  64. {
  65. // dataPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
  66. dataPath = new DirectoryInfo(".").FullName;
  67. Data.path = System.IO.Path.Combine(dataPath, "THUAI6.dat");
  68. if (File.Exists(Data.path))
  69. {
  70. using (StreamReader r = new StreamReader(Data.path))
  71. FilePath = r.ReadLine().Replace('\\', '/'); // 读取THUAI6.dat文件的第一行
  72. }
  73. else
  74. {
  75. FilePath = System.IO.Path.GetDirectoryName(@path);
  76. // 将dat文件写入程序运行路径
  77. FileStream fs = new FileStream(Data.path, FileMode.Create, FileAccess.ReadWrite);
  78. StreamWriter sw = new StreamWriter(fs);
  79. sw.Write(path);
  80. sw.Flush();
  81. sw.Close();
  82. }
  83. }
  84. public static void ChangeData(string newLine)
  85. {
  86. if (Directory.Exists(@newLine)) // 判断文件夹是否存在
  87. {
  88. Console.Write($"是否创建新路径 {newLine}?y/n:");
  89. if (Console.Read() != 'y')
  90. {
  91. Console.WriteLine("创建取消!");
  92. return;
  93. }
  94. using (StreamWriter w = new StreamWriter(path))
  95. w.WriteLine(@newLine.Trim('\r').Trim('\n'));
  96. Console.WriteLine($"当前下载路径为{newLine}");
  97. }
  98. }
  99. public static void ResetFilepath(string newPath)
  100. {
  101. FilePath = newPath.Replace('\\', '/');
  102. path = System.IO.Path.Combine(dataPath, "THUAI6.dat");
  103. FileStream fs = new FileStream(Data.path, FileMode.Create, FileAccess.ReadWrite);
  104. StreamWriter sw = new StreamWriter(fs);
  105. fs.SetLength(0);
  106. sw.Write(newPath);
  107. sw.Flush();
  108. sw.Close();
  109. fs.Close();
  110. }
  111. }
  112. public class Tencent_cos_download
  113. {
  114. public void download(string download_dir, string key)
  115. {
  116. // download_dir标记根文件夹路径,key为相对根文件夹的路径(不带./)
  117. // 初始化CosXmlConfig(提供配置SDK接口)
  118. string appid = "1314234950"; // 设置腾讯云账户的账户标识(APPID)
  119. string region = "ap-beijing"; // 设置一个默认的存储桶地域
  120. CosXmlConfig config = new CosXmlConfig.Builder()
  121. .IsHttps(true) // 设置默认 HTTPS 请求
  122. .SetAppid(appid) // 设置腾讯云账户的账户标识 APPID
  123. .SetRegion(region) // 设置一个默认的存储桶地域
  124. .SetDebugLog(true) // 显示日志
  125. .Build(); // 创建 CosXmlConfig 对象
  126. // 永久密钥访问凭证
  127. string secretId = "***"; //"云 API 密钥 SecretId";
  128. string secretKey = "***"; //"云 API 密钥 SecretKey";
  129. long durationSecond = 1000; // 每次请求签名有效时长,单位为秒
  130. QCloudCredentialProvider cosCredentialProvider = new DefaultQCloudCredentialProvider(
  131. secretId, secretKey, durationSecond
  132. );
  133. // 初始化 CosXmlServer
  134. CosXmlServer cosXml = new CosXmlServer(config, cosCredentialProvider);
  135. // 创建存储桶
  136. try
  137. {
  138. string bucket = "thuai6-1314234950"; // 格式:BucketName-APPID
  139. string localDir = System.IO.Path.GetDirectoryName(download_dir); // 本地文件夹
  140. string localFileName = System.IO.Path.GetFileName(download_dir); // 指定本地保存的文件名
  141. GetObjectRequest request = new GetObjectRequest(bucket, key, localDir, localFileName);
  142. Dictionary<string, string> test = request.GetRequestHeaders();
  143. request.SetCosProgressCallback(delegate (long completed, long total)
  144. {
  145. Console.WriteLine(String.Format("progress = {0:##.##}%", completed * 100.0 / total));
  146. });
  147. // 执行请求
  148. GetObjectResult result = cosXml.GetObject(request);
  149. // 请求成功
  150. }
  151. catch (CosClientException clientEx)
  152. {
  153. throw clientEx;
  154. }
  155. catch (CosServerException serverEx)
  156. {
  157. throw serverEx;
  158. }
  159. }
  160. public static void GetNewHash()
  161. {
  162. Tencent_cos_download Downloader = new Tencent_cos_download();
  163. Downloader.download(System.IO.Path.Combine(Data.FilePath, "hash.json"), "hash.json");
  164. }
  165. public static string GetFileMd5Hash(string strFileFullPath)
  166. {
  167. FileStream fst = null;
  168. try
  169. {
  170. fst = new FileStream(strFileFullPath, FileMode.Open);
  171. byte[] data = MD5.Create().ComputeHash(fst);
  172. StringBuilder sBuilder = new StringBuilder();
  173. for (int i = 0; i < data.Length; i++)
  174. {
  175. sBuilder.Append(data[i].ToString("x2"));
  176. }
  177. fst.Close();
  178. return sBuilder.ToString().ToLower();
  179. }
  180. catch (Exception)
  181. {
  182. if (fst != null)
  183. fst.Close();
  184. return "";
  185. }
  186. finally
  187. {
  188. }
  189. }
  190. private static void Check()
  191. {
  192. string json, MD5, jsonName;
  193. int newFile = 0, updateFile = 0;
  194. newFileName.Clear();
  195. updateFileName.Clear();
  196. jsonName = "hash.json";
  197. Tencent_cos_download Downloader = new Tencent_cos_download();
  198. try
  199. {
  200. // 如果json存在就删了重新下
  201. if (File.Exists(System.IO.Path.Combine(Data.FilePath, jsonName)))
  202. {
  203. File.Delete(System.IO.Path.Combine(Data.FilePath, jsonName));
  204. Downloader.download(System.IO.Path.Combine(Data.FilePath, jsonName), jsonName);
  205. }
  206. else
  207. {
  208. Downloader.download(System.IO.Path.Combine(Data.FilePath, jsonName), jsonName);
  209. }
  210. }
  211. catch (CosClientException clientEx)
  212. {
  213. // 请求失败
  214. Console.WriteLine("CosClientException: " + clientEx.ToString() + Environment.NewLine);
  215. return;
  216. }
  217. catch (CosServerException serverEx)
  218. {
  219. // 请求失败
  220. Console.WriteLine("CosClientException: " + serverEx.ToString() + Environment.NewLine);
  221. return;
  222. }
  223. using (StreamReader r = new StreamReader(System.IO.Path.Combine(Data.FilePath, jsonName)))
  224. json = r.ReadToEnd();
  225. json = json.Replace("\r", string.Empty).Replace("\n", string.Empty);
  226. Dictionary<string, string> jsonDict = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
  227. foreach (KeyValuePair<string, string> pair in jsonDict)
  228. {
  229. MD5 = GetFileMd5Hash(System.IO.Path.Combine(Data.FilePath, pair.Key));
  230. if (MD5.Length == 0) // 文档不存在
  231. newFileName.Add(pair.Key);
  232. else if (MD5 != pair.Value) // MD5不匹配
  233. updateFileName.Add(pair.Key);
  234. }
  235. newFile = newFileName.Count;
  236. updateFile = updateFileName.Count;
  237. Console.WriteLine("----------------------" + Environment.NewLine);
  238. if (newFile + updateFile == 0)
  239. {
  240. Console.WriteLine("当前平台已是最新版本!" + Environment.NewLine);
  241. newFileName.Clear();
  242. updateFileName.Clear();
  243. }
  244. else
  245. {
  246. Console.WriteLine($"发现{newFile}个新文件" + Environment.NewLine);
  247. foreach (string filename in newFileName)
  248. {
  249. Console.WriteLine(filename);
  250. }
  251. Console.WriteLine(Environment.NewLine + $"发现{updateFile}个文件更新" + Environment.NewLine);
  252. foreach (string filename in updateFileName)
  253. {
  254. Console.WriteLine(filename);
  255. }
  256. Console.Write(Environment.NewLine + "是否下载新文件? y/n:");
  257. if (Console.Read() != 'y')
  258. Console.WriteLine("下载取消!");
  259. else
  260. Download();
  261. }
  262. }
  263. private static void Download()
  264. {
  265. Tencent_cos_download Downloader = new Tencent_cos_download();
  266. int newFile = 0, updateFile = 0;
  267. int totalnew = newFileName.Count, totalupdate = updateFileName.Count;
  268. if (newFileName.Count > 0 || updateFileName.Count > 0)
  269. {
  270. try
  271. {
  272. foreach (string filename in newFileName)
  273. {
  274. Console.WriteLine(newFile + 1 + "/" + totalnew + ":开始下载" + filename);
  275. Downloader.download(System.IO.Path.Combine(@Data.FilePath, filename), filename);
  276. Console.WriteLine(filename + "下载完毕!" + Environment.NewLine);
  277. newFile++;
  278. }
  279. foreach (string filename in updateFileName)
  280. {
  281. Console.WriteLine(updateFile + 1 + "/" + totalupdate + ":开始下载" + filename);
  282. File.Delete(System.IO.Path.Combine(@Data.FilePath, filename));
  283. Downloader.download(System.IO.Path.Combine(@Data.FilePath, filename), filename);
  284. Console.WriteLine(filename + "下载完毕!" + Environment.NewLine);
  285. updateFile++;
  286. }
  287. }
  288. catch (CosClientException clientEx)
  289. {
  290. // 请求失败
  291. Console.WriteLine("CosClientException: " + clientEx.ToString() + Environment.NewLine);
  292. return;
  293. }
  294. catch (CosServerException serverEx)
  295. {
  296. // 请求失败
  297. Console.WriteLine("CosClientException: " + serverEx.ToString() + Environment.NewLine);
  298. return;
  299. }
  300. catch (Exception)
  301. {
  302. throw;
  303. }
  304. }
  305. else
  306. Console.WriteLine("当前平台已是最新版本!" + Environment.NewLine);
  307. newFileName.Clear();
  308. updateFileName.Clear();
  309. }
  310. public static bool CheckAlreadyDownload() // 检查是否已经下载
  311. {
  312. string existpath = System.IO.Path.Combine(Data.dataPath, "Exists.txt");
  313. if (!File.Exists(existpath)) // 文件不存在
  314. {
  315. FileStream fs = new FileStream(existpath, FileMode.Create, FileAccess.ReadWrite);
  316. fs.Close();
  317. return false;
  318. }
  319. else // 文件存在
  320. {
  321. FileStream fs = new FileStream(existpath, FileMode.Open, FileAccess.Read);
  322. StreamReader sr = new StreamReader(fs);
  323. if ("true" == sr.ReadLine())
  324. {
  325. sr.Close();
  326. fs.Close();
  327. return true;
  328. }
  329. else
  330. {
  331. sr.Close();
  332. fs.Close();
  333. return false;
  334. }
  335. }
  336. }
  337. public static void DownloadAll() // 下载全部文件
  338. {
  339. string jsonName = "hash.json";
  340. string json;
  341. Tencent_cos_download Downloader = new Tencent_cos_download();
  342. try
  343. {
  344. // 如果json存在就删了重新下
  345. if (File.Exists(System.IO.Path.Combine(Data.FilePath, jsonName)))
  346. {
  347. File.Delete(System.IO.Path.Combine(Data.FilePath, jsonName));
  348. Downloader.download(System.IO.Path.Combine(Data.FilePath, jsonName), jsonName);
  349. }
  350. else
  351. {
  352. Downloader.download(System.IO.Path.Combine(Data.FilePath, jsonName), jsonName);
  353. }
  354. }
  355. catch (CosClientException clientEx)
  356. {
  357. // 请求失败
  358. Console.WriteLine("CosClientException: " + clientEx.ToString() + Environment.NewLine);
  359. return;
  360. }
  361. catch (CosServerException serverEx)
  362. {
  363. // 请求失败
  364. Console.WriteLine("CosClientException: " + serverEx.ToString() + Environment.NewLine);
  365. return;
  366. }
  367. using (StreamReader r = new StreamReader(System.IO.Path.Combine(Data.FilePath, jsonName)))
  368. json = r.ReadToEnd();
  369. json = json.Replace("\r", string.Empty).Replace("\n", string.Empty);
  370. Dictionary<string, string> jsonDict = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
  371. newFileName.Clear();
  372. updateFileName.Clear();
  373. foreach (KeyValuePair<string, string> pair in jsonDict)
  374. {
  375. newFileName.Add(pair.Key);
  376. }
  377. Download();
  378. string existpath = System.IO.Path.Combine(Data.dataPath, "Exists.txt");
  379. FileStream fs = new FileStream(existpath, FileMode.Open, FileAccess.ReadWrite);
  380. StreamWriter sw = new StreamWriter(fs);
  381. fs.SetLength(0);
  382. sw.Write("true");
  383. sw.Close();
  384. fs.Close();
  385. }
  386. public static void Change_all_hash(string topDir, Dictionary<string, string> jsonDict) // 更改HASH
  387. {
  388. DirectoryInfo theFolder = new DirectoryInfo(@topDir);
  389. bool ifexist = false;
  390. // 遍历文件
  391. foreach (FileInfo NextFile in theFolder.GetFiles())
  392. {
  393. string filepath = topDir + @"/" + NextFile.Name; // 文件路径
  394. Console.WriteLine(filepath);
  395. foreach (KeyValuePair<string, string> pair in jsonDict)
  396. {
  397. if (System.IO.Path.Equals(filepath, System.IO.Path.Combine(Data.FilePath, pair.Key).Replace('\\', '/')))
  398. {
  399. ifexist = true;
  400. string MD5 = GetFileMd5Hash(filepath);
  401. jsonDict[pair.Key] = MD5;
  402. }
  403. }
  404. if (!ifexist && NextFile.Name != "hash.json")
  405. {
  406. string MD5 = GetFileMd5Hash(filepath);
  407. string relapath = filepath.Replace(Data.FilePath + '/', string.Empty);
  408. jsonDict.Add(relapath, MD5);
  409. }
  410. ifexist = false;
  411. }
  412. // 遍历文件夹
  413. foreach (DirectoryInfo NextFolder in theFolder.GetDirectories())
  414. {
  415. if (System.IO.Path.Equals(NextFolder.FullName, System.IO.Path.GetFullPath(System.IO.Path.Combine(Data.FilePath, playerFolder))))
  416. {
  417. foreach (FileInfo NextFile in NextFolder.GetFiles())
  418. {
  419. if (NextFile.Name == "README.md")
  420. {
  421. string MD5 = GetFileMd5Hash(NextFile.FullName);
  422. string relapath = NextFile.FullName.Replace('\\', '/').Replace(Data.FilePath + '/', string.Empty);
  423. jsonDict.Add(relapath, MD5);
  424. }
  425. }
  426. continue; // 如果是选手文件夹就忽略
  427. }
  428. Change_all_hash(NextFolder.FullName.Replace('\\', '/'), jsonDict);
  429. }
  430. }
  431. public static void UpdateHash()
  432. {
  433. while (true)
  434. {
  435. if (Directory.Exists(Data.FilePath))
  436. {
  437. string json;
  438. if (!File.Exists(System.IO.Path.Combine(Data.FilePath, "hash.json")))
  439. {
  440. Console.WriteLine("hash.json文件丢失!即将重新下载该文件!");
  441. GetNewHash();
  442. }
  443. using (StreamReader r = new StreamReader(System.IO.Path.Combine(Data.FilePath, "hash.json")))
  444. json = r.ReadToEnd();
  445. json = json.Replace("\r", string.Empty).Replace("\n", string.Empty).Replace("/", @"\\");
  446. Dictionary<string, string> jsonDict = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
  447. Change_all_hash(Data.FilePath, jsonDict);
  448. OverwriteHash(jsonDict);
  449. break;
  450. }
  451. else
  452. {
  453. Console.WriteLine("读取路径失败!请重新输入文件路径:");
  454. Data.ResetFilepath(Console.ReadLine());
  455. }
  456. }
  457. }
  458. public static void DeleteAll()
  459. {
  460. DirectoryInfo di = new DirectoryInfo(Data.FilePath);
  461. DirectoryInfo player = new DirectoryInfo(System.IO.Path.GetFullPath(System.IO.Path.Combine(Data.FilePath, playerFolder)));
  462. try
  463. {
  464. foreach (FileInfo file in di.GetFiles())
  465. {
  466. file.Delete();
  467. }
  468. foreach (FileInfo file in player.GetFiles())
  469. {
  470. if (file.Name == "README.md")
  471. {
  472. continue;
  473. }
  474. string filename = System.IO.Path.GetFileName(file.FullName);
  475. file.MoveTo(System.IO.Path.Combine(Data.FilePath, filename));
  476. }
  477. foreach (DirectoryInfo subdi in di.GetDirectories())
  478. {
  479. subdi.Delete(true);
  480. }
  481. }
  482. catch (UnauthorizedAccessException)
  483. {
  484. Console.WriteLine("权限不足,无法删除!");
  485. return;
  486. }
  487. catch (DirectoryNotFoundException)
  488. {
  489. Console.WriteLine("文件夹没有找到,请检查是否已经手动更改路径");
  490. return;
  491. }
  492. catch (IOException)
  493. {
  494. Console.WriteLine("文件已经打开,请关闭后再删除");
  495. return;
  496. }
  497. string existpath = System.IO.Path.Combine(Data.dataPath, "Exists.txt");
  498. FileStream fs = new FileStream(existpath, FileMode.Open, FileAccess.ReadWrite);
  499. StreamWriter sw = new StreamWriter(fs);
  500. fs.SetLength(0);
  501. sw.Write("false");
  502. sw.Close();
  503. fs.Close();
  504. try
  505. {
  506. File.Delete(Data.path);
  507. }
  508. catch (UnauthorizedAccessException)
  509. {
  510. Console.WriteLine("权限不足,无法删除!");
  511. return;
  512. }
  513. catch (DirectoryNotFoundException)
  514. {
  515. Console.WriteLine("文件夹没有找到,请检查是否已经手动更改路径");
  516. return;
  517. }
  518. catch (IOException)
  519. {
  520. Console.WriteLine("文件已经打开,请关闭后再删除");
  521. return;
  522. }
  523. Console.WriteLine($"删除成功!player文件夹中的文件已经放在{ProgramName}的根目录下");
  524. }
  525. public static void OverwriteHash(Dictionary<string, string> jsonDict)
  526. {
  527. string Contentjson = JsonConvert.SerializeObject(jsonDict);
  528. Contentjson = Contentjson.Replace("\r", String.Empty).Replace("\n", String.Empty).Replace(@"\\", "/");
  529. File.WriteAllText(@System.IO.Path.Combine(Data.FilePath, "hash.json"), Contentjson);
  530. }
  531. public static void MoveProgram()
  532. {
  533. string newPath = Console.ReadLine();
  534. DirectoryInfo newdi = new DirectoryInfo(newPath);
  535. DirectoryInfo olddi = new DirectoryInfo(Data.FilePath);
  536. try
  537. {
  538. foreach (DirectoryInfo direct in olddi.GetDirectories())
  539. {
  540. direct.MoveTo(System.IO.Path.Combine(newPath, direct.Name));
  541. }
  542. foreach (FileInfo file in olddi.GetFiles())
  543. {
  544. file.MoveTo(System.IO.Path.Combine(newPath, file.Name));
  545. }
  546. }
  547. catch (DirectoryNotFoundException)
  548. {
  549. Console.WriteLine("原路径未找到!请检查文件是否损坏");
  550. foreach (DirectoryInfo newdirect in newdi.GetDirectories())
  551. {
  552. newdirect.MoveTo(System.IO.Path.Combine(Data.FilePath, newdirect.Name));
  553. }
  554. foreach (FileInfo file in newdi.GetFiles())
  555. {
  556. file.MoveTo(System.IO.Path.Combine(Data.FilePath, file.Name));
  557. }
  558. Console.WriteLine("移动失败!");
  559. }
  560. catch (IOException)
  561. {
  562. Console.WriteLine("文件已打开或者目标路径下有同名文件!");
  563. foreach (DirectoryInfo newdirect in newdi.GetDirectories())
  564. {
  565. newdirect.MoveTo(System.IO.Path.Combine(Data.FilePath, newdirect.Name));
  566. }
  567. foreach (FileInfo file in newdi.GetFiles())
  568. {
  569. file.MoveTo(System.IO.Path.Combine(Data.FilePath, file.Name));
  570. }
  571. Console.WriteLine("移动失败!");
  572. }
  573. Data.ResetFilepath(newPath);
  574. Console.WriteLine("更改路径成功!");
  575. }
  576. public static void main(string[] args)
  577. {
  578. Data date = new Data("");
  579. while (true)
  580. {
  581. Console.WriteLine($"1. 更新hash.json 2. 检查更新 3.下载{ProgramName} 4.删除{ProgramName} 5.启动进程 6.移动{ProgramName}到其它路径");
  582. string choose = Console.ReadLine();
  583. if (choose == "1")
  584. {
  585. if (!CheckAlreadyDownload())
  586. {
  587. Console.WriteLine($"未下载{ProgramName},请先执行下载操作!");
  588. continue;
  589. }
  590. UpdateHash();
  591. }
  592. else if (choose == "2")
  593. {
  594. if (!CheckAlreadyDownload())
  595. {
  596. Console.WriteLine($"未下载{ProgramName},请先执行下载操作!");
  597. continue;
  598. }
  599. while (true)
  600. {
  601. if (Data.FilePath != null && Directory.Exists(Data.FilePath))
  602. {
  603. Check();
  604. break;
  605. }
  606. else
  607. {
  608. Console.WriteLine("读取路径失败!请重新输入文件路径:");
  609. Data.ResetFilepath(Console.ReadLine());
  610. }
  611. }
  612. }
  613. else if (choose == "3")
  614. {
  615. if (CheckAlreadyDownload())
  616. {
  617. Console.WriteLine($"已经将{ProgramName}下载到{Data.FilePath}!若要重新下载请先完成删除操作!");
  618. }
  619. else
  620. {
  621. string newpath;
  622. Console.WriteLine("请输入下载路径:");
  623. newpath = Console.ReadLine();
  624. Data.ResetFilepath(newpath);
  625. DownloadAll();
  626. }
  627. }
  628. else if (choose == "4")
  629. {
  630. DeleteAll();
  631. }
  632. else if (choose == "5")
  633. {
  634. if (CheckAlreadyDownload())
  635. {
  636. Process.Start(System.IO.Path.Combine(Data.FilePath, startName));
  637. }
  638. else
  639. {
  640. Console.WriteLine($"未下载{ProgramName},请先执行下载操作!");
  641. }
  642. }
  643. else if (choose == "6")
  644. {
  645. MoveProgram();
  646. }
  647. else if (choose == "exit")
  648. {
  649. return;
  650. }
  651. }
  652. }
  653. }
  654. }
  655. }