如何使用 InstallShield6.22 打包J2EE WEB工程

时间:2023-01-28 17:05:50

 

今天研究了一下用InstallShield6.22打包,顺便把代码给大家共享一下,希望对刚接触的朋友有所帮助(我也是刚接触的),程序包括安装JDK,TOMCATE,MYSQL等等,程序还不完善,以后有时间再跟大家分享。语言包我也发到资源里了,大家可以下载。 

#include "ifx.h"
    
 
function OnFirstUIBefore()         //变量
    string  szTitle, szMsg;
    string  szLicenseFile, szQuestion;
    string  szName, szCompany, szSerial;
    string  szTargetPath;
    string  szFile, szDir;
    string  szComponents, szTargetdir;
    string  szJDK, svTomcat, svMySql, szKey;
    LIST  list, listStartCopy;
    number  nResult, nLevel, nSize, nSetupType, nvSize, nType;   
   
begin       
    //初始化变量
    nSetupType = TYPICAL; 
    TARGETDIR = PROGRAMFILES
^@COMPANY_NAME ^@PRODUCT_NAME
    szDir = TARGETDIR;
    szName    = "试用版用户";
    szCompany = "wpabbs netstore";
    szSerial = "111-111111"; 


Dlg_Start:


Dlg_SdWelcome:    //欢迎 对话框
    szTitle = "欢迎您的使用";
    szMsg   = "";
    nResult = SdWelcome( szTitle, szMsg );
    if (nResult = BACK) goto Dlg_Start;

Dlg_SdLicense:    //软件许可协议 对话框
    szLicenseFile = SUPPORTDIR ^ "license.txt";
    szTitle    = "";
    szMsg      = "";
    szQuestion = "";
    nResult    = SdLicense( szTitle, szMsg, szQuestion, szLicenseFile );
    if (nResult = BACK) goto Dlg_SdWelcome;      
   
Dlg_SdShowInfoList://readme文件 对话框
 szFile = SUPPORTDIR ^ "infolist.txt";
 list = ListCreate( STRINGLIST );
 ListReadFromFile( list, szFile );
 szTitle = "";
 szMsg = "";
 nResult = SdShowInfoList( szTitle, szMsg, list ); 
 
ListDestroy( list );
if (nResult = BACK) goto Dlg_SdLicense;
 
 
Dlg_SdRegisterUserEx:  //用户信息 对话框
    szMsg   = "你的信息";
    szTitle = "个人信息"; 
    nResult = SdRegisterUserEx(szTitle,szMsg,szName,szCompany, szSerial );
    if(nResult = NEXT) then
        if(StrCompare(szSerial,"111-111111") != 0) then
         MessageBox("输入的序列号   "+szSerial+"不正确!",WARNING);
         goto Dlg_SdRegisterUserEx;
        endif;
    endif;
   
    if (nResult = BACK) goto Dlg_SdLicense;

Dlg_SdAskDestPath:     //安装路径  对话框
    szTitle = "";
    szMsg   = "";
    nResult = SdAskDestPath( szTitle, szMsg, szDir, 0 );
    TARGETDIR = szDir;
    if (nResult = BACK) goto Dlg_SdRegisterUserEx;

Dlg_SetupType:          //安装类型 对话框
    szTitle    = "选择安装类型";
    szMsg      = "";
    nResult = SetupType ( szTitle , szMsg , "" , nSetupType , 0 );
    if (nResult = BACK) then
        goto Dlg_SdAskDestPath;
        goto Dlg_SdRegisterUserEx
    else
        nSetupType = nResult;
        if (nSetupType != CUSTOM) then
        szTargetPath = TARGETDIR;
        nvSize = 0;
        ComponentCompareSizeRequired(MEDIA,szTargetPath,nvSize);
        if (nvSize != 0) then     
                MessageBox( szSdStr_NotEnoughSpace, WARNING );
            goto Dlg_SetupType;
            endif;
        endif;  
    endif;

Dlg_SdComponentTree:
    if ((nResult = BACK) && (nSetupType != CUSTOM)) goto Dlg_SetupType;
    szTitle    = "";
    szMsg      = "";
    szTargetdir = TARGETDIR;
    szComponents = "";
    nLevel = 2;
    if (nSetupType = CUSTOM) then
      nResult = SdComponentTree(szTitle, szMsg, szTargetdir, szComponents, nLevel);
      if (nResult = BACK) goto Dlg_SetupType; 
    endif;

Dlg_ObjDialogs:
    nResult = ShowObjWizardPages(nResult);
    if (nResult = BACK) goto Dlg_SdComponentTree;

Dlg_SdStartCopy:    //文件的复制
    szTitle = "文件复制";
    szMsg   = "所有工作准备完毕,点击下一步开始复制必备的安装文件。。。";
    listStartCopy = ListCreate( STRINGLIST );
    nResult = SdStartCopy( szTitle, szMsg, listStartCopy ); 
    ListDestroy(listStartCopy);       
    if (nResult = BACK) goto Dlg_ObjDialogs;  
   
 
    SetStatusWindow(0, "");
    Enable(STATUSEX);
    StatusUpdate(ON, 100); 

    return 0;
end;

    
function   OnFirstUIAfter()      
 
  STRING   szTitle,   szMsg1,   szMsg2,   szOption1,   szOption2, szDir ,szJDK;        
  STRING   szFolder; 
  STRING   svTomcat, szKey, szCmdLine;
  NUMBER   nvSize, nType;
   begin   

  //安装外部程序
   MessageBox("所有程序准备就绪,正在准备安装必备的其他程序及配置服务器。。。",INFORMATION);        
   MessageBox ("接下来系统将安装必要的JDK外部程序 ...如果系统提示已经安装JDK则点击取消进行下一步安装。", INFORMATION); 
    szJDK =  TARGETDIR ^ "1.exe";
    if (LaunchAppAndWait (szJDK, "", WAIT) < 0) then
       MessageBox ("不能加载程序 "+ szJDK +".",SEVERE);
    endif;  
   
  MessageBox ("接下来系统将安装必要的tomcat外部程序 ...如果系统提示已经安装tomcat则点击取消进行下一步安装。", INFORMATION); 
    szJDK =  TARGETDIR ^ "2.exe";
    if (LaunchAppAndWait (szJDK, "", WAIT) < 0) then
       MessageBox ("不能加载程序 "+ szJDK +".",SEVERE);
    endif; 
   
  MessageBox ("接下来系统将安装必要的mysql外部程序 ...如果系统提示已经安装mysql则点击取消进行下一步安装。", INFORMATION); 
    szJDK =  TARGETDIR ^ "3.exe";
    if (LaunchAppAndWait (szJDK, "", WAIT) < 0) then
       MessageBox ("不能加载程序 "+ szJDK +".",SEVERE);
    endif;
             
  MessageBox("请在安装完MySQL后点击确定,进行服务器配置。。。",SEVERE);           
   // 搜寻 tomcat 安装的路径
    RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);  
    szKey = "SOFTWARE//Apache Software Foundation//Tomcat//5.5";
    nType = REGDB_STRING; 
    svTomcat = "";
   
    if(RegDBGetKeyValueEx(szKey, "InstallPath", nType, svTomcat, nvSize) < 0) then
        MessageBox ("查找 Tomcat 路径失败,系统不能继续安装", SEVERE);    
    endif;
    szDir = svTomcat + "
//webapps//NetStore";
   
    MessageBox("正在准备附加程序文件。。。",INFORMATION);
   
    szFolder   =   TARGETDIR   +   "
//NetStore";
    CreateDir(szDir);                                                                  
          if   (XCopyFile(szFolder^"*.*",szDir,INCLUDE_SUBDIR)<0)    
          then  
                MessageBox("程序文件附加失败!",SEVERE);              
          else  
            MessageBox("程序文件已经附加成功!",INFORMATION);
          endif;
         
          // 准备关闭MySQL服务器   
                  LaunchAppAndWait ("net","stop mysql"   ,WAIT );  //启动MySQL
                  MessageBox("MySQL数据库已经关闭成功!正在准备复制数据库文件....",INFORMATION);
         
          szDir   =  "C://Program Files//MySQL//MySQL Server 5.0//data//netstore";   //此处是MySQL的绝对路径 
          szFolder   =   TARGETDIR   +   "
