1 /*
2  * Zaz
3  * Copyright (C) Remigiusz Dybka 2009 <remigiusz.dybka@gmail.com>
4  *
5  Zaz is free software: you can redistribute it and/or modify it
6  under the terms of the GNU General Public License as published by the
7  Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  Zaz is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  See the GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef __SETTINGS_H__
20 #define __SETTINGS_H__
21 
22 #include <vector>
23 #include <string>
24 #include <map>
25 
26 #ifdef WIN32
27 #define ENVVAR	  "APPDATA"
28 #define SEPARATOR "\\"
29 #else
30 #define ENVVAR	  "HOME"
31 #define SEPARATOR "/"
32 #endif
33 
34 #define LANGENVVAR	"LANGUAGE"
35 
36 #define DEFAULT_FILENAME "settings"
37 #define HIGHSCORE_FILENAME "hiscores"
38 #define DEFAULT_DIRECTORY ".zaz"
39 #define LOCAL_DATADIR_NAME "data"
40 
41 #ifdef HAVE_CONFIG_H
42 #include "config.h"
43 #endif // HAVE_CONFIG_H
44 
45 using namespace std;
46 
47 namespace Scenes
48 {
49 class Settings
50 {
51 public:
52     string fileNameInUse;
53     Settings(string fileName = getDefaultFileName());
54 
55     const string get(const string name, const string defval);
56     bool getb(const string name, bool defval);
57     void set(const string name, const string value);
58     void setb(const string name, bool value);
59     void Save(string fileName = getDefaultFileName());
60     const string getDataDir();
61     const string getLocalDataDir();
62     string getFilename(string phname);
63     const char *getCFilename(string phname);
64     static string getDefaultDirectory(void);
65     static string getDefaultFileName(void);
66     static string getHighscoreFileName(void);
67     bool installed;
68     char *forcedDir; // holds directory specified by -d option
69 
70 #ifdef ENABLE_NLS
71     map<string, string> languages;
72     void setLanguage(string lang);
73 #endif
74 
75 #ifdef WIN32
76     // converts given filename in UTF-8 to a short filename
77     // if the file does not exist - return empty string
78     static string W32_GetFileName(string);
79 
80     // creates a file from UTF-8 string and returns it short form
81     static string W32_CreateFile(string);
82 #endif
83 
84 private:
85     void Load();
86 
87     map<string, string> cfg;
88 };
89 }
90 
91 #endif //__SETTINGS_H__
92