diff options
Diffstat (limited to 'MediaBrowser.Server.Startup.Common')
7 files changed, 221 insertions, 78 deletions
diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs index c321b4c09..d8358909e 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs +++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs @@ -82,6 +82,7 @@ using MediaBrowser.Server.Implementations.Sync; using MediaBrowser.Server.Implementations.Themes; using MediaBrowser.Server.Implementations.TV; using MediaBrowser.Server.Startup.Common.FFMpeg; +using MediaBrowser.Server.Startup.Common.Migrations; using MediaBrowser.WebDashboard.Api; using MediaBrowser.XbmcMetadata.Providers; using System; @@ -322,84 +323,10 @@ namespace MediaBrowser.Server.Startup.Common private void PerformVersionMigration() { - DeleteDeprecatedModules(); - - if (!ServerConfigurationManager.Configuration.PlaylistImagesDeleted) - { - DeletePlaylistImages(); - ServerConfigurationManager.Configuration.PlaylistImagesDeleted = true; - ServerConfigurationManager.SaveConfiguration(); - } - } - - private void DeletePlaylistImages() - { - try - { - var path = Path.Combine(ApplicationPaths.DataPath, "playlists"); - - var files = Directory.GetFiles(path, "*", SearchOption.AllDirectories) - .Where(i => BaseItem.SupportedImageExtensions.Contains(Path.GetExtension(i) ?? string.Empty)) - .ToList(); - - foreach (var file in files) - { - try - { - File.Delete(file); - } - catch (IOException) - { - - } - } - } - catch (IOException) - { - - } - } - - private void DeleteDeprecatedModules() - { - try - { - MigrateUserFolders(); - } - catch (IOException) - { - } - - try - { - File.Delete(Path.Combine(ApplicationPaths.PluginsPath, "MBPhoto.dll")); - } - catch (IOException) - { - // Not there, no big deal - } - - try - { - File.Delete(Path.Combine(ApplicationPaths.PluginsPath, "MediaBrowser.Plugins.XbmcMetadata.dll")); - } - catch (IOException) - { - // Not there, no big deal - } - } - - private void MigrateUserFolders() - { - var rootPath = ApplicationPaths.RootFolderPath; - - var folders = new DirectoryInfo(rootPath).EnumerateDirectories("*", SearchOption.TopDirectoryOnly).Where(i => !string.Equals(i.Name, "default", StringComparison.OrdinalIgnoreCase)) - .ToList(); - - foreach (var folder in folders) - { - Directory.Delete(folder.FullName, true); - } + new MigrateUserFolders(ApplicationPaths).Run(); + new PlaylistImages(ServerConfigurationManager).Run(); + new RenameXbmcOptions(ServerConfigurationManager).Run(); + new RenameXmlOptions(ServerConfigurationManager).Run(); } /// <summary> diff --git a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj index 3f04694b9..da0e896e6 100644 --- a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj +++ b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj @@ -60,6 +60,11 @@ <Compile Include="FFMpeg\FFMpegDownloadInfo.cs" /> <Compile Include="FFMpeg\FFMpegInfo.cs" /> <Compile Include="INativeApp.cs" /> + <Compile Include="Migrations\IVersionMigration.cs" /> + <Compile Include="Migrations\MigrateUserFolders.cs" /> + <Compile Include="Migrations\PlaylistImages.cs" /> + <Compile Include="Migrations\RenameXbmcOptions.cs" /> + <Compile Include="Migrations\RenameXmlOptions.cs" /> <Compile Include="NativeEnvironment.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="StartupOptions.cs" /> diff --git a/MediaBrowser.Server.Startup.Common/Migrations/IVersionMigration.cs b/MediaBrowser.Server.Startup.Common/Migrations/IVersionMigration.cs new file mode 100644 index 000000000..a6a8c1a35 --- /dev/null +++ b/MediaBrowser.Server.Startup.Common/Migrations/IVersionMigration.cs @@ -0,0 +1,8 @@ + +namespace MediaBrowser.Server.Startup.Common.Migrations +{ + public interface IVersionMigration + { + void Run(); + } +} diff --git a/MediaBrowser.Server.Startup.Common/Migrations/MigrateUserFolders.cs b/MediaBrowser.Server.Startup.Common/Migrations/MigrateUserFolders.cs new file mode 100644 index 000000000..5e3df5701 --- /dev/null +++ b/MediaBrowser.Server.Startup.Common/Migrations/MigrateUserFolders.cs @@ -0,0 +1,36 @@ +using MediaBrowser.Controller; +using System; +using System.IO; +using System.Linq; + +namespace MediaBrowser.Server.Startup.Common.Migrations +{ + public class MigrateUserFolders : IVersionMigration + { + private readonly IServerApplicationPaths _appPaths; + + public MigrateUserFolders(IServerApplicationPaths appPaths) + { + _appPaths = appPaths; + } + + public void Run() + { + try + { + var rootPath = _appPaths.RootFolderPath; + + var folders = new DirectoryInfo(rootPath).EnumerateDirectories("*", SearchOption.TopDirectoryOnly).Where(i => !string.Equals(i.Name, "default", StringComparison.OrdinalIgnoreCase)) + .ToList(); + + foreach (var folder in folders) + { + Directory.Delete(folder.FullName, true); + } + } + catch (IOException) + { + } + } + } +} diff --git a/MediaBrowser.Server.Startup.Common/Migrations/PlaylistImages.cs b/MediaBrowser.Server.Startup.Common/Migrations/PlaylistImages.cs new file mode 100644 index 000000000..f6ddf5847 --- /dev/null +++ b/MediaBrowser.Server.Startup.Common/Migrations/PlaylistImages.cs @@ -0,0 +1,55 @@ +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Entities; +using System.IO; +using System.Linq; + +namespace MediaBrowser.Server.Startup.Common.Migrations +{ + public class PlaylistImages : IVersionMigration + { + private readonly IServerConfigurationManager _config; + + public PlaylistImages(IServerConfigurationManager config) + { + _config = config; + } + + public void Run() + { + if (!_config.Configuration.PlaylistImagesDeleted) + { + DeletePlaylistImages(); + _config.Configuration.PlaylistImagesDeleted = true; + _config.SaveConfiguration(); + } + } + + private void DeletePlaylistImages() + { + try + { + var path = Path.Combine(_config.ApplicationPaths.DataPath, "playlists"); + + var files = Directory.GetFiles(path, "*", SearchOption.AllDirectories) + .Where(i => BaseItem.SupportedImageExtensions.Contains(Path.GetExtension(i) ?? string.Empty)) + .ToList(); + + foreach (var file in files) + { + try + { + File.Delete(file); + } + catch (IOException) + { + + } + } + } + catch (IOException) + { + + } + } + } +} diff --git a/MediaBrowser.Server.Startup.Common/Migrations/RenameXbmcOptions.cs b/MediaBrowser.Server.Startup.Common/Migrations/RenameXbmcOptions.cs new file mode 100644 index 000000000..efc34c1d8 --- /dev/null +++ b/MediaBrowser.Server.Startup.Common/Migrations/RenameXbmcOptions.cs @@ -0,0 +1,56 @@ +using MediaBrowser.Controller.Configuration; +using System; + +namespace MediaBrowser.Server.Startup.Common.Migrations +{ + public class RenameXbmcOptions + { + private readonly IServerConfigurationManager _config; + + public RenameXbmcOptions(IServerConfigurationManager config) + { + _config = config; + } + + public void Run() + { + var changed = false; + + foreach (var option in _config.Configuration.MetadataOptions) + { + if (Migrate(option.DisabledMetadataSavers)) + { + changed = true; + } + if (Migrate(option.LocalMetadataReaderOrder)) + { + changed = true; + } + } + + if (changed) + { + _config.SaveConfiguration(); + } + } + + private bool Migrate(string[] options) + { + var changed = false; + + if (options != null) + { + for (var i = 0; i < options.Length; i++) + { + if (string.Equals(options[i], "Xbmc Nfo", StringComparison.OrdinalIgnoreCase)) + { + options[i] = "Nfo"; + changed = true; + } + } + } + + return changed; + } + } +} diff --git a/MediaBrowser.Server.Startup.Common/Migrations/RenameXmlOptions.cs b/MediaBrowser.Server.Startup.Common/Migrations/RenameXmlOptions.cs new file mode 100644 index 000000000..3034fad31 --- /dev/null +++ b/MediaBrowser.Server.Startup.Common/Migrations/RenameXmlOptions.cs @@ -0,0 +1,56 @@ +using MediaBrowser.Controller.Configuration; +using System; + +namespace MediaBrowser.Server.Startup.Common.Migrations +{ + public class RenameXmlOptions + { + private readonly IServerConfigurationManager _config; + + public RenameXmlOptions(IServerConfigurationManager config) + { + _config = config; + } + + public void Run() + { + var changed = false; + + foreach (var option in _config.Configuration.MetadataOptions) + { + if (Migrate(option.DisabledMetadataSavers)) + { + changed = true; + } + if (Migrate(option.LocalMetadataReaderOrder)) + { + changed = true; + } + } + + if (changed) + { + _config.SaveConfiguration(); + } + } + + private bool Migrate(string[] options) + { + var changed = false; + + if (options != null) + { + for (var i = 0; i < options.Length; i++) + { + if (string.Equals(options[i], "Media Browser Xml", StringComparison.OrdinalIgnoreCase)) + { + options[i] = "Media Browser Legacy Xml"; + changed = true; + } + } + } + + return changed; + } + } +} |
