瀏覽代碼

update zmp

master
sasgis 54 年之前
父節點
當前提交
4e1b6259c5
共有 2 個檔案被更改,包括 93 行新增29 行删除
  1. +86
    -28
      Yandex/YaTraf.zmp/GetUrlScript.txt
  2. +7
    -1
      Yandex/YaTraf.zmp/params.txt

+ 86
- 28
Yandex/YaTraf.zmp/GetUrlScript.txt 查看文件

@@ -1,40 +1,98 @@
function retrieve_ts(url: string; xstart: string; xend: string):integer; external 'ytrf_retrieve_ts@maps\YaTraf.dll stdcall';
function GetIntParam(key: string): Integer; external 'ytrf_GetIntParam@maps\YaTraf.dll stdcall';
function SetIntParam(key: string; val: Integer): integer; external 'ytrf_SetIntParam@maps\YaTraf.dll stdcall';
function GetUTS: Longint; external 'ytrf_GetUTS@maps\YaTraf.dll stdcall';
const
ts_key = 'ytrf_ts';
lts_key = 'ytrf_lts';
procedure InitScriptBuffer;
begin
if ScriptBuffer = '' then begin
ScriptBuffer := '<' + ts_key + '=0>_<' + lts_key + '=0>';
end;
end;
function ts_update_needed(delta: integer):integer;
procedure SaveIntValue(const key: string; const value: Integer);
var
lts, ts : integer;
lts_key: string;
val_expr, val_repl: string;
begin
result:=0;
lts_key:='ytrf_lts';
lts:=GetIntParam(lts_key);
ts:=GetUTS;
if (ts>lts+delta) then begin
SetIntParam(lts_key, GetUTS);
result:=1;
val_expr := '<' + key + '=(\d+)>';
val_repl := '<' + key + '=' + IntToStr(value) + '>';
ScriptBuffer := RegExprReplaceMatchSubStr(ScriptBuffer, val_expr, val_repl);
end;
function GetIntValue(const key: string): Integer;
var
val_expr, val_str: string;
begin
val_expr := '<' + key + '=(\d+)>';
val_str := RegExprGetMatchSubStr(ScriptBuffer, val_expr, 1);
if (val_str <> '') then begin
Result := StrToInt(val_str);
end else begin
Result := 0;
end;
end;
function DownloadUrl(const AUrl: AnsiString): string;
var
VResponseCode: Cardinal;
VResponseHeader, VResponseData: AnsiString;
VRequestUrl, VRequestHeader, VPostData: AnsiString;
begin
Result := '';
if Assigned(Downloader) then begin
VRequestUrl := AUrl;
VRequestHeader := '';
VPostData := '';
VResponseHeader := '';
VResponseData := '';
VResponseCode := Downloader.DoHttpRequest(VRequestUrl, VRequestHeader, VPostData, VResponseHeader, VResponseData);
if VResponseCode = 200 then begin
Result := VResponseData;
end;
end;
end;
function IsNeedUpdateTimeStamp(const ADelta: Integer): Boolean;
var
ts, lts: Integer;
begin
ts := GetUnixTime;
lts := GetIntValue(lts_key);
if (ts > lts + ADelta) then begin
SaveIntValue(lts_key, ts);
Result := True;
end else begin
Result := False;
end;
end;
function get_ts(delta: integer):integer;
function GetTimeStamp(const ADelta: Integer): Integer;
var
ts_key, url, data: string;
pt : LongInt;
ts: Integer;
ts_val: string;
stat_js: string;
begin
result:=0;
ts_key:='ytrf_ts';
if (ts_update_needed(delta)>0) then begin
url:='http://jgo.maps.yandex.net/trf/stat.js';
result:=retrieve_ts(url, 'timestamp:"', '"');
SetIntParam(ts_key, result);
end else begin
result:=GetIntParam(ts_key);
end;
ts := 0;
if IsNeedUpdateTimeStamp(ADelta) then begin
stat_js := DownloadUrl('http://jgo.maps.yandex.net/trf/stat.js');
if stat_js <> '' then begin
ts_val := RegExprGetMatchSubStr(stat_js, 'timestamp:"(\d+)"', 1);
if ts_val <> '' then begin
ts := StrToInt(ts_val);
SaveIntValue(ts_key, ts);
end;
end;
end else begin
ts := GetIntValue(ts_key);
end;
Result := ts;
end;
begin
ResultURL:='';
if (GetZ<>0) then ResultURL:=GetURLBase+inttostr(GetX)+'&y='+inttostr(GetY)+'&z='+inttostr(GetZ-1)+'&tm='+inttostr(get_ts(60));
InitScriptBuffer;
if GetZ <> 0 then begin
ResultURL := GetURLBase + IntToStr(GetX) + '&y=' + IntToStr(GetY) +
'&z=' + IntToStr(GetZ-1) + '&tm=' + IntToStr(GetTimeStamp(60));
end else begin
ResultURL := '';
end;
end.

+ 7
- 1
Yandex/YaTraf.zmp/params.txt 查看文件

@@ -19,4 +19,10 @@ separator=0
UseDwn=1
Sleep=0
DefHotKey=54
DelAfterShow=1
CacheType=9
IsUseDownloaderInScript=1
UseMemCache=1
MemCacheCapacity=100
MemCacheTTL=60000
MemCacheClearStrategy=1
RestartDownloadOnMemCacheTTL=1

Loading…
取消
儲存