Browse code

allow to set custom jpeg folder name

implements #13

rwa authored on 09.11.2018 21:51:31
Showing 2 changed files

... ...
@@ -1,7 +1,8 @@
1 1
 <?xml version="1.0" encoding="utf-8"?>
2 2
 <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 3
   <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
4
-    <StartArguments>register</StartArguments>
4
+    <StartArguments>
5
+    </StartArguments>
5 6
     <StartWorkingDirectory>C:\Users\winuser\Pictures</StartWorkingDirectory>
6 7
   </PropertyGroup>
7 8
   <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
... ...
@@ -11,46 +11,68 @@ namespace JpegDivider
11 11
     {
12 12
         static void Main(string[] args)
13 13
         {
14
-            if (args.Length > 1)
14
+            if (args.Length > 2)
15 15
             {
16 16
                 Console.WriteLine("Leave args blank or give exactly one dir!");
17 17
             }
18 18
 
19
-            switch (args[0].ToLower())
19
+            switch ((args.FirstOrDefault() ?? string.Empty).ToLower())
20 20
             {
21 21
                 case "help":
22 22
                     ShowHelp();
23
-                    return;
23
+                    break;
24 24
                 case "register":
25 25
                     RegisterShellExt();
26
-                    return;
26
+                    break;
27 27
                 case "deregister":
28 28
                     DeregisterShellExt();
29
-                    return;
29
+                    break;
30
+                case "setfolder":
31
+                    if (args.Length < 2) { Console.WriteLine("No folder given"); }
32
+                    SetFolder(args[1]);
33
+                    break;
30 34
                 default:
35
+                    string dir;
36
+                    if (args.Length > 0 && Directory.Exists(args[0]))
37
+                    {
38
+                        dir = args[0];
39
+                    }
40
+                    else
41
+                    {
42
+                        dir = Directory.GetCurrentDirectory();
43
+                    }
44
+
45
+                    Divide(dir);
46
+
31 47
                     break;
32 48
             }
33 49
 
34
-            string dir;
35
-            if (args.Length > 0 && Directory.Exists(args[0]))
36
-            {
37
-                dir = args[0];
38
-            }
39
-            else
50
+            Console.WriteLine("");
51
+            Console.WriteLine("Press any key...");
52
+            Console.ReadKey();
53
+        }
54
+
55
+        private static void SetFolder(string folder)
56
+        {
57
+            if (string.IsNullOrWhiteSpace(folder) || folder.IndexOfAny(Path.GetInvalidPathChars()) >= 0)
40 58
             {
41
-                dir = Directory.GetCurrentDirectory();
59
+                Console.WriteLine("Invalid folder name.");
60
+                return;
42 61
             }
43 62
 
44
-            Divide(dir);
45
-
46
-            Console.ReadKey();
63
+            Registry.SetValue(@"HKEY_CURRENT_USER\Software\JpegDivider", "folder", folder);
64
+            Console.WriteLine("Custom folder name successfully set.");
47 65
         }
48 66
 
49 67
         private static void Divide(string dir)
50 68
         {
51
-            Console.WriteLine($"working directory: {dir}");
69
+            Console.WriteLine($"Working directory: {dir}");
70
+
71
+            string subfolder = (string)Registry.GetValue(@"HKEY_CURRENT_USER\Software\JpegDivider", "folder", "JPEG") ?? "JPEG";
72
+            Console.WriteLine($"Jpeg subfolder: {subfolder}");
73
+
52 74
             // create 
53
-            string sepDir = Path.Combine(dir, "JPEG");
75
+            string sepDir = Path.Combine(dir, subfolder);
54 76
             if (!Directory.Exists(sepDir))
55 77
             {
56 78
                 Directory.CreateDirectory(sepDir);
... ...
@@ -63,7 +85,7 @@ namespace JpegDivider
63 85
             Console.WriteLine($"Found {files.Count} files.");
64 86
             foreach (string file in files)
65 87
             {
66
-                Console.Write($"moving file {Path.GetFileName(file)}...");
88
+                Console.Write($"Moving file {Path.GetFileName(file)}...");
67 89
                 try
68 90
                 {
69 91
                     File.Move(file, Path.Combine(sepDir, Path.GetFileName(file)));
... ...
@@ -99,6 +121,8 @@ namespace JpegDivider
99 121
                     reg.Close();
100 122
                     Registry.ClassesRoot.DeleteSubKey(MenuName);
101 123
                 }
124
+
125
+                Console.WriteLine("Successfully registered to explorer context menu");
102 126
             }
103 127
             catch (Exception ex)
104 128
             {
... ...
@@ -127,6 +151,8 @@ namespace JpegDivider
127 151
                 {
128 152
                     regcmd.SetValue("", $"\"{Assembly.GetEntryAssembly().Location}\" \"%L\"");
129 153
                 }
154
+
155
+                Console.WriteLine("Successfully registered from explorer context menu");
130 156
             }
131 157
             catch (Exception ex)
132 158
             {
... ...
@@ -152,12 +178,13 @@ namespace JpegDivider
152 178
             Console.WriteLine("Copyright(c) 2018, René Wagner");
153 179
             Console.WriteLine("https://gitlab.com/guzzisti1/rawfilewizard");
154 180
             Console.WriteLine("");
155
-            Console.WriteLine("divide jpegs from raw files by moving them to subfolder JPEG");
181
+            Console.WriteLine("divide jpegs from raw files by moving them to a specified subfolder (default: JPEG)");
156 182
             Console.WriteLine("the subfolder is created if not existing");
157 183
             Console.WriteLine("");
158 184
             Console.WriteLine("commandline:");
159 185
             Console.WriteLine("jpegdivider.exe - move jpegs from current working dir to subfolder");
160 186
             Console.WriteLine("jpgedivider.exe <path_to_folder> - move jpegs from specified folder to subfolder");
187
+            Console.WriteLine("jpegdivider.exe setfolder <folder_name> - set a custom folder name, default is JPEG");
161 188
             Console.WriteLine("jpegdivider.exe register - register the program to folder context menu, run JpegDivider on a selected folder from Windows Explorer");
162 189
             Console.WriteLine("jpegdivider.exe deregister - remove the programm from folder context menu");
163 190
             Console.WriteLine("jpgedivider.exe help - show this help");