author | unC0Rr |
Tue, 10 Sep 2024 13:56:51 +0200 | |
branch | transitional_engine |
changeset 16032 | 31cc1e450273 |
parent 15817 | 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; |
|
15817 | 11 |
|
12 |
if (!filesList) return; |
|
8052 | 13 |
|
14 |
for (i = filesList; *i != NULL; i++) |
|
15 |
{ |
|
16 |
char * fileName = *i; |
|
17 |
int fileNameLength = strlen(fileName); |
|
18 |
if (fileNameLength > 4) |
|
19 |
if (strcmp(fileName + fileNameLength - 4, ".hwp") == 0) |
|
20 |
{ |
|
21 |
const char * dir = PHYSFS_getRealDir(fileName); |
|
22 |
if(dir) |
|
23 |
{ |
|
24 |
char * fullPath = (char *)malloc(strlen(dir) + fileNameLength + 2); |
|
25 |
strcpy(fullPath, dir); |
|
26 |
strcat(fullPath, "/"); |
|
27 |
strcat(fullPath, fileName); |
|
28 |
||
8714 | 29 |
PHYSFS_mount(fullPath, NULL, 0); |
8052 | 30 |
|
31 |
free(fullPath); |
|
32 |
} |
|
33 |
} |
|
34 |
} |
|
35 |
||
36 |
PHYSFS_freeList(filesList); |
|
37 |
} |
|
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
|
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 |
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
|
40 |
{ |
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 |
int fileNameLength = strlen(fileName); |
13393 | 42 |
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
|
43 |
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
|
44 |
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
|
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 |
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
|
47 |
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
|
48 |
{ |
13393 | 49 |
dirLength = strlen(dir); |
50 |
if (dirLength > 4) |
|
51 |
{ |
|
52 |
if (strcmp(dir + dirLength - 4, ".hwp") == 0) |
|
53 |
{ |
|
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
|
54 |
#if PHYSFS_VER_MAJOR > 2 || PHYSFS_VER_MINOR > 0 |
13393 | 55 |
char * uniqName = (char *)malloc(strlen(dir) + fileNameLength + 2); |
56 |
strcpy(uniqName, dir); |
|
57 |
strcat(uniqName, ","); |
|
58 |
strcat(uniqName, fileName); |
|
59 |
PHYSFS_mountHandle(PHYSFS_openRead(fileName), uniqName, NULL, 0); |
|
60 |
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
|
61 |
#endif |
13393 | 62 |
} |
63 |
else |
|
64 |
{ |
|
65 |
char * fullPath = (char *)malloc(strlen(dir) + fileNameLength + 2); |
|
66 |
strcpy(fullPath, dir); |
|
67 |
strcat(fullPath, "/"); |
|
68 |
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
|
69 |
|
13393 | 70 |
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
|
71 |
|
13393 | 72 |
free(fullPath); |
73 |
} |
|
74 |
} |
|
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
|
75 |
} |
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
|
76 |
} |
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
|
77 |
} |