diff options
Diffstat (limited to 'MediaBrowser.Server.Startup.Common/Migrations')
5 files changed, 211 insertions, 0 deletions
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; + } + } +} |
