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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8052
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
     1
#include <string.h>
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
     2
#include <stdio.h>
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
     3
#include <stdlib.h>
8074
768427321cab thou shall not use system headers for crossplatformness
koda
parents: 8052
diff changeset
     4
#include "physfs.h"
8052
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
     5
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
     6
#include "hwpacksmounter.h"
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
     7
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
     8
void hedgewarsMountPackages()
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
     9
{
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    10
    char ** filesList = PHYSFS_enumerateFiles("/");
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    11
    char **i;
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    12
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    13
    for (i = filesList; *i != NULL; i++)
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    14
    {
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    15
        char * fileName = *i;
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    16
        int fileNameLength = strlen(fileName);
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    17
        if (fileNameLength > 4)
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    18
            if (strcmp(fileName + fileNameLength - 4, ".hwp") == 0)
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    19
            {
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    20
                const char * dir = PHYSFS_getRealDir(fileName);
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    21
                if(dir)
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    22
                {
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    23
                    char * fullPath = (char *)malloc(strlen(dir) + fileNameLength + 2);
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    24
                    strcpy(fullPath, dir);
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    25
                    strcat(fullPath, "/");
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    26
                    strcat(fullPath, fileName);
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    27
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    28
                    PHYSFS_mount(fullPath, NULL, 1);
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    29
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    30
                    free(fullPath);
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    31
                }
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    32
            }
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    33
    }
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    34
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    35
    PHYSFS_freeList(filesList);
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    36
}