fix: unicode problems

This commit is contained in:
Massimo Melina 2020-05-08 01:17:19 +02:00
parent 0c6365c528
commit 5628b4f08b
2 changed files with 22 additions and 11 deletions

View File

@ -1330,7 +1330,7 @@ function hasRightAttributes(fn:string):boolean; overload;
begin result:=hasRightAttributes(GetFileAttributes(pChar(fn))) end; begin result:=hasRightAttributes(GetFileAttributes(pChar(fn))) end;
function isAnyMacroIn(s:ansistring):boolean; inline; function isAnyMacroIn(s:ansistring):boolean; inline;
begin result:=pos(MARKER_OPEN, s) > 0 end; begin result:=pos(ansistring(MARKER_OPEN), s) > 0 end;
function loadDescriptionFile(fn:string):string; function loadDescriptionFile(fn:string):string;
begin begin
@ -3155,15 +3155,17 @@ function Tmainfrm.findFilebyURL(url:string; parent:Tfile=NIL; allowTemp:boolean=
if dirCrossing(s) then exit; if dirCrossing(s) then exit;
s:=includeTrailingPathDelimiter(f.resource)+s; // we made the ".." test before, so relative paths are allowed in the VFS s:=includeTrailingPathDelimiter(f.resource)+s; // we made the ".." test before, so relative paths are allowed in the VFS
if not fileOrDirExists(s) then if not fileOrDirExists(s) and fileOrDirExists(s+'.lnk') then
if fileOrDirExists(s+'.lnk') then s:=s+'.lnk' s:=s+'.lnk';
else s:=UTF8ToString(s); // these may actually be two distinct files, but it's very unlikely to be, and pratically we workaround big problem if not fileOrDirExists(s) or not hasRightAttributes(s) then
if not fileOrDirExists(s) or not hasRightAttributes(s) then exit; exit;
// found on disk, we need to build a temporary Tfile to return it // found on disk, we need to build a temporary Tfile to return it
result:=Tfile.createTemp(s); result:=Tfile.createTemp(s);
// the temp file inherits flags from the real folder // the temp file inherits flags from the real folder
if FA_DONT_LOG in f.flags then include(result.flags, FA_DONT_LOG); if FA_DONT_LOG in f.flags then
if not (FA_BROWSABLE in f.flags) then exclude(result.flags, FA_BROWSABLE); include(result.flags, FA_DONT_LOG);
if not (FA_BROWSABLE in f.flags) then
exclude(result.flags, FA_BROWSABLE);
// temp nodes are bound to parent's node // temp nodes are bound to parent's node
result.node:=f.node; result.node:=f.node;
end; // workTheRestByReal end; // workTheRestByReal
@ -3428,7 +3430,7 @@ var
addArray(nonPerc, ['~img_file', '~img'+intToStr(f.getSystemIcon())]); addArray(nonPerc, ['~img_file', '~img'+intToStr(f.getSystemIcon())]);
if recur or (itemFolder = '') then if recur or (itemFolder = '') then
itemFolder:=optUTF8(diffTpl, f.getFolder()); itemFolder:=f.getFolder();
if recur then if recur then
url:=substr(itemFolder, ofsRelItemUrl) url:=substr(itemFolder, ofsRelItemUrl)
else else
@ -3455,8 +3457,10 @@ var
if fingerprintsChk.checked and f.isFile() then if fingerprintsChk.checked and f.isFile() then
begin begin
s:=loadMD5for(f.resource); s:=loadMD5for(f.resource);
if s = '' then s:=hasher.getHashFor(f.resource); if s = '' then
if s > '' then fingerprint:='#!md5!'+s; s:=hasher.getHashFor(f.resource);
if s > '' then
fingerprint:='#!md5!'+s;
end; end;
if f.isLink() then if f.isLink() then
begin begin
@ -3601,6 +3605,13 @@ try
else else
inc(numberFiles); inc(numberFiles);
end; end;
{TODO this symbols will be available when executing macros in handleItem. Having
them at this stage is useful only in case immediate calculations are required.
This may happen seldom, but maybe some template is using it since we got this here.
Each symbols is an extra iteration on the template piece and we may be tempted
to consider for optimizations. To not risk legacy problems we should consider
treating table symbols with a regular expression and a Tdictionary instead.
}
table:=toSA([ table:=toSA([
'%upload-link%', if_(accountAllowed(FA_UPLOAD, cd, folder), diffTpl['upload-link']), '%upload-link%', if_(accountAllowed(FA_UPLOAD, cd, folder), diffTpl['upload-link']),
'%files%', diffTpl[if_(n>0, 'files','nofiles')], '%files%', diffTpl[if_(n>0, 'files','nofiles')],

View File

@ -739,7 +739,7 @@ end; // dotted
function getRes(name:pchar; typ:string='TEXT'):string; function getRes(name:pchar; typ:string='TEXT'):string;
var var
h1, h2: Thandle; h1, h2: Thandle;
p: pchar; p: pAnsiChar;
l: integer; l: integer;
ansi: ansiString; ansi: ansiString;
begin begin