diff --git a/wbackup/CommandParser.cs b/wbackup/CommandParser.cs index 032ea58..17c2944 100644 --- a/wbackup/CommandParser.cs +++ b/wbackup/CommandParser.cs @@ -6,6 +6,12 @@ namespace wbackup { + public enum ArchiveMode + { + tar, + tgz, + tbz + } public enum BackupMopde { @@ -21,8 +27,11 @@ public string destinationDir; public string logFileName; public DateTime? abortedTime = null; + public string preFixText = ""; + public string postFixText = ""; public BackupMopde backupMode = BackupMopde.Full; + public ArchiveMode archiveMode = ArchiveMode.tgz; public CommandParser(string[] args) { @@ -36,6 +45,18 @@ if ('-' == arg.First() || '/' == arg.First()) { string command = arg.Substring(1); + if ("tar" == command.ToLower()) + { + archiveMode = ArchiveMode.tar; + } + if ("tgz" == command.ToLower()) + { + archiveMode = ArchiveMode.tgz; + } + if ("tbz" == command.ToLower()) + { + archiveMode = ArchiveMode.tbz; + } if ("full" == command.ToLower()) { backupMode = BackupMopde.Full; diff --git a/wbackup/lib/ICSharpCode.SharpZipLib.dll b/wbackup/lib/ICSharpCode.SharpZipLib.dll new file mode 100644 index 0000000..e2e0483 --- /dev/null +++ b/wbackup/lib/ICSharpCode.SharpZipLib.dll Binary files differ diff --git a/wbackup/wBackupEngine.cs b/wbackup/wBackupEngine.cs new file mode 100644 index 0000000..0951870 --- /dev/null +++ b/wbackup/wBackupEngine.cs @@ -0,0 +1,139 @@ +using System; +using System.Collections.Generic; +using System.Collections.Concurrent; +using System.Numerics; +using System.Text; +using System.IO; +using ICSharpCode.SharpZipLib.GZip; +using ICSharpCode.SharpZipLib.Tar; +using System.Threading.Tasks; +using System.Linq; + +namespace wbackup +{ + class HardLinkFile + { + string sourceFileName; + string distanceFileName; + }; + + class DulplicateCheckDatabase + { + string directory; + string fileName; + uint hashValue; + uint fileSize; + } + + class wBackupEngine + { + protected int maxThread = 4; + protected BackupMopde backupMode = BackupMopde.Full; + protected List sourceFolder = new List(); + protected List ignoreFolder = new List(); + protected ConcurrentBag abortedFile = new ConcurrentBag(); + protected ConcurrentBag completeFile = new ConcurrentBag(); + protected ConcurrentBag hardLinkList = new ConcurrentBag(); + protected List> compressQueue = new List>(); + + public wBackupEngine() + { + + } + + /// + /// バックアップ対象フォルダを追加する + /// + /// + public void AddSourceFolder(string newFolder) + { + sourceFolder.Add(newFolder); + } + + /// + /// バックアップ除外フォルダを追加する + /// + /// + public void AddIgnoreFolder(string newFolder) + { + ignoreFolder.Add(newFolder); + } + + public void Do() + { + + } + + /// + /// バックアップ対象ファイルを列挙する + /// + protected async Task ListingSourceFiles() + { + await Task.Run(() => + { + foreach (string rootFolder in sourceFolder) + { + ListingSourceFiles(rootFolder); + } + }); + } + + protected void ListingSourceFiles(string rootFolder) + { + foreach (string fileName in Directory.GetFiles(rootFolder)) + { + if (backupMode == BackupMopde.Full) + { + var fileAttrib = File.GetAttributes(fileName); + File.SetAttributes(fileName, fileAttrib | FileAttributes.Archive); + uint hashValue = CalclateHash(fileName); + } + if (backupMode == BackupMopde.Incremental) + { + var fileAttrib = File.GetAttributes(fileName); + if (fileAttrib.HasFlag(FileAttributes.Archive)) + { + uint hashValue = CalclateHash(fileName); + } + } + } + + foreach (string directory in Directory.GetDirectories(rootFolder)) + { + var dirAttrib = File.GetAttributes(directory); + if (false == dirAttrib.HasFlag(FileAttributes.Hidden)) + { + ListingSourceFiles(directory); + } + } + } + + protected uint CalclateHash(string fileName) + { + byte[] readbuff = new byte[1024 * 4]; + Array.Clear(readbuff, 0, readbuff.Length); + Vector hashTemp1 = Vector.Zero; + Vector hashTemp2 = Vector.Zero; + using (var fs = File.OpenRead(fileName)) + { + int readLen = fs.Read(readbuff, 0, readbuff.Length); + fs.Close(); + ReadOnlySpan span = new ReadOnlySpan(readbuff); + for (int i = 0; i < readbuff.Length; i += Vector.Count * sizeof(int)) + { + hashTemp2 = new Vector(span.Slice(i, Vector.Count * sizeof(uint))); + hashTemp1 ^= hashTemp2; + } + } + + uint hashValue = 0; + for (int i = 0; i < Vector.Count; i++) + { + hashValue ^= hashTemp1[i]; + } + + return hashValue; + } + + } +}