private void GameSelecter_SelectedChanged(NesMiniApplication app) { if (this.InvokeRequired) { this.Invoke(new NesMiniApplication.ValueChangedHandler(GameSelecter_SelectedChanged), new object[] { app }); } else { /*Checked listbox*/ for (int x = 0; x < checkedListBox1.Items.Count; x++) { if (checkedListBox1.Items[x] == app) { checkedListBox1.SetItemChecked(x, app.Selected); break; } } /*Treeview*/ TreeNode tn = FindNode(app, treeView1.Nodes); if (tn != null) { if (tn.Checked != app.Selected) { tn.Checked = app.Selected; if (tn.Parent != null) { ValidateFolderCheck(tn.Parent); } } } } }
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 void Distinguish_DoWork(object sender, DoWorkEventArgs e) { var games = new List <NesMiniApplication>(); Dictionary <string, List <NesMiniApplication> > sortedGames = new Dictionary <string, List <NesMiniApplication> >(); var gameDirs = Directory.GetDirectories(Path.Combine(runningFolder, "games")); AddLog("Loading game list"); foreach (var gameDir in gameDirs) { try { // Removing empty directories without errors try { var game = NesMiniApplication.FromDirectory(gameDir); if (!sortedGames.ContainsKey(game.Name + " | " + game.GoogleSuffix)) { sortedGames.Add(game.Name + " | " + game.GoogleSuffix, new List <NesMiniApplication>()); } sortedGames[game.Name + " | " + game.GoogleSuffix].Add(game); } catch (FileNotFoundException ex) // Remove bad directories if any { Directory.Delete(gameDir, true); } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); continue; } } AddLog("Done loading game list", null); foreach (string gameName in sortedGames.Keys) { if (sortedGames[gameName].Count() > 1) { AddLog(gameName + " have " + sortedGames[gameName].Count()); string simmilar = findSimilar(sortedGames[gameName]); if (simmilar != "") { foreach (NesMiniApplication app in sortedGames[gameName]) { string f = app.Command.Substring(app.Command.LastIndexOf("/") + 1); string difference = f.Replace(simmilar, ""); if (difference.Contains(".")) { difference = difference.Substring(0, difference.IndexOf(".")); } AddLog("Renaming " + app.Name + " to " + app.Name + " - " + difference); app.Name = app.Name + " - " + difference; app.Save(); } } } } }
public void LoadLibrary() { LoadingLibrary = true; if (GamesRemoved != null) { if (gameLibrary.Count() > 0) { GamesRemoved(gameLibrary); } } gameLibrary.Clear(); // ReloadDefault(); string[] selectedGames = ConfigIni.SelectedGames.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (!System.IO.Directory.Exists(NesMiniApplication.GamesDirectory)) { Directory.CreateDirectory(NesMiniApplication.GamesDirectory); } var gameDirs = Directory.GetDirectories(NesMiniApplication.GamesDirectory); List <NesMiniApplication> toAdd = new List <NesMiniApplication>(); foreach (var gameDir in gameDirs) { try { // Removing empty directories without errors try { var game = NesMiniApplication.FromDirectory(gameDir); if (game.GetType() == typeof(NesMiniApplication)) { Console.Write(""); } game.Selected = selectedGames.Contains(game.Code); toAdd.Add(game); } catch (FileNotFoundException ex) // Remove bad directories if any { Debug.WriteLine(ex.Message + ex.StackTrace); Directory.Delete(gameDir, true); } } catch (Exception ex) { Debug.WriteLine(ex.Message + ex.StackTrace); MessageBox.Show(ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); continue; } } if (toAdd.Count() > 0) { AddGames(toAdd); } LoadingLibrary = false; Manager.EventBus.getInstance().SizeRecalculationRequest(); }
private NesMiniApplication GetSelectedListBox() { NesMiniApplication ret = null; if (checkedListBox1.SelectedItem != null) { ret = (NesMiniApplication)checkedListBox1.SelectedItem; } return(ret); }
public string getCommandLine(NesMiniApplication app) { if (NeedRomParameter) { return((Executable + " " + app.NesClassicRomPath + " " + app.Arguments).Trim()); } else { return((Executable + " " + app.Arguments).Trim()); } }
private void G_SelectedChanged(NesMiniApplication app) { if (!SelectedChangeBatch) { SaveChanges(); } if (SelectedChanged != null) { SelectedChanged(app); } }
public void SetImageForSelectedGame(string fileName) { if (currentApp == null || !(currentApp is NesMiniApplication)) { return; } var game = (currentApp as NesMiniApplication); game.Image = NesMiniApplication.LoadBitmap(fileName); SetGame(game); }
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"; emu.NeedRomParameter = false; } else { emu.SystemName = "Unknow"; emu.NeedRomParameter = true; } emu.Name = emu.Executable; string exeName = "app"; if (emu.Executable.StartsWith("/bin/")) { exeName = emu.Executable.Substring(5); } emu.DefaultImage = "blank_" + exeName + ".png"; emu.Prefix = "Z"; emu.SupportZip = true; emulators.Add(emu); SaveSettings(); return(emu); }
private NesMiniApplication GetSelectedTreeView() { NesMiniApplication ret = null; if (treeView1.SelectedNode != null) { if (treeView1.SelectedNode.Tag is NesMiniApplication) { ret = treeView1.SelectedNode.Tag as NesMiniApplication; } } return(ret); }
public void SetGame(NesMiniApplication app) { comboBox1.Items.Clear(); comboBox2.Items.Clear(); comboBox2.Text = ""; comboBox1.Items.AddRange(Manager.EmulatorManager.getInstance().getEmulatorList().ToArray()); currentApp = app; if (currentApp != null) { comboBox1.SelectedItem = currentApp.GetEmulator(); } ReloadFullCommandLine(); }
private void treeView1_AfterCheck(object sender, TreeViewEventArgs e) { if (e.Node.Tag == null) { if (e.Node.Nodes != null) { if (!InFolderUncheck) { NesMiniApplication last = null; Debug.WriteLine(e.Node.Text + " - " + e.Node.Checked.ToString()); Manager.GameManager.GetInstance().SelectedChangeBatch = true; treeView1.BeginUpdate(); if (e.Node.Checked) { InMassCheck = true; } foreach (TreeNode tn in e.Node.Nodes) { if (tn.Tag != null && tn.Tag is NesMiniApplication) { last = tn.Tag as NesMiniApplication; } if (tn.Checked != e.Node.Checked) { tn.Checked = e.Node.Checked; } } if (e.Node.Checked) { InMassCheck = false; } treeView1.EndUpdate(); Manager.GameManager.GetInstance().SelectedChangeBatch = false; if (!Manager.GameManager.LoadingLibrary) { Manager.EventBus.getInstance().SizeRecalculationRequest(); } } } } else { NesMiniApplication app = e.Node.Tag as NesMiniApplication; app.Selected = e.Node.Checked; } }
private void deleteGame(NesMiniApplication game) { try { if (MessageBox.Show(this, string.Format(Resources.DeleteGame, game.Name), Resources.AreYouSure, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes) { Manager.GameManager.GetInstance().DeleteGames(new List <NesMiniApplication>() { game }); } } catch (Exception ex) { Debug.WriteLine(ex.Message + ex.StackTrace); MessageBox.Show(this, ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void RefreshHakchiInfo() { hakchiGames.Clear(); var gameDirs = Directory.GetDirectories(Path.Combine(runningFolder, "games")); int nbGames = 0; int nbCompressedGames = 0; int invalidGames = 0; foreach (var gameDir in gameDirs) { try { nbGames++; // Removing empty directories without errors try { var game = NesMiniApplication.FromDirectory(gameDir); if ((System.IO.Directory.GetFiles(game.GamePath, "*.7z").Length > 0)) { nbCompressedGames++; } else { AddLog(game.Name + " is not compressed"); } hakchiGames.Add(game); } catch (FileNotFoundException ex) // Remove bad directories if any { invalidGames++; // Directory.Delete(gameDir, true); } } catch (Exception ex) { continue; } } nudNbGames.Value = nbGames; nudCompressedGames.Value = nbCompressedGames; nudInvalidGames.Value = invalidGames; }
private TreeNode FindNode(NesMiniApplication app, TreeNodeCollection nodes) { TreeNode ret = null; foreach (TreeNode tn in nodes) { if (tn.Tag == app) { ret = tn; break; } else { TreeNode tn2 = FindNode(app, tn.Nodes); if (tn2 != null) { ret = tn2; break; } } } return(ret); }
private void CompressWorker_DoWork(object sender, DoWorkEventArgs e) { AddLog("Start compression sequence", null); var games = new List <NesMiniApplication>(); var gameDirs = Directory.GetDirectories(Path.Combine(runningFolder, "games")); AddLog("Loading game list"); foreach (var gameDir in gameDirs) { try { // Removing empty directories without errors try { var game = NesMiniApplication.FromDirectory(gameDir); if ((System.IO.Directory.GetFiles(game.GamePath, "*.7z").Length > 0)) { } else { AddLog(game.Name + " is not compressed"); games.Add(game); } } catch (FileNotFoundException ex) // Remove bad directories if any { Directory.Delete(gameDir, true); } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); continue; } } AddLog("Done loading game list", null); AddLog(games.Count().ToString() + " games to compress"); foreach (NesMiniApplication nm in games) { System.Collections.Generic.List <string> ext = new System.Collections.Generic.List <string>(AppTypeCollection.GetAppByType(nm.GetType()).Extensions); foreach (string f in System.IO.Directory.GetFiles(nm.GamePath)) { if (ext.Contains(System.IO.Path.GetExtension(f))) { File.WriteAllBytes(f + ".7z", Compress(f)); System.IO.File.Delete(f); if (nm.Command.StartsWith("/bin/clover-kachikachi")) { //Replace with new command nm.Command = (f + ".7z").Replace(Path.Combine(runningFolder, "games"), AppTypeCollection.GetAppByType(nm.GetType()).DefaultApps[0] + " /usr/share/games/nes/kachikachi").Replace("\\", "/"); } else { nm.Command = nm.Command.Replace(System.IO.Path.GetFileName(f), System.IO.Path.GetFileName(f) + ".7z"); } nm.Save(); } } } AddLog("Done compressing"); }
private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e) { NesMiniApplication app = (NesMiniApplication)this.checkedListBox1.Items[e.Index]; app.Selected = (e.NewValue == CheckState.Checked); }
public string GetRomFile(NesMiniApplication app) { System.Collections.Generic.List <string> exts = new System.Collections.Generic.List <string>(AppTypeCollection.GetAppByType(app.GetType()).Extensions); List <string> expectedFiles = new List <string>(); expectedFiles.Add(app.Code + ".desktop"); expectedFiles.Add(app.Code + ".png"); expectedFiles.Add(app.Code + "_small.png"); List <string> possibleRomFiles = new List <string>(); List <string> zFiles = new List <string>(); foreach (string f in System.IO.Directory.GetFiles(app.GamePath)) { string fileName = System.IO.Path.GetFileName(f); if (!expectedFiles.Contains(fileName)) { string ext = System.IO.Path.GetExtension(fileName); if (ext == ".7z") { zFiles.Add(fileName); } else { if (!exts.Contains(ext)) { } else { possibleRomFiles.Add(fileName); } } } } string tempCommand = app.Command; tempCommand = tempCommand.Replace(".nes .7z", ".nes.7z"); /*Find if of the file is linked in the commande*/ string foundRom = ""; foreach (string z in zFiles) { if (tempCommand.Contains(z)) { foundRom = z; break; } } if (foundRom == "") { /*Rom was not found in 7z*/ foreach (string z in possibleRomFiles) { if (tempCommand.Contains(z)) { foundRom = z; break; } } } if (foundRom == "") { //Cant find rom from command line, now analyse files if (zFiles.Count >= 1) { //Most likely this one foundRom = zFiles[0]; } else { if (possibleRomFiles.Count >= 1) { foundRom = possibleRomFiles[0]; } } } if (foundRom == "") { string test = "abc"; } return(foundRom); }
private void ReloadInfo() { if (currentApp == null) { groupBoxOptions.Visible = true; groupBoxOptions.Enabled = false; labelID.Text = "ID: "; textBoxName.Text = ""; radioButtonOne.Checked = true; radioButtonTwo.Checked = false; radioButtonTwoSim.Checked = false; maskedTextBoxReleaseDate.Text = ""; textBoxPublisher.Text = ""; textBoxArguments.Text = ""; pictureBoxArt.Image = null; buttonBrowseImage.Enabled = false; buttonGoogle.Enabled = false; } else { groupBoxOptions.Visible = true; labelID.Text = "ID: " + currentApp.Code; textBoxName.Text = currentApp.Name; if (currentApp.Simultaneous && currentApp.Players == 2) { radioButtonTwoSim.Checked = true; } else if (currentApp.Players == 2) { radioButtonTwo.Checked = true; } else { radioButtonOne.Checked = true; } maskedTextBoxReleaseDate.Text = currentApp.ReleaseDate; textBoxPublisher.Text = currentApp.Publisher; textBoxArguments.Text = currentApp.Command; if (System.IO.File.Exists(currentApp.IconPath)) { pictureBoxArt.Image = NesMiniApplication.LoadBitmap(currentApp.IconPath); } else { pictureBoxArt.Image = null; } buttonShowGameGenieDatabase.Enabled = textBoxGameGenie.Enabled = currentApp is NesGame; textBoxGameGenie.Text = (currentApp is NesGame) ? (currentApp as NesGame).GameGenie : ""; groupBoxOptions.Enabled = true; if (currentApp.GetType() != typeof(NesDefaultGame)) { Enable(); } else { Disable(); } } }
public void SetGame(NesMiniApplication app) { currentApp = app; ReloadInfo(); }
public override void Execute() { ReportProgress(0); try { var apps = new List <NesMiniApplication>(); addedApplications = null; //bool NoForAllUnsupportedMappers = false; bool YesForAllUnsupportedMappers = false; YesForAllPatches = false; int count = 0; ReportStatus(Properties.Resources.AddingGames); foreach (var sourceFileName in _GamesToAdd) { NesMiniApplication app = null; try { var fileName = sourceFileName; var ext = Path.GetExtension(sourceFileName).ToLower(); bool? needPatch = YesForAllPatches ? (bool?)true : null; byte[] rawData = null; string tmp = null; if (ext == ".7z" || ext == ".zip" || ext == ".rar") { SevenZipExtractor.SetLibraryPath(Path.Combine(Program.BaseDirectoryInternal, IntPtr.Size == 8 ? @"tools\7z64.dll" : @"tools\7z.dll")); using (var szExtractor = new SevenZipExtractor(sourceFileName)) { var filesInArchive = new List <string>(); var gameFilesInArchive = new List <string>(); foreach (var f in szExtractor.ArchiveFileNames) { var e = Path.GetExtension(f).ToLower(); if (e == ".desktop" || Manager.EmulatorManager.getInstance().isFileValidRom(e)) { gameFilesInArchive.Add(f); } filesInArchive.Add(f); } if (gameFilesInArchive.Count == 1) // Only one NES file (or app) { fileName = gameFilesInArchive[0]; } else if (gameFilesInArchive.Count > 1) // Many NES files, need to select { var r = SelectFile(gameFilesInArchive.ToArray()); if (r == DialogResult.OK) { fileName = selectedFile; } else if (r == DialogResult.Ignore) { fileName = sourceFileName; } else { continue; } } else if (filesInArchive.Count == 1) // No NES files but only one another file { fileName = filesInArchive[0]; } else // Need to select { var r = SelectFile(filesInArchive.ToArray()); if (r == DialogResult.OK) { fileName = selectedFile; } else if (r == DialogResult.Ignore) { fileName = sourceFileName; } else { continue; } } if (fileName != sourceFileName) { var o = new MemoryStream(); if (Path.GetExtension(fileName).ToLower() == ".desktop" || // App in archive, need the whole directory szExtractor.ArchiveFileNames.Contains(Path.GetFileNameWithoutExtension(fileName) + ".jpg") || // Or it has cover in archive szExtractor.ArchiveFileNames.Contains(Path.GetFileNameWithoutExtension(fileName) + ".png")) { tmp = Path.Combine(Path.GetTempPath(), fileName); Directory.CreateDirectory(tmp); szExtractor.ExtractArchive(tmp); fileName = Path.Combine(tmp, fileName); } else { szExtractor.ExtractFile(fileName, o); rawData = new byte[o.Length]; o.Seek(0, SeekOrigin.Begin); o.Read(rawData, 0, (int)o.Length); } } } } if (Path.GetExtension(fileName).ToLower() == ".nes") { try { app = NesGame.Import(fileName, sourceFileName, YesForAllUnsupportedMappers ? (bool?)true : null, ref needPatch, needPatchCallback, null, rawData); // Trying to import Game Genie codes var lGameGeniePath = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName) + ".xml"); if (File.Exists(lGameGeniePath)) { GameGenieDataBase lGameGenieDataBase = new GameGenieDataBase(app); lGameGenieDataBase.ImportCodes(lGameGeniePath, true); lGameGenieDataBase.Save(); } } catch (Exception ex) { if (ex is UnsupportedMapperException || ex is UnsupportedFourScreenException) { var r = MessageBoxFromThread( (ex is UnsupportedMapperException) ? string.Format(Properties.Resources.MapperNotSupported, Path.GetFileName(fileName), (ex as UnsupportedMapperException).ROM.Mapper) : string.Format(Properties.Resources.FourScreenNotSupported, Path.GetFileName(fileName)), Properties.Resources.AreYouSure, _GamesToAdd.Count() <= 1 ? MessageBoxButtons.YesNo : MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, true); if (r == DialogResult.Abort) { YesForAllUnsupportedMappers = true; } if (r == DialogResult.Yes || r == DialogResult.Abort || r == DialogResult.Retry) { app = NesGame.Import(fileName, sourceFileName, true, ref needPatch, needPatchCallback, null, rawData); } else { continue; } } else { throw ex; } } } else { app = NesMiniApplication.Import(fileName, sourceFileName, rawData); } if (!string.IsNullOrEmpty(tmp) && Directory.Exists(tmp)) { Directory.Delete(tmp, true); } ConfigIni.SelectedGames += ";" + app.Code; } catch (Exception ex) { if (ex is System.Threading.ThreadAbortException) { ReportCompleted(); } Debug.WriteLine(ex.Message + ex.StackTrace); ReportError(ex.Message, false); } if (app != null) { apps.Add(app); } ReportProgress((++count * 100 / _GamesToAdd.Count())); } addedApplications = apps; ReportCompleted(); } catch (Exception exc) { ReportError(exc.Message, true); } }
private void Cleanup_DoWork(object sender, DoWorkEventArgs e) { var games = new List <NesMiniApplication>(); var gameDirs = Directory.GetDirectories(Path.Combine(runningFolder, "games")); AddLog("Cleanup"); foreach (var gameDir in gameDirs) { try { // Removing empty directories without errors try { var game = NesMiniApplication.FromDirectory(gameDir); string ogName = game.Name; bool dirty = false; if (game.Name.Trim() != game.Name) { game.Name = game.Name.Trim(); dirty = true; } if (game.Name.EndsWith("-")) { game.Name = game.Name.Substring(0, game.Name.Length - 1); dirty = true; } if (game.Name.Contains("_")) { dirty = true; game.Name = game.Name.Replace("_", " "); } while (game.Name.Contains(" ")) { dirty = true; game.Name = game.Name.Replace(" ", " "); } if (game.Name.Trim() != game.Name) { game.Name = game.Name.Trim(); dirty = true; } if (dirty) { AddLog("Renamed " + ogName + " to " + game.Name); game.Save(); } } catch (FileNotFoundException ex) // Remove bad directories if any { Directory.Delete(gameDir, true); } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); continue; } } AddLog("Done loading game list", null); }