Skip to content

Commit

Permalink
Added option to backup additional world files used by mods. Window no…
Browse files Browse the repository at this point in the history
…w remembers dimensions.
  • Loading branch information
Razzmatazzz committed Mar 2, 2021
1 parent 43f6ffc commit bafde27
Show file tree
Hide file tree
Showing 14 changed files with 348 additions and 49 deletions.
7 changes: 5 additions & 2 deletions App.config
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@
<setting name="FtpSaveDest" serializeAs="String">
<value />
</setting>
<setting name="Setting" serializeAs="String">
<value />
<setting name="MainWindowWidth" serializeAs="String">
<value>800</value>
</setting>
<setting name="MainWindowHeight" serializeAs="String">
<value>500</value>
</setting>
</ValheimSaveShield.Properties.Settings>
</userSettings>
Expand Down
28 changes: 28 additions & 0 deletions ExtraWorldFileEditWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Window x:Class="ValheimSaveShield.ExtraWorldFileEditWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ValheimSaveShield"
mc:Ignorable="d"
xmlns:ui="http://schemas.modernwpf.com/2019"
ui:WindowHelper.UseModernWindowStyle="True"
Title="File Extension" SizeToContent="Height" Width="200" ResizeMode="NoResize" FocusManager.FocusedElement="{Binding ElementName=txtExtension}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBox x:Name="txtExtension" Margin="5" Grid.Row="0" />
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button x:Name="btnOK" Content="OK" Margin="5" Grid.Column="1" Click="btnOK_Click"/>
<Button x:Name="btnCancel" Content="Cancel" Margin="5" Grid.Column="2" Click="btnCancel_Click"/>
</Grid>
</Grid>
</Window>
42 changes: 42 additions & 0 deletions ExtraWorldFileEditWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace ValheimSaveShield
{
/// <summary>
/// Interaction logic for ExtraWorldFileEditWindow.xaml
/// </summary>
public partial class ExtraWorldFileEditWindow : Window
{
public ExtraWorldFileEditWindow(string ext)
{
InitializeComponent();
if (ext != null) txtExtension.Text = ext;
}
public ExtraWorldFileEditWindow() : this(null) { }

private void btnCancel_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
Close();
}

private void btnOK_Click(object sender, RoutedEventArgs e)
{
DialogResult = true;
Tag = txtExtension.Text;
Close();
}
}
}
57 changes: 57 additions & 0 deletions ExtraWorldFilesWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<Window x:Class="ValheimSaveShield.ExtraWorldFilesWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ValheimSaveShield"
mc:Ignorable="d"
xmlns:ui="http://schemas.modernwpf.com/2019"
ui:WindowHelper.UseModernWindowStyle="True"
Title="Extra World Files" Height="350" Width="400">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Expander x:Name="expTip" Header="Instructions" Margin="10" Grid.Row="0">
<TextBlock TextWrapping="Wrap" Margin="10">
If you're using a mod that generates additional files in your worlds folder that you want backed up, you can list the additional file extensions here. To be supported, the additional world files must adhere to the Worldname.ext naming format where Worldname is the name of your world and .ext is the extension of the file.
<LineBreak/>
<LineBreak/>
For example: to back up an .ext file, you would add .ext to the list below.
</TextBlock>
</Expander>
<ListBox x:Name="lstExtensions" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<ListBox.ContextMenu>
<ContextMenu x:Name="menuExtensions" Opened="menuExtensions_Opened">
<MenuItem x:Name="menuAdd" Header="Add" Click="menuAdd_Click">
<MenuItem.Icon>
<Image Source="Resources/Add_32x.png"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem x:Name="menuEdit" Header="Edit" Click="menuEdit_Click">
<MenuItem.Icon>
<Image Source="Resources/Edit_32x.png"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem x:Name="menuRemove" Header="Remove" Click="menuRemove_Click">
<MenuItem.Icon>
<Image Source="Resources/Remove_32x.png"/>
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</ListBox.ContextMenu>
</ListBox>
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button x:Name="btnSave" Content="Save" Margin="10" Grid.Column="1" Click="btnSave_Click"/>
<Button x:Name="btnCancel" Content="Cancel" Margin="10" Grid.Column="2" Click="btnCancel_Click"/>
</Grid>
</Grid>
</Window>
99 changes: 99 additions & 0 deletions ExtraWorldFilesWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace ValheimSaveShield
{
/// <summary>
/// Interaction logic for ExtraWorldFilesWindow.xaml
/// </summary>
public partial class ExtraWorldFilesWindow : Window
{
public ExtraWorldFilesWindow()
{
InitializeComponent();
foreach (var ext in Properties.Settings.Default.WorldFileExtensions)
{
lstExtensions.Items.Add(ext);
}
}

private void menuExtensions_Opened(object sender, RoutedEventArgs e)
{
if (lstExtensions.SelectedIndex > -1)
{
menuEdit.Visibility = Visibility.Visible;
menuRemove.Visibility = Visibility.Visible;
}
else
{
menuEdit.Visibility = Visibility.Collapsed;
menuRemove.Visibility = Visibility.Collapsed;
}
}

private void btnSave_Click(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.WorldFileExtensions.Clear();
foreach (var ext in lstExtensions.Items)
{
Properties.Settings.Default.WorldFileExtensions.Add(ext.ToString());
}
Properties.Settings.Default.Save();
DialogResult = true;
Close();
}

private void btnCancel_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
Close();
}

private void menuRemove_Click(object sender, RoutedEventArgs e)
{
lstExtensions.Items.Remove(lstExtensions.SelectedItem);
}

private void menuAdd_Click(object sender, RoutedEventArgs e)
{
var editWin = new ExtraWorldFileEditWindow();
editWin.Owner = this;
editWin.WindowStartupLocation = WindowStartupLocation.CenterOwner;
if (editWin.ShowDialog().GetValueOrDefault())
{
var ext = editWin.Tag.ToString();
if (ext.IndexOf(".") != 0) {
ext = "." + ext;
}
lstExtensions.Items.Add(ext);
}
}

private void menuEdit_Click(object sender, RoutedEventArgs e)
{
var editWin = new ExtraWorldFileEditWindow(lstExtensions.SelectedItem.ToString());
editWin.Owner = this;
editWin.WindowStartupLocation = WindowStartupLocation.CenterOwner;
if (editWin.ShowDialog().GetValueOrDefault())
{
var ext = editWin.Tag.ToString();
if (ext.IndexOf(".") != 0)
{
ext = "." + ext;
}
lstExtensions.Items[lstExtensions.SelectedIndex] = ext;
}
}
}
}
16 changes: 13 additions & 3 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
mc:Ignorable="d"
xmlns:ui="http://schemas.modernwpf.com/2019"
ui:WindowHelper.UseModernWindowStyle="True"
Title="Valheim Save Shield" Height="450" Width="800" Loaded="Window_Loaded" Icon="Resources/vss_32.png" Closing="Window_Closing" Closed="Window_Closed" Deactivated="Window_Deactivated" MinHeight="200" MinWidth="300" StateChanged="Window_StateChanged" IsVisibleChanged="Window_IsVisibleChanged" ContentRendered="Window_ContentRendered">
Title="Valheim Save Shield" Height="500" Width="800" Loaded="Window_Loaded" Icon="Resources/vss_32.png" Closing="Window_Closing" Closed="Window_Closed" Deactivated="Window_Deactivated" MinHeight="200" MinWidth="300" StateChanged="Window_StateChanged" IsVisibleChanged="Window_IsVisibleChanged" ContentRendered="Window_ContentRendered">
<Window.Resources>
<Image x:Key="Save" Source="Resources/Save_32x.png"/>
<Image x:Key="SaveGrey" Source="Resources/Save_grey_32x.png"/>
Expand Down Expand Up @@ -38,7 +38,15 @@
</Grid>-->
<TabControl Grid.Row="0" TabIndex="5">
<TabItem x:Name="tabBackups" Header="Backups">
<DataGrid x:Name="dataBackups" BeginningEdit="DataBackups_BeginningEdit" SelectionMode="Single" CanUserDeleteRows="False" CellEditEnding="DataBackups_CellEditEnding" AutoGeneratingColumn="DataBackups_AutoGeneratingColumn">
<DataGrid x:Name="dataBackups" SelectionMode="Single" CanUserDeleteRows="False" AutoGeneratingColumn="DataBackups_AutoGeneratingColumn" ContextMenuOpening="dataBackups_ContextMenuOpening">
<DataGrid.Columns>
<DataGridTextColumn Header="Label" Binding="{Binding Path=Label}"/>
<DataGridCheckBoxColumn Header="Keep" Binding="{Binding Path=Keep}"/>
<DataGridTextColumn Header="Name" IsReadOnly="True" Binding="{Binding Path=Name, Mode=OneWay}"/>
<DataGridTextColumn Header="Type" IsReadOnly="True" Binding="{Binding Path=Type, Mode=OneWay}"/>
<DataGridTextColumn Header="Save Date" IsReadOnly="True" Binding="{Binding Path=SaveDate, Mode=OneWay}"/>
<DataGridCheckBoxColumn Header="Active" IsReadOnly="True" Binding="{Binding Path=Active, Mode=OneWay}"/>
</DataGrid.Columns>
<DataGrid.ContextMenu>
<ContextMenu x:Name="menuBackups" Opened="menuBackups_Opened">
<MenuItem x:Name="menuBackupsRestore" Header="Restore" Click="menuBackupsRestore_Click">
Expand Down Expand Up @@ -71,6 +79,7 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
Expand Down Expand Up @@ -126,6 +135,7 @@
<CheckBox x:Name="chkCreateLogFile" Content="Create log file" ToolTip="Whether a log.txt file should be created" HorizontalAlignment="Left" Margin="10,2,0,2" VerticalAlignment="Center" Grid.Row="6" Grid.ColumnSpan="2" Checked="chkCreateLogFile_Click" Unchecked="chkCreateLogFile_Click"/>
<CheckBox x:Name="chkAutoCheckUpdate" Content="Automatically check for update" HorizontalAlignment="Left" Margin="10,5,0,10" VerticalAlignment="Center" Grid.Row="7" Grid.ColumnSpan="2" Checked="chkAutoCheckUpdate_Click"/>
<Button x:Name="btnAppUpdate" Content="Check Now" ToolTip="Check to see if there's a new version of this program available" HorizontalAlignment="Left" Margin="250,5,0,10" VerticalAlignment="Center" Click="btnAppUpdate_Click" Grid.Row="7" Grid.ColumnSpan="2" />
<Button x:Name="btnExtraWorldFiles" Content="Extra world files" ToolTip="Back up additional files from your /worlds folder" HorizontalAlignment="Left" Margin="10,5" Grid.Row="8" Grid.ColumnSpan="2" Click="btnExtraWorldFiles_Click"/>
</Grid>
</TabItem>
<TabItem x:Name="tabLog" Header="Log">
Expand All @@ -141,7 +151,7 @@
</Label>
</StatusBarItem>
<StatusBarItem HorizontalAlignment="Left">
<Button x:Name="btnBackup" Click="BtnBackup_Click" ToolTip="Backup current save" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5,0" Height="26" VerticalContentAlignment="Center">
<Button x:Name="btnBackup" Click="BtnBackup_Click" ToolTip="Backup current saves" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5,0" Height="26" VerticalContentAlignment="Center">
<DynamicResource ResourceKey="Save"/>
</Button>
</StatusBarItem>
Expand Down
Loading

0 comments on commit bafde27

Please sign in to comment.