MainStartup.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. using MediaBrowser.Common.Implementations.Logging;
  2. using MediaBrowser.Model.Logging;
  3. using MediaBrowser.Server.Implementations;
  4. using MediaBrowser.Server.Startup.Common;
  5. using MediaBrowser.Server.Startup.Common.Browser;
  6. using MediaBrowser.ServerApplication.Native;
  7. using MediaBrowser.ServerApplication.Splash;
  8. using MediaBrowser.ServerApplication.Updates;
  9. using Microsoft.Win32;
  10. using System;
  11. using System.Configuration.Install;
  12. using System.Diagnostics;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Runtime.InteropServices;
  16. using System.ServiceProcess;
  17. using System.Threading;
  18. using System.Threading.Tasks;
  19. using System.Windows.Forms;
  20. using CommonIO.Windows;
  21. using Emby.Drawing.ImageMagick;
  22. using ImageMagickSharp;
  23. using MediaBrowser.Common.Net;
  24. using MediaBrowser.Server.Implementations.Logging;
  25. namespace MediaBrowser.ServerApplication
  26. {
  27. public class MainStartup
  28. {
  29. private static ApplicationHost _appHost;
  30. private static ILogger _logger;
  31. private static bool _isRunningAsService = false;
  32. private static bool _appHostDisposed;
  33. [DllImport("kernel32.dll", SetLastError = true)]
  34. static extern bool SetDllDirectory(string lpPathName);
  35. /// <summary>
  36. /// Defines the entry point of the application.
  37. /// </summary>
  38. public static void Main()
  39. {
  40. var options = new StartupOptions();
  41. _isRunningAsService = options.ContainsOption("-service");
  42. var currentProcess = Process.GetCurrentProcess();
  43. var applicationPath = currentProcess.MainModule.FileName;
  44. var architecturePath = Path.Combine(Path.GetDirectoryName(applicationPath), Environment.Is64BitProcess ? "x64" : "x86");
  45. Wand.SetMagickCoderModulePath(architecturePath);
  46. var success = SetDllDirectory(architecturePath);
  47. var appPaths = CreateApplicationPaths(applicationPath, _isRunningAsService);
  48. var logManager = new NlogManager(appPaths.LogDirectoryPath, "server");
  49. logManager.ReloadLogger(LogSeverity.Debug);
  50. logManager.AddConsoleOutput();
  51. var logger = _logger = logManager.GetLogger("Main");
  52. ApplicationHost.LogEnvironmentInfo(logger, appPaths, true);
  53. // Install directly
  54. if (options.ContainsOption("-installservice"))
  55. {
  56. logger.Info("Performing service installation");
  57. InstallService(applicationPath, logger);
  58. return;
  59. }
  60. // Restart with admin rights, then install
  61. if (options.ContainsOption("-installserviceasadmin"))
  62. {
  63. logger.Info("Performing service installation");
  64. RunServiceInstallation(applicationPath);
  65. return;
  66. }
  67. // Uninstall directly
  68. if (options.ContainsOption("-uninstallservice"))
  69. {
  70. logger.Info("Performing service uninstallation");
  71. UninstallService(applicationPath, logger);
  72. return;
  73. }
  74. // Restart with admin rights, then uninstall
  75. if (options.ContainsOption("-uninstallserviceasadmin"))
  76. {
  77. logger.Info("Performing service uninstallation");
  78. RunServiceUninstallation(applicationPath);
  79. return;
  80. }
  81. AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
  82. RunServiceInstallationIfNeeded(applicationPath);
  83. if (IsAlreadyRunning(applicationPath, currentProcess))
  84. {
  85. logger.Info("Shutting down because another instance of Media Browser Server is already running.");
  86. return;
  87. }
  88. if (PerformUpdateIfNeeded(appPaths, logger))
  89. {
  90. logger.Info("Exiting to perform application update.");
  91. return;
  92. }
  93. try
  94. {
  95. RunApplication(appPaths, logManager, _isRunningAsService, options);
  96. }
  97. finally
  98. {
  99. OnServiceShutdown();
  100. }
  101. }
  102. /// <summary>
  103. /// Determines whether [is already running] [the specified current process].
  104. /// </summary>
  105. /// <param name="applicationPath">The application path.</param>
  106. /// <param name="currentProcess">The current process.</param>
  107. /// <returns><c>true</c> if [is already running] [the specified current process]; otherwise, <c>false</c>.</returns>
  108. private static bool IsAlreadyRunning(string applicationPath, Process currentProcess)
  109. {
  110. var filename = Path.GetFileName(applicationPath);
  111. var duplicate = Process.GetProcesses().FirstOrDefault(i =>
  112. {
  113. try
  114. {
  115. return string.Equals(filename, Path.GetFileName(i.MainModule.FileName)) && currentProcess.Id != i.Id;
  116. }
  117. catch (Exception)
  118. {
  119. return false;
  120. }
  121. });
  122. if (duplicate != null)
  123. {
  124. _logger.Info("Found a duplicate process. Giving it time to exit.");
  125. if (!duplicate.WaitForExit(15000))
  126. {
  127. _logger.Info("The duplicate process did not exit.");
  128. return true;
  129. }
  130. }
  131. return false;
  132. }
  133. /// <summary>
  134. /// Creates the application paths.
  135. /// </summary>
  136. /// <param name="applicationPath">The application path.</param>
  137. /// <param name="runAsService">if set to <c>true</c> [run as service].</param>
  138. /// <returns>ServerApplicationPaths.</returns>
  139. private static ServerApplicationPaths CreateApplicationPaths(string applicationPath, bool runAsService)
  140. {
  141. var resourcesPath = Path.GetDirectoryName(applicationPath);
  142. if (runAsService)
  143. {
  144. var systemPath = Path.GetDirectoryName(applicationPath);
  145. var programDataPath = Path.GetDirectoryName(systemPath);
  146. return new ServerApplicationPaths(programDataPath, applicationPath, resourcesPath);
  147. }
  148. return new ServerApplicationPaths(ApplicationPathHelper.GetProgramDataPath(applicationPath), applicationPath, resourcesPath);
  149. }
  150. /// <summary>
  151. /// Gets a value indicating whether this instance can self restart.
  152. /// </summary>
  153. /// <value><c>true</c> if this instance can self restart; otherwise, <c>false</c>.</value>
  154. public static bool CanSelfRestart
  155. {
  156. get
  157. {
  158. return !_isRunningAsService;
  159. }
  160. }
  161. /// <summary>
  162. /// Gets a value indicating whether this instance can self update.
  163. /// </summary>
  164. /// <value><c>true</c> if this instance can self update; otherwise, <c>false</c>.</value>
  165. public static bool CanSelfUpdate
  166. {
  167. get
  168. {
  169. return !_isRunningAsService;
  170. }
  171. }
  172. private static readonly TaskCompletionSource<bool> ApplicationTaskCompletionSource = new TaskCompletionSource<bool>();
  173. /// <summary>
  174. /// Runs the application.
  175. /// </summary>
  176. /// <param name="appPaths">The app paths.</param>
  177. /// <param name="logManager">The log manager.</param>
  178. /// <param name="runService">if set to <c>true</c> [run service].</param>
  179. /// <param name="options">The options.</param>
  180. private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager, bool runService, StartupOptions options)
  181. {
  182. var fileSystem = new WindowsFileSystem(new PatternsLogger(logManager.GetLogger("FileSystem")));
  183. fileSystem.AddShortcutHandler(new MbLinkShortcutHandler(fileSystem));
  184. //fileSystem.AddShortcutHandler(new LnkShortcutHandler(fileSystem));
  185. var nativeApp = new WindowsApp(fileSystem, _logger)
  186. {
  187. IsRunningAsService = runService
  188. };
  189. _appHost = new ApplicationHost(appPaths,
  190. logManager,
  191. options,
  192. fileSystem,
  193. "emby.windows.zip",
  194. nativeApp);
  195. var initProgress = new Progress<double>();
  196. if (!runService)
  197. {
  198. if (!options.ContainsOption("-nosplash")) ShowSplashScreen(_appHost.ApplicationVersion, initProgress, logManager.GetLogger("Splash"));
  199. // Not crazy about this but it's the only way to suppress ffmpeg crash dialog boxes
  200. SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS | ErrorModes.SEM_NOALIGNMENTFAULTEXCEPT |
  201. ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_NOOPENFILEERRORBOX);
  202. }
  203. var task = _appHost.Init(initProgress);
  204. task = task.ContinueWith(new Action<Task>(a => _appHost.RunStartupTasks()));
  205. if (runService)
  206. {
  207. StartService(logManager);
  208. }
  209. else
  210. {
  211. Task.WaitAll(task);
  212. task = InstallVcredistIfNeeded(_appHost, _logger);
  213. Task.WaitAll(task);
  214. task = InstallFrameworkV46IfNeeded(_logger);
  215. Task.WaitAll(task);
  216. SystemEvents.SessionEnding += SystemEvents_SessionEnding;
  217. SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;
  218. HideSplashScreen();
  219. ShowTrayIcon();
  220. task = ApplicationTaskCompletionSource.Task;
  221. Task.WaitAll(task);
  222. }
  223. }
  224. private static ServerNotifyIcon _serverNotifyIcon;
  225. private static void ShowTrayIcon()
  226. {
  227. //Application.EnableVisualStyles();
  228. //Application.SetCompatibleTextRenderingDefault(false);
  229. _serverNotifyIcon = new ServerNotifyIcon(_appHost.LogManager, _appHost, _appHost.ServerConfigurationManager, _appHost.LocalizationManager);
  230. Application.Run();
  231. }
  232. private static SplashForm _splash;
  233. private static Thread _splashThread;
  234. private static void ShowSplashScreen(Version appVersion, Progress<double> progress, ILogger logger)
  235. {
  236. var thread = new Thread(() =>
  237. {
  238. _splash = new SplashForm(appVersion, progress);
  239. _splash.ShowDialog();
  240. });
  241. thread.SetApartmentState(ApartmentState.STA);
  242. thread.IsBackground = true;
  243. thread.Start();
  244. _splashThread = thread;
  245. }
  246. private static void HideSplashScreen()
  247. {
  248. if (_splash != null)
  249. {
  250. Action act = () =>
  251. {
  252. _splash.Close();
  253. _splashThread = null;
  254. };
  255. _splash.Invoke(act);
  256. }
  257. }
  258. static void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
  259. {
  260. if (e.Reason == SessionSwitchReason.SessionLogon)
  261. {
  262. BrowserLauncher.OpenDashboard(_appHost, _logger);
  263. }
  264. }
  265. public static void Invoke(Action action)
  266. {
  267. _serverNotifyIcon.Invoke(action);
  268. }
  269. /// <summary>
  270. /// Starts the service.
  271. /// </summary>
  272. private static void StartService(ILogManager logManager)
  273. {
  274. var service = new BackgroundService(logManager.GetLogger("Service"));
  275. service.Disposed += service_Disposed;
  276. ServiceBase.Run(service);
  277. }
  278. /// <summary>
  279. /// Handles the Disposed event of the service control.
  280. /// </summary>
  281. /// <param name="sender">The source of the event.</param>
  282. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  283. static void service_Disposed(object sender, EventArgs e)
  284. {
  285. ApplicationTaskCompletionSource.SetResult(true);
  286. OnServiceShutdown();
  287. }
  288. private static void OnServiceShutdown()
  289. {
  290. _logger.Info("Shutting down");
  291. DisposeAppHost();
  292. }
  293. /// <summary>
  294. /// Installs the service.
  295. /// </summary>
  296. private static void InstallService(string applicationPath, ILogger logger)
  297. {
  298. try
  299. {
  300. ManagedInstallerClass.InstallHelper(new[] { applicationPath });
  301. logger.Info("Service installation succeeded");
  302. }
  303. catch (Exception ex)
  304. {
  305. logger.ErrorException("Uninstall failed", ex);
  306. }
  307. }
  308. /// <summary>
  309. /// Uninstalls the service.
  310. /// </summary>
  311. private static void UninstallService(string applicationPath, ILogger logger)
  312. {
  313. try
  314. {
  315. ManagedInstallerClass.InstallHelper(new[] { "/u", applicationPath });
  316. logger.Info("Service uninstallation succeeded");
  317. }
  318. catch (Exception ex)
  319. {
  320. logger.ErrorException("Uninstall failed", ex);
  321. }
  322. }
  323. private static void RunServiceInstallationIfNeeded(string applicationPath)
  324. {
  325. var serviceName = BackgroundService.GetExistingServiceName();
  326. var ctl = ServiceController.GetServices().FirstOrDefault(s => s.ServiceName == serviceName);
  327. if (ctl == null)
  328. {
  329. RunServiceInstallation(applicationPath);
  330. }
  331. }
  332. /// <summary>
  333. /// Runs the service installation.
  334. /// </summary>
  335. private static void RunServiceInstallation(string applicationPath)
  336. {
  337. var startInfo = new ProcessStartInfo
  338. {
  339. FileName = applicationPath,
  340. Arguments = "-installservice",
  341. CreateNoWindow = true,
  342. WindowStyle = ProcessWindowStyle.Hidden,
  343. Verb = "runas",
  344. ErrorDialog = false
  345. };
  346. using (var process = Process.Start(startInfo))
  347. {
  348. process.WaitForExit();
  349. }
  350. }
  351. /// <summary>
  352. /// Runs the service uninstallation.
  353. /// </summary>
  354. private static void RunServiceUninstallation(string applicationPath)
  355. {
  356. var startInfo = new ProcessStartInfo
  357. {
  358. FileName = applicationPath,
  359. Arguments = "-uninstallservice",
  360. CreateNoWindow = true,
  361. WindowStyle = ProcessWindowStyle.Hidden,
  362. Verb = "runas",
  363. ErrorDialog = false
  364. };
  365. using (var process = Process.Start(startInfo))
  366. {
  367. process.WaitForExit();
  368. }
  369. }
  370. /// <summary>
  371. /// Handles the SessionEnding event of the SystemEvents control.
  372. /// </summary>
  373. /// <param name="sender">The source of the event.</param>
  374. /// <param name="e">The <see cref="SessionEndingEventArgs"/> instance containing the event data.</param>
  375. static void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e)
  376. {
  377. if (e.Reason == SessionEndReasons.SystemShutdown || !_isRunningAsService)
  378. {
  379. Shutdown();
  380. }
  381. }
  382. /// <summary>
  383. /// Handles the UnhandledException event of the CurrentDomain control.
  384. /// </summary>
  385. /// <param name="sender">The source of the event.</param>
  386. /// <param name="e">The <see cref="UnhandledExceptionEventArgs"/> instance containing the event data.</param>
  387. static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  388. {
  389. var exception = (Exception)e.ExceptionObject;
  390. new UnhandledExceptionWriter(_appHost.ServerConfigurationManager.ApplicationPaths, _logger, _appHost.LogManager).Log(exception);
  391. if (!_isRunningAsService)
  392. {
  393. MessageBox.Show("Unhandled exception: " + exception.Message);
  394. }
  395. if (!Debugger.IsAttached)
  396. {
  397. Environment.Exit(Marshal.GetHRForException(exception));
  398. }
  399. }
  400. /// <summary>
  401. /// Performs the update if needed.
  402. /// </summary>
  403. /// <param name="appPaths">The app paths.</param>
  404. /// <param name="logger">The logger.</param>
  405. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
  406. private static bool PerformUpdateIfNeeded(ServerApplicationPaths appPaths, ILogger logger)
  407. {
  408. // Look for the existence of an update archive
  409. var updateArchive = Path.Combine(appPaths.TempUpdatePath, "MBServer" + ".zip");
  410. if (File.Exists(updateArchive))
  411. {
  412. logger.Info("An update is available from {0}", updateArchive);
  413. // Update is there - execute update
  414. try
  415. {
  416. var serviceName = _isRunningAsService ? BackgroundService.GetExistingServiceName() : string.Empty;
  417. new ApplicationUpdater().UpdateApplication(appPaths, updateArchive, logger, serviceName);
  418. // And just let the app exit so it can update
  419. return true;
  420. }
  421. catch (Exception e)
  422. {
  423. logger.ErrorException("Error starting updater.", e);
  424. MessageBox.Show(string.Format("Error attempting to update application.\n\n{0}\n\n{1}", e.GetType().Name, e.Message));
  425. }
  426. }
  427. return false;
  428. }
  429. public static void Shutdown()
  430. {
  431. if (_isRunningAsService)
  432. {
  433. ShutdownWindowsService();
  434. }
  435. else
  436. {
  437. DisposeAppHost();
  438. ShutdownWindowsApplication();
  439. }
  440. }
  441. public static void Restart()
  442. {
  443. DisposeAppHost();
  444. if (!_isRunningAsService)
  445. {
  446. //_logger.Info("Hiding server notify icon");
  447. //_serverNotifyIcon.Visible = false;
  448. _logger.Info("Starting new instance");
  449. //Application.Restart();
  450. Process.Start(_appHost.ServerConfigurationManager.ApplicationPaths.ApplicationPath);
  451. ShutdownWindowsApplication();
  452. }
  453. }
  454. private static void DisposeAppHost()
  455. {
  456. if (!_appHostDisposed)
  457. {
  458. _logger.Info("Disposing app host");
  459. _appHostDisposed = true;
  460. _appHost.Dispose();
  461. }
  462. }
  463. private static void ShutdownWindowsApplication()
  464. {
  465. //_logger.Info("Calling Application.Exit");
  466. //Application.Exit();
  467. _logger.Info("Calling Environment.Exit");
  468. Environment.Exit(0);
  469. _logger.Info("Calling ApplicationTaskCompletionSource.SetResult");
  470. ApplicationTaskCompletionSource.SetResult(true);
  471. }
  472. private static void ShutdownWindowsService()
  473. {
  474. _logger.Info("Stopping background service");
  475. var service = new ServiceController(BackgroundService.GetExistingServiceName());
  476. service.Refresh();
  477. if (service.Status == ServiceControllerStatus.Running)
  478. {
  479. service.Stop();
  480. }
  481. }
  482. private static async Task InstallFrameworkV46IfNeeded(ILogger logger)
  483. {
  484. bool installFrameworkV46 = false;
  485. try
  486. {
  487. using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)
  488. .OpenSubKey("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full\\"))
  489. {
  490. if (ndpKey != null && ndpKey.GetValue("Release") != null)
  491. {
  492. if ((int)ndpKey.GetValue("Release") <= 393295)
  493. {
  494. //Found framework V4, but not yet V4.6
  495. installFrameworkV46 = true;
  496. }
  497. }
  498. else
  499. {
  500. //Nothing found in the registry for V4
  501. installFrameworkV46 = true;
  502. }
  503. }
  504. }
  505. catch (Exception ex)
  506. {
  507. logger.ErrorException("Error getting .NET Framework version", ex);
  508. }
  509. _logger.Info(".NET Framework 4.6 found: {0}", !installFrameworkV46);
  510. if (installFrameworkV46)
  511. {
  512. try
  513. {
  514. await InstallFrameworkV46().ConfigureAwait(false);
  515. }
  516. catch (Exception ex)
  517. {
  518. logger.ErrorException("Error installing .NET Framework version 4.6", ex);
  519. }
  520. }
  521. }
  522. private static async Task InstallFrameworkV46()
  523. {
  524. var httpClient = _appHost.HttpClient;
  525. var tmp = await httpClient.GetTempFile(new HttpRequestOptions
  526. {
  527. Url = "https://github.com/MediaBrowser/Emby.Resources/raw/master/netframeworkV46/NDP46-KB3045560-Web.exe",
  528. Progress = new Progress<double>()
  529. }).ConfigureAwait(false);
  530. var exePath = Path.ChangeExtension(tmp, ".exe");
  531. File.Copy(tmp, exePath);
  532. var startInfo = new ProcessStartInfo
  533. {
  534. FileName = exePath,
  535. CreateNoWindow = true,
  536. WindowStyle = ProcessWindowStyle.Hidden,
  537. Verb = "runas",
  538. ErrorDialog = false,
  539. Arguments = "/q /norestart"
  540. };
  541. _logger.Info("Running {0}", startInfo.FileName);
  542. using (var process = Process.Start(startInfo))
  543. {
  544. process.WaitForExit();
  545. //process.ExitCode
  546. /*
  547. 0 --> Installation completed successfully.
  548. 1602 --> The user canceled installation.
  549. 1603 --> A fatal error occurred during installation.
  550. 1641 --> A restart is required to complete the installation. This message indicates success.
  551. 3010 --> A restart is required to complete the installation. This message indicates success.
  552. 5100 --> The user's computer does not meet system requirements.
  553. */
  554. }
  555. }
  556. private static async Task InstallVcredistIfNeeded(ApplicationHost appHost, ILogger logger)
  557. {
  558. try
  559. {
  560. var version = ImageMagickEncoder.GetVersion();
  561. return;
  562. }
  563. catch (Exception ex)
  564. {
  565. logger.ErrorException("Error loading ImageMagick", ex);
  566. }
  567. try
  568. {
  569. await InstallVcredist().ConfigureAwait(false);
  570. }
  571. catch (Exception ex)
  572. {
  573. logger.ErrorException("Error installing Visual Studio C++ runtime", ex);
  574. }
  575. }
  576. private async static Task InstallVcredist()
  577. {
  578. var httpClient = _appHost.HttpClient;
  579. var tmp = await httpClient.GetTempFile(new HttpRequestOptions
  580. {
  581. Url = GetVcredistUrl(),
  582. Progress = new Progress<double>()
  583. }).ConfigureAwait(false);
  584. var exePath = Path.ChangeExtension(tmp, ".exe");
  585. File.Copy(tmp, exePath);
  586. var startInfo = new ProcessStartInfo
  587. {
  588. FileName = exePath,
  589. CreateNoWindow = true,
  590. WindowStyle = ProcessWindowStyle.Hidden,
  591. Verb = "runas",
  592. ErrorDialog = false
  593. };
  594. _logger.Info("Running {0}", startInfo.FileName);
  595. using (var process = Process.Start(startInfo))
  596. {
  597. process.WaitForExit();
  598. }
  599. }
  600. private static string GetVcredistUrl()
  601. {
  602. if (Environment.Is64BitProcess)
  603. {
  604. return "https://github.com/MediaBrowser/Emby.Resources/raw/master/vcredist2013/vcredist_x64.exe";
  605. }
  606. // TODO: ARM url - https://github.com/MediaBrowser/Emby.Resources/raw/master/vcredist2013/vcredist_arm.exe
  607. return "https://github.com/MediaBrowser/Emby.Resources/raw/master/vcredist2013/vcredist_x86.exe";
  608. }
  609. /// <summary>
  610. /// Sets the error mode.
  611. /// </summary>
  612. /// <param name="uMode">The u mode.</param>
  613. /// <returns>ErrorModes.</returns>
  614. [DllImport("kernel32.dll")]
  615. static extern ErrorModes SetErrorMode(ErrorModes uMode);
  616. /// <summary>
  617. /// Enum ErrorModes
  618. /// </summary>
  619. [Flags]
  620. public enum ErrorModes : uint
  621. {
  622. /// <summary>
  623. /// The SYSTE m_ DEFAULT
  624. /// </summary>
  625. SYSTEM_DEFAULT = 0x0,
  626. /// <summary>
  627. /// The SE m_ FAILCRITICALERRORS
  628. /// </summary>
  629. SEM_FAILCRITICALERRORS = 0x0001,
  630. /// <summary>
  631. /// The SE m_ NOALIGNMENTFAULTEXCEPT
  632. /// </summary>
  633. SEM_NOALIGNMENTFAULTEXCEPT = 0x0004,
  634. /// <summary>
  635. /// The SE m_ NOGPFAULTERRORBOX
  636. /// </summary>
  637. SEM_NOGPFAULTERRORBOX = 0x0002,
  638. /// <summary>
  639. /// The SE m_ NOOPENFILEERRORBOX
  640. /// </summary>
  641. SEM_NOOPENFILEERRORBOX = 0x8000
  642. }
  643. }
  644. }