FIX: Image file associated to Windows Photos opens only when there are no spaces in file name/path (fixes #2188)

(cherry picked from commit f7ba104e48)
This commit is contained in:
Alexander Koblov 2025-03-19 20:30:59 +03:00
commit 9cee7263d1
2 changed files with 21 additions and 12 deletions

View file

@ -380,13 +380,13 @@ var
wsStartPath: UnicodeString;
AppID, FileExt: UnicodeString;
begin
cchOut:= MAX_PATH;
SetLength(AppID, cchOut);
URL:= NormalizePathDelimiters(URL);
FileExt:= CeUtf8ToUtf16(ExtractFileExt(URL));
if CheckWin32Version(10) then
begin
cchOut:= MAX_PATH;
SetLength(AppID, cchOut);
if (AssocQueryStringW(ASSOCF_NONE, ASSOCSTR_APPID,
PWideChar(FileExt), nil, PWideChar(AppID), @cchOut) = S_OK) then
begin
@ -396,10 +396,16 @@ begin
// Special case Microsoft Photos
if (AppID = 'Microsoft.Windows.Photos_8wekyb3d8bbwe!App') then
begin
if CheckPhotosVersion then
// https://blogs.windows.com/windowsdeveloper/2024/06/03/microsoft-photos-migrating-from-uwp-to-windows-app-sdk/
if CheckPhotosVersion(2024, 11050) then
begin
URL:= URIEncode(URL);
URL:= 'ms-photos:viewer?fileName=' + StringReplace(URL, '%5C', '\', [rfReplaceAll]);
// https://github.com/doublecmd/doublecmd/issues/2188
if not CheckPhotosVersion(2025, 0) then
begin
URL:= URIEncode(URL);
URL:= StringReplace(URL, '%5C', '\', [rfReplaceAll]);
end;
URL:= 'ms-photos:viewer?fileName=' + URL;
end
// Microsoft Photos does not work correct
// when process has administrator rights

View file

@ -176,7 +176,7 @@ procedure CreateShortcut(const Target, Shortcut: String);
}
function ExtractFileAttributes(const FindData: TWin32FindDataW): DWORD;
function CheckPhotosVersion: Boolean;
function CheckPhotosVersion(ABuild, ARevision: UInt16): Boolean;
procedure UpdateEnvironment;
@ -1259,7 +1259,7 @@ var
bufferLength: PUINT32; buffer: PBYTE; count: PUINT32): LONG; stdcall;
ClosePackageInfo: function(packageInfoReference: PACKAGE_INFO_REFERENCE): LONG; stdcall;
function CheckPackageVersion(const Package: UnicodeString; Build, Revision: UInt16): Boolean;
function GetPackageVersion(const Package: UnicodeString; out Build, Revision: UInt16): Boolean;
var
Ret: ULONG;
Count: UINT32 = 0;
@ -1290,7 +1290,9 @@ begin
begin
with PPACKAGE_INFO(@PackageBuffer[0])^.packageId do
begin
Result:= (version.Build > Build) or ((version.Build = Build) and (version.Revision >= Revision));
Result:= True;
Build:= version.Build;
Revision:= version.Revision;
end;
end;
end;
@ -1300,20 +1302,21 @@ begin
end;
end;
function CheckPhotosVersion: Boolean;
function CheckPhotosVersion(ABuild, ARevision: UInt16): Boolean;
const
Build: UInt16 = 0;
Revision: UInt16 = 0;
PhotosNew: TDuplicates = dupIgnore;
begin
if (PhotosNew = dupIgnore) then
begin
// https://blogs.windows.com/windowsdeveloper/2024/06/03/microsoft-photos-migrating-from-uwp-to-windows-app-sdk/
if CheckPackageVersion('Microsoft.Windows.Photos_8wekyb3d8bbwe', 2024, 11050) then
if GetPackageVersion('Microsoft.Windows.Photos_8wekyb3d8bbwe', Build, Revision) then
PhotosNew:= dupAccept
else begin
PhotosNew:= dupError;
end;
end;
Result:= (PhotosNew = dupAccept);
Result:= (PhotosNew = dupAccept) and ((Build > ABuild) or ((Build = ABuild) and (Revision >= ARevision)));
end;
var