Graphic_random and folder/file naming, possible refactor inside

Started by skullywag, August 20, 2015, 05:31:17 AM

Previous topic - Next topic

skullywag

This came up in the chat over on the modders slack. We can obviously work around it so this is in no way important, this is just to serve as a "if you want to fix it" type dealy.

When assigning graphic_random and you point to a folder, if you have a texture with the same starting string as the folder name in the same dir as the folder, the game will find the file and bomb out as its not a folder, for example textures/metal (folder) and textures/metalSomething (file) would error if the graphic_random texpath was set to textures/metal. A simple fix would be to check the attributes of the file to see if it is of type "Directory".


FileAttributes attr = File.GetAttributes(@"filename");

if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
    // its a folder
else
    // its a file


(my c# isnt the best, the above may not be perfect)

And also Tynan are you happy for possible refactors to be passed this way in this forum or would you prefer them somewhere else.
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?