1 | #include <sys/stat.h> |
---|
2 | #include "orxonox_gui_file.h" |
---|
3 | |
---|
4 | |
---|
5 | void orxonox_gui_file_default (struct settings *orxonox_settings) |
---|
6 | { |
---|
7 | if (verbose >= 1) |
---|
8 | printf("Setting orxonox to it's default settings.\n"); |
---|
9 | |
---|
10 | orxonox_settings->video_fullscreen = 1; |
---|
11 | orxonox_settings->video_wireframe = 0; |
---|
12 | |
---|
13 | orxonox_settings->audio_enable_sound = 1; |
---|
14 | orxonox_settings->audio_music_volume = 80; |
---|
15 | orxonox_settings->audio_effects_volume = 80; |
---|
16 | |
---|
17 | orxonox_settings->exec_save_settings = 1; |
---|
18 | orxonox_settings->exec_show_menu = 0; |
---|
19 | |
---|
20 | return; |
---|
21 | } |
---|
22 | |
---|
23 | void orxonox_gui_file_save (char *config_file, struct settings *orxonox_settings) |
---|
24 | { |
---|
25 | FILE *IOFILE; |
---|
26 | char local_config_file[1000]; |
---|
27 | |
---|
28 | sprintf(local_config_file,"%s", config_file); |
---|
29 | if (!strncmp (local_config_file,"~/", 2)) |
---|
30 | { |
---|
31 | char buffer[100]; |
---|
32 | char *homedir = getenv("HOME"); |
---|
33 | sprintf(buffer, local_config_file); |
---|
34 | sprintf (local_config_file,"%s/%s", homedir,buffer+2); |
---|
35 | } |
---|
36 | |
---|
37 | IOFILE = fopen( local_config_file, "w"); |
---|
38 | if (verbose >= 1) |
---|
39 | printf ("Saving settings to %s\n", local_config_file); |
---|
40 | |
---|
41 | fprintf (IOFILE, "%s\n", "Configuration file of orxonox (do not edit if ou do not know what you are doing)"); |
---|
42 | fprintf (IOFILE, "orxonox_settings->video_fullscreen = %i\n", orxonox_settings->video_fullscreen); |
---|
43 | fprintf (IOFILE, "orxonox_settings->video_wireframe = %i\n", orxonox_settings->video_wireframe); |
---|
44 | |
---|
45 | fprintf (IOFILE, "orxonox_settings->audio_enable_sound = %i\n", orxonox_settings->audio_enable_sound); |
---|
46 | fprintf (IOFILE, "orxonox_settings->audio_music_volume = %i\n", orxonox_settings->audio_music_volume); |
---|
47 | fprintf (IOFILE, "orxonox_settings->audio_effects_volume = %i\n", orxonox_settings->audio_effects_volume); |
---|
48 | |
---|
49 | fprintf (IOFILE, "orxonox_settings->exec_save_settings = %i\n", orxonox_settings->exec_save_settings); |
---|
50 | fprintf (IOFILE, "orxonox_settings->exec_show_menu = %i\n", orxonox_settings->exec_show_menu); |
---|
51 | |
---|
52 | fprintf (IOFILE, "orxonox_settings->verbose = %i\n", verbose); |
---|
53 | |
---|
54 | fclose( IOFILE ); |
---|
55 | return; |
---|
56 | } |
---|
57 | |
---|
58 | void orxonox_gui_file_load (char *config_file, struct settings *orxonox_settings) |
---|
59 | { |
---|
60 | FILE *IOFILE; |
---|
61 | char variable[100]; |
---|
62 | char equals[5]; |
---|
63 | char value[100]; |
---|
64 | char buffer[100]; |
---|
65 | char local_config_file[1000]; |
---|
66 | |
---|
67 | sprintf(local_config_file,"%s", config_file); |
---|
68 | if (!strncmp (config_file, "~/", 2)) |
---|
69 | { |
---|
70 | char *homedir = getenv("HOME"); |
---|
71 | sprintf(buffer, local_config_file); |
---|
72 | sprintf (local_config_file,"%s/%s", homedir, buffer+2); |
---|
73 | } |
---|
74 | |
---|
75 | |
---|
76 | IOFILE = fopen(local_config_file, "r"); |
---|
77 | if (verbose >= 1) |
---|
78 | printf ("Loading settings from '%s'\n", local_config_file); |
---|
79 | |
---|
80 | fscanf (IOFILE, "Configuration file of orxonox (do not edit if ou do not know what you are doing)"); |
---|
81 | while (fscanf (IOFILE,"%s %s %s", variable, equals, value) != EOF) |
---|
82 | { |
---|
83 | if ( !strcmp (variable, "orxonox_settings->video_fullscreen")) |
---|
84 | { |
---|
85 | orxonox_settings->video_fullscreen = atoi (value); |
---|
86 | } |
---|
87 | else if ( !strcmp (variable, "orxonox_settings->video_wireframe")) |
---|
88 | { |
---|
89 | orxonox_settings->video_wireframe = atoi (value); |
---|
90 | } |
---|
91 | |
---|
92 | else if ( !strcmp (variable, "orxonox_settings->audio_enable_sound")) |
---|
93 | { |
---|
94 | orxonox_settings->audio_enable_sound = atoi (value); |
---|
95 | } |
---|
96 | else if ( !strcmp (variable, "orxonox_settings->audio_music_volume")) |
---|
97 | { |
---|
98 | orxonox_settings->audio_music_volume = atoi (value); |
---|
99 | } |
---|
100 | else if ( !strcmp (variable, "orxonox_settings->audio_effects_volume")) |
---|
101 | { |
---|
102 | orxonox_settings->audio_effects_volume = atoi (value); |
---|
103 | } |
---|
104 | |
---|
105 | else if ( !strcmp (variable, "orxonox_settings->exec_save_settings")) |
---|
106 | { |
---|
107 | orxonox_settings->exec_save_settings = atoi (value); |
---|
108 | } |
---|
109 | else if ( !strcmp (variable, "orxonox_settings->exec_show_menu")) |
---|
110 | { |
---|
111 | orxonox_settings->exec_show_menu = atoi (value); |
---|
112 | } |
---|
113 | |
---|
114 | else if ( !strcmp (variable, "orxonox_settings->verbose")) |
---|
115 | { |
---|
116 | verbose = atoi (value); |
---|
117 | } |
---|
118 | |
---|
119 | } |
---|
120 | fclose( IOFILE ); |
---|
121 | return; |
---|
122 | } |
---|
123 | |
---|