Previous 15994 Revisions Next

r1053 Sunday 30th September, 2007 at 00:08:45 UTC by Nathan Woods
[Windows GUI] Changed to use options_output_diff_ini_file(); allowing the MESS
GUI to work again
[src/osd/winui]m32opts.c

src/osd/winui/m32opts.c
r1052r1053
6565// static void LoadFolderFilter(int folder_index,int filters);
6666
6767static file_error LoadSettingsFile(core_options *opts, const char *filename);
68static file_error SaveSettingsFile(core_options *opts, const char *filename);
68static file_error SaveSettingsFile(core_options *opts, core_options *baseopts, const char *filename);
6969
7070static void LoadOptionsAndSettings(void);
7171
r1052r1053
8888
8989static void ui_parse_ini_file(core_options *opts, const char *name);
9090static BOOL add_options_entry(core_options *opts, const options_entry *entry);
91static core_options * options_prune(core_options *opts1, core_options *opts2);
9291static void remove_all_source_options(void);
9392
9493
r1052r1053
22622261}
22632262
22642263
2265static file_error SaveSettingsFile(core_options *opts, const char *filename)
2264static file_error SaveSettingsFile(core_options *opts, core_options *baseopts, const char *filename)
22662265{
22672266   core_file *file;
22682267   file_error filerr;
22692268
2270   if (opts != NULL)
2269   if ((opts != NULL) && ((baseopts == NULL) || !options_equal(opts, baseopts)))
22712270   {
22722271      filerr = core_fopen(filename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file);
22732272      if (filerr == FILERR_NONE)
22742273      {
2275         options_output_ini_file(opts, file);
2274         options_output_diff_ini_file(opts, baseopts, file);
22762275         core_fclose(file);
22772276      }
22782277   }
r1052r1053
26032602      core_options *opts = AddFolderFlags(settings);
26042603      // Save opts if it is non-null, else save settings.
26052604      // It will be null if there are no filters set.
2606      SaveSettingsFile((opts == NULL) ? settings : opts, UI_INI_FILENAME);
2605      SaveSettingsFile((opts == NULL) ? settings : opts, NULL, UI_INI_FILENAME);
26072606      // Free up the opts allocated by AddFolderFlags.
26082607      if (opts)
26092608      {
r1052r1053
26172616{
26182617   char buffer[MAX_PATH];
26192618   GetGlobalOptionsFileName(buffer, ARRAY_LENGTH(buffer));
2620   SaveSettingsFile(global, buffer);
2619   SaveSettingsFile(global, NULL, buffer);
26212620}
26222621
26232622char * GetVersionString(void)
r1052r1053
27832782}
27842783
27852784/*
2786 * return new core_options with only the differences contained in opts
2787 * different from the values in defaults.
2788 */
2789static core_options * options_prune(core_options *opts1, core_options *opts2)
2790{
2791   const options_entry *entry;
2792   core_options *pruned_options = options_create(memory_error);
2793   int changes = 0;
2794   char name[40];
2795
2796   // walk the core options
2797   entry = mame_core_options;
2798   while (entry->name != NULL || (entry->flags & OPTION_HEADER))
2799   {
2800      if (entry->name != NULL)
2801      {
2802         char *ptr;
2803         const char *value1, *value2;
2804
2805         strcpy(name, entry->name);
2806         // Trim off from ;altname
2807         if ((ptr = strchr(name, ';')) != NULL)
2808            *ptr = '\0';
2809         // Trim off from (min-max)
2810         if ((ptr = strchr(name, '(')) != NULL)
2811            *ptr = '\0';
2812
2813         value1 = options_get_string(opts1, name);
2814         value2 = options_get_string(opts2, name);
2815
2816         if (value1 != NULL  && value2 != NULL)
2817         {
2818            if (strcmp(value1, value2) != 0)
2819            {
2820               if (add_options_entry(pruned_options, entry))
2821               {
2822                  options_set_string(pruned_options, name, value1, OPTION_PRIORITY_CMDLINE);
2823                  changes++;
2824               }
2825            }
2826         }
2827      }
2828      entry++;
2829   }
2830
2831   // walk the win options
2832   entry = mame_win_options;
2833   while (entry->name != NULL || (entry->flags & OPTION_HEADER))
2834   {
2835      if (entry->name != NULL)
2836      {
2837         char *ptr;
2838         const char *value1, *value2;
2839
2840         strcpy(name, entry->name);
2841         // Trim off from ;altname
2842         if ((ptr = strchr(name, ';')) != NULL)
2843            *ptr = '\0';
2844         // Trim off from (min-max)
2845         if ((ptr = strchr(name, '(')) != NULL)
2846            *ptr = '\0';
2847
2848         value1 = options_get_string(opts1, name);
2849         value2 = options_get_string(opts2, name);
2850
2851         if (value1 != NULL  && value2 != NULL)
2852         {
2853            if (strcmp(value1, value2) != 0)
2854            {
2855               if (add_options_entry(pruned_options, entry))
2856               {
2857                  options_set_string(pruned_options, name, value1, OPTION_PRIORITY_CMDLINE);
2858                  changes++;
2859               }
2860            }
2861         }
2862      }
2863      entry++;
2864   }
2865
2866   // no changes made
2867   if (0 == changes)
2868   {
2869      options_free(pruned_options);
2870      pruned_options = NULL;
2871   }
2872   return pruned_options;
2873}
2874
2875/*
28762785 * Save ini file based on game_num and passed in opt_type.  If opts are
28772786 * NULL, the ini wiil be removed.
28782787 *
r1052r1053
28812790 */
28822791void save_options(OPTIONS_TYPE opt_type, core_options *opts, int game_num)
28832792{
2884
2793   core_options *baseopts = NULL;
28852794   const game_driver *driver = NULL;
28862795   astring *filename = NULL;
2887   core_options *save_options = NULL;
2888   BOOL use_opts = TRUE;
28892796
28902797   if (OPTIONS_GLOBAL != opt_type && NULL != opts && !options_equal(opts, global))
28912798   {
2892      core_options *default_options = load_options(opt_type - 1, game_num);
2893      save_options = options_prune(opts, default_options);
2894      options_free(default_options);
2895      use_opts = FALSE;
2799      baseopts = load_options(opt_type - 1, game_num);
28962800   }
28972801
28982802   if (game_num >= 0)
r1052r1053
29412845      filepath = astring_assemble_4(astring_alloc(), GetIniDir(), PATH_SEPARATOR, astring_c(filename), ".ini");
29422846      astring_free(filename);
29432847
2944      SaveSettingsFile((use_opts) ? opts : save_options, astring_c(filepath));
2848      SaveSettingsFile(opts, baseopts, astring_c(filepath));
29452849      astring_free(filepath);
29462850   }
2947   if (NULL != save_options)
2851   if (baseopts != NULL)
29482852   {
2949      options_free(save_options);
2853      options_free(baseopts);
29502854   }
29512855}
29522856

Previous 15994 Revisions Next


© 1998-2018 The MESS Team