fixing #6 and #3 · 58611739ae - SVN.BY: Go Git Service
Browse Source

fixing #6 and #3

Tiernan OToole 8 years ago
parent
commit
58611739ae
1 changed files with 22 additions and 2 deletions
  1. 22 2
      B2Uploader/Program.cs

+ 22 - 2
B2Uploader/Program.cs

@@ -23,6 +23,12 @@ namespace B2Uploader
23 23
 
24 24
         [Option('d', "directory", HelpText = "Directory you want to upload", Required = true)]
25 25
         public string Directory { get; set; }
26
+
27
+        [Option('m', "multithreads", HelpText = "Number of uploads you want to use at a time. Default is 2", Required = false)]
28
+        public int Threads { get; set; }
29
+
30
+        [Option('r', "recursive", HelpText = "Uploads the directory in Recursive mode. Any sub folders will also be uploaded", Required = false)]
31
+        public bool recursive { get; set; }
26 32
         
27 33
         [Option('v', "verbose", HelpText="Verbose Output")]
28 34
         public bool Verbose{get;set;}
@@ -46,8 +52,22 @@ namespace B2Uploader
46 52
 
47 53
                 var bucket = buckets.buckets.First();
48 54
 
49
-                string[] FilesToProcess = Directory.GetFiles(options.Directory);
50
-                Parallel.ForEach(FilesToProcess, new ParallelOptions() { MaxDegreeOfParallelism = 32 }, s =>
55
+                SearchOption so = SearchOption.TopDirectoryOnly;
56
+                if (options.recursive)
57
+                {
58
+                    so = SearchOption.AllDirectories;
59
+                }
60
+
61
+                string[] FilesToProcess = Directory.GetFiles(options.Directory, "*", so);
62
+
63
+                int maxParallel = 2;
64
+
65
+                if(options.Threads > 2)
66
+                {
67
+                    maxParallel = options.Threads;
68
+                }
69
+
70
+                Parallel.ForEach(FilesToProcess, new ParallelOptions() { MaxDegreeOfParallelism = maxParallel }, s =>
51 71
                 {
52 72
                     //check if file already exists
53 73