Skip to content

Commit

Permalink
Improvments to GUI related with restore window and pre-restore backup…
Browse files Browse the repository at this point in the history
… (eg. destination size shown as two values), new "Named backup" function, better files ordering in restore window
  • Loading branch information
sebeksd committed Apr 2, 2020
1 parent a8f8c0f commit 4ca8e6b
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 15 deletions.
22 changes: 18 additions & 4 deletions SaveGame Backup Tool/BackupMaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public enum BackupType
{
btNormal,
btManual,
btManualWithCustomPostfix,
btRestore
}

Expand All @@ -40,14 +41,16 @@ public BackupMaker()

}

private string BackupTypeToFilePostfix(BackupType lType)
private string BackupTypeToFilePostfix(BackupType lType, string lManualPostfix)
{
switch (lType)
{
case BackupType.btManual:
return "-manual";
case BackupType.btRestore:
return "-pre_restore";
case BackupType.btManualWithCustomPostfix:
return "-" + lManualPostfix;
default:
return "";
}
Expand All @@ -59,10 +62,11 @@ private string DirectoryForBakupType(BackupType lType, string lDestinationPath)
switch (lType)
{
case BackupType.btManual:
case BackupType.btManualWithCustomPostfix:
lSubFolder = "Manual";
break;
case BackupType.btRestore:
lSubFolder = "OnRestore";
lSubFolder = "Pre-Restore";
break;
default:
lSubFolder = "";
Expand Down Expand Up @@ -186,14 +190,19 @@ public bool CheckBackupFrequency(BackupTask lBackupTask)
public void RefreshDestinationDirectorySize(BackupTask pBackupTask)
{
pBackupTask.DestinationDirectorySize = GetDirectorySize(pBackupTask.Settings.DestinationPath);

long lManualSize = GetDirectorySize(Path.Combine(pBackupTask.Settings.DestinationPath, "Manual"));
long lPreRestore = GetDirectorySize(Path.Combine(pBackupTask.Settings.DestinationPath, "Pre-Restore"));

pBackupTask.ManualAndPreRestoreBackupsSize = (lManualSize > 0 ? lManualSize: 0) + (lPreRestore > 0 ? lPreRestore : 0);
}

public void CleanUpOldBackups(BackupTask lBackupTask, ref string pErrorMessage)
{
if (lBackupTask.DestinationDirectorySizeLimitReached())
{
DirectoryInfo lDirInfo = new DirectoryInfo(lBackupTask.Settings.DestinationPath);
FileInfo[] lFiles = lDirInfo.GetFiles().OrderBy(p => p.CreationTime).ToArray();
FileInfo[] lFiles = lDirInfo.GetFiles().OrderBy(f => f.CreationTime).ToArray();
try
{
int lFilesCount = lFiles.Length;
Expand Down Expand Up @@ -222,9 +231,14 @@ public void CleanUpOldBackups(BackupTask lBackupTask, ref string pErrorMessage)
}

public bool MakeBackup(BackupTask lBackupTask, BackupType lType, ref string pErrorMessage)
{
return MakeBackup(lBackupTask, lType, "", ref pErrorMessage);
}

public bool MakeBackup(BackupTask lBackupTask, BackupType lType, string lManualPostfix, ref string pErrorMessage)
{
string lBackupFileName = DateTime.Now.ToString(lBackupTask.Settings.BackupFileNamePattern);
lBackupFileName += BackupTypeToFilePostfix(lType);
lBackupFileName += BackupTypeToFilePostfix(lType, lManualPostfix);
lBackupFileName += ".zip";
string lDestinationPath = DirectoryForBakupType(lType, lBackupTask.Settings.DestinationPath);

Expand Down
12 changes: 8 additions & 4 deletions SaveGame Backup Tool/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<GroupBox Header="Force Backup" Height="54" Margin="0,235,4,0" VerticalAlignment="Top" HorizontalAlignment="Right" Width="209">
<Grid HorizontalAlignment="Left" Height="44" Margin="0,0,-2,-1" VerticalAlignment="Top" Width="199"/>
</GroupBox>
<Grid x:Name="gridTextEdits" Margin="10,30,7,0" Height="78" VerticalAlignment="Top">
<Button x:Name="buttonGetSavesPathFile" Content="File" Margin="0,28,0,0" VerticalAlignment="Top" RenderTransformOrigin="-0.18,-1.275" Click="buttonGetSavesPathFile_Click" Height="24" HorizontalAlignment="Right" Width="28"/>
<TextBox x:Name="textBoxSavesPath" Height="24" Margin="105,28,175,0" TextWrapping="NoWrap" VerticalAlignment="Top" TextChanged="textBoxSavesDirectory_TextChanged" LostFocus="textBox_LostFocus"/>
Expand All @@ -38,22 +41,23 @@
<Label x:Name="labelError" Content="Last error:" HorizontalAlignment="Left" Margin="0,6,0,0" VerticalAlignment="Top"/>
<TextBlock x:Name="textBlockLastError" Margin="10,32,7,10" TextWrapping="Wrap" Text="none" RenderTransformOrigin="0.311,0.109"/>
</Grid>
<Button x:Name="buttonForceBackup" Content="Force backup now" Margin="0,258,10,0" VerticalAlignment="Top" HorizontalAlignment="Right" Width="109" Height="22" Click="buttonForceBackup_Click" RenderTransformOrigin="0.462,1.411"/>
<Button x:Name="buttonManualBackup" Content="Manual backup" Margin="0,258,111,0" VerticalAlignment="Top" HorizontalAlignment="Right" Width="95" Height="22" Click="buttonManualBackup_Click" RenderTransformOrigin="0.462,1.411"/>
<ComboBox x:Name="comboBoxBackupTasks" Margin="37,3,124,0" VerticalAlignment="Top" IsEditable="false" SelectionChanged="comboBoxBackupTasks_SelectionChanged"/>
<Button x:Name="buttonAddBackupTask" Content="+" HorizontalAlignment="Right" Margin="0,3,97,0" VerticalAlignment="Top" Width="22" Height="22" Click="buttonAddBackupTask_Click" RenderTransformOrigin="-3.289,0.767"/>
<Button x:Name="buttonRemoveBackupTask" Content="-" Margin="0,3,70,0" VerticalAlignment="Top" Height="22" RenderTransformOrigin="-0.182,0.545" HorizontalAlignment="Right" Width="22" Click="buttonRemoveBackupTask_Click"/>
<TextBox x:Name="textBoxFileNameFilter" HorizontalAlignment="Left" Height="24" Margin="10,140,0,0" TextWrapping="NoWrap" Text="" VerticalAlignment="Top" Width="222" TextChanged="textBoxFileNameFilter_TextChanged"/>
<Label x:Name="labelFileNameFilter" Content="Source files filter:" HorizontalAlignment="Left" Margin="10,114,0,0" VerticalAlignment="Top"/>
<Label x:Name="labelFileNameFilter" Content="Source files filter:" HorizontalAlignment="Left" Margin="5,114,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="textBoxBackupFileNamePattern" Height="24" Margin="242,140,10,0" TextWrapping="NoWrap" Text="" VerticalAlignment="Top" TextChanged="textBoxBackupFileNamePattern_TextChanged"/>
<Label x:Name="labelBackupFileNamePattern" Content="Backup file name pattern:" HorizontalAlignment="Left" Margin="242,114,0,0" VerticalAlignment="Top"/>
<Label x:Name="labelBackupFileNamePattern" Content="Backup file name pattern:" HorizontalAlignment="Left" Margin="237,114,0,0" VerticalAlignment="Top"/>
<Rectangle x:Name="rectangleStatusIcon" HorizontalAlignment="Left" Height="22" Margin="10,3,0,0" Stroke="White" VerticalAlignment="Top" Width="22" Fill="#FFF4F4F5"/>
<Button x:Name="buttonAbout" Content="About" Margin="0,3,7,0" VerticalAlignment="Top" Height="22" Click="buttonAbout_Click" HorizontalAlignment="Right" Width="42"/>
<Label x:Name="labelDestinationDirSize" Content="Destination dir size:" HorizontalAlignment="Left" Margin="0,256,0,0" VerticalAlignment="Top"/>
<Label x:Name="labelDestinationDirSizeValue" Content="0" HorizontalAlignment="Left" Margin="113,256,0,0" VerticalAlignment="Top" RenderTransformOrigin="-0.634,0.445"/>
<CheckBox x:Name="checkBoxAutomaticDestinationDirSizeLimit" Content="Limit automatic backup space [MB]" HorizontalAlignment="Left" Margin="9,208,0,0" VerticalAlignment="Top" Width="513" Checked="checkBoxAutomaticDestinationDirSizeLimit_CheckedChanged" Unchecked="checkBoxAutomaticDestinationDirSizeLimit_CheckedChanged"/>
<xctk:DecimalUpDown x:Name="decimalUpDownDestinationDirSizeLimit" Margin="0,208,8,0" VerticalAlignment="Top" Maximum="99999" Minimum="1" Value="1000" Text="Backup" HorizontalAlignment="Right" Width="57" ValueChanged="decimalUpDownDestinationDirSizeLimit_ValueChanged"/>
<Button x:Name="ButtonTypicalLocations" Content="Typical locations" Margin="0,58,74,0" Click="ButtonTypicalLocations_Click" HorizontalAlignment="Right" Width="101" Height="24" VerticalAlignment="Top"/>
<Button x:Name="buttonRestore" Content="Restore" Margin="0,258,128,0" VerticalAlignment="Top" HorizontalAlignment="Right" Width="55" Height="22" Click="ButtonRestore_Click" RenderTransformOrigin="0.462,1.411"/>
<Button x:Name="buttonRestore" Content="Restore" Margin="0,258,223,0" VerticalAlignment="Top" HorizontalAlignment="Right" Width="55" Height="22" Click="ButtonRestore_Click" RenderTransformOrigin="0.462,1.411"/>
<Button x:Name="buttonNamedBackup" Content="Named backup" Margin="0,258,10,0" VerticalAlignment="Top" HorizontalAlignment="Right" Width="96" Height="22" RenderTransformOrigin="0.462,1.411" Click="buttonNamedBackup_Click"/>

</Grid>
</Window>
35 changes: 31 additions & 4 deletions SaveGame Backup Tool/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ private void SetToolTips()
ToolTipService.SetShowDuration(textBoxFileNameFilter, cToolTipDuration);
ToolTipService.SetShowDuration(textBoxBackupFileNamePattern, cToolTipDuration);
ToolTipService.SetShowDuration(checkBoxAutomaticBackup, cToolTipDuration);
ToolTipService.SetShowDuration(buttonForceBackup, cToolTipDuration);
ToolTipService.SetShowDuration(buttonManualBackup, cToolTipDuration);
ToolTipService.SetShowDuration(decimalUpDownBackupEvery, cToolTipDuration);
ToolTipService.SetShowDuration(rectangleStatusIcon, cToolTipDuration);
ToolTipService.SetShowDuration(checkBoxAutomaticDestinationDirSizeLimit, cToolTipDuration);
Expand All @@ -214,7 +214,7 @@ private void SetToolTips()
"Remember to set pattern the way that file name will be unique (eg time),\r\n" +
"function to create name from the pattern is DateTime.ToString for more info about this pattern possibilities search Internet :)";
checkBoxAutomaticBackup.ToolTip = "Check if you want this task to be run every few minutes (backup will be made only if files were modified).";
buttonForceBackup.ToolTip = "Perform a backup regardless of whether the files have been modified, if files are locked it will fail.";
buttonManualBackup.ToolTip = "Perform a backup regardless of whether the files have been modified, if files are locked it will fail.";
decimalUpDownBackupEvery.ToolTip = "Task will launch every few minutes (value set in this field) and it will check if file was modified and also if file is not locked.\r\n" +
"If file was not modified from last backup or it is locked for reading then next check will be triggered every 30 seconds (till backup is made).";
rectangleStatusIcon.ToolTip = "Global tasks status (works only for automated tasks), blue - tasks not checked, green - all tasks succeed or nothing to do, red - some task failed.\r\n" +
Expand Down Expand Up @@ -307,7 +307,12 @@ private void SelectTaskByIndex(int lIndex, bool lComboBoxOnly)
textBoxBackupFileNamePattern.Text = lBackupTask.Settings.BackupFileNamePattern;

if (lBackupTask.DestinationDirectorySize > 0)
labelDestinationDirSizeValue.Content = ByteSize.FromBytes(lBackupTask.DestinationDirectorySize).ToString();
{
if (lBackupTask.ManualAndPreRestoreBackupsSize > 0)
labelDestinationDirSizeValue.Content = ByteSize.FromBytes(lBackupTask.DestinationDirectorySize).ToString() + " + " + ByteSize.FromBytes(lBackupTask.ManualAndPreRestoreBackupsSize).ToString();
else
labelDestinationDirSizeValue.Content = ByteSize.FromBytes(lBackupTask.DestinationDirectorySize).ToString();
}
else if (lBackupTask.DestinationDirectorySize == 0)
labelDestinationDirSizeValue.Content = "[empty]";
else
Expand Down Expand Up @@ -578,13 +583,15 @@ private void decimalUpDownBackupEvery_ValueChanged(object sender, RoutedProperty
}
}

private void buttonForceBackup_Click(object sender, RoutedEventArgs e)
private void buttonManualBackup_Click(object sender, RoutedEventArgs e)
{
BackupTask lBackupTask = fSettings.Settings.BackupTasks[fSelectedBackupTaskIndex];

string lErrorMessage = "";
lBackupTask.SetLastBackupStatus(fBackupMaker.MakeBackup(lBackupTask, BackupType.btManual, ref lErrorMessage), lErrorMessage);

fBackupMaker.RefreshDestinationDirectorySize(lBackupTask);

// we made backup of currently selected item, refresh GUI to refresh last backup time
SelectTaskByIndex(-1, false); // reselect same item, refresh interface
}
Expand Down Expand Up @@ -748,5 +755,25 @@ private void ButtonRestore_Click(object sender, RoutedEventArgs e)
else
fRestore = null;
}

private void buttonNamedBackup_Click(object sender, RoutedEventArgs e)
{
NamedBackup lNamedBackupWindow = new NamedBackup();
lNamedBackupWindow.Owner = this;
lNamedBackupWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;

if (lNamedBackupWindow.ShowDialog() == true)
{
BackupTask lBackupTask = fSettings.Settings.BackupTasks[fSelectedBackupTaskIndex];

string lErrorMessage = "";
lBackupTask.SetLastBackupStatus(fBackupMaker.MakeBackup(lBackupTask, BackupType.btManualWithCustomPostfix, lNamedBackupWindow.GetBackupName(), ref lErrorMessage), lErrorMessage);

fBackupMaker.RefreshDestinationDirectorySize(lBackupTask);

// we made backup of currently selected item, refresh GUI to refresh last backup time
SelectTaskByIndex(-1, false); // reselect same item, refresh interface
}
}
}
}
15 changes: 15 additions & 0 deletions SaveGame Backup Tool/NamedBackup.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Window x:Class="SaveGameBackupTool.NamedBackup"
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:SaveGameBackupTool"
mc:Ignorable="d"
Title="Create custom named backup" Height="80.39" Width="443.327">
<Grid>
<Button x:Name="buttonCancel" Content="Cancel" Margin="0,13,86,0" VerticalAlignment="Top" HorizontalAlignment="Right" Width="75" Click="buttonCancel_Click"/>
<TextBox x:Name="textBoxName" Margin="10,10,166,0" TextWrapping="Wrap" Text="manual" Height="23" VerticalAlignment="Top" KeyDown="textBoxName_KeyDown"/>
<Button x:Name="buttonCreate" Content="Create" Margin="0,13,6,0" VerticalAlignment="Top" HorizontalAlignment="Right" Width="75" Click="buttonCreate_Click"/>

</Grid>
</Window>
54 changes: 54 additions & 0 deletions SaveGame Backup Tool/NamedBackup.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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 SaveGameBackupTool
{
/// <summary>
/// Logika interakcji dla klasy NamedBackup.xaml
/// </summary>
public partial class NamedBackup : Window
{
public NamedBackup()
{
InitializeComponent();
textBoxName.Focus();
textBoxName.SelectAll();
}

public string GetBackupName()
{
return textBoxName.Text;
}

private void buttonCreate_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
Close();
}

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

private void textBoxName_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
{
buttonCreate_Click(sender, e);
}
}
}
}
8 changes: 7 additions & 1 deletion SaveGame Backup Tool/PathHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ You should have received a copy of the GNU Lesser General Public License
*/

using System.IO;
using System.Linq;

namespace SaveGameBackupTool
{
Expand Down Expand Up @@ -106,7 +107,12 @@ public string[] GetAllFiles()
if (fIsFile)
return new string[] { fFilePath };
else if (IsDirectory)
return Directory.GetFiles(fDirectoryPath, "*", SearchOption.AllDirectories);
{
DirectoryInfo lDirInfo = new DirectoryInfo(fDirectoryPath);
FileInfo[] lFiles = lDirInfo.GetFiles("*", SearchOption.AllDirectories).OrderBy(f => f.CreationTime).ToArray();

return lFiles.Select(f => f.FullName).ToArray();//Directory.GetFiles(fDirectoryPath, "*", SearchOption.AllDirectories);
}
else
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions SaveGame Backup Tool/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// Możesz określić wszystkie wartości lub użyć domyślnych numerów kompilacji i poprawki
// przy użyciu symbolu „*”, tak jak pokazano poniżej:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.13")]
[assembly: AssemblyFileVersion("1.0.0.13")]
[assembly: AssemblyVersion("1.0.0.14")]
[assembly: AssemblyFileVersion("1.0.0.14")]
7 changes: 7 additions & 0 deletions SaveGame Backup Tool/SaveGame Backup Tool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@
<Compile Include="ApplicationInstanceManager.cs" />
<Compile Include="BackupMaker.cs" />
<Compile Include="CommandLineParameters.cs" />
<Compile Include="NamedBackup.xaml.cs">
<DependentUpon>NamedBackup.xaml</DependentUpon>
</Compile>
<Compile Include="PathHelper.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
Expand Down Expand Up @@ -127,6 +130,10 @@
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="NamedBackup.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Restore.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
2 changes: 2 additions & 0 deletions SaveGame Backup Tool/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public class BackupTask
public bool BackupChecked = false; // this is only runtime, it says if backup was checked at least once after app started
[System.Xml.Serialization.XmlIgnore]
public long DestinationDirectorySize = -1;
[System.Xml.Serialization.XmlIgnore]
public long ManualAndPreRestoreBackupsSize = -1;

[System.Xml.Serialization.XmlIgnore]
public bool SourceFilesChanged = true; // this flag is used to know if this task require checking files for changes
Expand Down

0 comments on commit 4ca8e6b

Please sign in to comment.