示例#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
void *WAV_Load(char const *filename, int *bits, int *rate, int *samples)
{
    try
    {
        // Relative paths are relative to the native working directory.
        de::String path = (de::NativePath::workPath() / de::NativePath(filename).expand()).withSeparators('/');
        QScopedPointer<de::FileHandle> hndl(&App_FileSystem().openFile(path, "rb"));

        // Read in the whole thing.
        size_t size = hndl->length();

        LOG_AS("WAV_Load");
        LOGDEV_RES_XVERBOSE("Loading from \"%s\" (size %i, fpos %i)")
                << de::NativePath(hndl->file().composePath()).pretty()
                << size
                << hndl->tell();

        uint8_t *data = (uint8_t *) M_Malloc(size);

        hndl->read(data, size);
        App_FileSystem().releaseFile(hndl->file());

        // Parse the RIFF data.
        void *sampledata = WAV_MemoryLoad((byte const *) data, size, bits, rate, samples);
        if(!sampledata)
        {
            LOG_RES_WARNING("Failed to load \"%s\"") << filename;
        }

        M_Free(data);
        return sampledata;
    }
    catch(de::FS1::NotFoundError const &)
    {} // Ignore.
    return 0;
}
示例#3
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;
}
示例#4
0
File1::~File1()
{
    App_FileSystem().releaseFile(*this);
    if(handle_) delete handle_;
}