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 (IOFILE) |
---|
39 | { |
---|
40 | if (verbose >= 1) |
---|
41 | printf ("Saving settings to '%s'\n", local_config_file); |
---|
42 | |
---|
43 | fprintf (IOFILE, "%s\n", "Configuration file of orxonox (do not edit if ou do not know what you are doing)"); |
---|
44 | fprintf (IOFILE, "orxonox_settings->video_fullscreen = %i\n", orxonox_settings->video_fullscreen); |
---|
45 | fprintf (IOFILE, "orxonox_settings->video_wireframe = %i\n", orxonox_settings->video_wireframe); |
---|
46 | |
---|
47 | fprintf (IOFILE, "orxonox_settings->audio_enable_sound = %i\n", orxonox_settings->audio_enable_sound); |
---|
48 | fprintf (IOFILE, "orxonox_settings->audio_music_volume = %i\n", orxonox_settings->audio_music_volume); |
---|
49 | fprintf (IOFILE, "orxonox_settings->audio_effects_volume = %i\n", orxonox_settings->audio_effects_volume); |
---|
50 | |
---|
51 | fprintf (IOFILE, "orxonox_settings->exec_save_settings = %i\n", orxonox_settings->exec_save_settings); |
---|
52 | fprintf (IOFILE, "orxonox_settings->exec_show_menu = %i\n", orxonox_settings->exec_show_menu); |
---|
53 | |
---|
54 | fprintf (IOFILE, "orxonox_settings->verbose = %i\n", verbose); |
---|
55 | |
---|
56 | fclose( IOFILE ); |
---|
57 | return; |
---|
58 | } |
---|
59 | else |
---|
60 | { |
---|
61 | if (verbose >= 1) |
---|
62 | printf ("Settingsfile '%s' does not exist.\n", local_config_file); |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | void orxonox_gui_file_load (char *config_file, struct settings *orxonox_settings) |
---|
67 | { |
---|
68 | FILE *IOFILE; |
---|
69 | char variable[100]; |
---|
70 | char equals[5]; |
---|
71 | char value[100]; |
---|
72 | char buffer[100]; |
---|
73 | char local_config_file[1000]; |
---|
74 | |
---|
75 | sprintf(local_config_file,"%s", config_file); |
---|
76 | if (!strncmp (config_file, "~/", 2)) |
---|
77 | { |
---|
78 | char *homedir = getenv("HOME"); |
---|
79 | sprintf(buffer, local_config_file); |
---|
80 | sprintf (local_config_file,"%s/%s", homedir, buffer+2); |
---|
81 | } |
---|
82 | |
---|
83 | |
---|
84 | IOFILE = fopen(local_config_file, "r"); |
---|
85 | if (IOFILE) |
---|
86 | { |
---|
87 | if (verbose >= 1) |
---|
88 | printf ("Loading settings from '%s'\n", local_config_file); |
---|
89 | |
---|
90 | fscanf (IOFILE, "Configuration file of orxonox (do not edit if ou do not know what you are doing)"); |
---|
91 | while (fscanf (IOFILE,"%s %s %s", variable, equals, value) != EOF) |
---|
92 | { |
---|
93 | if ( !strcmp (variable, "orxonox_settings->video_fullscreen")) |
---|
94 | { |
---|
95 | orxonox_settings->video_fullscreen = atoi (value); |
---|
96 | } |
---|
97 | else if ( !strcmp (variable, "orxonox_settings->video_wireframe")) |
---|
98 | { |
---|
99 | orxonox_settings->video_wireframe = atoi (value); |
---|
100 | } |
---|
101 | |
---|
102 | else if ( !strcmp (variable, "orxonox_settings->audio_enable_sound")) |
---|
103 | { |
---|
104 | orxonox_settings->audio_enable_sound = atoi (value); |
---|
105 | } |
---|
106 | else if ( !strcmp (variable, "orxonox_settings->audio_music_volume")) |
---|
107 | { |
---|
108 | orxonox_settings->audio_music_volume = atoi (value); |
---|
109 | } |
---|
110 | else if ( !strcmp (variable, "orxonox_settings->audio_effects_volume")) |
---|
111 | { |
---|
112 | orxonox_settings->audio_effects_volume = atoi (value); |
---|
113 | } |
---|
114 | |
---|
115 | else if ( !strcmp (variable, "orxonox_settings->exec_save_settings")) |
---|
116 | { |
---|
117 | orxonox_settings->exec_save_settings = atoi (value); |
---|
118 | } |
---|
119 | else if ( !strcmp (variable, "orxonox_settings->exec_show_menu")) |
---|
120 | { |
---|
121 | orxonox_settings->exec_show_menu = atoi (value); |
---|
122 | } |
---|
123 | |
---|
124 | else if ( !strcmp (variable, "orxonox_settings->verbose")) |
---|
125 | { |
---|
126 | verbose = atoi (value); |
---|
127 | } |
---|
128 | |
---|
129 | } |
---|
130 | fclose( IOFILE ); |
---|
131 | return; |
---|
132 | } |
---|
133 | |
---|
134 | else |
---|
135 | { |
---|
136 | if (verbose >= 1) |
---|
137 | printf ("File '%s' does not exist. Can not load orxonox-states.\n", local_config_file); |
---|
138 | } |
---|
139 | } |
---|