Deleting files
by Dylan Sale · in Torque Game Engine · 02/17/2004 (7:38 am) · 4 replies
Hey guys.
Just wondering if anyone knew if torque was able to delete files within its game directories or whether I have to add support for it. Ive had a look over the file scripting functions but I cant see anything to do with deleting files there, so I assume it doesnt have support at the moment. Correct me if I am wrong however ;)
Dylan
Just wondering if anyone knew if torque was able to delete files within its game directories or whether I have to add support for it. Ive had a look over the file scripting functions but I cant see anything to do with deleting files there, so I assume it doesnt have support at the moment. Correct me if I am wrong however ;)
Dylan
About the author
#2
Oh and it works straight out of the box ;)
02/17/2004 (8:05 am)
Yes, yes it does help. I was just in the process of researching how to stop people deleting files outside of the game (having found the dFileDelete function). Thank you, you have also shown me something new about the Resource Manager :DOh and it works straight out of the box ;)
#3
If you find any problems with it please let me know so I can fix my version too :)
02/17/2004 (8:09 am)
No problem. If you find any problems with it please let me know so I can fix my version too :)
Torque 3D Owner Robert Blanchet Jr.
ConsoleFunction(deleteFile, bool, 2, 2, "deleteFile(fileName)") { argc; // in a writeable directory? char file[1024]; Con::expandScriptFilename(file, sizeof(file), argv[1]); if(!ResourceManager->isValidWriteFileName(file)) { Con::errorf("Unable to delete file '%s'...", argv[1]); return(false); } // free the resource from the manager and delete the file ResourceObject* obj = ResourceManager->find(file); if(!obj) { Con::errorf("Unable to delete file '%s'...", argv[1]); return(false); } else { // free the resource ResourceManager->freeResource(obj); // delete it from the sytem if(!dFileDelete(file)) { Con::errorf("Unable to delete the file '%s'...", argv[1]); return(false); } } // return success Con::warnf("Deleting file '%s'...", argv[1]); return(true); }As you can see the heart of it all is the dFileDelete call which can be traced back into the Platform:: functionality where it is actually implemented by the various platforms. I'm also checking for the file in the resource manager because I dont want to delete anything that isn't loaded by the game for security reasons.
Hope that helps.