Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

79 rindas
2.0 KiB

  1. const
  2. cErrorFlag = 'e';
  3. function _RequestVersion(out AVersion: AnsiString): Boolean;
  4. var
  5. VCode: Cardinal;
  6. VVer, VHeader, VData: AnsiString;
  7. begin
  8. Result := False;
  9. AVersion := cErrorFlag;
  10. if Assigned(Downloader) then begin
  11. VCode := Downloader.DoHttpRequest(
  12. 'https://maps.googleapis.com/maps/api/js', '', '', VHeader, VData
  13. );
  14. if VCode = 200 then begin
  15. VVer := RegExprGetMatchSubStr(
  16. VData, 'https://khms\d+.googleapis\.com/kh\?v=(\d+)', 1
  17. );
  18. Result := VVer <> '';
  19. if Result then begin
  20. AVersion := VVer;
  21. end;
  22. end else
  23. if (VCode = 0) or (VCode >= 500) then begin
  24. // internet connection or server error
  25. AVersion := '';
  26. end else begin
  27. // fatal request error
  28. WriteLn(IntToStr(VCode));
  29. end;
  30. end;
  31. end;
  32. function _GetVersion(out AVersion: AnsiString): Boolean;
  33. begin
  34. if ScriptBuffer = '' then begin
  35. Global.Lock;
  36. try
  37. if Global.Exists(0) then begin
  38. ScriptBuffer := Global.GetVar(0);
  39. if ScriptBuffer = '' then begin // this should never happen
  40. ScriptBuffer := cErrorFlag;
  41. end;
  42. end else begin
  43. if _RequestVersion(ScriptBuffer) then begin
  44. Global.SetVar(0, ScriptBuffer);
  45. end;
  46. end;
  47. finally
  48. Global.Unlock;
  49. end;
  50. end;
  51. if (ScriptBuffer <> '') and (ScriptBuffer <> cErrorFlag) then begin
  52. AVersion := ScriptBuffer;
  53. end else begin
  54. AVersion := Version; // fallback to the Version from Params.txt
  55. end;
  56. Result := AVersion <> '';
  57. end;
  58. var
  59. VSatVer: AnsiString;
  60. begin
  61. if _GetVersion(VSatVer) then begin
  62. ResultURL := Format(
  63. 'https://khms%d.google.com/kh/v=%s&src=app&x=%d&y=%d&z=%d',
  64. [Random(4), VSatVer, GetX, GetY, GetZ-1]
  65. );
  66. end else begin
  67. ResultURL := Format(
  68. 'https://mt%d.google.com/vt/lyrs=s&hl=%s&x=%d&y=%d&z=%d',
  69. [Random(4), Lang, GetX, GetY, GetZ-1]
  70. );
  71. end;
  72. end.