converter: unicode file names

git-svn-id: trunk@46826 -
This commit is contained in:
mattias 2014-11-12 19:27:26 +00:00
parent 2fd3d1310c
commit 3ee0203df5
3 changed files with 47 additions and 12 deletions

View File

@ -31,6 +31,14 @@ type
procedure SaveToFile(const FileName: string); override; procedure SaveToFile(const FileName: string); override;
end; end;
{ TMemoryStreamUTF8 }
TMemoryStreamUTF8 = class(TMemoryStream)
public
procedure LoadFromFile(const FileName: string);
procedure SaveToFile(const FileName: string);
end;
procedure LoadStringsFromFileUTF8(List: TStrings; const FileName: string); procedure LoadStringsFromFileUTF8(List: TStrings; const FileName: string);
procedure SaveStringsToFileUTF8(List: TStrings; const FileName: string); procedure SaveStringsToFileUTF8(List: TStrings; const FileName: string);
@ -83,6 +91,32 @@ begin
Result:=CompareStr(UTF8LowerCase(List[Index1]),UTF8LowerCase(List[Index2])); Result:=CompareStr(UTF8LowerCase(List[Index1]),UTF8LowerCase(List[Index2]));
end; end;
{ TMemoryStreamUTF8 }
procedure TMemoryStreamUTF8.LoadFromFile(const FileName: string);
var
S: TFileStreamUTF8;
begin
S:=TFileStreamUTF8.Create (FileName,fmOpenRead or fmShareDenyWrite);
Try
LoadFromStream(S);
finally
S.free;
end;
end;
procedure TMemoryStreamUTF8.SaveToFile(const FileName: string);
var
S: TFileStreamUTF8;
begin
S:=TFileStreamUTF8.Create (FileName,fmCreate);
Try
SaveToStream(S);
finally
S.free;
end;
end;
constructor TFileStreamUTF8.Create(const AFileName: utf8string; Mode: Word); constructor TFileStreamUTF8.Create(const AFileName: utf8string; Mode: Word);
begin begin
Create(AFileName,Mode,438); Create(AFileName,Mode,438);

View File

@ -34,7 +34,7 @@ interface
uses uses
// LCL+FCL // LCL+FCL
Classes, SysUtils, LCLProc, Forms, Controls, Dialogs, LConvEncoding, Classes, SysUtils, LCLProc, Forms, Controls, Dialogs, LConvEncoding,
FileUtil, LazFileUtils, contnrs, IniFiles, FileUtil, LazFileUtils, LazUTF8Classes, contnrs, IniFiles,
// codetools // codetools
CodeToolManager, DefineTemplates, CodeCache, LinkScanner, FileProcs, CodeToolsStructs, CodeToolManager, DefineTemplates, CodeCache, LinkScanner, FileProcs, CodeToolsStructs,
// IDEIntf // IDEIntf
@ -1234,15 +1234,15 @@ end;
function TConvertDelphiProjPack.ExtractOptionsFromCFG(const CFGFilename: string): TModalResult; function TConvertDelphiProjPack.ExtractOptionsFromCFG(const CFGFilename: string): TModalResult;
var var
sl: TStringList; sl: TStringListUTF8;
i: Integer; i: Integer;
Line, s: string; Line, s: string;
c: char; c: char;
begin begin
try try
sl:=TStringList.Create; sl:=TStringListUTF8.Create;
try try
sl.LoadFromFile(UTF8ToSys(CFGFilename)); sl.LoadFromFile(CFGFilename);
for i:=0 to sl.Count-1 do begin for i:=0 to sl.Count-1 do begin
Line:=sl[i]; Line:=sl[i];
if Line='' then continue; if Line='' then continue;

View File

@ -33,8 +33,9 @@ interface
uses uses
// FCL+LCL // FCL+LCL
Classes, SysUtils, Math, LCLProc, Forms, Controls, Grids, LResources, LConvEncoding, Classes, SysUtils, Math, LCLProc, Forms, Controls, Grids, LResources,
Graphics, Dialogs, Buttons, StdCtrls, ExtCtrls, contnrs, FileUtil, LCLType, LConvEncoding, Graphics, Dialogs, Buttons, StdCtrls, ExtCtrls, contnrs,
FileUtil, LazUTF8Classes, LCLType,
// components // components
SynHighlighterLFM, SynEdit, SynEditMiscClasses, LFMTrees, SynHighlighterLFM, SynEdit, SynEditMiscClasses, LFMTrees,
// codetools // codetools
@ -281,16 +282,16 @@ end;
function TDFMConverter.ConvertDfmToLfm(const aFilename: string): TModalResult; function TDFMConverter.ConvertDfmToLfm(const aFilename: string): TModalResult;
var var
DFMStream, LFMStream, Utf8LFMStream: TMemoryStream; DFMStream, LFMStream, Utf8LFMStream: TMemoryStreamUTF8;
begin begin
Result:=mrOk; Result:=mrOk;
DFMStream:=TMemoryStream.Create; DFMStream:=TMemoryStreamUTF8.Create;
LFMStream:=TMemoryStream.Create; LFMStream:=TMemoryStreamUTF8.Create;
Utf8LFMStream:=TMemoryStream.Create; Utf8LFMStream:=TMemoryStreamUTF8.Create;
try try
// Note: The file is copied from DFM file earlier. Load it. // Note: The file is copied from DFM file earlier. Load it.
try try
DFMStream.LoadFromFile(UTF8ToSys(aFilename)); DFMStream.LoadFromFile(aFilename);
except except
on E: Exception do begin on E: Exception do begin
Result:=QuestionDlg(lisCodeToolsDefsReadError, Format( Result:=QuestionDlg(lisCodeToolsDefsReadError, Format(
@ -319,7 +320,7 @@ begin
FixWideString(LFMStream, Utf8LFMStream); FixWideString(LFMStream, Utf8LFMStream);
// Save the converted file. // Save the converted file.
try try
Utf8LFMStream.SaveToFile(UTF8ToSys(aFilename)); Utf8LFMStream.SaveToFile(aFilename);
except except
on E: Exception do begin on E: Exception do begin
Result:=MessageDlg(lisCodeToolsDefsWriteError, Result:=MessageDlg(lisCodeToolsDefsWriteError,