2
0

MainStartup.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  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.Management;
  16. using System.Runtime.InteropServices;
  17. using System.ServiceProcess;
  18. using System.Threading;
  19. using System.Threading.Tasks;
  20. using System.Windows.Forms;
  21. using CommonIO.Windows;
  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 Emby 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 duplicate = Process.GetProcesses().FirstOrDefault(i =>
  111. {
  112. try
  113. {
  114. if (currentProcess.Id == i.Id)
  115. {
  116. return false;
  117. }
  118. }
  119. catch (Exception)
  120. {
  121. return false;
  122. }
  123. try
  124. {
  125. //_logger.Info("Module: {0}", i.MainModule.FileName);
  126. if (string.Equals(applicationPath, i.MainModule.FileName, StringComparison.OrdinalIgnoreCase))
  127. {
  128. return true;
  129. }
  130. return false;
  131. }
  132. catch (Exception)
  133. {
  134. return false;
  135. }
  136. });
  137. if (duplicate != null)
  138. {
  139. _logger.Info("Found a duplicate process. Giving it time to exit.");
  140. if (!duplicate.WaitForExit(20000))
  141. {
  142. _logger.Info("The duplicate process did not exit.");
  143. return true;
  144. }
  145. }
  146. if (!_isRunningAsService)
  147. {
  148. return IsAlreadyRunningAsService(applicationPath);
  149. }
  150. return false;
  151. }
  152. private static bool IsAlreadyRunningAsService(string applicationPath)
  153. {
  154. var serviceName = BackgroundService.GetExistingServiceName();
  155. WqlObjectQuery wqlObjectQuery = new WqlObjectQuery(string.Format("SELECT * FROM Win32_Service WHERE State = 'Running' AND Name = '{0}'", serviceName));
  156. ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(wqlObjectQuery);
  157. ManagementObjectCollection managementObjectCollection = managementObjectSearcher.Get();
  158. foreach (ManagementObject managementObject in managementObjectCollection)
  159. {
  160. var obj = managementObject.GetPropertyValue("PathName");
  161. if (obj == null)
  162. {
  163. continue;
  164. }
  165. var path = obj.ToString();
  166. _logger.Info("Service path: {0}", path);
  167. // Need to use indexOf instead of equality because the path will have the full service command line
  168. if (path.IndexOf(applicationPath, StringComparison.OrdinalIgnoreCase) != -1)
  169. {
  170. _logger.Info("The windows service is already running");
  171. MessageBox.Show("Emby Server is already running as a Windows Service. Only one instance is allowed at a time. To run as a tray icon, shut down the Windows Service.");
  172. return true;
  173. }
  174. }
  175. return false;
  176. }
  177. /// <summary>
  178. /// Creates the application paths.
  179. /// </summary>
  180. /// <param name="applicationPath">The application path.</param>
  181. /// <param name="runAsService">if set to <c>true</c> [run as service].</param>
  182. /// <returns>ServerApplicationPaths.</returns>
  183. private static ServerApplicationPaths CreateApplicationPaths(string applicationPath, bool runAsService)
  184. {
  185. var resourcesPath = Path.GetDirectoryName(applicationPath);
  186. if (runAsService)
  187. {
  188. var systemPath = Path.GetDirectoryName(applicationPath);
  189. var programDataPath = Path.GetDirectoryName(systemPath);
  190. return new ServerApplicationPaths(programDataPath, applicationPath, resourcesPath);
  191. }
  192. return new ServerApplicationPaths(ApplicationPathHelper.GetProgramDataPath(applicationPath), applicationPath, resourcesPath);
  193. }
  194. /// <summary>
  195. /// Gets a value indicating whether this instance can self restart.
  196. /// </summary>
  197. /// <value><c>true</c> if this instance can self restart; otherwise, <c>false</c>.</value>
  198. public static bool CanSelfRestart
  199. {
  200. get
  201. {
  202. return !_isRunningAsService;
  203. }
  204. }
  205. /// <summary>
  206. /// Gets a value indicating whether this instance can self update.
  207. /// </summary>
  208. /// <value><c>true</c> if this instance can self update; otherwise, <c>false</c>.</value>
  209. public static bool CanSelfUpdate
  210. {
  211. get
  212. {
  213. return !_isRunningAsService;
  214. }
  215. }
  216. private static readonly TaskCompletionSource<bool> ApplicationTaskCompletionSource = new TaskCompletionSource<bool>();
  217. /// <summary>
  218. /// Runs the application.
  219. /// </summary>
  220. /// <param name="appPaths">The app paths.</param>
  221. /// <param name="logManager">The log manager.</param>
  222. /// <param name="runService">if set to <c>true</c> [run service].</param>
  223. /// <param name="options">The options.</param>
  224. private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager, bool runService, StartupOptions options)
  225. {
  226. var fileSystem = new WindowsFileSystem(new PatternsLogger(logManager.GetLogger("FileSystem")));
  227. fileSystem.AddShortcutHandler(new MbLinkShortcutHandler(fileSystem));
  228. //fileSystem.AddShortcutHandler(new LnkShortcutHandler(fileSystem));
  229. var nativeApp = new WindowsApp(fileSystem, _logger)
  230. {
  231. IsRunningAsService = runService
  232. };
  233. _appHost = new ApplicationHost(appPaths,
  234. logManager,
  235. options,
  236. fileSystem,
  237. "emby.windows.zip",
  238. nativeApp);
  239. var initProgress = new Progress<double>();
  240. if (!runService)
  241. {
  242. if (!options.ContainsOption("-nosplash")) ShowSplashScreen(_appHost.ApplicationVersion, initProgress, logManager.GetLogger("Splash"));
  243. // Not crazy about this but it's the only way to suppress ffmpeg crash dialog boxes
  244. SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS | ErrorModes.SEM_NOALIGNMENTFAULTEXCEPT |
  245. ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_NOOPENFILEERRORBOX);
  246. }
  247. var task = _appHost.Init(initProgress);
  248. Task.WaitAll(task);
  249. task = task.ContinueWith(new Action<Task>(a => _appHost.RunStartupTasks()), TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.AttachedToParent);
  250. if (runService)
  251. {
  252. StartService(logManager);
  253. }
  254. else
  255. {
  256. Task.WaitAll(task);
  257. task = InstallVcredist2013IfNeeded(_appHost, _logger);
  258. Task.WaitAll(task);
  259. SystemEvents.SessionEnding += SystemEvents_SessionEnding;
  260. SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;
  261. HideSplashScreen();
  262. ShowTrayIcon();
  263. task = ApplicationTaskCompletionSource.Task;
  264. Task.WaitAll(task);
  265. }
  266. }
  267. private static ServerNotifyIcon _serverNotifyIcon;
  268. private static TaskScheduler _mainTaskScheduler;
  269. private static void ShowTrayIcon()
  270. {
  271. //Application.EnableVisualStyles();
  272. //Application.SetCompatibleTextRenderingDefault(false);
  273. _serverNotifyIcon = new ServerNotifyIcon(_appHost.LogManager, _appHost, _appHost.ServerConfigurationManager, _appHost.LocalizationManager);
  274. _mainTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext();
  275. Application.Run();
  276. }
  277. private static SplashForm _splash;
  278. private static Thread _splashThread;
  279. private static void ShowSplashScreen(Version appVersion, Progress<double> progress, ILogger logger)
  280. {
  281. var thread = new Thread(() =>
  282. {
  283. _splash = new SplashForm(appVersion, progress);
  284. _splash.ShowDialog();
  285. });
  286. thread.SetApartmentState(ApartmentState.STA);
  287. thread.IsBackground = true;
  288. thread.Start();
  289. _splashThread = thread;
  290. }
  291. private static void HideSplashScreen()
  292. {
  293. if (_splash != null)
  294. {
  295. Action act = () =>
  296. {
  297. _splash.Close();
  298. _splashThread = null;
  299. };
  300. _splash.Invoke(act);
  301. }
  302. }
  303. static void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
  304. {
  305. if (e.Reason == SessionSwitchReason.SessionLogon)
  306. {
  307. BrowserLauncher.OpenDashboard(_appHost);
  308. }
  309. }
  310. public static void Invoke(Action action)
  311. {
  312. if (_isRunningAsService)
  313. {
  314. action();
  315. }
  316. else
  317. {
  318. Task.Factory.StartNew(action, CancellationToken.None, TaskCreationOptions.None, _mainTaskScheduler ?? TaskScheduler.Current);
  319. }
  320. }
  321. /// <summary>
  322. /// Starts the service.
  323. /// </summary>
  324. private static void StartService(ILogManager logManager)
  325. {
  326. var service = new BackgroundService(logManager.GetLogger("Service"));
  327. service.Disposed += service_Disposed;
  328. ServiceBase.Run(service);
  329. }
  330. /// <summary>
  331. /// Handles the Disposed event of the service control.
  332. /// </summary>
  333. /// <param name="sender">The source of the event.</param>
  334. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  335. static void service_Disposed(object sender, EventArgs e)
  336. {
  337. ApplicationTaskCompletionSource.SetResult(true);
  338. OnServiceShutdown();
  339. }
  340. private static void OnServiceShutdown()
  341. {
  342. _logger.Info("Shutting down");
  343. DisposeAppHost();
  344. }
  345. /// <summary>
  346. /// Installs the service.
  347. /// </summary>
  348. private static void InstallService(string applicationPath, ILogger logger)
  349. {
  350. try
  351. {
  352. ManagedInstallerClass.InstallHelper(new[] { applicationPath });
  353. logger.Info("Service installation succeeded");
  354. }
  355. catch (Exception ex)
  356. {
  357. logger.ErrorException("Uninstall failed", ex);
  358. }
  359. }
  360. /// <summary>
  361. /// Uninstalls the service.
  362. /// </summary>
  363. private static void UninstallService(string applicationPath, ILogger logger)
  364. {
  365. try
  366. {
  367. ManagedInstallerClass.InstallHelper(new[] { "/u", applicationPath });
  368. logger.Info("Service uninstallation succeeded");
  369. }
  370. catch (Exception ex)
  371. {
  372. logger.ErrorException("Uninstall failed", ex);
  373. }
  374. }
  375. private static void RunServiceInstallationIfNeeded(string applicationPath)
  376. {
  377. var serviceName = BackgroundService.GetExistingServiceName();
  378. var ctl = ServiceController.GetServices().FirstOrDefault(s => s.ServiceName == serviceName);
  379. if (ctl == null)
  380. {
  381. RunServiceInstallation(applicationPath);
  382. }
  383. }
  384. /// <summary>
  385. /// Runs the service installation.
  386. /// </summary>
  387. private static void RunServiceInstallation(string applicationPath)
  388. {
  389. var startInfo = new ProcessStartInfo
  390. {
  391. FileName = applicationPath,
  392. Arguments = "-installservice",
  393. CreateNoWindow = true,
  394. WindowStyle = ProcessWindowStyle.Hidden,
  395. Verb = "runas",
  396. ErrorDialog = false
  397. };
  398. using (var process = Process.Start(startInfo))
  399. {
  400. process.WaitForExit();
  401. }
  402. }
  403. /// <summary>
  404. /// Runs the service uninstallation.
  405. /// </summary>
  406. private static void RunServiceUninstallation(string applicationPath)
  407. {
  408. var startInfo = new ProcessStartInfo
  409. {
  410. FileName = applicationPath,
  411. Arguments = "-uninstallservice",
  412. CreateNoWindow = true,
  413. WindowStyle = ProcessWindowStyle.Hidden,
  414. Verb = "runas",
  415. ErrorDialog = false
  416. };
  417. using (var process = Process.Start(startInfo))
  418. {
  419. process.WaitForExit();
  420. }
  421. }
  422. /// <summary>
  423. /// Handles the SessionEnding event of the SystemEvents control.
  424. /// </summary>
  425. /// <param name="sender">The source of the event.</param>
  426. /// <param name="e">The <see cref="SessionEndingEventArgs"/> instance containing the event data.</param>
  427. static void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e)
  428. {
  429. if (e.Reason == SessionEndReasons.SystemShutdown || !_isRunningAsService)
  430. {
  431. Shutdown();
  432. }
  433. }
  434. /// <summary>
  435. /// Handles the UnhandledException event of the CurrentDomain control.
  436. /// </summary>
  437. /// <param name="sender">The source of the event.</param>
  438. /// <param name="e">The <see cref="UnhandledExceptionEventArgs"/> instance containing the event data.</param>
  439. static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  440. {
  441. var exception = (Exception)e.ExceptionObject;
  442. new UnhandledExceptionWriter(_appHost.ServerConfigurationManager.ApplicationPaths, _logger, _appHost.LogManager).Log(exception);
  443. if (!_isRunningAsService)
  444. {
  445. MessageBox.Show("Unhandled exception: " + exception.Message);
  446. }
  447. if (!Debugger.IsAttached)
  448. {
  449. Environment.Exit(Marshal.GetHRForException(exception));
  450. }
  451. }
  452. /// <summary>
  453. /// Performs the update if needed.
  454. /// </summary>
  455. /// <param name="appPaths">The app paths.</param>
  456. /// <param name="logger">The logger.</param>
  457. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
  458. private static bool PerformUpdateIfNeeded(ServerApplicationPaths appPaths, ILogger logger)
  459. {
  460. // Look for the existence of an update archive
  461. var updateArchive = Path.Combine(appPaths.TempUpdatePath, "MBServer" + ".zip");
  462. if (File.Exists(updateArchive))
  463. {
  464. logger.Info("An update is available from {0}", updateArchive);
  465. // Update is there - execute update
  466. try
  467. {
  468. var serviceName = _isRunningAsService ? BackgroundService.GetExistingServiceName() : string.Empty;
  469. new ApplicationUpdater().UpdateApplication(appPaths, updateArchive, logger, serviceName);
  470. // And just let the app exit so it can update
  471. return true;
  472. }
  473. catch (Exception e)
  474. {
  475. logger.ErrorException("Error starting updater.", e);
  476. MessageBox.Show(string.Format("Error attempting to update application.\n\n{0}\n\n{1}", e.GetType().Name, e.Message));
  477. }
  478. }
  479. return false;
  480. }
  481. public static void Shutdown()
  482. {
  483. if (_isRunningAsService)
  484. {
  485. ShutdownWindowsService();
  486. }
  487. else
  488. {
  489. DisposeAppHost();
  490. ShutdownWindowsApplication();
  491. }
  492. }
  493. public static void Restart()
  494. {
  495. DisposeAppHost();
  496. if (!_isRunningAsService)
  497. {
  498. //_logger.Info("Hiding server notify icon");
  499. //_serverNotifyIcon.Visible = false;
  500. _logger.Info("Starting new instance");
  501. //Application.Restart();
  502. Process.Start(_appHost.ServerConfigurationManager.ApplicationPaths.ApplicationPath);
  503. ShutdownWindowsApplication();
  504. }
  505. }
  506. private static void DisposeAppHost()
  507. {
  508. if (!_appHostDisposed)
  509. {
  510. _logger.Info("Disposing app host");
  511. _appHostDisposed = true;
  512. _appHost.Dispose();
  513. }
  514. }
  515. private static void ShutdownWindowsApplication()
  516. {
  517. if (_serverNotifyIcon != null)
  518. {
  519. _serverNotifyIcon.Dispose();
  520. _serverNotifyIcon = null;
  521. }
  522. //_logger.Info("Calling Application.Exit");
  523. //Application.Exit();
  524. _logger.Info("Calling Environment.Exit");
  525. Environment.Exit(0);
  526. _logger.Info("Calling ApplicationTaskCompletionSource.SetResult");
  527. ApplicationTaskCompletionSource.SetResult(true);
  528. }
  529. private static void ShutdownWindowsService()
  530. {
  531. _logger.Info("Stopping background service");
  532. var service = new ServiceController(BackgroundService.GetExistingServiceName());
  533. service.Refresh();
  534. if (service.Status == ServiceControllerStatus.Running)
  535. {
  536. service.Stop();
  537. }
  538. }
  539. private static async Task InstallVcredist2013IfNeeded(ApplicationHost appHost, ILogger logger)
  540. {
  541. // Reference
  542. // http://stackoverflow.com/questions/12206314/detect-if-visual-c-redistributable-for-visual-studio-2012-is-installed
  543. try
  544. {
  545. var subkey = Environment.Is64BitProcess
  546. ? "SOFTWARE\\WOW6432Node\\Microsoft\\VisualStudio\\12.0\\VC\\Runtimes\\x64"
  547. : "SOFTWARE\\Microsoft\\VisualStudio\\12.0\\VC\\Runtimes\\x86";
  548. using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default)
  549. .OpenSubKey(subkey))
  550. {
  551. if (ndpKey != null && ndpKey.GetValue("Version") != null)
  552. {
  553. var installedVersion = ((string)ndpKey.GetValue("Version")).TrimStart('v');
  554. if (installedVersion.StartsWith("12", StringComparison.OrdinalIgnoreCase))
  555. {
  556. return;
  557. }
  558. }
  559. }
  560. }
  561. catch (Exception ex)
  562. {
  563. logger.ErrorException("Error getting .NET Framework version", ex);
  564. return;
  565. }
  566. try
  567. {
  568. await InstallVcredist2013().ConfigureAwait(false);
  569. }
  570. catch (Exception ex)
  571. {
  572. logger.ErrorException("Error installing Visual Studio C++ runtime", ex);
  573. }
  574. }
  575. private async static Task InstallVcredist2013()
  576. {
  577. var httpClient = _appHost.HttpClient;
  578. var tmp = await httpClient.GetTempFile(new HttpRequestOptions
  579. {
  580. Url = GetVcredist2013Url(),
  581. Progress = new Progress<double>()
  582. }).ConfigureAwait(false);
  583. var exePath = Path.ChangeExtension(tmp, ".exe");
  584. File.Copy(tmp, exePath);
  585. var startInfo = new ProcessStartInfo
  586. {
  587. FileName = exePath,
  588. CreateNoWindow = true,
  589. WindowStyle = ProcessWindowStyle.Hidden,
  590. Verb = "runas",
  591. ErrorDialog = false
  592. };
  593. _logger.Info("Running {0}", startInfo.FileName);
  594. using (var process = Process.Start(startInfo))
  595. {
  596. process.WaitForExit();
  597. }
  598. }
  599. private static string GetVcredist2013Url()
  600. {
  601. if (Environment.Is64BitProcess)
  602. {
  603. return "https://github.com/MediaBrowser/Emby.Resources/raw/master/vcredist2013/vcredist_x64.exe";
  604. }
  605. // TODO: ARM url - https://github.com/MediaBrowser/Emby.Resources/raw/master/vcredist2013/vcredist_arm.exe
  606. return "https://github.com/MediaBrowser/Emby.Resources/raw/master/vcredist2013/vcredist_x86.exe";
  607. }
  608. /// <summary>
  609. /// Sets the error mode.
  610. /// </summary>
  611. /// <param name="uMode">The u mode.</param>
  612. /// <returns>ErrorModes.</returns>
  613. [DllImport("kernel32.dll")]
  614. static extern ErrorModes SetErrorMode(ErrorModes uMode);
  615. /// <summary>
  616. /// Enum ErrorModes
  617. /// </summary>
  618. [Flags]
  619. public enum ErrorModes : uint
  620. {
  621. /// <summary>
  622. /// The SYSTE m_ DEFAULT
  623. /// </summary>
  624. SYSTEM_DEFAULT = 0x0,
  625. /// <summary>
  626. /// The SE m_ FAILCRITICALERRORS
  627. /// </summary>
  628. SEM_FAILCRITICALERRORS = 0x0001,
  629. /// <summary>
  630. /// The SE m_ NOALIGNMENTFAULTEXCEPT
  631. /// </summary>
  632. SEM_NOALIGNMENTFAULTEXCEPT = 0x0004,
  633. /// <summary>
  634. /// The SE m_ NOGPFAULTERRORBOX
  635. /// </summary>
  636. SEM_NOGPFAULTERRORBOX = 0x0002,
  637. /// <summary>
  638. /// The SE m_ NOOPENFILEERRORBOX
  639. /// </summary>
  640. SEM_NOOPENFILEERRORBOX = 0x8000
  641. }
  642. }
  643. }