Skip to content

Commit

Permalink
Add the "getConfigPathPrefix()" function in "consoleLib.c"
Browse files Browse the repository at this point in the history
  • Loading branch information
JDDev0 committed Oct 31, 2024
1 parent 86a9984 commit 0df4338
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
19 changes: 19 additions & 0 deletions consoleLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@
mkdir(name, 0755);
}

void getConfigPathPrefix(char* dest) {
strcpy(dest, getenv("HOME"));
strcat(dest, "/.jddev0");
makeDirectory(dest);
strcat(dest, "/ConsoleSokoban");
makeDirectory(dest);
strcat(dest, "/");
}

void sleepMS(unsigned int time) {
usleep(time * 1000);
}
Expand Down Expand Up @@ -374,6 +383,16 @@
_mkdir(name);
}

void getConfigPathPrefix(char* dest) {
strcpy(dest, getenv("HOMEDRIVE"));
strcat(dest, getenv("HOMEPATH"));
strcat(dest, "/.jddev0");
makeDirectory(dest);
strcat(dest, "/ConsoleSokoban");
makeDirectory(dest);
strcat(dest, "/");
}

void sleepMS(unsigned int time) {
Sleep(time);
}
Expand Down
4 changes: 4 additions & 0 deletions consoleLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define CONSOLE_LIB_H
#define CONSOLE_LIB_VER "v0.0.1"

#define CONFIG_PATH_FOLDER "ConsoleSokoban"

//Keys
//Arrow keys
#define CL_KEY_LEFT 5000
Expand Down Expand Up @@ -41,6 +43,8 @@

void makeDirectory(const char* name);

void getConfigPathPrefix(char* dest);

void sleepMS(unsigned int time);

void drawf(const char *restrict format, ...);
Expand Down
14 changes: 2 additions & 12 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1076,12 +1076,7 @@ void readLevelData(void) {
levelCount = 0;
}

strcpy(pathMapSaveData, getenv("HOME"));
strcat(pathMapSaveData, "/.jddev0");
makeDirectory(pathMapSaveData);
strcat(pathMapSaveData, "/ConsoleSokoban");
makeDirectory(pathMapSaveData);
strcat(pathMapSaveData, "/");
getConfigPathPrefix(pathMapSaveData);

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

int levelCountTmp = 100;

strcpy(pathMapSaveData, getenv("HOME"));
strcat(pathMapSaveData, "/.jddev0");
makeDirectory(pathMapSaveData);
strcat(pathMapSaveData, "/ConsoleSokoban");
makeDirectory(pathMapSaveData);
strcat(pathMapSaveData, "/");
getConfigPathPrefix(pathMapSaveData);

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

0 comments on commit 0df4338

Please sign in to comment.