Created
January 21, 2020 16:49
-
-
Save TheCrazyT/94bd3e8878ade4abc99ff8e7adda05a7 to your computer and use it in GitHub Desktop.
Batchmode for slimshader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/SlimShader.Studio/Modules/Startup/Module.cs b/src/SlimShader.Studio/Modules/Startup/Module.cs | |
index cc8b2fd..69a6880 100644 | |
--- a/src/SlimShader.Studio/Modules/Startup/Module.cs | |
+++ b/src/SlimShader.Studio/Modules/Startup/Module.cs | |
@@ -1,5 +1,7 @@ | |
using System.ComponentModel.Composition; | |
+using System.IO; | |
using System.Reflection; | |
+using System.Text; | |
using Caliburn.Micro; | |
using Gemini.Framework; | |
using Gemini.Framework.Results; | |
@@ -21,7 +23,45 @@ public Module(IResourceManager resourceManager) | |
public override void Initialize() | |
{ | |
- Shell.Title = "SlimShader Studio"; | |
+ var args = System.Environment.GetCommandLineArgs(); | |
+ if (args.Length > 1) | |
+ { | |
+ System.Diagnostics.Debug.Listeners.Clear(); | |
+ FormWithConsole.NativeMethods.AllocConsole(); | |
+ System.Console.WriteLine("initializing"); | |
+ if (args[1].Equals("*")) | |
+ { | |
+ DirectoryInfo d = new DirectoryInfo(@".");//Assuming Test is your Folder | |
+ FileInfo[] files = d.GetFiles("*.shdr"); //Getting Text files | |
+ string str = ""; | |
+ args = new string[files.Length+1]; | |
+ int i = 1; | |
+ foreach (FileInfo file in files) | |
+ { | |
+ args[i++] = file.Name; | |
+ } | |
+ } | |
+ for (int i = 1; i < args.Length; i++) { | |
+ var path = args[i]; | |
+ System.Console.WriteLine("converting {0}", path); | |
+ try | |
+ { | |
+ var _bytecodeContainer = BytecodeContainer.Parse(File.ReadAllBytes(path)); | |
+ var disassembledCode = _bytecodeContainer.ToString(); | |
+ File.WriteAllBytes(path + ".src", Encoding.ASCII.GetBytes(disassembledCode.ToCharArray())); | |
+ } | |
+ catch (System.Exception e) | |
+ { | |
+ System.Console.WriteLine("error {0}", e); | |
+ } | |
+ } | |
+ System.Console.WriteLine("Done.Press enter to finish."); | |
+ System.Console.ReadLine(); | |
+ System.Environment.Exit(0); | |
+ return; | |
+ } | |
+ | |
+ Shell.Title = "SlimShader Studio"; | |
Shell.Icon = _resourceManager.GetBitmap("Resources/Icon.ico", | |
Assembly.GetExecutingAssembly().GetAssemblyName()); | |
Shell.ShowTool(IoC.Get<ControlFlowViewerViewModel>()); | |
diff --git a/src/SlimShader.Studio/SlimShader.Studio.csproj b/src/SlimShader.Studio/SlimShader.Studio.csproj | |
index 57f7658..f6993b4 100644 | |
--- a/src/SlimShader.Studio/SlimShader.Studio.csproj | |
+++ b/src/SlimShader.Studio/SlimShader.Studio.csproj | |
@@ -131,6 +131,7 @@ | |
<Compile Include="Modules\ShaderViewer\Views\EditorView.xaml.cs"> | |
<DependentUpon>EditorView.xaml</DependentUpon> | |
</Compile> | |
+ <Compile Include="Modules\Startup\Class1.cs" /> | |
<Compile Include="Modules\Startup\Module.cs" /> | |
<Compile Include="Properties\AssemblyInfo.cs"> | |
<SubType>Code</SubType> | |
diff --git a/src/SlimShader.Studio/Modules/Startup/Class1.cs b/src/SlimShader.Studio/Modules/Startup/Class1.cs | |
new file mode 100644 | |
index 0000000..c9121f8 | |
--- /dev/null | |
+++ b/src/SlimShader.Studio/Modules/Startup/Class1.cs | |
@@ -0,0 +1,32 @@ | |
+using System; | |
+using System.Runtime.InteropServices; | |
+ | |
+namespace FormWithConsole | |
+{ | |
+ internal static class NativeMethods | |
+ { | |
+ // http://msdn.microsoft.com/en-us/library/ms681944(VS.85).aspx | |
+ /// <summary> | |
+ /// Allocates a new console for the calling process. | |
+ /// </summary> | |
+ /// <returns>nonzero if the function succeeds; otherwise, zero.</returns> | |
+ /// <remarks> | |
+ /// A process can be associated with only one console, | |
+ /// so the function fails if the calling process already has a console. | |
+ /// </remarks> | |
+ [DllImport("kernel32.dll", SetLastError = true)] | |
+ internal static extern int AllocConsole(); | |
+ | |
+ // http://msdn.microsoft.com/en-us/library/ms683150(VS.85).aspx | |
+ /// <summary> | |
+ /// Detaches the calling process from its console. | |
+ /// </summary> | |
+ /// <returns>nonzero if the function succeeds; otherwise, zero.</returns> | |
+ /// <remarks> | |
+ /// If the calling process is not already attached to a console, | |
+ /// the error code returned is ERROR_INVALID_PARAMETER (87). | |
+ /// </remarks> | |
+ [DllImport("kernel32.dll", SetLastError = true)] | |
+ internal static extern int FreeConsole(); | |
+ } | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment