3
* Copyright (C) Remigiusz Dybka 2009 <remigiusz.dybka@gmail.com>
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.
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.
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/>.
31
Profile::Profile(string _name)
39
name = getDefaultProfileName();
43
fileName = Scenes::Settings::getDefaultDirectory() + SEPARATOR + name + ".profile";
47
phile.open(Scenes::Settings::W32_GetFileName(fileName).c_str());
49
phile.open(fileName.c_str());
54
// if we create a new default profile, let's read in level progress
55
// from the settings file
58
Scenes::Settings sets;
59
for (int f = 1; f < 100; f++)
62
n << "level" << f << "_completed";
63
if (sets.getb(n.str() ,false))
66
n << MIGRATE_SET << ":" << f << ":completed";
77
while (getline(phile, cfgline))
79
int col = cfgline.find_last_of(":");
82
continue; // format error
84
string name = cfgline.substr(0, col);
85
string value = cfgline.substr(col + 1);
101
phile.open(Scenes::Settings::W32_CreateFile(fileName).c_str());
103
phile.open(fileName.c_str());
108
ERR("Could not save profile in " + fileName);
111
map<string, string>::iterator iter;
113
for (iter = cfg.begin(); iter != cfg.end(); ++iter)
115
string cfgline = iter->first;
117
cfgline.append(iter->second);
118
cfgline.append("\n");
126
const string Profile::get(const string name, const string defval)
128
if (!cfg.count(name))
134
void Profile::set(const string name, const string value)
139
bool Profile::getb(const string name, bool defval)
141
if (!cfg.count(name))
143
string val = defval?"TRUE":"FALSE";
150
//char buff[strlen(cfg[name].c_str()) + 1];
151
strcpy(buff, cfg[name].c_str());
152
int s = strlen(buff);
154
for (int f = 0; f < s; f++)
156
buff[f] = toupper(buff[f]);
159
if (!strcmp(buff, "TRUE"))
167
void Profile::setb(const string name, bool value)
169
string val = value?"TRUE":"FALSE";
173
string Profile::getDefaultProfileName()
176
char *r = getenv(ENVUSERNAME);
192
if (GetUserNameW(wu, &n))
194
char userName[n * 2];
195
if (WideCharToMultiByte(CP_UTF8, 0, wu, -1, userName, MAX_PATH * 2, NULL, NULL))
196
return string(userName);
199
return string(_("Anonymous"));