Skip to content

Commit 0df4338

Browse files
committed
Add the "getConfigPathPrefix()" function in "consoleLib.c"
1 parent 86a9984 commit 0df4338

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

consoleLib.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,15 @@
138138
mkdir(name, 0755);
139139
}
140140

141+
void getConfigPathPrefix(char* dest) {
142+
strcpy(dest, getenv("HOME"));
143+
strcat(dest, "/.jddev0");
144+
makeDirectory(dest);
145+
strcat(dest, "/ConsoleSokoban");
146+
makeDirectory(dest);
147+
strcat(dest, "/");
148+
}
149+
141150
void sleepMS(unsigned int time) {
142151
usleep(time * 1000);
143152
}
@@ -374,6 +383,16 @@
374383
_mkdir(name);
375384
}
376385

386+
void getConfigPathPrefix(char* dest) {
387+
strcpy(dest, getenv("HOMEDRIVE"));
388+
strcat(dest, getenv("HOMEPATH"));
389+
strcat(dest, "/.jddev0");
390+
makeDirectory(dest);
391+
strcat(dest, "/ConsoleSokoban");
392+
makeDirectory(dest);
393+
strcat(dest, "/");
394+
}
395+
377396
void sleepMS(unsigned int time) {
378397
Sleep(time);
379398
}

consoleLib.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#define CONSOLE_LIB_H
33
#define CONSOLE_LIB_VER "v0.0.1"
44

5+
#define CONFIG_PATH_FOLDER "ConsoleSokoban"
6+
57
//Keys
68
//Arrow keys
79
#define CL_KEY_LEFT 5000
@@ -41,6 +43,8 @@
4143

4244
void makeDirectory(const char* name);
4345

46+
void getConfigPathPrefix(char* dest);
47+
4448
void sleepMS(unsigned int time);
4549

4650
void drawf(const char *restrict format, ...);

main.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,12 +1076,7 @@ void readLevelData(void) {
10761076
levelCount = 0;
10771077
}
10781078

1079-
strcpy(pathMapSaveData, getenv("HOME"));
1080-
strcat(pathMapSaveData, "/.jddev0");
1081-
makeDirectory(pathMapSaveData);
1082-
strcat(pathMapSaveData, "/ConsoleSokoban");
1083-
makeDirectory(pathMapSaveData);
1084-
strcat(pathMapSaveData, "/");
1079+
getConfigPathPrefix(pathMapSaveData);
10851080

10861081
char mapData[65536];
10871082
int mapDataByteOffset = 0;
@@ -1254,12 +1249,7 @@ void updateLevelPackStats(int levelPackIndex) {
12541249

12551250
int levelCountTmp = 100;
12561251

1257-
strcpy(pathMapSaveData, getenv("HOME"));
1258-
strcat(pathMapSaveData, "/.jddev0");
1259-
makeDirectory(pathMapSaveData);
1260-
strcat(pathMapSaveData, "/ConsoleSokoban");
1261-
makeDirectory(pathMapSaveData);
1262-
strcat(pathMapSaveData, "/");
1252+
getConfigPathPrefix(pathMapSaveData);
12631253

12641254
if(strlen(build_in_map_prefix) <= strlen(pathMapData[currentMapIndex]) &&
12651255
memcmp(build_in_map_prefix, pathMapData[currentMapIndex], strlen(build_in_map_prefix)) == 0) {

0 commit comments

Comments
 (0)