From bafde2758e14ded9d1e8a29af0d3ce7e0cfe77b1 Mon Sep 17 00:00:00 2001 From: Razzmatazz Date: Tue, 2 Mar 2021 12:53:14 -0600 Subject: [PATCH] Added option to backup additional world files used by mods. Window now remembers dimensions. --- App.config | 7 +- ExtraWorldFileEditWindow.xaml | 28 ++++++++ ExtraWorldFileEditWindow.xaml.cs | 42 ++++++++++++ ExtraWorldFilesWindow.xaml | 57 +++++++++++++++++ ExtraWorldFilesWindow.xaml.cs | 99 +++++++++++++++++++++++++++++ MainWindow.xaml | 16 ++++- MainWindow.xaml.cs | 68 ++++++++++---------- Properties/AssemblyInfo.cs | 4 +- Properties/Settings.Designer.cs | 31 +++++++-- Properties/Settings.settings | 8 ++- Resources/ExclamationPoint_32x.png | Bin 0 -> 220 bytes SaveBackup.cs | 13 +++- SaveFile.cs | 9 +++ ValheimSaveShield.csproj | 15 +++++ 14 files changed, 348 insertions(+), 49 deletions(-) create mode 100644 ExtraWorldFileEditWindow.xaml create mode 100644 ExtraWorldFileEditWindow.xaml.cs create mode 100644 ExtraWorldFilesWindow.xaml create mode 100644 ExtraWorldFilesWindow.xaml.cs create mode 100644 Resources/ExclamationPoint_32x.png diff --git a/App.config b/App.config index 850feaa..f3a94ee 100644 --- a/App.config +++ b/App.config @@ -52,8 +52,11 @@ - - + + 800 + + + 500 diff --git a/ExtraWorldFileEditWindow.xaml b/ExtraWorldFileEditWindow.xaml new file mode 100644 index 0000000..0028c21 --- /dev/null +++ b/ExtraWorldFileEditWindow.xaml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 9673a11..0cc1af8 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -117,6 +117,8 @@ public MainWindow() Properties.Settings.Default.UpgradeRequired = false; Properties.Settings.Default.Save(); } + Width = Properties.Settings.Default.MainWindowWidth; + Height = Properties.Settings.Default.MainWindowHeight; if (Properties.Settings.Default.SaveFolders == null) { Properties.Settings.Default.SaveFolders = new StringCollection(); @@ -142,6 +144,11 @@ public MainWindow() Properties.Settings.Default.CharBackupKeep = new StringDictionary(); Properties.Settings.Default.Save(); } + if (Properties.Settings.Default.WorldFileExtensions == null) + { + Properties.Settings.Default.WorldFileExtensions = new StringCollection(); + Properties.Settings.Default.Save(); + } if (Properties.Settings.Default.BackupFolder.Length == 0) { logMessage("Backup folder not set; reverting to default."); @@ -785,34 +792,13 @@ private Dictionary getBackupKeeps(string type) return keeps; } - private void DataBackups_BeginningEdit(object sender, DataGridBeginningEditEventArgs e) - { - if (e.Column.Header.ToString().Equals("Name") || - e.Column.Header.ToString().Equals("Type") || - e.Column.Header.ToString().Equals("SaveDate") || - e.Column.Header.ToString().Equals("Active")) e.Cancel = true; - } - - private void DataBackups_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) - { - if (e.Column.Header.ToString().Equals("Name") && e.EditAction == DataGridEditAction.Commit) - { - SaveBackup sb = (SaveBackup)e.Row.Item; - if (sb.Label.Equals("")) - { - sb.Label = sb.SaveDate.Ticks.ToString(); - } - } - } - private void updateSavedLabels() { var savedWorldLabels = new StringDictionary(); var savedCharLabels = new StringDictionary(); - for (int i = 0; i < listBackups.Count; i++) + foreach (var s in listBackups) { - SaveBackup s = listBackups[i]; - if (!s.Label.Equals(s.DefaultLabel)) + if (s.Label != s.DefaultLabel) { if (s.Type.Equals("World")) { @@ -957,7 +943,9 @@ private void checkForUpdate() private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { - //any cleanup to do before exit + Properties.Settings.Default.MainWindowWidth = Width; + Properties.Settings.Default.MainWindowHeight = Height; + Properties.Settings.Default.Save(); } private void Window_Closed(object sender, EventArgs e) @@ -1042,17 +1030,7 @@ public static void CopyFolder(DirectoryInfo source, DirectoryInfo target) private void DataBackups_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e) { - if (e.Column.Header.Equals("DefaultLabel") || - e.Column.Header.Equals("FileName") || - e.Column.Header.Equals("FullPath") || - e.Column.Header.Equals("Folder") || - e.Column.Header.Equals("ActivePaths")) { - e.Cancel = true; - } - else if (e.Column.Header.Equals("SaveDate")) - { - //e.Column.SortDirection = System.ComponentModel.ListSortDirection.Ascending; - } + e.Cancel = true; } private void btnAppUpdate_Click(object sender, RoutedEventArgs e) @@ -1554,6 +1532,26 @@ private void menuBackupsViewMap_Click(object sender, RoutedEventArgs e) logMessage($"Error showing map: {ex.Message}", LogType.Error); } } + + private void btnExtraWorldFiles_Click(object sender, RoutedEventArgs e) + { + var win = new ExtraWorldFilesWindow(); + win.Owner = this; + win.WindowStartupLocation = WindowStartupLocation.CenterOwner; + win.ShowDialog(); + } + + private void dataBackups_ContextMenuOpening(object sender, ContextMenuEventArgs e) + { + if (dataBackups.SelectedIndex > -1) + { + menuBackups.Visibility = Visibility.Visible; + } + else + { + menuBackups.Visibility = Visibility.Collapsed; + } + } } public enum LogType diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 25d45d6..0db2f5b 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -51,5 +51,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.4.2.0")] -[assembly: AssemblyFileVersion("0.4.2.0")] +[assembly: AssemblyVersion("0.4.3.0")] +[assembly: AssemblyFileVersion("0.4.3.0")] diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs index b94b026..c5494b0 100644 --- a/Properties/Settings.Designer.cs +++ b/Properties/Settings.Designer.cs @@ -248,13 +248,36 @@ public string FtpSaveDest { [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("")] - public string Setting { + public global::System.Collections.Specialized.StringCollection WorldFileExtensions { + get { + return ((global::System.Collections.Specialized.StringCollection)(this["WorldFileExtensions"])); + } + set { + this["WorldFileExtensions"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("800")] + public double MainWindowWidth { + get { + return ((double)(this["MainWindowWidth"])); + } + set { + this["MainWindowWidth"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("500")] + public double MainWindowHeight { get { - return ((string)(this["Setting"])); + return ((double)(this["MainWindowHeight"])); } set { - this["Setting"] = value; + this["MainWindowHeight"] = value; } } } diff --git a/Properties/Settings.settings b/Properties/Settings.settings index dad27a2..6dcd3bd 100644 --- a/Properties/Settings.settings +++ b/Properties/Settings.settings @@ -59,8 +59,14 @@ - + + + 800 + + + 500 + \ No newline at end of file diff --git a/Resources/ExclamationPoint_32x.png b/Resources/ExclamationPoint_32x.png new file mode 100644 index 0000000000000000000000000000000000000000..269865ff6a6306ec192b74414e4b8d38d52375de GIT binary patch literal 220 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzmSQK*5Dp-y;YjHK@;M7UB8wRq zWZOZQvH$7ERG^?_iEBhjaDG}zd16s2LwR|*US?i)adKios$PCk`s{Z$Qb0wKo-U3d z5v|Dy60FLy29s7jyuCgD|HqTXg@qGS)Pz^^Eig+^41Zj0sVB1U!Q%XsnZ^$k4PG?_ zviDdeTwz?yCsE39bF1Rct@2h9yA%y>$w`>;Nt|U}oFKx$u>Bn$*WrJ2L6$Ihy85}S Ib4q9e06RWKjQ{`u literal 0 HcmV?d00001 diff --git a/SaveBackup.cs b/SaveBackup.cs index c1687cc..d27adc1 100644 --- a/SaveBackup.cs +++ b/SaveBackup.cs @@ -28,7 +28,7 @@ public string Label { get { - if (this.saveData.label == "") + if (this.saveData.label == "" || this.saveData.label == null) { return this.DefaultLabel; } @@ -39,7 +39,7 @@ public string Label } set { - if (value == "") + if (value == "" || value == null) { this.saveData.label = this.DefaultLabel; } else @@ -205,6 +205,15 @@ public void Restore(string path) string sourcefwl = info.DirectoryName + "\\" + this.Name + ".fwl"; string destfwl = destInfo.DirectoryName + "\\" + this.Name + ".fwl"; File.Copy(sourcefwl, destfwl, true); + foreach (var ext in Properties.Settings.Default.WorldFileExtensions) + { + string sourcefile = info.DirectoryName + "\\" + this.Name + ext; + if (File.Exists(sourcefile)) + { + string destfile = destInfo.DirectoryName + "\\" + this.Name + ext; + File.Copy(sourcefile, destfile, true); + } + } } } diff --git a/SaveFile.cs b/SaveFile.cs index 758b0ef..51c8dc3 100644 --- a/SaveFile.cs +++ b/SaveFile.cs @@ -146,6 +146,15 @@ public SaveBackup PerformBackup() string sourcefwl = info.DirectoryName + "\\" + this.Name + ".fwl"; string destfwl = this.BackupFolder + "\\" + this.Name + ".fwl"; File.Copy(sourcefwl, destfwl, true); + foreach (var ext in Properties.Settings.Default.WorldFileExtensions) + { + string sourcefile = info.DirectoryName + "\\" + this.Name + ext; + if (File.Exists(sourcefile)) + { + string destfile = this.BackupFolder + "\\" + this.Name + ext; + File.Copy(sourcefile, destfile, true); + } + } } return new SaveBackup(this.BackupPath); } diff --git a/ValheimSaveShield.csproj b/ValheimSaveShield.csproj index 3b73899..3a42a81 100644 --- a/ValheimSaveShield.csproj +++ b/ValheimSaveShield.csproj @@ -109,6 +109,12 @@ MSBuild:Compile Designer + + ExtraWorldFileEditWindow.xaml + + + ExtraWorldFilesWindow.xaml + FtpSettingsWindow.xaml @@ -122,6 +128,14 @@ + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -180,6 +194,7 @@ +