diff --git a/flips-gtk.cpp b/flips-gtk.cpp index 72c70a7..fb86493 100644 --- a/flips-gtk.cpp +++ b/flips-gtk.cpp @@ -356,7 +356,7 @@ static void ApplyPatchMultiAutoSub(gpointer data, gpointer user_data) gchar * outrompath=g_strndup(patchpath, strlen(patchpath)+strlen(romext)+1); strcpy(GetExtension(outrompath), romext); - struct errorinfo errinf=ApplyPatchMem(patch, rompath, true, outrompath, NULL, true); + struct errorinfo errinf=ApplyPatchMem(patch, rompath, !cfg.getint("skipchecksum"), outrompath, NULL, true); if (errinf.level==el_broken) error(ea_invalid); if (errinf.level==el_notthis) error(ea_no_auto); if (errinf.level==el_warning) error(ea_warning); @@ -433,7 +433,7 @@ static void ApplyPatchMulti(gpointer data, gpointer user_data) char * outromext=GetExtension(outromname); strcpy(outromext, state->romext); - struct errorinfo errinf=ApplyPatchMem2(patch, state->rommem, state->removeHeaders, true, outromname, NULL); + struct errorinfo errinf=ApplyPatchMem2(patch, state->rommem, state->removeHeaders, !cfg.getint("skipchecksum"), outromname, NULL); if (errinf.level==el_broken) error(e_invalid); if (errinf.level==el_notthis) error(e_invalid_this); if (errinf.level==el_warning) error(e_warning); @@ -486,7 +486,7 @@ static void a_ApplyPatch(GtkButton* widget, gpointer user_data) char * outromname=SelectRom(outromname_d, "Select Output File", true); if (outromname) { - struct errorinfo errinf=ApplyPatchMem(patchfile, inromname, true, outromname, NULL, cfg.getint("autorom")); + struct errorinfo errinf=ApplyPatchMem(patchfile, inromname, !cfg.getint("skipchecksum"), outromname, NULL, cfg.getint("autorom")); ShowMessage(errinf); } g_free(inromname); @@ -596,43 +596,8 @@ static void a_CreatePatch(GtkButton* widget, gpointer user_data) gtk_file_filter_add_pattern(filter, typeinfo[i].filter); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); } - gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filters[lasttype-1]); - - struct wrap { - GtkFileChooser* chooser; - GtkFileFilter** filters; - int current_filter_id; - - void notify(GObject* self, GParamSpec* pspec) - { - GtkFileFilter* filter = gtk_file_chooser_get_filter(chooser); - int new_filter_id = 0; - while (filter != filters[new_filter_id]) - new_filter_id++; - - const char * prev_ext = typeinfo[current_filter_id].filter+1; - const char * new_ext = typeinfo[new_filter_id].filter+1; - - char * current_name = gtk_file_chooser_get_current_name(chooser); - char * current_name_ext = strrchr(current_name, '.'); - if (!strcmp(current_name_ext, prev_ext)) - { - // good thing they're all the same length - strcpy(current_name_ext, new_ext); - gtk_file_chooser_set_current_name(chooser, current_name); - } - - g_free(current_name); - current_filter_id = new_filter_id; - } - static void notify_s(GObject* self, GParamSpec* pspec, void* userdata) - { - ((wrap*)userdata)->notify(self, pspec); - } - }; - wrap filter_updater = { GTK_FILE_CHOOSER(dialog), filters, lasttype-1 }; - g_signal_connect(dialog, "notify::filter", G_CALLBACK(&wrap::notify_s), &filter_updater); + gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filters[lasttype-1]); if (gtk_dialog_run(GTK_DIALOG(dialog))==GTK_RESPONSE_ACCEPT) { patchname=gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog)); @@ -643,8 +608,11 @@ static void a_CreatePatch(GtkButton* widget, gpointer user_data) { if (filter==filters[i]) { + if (patchname && lasttype!=i && !strcmp(GetExtension(patchname), typeinfo[lasttype-1].filter+1)) + { + strcpy(GetExtension(patchname), typeinfo[i].filter+1); + } cfg.setint("lasttype", i+1); - lasttype = i+1; } } @@ -709,7 +677,7 @@ static void a_ApplyRun(GtkButton* widget, gpointer user_data) else outromname=g_file_get_uri(outrom_file); g_object_unref(outrom_file); - struct errorinfo errinf=ApplyPatchMem(patchfile, romname, true, outromname, NULL, cfg.getint("autorom")); + struct errorinfo errinf=ApplyPatchMem(patchfile, romname, !cfg.getint("skipchecksum"), outromname, NULL, cfg.getint("autorom")); if (errinf.level!=el_ok) ShowMessage(errinf); if (errinf.level>=el_notthis) goto cleanup; @@ -795,6 +763,13 @@ static void a_ShowSettings(GtkButton* widget, gpointer user_data) gtk_grid_attach(grid, autoRom, 0,3, 1,1); flatpakDisable(autoRom); + GtkWidget* skipChecksum; + skipChecksum=gtk_check_button_new_with_mnemonic("Ignore checksum when patching"); + if (cfg.getint("skipchecksum")) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(skipChecksum), true); + g_object_ref(skipChecksum); + gtk_grid_attach(grid, skipChecksum, 0,4, 1,1); + flatpakDisable(skipChecksum); + gtk_container_add(GTK_CONTAINER(settingswindow), GTK_WIDGET(grid)); gtk_widget_show_all(settingswindow); @@ -802,8 +777,10 @@ static void a_ShowSettings(GtkButton* widget, gpointer user_data) cfg.setint("assocemu", (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(emuAssoc)))); cfg.setint("autorom", (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(autoRom)))); + cfg.setint("skipchecksum", (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(skipChecksum)))); g_object_unref(emuAssoc); g_object_unref(autoRom); + g_object_unref(skipChecksum); } static gboolean filterExecOnly(const GtkFileFilterInfo* filter_info, gpointer data)