Skip to content

Commit

Permalink
Merge pull request #56 from axel7083/feature/start-from-editor
Browse files Browse the repository at this point in the history
feat: allowing to config emulator executable to start rom
  • Loading branch information
axel7083 authored Mar 16, 2024
2 parents 2528359 + c4f9459 commit 25edf95
Show file tree
Hide file tree
Showing 9 changed files with 272 additions and 34 deletions.
12 changes: 12 additions & 0 deletions Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions SM64DSe.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,12 @@
<Compile Include="src\ui\dialogs\DropdownDialog.Designer.cs">
<DependentUpon>DropdownDialog.cs</DependentUpon>
</Compile>
<Compile Include="src\ui\dialogs\RunningDialog.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="src\ui\dialogs\RunningDialog.Designer.cs">
<DependentUpon>RunningDialog.cs</DependentUpon>
</Compile>
<Compile Include="src\ui\dls\DL Editor.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -592,6 +598,9 @@
<EmbeddedResource Include="src\ui\CodeFixerForm.resx">
<DependentUpon>CodeFixerForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="src\ui\dialogs\RunningDialog.resx">
<DependentUpon>RunningDialog.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="src\ui\dls\DL Editor.resx">
<DependentUpon>DL Editor.cs</DependentUpon>
</EmbeddedResource>
Expand Down
23 changes: 22 additions & 1 deletion src/core/NitroROM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ You should have received a copy of the GNU General Public License along
using Newtonsoft.Json;
using System.Diagnostics;
using System.Windows.Forms;
using SM64DSe.ui.dialogs;

namespace SM64DSe
{
Expand Down Expand Up @@ -491,7 +492,27 @@ void OnROMBuilt(object sender, EventArgs e) {
}

public static void RunROM() {
BuildROM(true);
if (Program.m_IsROMFolder)
{
BuildROM(true);
return;
}

// Stop read write
Program.m_ROM.EndRW();

string executable = Properties.Settings.Default.EmulatorExecutablePath;
if (executable == null || executable.Trim() == "")
{
throw new Exception("Executable not found");
}

if (!File.Exists(executable))
{
throw new Exception("executable file does not exist.");
}

new RunningDialog(executable).ShowDialog();
}

public static FileStream GetExtractedStream(string path) {
Expand Down
6 changes: 5 additions & 1 deletion src/ui/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ private void LoadROM(string filename)
btnMore.Enabled = true;
extractROMButton.Visible = true;
btnBuildROM.Visible = false;
btnRunROM.Visible = false;

// Show run button if emulator executable is defined
string executable = Properties.Settings.Default.EmulatorExecutablePath;
btnRunROM.Visible = executable != null && executable.Trim() != "";

btnLZCompressWithHeader.Enabled = true;
btnLZDecompressWithHeader.Enabled = true;
btnLZForceCompression.Enabled = true;
Expand Down
124 changes: 92 additions & 32 deletions src/ui/SettingsForm.Designer.cs

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions src/ui/SettingsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ private void SettingsForm_Load(object sender, EventArgs e)
chkRememberLastUsedModelImportationSettings.Checked = Properties.Settings.Default.RememberLastUsedModelImportationSettings;
chkRememberLastUsedCollisionTypeAssignments.Checked = Properties.Settings.Default.RememberMaterialCollisionTypeAssignments;
chkDisableTextureSizeWarning.Checked = Properties.Settings.Default.DisableTextureSizeWarning;
emulatorExecutablePath.Text = Properties.Settings.Default.EmulatorExecutablePath;
}

private void btnOk_Click(object sender, EventArgs e)
Expand All @@ -54,7 +55,16 @@ private void btnOk_Click(object sender, EventArgs e)
Properties.Settings.Default.RememberLastUsedModelImportationSettings = chkRememberLastUsedModelImportationSettings.Checked;
Properties.Settings.Default.RememberMaterialCollisionTypeAssignments = chkRememberLastUsedCollisionTypeAssignments.Checked;
Properties.Settings.Default.DisableTextureSizeWarning = chkDisableTextureSizeWarning.Checked;
Properties.Settings.Default.EmulatorExecutablePath = this.emulatorExecutablePath.Text;
Properties.Settings.Default.Save();
}

private void browserBtn_Click(object sender, EventArgs e)
{
if (this.openFileExe.ShowDialog() == DialogResult.OK)
{
emulatorExecutablePath.Text = this.openFileExe.FileName;
}
}
}
}
3 changes: 3 additions & 0 deletions src/ui/SettingsForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="openFileExe.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
Expand Down
81 changes: 81 additions & 0 deletions src/ui/dialogs/RunningDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions src/ui/dialogs/RunningDialog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Diagnostics;
using System.Windows.Forms;

namespace SM64DSe.ui.dialogs
{
public partial class RunningDialog : Form
{
private string executable;
public RunningDialog(string executable)
{
this.executable = executable;
InitializeComponent();
}

protected override void OnShown(EventArgs e)
{
base.OnShown(e);
RunProcessAsync();
}

private void RunProcessAsync()
{
Process process = new Process();
process.StartInfo.FileName = this.executable;
process.StartInfo.Arguments = Program.m_ROMPath;
process.EnableRaisingEvents = true;

process.Exited += (sender, e) =>
{
this.Close();
process.Dispose();
};

process.Start();
}
}
}

0 comments on commit 25edf95

Please sign in to comment.