…Show last 300 lines
61 InSwitches := true
62 continue
63 }
64 }
65 }
66 if ( SkipParameters > 0 )
67 {
68 SkipParameters--
69 continue
70 }
71 CommandLine .= A_LoopField
72 }
73 CommandLine := StripWhitespace( CommandLine, true, false )
74 return CommandLine
75}
76
77
78; --------------------------------------------------------------------
79; Purpose: Read a Windows Command Line styled string and
80; break it down into seperate arguments.
81; Each argument will go on a seperate line.
82; Input:
83; String - The string to parse.
84; StripQuotes - Remove quotes from the command line.
85; StripWhitespace - Remove the whitespace between the arguments.
86; If false, whitespace will go at
87; the start of each line.
88; Output:
89; RETURN - The parsed commands.
90; --------------------------------------------------------------------
91SplitCommandString( String, StripQuotes = true, StripWhitespace = true )
92{
93 InQuotes := false
94 NewLine := true
95
96 ; Set the probable/maximum size beforehand to avoid multiple resizings while assembling it.
97 VarSetCapacity( OutString, StrLen( String ) )
98
99 Loop, Parse, String
100 {
101 if ( !InQuotes )
102 {
103 if A_LoopField is space
104 {
105 if ( !NewLine )
106 {
107 NewLine := true
108 OutString .= "`n"
109 }
110 if ( StripWhitespace )
111 continue
112 }
113 }
114 if A_LoopField is not space
115 NewLine := false
116 if ( A_LoopField = """" )
117 {
118 InQuotes := !InQuotes
119 if ( StripQuotes )
120 continue
121 }
122 OutString .= A_LoopField
123 }
124 return OutString
125}
126
127
128; --------------------------------------------------------------------
129; Purpose: Removes whitespace from the edges of a string.
130; Input:
131; String - The string to parse.
132; Front - Remove whitespace from the starting edge.
133; Back - Remove whitespace from the trailing edge.
134; Output:
135; RETURN - The stripped string.
136; --------------------------------------------------------------------
137StripWhitespace( String, Front = true, Back = true )
138{
139 if String is space ; Those loops can't properly handle an entirely blank string.
140 return ""
141
142 if ( Front )
143 {
144 Loop, % StrLen( String ) ;%
145 {
146 Character := SubStr( String, A_Index, 1 )
147 if Character is not space
148 {
149 StringTrimLeft, String, String, A_Index - 1
150 break
151 }
152 }
153 }
154 if ( Back )
155 {
156 Length := StrLen( String )
157 Loop, %Length%
158 {
159 Character := SubStr( String, Length - ( A_Index - 1 ), 1 )
160 if Character is not space
161 {
162 StringTrimRight, String, String, A_Index - 1
163 break
164 }
165 }
166 }
167 return String
168}
169/* ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; BinRead ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
170| - Open binary file
171| - Read n bytes (n = 0: all)
172| - From offset (offset < 0: counted from end)
173| - Close file
174| data (replaced) <- file[offset + 0..n-1]
175| Return #bytes actually read
176*/ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
177
178BinRead(file, ByRef data, n=0, offset=0)
179{
180 h := DllCall("CreateFile","Str",file,"Uint",0x80000000,"Uint",3,"UInt",0,"UInt",3,"Uint",0,"UInt",0)
181 IfEqual h,-1, SetEnv, ErrorLevel, -1
182 IfNotEqual ErrorLevel,0,Return,0 ; couldn't open the file
183
184 m = 0 ; seek to offset
185 IfLess offset,0, SetEnv,m,2
186 r := DllCall("SetFilePointerEx","Uint",h,"Int64",offset,"UInt *",p,"Int",m)
187 IfEqual r,0, SetEnv, ErrorLevel, -3
188 IfNotEqual ErrorLevel,0, {
189 t = %ErrorLevel% ; save ErrorLevel to be returned
190 DllCall("CloseHandle", "Uint", h)
191 ErrorLevel = %t% ; return seek error
192 Return 0
193 }
194
195 TotalRead = 0
196 data =
197 IfEqual n,0, SetEnv n,0xffffffff ; almost infinite
198
199 format = %A_FormatInteger% ; save original integer format
200 SetFormat Integer, Hex ; for converting bytes to hex
201
202 Loop %n%
203 {
204 result := DllCall("ReadFile","UInt",h,"UChar *",c,"UInt",1,"UInt *",Read,"UInt",0)
205 if (!result or Read < 1 or ErrorLevel)
206 break
207 TotalRead += Read ; count read
208 c += 0 ; convert to hex
209 StringTrimLeft c, c, 2 ; remove 0x
210 c = 0%c% ; pad left with 0
211 StringRight c, c, 2 ; always 2 digits
212 data = %data%%c% ; append 2 hex digits
213 }
214
215 IfNotEqual ErrorLevel,0, SetEnv,t,%ErrorLevel%
216
217 h := DllCall("CloseHandle", "Uint", h)
218 IfEqual h,-1, SetEnv, ErrorLevel, -2
219 IfNotEqual t,,SetEnv, ErrorLevel, %t%
220
221 SetFormat Integer, %format% ; restore original format
222 Totalread += 0 ; convert to original format
223 Return TotalRead
224}
225base(num,inputbase,outputbase){
226 VarSetCapacity(S,65,0)
227 toDec := DllCall("msvcrt\_strtoui64", Str,num, Uint,0, Int,inputbase, "CDECL Int64")
228 DllCall("msvcrt\_i64toa", Int64,toDec, Str,S, Int,outputbase)
229 return, S
230}
231EXEiD()
232{
233 dosbox:="c:\program files (x86)\dosbox-0.74\dosbox.exe"
234 args:=GetCommandLine()
235 argso=%args%
236 StringReplace,args,args,", ,All
237 If (SubStr(args,1,InStr(args,a_space)-1) = "shortcut")
238 {
239 argsep:=SplitCommandString(args)
240 StringSplit,argsep,argsep,`n
241 SplitPath,argsep2,filename,dir
242 if !dir
243 {
244 FileCreateShortcut,%argsep2%,%filename%.lnk
245 }
246 Else
247 {
248 FileCreateShortcut,%argsep2%,%dir%\%filename%.lnk
249 }
250 exit
251 }
252 else If (SubStr(args,1,InStr(args,a_space)-1) = "doscut")
253 {
254 argsep:=SplitCommandString(args)
255 StringSplit,argsep,argsep,`n
256 SplitPath,argsep2,filename,dir
257 if !dir
258 {
259 FileCreateShortcut,%dosbox%,%filename%.lnk,,%argsep2% -noconsole -exit
260 }
261 Else
262 {
263 FileCreateShortcut,%dosbox%,%dir%\%filename%.lnk,%dir%,%argsep2% -noconsole -exit
264 }
265 exit
266 }
267 else If (SubStr(args,1,InStr(args,a_space)-1) = "deskdoscut")
268 {
269 argsep:=SplitCommandString(args)
270 StringSplit,argsep,argsep,`n
271 SplitPath,argsep2,filename,dir
272 if !dir
273 {
274 FileCreateShortcut,%dosbox%,%a_desktop%\%filename%.lnk,,%argsep2% -noconsole -exit
275 }
276 Else
277 {
278 FileCreateShortcut,%dosbox%,%a_desktop%\%filename%.lnk,%dir%,%argsep2% -noconsole -exit
279 }
280 exit
281 }
282 ;Debug Line
283 ;MsgBox,%args%
284 DllCall("GetBinaryTypeA",str,args,uintp,result)
285 If(result=0)
286 {
287 output:="Win32"
288 ;msgbox,%args%
289 Run,%argso%
290 }
291 else If(result=1)
292 {
293 output:="DOS"
294 ;Launch in DOSBox
295 Run,%dosbox% %args% -noconsole -exit
296 FileDelete,std???.txt ;Delete DOSBox logs due to lack of console
297 }
298 else if(result=2)
299 {
300 output:="Win16"
301 ;Launch in Win3x DOSBox
302 Loop,%args%
303 ShortPath=%A_LoopFileShortPath%
304 SplitPath,ShortPath,fn,dir
305 ;The renaming is due to a Windows bug/feature where it redirects calls to read/write system.ini for legacy apps
306 ;We need it to read/write where we're telling it..
307 FileMove,c:\ntvdm64\vhd\windows\system.ini,c:\ntvdm64\vhd\windows\temp.ini,1
308 IniWrite,d:\%fn%,c:\ntvdm64\vhd\windows\temp.ini,boot,shell
309 FileMove,c:\ntvdm64\vhd\windows\temp.ini,c:\ntvdm64\vhd\windows\system.ini,1
310 RunWait,%dosbox% -c "mount c: c:\ntvdm64\vhd" -c "mount d: %dir%" -c "path c:\;d:\;z:\;" -c "c:\windows\win :" -noconsole -exit
311 FileMove,c:\ntvdm64\vhd\windows\system.ini,c:\ntvdm64\vhd\windows\temp.ini,1
312 IniWrite,progman.exe,c:\ntvdm64\vhd\windows\system.ini,boot,shell
313 FileMove,c:\ntvdm64\vhd\windows\temp.ini,c:\ntvdm64\vhd\windows\system.ini,1
314 FileDelete,std???.txt
315 }
316 else if(result=3)
317 {
318 output:="PIF"
319 ;Parse PIF file and then Launch EXE in DOSBox
320 datalen:=BinRead(args,data)
321
322 ;This loop converts the raw hex to decimal and then to ACSII so we can work with it.
323 loop parse, data
324 {
325 count += 1
326 hex .= a_loopfield
327 if count = 2
328 {
329 textdata.= chr(base(hex, 16, 10))
330 count :=
331 hex :=
332 }
333 }
334 ;Find the first path in the PIF and use that.
335 RegexMatch(textdata, "\w:.+?\.(\w{3})", Match)
336 Run,%dosbox% %Match% -noconsole -exit
337
338 }
339 else if(result=4)
340 {
341 output:="POSIX"
342 MsgBox,"There's no handler for %output% executables yet, sorry!"
343 }
344 else if(result=5)
345 {
346 output:="OS/2"
347 MsgBox,"There's no handler for %output% executables yet, sorry!"
348 }
349 else if(result=6)
350 {
351 output:="Win64"
352 ;msgbox,%args%
353 Run,%argso%
354 }
355
356 ;MsgBox,%args% is a %output% binary, AKA type %result%.
357
358}
359EXEiD()