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.

MainWindow.xaml.cs 30 kB

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