Ejemplo n.º 1
0
		private void FormDragDrop_internal(object sender, DragEventArgs e)
		{
			var filePaths = (string[])e.Data.GetData(DataFormats.FileDrop);
			var isLua = false;
			foreach (var path in filePaths)
			{
				var extension = Path.GetExtension(path);
				if (extension != null && extension.ToUpper() == ".LUA")
				{
					OpenLuaConsole();
					if (GlobalWin.Tools.Has<LuaConsole>())
					{
						GlobalWin.Tools.LuaConsole.LoadLuaFile(path);
					}
					isLua = true;
				}
			}
			if (isLua)
			{
				return;
			}

			var ext = Path.GetExtension(filePaths[0]) ?? string.Empty;
			if (ext.ToUpper() == ".LUASES")
			{
				OpenLuaConsole();
				if (GlobalWin.Tools.Has<LuaConsole>())
				{
					GlobalWin.Tools.LuaConsole.LoadLuaSession(filePaths[0]);
				}
			}
			else if (MovieService.IsValidMovieExtension(ext))
			{
				if (Global.Emulator.IsNull())
				{
					OpenRom();
				}

				if (Global.Emulator.IsNull())
				{
					return;
				}

				StartNewMovie(MovieService.Get(filePaths[0]), false);
			}
			else if (ext.ToUpper() == ".STATE")
			{
				LoadState(filePaths[0], Path.GetFileName(filePaths[0]));
			}
			else if (ext.ToUpper() == ".CHT")
			{
				Global.CheatList.Load(filePaths[0], false);
				GlobalWin.Tools.Load<Cheats>();
			}
			else if (ext.ToUpper() == ".WCH")
			{
				GlobalWin.Tools.LoadRamWatch(true);
				(GlobalWin.Tools.Get<RamWatch>() as RamWatch).LoadWatchFile(new FileInfo(filePaths[0]), false);
			}

			else if (ext.ToUpper() == ".CDL" && Global.Emulator is PCEngine)
			{
				GlobalWin.Tools.Load<CDL>();
				(GlobalWin.Tools.Get<CDL>() as CDL).LoadFile(filePaths[0]);
			}

			else if (MovieImport.IsValidMovieExtension(Path.GetExtension(filePaths[0])))
			{
				if (Global.Emulator.IsNull())
				{
					OpenRom();
				}

				if (Global.Emulator.IsNull())
				{
					return;
				}

				// tries to open a legacy movie format by importing it
				string errorMsg;
				string warningMsg;
				var movie = MovieImport.ImportFile(filePaths[0], out errorMsg, out warningMsg);
				if (!string.IsNullOrEmpty(errorMsg))
				{
					MessageBox.Show(errorMsg, "Conversion error", MessageBoxButtons.OK, MessageBoxIcon.Error);
				}
				else
				{
					// fix movie extension to something palatable for these purposes. 
					// for instance, something which doesnt clobber movies you already may have had.
					// i'm evenly torn between this, and a file in %TEMP%, but since we dont really have a way to clean up this tempfile, i choose this:
					StartNewMovie(movie, false);
				}

				GlobalWin.OSD.AddMessage(warningMsg);
			}
			else
			{
				var args = new LoadRomArgs();
				args.OpenAdvanced = new OpenAdvanced_OpenRom { Path = filePaths[0] };
				LoadRom(filePaths[0], args);
			}
		}
Ejemplo n.º 2
0
		private void OpenAdvancedMenuItem_Click(object sender, EventArgs e)
		{
			var oac = new OpenAdvancedChooser(this);
			if (oac.ShowHawkDialog() == System.Windows.Forms.DialogResult.Cancel)
				return;

			if (oac.Result == OpenAdvancedChooser.Command.RetroLaunchNoGame)
			{
				var argsNoGame = new LoadRomArgs();
				argsNoGame.OpenAdvanced = new OpenAdvanced_LibretroNoGame(Global.Config.LibretroCore);
				LoadRom("", argsNoGame);
				return;
			}

			var args = new LoadRomArgs();

			var filter = RomFilter;

			if (oac.Result == OpenAdvancedChooser.Command.RetroLaunchGame)
			{
				args.OpenAdvanced = new OpenAdvanced_Libretro();
				filter = oac.SuggestedExtensionFilter;
			}
			else if (oac.Result == OpenAdvancedChooser.Command.ClassicLaunchGame)
				args.OpenAdvanced = new OpenAdvanced_OpenRom();
			else throw new InvalidOperationException("Automatic Alpha Sanitizer");


			//-----------------
			//CLONE OF CODE FROM OpenRom (mostly)
			var ofd = new OpenFileDialog
			{
				InitialDirectory = PathManager.GetRomsPath(Global.Emulator.SystemId),
				Filter = filter,
				RestoreDirectory = false,
				FilterIndex = _lastOpenRomFilter,
				Title = "Open Advanced"
			};

			var result = ofd.ShowHawkDialog();
			if (result != DialogResult.OK)
			{
				return;
			}

			var file = new FileInfo(ofd.FileName);
			Global.Config.LastRomPath = file.DirectoryName;
			_lastOpenRomFilter = ofd.FilterIndex;
			//-----------------



			LoadRom(file.FullName, args);
		}
Ejemplo n.º 3
0
		public bool GameIsClosing { get; set; } // Lets tools make better decisions when being called by CloseGame

		public void CloseRom(bool clearSram = false)
		{
			//This gets called after Close Game gets called.
			//Tested with NESHawk and SMB3 (U)
			if (GlobalWin.Tools.AskSave())
			{
				CloseGame(clearSram);
				var coreComm = CreateCoreComm();
				CoreFileProvider.SyncCoreCommInputSignals(coreComm);
				Global.Emulator = new NullEmulator(coreComm, Global.Config.GetCoreSettings<NullEmulator>());
				Global.Game = GameInfo.NullInstance;

				GlobalWin.Tools.Restart();
				RewireSound();
				Global.Rewinder.ResetRewindBuffer();
				Text = "BizHawk" + (VersionInfo.DeveloperBuild ? " (interim) " : string.Empty);
				HandlePlatformMenus();
				_stateSlots.Clear();
				UpdateDumpIcon();
				UpdateCoreStatusBarButton();
				ClearHolds();
				PauseOnFrame = null;
				ToolHelpers.UpdateCheatRelatedTools(null, null);
				UpdateStatusSlots();
				CurrentlyOpenRom = null;
				CurrentlyOpenRomArgs = null;
			}
		}
