Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/hakchi2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElie Rodrigue <elie.rodrigue@nubik.ca>2017-05-17 15:43:52 +0300
committerElie Rodrigue <elie.rodrigue@nubik.ca>2017-05-17 15:43:52 +0300
commit3b29126c29755fd60fa249d4b456924f75fd2e9a (patch)
tree42d9c734fdf4d8686f796125899276e4aa0201e3
parent9119d42e15cab57132da92b98dfffd2ed83e1f7a (diff)
Fixed / Added some attributes to NesMiniApplication
Switched System detector to an emulator based system Removed listing of default nes games, use the fetch default games option from the menu to manage them.
-rw-r--r--Apps/NesMiniApplication.cs109
-rw-r--r--Apps/UnknowSystem.cs2
-rw-r--r--MainForm.cs4
-rw-r--r--Manager/EmulatorManager.cs178
-rw-r--r--Manager/GameManager.cs2
-rw-r--r--Manager/SystemType.cs222
-rw-r--r--NesMenuCollection.cs7
-rw-r--r--UI/Components/GameSelecter.cs2
-rw-r--r--WorkerForm.cs2
-rw-r--r--hakchi_gui.csproj2
10 files changed, 267 insertions, 263 deletions
diff --git a/Apps/NesMiniApplication.cs b/Apps/NesMiniApplication.cs
index 529836b6..7e3b716c 100644
--- a/Apps/NesMiniApplication.cs
+++ b/Apps/NesMiniApplication.cs
@@ -120,19 +120,58 @@ namespace com.clusterrr.hakchi_gui
}
}
- private Manager.SystemType.SystemDetectionEntry getSysInfo()
- {
- if(_sysInfo == null)
- {
- _sysInfo = Manager.SystemType.getInstance().GetSystemInfo(this);
- }
- return _sysInfo;
+ public Manager.EmulatorManager.Emulator GetEmulator()
+ {
+ return Manager.EmulatorManager.getInstance().GetEmulator(this);
}
- private Manager.SystemType.SystemDetectionEntry _sysInfo;
- public string GetSystemName()
- {
+
+ public string Executable
+ {
+ get
+ {
+ string ret =command;
+ if(ret.IndexOf(" ")!= -1)
+ {
+ ret = ret.Substring(0, ret.IndexOf(" "));
+ }
+
+ return ret;
+
+ }
+ }
+ public string CommandWithoutArguments
+ {
+ get
+ {
+ string ret = command;
+ if(ret.IndexOf(" ") != -1)
+ {
+ if(ret.IndexOf(" ",ret.IndexOf(" "))!=-1)
+ {
+ ret = ret.Substring(0, ret.IndexOf(" ", ret.IndexOf(" ")));
+ }
+ }
+
+ return ret;
+ }
+ }
+ public string NesClassicRomPath
+ {
+ get
+ {
+ string ret = "";
- return getSysInfo().SystemName;
+ if (this.Command.IndexOf(" ") != -1)
+ {
+ ret = Command.Substring(Command.IndexOf(" ") + 1);
+ }
+
+ if (ret.IndexOf(" ") != -1)
+ {
+ ret = ret.Substring(0, ret.IndexOf(" "));
+ }
+ return ret;
+ }
}
public string RomFile
{
@@ -199,18 +238,19 @@ namespace com.clusterrr.hakchi_gui
return ImportApp(fileName);
if (rawRomData == null)
rawRomData = File.ReadAllBytes(fileName);
- List<Manager.SystemType.SystemDetectionEntry> availableSystem = Manager.SystemType.getInstance().ListByFileType(System.IO.Path.GetFileName(fileName));
- Manager.SystemType.SystemDetectionEntry toUse = null;
- if(availableSystem.Count >0)
+ List<Manager.EmulatorManager.Emulator> availableEmus = Manager.EmulatorManager.getInstance().ListByFileType(System.IO.Path.GetFileName(fileName));
+ Manager.EmulatorManager.Emulator toUse = null;
+ if(availableEmus.Count >0)
{
- toUse = availableSystem[0];
+ toUse = availableEmus[0];
+ return (NesMiniApplication)UnknowSystem.Import(fileName, sourceFile, rawRomData, toUse.Prefix[0], toUse.Executable, Manager.BitmapManager.getInstance().GetBitmap(".\\images\\" + toUse.DefaultImage), toUse.SupportZip); ;
}
- else
- {
- toUse = Manager.SystemType.getInstance().AddBlank(System.IO.Path.GetFileName(fileName));
+ else
+ {
+ return null;
}
- return (NesMiniApplication)UnknowSystem.Import(fileName, sourceFile, rawRomData, toUse.Prefix[0], toUse.Executable,Manager.BitmapManager.getInstance().GetBitmap(".\\images\\"+toUse.Image), toUse.SupportZip); ;
+
//string application = extension.Length > 2 ? ("/bin/" + extension.Substring(1)) : DefaultApp;
//return Import(fileName, sourceFile, rawRomData, DefaultPrefix, application, DefaultCover);
@@ -280,18 +320,25 @@ namespace com.clusterrr.hakchi_gui
}
public string Arguments
{
- get
- {
- return command.Substring(command.IndexOf(RomFile) + RomFile.Length).Trim();
- }
- set
- {
- command = command.Substring(0, command.IndexOf(RomFile) + RomFile.Length);
- if(value!= "")
- {
- command = command + " " + value;
- }
- }
+ get
+ {
+ string ret = "";
+ if (command.IndexOf(" ") != -1)
+ {
+ if (command.IndexOf(" ", command.IndexOf(" ")+1) != -1)
+ {
+ ret = command.Substring(command.IndexOf(" ", command.IndexOf(" ") + 1) + 1).Trim(); ;
+ }
+ }
+
+ return ret;
+ }
+ set
+ {
+
+ command = (Executable + " " + NesClassicRomPath + " " + value).Trim();
+ }
+
}
private static NesMiniApplication ImportApp(string fileName)
{
diff --git a/Apps/UnknowSystem.cs b/Apps/UnknowSystem.cs
index 368ed6da..95c0b4c3 100644
--- a/Apps/UnknowSystem.cs
+++ b/Apps/UnknowSystem.cs
@@ -10,7 +10,7 @@ namespace com.clusterrr.hakchi_gui
{
get
{
- return GetSystemName();
+ return "(" + GetEmulator().SystemName + ")";
}
}
diff --git a/MainForm.cs b/MainForm.cs
index 7c040e15..85423ba7 100644
--- a/MainForm.cs
+++ b/MainForm.cs
@@ -33,7 +33,7 @@ namespace com.clusterrr.hakchi_gui
public MainForm()
{
InitializeComponent();
- Manager.SystemType.getInstance();
+
FormInitialize();
Clovershell = new ClovershellConnection() { AutoReconnect = true, Enabled = true };
Clovershell.OnConnected += Clovershell_OnConnected;
@@ -123,7 +123,7 @@ namespace com.clusterrr.hakchi_gui
MessageBoxManager.Abort = Resources.YesForAll;
var extensions = new List<string>() { "*.new", "*.unf", "*.unif", ".*fds", "*.desktop", "*.zip", "*.7z", "*.rar" };
- foreach (var ext in Manager.SystemType.getInstance().GetSupportedExtensions())
+ foreach (var ext in Manager.EmulatorManager.getInstance().GetSupportedExtensions())
if (!extensions.Contains("*" + ext))
extensions.Add("*" + ext);
openFileDialogNes.Filter = Resources.GamesAndApps + "|" + string.Join(";", extensions.ToArray()) + "|" + Resources.AllFiles + "|*.*";
diff --git a/Manager/EmulatorManager.cs b/Manager/EmulatorManager.cs
new file mode 100644
index 00000000..e5cc6dca
--- /dev/null
+++ b/Manager/EmulatorManager.cs
@@ -0,0 +1,178 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.IO;
+namespace com.clusterrr.hakchi_gui.Manager
+{
+ public class EmulatorManager
+ {
+ private static string FoldersXmlPath = Path.Combine(Path.Combine(Program.BaseDirectoryExternal, ConfigIni.ConfigDir), "Emulators.txt");
+ public class Emulator
+ {
+ public string SystemName { get; set; }
+ public string Name { get; set; }
+ public bool SupportZip { get; set; }
+ public string DefaultImage { get; set; }
+ public string Prefix { get; set; }
+ public string Executable { get; set; }
+ public List<string> AvailableArguments { get;set; }
+ public List<string> Extensions { get; set; }
+
+ public string getCommandLine(NesMiniApplication app)
+ {
+ return (Executable + " " + app.NesClassicRomPath + " " + app.Arguments).Trim();
+ }
+ }
+ public static EmulatorManager getInstance()
+ {
+ if (instance == null)
+ {
+ instance = new EmulatorManager();
+ }
+ return instance;
+ }
+ private List<Emulator> emulators = new List<Emulator>();
+ private static EmulatorManager instance;
+ private EmulatorManager()
+ {
+ LoadSettings();
+
+ // SaveSettings();
+ }
+ private void LoadSettings()
+ {
+ if (System.IO.File.Exists(FoldersXmlPath))
+ {
+ emulators = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Emulator>>(System.IO.File.ReadAllText(FoldersXmlPath));
+ }
+ }
+ public void SaveSettings()
+ {
+ System.IO.File.WriteAllText(FoldersXmlPath, Newtonsoft.Json.JsonConvert.SerializeObject(emulators, Newtonsoft.Json.Formatting.Indented));
+ }
+ public Emulator GetEmulator(NesMiniApplication game)
+ {
+ Emulator ret = null;
+ foreach(Emulator emu in emulators)
+ {
+ if(game.CommandWithoutArguments == emu.Executable)
+ {
+ ret = emu;
+
+ if(game.Arguments != "" && !ret.AvailableArguments.Contains(game.Arguments))
+ {
+ ret.AvailableArguments.Add(game.Arguments);
+ SaveSettings();
+ }
+ break;
+ }
+ }
+ if(ret == null)
+ {
+ ret = getUnknowEmulator(game);
+ }
+
+
+
+ return ret;
+ }
+ private Emulator getUnknowEmulator(NesMiniApplication game)
+ {
+ Emulator emu = new Emulator();
+ emu.Extensions = new List<string>();
+ emu.Extensions.Add(System.IO.Path.GetExtension(game.RomFile));
+ emu.AvailableArguments = new List<string>();
+ if((game.Command == null || game.Command == "" )&& emu.Extensions[0].Trim() != "")
+ {
+ emu.Executable = "/bin/" + emu.Extensions[0].Substring(1);
+ }
+ else
+ {
+ if (game.Executable.Trim() != "")
+ {
+ emu.Executable = game.Executable;
+ }
+ else
+ {
+ emu.Executable = game.Command;
+ }
+ }
+ if(game.Arguments.Trim() !="")
+ {
+ emu.AvailableArguments.Add(game.Arguments);
+ }
+ if(game.NesClassicRomPath.Trim() =="")
+ {
+ emu.SystemName = "Application";
+ }
+ else
+ {
+ emu.SystemName = "Unknow";
+ }
+ emu.Name = emu.Executable;
+ emu.DefaultImage = "blank_app.png";
+ emu.Prefix = "Z";
+ emu.SupportZip = true;
+ emulators.Add(emu);
+ SaveSettings();
+ return emu;
+
+ }
+ public bool isFileValidRom(string extension)
+ {
+ bool ret = false;
+ foreach (Emulator sde in emulators)
+ {
+ foreach (string ext in sde.Extensions)
+ {
+ if (ext == extension)
+ {
+ ret = true;
+ break;
+ }
+ }
+ if (ret)
+ {
+ break;
+ }
+ }
+ return ret;
+ }
+ public List<string> GetSupportedExtensions()
+ {
+ List<string> ret = new List<string>();
+
+
+ foreach (Emulator e in emulators)
+ {
+ ret.AddRange(e.Extensions);
+
+ }
+
+ return ret;
+ }
+ public List<Emulator> ListByFileType(string fileName)
+ {
+ List<Emulator> fileTypeAppliable = new List<Emulator>();
+ foreach (Emulator e in emulators)
+ {
+ bool apply = false;
+ foreach (string s in e.Extensions)
+ {
+ if (fileName.EndsWith(s) || (e.SupportZip && fileName.EndsWith(".7z")))
+ {
+ apply = true;
+ break;
+ }
+ }
+ if (apply)
+ {
+ fileTypeAppliable.Add(e);
+ }
+
+ }
+ return fileTypeAppliable;
+ }
+ }
+}
diff --git a/Manager/GameManager.cs b/Manager/GameManager.cs
index d13cf77f..a90e62c1 100644
--- a/Manager/GameManager.cs
+++ b/Manager/GameManager.cs
@@ -315,7 +315,7 @@ namespace com.clusterrr.hakchi_gui.Manager
}
gameLibrary.Clear();
- ReloadDefault();
+ // ReloadDefault();
string[] selectedGames = ConfigIni.SelectedGames.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
if (!System.IO.Directory.Exists(NesMiniApplication.GamesDirectory))
{
diff --git a/Manager/SystemType.cs b/Manager/SystemType.cs
deleted file mode 100644
index 422831c1..00000000
--- a/Manager/SystemType.cs
+++ /dev/null
@@ -1,222 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.IO;
-namespace com.clusterrr.hakchi_gui.Manager
-{
- public class SystemType
- {
- private static string FoldersXmlPath = Path.Combine(Path.Combine(Program.BaseDirectoryExternal, ConfigIni.ConfigDir), "SystemsDetection.txt");
- public class SystemDetectionEntry
- {
- public string Prefix { get; set; }
- public string Image { get; set; }
- public bool SupportZip { get; set; }
- public string SystemName { get; set; }
- public string Executable { get; set; }
- public List<string> Extensions { get; set; }
- }
- public static SystemType getInstance()
- {
- if(instance == null)
- {
- instance = new SystemType();
- }
- return instance;
- }
- private List<SystemDetectionEntry> systemDetections = new List<SystemDetectionEntry>();
- private static SystemType instance;
- private SystemType()
- {
- LoadSettings();
-
- // SaveSettings();
- }
- private void LoadSettings()
- {
- if(System.IO.File.Exists(FoldersXmlPath))
- {
- systemDetections = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SystemDetectionEntry>>(System.IO.File.ReadAllText(FoldersXmlPath));
- }
- }
- public void SaveSettings()
- {
- System.IO.File.WriteAllText(FoldersXmlPath, Newtonsoft.Json.JsonConvert.SerializeObject(systemDetections,Newtonsoft.Json.Formatting.Indented));
- }
- public SystemDetectionEntry GetSystemInfo(NesMiniApplication game)
- {
- SystemDetectionEntry ret = null;
- List<Manager.SystemType.SystemDetectionEntry> execappliable = Manager.SystemType.getInstance().ListByExec(game.Command);
- if (execappliable.Count > 1)
- {
- /*Continue detection*/
- List<Manager.SystemType.SystemDetectionEntry> fileTypeAppliable = Manager.SystemType.getInstance().ListByFileType(game.RomFile, execappliable);
- if (fileTypeAppliable.Count == 0)
- {
- //Cant detect file type...
- List<Manager.SystemType.SystemDetectionEntry> byPrefix = Manager.SystemType.getInstance().ListByPrefix(game.Prefix, execappliable);
- if (byPrefix.Count > 0)
- {
- //Take first one
- ret = byPrefix[0];
- }
- else
- {
- ret = execappliable[0];
- }
-
- }
- else
- {
- if (fileTypeAppliable.Count == 1)
- {
- ret = fileTypeAppliable[0];
- }
- else
- {
- //Still multiple
- List<Manager.SystemType.SystemDetectionEntry> byPrefix = Manager.SystemType.getInstance().ListByPrefix(game.Prefix, fileTypeAppliable);
- if (byPrefix.Count > 0)
- {
- //Take first one
- ret = byPrefix[0];
- }
- else
- {
- ret = fileTypeAppliable[0];
- }
- }
- }
- }
- else
- {
- if (execappliable.Count == 1)
- {
- ret = execappliable[0];
- }
- }
- if(ret == null)
- {
- ret = AddBlank(game.RomFile);
- }
- return ret;
- }
- public SystemDetectionEntry AddBlank(string fileName)
- {
- SystemDetectionEntry sde = new SystemDetectionEntry();
- sde.Extensions = new List<string>();
- sde.Extensions.Add(System.IO.Path.GetExtension(fileName));
- if (sde.Extensions[0].Length != 0)
- {
- sde.Executable = "/bin/" + sde.Extensions[0].Substring(1);
- }
- else
-
- {
- sde.Executable = fileName;
- }
- sde.Image = "blank_app.png";
- sde.Prefix = "Z";
- sde.SupportZip = true;
- sde.SystemName = "Unknow";
- systemDetections.Add(sde);
- SaveSettings();
- return sde;
- }
- public List<Manager.SystemType.SystemDetectionEntry> ListByExec(string command)
- {
- return ListByExec(command, systemDetections);
- }
- public List<Manager.SystemType.SystemDetectionEntry> ListByExec(string command, List<Manager.SystemType.SystemDetectionEntry> subset)
- {
- List<Manager.SystemType.SystemDetectionEntry> execappliable = new List<Manager.SystemType.SystemDetectionEntry>();
- foreach (Manager.SystemType.SystemDetectionEntry e in subset)
- {
- if ((e.Executable != "" &&command.StartsWith(e.Executable)) || e.Executable == "" && command == "")
- {
- execappliable.Add(e);
- }
- }
- return execappliable;
- }
- public List<Manager.SystemType.SystemDetectionEntry> ListByFileType(string fileName)
- {
- return ListByFileType(fileName, systemDetections);
- }
- public List<string> GetSupportedExtensions()
- {
- List<string> ret = new List<string>();
-
-
- foreach (Manager.SystemType.SystemDetectionEntry e in systemDetections)
- {
- ret.AddRange(e.Extensions);
-
- }
-
- return ret;
- }
- public List<Manager.SystemType.SystemDetectionEntry> ListByFileType(string fileName, List<Manager.SystemType.SystemDetectionEntry> subset)
- {
- List<Manager.SystemType.SystemDetectionEntry> fileTypeAppliable = new List<Manager.SystemType.SystemDetectionEntry>();
- foreach (Manager.SystemType.SystemDetectionEntry e in subset)
- {
- bool apply = false;
- foreach (string s in e.Extensions)
- {
- if (fileName.EndsWith(s) || (e.SupportZip && fileName.EndsWith(".7z")))
- {
- apply = true;
- break;
- }
- }
- if (apply)
- {
- fileTypeAppliable.Add(e);
- }
-
- }
- return fileTypeAppliable;
- }
- public bool isFileValidRom(string extension)
- {
- bool ret = false;
- foreach(SystemDetectionEntry sde in systemDetections)
- {
- foreach(string ext in sde.Extensions)
- {
- if(ext == extension)
- {
- ret = true;
- break;
- }
- }
- if (ret)
- {
- break;
- }
- }
- return ret;
- }
- public List<Manager.SystemType.SystemDetectionEntry> ListByPrefix(string prefix)
- {
- return ListByPrefix(prefix, systemDetections);
- }
- public List<Manager.SystemType.SystemDetectionEntry> ListByPrefix(string prefix, List<Manager.SystemType.SystemDetectionEntry> subset)
- {
- List<Manager.SystemType.SystemDetectionEntry> fileTypeAppliable = new List<Manager.SystemType.SystemDetectionEntry>();
- foreach (Manager.SystemType.SystemDetectionEntry e in subset)
- {
-
- if (e.Prefix == prefix )
- {
- fileTypeAppliable.Add(e);
- }
-
-
- }
- return fileTypeAppliable;
- }
- }
-}
diff --git a/NesMenuCollection.cs b/NesMenuCollection.cs
index 43992641..796be0ca 100644
--- a/NesMenuCollection.cs
+++ b/NesMenuCollection.cs
@@ -152,11 +152,12 @@ namespace com.clusterrr.hakchi_gui
var Systems = new Dictionary<string, NesMenuCollection>();
foreach(var game in root)
{
- if(!Systems.ContainsKey(((NesMiniApplication)game).GetSystemName()))
+ Manager.EmulatorManager.Emulator emu = ((NesMiniApplication)game).GetEmulator();
+ if(!Systems.ContainsKey(emu.SystemName))
{
- Systems[((NesMiniApplication)game).GetSystemName()] = new NesMenuCollection();
+ Systems[emu.SystemName] = new NesMenuCollection();
}
- Systems[((NesMiniApplication)game).GetSystemName()].Add(game);
+ Systems[emu.SystemName].Add(game);
}
root.Clear();
foreach(string system in Systems.Keys)
diff --git a/UI/Components/GameSelecter.cs b/UI/Components/GameSelecter.cs
index fa603f67..9297b109 100644
--- a/UI/Components/GameSelecter.cs
+++ b/UI/Components/GameSelecter.cs
@@ -263,7 +263,7 @@ namespace com.clusterrr.hakchi_gui.UI.Components
/*Add to treeview*/
foreach (var game in e.OrderBy(o => o.Name))
{
- string systemName = game.GetSystemName();
+ string systemName = game.GetEmulator().SystemName;
TreeNode tn = getSystemTreeNode(systemName);
TreeNode gameNode = new TreeNode(game.Name);
gameNode.Tag = game;
diff --git a/WorkerForm.cs b/WorkerForm.cs
index abb54240..132572ca 100644
--- a/WorkerForm.cs
+++ b/WorkerForm.cs
@@ -1042,7 +1042,7 @@ namespace com.clusterrr.hakchi_gui
foreach (var f in szExtractor.ArchiveFileNames)
{
var e = Path.GetExtension(f).ToLower();
- if (e == ".desktop" || Manager.SystemType.getInstance().isFileValidRom(e))
+ if (e == ".desktop" || Manager.EmulatorManager.getInstance().isFileValidRom(e))
gameFilesInArchive.Add(f);
filesInArchive.Add(f);
}
diff --git a/hakchi_gui.csproj b/hakchi_gui.csproj
index a0b642eb..b4c4cdfe 100644
--- a/hakchi_gui.csproj
+++ b/hakchi_gui.csproj
@@ -315,9 +315,9 @@
<Compile Include="LibWinUsb\WinUsb\WinUsbDevice.cs" />
<Compile Include="LibWinUsb\WinUsb\WinUsbRegistry.cs" />
<Compile Include="Manager\BitmapManager.cs" />
+ <Compile Include="Manager\EmulatorManager.cs" />
<Compile Include="Manager\EventBus.cs" />
<Compile Include="Manager\GameManager.cs" />
- <Compile Include="Manager\SystemType.cs" />
<Compile Include="MessageBoxManager.cs" />
<Compile Include="Properties\Resources.Designer.cs" />
<Compile Include="Properties\Settings.Designer.cs">