diff --git a/FriishProduce/FriishProduce.csproj b/FriishProduce/FriishProduce.csproj index 832cc3b..cab2416 100644 --- a/FriishProduce/FriishProduce.csproj +++ b/FriishProduce/FriishProduce.csproj @@ -344,7 +344,6 @@ - diff --git a/FriishProduce/MainForm.Designer.cs b/FriishProduce/MainForm.Designer.cs index d944588..def26e9 100644 --- a/FriishProduce/MainForm.Designer.cs +++ b/FriishProduce/MainForm.Designer.cs @@ -40,8 +40,6 @@ private void InitializeComponent() this.menu_new_project = new System.Windows.Forms.ToolStripMenuItem(); this.menu_open_project = new System.Windows.Forms.ToolStripMenuItem(); this.menu_save_project_as = new System.Windows.Forms.ToolStripMenuItem(); - this.menu_save_as_wad = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator(); this.menu_settings = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator(); this.menu_exit = new System.Windows.Forms.ToolStripMenuItem(); @@ -51,10 +49,11 @@ private void InitializeComponent() this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.menu_retrieve_gamedata_online = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); + this.menu_save_as_wad = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator(); this.menu_close_project = new System.Windows.Forms.ToolStripMenuItem(); this.menu_help = new System.Windows.Forms.ToolStripMenuItem(); this.menu_about_app = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator(); this.MainPanel = new System.Windows.Forms.Panel(); this.Logo = new System.Windows.Forms.PictureBox(); this.ToolStrip = new System.Windows.Forms.ToolStrip(); @@ -72,6 +71,7 @@ private void InitializeComponent() this.toolbarSaveAsWAD = new System.Windows.Forms.ToolStripButton(); this.SaveProject = new System.Windows.Forms.SaveFileDialog(); this.BrowseProject = new System.Windows.Forms.OpenFileDialog(); + this.toolStripSeparator5 = new System.Windows.Forms.ToolStripSeparator(); this.MenuStrip.SuspendLayout(); this.MainPanel.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.Logo)).BeginInit(); @@ -144,10 +144,9 @@ private void InitializeComponent() this.menu_new_project, this.menu_open_project, this.menu_save_project_as, - this.menu_save_as_wad, - this.toolStripMenuItem1, - this.menu_settings, this.toolStripSeparator4, + this.menu_settings, + this.toolStripSeparator5, this.menu_exit}); this.menu_file.Name = "menu_file"; resources.ApplyResources(this.menu_file, "menu_file"); @@ -176,19 +175,6 @@ private void InitializeComponent() this.menu_save_project_as.Tag = "save_project_as"; this.menu_save_project_as.Click += new System.EventHandler(this.SaveAs_Click); // - // menu_save_as_wad - // - resources.ApplyResources(this.menu_save_as_wad, "menu_save_as_wad"); - this.menu_save_as_wad.Image = global::FriishProduce.Properties.Resources.wooden_box_pencil; - this.menu_save_as_wad.Name = "menu_save_as_wad"; - this.menu_save_as_wad.Tag = "save_as_wad"; - this.menu_save_as_wad.Click += new System.EventHandler(this.ExportWAD_Click); - // - // toolStripMenuItem1 - // - this.toolStripMenuItem1.Name = "toolStripMenuItem1"; - resources.ApplyResources(this.toolStripMenuItem1, "toolStripMenuItem1"); - // // menu_settings // this.menu_settings.Image = global::FriishProduce.Properties.Resources.wrench; @@ -218,6 +204,8 @@ private void InitializeComponent() this.toolStripSeparator1, this.menu_retrieve_gamedata_online, this.toolStripSeparator2, + this.menu_save_as_wad, + this.toolStripSeparator3, this.menu_close_project}); this.menu_project.Name = "menu_project"; resources.ApplyResources(this.menu_project, "menu_project"); @@ -257,6 +245,19 @@ private void InitializeComponent() this.toolStripSeparator2.Name = "toolStripSeparator2"; resources.ApplyResources(this.toolStripSeparator2, "toolStripSeparator2"); // + // menu_save_as_wad + // + resources.ApplyResources(this.menu_save_as_wad, "menu_save_as_wad"); + this.menu_save_as_wad.Image = global::FriishProduce.Properties.Resources.wooden_box_pencil; + this.menu_save_as_wad.Name = "menu_save_as_wad"; + this.menu_save_as_wad.Tag = "save_as_wad"; + this.menu_save_as_wad.Click += new System.EventHandler(this.ExportWAD_Click); + // + // toolStripSeparator3 + // + this.toolStripSeparator3.Name = "toolStripSeparator3"; + resources.ApplyResources(this.toolStripSeparator3, "toolStripSeparator3"); + // // menu_close_project // resources.ApplyResources(this.menu_close_project, "menu_close_project"); @@ -280,11 +281,6 @@ private void InitializeComponent() this.menu_about_app.Tag = "about_app"; this.menu_about_app.Click += new System.EventHandler(this.About_Click); // - // toolStripSeparator3 - // - this.toolStripSeparator3.Name = "toolStripSeparator3"; - resources.ApplyResources(this.toolStripSeparator3, "toolStripSeparator3"); - // // MainPanel // this.MainPanel.BackColor = System.Drawing.Color.Gainsboro; @@ -423,6 +419,11 @@ private void InitializeComponent() // this.BrowseProject.DefaultExt = "fppj"; // + // toolStripSeparator5 + // + this.toolStripSeparator5.Name = "toolStripSeparator5"; + resources.ApplyResources(this.toolStripSeparator5, "toolStripSeparator5"); + // // MainForm // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; @@ -476,7 +477,6 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripButton toolbarCloseProject; private System.Windows.Forms.ToolStripSeparator toolStripSeparator8; private System.Windows.Forms.ToolStripButton ToolStrip_Settings; - private System.Windows.Forms.ToolStripSeparator toolStripMenuItem1; private System.Windows.Forms.ToolStripDropDownButton toolbarNewProject; private System.Windows.Forms.OpenFileDialog BrowseProject; private System.Windows.Forms.ToolStripMenuItem menu_open_project; @@ -491,6 +491,7 @@ private void InitializeComponent() internal System.Windows.Forms.ToolStripMenuItem menu_save_as_wad; internal System.Windows.Forms.ToolStripMenuItem menu_open_image; internal System.Windows.Forms.ToolStripButton toolbarOpenImage; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator5; } } diff --git a/FriishProduce/MainForm.cs b/FriishProduce/MainForm.cs index ef3dd5d..f2441f7 100644 --- a/FriishProduce/MainForm.cs +++ b/FriishProduce/MainForm.cs @@ -399,7 +399,7 @@ private void OpenProject_Click(object sender, EventArgs e) addTab(project.Platform, project); } - catch + catch (Exception ex) { MessageBox.Show("Not a valid project file!", MessageBox.Buttons.Ok, MessageBox.Icons.Error); } diff --git a/FriishProduce/MainForm.resx b/FriishProduce/MainForm.resx index 563e34e..5582d97 100644 --- a/FriishProduce/MainForm.resx +++ b/FriishProduce/MainForm.resx @@ -162,13 +162,13 @@ False - 155, 22 + 180, 22 new_project - 155, 22 + 180, 22 open_project @@ -177,34 +177,22 @@ False - 155, 22 + 180, 22 save_project_as - - False - - - 155, 22 - - - save_as_wad - - - 152, 6 - - 155, 22 + 180, 22 settings - 152, 6 + 177, 6 - 155, 22 + 180, 22 exit @@ -248,6 +236,18 @@ 206, 6 + + False + + + 209, 22 + + + save_as_wad + + + 206, 6 + False @@ -300,9 +300,6 @@ 2 - - 6, 6 - 0, 0 @@ -492,6 +489,9 @@ 229, 17 + + 206, 6 + True @@ -2903,9 +2903,6 @@ AAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAhAAAAIQBAAD8HwAA//8AAP//AAA= - - NoControl - 16, 110 @@ -2957,18 +2954,6 @@ System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - menu_save_as_wad - - - System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - toolStripMenuItem1 - - - System.Windows.Forms.ToolStripSeparator, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - menu_settings @@ -3023,6 +3008,18 @@ System.Windows.Forms.ToolStripSeparator, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + menu_save_as_wad + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + toolStripSeparator3 + + + System.Windows.Forms.ToolStripSeparator, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + menu_close_project @@ -3041,12 +3038,6 @@ System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - toolStripSeparator3 - - - System.Windows.Forms.ToolStripSeparator, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - toolbarNewProject @@ -3131,6 +3122,12 @@ System.Windows.Forms.OpenFileDialog, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + toolStripSeparator5 + + + System.Windows.Forms.ToolStripSeparator, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + MainForm diff --git a/FriishProduce/ProjectForm.cs b/FriishProduce/ProjectForm.cs index b2eb60b..1c33ec3 100644 --- a/FriishProduce/ProjectForm.cs +++ b/FriishProduce/ProjectForm.cs @@ -85,7 +85,7 @@ public bool IsExportable && !string.IsNullOrWhiteSpace(channel_title.Text) && !string.IsNullOrEmpty(_bannerTitle) && (img != null) - && rom?.Path != null; + && rom?.FilePath != null; return save_data_title.Visible ? yes && !string.IsNullOrEmpty(_saveDataTitle[0]) : yes; } @@ -122,6 +122,7 @@ private Region inWadRegion } } + private Project project; private WAD outWad; private libWiiSharp.Region outWadRegion { @@ -134,7 +135,6 @@ private libWiiSharp.Region outWadRegion } protected ROM rom { get; set; } - protected GameData gameData { get; set; } protected string patch { get; set; } protected string manual { get; set; } protected ImageHelper img { get; set; } @@ -203,14 +203,13 @@ public void SaveProject(string path) { Platform = platform, - ROM = rom?.Path, + ROM = rom?.FilePath, Patch = patch, Manual = (manual_type_list.SelectedIndex, manual), Img = img?.Source ?? null, InjectionMethod = injection_methods.SelectedIndex, ForwarderOptions = (FStorage_USB.Checked, toggleSwitch1.Checked), ContentOptions = contentOptions ?? null, - GameData = gameData, WADRegion = TargetRegion.SelectedIndex, LinkSaveDataTitle = LinkSaveData.Checked, ImageOptions = (imageintpl.SelectedIndex, image_fit.Checked), @@ -417,70 +416,14 @@ public ProjectForm(Platform platform, string ROMpath = null, Project project = n _isShown = true; if (project != null && ROMpath == null) - { - // Error messages for not found files - // ******** - foreach (var item in new string[] { project.ROM, project.Patch, project.BaseFile }) - if (!File.Exists(item) && !string.IsNullOrWhiteSpace(item)) MessageBox.Show(string.Format(Program.Lang.Msg(10, true), Path.GetFileName(item))); - - if (project.GameData != null) gameData = project.GameData; - - rom.Path = File.Exists(project.ROM) ? project.ROM : null; - LoadROM(rom.Path, false); - - img = new ImageHelper(project.Platform, null); - img.LoadToSource(project.Img); - LoadImage(project.Img); - - if (File.Exists(project.BaseFile)) - { - WADPath = project.BaseFile; - ImportWAD.Checked = true; - DownloadWAD.Checked = false; - LoadWAD(project.BaseFile); - } - else - { - Base.SelectedIndex = project.Base.Item1; - for (int i = 0; i < baseRegionList.Items.Count; i++) - if (baseRegionList.Items[i].GetType() == typeof(ToolStripMenuItem)) (baseRegionList.Items[i] as ToolStripMenuItem).Checked = false; - UpdateBaseForm(project.Base.Item2); - (baseRegionList.Items[project.Base.Item2] as ToolStripMenuItem).Checked = true; - } - - SetROMDataText(); - - channel_title.Text = project.ChannelTitles[1]; - banner_title.Text = project.BannerTitle; - released.Value = project.BannerYear; - players.Value = project.BannerPlayers; - save_data_title.Lines = project.SaveDataTitle; - tid.Text = project.TitleID; - - TargetRegion.SelectedIndex = project.WADRegion; - injection_methods.SelectedIndex = project.InjectionMethod; - imageintpl.SelectedIndex = project.ImageOptions.Item1; - image_fit.Checked = project.ImageOptions.Item2; - - contentOptions = project.ContentOptions; - - IsEmpty = false; - - patch = File.Exists(project.Patch) ? project.Patch : null; - Patch.Checked = !string.IsNullOrWhiteSpace(project.Patch); - LoadManual(project.Manual.Type, project.Manual.File); - } + this.project = project; if (ROMpath != null && project == null) { - rom.Path = ROMpath; - LoadROM(rom.Path, Properties.Settings.Default.auto_retrieve_game_data); + rom.FilePath = ROMpath; + LoadROM(rom.FilePath, Properties.Settings.Default.auto_retrieve_game_data); randomTID(); } - - LinkSaveData.Checked = project == null ? Properties.Settings.Default.link_save_data : project.LinkSaveDataTitle; - FStorage_USB.Checked = project == null ? Options.FORWARDER.Default.root_storage_device.ToLower().Contains("usb") : project.ForwarderOptions.Item1; - toggleSwitch1.Checked = project == null ? Options.FORWARDER.Default.nand_loader.ToLower().Contains("vwii") : project.ForwarderOptions.Item2; } private void Form_Shown(object sender, EventArgs e) @@ -581,7 +524,63 @@ private void Form_Shown(object sender, EventArgs e) }) if (platform == customManualplatform) manual_type_list.Enabled = true; + if (project != null) + { + // Error messages for not found files + // ******** + foreach (var item in new string[] { project.ROM, project.Patch, project.BaseFile }) + if (!File.Exists(item) && !string.IsNullOrWhiteSpace(item)) MessageBox.Show(string.Format(Program.Lang.Msg(10, true), Path.GetFileName(item))); + + img = new ImageHelper(project.Platform, null); + img.LoadToSource(project.Img); + LoadROM(project.ROM, false); + LoadImage(project.Img); + + if (File.Exists(project.BaseFile)) + { + WADPath = project.BaseFile; + ImportWAD.Checked = true; + DownloadWAD.Checked = false; + LoadWAD(project.BaseFile); + } + else + { + Base.SelectedIndex = project.Base.Item1; + for (int i = 0; i < baseRegionList.Items.Count; i++) + if (baseRegionList.Items[i].GetType() == typeof(ToolStripMenuItem)) (baseRegionList.Items[i] as ToolStripMenuItem).Checked = false; + UpdateBaseForm(project.Base.Item2); + (baseRegionList.Items[project.Base.Item2] as ToolStripMenuItem).Checked = true; + } + + SetROMDataText(); + + channel_title.Text = project.ChannelTitles[1]; + banner_title.Text = project.BannerTitle; + released.Value = project.BannerYear; + players.Value = project.BannerPlayers; + save_data_title.Lines = project.SaveDataTitle; + tid.Text = project.TitleID; + + TargetRegion.SelectedIndex = project.WADRegion; + injection_methods.SelectedIndex = project.InjectionMethod; + imageintpl.SelectedIndex = project.ImageOptions.Item1; + image_fit.Checked = project.ImageOptions.Item2; + + contentOptions = project.ContentOptions; + + IsEmpty = false; + + patch = File.Exists(project.Patch) ? project.Patch : null; + Patch.Checked = !string.IsNullOrWhiteSpace(project.Patch); + LoadManual(project.Manual.Type, project.Manual.File); + + project = null; + } + + LinkSaveData.Checked = project == null ? Properties.Settings.Default.link_save_data : project.LinkSaveDataTitle; + FStorage_USB.Checked = project == null ? Options.FORWARDER.Default.root_storage_device.ToLower().Contains("usb") : project.ForwarderOptions.Item1; FStorage_SD.Checked = !FStorage_USB.Checked; + toggleSwitch1.Checked = project == null ? Options.FORWARDER.Default.nand_loader.ToLower().Contains("vwii") : project.ForwarderOptions.Item2; } // ----------------------------------- @@ -606,7 +605,7 @@ public bool[] ToolbarButtons { platform != Platform.Flash && platform != Platform.RPGM - && (rom?.Bytes != null || !string.IsNullOrWhiteSpace(rom?.Path)), // LibRetro / game data + && (rom?.Bytes != null || !string.IsNullOrWhiteSpace(rom?.FilePath)), // LibRetro / game data platform != Platform.Flash && platform != Platform.RPGM @@ -616,12 +615,12 @@ public bool[] ToolbarButtons protected virtual void SetROMDataText() { - filename.Text = string.Format(Program.Lang.String("filename", Name), !string.IsNullOrWhiteSpace(rom?.Path) ? Path.GetFileName(rom.Path) : Program.Lang.String("none")); + filename.Text = string.Format(Program.Lang.String("filename", Name), !string.IsNullOrWhiteSpace(rom?.FilePath) ? Path.GetFileName(rom.FilePath) : Program.Lang.String("none")); - if (platform == Platform.RPGM && (rom as RPGM)?.GetTitle(rom.Path) != null) - software_name.Text = string.Format(Program.Lang.String("software_name", Name), (rom as RPGM).GetTitle(rom.Path)?.Replace(Environment.NewLine, " - ") ?? Program.Lang.String("none")); + if (platform == Platform.RPGM && (rom as RPGM)?.GetTitle(rom.FilePath) != null) + software_name.Text = string.Format(Program.Lang.String("software_name", Name), (rom as RPGM).GetTitle(rom.FilePath)?.Replace(Environment.NewLine, " - ") ?? Program.Lang.String("none")); else - software_name.Text = string.Format(Program.Lang.String("software_name", Name), gameData?.CleanTitle?.Replace(Environment.NewLine, " - ") ?? Program.Lang.String("none")); + software_name.Text = string.Format(Program.Lang.String("software_name", Name), rom.CleanTitle?.Replace(Environment.NewLine, " - ") ?? Program.Lang.String("none")); label11.Text = !string.IsNullOrWhiteSpace(patch) ? Path.GetFileName(patch) : Program.Lang.String("none"); label11.Enabled = !string.IsNullOrWhiteSpace(patch); @@ -635,7 +634,7 @@ private void randomTID() public string GetName() { - string FILENAME = Patch.Checked ? Path.GetFileNameWithoutExtension(patch) : Path.GetFileNameWithoutExtension(rom?.Path); + string FILENAME = Patch.Checked ? Path.GetFileNameWithoutExtension(patch) : Path.GetFileNameWithoutExtension(rom?.FilePath); string CHANNELNAME = channel_title.Text; string FULLNAME = System.Text.RegularExpressions.Regex.Replace(_bannerTitle.Replace(": ", Environment.NewLine).Replace(" - ", Environment.NewLine), @"\((.*?)\)", "").Replace("\r\n", "\n").Replace("\n", " - "); string TITLEID = tid.Text.ToUpper(); @@ -684,6 +683,7 @@ public bool CheckUnsaved() private void Value_Changed(object sender, EventArgs e) { + resetBannerPreview(); refreshData(); } @@ -1007,12 +1007,14 @@ protected bool LoadImage(Bitmap src) public void LoadROM(string ROMpath, bool LoadGameData = true) { + if (ROMpath == null || rom == null || !File.Exists(ROMpath)) return; + switch (platform) { // ROM file formats // **************** default: - if (rom == null || !rom.CheckValidity(ROMpath)) + if (!rom.CheckValidity(ROMpath)) { MessageBox.Show(Program.Lang.Msg(2), 0, MessageBox.Icons.Warning); return; @@ -1022,7 +1024,7 @@ public void LoadROM(string ROMpath, bool LoadGameData = true) // ZIP format // **************** case Platform.NEO: - if (!rom.CheckZIPValidity(ROMpath, new string[] { "c1", "c2", "m1", "p1", "s1", "v1" }, true, true)) + if (!rom.CheckZIPValidity(new string[] { "c1", "c2", "m1", "p1", "s1", "v1" }, true, true, ROMpath)) { MessageBox.Show(Program.Lang.Msg(2), 0, MessageBox.Icons.Warning); return; @@ -1050,7 +1052,7 @@ public void LoadROM(string ROMpath, bool LoadGameData = true) break; } - if (rom != null) rom.Path = ROMpath; + rom.FilePath = ROMpath; IsEmpty = false; IsModified = true; @@ -1059,46 +1061,45 @@ public void LoadROM(string ROMpath, bool LoadGameData = true) patch = null; Patch.Checked = false; - gameData = new GameData(); if (rom != null && LoadGameData && ToolbarButtons[0]) this.LoadGameData(); } public async void LoadGameData() { - if (rom == null || rom.Path == null) return; + if (rom == null || rom.FilePath == null) return; try { - gameData = new GameData(); - var Retrieved = await Task.FromResult(gameData.Get(platform, rom.Path)); - if (Retrieved) + var gameData = await Task.FromResult(rom.GetData(platform, rom.FilePath)); + bool retrieved = gameData != (null, null, null, null, null); + + if (retrieved) { // Set banner title - banner_title.Text = gameData.CleanTitle ?? banner_title.Text; + banner_title.Text = rom.CleanTitle ?? banner_title.Text; // Set channel title text - if (gameData.CleanTitle != null) + if (rom.CleanTitle != null) { - var text = gameData.CleanTitle.Replace("\r", "").Split('\n'); + var text = rom.CleanTitle.Replace("\r", "").Split('\n'); if (text[0].Length <= channel_title.MaxLength) { channel_title.Text = text[0]; } } // Set image - if (gameData.ImgURL != null) { LoadImage(gameData.ImgURL); } + if (gameData.Image != null) { LoadImage(gameData.Image); } // Set year and players released.Value = !string.IsNullOrEmpty(gameData.Year) ? int.Parse(gameData.Year) : released.Value; players.Value = !string.IsNullOrEmpty(gameData.Players) ? int.Parse(gameData.Players) : players.Value; } - if (Retrieved && LinkSaveData.Checked) linkSaveDataTitle(); - else if (gameData?.CleanTitle != null && channel_title.TextLength <= save_data_title.MaxLength) save_data_title.Text = channel_title.Text; + if (retrieved && LinkSaveData.Checked) linkSaveDataTitle(); + else if (rom.CleanTitle != null && channel_title.TextLength <= save_data_title.MaxLength) save_data_title.Text = channel_title.Text; // Show message if partially failed to retrieve data - if (Retrieved && (gameData.Title == null || gameData.Players == null || gameData.Year == null || gameData.ImgURL == null)) + if (retrieved && (gameData.Title == null || gameData.Players == null || gameData.Year == null || gameData.Image == null)) MessageBox.Show(Program.Lang.Msg(4)); - else if (!Retrieved) System.Media.SystemSounds.Beep.Play(); - + else if (!retrieved) System.Media.SystemSounds.Beep.Play(); } catch (Exception ex) { @@ -1227,7 +1228,7 @@ public void ForwarderCreator(string path) { Forwarder f = new Forwarder() { - ROM = rom.Path, + ROM = rom.FilePath, ID = _tID, Emulator = injection_methods.SelectedItem.ToString(), Storage = FStorage_USB.Checked ? Forwarder.Storages.USB : Forwarder.Storages.SD @@ -1248,7 +1249,7 @@ public void ForwarderCreator(string path) public void FlashInject() { Injectors.Flash.Settings = contentOptions; - outWad = Injectors.Flash.Inject(outWad, rom.Path, _saveDataTitle, img); + outWad = Injectors.Flash.Inject(outWad, rom.FilePath, _saveDataTitle, img); } public void WiiVCInject() diff --git a/FriishProduce/ProjectForm.resx b/FriishProduce/ProjectForm.resx index fcb310e..c25cdbc 100644 --- a/FriishProduce/ProjectForm.resx +++ b/FriishProduce/ProjectForm.resx @@ -142,7 +142,7 @@ NoControl - 7, 230 + 7, 227 130, 13 @@ -169,7 +169,7 @@ null - 9, 248 + 9, 245 491, 21 @@ -196,7 +196,7 @@ NoControl - 9, 291 + 9, 290 67, 17 @@ -226,7 +226,7 @@ NoControl - 9, 273 + 9, 271 91, 17 @@ -1965,6 +1965,21 @@ 240, 17 + + NoControl + + + 10, 19 + + + 490, 200 + + + StretchImage + + + 41 + bannerPreview @@ -2004,33 +2019,6 @@ 1 - - NoControl - - - 10, 19 - - - 490, 205 - - - StretchImage - - - 41 - - - bannerPreview - - - System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox5 - - - 1 - System @@ -2061,24 +2049,6 @@ 3 - - NoControl - - - 14, 48 - - - 131, 21 - - - 24 - - - manual_type - - - TopRight - manual_type @@ -2118,6 +2088,36 @@ 7 + + NoControl + + + 14, 48 + + + 131, 21 + + + 24 + + + manual_type + + + TopRight + + + manual_type + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox4 + + + 0 + True diff --git a/FriishProduce/_classes/Creators/WiiVC/NEO.cs b/FriishProduce/_classes/Creators/WiiVC/NEO.cs index 26200eb..daf8701 100644 --- a/FriishProduce/_classes/Creators/WiiVC/NEO.cs +++ b/FriishProduce/_classes/Creators/WiiVC/NEO.cs @@ -36,7 +36,7 @@ protected override void Load() MainContentIndex = WAD.Contents[6].Length > WAD.Contents[5].Length ? 6 : 5; else MainContentIndex = 5; - ZIP = ZipFile.Read(new MemoryStream(File.ReadAllBytes(ROM.Path))); + ZIP = ZipFile.Read(new MemoryStream(File.ReadAllBytes(ROM.FilePath))); base.Load(); } diff --git a/FriishProduce/_classes/Databases/GameData.cs b/FriishProduce/_classes/Databases/GameData.cs deleted file mode 100644 index 240a193..0000000 --- a/FriishProduce/_classes/Databases/GameData.cs +++ /dev/null @@ -1,256 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.IO.Hashing; -using System.Net; -using System.Text; -using System.Text.RegularExpressions; - -namespace FriishProduce -{ - [Serializable] - public class GameData - { - private string title { get; set; } - public string Title { get => title; } - public string CleanTitle - { - get - { - if (Title == null) return null; - - string title = Regex.Replace(Title?.Replace(": ", Environment.NewLine).Replace(" - ", Environment.NewLine), @"\((.*?)\)", ""); - if (title.Contains(", The")) title = "The " + title.Replace(", The", string.Empty); - return title.Trim(); - } - } - - private string crc32 { get; set; } - private string serial { get; set; } - - private string year { get; set; } - public string Year { get => year; } - - private string players { get; set; } - public string Players { get => players; } - - private string setImgURL(string console, string title, bool useGitHub) - { - return !useGitHub ? "https://thumbnails.libretro.com/" + Uri.EscapeUriString(console) + "/Named_Titles/" + Uri.EscapeUriString(title) + ".png" - : "https://github.com/libretro/libretro-thumbnails/blob/master/" + Uri.EscapeUriString(console) + "/Named_Titles/" + Uri.EscapeUriString(title) + ".png?raw=true"; - } - private string imgURL { get; set; } - public string ImgURL { get => imgURL; } - - private readonly string db_base = "https://raw.githubusercontent.com/libretro/libretro-database/master/metadat/"; - - private string db_name(Platform platform) - { - Dictionary names = new Dictionary - { - { "Nintendo - Nintendo Entertainment System", Platform.NES }, - { "Nintendo - Super Nintendo Entertainment System", Platform.SNES }, - { "Nintendo - Nintendo 64", Platform.N64 }, - { "Sega - Master System - Mark III", Platform.SMS }, - { "Sega - Mega Drive - Genesis", Platform.SMD }, - { "NEC - PC Engine - TurboGrafx 16", Platform.PCE }, - { "NEC - PC Engine SuperGrafx", Platform.PCE }, - { "NEC - PC Engine CD - TurboGrafx-CD", Platform.PCECD }, - { "MAME", Platform.NEO }, - { "Microsoft - MSX", Platform.MSX }, - { "Microsoft - MSX2", Platform.MSX }, - { "Microsoft - MSX 2", Platform.MSX }, - { "Nintendo - Game Boy", Platform.GB }, - { "Nintendo - Game Boy Color", Platform.GBC }, - { "Nintendo - Game Boy Advance", Platform.GBA }, - { "Nintendo - GameCube", Platform.GCN }, - { "Sega - 32X", Platform.S32X }, - { "Sega - Mega-CD - Sega CD", Platform.SMCD }, - { "Sony - PlayStation", Platform.PSX }, - }; - - foreach (KeyValuePair item in names) - { - if (item.Value == platform) - { - return item.Key; - } - } - - return null; - } - - private bool db_search(string path, Platform platform, int type) - { - #region Establish URL of database entry - string URL = null; - string db_name = this.db_name(platform); - - if (db_name != null) - { - switch (platform) - { - case Platform.PCECD: - case Platform.GCN: - case Platform.SMCD: - case Platform.PSX: - URL = db_base + "redump/" + Uri.EscapeUriString(db_name) + ".dat"; - break; - - case Platform.NEO: - URL = db_base + "mame-split/" + Uri.EscapeUriString(db_name) + " 2016.dat"; - break; - - default: - URL = db_base + "releaseyear/" + Uri.EscapeUriString(db_name) + ".dat"; - break; - } - - switch (type) - { - case 1: // developer - URL = db_base + "developer/" + Uri.EscapeUriString(db_name) + ".dat"; - break; - - case 2: // maxusers - URL = db_base + "maxusers/" + Uri.EscapeUriString(db_name) + ".dat"; - break; - - case 3: // serial - URL = db_base + "serial/" + Uri.EscapeUriString(db_name) + ".dat"; - break; - } - } - #endregion - - if (URL != null) - { - try - { - using (WebClient c = new WebClient()) - { - // Scan retrieved database - // **************** - var db_lines = Encoding.UTF8.GetString(Web.Get(URL)).Split(Environment.NewLine.ToCharArray()); - - for (int i = 5; i < db_lines.Length; i++) - { - int searchMethod = serial != null && db_lines[i].ToLower().Contains(serial?.ToLower()) ? 2 - : db_lines[i].ToLower().Contains(Path.GetFileName(path).ToLower()) || db_lines[i].ToLower().Contains(crc32) ? 1 - : 0; - - if (searchMethod != 0) - { - int x = i; - while ((searchMethod == 1 && x > i - 10) || (searchMethod == 2 && x < i + 10)) - { - string line = db_lines[x]; - - if (title == null && (db_lines[x].Contains("name \"") || db_lines[x].Contains("comment \"")) && !db_lines[x].Contains("rom (")) - { - title = db_lines[x].Replace("\t", "").Replace("name \"", "").Replace("comment \"", "").Replace("\"", ""); - } - - if (serial == null && db_lines[x].Contains("serial ")) - { - serial = db_lines[x].Substring(db_lines[x].IndexOf("serial ")).Replace("serial ", "").TrimStart('\"', ' ', '\t', ')').TrimEnd('\"', ' ', '\t', ')'); - } - - if (db_lines[x].Contains("releaseyear")) - { - year = db_lines[x].Trim().Replace("releaseyear \"", "").TrimStart('\"', ' ', '\t', ')').TrimEnd('\"', ' ', '\t', ')'); - } - - if (db_lines[x].Contains("users ")) - { - players = db_lines[x].Replace("users ", "").TrimStart('\"', ' ', '\t', ')').TrimEnd('\"', ' ', '\t', ')'); - } - - if (searchMethod == 1) x--; else x++; - } - - return true; - } - } - } - } - catch { return false; } - } - - return false; - } - - /// - /// Gets any game metadata that is available for the file based on its CRC32 reading hash, including the software title, year, players, and title image URL. - /// - /// - /// - public bool Get(Platform platform, string path) - { - title = null; - year = null; - players = null; - serial = null; - imgURL = null; - - bool isDisc = platform == Platform.PCECD || platform == Platform.GCN || platform == Platform.SMCD || platform == Platform.PSX; - if (isDisc) - { - if (Path.GetExtension(path).ToLower() == ".cue") - foreach (var item in Directory.EnumerateFiles(Path.GetDirectoryName(path))) - if (Path.GetExtension(item).ToLower() == ".bin" && Path.GetFileNameWithoutExtension(path).ToLower() == Path.GetFileNameWithoutExtension(item).ToLower()) - { - path = item; - } - - if (Path.GetExtension(path).ToLower() != ".bin") goto NotFound; - } - - using (var file = File.OpenRead(path)) - { - var crc = new Crc32(); - crc.Append(file); - var hash_array = crc.GetCurrentHash(); - Array.Reverse(hash_array); - crc32 = BitConverter.ToString(hash_array).Replace("-", "").ToLower(); - } - - if (!Web.InternetTest("https://gbatemp.net/")) goto NotFound; - - db_search(path, platform, 0); - if (title == null || year == null) db_search(path, platform, 1); - - if (title != null) - { - db_search(path, platform, 2); - - #region Get image - imgURL = setImgURL - ( - db_name(platform), - title.Replace('/', '_'), - Properties.Settings.Default.gamedata_source_image == 2 ? true : Properties.Settings.Default.gamedata_source_image == 1 ? false : !Web.InternetTest("https://thumbnails.libretro.com/README.md") - ); - - try - { - using (WebClient c = new WebClient()) - using (Stream s = c.OpenRead(imgURL)) - { - // Do something - } - } - catch { imgURL = null; } - #endregion - - return true; - } - - else goto NotFound; - - NotFound: - System.Media.SystemSounds.Beep.Play(); - return false; - } - } -} diff --git a/FriishProduce/_classes/Files/ROM/RPGM.cs b/FriishProduce/_classes/Files/ROM/RPGM.cs index 802ace3..4512f7e 100644 --- a/FriishProduce/_classes/Files/ROM/RPGM.cs +++ b/FriishProduce/_classes/Files/ROM/RPGM.cs @@ -8,13 +8,16 @@ public string GetTitle(string path = null) { if (path == null) return null; - foreach (var file in Directory.EnumerateFiles(System.IO.Path.GetDirectoryName(path), "*.*", SearchOption.AllDirectories)) + foreach (var file in Directory.EnumerateFiles(Path.GetDirectoryName(path), "*.*", SearchOption.AllDirectories)) { - if (System.IO.Path.GetFileName(file).ToLower() == "rpg_rt.ini") + if (Path.GetFileName(file).ToLower() == "rpg_rt.ini") { foreach (var line in File.ReadAllLines(file)) { - if (line.ToLower().StartsWith("gametitle=")) return line.Substring("GameTitle=".Length); + if (line.ToLower().StartsWith("gametitle=")) + { + return line.Substring("GameTitle=".Length); + } } } } diff --git a/FriishProduce/_classes/Files/ROM/_base.cs b/FriishProduce/_classes/Files/ROM/_base.cs index b1f0957..8ff6ce7 100644 --- a/FriishProduce/_classes/Files/ROM/_base.cs +++ b/FriishProduce/_classes/Files/ROM/_base.cs @@ -1,6 +1,11 @@ using Ionic.Zip; using System; +using System.Collections.Generic; using System.IO; +using System.IO.Hashing; +using System.Net; +using System.Text; +using System.Text.RegularExpressions; namespace FriishProduce { @@ -8,7 +13,7 @@ namespace FriishProduce public abstract class ROM { private string _rom; - public string Path + public string FilePath { get => _rom; @@ -68,8 +73,11 @@ public virtual bool CheckValidity(string path) return true; } - public virtual bool CheckZIPValidity(string path, string[] strings, bool searchEndingOnly, bool forceLowercase) + public virtual bool CheckZIPValidity(string[] strings, bool searchEndingOnly, bool forceLowercase, string path = null) { + if (path == null && FilePath != null) path = FilePath; + if (!File.Exists(path)) return true; + using (ZipFile ZIP = ZipFile.Read(path)) { int applicable = 0; @@ -92,10 +100,10 @@ public virtual bool CheckZIPValidity(string path, string[] strings, bool searchE } } - public virtual bool CheckZIPValidity(string[] strings, bool searchEndingOnly, bool forceLowercase) => CheckZIPValidity(Path, strings, searchEndingOnly, forceLowercase); - - public bool CheckSize(int length) + public bool CheckSize(int length = 0) { + if (length == 0) length = MaxSize; + if (Bytes.Length > length && MaxSize > 0) { bool isMB = length >= 1048576; @@ -107,8 +115,6 @@ public bool CheckSize(int length) return true; } - public bool CheckSize() => CheckSize(MaxSize); - public void Patch(string filePath) { if (!File.Exists(filePath) || string.IsNullOrWhiteSpace(filePath)) return; @@ -139,5 +145,244 @@ public void Patch(string filePath) patched = Out; } + + /// + /// Gets any game metadata that is available for the file based on its CRC32 reading hash, including the software title, year, players, and title image URL. + /// + /// + /// + public (string Title, string Year, string Players, string Serial, string Image) GetData(Platform platform, string path) + { + string crc32 = null; + string title = null; + string year = null; + string players = null; + string serial = null; + string imgURL = null; + + bool isDisc = platform == Platform.PCECD || platform == Platform.GCN || platform == Platform.SMCD || platform == Platform.PSX; + if (isDisc) + { + if (Path.GetExtension(path).ToLower() == ".cue") + foreach (var item in Directory.EnumerateFiles(Path.GetDirectoryName(path))) + if (Path.GetExtension(item).ToLower() == ".bin" && Path.GetFileNameWithoutExtension(path).ToLower() == Path.GetFileNameWithoutExtension(item).ToLower()) + { + path = item; + } + + if (Path.GetExtension(path).ToLower() != ".bin") goto NotFound; + } + + using (var file = File.OpenRead(path)) + { + var crc = new Crc32(); + crc.Append(file); + var hash_array = crc.GetCurrentHash(); + Array.Reverse(hash_array); + crc32 = BitConverter.ToString(hash_array).Replace("-", "").ToLower(); + } + + if (!Web.InternetTest("https://gbatemp.net/")) goto NotFound; + + var values = db_search(path, crc32, platform, 0); + (serial, title, year, players) = (values.serial ?? serial, values.title ?? title, values.year ?? year, values.players ?? players); + + if (title == null || year == null) + { + values = db_search(path, crc32, platform, 1); + (serial, title, year, players) = (values.serial ?? serial, values.title ?? title, values.year ?? year, values.players ?? players); + } + + if (title != null) + { + CleanTitle = Regex.Replace(title?.Replace(": ", Environment.NewLine).Replace(" - ", Environment.NewLine), @"\((.*?)\)", ""); + if (CleanTitle.Contains(", The")) CleanTitle = "The " + CleanTitle.Replace(", The", string.Empty); + CleanTitle = CleanTitle.Trim(); + + values = db_search(path, crc32, platform, 2); + (serial, title, year, players) = (values.serial ?? serial, values.title ?? title, values.year ?? year, values.players ?? players); + + #region Get image + imgURL = setImgURL + ( + db_name(platform), + title.Replace('/', '_'), + Properties.Settings.Default.gamedata_source_image == 2 ? true : Properties.Settings.Default.gamedata_source_image == 1 ? false : !Web.InternetTest("https://thumbnails.libretro.com/README.md") + ); + + try + { + using (WebClient c = new WebClient()) + using (Stream s = c.OpenRead(imgURL)) + { + // Do something + } + } + catch { imgURL = null; } + #endregion + + CleanTitle = CleanTitle.Trim(); + return (title, year, players, serial, imgURL); + } + + else goto NotFound; + + NotFound: + System.Media.SystemSounds.Beep.Play(); + return (null, null, null, null, null); + } + + public string CleanTitle { get; protected set; } + + #region -- Private gamedata variables and functions -- + private readonly string db_base = "https://raw.githubusercontent.com/libretro/libretro-database/master/metadat/"; + + private string setImgURL(string console, string title, bool useGitHub) + { + return !useGitHub ? "https://thumbnails.libretro.com/" + Uri.EscapeUriString(console) + "/Named_Titles/" + Uri.EscapeUriString(title) + ".png" + : "https://github.com/libretro/libretro-thumbnails/blob/master/" + Uri.EscapeUriString(console) + "/Named_Titles/" + Uri.EscapeUriString(title) + ".png?raw=true"; + } + + private string db_name(Platform platform) + { + Dictionary names = new Dictionary + { + { "Nintendo - Nintendo Entertainment System", Platform.NES }, + { "Nintendo - Super Nintendo Entertainment System", Platform.SNES }, + { "Nintendo - Nintendo 64", Platform.N64 }, + { "Sega - Master System - Mark III", Platform.SMS }, + { "Sega - Mega Drive - Genesis", Platform.SMD }, + { "NEC - PC Engine - TurboGrafx 16", Platform.PCE }, + { "NEC - PC Engine SuperGrafx", Platform.PCE }, + { "NEC - PC Engine CD - TurboGrafx-CD", Platform.PCECD }, + { "MAME", Platform.NEO }, + { "Microsoft - MSX", Platform.MSX }, + { "Microsoft - MSX2", Platform.MSX }, + { "Microsoft - MSX 2", Platform.MSX }, + { "Nintendo - Game Boy", Platform.GB }, + { "Nintendo - Game Boy Color", Platform.GBC }, + { "Nintendo - Game Boy Advance", Platform.GBA }, + { "Nintendo - GameCube", Platform.GCN }, + { "Sega - 32X", Platform.S32X }, + { "Sega - Mega-CD - Sega CD", Platform.SMCD }, + { "Sony - PlayStation", Platform.PSX }, + }; + + foreach (KeyValuePair item in names) + { + if (item.Value == platform) + { + return item.Key; + } + } + + return null; + } + + private (string serial, string title, string year, string players) db_search(string path, string crc32, Platform platform, int type) + { + string serial = null; + string title = null; + string year = null; + string players = null; + + #region Establish URL of database entry + string URL = null; + string db_name = this.db_name(platform); + + if (db_name != null) + { + switch (platform) + { + case Platform.PCECD: + case Platform.GCN: + case Platform.SMCD: + case Platform.PSX: + URL = db_base + "redump/" + Uri.EscapeUriString(db_name) + ".dat"; + break; + + case Platform.NEO: + URL = db_base + "mame-split/" + Uri.EscapeUriString(db_name) + " 2016.dat"; + break; + + default: + URL = db_base + "releaseyear/" + Uri.EscapeUriString(db_name) + ".dat"; + break; + } + + switch (type) + { + case 1: // developer + URL = db_base + "developer/" + Uri.EscapeUriString(db_name) + ".dat"; + break; + + case 2: // maxusers + URL = db_base + "maxusers/" + Uri.EscapeUriString(db_name) + ".dat"; + break; + + case 3: // serial + URL = db_base + "serial/" + Uri.EscapeUriString(db_name) + ".dat"; + break; + } + } + #endregion + + if (URL != null) + { + try + { + using (WebClient c = new WebClient()) + { + // Scan retrieved database + // **************** + var db_lines = Encoding.UTF8.GetString(Web.Get(URL)).Split(Environment.NewLine.ToCharArray()); + + for (int i = 5; i < db_lines.Length; i++) + { + int searchMethod = serial != null && db_lines[i].ToLower().Contains(serial?.ToLower()) ? 2 + : db_lines[i].ToLower().Contains(Path.GetFileName(path).ToLower()) || db_lines[i].ToLower().Contains(crc32) ? 1 + : 0; + + if (searchMethod != 0) + { + int x = i; + while ((searchMethod == 1 && x > i - 10) || (searchMethod == 2 && x < i + 10)) + { + string line = db_lines[x]; + + if (title == null && (db_lines[x].Contains("name \"") || db_lines[x].Contains("comment \"")) && !db_lines[x].Contains("rom (")) + { + title = db_lines[x].Replace("\t", "").Replace("name \"", "").Replace("comment \"", "").Replace("\"", ""); + } + + if (serial == null && db_lines[x].Contains("serial ")) + { + serial = db_lines[x].Substring(db_lines[x].IndexOf("serial ")).Replace("serial ", "").TrimStart('\"', ' ', '\t', ')').TrimEnd('\"', ' ', '\t', ')'); + } + + if (db_lines[x].Contains("releaseyear")) + { + year = db_lines[x].Trim().Replace("releaseyear \"", "").TrimStart('\"', ' ', '\t', ')').TrimEnd('\"', ' ', '\t', ')'); + } + + if (db_lines[x].Contains("users ")) + { + players = db_lines[x].Replace("users ", "").TrimStart('\"', ' ', '\t', ')').TrimEnd('\"', ' ', '\t', ')'); + } + + if (searchMethod == 1) x--; else x++; + } + + return (serial, title, year, players); + } + } + } + } + catch { return (null, null, null, null); } + } + + return (null, null, null, null); + } + #endregion } } diff --git a/FriishProduce/_classes/Program/Project.cs b/FriishProduce/_classes/Program/Project.cs index 50195e5..7ece56d 100644 --- a/FriishProduce/_classes/Program/Project.cs +++ b/FriishProduce/_classes/Program/Project.cs @@ -12,7 +12,6 @@ public class Project public string WADFile { get; set; } public string Patch { get; set; } public (int Type, string File) Manual { get; set; } - public GameData GameData { get; set; } public System.Drawing.Bitmap Img { get; set; }