diff --git a/Saviour Backup System/Saviour Backup System.csproj b/Saviour Backup System/Saviour Backup System.csproj
index ceb79e7..dc70e1e 100644
--- a/Saviour Backup System/Saviour Backup System.csproj
+++ b/Saviour Backup System/Saviour Backup System.csproj
@@ -87,6 +87,7 @@
False
C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v4.0\Desktop\System.Data.SqlServerCe.dll
+
@@ -124,6 +125,7 @@
backupViewer.cs
+
Form
diff --git a/Saviour Backup System/compression.cs b/Saviour Backup System/compression.cs
new file mode 100644
index 0000000..24a3efc
--- /dev/null
+++ b/Saviour Backup System/compression.cs
@@ -0,0 +1,91 @@
+using System;
+using System.Text;
+using System.Collections.Generic;
+using System.IO;
+using System.IO.Compression;
+using System.Threading;
+using Microsoft.Win32;
+using System.Windows.Forms;
+namespace Saviour_Backup_System
+{
+ class compression
+ {
+ private static List threads = new List();
+ private volatile static string Gdirectory;
+ private volatile static string Goutput;
+ private volatile static string GfileName;
+
+ public static void Compress(string directory, string outputFile, bool LZMA) {
+ GfileName = outputFile.Split('.')[0]; Gdirectory = directory; Goutput = outputFile; //store as globals
+ compressToZip();
+ if (!LZMA) { //We dont need to do LZMA, so just, dont!
+ File.Copy(Gdirectory + "\\" + GfileName + ".zip", Gdirectory.Replace("\\Temp", "") + GfileName + ".backup");
+ }
+ else if (has7Zip() && LZMA) {
+ DialogResult result = MessageBox.Show("7-Zip has been detected on your computer\nWould you like to use this instead?", "Use 7-Zip?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
+ if (result == DialogResult.Yes) {
+ threads.Add(new Thread(new ThreadStart(compression7Zip)));
+ threads[threads.Count].Start();
+ return;
+ } else if (LZMA) {
+ //Code to interface with 7z.exe goes here!
+ }
+ }
+
+ }
+ private static void compression7Zip() { //need to write this!
+ string directory = Gdirectory;
+ string outputFile = Goutput;
+ return;
+ }
+
+ private static void compressToZip() {
+ ZipFile.CreateFromDirectory(Gdirectory, Gdirectory.Replace("\\Temp", "") + GfileName + ".zip");
+ }
+
+ private static void CompressFileLZMA(string inFile, string outFile)
+ {
+ SevenZip.Compression.LZMA.Encoder coder = new SevenZip.Compression.LZMA.Encoder();
+ FileStream input = new FileStream(inFile, FileMode.Open);
+ FileStream output = new FileStream(outFile, FileMode.Create);
+
+ // Write the encoder properties
+ coder.WriteCoderProperties(output);
+
+ // Write the decompressed file size.
+ output.Write(BitConverter.GetBytes(input.Length), 0, 8);
+
+ // Encode the file.
+ coder.Code(input, output, input.Length, -1, null);
+ output.Flush();
+ output.Close();
+ }
+
+ private static void DecompressFileLZMA(string inFile, string outFile)
+ {
+ SevenZip.Compression.LZMA.Decoder coder = new SevenZip.Compression.LZMA.Decoder();
+ FileStream input = new FileStream(inFile, FileMode.Open);
+ FileStream output = new FileStream(outFile, FileMode.Create);
+
+ // Read the decoder properties
+ byte[] properties = new byte[5];
+ input.Read(properties, 0, 5);
+
+ // Read in the decompress file size.
+ byte[] fileLengthBytes = new byte[8];
+ input.Read(fileLengthBytes, 0, 8);
+ long fileLength = BitConverter.ToInt64(fileLengthBytes, 0);
+
+ coder.SetDecoderProperties(properties);
+ coder.Code(input, output, input.Length, fileLength, null);
+ output.Flush();
+ output.Close();
+ }
+
+ private static bool has7Zip() {
+ string path = (string) Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\7-Zip", "Path", "NULL");
+ if (path == "NULL") { return false;}
+ return File.Exists(path + "7z.exe");
+ }
+ }
+}