summaryrefslogtreecommitdiff
path: root/plugins/Utils.pas/utils.pas
blob: 5b9b35118b60c90ab656054be69a6aa338c9b561 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
unit utils;

interface

uses windows;

function SaveTemporaryW(ptr:pointer;size:dword;ext:PWideChar=nil):PWideChar;
function SaveTemporary (ptr:pointer;size:dword;ext:PAnsiChar=nil):PAnsiChar;

implementation

uses common,io;

function SaveTemporaryW(ptr:pointer;size:dword;ext:PWideChar=nil):PWideChar;
var
  buf,buf1:array [0..MAX_PATH-1] of WideChar;
  f:THANDLE;
begin
  GetTempPathW(MAX_PATH,buf);
  GetTempFileNameW(buf,'wat',GetCurrentTime,buf1);
  ChangeExtW(buf1,ext);

  f:=ReWrite(buf1);
  BlockWrite(f,PByte(ptr)^,size);
  CloseHandle(f);
  StrDupW(result,buf1);
end;

function SaveTemporary(ptr:pointer;size:dword;ext:PAnsiChar=nil):PAnsiChar;
var
  buf,buf1:array [0..MAX_PATH-1] of AnsiChar;
  f:THANDLE;
begin
  GetTempPathA(SizeOf(buf),buf);
  GetTempFileNameA(buf,'wat',GetCurrentTime,buf1);
  ChangeExt(buf1,ext);

  f:=ReWrite(buf1);
  BlockWrite(f,PByte(ptr)^,size);
  CloseHandle(f);
  StrDup(result,buf1);
end;

end.