author | alfadur |
Sun, 04 Nov 2018 04:39:21 +0300 | |
changeset 14147 | 32383b888309 |
parent 13395 | fa81f809fbb9 |
child 15839 | 0defc1d3261d |
permissions | -rw-r--r-- |
8052 | 1 |
#include <string.h> |
2 |
#include <stdio.h> |
|
3 |
#include <stdlib.h> |
|
4 |
||
5 |
#include "hwpacksmounter.h" |
|
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 | 8 |
{ |
9 |
char ** filesList = PHYSFS_enumerateFiles("/"); |
|
10 |
char **i; |
|
11 |
||
12 |
for (i = filesList; *i != NULL; i++) |
|
13 |
{ |
|
14 |
char * fileName = *i; |
|
15 |
int fileNameLength = strlen(fileName); |
|
16 |
if (fileNameLength > 4) |
|
17 |
if (strcmp(fileName + fileNameLength - 4, ".hwp") == 0) |
|
18 |
{ |
|
19 |
const char * dir = PHYSFS_getRealDir(fileName); |
|
20 |
if(dir) |
|
21 |
{ |
|
22 |
char * fullPath = (char *)malloc(strlen(dir) + fileNameLength + 2); |
|
23 |
strcpy(fullPath, dir); |
|
24 |
strcat(fullPath, "/"); |
|
25 |
strcat(fullPath, fileName); |
|
26 |
||
8714 | 27 |
PHYSFS_mount(fullPath, NULL, 0); |
8052 | 28 |
|
29 |
free(fullPath); |
|
30 |
} |
|
31 |
} |
|
32 |
} |
|
33 |
||
34 |
PHYSFS_freeList(filesList); |
|
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); |
13393 | 40 |
int dirLength = 0; |
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
|
41 |
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
|
42 |
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
|
43 |
{ |
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 |
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
|
45 |
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
|
46 |
{ |
13393 | 47 |
dirLength = strlen(dir); |
48 |
if (dirLength > 4) |
|
49 |
{ |
|
50 |
if (strcmp(dir + dirLength - 4, ".hwp") == 0) |
|
51 |
{ |
|
13395
fa81f809fbb9
IFDEF for Phys 2.0 which has no mountHandle - result will just be no hwp in hwp on those systems, which would be rarely used and DLC only.
nemo
parents:
13393
diff
changeset
|
52 |
#if PHYSFS_VER_MAJOR > 2 || PHYSFS_VER_MINOR > 0 |
13393 | 53 |
char * uniqName = (char *)malloc(strlen(dir) + fileNameLength + 2); |
54 |
strcpy(uniqName, dir); |
|
55 |
strcat(uniqName, ","); |
|
56 |
strcat(uniqName, fileName); |
|
57 |
PHYSFS_mountHandle(PHYSFS_openRead(fileName), uniqName, NULL, 0); |
|
58 |
free(uniqName); |
|
13395
fa81f809fbb9
IFDEF for Phys 2.0 which has no mountHandle - result will just be no hwp in hwp on those systems, which would be rarely used and DLC only.
nemo
parents:
13393
diff
changeset
|
59 |
#endif |
13393 | 60 |
} |
61 |
else |
|
62 |
{ |
|
63 |
char * fullPath = (char *)malloc(strlen(dir) + fileNameLength + 2); |
|
64 |
strcpy(fullPath, dir); |
|
65 |
strcat(fullPath, "/"); |
|
66 |
strcat(fullPath, fileName); |
|
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
|
67 |
|
13393 | 68 |
PHYSFS_mount(fullPath, NULL, 0); |
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
|
69 |
|
13393 | 70 |
free(fullPath); |
71 |
} |
|
72 |
} |
|
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
|
73 |
} |
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
|
74 |
} |
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
|
75 |
} |