From f251c2610228fa416ad98f1323a399f912464914 Mon Sep 17 00:00:00 2001 From: Julian van de Groep Date: Fri, 16 Aug 2019 21:13:18 +0200 Subject: [PATCH] adjustments to the filesystem storage method --- BackupManager/Config.cs | 2 +- BackupManager/Program.cs | 51 ++++++---------------------------- BackupManager/StorageMethod.cs | 2 +- 3 files changed, 11 insertions(+), 44 deletions(-) diff --git a/BackupManager/Config.cs b/BackupManager/Config.cs index f28573a..c4caeae 100644 --- a/BackupManager/Config.cs +++ b/BackupManager/Config.cs @@ -12,7 +12,7 @@ public string SftpBackupDirectoryPath { get; set; } public string SftpTrustedHost { get; set; } - public string FileSystemPath { get; set; } = @"backups"; + public string FileSystemPathV2 { get; set; } public string MySqlDumpPathWindows { get; set; } = @"C:\Program Files\MariaDB 10.3\bin\mysqldump.exe"; public string MySqlDumpPath { get; set; } = @"mysqldump"; diff --git a/BackupManager/Program.cs b/BackupManager/Program.cs index aabfc0b..88a59d6 100644 --- a/BackupManager/Program.cs +++ b/BackupManager/Program.cs @@ -40,6 +40,10 @@ namespace BackupManager CONFIG_NAME ); + public static string FSPath => string.IsNullOrWhiteSpace(Config.FileSystemPathV2) + ? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), @"Backups") + : Config.FileSystemPathV2; + private static object BackupStorage; private static SftpClient SFTP; @@ -150,8 +154,8 @@ namespace BackupManager break; case StorageMethod.FileSystem: - if (!Directory.Exists(Config.FileSystemPath)) - Directory.CreateDirectory(Config.FileSystemPath); + if (!Directory.Exists(FSPath)) + Directory.CreateDirectory(FSPath); break; } @@ -179,12 +183,12 @@ namespace BackupManager if (Directory.Exists(Config.MisuzuPath)) { Log(@"Filesystem backup..."); - string mszConfig = GetMisuzuConfig(); + string mszConfig = Path.Combine(Config.MisuzuPath, @"config/config.ini"); if (!File.Exists(mszConfig)) Error(@"Could not find Misuzu config."); - string mszStore = FindMisuzuStorageDir(mszConfig); + string mszStore = Path.Combine(Config.MisuzuPath, @"store"); if (!Directory.Exists(mszStore)) Error(@"Could not find Misuzu storage directory."); @@ -273,43 +277,6 @@ namespace BackupManager return null; } - public static string GetMisuzuConfig() - { - return Path.Combine(Config.MisuzuPath, @"config/config.ini"); - } - - public static string FindMisuzuStorageDir(string config) - { - Log(@"Finding storage directory..."); - - string[] configLines = File.ReadAllLines(config); - bool storageSectionFound = false; - string path = string.Empty; - - foreach (string line in configLines) - { - if (!string.IsNullOrEmpty(path)) - break; - if (line.StartsWith('[')) - storageSectionFound = line == @"[Storage]"; - if (!storageSectionFound) - continue; - - string[] split = line.Split('=', StringSplitOptions.RemoveEmptyEntries); - - if (split.Length < 2 || split[0] != @"path") - continue; - - path = string.Join('=', split.Skip(1)); - break; - } - - if (string.IsNullOrEmpty(path)) - path = Path.Combine(Config.MisuzuPath, @"store"); - - return path; - } - public static string CreateMisuzuDataBackup(string configPath, string storePath) { Log(@"Creating Zip archive containing non-volatile Misuzu data..."); @@ -407,7 +374,7 @@ namespace BackupManager break; case StorageMethod.FileSystem: - BackupStorage = name ?? Config.FileSystemPath; + BackupStorage = name ?? FSPath; break; } } diff --git a/BackupManager/StorageMethod.cs b/BackupManager/StorageMethod.cs index 47fd2cf..e83a2c6 100644 --- a/BackupManager/StorageMethod.cs +++ b/BackupManager/StorageMethod.cs @@ -4,6 +4,6 @@ { //GoogleDrive = 1, Sftp = 2, - FileSystem = 4, // for debugging mysqldump + FileSystem = 4, } }