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

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