AppDownloader.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. #define TRACE
  2. using System;
  3. using System.ComponentModel;
  4. using System.Diagnostics;
  5. using System.Globalization;
  6. using System.IO;
  7. using System.Net;
  8. using System.Reflection;
  9. using System.Threading;
  10. namespace Microsoft.Samples.AppUpdater
  11. {
  12. public class AppDownloader
  13. {
  14. internal delegate void NotifyUpdateFileInfoEventHandler(object sender, NotifyUpdateFileInfoEventArgs e);
  15. internal delegate void UpdateCompleteEventHandler(object sender, UpdateCompleteEventArgs e);
  16. private AppUpdater AppMan;
  17. private Thread UpdaterThread;
  18. private AppStartConfig Config;
  19. private UpdateLog Log;
  20. private UpdateCompleteEventArgs UpdateEventArgs;
  21. private NotifyUpdateFileInfoEventArgs UpdateFileInfoEventArgs;
  22. private AppKeys Keys;
  23. private bool _ValidateAssemblies;
  24. private bool _SynchronizationDownload;
  25. private int _SecondsBetweenDownloadRetry = 60;
  26. private int _DownloadRetryAttempts = 3;
  27. private int _UpdateRetryAttempts = 2;
  28. [Description("Specifies whether or not downloaded assemblies must be signed with valid public keys inorder to be downloaded.")]
  29. [DefaultValue(false)]
  30. public bool ValidateAssemblies
  31. {
  32. get
  33. {
  34. return _ValidateAssemblies;
  35. }
  36. set
  37. {
  38. _ValidateAssemblies = value;
  39. }
  40. }
  41. [Description("Specifies whether or not downloaded assemblies must be Synchronize.")]
  42. [DefaultValue(false)]
  43. public bool SynchronizationDownload
  44. {
  45. get
  46. {
  47. return _SynchronizationDownload;
  48. }
  49. set
  50. {
  51. _SynchronizationDownload = value;
  52. }
  53. }
  54. [Description("Seconds between download retry attempts.")]
  55. [DefaultValue(60)]
  56. public int SecondsBetweenDownloadRetry
  57. {
  58. get
  59. {
  60. return _SecondsBetweenDownloadRetry;
  61. }
  62. set
  63. {
  64. _SecondsBetweenDownloadRetry = value;
  65. }
  66. }
  67. [DefaultValue(3)]
  68. [Description("Number of times to retry downloads when an error is encountered.")]
  69. public int DownloadRetryAttempts
  70. {
  71. get
  72. {
  73. return _DownloadRetryAttempts;
  74. }
  75. set
  76. {
  77. _DownloadRetryAttempts = value;
  78. }
  79. }
  80. [DefaultValue(2)]
  81. [Description("Number of times times to retry the app update.")]
  82. public int UpdateRetryAttempts
  83. {
  84. get
  85. {
  86. return _UpdateRetryAttempts;
  87. }
  88. set
  89. {
  90. _UpdateRetryAttempts = value;
  91. }
  92. }
  93. [Browsable(false)]
  94. public UpdateState State => AppMan.Manifest.State;
  95. internal event NotifyUpdateFileInfoEventHandler OnNotifyUpdateFileInfo;
  96. internal event UpdateCompleteEventHandler OnUpdateComplete;
  97. public AppDownloader(AppUpdater appMan)
  98. {
  99. AppMan = appMan;
  100. Log = new UpdateLog();
  101. UpdateEventArgs = new UpdateCompleteEventArgs();
  102. UpdateFileInfoEventArgs = new NotifyUpdateFileInfoEventArgs();
  103. }
  104. public void Start()
  105. {
  106. if (!SynchronizationDownload)
  107. {
  108. if (UpdaterThread == null)
  109. {
  110. UpdaterThread = new Thread(RunThread);
  111. }
  112. else if (!UpdaterThread.IsAlive)
  113. {
  114. UpdaterThread = new Thread(RunThread);
  115. }
  116. UpdaterThread.Name = "Updater Thread";
  117. if (!UpdaterThread.IsAlive)
  118. {
  119. UpdaterThread.Start();
  120. }
  121. }
  122. else
  123. {
  124. RunThread();
  125. }
  126. }
  127. public void Stop()
  128. {
  129. if (UpdaterThread != null && UpdaterThread.IsAlive)
  130. {
  131. UpdaterThread.Abort();
  132. UpdaterThread = null;
  133. }
  134. }
  135. public void RunThread()
  136. {
  137. string directoryName = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
  138. directoryName = Path.Combine(Directory.GetParent(directoryName).FullName, "AppStart.config");
  139. Config = AppStartConfig.Load(directoryName);
  140. try
  141. {
  142. if (AppMan.Manifest.State.Phase == UpdatePhases.Complete)
  143. {
  144. AppMan.Manifest.State.Phase = UpdatePhases.Scavenging;
  145. AppMan.Manifest.State.UpdateFailureCount = 0;
  146. AppMan.Manifest.State.UpdateFailureEncoutered = false;
  147. AppMan.Manifest.State.DownloadDestination = CreateTempDirectory();
  148. if (AppMan.ChangeDetectionMode == ChangeDetectionModes.ServerManifestCheck)
  149. {
  150. ServerManifest serverManifest = new ServerManifest();
  151. serverManifest.Load(AppMan.UpdateUrl);
  152. AppMan.Manifest.State.DownloadSource = serverManifest.ApplicationUrl;
  153. }
  154. else
  155. {
  156. AppMan.Manifest.State.DownloadSource = AppMan.UpdateUrl;
  157. }
  158. AppMan.Manifest.Update();
  159. }
  160. if (AppMan.Manifest.State.Phase == UpdatePhases.Scavenging)
  161. {
  162. Scavenge();
  163. AppMan.Manifest.State.Phase = UpdatePhases.Downloading;
  164. AppMan.Manifest.Update();
  165. }
  166. if (AppMan.Manifest.State.Phase == UpdatePhases.Downloading)
  167. {
  168. Download();
  169. AppMan.Manifest.State.Phase = UpdatePhases.Validating;
  170. AppMan.Manifest.Update();
  171. }
  172. if (AppMan.Manifest.State.Phase == UpdatePhases.Validating)
  173. {
  174. Validate();
  175. AppMan.Manifest.State.Phase = UpdatePhases.Merging;
  176. AppMan.Manifest.Update();
  177. }
  178. if (AppMan.Manifest.State.Phase == UpdatePhases.Merging)
  179. {
  180. MergeDirectory(AppDomain.CurrentDomain.BaseDirectory, AppMan.Manifest.State.DownloadDestination);
  181. AppMan.Manifest.State.Phase = UpdatePhases.Finalizing;
  182. AppMan.Manifest.Update();
  183. }
  184. if (AppMan.Manifest.State.Phase == UpdatePhases.Finalizing)
  185. {
  186. FinalizeUpdate();
  187. }
  188. AppMan.Manifest.State.Phase = UpdatePhases.Complete;
  189. AppMan.Manifest.State.UpdateFailureCount = 0;
  190. AppMan.Manifest.State.UpdateFailureEncoutered = false;
  191. AppMan.Manifest.State.DownloadSource = "";
  192. AppMan.Manifest.State.DownloadDestination = "";
  193. AppMan.Manifest.State.NewVersionDirectory = "";
  194. AppMan.Manifest.Update();
  195. }
  196. catch (ThreadAbortException)
  197. {
  198. Thread.ResetAbort();
  199. return;
  200. }
  201. catch (Exception failureException)
  202. {
  203. UpdateEventArgs.FailureException = failureException;
  204. }
  205. if (AppMan.Manifest.State.Phase != 0)
  206. {
  207. HandleUpdateFailure();
  208. }
  209. else
  210. {
  211. HandleUpdateSuccess();
  212. }
  213. }
  214. private void HandleUpdateSuccess()
  215. {
  216. try
  217. {
  218. Log.AddSuccess(GetFileVersion(Config.AppExePath));
  219. }
  220. catch (Exception)
  221. {
  222. }
  223. if (this.OnUpdateComplete != null)
  224. {
  225. UpdateEventArgs.UpdateSucceeded = true;
  226. UpdateEventArgs.NewVersion = new Version(GetFileVersion(Config.AppExePath));
  227. if (UpdateEventArgs.ErrorMessage == "")
  228. {
  229. UpdateEventArgs.ErrorMessage = "Unknown Error";
  230. }
  231. this.OnUpdateComplete(this, UpdateEventArgs);
  232. }
  233. }
  234. private void HandleUpdateFailure()
  235. {
  236. try
  237. {
  238. Log.AddError(UpdateEventArgs.FailureException.ToString());
  239. }
  240. catch (Exception)
  241. {
  242. }
  243. AppMan.Manifest.State.UpdateFailureEncoutered = true;
  244. AppMan.Manifest.State.UpdateFailureCount++;
  245. AppMan.Manifest.Update();
  246. if (AppMan.Manifest.State.UpdateFailureCount >= UpdateRetryAttempts)
  247. {
  248. AppMan.Manifest.State.Phase = UpdatePhases.Complete;
  249. AppMan.Manifest.State.UpdateFailureEncoutered = false;
  250. AppMan.Manifest.State.UpdateFailureCount = 0;
  251. AppMan.Manifest.State.DownloadSource = "";
  252. AppMan.Manifest.State.DownloadDestination = "";
  253. AppMan.Manifest.Update();
  254. }
  255. if (this.OnUpdateComplete != null)
  256. {
  257. UpdateEventArgs.UpdateSucceeded = false;
  258. if (UpdateEventArgs.ErrorMessage == "")
  259. {
  260. UpdateEventArgs.ErrorMessage = "Unknown Error";
  261. }
  262. this.OnUpdateComplete(this, UpdateEventArgs);
  263. }
  264. }
  265. private void Download()
  266. {
  267. bool flag = true;
  268. int num = 0;
  269. int num2 = 0;
  270. WebFileLoader.NotifyUpdateFileInfoEventHandler value = this.OnNotifyUpdateFileInfo.Invoke;
  271. WebFileLoader.OnNotifyUpdateFileInfo += value;
  272. while (flag)
  273. {
  274. Thread.Sleep(TimeSpan.FromSeconds(num2));
  275. num2 = SecondsBetweenDownloadRetry;
  276. num++;
  277. Trace.WriteLine("APPMANAGER: Attempting to download update from: " + AppMan.Manifest.State.DownloadSource);
  278. try
  279. {
  280. int fileTotal = WebFileLoader.CopyDirectory(AppMan.Manifest.State.DownloadSource, AppMan.Manifest.State.DownloadDestination, 0, bReport: true);
  281. if (this.OnNotifyUpdateFileInfo != null)
  282. {
  283. UpdateFileInfoEventArgs.FileTotal = fileTotal;
  284. UpdateFileInfoEventArgs.FileName = "";
  285. UpdateFileInfoEventArgs.CurrentFile = -1;
  286. this.OnNotifyUpdateFileInfo(this, UpdateFileInfoEventArgs);
  287. }
  288. WebFileLoader.CopyDirectory(AppMan.Manifest.State.DownloadSource, AppMan.Manifest.State.DownloadDestination, fileTotal, bReport: true);
  289. flag = false;
  290. }
  291. catch (WebException ex)
  292. {
  293. if (num >= DownloadRetryAttempts)
  294. {
  295. UpdateEventArgs.ErrorMessage = "Download of a new update from '" + AppMan.Manifest.State.DownloadSource + "' failed with the network error: " + ex.Message;
  296. WebFileLoader.OnNotifyUpdateFileInfo -= value;
  297. throw ex;
  298. }
  299. }
  300. catch (IOException ex2)
  301. {
  302. if (num >= DownloadRetryAttempts)
  303. {
  304. UpdateEventArgs.ErrorMessage = "Saving the new update to disk at '" + AppMan.Manifest.State.DownloadDestination + "' failed with the following error: " + ex2.Message;
  305. WebFileLoader.OnNotifyUpdateFileInfo -= value;
  306. throw ex2;
  307. }
  308. }
  309. catch (Exception ex3)
  310. {
  311. if (num >= DownloadRetryAttempts)
  312. {
  313. UpdateEventArgs.ErrorMessage = "Update failed with the following error: '" + ex3.Message + "'";
  314. WebFileLoader.OnNotifyUpdateFileInfo -= value;
  315. throw ex3;
  316. }
  317. }
  318. finally
  319. {
  320. WebFileLoader.OnNotifyUpdateFileInfo -= value;
  321. }
  322. }
  323. }
  324. private void Validate()
  325. {
  326. if (ValidateAssemblies)
  327. {
  328. Keys = new AppKeys(AppMan.Manifest.State.DownloadSource);
  329. Keys.InitializeKeyCheck();
  330. try
  331. {
  332. ValidateDirectory(AppMan.Manifest.State.DownloadDestination);
  333. }
  334. catch (Exception)
  335. {
  336. Keys.UnInitializeKeyCheck();
  337. HardDirectoryDelete(AppMan.Manifest.State.DownloadDestination);
  338. AppMan.Manifest.State.UpdateFailureCount = UpdateRetryAttempts;
  339. AppMan.Manifest.Update();
  340. throw;
  341. }
  342. Keys.UnInitializeKeyCheck();
  343. }
  344. }
  345. private void ValidateDirectory(string source)
  346. {
  347. try
  348. {
  349. DirectoryInfo directoryInfo = new DirectoryInfo(source);
  350. FileInfo[] files = directoryInfo.GetFiles();
  351. FileInfo[] array = files;
  352. foreach (FileInfo fileInfo in array)
  353. {
  354. if (!Keys.ValidateAssembly(fileInfo.FullName))
  355. {
  356. throw new Exception("Invalid assembly: " + fileInfo.FullName);
  357. }
  358. }
  359. DirectoryInfo[] directories = directoryInfo.GetDirectories();
  360. DirectoryInfo[] array2 = directories;
  361. foreach (DirectoryInfo directoryInfo2 in array2)
  362. {
  363. ValidateDirectory(Path.Combine(source, directoryInfo2.Name));
  364. }
  365. }
  366. catch (Exception ex)
  367. {
  368. UpdateEventArgs.ErrorMessage = ex.Message;
  369. throw;
  370. }
  371. }
  372. private void Scavenge()
  373. {
  374. DirectoryInfo directoryInfo = new DirectoryInfo(GetParentFolder(AppDomain.CurrentDomain.BaseDirectory));
  375. DirectoryInfo[] directories = directoryInfo.GetDirectories();
  376. DirectoryInfo[] array = directories;
  377. foreach (DirectoryInfo directoryInfo2 in array)
  378. {
  379. if (MakeValidPath(directoryInfo2.FullName).ToLower(new CultureInfo("en-US")) != AppDomain.CurrentDomain.BaseDirectory.ToLower(new CultureInfo("en-US")) && MakeValidPath(directoryInfo2.FullName).ToLower(new CultureInfo("en-US")) != Config.AppPath.ToLower(new CultureInfo("en-US")) && directoryInfo2.Name.ToLower(new CultureInfo("en-US")) != "bin")
  380. {
  381. try
  382. {
  383. HardDirectoryDelete(MakeValidPath(directoryInfo2.FullName));
  384. }
  385. catch (Exception)
  386. {
  387. }
  388. }
  389. }
  390. }
  391. private void MergeDirectory(string source, string destination)
  392. {
  393. try
  394. {
  395. DirectoryInfo directoryInfo = new DirectoryInfo(source);
  396. if (!Directory.Exists(destination))
  397. {
  398. Directory.CreateDirectory(destination);
  399. DirectoryInfo directoryInfo2 = new DirectoryInfo(destination);
  400. directoryInfo2.Attributes = directoryInfo.Attributes;
  401. }
  402. FileInfo[] files = directoryInfo.GetFiles();
  403. FileInfo[] array = files;
  404. foreach (FileInfo fileInfo in array)
  405. {
  406. if (!File.Exists(Path.Combine(destination, fileInfo.Name)) && !isManifestFile(fileInfo.Name))
  407. {
  408. fileInfo.CopyTo(Path.Combine(destination, fileInfo.Name), overwrite: true);
  409. }
  410. }
  411. DirectoryInfo[] directories = directoryInfo.GetDirectories();
  412. DirectoryInfo[] array2 = directories;
  413. foreach (DirectoryInfo directoryInfo3 in array2)
  414. {
  415. MergeDirectory(Path.Combine(source, directoryInfo3.Name), Path.Combine(destination, directoryInfo3.Name));
  416. }
  417. }
  418. catch (Exception ex)
  419. {
  420. UpdateEventArgs.ErrorMessage = "Copy of user files from the current app directory '" + source + "' to the new app directory'" + destination + "' failed with the following error: " + ex.Message;
  421. throw;
  422. }
  423. }
  424. private void FinalizeUpdate()
  425. {
  426. try
  427. {
  428. if (AppMan.Manifest.State.NewVersionDirectory == "")
  429. {
  430. AppMan.Manifest.State.NewVersionDirectory = CreateNewVersionDirectory();
  431. AppMan.Manifest.Update();
  432. }
  433. }
  434. catch (Exception)
  435. {
  436. UpdateEventArgs.ErrorMessage = "Failed to create the New Version Directory, using temp download directory as final destination.";
  437. AppMan.Manifest.State.NewVersionDirectory = AppMan.Manifest.State.DownloadDestination;
  438. AppMan.Manifest.Update();
  439. }
  440. try
  441. {
  442. if (AppMan.Manifest.State.NewVersionDirectory.ToLower(new CultureInfo("en-US")) != AppMan.Manifest.State.DownloadDestination.ToLower(new CultureInfo("en-US")))
  443. {
  444. CopyDirectory(AppMan.Manifest.State.DownloadDestination, AppMan.Manifest.State.NewVersionDirectory);
  445. }
  446. }
  447. catch (Exception ex2)
  448. {
  449. UpdateEventArgs.ErrorMessage = "Failed to copy the downloaded update at: '" + AppMan.Manifest.State.DownloadDestination + "' to the new version directory at: '" + AppMan.Manifest.State.NewVersionDirectory + "'";
  450. throw ex2;
  451. }
  452. try
  453. {
  454. char[] trimChars = new char[1]
  455. {
  456. '\\'
  457. };
  458. Config.AppFolderName = Path.GetFileName(AppMan.Manifest.State.NewVersionDirectory.TrimEnd(trimChars));
  459. Config.Udpate();
  460. }
  461. catch (Exception ex3)
  462. {
  463. UpdateEventArgs.ErrorMessage = "Failed to write to 'AppStart.config'";
  464. throw ex3;
  465. }
  466. try
  467. {
  468. if (AppMan.Manifest.State.NewVersionDirectory.ToLower(new CultureInfo("en-US")) != AppMan.Manifest.State.DownloadDestination.ToLower(new CultureInfo("en-US")))
  469. {
  470. HardDirectoryDelete(AppMan.Manifest.State.DownloadDestination);
  471. }
  472. }
  473. catch (Exception)
  474. {
  475. }
  476. }
  477. private string CreateTempDirectory()
  478. {
  479. int num = 0;
  480. Random random = new Random();
  481. string str = "";
  482. string parentFolder = GetParentFolder(AppDomain.CurrentDomain.BaseDirectory);
  483. string text;
  484. do
  485. {
  486. text = parentFolder + "AppUpdate" + str + "\\";
  487. str = "_" + random.Next(10000).ToString();
  488. num++;
  489. }
  490. while (num <= 50 && Directory.Exists(text));
  491. if (num >= 50)
  492. {
  493. UpdateEventArgs.ErrorMessage = "Failed to created temporary download directory in: '" + parentFolder + "'";
  494. throw new Exception("Failed to create temporary download Directory after 1000 attempts");
  495. }
  496. try
  497. {
  498. Directory.CreateDirectory(text);
  499. return text;
  500. }
  501. catch (Exception ex)
  502. {
  503. throw ex;
  504. }
  505. }
  506. private string CreateNewVersionDirectory()
  507. {
  508. string downloadDestination = AppMan.Manifest.State.DownloadDestination;
  509. downloadDestination += Config.AppExeName;
  510. string fileVersion = GetFileVersion(downloadDestination);
  511. string parentFolder = GetParentFolder(AppMan.Manifest.State.DownloadDestination);
  512. string text = "";
  513. int num = 1;
  514. bool flag = false;
  515. string str = "";
  516. do
  517. {
  518. text = parentFolder + fileVersion + str + "\\";
  519. str = "_" + num.ToString();
  520. num++;
  521. try
  522. {
  523. if (!Directory.Exists(text))
  524. {
  525. Directory.CreateDirectory(text);
  526. flag = true;
  527. }
  528. }
  529. catch (Exception)
  530. {
  531. flag = false;
  532. }
  533. }
  534. while (num <= 999 && !flag);
  535. if (num >= 999)
  536. {
  537. text = AppMan.Manifest.State.DownloadDestination;
  538. }
  539. return text;
  540. }
  541. private string MakeValidPath(string source)
  542. {
  543. if (source.EndsWith("\\"))
  544. {
  545. return source;
  546. }
  547. return source + "\\";
  548. }
  549. private void CopyDirectory(string source, string destination)
  550. {
  551. try
  552. {
  553. DirectoryInfo directoryInfo = new DirectoryInfo(source);
  554. if (!Directory.Exists(destination))
  555. {
  556. Directory.CreateDirectory(destination);
  557. DirectoryInfo directoryInfo2 = new DirectoryInfo(destination);
  558. directoryInfo2.Attributes = directoryInfo.Attributes;
  559. }
  560. FileInfo[] files = directoryInfo.GetFiles();
  561. FileInfo[] array = files;
  562. foreach (FileInfo fileInfo in array)
  563. {
  564. if (!File.Exists(Path.Combine(destination, fileInfo.Name)))
  565. {
  566. fileInfo.CopyTo(Path.Combine(destination, fileInfo.Name), overwrite: true);
  567. }
  568. }
  569. DirectoryInfo[] directories = directoryInfo.GetDirectories();
  570. DirectoryInfo[] array2 = directories;
  571. foreach (DirectoryInfo directoryInfo3 in array2)
  572. {
  573. CopyDirectory(Path.Combine(source, directoryInfo3.Name), Path.Combine(destination, directoryInfo3.Name));
  574. }
  575. }
  576. catch (Exception ex)
  577. {
  578. throw ex;
  579. }
  580. }
  581. private void HardDirectoryDelete(string source)
  582. {
  583. string directoryName = Path.GetDirectoryName(source);
  584. string text = Path.GetDirectoryName(directoryName) + "\\" + Config.SetupVersion + "\\";
  585. StreamWriter streamWriter = new StreamWriter("TestFile.txt", append: true);
  586. streamWriter.WriteLine("ParentPath: " + text + "\r\n");
  587. streamWriter.Close();
  588. if (!(source == text))
  589. {
  590. try
  591. {
  592. if (Directory.Exists(source))
  593. {
  594. DirectoryInfo directoryInfo = new DirectoryInfo(source);
  595. directoryInfo.Attributes = FileAttributes.Normal;
  596. FileInfo[] files = directoryInfo.GetFiles();
  597. FileInfo[] array = files;
  598. foreach (FileInfo fileInfo in array)
  599. {
  600. fileInfo.Attributes = FileAttributes.Normal;
  601. }
  602. DirectoryInfo[] directories = directoryInfo.GetDirectories();
  603. DirectoryInfo[] array2 = directories;
  604. foreach (DirectoryInfo directoryInfo2 in array2)
  605. {
  606. HardDirectoryDelete(Path.Combine(source, directoryInfo2.Name));
  607. }
  608. directoryInfo.Delete(recursive: true);
  609. }
  610. }
  611. catch (Exception ex)
  612. {
  613. throw ex;
  614. }
  615. }
  616. }
  617. private string GetFileVersion(string filePath)
  618. {
  619. AssemblyName assemblyName = AssemblyName.GetAssemblyName(filePath);
  620. return assemblyName.Version.ToString();
  621. }
  622. private string GetParentFolder(string filePath)
  623. {
  624. DirectoryInfo directoryInfo = new DirectoryInfo(filePath.Trim('\\'));
  625. return directoryInfo.Parent.FullName + "\\";
  626. }
  627. private bool isManifestFile(string name)
  628. {
  629. string fileName = Path.GetFileName(AppMan.Manifest.FilePath);
  630. if (fileName.ToLower(new CultureInfo("en-US")) == name.ToLower(new CultureInfo("en-US")))
  631. {
  632. return true;
  633. }
  634. return false;
  635. }
  636. }
  637. }