Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 64431
Collapse All | Expand All

(-)include/config.h (-2 / +2 lines)
Lines 55-64 Link Here
55
};
55
};
56
56
57
// Load config from file
57
// Load config from file
58
void load_config(char *file, CONFIG *conf);
58
bool load_config(char *file, CONFIG *conf);
59
59
60
// Save config to file
60
// Save config to file
61
void save_config(char *file, CONFIG *conf);
61
bool save_config(char *file, CONFIG *conf);
62
62
63
#endif
63
#endif
64
64
(-)src/main.cpp (-2 / +12 lines)
Lines 22-30 Link Here
22
    3. This notice may not be removed or altered from any source
22
    3. This notice may not be removed or altered from any source
23
    distribution.
23
    distribution.
24
24
25
26
 Mika Halttunen <lsoft@mbnet.fi>
25
 Mika Halttunen <lsoft@mbnet.fi>
27
26
27
 09/22/2004 - Added support for ~/.tomatoesrc
28
              Greg Watson <gwatson@linuxlogin.com>
29
30
28
*************************************************************************/
31
*************************************************************************/
29
32
30
#include <stdlib.h>
33
#include <stdlib.h>
Lines 105-110 Link Here
105
108
106
// The good old main()
109
// The good old main()
107
int main(int argc, char *argv[]) {
110
int main(int argc, char *argv[]) {
111
	// filename for ~/.tomatoesrc
112
	char filename[255];
113
        strncpy(filename, getenv("HOME"), 200);
114
        strcat(filename, "/.tomatoesrc");
115
	
108
	// Initialize SDL and OpenGL
116
	// Initialize SDL and OpenGL
109
	init_sdl_and_gl();
117
	init_sdl_and_gl();
110
118
Lines 173-179 Link Here
173
	FSOUND_Close();
181
	FSOUND_Close();
174
182
175
	// Save the config
183
	// Save the config
176
	save_config("./config.cfg", &config);
184
	// Try ~/.tomatoesrc first
185
	if (!save_config(filename, &config))
186
		save_config("./config.cfg", &config);
177
	return 0;
187
	return 0;
178
}
188
}
179
189
(-)src/menu.cpp (-3 / +15 lines)
Lines 490-495 Link Here
490
	setting_key = false;
490
	setting_key = false;
491
	key_to_set = NULL;
491
	key_to_set = NULL;
492
	prev_key = 0;
492
	prev_key = 0;
493
	
494
	// buffer for filename for config file
495
	char filename[255];
496
497
498
	// make the filename = ~/.tomatoesrc		
499
	strncpy(filename, getenv("HOME"), 200);
500
	strcat(filename, "/.tomatoesrc");
493
501
494
	// Load the hiscores
502
	// Load the hiscores
495
	load_hiscore_list(HISCORE_FILE);
503
	load_hiscore_list(HISCORE_FILE);
Lines 611-617 Link Here
611
					mid_state_wait = 3 * 60;
619
					mid_state_wait = 3 * 60;
612
620
613
					// Restore the settings
621
					// Restore the settings
614
					load_config("./config.cfg", &config);
622
					if (!load_config(filename, &config))
623
						load_config("./config.cfg", &config);
615
					FSOUND_SetSFXMasterVolume(config.sound_vol);
624
					FSOUND_SetSFXMasterVolume(config.sound_vol);
616
					FMUSIC_SetMasterVolume(music_mod, config.music_vol);
625
					FMUSIC_SetMasterVolume(music_mod, config.music_vol);
617
				}
626
				}
Lines 697-703 Link Here
697
						mid_state = 1;
706
						mid_state = 1;
698
						mid_state_wait = 3 * 60;
707
						mid_state_wait = 3 * 60;
699
708
700
						save_config("./config.cfg", &config);
709
						// Try to write to ~/.tomatoesrc file first
710
						if (!save_config(filename, &config))
711
							save_config("./config.cfg", &config);
701
						break;
712
						break;
702
713
703
					case MENU_CANCEL:			// Cancel the changes
714
					case MENU_CANCEL:			// Cancel the changes
Lines 710-716 Link Here
710
						mid_state_wait = 3 * 60;
721
						mid_state_wait = 3 * 60;
711
722
712
						// Restore the settings
723
						// Restore the settings
713
						load_config("./config.cfg", &config);
724
						if (!load_config(filename, &config))
725
							load_config("./config.cfg", &config);
714
						FSOUND_SetSFXMasterVolume(config.sound_vol);
726
						FSOUND_SetSFXMasterVolume(config.sound_vol);
715
						FMUSIC_SetMasterVolume(music_mod, config.music_vol);
727
						FMUSIC_SetMasterVolume(music_mod, config.music_vol);
716
				}
728
				}
(-)src/init.cpp (-1 / +10 lines)
Lines 24-35 Link Here
24
24
25
25
26
 Mika Halttunen <lsoft@mbnet.fi>
26
 Mika Halttunen <lsoft@mbnet.fi>
