feat(relinker): write a desktop entry with the game icon for Linux executables #353
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/353"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-02T11:45:30Z.
What
Linux counterpart of #350. ELF has no icon resource; desktops take the icon from a freedesktop
.desktopentry. Whensce_sys/icon0.pngsits beside the input executable, the relinker now writes next to the output:<output>.png: the icon, byte for byte (PNG signature and IHDR checked).<output>.desktop:Type=Application,Name,Exec,Path(output directory),Icon,Terminal=false,Categories=Game;. It is marked executable so file managers (Dolphin, Nautilus) offer to launch it.Nameis thetitleNamefromsce_sys/param.json, parsed with the existing libkernelParamJsonParser(same language choice assceAppContent/AppMetadata), with ™ ® © and line breaks removed and spaces collapsed. Withoutparam.json, the output file name is used.Execis quoted and escaped as the Desktop Entry spec requires (",`,$,\,%). Paths are absolute because the spec has no relative form.Without
icon0.pngnothing extra is written and the output is unchanged. A malformedicon0.pngorparam.jsonfails the relink with the file path, like #350 does for Windows. No new flags or dependencies; only the C++ standard library.No conflict with #350: the two PRs touch different lines (
git merge-treeis clean), and the TechnicalDebt entry that #350 removes is left for it.Tested
Linux (CachyOS, GCC 16), Release: full ctest (109) passes, including the new C++ test
linux_desktop_entry(elfpatcher/tests/LinuxDesktopEntryTests.cpp, registered next tofile_writer_tests, so it doesn't depend on Python).icon0.png(no files written), title cleanup (Some™ Game®:\n Edition©→Some Game: Edition), byte-identical icon, exec bit, the output name as fallback with%and$in the path, a non-PNG icon, and a malformedparam.json.desktop-file-validateaccepts the generated entry, including one whose path has a space,%and$.Malformed desktop entry line: Edition©).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by QDarkRex on 2026-10-02T14:11:19Z.
Built f2cc42e on Ubuntu 24.04 (GCC 13): relinker ctest 16/16 including
linux_desktop_entry. I also ran the writer on paths with spaces,$HOME, backticks,",\,%u, a leading-and Japanese names:desktop-file-validateaccepts every entry andExec/Path/Icondecode back to the exact paths, so both escaping layers hold.Two small things:
main.cpp,fileWriter.WritethenLinuxDesktopEntryWriter().Write), so a malformedicon0.pngorparam.jsonprintsFAILand exits 2 with a finished ELF already on disk. Checking the icon and title before writing the executable would keep failure all-or-nothing, as in #350.escapeValueonly doubles\. An output directory whose name contains a newline produces an entry thatdesktop-file-validaterejects; escaping\n,\t,\r(or throwing on control characters) would close that.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T05:42:59Z.
I agree with both of QDarkRex's points: validating icon0.png and param.json before writing the executable would keep a failed relink from leaving an ELF behind, and escaping (or rejecting) control characters in Exec, Path and Icon keeps the entry valid for any output path. Could you address those? Writing the .desktop and .png next to every Linux output is also a behaviour change, so I'll leave the go-ahead on that to @boykopovar
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T06:42:00Z.
Thanks @QDarkRex for testing it and @oneandonlydean for the review. Both points are done, rebased onto main:
Prepare(reads and checks icon0.png and param.json, builds the entry text) andWrite.main.cppcallsPreparebeforefileWriter.Write, so a malformed icon or title fails before the ELF is on disk. The failure tests now check that neither the.desktopnor the.pngwas written.\n,\t,\r, 0x7f, ...) is refused with a clear error, rather than escaped. A newline can't round-trip throughExecanyway. The test covers those four, and it fails if the check is removed.linux_desktop_entryand the other relinker tests pass on Linux. The go-ahead on writing the.desktop/.pngnext to every Linux output stays with boykopovar, as you said.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T07:39:54Z.
Thanks, both points are handled:
Preparereads and checks icon0.png and param.json before the executable is written, and a path with a control character is refused with a clear error.One small gap is left for all-or-nothing: in
main.cpp,Preparestill runs after the--registryJSON and the guest modules are written, so a malformed icon0.png or param.json now leaves those files behind instead of the ELF.Prepareonly needs the input and output paths, so calling it before the firstfileWriter.Write(above the registry write) would leave nothing on disk when it fails, the same as the Windows icon, whichWindowsPePatcherreads insidePatchbefore anything is written.The go-ahead on writing the .desktop and .png next to every Linux output is still with @boykopovar.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T09:02:17Z.
Thanks, done and rebased onto main:
Preparenow runs before the firstfileWriter.Write(above the--registrywrite and the guest modules), so a malformed icon0.png or param.json leaves nothing on disk. Checked with a synthetic input, a broken icon0.png and--registry:FAIL, exit 2, output directory empty; with no icon the executable and registry are written as before.linux_desktop_entryand the full Release ctest pass on Linux (onlyagc_driver_pixel_helper_lanesfails locally, also on main).Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T09:51:51Z.
Thanks, that closes it:
Preparenow runs before the registry, the guest modules and the executable are written, so a bad icon0.png or param.json leaves nothing behind. Merged with current main it builds, andlinux_desktop_entryand the rest of ctest pass here. From my side only the go-ahead from @boykopovar on writing the .desktop and .png next to every Linux output is left.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T10:45:39Z.
Rebased onto current main and adapted to what landed since:
--macoswould have got a Linux.desktoptoo. It's now written only for Linux output (!toWindows && !toMacos).main.cppand the writer go throughIo::NativePath/Io::Utf8Pathlike the rest of the relinker (#b74774f, non-ASCII paths on Windows hosts). On Linux these are the identity.linux_desktop_entry_outputrelinks a fixture end to end: no icon → no entry; icon + param.json →.desktop+.pngwith Name/Exec/Path/Icon checked anddesktop-file-validateclean (when installed);--macosand--windows→ neither file; malformed icon → nothing on disk. It fails on the--macoscase without the fix.All 101 relinker tests pass locally on Linux.