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

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