27
  
28
 09/22/2004 - Added support for ~/.tomatoesrc instead of just ./config.cfg
29
	      Greg Watson <gwatson@linuxlogin.com>
27
30
28
*************************************************************************/
31
*************************************************************************/
29
32
30
#include <stdio.h>
33
#include <stdio.h>
31
#include <stdlib.h>
34
#include <stdlib.h>
32
#include <stdarg.h>
35
#include <stdarg.h>
36
#include <string.h>
33
37
34
#include "SDL.h"
38
#include "SDL.h"
35
#ifdef WIN32
39
#ifdef WIN32
Lines 85-93 Link Here
85
89
86
// Initialize SDL and OpenGL
90
// Initialize SDL and OpenGL
87
void init_sdl_and_gl() {
91
void init_sdl_and_gl() {
92
	char filename[255];
88
93
89
	// Load the config
94
	// Load the config
90
	load_config("./config.cfg", &config);
95
	// Check the users ~/.tomatoesrc first
96
	strncpy(filename, getenv("HOME"), 200);
97
	strcat(filename, "/.tomatoesrc");
98
	if (!load_config(filename, &config))
99
		load_config("./config.cfg", &config);
91
100
92
	// Check for 8-bit
101
	// Check for 8-bit
93
	if(config.vid_color_depth == 8)
102
	if(config.vid_color_depth == 8)
(-)src/config.cpp (-5 / +20 lines)
Lines 25-43 Link Here
25
25
26
 Mika Halttunen <lsoft@mbnet.fi>
26
 Mika Halttunen <lsoft@mbnet.fi>
27
27
28
 09/22/2004 - Changed functions to return bool on success/failure of 
29
	      load/save config.  Greg Watson <gwatson@linuxlogin.com>
30
28
*************************************************************************/
31
*************************************************************************/
29
32
30
#include <stdio.h>
33
#include <stdio.h>
34
#include <string.h>
31
#include "config.h"
35
#include "config.h"
32
#include "init.h"
36
#include "init.h"
33
37
34
38
35
// Load config from file
39
// Load config from file
36
void load_config(char *file, CONFIG *conf) {
40
bool load_config(char *file, CONFIG *conf) {
37
41
38
	FILE *f = fopen(file, "rt");
42
	FILE *f = fopen(file, "rt");
39
	if(!f)
43
	if (!f) {
40
		error_msg("Unable to load config file: %s!", file);
44
		// If we are not tying to load ~/.tomatoesrc, then 
45
		// abort program, since no config was found at all
46
		if (!strstr(file, "tomatoesrc")) 
47
			error_msg("Unable to load config file: %s!", file);
48
49
		// return false since we couldn't load
50
		return false;
51
	}
41
52
42
	fscanf(f, "video_mode = %d x %d\n", &(conf->vid_w), &(conf->vid_h));
53
	fscanf(f, "video_mode = %d x %d\n", &(conf->vid_w), &(conf->vid_h));
43
	fscanf(f, "video_mode_color_depth = %d\n", &(conf->vid_color_depth));
54
	fscanf(f, "video_mode_color_depth = %d\n", &(conf->vid_color_depth));
Lines 56-70 Link Here
56
	fscanf(f, "perspective = %d\n", &(conf->perspective_mode));
67
	fscanf(f, "perspective = %d\n", &(conf->perspective_mode));
57
	fscanf(f, "moving_style = %d\n", &(conf->moving_style));
68
	fscanf(f, "moving_style = %d\n", &(conf->moving_style));
58
	fclose(f);
69
	fclose(f);
70
	return true;
59
}
71
}
60
72
61
73
62
// Save config to file
74
// Save config to file
63
void save_config(char *file, CONFIG *conf) {
75
bool save_config(char *file, CONFIG *conf) {
64
76
65
	FILE *f = fopen(file, "wt");
77
	FILE *f = fopen(file, "wt");
66
	if(!f)
78
	if(!f) {
67
		error_msg("Unable to save config file: %s!", file);
79
		error_msg("Unable to save config file: %s!", file);
80
		return false;
81
	}
68
82
69
	fprintf(f, "video_mode = %d x %d\n", (conf->vid_w), (conf->vid_h));
83
	fprintf(f, "video_mode = %d x %d\n", (conf->vid_w), (conf->vid_h));
70
	fprintf(f, "video_mode_color_depth = %d\n", (conf->vid_color_depth));
84
	fprintf(f, "video_mode_color_depth = %d\n", (conf->vid_color_depth));
Lines 83-88 Link Here
83
	fprintf(f, "perspective = %d\n", (conf->perspective_mode));
97
	fprintf(f, "perspective = %d\n", (conf->perspective_mode));
84
	fprintf(f, "moving_style = %d\n", (conf->moving_style));
98
	fprintf(f, "moving_style = %d\n", (conf->moving_style));
85
	fclose(f);
99
	fclose(f);
100
	return true; 
86
}
101
}
87
102
88
103

Return to bug 64431