From 875de91fcea73cd4f3f326e824f4979e95c44826 Mon Sep 17 00:00:00 2001 From: doug Date: Mon, 5 Dec 2011 03:35:33 +0000 Subject: [PATCH] Fixed a few things that allow it to compile and run on Windows: 1) htonl() and htons() are declared in winsock.h on Windows and require ws2_32 to be linked in. 2) mingw does not have asprintf, so I changed the Qt GUI to use QString's sprintf() member function which should behave identically. 3) Windows Vista and 7 try to run any program with "patch" in the name with administrative privileges for backwards compatibility with legacy stuff, so I added a build step to the Qt app to embed a manifest. I also need to do the same thing with the cli app... --- Makefile.win | 5 +++++ cli/Makefile.inc | 2 +- lib/checksum.c | 4 ++++ lib/locate_drvr.c | 4 ++++ qtgui/RomPatcher.cpp | 3 +-- qtgui/RomPatcher.manifest | 10 ++++++++++ qtgui/RomPatcher.pro | 5 +++++ qtgui/RomPatcher.rc | 2 ++ 8 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 Makefile.win create mode 100644 qtgui/RomPatcher.manifest create mode 100644 qtgui/RomPatcher.rc diff --git a/Makefile.win b/Makefile.win new file mode 100644 index 0000000..cbe70b6 --- /dev/null +++ b/Makefile.win @@ -0,0 +1,5 @@ +# Windows requires -lws2_32 for htons(), htonl(), etc. +# Use make -f Makefile.win to use this Makefile, which adds +# the required library to the LDFLAGS. +LDFLAGS += -lws2_32 +include Makefile \ No newline at end of file diff --git a/cli/Makefile.inc b/cli/Makefile.inc index f8bac28..096cbf4 100644 --- a/cli/Makefile.inc +++ b/cli/Makefile.inc @@ -9,6 +9,6 @@ cli_clean: rm -f $(ROMPATCHER_EXE) $(ROMPATCHER_EXE): $(ROMPATCHER_SRCS:%.c=%.o) $(ROMLIB_A) - $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) $(ROMLIB_A) + $(CC) $(CFLAGS) -o $@ $< $(ROMLIB_A) $(LDFLAGS) cli/%o: cli/%.c diff --git a/lib/checksum.c b/lib/checksum.c index d607b6b..fc66aec 100644 --- a/lib/checksum.c +++ b/lib/checksum.c @@ -1,5 +1,9 @@ #include +#ifdef __MINGW32__ +#include +#else #include +#endif #include "macrompatcher.h" RomErr GetChecksum(RomCtx *rom, uint32_t *checksum) { diff --git a/lib/locate_drvr.c b/lib/locate_drvr.c index aa8dd62..aa6d8bd 100644 --- a/lib/locate_drvr.c +++ b/lib/locate_drvr.c @@ -1,4 +1,8 @@ +#ifdef __MINGW32__ +#include +#else #include +#endif #include #include "macrompatcher.h" diff --git a/qtgui/RomPatcher.cpp b/qtgui/RomPatcher.cpp index 69d5c3f..ca3d6a1 100644 --- a/qtgui/RomPatcher.cpp +++ b/qtgui/RomPatcher.cpp @@ -100,8 +100,7 @@ void RomPatcher::updateChecksumUI() uint32_t cksum; char *cksumstr = NULL; GetChecksum(rom, &cksum); - asprintf(&cksumstr, "Checksum: %#x", cksum); - checksum->setText(cksumstr); + checksum->setText(QString().sprintf("%#x", cksum)); free(cksumstr); } diff --git a/qtgui/RomPatcher.manifest b/qtgui/RomPatcher.manifest new file mode 100644 index 0000000..38e7e50 --- /dev/null +++ b/qtgui/RomPatcher.manifest @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/qtgui/RomPatcher.pro b/qtgui/RomPatcher.pro index e7f6aaa..3a9dc43 100644 --- a/qtgui/RomPatcher.pro +++ b/qtgui/RomPatcher.pro @@ -4,3 +4,8 @@ HEADERS = RomPatcher.h CONFIG += qt LIBS += ../lib/libmacrom.a + +win32 { + QMAKE_PRE_LINK += "windres --input ../qtgui/RomPatcher.rc --output RomPatcher.res --output-format=coff" + LIBS += -lws2_32 RomPatcher.res +} diff --git a/qtgui/RomPatcher.rc b/qtgui/RomPatcher.rc new file mode 100644 index 0000000..9172543 --- /dev/null +++ b/qtgui/RomPatcher.rc @@ -0,0 +1,2 @@ +#include "winuser.h" +1 RT_MANIFEST RomPatcher.manifest \ No newline at end of file