diff --git a/Windows/MainWindow.cs b/Windows/MainWindow.cs index 6fd3fe2..a641f5e 100644 --- a/Windows/MainWindow.cs +++ b/Windows/MainWindow.cs @@ -563,6 +563,33 @@ internal static void RefreshLists() { Instance?.listBoxEntries.Refresh(); } + internal static void ImportManualSave(string content) { + if (Instance == null || string.IsNullOrWhiteSpace(content)) return; + + try { + var context = ToNLogContext.Instance ?? new ToNLogContext(); + string dateKey = ToNLogContext.Instance?.DateKey ?? DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); + DateTime now = DateTime.Now; + + Instance.AddLogEntry(dateKey, content, now, context); + + var collection = SaveData[dateKey]; + if (collection != null) { + if (!Instance.listBoxKeys.Items.Contains(collection)) { + int idx = SaveData.Collection.IndexOf(collection); + if (idx < 0) idx = Instance.listBoxKeys.Items.Count; + Instance.listBoxKeys.Items.Insert(Math.Min(Math.Max(idx, 0), Instance.listBoxKeys.Items.Count), collection); + } + Instance.listBoxKeys.SelectedItem = collection; + Instance.UpdateEntries(); + } + + Instance.Export(null, true); + } catch (Exception ex) { + Logger.Error(ex); + } + } + private void UpdateEntries() { listBoxEntries.Items.Clear(); if (JustCopiedIndex > -1) SetJustCopied(-1); diff --git a/Windows/SettingsWindow.Designer.cs b/Windows/SettingsWindow.Designer.cs index 63811b3..d8aac64 100644 --- a/Windows/SettingsWindow.Designer.cs +++ b/Windows/SettingsWindow.Designer.cs @@ -45,6 +45,7 @@ private void InitializeComponent() { check24Hour = new CheckBox(); btnCheckForUpdates = new Button(); btnOpenData = new Button(); + btnManualImport = new Button(); ctxData = new ContextMenuStrip(components); setDataLocationToolStripMenuItem = new ToolStripMenuItem(); ctxItemPickFolder = new ToolStripMenuItem(); @@ -336,12 +337,27 @@ private void InitializeComponent() { btnCheckForUpdates.ForeColor = Color.White; btnCheckForUpdates.Location = new Point(0, 4); btnCheckForUpdates.Name = "btnCheckForUpdates"; - btnCheckForUpdates.Size = new Size(510, 24); + btnCheckForUpdates.Size = new Size(360, 24); btnCheckForUpdates.TabIndex = 4; btnCheckForUpdates.Text = "Check For Updates"; btnCheckForUpdates.UseVisualStyleBackColor = true; btnCheckForUpdates.Click += btnCheckForUpdates_Click; // + // btnManualImport + // + btnManualImport.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right; + btnManualImport.FlatAppearance.BorderColor = Color.FromArgb(122, 122, 122); + btnManualImport.FlatStyle = FlatStyle.Flat; + btnManualImport.ForeColor = Color.White; + btnManualImport.Location = new Point(366, 4); + btnManualImport.Name = "btnManualImport"; + btnManualImport.Size = new Size(146, 24); + btnManualImport.TabIndex = 5; + btnManualImport.Tag = "|Manually import save code text"; + btnManualImport.Text = "Import"; + btnManualImport.UseVisualStyleBackColor = true; + btnManualImport.Click += btnManualImport_Click; + // // btnOpenData // btnOpenData.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right; @@ -352,7 +368,7 @@ private void InitializeComponent() { btnOpenData.Location = new Point(516, 4); btnOpenData.Name = "btnOpenData"; btnOpenData.Size = new Size(53, 24); - btnOpenData.TabIndex = 5; + btnOpenData.TabIndex = 6; btnOpenData.Tag = "|Open local app data folder."; btnOpenData.Text = "Data"; btnOpenData.UseVisualStyleBackColor = true; @@ -425,6 +441,7 @@ private void InitializeComponent() { // panel1.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; panel1.Controls.Add(btnCheckForUpdates); + panel1.Controls.Add(btnManualImport); panel1.Controls.Add(btnOpenData); panel1.Location = new Point(8, 575); panel1.Name = "panel1"; @@ -1513,6 +1530,7 @@ private void InitializeComponent() { private CheckBox checkShowSeconds; private CheckBox check24Hour; private Button btnOpenData; + private Button btnManualImport; private ToolTip toolTip; private CheckBox checkColorObjectives; private CheckBox checkSaveTerrorsNote; diff --git a/Windows/SettingsWindow.cs b/Windows/SettingsWindow.cs index c801f29..705689a 100644 --- a/Windows/SettingsWindow.cs +++ b/Windows/SettingsWindow.cs @@ -802,5 +802,34 @@ private void BindControlsRecursive(Control.ControlCollection controls) { } } #endregion + + #region ManualImport + private void btnManualImport_Click(object sender, EventArgs e) { + // Temporary hard-coded localization + string title = LANG.S("SETTINGS.MANUALIMPORT.TITLE") ?? "Manual Import Save Code"; + var edit = EditWindow.Show(string.Empty, title, this); + if (!edit.Accept) return; + + string input = (edit.Text).Trim(); + if (string.IsNullOrEmpty(input)) { + MessageBox.Show(LANG.S("SETTINGS.MANUALIMPORT.EMPTY") ?? "Please paste the text that contains the save code.", + title, MessageBoxButtons.OK, MessageBoxIcon.Warning); + return; + } + + if (input.Length < 1000) { + MessageBox.Show(LANG.S("SETTINGS.MANUALIMPORT.INVALID") ?? "No valid save data was found.", + title, MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + MainWindow.ImportManualSave(input); + + MessageBox.Show(LANG.S("SETTINGS.MANUALIMPORT.SUCCESS") ?? "Imported successfully.", + title, MessageBoxButtons.OK, MessageBoxIcon.Information); + } + #endregion } } + +