Rev 73 | Rev 81 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 73 | Rev 79 | ||
---|---|---|---|
Line 29... | Line 29... | ||
29 | end; |
29 | end; |
30 | 30 | ||
31 | const |
31 | const |
32 | // Prefixes for UD2_RunCmd() |
32 | // Prefixes for UD2_RunCmd() |
33 | UD2_RUN_IN_OWN_DIRECTORY_PREFIX = '$RIOD$'; |
33 | UD2_RUN_IN_OWN_DIRECTORY_PREFIX = '$RIOD$'; |
- | 34 | UD2_RUN_AS_ADMIN = '$ADMIN$'; |
|
34 | 35 | ||
35 | function SplitString(const aSeparator, aString: String; aMax: Integer = 0): TArrayOfString; |
36 | function SplitString(const aSeparator, aString: String; aMax: Integer = 0): TArrayOfString; |
36 | function BetterInterpreteBool(str: String): boolean; |
37 | function BetterInterpreteBool(str: String): boolean; |
37 | function GetOwnCmdName: string; |
38 | function GetOwnCmdName: string; |
38 | function ExpandEnvStr(const szInput: string): string; |
39 | function ExpandEnvStr(const szInput: string): string; |
39 | procedure UD2_RunCMD(cmdLine: string; WindowMode: integer); |
40 | procedure UD2_RunCMD(cmdLine: string; WindowMode: integer=SW_NORMAL); |
40 | function SplitIconString(IconString: string): TIconFileIdx; |
41 | function SplitIconString(IconString: string): TIconFileIdx; |
41 | // function GetHTML(AUrl: string): string; |
42 | // function GetHTML(AUrl: string): string; |
42 | procedure VTS_CheckUpdates(VTSID, CurVer: string); |
43 | procedure VTS_CheckUpdates(VTSID, CurVer: string); |
43 | function FormatOSError(ec: DWORD): string; |
44 | function FormatOSError(ec: DWORD): string; |
44 | 45 | ||
Line 191... | Line 192... | ||
191 | result.FileName := ExpandEnvStr(copy(IconString, 0, p-1)); |
192 | result.FileName := ExpandEnvStr(copy(IconString, 0, p-1)); |
192 | result.IconIndex := StrToInt(Copy(IconString, p+1, Length(IconString)-p)); |
193 | result.IconIndex := StrToInt(Copy(IconString, p+1, Length(IconString)-p)); |
193 | end; |
194 | end; |
194 | end; |
195 | end; |
195 | 196 | ||
196 | procedure UD2_RunCMD(cmdLine: string; WindowMode: integer); |
197 | procedure UD2_RunCMD(cmdLine: string; WindowMode: integer=SW_NORMAL); |
197 | // Discussion: http://stackoverflow.com/questions/32802679/acceptable-replacement-for-winexec/32804669#32804669 |
198 | // Discussion: http://stackoverflow.com/questions/32802679/acceptable-replacement-for-winexec/32804669#32804669 |
198 | // Version 1: http://pastebin.com/xQjDmyVe |
199 | // Version 1: http://pastebin.com/xQjDmyVe |
199 | // --> CreateProcess + ShellExecuteEx |
200 | // --> CreateProcess + ShellExecuteEx |
200 | // --> Problem: Run-In-Same-Directory functionality is not possible |
201 | // --> Problem: Run-In-Same-Directory functionality is not possible |
201 | // (requires manual command and argument separation) |
202 | // (requires manual command and argument separation) |
Line 253... | Line 254... | ||
253 | cmdFile := Copy(cmdLine, 1, p-1); |
254 | cmdFile := Copy(cmdLine, 1, p-1); |
254 | cmdArgs := Copy(cmdLine, p+1, Length(cmdLine)-p); |
255 | cmdArgs := Copy(cmdLine, p+1, Length(cmdLine)-p); |
255 | end; |
256 | end; |
256 | end; |
257 | end; |
257 | 258 | ||
258 | if Copy(cmdLine, 1, Length(UD2_RUN_IN_OWN_DIRECTORY_PREFIX)) = UD2_RUN_IN_OWN_DIRECTORY_PREFIX then |
259 | if Pos(UD2_RUN_IN_OWN_DIRECTORY_PREFIX, cmdLine) >= 1 then |
259 | begin |
260 | begin |
- | 261 | cmdLine := StringReplace(cmdLine, UD2_RUN_IN_OWN_DIRECTORY_PREFIX, '', [rfReplaceAll]); |
|
- | 262 | ||
260 | cmdLine := Copy(cmdLine, 1+Length(UD2_RUN_IN_OWN_DIRECTORY_PREFIX), Length(cmdLine)-Length(UD2_RUN_IN_OWN_DIRECTORY_PREFIX)); |
263 | cmdLine := Copy(cmdLine, 1+Length(UD2_RUN_IN_OWN_DIRECTORY_PREFIX), Length(cmdLine)-Length(UD2_RUN_IN_OWN_DIRECTORY_PREFIX)); |
261 | 264 | ||
262 | cmdFile := ExtractFileName(cmdLine); |
265 | cmdFile := ExtractFileName(cmdLine); |
263 | cmdDir := ExtractFilePath(cmdLine); |
266 | cmdDir := ExtractFilePath(cmdLine); |
264 | end |
267 | end |
Line 267... | Line 270... | ||
267 | cmdFile := cmdLine; |
270 | cmdFile := cmdLine; |
268 | cmdDir := ''; |
271 | cmdDir := ''; |
269 | end; |
272 | end; |
270 | 273 | ||
271 | ZeroMemory(@sei, SizeOf(sei)); |
274 | ZeroMemory(@sei, SizeOf(sei)); |
- | 275 | ||
- | 276 | if Pos(UD2_RUN_AS_ADMIN, cmdLine) >= 1 then |
|
- | 277 | begin |
|
- | 278 | cmdLine := StringReplace(cmdLine, UD2_RUN_AS_ADMIN, '', [rfReplaceAll]); |
|
- | 279 | ||
- | 280 | sei.lpVerb := 'runas'; |
|
- | 281 | end; |
|
- | 282 | ||
272 | sei.cbSize := SizeOf(sei); |
283 | sei.cbSize := SizeOf(sei); |
273 | sei.lpFile := PChar(cmdFile); |
284 | sei.lpFile := PChar(cmdFile); |
274 | {$IFNDEF PREFER_SHELLEXECUTEEX_MESSAGES} |
285 | {$IFNDEF PREFER_SHELLEXECUTEEX_MESSAGES} |
275 | sei.fMask := SEE_MASK_FLAG_NO_UI; |
286 | sei.fMask := SEE_MASK_FLAG_NO_UI; |
276 | {$ENDIF} |
287 | {$ENDIF} |
Line 283... | Line 294... | ||
283 | {$ENDIF} |
294 | {$ENDIF} |
284 | end; |
295 | end; |
285 | 296 | ||
286 | function GetHTML(AUrl: string): string; |
297 | function GetHTML(AUrl: string): string; |
287 | // http://www.delphipraxis.net/post43515.html |
298 | // http://www.delphipraxis.net/post43515.html |
- | 299 | // Modificated by ViaThinkSoft |
|
288 | var |
300 | var |
289 | databuffer : array[0..4095] of char; |
301 | databuffer : array[0..4095] of char; |
290 | ResStr : string; |
302 | ResStr : string; |
291 | hSession, hfile: hInternet; |
303 | hSession, hfile: hInternet; |
292 | dwindex,dwcodelen,dwread,dwNumber: cardinal; |
304 | dwindex,dwcodelen,dwread,dwNumber: cardinal; |
Line 294... | Line 306... | ||
294 | res : pchar; |
306 | res : pchar; |
295 | Str : pchar; |
307 | Str : pchar; |
296 | begin |
308 | begin |
297 | ResStr:=''; |
309 | ResStr := ''; |
298 | if system.pos('http://',lowercase(AUrl))=0 then |
310 | if system.pos('http://',lowercase(AUrl)) = 0 then |
- | 311 | begin |
|
299 | AUrl:='http://'+AUrl; |
312 | AUrl:='http://'+AUrl; |
- | 313 | end; |
|
300 | 314 | ||
301 | // Hinzugefügt |
315 | // [ViaThinkSoft] Added |
302 | Application.ProcessMessages; |
316 | Application.ProcessMessages; |
303 | 317 | ||
304 | hSession:=InternetOpen('InetURL:/1.0', |
318 | hSession:=InternetOpen('InetURL:/1.0', |
305 | INTERNET_OPEN_TYPE_PRECONFIG, |
319 | INTERNET_OPEN_TYPE_PRECONFIG, |
306 | nil, |
320 | nil, |
307 | nil, |
321 | nil, |
308 | 0); |
322 | 0); |
309 | if assigned(hsession) then |
323 | if assigned(hsession) then |
310 | begin |
324 | begin |
311 | // Hinzugefügt |
325 | // [ViaThinkSoft] Added |
312 | application.ProcessMessages; |
326 | Application.ProcessMessages; |
313 | 327 | ||
314 | hfile:=InternetOpenUrl( |
328 | hfile := InternetOpenUrl(hsession, |
315 | hsession, |
- | |
316 | pchar(AUrl), |
329 | pchar(AUrl), |
317 | nil, |
330 | nil, |
318 | 0, |
331 | 0, |
319 | INTERNET_FLAG_RELOAD, |
332 | INTERNET_FLAG_RELOAD, |
320 | 0); |
333 | 0); |
321 | dwIndex := 0; |
334 | dwIndex := 0; |
322 | dwCodeLen := 10; |
335 | dwCodeLen := 10; |
323 | 336 | ||
324 | // Hinzugefügt |
337 | // [ViaThinkSoft] Added |
325 | application.ProcessMessages; |
338 | Application.ProcessMessages; |
326 | 339 | ||
327 | HttpQueryInfo(hfile, |
340 | HttpQueryInfo(hfile, |
328 | HTTP_QUERY_STATUS_CODE, |
341 | HTTP_QUERY_STATUS_CODE, |
329 | @dwcode, |
342 | @dwcode, |
330 | dwcodeLen, |
343 | dwcodeLen, |
Line 337... | Line 350... | ||
337 | @databuffer, |
350 | @databuffer, |
338 | dwNumber, |
351 | dwNumber, |
339 | DwRead)) do |
352 | DwRead)) do |
340 | begin |
353 | begin |
341 | 354 | ||
342 | // Hinzugefügt |
355 | // [ViaThinkSoft] Added |
343 | application.ProcessMessages; |
356 | Application.ProcessMessages; |
344 | 357 | ||
345 | if dwRead =0 then |
358 | if dwRead =0 then |
346 | break; |
359 | break; |
347 | databuffer[dwread]:=#0; |
360 | databuffer[dwread]:=#0; |
348 | Str := pchar(@databuffer); |
361 | Str := pchar(@databuffer); |
Line 371... | Line 384... | ||
371 | *) |
384 | *) |
372 | LNG_DOWNLOAD_ERR = 'An error occurred while searching for updates. Please check your internet connection and firewall.'; |
385 | LNG_DOWNLOAD_ERR = 'An error occurred while searching for updates. Please check your internet connection and firewall.'; |
373 | LNG_NEW_VERSION = 'A new version is available. Do you want to download it now?'; |
386 | LNG_NEW_VERSION = 'A new version is available. Do you want to download it now?'; |
374 | LNG_NO_UPDATE = 'You already have the newest program version.'; |
387 | LNG_NO_UPDATE = 'You already have the newest program version.'; |
375 | var |
388 | var |
376 | temp: string; |
389 | status: string; |
377 | begin |
390 | begin |
378 | temp := GetHTML('http://www.viathinksoft.de/update/?id='+VTSID); |
391 | status := GetHTML('http://www.viathinksoft.de/update/?id='+VTSID); |
379 | if Copy(temp, 0, 7) = 'Status:' then |
392 | if Copy(status, 0, 7) = 'Status:' then |
380 | begin |
393 | begin |
381 | MessageDlg(LNG_DOWNLOAD_ERR, mtError, [mbOK], 0); |
394 | MessageDlg(LNG_DOWNLOAD_ERR, mtError, [mbOK], 0); |
382 | end |
395 | end |
383 | else |
396 | else |
384 | begin |
397 | begin |
385 | if GetHTML('http://www.viathinksoft.de/update/?id='+VTSID) <> CurVer then |
398 | if status <> CurVer then |
386 | begin |
399 | begin |
387 | if MessageDlg(LNG_NEW_VERSION, mtConfirmation, mbYesNoCancel, 0) = ID_YES then |
400 | if MessageDlg(LNG_NEW_VERSION, mtConfirmation, mbYesNoCancel, 0) = ID_YES then |
388 | begin |
401 | begin |
389 | shellexecute(application.handle, 'open', pchar('http://www.viathinksoft.de/update/?id=@spacemission'), '', '', sw_normal); |
402 | shellexecute(application.handle, 'open', pchar('http://www.viathinksoft.de/update/?id=@'+VTSID), '', '', sw_normal); |
390 | end; |
403 | end; |
391 | end |
404 | end |
392 | else |
405 | else |
393 | begin |
406 | begin |
394 | MessageDlg(LNG_NO_UPDATE, mtInformation, [mbOk], 0); |
407 | MessageDlg(LNG_NO_UPDATE, mtInformation, [mbOk], 0); |