ID:160221
 
Suppose you load up a file using:
mob/verb/LoadFile(file as null|file)

That will let you grab a file from pretty much anywhere and stuff it into your program. Now, once loaded, that file has a small change made to it and it needs to be saved. How would you do that? Can you do that?

The only thing I can think of is to load the file into a variable, modify it, delete the original and save it again, except things like fdel() and text2file() which are what I'm using don't really let you effect a file, they only let you effect things happening in the program's directory.

So if my program is located at:
C:\Stuff\MyProgram

And I load up a file from:
C:\Goodies\MyStuff

But I need to make a change to that file and save those changes, is there any way that I can save that file back at C:\Goodies\MyStuff, or am I stuck with just creating a new file in the C:\Stuff\MyProgram directory or subdirectories?


The reason I'm asking this is that I want players to be able to load up custom maps, earn high scores on them, and have those high scores saved to the map files. Then whenever the map is loaded again, those high scores will still be there.
Modifying/deleting files outside the project's directory/subdirectories is a security risk, so you can understand it'd always be restricetd unless running in trusted mode. Also, bear in mind you can only mess with the host's computer/files, not the players, but this does seem to be what you want anyway.
This might not be doable* unless the player types in the path to the directory in the game or something, because you need it to tell a proc (probably text2file() only...) which file to access, and I don't know how you can get the path to the file from the code, if you even can (you can get the filename only AFAIK).

*: Of course, it'd always be pretty easily doable with something external like a small program run through shell(), or a DLL file you call().
FTP() it to yourself and overwrite the old file.
In response to Kaioken
Unless your DLL lives in the host's BYOND\bin, you're looking at trusted mode again for that.
The problem here, unfortunately, is not with the output functionality, but rather with the input functionality. I imagine (but haven't actually checked or tested) that you could use Hobnob's File I/O library (ID:667898) to write to an arbitrary file on the system, but actually finding that file is an issue. The following snippet demonstrates:
client/verb/Test(f as null|file)
if(f)
src << "You selected '[f]'."


Instead of saying "You selected 'C:\...\file.extension'.", it says "You selected 'file.extension', which means you have no way of finding this file on their system without manually scanning every directory.