I’ve run into a situation where juce doesn’t seem to be able to tell the difference between an empty properties file and one that’s unreadable. This is a drag because I can’t tell whether a file contains a particular property or not. Something like:
PropertiesFile *foo = new PropertiesFile(unreadable_file_that_contains_property_bar,-1,PropertiesFile::storeAsXML);
// Do something
From looking through the code, it appears the root cause of this is that juce_fileRead doesn’t check the return value of ReadFile on windows. I can’t tell if the signature of juce_fileRead needs to change. juce_posix_SharedCode.h’s implementation of juce_fileRead does return what read() returns, so if callers that check the return value of juce_fileRead for -1 can learn about errors.
So maybe it’s enough to change juce_fileRead in juce_win32_Files.cpp to return -1 if ReadFile fails?
Though to get the info all the outside juce, we’d need more changes:
- FileInputStream::read checks the return value of juce_fileRead for < 0 and then either throws an exception or somehow communicates the error to the caller (signature change?). Given the number of places that would need to change, an exception seems like the way to go.
Assuming an exception, I might not need any other changes. I can wrap the call the the PropertiesFile constructor in a try/catch block and I think I’m all set.
If there’s a decent chance a patch like this would get applied, I’ll write it.