Correctly set game actions based on manifest after install
parent
c571058817
commit
6f6a7188ee
|
@ -41,6 +41,8 @@ namespace LANCommander.Playnite.Extension
|
||||||
};
|
};
|
||||||
|
|
||||||
InvokeOnInstalled(new GameInstalledEventArgs(installInfo));
|
InvokeOnInstalled(new GameInstalledEventArgs(installInfo));
|
||||||
|
|
||||||
|
Plugin.UpdateGamesFromManifest();
|
||||||
}
|
}
|
||||||
|
|
||||||
private string Download(LANCommander.SDK.Models.Game game)
|
private string Download(LANCommander.SDK.Models.Game game)
|
||||||
|
|
|
@ -37,33 +37,38 @@ namespace LANCommander.Playnite.Extension
|
||||||
|
|
||||||
public override IEnumerable<GameMetadata> GetGames(LibraryGetGamesArgs args)
|
public override IEnumerable<GameMetadata> GetGames(LibraryGetGamesArgs args)
|
||||||
{
|
{
|
||||||
|
var gameMetadata = new List<GameMetadata>();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var syncedGames = PlayniteApi.Database.Games;
|
|
||||||
|
|
||||||
var games = LANCommander
|
var games = LANCommander
|
||||||
.GetGames()
|
.GetGames()
|
||||||
.Where(g => g.Archives != null && g.Archives.Count() > 0)
|
.Where(g => g.Archives != null && g.Archives.Count() > 0);
|
||||||
.Select(g =>
|
|
||||||
{
|
|
||||||
return new GameMetadata()
|
|
||||||
{
|
|
||||||
IsInstalled = false,
|
|
||||||
Name = g.Title,
|
|
||||||
SortingName = g.SortTitle,
|
|
||||||
Description = g.Description,
|
|
||||||
GameId = g.Id.ToString(),
|
|
||||||
ReleaseDate = new ReleaseDate(g.ReleasedOn),
|
|
||||||
Version = g.Archives.OrderByDescending(a => a.CreatedOn).FirstOrDefault().Version,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
return games;
|
foreach (var game in games)
|
||||||
|
{
|
||||||
|
var existingGame = PlayniteApi.Database.Games.FirstOrDefault(g => g.GameId == game.Id.ToString() && g.PluginId == Id && g.IsInstalled);
|
||||||
|
|
||||||
|
var metadata = new GameMetadata()
|
||||||
|
{
|
||||||
|
IsInstalled = existingGame != null,
|
||||||
|
Name = game.Title,
|
||||||
|
SortingName = game.SortTitle,
|
||||||
|
Description = game.Description,
|
||||||
|
GameId = game.Id.ToString(),
|
||||||
|
ReleaseDate = new ReleaseDate(game.ReleasedOn),
|
||||||
|
Version = game.Archives.OrderByDescending(a => a.CreatedOn).FirstOrDefault().Version,
|
||||||
|
};
|
||||||
|
|
||||||
|
gameMetadata.Add(metadata);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return new List<GameMetadata>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return gameMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IEnumerable<InstallController> GetInstallActions(GetInstallActionsArgs args)
|
public override IEnumerable<InstallController> GetInstallActions(GetInstallActionsArgs args)
|
||||||
|
@ -157,42 +162,52 @@ namespace LANCommander.Playnite.Extension
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
private GameMetadata ParseManifest(string installDirectory)
|
public void UpdateGamesFromManifest()
|
||||||
{
|
{
|
||||||
var manifestContents = File.ReadAllText(Path.Combine(installDirectory, "_manifest.yml"));
|
var games = PlayniteApi.Database.Games;
|
||||||
var deserializer = new DeserializerBuilder()
|
|
||||||
.WithNamingConvention(PascalCaseNamingConvention.Instance)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
try
|
foreach (var game in games.Where(g => g.PluginId == Id && g.IsInstalled))
|
||||||
{
|
{
|
||||||
var manifest = deserializer.Deserialize<GameManifest>(manifestContents);
|
if (!Directory.Exists(game.InstallDirectory))
|
||||||
|
continue;
|
||||||
|
|
||||||
var metadata = new GameMetadata()
|
var manifestPath = Path.Combine(game.InstallDirectory, "_manifest.yml");
|
||||||
|
|
||||||
|
if (File.Exists(manifestPath))
|
||||||
{
|
{
|
||||||
Name = manifest.Title,
|
try
|
||||||
SortingName = manifest.SortTitle,
|
|
||||||
Description = manifest.Description,
|
|
||||||
ReleaseDate = new ReleaseDate(manifest.ReleasedOn),
|
|
||||||
Version = manifest.Version,
|
|
||||||
GameActions = manifest.Actions.Select(a =>
|
|
||||||
{
|
{
|
||||||
return new PN.SDK.Models.GameAction()
|
var manifestContents = File.ReadAllText(manifestPath);
|
||||||
{
|
var deserializer = new DeserializerBuilder()
|
||||||
Name = a.Name,
|
.WithNamingConvention(PascalCaseNamingConvention.Instance)
|
||||||
Arguments = a.Arguments,
|
.Build();
|
||||||
Path = a.Path,
|
|
||||||
WorkingDir = a.WorkingDirectory,
|
|
||||||
IsPlayAction = a.IsPrimaryAction
|
|
||||||
};
|
|
||||||
}).ToList()
|
|
||||||
};
|
|
||||||
|
|
||||||
return metadata;
|
var manifest = deserializer.Deserialize<GameManifest>(manifestContents);
|
||||||
}
|
|
||||||
catch
|
if (game.GameActions == null)
|
||||||
{
|
game.GameActions = new System.Collections.ObjectModel.ObservableCollection<PN.SDK.Models.GameAction>();
|
||||||
throw new FileNotFoundException("The manifest file is invalid or corrupt.");
|
|
||||||
|
foreach (var action in manifest.Actions)
|
||||||
|
{
|
||||||
|
bool isFirstAction = !manifest.Actions.Any(a => a.IsPrimaryAction) && manifest.Actions.First().Name == action.Name;
|
||||||
|
|
||||||
|
game.GameActions.AddMissing(new PN.SDK.Models.GameAction()
|
||||||
|
{
|
||||||
|
Name = action.Name,
|
||||||
|
Arguments = action.Arguments,
|
||||||
|
Path = PlayniteApi.ExpandGameVariables(game, action.Path),
|
||||||
|
WorkingDir = action.WorkingDirectory ?? game.InstallDirectory,
|
||||||
|
IsPlayAction = action.IsPrimaryAction || isFirstAction
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayniteApi.Database.Games.Update(game);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,8 @@ namespace LANCommander.Playnite.Extension
|
||||||
|
|
||||||
public override void Uninstall(UninstallActionArgs args)
|
public override void Uninstall(UninstallActionArgs args)
|
||||||
{
|
{
|
||||||
Directory.Delete(Game.InstallDirectory, true);
|
if (!String.IsNullOrWhiteSpace(Game.InstallDirectory) && Directory.Exists(Game.InstallDirectory))
|
||||||
|
Directory.Delete(Game.InstallDirectory, true);
|
||||||
|
|
||||||
InvokeOnUninstalled(new GameUninstalledEventArgs());
|
InvokeOnUninstalled(new GameUninstalledEventArgs());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue