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

📄 covertfuncs.pas

📁 用于CD/DVD烧录的Delphi源码,包括source和demo
💻 PAS
📖 第 1 页 / 共 2 页
字号:

function ConvertDataBlock(DataBlock: Integer): Integer;
var
  DataSize: Integer;
begin
  DataSize := 2048;
  case DataBlock of
    $00: DataSize := 2352;
    $01: DataSize := 2368;
    $02: DataSize := 2448;
    $03: DataSize := 2448;
    $08: DataSize := 2048;
    $09: DataSize := 2336;
    $0A: DataSize := 2048;
    $0B: DataSize := 2056;
    $0C: DataSize := 2324;
    $0D: DataSize := 2324;
  end;
  result := DataSize;
end;

{   btRAW_DATA_BLOCK = $00,
    btRAW_DATA_P_Q_SUB = $01,
    btRAW_DATA_P_W_SUB = $02,
    btRAW_DATA_P_W_SUB2 = $03,
    btMODE_1 = $08,
    btMODE_2 = $09,
    btMODE_2_XA_FORM_1 = $0A,
    btMODE_2_XA_FORM_1_SUB = $0B,
    btMODE_2_XA_FORM_2 = $0C,
    btMODE_2_XA_FORM_2_SUB = $0D }

function GetFileSize(const FileName: string): LongInt;
var
  SearchRec: TSearchRec;
begin
  try
    if FindFirst(ExpandFileName(FileName), faAnyFile, SearchRec) = 0 then
    begin
      Result := SearchRec.Size;
    end
    else
      Result := -1;
  finally
    SysUtils.FindClose(SearchRec);
  end;
end;




function IntToMB(const ASize: Int64): string;
begin
  Result := IntToStr(ASize div 1024 div 1024);
end;

function VolumeDateTimeToStr(const VDT: TVolumeDateTime): string;
begin
  Result := string(VDT.Day) + '.' + string(VDT.Month) + '.' +
    string(VDT.Year) + ' ' + string(VDT.Hour) + ':' +
    string(VDT.Minute) + ':' + string(VDT.Second) + '.' +
    string(VDT.MSeconds) + ' ' + IntToStr(VDT.GMTOffset * 15) + ' min from GMT';
end;

function ArrOfChar(AStr: string): TCharArr;
var
  j: integer;
begin
  SetLength(Result, Length(AStr));
  for j := 0 to Length(AStr) - 1 do
    Result[j] := AStr[j + 1];
end;

function SwapWord(const AValue: Word): Word;
begin
  Result := ((AValue shl 8) and $FF00) or ((AValue shr 8) and $00FF);
end;

function SwapDWord(const AValue: LongWord): LongWord;
begin
  Result := ((AValue shl 24) and $FF000000) or
    ((AValue shl 8) and $00FF0000) or
    ((AValue shr 8) and $0000FF00) or
    ((AValue shr 24) and $000000FF);
end;

function BuildBothEndianWord(const AValue: Word): TBothEndianWord;
begin
  Result.LittleEndian := AValue;
  Result.BigEndian := SwapWord(AValue);
end;

function BuildBothEndianDWord(const AValue: LongWord): TBothEndianDWord;
begin
  Result.LittleEndian := AValue;
  Result.BigEndian := SwapDWord(AValue);
end;

function BuildVolumeDateTime(const ADateTime: TDateTime; const AGMTOffset:
  Byte): TVolumeDateTime;
var
  Hour, Min, Sec, MSec,
    Year, Month, Day: Word;
  s: string;
begin
  DecodeTime(ADateTime, Hour, Min, Sec, MSec);
  DecodeDate(ADateTime, Year, Month, Day);
  Result.GMTOffset := AGMTOffset;
  s := IntToStr(Hour);
  StrPCopy(Result.Hour, s);
  s := IntToStr(Min);
  StrPCopy(Result.Minute, s);
  s := IntToStr(Sec);
  StrPCopy(Result.Second, s);
  s := IntToStr(MSec);
  StrPCopy(Result.MSeconds, s);
  s := IntToStr(Year);
  StrPCopy(Result.Year, s);
  s := IntToStr(Month);
  StrPCopy(Result.Month, s);
  s := IntToStr(Day);
  StrPCopy(Result.Day, s);
