ManagedFileSystem.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. #pragma warning disable CS1591
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Globalization;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using MediaBrowser.Common.Configuration;
  10. using MediaBrowser.Model.IO;
  11. using MediaBrowser.Model.System;
  12. using Microsoft.Extensions.Logging;
  13. using OperatingSystem = MediaBrowser.Common.System.OperatingSystem;
  14. namespace Emby.Server.Implementations.IO
  15. {
  16. /// <summary>
  17. /// Class ManagedFileSystem.
  18. /// </summary>
  19. public class ManagedFileSystem : IFileSystem
  20. {
  21. protected ILogger<ManagedFileSystem> Logger;
  22. private readonly List<IShortcutHandler> _shortcutHandlers = new List<IShortcutHandler>();
  23. private readonly string _tempPath;
  24. private readonly bool _isEnvironmentCaseInsensitive;
  25. public ManagedFileSystem(
  26. ILogger<ManagedFileSystem> logger,
  27. IApplicationPaths applicationPaths)
  28. {
  29. Logger = logger;
  30. _tempPath = applicationPaths.TempDirectory;
  31. _isEnvironmentCaseInsensitive = OperatingSystem.Id == OperatingSystemId.Windows;
  32. }
  33. public virtual void AddShortcutHandler(IShortcutHandler handler)
  34. {
  35. _shortcutHandlers.Add(handler);
  36. }
  37. /// <summary>
  38. /// Determines whether the specified filename is shortcut.
  39. /// </summary>
  40. /// <param name="filename">The filename.</param>
  41. /// <returns><c>true</c> if the specified filename is shortcut; otherwise, <c>false</c>.</returns>
  42. /// <exception cref="ArgumentNullException">filename</exception>
  43. public virtual bool IsShortcut(string filename)
  44. {
  45. if (string.IsNullOrEmpty(filename))
  46. {
  47. throw new ArgumentNullException(nameof(filename));
  48. }
  49. var extension = Path.GetExtension(filename);
  50. return _shortcutHandlers.Any(i => string.Equals(extension, i.Extension, StringComparison.OrdinalIgnoreCase));
  51. }
  52. /// <summary>
  53. /// Resolves the shortcut.
  54. /// </summary>
  55. /// <param name="filename">The filename.</param>
  56. /// <returns>System.String.</returns>
  57. /// <exception cref="ArgumentNullException">filename</exception>
  58. public virtual string ResolveShortcut(string filename)
  59. {
  60. if (string.IsNullOrEmpty(filename))
  61. {
  62. throw new ArgumentNullException(nameof(filename));
  63. }
  64. var extension = Path.GetExtension(filename);
  65. var handler = _shortcutHandlers.FirstOrDefault(i => string.Equals(extension, i.Extension, StringComparison.OrdinalIgnoreCase));
  66. return handler?.Resolve(filename);
  67. }
  68. public virtual string MakeAbsolutePath(string folderPath, string filePath)
  69. {
  70. // path is actually a stream
  71. if (string.IsNullOrWhiteSpace(filePath) || filePath.Contains("://", StringComparison.Ordinal))
  72. {
  73. return filePath;
  74. }
  75. if (filePath.Length > 3 && filePath[1] == ':' && filePath[2] == '/')
  76. {
  77. // absolute local path
  78. return filePath;
  79. }
  80. // unc path
  81. if (filePath.StartsWith("\\\\", StringComparison.Ordinal))
  82. {
  83. return filePath;
  84. }
  85. var firstChar = filePath[0];
  86. if (firstChar == '/')
  87. {
  88. // for this we don't really know
  89. return filePath;
  90. }
  91. // relative path
  92. if (firstChar == '\\')
  93. {
  94. filePath = filePath.Substring(1);
  95. }
  96. try
  97. {
  98. return Path.GetFullPath(Path.Combine(folderPath, filePath));
  99. }
  100. catch (ArgumentException)
  101. {
  102. return filePath;
  103. }
  104. catch (PathTooLongException)
  105. {
  106. return filePath;
  107. }
  108. catch (NotSupportedException)
  109. {
  110. return filePath;
  111. }
  112. }
  113. /// <summary>
  114. /// Creates the shortcut.
  115. /// </summary>
  116. /// <param name="shortcutPath">The shortcut path.</param>
  117. /// <param name="target">The target.</param>
  118. /// <exception cref="ArgumentNullException">The shortcutPath or target is null.</exception>
  119. public virtual void CreateShortcut(string shortcutPath, string target)
  120. {
  121. if (string.IsNullOrEmpty(shortcutPath))
  122. {
  123. throw new ArgumentNullException(nameof(shortcutPath));
  124. }
  125. if (string.IsNullOrEmpty(target))
  126. {
  127. throw new ArgumentNullException(nameof(target));
  128. }
  129. var extension = Path.GetExtension(shortcutPath);
  130. var handler = _shortcutHandlers.Find(i => string.Equals(extension, i.Extension, StringComparison.OrdinalIgnoreCase));
  131. if (handler != null)
  132. {
  133. handler.Create(shortcutPath, target);
  134. }
  135. else
  136. {
  137. throw new NotImplementedException();
  138. }
  139. }
  140. /// <summary>
  141. /// Returns a <see cref="FileSystemMetadata"/> object for the specified file or directory path.
  142. /// </summary>
  143. /// <param name="path">A path to a file or directory.</param>
  144. /// <returns>A <see cref="FileSystemMetadata"/> object.</returns>
  145. /// <remarks>If the specified path points to a directory, the returned <see cref="FileSystemMetadata"/> object's
  146. /// <see cref="FileSystemMetadata.IsDirectory"/> property will be set to true and all other properties will reflect the properties of the directory.</remarks>
  147. public virtual FileSystemMetadata GetFileSystemInfo(string path)
  148. {
  149. // Take a guess to try and avoid two file system hits, but we'll double-check by calling Exists
  150. if (Path.HasExtension(path))
  151. {
  152. var fileInfo = new FileInfo(path);
  153. if (fileInfo.Exists)
  154. {
  155. return GetFileSystemMetadata(fileInfo);
  156. }
  157. return GetFileSystemMetadata(new DirectoryInfo(path));
  158. }
  159. else
  160. {
  161. var fileInfo = new DirectoryInfo(path);
  162. if (fileInfo.Exists)
  163. {
  164. return GetFileSystemMetadata(fileInfo);
  165. }
  166. return GetFileSystemMetadata(new FileInfo(path));
  167. }
  168. }
  169. /// <summary>
  170. /// Returns a <see cref="FileSystemMetadata"/> object for the specified file path.
  171. /// </summary>
  172. /// <param name="path">A path to a file.</param>
  173. /// <returns>A <see cref="FileSystemMetadata"/> object.</returns>
  174. /// <remarks><para>If the specified path points to a directory, the returned <see cref="FileSystemMetadata"/> object's
  175. /// <see cref="FileSystemMetadata.IsDirectory"/> property and the <see cref="FileSystemMetadata.Exists"/> property will both be set to false.</para>
  176. /// <para>For automatic handling of files <b>and</b> directories, use <see cref="GetFileSystemInfo"/>.</para></remarks>
  177. public virtual FileSystemMetadata GetFileInfo(string path)
  178. {
  179. var fileInfo = new FileInfo(path);
  180. return GetFileSystemMetadata(fileInfo);
  181. }
  182. /// <summary>
  183. /// Returns a <see cref="FileSystemMetadata"/> object for the specified directory path.
  184. /// </summary>
  185. /// <param name="path">A path to a directory.</param>
  186. /// <returns>A <see cref="FileSystemMetadata"/> object.</returns>
  187. /// <remarks><para>If the specified path points to a file, the returned <see cref="FileSystemMetadata"/> object's
  188. /// <see cref="FileSystemMetadata.IsDirectory"/> property will be set to true and the <see cref="FileSystemMetadata.Exists"/> property will be set to false.</para>
  189. /// <para>For automatic handling of files <b>and</b> directories, use <see cref="GetFileSystemInfo"/>.</para></remarks>
  190. public virtual FileSystemMetadata GetDirectoryInfo(string path)
  191. {
  192. var fileInfo = new DirectoryInfo(path);
  193. return GetFileSystemMetadata(fileInfo);
  194. }
  195. private FileSystemMetadata GetFileSystemMetadata(FileSystemInfo info)
  196. {
  197. var result = new FileSystemMetadata
  198. {
  199. Exists = info.Exists,
  200. FullName = info.FullName,
  201. Extension = info.Extension,
  202. Name = info.Name
  203. };
  204. if (result.Exists)
  205. {
  206. result.IsDirectory = info is DirectoryInfo || (info.Attributes & FileAttributes.Directory) == FileAttributes.Directory;
  207. // if (!result.IsDirectory)
  208. //{
  209. // result.IsHidden = (info.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden;
  210. //}
  211. if (info is FileInfo fileInfo)
  212. {
  213. result.Length = fileInfo.Length;
  214. // Issue #2354 get the size of files behind symbolic links
  215. if (fileInfo.Attributes.HasFlag(FileAttributes.ReparsePoint))
  216. {
  217. using (Stream thisFileStream = File.OpenRead(fileInfo.FullName))
  218. {
  219. result.Length = thisFileStream.Length;
  220. }
  221. }
  222. result.DirectoryName = fileInfo.DirectoryName;
  223. }
  224. result.CreationTimeUtc = GetCreationTimeUtc(info);
  225. result.LastWriteTimeUtc = GetLastWriteTimeUtc(info);
  226. }
  227. else
  228. {
  229. result.IsDirectory = info is DirectoryInfo;
  230. }
  231. return result;
  232. }
  233. private static ExtendedFileSystemInfo GetExtendedFileSystemInfo(string path)
  234. {
  235. var result = new ExtendedFileSystemInfo();
  236. var info = new FileInfo(path);
  237. if (info.Exists)
  238. {
  239. result.Exists = true;
  240. var attributes = info.Attributes;
  241. result.IsHidden = (attributes & FileAttributes.Hidden) == FileAttributes.Hidden;
  242. result.IsReadOnly = (attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly;
  243. }
  244. return result;
  245. }
  246. /// <summary>
  247. /// Takes a filename and removes invalid characters.
  248. /// </summary>
  249. /// <param name="filename">The filename.</param>
  250. /// <returns>System.String.</returns>
  251. /// <exception cref="ArgumentNullException">The filename is null.</exception>
  252. public virtual string GetValidFilename(string filename)
  253. {
  254. var builder = new StringBuilder(filename);
  255. foreach (var c in Path.GetInvalidFileNameChars())
  256. {
  257. builder = builder.Replace(c, ' ');
  258. }
  259. return builder.ToString();
  260. }
  261. /// <summary>
  262. /// Gets the creation time UTC.
  263. /// </summary>
  264. /// <param name="info">The info.</param>
  265. /// <returns>DateTime.</returns>
  266. public DateTime GetCreationTimeUtc(FileSystemInfo info)
  267. {
  268. // This could throw an error on some file systems that have dates out of range
  269. try
  270. {
  271. return info.CreationTimeUtc;
  272. }
  273. catch (Exception ex)
  274. {
  275. Logger.LogError(ex, "Error determining CreationTimeUtc for {FullName}", info.FullName);
  276. return DateTime.MinValue;
  277. }
  278. }
  279. /// <summary>
  280. /// Gets the creation time UTC.
  281. /// </summary>
  282. /// <param name="path">The path.</param>
  283. /// <returns>DateTime.</returns>
  284. public virtual DateTime GetCreationTimeUtc(string path)
  285. {
  286. return GetCreationTimeUtc(GetFileSystemInfo(path));
  287. }
  288. public virtual DateTime GetCreationTimeUtc(FileSystemMetadata info)
  289. {
  290. return info.CreationTimeUtc;
  291. }
  292. public virtual DateTime GetLastWriteTimeUtc(FileSystemMetadata info)
  293. {
  294. return info.LastWriteTimeUtc;
  295. }
  296. /// <summary>
  297. /// Gets the creation time UTC.
  298. /// </summary>
  299. /// <param name="info">The info.</param>
  300. /// <returns>DateTime.</returns>
  301. public DateTime GetLastWriteTimeUtc(FileSystemInfo info)
  302. {
  303. // This could throw an error on some file systems that have dates out of range
  304. try
  305. {
  306. return info.LastWriteTimeUtc;
  307. }
  308. catch (Exception ex)
  309. {
  310. Logger.LogError(ex, "Error determining LastAccessTimeUtc for {FullName}", info.FullName);
  311. return DateTime.MinValue;
  312. }
  313. }
  314. /// <summary>
  315. /// Gets the last write time UTC.
  316. /// </summary>
  317. /// <param name="path">The path.</param>
  318. /// <returns>DateTime.</returns>
  319. public virtual DateTime GetLastWriteTimeUtc(string path)
  320. {
  321. return GetLastWriteTimeUtc(GetFileSystemInfo(path));
  322. }
  323. public virtual void SetHidden(string path, bool isHidden)
  324. {
  325. if (OperatingSystem.Id != OperatingSystemId.Windows)
  326. {
  327. return;
  328. }
  329. var info = GetExtendedFileSystemInfo(path);
  330. if (info.Exists && info.IsHidden != isHidden)
  331. {
  332. if (isHidden)
  333. {
  334. File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden);
  335. }
  336. else
  337. {
  338. var attributes = File.GetAttributes(path);
  339. attributes = RemoveAttribute(attributes, FileAttributes.Hidden);
  340. File.SetAttributes(path, attributes);
  341. }
  342. }
  343. }
  344. public virtual void SetAttributes(string path, bool isHidden, bool isReadOnly)
  345. {
  346. if (OperatingSystem.Id != OperatingSystemId.Windows)
  347. {
  348. return;
  349. }
  350. var info = GetExtendedFileSystemInfo(path);
  351. if (!info.Exists)
  352. {
  353. return;
  354. }
  355. if (info.IsReadOnly == isReadOnly && info.IsHidden == isHidden)
  356. {
  357. return;
  358. }
  359. var attributes = File.GetAttributes(path);
  360. if (isReadOnly)
  361. {
  362. attributes = attributes | FileAttributes.ReadOnly;
  363. }
  364. else
  365. {
  366. attributes = RemoveAttribute(attributes, FileAttributes.ReadOnly);
  367. }
  368. if (isHidden)
  369. {
  370. attributes = attributes | FileAttributes.Hidden;
  371. }
  372. else
  373. {
  374. attributes = RemoveAttribute(attributes, FileAttributes.Hidden);
  375. }
  376. File.SetAttributes(path, attributes);
  377. }
  378. private static FileAttributes RemoveAttribute(FileAttributes attributes, FileAttributes attributesToRemove)
  379. {
  380. return attributes & ~attributesToRemove;
  381. }
  382. /// <summary>
  383. /// Swaps the files.
  384. /// </summary>
  385. /// <param name="file1">The file1.</param>
  386. /// <param name="file2">The file2.</param>
  387. public virtual void SwapFiles(string file1, string file2)
  388. {
  389. if (string.IsNullOrEmpty(file1))
  390. {
  391. throw new ArgumentNullException(nameof(file1));
  392. }
  393. if (string.IsNullOrEmpty(file2))
  394. {
  395. throw new ArgumentNullException(nameof(file2));
  396. }
  397. var temp1 = Path.Combine(_tempPath, Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture));
  398. // Copying over will fail against hidden files
  399. SetHidden(file1, false);
  400. SetHidden(file2, false);
  401. Directory.CreateDirectory(_tempPath);
  402. File.Copy(file1, temp1, true);
  403. File.Copy(file2, file1, true);
  404. File.Copy(temp1, file2, true);
  405. }
  406. public virtual bool ContainsSubPath(string parentPath, string path)
  407. {
  408. if (string.IsNullOrEmpty(parentPath))
  409. {
  410. throw new ArgumentNullException(nameof(parentPath));
  411. }
  412. if (string.IsNullOrEmpty(path))
  413. {
  414. throw new ArgumentNullException(nameof(path));
  415. }
  416. var separatorChar = Path.DirectorySeparatorChar;
  417. return path.IndexOf(parentPath.TrimEnd(separatorChar) + separatorChar, StringComparison.OrdinalIgnoreCase) != -1;
  418. }
  419. public virtual bool IsRootPath(string path)
  420. {
  421. if (string.IsNullOrEmpty(path))
  422. {
  423. throw new ArgumentNullException(nameof(path));
  424. }
  425. var parent = Path.GetDirectoryName(path);
  426. if (!string.IsNullOrEmpty(parent))
  427. {
  428. return false;
  429. }
  430. return true;
  431. }
  432. public virtual string NormalizePath(string path)
  433. {
  434. if (string.IsNullOrEmpty(path))
  435. {
  436. throw new ArgumentNullException(nameof(path));
  437. }
  438. if (path.EndsWith(":\\", StringComparison.OrdinalIgnoreCase))
  439. {
  440. return path;
  441. }
  442. return path.TrimEnd(Path.DirectorySeparatorChar);
  443. }
  444. public virtual bool AreEqual(string path1, string path2)
  445. {
  446. if (path1 == null && path2 == null)
  447. {
  448. return true;
  449. }
  450. if (path1 == null || path2 == null)
  451. {
  452. return false;
  453. }
  454. return string.Equals(NormalizePath(path1), NormalizePath(path2), StringComparison.OrdinalIgnoreCase);
  455. }
  456. public virtual string GetFileNameWithoutExtension(FileSystemMetadata info)
  457. {
  458. if (info.IsDirectory)
  459. {
  460. return info.Name;
  461. }
  462. return Path.GetFileNameWithoutExtension(info.FullName);
  463. }
  464. public virtual bool IsPathFile(string path)
  465. {
  466. // Cannot use Path.IsPathRooted because it returns false under mono when using windows-based paths, e.g. C:\\
  467. if (path.IndexOf("://", StringComparison.OrdinalIgnoreCase) != -1 &&
  468. !path.StartsWith("file://", StringComparison.OrdinalIgnoreCase))
  469. {
  470. return false;
  471. }
  472. return true;
  473. }
  474. public virtual void DeleteFile(string path)
  475. {
  476. SetAttributes(path, false, false);
  477. File.Delete(path);
  478. }
  479. public virtual List<FileSystemMetadata> GetDrives()
  480. {
  481. // check for ready state to avoid waiting for drives to timeout
  482. // some drives on linux have no actual size or are used for other purposes
  483. return DriveInfo.GetDrives().Where(d => d.IsReady && d.TotalSize != 0 && d.DriveType != DriveType.Ram)
  484. .Select(d => new FileSystemMetadata
  485. {
  486. Name = d.Name,
  487. FullName = d.RootDirectory.FullName,
  488. IsDirectory = true
  489. }).ToList();
  490. }
  491. public virtual IEnumerable<FileSystemMetadata> GetDirectories(string path, bool recursive = false)
  492. {
  493. return ToMetadata(new DirectoryInfo(path).EnumerateDirectories("*", GetEnumerationOptions(recursive)));
  494. }
  495. public virtual IEnumerable<FileSystemMetadata> GetFiles(string path, bool recursive = false)
  496. {
  497. return GetFiles(path, null, false, recursive);
  498. }
  499. public virtual IEnumerable<FileSystemMetadata> GetFiles(string path, IReadOnlyList<string> extensions, bool enableCaseSensitiveExtensions, bool recursive = false)
  500. {
  501. var enumerationOptions = GetEnumerationOptions(recursive);
  502. // On linux and osx the search pattern is case sensitive
  503. // If we're OK with case-sensitivity, and we're only filtering for one extension, then use the native method
  504. if ((enableCaseSensitiveExtensions || _isEnvironmentCaseInsensitive) && extensions != null && extensions.Count == 1)
  505. {
  506. return ToMetadata(new DirectoryInfo(path).EnumerateFiles("*" + extensions[0], enumerationOptions));
  507. }
  508. var files = new DirectoryInfo(path).EnumerateFiles("*", enumerationOptions);
  509. if (extensions != null && extensions.Count > 0)
  510. {
  511. files = files.Where(i =>
  512. {
  513. var ext = i.Extension;
  514. if (ext == null)
  515. {
  516. return false;
  517. }
  518. return extensions.Contains(ext, StringComparer.OrdinalIgnoreCase);
  519. });
  520. }
  521. return ToMetadata(files);
  522. }
  523. public virtual IEnumerable<FileSystemMetadata> GetFileSystemEntries(string path, bool recursive = false)
  524. {
  525. var directoryInfo = new DirectoryInfo(path);
  526. var enumerationOptions = GetEnumerationOptions(recursive);
  527. return ToMetadata(directoryInfo.EnumerateDirectories("*", enumerationOptions))
  528. .Concat(ToMetadata(directoryInfo.EnumerateFiles("*", enumerationOptions)));
  529. }
  530. private IEnumerable<FileSystemMetadata> ToMetadata(IEnumerable<FileSystemInfo> infos)
  531. {
  532. return infos.Select(GetFileSystemMetadata);
  533. }
  534. public virtual IEnumerable<string> GetDirectoryPaths(string path, bool recursive = false)
  535. {
  536. return Directory.EnumerateDirectories(path, "*", GetEnumerationOptions(recursive));
  537. }
  538. public virtual IEnumerable<string> GetFilePaths(string path, bool recursive = false)
  539. {
  540. return GetFilePaths(path, null, false, recursive);
  541. }
  542. public virtual IEnumerable<string> GetFilePaths(string path, string[] extensions, bool enableCaseSensitiveExtensions, bool recursive = false)
  543. {
  544. var enumerationOptions = GetEnumerationOptions(recursive);
  545. // On linux and osx the search pattern is case sensitive
  546. // If we're OK with case-sensitivity, and we're only filtering for one extension, then use the native method
  547. if ((enableCaseSensitiveExtensions || _isEnvironmentCaseInsensitive) && extensions != null && extensions.Length == 1)
  548. {
  549. return Directory.EnumerateFiles(path, "*" + extensions[0], enumerationOptions);
  550. }
  551. var files = Directory.EnumerateFiles(path, "*", enumerationOptions);
  552. if (extensions != null && extensions.Length > 0)
  553. {
  554. files = files.Where(i =>
  555. {
  556. var ext = Path.GetExtension(i);
  557. if (ext == null)
  558. {
  559. return false;
  560. }
  561. return extensions.Contains(ext, StringComparer.OrdinalIgnoreCase);
  562. });
  563. }
  564. return files;
  565. }
  566. public virtual IEnumerable<string> GetFileSystemEntryPaths(string path, bool recursive = false)
  567. {
  568. return Directory.EnumerateFileSystemEntries(path, "*", GetEnumerationOptions(recursive));
  569. }
  570. private EnumerationOptions GetEnumerationOptions(bool recursive)
  571. {
  572. return new EnumerationOptions
  573. {
  574. RecurseSubdirectories = recursive,
  575. IgnoreInaccessible = true,
  576. // Don't skip any files.
  577. AttributesToSkip = 0
  578. };
  579. }
  580. private static void RunProcess(string path, string args, string workingDirectory)
  581. {
  582. using (var process = Process.Start(new ProcessStartInfo
  583. {
  584. Arguments = args,
  585. FileName = path,
  586. CreateNoWindow = true,
  587. WorkingDirectory = workingDirectory,
  588. WindowStyle = ProcessWindowStyle.Normal
  589. }))
  590. {
  591. process.WaitForExit();
  592. }
  593. }
  594. }
  595. }