FIX: Don't use UTF8Decode/UTF8Encode functions (fixes #245)

This commit is contained in:
Alexander Koblov 2021-11-08 19:06:53 +03:00
commit c9baafdb36
16 changed files with 96 additions and 77 deletions

View file

@ -1,15 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="10"/>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
<CompatibilityMode Value="True"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="EverythingDsx"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
@ -17,9 +18,6 @@
<i18n>
<EnableI18N LFM="False"/>
</i18n>
<VersionInfo>
<StringTable ProductVersion=""/>
</VersionInfo>
<BuildModes Count="2">
<Item1 Name="Release" Default="True"/>
<Item2 Name="Debug">
@ -68,17 +66,29 @@
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
<HostApplicationFilename Value="R:\Temp\doublecmd\doublecmd.exe"/>
</local>
<FormatVersion Value="2"/>
<Modes Count="1">
<Mode0 Name="default">
<local>
<HostApplicationFilename Value="R:\Temp\doublecmd\doublecmd.exe"/>
</local>
</Mode0>
</Modes>
</RunParams>
<RequiredPackages Count="1">
<Item1>
<PackageName Value="doublecmd_common"/>
</Item1>
</RequiredPackages>
<Units Count="2">
<Unit0>
<Filename Value="EverythingDsx.lpr"/>
<IsPartOfProject Value="True"/>
</Unit0>
<Unit1>
<Filename Value="..\everything.pas"/>
<Filename Value="everything.pas"/>
<IsPartOfProject Value="True"/>
</Unit1>
</Units>
@ -87,12 +97,12 @@
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="EverythingDsx.dsx" ApplyConventions="False"/>
<Filename Value="..\everything.dsx" ApplyConventions="False"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<OtherUnitFiles Value=".."/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
<OtherUnitFiles Value="..\..\..\..\sdk"/>
<UnitOutputDirectory Value="..\lib"/>
</SearchPaths>
<CodeGeneration>
<SmartLinkUnit Value="True"/>

View file

@ -3,7 +3,7 @@ library EverythingDsx;
{$mode objfpc}{$H+}
uses
Classes, DsxPlugin, everything;
Classes, Everything, DsxPlugin, DCConvertEncoding;
threadvar
AddFileProc: TSAddFileProc;
@ -12,7 +12,7 @@ procedure FoundCallback(FileName: PWideChar);
var
S: String;
begin
S:= UTF8Encode(UnicodeString(FileName));
S:= CeUtf16ToUtf8(UnicodeString(FileName));
AddFileProc(0, PAnsiChar(S));
end;

View file

@ -38,7 +38,7 @@ function ShowPasswordQuery(var Encrypt: Boolean; var Password: WideString): Bool
implementation
uses
SevenZipCodecs;
LazUTF8, SevenZipCodecs;
{$R *.res}
@ -108,9 +108,9 @@ end;
function ComboBoxAdd(hwndDlg: HWND; ItemID: Integer; ItemText: String; ItemData: PtrInt): Integer;
var
Text: WideString;
Text: UnicodeString;
begin
Text:= UTF8Decode(ItemText);
Text:= UTF8ToUTF16(ItemText);
Result:= SendDlgItemMessageW(hwndDlg, ItemID, CB_ADDSTRING, 0, LPARAM(PWideChar(Text)));
SendDlgItemMessage(hwndDlg, ItemID, CB_SETITEMDATA, Result, ItemData);
end;

View file

@ -533,7 +533,7 @@ begin
if (Is7ZipLoaded or Load7Zip) then
LoadLibraries
else begin
MessageBoxW(0, PWideChar(UTF8Decode(rsSevenZipLoadError)), 'SevenZip', MB_OK or MB_ICONERROR);
MessageBoxW(0, PWideChar(UTF8ToUTF16(rsSevenZipLoadError)), 'SevenZip', MB_OK or MB_ICONERROR);
end;
// Create password cache object
PasswordCache:= TPasswordCache.Create;

View file

