diff --git a/Appveyor.yml b/Appveyor.yml new file mode 100644 index 0000000..8a0811e --- /dev/null +++ b/Appveyor.yml @@ -0,0 +1,19 @@ +version: 1.0.{build} +image: Visual Studio 2017 +configuration: +- Release +- Repack +platform: Any CPU +before_build: +- cmd: nuget restore +build: + verbosity: minimal +artifacts: +- path: MamesaverDeploy\bin\Repack\Mamesaver.msi + name: Mamesaver.msi +- path: Mamesaver\bin\Repack\Mamesaver.scr + name: Mamesaver.scr +- path: Mamesaver\bin\Repack\*.dll + name: dlls +- path: Mamesaver\bin\Repack\Mamesaver.exe + name: repack exe \ No newline at end of file diff --git a/Mamesaver.Test/Mamesaver.Test.csproj b/Mamesaver.Test/Mamesaver.Test.csproj index 3248dca..61f72a6 100644 --- a/Mamesaver.Test/Mamesaver.Test.csproj +++ b/Mamesaver.Test/Mamesaver.Test.csproj @@ -18,6 +18,7 @@ UnitTest + PackageReference true diff --git a/Mamesaver.sln b/Mamesaver.sln index ca13fa2..17f3e5e 100644 --- a/Mamesaver.sln +++ b/Mamesaver.sln @@ -5,6 +5,7 @@ VisualStudioVersion = 15.0.27703.2042 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{45991C83-871A-4411-BA15-2A850C9EA855}" ProjectSection(SolutionItems) = preProject + Appveyor.yml = Appveyor.yml LICENCE.TXT = LICENCE.TXT README.md = README.md EndProjectSection diff --git a/Mamesaver/Mamesaver.csproj b/Mamesaver/Mamesaver.csproj index 6b7520f..449500b 100644 --- a/Mamesaver/Mamesaver.csproj +++ b/Mamesaver/Mamesaver.csproj @@ -58,6 +58,7 @@ false prompt MinimumRecommendedRules.ruleset + false diff --git a/Mamesaver/Properties/AssemblyInfo.cs b/Mamesaver/Properties/AssemblyInfo.cs index 0d0c0e1..ced263a 100644 --- a/Mamesaver/Properties/AssemblyInfo.cs +++ b/Mamesaver/Properties/AssemblyInfo.cs @@ -29,4 +29,4 @@ // Revision // [assembly: AssemblyVersion("3.0.*")] -[assembly: AssemblyFileVersion("3.0")] +[assembly: AssemblyFileVersion("3.0.1")] diff --git a/Mamesaver/Services/Mame/GameListBuilder.cs b/Mamesaver/Services/Mame/GameListBuilder.cs index 2a14ee8..2d1afad 100644 --- a/Mamesaver/Services/Mame/GameListBuilder.cs +++ b/Mamesaver/Services/Mame/GameListBuilder.cs @@ -24,7 +24,7 @@ public class GameListBuilder /// Number of ROMs to process per batch. Rom files are batched when passing as arguments to Mame both /// to minimise processing time and to allow a visual indicator that games are being processed. /// - private const int RomsPerBatch = 50; + private const int DefaultRomsPerBatch = 50; /// /// Settings for parsing MAME's listxml output @@ -57,9 +57,22 @@ public List GetGameList(Action progressCallback) var games = new List(); // Enrich game metadata for each verified game - var verifiedGames = GetVerifiedSets(progressCallback).Keys; + var verifiedGames = GetVerifiedSets(progressCallback).Keys.ToList(); var romFiles = GetRomFiles(); + try + { + return GetGameList(progressCallback, romFiles, verifiedGames, games, DefaultRomsPerBatch); + } + catch (XmlException) + { + // Fallback for old versions of MAME which don't support extracting game details for multiple games at a time + return GetGameList(progressCallback, romFiles, verifiedGames, games, 1); + } + } + + private List GetGameList(Action progressCallback, List romFiles, List verifiedGames, List games, int romsPerBatch) + { // Get details for each verified ROM var index = 0; @@ -68,14 +81,14 @@ public List GetGameList(Action progressCallback) var romsProcessed = romFiles.Count + (romFiles.Count - verifiedGames.Count); List romsToProcess; - while ((romsToProcess = verifiedGames.Skip(index).Take(RomsPerBatch).ToList()).Any()) + while ((romsToProcess = verifiedGames.Skip(index).Take(romsPerBatch).ToList()).Any()) { using (var stream = GetGameDetails(romsToProcess)) { games.AddRange(GetRomDetails(stream)); } - index += RomsPerBatch; + index += romsPerBatch; romsProcessed += romsToProcess.Count; // There are two distinct phases in the game list builder, so we are halving the processed count @@ -109,7 +122,7 @@ private List GetRomDetails(StreamReader stream, bool verify = tr reader.ReadStartElement("mame"); // Read each machine, enriching metadata for verified sets - while (reader.Read() && reader.Name == "machine") + while (reader.Read() && (reader.Name == "machine" || reader.Name == "game")) { // Read game metadata var element = (XElement)XNode.ReadFrom(reader); @@ -201,6 +214,16 @@ private static bool IsGameValid(XElement element, string name) /// are returned in the value of the dictionary while the name is used as the key. /// private IDictionary GetVerifiedSets(Action progressCallback) + { + var verifiedSets = GetVerifiedSets(progressCallback, DefaultRomsPerBatch); + if (verifiedSets.Any()) return verifiedSets; + + // Cater for old versions of MAME which only support verifying a single ROM at a time + verifiedSets = GetVerifiedSets(progressCallback, 1); + return verifiedSets; + } + + private IDictionary GetVerifiedSets(Action progressCallback, int romsPerBatch) { var verifiedRoms = new Dictionary(); var regex = new Regex(@"romset (\w*)(?:\s\[(\w*)\])? is good"); //only accept the "good" ROMS @@ -212,7 +235,7 @@ private IDictionary GetVerifiedSets(Action progressCallback var filesProcessed = 0; List filesToVerify; - while ((filesToVerify = romFiles.Skip(index).Take(RomsPerBatch).ToList()).Any()) + while ((filesToVerify = romFiles.Skip(index).Take(romsPerBatch).ToList()).Any()) { var arguments = new List { "-verifyroms" }.Concat(filesToVerify).ToArray(); using (var stream = _invoker.GetOutput(arguments)) @@ -227,7 +250,7 @@ private IDictionary GetVerifiedSets(Action progressCallback } } - index += RomsPerBatch; + index += romsPerBatch; filesProcessed += filesToVerify.Count; // There are two distinct phases in the game list builder, so we are halving the processed count diff --git a/Mamesaver/Services/Mame/MameInvoker.cs b/Mamesaver/Services/Mame/MameInvoker.cs index 7a1b6d7..fc2c375 100644 --- a/Mamesaver/Services/Mame/MameInvoker.cs +++ b/Mamesaver/Services/Mame/MameInvoker.cs @@ -120,9 +120,9 @@ public Process Run(bool start, params string[] arguments) /// Registers a MAME process for automatic termination on shutdown. /// /// - public void Register(Process process) => _processes.Add(process); + private void Register(Process process) => _processes.Add(process); - public virtual void Dispose(bool disposing) + protected virtual void Dispose(bool disposing) { if (!disposing) return; TryStopProcesses(); diff --git a/README.md b/README.md index 5f0b4ce..d1f9458 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ - [Open source](#open-source) -v3.0 +v3.0.1 Licensed under The MIT License [![Build status](https://ci.appveyor.com/api/projects/status/2b8n7te1bq8rf1pp?svg=true)](https://ci.appveyor.com/project/mmihajlovic/mamesaver) @@ -33,7 +33,7 @@ Mamesaver is a Windows screen saver that runs MAME with a random game for specif ### REQUIREMENTS * Microsoft .NET 4.6 -* A working installation of MAME. I used 0.200 but older ones will probably work too. +* A working installation of MAME. Versions from 0.155 have been tested, but earlier versions may also work. * Some working ROMS which can run in MAME successfully. * Each ROM that is installed should have been run at least once to remove the initial disclaimer screen as this is the last thing you want to see when the screen saver is running.