Skip to content

Commit

Permalink
Config reverts if apply failed (fixes #116)
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed Jul 3, 2013
1 parent 54ee673 commit 8769796
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/cdogs/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ extern Config gConfig;

void ConfigLoad(Config *config, const char *filename);
void ConfigSave(Config *config, const char *filename);
void ConfigApply(Config *config);
int ConfigApply(Config *config);
void ConfigLoadDefault(Config *config);
int ConfigGetVersion(FILE *f);

Expand Down
3 changes: 2 additions & 1 deletion src/cdogs/config_apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@
#include "gamedata.h"


void ConfigApply(Config *config)
int ConfigApply(Config *config)
{
BlitSetBrightness(config->Graphics.Brightness);
SoundReconfigure(&gSoundDevice, &config->Sound);
gCampaign.seed = config->Game.RandomSeed;
GraphicsInitialize(&gGraphicsDevice, &config->Graphics, 0);
return gGraphicsDevice.IsInitialized;
}
12 changes: 11 additions & 1 deletion src/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@ void MenuChangeIndex(menu_t *menu, int cmd)

void MenuActivate(menu_t *menu, int cmd)
{
Config lastConfig = gConfig;
SoundPlay(&gSoundDevice, SND_SWITCH);
switch (menu->type)
{
Expand Down Expand Up @@ -927,5 +928,14 @@ void MenuActivate(menu_t *menu, int cmd)
assert(0);
break;
}
ConfigApply(&gConfig);
if (!ConfigApply(&gConfig))
{
printf("Error: cannot apply new config; applying last config\n");
gConfig = lastConfig;
if (!ConfigApply(&gConfig))
{
printf("Error: cannot apply last config!\n");
exit(1);
}
}
}

0 comments on commit 8769796

Please sign in to comment.