diff --git a/wbackup/BackupStreamBase.cs b/wbackup/BackupStreamBase.cs new file mode 100644 index 0000000..4c1c465 --- /dev/null +++ b/wbackup/BackupStreamBase.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; +using System.Collections.Concurrent; + +namespace wbackup +{ + class BackupStreamBase + { + protected bool working; + protected BackupStreamBase nextStream = null; + protected ConcurrentQueue sourceFileQueue = null; + protected Thread threadInstance = null; + + public BackupStreamBase(BackupStreamBase stream = null) + { + nextStream = stream; + sourceFileQueue = new ConcurrentQueue(); + threadInstance = new Thread(this.DoWork); + } + + /// + /// バックアップ対象フォルダを追加する + /// + /// + public void AddSource(string newFolder) + { + sourceFileQueue.Enqueue(newFolder); + } + + public void Start() + { + threadInstance.Start(); + } + + public void DoWork(object data) + { + working = true; + while (true) + { + // 次に処理すべきデータを取得する + string sourceFileName; + if (false == sourceFileQueue.TryDequeue(out sourceFileName)) + { + Thread.Sleep(1000); + continue; + } + + // これ以上処理するデータが無いことを示す + if (sourceFileName == "") + { + nextStream.AddSource(""); + break; + } + + // ファイルの処理を行う + DoWork(sourceFileName); + } + working = false; + } + + public virtual void DoWork(string sourceFileName) + { + + } + } +} diff --git a/wbackup/ListingAllSourceFile.cs b/wbackup/ListingAllSourceFile.cs new file mode 100644 index 0000000..c9ffbd6 --- /dev/null +++ b/wbackup/ListingAllSourceFile.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Collections.Concurrent; +using System.Numerics; +using System.IO; +using System.Threading.Tasks; +using System.Text.RegularExpressions; + +namespace wbackup +{ + class ListingAllSourceFile : BackupStreamBase + { + protected List ignoreFolder = new List(); + + public ListingAllSourceFile(BackupStreamBase stream = null):base(stream) + { + + } + + + /// + /// バックアップ除外フォルダを追加する + /// + /// + public void AddIgnoreFolder(string newFolder) + { + ignoreFolder.Add(newFolder); + } + + public override void DoWork(string sourceFileName) + { + ListingSourceFiles(sourceFileName); + } + + /// + /// ソースファイルのリストを作成する + /// + /// + protected void ListingSourceFiles(string rootFolder) + { + foreach (string fileName in Directory.GetFiles(rootFolder)) + { + if (false == isIgnoreFile(fileName)) + { + var fileAttrib = File.GetAttributes(fileName); + File.SetAttributes(fileName, fileAttrib | FileAttributes.Archive); + nextStream.AddSource(fileName); + } + } + + foreach (string directory in Directory.GetDirectories(rootFolder)) + { + var dirAttrib = File.GetAttributes(directory); + if (false == dirAttrib.HasFlag(FileAttributes.Hidden)) + { + ListingSourceFiles(directory); + } + } + } + + /// + /// バックアップ対象外ファイルか判定する + /// + /// + /// + protected bool isIgnoreFile(string sourceFileName) + { + foreach (var ignoreInfo in ignoreFolder) + { + if (Regex.IsMatch(sourceFileName, ignoreInfo)) + { + return true; + } + } + + return false; + } + } +} diff --git a/wbackup/wBackupEngine.cs b/wbackup/wBackupEngine.cs index 0951870..b8c82f6 100644 --- a/wbackup/wBackupEngine.cs +++ b/wbackup/wBackupEngine.cs @@ -78,6 +78,10 @@ }); } + /// + /// ソースファイルのリストを作成する + /// + /// protected void ListingSourceFiles(string rootFolder) { foreach (string fileName in Directory.GetFiles(rootFolder)) @@ -108,6 +112,11 @@ } } + /// + /// ファイル先頭4KBからハッシュ値を算出する + /// + /// + /// protected uint CalclateHash(string fileName) { byte[] readbuff = new byte[1024 * 4];