src/osd/winui/m32opts.c
| r1052 | r1053 | |
| 65 | 65 | // static void LoadFolderFilter(int folder_index,int filters); |
| 66 | 66 | |
| 67 | 67 | static file_error LoadSettingsFile(core_options *opts, const char *filename); |
| 68 | | static file_error SaveSettingsFile(core_options *opts, const char *filename); |
| 68 | static file_error SaveSettingsFile(core_options *opts, core_options *baseopts, const char *filename); |
| 69 | 69 | |
| 70 | 70 | static void LoadOptionsAndSettings(void); |
| 71 | 71 | |
| r1052 | r1053 | |
| 88 | 88 | |
| 89 | 89 | static void ui_parse_ini_file(core_options *opts, const char *name); |
| 90 | 90 | static BOOL add_options_entry(core_options *opts, const options_entry *entry); |
| 91 | | static core_options * options_prune(core_options *opts1, core_options *opts2); |
| 92 | 91 | static void remove_all_source_options(void); |
| 93 | 92 | |
| 94 | 93 | |
| r1052 | r1053 | |
| 2262 | 2261 | } |
| 2263 | 2262 | |
| 2264 | 2263 | |
| 2265 | | static file_error SaveSettingsFile(core_options *opts, const char *filename) |
| 2264 | static file_error SaveSettingsFile(core_options *opts, core_options *baseopts, const char *filename) |
| 2266 | 2265 | { |
| 2267 | 2266 | core_file *file; |
| 2268 | 2267 | file_error filerr; |
| 2269 | 2268 | |
| 2270 | | if (opts != NULL) |
| 2269 | if ((opts != NULL) && ((baseopts == NULL) || !options_equal(opts, baseopts))) |
| 2271 | 2270 | { |
| 2272 | 2271 | filerr = core_fopen(filename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file); |
| 2273 | 2272 | if (filerr == FILERR_NONE) |
| 2274 | 2273 | { |
| 2275 | | options_output_ini_file(opts, file); |
| 2274 | options_output_diff_ini_file(opts, baseopts, file); |
| 2276 | 2275 | core_fclose(file); |
| 2277 | 2276 | } |
| 2278 | 2277 | } |
| r1052 | r1053 | |
| 2603 | 2602 | core_options *opts = AddFolderFlags(settings); |
| 2604 | 2603 | // Save opts if it is non-null, else save settings. |
| 2605 | 2604 | // 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); |
| 2607 | 2606 | // Free up the opts allocated by AddFolderFlags. |
| 2608 | 2607 | if (opts) |
| 2609 | 2608 | { |
| r1052 | r1053 | |
| 2617 | 2616 | { |
| 2618 | 2617 | char buffer[MAX_PATH]; |
| 2619 | 2618 | GetGlobalOptionsFileName(buffer, ARRAY_LENGTH(buffer)); |
| 2620 | | SaveSettingsFile(global, buffer); |
| 2619 | SaveSettingsFile(global, NULL, buffer); |
| 2621 | 2620 | } |
| 2622 | 2621 | |
| 2623 | 2622 | char * GetVersionString(void) |
| r1052 | r1053 | |
| 2783 | 2782 | } |
| 2784 | 2783 | |
| 2785 | 2784 | /* |
| 2786 | | * return new core_options with only the differences contained in opts |
| 2787 | | * different from the values in defaults. |
| 2788 | | */ |
| 2789 | | static 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 | | /* |
| 2876 | 2785 | * Save ini file based on game_num and passed in opt_type. If opts are |
| 2877 | 2786 | * NULL, the ini wiil be removed. |
| 2878 | 2787 | * |
| r1052 | r1053 | |
| 2881 | 2790 | */ |
| 2882 | 2791 | void save_options(OPTIONS_TYPE opt_type, core_options *opts, int game_num) |
| 2883 | 2792 | { |
| 2884 | | |
| 2793 | core_options *baseopts = NULL; |
| 2885 | 2794 | const game_driver *driver = NULL; |
| 2886 | 2795 | astring *filename = NULL; |
| 2887 | | core_options *save_options = NULL; |
| 2888 | | BOOL use_opts = TRUE; |
| 2889 | 2796 | |
| 2890 | 2797 | if (OPTIONS_GLOBAL != opt_type && NULL != opts && !options_equal(opts, global)) |
| 2891 | 2798 | { |
| 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); |
| 2896 | 2800 | } |
| 2897 | 2801 | |
| 2898 | 2802 | if (game_num >= 0) |
| r1052 | r1053 | |
| 2941 | 2845 | filepath = astring_assemble_4(astring_alloc(), GetIniDir(), PATH_SEPARATOR, astring_c(filename), ".ini"); |
| 2942 | 2846 | astring_free(filename); |
| 2943 | 2847 | |
| 2944 | | SaveSettingsFile((use_opts) ? opts : save_options, astring_c(filepath)); |
| 2848 | SaveSettingsFile(opts, baseopts, astring_c(filepath)); |
| 2945 | 2849 | astring_free(filepath); |
| 2946 | 2850 | } |
| 2947 | | if (NULL != save_options) |
| 2851 | if (baseopts != NULL) |
| 2948 | 2852 | { |
| 2949 | | options_free(save_options); |
| 2853 | options_free(baseopts); |
| 2950 | 2854 | } |
| 2951 | 2855 | } |
| 2952 | 2856 | |