misc/physfs/extras/hwpacksmounter.c
author koda
Tue, 20 Nov 2012 18:51:42 +0100
changeset 8074 768427321cab
parent 8052 845b5ae03841
child 8119 257ffa847aa2
permissions -rw-r--r--
thou shall not use system headers for crossplatformness

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "physfs.h"

#include "hwpacksmounter.h"

void hedgewarsMountPackages()
{
    char ** filesList = PHYSFS_enumerateFiles("/");
    char **i;

    for (i = filesList; *i != NULL; i++)
    {
        char * fileName = *i;
        int fileNameLength = strlen(fileName);
        if (fileNameLength > 4)
            if (strcmp(fileName + fileNameLength - 4, ".hwp") == 0)
            {
                const char * dir = PHYSFS_getRealDir(fileName);
                if(dir)
                {
                    char * fullPath = (char *)malloc(strlen(dir) + fileNameLength + 2);
                    strcpy(fullPath, dir);
                    strcat(fullPath, "/");
                    strcat(fullPath, fileName);

                    PHYSFS_mount(fullPath, NULL, 1);

                    free(fullPath);
                }
            }
    }

    PHYSFS_freeList(filesList);
}