Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API to provide cache and data directories #934

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

modmuss50
Copy link
Member

@modmuss50 modmuss50 commented Jun 4, 2024

This is very work in progress, I look forward to getting some input on this:

The goal with this PR is to strongly define all of the locations on the filesystem where a mod should read/write files. Currently the only defined directory is ./config. This is useful for a few reasons, its easier for the developer as they do not need to implement platform specific code, better for the user as all of the mods files are located togeather and allows for new technology such as the fabric-sandbox.

This PR adds 4 new directories that mods can use to store data:

  • getCacheDir() returns an instance specific directory for mods to store data that should be cached across runs. Fabric loader uses this to cache the remapped jars. The contents of this directory can be regenerated if deleted.
  • getGlobalCacheDir() returns a location that is shared across all instances of Fabric Loader (regardless of Launcher or Game). This can be used to cache files across multiple instances, an example of this might be downloading addional files required for your mod. As above contents of this directory can be regenerated if deleted.
  • getDataDir() returns an instance specific directory for mods to store user generated data. This directory should be included in mod packs. An example of this may be client side map data (when playing on an MP server), schematics, blueprints. Basically anything that isnt a human editable file should go here (otherwise it lives in /config).
  • getGlobalDataDir()is similar to the global cache dir, but may be included in computer backups or synced across computer (E.G Active directory on windows). This directory may be used to store files such as private keys to encrypt secrets, the secrets themselves, or just user configuration that should persist to all instances of the game.

It is not expected that a user will ever manualy edit files in these locations. A sandbox may grant full access to all of these directories, without any isolation. Thus untrusted code must not be executed from these locations.

A mod ideally should not be saving any files outside of these locations + /config and the save directory.

On a server the global directories are stored within the servers directory, and are not shared between instances.

I am very much open to feedback on these locations, we should try our best to ensure that they are good, as changing them later will be difficult to do without introducing breaking changes.

Windows MacOS Linux Include in Mod Pack
Data ./fabric/modid/ ./fabric/modid/ ./fabric/modid/
Cache ./cache/modid/ ./cache/modid/ ./cache/modid/ ⛔️
Global Data %AppData%/net.fabricmc.loader/modid/ ~/Library/Application Support/net.fabricmc.loader/modid/ ~/.config/net.fabricmc.loader/modid/ ⛔️
Global Cache %LocalAppData%/net.fabricmc.loader/modid/ ~/Library/Caches/net.fabricmc.loader/modid/ ~/.cache/net.fabricmc.loader/modid/ ⛔️
Global Data (Server) ./fabric-global/modid/ ./fabric-global/modid/ ./fabric-global/modid/ ⛔️
Global Cache (Server) ./cache-global/modid/ ./cache-global/modid/ ./cache-global/modid/ ⛔️

Extra care needs to be taken to test this on a range of linux platforms/launchers, especially those using Docker, Flatpacks and Snaps. This can be tested easily by copying this code in a mod.

@modmuss50 modmuss50 requested review from sfPlayer1 and a team June 4, 2024 14:25
@modmuss50 modmuss50 added this to the 0.16.0 milestone Jun 5, 2024
@modmuss50 modmuss50 removed this from the 0.16.0 milestone Jul 9, 2024
@melontini
Copy link

Since the cache dirs are not meant to be included in modpacks and not to be interacted with by players, maybe they should be hidden?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants