private void btnLoadPalFile_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.SetFilter("Palette Files (*.pal)|*.pal|All Files (*.*)|*.*"); if (ofd.ShowDialog() == DialogResult.OK) { using (FileStream paletteFile = File.OpenRead(ofd.FileName)) { byte[] paletteFileData = new byte[512 * 3]; int byteCount = paletteFile.Read(paletteFileData, 0, 512 * 3); if (byteCount == 64 * 3 || byteCount == 512 * 3) { _paletteData = new Int32[byteCount / 3]; for (int i = 0; i < byteCount; i += 3) { _paletteData[i / 3] = (Int32)((UInt32)0xFF000000 | (UInt32)paletteFileData[i + 2] | (UInt32)(paletteFileData[i + 1] << 8) | (UInt32)(paletteFileData[i] << 16)); } RefreshPalette(); byte[] bytePalette = new byte[_paletteData.Length * sizeof(int)]; Buffer.BlockCopy(_paletteData, 0, bytePalette, 0, bytePalette.Length); ConfigManager.Config.VideoInfo.AddPalette(Path.GetFileNameWithoutExtension(ofd.FileName), bytePalette); } paletteFile.Close(); } } }
public static bool RequestBiosFile(string fileName, int fileSize, RomFormat format) { if (MesenMsgBox.Show("BiosNotFound", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, fileName, fileSize.ToString()) == DialogResult.OK) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.SetFilter(ResourceHelper.GetMessage("FilterAll")); if (ofd.ShowDialog(Application.OpenForms[0]) == DialogResult.OK) { byte[] fileData; string hash = GetFileHash(ofd.FileName, out fileData); if (!GetExpectedHashes(format).Contains(hash)) { if (MesenMsgBox.Show("BiosMismatch", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, GetExpectedHashes(format)[0], hash) != DialogResult.OK) { //Files don't match and user cancelled the action return(false); } } File.WriteAllBytes(Path.Combine(ConfigManager.HomeFolder, fileName), fileData); return(true); } } } return(false); }
private void btnLoadPalFile_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.SetFilter("Palette Files (*.pal)|*.pal|All Files (*.*)|*.*"); if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { using (FileStream paletteFile = File.OpenRead(ofd.FileName)) { byte[] paletteFileData = new byte[64 * 3]; if (paletteFile.Read(paletteFileData, 0, 64 * 3) == 64 * 3) { for (int i = 0; i < 64; i++) { int fileOffset = i * 3; _paletteData[i] = (Int32)((UInt32)0xFF000000 | (UInt32)paletteFileData[fileOffset + 2] | (UInt32)(paletteFileData[fileOffset + 1] << 8) | (UInt32)(paletteFileData[fileOffset] << 16)); } RefreshPalette(); byte[] bytePalette = new byte[_paletteData.Length * sizeof(int)]; Buffer.BlockCopy(_paletteData, 0, bytePalette, 0, bytePalette.Length); ConfigManager.Config.VideoInfo.AddPalette(Path.GetFileNameWithoutExtension(ofd.FileName), bytePalette); } paletteFile.Close(); } } }
private void btnBrowse_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.SetFilter(ResourceHelper.GetMessage("FilterRom")); if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { LoadGame(ofd.FileName); } }
private void mnuImport_Click(object sender, EventArgs e) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.SetFilter("Watch files (*.mwf)|*.mwf"); if (ofd.ShowDialog() == DialogResult.OK) { WatchManager.Import(ofd.FileName); } } }
private void mnuImportLabels_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.SetFilter("All supported files (*.dbg, *.msl, *.sym, *.tass)|*.dbg;*.msl;*.sym;*.tass"); if (ofd.ShowDialog() == DialogResult.OK) { ImportLabelFile(ofd.FileName); RefreshDisassembly(); } }
private void mnuPlayMovie_Click(object sender, EventArgs e) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.SetFilter(ResourceHelper.GetMessage("FilterMovie")); ofd.InitialDirectory = ConfigManager.MovieFolder; if (ofd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { InteropEmu.MoviePlay(ofd.FileName); } } }
private void mnuLoadTapeFile_Click(object sender, EventArgs e) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.SetFilter(ResourceHelper.GetMessage("FilterTapeFiles")); ofd.InitialDirectory = ConfigManager.SaveFolder; ofd.FileName = InteropEmu.GetRomInfo().GetRomName() + ".fbt"; if (ofd.ShowDialog(this) == DialogResult.OK) { InteropEmu.LoadTapeFile(ofd.FileName); } } }
private void mnuImport_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.SetFilter("Memory dump files (*.dmp)|*.dmp|All files (*.*)|*.*"); ofd.InitialDirectory = ConfigManager.DebuggerFolder; if (ofd.ShowDialog() == DialogResult.OK) { InteropEmu.DebugSetMemoryState(_memoryType, File.ReadAllBytes(ofd.FileName)); RefreshData(); } }
private void mnuImport_Click(object sender, EventArgs e) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.SetFilter("Memory dump files (*.dmp)|*.dmp|All files (*.*)|*.*"); ofd.InitialDirectory = ConfigManager.DebuggerFolder; if (ofd.ShowDialog() == DialogResult.OK) { byte[] fileContent = File.ReadAllBytes(ofd.FileName); DebugApi.SetMemoryState(_memoryType, fileContent, fileContent.Length); RefreshData(); } } }
private void mnuLoadCdlFile_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.SetFilter("CDL files (*.cdl)|*.cdl"); if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (!InteropEmu.DebugLoadCdlFile(ofd.FileName)) { MessageBox.Show("Could not load CDL file. The file selected file is invalid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void mnuRunAutomaticTest_Click(object sender, EventArgs e) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.SetFilter("*.nes|*.nes"); if (ofd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { string filename = ofd.FileName; Task.Run(() => { InteropEmu.RunAutomaticTest(filename); }); } } }
public static void LoadStateFromFile() { if (EmuRunner.IsRunning()) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.InitialDirectory = ConfigManager.SaveStateFolder; ofd.SetFilter(ResourceHelper.GetMessage("FilterSavestate")); if (ofd.ShowDialog(frmMain.Instance) == DialogResult.OK) { EmuApi.LoadStateFile(ofd.FileName); } } } }
public static void LoadPatchFile(string patchFile) { string patchFolder = Path.GetDirectoryName(patchFile); HashSet <string> romExtensions = new HashSet <string>() { ".sfc", ".smc", ".swc", ".fig" }; List <string> romsInFolder = new List <string>(); foreach (string filepath in Directory.EnumerateFiles(patchFolder)) { if (romExtensions.Contains(Path.GetExtension(filepath).ToLowerInvariant())) { romsInFolder.Add(filepath); } } if (romsInFolder.Count == 1) { //There is a single rom in the same folder as the IPS/BPS patch, use it automatically LoadRom(romsInFolder[0], patchFile); } else { if (!IsRunning()) { //Prompt the user for a rom to load if (MesenMsgBox.Show("SelectRomIps", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.SetFilter(ResourceHelper.GetMessage("FilterRom")); if (ConfigManager.Config.RecentFiles.Items.Count > 0) { ofd.InitialDirectory = ConfigManager.Config.RecentFiles.Items[0].RomFile.Folder; } if (ofd.ShowDialog(frmMain.Instance) == DialogResult.OK) { LoadRom(ofd.FileName, patchFile); } } } } else if (MesenMsgBox.Show("PatchAndReset", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { //Confirm that the user wants to patch the current rom and reset LoadRom(EmuApi.GetRomInfo().RomPath, patchFile); } } }
private void LoadScript() { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.SetFilter("Lua scripts (*.lua)|*.lua"); if (ConfigManager.Config.DebugInfo.RecentScripts.Count > 0) { ofd.InitialDirectory = Path.GetDirectoryName(ConfigManager.Config.DebugInfo.RecentScripts[0]); } if (ofd.ShowDialog() == DialogResult.OK) { LoadScriptFile(ofd.FileName); } } }
private void LoadStateFromFile() { if (_emuThread != null) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.InitialDirectory = ConfigManager.SaveStateFolder; ofd.SetFilter(ResourceHelper.GetMessage("FilterSavestate")); if (ofd.ShowDialog(this) == DialogResult.OK) { InteropEmu.LoadStateFile(ofd.FileName); } } } }
private void LoadPatchFile(string patchFile) { string patchFolder = Path.GetDirectoryName(patchFile); HashSet <string> romExtensions = new HashSet <string>() { ".nes", ".fds", ".unf", "*.unif" }; List <string> romsInFolder = new List <string>(); foreach (string filepath in Directory.EnumerateFiles(patchFolder)) { if (romExtensions.Contains(Path.GetExtension(filepath).ToLowerInvariant())) { romsInFolder.Add(filepath); } } if (romsInFolder.Count == 1) { //There is a single rom in the same folder as the IPS/BPS patch, use it automatically LoadROM(romsInFolder[0], true, patchFile); } else { if (_emuThread == null) { //Prompt the user for a rom to load if (MesenMsgBox.Show("SelectRomIps", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.SetFilter(ResourceHelper.GetMessage("FilterRom")); if (ConfigManager.Config.RecentFiles.Count > 0) { ofd.InitialDirectory = ConfigManager.Config.RecentFiles[0].RomFile.Folder; } if (ofd.ShowDialog(this) == DialogResult.OK) { LoadROM(ofd.FileName, true, patchFile); } } } } else if (MesenMsgBox.Show("PatchAndReset", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { //Confirm that the user wants to patch the current rom and reset LoadROM(_currentRomPath.Value, true, patchFile); } } }
private void mnuTestRecordMovie_Click(object sender, EventArgs e) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.SetFilter(ResourceHelper.GetMessage("FilterMovie")); ofd.InitialDirectory = ConfigManager.MovieFolder; if (ofd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { SaveFileDialog sfd = new SaveFileDialog(); sfd.SetFilter(ResourceHelper.GetMessage("FilterTest")); sfd.InitialDirectory = ConfigManager.TestFolder; sfd.FileName = Path.GetFileNameWithoutExtension(ofd.FileName) + ".mtp"; if (sfd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { InteropEmu.RomTestRecordFromMovie(sfd.FileName, ofd.FileName); } } } }
private void mnuImportLabels_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.SetFilter("All supported files (*.dbg, *.mlb)|*.dbg;*.mlb"); if (ofd.ShowDialog() == DialogResult.OK) { string ext = Path.GetExtension(ofd.FileName).ToLower(); if (ext == ".mlb") { MesenLabelFile.Import(ofd.FileName); } else { Ld65DbgImporter dbgImporter = new Ld65DbgImporter(); dbgImporter.Import(ofd.FileName); } } }
private void btnBrowseCheat_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.SetFilter(ResourceHelper.GetMessage("FilterCheat")); if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { _cheatFile = ofd.FileName; _isMesenCheatFile = NestopiaCheatLoader.IsMesenCheatFile(_cheatFile); if (_isMesenCheatFile) { txtGameName.Text = ""; _gameName = ""; _gameCrc = ""; } txtCheatFile.Text = Path.GetFileName(_cheatFile); UpdateImportButton(); } }
/// <summary> /// Allows the user to pick a project file. /// </summary> public static void OpenProject() { OpenFileDialog of = new OpenFileDialog(); of.SetFilter(new FileFilter("MK Project File", "mkproj")); string lastfolder = ""; if (GeneralSettings.RecentFiles.Count > 0) { string path = GeneralSettings.RecentFiles[0][1]; while (path.Contains("/")) { path = path.Replace("/", "\\"); } List <string> folders = path.Split('\\').ToList(); for (int i = 0; i < folders.Count - 1; i++) { lastfolder += folders[i]; if (i != folders.Count - 2) { lastfolder += "\\"; } } } of.SetInitialDirectory(lastfolder); of.SetTitle("Choose a project file..."); string result = of.Show() as string; if (!string.IsNullOrEmpty(result)) { if (!result.EndsWith(".mkproj")) { new MessageBox("Error", "Invalid project file.", ButtonType.OK, IconType.Error); } else { CloseProject(); Data.SetProjectPath(result); MainWindow.CreateEditor(); MakeRecentProject(); } } }
private void OpenFile() { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.SetFilter(ResourceHelper.GetMessage("FilterRom")); if (ConfigManager.Config.Preferences.OverrideGameFolder && Directory.Exists(ConfigManager.Config.Preferences.GameFolder)) { ofd.InitialDirectory = ConfigManager.Config.Preferences.GameFolder; } else if (ConfigManager.Config.RecentFiles.Items.Count > 0) { ofd.InitialDirectory = ConfigManager.Config.RecentFiles.Items[0].RomFile.Folder; } if (ofd.ShowDialog(frmMain.Instance) == DialogResult.OK) { EmuRunner.LoadFile(ofd.FileName); } } }
public static void RunTest() { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.SetFilter(ResourceHelper.GetMessage("FilterTest")); ofd.InitialDirectory = ConfigManager.TestFolder; if (ofd.ShowDialog(frmMain.Instance) == DialogResult.OK) { int result = TestApi.RunRecordedTest(ofd.FileName, false); if (result == 0) { MessageBox.Show("Test passed.", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("ERROR: Test failed! (" + result + ")", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void mnuLoadTblFile_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.SetFilter("TBL files (*.tbl)|*.tbl"); if (ofd.ShowDialog() == DialogResult.OK) { string[] fileContents = File.ReadAllLines(ofd.FileName); var tblDict = TblLoader.ToDictionary(fileContents); if (tblDict == null) { MessageBox.Show("Could not load TBL file. The file selected file appears to be invalid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { DebugWorkspaceManager.GetWorkspace().TblMappings = new List <string>(fileContents); this.ctrlHexViewer.ByteCharConverter = new TblByteCharConverter(tblDict); this.mnuShowCharacters.Checked = true; } } }
public static void RequestFirmwareFile(MissingFirmwareMessage msg) { string filename = Utf8Marshaler.GetStringFromIntPtr(msg.Filename); if (MesenMsgBox.Show("FirmwareNotFound", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, msg.FirmwareType.ToString(), filename, msg.Size.ToString()) == DialogResult.OK) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.SetFilter(ResourceHelper.GetMessage("FilterAll")); if (ofd.ShowDialog(Application.OpenForms[0]) == DialogResult.OK) { if (GetFileHash(ofd.FileName) != GetExpectedHash(msg.FirmwareType)) { if (MesenMsgBox.Show("FirmwareMismatch", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, msg.FirmwareType.ToString(), GetFileHash(ofd.FileName), GetExpectedHash(msg.FirmwareType)) != DialogResult.OK) { //Files don't match and user cancelled the action return; } } File.Copy(ofd.FileName, Path.Combine(ConfigManager.FirmwareFolder, filename)); } } } }
private void mnuInstallHdPack_Click(object sender, EventArgs e) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.SetFilter(ResourceHelper.GetMessage("FilterZipFiles")); if (ofd.ShowDialog(this) == DialogResult.OK) { try { using (FileStream stream = File.Open(ofd.FileName, FileMode.Open)) { ZipArchive zip = new ZipArchive(stream); //Find the hires.txt file ZipArchiveEntry hiresEntry = null; foreach (ZipArchiveEntry entry in zip.Entries) { if (entry.Name == "hires.txt") { hiresEntry = entry; break; } } if (hiresEntry != null) { using (Stream entryStream = hiresEntry.Open()) { using (StreamReader reader = new StreamReader(entryStream)) { string hiresData = reader.ReadToEnd(); RomInfo romInfo = InteropEmu.GetRomInfo(); //If there's a "supportedRom" tag, check if it matches the current ROM Regex supportedRomRegex = new Regex("<supportedRom>([^\\n]*)"); Match match = supportedRomRegex.Match(hiresData); if (match.Success) { if (!match.Groups[1].Value.ToUpper().Contains(InteropEmu.GetRomInfo().Sha1.ToUpper())) { MesenMsgBox.Show("InstallHdPackWrongRom", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } //Extract HD pack try { string targetFolder = Path.Combine(ConfigManager.HdPackFolder, Path.GetFileNameWithoutExtension(romInfo.GetRomName())); if (Directory.Exists(targetFolder)) { //Warn if the folder already exists if (MesenMsgBox.Show("InstallHdPackConfirmOverwrite", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, targetFolder) != DialogResult.OK) { return; } } else { Directory.CreateDirectory(targetFolder); } string hiresFileFolder = hiresEntry.FullName.Substring(0, hiresEntry.FullName.Length - "hires.txt".Length); foreach (ZipArchiveEntry entry in zip.Entries) { //Extract only the files in the same subfolder as the hires.txt file (and only if they have a name & size > 0) if (!string.IsNullOrWhiteSpace(entry.Name) && entry.Length > 0 && entry.FullName.StartsWith(hiresFileFolder)) { entry.ExtractToFile(Path.Combine(targetFolder, entry.Name), true); } } } catch (Exception ex) { MesenMsgBox.Show("InstallHdPackError", MessageBoxButtons.OK, MessageBoxIcon.Error, ex.ToString()); return; } } //Turn on HD Pack support automatically after installation succeeds ConfigManager.Config.VideoInfo.UseHdPacks = true; ConfigManager.ApplyChanges(); ConfigManager.Config.ApplyConfig(); if (MesenMsgBox.Show("InstallHdPackConfirmReset", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { //Power cycle game if the user agrees InteropEmu.PowerCycle(); } } } else { MesenMsgBox.Show("InstallHdPackInvalidPack", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch { //Invalid file (file missing, not a zip file, etc.) MesenMsgBox.Show("InstallHdPackInvalidZipFile", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
public TilesetEditor(IContainer Parent) : base(Parent) { Submodes = new SubmodeView(this); Submodes.SetHeaderHeight(31); Submodes.SetHeaderWidth(96); Submodes.SetHeaderSelHeight(1); Submodes.SetTextY(6); PassageContainer = Submodes.CreateTab("Passage"); VignetteFade PassageFade = new VignetteFade(PassageContainer); PassageContainer.OnSizeChanged += delegate(BaseEventArgs e) { PassageFade.SetSize(PassageContainer.Size); }; FourDirContainer = Submodes.CreateTab("4-Dir"); VignetteFade FourDirFade = new VignetteFade(FourDirContainer); FourDirContainer.OnSizeChanged += delegate(BaseEventArgs e) { FourDirFade.SetSize(FourDirContainer.Size); }; //PriorityContainer = Submodes.CreateTab("Priority"); //VignetteFade PriorityFade = new VignetteFade(PriorityContainer); //PriorityContainer.OnSizeChanged += delegate (BaseEventArgs e) { PriorityFade.SetSize(PriorityContainer.Size); }; //Submodes.CreateTab("Terrain Tag"); //Submodes.CreateTab("Bush Flag"); //Submodes.CreateTab("Counter Flag"); Container PassageSubContainer = new Container(PassageContainer); PassageList = new TilesetDisplay(PassageSubContainer); PassageList.OnTilesetLoaded += delegate(BaseEventArgs e) { PassageDrawAll(); }; PassageList.OnTileClicked += delegate(MouseEventArgs e) { PassageInput(e); }; Container FourDirSubContainer = new Container(FourDirContainer); FourDirList = new TilesetDisplay(FourDirSubContainer); FourDirList.OnTilesetLoaded += delegate(BaseEventArgs e) { FourDirDrawAll(); }; FourDirList.OnTileClicked += delegate(MouseEventArgs e) { FourDirInput(e); }; PassageContainer.SetBackgroundColor(28, 50, 73); FourDirContainer.SetBackgroundColor(28, 50, 73); //PriorityContainer.SetBackgroundColor(28, 50, 73); SharedContainer = new Container(this); SharedContainer.SetPosition(22, 41); SharedContainer.Sprites["bg"] = new Sprite(SharedContainer.Viewport); SimpleFade fade = new SimpleFade(SharedContainer); fade.SetPosition(4, 4); NameLabel = new Label(SharedContainer); NameLabel.SetText("Name"); NameLabel.SetFont(Font.Get("Fonts/Ubuntu-B", 14)); NameLabel.SetPosition(19, 16); NameBox = new TextBox(SharedContainer); NameBox.SetPosition(19, 40); NameBox.SetSize(156, 21); NameBox.SetSkin(1); // Updates tileset list NameBox.OnTextChanged += delegate(BaseEventArgs e) { if (this.Tileset == null) { return; } this.Tileset.Name = NameBox.Text; ListItem item = DBDataList.DataList.Items[TilesetID - 1]; item.Name = item.Name.Split(':')[0] + ": " + this.Tileset.Name; DBDataList.DataList.Redraw(); }; GraphicLabel = new Label(SharedContainer); GraphicLabel.SetFont(Font.Get("Fonts/Ubuntu-B", 14)); GraphicLabel.SetPosition(19, 79); GraphicLabel.SetText("Tileset Graphic"); GraphicBox = new BrowserBox(SharedContainer); GraphicBox.SetPosition(19, 103); GraphicBox.SetSize(156, 21); GraphicBox.OnDropDownClicked += delegate(BaseEventArgs e) { OpenFileDialog of = new OpenFileDialog(); of.SetFilter(new FileFilter("PNG Image", "png")); of.SetInitialDirectory(Game.Data.ProjectPath + "/gfx/tilesets"); of.SetTitle("Pick a tileset..."); object result = of.Show(); if (result != null) { // Converts path (C:/.../.../tileset_image.png) to filename (tileset_image) string path = result as string; while (path.Contains('\\')) { path = path.Replace('\\', '/'); } string[] folders = path.Split('/'); string file_ext = folders[folders.Length - 1]; string[] dots = file_ext.Split('.'); string file = ""; for (int i = 0; i < dots.Length - 1; i++) { file += dots[i]; if (i != dots.Length - 2) { file += '.'; } } string tilesetsfolder = Game.Data.ProjectPath + "/gfx/tilesets"; // Selected file not in the tilesets folder // Copies source to tilesets folder string chosenparent = System.IO.Directory.GetParent(path).FullName; while (chosenparent.Contains('\\')) { chosenparent = chosenparent.Replace('\\', '/'); } if (chosenparent != tilesetsfolder) { MessageBox box = new MessageBox("Error", "The selected file doesn't exist in the gfx/tilesets folder. Would you like to copy it in?", ButtonType.YesNo); box.OnButtonPressed += delegate(BaseEventArgs e) { if (box.Result == 0) // Yes { string newfilename = null; if (System.IO.File.Exists(tilesetsfolder + "/" + file_ext)) { int iterator = 1; while (string.IsNullOrEmpty(newfilename)) { if (!System.IO.File.Exists(tilesetsfolder + "/" + file + " (" + iterator.ToString() + ")." + dots[dots.Length - 1])) { newfilename = tilesetsfolder + "/" + file + " (" + iterator.ToString() + ")." + dots[dots.Length - 1]; file = file + " (" + iterator.ToString() + ")"; } iterator++; } } else { newfilename = tilesetsfolder + "/" + file_ext; } System.IO.File.Copy(path, newfilename); SetTilesetGraphic(file); } }; } // File is in tilesets folder else { SetTilesetGraphic(file); } } }; // Updates graphic if typed GraphicBox.TextArea.OnWidgetDeselected += delegate(BaseEventArgs e) { string file = GraphicBox.Text; if (!System.IO.File.Exists(Game.Data.ProjectPath + "/gfx/tilesets/" + file + ".png")) { new MessageBox("Error", "No tileset with the name '" + file + "' exists in gfx/tilesets.", IconType.Error); } else { SetTilesetGraphic(file); } }; ClearTilesetButton = new Button(SharedContainer); ClearTilesetButton.SetPosition(25, 150); ClearTilesetButton.SetSize(140, 44); ClearTilesetButton.SetFont(Font.Get("Fonts/Ubuntu-B", 16)); ClearTilesetButton.SetText("Clear Tileset"); ClearTilesetButton.OnClicked += delegate(BaseEventArgs e) { ConfirmClearTileset(); }; Submodes.SelectTab(1); }
private void mnuTestRun_Click(object sender, EventArgs e) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.SetFilter(ResourceHelper.GetMessage("FilterTest")); ofd.InitialDirectory = ConfigManager.TestFolder; ofd.Multiselect = true; if (ofd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { List <string> passedTests = new List <string>(); List <string> failedTests = new List <string>(); List <int> failedFrameCount = new List <int>(); this.menuStrip.Enabled = false; Task.Run(() => { foreach (string filename in ofd.FileNames) { int result = InteropEmu.RunRecordedTest(filename); if (result == 0) { passedTests.Add(Path.GetFileNameWithoutExtension(filename)); } else { failedTests.Add(Path.GetFileNameWithoutExtension(filename)); failedFrameCount.Add(result); } } this.BeginInvoke((MethodInvoker)(() => { if (failedTests.Count == 0) { MessageBox.Show("All tests passed.", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { StringBuilder message = new StringBuilder(); if (passedTests.Count > 0) { message.AppendLine("Passed tests:"); foreach (string test in passedTests) { message.AppendLine(" -" + test); } message.AppendLine(""); } message.AppendLine("Failed tests:"); for (int i = 0, len = failedTests.Count; i < len; i++) { message.AppendLine(" -" + failedTests[i] + " (" + failedFrameCount[i] + ")"); } MessageBox.Show(message.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.menuStrip.Enabled = true; })); }); } } }
public static void ImportMaps() { Setup(); OpenFileDialog of = new OpenFileDialog(); of.SetFilter(new FileFilter("RPG Maker XP Map", "rxdata")); of.SetTitle("Pick map(s)"); of.SetAllowMultiple(true); object ret = of.Show(); List <string> Files = new List <string>(); if (ret is string) { Files.Add(ret as string); } else if (ret is List <string> ) { Files = ret as List <string>; } else { return; // No files picked } for (int i = 0; i < Files.Count; i++) { while (Files[i].Contains('\\')) { Files[i] = Files[i].Replace('\\', '/'); } } string[] folders = Files[0].Split('/'); string parent = ""; string root = ""; for (int i = 0; i < folders.Length - 1; i++) { parent += folders[i]; if (i != folders.Length - 2) { root += folders[i]; } if (i != folders.Length - 2) { parent += '/'; } if (i != folders.Length - 3) { root += '/'; } } List <string> Names = new List <string>(); foreach (string f in Files) { string[] l = f.Split('/').Last().Split('.'); string n = ""; for (int i = 0; i < l.Length - 1; i++) { n += l[i]; if (i != l.Length - 2) { n += '.'; } } Names.Add(n); } // Load MapInfos.rxdata IntPtr infofile = Ruby.Funcall(Ruby.GetConst(Ruby.Object.Class, "File"), "open", Ruby.String.ToPtr(parent + "/MapInfos.rxdata"), Ruby.String.ToPtr("rb")); IntPtr infos = Ruby.Funcall(Ruby.GetConst(Ruby.Object.Class, "Marshal"), "load", infofile); Ruby.Pin(infos); IntPtr keys = Ruby.Funcall(infos, "keys"); Ruby.Pin(keys); Ruby.Funcall(infofile, "close"); // Load Tilesets.rxdata IntPtr tilesetfile = Ruby.Funcall(Ruby.GetConst(Ruby.Object.Class, "File"), "open", Ruby.String.ToPtr(parent + "/Tilesets.rxdata"), Ruby.String.ToPtr("rb")); IntPtr tilesets = Ruby.Funcall(Ruby.GetConst(Ruby.Object.Class, "Marshal"), "load", tilesetfile); Ruby.Pin(tilesets); Ruby.Funcall(tilesetfile, "close"); Action <int> ImportMap = null; ImportMap = delegate(int MapIndex) { // Convert rxdata (Ruby) to mkd (C#) string MapName = Names[MapIndex]; string file = Files[MapIndex]; while (file.Contains('\\')) { file = file.Replace('\\', '/'); } // Load Map.rxdata IntPtr f = Ruby.Funcall(Ruby.GetConst(Ruby.Object.Class, "File"), "open", Ruby.String.ToPtr(file), Ruby.String.ToPtr("rb")); IntPtr map = Ruby.Funcall(Ruby.GetConst(Ruby.Object.Class, "Marshal"), "load", f); Ruby.Pin(map); Ruby.Funcall(f, "close"); int id = Convert.ToInt32(file.Substring(file.Length - 10, 3)); // Link Map with its MapInfo IntPtr info = IntPtr.Zero; for (int i = 0; i < Ruby.Array.Length(keys); i++) { if (Ruby.Array.Get(keys, i) == Ruby.Integer.ToPtr(id)) { info = Ruby.Funcall(infos, "[]", Ruby.Array.Get(keys, i)); } } if (info == IntPtr.Zero) { throw new Exception($"No MapInfo could be found for map ({MapName})."); } Game.Map data = new Game.Map(); data.ID = Editor.GetFreeMapID(); data.DisplayName = MapInfo.Name(info); data.DevName = data.DisplayName; data.Width = Map.Width(map); data.Height = Map.Height(map); IntPtr tileset = Ruby.Array.Get(tilesets, Map.TilesetID(map)); Ruby.Pin(tileset); string tilesetname = Tileset.Name(tileset); Action cont = null; Game.Tileset existing = Data.Tilesets.Find(t => t != null && (t.Name == tilesetname || t.GraphicName == tilesetname)); bool exist = existing != null; string message = $"Importing Map ({MapName})...\n\n"; if (exist) { message += "The tileset of the imported map has the same name as an already-defined tileset in " + $"the database ({existing.Name}).\n" + "Would you like to use this tileset, choose a different one, or import it?"; } else { message += $"No tilesets similar to the one used in the imported map ({Tileset.Name(tileset)}) could be found.\n" + "Would you like to pick an existing tileset, or import it?"; } List <string> Options = new List <string>(); if (exist) { Options.Add("Use this"); } Options.Add("Pick other"); Options.Add("Import it"); MessageBox box = new MessageBox("Importing Map", message, Options); box.OnButtonPressed += delegate(BaseEventArgs e) { if (Options[box.Result] == "Use this") // Use the matched tileset { data.TilesetIDs = new List <int>() { existing.ID }; cont(); } else if (Options[box.Result] == "Pick other") // Pick other tileset { TilesetPicker picker = new TilesetPicker(null); picker.OnClosed += delegate(BaseEventArgs e) { if (picker.ChosenTilesetID > 0) // Chose tileset { data.TilesetIDs = new List <int>() { picker.ChosenTilesetID }; cont(); } else // Didn't pick tileset; cancel importing { data = null; Ruby.Unpin(tileset); Ruby.Unpin(map); MessageBox b = new MessageBox("Warning", $"Importing Map ({MapName})...\n\nAs no tileset was chosen, this map will not be imported.", IconType.Warning); b.OnButtonPressed += delegate(BaseEventArgs e) { if (MapIndex < Files.Count - 1) { ImportMap(MapIndex + 1); } }; } }; } else if (Options[box.Result] == "Import it") // Import the tileset { string filename = root + "/Graphics/Tilesets/" + Tileset.TilesetName(tileset) + ".png"; if (!File.Exists(filename)) // Graphic doesn't exist { MessageBox b = new MessageBox("Error", $"Importing Map ({MapName})...\n\nThe tileset graphic could not be found. The tileset cannot be imported, and thus this map will not be imported.", IconType.Error); b.OnButtonPressed += delegate(BaseEventArgs e) { if (MapIndex < Files.Count - 1) { ImportMap(MapIndex + 1); } }; } else // Graphic does exist { Bitmap bmp = new Bitmap(filename); int pw = bmp.Width / 32 * 33; int ph = bmp.Height / 32 * 33; if (pw > Graphics.MaxTextureSize.Width || ph > Graphics.MaxTextureSize.Height) { MessageBox b = new MessageBox("Error", $"Importing Map ({MapName})...\n\n" + $"The formatted tileset will exceed the maximum texture size ({Graphics.MaxTextureSize.Width},{Graphics.MaxTextureSize.Height}).\n" + "This map will not be imported." ); b.OnButtonPressed += delegate(BaseEventArgs e) { if (MapIndex < Files.Count - 1) { ImportMap(MapIndex + 1); } }; } else { string destination = Data.ProjectPath + "/gfx/tilesets/"; string name = Tileset.TilesetName(tileset); if (File.Exists(destination + Tileset.TilesetName(tileset) + ".png")) { int i = 0; do { i++; } while (File.Exists(destination + Tileset.TilesetName(tileset) + " (" + i.ToString() + ").png")); destination += Tileset.TilesetName(tileset) + " (" + i.ToString() + ").png"; name += " (" + i.ToString() + ")"; } else { destination += Tileset.TilesetName(tileset) + ".png"; } File.Copy(filename, destination); Game.Tileset set = new Game.Tileset(); set.Name = Tileset.Name(tileset); set.GraphicName = name; set.ID = Editor.GetFreeTilesetID(); int tilecount = 8 * bmp.Height / 32; set.Passabilities = new List <Passability>(); set.Priorities = new List <int?>(); set.Tags = new List <int?>(); for (int i = 0; i < tilecount; i++) { set.Passabilities.Add(Passability.All); set.Priorities.Add(0); set.Tags.Add(null); } Data.Tilesets[set.ID] = set; set.CreateBitmap(); if (Editor.MainWindow.DatabaseWidget != null) { Editor.MainWindow.DatabaseWidget.DBDataList.RefreshList(); } data.TilesetIDs = new List <int>() { set.ID }; cont(); } } } }; // Called whenever a choice has been made for tileset importing. cont = new Action(delegate() { if (data.TilesetIDs == null || data.TilesetIDs.Count == 0) // Should not be reachable { throw new Exception("Cannot continue without a tileset."); } data.Layers = new List <Layer>(); bool RemovedAutotiles = false; bool RemovedEvents = Ruby.Integer.FromPtr(Ruby.Funcall(Map.Events(map), "length")) > 0; IntPtr Tiles = Map.Data(map); int XSize = Table.XSize(Tiles); int YSize = Table.YSize(Tiles); int ZSize = Table.ZSize(Tiles); IntPtr tiledata = Table.Data(Tiles); for (int z = 0; z < ZSize; z++) { Layer layer = new Layer($"Layer {z + 1}"); for (int y = 0; y < YSize; y++) { for (int x = 0; x < XSize; x++) { int idx = x + y * XSize + z * XSize * YSize; int tileid = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(tiledata, idx)); if (tileid < 384) { RemovedAutotiles = true; } if (tileid == 0) { layer.Tiles.Add(null); } else { layer.Tiles.Add(new TileData() { TileType = TileType.Tileset, Index = 0, ID = tileid - 384 }); } } } data.Layers.Add(layer); } Ruby.Unpin(map); Ruby.Unpin(tileset); Editor.AddMap(data); if (MapIndex < Files.Count - 1) { ImportMap(MapIndex + 1); } else { string Title = "Warning"; string Msg = ""; if (Files.Count > 1) { Msg = "The maps were imported successfully"; } else { Msg = "The map was imported successfully"; } if (RemovedEvents && RemovedAutotiles) { Msg += ", but all events and autotiles have been deleted as these have not yet been implemented in RPG Studio MK."; } else if (RemovedEvents) { Msg += ", but all events have been deleted as these have not yet been implemented in RPG Studio MK."; } else if (RemovedAutotiles) { Msg += ", but all autotiles have been deleted as these have not yet been implemented in RPG Studio MK."; } else { Title = "Success"; Msg += "."; } List <string> options = new List <string>(); if (Editor.ProjectSettings.LastMode != "MAPPING") { options.Add("Go to Map"); } options.Add("OK"); MessageBox box = new MessageBox(Title, Msg, options, IconType.Info); box.OnButtonPressed += delegate(BaseEventArgs e) { if (options[box.Result] == "Go to Map") // Go to map { Editor.SetMode("MAPPING"); Editor.MainWindow.MapWidget.MapSelectPanel.SetMap(data); } }; Ruby.Unpin(keys); Ruby.Unpin(infos); Ruby.Unpin(tileset); Cleanup(); } }); }; ImportMap(0); }