cemu-project / Cemu

Cemu - Wii U emulator
https://cemu.info
Mozilla Public License 2.0
6.84k stars 528 forks source link

Saving settings.xml replaces symlink with regular file #1258

Closed bcat closed 1 month ago

bcat commented 1 month ago

Current Behavior

I am using Cemu on Windows together with a number of other emulators, launched from a separate frontend. Since there is no standardization of "user data" paths across different emulators on Windows, I run all my emulators in "portable mode" and use NTFS symlink support to link the various emulator config files into a common directory tree. This makes it much easier for me to back up my emulator configs, saves, etc., as well as to share them across systems.

I tried to implement this setup for Cemu, and while linking directories like gameProfiles and mlc01 works fine, linking settings.xml does not. It seems that Cemu updates its config files by first writing to a temporary file and then renaming the temporary file over the existing one. I assume the intent is to keep from leaving an incomplete config file in case of error (at least on platforms supporting atomic rename), but this has the side effect of wiping out the symlink and replacing it with a regular file every time Cemu exits.

Expected Behavior

I expected Cemu to open and rewrite settings.xml "in place", similar to other emulators (e.g., RetroArch, MAME, etc.) update their config files. This would respect the symlink and avoid replacing it with a regular file.

Alternatively, we could preserve the rename behavior (which may have some advantages as mentioned above) by having Cemu look for config files in a subdirectory (e.g., configs/settings.xml) of the Cemu directory rather than in the top-level Cemu directory. Then folks could just symlink the configs directory and Cemu could continue to write the config files the same way it currently does. (This could also be made configurable via command-line flags to set the different directories that the Windows build currently hardcodes to the executable's parent directory. That would be the most flexible option, but it may be overkill compared to simply checking for a configs subdirectory and using it if it exists.)

Steps to Reproduce

  1. Install Cemu to a directory like %LOCALAPPDATA%\Programs\Cemu.
  2. Create a symlink from %LOCALAPPDATA%\Programs\Cemu\settings.xml to a different path like %USERPROFILE%\Documents\Emulation\Configs\Cemu\settings.xml.
  3. Run and exit Cemu.
  4. Observe that %LOCALAPPDATA%\Programs\Cemu\settings.xml is no longer a symlink, but has been replaced by a regular file instead.

System Info (Optional)

OS: Windows 10 Version 22H2 (OS Build 19045.4651) Cemu: 2.0-88 (Experimental)

Emulation Settings (Optional)

No response

Logs (Optional)

No response

Exzap commented 1 month ago

If you create a directory portable next to Cemu.exe it should place all dynamic files in there, including settings.xml. I haven't tested this myself but you should be able to symlink the portable directory as a whole.

bcat commented 1 month ago

Oh, I didn't know about that, thanks! Symlinking the portable directory does indeed seem to work. Feel free to close this if you think it's working as intended or not worth fixing given that.

Exzap commented 1 month ago

Thanks for confirming that symlinking portable works. Making settings.xml symlink aware is theoretically possible but it's not worth the maintenance burden when there exists a cleaner solution