Reviewed, simplified code.
This commit is contained in:
@@ -1,13 +1,9 @@
|
||||
unit uCommon;
|
||||
unit ucommon;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Windows;
|
||||
|
||||
const
|
||||
cProgramName = 'Tim2View by [Lab 313]';
|
||||
cProgramVersion = '2.0 Release';
|
||||
cProgramName = 'Tim2View r55 by [Lab 313]';
|
||||
cExtractedTimsDir = 'TIMS';
|
||||
cExtractedPngsDir = 'PNGS';
|
||||
cMaxFileSize = $2EAEED80;
|
||||
@@ -29,19 +25,16 @@ type
|
||||
TBytesArray = array [0 .. cMaxFileSize - 1] of byte;
|
||||
PBytesArray = ^TBytesArray;
|
||||
|
||||
function GetFileSizeAPI(const FileName: string): Int64;
|
||||
function CheckFileExists(const FileName: string): boolean;
|
||||
// function cHex2Int( const Value : string) : Integer;
|
||||
function ExtractJustName(const Path: string): string;
|
||||
procedure Text2Clipboard(const S: string);
|
||||
function ExtractJustName(const Path: string): string;
|
||||
function Min(A, B: Integer): Integer;
|
||||
function Max(A, B: Integer): Integer;
|
||||
function GetCoreCount: Integer;
|
||||
function FileSize(const FileName: string): Integer;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
System.SysUtils, Clipbrd;
|
||||
uses sysutils, windows, clipbrd;
|
||||
|
||||
function GetCoreCount: Integer;
|
||||
var
|
||||
@@ -51,6 +44,11 @@ begin
|
||||
Result := SystemInfo.dwNumberOfProcessors;
|
||||
end;
|
||||
|
||||
procedure Text2Clipboard(const S: string);
|
||||
begin
|
||||
Clipboard.AsText := S;
|
||||
end;
|
||||
|
||||
function Min(A, B: Integer): Integer;
|
||||
begin
|
||||
if A < B then
|
||||
@@ -67,61 +65,13 @@ begin
|
||||
Result := B;
|
||||
end;
|
||||
|
||||
procedure Text2Clipboard(const S: string);
|
||||
begin
|
||||
Clipboard.AsText := S;
|
||||
end;
|
||||
|
||||
function ExtractJustName(const Path: string): string;
|
||||
begin
|
||||
Result := ExtractFileName(Path);
|
||||
Result := Copy(Result, 1, Length(Result) - Length(ExtractFileExt(Result)));
|
||||
end;
|
||||
|
||||
function Hex2Int(const Value: string): Integer;
|
||||
var
|
||||
I: Integer;
|
||||
begin
|
||||
Result := 0;
|
||||
I := 1;
|
||||
if Value = '' then
|
||||
Exit; { >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> }
|
||||
if Value[1] = '$' then
|
||||
Inc(I);
|
||||
while I <= Length(Value) do
|
||||
begin
|
||||
if (Value[I] >= '0') and (Value[I] <= '9') then
|
||||
Result := (Result shl 4) or (Ord(Value[I]) - Ord('0'))
|
||||
else if (Value[I] >= 'A') and (Value[I] <= 'F') then
|
||||
Result := (Result shl 4) or (Ord(Value[I]) - Ord('A') + 10)
|
||||
else if (Value[I] >= 'a') and (Value[I] <= 'f') then
|
||||
Result := (Result shl 4) or (Ord(Value[I]) - Ord('a') + 10)
|
||||
else
|
||||
break;
|
||||
Inc(I);
|
||||
end;
|
||||
end;
|
||||
|
||||
function CopyEnd(const S: string; Idx: Integer): string;
|
||||
begin
|
||||
Result := Copy(S, Idx, MaxInt);
|
||||
end;
|
||||
|
||||
function cHex2Int(const Value: string): Integer;
|
||||
begin
|
||||
if (Length(Value) > 2) and (Value[1] = '0') and
|
||||
((Value[2] = 'x') or (Value[2] = 'X')) then
|
||||
Result := Hex2Int(CopyEnd(Value, 3))
|
||||
else
|
||||
Result := Hex2Int(Value);
|
||||
end;
|
||||
|
||||
function CheckFileExists(const FileName: string): boolean;
|
||||
begin
|
||||
Result := FileExists(FileName);
|
||||
end;
|
||||
|
||||
function GetFileSizeAPI(const FileName: string): Int64;
|
||||
function FileSize(const FileName: string): Integer;
|
||||
var
|
||||
FindData: TWin32FindData;
|
||||
hFind: THandle;
|
||||
@@ -134,7 +84,7 @@ begin
|
||||
|
||||
Windows.FindClose(hFind);
|
||||
if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then
|
||||
Result := FindData.nFileSizeLow;
|
||||
Result := Integer(FindData.nFileSizeLow);
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
Reference in New Issue
Block a user