请问,如何在网络上更新已经开发的软件,不要到客户那里逐个的更换软件?
解决方案 »
- 动态SQL语句插入空内容到blob字段(Oracle)
- Delphi2007
- 多线程问题??急用
- 求教delphi对VF的基本读写操作??
- 怎么样在DBGRID中点击标题栏实现跟联接(ADO,BDE,DBEXPRESS等)无关的排序
- 请问在windows2K底下如何在"\HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum\Root"创建一个键值???
- <高分求救!!>如何去掉CMOS的密码??(100分)
- 德国科学家在人类血液中发现艾滋克星
- 大虾们救命啊!关于ACCESS的问题!!
- Delphi确实很好,学了好几年了,但在上海差点没有找到工作,很少有招学Delphi的
- 一条SQL查找的语句多何写
- EXE程序转化成dll程序,应该怎么转化?
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.}
你的程序只有一个可执行文件。想实现自动升级功能恐怕有点麻烦。必须外挂一个升级程序。在主程序启动之前判断是否有新版本。如果有,就用覆盖拷贝的方式把旧版本的程序覆盖。因为程序本身不能把自己删除然后拷贝。我现在开发的一个东东就是具备自动升级功能。给你讲讲主要的思路吧。
1:应用程序有一个主框架。这个主框架是不会经常更新的。而且就是这个主框架来实现自动升级功能。
2:用包的形式调用每一个子模块,也就是*.bpl.这样,我们如果要更新某个模块的功能。就不用将整个应用程序都重新编译了,而只是需要重新编译某一个包文件。然后文件自己有一个时间属性。根据这个属性,就可以判断哪一个是更新的啦。
3:朱框架有一个上传最新文件的功能。也就是上传*.bpl的功能。编译之后的最新文件通过该功能存储在数据库中。
4:*.bpl文件是以文件流的方式存储在后台数据库的。同时也存储了这个文件的相关的信息。 比如:名称、创建日期、大小等等。可以在主程序(也就是主框架)启动之后,判断所有的本地文件是否和数据库中的文件信息一致。如果不一致那么下载更新。也可以在调用每一个模块之前判断。这两种方法的利弊。你自己可以分析。
大概思路就是这些,具体还要你自己在练习中慢慢体会。 GOOD LUCK!
因为开发的时候没有使用包等方法,所以只能更新EXE文件。这种方法有不稳定的因素,请问还有没有更好的方法!