Skip to content
This repository has been archived by the owner on Jul 24, 2022. It is now read-only.

Commit

Permalink
Merge pull request #15 from UrbanCMC/issue-12
Browse files Browse the repository at this point in the history
Centralize name-logic with fallback to filename
  • Loading branch information
Valters committed Sep 13, 2017
2 parents 9467bc9 + c7eec19 commit a236d1d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 58 deletions.
50 changes: 30 additions & 20 deletions Spectabis-WPF/Domain/GetGameName.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;

namespace Spectabis_WPF.Domain
{
Expand All @@ -8,36 +9,45 @@ class GetGameName
private static string emuDir = Properties.Settings.Default.emuDir;

//Returns a game name, using PCSX2 database file
public static string GetName(string _gameserial)
public static string GetName(string _path)
{
string GameIndex = emuDir + @"\GameIndex.dbf";
string GameName = "UNKNOWN";
var serial = "";

//Reads the GameIndex file by line
using (var reader = new StreamReader(GameIndex))
//Get the serial number of the game
if (SupportedGames.ScrappingFiles.Any(a => _path.EndsWith(a)))
{
serial = GetSerial.GetSerialNumber(_path);
}

bool serialFound = false;
while (!reader.EndOfStream)
if (!string.IsNullOrWhiteSpace(serial))
{
//Reads the GameIndex file by line
using (var reader = new StreamReader(GameIndex))
{
var line = reader.ReadLine();

//Forges a GameIndex.dbf entry
//If forged line appears in GameIndex.dbf stop and read the next line
if (line.Contains("Serial = " + _gameserial))
bool serialFound = false;
while (!reader.EndOfStream)
{
serialFound = true;
}
//The next line which contains name associated with gameserial
else if (serialFound == true)
{
//Cleans the data
GameName = line.Replace("Name = ", String.Empty);
return GameName;
var line = reader.ReadLine();

//Forges a GameIndex.dbf entry
//If forged line appears in GameIndex.dbf stop and read the next line
if (line.Contains("Serial = " + serial))
{
serialFound = true;
}
//The next line which contains name associated with gameserial
else if (serialFound)
{
//Cleans the data
return line.Replace("Name = ", String.Empty);
}
}
}
return GameName;
}

//We didn't find a name for the game, just return the file name
return Path.GetFileNameWithoutExtension(_path);
}
}
}
13 changes: 2 additions & 11 deletions Spectabis-WPF/Views/AddGame.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,16 @@ private void ISOBrowser_Button_Click(object sender, RoutedEventArgs e)
}
if (ISODialog.ShowDialog().Value == true)
{
var serial = GetSerial.GetSerialNumber(ISODialog.FileName);

if(Properties.Settings.Default.titleAsFile)
{
title = Path.GetFileNameWithoutExtension(ISODialog.FileName);
}
else
{
title = GetGameName.GetName(serial);
}

var file = ISODialog.FileName;

//If title was not extracted, set it from file
if(title == "UNKNOWN")
{
title = Path.GetFileNameWithoutExtension(file);
title = GetGameName.GetName(ISODialog.FileName);
}

var file = ISODialog.FileName;
title = GameProfile.Create(null, file, title);

//Change initial button and text
Expand Down
5 changes: 2 additions & 3 deletions Spectabis-WPF/Views/GameDiscovery.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,9 @@ private void CreateProfiles()
{
foreach(string game in gamesToAdd)
{
var profile = GetSerial.GetSerialNumber(game);
profile = GetGameName.GetName(profile);
GameProfile.Create(null,game,profile);
GameProfile.Create(null, game, GetGameName.GetName(game));
}

Console.WriteLine("Game profiles created!");
Back();
}
Expand Down
29 changes: 5 additions & 24 deletions Spectabis-WPF/Views/Library.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -841,11 +841,9 @@ public void PushSnackbar(string message)
//Push when a new game in directory is detected
private void PushDirectoryDialog(string game)
{
string serial = GetSerial.GetSerialNumber(game);

TextBlock text = new TextBlock();
text.FontFamily = new FontFamily("Roboto Light");
text.Text = $"Would you like to add \"{GetGameName.GetName(serial)}\" ?";
text.Text = $"Would you like to add \"{GetGameName.GetName(game)}\" ?";
text.TextWrapping = TextWrapping.Wrap;
text.VerticalAlignment = VerticalAlignment.Center;
text.Margin = new Thickness(0, 0, 10, 0);
Expand Down Expand Up @@ -888,27 +886,13 @@ private void DirectoryDialog_Click(object sender, EventArgs e)
{
Console.WriteLine("Adding " + game);

//If file supports extraction of serial number, then do just that
if (SupportedGames.ScrappingFiles.Any(s => game.EndsWith(s)))
if (Properties.Settings.Default.titleAsFile)
{
//If file supports scrapping, then do that
string serial = GetSerial.GetSerialNumber(game);
string title = GetGameName.GetName(serial);

if (Properties.Settings.Default.titleAsFile)
{
AddGame(null, game, Path.GetFileNameWithoutExtension(game));
}
else
{
AddGame(null, game, title);
}
AddGame(null, game, Path.GetFileNameWithoutExtension(game));
}
else
{
//Add game and use file name as game name
string title = Path.GetFileNameWithoutExtension(game);
AddGame(null, game, title);
AddGame(null, game, GetGameName.GetName(game));
}
}

Expand Down Expand Up @@ -987,16 +971,13 @@ private void Grid_Drop(object sender, System.Windows.DragEventArgs e)
//If file supports name scrapping
if (SupportedGames.ScrappingFiles.Any(s => file.EndsWith(s)))
{
string SerialNumber = GetSerial.GetSerialNumber(file);
string GameName = GetGameName.GetName(SerialNumber);

if(Properties.Settings.Default.titleAsFile)
{
AddGame(null, file, Path.GetFileNameWithoutExtension(file));
}
else
{
AddGame(null, file, GameName);
AddGame(null, file, GetGameName.GetName(file));
}
}
else
Expand Down

0 comments on commit a236d1d

Please sign in to comment.