您的位置:首页 > 其它

Intallshield 如何遍历全盘与更新文件

2010-08-06 15:41 204 查看
最近我们做的产品遇到这个问题:客户没有将原来的版本删除干净,导致安装新版本的时候查找dll文件的时候发生调用错误。我没有去追查windows是如何查找 dll 文件的,但确实出现了错误的调用。所以决定在安装新版本的时候遍历全盘把原来的dll文件替换掉。其实相对来说比较简单,但对于刚入门的菜鸟来说当时的确难为到了我。所以在做的过程中总计了一些自己认为有些参考价值的东西。

1. 本来打算自己画一个对话框的,但那样的确太过麻烦。所以改了下 AskOptions() 的 Title.

    SetDialogTitle (DLG_ASK_OPTIONS, "Search And Update Client Components/n      Select the actions of the following options");

 

2. 遍历整个硬盘,搜索要更新的文件。

 function DoUpdateDll() 

STRING svResult, szServerPath,svString, strtemp; 

LIST listID;  

NUMBER temp,nResult;

begin

     SetStatusWindow( 1, "" );

Enable( STATUSEX );

SetStatusWindow( 60, "");    //输入提示内容

CreateInstallationInfo();  

    listID = ListCreate(STRINGLIST);

GetValidDrivesList( listID, FIXED_DRIVE, 10 ); 

       nResult = ListGetFirstString (listID, svString);     

       while( nResult !=END_OF_LIST )

         strtemp = svString;

              strtemp=strtemp+"://"; ;

         DoFindAndReplaceFiles( strtemp, "" );   //“” 中为要更新的文件名

   DoFindAndReplaceFiles( strtemp, "");

  DoFindAndReplaceFiles( strtemp, "");

  DoFindAndReplaceFiles( strtemp, "");

 nResult = ListGetNextString (listID, svString); //得到下一个硬盘

  endwhile; 

     SetStatusWindow( 100, "");  //进度条显示满格,查找替换完成

     Delay( 2 );    

     Disable( STATUSEX );

     ListDestroy( listID);    

     MessageBox( "", WARNING );   //输入提示内容

 end;         

 

 //查找替换程序

 function DoFindAndReplaceFiles(strtemp,filename)

  STRING svResult, szServerPath;

  NUMBER nResultTmp;

 begin     

    szServerPath = TARGETDIR ^ "";   //“” 中为你的程序默认的安装路径, TARGETDIR是更改后的路径

    szServerPath = szServerPath + filename;

  nResultTmp = FindAllFiles( strtemp, filename, svResult, RESET );   //可以参照 FIndAllFiles() 函数来看。

  while( nResultTmp>=0 )

  CopyFile( szServerPath, svResult );  

  nResultTmp = FindAllFiles( strtemp, filename, svResult, CONTINUE );

  endwhile; 

FindAllFiles(strtemp, filename, svResult, CANCEL );// 这句要小心,不能遗漏。

 end;     

 

以上的一些可能还存在不少可以改进的地方,希望老鸟指导。有些东西不会,不用怕,总能找到解决的方法。

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息