CC: Tweaked

CC: Tweaked

57M Downloads

[Java API] Methode to retrieve real file path for given computer path

MadddinTribleD opened this issue ยท 4 comments

commented

There should be a simple way to retrieve the real file path (in world folder) for a given computer path via the IFileSystem-api.

Currently the IFileSystem only allows checking if a file or directory exists.

This results in a addon developer, that need the real file path, to use reflection on members of FileSystemWrapperMount and other private classes only to to get the path.

A other way i currently use is to create a temporary file, open it for read and use reflection on the returned FileChannelImpl. Here is an example:

String path = "/test/sub/"
fileSystem.openChannelForWrite(path + "helpfile").close();
ReadableByteChannel channel = fileSystem.openChannelForRead(path + "helpfile");
String realPath = ReflectionHelper.getPrivateValue(FileChannelImpl.class, (FileChannelImpl)channel, "path");
commented

Can you explain why you need access to the underlying file path? We intentionally hide that sort of information, as it means we can control how the mount is used (and so ensure that the computer's storage capacity is not overreached).

commented

I currently write a addon that lets you use git in lua.
To execute commands on a git-repository that lays in a computer-directory i convert the computer-directory to the real path and use JGit to interact with that repository.

To clarify: I dont want to access the real path via lua. Only via Java

commented

JGit is something we discussed when implementing this functionality. It should be possible to implement a Repository which sits over CC's filesystem abstraction (see, for instance InMemoryRepository). That said, I don't think anyone has tried, so I'd be curious as to how feasible it'd actually be.

commented

Ok i think i came up with a good solution.

I could instead of using a directory in the computer, make a own IWritableMount that uses my own directory.
In the computer it would show up in the location the user specified.
So if the user writes to it, it will check if there is enought space for writing and fail if there is not.
If the user clones/checks out a repo, i would after the operation is complete check the size and either mount it Readonly or unmount it completely (could be a config option i guess).

So i would not really need to interact with the filesystem of CC and dont need the path.