misc/libphyslayer/hwpacksmounter.c
author sheepluva
Wed, 22 Jan 2014 15:53:36 +0100
changeset 10052 6748866c94ee
parent 8978 e6ef8fe314bd
child 13393 ae5d6448c5be
permissions -rw-r--r--
fix server not building
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
8714
ab201a62d115 Prepend, not append
unc0rr
parents: 8524
diff changeset
    27
                    PHYSFS_mount(fullPath, NULL, 0);
8052
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
}
8978
e6ef8fe314bd suggestion of unc0rr's to fix issue w/ random maps in campaign. load sidecar packages in physfs for lua. should be useful also for lua that does custom layouts
nemo
parents: 8714
diff changeset
    36
e6ef8fe314bd suggestion of unc0rr's to fix issue w/ random maps in campaign. load sidecar packages in physfs for lua. should be useful also for lua that does custom layouts
nemo
parents: 8714
diff changeset
    37
PHYSFS_DECL void hedgewarsMountPackage(char * fileName)
e6ef8fe314bd suggestion of unc0rr's to fix issue w/ random maps in campaign. load sidecar packages in physfs for lua. should be useful also for lua that does custom layouts
nemo
parents: 8714
diff changeset
    38
{
e6ef8fe314bd suggestion of unc0rr's to fix issue w/ random maps in campaign. load sidecar packages in physfs for lua. should be useful also for lua that does custom layouts
nemo
parents: 8714
diff changeset
    39
    int fileNameLength = strlen(fileName);
e6ef8fe314bd suggestion of unc0rr's to fix issue w/ random maps in campaign. load sidecar packages in physfs for lua. should be useful also for lua that does custom layouts
nemo
parents: 8714
diff changeset
    40
    if (fileNameLength > 4)
e6ef8fe314bd suggestion of unc0rr's to fix issue w/ random maps in campaign. load sidecar packages in physfs for lua. should be useful also for lua that does custom layouts
nemo
parents: 8714
diff changeset
    41
        if (strcmp(fileName + fileNameLength - 4, ".hwp") == 0)
e6ef8fe314bd suggestion of unc0rr's to fix issue w/ random maps in campaign. load sidecar packages in physfs for lua. should be useful also for lua that does custom layouts
nemo
parents: 8714
diff changeset
    42
        {
e6ef8fe314bd suggestion of unc0rr's to fix issue w/ random maps in campaign. load sidecar packages in physfs for lua. should be useful also for lua that does custom layouts
nemo
parents: 8714
diff changeset
    43
            const char * dir = PHYSFS_getRealDir(fileName);
e6ef8fe314bd suggestion of unc0rr's to fix issue w/ random maps in campaign. load sidecar packages in physfs for lua. should be useful also for lua that does custom layouts
nemo
parents: 8714
diff changeset
    44
            if(dir)
e6ef8fe314bd suggestion of unc0rr's to fix issue w/ random maps in campaign. load sidecar packages in physfs for lua. should be useful also for lua that does custom layouts
nemo
parents: 8714
diff changeset
    45
            {
e6ef8fe314bd suggestion of unc0rr's to fix issue w/ random maps in campaign. load sidecar packages in physfs for lua. should be useful also for lua that does custom layouts
nemo
parents: 8714
diff changeset
    46
                char * fullPath = (char *)malloc(strlen(dir) + fileNameLength + 2);
e6ef8fe314bd suggestion of unc0rr's to fix issue w/ random maps in campaign. load sidecar packages in physfs for lua. should be useful also for lua that does custom layouts
nemo
parents: 8714
diff changeset
    47
                strcpy(fullPath, dir);
e6ef8fe314bd suggestion of unc0rr's to fix issue w/ random maps in campaign. load sidecar packages in physfs for lua. should be useful also for lua that does custom layouts
nemo
parents: 8714
diff changeset
    48
                strcat(fullPath, "/");
e6ef8fe314bd suggestion of unc0rr's to fix issue w/ random maps in campaign. load sidecar packages in physfs for lua. should be useful also for lua that does custom layouts
nemo
parents: 8714
diff changeset
    49
                strcat(fullPath, fileName);
e6ef8fe314bd suggestion of unc0rr's to fix issue w/ random maps in campaign. load sidecar packages in physfs for lua. should be useful also for lua that does custom layouts
nemo
parents: 8714
diff changeset
    50
e6ef8fe314bd suggestion of unc0rr's to fix issue w/ random maps in campaign. load sidecar packages in physfs for lua. should be useful also for lua that does custom layouts
nemo
parents: 8714
diff changeset
    51
                PHYSFS_mount(fullPath, NULL, 0);
e6ef8fe314bd suggestion of unc0rr's to fix issue w/ random maps in campaign. load sidecar packages in physfs for lua. should be useful also for lua that does custom layouts
nemo
parents: 8714
diff changeset
    52
e6ef8fe314bd suggestion of unc0rr's to fix issue w/ random maps in campaign. load sidecar packages in physfs for lua. should be useful also for lua that does custom layouts
nemo
parents: 8714
diff changeset
    53
                free(fullPath);
e6ef8fe314bd suggestion of unc0rr's to fix issue w/ random maps in campaign. load sidecar packages in physfs for lua. should be useful also for lua that does custom layouts
nemo
parents: 8714
diff changeset
    54
            }
e6ef8fe314bd suggestion of unc0rr's to fix issue w/ random maps in campaign. load sidecar packages in physfs for lua. should be useful also for lua that does custom layouts
nemo
parents: 8714
diff changeset
    55
        }
e6ef8fe314bd suggestion of unc0rr's to fix issue w/ random maps in campaign. load sidecar packages in physfs for lua. should be useful also for lua that does custom layouts
nemo
parents: 8714
diff changeset
    56
}