home *** CD-ROM | disk | FTP | other *** search
/ PC World 1999 February / PCWorld_1999-02_cd.bin / temacd / HotKeys / Setup.dpr < prev    next >
Text File  |  1998-10-27  |  6KB  |  193 lines

  1. program Setup;
  2.  
  3. uses
  4.   Windows;
  5.  
  6. {$R RESOURCE.RES}
  7.  
  8. {$I-}
  9. const
  10.   InfFile : array[0..70] of string =
  11.           ( '[Version]',
  12.             'Signature=$Chicago$',
  13.             'Provider=%Author%',
  14.             '[DefaultInstall]',
  15.             'CopyFiles=Hotkeys.Files.Install',
  16.             'UpdateInis=Hotkeys.Add.Inis',
  17.             'AddReg=Hotkeys.Add.Reg',
  18.             '[DefaultUnInstall]',
  19.             'DelFiles=Hotkeys.Files.UnInstall',
  20.             'UpdateInis=Hotkeys.Del.Inis',
  21.             'DelReg=Hotkeys.Del.Reg',
  22.             '[DestinationDirs]',
  23.             'Hotkeys.Files.Install=24,%InstallDir%',
  24.             'Hotkeys.Files.UnInstall=24,%InstallDir%',
  25.             'Hotkeys.Files.Other=24,%InstallDir%',
  26.             '[SourceDisksNames]',
  27.             '1="%Hotkeys%","",1',
  28.             '[SourceDisksFiles]',
  29.             'HOTKEYS.EXE=1',
  30.             'HKRESTRT.EXE=1',
  31.             'HKTODOS.PIF=1',
  32.             'HOTKEYS.HLP=1',
  33.             'HOTKEYS.HKD=1',
  34.             'SETUP.EXE=1',
  35.             '[Hotkeys.Files.Install]',
  36.             'HOTKEYS.EXE',
  37.             'HOTKEYS.HLP',
  38.             'HOTKEYS.HKD,,,16',
  39.             'HKRESTRT.EXE',
  40.             'HKTODOS.PIF',
  41.             'UNINSTAL.EXE,SETUP.EXE',
  42.             '[Hotkeys.Files.UnInstall]',
  43.             'HOTKEYS.EXE',
  44.             'HOTKEYS.HLP',
  45.             'HOTKEYS.HKD',
  46.             'HKRESTRT.EXE',
  47.             'HKTODOS.PIF',
  48.             'HOTKEYS.GID',
  49.             'HOTKEYS.FTS',
  50.             'HOTKEYS.INI',
  51.             'HKSETUP.INF',
  52.             'UNINSTAL.EXE,,,1',
  53.             '[Hotkeys.Add.Inis]',
  54.             'setup.ini, progman.groups,, "group1=""Hotkeys"""',
  55.             'setup.ini, group1,, """%Hotkeys%"", ""%24%\%InstallDir%\HOTKEYS.EXE"",,,,,%Hotkeys%',
  56.             'setup.ini, group1,, """%Hothelp%"", ""%24%\%InstallDir%\HOTKEYS.HLP"",,,,,%Hothelp%',
  57.             'setup.ini, group1,, """%Hotinst%"", ""%24%\%InstallDir%\UNINSTAL.EXE"",""%24%\%InstallDir%\UNINSTAL.EXE"",1,,,%Hotinst%',
  58.             '[Hotkeys.Del.Inis]',
  59.             'setup.ini, progman.groups,, "group1=""Hotkeys"""',
  60.             'setup.ini, group1,, """%Hotkeys%""',
  61.             'setup.ini, group1,, """%Hothelp%""',
  62.             'setup.ini, group1,, """%Hotinst%""',
  63.             '[Hotkeys.Add.Reg]',
  64.             'HKLM,%UIF%',
  65.             'HKLM,%UIF%,DisplayName,,"%Hotkeys% %Version%"',
  66.             'HKLM,%UIF%,UninstallString,,"%24%\%InstallDir%\UNINSTAL.EXE"',
  67.             'HKLM,%RUN%,Hotkeys,,"%24%\%InstallDir%\HOTKEYS.EXE"',
  68.             'HKLM,%RNO%,Hotkeys,,"%24%\%InstallDir%\UNINSTAL.EXE RunHotkeys"',
  69.             '[Hotkeys.Del.Reg]',
  70.             'HKLM,%UIF%',
  71.             'HKLM,%RUN%,Hotkeys',
  72.             '[Strings]',
  73.             'Hotkeys="Hotkeys"',
  74.             'Version="version 1.3"',
  75.             'Hothelp="Hotkeys Help"',
  76.             'Hotinst="Hotkeys Uninstall"',
  77.             'InstallDir="Progra~1\Hotkeys"',
  78.             'Author="SheAr software"',
  79.             'UIF="Software\Microsoft\Windows\CurrentVersion\Uninstall\Hotkeys"',
  80.             'RUN="Software\Microsoft\Windows\CurrentVersion\Run"',
  81.             'RNO="Software\Microsoft\Windows\CurrentVersion\RunOnce"');
  82.  
  83. function IsWinNT: Boolean;
  84. var
  85.   OsVersionInfo: TOSVersionInfo;
  86. begin
  87.   OsVersionInfo.dwOSVersionInfoSize := sizeof(TOsVersionInfo);
  88.   GetVersionEx(OsVersionInfo);
  89.   Result := OsVersionInfo.dwPlatformID = VER_PLATFORM_WIN32_NT;
  90. end;
  91.  
  92.  
  93. function GetWinDir: String;
  94. var
  95.   Buf: array[0..MAX_PATH] of char;
  96. begin
  97.   GetWindowsDirectory(Buf, MAX_PATH);
  98.   Result := Buf;
  99.   if Result[Length(Result)]<>'\' then Result := Result + '\';
  100. end;
  101.  
  102. function GetAppDir: String;
  103. begin
  104.   Result := ParamStr(0);
  105.   while (Result<>'') and (Result[Length(Result)]<>'\') do Delete(Result, Length(Result), 1);
  106. end;
  107.  
  108. function WinExecAndWait(FileName: String; Visibility: Integer): Integer;
  109. var
  110.   StartupInfo: TStartupInfo;
  111.   ProcessInfo: TProcessInformation;
  112. begin
  113.   FillChar(StartupInfo,Sizeof(StartupInfo),#0);
  114.   StartupInfo.cb := Sizeof(StartupInfo);
  115.  
  116.   StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
  117.   StartupInfo.wShowWindow := Visibility;
  118.   if not CreateProcess(nil, PChar(FileName), nil, nil, False, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo) then
  119.    Result := -1
  120.   else
  121.    begin
  122.      WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
  123.      GetExitCodeProcess(ProcessInfo.hProcess,Result);
  124.    end;
  125. end;
  126.  
  127. var
  128.   F : Text;
  129.   Command, AppDir: String;
  130.  
  131. const
  132.   InfFileName = 'HKSETUP.INF';
  133.  
  134. procedure ExportInfFile;
  135. var
  136.   i : integer;
  137. begin
  138.   AssignFile(F, AppDir + InfFileName);
  139.   Rewrite(F);
  140.   for i:=Low(InfFile) to High(InfFile) do WriteLn(F, InfFile[i]);
  141.   CloseFile(F);
  142. end;
  143.  
  144. procedure CloseHotkeys;
  145. var
  146.   hwndHotkeys: THandle;
  147. const
  148.   WM_USER     = $0400;
  149.   WM_QUITHOTK = WM_USER+2004;
  150. begin
  151.   hwndHotkeys := FindWindow('TfrmHotkeyEdit', nil);
  152.   if hwndHotkeys<>0 then
  153.    begin
  154.      SendMessage(hwndHotkeys, WM_QUITHOTK, WM_QUITHOTK, 0);
  155.      Sleep(500);
  156.    end;
  157. end;
  158.  
  159. begin
  160.   AppDir := GetAppDir;
  161.  
  162.   if IsWinNT then
  163.    Command := 'rundll32.exe setupapi'
  164.   else
  165.    Command := 'rundll.exe setupx.dll';
  166.  
  167.   Command := Command + ',InstallHinfSection Default';
  168.  
  169.   if ParamStr(1)='RunHotkeys' then
  170.    WinExec(PChar(Copy(GetWinDir, 1, 3) + 'PROGRA~1\HOTKEYS\HOTKEYS.EXE'), SW_SHOW)
  171.   else if Pos('UNINSTAL.EXE', CharUpper(PChar(ParamStr(0))))>0 then
  172.    begin
  173.      if MessageBox(0, 'Are you sure you want to completely remove the Hotkeys application from your system?', 'Hotkeys 1.3 Uninstall', MB_ICONQUESTION or MB_YESNO)=IDYES then
  174.       begin
  175.         CloseHotkeys;
  176.         // Deletes the hotkeys application
  177.         ExportInfFile;
  178.         WinExecAndWait(Command +'Uninstall 132 ' + AppDir + InfFileName, SW_SHOW);
  179.         DeleteFile(PChar(ParamStr(0)));
  180.       end;
  181.    end
  182.   else
  183.    begin
  184.      if MessageBox(0, 'This will install the Hotkeys application on your harddisk. Press ''Ok'' to continue with installation or ''Cancel'' to cancel the installation.', 'Hotkeys 1.3 Installation', MB_OKCANCEL)=IDOK then
  185.       begin
  186.         CloseHotkeys;
  187.         ExportInfFile;
  188.         WinExecAndWait(Command + 'Install 132 ' + AppDir + InfFileName, SW_SHOW);
  189.         Erase(F);
  190.       end;
  191.    end;
  192. end.
  193.