6
6
using EnvDTE ;
7
7
using LibGit2Sharp ;
8
8
using Microsoft . VisualStudio . Text ;
9
- using Process = System . Diagnostics . Process ;
10
9
11
10
namespace GitDiffMargin . Git
12
11
{
@@ -112,19 +111,19 @@ public void StartExternalDiff(ITextDocument textDocument)
112
111
var diffCmd = repo . Config . Get < string > ( "difftool." + diffGuiTool . Value + ".cmd" ) ;
113
112
var cmd = diffCmd . Value . Replace ( "$LOCAL" , tempFileName ) . Replace ( "$REMOTE" , filename ) ;
114
113
115
- string exe ;
116
- var args = CommandLineToArgs ( cmd , out exe ) ;
117
-
118
- var process = new Process
119
- {
120
- StartInfo =
121
- {
122
- FileName = exe ,
123
- Arguments = string . Join ( " " , args )
124
- }
125
- } ;
126
-
127
- process . Start ( ) ;
114
+ var si = new STARTUPINFO ( ) ;
115
+ PROCESS_INFORMATION pi ;
116
+ CreateProcess (
117
+ null ,
118
+ cmd ,
119
+ IntPtr . Zero ,
120
+ IntPtr . Zero ,
121
+ false ,
122
+ 0 ,
123
+ IntPtr . Zero ,
124
+ null ,
125
+ ref si ,
126
+ out pi ) ;
128
127
}
129
128
}
130
129
@@ -148,36 +147,47 @@ public string GetGitRepository(string filePath)
148
147
return directoryInfo != null ? directoryInfo . FullName : null ;
149
148
}
150
149
151
- [ DllImport ( "shell32.dll" , SetLastError = true ) ]
152
- static extern IntPtr CommandLineToArgvW (
153
-
154
- [ MarshalAs ( UnmanagedType . LPWStr ) ] string lpCmdLine , out int pNumArgs ) ;
155
- private static string [ ] CommandLineToArgs ( string commandLine , out string executableName )
150
+ [ DllImport ( "kernel32.dll" ) ]
151
+ static extern bool CreateProcess (
152
+ string lpApplicationName ,
153
+ string lpCommandLine ,
154
+ IntPtr lpProcessAttributes ,
155
+ IntPtr lpThreadAttributes ,
156
+ bool bInheritHandles ,
157
+ uint dwCreationFlags ,
158
+ IntPtr lpEnvironment ,
159
+ string lpCurrentDirectory ,
160
+ ref STARTUPINFO lpStartupInfo ,
161
+ out PROCESS_INFORMATION lpProcessInformation ) ;
162
+
163
+ public struct PROCESS_INFORMATION
156
164
{
157
- int argCount ;
158
- var result = CommandLineToArgvW ( commandLine , out argCount ) ;
159
- if ( result == IntPtr . Zero )
160
- {
161
- throw new System . ComponentModel . Win32Exception ( ) ;
162
- }
163
-
164
- try
165
- {
166
- var pStr = Marshal . ReadIntPtr ( result , 0 * IntPtr . Size ) ;
167
- executableName = Marshal . PtrToStringUni ( pStr ) ;
168
- var args = new string [ argCount - 1 ] ;
169
- for ( var i = 0 ; i < args . Length ; i ++ )
170
- {
171
- pStr = Marshal . ReadIntPtr ( result , ( i + 1 ) * IntPtr . Size ) ;
172
- var arg = Marshal . PtrToStringUni ( pStr ) ;
173
- args [ i ] = arg ;
174
- }
175
- return args ;
176
- }
177
- finally
178
- {
179
- Marshal . FreeHGlobal ( result ) ;
180
- }
165
+ public IntPtr hProcess ;
166
+ public IntPtr hThread ;
167
+ public uint dwProcessId ;
168
+ public uint dwThreadId ;
169
+ }
170
+
171
+ public struct STARTUPINFO
172
+ {
173
+ public uint cb ;
174
+ public string lpReserved ;
175
+ public string lpDesktop ;
176
+ public string lpTitle ;
177
+ public uint dwX ;
178
+ public uint dwY ;
179
+ public uint dwXSize ;
180
+ public uint dwYSize ;
181
+ public uint dwXCountChars ;
182
+ public uint dwYCountChars ;
183
+ public uint dwFillAttribute ;
184
+ public uint dwFlags ;
185
+ public short wShowWindow ;
186
+ public short cbReserved2 ;
187
+ public IntPtr lpReserved2 ;
188
+ public IntPtr hStdInput ;
189
+ public IntPtr hStdOutput ;
190
+ public IntPtr hStdError ;
181
191
}
182
192
}
183
193
}
0 commit comments