//netstore_data";   
          CreateDir(szDir);                                                                  
          if   (XCopyFile(szFolder^"*.*",szDir,COMP_NORMAL)<0)    
          then  
                MessageBox("数据库文件附加失败!",SEVERE);              
          else  
            MessageBox("数据库文件已经附加成功!",INFORMATION);    
          endif; 
           
          DeleteDir(TARGETDIR, ALLCONTENTS);   //删除所有已经拷贝文件  
         
         
          // 准备启动MySQL服务器   
                  LaunchAppAndWait ("net","start mysql"   ,WAIT );  //启动MySQL
                  MessageBox("MySQL数据库已经启动成功!正在准备启动Tomcat....",INFORMATION);
          // 准备启动TOMCAT服务器
      RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);  
      szKey = "SOFTWARE//Apache Software Foundation//Tomcat//5.5";
     //szKey = "SOFTWARE//MySQL AB//MySQL Server 5.0"; 
      nType = REGDB_STRING; 
      svTomcat = "";  
            if(RegDBGetKeyValueEx(szKey, "InstallPath", nType, svTomcat, nvSize) < 0) then
             MessageBox ("查找 Tomcat 路径失败,系统不能继续安装", SEVERE);    
            endif; 
            TARGETDIR = svTomcat + "
//bin//tomcat5.exe";
            LaunchAppAndWait (TARGETDIR,"",NOWAIT);  //启动tomcat
            MessageBox("Tomcat 已经启动成功!正在准备打开网页....",INFORMATION);
            //准备打开浏览器
            szCmdLine = "
http://LocalHost:8080/NetStore/index.jsp";
   if (LaunchApp(PROGRAMFILES ^"Internet Explorer"^"IEXPLORE.EXE", szCmdLine) < 0) then
    MessageBox ("不能打开浏览器.",SEVERE);
   endif;

           return 0;
  end;                            
   
    
    

    
///////////////////////////////////////////////////////////////////////////////
//
//  FUNCTION:   OnMoving
//
//  EVENT:      Moving event is sent when file transfer is started as a result of
//              ComponentTransferData call, before any file transfer operations
//              are performed.
//
///////////////////////////////////////////////////////////////////////////////  

  function   OnMaintUIAfter()  
          NUMBER   nResult,   nType, nvSize;  
          STRING   szTitle,   szMsg,   svDir,   svResult,   szCaption;  
          STRING   svTomcat, szKey;
  begin  

  Dlg_Start:  
          Disable(BACKBUTTON);  
          nType   =   SdWelcomeMaint(szTitle,   szMsg,   MODIFY);  
          Enable(BACKBUTTON);  
   
          if   (nType   =   REMOVEALL)   then  
                  MessageBox("正在准备卸载其他相关程序,如果在卸载过程中发生错误请手动卸载外部程序。。。",INFORMATION);  
                   //获得TOMCAT路径
                  RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);  
        szKey = "SOFTWARE//Apache Software Foundation//Tomcat//5.5"; 
        nType = REGDB_STRING; 
        svTomcat = "";  
              if(RegDBGetKeyValueEx(szKey, "InstallPath", nType, svTomcat, nvSize) < 0) then
               MessageBox ("查找 Tomcat 路径失败,系统不能继续卸载", SEVERE);    
              endif; 
              TARGETDIR = svTomcat + "
//Uninstall.exe";

                  LaunchAppAndWait(TARGETDIR,"-k stop",WAIT);            
                  LaunchAppAndWait(TARGETDIR,"-k uninstall",WAIT);
          
                  LaunchAppAndWait("net","stop mysql",WAIT);
                  LaunchAppAndWait("C://Program Files//MySQL//MySQL Server 5.0//bin//mysqld.exe","-remove",WAIT);                   
                  svResult   =   SdLoadString(IFX_MAINTUI_MSG);  
                  szCaption   =   SdLoadString(IFX_ONMAINTUI_CAPTION);  
                  nResult   =   SprintfBox(MB_OKCANCEL,szCaption,"%s",svResult);  
                  if   (nResult   =   IDCANCEL)   goto   Dlg_Start;  
 
          endif;  
   
          nResult   =   NEXT;
          return 0;  

  end;  

function OnMoving()
    string szAppPath;
begin
    // Set LOGO Compliance Application Path
    // TO DO : if your application .exe is in a subfolder of TARGETDIR then add subfolder
    LaunchAppAndWait("net","stop mysql",WAIT);
    szAppPath = TARGETDIR;
    RegDBSetItem(REGDB_APPPATH, szAppPath);
    RegDBSetItem(REGDB_APPPATH_DEFAULT, szAppPath ^ @PRODUCT_KEY);
end;