File: maplib.cpp

package info (click to toggle)
warzone2100 4.6.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 660,320 kB
  • sloc: cpp: 676,209; ansic: 391,201; javascript: 78,238; python: 16,632; php: 4,294; sh: 4,094; makefile: 2,629; lisp: 1,492; cs: 489; xml: 404; perl: 224; ruby: 156; java: 89
file content (89 lines) | stat: -rw-r--r-- 1,866 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "maplib.h"

void physfs_init(const char* binpath)
{
    PHYSFS_init(binpath);

    // Add cwd
    PHYSFS_setWriteDir(".");
    PHYSFS_mount(".", NULL, 1);
}

void physfs_shutdown()
{
    PHYSFS_deinit();
}

char* physfs_addmappath(char *path)
{
    char *p_path, *p_result;
    char *result;
    int length;

    result = (char *)malloc(PATH_MAX * sizeof(char));
    result[0] = '\0';
    p_result = result;
    
    length = strlen(path);
    if (length >= 3 && strcmp(&path[length-3], ".wz")==0)
    {
        PHYSFS_mount(path, NULL, 1);
            
        strcat(p_result, "multiplay/maps/");
        p_result += strlen("multiplay/maps/");        
        
        p_path = strrchr(path, PHYSFS_getDirSeparator()[0]);
        if (p_path)
        {
            // Remove the path
            p_path++;
            strcpy(p_result, p_path);

			path[strlen(path) - strlen(result) - 1] = '\0';
			PHYSFS_mount(path, NULL, 1);
        }
        else
        {
            strcpy(p_result, path);
        }

        // remove ".wz" from end
        length = strlen(result);
        result[length-3] = '\0';
    }
    else
    {
        if (PHYSFS_exists("multiplay/maps"))
        {
            strcat(p_result, "multiplay/maps/");
            p_result += strlen("multiplay/maps/");
        }

        p_path = strrchr(path, PHYSFS_getDirSeparator()[0]);
        if (p_path)
        {
            // Remove the path
            p_path++;
            strcpy(p_result, p_path);
        }
        else
        {
            strcpy(p_result, path);
        }        
    }

    return result;
}

void physfs_printSearchPath()
{
    char ** i, ** searchPath;

    debug(0, "%s", "Search paths:");
    searchPath = PHYSFS_getSearchPath();
    for (i = searchPath; *i != NULL; i++)
    {
        debug(0, "    [%s]", *i);
    }
    PHYSFS_freeList(searchPath);
}