Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add checksum skip checkbox to settings window #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions flips-gtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -677,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;

Expand Down Expand Up @@ -763,15 +763,24 @@ 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);
gtk_main();

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)
Expand Down
17 changes: 12 additions & 5 deletions flips-w32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ struct {
unsigned char lastRomType;
bool openInEmulatorOnAssoc;
bool enableAutoRomSelector;
bool skipChecksum;
enum patchtype lastPatchType;
int windowleft;
int windowtop;
Expand Down Expand Up @@ -264,7 +265,7 @@ int a_ApplyPatch(LPCWSTR clipatchname)
if (*inromext && *outromext) wcscpy(outromext, inromext);
}
if (!SelectRom(outromname, TEXT("Select Output File"), true)) goto cancel;
struct errorinfo errinf=ApplyPatchMem(patch, inromname, true, outromname, NULL, state.enableAutoRomSelector);
struct errorinfo errinf=ApplyPatchMem(patch, inromname, !state.skipChecksum, outromname, NULL, state.enableAutoRomSelector);
delete patch;
MessageBoxA(hwndMain, errinf.description, flipsversion, mboxtype[errinf.level]);
return errinf.level;
Expand Down Expand Up @@ -334,7 +335,7 @@ int a_ApplyPatch(LPCWSTR clipatchname)
if (foundRom!=romname) canUseFoundRom=false;

wcscpy(GetExtension(thisFileName), GetExtension(romname));
struct errorinfo errinf=ApplyPatchMem(patch, romname, true, thisFileNameWithPath, NULL, true);
struct errorinfo errinf=ApplyPatchMem(patch, romname, !state.skipChecksum, thisFileNameWithPath, NULL, true);

if (errinf.level==el_broken) worsterror=max(worsterror, e_invalid);
if (errinf.level==el_notthis) worsterror=max(worsterror, e_no_auto);
Expand Down Expand Up @@ -410,7 +411,7 @@ int a_ApplyPatch(LPCWSTR clipatchname)
{
LPWSTR patchExtension=GetExtension(thisFileName);
wcscpy(patchExtension, romExtension);
struct errorinfo errinf=ApplyPatchMem2(patch, inrom, removeheaders, true, thisFileNameWithPath, NULL);
struct errorinfo errinf=ApplyPatchMem2(patch, inrom, removeheaders, !state.skipChecksum, thisFileNameWithPath, NULL);

if (errinf.level==el_broken) worsterror=max(worsterror, e_invalid);
if (errinf.level==el_notthis) worsterror=max(worsterror, e_invalid_this);
Expand Down Expand Up @@ -566,7 +567,7 @@ int a_ApplyRun(LPCWSTR clipatchname)
WCHAR outfilename[MAX_PATH];
GetFullPathName(outfilename_rel, MAX_PATH, outfilename, NULL);

errinf=ApplyPatchMem(patch, romname, true, outfilename, NULL, state.enableAutoRomSelector);
errinf=ApplyPatchMem(patch, romname, !state.skipChecksum, outfilename, NULL, state.enableAutoRomSelector);
error:

if (errinf.level!=el_ok) MessageBoxA(hwndMain, errinf.description, flipsversion, mboxtype[errinf.level]);
Expand Down Expand Up @@ -616,7 +617,7 @@ void a_ShowSettings()
hwndSettings=CreateWindowA(
"floatingmunchers", flipsversion,
WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_BORDER|WS_MINIMIZEBOX,
CW_USEDEFAULT, CW_USEDEFAULT, 3+6+202+6+3, 21 + 6+23+6+23+3+13+1+17+4+17+6 + 3, NULL, NULL, GetModuleHandle(NULL), NULL);
CW_USEDEFAULT, CW_USEDEFAULT, 3+6+202+6+3, 21 + 6+23+6+23+3+13+1+17+4+17+6 + 3+17+6 + 3, NULL, NULL, GetModuleHandle(NULL), NULL);

HFONT hfont=(HFONT)GetStockObject(DEFAULT_GUI_FONT);
HWND item;
Expand Down Expand Up @@ -674,6 +675,10 @@ void a_ShowSettings()
check("Enable automatic ROM selector", 202, 17, 105); Button_SetCheck(item, (state.enableAutoRomSelector));
endline(3);

line(17);
check("Ignore checksum when patching", 202, 17, 106); Button_SetCheck(item, (state.skipChecksum));
endline(3);

ShowWindow(hwndSettings, SW_SHOW);
#undef firstbutton
#undef button
Expand Down Expand Up @@ -782,6 +787,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
if (wParam==103) state.openInEmulatorOnAssoc=false;
if (wParam==104) state.openInEmulatorOnAssoc=true;
if (wParam==105) state.enableAutoRomSelector^=1;
if (wParam==106) state.skipChecksum^=1;
}
break;
case WM_CLOSE:
Expand Down Expand Up @@ -934,6 +940,7 @@ void GUILoadConfig()
state.lastRomType=0;
state.openInEmulatorOnAssoc=false;
state.enableAutoRomSelector=false;
state.skipChecksum=false;
state.lastPatchType=ty_bps;
state.windowleft=CW_USEDEFAULT;
state.windowtop=CW_USEDEFAULT;
Expand Down