求一自动升级程序的源码,升级exe程序和指定文件下的文件

解决方案 »

  1.   

    盒子上有一个现成的源码
    下载地址:http://www.2ccc.com/article.asp?articleid=5111
      

  2.   

    我看到了,是d2007的呀,我是delphi7的呀
      

  3.   

    Procedure FileCopy( Const sourcefilename, targetfilename: String );
    Var
      S, T: TFileStream;
    Begin
      S := TFileStream.Create( sourcefilename, fmOpenRead );  try
        T := TFileStream.Create( targetfilename,
                                 fmOpenWrite or fmCreate );
        try
          T.CopyFrom(S, S.Size ) ;
        finally
          T.Free;
        end;
      finally
        S.Free;
      end;
    End;
    procedure TUpDateForm.UpdateLoad;
    var
       ado:TADOquery;
       myinifile:TInifile;
       filename:string;
       sfile,s,upd:string;
       i,j:integer;
       T:TextFile;
    begin
       Filename:=ExtractFilePath(Paramstr(0))+'mini.ini';
       myinifile:=Tinifile.Create(filename);
       upd:=myinifile.ReadString('update','updatenumber','');
       ado:=TAdoquery.Create(nil);
       ado.Connection:=Linkdata(Application.Handle);
       ado.close;
       ado.SQL.Clear;
       ado.SQL.Add('select * from QAUpdate where QAUpdateint=2');
       ado.Open;
       if Ado.RecordCount=0 then
       begin
            Application.MessageBox('没有找到更新的路径!','提示信息',MB_YESNO);
            exit;
       end
       else
       begin
       s:=ado.FieldByName('QAUpdateName').AsString;
       ado.Close;
       ado.SQL.Clear;
       ado.SQL.Add('select * from QAUpdate where QAUpdateint=0 and QAUpdateNumber>:QAUpdateNumber');
       ado.Parameters.ParamByName('QAUpdateNumber').Value:=strtoFloat(upd);
       ado.Open;
       if ado.RecordCount=0 then
          begin
            Application.MessageBox('没有更新!','提示信息',MB_YESNO);
            exit;
          end
            else
              begin
              i:=Ado.RecordCount;
              j:=0;
              Gauge1.MinValue:=0;
              Gauge1.MaxValue:=Ado.RecordCount;
              Gauge1.Progress:=0;          Memo1.Clear;
              Memo1.Lines.Add('------------------------------更新开始-----------------------------------');
              AssignFile(T,ExtractFilePath(Paramstr(0))+'Update.log');
              Append(T);
              writeln(T,'------------------------------更新开始-----------------------------------'+#13);
              try
                ado.First;
                repeat
                   j:=j+1;
                   sfile:=ado.FieldByName('QAUpdateName').AsString;
                   filecopy(s+sfile,pChar(ExtractFilePath(Paramstr(0)))+sfile);
                   Memo1.Lines.Add('一共有'+inttostr(i)+'个文件要更新,第'+inttostr(j)+'个文件更新完毕。');
                   Memo1.Lines.Add('文件名为:'+ado.FieldByName('QAUpdatere').AsString);
                   Memo1.Lines.Add('更新时间为: '+datetimetostr(Now()));
                   Gauge1.Progress:=Gauge1.Progress+1;
                   writeln(T,'一共有'+inttostr(i)+'个文件要更新,第'+inttostr(j)+'个文件更新完毕。'+'文件名为:'+ado.FieldByName('QAUpdatere').AsString+'更新时间为: '+datetimetostr(Now())+#13);
                   ado.Next;
                until ado.Eof ;
                Memo1.Lines.Add('------------------------------更新结束-----------------------------------');
                writeln(T,'------------------------------更新结束-----------------------------------'+#13);
                closefile(T);   
                ado.Close;
                ado.SQL.Clear;
                ado.SQL.Add('select max(QAUpdateNumber) as tt from QAUpdate where QAUpdateint=0');
                ado.Open;
                upd:=ado.FieldByName('tt').AsString;
                myinifile.WriteString('update','updatenumber',upd);
                //application.MessageBox('升级成功!','提示信息',48);
               except on e:exception do
                begin
                   application.MessageBox(pchar('无法保存文件,可能是您开启了病毒防火墙!'+#13+#13+e.Message),'错误信息',16);
                end;
              end;
              end;
           // memo1.lines.savetofile(pChar(ExtractFilePath(Paramstr(0))+'update.log'));{能保存信息,但只能覆盖原有的信息}
       ado.close;
       end;
       Linkdata(Application.Handle).Free;
    end;