diff --git a/NHSE.Core/Save/Meta/HorizonSave.cs b/NHSE.Core/Save/Meta/HorizonSave.cs
index e18d7dc..d9506ec 100644
--- a/NHSE.Core/Save/Meta/HorizonSave.cs
+++ b/NHSE.Core/Save/Meta/HorizonSave.cs
@@ -87,5 +87,12 @@ public string GetSaveTitle(string prefix)
return $"{prefix} - {townName} @ {timestamp}";
}
+
+ public string GetBackupFolderTitle()
+ {
+ var townName = Players[0].Personal.TownName;
+ var timestamp = Main.LastSaved.TimeStamp.Replace(':', '.');
+ return StringUtil.CleanFileName($"{townName} - {timestamp}");
+ }
}
}
diff --git a/NHSE.WinForms/Editor.Designer.cs b/NHSE.WinForms/Editor.Designer.cs
index 0b69b89..816d526 100644
--- a/NHSE.WinForms/Editor.Designer.cs
+++ b/NHSE.WinForms/Editor.Designer.cs
@@ -32,7 +32,6 @@ private void InitializeComponent()
this.components = new System.ComponentModel.Container();
this.Menu_Editor = new System.Windows.Forms.MenuStrip();
this.Menu_File = new System.Windows.Forms.ToolStripMenuItem();
- this.Menu_Open = new System.Windows.Forms.ToolStripMenuItem();
this.Menu_Save = new System.Windows.Forms.ToolStripMenuItem();
this.Menu_Tools = new System.Windows.Forms.ToolStripMenuItem();
this.Menu_DumpDecrypted = new System.Windows.Forms.ToolStripMenuItem();
@@ -71,6 +70,7 @@ private void InitializeComponent()
this.NUD_PatternIndex = new System.Windows.Forms.NumericUpDown();
this.PB_Pattern = new System.Windows.Forms.PictureBox();
this.Tab_Map = new System.Windows.Forms.TabPage();
+ this.B_EditLandFlags = new System.Windows.Forms.Button();
this.L_PlayerHouse = new System.Windows.Forms.Label();
this.NUD_PlayerHouse = new System.Windows.Forms.NumericUpDown();
this.B_LoadHouse = new System.Windows.Forms.Button();
@@ -81,7 +81,9 @@ private void InitializeComponent()
this.B_EditTurnipExchange = new System.Windows.Forms.Button();
this.B_EditBuildings = new System.Windows.Forms.Button();
this.B_RecycleBin = new System.Windows.Forms.Button();
- this.B_EditLandFlags = new System.Windows.Forms.Button();
+ this.Menu_Options = new System.Windows.Forms.ToolStripMenuItem();
+ this.Menu_Settings = new System.Windows.Forms.ToolStripMenuItem();
+ this.Menu_Language = new System.Windows.Forms.ToolStripComboBox();
this.Menu_Editor.SuspendLayout();
this.TC_Editors.SuspendLayout();
this.Tab_Players.SuspendLayout();
@@ -103,7 +105,8 @@ private void InitializeComponent()
this.Menu_Editor.BackColor = System.Drawing.SystemColors.Control;
this.Menu_Editor.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.Menu_File,
- this.Menu_Tools});
+ this.Menu_Tools,
+ this.Menu_Options});
this.Menu_Editor.Location = new System.Drawing.Point(0, 0);
this.Menu_Editor.Name = "Menu_Editor";
this.Menu_Editor.Size = new System.Drawing.Size(404, 24);
@@ -113,25 +116,16 @@ private void InitializeComponent()
// Menu_File
//
this.Menu_File.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.Menu_Open,
this.Menu_Save});
this.Menu_File.Name = "Menu_File";
this.Menu_File.Size = new System.Drawing.Size(37, 20);
this.Menu_File.Text = "File";
//
- // Menu_Open
- //
- this.Menu_Open.Name = "Menu_Open";
- this.Menu_Open.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O)));
- this.Menu_Open.Size = new System.Drawing.Size(146, 22);
- this.Menu_Open.Text = "Open";
- this.Menu_Open.Click += new System.EventHandler(this.Menu_Open_Click);
- //
// Menu_Save
//
this.Menu_Save.Name = "Menu_Save";
this.Menu_Save.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S)));
- this.Menu_Save.Size = new System.Drawing.Size(146, 22);
+ this.Menu_Save.Size = new System.Drawing.Size(180, 22);
this.Menu_Save.Text = "Save";
this.Menu_Save.Click += new System.EventHandler(this.Menu_Save_Click);
//
@@ -543,6 +537,16 @@ private void InitializeComponent()
this.Tab_Map.Text = "Map";
this.Tab_Map.UseVisualStyleBackColor = true;
//
+ // B_EditLandFlags
+ //
+ this.B_EditLandFlags.Location = new System.Drawing.Point(202, 76);
+ this.B_EditLandFlags.Name = "B_EditLandFlags";
+ this.B_EditLandFlags.Size = new System.Drawing.Size(92, 40);
+ this.B_EditLandFlags.TabIndex = 53;
+ this.B_EditLandFlags.Text = "Edit Flags";
+ this.B_EditLandFlags.UseVisualStyleBackColor = true;
+ this.B_EditLandFlags.Click += new System.EventHandler(this.B_EditLandFlags_Click);
+ //
// L_PlayerHouse
//
this.L_PlayerHouse.Location = new System.Drawing.Point(16, 6);
@@ -649,15 +653,31 @@ private void InitializeComponent()
this.B_RecycleBin.UseVisualStyleBackColor = true;
this.B_RecycleBin.Click += new System.EventHandler(this.B_RecycleBin_Click);
//
- // B_EditLandFlags
+ // Menu_Options
//
- this.B_EditLandFlags.Location = new System.Drawing.Point(202, 76);
- this.B_EditLandFlags.Name = "B_EditLandFlags";
- this.B_EditLandFlags.Size = new System.Drawing.Size(92, 40);
- this.B_EditLandFlags.TabIndex = 53;
- this.B_EditLandFlags.Text = "Edit Flags";
- this.B_EditLandFlags.UseVisualStyleBackColor = true;
- this.B_EditLandFlags.Click += new System.EventHandler(this.B_EditLandFlags_Click);
+ this.Menu_Options.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.Menu_Language,
+ this.Menu_Settings});
+ this.Menu_Options.Name = "Menu_Options";
+ this.Menu_Options.Size = new System.Drawing.Size(61, 20);
+ this.Menu_Options.Text = "Options";
+ //
+ // Menu_Settings
+ //
+ this.Menu_Settings.Name = "Menu_Settings";
+ this.Menu_Settings.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.P)));
+ this.Menu_Settings.Size = new System.Drawing.Size(180, 22);
+ this.Menu_Settings.Text = "Settings";
+ this.Menu_Settings.Click += new System.EventHandler(this.Menu_Settings_Click);
+ //
+ // Menu_Language
+ //
+ this.Menu_Language.Enabled = false;
+ this.Menu_Language.Items.AddRange(new object[] {
+ "English"});
+ this.Menu_Language.Name = "Menu_Language";
+ this.Menu_Language.Size = new System.Drawing.Size(115, 23);
+ this.Menu_Language.Text = "Language";
//
// Editor
//
@@ -698,7 +718,6 @@ private void InitializeComponent()
private System.Windows.Forms.MenuStrip Menu_Editor;
private System.Windows.Forms.ToolStripMenuItem Menu_File;
- private System.Windows.Forms.ToolStripMenuItem Menu_Open;
private System.Windows.Forms.ToolStripMenuItem Menu_Save;
private System.Windows.Forms.ToolStripMenuItem Menu_Tools;
private System.Windows.Forms.TabControl TC_Editors;
@@ -748,6 +767,9 @@ private void InitializeComponent()
private System.Windows.Forms.Button B_DumpHouse;
private System.Windows.Forms.Label L_PlayerHouse;
private System.Windows.Forms.Button B_EditLandFlags;
+ private System.Windows.Forms.ToolStripMenuItem Menu_Options;
+ private System.Windows.Forms.ToolStripComboBox Menu_Language;
+ private System.Windows.Forms.ToolStripMenuItem Menu_Settings;
}
}
diff --git a/NHSE.WinForms/Editor.cs b/NHSE.WinForms/Editor.cs
index 7b906d0..6682275 100644
--- a/NHSE.WinForms/Editor.cs
+++ b/NHSE.WinForms/Editor.cs
@@ -25,11 +25,13 @@ public Editor(HorizonSave file)
Villagers = LoadVillagers();
Text = SAV.GetSaveTitle("NHSE");
+ Menu_Language.SelectedIndex = 0; // en
}
- private void Menu_Open_Click(object sender, EventArgs e)
+ private void Menu_Settings_Click(object sender, EventArgs e)
{
- WinFormsUtil.Alert("I don't do anything yet!");
+ using var editor = new SettingsEditor();
+ editor.ShowDialog();
}
private void Menu_Save_Click(object sender, EventArgs e)
diff --git a/NHSE.WinForms/Main.cs b/NHSE.WinForms/Main.cs
index d3944a9..ba002a9 100644
--- a/NHSE.WinForms/Main.cs
+++ b/NHSE.WinForms/Main.cs
@@ -12,6 +12,10 @@ namespace NHSE.WinForms
///
public partial class Main : Form
{
+ public const string BackupFolderName = "bak";
+ public static readonly string WorkingDirectory = Application.StartupPath;
+ public static readonly string BackupPath = Path.Combine(WorkingDirectory, BackupFolderName);
+
public Main()
{
InitializeComponent();
@@ -127,9 +131,30 @@ private static void OpenSaveFile(string path)
var settings = Settings.Default;
settings.LastFilePath = path;
+
+ if (!settings.BackupPrompted)
+ {
+ settings.BackupPrompted = true;
+ var line1 = string.Format(MessageStrings.MsgBackupCreateLocation, BackupFolderName);
+ var line2 = MessageStrings.MsgBackupCreateQuestion;
+ var prompt = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, line1, line2);
+ settings.AutomaticBackup = prompt == DialogResult.Yes;
+ }
+
+ if (settings.AutomaticBackup)
+ BackupSaveFile(file, path, BackupPath);
+
settings.Save();
}
+ private static void BackupSaveFile(HorizonSave file, string path, string bak)
+ {
+ Directory.CreateDirectory(bak);
+ var dest = Path.Combine(bak, file.GetBackupFolderTitle());
+ if (!Directory.Exists(dest))
+ FileUtil.CopyFolder(path, dest);
+ }
+
private void Main_KeyDown(object sender, KeyEventArgs e)
{
if (ModifierKeys != Keys.Control)
@@ -157,6 +182,12 @@ private void Main_KeyDown(object sender, KeyEventArgs e)
editor.ShowDialog();
break;
}
+ case Keys.P:
+ {
+ using var editor = new SettingsEditor();
+ editor.ShowDialog();
+ break;
+ }
}
}
}
diff --git a/NHSE.WinForms/Properties/Settings.Designer.cs b/NHSE.WinForms/Properties/Settings.Designer.cs
index f3c101b..ef80532 100644
--- a/NHSE.WinForms/Properties/Settings.Designer.cs
+++ b/NHSE.WinForms/Properties/Settings.Designer.cs
@@ -94,5 +94,29 @@ internal sealed partial class Settings : global::System.Configuration.Applicatio
this["SysBotGenericOffset"] = value;
}
}
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("True")]
+ public bool AutomaticBackup {
+ get {
+ return ((bool)(this["AutomaticBackup"]));
+ }
+ set {
+ this["AutomaticBackup"] = value;
+ }
+ }
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("False")]
+ public bool BackupPrompted {
+ get {
+ return ((bool)(this["BackupPrompted"]));
+ }
+ set {
+ this["BackupPrompted"] = value;
+ }
+ }
}
}
diff --git a/NHSE.WinForms/Properties/Settings.settings b/NHSE.WinForms/Properties/Settings.settings
index 269e52e..a7bcf02 100644
--- a/NHSE.WinForms/Properties/Settings.settings
+++ b/NHSE.WinForms/Properties/Settings.settings
@@ -20,5 +20,11 @@
2889584832
+
+ True
+
+
+ False
+
\ No newline at end of file
diff --git a/NHSE.WinForms/Subforms/Program/SettingsEditor.Designer.cs b/NHSE.WinForms/Subforms/Program/SettingsEditor.Designer.cs
new file mode 100644
index 0000000..43e3b13
--- /dev/null
+++ b/NHSE.WinForms/Subforms/Program/SettingsEditor.Designer.cs
@@ -0,0 +1,65 @@
+namespace NHSE.WinForms
+{
+ partial class SettingsEditor
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.PG_Settings = new System.Windows.Forms.PropertyGrid();
+ this.SuspendLayout();
+ //
+ // PG_Settings
+ //
+ this.PG_Settings.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.PG_Settings.Location = new System.Drawing.Point(0, 0);
+ this.PG_Settings.Name = "PG_Settings";
+ this.PG_Settings.Size = new System.Drawing.Size(322, 310);
+ this.PG_Settings.TabIndex = 0;
+ //
+ // SettingsEditor
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(322, 310);
+ this.Controls.Add(this.PG_Settings);
+ this.Icon = global::NHSE.WinForms.Properties.Resources.icon;
+ this.KeyPreview = true;
+ this.MaximizeBox = false;
+ this.MinimizeBox = false;
+ this.Name = "SettingsEditor";
+ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
+ this.Text = "Settings Editor";
+ this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.SettingsEditor_FormClosing);
+ this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.SettingsEditor_KeyDown);
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.PropertyGrid PG_Settings;
+ }
+}
\ No newline at end of file
diff --git a/NHSE.WinForms/Subforms/Program/SettingsEditor.cs b/NHSE.WinForms/Subforms/Program/SettingsEditor.cs
new file mode 100644
index 0000000..e5eaa9e
--- /dev/null
+++ b/NHSE.WinForms/Subforms/Program/SettingsEditor.cs
@@ -0,0 +1,28 @@
+using System.Windows.Forms;
+using NHSE.WinForms.Properties;
+
+namespace NHSE.WinForms
+{
+ public partial class SettingsEditor : Form
+ {
+ private readonly Settings obj;
+
+ public SettingsEditor()
+ {
+ obj = Settings.Default;
+ InitializeComponent();
+ PG_Settings.SelectedObject = obj;
+ }
+
+ private void SettingsEditor_FormClosing(object sender, FormClosingEventArgs e)
+ {
+ obj.Save();
+ }
+
+ private void SettingsEditor_KeyDown(object sender, KeyEventArgs e)
+ {
+ if (e.KeyCode == Keys.W && ModifierKeys == Keys.Control)
+ Close();
+ }
+ }
+}
diff --git a/NHSE.WinForms/Subforms/Program/SettingsEditor.resx b/NHSE.WinForms/Subforms/Program/SettingsEditor.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/NHSE.WinForms/Subforms/Program/SettingsEditor.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/NHSE.WinForms/Util/FileUtil.cs b/NHSE.WinForms/Util/FileUtil.cs
new file mode 100644
index 0000000..65c79f7
--- /dev/null
+++ b/NHSE.WinForms/Util/FileUtil.cs
@@ -0,0 +1,28 @@
+using System.IO;
+
+namespace NHSE.WinForms
+{
+ public static class FileUtil
+ {
+ public static void CopyFolder(string source, string dest, bool subfolders = true)
+ {
+ Directory.CreateDirectory(dest);
+
+ var dir = new DirectoryInfo(source);
+ foreach (var file in dir.EnumerateFiles())
+ {
+ var path = Path.Combine(dest, file.Name);
+ file.CopyTo(path, false);
+ }
+
+ if (!subfolders)
+ return;
+
+ foreach (var folder in dir.EnumerateDirectories())
+ {
+ var path = Path.Combine(dest, folder.Name);
+ CopyFolder(folder.FullName, path);
+ }
+ }
+ }
+}
diff --git a/NHSE.WinForms/Util/MessageStrings.cs b/NHSE.WinForms/Util/MessageStrings.cs
new file mode 100644
index 0000000..dc5d5a9
--- /dev/null
+++ b/NHSE.WinForms/Util/MessageStrings.cs
@@ -0,0 +1,8 @@
+namespace NHSE.WinForms
+{
+ public static class MessageStrings
+ {
+ public static string MsgBackupCreateLocation { get; set; } = "NHSE can perform automatic backups if you create a folder with the name '{0}' in the same folder as NHSE's executable.";
+ public static string MsgBackupCreateQuestion { get; set; } = "Would you NHSE to automatically keep a backup of your save data?";
+ }
+}