misc/libphyslayer/hwpacksmounter.c
author nemo
Sat, 11 May 2013 21:50:14 -0400
changeset 8978 e6ef8fe314bd
parent 8714 ab201a62d115
child 13393 ae5d6448c5be
permissions -rw-r--r--
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

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

#include "hwpacksmounter.h"

PHYSFS_DECL 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, 0);

                    free(fullPath);
                }
            }
    }

    PHYSFS_freeList(filesList);
}

PHYSFS_DECL void hedgewarsMountPackage(char * fileName)
{
    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, 0);

                free(fullPath);
            }
        }
}