misc/physfs/extras/hwpacksmounter.c
author koda
Wed, 20 Feb 2013 02:21:58 +0100
branchwebgl
changeset 8450 404ddce27b23
parent 8119 257ffa847aa2
permissions -rw-r--r--
add support for clang 3.3 (although there has to be a better way for this) and output right version number
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>
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
     4
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
     5
#include "hwpacksmounter.h"
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
     6
8119
257ffa847aa2 physfs: no carbon depency on osx, add cdecl attributes on extra functions
koda
parents: 8074
diff changeset
     7
PHYSFS_DECL void hedgewarsMountPackages()
8052
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
     8
{
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
     9
    char ** filesList = PHYSFS_enumerateFiles("/");
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    10
    char **i;
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    11
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    12
    for (i = filesList; *i != NULL; i++)
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    13
    {
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    14
        char * fileName = *i;
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    15
        int fileNameLength = strlen(fileName);
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    16
        if (fileNameLength > 4)
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    17
            if (strcmp(fileName + fileNameLength - 4, ".hwp") == 0)
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    18
            {
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    19
                const char * dir = PHYSFS_getRealDir(fileName);
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    20
                if(dir)
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    21
                {
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    22
                    char * fullPath = (char *)malloc(strlen(dir) + fileNameLength + 2);
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    23
                    strcpy(fullPath, dir);
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    24
                    strcat(fullPath, "/");
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    25
                    strcat(fullPath, fileName);
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    26
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    27
                    PHYSFS_mount(fullPath, NULL, 1);
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    28
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    29
                    free(fullPath);
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    30
                }
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
    PHYSFS_freeList(filesList);
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents:
diff changeset
    35
}