Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/legacy mame #54

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Appveyor.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions Mamesaver.Test/Mamesaver.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
1 change: 1 addition & 0 deletions Mamesaver.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Mamesaver/Mamesaver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" CopyLocal="True" />
Expand Down
2 changes: 1 addition & 1 deletion Mamesaver/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
// Revision
//
[assembly: AssemblyVersion("3.0.*")]
[assembly: AssemblyFileVersion("3.0")]
[assembly: AssemblyFileVersion("3.0.1")]
37 changes: 30 additions & 7 deletions Mamesaver/Services/Mame/GameListBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </summary>
private const int RomsPerBatch = 50;
private const int DefaultRomsPerBatch = 50;

/// <summary>
/// Settings for parsing MAME's listxml output
Expand Down Expand Up @@ -57,9 +57,22 @@ public List<SelectableGame> GetGameList(Action<int> progressCallback)
var games = new List<SelectableGame>();

// 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<SelectableGame> GetGameList(Action<int> progressCallback, List<string> romFiles, List<string> verifiedGames, List<SelectableGame> games, int romsPerBatch)
{
// Get details for each verified ROM
var index = 0;

Expand All @@ -68,14 +81,14 @@ public List<SelectableGame> GetGameList(Action<int> progressCallback)
var romsProcessed = romFiles.Count + (romFiles.Count - verifiedGames.Count);

List<string> 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
Expand Down Expand Up @@ -109,7 +122,7 @@ private List<SelectableGame> 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);
Expand Down Expand Up @@ -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.
/// </summary>
private IDictionary<string, string> GetVerifiedSets(Action<int> 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<string, string> GetVerifiedSets(Action<int> progressCallback, int romsPerBatch)
{
var verifiedRoms = new Dictionary<string, string>();
var regex = new Regex(@"romset (\w*)(?:\s\[(\w*)\])? is good"); //only accept the "good" ROMS
Expand All @@ -212,7 +235,7 @@ private IDictionary<string, string> GetVerifiedSets(Action<int> progressCallback
var filesProcessed = 0;

List<string> filesToVerify;
while ((filesToVerify = romFiles.Skip(index).Take(RomsPerBatch).ToList()).Any())
while ((filesToVerify = romFiles.Skip(index).Take(romsPerBatch).ToList()).Any())
{
var arguments = new List<string> { "-verifyroms" }.Concat(filesToVerify).ToArray();
using (var stream = _invoker.GetOutput(arguments))
Expand All @@ -227,7 +250,7 @@ private IDictionary<string, string> GetVerifiedSets(Action<int> 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
Expand Down
4 changes: 2 additions & 2 deletions Mamesaver/Services/Mame/MameInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ public Process Run(bool start, params string[] arguments)
/// Registers a MAME process for automatic termination on shutdown.
/// </summary>
/// <param name="process"></param>
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();
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.

Expand Down