From cf436a48a7fcc867038c816693e0f263fb03b4aa Mon Sep 17 00:00:00 2001 From: Dassu Date: Fri, 6 Nov 2020 21:33:40 +1100 Subject: [PATCH 1/2] Added basic launch options functionality --- VG Music Studio/UI/MainForm.cs | 264 ++++++++++++++++++++++----------- 1 file changed, 179 insertions(+), 85 deletions(-) diff --git a/VG Music Studio/UI/MainForm.cs b/VG Music Studio/UI/MainForm.cs index 761394f..2ab6a77 100644 --- a/VG Music Studio/UI/MainForm.cs +++ b/VG Music Studio/UI/MainForm.cs @@ -1,4 +1,4 @@ -using Kermalis.VGMusicStudio.Core; +using Kermalis.VGMusicStudio.Core; using Kermalis.VGMusicStudio.Properties; using Kermalis.VGMusicStudio.Util; using Microsoft.WindowsAPICodePack.Dialogs; @@ -21,6 +21,8 @@ internal class MainForm : ThemedForm public static MainForm Instance { get; } = new MainForm(); + private string[] _launchArgs; + public readonly bool[] PianoTracks = new bool[SongInfoControl.SongInfo.MaxTracks]; private bool _playlistPlaying; @@ -147,6 +149,7 @@ private MainForm() MinimumSize = new Size(_intendedWidth + (Width - _intendedWidth), _intendedHeight + (Height - _intendedHeight)); // Borders Resize += OnResize; Text = Utils.ProgramName; + Shown += MainForm_Shown; // Taskbar Buttons if (TaskbarManager.IsPlatformSupported) @@ -163,6 +166,76 @@ private MainForm() OnResize(null, null); } + public void SetLaunchArgs(string[] args) + { + _launchArgs = args; + } + + private void MainForm_Shown(object sender, EventArgs e) + { + string romfilename = null; + string engine = null; + long songID = -1; + if (_launchArgs != null && _launchArgs.Length > 0) + { + for (int i = 0; i < _launchArgs.Length; i++) + { + switch (_launchArgs[i].ToLower()) + { + case "-mp2k": + case "-dse": + case "-alphadream": + case "-sdat": + engine = _launchArgs[i]; + break; + case "-filename": + if (i + 1 > _launchArgs.Length) goto default; + romfilename = _launchArgs[i + 1]; + i++; + break; + case "-songid": + if (i + 1 > _launchArgs.Length) goto default; + + if (!long.TryParse(_launchArgs[i + 1], out songID)) + long.TryParse(_launchArgs[i + 1], System.Globalization.NumberStyles.HexNumber, new System.Globalization.CultureInfo("en-US"), out songID); + i++; + break; + default: + FlexibleMessageBox.Show(string.Format("Unhandled launch command {0}", _launchArgs[i])); + break; + } + } + } + + bool success = false; + if (romfilename != null && romfilename.Length > 0) + { + switch (engine) + { + case "-mp2k": + success = OpenMP2K(romfilename); + break; + case "-dse": + success = OpenDSE(romfilename); + break; + case "-alphadream": + success = OpenAlphaDream(romfilename); + break; + case "-sdat": + success = OpenSDAT(romfilename); + break; + case null: + default: + break; + } + } + else success = false; + + if (success && songID > -1) + { + SetAndLoadSong(songID); + } + } private void VolumeBar_ValueChanged(object sender, EventArgs e) { @@ -315,6 +388,32 @@ private void EndCurrentPlaylist(object sender, EventArgs e) } } + private bool OpenDSE(string filename) + { + DisposeEngine(); + bool success; + try + { + new Engine(Engine.EngineType.NDS_DSE, filename); + success = true; + } + catch (Exception ex) + { + FlexibleMessageBox.Show(ex, Strings.ErrorOpenDSE); + success = false; + } + if (success) + { + var config = (Core.NDS.DSE.Config)Engine.Instance.Config; + FinishLoading(config.BGMFiles.Length); + _songNumerical.Visible = false; + _exportDLSItem.Visible = false; + _exportMIDIItem.Visible = false; + _exportSF2Item.Visible = false; + } + return success; + } + private void OpenDSE(object sender, EventArgs e) { var d = new CommonOpenFileDialog @@ -324,29 +423,34 @@ private void OpenDSE(object sender, EventArgs e) }; if (d.ShowDialog() == CommonFileDialogResult.Ok) { - DisposeEngine(); - bool success; - try - { - new Engine(Engine.EngineType.NDS_DSE, d.FileName); - success = true; - } - catch (Exception ex) - { - FlexibleMessageBox.Show(ex, Strings.ErrorOpenDSE); - success = false; - } - if (success) - { - var config = (Core.NDS.DSE.Config)Engine.Instance.Config; - FinishLoading(config.BGMFiles.Length); - _songNumerical.Visible = false; - _exportDLSItem.Visible = false; - _exportMIDIItem.Visible = false; - _exportSF2Item.Visible = false; - } + OpenDSE(d.FileName); } } + private bool OpenAlphaDream(string filename) + { + DisposeEngine(); + bool success; + try + { + new Engine(Engine.EngineType.GBA_AlphaDream, File.ReadAllBytes(filename)); + success = true; + } + catch (Exception ex) + { + FlexibleMessageBox.Show(ex, Strings.ErrorOpenAlphaDream); + success = false; + } + if (success) + { + var config = (Core.GBA.AlphaDream.Config)Engine.Instance.Config; + FinishLoading(config.SongTableSizes[0]); + _songNumerical.Visible = true; + _exportDLSItem.Visible = true; + _exportMIDIItem.Visible = false; + _exportSF2Item.Visible = true; + } + return success; + } private void OpenAlphaDream(object sender, EventArgs e) { var d = new CommonOpenFileDialog @@ -356,28 +460,33 @@ private void OpenAlphaDream(object sender, EventArgs e) }; if (d.ShowDialog() == CommonFileDialogResult.Ok) { - DisposeEngine(); - bool success; - try - { - new Engine(Engine.EngineType.GBA_AlphaDream, File.ReadAllBytes(d.FileName)); - success = true; - } - catch (Exception ex) - { - FlexibleMessageBox.Show(ex, Strings.ErrorOpenAlphaDream); - success = false; - } - if (success) - { - var config = (Core.GBA.AlphaDream.Config)Engine.Instance.Config; - FinishLoading(config.SongTableSizes[0]); - _songNumerical.Visible = true; - _exportDLSItem.Visible = true; - _exportMIDIItem.Visible = false; - _exportSF2Item.Visible = true; - } + OpenAlphaDream(d.FileName); + } + } + private bool OpenMP2K(string filename) + { + DisposeEngine(); + bool success; + try + { + new Engine(Engine.EngineType.GBA_MP2K, File.ReadAllBytes(filename)); + success = true; + } + catch (Exception ex) + { + FlexibleMessageBox.Show(ex, Strings.ErrorOpenMP2K); + success = false; } + if (success) + { + var config = (Core.GBA.MP2K.Config)Engine.Instance.Config; + FinishLoading(config.SongTableSizes[0]); + _songNumerical.Visible = true; + _exportDLSItem.Visible = false; + _exportMIDIItem.Visible = true; + _exportSF2Item.Visible = false; + } + return success; } private void OpenMP2K(object sender, EventArgs e) { @@ -388,29 +497,34 @@ private void OpenMP2K(object sender, EventArgs e) }; if (d.ShowDialog() == CommonFileDialogResult.Ok) { - DisposeEngine(); - bool success; - try - { - new Engine(Engine.EngineType.GBA_MP2K, File.ReadAllBytes(d.FileName)); - success = true; - } - catch (Exception ex) - { - FlexibleMessageBox.Show(ex, Strings.ErrorOpenMP2K); - success = false; - } - if (success) - { - var config = (Core.GBA.MP2K.Config)Engine.Instance.Config; - FinishLoading(config.SongTableSizes[0]); - _songNumerical.Visible = true; - _exportDLSItem.Visible = false; - _exportMIDIItem.Visible = true; - _exportSF2Item.Visible = false; - } + OpenMP2K(d.FileName); } } + private bool OpenSDAT(string filename) + { + DisposeEngine(); + bool success; + try + { + new Engine(Engine.EngineType.NDS_SDAT, new Core.NDS.SDAT.SDAT(File.ReadAllBytes(filename))); + success = true; + } + catch (Exception ex) + { + FlexibleMessageBox.Show(ex, Strings.ErrorOpenSDAT); + success = false; + } + if (success) + { + var config = (Core.NDS.SDAT.Config)Engine.Instance.Config; + FinishLoading(config.SDAT.INFOBlock.SequenceInfos.NumEntries); + _songNumerical.Visible = true; + _exportDLSItem.Visible = false; + _exportMIDIItem.Visible = false; + _exportSF2Item.Visible = false; + } + return success; + } private void OpenSDAT(object sender, EventArgs e) { var d = new CommonOpenFileDialog @@ -420,27 +534,7 @@ private void OpenSDAT(object sender, EventArgs e) }; if (d.ShowDialog() == CommonFileDialogResult.Ok) { - DisposeEngine(); - bool success; - try - { - new Engine(Engine.EngineType.NDS_SDAT, new Core.NDS.SDAT.SDAT(File.ReadAllBytes(d.FileName))); - success = true; - } - catch (Exception ex) - { - FlexibleMessageBox.Show(ex, Strings.ErrorOpenSDAT); - success = false; - } - if (success) - { - var config = (Core.NDS.SDAT.Config)Engine.Instance.Config; - FinishLoading(config.SDAT.INFOBlock.SequenceInfos.NumEntries); - _songNumerical.Visible = true; - _exportDLSItem.Visible = false; - _exportMIDIItem.Visible = false; - _exportSF2Item.Visible = false; - } + OpenSDAT(d.FileName); } } From 5313078b4d8496623bcd39ede579074904fd7a4c Mon Sep 17 00:00:00 2001 From: Dassu Date: Fri, 6 Nov 2020 21:34:34 +1100 Subject: [PATCH 2/2] Added basic launch option functionality --- VG Music Studio/Program.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/VG Music Studio/Program.cs b/VG Music Studio/Program.cs index e2e2529..3c92c5f 100644 --- a/VG Music Studio/Program.cs +++ b/VG Music Studio/Program.cs @@ -1,4 +1,4 @@ -using Kermalis.VGMusicStudio.Core; +using Kermalis.VGMusicStudio.Core; using Kermalis.VGMusicStudio.Properties; using Kermalis.VGMusicStudio.UI; using System; @@ -9,7 +9,7 @@ namespace Kermalis.VGMusicStudio internal static class Program { [STAThread] - private static void Main() + private static void Main(string[] args) { #if DEBUG //Debug.GBAGameCodeScan(@"C:\Users\Kermalis\Documents\Emulation\GBA\Games"); @@ -24,6 +24,7 @@ private static void Main() return; } Application.EnableVisualStyles(); + MainForm.Instance.SetLaunchArgs(args); Application.Run(MainForm.Instance); } }