Browse Source

Add Shell32 class with CommandLineToArgvW wrapper; fix up comments.

Douglas Thrift 9 years ago
parent
commit
b03201dbf5

+ 1 - 1
ssh-handler/HandlerSettingsBox.xaml

@@ -14,4 +14,4 @@
     <StackPanel
         Name="SettingsPanel"
         />
-</GroupBox>
+</GroupBox>

+ 2 - 2
ssh-handler/HandlerSettingsBox.xaml.cs

@@ -1,4 +1,4 @@
-// SSH Handler Settings
+// Handler Settings Box
 //
 // Douglas Thrift
 //
@@ -46,4 +46,4 @@ public partial class HandlerSettingsBox : GroupBox
                 break;
             }
     }
-}
+}

+ 1 - 1
ssh-handler/OptionalExecutablePanel.xaml.cs

@@ -1,4 +1,4 @@
-// SSH Handler Settings
+// Optional Executable Panel
 //
 // Douglas Thrift
 //

+ 1 - 1
ssh-handler/OptionalYesNoDirectoryPanel.xaml.cs

@@ -1,4 +1,4 @@
-// SSH Handler Settings
+// Optional Yes/No/Directory Panel
 //
 // Douglas Thrift
 //

+ 1 - 1
ssh-handler/OptionalYesNoExecutablePanel.xaml.cs

@@ -1,4 +1,4 @@
-// SSH Handler Settings
+// Optional Yes/No/Executable Panel
 //
 // Douglas Thrift
 //

+ 1 - 1
ssh-handler/SettingsDialog.xaml.cs

@@ -1,4 +1,4 @@
-// SSH Handler Settings
+// Settings Dialog
 //
 // Douglas Thrift
 //

+ 54 - 0
ssh-handler/Shell32.cs

@@ -0,0 +1,54 @@
+// Shell32
+//
+// Douglas Thrift
+//
+// Shell32.cs
+
+/*  Copyright 2014 Douglas Thrift
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Runtime.InteropServices;
+
+public static class Shell32
+{
+    public static IList<string> CommandLineToArgv(string cmdLine)
+    {
+        int numArgs;
+        var argv = CommandLineToArgvW(cmdLine, out numArgs);
+
+        if (argv == IntPtr.Zero)
+            throw new Win32Exception();
+
+        try
+        {
+            string[] args = new string[numArgs];
+
+            for (int index = 0; index != numArgs; ++index)
+                args[index] = Marshal.PtrToStringUni(Marshal.ReadIntPtr(argv, index * IntPtr.Size));
+
+            return args;
+        }
+        finally
+        {
+            Marshal.FreeHGlobal(argv);
+        }
+    }
+
+    [DllImport("shell32.dll", SetLastError = true)]
+    private static extern IntPtr CommandLineToArgvW([MarshalAs(UnmanagedType.LPWStr)] string lpCmdLine, out int pNumArgs);
+}

+ 2 - 2
ssh-handler/SshHandler.cs

@@ -99,8 +99,8 @@ public class SshHandler
 
     private static int Settings()
     {
-        SettingsDialog settings = new SettingsDialog(handlers);
-        Nullable<bool> result = settings.ShowDialog();
+        var settings = new SettingsDialog(handlers);
+        var result = settings.ShowDialog();
         Debug.WriteLine("Settings result: {0}", result, null);
 
         return 0;

+ 1 - 0
ssh-handler/ssh-handler.csproj

@@ -94,6 +94,7 @@
     <Compile Include="PuttyHandler.cs" />
     <Compile Include="Setting.cs" />
     <Compile Include="SettingType.cs" />
+    <Compile Include="Shell32.cs" />
     <Compile Include="SshHandler.cs" />
     <Compile Include="SettingsDialog.xaml.cs">
       <DependentUpon>SettingsDialog.xaml</DependentUpon>