commit 00ee9a7c1e2b7143f86bf42c033d001404f187de
parent de4d06c64b47df77b232e0e5a5054b18e5c8ec33
Author: rwa <apollo@rw-net.de>
Date: Fri, 9 Nov 2018 21:51:31 +0100
allow to set custom jpeg folder name
implements #13
Diffstat:
2 files changed, 48 insertions(+), 20 deletions(-)
diff --git a/JpegDivider/JpegDivider.csproj.user b/JpegDivider/JpegDivider.csproj.user
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
- <StartArguments>register</StartArguments>
+ <StartArguments>
+ </StartArguments>
<StartWorkingDirectory>C:\Users\winuser\Pictures</StartWorkingDirectory>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
diff --git a/JpegDivider/Program.cs b/JpegDivider/Program.cs
@@ -11,46 +11,68 @@ namespace JpegDivider
{
static void Main(string[] args)
{
- if (args.Length > 1)
+ if (args.Length > 2)
{
Console.WriteLine("Leave args blank or give exactly one dir!");
}
- switch (args[0].ToLower())
+ switch ((args.FirstOrDefault() ?? string.Empty).ToLower())
{
case "help":
ShowHelp();
- return;
+ break;
case "register":
RegisterShellExt();
- return;
+ break;
case "deregister":
DeregisterShellExt();
- return;
+ break;
+ case "setfolder":
+ if (args.Length < 2) { Console.WriteLine("No folder given"); }
+ SetFolder(args[1]);
+ break;
default:
+ string dir;
+ if (args.Length > 0 && Directory.Exists(args[0]))
+ {
+ dir = args[0];
+ }
+ else
+ {
+ dir = Directory.GetCurrentDirectory();
+ }
+
+ Divide(dir);
+
break;
}
- string dir;
- if (args.Length > 0 && Directory.Exists(args[0]))
- {
- dir = args[0];
- }
- else
+ Console.WriteLine("");
+ Console.WriteLine("Press any key...");
+ Console.ReadKey();
+ }
+
+ private static void SetFolder(string folder)
+ {
+ if (string.IsNullOrWhiteSpace(folder) || folder.IndexOfAny(Path.GetInvalidPathChars()) >= 0)
{
- dir = Directory.GetCurrentDirectory();
+ Console.WriteLine("Invalid folder name.");
+ return;
}
- Divide(dir);
-
- Console.ReadKey();
+ Registry.SetValue(@"HKEY_CURRENT_USER\Software\JpegDivider", "folder", folder);
+ Console.WriteLine("Custom folder name successfully set.");
}
private static void Divide(string dir)
{
- Console.WriteLine($"working directory: {dir}");
+ Console.WriteLine($"Working directory: {dir}");
+
+ string subfolder = (string)Registry.GetValue(@"HKEY_CURRENT_USER\Software\JpegDivider", "folder", "JPEG") ?? "JPEG";
+ Console.WriteLine($"Jpeg subfolder: {subfolder}");
+
// create
- string sepDir = Path.Combine(dir, "JPEG");
+ string sepDir = Path.Combine(dir, subfolder);
if (!Directory.Exists(sepDir))
{
Directory.CreateDirectory(sepDir);
@@ -63,7 +85,7 @@ namespace JpegDivider
Console.WriteLine($"Found {files.Count} files.");
foreach (string file in files)
{
- Console.Write($"moving file {Path.GetFileName(file)}...");
+ Console.Write($"Moving file {Path.GetFileName(file)}...");
try
{
File.Move(file, Path.Combine(sepDir, Path.GetFileName(file)));
@@ -99,6 +121,8 @@ namespace JpegDivider
reg.Close();
Registry.ClassesRoot.DeleteSubKey(MenuName);
}
+
+ Console.WriteLine("Successfully registered to explorer context menu");
}
catch (Exception ex)
{
@@ -127,6 +151,8 @@ namespace JpegDivider
{
regcmd.SetValue("", $"\"{Assembly.GetEntryAssembly().Location}\" \"%L\"");
}
+
+ Console.WriteLine("Successfully registered from explorer context menu");
}
catch (Exception ex)
{
@@ -152,12 +178,13 @@ namespace JpegDivider
Console.WriteLine("Copyright(c) 2018, René Wagner");
Console.WriteLine("https://gitlab.com/guzzisti1/rawfilewizard");
Console.WriteLine("");
- Console.WriteLine("divide jpegs from raw files by moving them to subfolder JPEG");
+ Console.WriteLine("divide jpegs from raw files by moving them to a specified subfolder (default: JPEG)");
Console.WriteLine("the subfolder is created if not existing");
Console.WriteLine("");
Console.WriteLine("commandline:");
Console.WriteLine("jpegdivider.exe - move jpegs from current working dir to subfolder");
Console.WriteLine("jpgedivider.exe <path_to_folder> - move jpegs from specified folder to subfolder");
+ Console.WriteLine("jpegdivider.exe setfolder <folder_name> - set a custom folder name, default is JPEG");
Console.WriteLine("jpegdivider.exe register - register the program to folder context menu, run JpegDivider on a selected folder from Windows Explorer");
Console.WriteLine("jpegdivider.exe deregister - remove the programm from folder context menu");
Console.WriteLine("jpgedivider.exe help - show this help");