CommandHelper

CommandHelper

46.5k Downloads

an option like "paths-are-relative"

LadyCailinBot opened this issue ยท 1 comments

commented

CMDHELPER-2769 - Reported by Hekta

What would you think of adding an option like "paths-are-relative" in preferences.ini, if false paths are absolute, default true ?

Presently files paths are always relative to the file that is being run, but in certain circumstances it can be difficult to find a file if the read() function is used in procedures or include() for example and if we can not always predict from which file(s) the procedure will be called.

Or otherwise, a "paths-are-relative-to-base-dir" option, if false paths are relative to the file that is being run.

commented

Comment by LadyCailin

I don't think a global option would be appropriate, because then you wouldn't be able to do mixed types on the same server. I do see your point though. I think ideally, you would be able to pass in an absolute path to the included file. You can get an absolute path to the current file with reflect_pull('file'), which you can then pass to the proc in the other file. If the file being read isn't relative to the file reading, then an absolute path makes sense, and in general, relative paths using "." have a tendency to obfuscate things anyways. Ideally, you always have an absolute path as the "base" that only the controller knows about, and internal libraries can use relative paths to that, but they don't know about that path inherently.

So anyways, I think I'm going to decline this feature, at least for now. File paths and file handling are a pain point in other languages, so I want to make sure to get it done right in mscript the first time. I will however, add a few functions to make file path management easier, for instance file_parent('/path/to/file') would return '/path/to/' and file_resolve('/path/../to/file') would return '/to/file'.

You may have noticed there's a fairly distinct lack of file handling functions, that's because file handling can very easily introduce a security risk to your server itself (not just the minecraft server) so I'm treading very carefully with that, and like I said, other languages make file handling far too hard, so I'm trying to fix that.