Ejemplo n.º 4
0
		// Still needs a good bit of refactoring
		public bool LoadRom(string path, LoadRomArgs args)
		{
			//default args
			if (args == null) args = new LoadRomArgs();

			//if this is the first call to LoadRom (they will come in recursively) then stash the args
			bool firstCall = false;
			if (CurrentLoadRomArgs == null)
			{
				firstCall = true;
				CurrentLoadRomArgs = args;
			}
			else
			{
				args = CurrentLoadRomArgs;
			}

			try
			{
				// If deterministic emulation is passed in, respect that value regardless, else determine a good value (currently that simply means movies require deterministic emulaton)
				bool deterministic = args.Deterministic.HasValue ?
					args.Deterministic.Value :
					Global.MovieSession.QueuedMovie != null;
				//Global.MovieSession.Movie.IsActive;

				if (!GlobalWin.Tools.AskSave())
				{
					return false;
				}

				bool asLibretro = (args.OpenAdvanced is OpenAdvanced_Libretro || args.OpenAdvanced is OpenAdvanced_LibretroNoGame);

				var loader = new RomLoader
				{
					ChooseArchive = LoadArhiveChooser,
					ChoosePlatform = ChoosePlatformForRom,
					Deterministic = deterministic,
					MessageCallback = GlobalWin.OSD.AddMessage,
					AsLibretro = asLibretro
				};
				Global.FirmwareManager.RecentlyServed.Clear();

				loader.OnLoadError += ShowLoadError;
				loader.OnLoadSettings += CoreSettings;
				loader.OnLoadSyncSettings += CoreSyncSettings;

				// this also happens in CloseGame().  but it needs to happen here since if we're restarting with the same core,
				// any settings changes that we made need to make it back to config before we try to instantiate that core with
				// the new settings objects
				CommitCoreSettingsToConfig(); // adelikat: I Think by reordering things, this isn't necessary anymore
				CloseGame();

				var nextComm = CreateCoreComm();

				//we need to inform LoadRom which Libretro core to use...
				IOpenAdvanced ioa = args.OpenAdvanced;
				if (ioa is IOpenAdvancedLibretro)
				{
					var ioaretro = ioa as IOpenAdvancedLibretro;

					//prepare a core specification
					//if it wasnt already specified, use the current default
					if (ioaretro.CorePath == null) ioaretro.CorePath = Global.Config.LibretroCore;
					nextComm.LaunchLibretroCore = ioaretro.CorePath;
					if (nextComm.LaunchLibretroCore == null)
						throw new InvalidOperationException("Can't load a file via Libretro until a core is specified");
				}

				CoreFileProvider.SyncCoreCommInputSignals(nextComm);
				var result = loader.LoadRom(path, nextComm);

				//we need to replace the path in the OpenAdvanced with the canonical one the user chose.
				//It can't be done until loder.LoadRom happens (for CanonicalFullPath)
				//i'm not sure this needs to be more abstractly engineered yet until we have more OpenAdvanced examples
				if (ioa is OpenAdvanced_Libretro)
				{
					var oaretro = ioa as OpenAdvanced_Libretro;
					oaretro.token.Path = loader.CanonicalFullPath;
				}
				if (ioa is OpenAdvanced_OpenRom) ((OpenAdvanced_OpenRom)ioa).Path = loader.CanonicalFullPath;
				string loaderName = "*" + OpenAdvancedSerializer.Serialize(ioa);

				if (result)
				{
					Global.Emulator = loader.LoadedEmulator;
					Global.Game = loader.Game;
					CoreFileProvider.SyncCoreCommInputSignals(nextComm);
					InputManager.SyncControls();

					if (Global.Emulator is TI83 && Global.Config.TI83autoloadKeyPad)
					{
						GlobalWin.Tools.Load<TI83KeyPad>();
					}

					if (loader.LoadedEmulator is NES)
					{
						var nes = loader.LoadedEmulator as NES;
						if (!string.IsNullOrWhiteSpace(nes.GameName))
						{
							Global.Game.Name = nes.GameName;
						}

						Global.Game.Status = nes.RomStatus;
					}
					else if (loader.LoadedEmulator is QuickNES)
					{
						var qns = loader.LoadedEmulator as QuickNES;
						if (!string.IsNullOrWhiteSpace(qns.BootGodName))
						{
							Global.Game.Name = qns.BootGodName;
						}
						if (qns.BootGodStatus.HasValue)
						{
							Global.Game.Status = qns.BootGodStatus.Value;
						}
					}

					Global.Rewinder.ResetRewindBuffer();

					if (Global.Emulator.CoreComm.RomStatusDetails == null && loader.Rom != null)
					{
						Global.Emulator.CoreComm.RomStatusDetails = string.Format(
							"{0}\r\nSHA1:{1}\r\nMD5:{2}\r\n",
							loader.Game.Name,
							loader.Rom.RomData.HashSHA1(),
							loader.Rom.RomData.HashMD5());
					}

					if (Global.Emulator.BoardName != null)
					{
						Console.WriteLine("Core reported BoardID: \"{0}\"", Global.Emulator.BoardName);
					}

					// restarts the lua console if a different rom is loaded.
					// im not really a fan of how this is done..
					if (Global.Config.RecentRoms.Empty || Global.Config.RecentRoms.MostRecent != loaderName)
					{
						GlobalWin.Tools.Restart<LuaConsole>();
					}

					Global.Config.RecentRoms.Add(loaderName);
					JumpLists.AddRecentItem(loaderName, ioa.DisplayName);

					// Don't load Save Ram if a movie is being loaded
					if (!Global.MovieSession.MovieIsQueued && File.Exists(PathManager.SaveRamPath(loader.Game)))
					{
						LoadSaveRam();
					}

					GlobalWin.Tools.Restart();

					if (Global.Config.LoadCheatFileByGame)
					{
						if (Global.CheatList.AttemptToLoadCheatFile())
						{
							GlobalWin.OSD.AddMessage("Cheats file loaded");
						}
					}

					SetWindowText();
					CurrentlyOpenRom = loaderName;
					HandlePlatformMenus();
					_stateSlots.Clear();
					UpdateCoreStatusBarButton();
					UpdateDumpIcon();
					SetMainformMovieInfo();
					CurrentlyOpenRomArgs = args;

					Global.Rewinder.CaptureRewindState();

					Global.StickyXORAdapter.ClearStickies();
					Global.StickyXORAdapter.ClearStickyFloats();
					Global.AutofireStickyXORAdapter.ClearStickies();

					RewireSound();
					ToolHelpers.UpdateCheatRelatedTools(null, null);
					if (Global.Config.AutoLoadLastSaveSlot && _stateSlots.HasSlot(Global.Config.SaveSlot))
					{
						LoadQuickSave("QuickSave" + Global.Config.SaveSlot);
					}

					if (Global.FirmwareManager.RecentlyServed.Count > 0)
					{
						Console.WriteLine("Active Firmwares:");
						foreach (var f in Global.FirmwareManager.RecentlyServed)
						{
							Console.WriteLine("  {0} : {1}", f.FirmwareId, f.Hash);
						}
					}
					return true;
				}
				else
				{
					//This shows up if there's a problem                
					// TODO: put all these in a single method or something

					//The ROM has been loaded by a recursive invocation of the LoadROM method.
					if (!(Global.Emulator is NullEmulator))
					{
						return true;
					}

					HandlePlatformMenus();
					_stateSlots.Clear();
					UpdateStatusSlots();
					UpdateCoreStatusBarButton();
					UpdateDumpIcon();
					SetMainformMovieInfo();
					SetWindowText();
					return false;
				}
			}
			finally
			{
				if (firstCall)
				{
					CurrentLoadRomArgs = null;
				}
			}
		}
Ejemplo n.º 5
0
		private void OpenRom()
		{
			var ofd = new OpenFileDialog
			{
				InitialDirectory = PathManager.GetRomsPath(Global.Emulator.SystemId),
				Filter = RomFilter,
				RestoreDirectory = false,
				FilterIndex = _lastOpenRomFilter
			};

			var result = ofd.ShowHawkDialog();
			if (result != DialogResult.OK)
			{
				return;
			}

			var file = new FileInfo(ofd.FileName);
			Global.Config.LastRomPath = file.DirectoryName;
			_lastOpenRomFilter = ofd.FilterIndex;

			var lra = new LoadRomArgs { OpenAdvanced = new OpenAdvanced_OpenRom { Path = file.FullName } };
			LoadRom(file.FullName, lra);
		}
Ejemplo n.º 6
0
		private void LoadRomFromRecent(string rom)
		{

			var ioa = OpenAdvancedSerializer.ParseWithLegacy(rom);

			LoadRomArgs args = new LoadRomArgs()
			{
				OpenAdvanced = ioa
			};

			//if(ioa is this or that) - for more complex behaviour
			rom = ioa.SimplePath;

			if (!LoadRom(rom, args))
			{
				Global.Config.RecentRoms.HandleLoadError(rom);
			}
		}
Ejemplo n.º 7
0
 private void _LoadRom(string filename, string archive = null)
 {
     var args = new LoadRomArgs();
     args.OpenAdvanced = new OpenAdvanced_OpenRom { Path = filename };
     LoadRom(filename, args);
 }