2014-09-06 04:21:23 +00:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using System.Collections.Generic;
|
2013-07-01 18:17:55 +00:00
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.IO;
|
2016-10-29 20:02:21 +00:00
|
|
|
|
using System.Xml;
|
2016-10-25 19:02:04 +00:00
|
|
|
|
using MediaBrowser.Model.IO;
|
2016-10-29 20:02:21 +00:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using MediaBrowser.Model.Xml;
|
2013-07-01 18:17:55 +00:00
|
|
|
|
|
2014-06-30 03:04:50 +00:00
|
|
|
|
namespace MediaBrowser.LocalMetadata.Savers
|
2013-07-01 18:17:55 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Saves game.xml for games
|
|
|
|
|
/// </summary>
|
2016-10-29 20:02:21 +00:00
|
|
|
|
public class GameXmlSaver : BaseXmlSaver
|
2013-07-01 18:17:55 +00:00
|
|
|
|
{
|
2016-10-29 20:02:21 +00:00
|
|
|
|
private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
|
2015-06-21 03:35:22 +00:00
|
|
|
|
|
2016-10-29 20:02:21 +00:00
|
|
|
|
public override bool IsEnabledFor(IHasMetadata item, ItemUpdateType updateType)
|
2013-07-01 18:17:55 +00:00
|
|
|
|
{
|
2014-02-10 20:11:46 +00:00
|
|
|
|
if (!item.SupportsLocalMetadata)
|
2014-02-08 20:02:35 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-11 21:41:01 +00:00
|
|
|
|
return item is Game && updateType >= ItemUpdateType.MetadataDownload;
|
2013-07-01 18:17:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-29 20:02:21 +00:00
|
|
|
|
protected override List<string> GetTagsUsed()
|
2013-07-01 18:17:55 +00:00
|
|
|
|
{
|
2016-10-29 20:02:21 +00:00
|
|
|
|
var list = new List<string>
|
|
|
|
|
{
|
|
|
|
|
"GameSystem",
|
|
|
|
|
"Players"
|
|
|
|
|
};
|
2013-07-01 18:17:55 +00:00
|
|
|
|
|
2016-10-29 20:02:21 +00:00
|
|
|
|
return list;
|
|
|
|
|
}
|
2013-07-01 18:17:55 +00:00
|
|
|
|
|
2016-10-29 20:02:21 +00:00
|
|
|
|
protected override void WriteCustomElements(IHasMetadata item, XmlWriter writer)
|
|
|
|
|
{
|
2013-07-01 18:27:19 +00:00
|
|
|
|
var game = (Game)item;
|
|
|
|
|
|
2016-10-29 20:02:21 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(game.GameSystem))
|
2013-07-01 18:27:19 +00:00
|
|
|
|
{
|
2016-10-29 20:02:21 +00:00
|
|
|
|
writer.WriteElementString("GameSystem", game.GameSystem);
|
2013-07-01 18:27:19 +00:00
|
|
|
|
}
|
2016-10-29 20:02:21 +00:00
|
|
|
|
if (game.PlayersSupported.HasValue)
|
2013-07-01 18:27:19 +00:00
|
|
|
|
{
|
2016-10-29 20:02:21 +00:00
|
|
|
|
writer.WriteElementString("Players", game.PlayersSupported.Value.ToString(UsCulture));
|
2013-07-01 18:27:19 +00:00
|
|
|
|
}
|
2013-07-01 18:17:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-29 20:02:21 +00:00
|
|
|
|
protected override string GetLocalSavePath(IHasMetadata item)
|
2013-07-01 18:17:55 +00:00
|
|
|
|
{
|
2014-02-02 13:36:31 +00:00
|
|
|
|
return GetGameSavePath((Game)item);
|
2013-10-01 18:24:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-29 20:02:21 +00:00
|
|
|
|
protected override string GetRootElementName(IHasMetadata item)
|
|
|
|
|
{
|
|
|
|
|
return "Item";
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-02 13:36:31 +00:00
|
|
|
|
public static string GetGameSavePath(Game item)
|
2013-10-01 18:24:27 +00:00
|
|
|
|
{
|
2017-07-31 05:16:22 +00:00
|
|
|
|
if (item.IsInMixedFolder)
|
2013-10-01 18:24:27 +00:00
|
|
|
|
{
|
|
|
|
|
return Path.ChangeExtension(item.Path, ".xml");
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-06 04:39:16 +00:00
|
|
|
|
return Path.Combine(item.ContainingFolderPath, "game.xml");
|
2013-07-01 18:17:55 +00:00
|
|
|
|
}
|
2016-10-29 20:02:21 +00:00
|
|
|
|
|
|
|
|
|
public GameXmlSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger, xmlReaderSettingsFactory)
|
|
|
|
|
{
|
|
|
|
|
}
|
2013-07-01 18:17:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|