Skip to content

Conversation

@flagrama
Copy link

@flagrama flagrama commented Feb 10, 2025

This PR adds support for running the randomizer in environments where the app directory itself is not writable. My personal motivation behind this was to let the randomizer run in a flatpak environment, however as I worked on this I realized it also helps resolve installing the randomizer in say /usr/local/bin or :\Program Files as well, although I've only made changes necessary for Linux environments currently. Windows should be handled by someone who actually uses the platform, possibly with an eye to also create a store package.

Changes:

  • Python
    • Rename existing local_path and data_path functions to make it clear they should only be used for reading files, not writing.
    • Add functions for each of the directory types specified in the XDG Base Directory Specification
      • While all of these get used for Linux/Flatpak, other platforms may end up using the same directory for one or all of them
    • Implement the new functions in place of the old functions wherever custom user data is expected. Overall we had pretty good separation between always existing readable data and potentially non-existent user-provided data so this was easier than expected.
    • Create and copy any files and directories the user is supposed to be able to write to to the user directories. (i.e. create the music folder in the writable data directory, copy the conversion script to it, copy the music_exclusion_list to the writable data directory)
  • GUI
    • Add a configuration to build without font optimization. Flatpak build environment has no internet access, and font optimization requires internet access.
    • Refresh package-lock.json. This hasn't been updated since 7.1, but the tool Flatpak provides for downloading node modules as sources prior to entering the build environment works off of this, and if the output from the package-lock.json does not exactly match what the package.json needs in the build environment, issues arise.
    • Ensure settings.sav is read and written at XDG_CONFIG_HOME if the app directory is not writable.
    • Have the default output directory checked when clicking the UI button to open it be XDG_DATA_HOME/Output if the app directory is not writable
    • Have the app directory button open XDG_DATA_HOME if the app directory is not writable
  • Compress
    • I needed to add support for reading and writing the ARCHIVE.bin file from XDG_CACHE_HOME if the app directory is not writable.
      • Currently only x86_64 and AArch64 are built. Unsure whether to bother with ARM32 though.

Flatpak and Flathub

With these changes it is now possible to build a Flatpak for OoTR, so long as it is using this branch as its git source for now. I have created a repository with all the files needed to do so. If you wish to give it a try yourself, you should install Flatpak, the Flathub repository (tutorial for building has you install it user-wide, not sure if issues arise with a globally configured one, but you can have both installed at the same time) and the Flatpak building tools. I found all of these available from my package manager. If further help finding them is needed I can do so.

To build and install the Flatpak in that repository, run flatpak-builder --force-clean --user --install-deps-from=flathub --repo=repo --install builddir com.ootrandomizer.electrongui.yml then to run the Flatpak run flatpak run com.ootrandomizer.electrongui. It is also possible to create a file to share with other users if desired.

While that repository has the basics, we should decide if we want to distribute the Flatpak on ootrandomizer.com, or if we should submit the package to Flathub in which case there is still more required work to do. Other adjustments can be made as desired too.

@flagrama
Copy link
Author

Also, here is a compare without renaming local_path and data_path for easier viewing: https://github.com/OoTRandomizer/OoT-Randomizer/compare/Dev...flagrama:OoT-Randomizer:flatpak-prep-norename?expand=1

@fenhl fenhl added Component: GUI/Website Specifically affects the OoTR GUI Status: Needs Review Someone should be looking at it Component: Randomizer Core Generally the core functions of the python Status: Needs Testing Probably should be tested Component: Misc A catch-all label Type: Maintenance Code style, infrastructure, updating dependencies labels Feb 10, 2025
@flagrama
Copy link
Author

Could I request the label Component: Cosmetics as well? Most of the Python changes are specifically on custom cosmetics code.

@fenhl fenhl added the Component: Cosmetics Affects the patching of cosmetics label Feb 10, 2025
@flagrama flagrama marked this pull request as ready for review February 11, 2025 19:54
@flagrama
Copy link
Author

flagrama commented Feb 11, 2025

Okay, I think this is good for review now. I did have Dusk give the Flatpak a try, and seemed to patch models fine, and I've tested custom music. I'm going to upload a version of the Flatpak to the dev channel as well so I can link it here for more testing, though building for yourself should also work. Some testing should also be done with the branch and release build of it in a normal circumstance to make sure behaviour hasn't changed. I tried hard to make sure it wouldn't, but you never know.

I was able to cross-compile an AARCH64 version of the Compress executable, but my distro doesn't have packages for 32-bit ARM so someone else will have to get that if it seems necessary. Flathub itself will only create x86_64 and AARCH64 packages.

I can also change to the other branch without the renames adding readonly_ if desired, but I'd prefer having something more obvious like in this branch.

accept cwd for run_process
@Tri4ceKid
Copy link

Loving the work so far! I've noticed that custom voices aren't working; everything except "Silent" just uses the default voices.

@flagrama
Copy link
Author

Thanks for the info. I look into it soon.

@flagrama
Copy link
Author

@Tri4ceKid the new commit should fix the issue. Do you need a new flatpak made, or can you make one yourself to test?

@Tri4ceKid
Copy link

I would appreciate a new flatpak as I'm not yet familiar with the process of making one.

@flagrama
Copy link
Author

Updated the link in the "ready to review" comment to a new flatpak build on discord.

Should be local path if possible, otherwise user data
Copy link
Collaborator

@fenhl fenhl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor code style nit, the Python looks good other than that afaict. Would appreciate if someone else could give the GUI code changes a review.

@fenhl
Copy link
Collaborator

fenhl commented May 17, 2025

I can probably take care of building the compressor for ARM32, just need to figure out how.

flagrama and others added 3 commits May 17, 2025 15:31
Code style

Co-authored-by: Fenhl <[email protected]>
# Conflicts:
#	Patches.py
@flagrama
Copy link
Author

I can probably take care of building the compressor for ARM32, just need to figure out how.

Feel free to add the commit with it directly to the PR

@fenhl fenhl removed the Status: Waiting for Author Changes or response requested label May 18, 2025
@flagrama
Copy link
Author

flagrama commented Jun 2, 2025


/* Read archive if it exists*/
file = fopen("ARCHIVE.bin", "rb");
file = fopen(getArchivePath(), "rb");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternate method to specifying the path to ARCHIVE.bin would be changing the working folder in the python call (see Main.py and Utils.py in PR #2314). This avoids the need to recompile the compressor for all platforms if that becomes a problem.

Copy link
Author

@flagrama flagrama Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would still require changing the source code for the compressor due to needing dmaTable.dat as well. It's also not possible to copy to a user directory on install as a flatpak can be installed globally for the system further making dmaTable.dat a problem.

@fenhl fenhl removed the Status: Needs Review Someone should be looking at it label Sep 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Cosmetics Affects the patching of cosmetics Component: GUI/Website Specifically affects the OoTR GUI Component: Misc A catch-all label Component: Randomizer Core Generally the core functions of the python Status: Needs Testing Probably should be tested Status: Waiting for Maintainers Type: Maintenance Code style, infrastructure, updating dependencies

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants