Skip to content

Commit

Permalink
Merge pull request #3 from weberonede/v1.1.0
Browse files Browse the repository at this point in the history
Version 1.1.0
  • Loading branch information
marvinweber authored Mar 27, 2019
2 parents f1bfee8 + 8795f8a commit d6756fa
Show file tree
Hide file tree
Showing 7 changed files with 337 additions and 101 deletions.
39 changes: 25 additions & 14 deletions KPSimpleBackup/KPSimpleBackup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Windows.Forms;
Expand Down Expand Up @@ -82,17 +83,21 @@ private void OnMenuSettings(object sender, EventArgs e)

private void OnSaveAction(object sender, FileSavedEventArgs e)
{
this.BackupAction(e.Database);
// only create backup if auto-backup is enabled
if (this.m_config.AutoDatabaseBackup)
{
this.BackupAction(e.Database);
}
}

private void OnMenuBackupNow(object sender, EventArgs e)
{
// show warning and abort if configuration isn't finished
// show warning and return if configuration isn't finished
if (!this.m_config.BackupConfigured)
{
MessageService.ShowWarning(
"Database cannot be backuped, because configuration is not finished.",
"Goto Tools -> KPSimpleBackup -> Settings and finish configuration!"
"Database backup cannot be created, because the configuration is not finished.",
"Please goto \"Tools -> KPSimpleBackup -> Settings\" and add a backup folder!"
);
return;
}
Expand All @@ -107,17 +112,23 @@ private void BackupAction(PwDatabase database)
return;
}

string dbBackupFileName = this.GetBackupFileName(database);
string time = DateTime.Now.ToString(@"yyyy\.MM\.dd\_H\.mm\.ss");
string backupFolderPath = this.m_config.BackupPath;
string path = "file:///" + backupFolderPath + dbBackupFileName + "_" + time + ".kdbx";
IOConnectionInfo connection = IOConnectionInfo.FromPath(path);

// save database TODO add Logger
database.SaveAs(connection, false, null);
List<String> paths = this.m_config.BackupPath;
String dateTimeFormat = this.m_config.DateFormat;
string time = DateTime.Now.ToString(dateTimeFormat);

// Cleanup
this.Cleanup(backupFolderPath, dbBackupFileName);
// Save backup database for each specified path
foreach (String backupFolderPath in paths)
{
string dbBackupFileName = this.GetBackupFileName(database);
string path = "file:///" + backupFolderPath + dbBackupFileName + "_" + time + ".kdbx";
IOConnectionInfo connection = IOConnectionInfo.FromPath(path);

// save database TODO add Logger
database.SaveAs(connection, false, null);

// Cleanup
this.Cleanup(backupFolderPath, dbBackupFileName);
}
}

private String GetBackupFileName(PwDatabase database)
Expand Down
44 changes: 39 additions & 5 deletions KPSimpleBackup/KPSimpleBackupConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using KeePass.App.Configuration;

namespace KPSimpleBackup
Expand All @@ -8,10 +10,13 @@ public class KPSimpleBackupConfig
private AceCustomConfig customConfig;

// default config values
private static readonly String DEFAULT_BACKUP_PATH = "";
private static readonly long DEFAULT_FILE_AMOUNT_TO_KEEP = 15;
private static readonly bool DEFAULT_USE_DATABASE_NAMES_FOR_BACKUP_FILES = false;
private static readonly bool DEFAULT_USE_RECYCLE_BIN_DELETED_BACKUPS = true;
private static readonly bool DEFAULT_AUTO_BACKUP_DATABASE = true;
private static readonly string DEFAULT_DATE_FORMAT = "yyyy.MM.dd_H.mm.ss";
private static readonly String EMPTY_STRING = "";
private static readonly char PATH_SEPERATOR = ';';

public KPSimpleBackupConfig(AceCustomConfig customConfig)
{
Expand All @@ -22,20 +27,23 @@ public bool BackupConfigured
{
get
{
return this.BackupPath != DEFAULT_BACKUP_PATH;
List<String> paths = this.BackupPath;
return !(paths.Count == 0 || paths[0] == EMPTY_STRING);
}
}

public String BackupPath
public List<String> BackupPath
{
get
{
return this.customConfig.GetString("KPSimpleBackupConfig_backupPath", DEFAULT_BACKUP_PATH);
String paths = this.customConfig.GetString("KPSimpleBackupConfig_backupPath", EMPTY_STRING);
return paths.Split(PATH_SEPERATOR).ToList();
}

set
{
this.customConfig.SetString("KPSimpleBackupConfig_backupPath", value);
String paths = String.Join(Char.ToString(PATH_SEPERATOR), value.ToArray());
this.customConfig.SetString("KPSimpleBackupConfig_backupPath", paths);
}
}

Expand Down Expand Up @@ -77,5 +85,31 @@ public bool UseRecycleBinDeletedBackups
this.customConfig.SetBool("KPSimpleBackupConfig_useRecycleBinDeletedBackups", value);
}
}

public bool AutoDatabaseBackup
{
get
{
return this.customConfig.GetBool("KPSimpleBackupConfig_autoDatabaseBackup", DEFAULT_AUTO_BACKUP_DATABASE);
}

set
{
this.customConfig.SetBool("KPSimpleBackupConfig_autoDatabaseBackup", value);
}
}

public string DateFormat
{
get
{
return this.customConfig.GetString("KPSimpleBackupConfig_dateFormat", DEFAULT_DATE_FORMAT);
}

set
{
this.customConfig.SetString("KPSimpleBackupConfig_dateFormat", value);
}
}
}
}
4 changes: 2 additions & 2 deletions KPSimpleBackup/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: NeutralResourcesLanguage("en")]

Loading

0 comments on commit d6756fa

Please sign in to comment.