Author Topic: CFile system  (Read 2535 times)

0 Members and 1 Guest are viewing this topic.

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Sorta request... Can any one give any hints on how to read files? Also how to use paths

Tried the above and though i could create new files (though only to the current mod directory) filled with text content very easily i was unable to load any existing ones. Also the fileExists gave pretty much null for every single file that i tried even for the one that  was created (and closed) by the very same script as well as for other files in the same directory. Same goes with 'string Path' option... Does it refer to the current directory (ie. mod dir), main freespace directory? something else? And more importantly is it something that is not platform dependant?

Also the mouse control options currently using io library seem to be interfering (overriding) Lua's own io library so certain amount of inbuild lua functions can not be used - or at least so it seems.
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Whoops to that. It's probably too late to update the io library. OTOH, I'm not sure if I want the entire Lua IO library available for general consumption; it makes it possible to rename and delete files on other portions of the hard drive, which makes scripting much more of a risk on Windows computers, or other OSes with lax filesystem security. Not appropriate for a game scripting system at all.

CFile, on the other hand, has a number of issues. First, it has problems when you try to look for file types that aren't hardcoded as enabled. Thus, you can do fileExists() on an ogg in the root directory or a mod directory and it'll come up positive, but if you try it with a .tbm, it won't work. Similarly, if you make your own filetypes, CFile just won't deal with them; although it'll probably open them for writing.

Another problem with CFile is that when doing rename, write, etc. - basically any operation, really, but the ones that make changes are the most critical - you can't specify which directory it happens in. Thus, you can run fileExists() on a .ogg in the main directory, but if you try to rename it, it'll try to rename it as if it existed in your primary mod directory - and promptly fail. The same problem exists for deleteFile().

So two things need to be done with CFile:
  • Enable support for other file extensions beyond the hardcoded ones. (This limitation exists to speed up indexing)
    It looks like this is possible on a limited basis using the _ext functions that Goober added. I'll have to update some internal CFile functions, but nothing core or critical to the rest of the system.
  • Modify the rename and delete functions to support mods properly.
    This looks a bit more difficult. Probably involving a new function or changes to critical functions like cf_create_default_path_string to (a) work in the same precedence as the exists function, and (b) allow you to specify the mod folder (For things like opening files and creating directories)
-C

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
check the old mouse script, it had a sorta cheap way of reading settings from a file, and creating a file when none was present.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
It looks like it doesn't actually get around either of those two problems though, does it? Although it's interesting to me that you were able to load the .cfg file from the root directory. From what I saw while testing, that shouldn't be possible.
-C

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
the config file the mouse script made usually ended up in the mod's root directory (mod being my script_dev folder under freespace root). i did not try putting it anywhere else. it might take relative paths though.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN