Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic launch-option functionality #82

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions VG Music Studio/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Kermalis.VGMusicStudio.Core;
using Kermalis.VGMusicStudio.Core;
using Kermalis.VGMusicStudio.Properties;
using Kermalis.VGMusicStudio.UI;
using System;
Expand All @@ -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");
Expand All @@ -24,6 +24,7 @@ private static void Main()
return;
}
Application.EnableVisualStyles();
MainForm.Instance.SetLaunchArgs(args);
Application.Run(MainForm.Instance);
}
}
Expand Down
264 changes: 179 additions & 85 deletions VG Music Studio/UI/MainForm.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Kermalis.VGMusicStudio.Core;
using Kermalis.VGMusicStudio.Core;
using Kermalis.VGMusicStudio.Properties;
using Kermalis.VGMusicStudio.Util;
using Microsoft.WindowsAPICodePack.Dialogs;
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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)
{
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
{
Expand All @@ -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
Expand All @@ -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);
}
}

Expand Down