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

📄 pdrvunnt.pas

📁 测试用例
💻 PAS
📖 第 1 页 / 共 2 页
字号:
    Strings       : TStringList;
    WinOther      : TStringList;
    RASDDDLL      : ShortString;
    RASDDDLLDNum  : Byte;
    RASDDDLLFile  : ShortString;
    RASDDDLLDisk  : ShortString;
    RASDDUI       : ShortString;
    RASDDUIDNum   : Byte;
    RASDDUIFile   : ShortString;
    RASDDUIDisk   : ShortString;
    RASDDHLP      : ShortString;
    RASDDHLPDNum  : Byte;
    RASDDHLPFile  : ShortString;
    RASDDHLPDisk  : ShortString;

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

    WinNT4Layout   : Boolean;
    Failed        : Boolean;
    OpenDialog    : TOpenDialog;

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

var
  LocalVars  : PLocals;
  SizeNeeded : DWORD;
  Ok         : Boolean;

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

    with LocalVars^ do begin

      StrCopy(StrBuf, '');

      StrCat(StrBuf, SourceName);
      StrCat(StrBuf, ' ');
      StrCat(StrBuf, DriverDir);
      AddBackSlashZ(StrBuf, StrBuf);
      StrCat(StrBuf, DestName);

      StrCopy(StrBuf1, '');
      StrCat(StrBuf1, DriverDir);
      AddBackSlashZ(StrBuf1, StrBuf1);
      StrCat(StrBuf1, DestName);
      if StrPos(SourceName, DestName) = nil then
        Result := (WinExecAndWait32('expand ', StrBuf, sw_Hide) <> -1)
      else
        Result := CopyFile(SourceName, StrBuf1, False);
    end;
  end;

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

  procedure ReplaceString(Strings : TStrings; var St : string);
    {- replaces expressions of the form %exp% with their name from Strings}
  var
    i,p1,p2 : integer;
    Key,Tmp : string;
  begin
    p1 := pos('%',St);
    if p1 <> 0 then begin
      delete(St,p1,1);
      p2 := pos('%',St);
      if p2 = 0 then
        raise exception.Create('Unexpected INF format encountered');
      Key := copy(St,p1,p2-p1);
      delete(St,p1,p2-p1+1);
      for i := 0 to pred(Strings.Count) do begin
        Tmp := Strings[i];
        if copy(Tmp,1,p2-p1) = Key then begin
          p2 := pos('=',Tmp);
          if p2 <> 0 then begin
            Insert(copy(Tmp,P2+1,MaxLongInt),St,p1);
            break;
          end;
        end;
      end;
    end;
  end;

