2014-02-10 11:39:41 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-07-01 11:17:55 -07:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2013-10-28 07:56:57 -07:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2013-10-01 11:24:27 -07:00
|
|
|
|
using System.Collections.Generic;
|
2013-07-01 11:17:55 -07:00
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.IO;
|
2013-08-13 07:51:26 -07:00
|
|
|
|
using System.Security;
|
2013-07-01 11:17:55 -07:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Providers.Savers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Saves game.xml for games
|
|
|
|
|
/// </summary>
|
2014-02-02 09:59:14 -07:00
|
|
|
|
public class GameXmlSaver : IMetadataFileSaver
|
2013-07-01 11:17:55 -07:00
|
|
|
|
{
|
2014-02-02 06:36:31 -07:00
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2014-02-02 22:35:43 -07:00
|
|
|
|
return "Media Browser Xml";
|
2014-02-02 06:36:31 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-01 11:17:55 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Determines whether [is enabled for] [the specified item].
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="updateType">Type of the update.</param>
|
|
|
|
|
/// <returns><c>true</c> if [is enabled for] [the specified item]; otherwise, <c>false</c>.</returns>
|
2014-02-02 06:36:31 -07:00
|
|
|
|
public 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Saves the specified item.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
|
/// <returns>Task.</returns>
|
2014-02-02 06:36:31 -07:00
|
|
|
|
public void Save(IHasMetadata item, CancellationToken cancellationToken)
|
2013-07-01 11:17:55 -07:00
|
|
|
|
{
|
|
|
|
|
var builder = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
builder.Append("<Item>");
|
|
|
|
|
|
2013-07-01 11:27:19 -07:00
|
|
|
|
var game = (Game)item;
|
|
|
|
|
|
|
|
|
|
if (game.PlayersSupported.HasValue)
|
|
|
|
|
{
|
|
|
|
|
builder.Append("<Players>" + SecurityElement.Escape(game.PlayersSupported.Value.ToString(UsCulture)) + "</Players>");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(game.GameSystem))
|
|
|
|
|
{
|
2013-09-25 08:11:23 -07:00
|
|
|
|
builder.Append("<GameSystem>" + SecurityElement.Escape(game.GameSystem) + "</GameSystem>");
|
2013-07-01 11:27:19 -07:00
|
|
|
|
}
|
2013-10-02 07:14:10 -07:00
|
|
|
|
|
2013-10-28 07:56:57 -07:00
|
|
|
|
var val = game.GetProviderId(MetadataProviders.NesBox);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(val))
|
|
|
|
|
{
|
|
|
|
|
builder.Append("<NesBox>" + SecurityElement.Escape(val) + "</NesBox>");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val = game.GetProviderId(MetadataProviders.NesBoxRom);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(val))
|
|
|
|
|
{
|
|
|
|
|
builder.Append("<NesBoxRom>" + SecurityElement.Escape(val) + "</NesBoxRom>");
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-02 06:36:31 -07:00
|
|
|
|
XmlSaverHelpers.AddCommonNodes(game, builder);
|
2013-07-01 11:17:55 -07:00
|
|
|
|
|
|
|
|
|
builder.Append("</Item>");
|
|
|
|
|
|
|
|
|
|
var xmlFilePath = GetSavePath(item);
|
|
|
|
|
|
2013-09-25 08:11:23 -07:00
|
|
|
|
XmlSaverHelpers.Save(builder, xmlFilePath, new List<string>
|
2013-07-01 11:17:55 -07:00
|
|
|
|
{
|
2013-07-01 11:27:19 -07:00
|
|
|
|
"Players",
|
2013-10-28 07:56:57 -07:00
|
|
|
|
"GameSystem",
|
|
|
|
|
"NesBox",
|
|
|
|
|
"NesBoxRom"
|
2013-07-01 11:17:55 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-02 06:36:31 -07:00
|
|
|
|
public string GetSavePath(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
|
|
|
|
}
|
|
|
|
|
|
2014-02-02 06:36:31 -07:00
|
|
|
|
public static string GetGameSavePath(Game item)
|
2013-10-01 11:24:27 -07:00
|
|
|
|
{
|
|
|
|
|
if (item.IsInMixedFolder)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|