ADD: Some code for Unicode support

This commit is contained in:
Alexander Koblov 2008-05-24 05:47:51 +00:00
commit 4e62334588
4 changed files with 40 additions and 39 deletions

View file

@ -13,7 +13,7 @@ procedure LoadPaths;
implementation
uses
LCLProc, SysUtils, IniFiles;
LCLProc, SysUtils, uClassesEx, uOSUtils;
function GetAppName : String;
begin
@ -22,14 +22,14 @@ end;
procedure LoadPaths;
var
Ini : TIniFile;
Ini : TIniFileEx;
begin
gpExePath := ExtractFilePath(ParamStr(0));
DebugLn('Executable directory: ', gpExePath);
gpCfgDir := gpExePath;
Ini := TIniFile.Create(gpCfgDir + 'doublecmd.ini');
Ini := TIniFileEx.Create(gpCfgDir + 'doublecmd.ini');
if Ini.ReadInteger('Configuration', 'UseIniInProgramDir', 1) = 1 then // use ini file from program dir
begin
gpIniDir := gpCfgDir;
@ -37,11 +37,12 @@ begin
else
begin
OnGetApplicationName := @GetAppName;
gpIniDir := GetAppConfigDir(False);
if not DirectoryExists(gpIniDir) then
gpIniDir := GetAppConfigDir;
if not mbDirectoryExists(gpIniDir) then
ForceDirectories(gpIniDir);
OnGetApplicationName := nil;
gpIniDir := IncludeTrailingPathDelimiter(gpIniDir); // add if need path delimiter
DebugLn('Configuration directory: ', gpIniDir);
end;
Ini.Free;

View file

@ -130,7 +130,7 @@ type
implementation
uses
LCLProc, SysUtils, uLog;
LCLProc, SysUtils, uLog, uClassesEx;
constructor TExtAction.Create;
begin
@ -150,12 +150,12 @@ end;
procedure TExts.LoadFromFile(const sName:String);
var
extFile: TStringList;
extFile: TStringListEx;
sLine, s, sExt: String;
extcmd: TExtAction;
I, iIndex: Integer;
begin
extFile:= TStringList.Create;
extFile:= TStringListEx.Create;
extFile.LoadFromFile(sName);
extcmd:=nil;
for I:= 0 to extFile.Count - 1 do
@ -258,13 +258,13 @@ var
I, J, iIndex,
iCount,
iBegin, iEnd : Integer;
extFile : TStringList;
extFile : TStringListEx;
sLine,
sNewName,
sSectionName: String;
bExists : Boolean;
begin
extFile:= TStringList.Create;
extFile:= TStringListEx.Create;
if FileExists(sName) then
begin

View file

@ -50,7 +50,7 @@ procedure FileWriteLn(hFile: Integer; S: String);
implementation
uses
LCLProc, SysUtils, uGlobs, uShowMsg, Classes, uLng, uDCUtils, uFindEx, uOSUtils;
LCLProc, SysUtils, uGlobs, uShowMsg, Classes, uClassesEx, uLng, uDCUtils, uFindEx, uOSUtils;
const
cBlockSize=16384; // size of block if copyfile
@ -59,27 +59,27 @@ const
function CopyFile(const sSrc, sDst:String; bAppend:Boolean):Boolean;
var
src, dst:TFileStream;
src, dst:TFileStreamEx;
stat:stat64;
iDstBeg:Integer; // in the append mode we store original size
Buffer: PChar;
begin
Result:=False;
if not FileExists(sSrc) then Exit;
if not mbFileExists(sSrc) then Exit;
dst:=nil; // for safety exception handling
GetMem(Buffer,cBlockSize+1);
try
try
src:=TFileStream.Create(sSrc,fmOpenRead or fmShareDenyNone);
src:=TFileStreamEx.Create(sSrc,fmOpenRead or fmShareDenyNone);
if bAppend then
begin
dst:=TFileStream.Create(sDst,fmOpenReadWrite);
dst:=TFileStreamEx.Create(sDst,fmOpenReadWrite);
dst.Seek(0,soFromEnd); // seek to end
end
else
dst:=TFileStream.Create(sDst,fmCreate);
dst:=TFileStreamEx.Create(sDst,fmCreate);
iDstBeg:=dst.Size;
// we dont't use CopyFrom, because it's alocate and free buffer every time is called
while (dst.Size+cBlockSize)<= (src.Size+iDstBeg) do

View file

@ -22,7 +22,7 @@ unit uGlobs;
interface
uses
Classes, Controls, uExts, uColorExt, Graphics, IniFiles, uWDXModule, uColumns;
Classes, Controls, uExts, uColorExt, Graphics, uClassesEx, uWDXModule, uColumns;
type
TControlPosition = object
@ -80,9 +80,9 @@ var
gMouseSelectionEnabled: Boolean = True;
gMouseSelectionButton: Integer = 0;
glsHotDir:TStringList;
glsDirHistory:TStringList;
glsMaskHistory : TStringList;
glsHotDir:TStringListEx;
glsDirHistory:TStringListEx;
glsMaskHistory : TStringListEx;
gCutTextToColWidth : Boolean;
gScrollMode: Integer;
@ -173,7 +173,7 @@ const
function LoadGlobs : Boolean;
procedure SaveGlobs;
function LoadStringsFromFile(var list:TStringList; const sFileName:String):boolean;
function LoadStringsFromFile(var list:TStringListEx; const sFileName:String):boolean;
procedure ResizeToScreen(Control:TControl; Width:integer=1024; Height:integer=768);
@ -184,7 +184,7 @@ const
cMaxStringItems=50;
var
gIni:TIniFile = nil;
gIni:TIniFileEx = nil;
implementation
uses
@ -258,36 +258,36 @@ end;
procedure InitGlobs;
begin
{ Load location of configuration files }
gIni := TIniFile.Create(gpCfgDir + 'doublecmd.ini');
gIni := TIniFileEx.Create(gpCfgDir + 'doublecmd.ini');
gUseIniInProgramDir := gIni.ReadBool('Configuration', 'UseIniInProgramDir', True);
gIni.Free;
{ Create default configuration files if need }
// main ini file
if not FileExists(gpIniDir + 'doublecmd.ini') then
if not mbFileExists(gpIniDir + 'doublecmd.ini') then
CopyFile(gpCfgDir + 'doublecmd.ini', gpIniDir + 'doublecmd.ini');
// toolbar file
if not FileExists(gpIniDir + 'default.bar') then
if not mbFileExists(gpIniDir + 'default.bar') then
CopyFile(gpCfgDir + 'default.bar', gpIniDir + 'default.bar');
// extension file
if not FileExists(gpIniDir + 'doublecmd.ext') then
if not mbFileExists(gpIniDir + 'doublecmd.ext') then
CopyFile(gpCfgDir + 'doublecmd.ext', gpIniDir + 'doublecmd.ext');
// pixmaps file
if not FileExists(gpIniDir + 'pixmaps.txt') then
if not mbFileExists(gpIniDir + 'pixmaps.txt') then
CopyFile(gpCfgDir + 'pixmaps.txt', gpIniDir + 'pixmaps.txt');
// editor highlight file1
if not FileExists(gpIniDir + 'editor.col') then
if not mbFileExists(gpIniDir + 'editor.col') then
CopyFile(gpCfgDir + 'editor.col', gpIniDir + 'editor.col');
// editor highlight file2
if not FileExists(gpIniDir + 'twilight.col') then
if not mbFileExists(gpIniDir + 'twilight.col') then
CopyFile(gpCfgDir + 'twilight.col', gpIniDir + 'twilight.col');
gIni := TIniFile.Create(gpIniDir + 'doublecmd.ini');
gIni := TIniFileEx.Create(gpIniDir + 'doublecmd.ini');
gExts := TExts.Create;
gColorExt := TColorExt.Create;
glsHotDir := TStringList.Create;
glsDirHistory := TStringList.Create;
glsMaskHistory := TStringList.Create;
glsHotDir := TStringListEx.Create;
glsDirHistory := TStringListEx.Create;
glsMaskHistory := TStringListEx.Create;
//---------------------
WdxPlugins:=TWDXModuleList.Create;
WdxPlugins.Load(gIni);
@ -316,7 +316,7 @@ begin
ColSet.Free;
{ Save location of configuration files }
gIni := TIniFile.Create(gpCfgDir + 'doublecmd.ini');
gIni := TIniFileEx.Create(gpCfgDir + 'doublecmd.ini');
gIni.WriteBool('Configuration', 'UseIniInProgramDir', gUseIniInProgramDir);
gIni.Free;
@ -416,13 +416,13 @@ begin
gCutTextToColWidth := gIni.ReadBool('Configuration', 'CutTextToColWidth', False);
if FileExists(gpIniDir + 'doublecmd.ext') then
if mbFileExists(gpIniDir + 'doublecmd.ext') then
gExts.LoadFromFile(gpIniDir + 'doublecmd.ext');
if FileExists(gpIniDir + 'dirhistory.txt') then
if mbFileExists(gpIniDir + 'dirhistory.txt') then
LoadStringsFromFile(glsDirHistory,gpIniDir + 'dirhistory.txt');
if FileExists(gpIniDir + 'maskhistory.txt') then
if mbFileExists(gpIniDir + 'maskhistory.txt') then
LoadStringsFromFile(glsMaskHistory, gpIniDir + 'maskhistory.txt');
gColorExt.Load;
@ -438,14 +438,14 @@ begin
Result := True;
end;
function LoadStringsFromFile(var list:TStringList; const sFileName:String):boolean;
function LoadStringsFromFile(var list:TStringListEx; const sFileName:String):boolean;
var
i:Integer;
begin
Assert(list <> nil,'LoadStringsFromFile: list=nil');
list.Clear;
Result:=False;
if not FileExists(sFileName) then Exit;
if not mbFileExists(sFileName) then Exit;
list.LoadFromFile(sFileName);
for i:=list.Count-1 downto 0 do
if i>cMaxStringItems then