📄 pdrvuni.pas
字号:
(***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is TurboPower Async Professional
*
* The Initial Developer of the Original Code is
* TurboPower Software
*
* Portions created by the Initial Developer are Copyright (C) 1991-2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** *)
{*********************************************************}
{* PDRVUNI.PAS 4.06 *}
{*********************************************************}
{* Win9x/ME Printer driver installation methods *}
{*********************************************************}
{Global defines potentially affecting this unit}
{$I AWDEFINE.INC}
{Options required for this unit}
{$X+,I-,T-}
{$H-,J-}
unit PDrvUni;
{- Fax printer driver installation -- UniDrv.DLL/.HLP support }
interface
function UniDrvFilesExist : Boolean;
{ Returns True if both UniDrv.DLL and UniDrv.HLP are already installed }
function InstallUniDrvFiles : Integer;
{ Attempts to install UniDrv.DLL and UniDrv.HLP from setup disks }
implementation
uses
SysUtils,
IniFiles,
Classes,
OoMisc,
LZExpand,
ShellAPI,
WinProcs,
WinTypes,
Messages,
CommDlg;
type
PFileBuf = ^TFileBuf;
TFileBuf = array[0..16383] of Byte;
function CharExistsS(const S : ShortString; C : AnsiChar) : Boolean; register;
{-Determine whether a given character exists in a string. }
asm
xor ecx, ecx
mov ch, [eax]
inc eax
or ch, ch
jz @@Done
jmp @@5
@@Loop:
cmp dl, [eax+3]
jne @@1
inc cl
jmp @@Done
@@1:
cmp dl, [eax+2]
jne @@2
inc cl
jmp @@Done
@@2:
cmp dl, [eax+1]
jne @@3
inc cl
jmp @@Done
@@3:
cmp dl, [eax+0]
jne @@4
inc cl
jmp @@Done
@@4:
add eax, 4
sub ch, 4
@@5:
cmp ch, 4
jge @@Loop
cmp ch, 3
je @@1
cmp ch, 2
je @@2
cmp ch, 1
je @@3
@@Done:
xor eax, eax
mov al, cl
end;
function WordPositionS(N : Cardinal; S, WordDelims : ShortString;
var Pos : Cardinal) : Boolean;
{-Given an array of word delimiters, set Pos to the start position of the
N'th word in a string. Result indicates success/failure.}
var
I : Cardinal;
Count : Byte;
SLen : Byte absolute S;
begin
Count := 0;
I := 1;
Result := False;
while (I <= SLen) and (Count <> N) do begin
{skip over delimiters}
while (I <= SLen) and CharExistsS(WordDelims, S[I]) do
Inc(I);
{if we're not beyond end of S, we're at the start of a word}
if I <= SLen then
Inc(Count);
{if not finished, find the end of the current word}
if Count <> N then
while (I <= SLen) and not CharExistsS(WordDelims, S[I]) do
Inc(I)
else
Pos := I;
Result := True;
end;
end;
function ExtractWordS(N : Cardinal; S, WordDelims : ShortString) : ShortString;
{-Given an array of word delimiters, return the N'th word in a string.}
var
I : Cardinal;
Len : Byte;
SLen : Byte absolute S;
begin
Len := 0;
if WordPositionS(N, S, WordDelims, I) then
{find the end of the current word}
while (I <= SLen) and not CharExistsS(WordDelims, S[I]) do begin
{add the I'th character to result}
Inc(Len);
Result[Len] := S[I];
Inc(I);
end;
Result[0] := Char(Len);
end;
function WinExecAndWait32(FileName : PChar; CommandLine : PChar;
Visibility : Integer) : Integer;
{ returns -1 if the Exec failed, otherwise returns the process' exit
code when the process terminates }
var
zAppName:array[0..512] of char;
zCurDir:array[0..255] of char;
WorkDir:ShortString;
StartupInfo:TStartupInfo;
ProcessInfo:TProcessInformation;
Temp : DWORD;
begin
StrCopy(zAppName, FileName);
StrCat(zAppName, CommandLine);
GetDir(0, WorkDir);
StrPCopy(zCurDir, WorkDir);
FillChar(StartupInfo, Sizeof(StartupInfo),#0);
StartupInfo.cb := Sizeof(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := Visibility;
if not CreateProcess(nil,
zAppName, { pointer to command line string }
nil, { pointer to process security attributes }
nil, { pointer to thread security attributes }
false, { handle inheritance flag }
CREATE_NEW_CONSOLE or { creation flags }
NORMAL_PRIORITY_CLASS,
nil, { pointer to new environment block }
nil, { pointer to current directory name }
StartupInfo, { pointer to STARTUPINFO }
ProcessInfo) then { pointer to PROCESS_INF }
Result := -1
else begin
WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
GetExitCodeProcess(ProcessInfo.hProcess,Temp);
Result := Integer(Temp);
end;
end;
function FindTextInSection (var F : Text; TextToFind : PChar;
SectionToSearch : PChar) : ShortString;
var
Buf : array[0..255] of Char;
GotSec : Boolean;
FoundText : Boolean;
begin
Result := '';
GotSec := False;
FoundText := False;
TextToFind := StrUpper(TextToFind);
SectionToSearch := StrUpper(SectionToSearch);
Reset(F);
while (not GotSec) and (not eof(F)) do begin
Readln(F, Buf);
GotSec := (StrPos(StrUpper(Buf), SectionToSearch) <> nil);
end;
while (not FoundText) and GotSec do begin
Readln(F, Buf);
FoundText := (StrPos(StrUpper(Buf), TextToFind) <> nil);
{ did we start a new section? }
if (Buf[0] = '[') and (Buf[pred(StrLen(Buf))] = ']') then
GotSec := False;
end;
if FoundText then
Result := StrPas(Buf);
end;
function UniDrvFilesExist : Boolean;
var
StBuf1 : array[0..255] of Char;
StBuf2 : array[0..255] of Char;
var
SysDir : array[0..255] of Char;
begin
UniDrvFilesExist := False;
{ get the Windows system directory }
if (GetSystemDirectory(SysDir, sizeof(SysDir)) = 0) then begin
MessageBox(0, 'Couldn''t determine Windows\System directory', 'Error', MB_ICONEXCLAMATION);
Exit;
end;
StrCopy(StBuf1, SysDir);
AddBackSlashZ(StBuf1, StBuf1);
StrCopy(StBuf2, StBuf1);
StrCat(StBuf1, 'unidrv.dll');
StrCat(StBuf2, 'unidrv.hlp');
UniDrvFilesExist := ExistFileZ(StBuf1) and ExistFileZ(StBuf2);
end;
function InstallUniDrvFiles : Integer;
type
PLocals = ^TLocals;
TLocals = record
InfTextFile : TextFile;
InfBuf : TFileBuf;
InfIniFile : TIniFile;
DiskList : TStringList;
WinOther : TStringList;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -