⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pdrvuni.pas

📁 测试用例
💻 PAS
📖 第 1 页 / 共 2 页
字号:
    UniDrvDLL     : ShortString;
    UniDrvDLLDNum : Byte;
    UniDrvDLLFile : ShortString;
    UniDrvDLLDisk : ShortString;
    UniDrvHLP     : ShortString;
    UniDrvHLPDNum : Byte;
    UniDrvHLPFile : ShortString;
    UniDrvHLPDisk : ShortString;
    IconLib       : ShortString;
    IconLibDNum   : Byte;
    IconLibFile   : ShortString;
    IconLibDisk   : ShortString;

    WinDir        : array[0..255] of Char;
    SysDir        : array[0..255] of Char;

    Win95Layout   : Boolean;
    Failed        : Boolean;
    OpenDialog    : TOpenFileName;

    St            : ShortString;
    StBuf         : array[0..255] of Char;
    FileBuf       : array[0..255] of Char;
    TitleBuf      : array[0..255] of Char;
    FilterBuf     : array[0..255] of Char;
  end;

var
  LocalVars : PLocals;
  Temp      : string;                                               
  Ok        : Boolean;

  function InstallUniFile (SourceName : PChar; DestName : PChar) : Boolean;
    { Copy and uncompress one file }
  var
    ofStrSrc    : TOFStruct;
    ofStrDst    : TOFStruct;
    hfSrcFile   : Integer;
    hfDstFile   : Integer;
    StrBuf      : array[0..255] of Char;
  begin

    with LocalVars^ do
      if Win95Layout then begin
        StrCopy(StrBuf, ' /c extract.exe /Y /L ');                   
        StrCat(StrBuf, SysDir);
        StrCat(StrBuf, ' ');
        StrCat(StrBuf, SourceName);
        StrCat(StrBuf, ' ');
        StrCat(StrBuf, DestName);
        InstallUniFile :=
          (WinExecAndWait32('command.com', StrBuf, sw_Hide) <> -1);

        if not(FileExists(StrPas(SysDir) + '\' + StrPas(DestName))) then
          { file was not in specified CAB, if additional cabs are found }
          { we assume cabs are on CD, so we search all cabs for files   }
          if FileExists(ExtractFilePath(StrPas(SourceName)) + 'WIN95_02.CAB') then begin
            StrCopy(StrBuf, ' /c extract.exe /A /Y /L ');
            StrCat(StrBuf, SysDir);
            StrCat(StrBuf, ' ');
            StrCat(StrBuf, 'WIN95_02.CAB');
            StrCat(StrBuf, ' ');
            StrCat(StrBuf, DestName);
            Result := (WinExecAndWait32('command.com', StrBuf, sw_Hide) <> -1);
          end;

      end else begin
        InstallUniFile := False;
        StrCopy(StrBuf, SysDir);
        AddBackSlashZ(StrBuf, StrBuf);
        StrCat(StrBuf, DestName);
        hfSrcFile := LZOpenFile(SourceName, ofStrSrc, OF_READ);
        hfDstFile := LZOpenFile(StrBuf, ofStrDst, OF_CREATE);
        if (hfSrcFile <> -1) and (hfDstFile <> -1) then
          InstallUniFile := (LZCopy(hfSrcFile, hfDstFile) <> -1);
        LZClose(hfSrcFile);
        LZClose(hfDstFile);
      end;
  end;

  function FilterCopy(P : PChar; const S : string): PChar;
  begin
    Result := nil;
    if S <> '' then begin
      Result := StrPCopy(P, S);
      while P^ <> #0 do begin
        if P^ = '|' then P^ := #0;
        Inc(P);
      end;
      Inc(P);
      P^ := #0;
    end;
  end;

  procedure CleanUp;
  begin
    {free memory}
    with LocalVars^ do begin
      if InfIniFile <> nil then
        InfIniFile.Free;
      if DiskList <> nil then
        DiskList.Free;
    end;
  end;

begin
  Result := ecOK;
  GetMem(LocalVars, sizeof(TLocals));
  with LocalVars^ do begin
    InfIniFile := nil;
    DiskList := nil;
    FillChar(OpenDialog, SizeOf(OpenDialog), 0);

    if UniDrvFilesExist then begin
      Result := ecUniAlreadyInstalled;
    end;

    { get the Windows system directory and Windows directory }
    if (GetSystemDirectory(SysDir, sizeof(SysDir)) = 0) then begin
      CleanUp;
      Result := ecUniCannotGetSysDir;
      Exit;
    end;
    if (GetWindowsDirectory(WinDir, sizeof(WinDir)) = 0) then begin
      CleanUp;
      Result := ecUniCannotGetWinDir;
      Exit;
    end;

    Win95Layout := False;
    StrCopy(StBuf, SysDir);
    StrCat(StBuf, '\SETUP.INF');
    InfIniFile := TIniFile.Create(StrPas(StBuf));
    St := InfIniFile.ReadString('setup', 'help', '');
    if (St = '') then begin
      { must be Windows95, so open Layout.Inf instead }
      InfIniFile.Free;
      StrCopy(StBuf, WinDir);
      StrCat(StBuf, '\INF\LAYOUT.INF');
      InfIniFile := TIniFile.Create(StrPas(StBuf));

      { confirm that it's Windows95 }
      St := InfIniFile.ReadString('version', 'signature', '');
      if (St <> '$CHICAGO$') then begin
        CleanUp;
        Result := ecUniUnknownLayout;
        Exit;
      end;

      Win95Layout := True;

      if Result = ecUniAlreadyInstalled then
      { check to see if ICONLIB.DLL is installed }
        if not(FileExists(StrPas(SysDir) + '\iconlib.dll')) then
          Result := ecOK;
    end;
    if Result  <> ecOK then begin
      CleanUp;
      Result := ecUniAlreadyInstalled;
      Exit;
    end;

    { read the disk name list and search for UniDrv.DLL/HLP in this inf file }
    if Win95Layout then begin
      UniDrvDLL := InfIniFile.ReadString('SourceDisksFiles', 'unidrv.dll', '');
      UniDrvHLP := InfIniFile.ReadString('SourceDisksFiles', 'unidrv.hlp', '');
      IconLib := InfIniFile.ReadString('SourceDisksFiles', 'iconlib.dll', '');
      { It's OK if we can't find/parse the INF. Some installations of Windows }
      { do not install the LAYOUT.INF, so we will let the user browse for     }
      { the required files.  Default cab numbers are from the Win98SE MSDN CD }

      UniDrvDLLDNum := StrToIntDef(ExtractWordS(1, UniDrvDLL, ','), 13);
      St := InfIniFile.ReadString('SourceDisksNames',
                                  IntToStr(UniDrvDLLDNum),
                                  '');
      UniDrvDLLDisk := ExtractWordS(1, St, ',"');
      UniDrvDLLFile := ExtractWordS(2, St, ',"');

      UniDrvHLPDNum := StrToIntDef(ExtractWordS(1, UniDrvHLP, ','), 17);
      St := InfIniFile.ReadString('SourceDisksNames',
                                  IntToStr(UniDrvHLPDNum),
                                  '');
      UniDrvHLPDisk := ExtractWordS(1, St, ',"');
      UniDrvHLPFile := ExtractWordS(2, St, ',"');

      IconLibDNum := StrToIntDef(ExtractWordS(1, IconLib, ','), 12);
      St := InfIniFile.ReadString('SourceDisksNames',
                                  IntToStr(IconLibDNum),
                                  '');
      IconLibDisk := ExtractWordS(1, St, ',"');
      IconLibFile := ExtractWordS(2, St, ',"');
    end else begin
      { not Windows 95 }
      CleanUp;
      Result := ecUniUnknownLayout;
      Exit;
    end;

    Failed := False;
    OpenDialog.hInstance := HInstance;
    with OpenDialog do begin
      lStructSize := SizeOf(OpenDialog);
      Temp := 'Insert ' + UniDrvDLLDisk + ' and Browse to listed file';
      lpstrTitle := StrPCopy(TitleBuf, Temp);
      nMaxFile := SizeOf(FileBuf);
      lpstrFile := StrPCopy(FileBuf, UniDrvDLLFile);
      Flags := OFN_FILEMUSTEXIST;
      lpStrFilter := FilterCopy(FilterBuf,
        UniDrvDLLFile+'|'+UniDrvDLLFile+'|'+'All files|*.*');
    end;
    Failed := not GetOpenFileName(OpenDialog);

   if (not Failed) then
      { found unidrv.dll, uncompress it or extract it from cab file }
      Failed := not InstallUniFile(StrCopy(StBuf, OpenDialog.lpstrFile), 'unidrv.dll');

    if (not Failed) and (UniDrvHLPDNum <> UniDrvDLLDNum) then begin
      { if the new file is in the same directory, we don't need to show the dialog again }
      if not(FileExists(ExtractFilePath(
        StrPas(OpenDialog.lpstrFile)) + UniDrvHlpFile)) then
        { need another disk prompt }
        with OpenDialog do begin
          Temp := 'Insert ' + UniDrvHLPDisk + ' and Browse to listed file';
          lpstrTitle := StrPCopy(TitleBuf, Temp);
          nMaxFile := SizeOf(FileBuf);

          lpstrFile := StrPCopy(FileBuf, UniDrvHLPFile);
          lpStrFilter := FilterCopy(FilterBuf,
            UniDrvHLPFile+'|'+UniDrvHLPFile+'|'+'All files|*.*');
          Failed := not GetOpenFileName(OpenDialog);
        end;
    end;
    
    if (not Failed) then
      { found unidrv.hlp, uncompress it or extract it from cab file }
      Failed := not InstallUniFile(
        StrPCopy(StBuf,ExtractFilePath(
        StrPas(OpenDialog.lpstrFile)) + UniDrvHlpFile), 'unidrv.hlp');

    if Win95Layout then begin
      if (not Failed) and (IconLibDNum <> UniDrvHLPDNum) then
        { if the new file is in the same directory, we don't need to show the dialog again }
        if not(FileExists(ExtractFilePath(
          StrPas(OpenDialog.lpstrFile)) + IconLibFile)) then
          with OpenDialog do begin
            { need another disk prompt }
            Temp := 'Insert ' + IconLibDisk + ' and Browse to listed file';
            lpstrTitle := StrPCopy(TitleBuf, Temp);
                  nMaxFile := SizeOf(FileBuf);

            lpstrFile := StrPCopy(FileBuf, IconLibFile);
            lpStrFilter := FilterCopy(FilterBuf,
              IconLibFile+'|'+IconLibFile+'|'+'All files|*.*');
            Failed := not GetOpenFileName(OpenDialog);
          end;
      if (not Failed) then
        { found unidrv.hlp, uncompress it or extract it from cab file }
        Failed := not InstallUniFile(StrCopy(StBuf,
           StrPCopy(StBuf,ExtractFilePath(
          StrPas(OpenDialog.lpstrFile)) + IconLibFile)), 'iconlib.dll');
    end;

    { make sure files were copied correctly to the windows system directory }
    { some Windows install CDs do not include Unidrv.hlp, so ignore it if we }
    { don't find it }
    Ok := ExistFileZ(StrPCopy(StBuf, StrPas(SysDir) + '\unidrv.dll'))
      and ExistFileZ(StrPCopy(StBuf, StrPas(SysDir) + '\iconlib.dll'));
    if not Ok then begin
      CleanUp;
      Result := ecUniCannotInstallFile;
    end else begin
      CleanUp;
      Result := ecOK;
    end;
  end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -