char *GetFileDataByName(SimpleArchive *archive, const char *fileName, Allocator *allocator)
{
    int idx = GetIdxFromName(archive, fileName);
    if (-1 != idx)
        return GetFileDataByIdx(archive, idx, allocator);
    return NULL;
}
static bool ExtractFileByIdx(SimpleArchive *archive, int idx, const char *dstDir, Allocator *allocator)
{
    FileInfo *fi = &archive->files[idx];

    char *uncompressed = GetFileDataByIdx(archive, idx, allocator);
    if (!uncompressed)
        return false;

    bool ok = false;
    char *filePath = path::JoinUtf(dstDir, fi->name, allocator);
    if (filePath)
        ok = file::WriteAllUtf(filePath, uncompressed, fi->uncompressedSize);

    Allocator::Free(allocator, filePath);
    Allocator::Free(allocator, uncompressed);

    return ok;
}
bool ExtractFileByIdx(SimpleArchive *archive, int idx, const char *dstDir, Allocator *allocator)
{
    bool ok;
    const char *filePath = NULL;
    FileInfo *fi = &archive->files[idx];

    char *uncompressed = GetFileDataByIdx(archive, idx, allocator);
    if (!uncompressed)
        goto Error;

    const char *fileName = fi->name;
    filePath = path::JoinUtf(dstDir, fileName, allocator);

    ok = file::WriteAllUtf(filePath, uncompressed, fi->uncompressedSize);
Exit:
    Allocator::Free(allocator, (void*)filePath);
    Allocator::Free(allocator, uncompressed);
    return ok;
Error:
    ok = false;
    goto Exit;
}
Exemple #4
0
char *ArchFile::GetFileDataByName(const WCHAR *fileName, size_t *len)
{
    return GetFileDataByIdx(GetFileIndex(fileName), len);
}