mirror of
https://github.com/kwsch/NHSE.git
synced 2026-07-17 00:31:10 -05:00
Change folderbrowser to openfile, select main instead
- Open file => main.dat will load the parent folder - Allow dropping of main.dat (loads the parent folder) - Shift clicking still behaves the same way - Handle command line arguments to auto-load savedata from arg indexes >=1 Closes #37 ; unsure on licensing & mono compatibility, less dependencies
This commit is contained in:
parent
92959fba6a
commit
74f6157fa3
2
NHSE.WinForms/Main.Designer.cs
generated
2
NHSE.WinForms/Main.Designer.cs
generated
|
|
@ -38,7 +38,7 @@ private void InitializeComponent()
|
|||
this.B_Open.Name = "B_Open";
|
||||
this.B_Open.Size = new System.Drawing.Size(306, 121);
|
||||
this.B_Open.TabIndex = 0;
|
||||
this.B_Open.Text = "Open Folder";
|
||||
this.B_Open.Text = "Open main.dat\r\n\r\nOr...\r\n\r\nDrag&&Drop folder here!";
|
||||
this.B_Open.UseVisualStyleBackColor = true;
|
||||
this.B_Open.Click += new System.EventHandler(this.Menu_Open);
|
||||
//
|
||||
|
|
|
|||
|
|
@ -20,6 +20,10 @@ public Main()
|
|||
WindowState = FormWindowState.Minimized;
|
||||
Show();
|
||||
WindowState = FormWindowState.Normal;
|
||||
|
||||
var args = Environment.GetCommandLineArgs();
|
||||
for (int i = 1; i < args.Length; i++)
|
||||
Open(args[i]);
|
||||
}
|
||||
|
||||
private static void Open(HorizonSave file) => new Editor(file).Show();
|
||||
|
|
@ -56,9 +60,15 @@ private void Menu_Open(object sender, EventArgs e)
|
|||
return;
|
||||
}
|
||||
}
|
||||
using var fbd = new FolderBrowserDialog();
|
||||
if (fbd.ShowDialog() == DialogResult.OK)
|
||||
Open(fbd.SelectedPath);
|
||||
|
||||
using var ofd = new OpenFileDialog
|
||||
{
|
||||
Title = "Open main.dat ...",
|
||||
Filter = "New Horizons Save File (main.dat)|main.dat",
|
||||
FileName = "main.dat",
|
||||
};
|
||||
if (ofd.ShowDialog() == DialogResult.OK)
|
||||
Open(ofd.FileName);
|
||||
}
|
||||
|
||||
private static void Open(string path)
|
||||
|
|
@ -67,7 +77,7 @@ private static void Open(string path)
|
|||
try
|
||||
#endif
|
||||
{
|
||||
OpenSaveFile(path);
|
||||
OpenFileOrPath(path);
|
||||
}
|
||||
#if !DEBUG
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
|
|
@ -79,6 +89,25 @@ private static void Open(string path)
|
|||
#endif
|
||||
}
|
||||
|
||||
private static void OpenFileOrPath(string path)
|
||||
{
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
OpenSaveFile(path);
|
||||
return;
|
||||
}
|
||||
|
||||
var dir = Path.GetDirectoryName(path);
|
||||
if (dir is null || !Directory.Exists(dir)) // ya never know
|
||||
{
|
||||
WinFormsUtil.Error("Unable to open the folder that contains the save file.",
|
||||
"Try moving it to another location and opening from there.");
|
||||
return;
|
||||
}
|
||||
|
||||
OpenSaveFile(dir);
|
||||
}
|
||||
|
||||
private static void OpenSaveFile(string path)
|
||||
{
|
||||
var file = new HorizonSave(path);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user