@ -450,7 +450,7 @@ begin
Ini:= TIniFile.Create(ConfigFile);
try
LibraryPath:= Ini.ReadString('Library', TargetCPU, EmptyStr);
LibraryPath:= Utf16ToUtf8(ExpandEnvironmentStrings(UTF8Decode(LibraryPath)));
LibraryPath:= Utf16ToUtf8(ExpandEnvironmentStrings(UTF8ToUTF16(LibraryPath)));
for ArchiveFormat:= Low(TArchiveFormat) to High(TArchiveFormat) do
begin
Section:= GUIDToString(PluginConfig[ArchiveFormat].ArchiveCLSID^);

View file

@ -167,7 +167,7 @@ function GetFileAttributesEx(lpFileName: LPCSTR; fInfoLevelId: TGET_FILEEX_INFO_
implementation
uses
LazFileUtils;
LazUTF8, LazFileUtils;
function StreamCopy(Source, Target: TStream): Int64;
begin
@ -232,7 +232,7 @@ end;
function FileDelete(const FileName: String): Boolean;
begin
Result:= DeleteFileW(PWideChar(UTF8Decode(FileName)));
Result:= DeleteFileW(PWideChar(UTF8ToUTF16(FileName)));
end;
function FindUnusedFileName(const FileName, FileExt: String): String;
@ -251,7 +251,7 @@ function FileMove(const OldName, NewName: String; Replace: Boolean): Boolean;
const
dwFlags: array[Boolean] of DWORD = (0, MOVEFILE_REPLACE_EXISTING);
begin
Result:= MoveFileExW(PWideChar(UTF8Decode(OldName)), PWideChar(UTF8Decode(NewName)),
Result:= MoveFileExW(PWideChar(UTF8ToUTF16(OldName)), PWideChar(UTF8ToUTF16(NewName)),
dwFlags[Replace] or MOVEFILE_COPY_ALLOWED);
end;
@ -262,7 +262,7 @@ end;
class function JclSysUtils.LoadModule(var Module: TModuleHandle; FileName: String): Boolean;
begin
Module:= LoadLibraryW(PWideChar(UTF8Decode(FileName)));
Module:= LoadLibraryW(PWideChar(UTF8ToUTF16(FileName)));
Result:= Module <> INVALID_MODULEHANDLE_VALUE;
end;
@ -314,13 +314,13 @@ end;
function CreateFile(lpFileName: LPCSTR; dwDesiredAccess: DWORD; dwShareMode: DWORD; lpSecurityAttributes: LPSECURITY_ATTRIBUTES;
dwCreationDisposition: DWORD; dwFlagsAndAttributes: DWORD; hTemplateFile: HANDLE): HANDLE;
begin
Result:= CreateFileW(PWideChar(UTF8Decode(lpFileName)), dwDesiredAccess, dwShareMode,
Result:= CreateFileW(PWideChar(UTF8ToUTF16(lpFileName)), dwDesiredAccess, dwShareMode,
lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
end;
function GetFileAttributesEx(lpFileName: LPCSTR; fInfoLevelId: TGET_FILEEX_INFO_LEVELS; lpFileInformation: Pointer): BOOL;
begin
Result:= GetFileAttributesExW(PWideChar(UTF8Decode(lpFileName)), fInfoLevelId, lpFileInformation);
Result:= GetFileAttributesExW(PWideChar(UTF8ToUTF16(lpFileName)), fInfoLevelId, lpFileInformation);
end;
{ TJclDynamicSplitStream }
@ -436,26 +436,26 @@ procedure TJclWideStringList.PutObject(Index: Integer; AObject: TObject);
begin
Data[Index] := AObject;
end;
function TJclWideStringList.CompareWideStringProc(Key1, Key2: Pointer): Integer;
begin
{$if FPC_FULLVERSION<30002}
Result:= WideStringManager.CompareWideStringProc(WideString(Key1^), WideString(Key2^));
{$else}
Result:= WideStringManager.CompareWideStringProc(WideString(Key1^), WideString(Key2^), []);
{$endif}
end;
function TJclWideStringList.CompareTextWideStringProc(Key1, Key2: Pointer): Integer;
begin
{$if FPC_FULLVERSION<30002}
Result:= WideStringManager.CompareTextWideStringProc(WideString(Key1^), WideString(Key2^));
{$else}
Result:= WideStringManager.CompareWideStringProc(WideString(Key1^), WideString(Key2^), [coIgnoreCase]);
{$endif}
end;
constructor TJclWideStringList.Create;
function TJclWideStringList.CompareWideStringProc(Key1, Key2: Pointer): Integer;
begin
{$if FPC_FULLVERSION<30002}
Result:= WideStringManager.CompareWideStringProc(WideString(Key1^), WideString(Key2^));
{$else}
Result:= WideStringManager.CompareWideStringProc(WideString(Key1^), WideString(Key2^), []);
{$endif}
end;
function TJclWideStringList.CompareTextWideStringProc(Key1, Key2: Pointer): Integer;
begin
{$if FPC_FULLVERSION<30002}
Result:= WideStringManager.CompareTextWideStringProc(WideString(Key1^), WideString(Key2^));
{$else}
Result:= WideStringManager.CompareWideStringProc(WideString(Key1^), WideString(Key2^), [coIgnoreCase]);
{$endif}
end;
constructor TJclWideStringList.Create;
begin
inherited Create;
OnKeyPtrCompare := @CompareTextWideStringProc;

View file

@ -29,7 +29,8 @@ uses
cthreads,
{$ENDIF}
FPCAdds,
Classes, SysUtils, TorrentFile, WcxPlugin, DCDateTimeUtils, DCClassesUtf8;
Classes, SysUtils, TorrentFile, WcxPlugin, DCDateTimeUtils, DCClassesUtf8,
DCConvertEncoding;
type
PTorrentHandle = ^TTorrentHandle;
@ -57,7 +58,7 @@ begin
Exit;
end;
try
AFileName := UTF8Encode(UnicodeString(ArchiveData.ArcName));
AFileName := CeUtf16ToUtf8(UnicodeString(ArchiveData.ArcName));
AStream:= TFileStreamEx.Create(AFileName, fmOpenRead or fmShareDenyNone);
try
New(AHandle);
@ -93,7 +94,7 @@ begin
AFile:= TTorrentSubFile(AHandle.Torrent.Files[AHandle.Index]);
HeaderData.FileTime:= UnixFileTimeToWcxTime(AHandle.Torrent.CreationTime);
HeaderData.FileName:= UTF8Decode(AFile.Path + AFile.Name);
HeaderData.FileName:= CeUtf8ToUtf16(AFile.Path + AFile.Name);
HeaderData.UnpSize:= Int64Rec(AFile.Length).Lo;
HeaderData.UnpSizeHigh:= Int64Rec(AFile.Length).Hi;
HeaderData.PackSize:= HeaderData.UnpSize;

View file

@ -201,7 +201,7 @@ begin
sFileName := Arc.GetFileName(Arc.Tag);
StringToArrayW(UTF8Decode(sFileName), @HeaderData.FileName, SizeOf(HeaderData.FileName));
StringToArrayW(CeUtf8ToUtf16(sFileName), @HeaderData.FileName, SizeOf(HeaderData.FileName));
with Arc.Items[Arc.Tag] do
begin
@ -246,7 +246,7 @@ begin
// Show progress and ask if aborting.
if Assigned(Arc.FProcessDataProcW) then
begin
if Arc.FProcessDataProcW(PWideChar(UTF8Decode(Arc.Items[Arc.Tag].FileName)),
if Arc.FProcessDataProcW(PWideChar(CeUtf8ToUtf16(Arc.Items[Arc.Tag].FileName)),
Arc.Items[Arc.Tag].UncompressedSize) = 0
then
Arc.FOperationResult := E_EABORTED;
@ -268,7 +268,7 @@ begin
// Show progress and ask if aborting.
if Assigned(Arc.FProcessDataProcW) then
begin
if Arc.FProcessDataProcW(PWideChar(UTF8Decode(Arc.Items[Arc.Tag].FileName)),
if Arc.FProcessDataProcW(PWideChar(CeUtf8ToUtf16(Arc.Items[Arc.Tag].FileName)),
Arc.Items[Arc.Tag].UncompressedSize) = 0
then
Arc.FOperationResult := E_EABORTED;
@ -574,9 +574,9 @@ var
begin
if (not mbFileExists(ImageName)) and Assigned(FChangeVolProcW) then
begin
StrPCopy(AVolume, UTF8Decode(ImageName));
StrPCopy(AVolume, CeUtf8ToUtf16(ImageName));
Abort := (FChangeVolProcW(AVolume, PK_VOL_ASK) = 0);
if not Abort then ImageName:= UTF8Encode(UnicodeString(AVolume));
if not Abort then ImageName:= CeUtf16ToUtf8(UnicodeString(AVolume));
end;
end;
@ -587,7 +587,7 @@ begin
if Assigned(FProcessDataProcW) then
begin
if Assigned(Item) then
Abort := (FProcessDataProcW(PWideChar(UTF8Decode(Item.FileName)), -(Progress + 1000)) = 0)
Abort := (FProcessDataProcW(PWideChar(CeUtf8ToUtf16(Item.FileName)), -(Progress + 1000)) = 0)
else
Abort := (FProcessDataProcW(nil, -(Progress + 1000)) = 0);
end;

View file

@ -38,6 +38,7 @@ interface
uses
{$IFDEF MSWINDOWS}
Windows,
DCConvertEncoding,
{$ENDIF}
{$IFDEF LibcAPI}
Libc,
@ -447,7 +448,7 @@ begin
end;
{$ENDIF UNIX}
{$IFDEF MSWINDOWS}
Result := CopyFileW(PWideChar(UTF8Decode(Source)), PWideChar(UTF8Decode(Destination)), FailIfExists);
Result := CopyFileW(PWideChar(CeUtf8ToUtf16(Source)), PWideChar(CeUtf8ToUtf16(Destination)), FailIfExists);
{$ENDIF MSWINDOWS}
end;
{ -------------------------------------------------------------------------- }
@ -556,7 +557,7 @@ function AbGetDriveFreeSpace(const ArchiveName : string) : Int64;
var
FreeAvailable, TotalSpace: Int64;
begin
if GetDiskFreeSpaceExW(PWideChar(UTF8Decode(ExtractFilePath(ExpandFileName(ArchiveName)))),
if GetDiskFreeSpaceExW(PWideChar(CeUtf8ToUtf16(ExtractFilePath(ExpandFileName(ArchiveName)))),
FreeAvailable, TotalSpace, nil) then
Result := FreeAvailable
else
@ -997,18 +998,20 @@ end;
{ -------------------------------------------------------------------------- }
function AbWriteVolumeLabel(const VolName : string;
Drive : Char) : Cardinal;
{$IFDEF MSWINDOWS}
var
Temp : WideString;
Temp : UnicodeString;
Vol : array[0..11] of WideChar;
Root : array[0..3] of WideChar;
{$ENDIF}
begin
Temp := UTF8Decode(VolName);
{$IFDEF MSWINDOWS}
Temp := CeUtf8ToUtf16(VolName);
StrPCopyW(Root, '%:' + AbPathDelim);
Root[0] := Drive;
if Length(Temp) > 11 then
SetLength(Temp, 11);
StrPCopyW(Vol, Temp);
{$IFDEF MSWINDOWS}
if Windows.SetVolumeLabelW(Root, Vol) then
Result := 0
else Result := GetLastError;
@ -1257,7 +1260,7 @@ begin
aAttr.Attr := -1;
aAttr.Mode := 0;
{$IFDEF MSWINDOWS}
Result := GetFileAttributesExW(PWideChar(UTF8Decode(aFileName)), GetFileExInfoStandard, @FindData);
Result := GetFileAttributesExW(PWideChar(CeUtf8ToUtf16(aFileName)), GetFileExInfoStandard, @FindData);
if Result then begin
if Windows.FileTimeToLocalFileTime(FindData.ftLastWriteTime, LocalFileTime) and
FileTimeToDosDateTime(LocalFileTime, FileDate.Hi, FileDate.Lo) then

View file

@ -1687,7 +1687,7 @@ begin
{$IFDEF MSWINDOWS}
FItemInfo.IsUTF8 := False;
HostOS := hosDOS;
UnicName := UTF8Decode(Value);
UnicName := CeUtf8ToUtf16(Value);
if CeTryEncode(UnicName, CP_OEMCP, False, AnsiName) then
{no-op}
else if (GetACP <> GetOEMCP) and CeTryEncode(UnicName, CP_ACP, False, AnsiName) then

View file

@ -838,7 +838,7 @@ begin
SendStream.PluginNumber:= PluginNumber;
SendStream.ProgressProc:= ProgressProc;
SendStream.TargetName:= PWideChar(ServerToClient(FileName));
SendStream.SourceName:= PWideChar(UTF8Decode(FDirectFileName));
SendStream.SourceName:= PWideChar(CeUtf8ToUtf16(FDirectFileName));
try
if not DataSocket then Exit;
@ -887,7 +887,7 @@ begin
RetrStream.PluginNumber := PluginNumber;
RetrStream.ProgressProc := ProgressProc;
RetrStream.SourceName := PWideChar(ServerToClient(FileName));
RetrStream.TargetName := PWideChar(UTF8Decode(FDirectFileName));
RetrStream.TargetName := PWideChar(CeUtf8ToUtf16(FDirectFileName));
try
FTPCommand('TYPE I');

View file

@ -123,7 +123,7 @@ implementation
uses
IniFiles, StrUtils, FtpAdv, FtpUtils, FtpConfDlg, syncobjs, LazFileUtils,
LazUTF8, DCClassesUtf8, SftpSend, ScpSend, FtpProxy;
LazUTF8, DCClassesUtf8, DCConvertEncoding, SftpSend, ScpSend, FtpProxy;
var
DefaultIniName: String;
@ -261,8 +261,8 @@ var
APassword: UnicodeString;
AConnection: UnicodeString;
begin
APassword:= UTF8Decode(Password);
AConnection:= UTF8Decode(ConnectionName);
APassword:= CeUtf8ToUtf16(Password);
AConnection:= CeUtf8ToUtf16(ConnectionName);
if (Mode = FS_CRYPT_LOAD_PASSWORD) or (Mode = FS_CRYPT_LOAD_PASSWORD_NO_UI) then
begin
SetLength(APassword, MAX_PATH);
@ -298,7 +298,7 @@ begin
while sTemp <> EmptyStr do
FtpSend.ExecuteCommand(Copy2SymbDel(sTemp, ';'));
if Length(Connection.Path) > 0 then
FtpSend.ChangeWorkingDir(FtpSend.ClientToServer(UTF8Decode(Connection.Path)));
FtpSend.ChangeWorkingDir(FtpSend.ClientToServer(CeUtf8ToUtf16(Connection.Path)));
Result := True;
end;
end;
@ -398,7 +398,7 @@ begin
end
else begin
Connection.CachedPassword:= APassword;
LogProc(PluginNumber, MSGTYPE_CONNECT, PWideChar('CONNECT ' + PathDelim + UTF8Decode(ConnectionName)));
LogProc(PluginNumber, MSGTYPE_CONNECT, PWideChar('CONNECT ' + PathDelim + CeUtf8ToUtf16(ConnectionName)));
ActiveConnectionList.AddObject(ConnectionName, FtpSend);
if Connection.OpenSSH and (ConnectionName <> cQuickConnection) then
begin
@ -608,7 +608,7 @@ begin
FillChar(FindData, SizeOf(FindData), 0);
if I < RootCount then
begin
StrPCopy(FindData.cFileName, UTF8Decode(RootList[I]));
StrPCopy(FindData.cFileName, CeUtf8ToUtf16(RootList[I]));
FindData.dwFileAttributes := 0;
Inc(ListRec^.Index);
Result := True;
@ -616,7 +616,7 @@ begin
else if I - RootCount < ConnectionList.Count then
begin
Connection := TConnection(ConnectionList.Objects[I - RootCount]);
StrPCopy(FindData.cFileName, UTF8Decode(Connection.ConnectionName));
StrPCopy(FindData.cFileName, CeUtf8ToUtf16(Connection.ConnectionName));
FindData.dwFileAttributes := FILE_ATTRIBUTE_NORMAL;
Inc(ListRec^.Index);
Result := True;

View file

@ -582,7 +582,7 @@ begin
SendStream := TFileStreamEx.Create(FDirectFileName, fmOpenRead or fmShareDenyWrite);
TargetName:= PWideChar(ServerToClient(FileName));
SourceName:= PWideChar(UTF8Decode(FDirectFileName));
SourceName:= PWideChar(CeUtf8ToUtf16(FDirectFileName));
FileSize:= SendStream.Size;
FBuffer:= GetMem(SMB_BUFFER_SIZE);
@ -659,7 +659,7 @@ begin
RetrStream := TFileStreamEx.Create(FDirectFileName, fmCreate or fmShareDenyWrite);
SourceName := PWideChar(ServerToClient(FileName));
TargetName := PWideChar(UTF8Decode(FDirectFileName));
TargetName := PWideChar(CeUtf8ToUtf16(FDirectFileName));
libssh2_session_set_blocking(FSession, 0);
try

View file

@ -69,7 +69,7 @@ implementation
uses
LazUTF8, DCBasicTypes, DCDateTimeUtils, DCStrUtils, DCOSUtils, FtpFunc, CTypes,
DCClassesUtf8, DCFileAttributes;
DCClassesUtf8, DCFileAttributes, DCConvertEncoding;
const
SMB_BUFFER_SIZE = 131072;
@ -218,7 +218,7 @@ begin
SendStream := TFileStreamEx.Create(FDirectFileName, fmOpenRead or fmShareDenyWrite);
TargetName:= PWideChar(ServerToClient(FileName));
SourceName:= PWideChar(UTF8Decode(FDirectFileName));
SourceName:= PWideChar(CeUtf8ToUtf16(FDirectFileName));
FileSize:= SendStream.Size;
FBuffer:= GetMem(SMB_BUFFER_SIZE);
@ -309,7 +309,7 @@ begin
end;
SourceName := PWideChar(ServerToClient(FileName));
TargetName := PWideChar(UTF8Decode(FDirectFileName));
TargetName := PWideChar(CeUtf8ToUtf16(FDirectFileName));
if Restore then TotalBytesToRead:= RetrStream.Seek(0, soEnd);

View file

@ -69,6 +69,11 @@
<FormatVersion Value="2"/>
<Modes Count="0"/>
</RunParams>
<RequiredPackages Count="1">
<Item1>
<PackageName Value="doublecmd_common"/>
</Item1>
</RequiredPackages>
<Units Count="1">
<Unit0>
<Filename Value="preview.lpr"/>

View file

@ -51,7 +51,7 @@ function GetPreviewHandler(const FileName: UnicodeString): IPreviewHandler;
implementation
uses
ComObj;
ComObj, DCConvertEncoding, DCClassesUtf8;
type
IInitializeWithFile = interface(IUnknown)
@ -86,7 +86,7 @@ var
ABuffer: array[0..MAX_PATH] of WideChar;
begin
Res := AssocQueryStringW(ASSOCF_INIT_DEFAULTTOSTAR, ASSOCSTR_SHELLEXTENSION, PWideChar(FileExt),
PWideChar(UTF8Decode(GuidToString(interfaceID))), ABuffer, @cchOut);
PWideChar(CeUtf8ToUtf16(GuidToString(interfaceID))), ABuffer, @cchOut);
if (Res <> S_OK) then Exit(Default(TGUID));
Res := CLSIDFromString(ABuffer, @Result);
if (Res <> NOERROR) then Exit(Default(TGUID));
@ -97,7 +97,7 @@ var
Res: HRESULT;
ClassID: TGUID;
AStream: IStream;
AFile: TFileStream;
AFile: TFileStreamEx;
AShellItem: IShellItem;
AInitializeWithFile: IInitializeWithFile;
AInitializeWithItem: IInitializeWithItem;
@ -112,7 +112,7 @@ begin
Res:= AInitializeWithFile.Initialize(PWideChar(FileName), STGM_READ)
else if Supports(Result, IInitializeWithStream, AInitializeWithStream) then
try
AFile:= TFileStream.Create(UTF8Encode(FileName), fmOpenRead or fmShareDenyNone);
AFile:= TFileStreamEx.Create(CeUtf16ToUtf8(FileName), fmOpenRead or fmShareDenyNone);
AStream:= TStreamAdapter.Create(AFile, soOwned) as IStream;
Res:= AInitializeWithStream.Initialize(AStream, STGM_READ);
except