end;

function BuildDirectoryDateTime(const ADateTime: TDateTime; const AGMTOffset:
  Byte): TDirectoryDateTime;
var
  Hour, Min, Sec, MSec,
    Year, Month, Day: Word;
begin
  DecodeTime(ADateTime, Hour, Min, Sec, MSec);
  DecodeDate(ADateTime, Year, Month, Day);
  Result.GMTOffset := AGMTOffset;
  Result.Hour := Hour;
  Result.Minute := Min;
  Result.Second := Sec;
  Result.Year := Year;
  Result.Month := Month;
  Result.Day := Day;
end;

function RetrieveFileSize(const AFileName: string): LongWord;
var
  SR: TSearchRec;
begin
  Result := 0;
  if (FileExists(AFileName)) and
    (FindFirst(AFileName, faAnyFile, SR) = 0) then
  begin
    if ((SR.Attr and faDirectory) = 0) and
      ((SR.Attr and faVolumeID) = 0) then
      Result := SR.Size;
      FindClose(sr);
  end;
end;

function Sgn(X: Extended): Integer;
begin
  if X < 0 then
    Result := -1
  else if X = 0 then
    Result := 0
  else
    Result := 1;
end;

function RoundUp(X: Extended): Integer;
var
  Temp: Extended;
begin
  Temp := Int(X) + Sgn(Frac(X));
  Result := round(Temp);
end;

function IsAdministrator: Boolean;
var
  hAccessToken: THandle;
  ptgGroups: PTokenGroups;
  dwInfoBufferSize: DWORD;
  psidAdministrators: PSID;
  x: Integer;
  bSuccess: BOOL;
begin
  Result := False;
  bSuccess := OpenThreadToken(GetCurrentThread, TOKEN_QUERY, True,
    hAccessToken);
  if not bSuccess then
  begin
    if GetLastError = ERROR_NO_TOKEN then
      bSuccess := OpenProcessToken(GetCurrentProcess, TOKEN_QUERY,
        hAccessToken);
  end;
  if bSuccess then
  begin
    GetMem(ptgGroups, 1024);
    bSuccess := GetTokenInformation(hAccessToken, TokenGroups,
      ptgGroups, 1024, dwInfoBufferSize);
    CloseHandle(hAccessToken);
    if bSuccess then
    begin
      AllocateAndInitializeSid(SECURITY_NT_AUTHORITY, 2,
        SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,
        0, 0, 0, 0, 0, 0, psidAdministrators);
{$R-}
      for x := 0 to ptgGroups.GroupCount - 1 do
        if EqualSid(psidAdministrators, ptgGroups.Groups[x].Sid) then
        begin
          Result := True;
          Break;
        end;
{$R+}
      FreeSid(psidAdministrators);
    end;
    FreeMem(ptgGroups);
  end;
end;

function Endian(const Source; var Destination; const Count: Integer): Boolean;
var
  PSource, PDestination: PChar;
  I: Integer;
begin
  Result := False;
  PSource := @Source;
  PDestination := PChar(@Destination) + Count;
  for i := 0 to Count - 1 do
  begin
    Dec(PDestination);
    pDestination^ := PSource^;
    Inc(PSource);
    Result := True;
  end;
end;

function EndianToIntelBytes(const AValue: array of Byte; Count: Byte): Integer;
var
  I: Integer;
begin
  Result := 0;
  for I := 0 to Count - 1 do
  begin
    Result := (AValue[I] shl ((Count - (I + 1)) * 8) or Result);
  end;
end;

function GetLBA(const Byte1, Byte2, Byte3, Byte4: Byte): LongWord;
begin
  Result := (Byte1 shl 24) or (Byte2 shl 16) or (Byte3 shl 8) or Byte4;
