diff --git a/wbackup.sln b/wbackup.sln new file mode 100644 index 0000000..feda39d --- /dev/null +++ b/wbackup.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30413.136 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "wbackup", "wbackup\wbackup.csproj", "{1EA6ED4D-C97F-4CBA-B30D-786647B21198}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1EA6ED4D-C97F-4CBA-B30D-786647B21198}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1EA6ED4D-C97F-4CBA-B30D-786647B21198}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1EA6ED4D-C97F-4CBA-B30D-786647B21198}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1EA6ED4D-C97F-4CBA-B30D-786647B21198}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {59B6E51D-A4F6-4A19-9617-0342D85BB4D8} + EndGlobalSection +EndGlobal diff --git a/wbackup/CommandParser.cs b/wbackup/CommandParser.cs new file mode 100644 index 0000000..29f4333 --- /dev/null +++ b/wbackup/CommandParser.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace wbackup +{ + class CommandParser + { + public string sourceDir; + public string destinationDir; + + public CommandParser(string[] args) + { + bool isSource = false; ; + bool isDestination = false; + + foreach (var arg in args) + { + if ('-' == arg.First() || '/' == arg.First()) + { + string command = arg.Substring(1); + if ("srce" == command.ToLower()) + { + isSource = true; + } + if ("dest" == command.ToLower()) + { + isDestination = true; + } + } + else + { + if (isSource) + { + sourceDir = arg; + isSource = false; + } + + if (isDestination) + { + destinationDir = arg; + isDestination = false; + } + } + } + } + } +} diff --git a/wbackup/Program.cs b/wbackup/Program.cs new file mode 100644 index 0000000..3968e9a --- /dev/null +++ b/wbackup/Program.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.IO; +using System.IO.Enumeration; +using System.Linq; +using System.Threading; +using System.Security.Cryptography.X509Certificates; +using ICSharpCode.SharpZipLib.Zip; +using System.Threading.Tasks; + +namespace wbackup +{ + class Program + { + public static CommandParser param; + + static void Main(string[] args) + { + param = new CommandParser(args); + ConcurrentQueue srceFilesQueue = new ConcurrentQueue(Directory.GetFiles(param.sourceDir, "*.*", SearchOption.AllDirectories)); + + Parallel.For(0, 4, i => + { + var nameTrans = new ZipNameTransform(); + var zf = ZipFile.Create(param.destinationDir + "-" + DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + i.ToString("00") + ".zip"); + zf.BeginUpdate(); + + while (srceFilesQueue.TryDequeue(out string srceFileName)) + { + if (File.GetAttributes(srceFileName).HasFlag(FileAttributes.Archive)) + { + string f = nameTrans.TransformFile(srceFileName); + + zf.Add(srceFileName, f); + } + } + + zf.CommitUpdate(); + }); + + Console.WriteLine("Hello World!"); + } + } +} diff --git a/wbackup/Properties/launchSettings.json b/wbackup/Properties/launchSettings.json new file mode 100644 index 0000000..cc18adf --- /dev/null +++ b/wbackup/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "wbackup": { + "commandName": "Project", + "commandLineArgs": "-srce \"D:\\win32_11gR2_client\" -dest \"C:\\CLWORK\\archive\"" + } + } +} \ No newline at end of file diff --git a/wbackup/wbackup.csproj b/wbackup/wbackup.csproj new file mode 100644 index 0000000..d07cc14 --- /dev/null +++ b/wbackup/wbackup.csproj @@ -0,0 +1,12 @@ + + + + Exe + netcoreapp3.1 + + + + + + +