ソースを参照

ADD: WebpDirConv

HOME 8 ヶ月 前
コミット
dea646b31f

+ 16 - 2
StrangeTools.sln

@@ -78,9 +78,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CompressWorker", "CompressW
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SniTamper", "SniTamper", "{0CAFC020-EA0B-4DB1-9782-645970A53BA5}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SniTamperPoc", "SniTamperPoc\SniTamperPoc.csproj", "{BAEB09B6-59C9-479C-AB35-12BC2C10F5AE}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SniTamperPoc", "SniTamperPoc\SniTamperPoc.csproj", "{BAEB09B6-59C9-479C-AB35-12BC2C10F5AE}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SniTamperProxy", "SniTamperProxy\SniTamperProxy.csproj", "{8E775D0B-CB5E-4921-81F0-D236F60072FC}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SniTamperProxy", "SniTamperProxy\SniTamperProxy.csproj", "{8E775D0B-CB5E-4921-81F0-D236F60072FC}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreateTimePrefixRen", "CreateTimePrefixRen\CreateTimePrefixRen.csproj", "{FB7B086B-EAB5-4694-88F6-7BD794224532}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebpDirConv", "WebpDirConv\WebpDirConv.csproj", "{9AC94CF3-80A1-4558-BDA9-A6D99C8F643A}"
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -220,6 +224,14 @@ Global
 		{8E775D0B-CB5E-4921-81F0-D236F60072FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{8E775D0B-CB5E-4921-81F0-D236F60072FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{8E775D0B-CB5E-4921-81F0-D236F60072FC}.Release|Any CPU.Build.0 = Release|Any CPU
+		{FB7B086B-EAB5-4694-88F6-7BD794224532}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{FB7B086B-EAB5-4694-88F6-7BD794224532}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{FB7B086B-EAB5-4694-88F6-7BD794224532}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{FB7B086B-EAB5-4694-88F6-7BD794224532}.Release|Any CPU.Build.0 = Release|Any CPU
+		{9AC94CF3-80A1-4558-BDA9-A6D99C8F643A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{9AC94CF3-80A1-4558-BDA9-A6D99C8F643A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{9AC94CF3-80A1-4558-BDA9-A6D99C8F643A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{9AC94CF3-80A1-4558-BDA9-A6D99C8F643A}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -260,6 +272,8 @@ Global
 		{0CAFC020-EA0B-4DB1-9782-645970A53BA5} = {3120ADE6-C606-42F1-9AA8-B7F1A8933CD7}
 		{BAEB09B6-59C9-479C-AB35-12BC2C10F5AE} = {0CAFC020-EA0B-4DB1-9782-645970A53BA5}
 		{8E775D0B-CB5E-4921-81F0-D236F60072FC} = {0CAFC020-EA0B-4DB1-9782-645970A53BA5}
+		{FB7B086B-EAB5-4694-88F6-7BD794224532} = {3120ADE6-C606-42F1-9AA8-B7F1A8933CD7}
+		{9AC94CF3-80A1-4558-BDA9-A6D99C8F643A} = {3120ADE6-C606-42F1-9AA8-B7F1A8933CD7}
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 		SolutionGuid = {017A8C58-F476-47E7-9CBE-077A98A76AB4}

+ 77 - 0
WebpDirConv/Program.cs

@@ -0,0 +1,77 @@
+using System.Diagnostics;
+
+
+if (args.Length != 2)
+{
+    Console.WriteLine("Err: 2 args required, <inputDir> <outputDir>");
+    return 1;
+}
+
+var inputDir = args[0];
+var outputDir = args[1];
+
+if (!Directory.Exists(inputDir))
+{
+    Console.WriteLine("Err: inputDir dose not exist");
+    return 1;
+}
+
+if (!Directory.Exists(outputDir))
+{
+    Console.WriteLine("Err: outputDir dose not exist");
+    return 1;
+}
+
+Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Idle;
+
+var fullInputDir = Path.GetFullPath(inputDir);
+var fullOutputDir = Path.GetFullPath(outputDir);
+
+var filePathsToProcess = Directory.GetFiles(fullInputDir, "*", SearchOption.AllDirectories);
+
+void ProcessFunc(string inputFilePath)
+{
+    var outputFilePath = Path.ChangeExtension(Path.Combine(fullOutputDir, inputFilePath[(fullInputDir.Length + 1)..]), ".webp");
+    if (File.Exists(outputFilePath))
+    {
+        lock (Console.Out) Console.WriteLine("SKIP EXIST: " + outputFilePath);
+        return;
+    }
+
+    var outputFileDir = Path.GetDirectoryName(outputFilePath);
+    if (Directory.Exists(outputFileDir) == false)
+    {
+        lock (Console.Out) Console.WriteLine("Create dir: " + outputFileDir);
+        Directory.CreateDirectory(outputFileDir);
+    }
+
+    var pWebp = new Process
+    {
+        StartInfo =
+        {
+            FileName = "cwebp",
+            ArgumentList =
+            {
+                inputFilePath, "-o", outputFilePath , "-quiet"
+            },
+            UseShellExecute = false,
+            CreateNoWindow = false,
+
+        }
+    };
+
+    pWebp.Start();
+    pWebp.WaitForExit();
+
+    lock (Console.Out) Console.WriteLine($"PROCESS {pWebp.ExitCode} {outputFilePath}");
+}
+
+Parallel.ForEach(filePathsToProcess, ProcessFunc);
+
+// for debug
+//foreach (var s in filePathsToProcess)
+//{
+//    ProcessFunc(s);
+//}
+
+return 0;

+ 8 - 0
WebpDirConv/Properties/launchSettings.json

@@ -0,0 +1,8 @@
+{
+  "profiles": {
+    "WebpDirConv": {
+      "commandName": "Project",
+      "commandLineArgs": "F:\\var\\tmp\\de_s Z:\\var\\tmp\\de_w" 
+    }
+  }
+}

+ 10 - 0
WebpDirConv/WebpDirConv.csproj

@@ -0,0 +1,10 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>net8.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+  </PropertyGroup>
+
+</Project>