Procedure tfrmmain. btnupdatefilesclick (Sender: tobject );
Begin
Try
If assigned (gexemm) then
Freeandnil (gexemm );
If assigned (ginimm) then
Freeandnil (ginimm );
Gexemm: = tfilestream. Create (extractfilepath (application. exename) +
'Download \ jlpos.exe ', fmopenread );
Ginimm: = tfilestream. Create (extractfilepath (application. exename) +
'Download \ Client. ini ', fmopenread );
Gexemm2.clear;
Ginimm2.clear;
Gexemm2.copyfrom (gexemm, 0 );
Ginimm2.copyfrom (ginimm, 0 );
Freeandnil (gexemm );
Freeandnil (ginimm );
Except
On E: exception do
Begin
Gsyslog. writelog ('btnupdatefilesclick: '+ E. Message );
Exit;
End;
End;
End;
Function tservermethods1.downloadfile (const filename: string): tstream;
VaR
F: string;
Begin
Result: = nil;
Try
F: = extractfilepath (application. exename) + 'Download \ '+ filename;
If not fileexists (f) then
Exit;
Result: = tmemorystream. Create;
If lowercase (filename) = 'jlpos.exe 'then
Result. copyfrom (gexemm2, 0)
Else if lowercase (filename) = 'client. ini 'then
Result. copyfrom (ginimm2, 0 );
Result. Position: = 0;
Except
On E: exception do
Begin
Gsyslog. writelog ('downloadfile: '+ E. Message );
Exit;
End;
End;
End;
Function tdmcommonfun. downloadfile (const filename: string): Boolean;
VaR
A: tservermethods1client;
INI: Tinifile;
Stream, Ms: tstream;
Buffer: tbytes;
Readcount: integer;
Const
Bufsize = $ f000;
Begin
Result: = false;
If (not tryconnectappserver) or (filename = '') then
Exit;
A: = tservermethods1client. Create (sqlconnection1.dbxconnection );
MS: = tmemorystream. Create;
Try
Stream: = A. downloadfile (filename );
If stream. size =-1 then
Begin
Setlength (buffer, bufsize );
Repeat
Readcount: = stream. Read (buffer [0], bufsize );
If readcount> 0 then
Ms. writebuffer (buffer [0], readcount );
If readcount <bufsize then
Break;
Until readcount <bufsize;
End
Else
Begin
Ms. copyfrom (stream, 0 );
End;
// Delete BAK files
If fileexists (extractfilepath (application. exename) + filename + 'bak') then
Deletefile (pwidechar (extractfilepath (application. exename) + filename
+ 'Bak '));
// Rename an existing file
If fileexists (extractfilepath (application. exename) + filename) then
Begin
Renamefile (extractfilepath (application. exename) + filename,
Extractfilepath (application. exename) + filename + 'bak ');
End;
// Download the latest file
Tmemorystream (MS). savetofile (extractfilepath (application. exename) +
Filename );
// Update the local version
INI: = Tinifile. Create (extractfilepath (application. exename) + 'client. ini ');
Try
INI. writeinteger (filename, 'ver ', getver (filename ));
Finally
INI. Free;
End;
Finally
A. Free;
Ms. Free;
End;
Result: = true;
End;