begin
  GetMem(LocalVars, sizeof(TLocals));
  with LocalVars^ do begin
    InfIniFile := nil;
    DiskList := nil;
    OpenDialog := nil;

    if UniDrvFilesExist then begin
      CleanUp;
      Result := ecUniAlreadyInstalled;
      Exit;
    end;

    if (GetSystemDirectory(SysDir, sizeof(SysDir)) = 0) then begin
      CleanUp;
      Result := ecUniCannotGetWinDir;
      Exit;
    end;
    { get the Windows NT printer driver directory }
    if not GetPrinterDriverDirectory(nil, nil, 1, @DriverDir, sizeof(DriverDir), SizeNeeded) then begin
      CleanUp;
      Result := ecUniCannotGetPrinterDriverDir;
      Exit;
    end;
    if (GetWindowsDirectory(WinDir, sizeof(WinDir)) = 0) then begin
      CleanUp;
      Result := ecUniCannotGetWinDir;
      Exit;
    end;

    WinNT4Layout := True;
    StrCopy(StBuf, WinDir);
    StrCat(StBuf, '\INF\LAYOUT.INF');
    InfIniFile := TIniFile.Create(StrPas(StBuf));

    { find out what version of NT it is }
    St := InfIniFile.ReadString('version', 'signature', '');
    if (St <> '$Windows NT$') then
      WinNT4Layout := False;

    { read the disk name list and search for RASDD.DLL/HLP in this inf file }
    if WinNT4Layout then begin
      RasDDDLL := InfIniFile.ReadString('SourceDisksFiles', 'Rasdd.dll', '');
      RASDDHLP := InfIniFile.ReadString('SourceDisksFiles', 'Rasddui.hlp', '');
      RASDDUI := InfIniFile.ReadString('SourceDisksFiles', 'Rasddui.dll', '');

      Strings := TStringList.Create;
      InfIniFile.ReadSectionValues('Strings', Strings);

      RASDDDLLDNum := StrToIntDef(ExtractWordS(1, RASDDDLL, ','), 0);
      St := InfIniFile.ReadString('SourceDisksNames.x86',
                                  IntToStr(RASDDDLLDNum),'');
      RASDDDLLDisk := ExtractWordS(1, St, ',\');
      ReplaceString(Strings,RASDDDLLDisk);
      RASDDDLLFile := 'Rasdd.dl_';

      RASDDHLPDNum := StrToIntDef(ExtractWordS(1, RASDDHLP, ','), 0);
      St := InfIniFile.ReadString('SourceDisksNames.x86',
                                  IntToStr(RASDDHLPDNum),'');
      RASDDHLPDisk := ExtractWordS(1, St, ',\');
      ReplaceString(Strings,RASDDHLPDisk);
      RASDDHLPFile := 'Rasddui.hl_';

      RASDDUIDNum := StrToIntDef(ExtractWordS(1, RASDDUI, ','), 0);
      St := InfIniFile.ReadString('SourceDisksNames.x86',
                                  IntToStr(RASDDUIDNum),'');
      RASDDUIDisk := ExtractWordS(1, St, ',\');
      ReplaceString(Strings,RASDDUIDisk);
      RASDDUIFile := 'Rasddui.dl_';
    end else begin
      { NT 3.51 }
      InfIniFile.Free;

      StrCopy(StBuf, SysDir);
      StrCat(StBuf, '\SETUP.INF');
      InfIniFile := TIniFile.Create(StrPas(StBuf));

      DiskList := TStringList.Create;
      InfIniFile.ReadSectionValues('Source Media Descriptions', DiskList);

      Assign(InfTextFile, StrPas(SysDir) + '\PRINTER.INF');
      SetTextBuf(InfTextFile, InfBuf, sizeof(TFileBuf));
      Reset(InfTextFile);
      RASDDDLL := FindTextInSection(InfTextFile, pChar('RASDD'),pChar('[FILES-PRINTERDRIVER]'));
      RASDDHLP := FindTextInSection(InfTextFile, pChar('RASDD'),pChar('[FILES-PRINTERDRIVERHELP]'));
      RASDDUI := FindTextInSection(InfTextFile, pChar('RASDDUI'),pChar('[FILES-PRINTERCONFIG]'));
      Close(InfTextFile);
      
      RASDDDLLDNum := StrToInt(ExtractWordS(2, RASDDDLL, '=,'));
      RASDDDLLDisk := ExtractWordS(2, DiskList.Strings[pred(RASDDDLLDNum)],
                                   ',"');
      RASDDDLLFile := 'Rasdd.dl_';

      RASDDHLPDNum := StrToInt(ExtractWordS(2, RASDDHLP, '=,'));
      RASDDHLPDisk := ExtractWordS(2, DiskList.Strings[pred(RASDDHLPDNum)],
                                   ',"');
      RASDDHLPFile := 'Rasddui.hl_';

      RASDDUIDNum := StrToInt(ExtractWordS(2, RASDDUI, '=,'));
      RASDDUIDisk := ExtractWordS(2, DiskList.Strings[pred(RASDDUIDNum)],
                                   ',"');
      RASDDUIFile := 'Rasddui.dl_';
    end;

    Failed := False;
    OpenDialog := TOpenDialog.Create(nil);
    with OpenDialog do begin
      if RASDDDLLDisk = '' then
        Title := 'Browse to listed file'
      else
        Title := 'Insert ' + RASDDDLLDisk + ' and Browse to listed file';
      Filename := RASDDDLLFile;
      Options := [ofFileMustExist];
      Filter := Filename+'|'+'Rasdd.dl?'+'|'+'All files|*.*';
    end;
    Failed := not OpenDialog.Execute;

    if (not Failed) then
      { found RASDD.dll, uncompress it }
      Failed := not InstallUniFile(StrPCopy(StBuf, OpenDialog.Filename), 'Rasdd.dll');

    if (not Failed) and (RASDDHLPDNum <> RASDDDLLDNum) then begin
      { need another disk prompt }
      with OpenDialog do begin
        if RASDDDLLDisk = '' then
          Title := 'Browse to listed file'
        else
          Title := 'Insert ' + RASDDHLPDisk + ' and Browse to listed file';
        Filename := RASDDHLPFile;
        Filter := Filename+'|'+'Rasddui.hl?'+'|'+'All files|*.*';
        if not OpenDialog.Execute then
          Failed := True;
      end;
    end else
      if FileExists(ExtractFilePath(OpenDialog.FileName) + 'Rasddui.hlp') then
        OpenDialog.Filename := ExtractFilePath(OpenDialog.FileName) + 'Rasddui.hlp'
      else
        OpenDialog.FileName := ExtractFilePath(OpenDialog.FileName) + 'Rasddui.hl_';

    if (not Failed) then
      { found RASDDUI.hlp, uncompress it }
      Failed := not InstallUniFile(StrPCopy(StBuf, OpenDialog.Filename),
                                   'Rasddui.hlp');

    OpenDialog.Filename := RASDDUIFile;
    if (not Failed) and (RASDDUIDNum <> RASDDHLPDNum) then
      { need another disk prompt }
      with OpenDialog do begin
        if RASDDDLLDisk = '' then
          Title := 'Browse to listed file'
        else
          Title := 'Insert ' + RASDDUIDisk + ' and Browse to listed file';
        Filter := Filename+'|'+'Rasddui.dl?'+'|'+'All files|*.*';
        if not OpenDialog.Execute then
          Failed := True;
      end;

    if FileExists(ExtractFilePath(OpenDialog.FileName) + 'Rasddui.dll') then
      OpenDialog.FileName := ExtractFilePath(OpenDialog.FileName) + 'Rasddui.dll'
    else
      OpenDialog.FileName := ExtractFilePath(OpenDialog.FileName) + 'Rasddui.dl_';

    if (not Failed) then
      { found RASDDUI.DLL, uncompress it}
      Failed := not InstallUniFile(StrPCopy(StBuf, OpenDialog.Filename), 'Rasddui.dll');

    { make sure files were copied correctly to the windows system directory }
    Ok := UniDrvFilesExist;
    if not Ok then begin
      CleanUp;
      Result := ecRasDDNotInstalled;                                     {!!.05}
    end else begin
      CleanUp;
      Result := ecOK;
    end;
  end;
end;

end.

⌨️ 快捷键说明

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