codetools now saves files keeping the file case on disk

git-svn-id: trunk@7747 -
This commit is contained in:
mattias 2005-09-19 21:57:39 +00:00
parent 122df55eae
commit f2b6a4f242
5 changed files with 168 additions and 2 deletions

View File

@ -82,6 +82,7 @@ function FilenameIsMatching(const Mask, Filename: string;
MatchExactly: boolean): boolean;
function ClearFile(const Filename: string; RaiseOnError: boolean): boolean;
function GetTempFilename(const Path, Prefix: string): string;
function FindDiskFilename(const Filename: string): string;
type
TCTPascalExtType = (petNone, petPAS, petPP, petP);
@ -286,6 +287,83 @@ begin
until false;
end;
function FindDiskFilename(const Filename: string): string;
// Searches for the filename case on disk.
// The file must exist.
// For example:
// If Filename='file' and there is only a 'File' then 'File' will be returned.
var
StartPos: Integer;
EndPos: LongInt;
FileInfo: TSearchRec;
CurDir: String;
CurFile: String;
AliasFile: String;
Ambiguous: Boolean;
begin
Result:=Filename;
if not FileExists(Filename) then exit;
// check every directory and filename
StartPos:=1;
{$IFDEF Win32}
// uppercase Drive letter and skip it
if ((length(Result)>=2) and (Result[1] in ['A'..'Z','a'..'z'])
and (Result[2]=':')) then begin
StartPos:=3;
if Result[1] in ['a'..'z'] then
Result[1]:=upcase(Result[1]);
end;
{$ENDIF}
repeat
// skip PathDelim
while (StartPos<=length(Result)) and (Result[StartPos]=PathDelim) do
inc(StartPos);
// find end of filename part
EndPos:=StartPos;
while (EndPos<=length(Result)) and (Result[EndPos]<>PathDelim) do
inc(EndPos);
if EndPos>StartPos then begin
// search file
CurDir:=copy(Result,1,StartPos-1);
CurFile:=copy(Result,StartPos,EndPos-StartPos);
AliasFile:='';
Ambiguous:=false;
if SysUtils.FindFirst(CurDir+FileMask,faAnyFile,FileInfo)=0 then
begin
repeat
// check if special file
if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='')
then
continue;
if CompareText(FileInfo.Name,CurFile)=0 then begin
//writeln('FindDiskFilename ',FileInfo.Name,' ',CurFile);
if FileInfo.Name=CurFile then begin
// file found, has already the correct name
AliasFile:='';
break;
end else begin
// alias found, but has not the correct name
if AliasFile='' then begin
AliasFile:=FileInfo.Name;
end else begin
// there are more than one candidate
Ambiguous:=true;
break;
end;
end;
end;
until SysUtils.FindNext(FileInfo)<>0;
end;
SysUtils.FindClose(FileInfo);
if (AliasFile<>'') and (not Ambiguous) then begin
// better filename found -> replace
Result:=CurDir+AliasFile+copy(Result,EndPos,length(Result));
end;
end;
StartPos:=EndPos+1;
until StartPos>length(Result);
end;
function CompareFilenames(const Filename1, Filename2: string): integer;
begin
{$IFDEF WIN32}

View File

@ -665,12 +665,15 @@ end;
function TSourceLog.SaveToFile(const Filename: string): boolean;
var
fs: TFileStream;
TheFilename: String;
begin
//DebugLn('TSourceLog.SaveToFile Self=',DbgS(Self));
Result:=true;
try
InvalidateFileStateCache;
fs:=TFileStream.Create(Filename, fmCreate);
// keep filename case on disk
TheFilename:=FindDiskFilename(Filename);
fs:=TFileStream.Create(TheFilename, fmCreate);
try
if fSrcLen>0 then
fs.Write(FSource[1],length(FSource));

View File

@ -5317,6 +5317,7 @@ var
OtherUnitIndex: Integer;
FilenameNoPath: String;
LoadBufferFlags: TLoadBufferFlags;
DiskFilename: String;
begin
{$IFDEF IDE_VERBOSE}
writeln('');
@ -5333,6 +5334,12 @@ begin
// normalize filename
AFilename:=TrimFilename(AFilename);
DiskFilename:=FindDiskFilename(AFilename);
if DiskFilename<>AFilename then begin
debugln('WARNING: TMainIDE.DoOpenEditorFile Opening "',DiskFilename,'" instead "',DiskFilename,'"');
AFilename:=DiskFilename;
end;
FilenameNoPath:=ExtractFilename(AFilename);
// check to not open directories

View File

@ -82,11 +82,12 @@ type
);
TSearchFileInPathFlags = set of TSearchFileInPathFlag;
function GetAllFilesMask: string;
function SearchFileInPath(const Filename, BasePath, SearchPath,
Delimiter: string; Flags: TSearchFileInPathFlags): string;
function SearchAllFilesInPath(const Filename, BasePath, SearchPath,
Delimiter: string; Flags: TSearchFileInPathFlags): TStrings;
function GetAllFilesMask: string;
function FindDiskFilename(const Filename: string): string;
// file actions
function ReadFileToString(const Filename: string): string;

View File

@ -1121,6 +1121,83 @@ begin
end;
end;
function FindDiskFilename(const Filename: string): string;
// Searches for the filename case on disk.
// The file must exist.
// For example:
// If Filename='file' and there is only a 'File' then 'File' will be returned.
var
StartPos: Integer;
EndPos: LongInt;
FileInfo: TSearchRec;
CurDir: String;
CurFile: String;
AliasFile: String;
Ambiguous: Boolean;
begin
Result:=Filename;
if not FileExists(Filename) then exit;
// check every directory and filename
StartPos:=1;
{$IFDEF Win32}
// uppercase Drive letter and skip it
if ((length(Result)>=2) and (Result[1] in ['A'..'Z','a'..'z'])
and (Result[2]=':')) then begin
StartPos:=3;
if Result[1] in ['a'..'z'] then
Result[1]:=upcase(Result[1]);
end;
{$ENDIF}
repeat
// skip PathDelim
while (StartPos<=length(Result)) and (Result[StartPos]=PathDelim) do
inc(StartPos);
// find end of filename part
EndPos:=StartPos;
while (EndPos<=length(Result)) and (Result[EndPos]<>PathDelim) do
inc(EndPos);
if EndPos>StartPos then begin
// search file
CurDir:=copy(Result,1,StartPos-1);
CurFile:=copy(Result,StartPos,EndPos-StartPos);
AliasFile:='';
Ambiguous:=false;
if SysUtils.FindFirst(CurDir+GetAllFilesMask,faAnyFile,FileInfo)=0 then
begin
repeat
// check if special file
if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='')
then
continue;
if CompareText(FileInfo.Name,CurFile)=0 then begin
//writeln('FindDiskFilename ',FileInfo.Name,' ',CurFile);
if FileInfo.Name=CurFile then begin
// file found, has already the correct name
AliasFile:='';
break;
end else begin
// alias found, but has not the correct name
if AliasFile='' then begin
AliasFile:=FileInfo.Name;
end else begin
// there are more than one candidate
Ambiguous:=true;
break;
end;
end;
end;
until SysUtils.FindNext(FileInfo)<>0;
end;
SysUtils.FindClose(FileInfo);
if (AliasFile<>'') and (not Ambiguous) then begin
// better filename found -> replace
Result:=CurDir+AliasFile+copy(Result,EndPos,length(Result));
end;
end;
StartPos:=EndPos+1;
until StartPos>length(Result);
end;
function GetAllFilesMask: string;
begin
{$IFDEF win32}