diff --git a/NHSE.WinForms/Main.Designer.cs b/NHSE.WinForms/Main.Designer.cs index d8b4943..7131f87 100644 --- a/NHSE.WinForms/Main.Designer.cs +++ b/NHSE.WinForms/Main.Designer.cs @@ -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); // diff --git a/NHSE.WinForms/Main.cs b/NHSE.WinForms/Main.cs index 0f92a8e..fbab87d 100644 --- a/NHSE.WinForms/Main.cs +++ b/NHSE.WinForms/Main.cs @@ -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);