Change data path to comply with XDG specs for data
This commit is contained in:
parent
78ae4bb292
commit
00a67602dd
1 changed files with 8 additions and 5 deletions
13
main.cpp
13
main.cpp
|
@ -161,13 +161,13 @@ void gameOver(int score){
|
||||||
printf("Input your name (without spaces!) and press ENTER to return to main menu.");
|
printf("Input your name (without spaces!) and press ENTER to return to main menu.");
|
||||||
SetCursorPosition((paMaxX/2)-19,(paMaxY/2)+6);
|
SetCursorPosition((paMaxX/2)-19,(paMaxY/2)+6);
|
||||||
printf("Enter you name: ");
|
printf("Enter you name: ");
|
||||||
//Save player scores at $HOME/.config/cursedSnakeGameScores
|
//Save player scores at $HOME/.local/share/cursedSnakeGameScores
|
||||||
FILE *cmd=popen("echo -n $HOME", "r");
|
FILE *cmd=popen("echo -n $HOME", "r");
|
||||||
char result[100]={0x0};
|
char result[100]={0x0};
|
||||||
fgets(result, sizeof(result), cmd);
|
fgets(result, sizeof(result), cmd);
|
||||||
pclose(cmd);
|
pclose(cmd);
|
||||||
string fullpath=result;
|
string fullpath=result;
|
||||||
fullpath+="/.config/cursedSnakeGameScores";
|
fullpath+="/.local/share/cursedSnakeGameScores";
|
||||||
|
|
||||||
FILE *fptr = fopen(fullpath.c_str(),"a");
|
FILE *fptr = fopen(fullpath.c_str(),"a");
|
||||||
if (fptr == NULL)
|
if (fptr == NULL)
|
||||||
|
@ -306,7 +306,8 @@ int mainMenu() {
|
||||||
|
|
||||||
void showScores() {
|
void showScores() {
|
||||||
endwin();
|
endwin();
|
||||||
system("sort $HOME/.config/cursedSnakeGameScores -nr > $HOME/.config/cursedSnakeGameScores.tmp && mv $HOME/.config/cursedSnakeGameScores.tmp $HOME/.config/cursedSnakeGameScores");
|
system("if [[ ! -f $HOME/.local/share/cursedSnakeGameScores ]]; then touch $HOME/.local/share/cursedSnakeGameScores; fi");
|
||||||
|
system("sort $HOME/.local/share/cursedSnakeGameScores -nr > $HOME/.local/share/cursedSnakeGameScores.tmp && mv $HOME/.local/share/cursedSnakeGameScores.tmp $HOME/.local/share/cursedSnakeGameScores");
|
||||||
int line=0,currentLine=0;
|
int line=0,currentLine=0;
|
||||||
char c; //UserInputCharacter
|
char c; //UserInputCharacter
|
||||||
FILE *cmd=popen("echo -n $HOME", "r");
|
FILE *cmd=popen("echo -n $HOME", "r");
|
||||||
|
@ -314,11 +315,13 @@ void showScores() {
|
||||||
fgets(result, sizeof(result), cmd);
|
fgets(result, sizeof(result), cmd);
|
||||||
pclose(cmd);
|
pclose(cmd);
|
||||||
string fullpath=result;
|
string fullpath=result;
|
||||||
fullpath+="/.config/cursedSnakeGameScores";
|
fullpath+="/.local/share/cursedSnakeGameScores";
|
||||||
|
|
||||||
FILE *fptr = fopen(fullpath.c_str(),"r");
|
FILE *fptr = fopen(fullpath.c_str(),"r");
|
||||||
if(fptr == NULL) {
|
if(fptr == NULL) {
|
||||||
perror("Error in opening file");
|
perror("Error in opening file, creating data file.");
|
||||||
|
system("touch $HOME/.local/share/cursedSnakeGameScores");
|
||||||
|
sleep(3);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
|
|
Loading…
Reference in a new issue