MainWindow.xaml.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. using Microsoft.Win32;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using PackingPress.Common;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Collections.ObjectModel;
  8. using System.Data;
  9. using System.Diagnostics;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Text.RegularExpressions;
  14. using System.Threading;
  15. using System.Threading.Tasks;
  16. using System.Web;
  17. using System.Windows;
  18. using System.Windows.Controls;
  19. using System.Windows.Data;
  20. using System.Windows.Documents;
  21. using System.Windows.Input;
  22. using System.Windows.Media;
  23. using System.Windows.Media.Imaging;
  24. using System.Windows.Navigation;
  25. using System.Windows.Shapes;
  26. namespace PackingPress
  27. {
  28. /// <summary>
  29. /// MainWindow.xaml 的交互逻辑
  30. /// </summary>
  31. public partial class MainWindow : BaseWindow
  32. {
  33. List<InstallEntity> installEntitys = new List<InstallEntity>();
  34. private string pcClientFilePath = string.Empty;
  35. public MainWindow()
  36. {
  37. funcInOutHelper.AddDelegate(DecompressionFinish);
  38. funcInOutHelper.AddDelegate(CreatePackageFinish);
  39. funcInOutHelper.AddDelegate(HideWindow);
  40. funcInOutHelper.AddDelegate(BingControl);
  41. InitializeComponent();
  42. }
  43. private void Button_Click(object sender, RoutedEventArgs e)
  44. {
  45. if (GetHardDiskFreeSpace() < 1024)
  46. {
  47. MessageBox.Show(TranslateHelper.Translate("Diskfull"));
  48. return;
  49. }
  50. WaitProcessWindow processWindow = new WaitProcessWindow();
  51. processWindow.Show();
  52. Task.Run(() =>
  53. {
  54. funcInOutHelper.RunDelegate("HideWindow");
  55. var directorys = new List<InstallEntity>();
  56. var files = new List<InstallEntity>();
  57. var packages = new List<UpgradePackage>();
  58. List<InstallEntity> selectItems = dtgShow.SelectedCells.Select(f => f.Item as InstallEntity).Distinct().ToList();
  59. if (selectItems.Count == 0)
  60. {
  61. selectItems = installEntitys;
  62. }
  63. bool isNeedOldAndroid = true, isNeedOldPC = true, isNeedOldAgent = true, isNeedOldMac = true, isNeedOldvBox = true;
  64. SettingJsonGet jObjectSystemConfig = new SettingJsonGet(AppDomain.CurrentDomain.BaseDirectory + "\\DescriptionConfig.json");
  65. var jsonRoot = (JObject)jObjectSystemConfig.GetJsonRoot();
  66. foreach (var item in selectItems)
  67. {
  68. var entity = item;
  69. if (entity != null && !string.IsNullOrWhiteSpace(entity.Path))
  70. {
  71. if (entity != null && entity.IsDirectory)
  72. {
  73. directorys.Add(entity);
  74. }
  75. else
  76. {
  77. files.Add(entity);
  78. }
  79. string pcClientVersion = RegexHelper.MatchSub(entity.Path, "Flyinsono_Windows_([0-9.]*).exe");
  80. if (!string.IsNullOrWhiteSpace(pcClientVersion))
  81. {
  82. pcClientFilePath = entity.FullPath;
  83. AddPackageFile(packages, jsonRoot, PackagePlatform.PC, PackageType.Client, pcClientVersion, entity.FullPath);
  84. isNeedOldPC = false;
  85. continue;
  86. }
  87. string vboxClientVersion = RegexHelper.MatchSub(entity.Path, "Flyinsono_SonoPost_([0-9.]*).apk");
  88. if (!string.IsNullOrWhiteSpace(vboxClientVersion))
  89. {
  90. AddPackageFile(packages, jsonRoot, PackagePlatform.Android, PackageType.Agent, vboxClientVersion, entity.FullPath);
  91. isNeedOldvBox = false;
  92. continue;
  93. }
  94. string androidClientVersion = RegexHelper.MatchSub(entity.Path, "Flyinsono_Android_([0-9.]*).apk");
  95. if (!string.IsNullOrWhiteSpace(androidClientVersion))
  96. {
  97. AddPackageFile(packages, jsonRoot, PackagePlatform.Android, PackageType.Client, androidClientVersion, entity.FullPath);
  98. isNeedOldAndroid = false;
  99. continue;
  100. }
  101. string agentVersion = RegexHelper.MatchSub(entity.Path, "AgentSetup_([0-9.]*).exe");
  102. if (!string.IsNullOrWhiteSpace(agentVersion))
  103. {
  104. AddPackageFile(packages, jsonRoot, PackagePlatform.PC, PackageType.Agent, agentVersion, entity.FullPath);
  105. isNeedOldAgent = false;
  106. continue;
  107. }
  108. string macClientVersion = RegexHelper.MatchSub(entity.Path, "Flyinsono_Mac_([0-9.]*).pkg");
  109. if (!string.IsNullOrWhiteSpace(macClientVersion))
  110. {
  111. AddPackageFile(packages, jsonRoot, PackagePlatform.Mac, PackageType.Client, macClientVersion, entity.FullPath);
  112. isNeedOldMac = false;
  113. continue;
  114. }
  115. }
  116. }
  117. if (isNeedOldAgent || isNeedOldAndroid || isNeedOldPC || isNeedOldMac || isNeedOldvBox)
  118. {
  119. UpgradePackageReader upgradePackageReader = new UpgradePackageReader("bakupgrade.pak");
  120. foreach (var package in upgradePackageReader.Packages)
  121. {
  122. switch (package.Platform)
  123. {
  124. case PackagePlatform.Android:
  125. if (package.Type == PackageType.Agent)
  126. {
  127. if (isNeedOldvBox)
  128. {
  129. packages.Add(new UpgradePackage(package.Platform, package.Type, package.Version, package.Description, package.FileData));
  130. }
  131. }
  132. else
  133. {
  134. if (isNeedOldAndroid)
  135. {
  136. packages.Add(new UpgradePackage(package.Platform, package.Type, package.Version, package.Description, package.FileData));
  137. }
  138. }
  139. break;
  140. case PackagePlatform.PC:
  141. if (isNeedOldPC)
  142. {
  143. packages.Add(new UpgradePackage(package.Platform, package.Type, package.Version, package.Description, package.FileData));
  144. }
  145. break;
  146. case PackagePlatform.Mac:
  147. if (isNeedOldMac)
  148. {
  149. packages.Add(new UpgradePackage(package.Platform, package.Type, package.Version, package.Description, package.FileData));
  150. }
  151. break;
  152. }
  153. if (isNeedOldAgent && package.Type == PackageType.Agent)
  154. {
  155. packages.Add(new UpgradePackage(package.Platform, package.Type, package.Version, package.Description, package.FileData));
  156. }
  157. }
  158. }
  159. if (files.Count > 0)
  160. {
  161. var writer = new UpgradePackageWriter("bakupgrade.pak");
  162. foreach (var upgradePackage in packages)
  163. {
  164. writer.AddPackage(upgradePackage);
  165. }
  166. writer.Save();
  167. }
  168. var systemPackageDir = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SystemPackage");
  169. var uFilePackageDir = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "UFilePackage");
  170. Directory.CreateDirectory(systemPackageDir);
  171. CreateUpgradePackage(systemPackageDir);
  172. using (Process ps = new Process())
  173. {
  174. ps.StartInfo.FileName = "cmd.exe";
  175. ps.StartInfo.UseShellExecute = false;
  176. ps.StartInfo.RedirectStandardOutput = true;
  177. ps.StartInfo.RedirectStandardInput = true;
  178. ps.StartInfo.CreateNoWindow = true;
  179. ps.StartInfo.Verb = "runas";
  180. ps.Start();
  181. if (files.Count > 0)
  182. {
  183. File.Copy(
  184. System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bakupgrade.pak"),
  185. System.IO.Path.Combine(systemPackageDir, "upgrade.pak"),
  186. true);
  187. }
  188. directorys.ForEach(directory =>
  189. {
  190. ps.StandardInput.WriteLine($"xcopy \"{directory.FullPath}\" \"{ AppDomain.CurrentDomain.BaseDirectory}\\SystemPackage\\{directory.Path}\\\" /c/e/q/y/j/r");
  191. });
  192. files.ForEach(fileInfo =>
  193. {
  194. if (RegexHelper.IsMatch(fileInfo.Path, "Flyinsono_Windows_([0-9.]*).exe")) { return; }
  195. if (RegexHelper.IsMatch(fileInfo.Path, "Flyinsono_SonoPost_([0-9.]*).apk")) { return; }
  196. Directory.CreateDirectory(uFilePackageDir);
  197. File.Copy(
  198. fileInfo.FullPath,
  199. System.IO.Path.Combine(uFilePackageDir, fileInfo.Path),
  200. true);
  201. });
  202. ps.StandardInput.WriteLine($"exit");
  203. var result = ps.StandardOutput.ReadToEnd();
  204. }
  205. Thread.Sleep(8000);
  206. var ufilePackageZip = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "UFilePackage.zip");
  207. if (File.Exists(ufilePackageZip))
  208. {
  209. File.Delete(ufilePackageZip);
  210. }
  211. var systemPackageZip = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SystemPackage.zip");
  212. if (File.Exists(systemPackageZip))
  213. {
  214. File.Delete(systemPackageZip);
  215. }
  216. if (Directory.Exists(systemPackageDir))
  217. {
  218. ZipHelper.Zips(
  219. systemPackageDir,
  220. systemPackageZip
  221. );
  222. }
  223. if (Directory.Exists(uFilePackageDir))
  224. {
  225. ZipHelper.Zips(
  226. uFilePackageDir,
  227. ufilePackageZip
  228. );
  229. }
  230. using (Process ps = new Process())
  231. {
  232. ps.StartInfo.FileName = "cmd.exe";
  233. ps.StartInfo.UseShellExecute = false;
  234. ps.StartInfo.RedirectStandardOutput = true;
  235. ps.StartInfo.RedirectStandardInput = true;
  236. ps.StartInfo.CreateNoWindow = true;
  237. ps.StartInfo.Verb = "runas";
  238. ps.Start();
  239. ps.StandardInput.WriteLine($"rd /s /q \"{ AppDomain.CurrentDomain.BaseDirectory}\\SystemPackage\\\"");
  240. ps.StandardInput.WriteLine($"rd /s /q \"{ AppDomain.CurrentDomain.BaseDirectory}\\UFilePackage\\\"");
  241. ps.StandardInput.WriteLine($"rd /s /q \"{ AppDomain.CurrentDomain.BaseDirectory}\\InstallPackage\\\"");
  242. ps.StandardInput.WriteLine($"exit");
  243. var result = ps.StandardOutput.ReadToEnd();
  244. }
  245. }).ContinueWith(f=> {
  246. if (f.IsFaulted)
  247. {
  248. FileHelper.AppendWriteFile("ErrorInfo.txt", JsonConvert.SerializeObject(f.Exception.InnerExceptions.Select(ex => ex.Message + "|" + ex.StackTrace + ";")));
  249. }
  250. if (f.IsCompleted)
  251. {
  252. funcInOutHelper.RunDelegate("CreatePackageFinish", processWindow);
  253. }
  254. });
  255. }
  256. private void CreateUpgradePackage(string upgradeFolder)
  257. {
  258. var upgradeFilesCreater = new UpgradeFilesCreater();
  259. if (File.Exists(pcClientFilePath))
  260. {
  261. upgradeFilesCreater.CreateUpgradePackage(pcClientFilePath, upgradeFolder);
  262. }
  263. }
  264. private void AddPackageFile(List<UpgradePackage> packages, JObject jsonRoot, PackagePlatform packagePlatform, PackageType packageType , string androidClientVersion, string filePath)
  265. {
  266. var descriptionEncrypt = string.Empty;
  267. if (packageType == PackageType.Client)
  268. {
  269. var cnDescription = jsonRoot.GetJPropertyValueByPath<string>($"$.{packagePlatform}.ChineseDescription");
  270. var usDescription = jsonRoot.GetJPropertyValueByPath<string>($"$.{packagePlatform}.EnglishDescription");
  271. var portugalDescription = jsonRoot.GetJPropertyValueByPath<string>($"$.{packagePlatform}.PortugalDescription");
  272. var rumaniaDescription = jsonRoot.GetJPropertyValueByPath<string>($"$.{packagePlatform}.RumaniaDescription");
  273. descriptionEncrypt = "[{\"Language\":\"Chinese\",\"Content\":\"" +
  274. DesBuilder.Encrypt(HttpUtility.UrlDecode(cnDescription)) +
  275. "\"},{\"Language\":\"English\",\"Content\":\"" +
  276. DesBuilder.Encrypt(HttpUtility.UrlDecode(usDescription)) +
  277. "\"},{\"Language\":\"Portuguese\",\"Content\":\"" +
  278. DesBuilder.Encrypt(HttpUtility.UrlDecode(portugalDescription)) +
  279. "\"},{\"Language\":\"Romanian\",\"Content\":\"" +
  280. DesBuilder.Encrypt(HttpUtility.UrlDecode(rumaniaDescription)) +
  281. "\"}]";
  282. }
  283. using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
  284. {
  285. byte[] fileBytes = new byte[fileStream.Length];
  286. fileStream.Read(fileBytes, 0, (int)fileStream.Length);
  287. packages.Add(new UpgradePackage(packagePlatform, packageType, new Version(androidClientVersion), descriptionEncrypt, fileBytes));
  288. }
  289. }
  290. private void DtgShow_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  291. {
  292. PackageDescriptionWindow packageDescriptionWindow = new PackageDescriptionWindow();
  293. packageDescriptionWindow.Show();
  294. }
  295. private void Decompression_Click(object sender, RoutedEventArgs e)
  296. {
  297. if (GetHardDiskFreeSpace() < 1024)
  298. {
  299. MessageBox.Show(TranslateHelper.Translate("Diskfull"));
  300. return;
  301. }
  302. WaitProcessWindow processWindow = new WaitProcessWindow();
  303. processWindow.Show();
  304. Task.Run(() =>
  305. {
  306. funcInOutHelper.RunDelegate("HideWindow");
  307. string[] files = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory);
  308. foreach (var file in files)
  309. {
  310. var extensionName = System.IO.Path.GetExtension(file);
  311. if (extensionName.ToLower() == ".zip" || extensionName.ToLower() == ".rar")
  312. {
  313. if (!Directory.Exists($"{AppDomain.CurrentDomain.BaseDirectory}\\InstallPackage"))
  314. {
  315. ZipHelper.Decompression(file, $"{AppDomain.CurrentDomain.BaseDirectory}\\InstallPackage");
  316. }
  317. break;
  318. }
  319. }
  320. string[] installFiles = Directory.GetFiles($"{AppDomain.CurrentDomain.BaseDirectory}\\InstallPackage");
  321. string[] installDirectories = Directory.GetDirectories($"{AppDomain.CurrentDomain.BaseDirectory}\\InstallPackage");
  322. installEntitys.Clear();
  323. foreach (var installFile in installFiles)
  324. {
  325. if (string.IsNullOrWhiteSpace(installFile)) { continue; }
  326. if (installFile.IndexOf("InstallerMaker.exe", StringComparison.Ordinal) > -1) { continue; }
  327. if (installFile.IndexOf("UpgradePackageBuilder.exe", StringComparison.Ordinal) > -1) { continue; }
  328. if (installFile.IndexOf("AgentSetupFull_", StringComparison.Ordinal) > -1) { continue; }
  329. if (installFile.IndexOf("StationSetup_", StringComparison.Ordinal) > -1) { continue; }
  330. if (installFile.IndexOf("Vestris.ResourceLib.dll", StringComparison.Ordinal) > -1) { continue; }
  331. if (installFile.IndexOf("ClientUpgrade_Release", StringComparison.Ordinal) > -1) { continue; }
  332. if (installFile.IndexOf("PersonalFlyinsono_Release", StringComparison.Ordinal) > -1) { continue; }
  333. if (installFile.IndexOf("vCarotidInstallFiles.zip", StringComparison.Ordinal) > -1) { continue; }
  334. installEntitys.Add(new InstallEntity { IsDirectory = false, FullPath = installFile, Path = installFile.Substring(installFile.LastIndexOf('\\') + 1) });
  335. }
  336. foreach (var installDirectory in installDirectories)
  337. {
  338. if (string.IsNullOrWhiteSpace(installDirectory)) { continue; }
  339. if (installDirectory.IndexOf("TestClient", StringComparison.Ordinal) > -1) { continue; }
  340. if (installDirectory.IndexOf("Terminal", StringComparison.Ordinal) > -1) { continue; }
  341. if (installDirectory.IndexOf("Station", StringComparison.Ordinal) > -1) { continue; }
  342. if (installDirectory.IndexOf("License", StringComparison.Ordinal) > -1) { continue; }
  343. if (installDirectory.IndexOf("Agent", StringComparison.Ordinal) > 1) { continue; }
  344. if (installDirectory.IndexOf("ClickOnceSetup", StringComparison.Ordinal) > -1) { continue; }
  345. if (installDirectory.IndexOf("IPLocationServerTool", StringComparison.Ordinal) > -1) { continue; }
  346. if (installDirectory.IndexOf("EncryptTool", StringComparison.Ordinal) > -1) { continue; }
  347. if (installDirectory.IndexOf("UploadClient", StringComparison.Ordinal) > -1) { continue; }
  348. if (Regex.IsMatch(installDirectory,"PackingPress$")) { continue; }
  349. if (installDirectory.IndexOf("TranslateTool", StringComparison.Ordinal) > -1) { continue; }
  350. var entity = new InstallEntity { IsDirectory = true, FullPath = installDirectory, Path = installDirectory.Substring(installDirectory.LastIndexOf('\\') + 1) };
  351. if (entity.Path == "Client")
  352. {
  353. if (Directory.Exists(installDirectory + "\\Mobile\\Android\\"))
  354. {
  355. var androidApk = Directory.GetFiles(installDirectory + "\\Mobile\\Android\\");
  356. foreach (var apkpath in androidApk)
  357. {
  358. if (RegexHelper.IsMatch(apkpath, "Flyinsono_Android_([0-9.]*).apk"))
  359. {
  360. FileInfo androidApkInfo = new FileInfo(apkpath);
  361. var androidFile = new InstallEntity { IsDirectory = false, FullPath = installDirectory + $"\\Mobile\\Android\\{androidApkInfo.Name}", Path = androidApkInfo.Name };
  362. installEntitys.Add(androidFile);
  363. break;
  364. }
  365. }
  366. }
  367. continue;
  368. }
  369. else if (entity.Path == "SONOPOST")
  370. {
  371. if (Directory.Exists(installDirectory))
  372. {
  373. var androidApk = Directory.GetFiles(installDirectory);
  374. foreach (var apkpath in androidApk)
  375. {
  376. if (RegexHelper.IsMatch(apkpath, "Flyinsono_SonoPost_([0-9.]*).apk"))
  377. {
  378. FileInfo androidApkInfo = new FileInfo(apkpath);
  379. var androidFile = new InstallEntity { IsDirectory = false, FullPath = installDirectory + $"\\{androidApkInfo.Name}", Path = androidApkInfo.Name };
  380. installEntitys.Add(androidFile);
  381. break;
  382. }
  383. }
  384. }
  385. continue;
  386. }
  387. installEntitys.Add(entity);
  388. }
  389. funcInOutHelper.RunDelegate("BingControl");
  390. }).ContinueWith(f =>
  391. {
  392. if (f.IsCompleted)
  393. {
  394. funcInOutHelper.RunDelegate("DecompressionFinish", processWindow);
  395. }
  396. });
  397. }
  398. /// <summary>
  399. /// 获取指定驱动器的剩余空间总大小(单位为MB)
  400. /// </summary>
  401. private long GetHardDiskFreeSpace()
  402. {
  403. var strHardDiskName = RegexHelper.MatchSub(AppDomain.CurrentDomain.BaseDirectory,"^([a-zA-Z]:\\\\).*");
  404. long freeSpace = new long();
  405. System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();
  406. foreach (System.IO.DriveInfo drive in drives)
  407. {
  408. if (drive.Name == strHardDiskName)
  409. {
  410. freeSpace = drive.TotalFreeSpace / (1024 * 1024);
  411. }
  412. }
  413. return freeSpace;
  414. }
  415. private object BingControl(object obj)
  416. {
  417. dtgShow.ItemsSource = null;
  418. dtgShow.ItemsSource = installEntitys;
  419. return obj;
  420. }
  421. private object HideWindow(object obj)
  422. {
  423. this.Hide();
  424. return null;
  425. }
  426. private object DecompressionFinish(object processWindow)
  427. {
  428. this.Show();
  429. ((WaitProcessWindow)processWindow).Close();
  430. MessageBox.Show($"{TranslateHelper.Translate("DecompressionFinish")}!");
  431. return null;
  432. }
  433. private object CreatePackageFinish(object processWindow)
  434. {
  435. this.Show();
  436. ((WaitProcessWindow)processWindow).Close();
  437. MessageBox.Show($"{TranslateHelper.Translate("PackagingFinish")}!");
  438. return null;
  439. }
  440. private void DtgShow_DragEnter(object sender, DragEventArgs e)
  441. {
  442. }
  443. private void SetDescription_Click(object sender, RoutedEventArgs e)
  444. {
  445. PackageDescriptionWindow packageDescriptionWindow = new PackageDescriptionWindow();
  446. packageDescriptionWindow.Show();
  447. }
  448. private void UploadSetting_Click(object sender, RoutedEventArgs e)
  449. {
  450. using (var stream = OpenFileBrowserDialog("conf"))
  451. {
  452. if (stream != Stream.Null)
  453. {
  454. var serverSetting = AppDomain.CurrentDomain.BaseDirectory + "\\InstallPackage\\Server\\Settings\\Server\\Setting.conf";
  455. if (!File.Exists(serverSetting))
  456. {
  457. MessageBox.Show($"{TranslateHelper.Translate("CannotFindSettingFile")}");
  458. return;
  459. }
  460. using (FileStream fileStream = new FileStream(serverSetting, FileMode.Create))
  461. {
  462. byte[] readBytes = new byte[4096];
  463. int readCount;
  464. do
  465. {
  466. readCount = stream.Read(readBytes, 0, readBytes.Length);
  467. fileStream.Write(readBytes, 0, readCount);
  468. } while (readCount > 0);
  469. MessageBox.Show($"{TranslateHelper.Translate("UploadSuccess")}");
  470. }
  471. }
  472. }
  473. }
  474. /// <summary>
  475. /// 打开选择文件对话框
  476. /// </summary>
  477. /// <param name="defaultExt"></param>
  478. /// <returns></returns>
  479. private static Stream OpenFileBrowserDialog(string defaultExt = "")
  480. {
  481. System.Windows.Forms.OpenFileDialog fileDialog = new System.Windows.Forms.OpenFileDialog();
  482. if (!string.IsNullOrWhiteSpace(defaultExt))
  483. {
  484. fileDialog.DefaultExt = defaultExt;
  485. fileDialog.Filter = $"*.{defaultExt}|*.{defaultExt}";
  486. }
  487. System.Windows.Forms.DialogResult result = fileDialog.ShowDialog();
  488. if (result == System.Windows.Forms.DialogResult.Cancel)
  489. {
  490. return Stream.Null;
  491. }
  492. var fileStream = fileDialog.OpenFile();
  493. return fileStream;
  494. }
  495. }
  496. }