godot icon indicating copy to clipboard operation
godot copied to clipboard

Add custom paths support (custom `res://`/`user://`-like paths)

Open adamscott opened this issue 1 year ago • 5 comments

Capture d’écran du 2024-01-25 09-45-02_2

tl;dr

Enables custom resource paths that users can setup and use themselves.

# Maps a path to a custom path
FileAccess.map_path_to_custom_path("home", "/home/myself")
# (with or without the ://, it removes it automatically)
FileAccess.map_path_to_custom_path("home://", "/home/myself")
# Map classes (custom `FileAccess` and `DirAccess`) to custom path
FileAccess.map_classes_to_custom_path("cloud://", "CloudFileAccess", "CloudDirAccess")
# Removes a custom path
FileAccess.remove_custom_path("home")
# Checks if the prefix is supported
FileAccess.is_custom_path("home")
# Returns a dictionary containing the definition of the custom path
FileAccess.get_custom_path_data("home")
# Returns an array containing all the custom path prefixes
FileAccess.get_custom_paths()

Todo

  • [ ] Write the documentation

Fixes

  • Fix godotengine/godot-proposals#6307
  • Closes godotengine/internal-team-priorities#92

adamscott avatar Jan 25 '24 15:01 adamscott

This is big step (even if not directly) towards global addons 🥳 I like it

arkology avatar Jan 25 '24 15:01 arkology

This is big step (even not directly) towards global addons 🥳

That's the goal!

adamscott avatar Jan 25 '24 16:01 adamscott

Why do is_resource_path and get_resource_path(s) fail for res and user? I understand that adding/removing them is dangerous, so those erroring makes sense. But the current handling of the getter methods are just exposing an implementation detail to the user. They should instead be a consistent API for "every virtual path *:// managed by Godot"...

RedMser avatar Jan 25 '24 17:01 RedMser

But the current handling of the getter methods are just exposing an implementation detail to the user.

No, user:// and res:// are special cases handled differently. This PR is not about exposing an implementation detail, it's a feature in itself.

adamscott avatar Jan 25 '24 21:01 adamscott

the pr is good. i used the pr, i think will need add prefix_dir options in "EditorFileDialog" and "FileDialog"

zedrun00 avatar Aug 27 '24 03:08 zedrun00

@adamscott Do you think it's possible to add memory based file system to this PR? A simple VFS so files can be used directly from memory like "memory://my_scene.tscn"

CycloneRing avatar Oct 11 '24 12:10 CycloneRing

@adamscott Do you think it's possible to add memory based file system to this PR? A simple VFS so files can be used directly from memory like "memory://my_scene.tscn"

This clearly isn't in the scope of my PR.

adamscott avatar Oct 11 '24 14:10 adamscott

@adamscott are you sure? it is in the scope of your PR's example usage, so i would say the answer is "already possible, no need to add anything".

FileAccess.map_classes_to_custom_path("cloud://", "CloudFileAccess", "CloudDirAccess")

nonchip avatar Oct 15 '24 06:10 nonchip

@adamscott Do you think it's possible to add memory based file system to this PR? A simple VFS so files can be used directly from memory like "memory://my_scene.tscn"

This? #98287

scgm0 avatar Oct 22 '24 04:10 scgm0

Is there anything we can help with to bring the moment of merge of this PR closer?

Also if I'm correct this PR and https://github.com/godotengine/godot/pull/98544 are related.

arkology avatar Mar 12 '25 07:03 arkology

Is there anything we can help with to bring the moment of merge of this PR closer?

Also if I'm correct this PR and #98544 are related.

They are not related; they simply implement the same proposal (https://github.com/godotengine/godot-proposals/issues/6307). This PR is based on the existing FileAccess & DirAccess, while #98544 opts to refactor the I/O system, replacing the current FileAccess & DirAccess.

scgm0 avatar Mar 12 '25 11:03 scgm0

I think it would be renamed to custom schemes. scheme://path See also https://en.wikipedia.org/wiki/Uniform_Resource_Identifier#Syntax

markushonok avatar Oct 16 '25 17:10 markushonok