Пример #1
0
    void parseRawUri(String rawUri, QChar sep, resourceclassid_t defaultResourceClass)
    {
        LOG_AS("Uri::parseRawUri");

        clearCachedResolved();

        scheme = extractScheme(rawUri); // scheme removed
        if(sep != '/') rawUri.replace(sep, '/'); // force slashes as separator
        path = rawUri;
        strPath = path.toString(); // for legacy code

        if(!scheme.isEmpty())
        {
            if(defaultResourceClass == RC_NULL || App_FileSystem().knownScheme(scheme))
            {
                // Scheme is accepted as is.
                return;
            }
            LOG_RES_WARNING("Unknown scheme \"%s\" for path \"%s\", using default scheme instead") << scheme << strPath;
        }

        // Attempt to guess the scheme by interpreting the path?
        if(defaultResourceClass == RC_UNKNOWN)
        {
            defaultResourceClass = DD_GuessFileTypeFromFileName(strPath).defaultClass();
        }

        if(VALID_RESOURCECLASSID(defaultResourceClass))
        {
            FS1::Scheme &fsScheme = App_FileSystem().scheme(ResourceClass::classForId(defaultResourceClass).defaultScheme());
            scheme = fsScheme.name();
        }
    }
Пример #2
0
/**
 * The path inside the zip might be mapped to another virtual location.
 *
 * @return  @c true= iff @a path was mapped to another location.
 *
 * @todo This is clearly implemented in the wrong place. Path mapping
 *       should be done at a higher level.
 */
static bool applyGamePathMappings(String &path)
{
    // Manually mapped to Defs?
    if (path.beginsWith('@'))
    {
        path.remove(0, 1);
        if (path.at(0) == '/') path.remove(0, 1);

        path = String("$(App.DefsPath)/$(GamePlugin.Name)/auto") / path;
        return true;
    }

    // Manually mapped to Data?
    if (path.beginsWith('#'))
    {
        path.remove(0, 1);
        if (path.at(0) == '/') path.remove(0, 1);

        // Is there a prefix to be omitted in the name?
        if (int slash = path.lastIndexOf('/'))
        {
            // The slash must not be too early in the string.
            if (slash >= 2)
            {
                // Good old negative indices.
                if (path.at(slash - 2) == '.' && path.at(slash - 1) >= '1' && path.at(slash - 1) <= '9')
                    path.remove(slash - 2, 2);
            }
        }

        path = String("$(App.DataPath)/$(GamePlugin.Name)/auto") / path;
        return true;
    }

    // Implicitly mapped to another location?
    if (!path.contains('/'))
    {
        // No directory separators; i.e., a root file.
        FileType const &ftype = DD_GuessFileTypeFromFileName(path.fileName());

        switch (ftype.defaultClass())
        {
        case RC_PACKAGE:
            // Mapped to the Data directory.
            path = String("$(App.DataPath)/$(GamePlugin.Name)/auto") / path;
            return true;

        case RC_DEFINITION:
            // Mapped to the Defs directory?
            path = String("$(App.DefsPath)/$(GamePlugin.Name)/auto") / path;
            return true;

        default:
            return false;
        }
    }

    // Key-named directories in the root might be mapped to another location.
    FS1::Schemes const &schemes = App_FileSystem().allSchemes();
    DENG2_FOR_EACH_CONST(FS1::Schemes, i, schemes)
    {
        if ((*i)->mapPath(path))
        {
            return true;
        }
    }
    return false;
}