From 8a0c93172c17b7b6811c497f8e9c09c1e7a87e3c Mon Sep 17 00:00:00 2001 From: FUH22860 Date: Fri, 13 Jan 2023 14:28:52 +0100 Subject: [PATCH] Added compression && changed directory structure --- Program.cs | 9 ++++++--- Update.cs | 24 +++++++++++++++++++++++- update.csproj | 4 ++++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Program.cs b/Program.cs index 78fa15c..7700fb3 100644 --- a/Program.cs +++ b/Program.cs @@ -3,9 +3,12 @@ string result = Update.copyEverthingBeforeUpdateToBackupLocation(); Console.WriteLine(result); - string result2 = Update.copyEverthingFromBackupLocationToFinalDestination(); - Console.WriteLine(result2); + //string result2 = Update.copyEverthingFromBackupLocationToFinalDestination(); + //Console.WriteLine(result2); - Console.WriteLine(args); + //Console.WriteLine(args.Length); + + bool result3 = Update.zipAllContentInBackupLocation(); + Console.WriteLine(result3); } } \ No newline at end of file diff --git a/Update.cs b/Update.cs index 0b6e288..fe15846 100644 --- a/Update.cs +++ b/Update.cs @@ -1,3 +1,5 @@ +using System.IO.Compression; + public class Update { public static string getHomePath() { string homePath = string.Empty; @@ -10,7 +12,7 @@ public class Update { } } public static string copyEverthingBeforeUpdateToBackupLocation() { - string targetPath = getHomePath() + "/backup/"; + string targetPath = getHomePath() + "/backup/uncompressed/"; string[] systemFilesToCopy = {"/etc/fstab", "/etc/makepkg.conf"}; List filesToCopy = new List(systemFilesToCopy); @@ -67,4 +69,24 @@ public class Update { return "You have not configured a backup location!"; } } + + public static bool zipAllContentInBackupLocation() { + string targetPath = getHomePath() + "/backup/compressed/"; + Directory.CreateDirectory(targetPath); + + string sourcePath = getHomePath() + "/backup/uncompressed/"; + string targetZip = getHomePath() + "/backup/compressed/backup.zip"; + ZipFile.CreateFromDirectory(sourcePath, targetZip); + + string pacmanDatabaseLocation = "/var/lib/pacman/local/"; + string pacmanDatabaseZip = getHomePath() + "/backup/compressed/pacman_database.zip"; + ZipFile.CreateFromDirectory(pacmanDatabaseLocation, pacmanDatabaseZip); + + if (File.Exists(targetZip) && File.Exists(pacmanDatabaseZip)) { + return true; + } else { + return false; + } + + } } \ No newline at end of file diff --git a/update.csproj b/update.csproj index 1957e72..110dc7d 100644 --- a/update.csproj +++ b/update.csproj @@ -10,5 +10,9 @@ enable enable + + + +