Subversion Repositories autosfx

Compare Revisions

Regard whitespace Rev HEAD → Rev 1

/Functions.pas
3,8 → 3,7
interface
 
uses
Forms, Windows, Classes, SysUtils, ShellAPI,
ZipMstr19, ZmUtils19, ShlObj, ActiveX;
Windows, Classes, SysUtils, ShellAPI;
 
type
TLineBreak = (lbWindows, lbLinux, lbMac);
16,11 → 15,7
function GetTempDirectory: String;
function NormalizeLineBreaks(s: string; mode: TLineBreak): string;
function ExtractFileNameWithoutExt(const fil: string): string;
function SearchNextFreeName(s: string; wantDir: boolean): string;
function GetSpecialFolderPath(const Folder: integer): string;
function IsExtractable(AFilename: string): boolean;
function IsDirectoryWritable(const Dir: String): Boolean;
function IsAtFlobbyDisk(AFileOrDir: string): boolean;
function SearchNextFreeName(s: string): string;
 
implementation
 
155,7 → 150,7
result := Copy(ExtractFileName(fil), 1, Length(ExtractFileName(fil))-Length(ExtractFileExt(fil)));
end;
 
function SearchNextFreeName(s: string; wantDir: boolean): string;
function SearchNextFreeName(s: string): string;
var
i: integer;
begin
162,87 → 157,27
if not FileExists(s) and not DirectoryExists(s) then
begin
result := s;
if wantDir then result := IncludeTrailingPathDelimiter(result);
Exit;
end;
 
i := 2;
 
if wantDir then
if FileExists(s) then
begin
s := ExcludeTrailingPathDelimiter(s);
repeat
result := Format('%s (%d)', [s, i]);
result := Format('%s (%d)%s', [ExtractFileNameWithoutExt(s), i, ExtractFileExt(s)]);
inc(i);
until not DirectoryExists(result) and not FileExists(result);
result := IncludeTrailingPathDelimiter(result);
until not DirectoryExists(result);
end
else
else if DirectoryExists(s) then
begin
s := ExcludeTrailingPathDelimiter(s);
repeat
result := Format('%s (%d)%s', [ExtractFilePath(s)+ExtractFileNameWithoutExt(s), i, ExtractFileExt(s)]);
result := Format('%s (%d)', [s, i]);
inc(i);
until not DirectoryExists(result) and not FileExists(result);
until not DirectoryExists(result); // Todo: Legt man sich hier nun auf einen ordnernamen fest???
result := IncludeTrailingPathDelimiter(result);
end;
end;
 
// GetSpecialFolderPath
// Ref: http://www.wer-weiss-was.de/theme159/article1058561.html
function GetSpecialFolderPath(const Folder: integer): string;
var
PIDL: PItemIDList;
Path: array[0..MAX_PATH] of char;
Malloc: IMalloc;
begin
Path := '';
if Succeeded((SHGetSpecialFolderLocation(0, Folder, PIDL))) then
if (SHGetPathFromIDList(PIDL, Path)) then
if Succeeded(ShGetMalloc(Malloc)) then
begin
Malloc.Free(PIDL);
Malloc := nil;
end;
Result := Path;
end;
 
function IsExtractable(AFilename: string): boolean;
var
q: integer;
uz: TZipMaster19;
begin
// TODO: Ist die Funktion gut? Fraglich, ob EOC64 ein Teil von EOC ist.
uz := TZipMaster19.Create(nil);
try
q := uz.QueryZip(AFilename);
result := true;
if (q and zqbHasLocal) <> zqbHasLocal then result := false;
if (q and zqbHasCentral) <> zqbHasCentral then result := false;
if ((q and zqbHasEOC) <> zqbHasEOC) and
((q and zqbHasEOC64) <> zqbHasEOC64) then result := false;
finally
uz.Free;
end;
end;
 
// Ref: http://www.delphiarea.com/articles/how-to-find-if-a-directory-is-writable/
function IsDirectoryWritable(const Dir: String): Boolean;
var
TempFile: array[0..MAX_PATH] of Char;
begin
if GetTempFileName(PChar(Dir), 'DA', 0, TempFile) <> 0 then
Result := Windows.DeleteFile(TempFile)
else
Result := False;
end;
 
function IsAtFlobbyDisk(AFileOrDir: string): boolean;
var
s: string;
begin
s := ExtractFileDrive(AFileOrDir);
s := UpperCase(s);
 
result := (s = 'A:') or (s = 'B:');
end;
 
end.