end;

function HMSFtoLBA(const AHour, AMinute, ASecond, AFrame: Byte): LongWord;
begin
  Result := (AHour * 60 * 60 * 75) + (AMinute * 60 * 75) + (ASecond * 75) + AFrame;
end;


function LBA2HMSF(LBA: Integer): string;
var
  M, S, F: Integer;
begin
  F := (LBA mod 75);
  S := (LBA div 75) mod 60;
  M := (LBA div 75) div 60;
  Result := Format('%02.02d:%02.02d:%02.02d', [m, s, f])
end;


Procedure LBA2MSF(Const LBA: Integer; Var Min, Sec, Frame :Integer);
begin
  Frame := (LBA mod 75);
  Sec := (LBA div 75) mod 60;
  Min := (LBA div 75) div 60;
end;


function LBA2PreCDDB(LBA: Integer): Integer;
var
  M, S, Start: Integer;
begin
  Start := 150 + LBA;
  S := (Start div 75) mod 60;
  M := (Start div 75) div 60;
  Result := ((M * 60) + S);
end;


function TimePos2SectorPos(Min, Sec, Frame : longint) : longint;
begin
    Result := longint(Min) * 4500 + Longint(Sec) * 75 + Frame - 150;
end;


function SectorPos2TimePos(SectorPos : longint) : longint;
var
    Min, Sec, Frame : longint;
begin
    Frame := SectorPos mod 75;
    Sec   := ((SectorPos + 150) div 75) mod 60;
    Min   := (SectorPos + 150) div 4500;
    Result := (Min shl 16) + (Sec shl 8) + Frame;
end;

function HiWord(Lx: LongWord): Word;
begin
  Result := (Lx shr 16) and $FFFF;
end;

function LoWord(Lx: LongWord): Word;
begin
  Result := Lx;
end;

function HiByte(Lx: Word): Byte;
begin
  Result := (Lx shr 8) and $FF;
end;

function LoByte(Lx: Word): Byte;
begin
  Result := Lx and $FF;
end;

function IsBitSet(const Value: LongWord; const Bit: Byte): Boolean;
begin
  Result := (Value and (1 shl Bit)) <> 0;
end;

function BitOn(const Value: LongWord; const Bit: Byte): LongWord;
begin
  Result := Value or (1 shl Bit);
end;

function BitOff(const Value: LongWord; const Bit: Byte): LongWord;
begin
  Result := Value and ((1 shl Bit) xor $FFFFFFFF);
end;

function BitToggle(const Value: LongWord; const Bit: Byte): LongWord;
begin
  Result := Value xor (1 shl Bit);
end;

function ByteToBin(Value: Byte): string;
var
  I: Integer;
begin
  Result := StringOfChar('0', 8);

  for I := 0 to 7 do
  begin
    if (Value mod 2) = 1 then
      Result[8 - i] := '1';

    Value := Value div 2;
  end;
end;

function GetShortFilename(const FileName: TFileName): TFileName;
var
  buffer: array[0..MAX_PATH - 1] of char;
begin
  SetString(Result, buffer, GetShortPathName(pchar(FileName), buffer, MAX_PATH -
    1));
end;

function GetISOFilename(const FileName: string): string;
var
  TempRes: string;
  Ext: string;
begin
  if length(Filename) > 12 then
  begin
    Ext := extractfileext(Filename);
    TempRes := copy(Filename, 1, 6);
    TempRes := TempRes + '~1' + Ext + ';1';
  end
  else
    TempRes := Filename;
  Result := UpperCase(TempRes);
end;

function CDDB_Sum(N: Integer): Integer;
var
  Ret: Integer;
begin
  Ret := 0;
  while (N > 0) do
  begin
    Ret := Ret + (N mod 10);
    N := N div 10;
  end;
  Result := Ret;
end;

end.

⌨️ 快捷键说明

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