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