我想做一个根据程序的版本号,自动升级程序的软件。准备ftp实现,从ftp服务器自动下载。那位大侠能提供一些相关资料,源代码更好。在这里提前谢谢了。我的信箱是:[email protected].
解决方案 »
- 急急急!!delphi7 FastReport v2.4打印问题
- 万分紧急!RPC服务器不可用问题!!
- 有谁有松下KX-p1121打印命令说明???
- 开发一个全屏幕的信息提示框,请高手指点!!!请各位高手发言啊见人有分啊!!!
- 避免内存泄露,对象安全释放的问题
- excel的数据导入到sql server中
- 怎么在*.exe 程序执行时,执行我的一个exe 程序
- 公司的头交了一个任务给我,让我解决以前公司做的三层结构的效率问题,还请大家帮忙发表下意见,谢谢
- 急问,如何实现dialog的execute?
- 如何检测一个tcp/udp端口是不是被占用?
- 应用程序服务器怎样根据IP限制客户端的连接???急!!!!!!!!!
- 遇到一个SQL问题,大家帮解决一下
Detect and Download a new version of (an own) application?
uses
{...,}IniFiles, UrlMon, type
TForm1 = class(TForm)
{...}
private
winsc: TiniFile;
old: Integer;
vernfo: TIniFile;
end;
implementation {$R *.dfm} function DownloadFile(Source, Dest: string): Boolean;
{ Function for Downloading the file found on the net }
begin
try
Result := UrlDownloadToFile(nil, PChar(Source), PChar(Dest), 0, nil) = 0;
except
Result := False;
end;
end; function GetPathPath: string;
{ Retrive app path }
begin
Result := ExtractFilePath(Application.ExeName);
end; procedure TForm1.DownLoadNewVersion1Click(Sender: TObject);
var
apath: string;
new: Integer;
begin
// This is the exact code from my application
apath := GetPathPath;
Gauge1.Progress := 0;
StatusBar1.SimplePanel := True;
StatusBar1.SimpleText := 'Connecting to http://tsoft.home.ro';
Gauge1.Progress := 20;
if DownloadFile('http://www.tsoft.home.ro/update.ini', PChar(apath) + '/update.ini') then
begin
Gauge1.Progress := 50;
StatusBAr1.SimplePanel := True;
StatusBar1.SimpleText := 'Checking for newer versions...';
vernfo := TiniFile.Create(GetPathPath + '/update.ini');
new := vernfo.ReadInteger('version', 'wsc', 7);
vernfo.Free;
if (old = new) then
begin
StatusBar1.SimplePanel := True;
StatusBar1.SimpleText := 'No new version detected';
Gauge1.Progress := 100;
end
else if DownloadFile('http://www.tsoft.home.ro/winsafe.exe',
PChar(apath) + '/winsafe.exe') then
begin
ShowMessage('Update succeseful');
Gauge1.Progress := 100;
winsc := TIniFile.Create(ChangeFileExt(Application.ExeName, '.ini'));
winsc.WriteInteger('wsc', 'vernfo', new);
winsc.Free;
end
else
MessageDlg('A new version has appeard but it requires a second install',
mtInformation, [mbOK], 0);
end
else
begin
StatusBar1.SimplePanel := True;
StatusBar1.SimpleText := 'Failed to connect probably a internet problem';
Gauge1.Progress := 0;
end;
end; procedure TForm1.FormCreate(Sender: TObject);
begin
//App version
winsc := TIniFile.Create(ChangeFileExt(Application.ExeName, '.ini'));
try
old := winsc.ReadInteger('wsc', 'vernfo', 1);
finally
winsc.Free;
end;
end; end. {The concept is very simple u download a ini file from your website that contains
the version you compare it with the one from your computer and it downloads the
file if the versions are Not equal if you find any froblems write me.}
多个文件需要更新的话,最好建立一张文件更新的映射列表。
注意多个关联文件的同步更新。
不推荐采用INI文件,多文件时无法描述文件的层次关系。