CoreAppHost.cs 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System.Collections.Generic;
  2. using System.Reflection;
  3. using Emby.Server.Implementations;
  4. using MediaBrowser.Common.Net;
  5. using MediaBrowser.Controller.Drawing;
  6. using MediaBrowser.Model.IO;
  7. using Microsoft.Extensions.Configuration;
  8. using Microsoft.Extensions.Logging;
  9. namespace Jellyfin.Server
  10. {
  11. /// <summary>
  12. /// Implementation of the abstract <see cref="ApplicationHost" /> class.
  13. /// </summary>
  14. public class CoreAppHost : ApplicationHost
  15. {
  16. /// <summary>
  17. /// Initializes a new instance of the <see cref="CoreAppHost" /> class.
  18. /// </summary>
  19. /// <param name="applicationPaths">The <see cref="ServerApplicationPaths" /> to be used by the <see cref="CoreAppHost" />.</param>
  20. /// <param name="loggerFactory">The <see cref="ILoggerFactory" /> to be used by the <see cref="CoreAppHost" />.</param>
  21. /// <param name="options">The <see cref="StartupOptions" /> to be used by the <see cref="CoreAppHost" />.</param>
  22. /// <param name="fileSystem">The <see cref="IFileSystem" /> to be used by the <see cref="CoreAppHost" />.</param>
  23. /// <param name="imageEncoder">The <see cref="IImageEncoder" /> to be used by the <see cref="CoreAppHost" />.</param>
  24. /// <param name="networkManager">The <see cref="INetworkManager" /> to be used by the <see cref="CoreAppHost" />.</param>
  25. /// <param name="configuration">The <see cref="IConfiguration" /> to be used by the <see cref="CoreAppHost" />.</param>
  26. public CoreAppHost(
  27. ServerApplicationPaths applicationPaths,
  28. ILoggerFactory loggerFactory,
  29. StartupOptions options,
  30. IFileSystem fileSystem,
  31. IImageEncoder imageEncoder,
  32. INetworkManager networkManager,
  33. IConfiguration configuration)
  34. : base(
  35. applicationPaths,
  36. loggerFactory,
  37. options,
  38. fileSystem,
  39. imageEncoder,
  40. networkManager,
  41. configuration)
  42. {
  43. }
  44. /// <inheritdoc />
  45. public override bool CanSelfRestart => StartupOptions.RestartPath != null;
  46. /// <inheritdoc />
  47. protected override void RestartInternal() => Program.Restart();
  48. /// <inheritdoc />
  49. protected override IEnumerable<Assembly> GetAssembliesWithPartsInternal()
  50. {
  51. yield return typeof(CoreAppHost).Assembly;
  52. }
  53. /// <inheritdoc />
  54. protected override void ShutdownInternal() => Program.Shutdown();
  55. /// <summary>
  56. /// Runs the migration routines if necessary.
  57. /// </summary>
  58. public void TryMigrate()
  59. {
  60. var previousVersion = ConfigurationManager.CommonConfiguration.PreviousVersion;
  61. switch (ApplicationVersion.CompareTo(previousVersion))
  62. {
  63. case 1:
  64. Logger.LogWarning("Version check shows Jellyfin was updated: previous version={0}, current version={1}", previousVersion, ApplicationVersion);
  65. Migrations.Run(this, Logger);
  66. ConfigurationManager.CommonConfiguration.PreviousVersion = ApplicationVersion;
  67. ConfigurationManager.SaveConfiguration();
  68. break;
  69. case 0:
  70. // nothing to do, versions match
  71. break;
  72. case -1:
  73. Logger.LogWarning("Version check shows Jellyfin was rolled back, use at your own risk: previous version={0}, current version={1}", previousVersion, ApplicationVersion);
  74. // no "rollback" routines for now
  75. ConfigurationManager.CommonConfiguration.PreviousVersion = ApplicationVersion;
  76. ConfigurationManager.SaveConfiguration();
  77. break;
  78. }
  79. }
  80. }
  81. }