Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 71 lines (57 sloc) 2.796 kb
cd298d6 @DusteDdk terrible mess
authored
1 /************************************************************************
2 * This file is part of Wizznic. *
e61c024 @DusteDdk Updated copyleft header.
authored
3 * Copyright 2009-2012 Jimmy Christensen <dusted@dusted.dk> *
cd298d6 @DusteDdk terrible mess
authored
4 * Wizznic is free software: you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation, either version 3 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * Wizznic is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
aa80153 @DusteDdk Nuked all windows newlines.
authored
15 * along with Wizznic. If not, see <http://www.gnu.org/licenses/>. *
cd298d6 @DusteDdk terrible mess
authored
16 ************************************************************************/
17
540ed40 @DusteDdk Initial commit
authored
18 #include "userfiles.h"
19
20
21 #include <sys/stat.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <stdlib.h>
25
26 static char* strConfDir;
27 static char* strEditLvlDir;
28 static char* strHsDir;
29
30 void initUserPaths()
31 {
32 #ifdef PER_USER_FILES
33
34 //Generate directory string
35 if(getenv("XDG_CONFIG_HOME") != NULL)
36 {
37 strConfDir = malloc( sizeof(char)*(strlen(getenv("XDG_CONFIG_HOME"))+strlen("/wizznic"))+1 );
38 sprintf( strConfDir, "%s/wizznic", getenv("XDG_CONFIG_HOME") );
39 } else if( getenv("HOME") != NULL)
40 {
41 strConfDir = malloc( sizeof(char)*(strlen(getenv("HOME"))+strlen("/.wizznic"))+1 );
42 sprintf( strConfDir, "%s/.wizznic", getenv("HOME") );
43 } else {
44 strConfDir = malloc(sizeof(char)*strlen(".")+1);
45 sprintf( strConfDir, "." );
46 }
47
48
49 #else
50 strConfDir = malloc(sizeof(char)*strlen(".")+1);
51 sprintf( strConfDir, "." );
52 #endif
53
54 strEditLvlDir = malloc( sizeof(char)*( strlen(strConfDir)+strlen("/editorlevels")+1 ) );
55 sprintf( strEditLvlDir, "%s/editorlevels", strConfDir );
56
57 strHsDir = malloc( sizeof(char)*( strlen(strConfDir)+strlen("/highscores")+1 ) );
58 sprintf( strHsDir, "%s/highscores", strConfDir );
59
60 //Check if dir exists (we check each dir, since ./ might exist without the others
61 struct stat s;
62 if (stat(strConfDir,&s) != 0) mkdir(strConfDir,S_IRWXU);
63 if (stat(strEditLvlDir,&s) != 0) mkdir(strEditLvlDir,S_IRWXU);
64 if (stat(strHsDir,&s) != 0) mkdir(strHsDir,S_IRWXU);
65
66 }
67
68 char* getConfigDir() { return( strConfDir ); }
69 char* getHighscoreDir() { return( strHsDir ); }
70 char* getUserLevelDir() { return( strEditLvlDir ); }
Something went wrong with that request. Please try again.