Jassertfalse in File paths


#1

Now, if your app is multiplatform (Projucer for example) and you happen to have Mac paths defined in it while you debug on Windows, juce_File.cpp asserts all the time…

The code checks if the machine runs on Windows or Mac and wrongly assumes that all paths should match the OS format of the compiler.

See in juce_File.cpp

String File::parseAbsolutePath (const String& p)
{
    if (p.isEmpty())
        return String();
#if JUCE_WINDOWS
    // Windows..
    String path (removeEllipsis (p.replaceCharacter ('/', '\\')));
    if (path.startsWithChar (separator))
    {
        if (path[1] != separator)
        {
            /*  When you supply a raw string to the File object constructor, it must be an absolute path.
                If you're trying to parse a string that may be either a relative path or an absolute path,
                you MUST provide a context against which the partial path can be evaluated - you can do
                this by simply using File::getChildFile() instead of the File constructor. E.g. saying
                "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
                path if that's what was supplied, or would evaluate a partial path relative to the CWD.
            */
            jassertfalse;

Would it be possible to remove this jassertfalse or add a flag to remove it when appropriate?
Thanks


#2

For me this assert is very helpful to stop me to use File the wrong way.

You can use String for relative paths, and when you construct an actual file path, i.e. because you want to access them in the next step, you start with the File::SpecialLocationType factory: File::getSpecialLocation (const SpecialLocationType type).

It is very errore prone to assume the default constructor of File to represent a certain path.

A File according to the docs "Represents a local file or directory. ". IMHO this is the only approach that makes sure, that the file CAN actually exist in a deterministic place in the file system. How should the system know, if the path should start with a drive letter, or a slash, or anything else?

Take full profit by using the abstraction layer provided by SpecialLocations.