Refresh VFS in "development mode"

Refresh VFS in "development mode"

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Refresh VFS in "development mode"

Post by gajop »

Is there any way to refresh VFS so it becomes aware of any files that have been added/removed?
Often when working on new features, I gradually add new files, and it's cumbersome to have to restart spring every time, when something like /luaui reload or /luarules reload should be enough. Require me to put "devel = true" in modinfo.lua if needs be.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Refresh VFS in "development mode"

Post by gajop »

This could also be useful outside of dev mode, for things like having an in-game load/save mechanism. Example of the scenario:
1) Person saves a game into a new file (this can be done using the built in os library)
2) Person wants to load a game, using VFS.DirList* to list existing files in a directory, one can only see old files, the new file wouldn't appear.

*VFS.DirList seems to be the only cross-platform way to list files in a directory in Spring, is there anything else? (the only libraries I found seem to require compiling, like f.e LFS)
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Refresh VFS in "development mode"

Post by jK »

The VFS has many `lenses` (to speak in unity terms). And the native fs lense, doesn't cache anything and always loads the current data.
So when your game files are in a .sdd, you can modify them at runtime. It's also the point of /luaxyz reload, /reloadcegs & /reloadcob.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Refresh VFS in "development mode"

Post by gajop »

I can modify existing files, sure, but it doesn't detect new files until restart.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Refresh VFS in "development mode"

Post by zwzsg »

gajop wrote:This could also be useful outside of dev mode, for things like having an in-game load/save mechanism. Example of the scenario:
1) Person saves a game into a new file (this can be done using the built in os library)
2) Person wants to load a game, using VFS.DirList* to list existing files in a directory, one can only see old files, the new file wouldn't appear.
Works for me! On step 2, I see the newly created file.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Refresh VFS in "development mode"

Post by gajop »

Odd, works for me too.
I'm 100% sure that it didn't work with images (to be used in chili components), and it didn't work with VFS.Include.

Btw, let's say I want to implement a save/load mechanic (or something similar). I can load files using VFS.LoadFile, which maps files as seen in the VFS.DirList (lua doesn't implement it's own directory listing function, so I have to rely on this).
However, how am I supposed to save a file (a string)? Using io.open doesn't work here, as it uses the OS fs, not the VFS one (directories just don't look the same).
Basically, I'd like a VFS.SaveFile(filename, stringData) function, or something that maps VFS path to OS path.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Refresh VFS in "development mode"

Post by gajop »

Btw, I'm still having this issue. I really want to mark it solved, it's kinda annoying:
Often when working on new features, I gradually add new files, and it's cumbersome to have to restart spring every time, when something like /luaui reload or /luarules reload should be enough. Require me to put "devel = true" in modinfo.lua if needs be.
Every time I add new lua files to my project I need to restart Spring, probably because how I include them, which is done by iterating through all paths of a VFS.DirList() and including them via VFS.Include(). Newly added files don't appear in VFS.DirList(), and they probably don't appear because I'm using VFS.DirList() without a VFS.RAW_ONLY param.

So VFS.DirList() can be used to get new files, but in order to do that VFS.RAW_ONLY must be used, even when working in an .sdd folder. Is this a bug or intended? Not a biggy for me, but it means I just need to use a prefix with "games/ToolBox.sdd", still seems off.
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: Refresh VFS in "development mode"

Post by Silentwings »

At some point in the past there was /editdefs but i've not made it work for a while.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Refresh VFS in "development mode"

Post by gajop »

So, uhm, bump!
I still need to restart Spring every time I add new files as part of the mod.
We really need a development mode that would allow files in VFS.MOD to be updated much like the VFS.RAW.
abma
Spring Developer
Posts: 3798
Joined: 01 Jun 2009, 00:08

Re: Refresh VFS in "development mode"

Post by abma »

gajop wrote:I still need to restart Spring every time I add new files as part of the mod.
imo this makes sense, as archives are "synced". are you trying to access the files from synced or from unsynced? i guess to update file list at c++ side currently RemoveArchive + AddArchive has to be called at least.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Refresh VFS in "development mode"

Post by gajop »

abma wrote:
gajop wrote:I still need to restart Spring every time I add new files as part of the mod.
imo this makes sense, as archives are "synced". are you trying to access the files from synced or from unsynced? i guess to update file list at c++ side currently RemoveArchive + AddArchive has to be called at least.
It happens in both cases when using accessing stuff via VFS.MOD.
While it's fine for .sdz, .sd7 and in the odd case when you are multiplayer testing an .sdd archive, I don't think it makes much sense for when you are developing. I find it analogous to restarting an IDE each time I add a file, which would be a bit annoying if you try to keep your code modular.
Post Reply

Return to “Lua Scripts”