command[CONTROL::PAUSE] = 0;
}
-bool Config::isControl(CONTROL::TYPE type)
+bool Config::isControl(CONTROL::TYPE type) const
{
return command[type];
}
bool Config::loadJoystickConfig()
{
char filename[PATH_MAX];
- sprintf(filename, "%sjoystick.cfg", engine->userHomeDirectory);
+ snprintf(filename, sizeof filename, "%sjoystick.cfg", engine->userHomeDirectory);
debug(("Loading joystick config from %s\n", filename));
bool Config::saveJoystickConfig()
{
+ bool ret = true;
char filename[PATH_MAX];
- sprintf(filename, "%sjoystick.cfg", engine->userHomeDirectory);
+ snprintf(filename, sizeof filename, "%sjoystick.cfg", engine->userHomeDirectory);
debug(("Saving joystick config to %s\n", filename));
if (!fp)
{
- debug(("WARNING: Couldn't save joystick config\n"));
+ debug(("WARNING: Couldn't save joystick config: %s\n", strerror(errno)));
return false;
}
-
- fwrite(&joystick, sizeof(Joystick), 1, fp);
-
+
+ if (fwrite(&joystick, sizeof(Joystick), 1, fp) != 1)
+ {
+ debug(("WARNING: Couldn't save joystick config: %s\n", strerror(errno)));
+ ret = false;
+ }
+
fclose(fp);
- return true;
+ return ret;
}
bool Config::loadKeyConfig()
{
char filename[PATH_MAX];
- sprintf(filename, "%skeyboard.cfg", engine->userHomeDirectory);
+ snprintf(filename, sizeof filename, "%skeyboard.cfg", engine->userHomeDirectory);
debug(("Loading keyboard config from %s\n", filename));
fclose(fp);
return false;
}
-
- for (int i = 0; i < CONTROL::MAX; i++)
- {
- if (keyboard.control[i] < 0 || keyboard.control[i] >= 350)
- {
- fclose(fp);
- return false;
- }
- }
fclose(fp);
bool Config::saveKeyConfig()
{
+ bool ret = true;
char filename[PATH_MAX];
- sprintf(filename, "%skeyboard.cfg", engine->userHomeDirectory);
+ snprintf(filename, sizeof filename, "%skeyboard.cfg", engine->userHomeDirectory);
debug(("Saving keyboard config to %s\n", filename));
if (!fp)
{
+ debug(("WARNING: Couldn't save keyboard config: %s\n", strerror(errno)));
return false;
}
-
- fwrite(&keyboard, sizeof(keyboard), 1, fp);
-
+
+ if (fwrite(&keyboard, sizeof(keyboard), 1, fp) != 1)
+ {
+ debug(("WARNING: Couldn't save keyboard config: %s\n", strerror(errno)));
+ ret = false;
+ }
+
fclose(fp);
- return true;
+ return ret;
}
void Config::restoreKeyDefaults()