(svn r4038) -backport (3966, 3972 and 4019) -Fix: [OSX 10.3 and newer] [ 1157244 ] Can't save game if name contains german umlauts (loading savegames with certain chars still look a bit odd)
--- a/Makefile Wed Mar 22 21:24:26 2006 +0000
+++ b/Makefile Wed Mar 22 21:40:26 2006 +0000
@@ -475,6 +475,12 @@
endif
endif
+ifdef OSX
+ifndef JAGUAR
+LIBS += -liconv
+endif
+endif
+
# enables/disables assert()
ifdef DISABLE_ASSERTS
CFLAGS += -DNDEBUG
--- a/network_core.h Wed Mar 22 21:24:26 2006 +0000
+++ b/network_core.h Wed Mar 22 21:40:26 2006 +0000
@@ -11,13 +11,10 @@
#ifdef ENABLE_NETWORK
-#ifdef __APPLE__
-#include <AvailabilityMacros.h>
-#if (MAC_OS_X_VERSION_MAX_ALLOWED == MAC_OS_X_VERSION_10_2)
+#if defined(__APPLE__) && (MAC_OS_X_VERSION_MAX_ALLOWED == MAC_OS_X_VERSION_10_2)
// OSX 10.2 don't have socklen_t defined, so we will define it here
typedef int socklen_t;
#endif
-#endif
// Windows stuff
#if defined(WIN32) || defined(WIN64)
--- a/os/macosx/Makefile.setup Wed Mar 22 21:24:26 2006 +0000
+++ b/os/macosx/Makefile.setup Wed Mar 22 21:40:26 2006 +0000
@@ -108,3 +108,16 @@
LDFLAGS:= $(LDFLAGS_PPC)
endif
endif
+
+# setting up flags to make a binary, that fits the system it builds on
+ifndef FAT_BINARY
+ ifndef JAGUAR
+ ifeq ($(shell uname), Darwin)
+ # it's a hardware mac, not crosscompiling
+ ifeq ($(shell uname -r), 6.8)
+ # OSX 10.2.8 uses Darwin 6.8, so we better set JAGUAR so we avoid the stuff that was added in 10.3 or later
+ JAGUAR:=1
+ endif
+ endif
+ endif
+endif
--- a/saveload.c Wed Mar 22 21:24:26 2006 +0000
+++ b/saveload.c Wed Mar 22 21:40:26 2006 +0000
@@ -1243,6 +1243,12 @@
extern void BeforeSaveGame(void);
extern bool LoadOldSaveGame(const char *file);
+#if defined(__APPLE__) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3)
+extern const char *convert_to_fs_charset(const char *filename);
+#else
+#define convert_to_fs_charset(str) (str)
+#endif
+
/** Small helper function to close the to be loaded savegame an signal error */
static inline SaveOrLoadResult AbortSaveLoad(void)
{
@@ -1347,7 +1353,6 @@
save_thread = NULL;
}
-
/**
* Main Save or Load function where the high-level saveload functions are
* handled. It opens the savegame, selects format and checks versions
@@ -1378,7 +1383,11 @@
return SL_OK;
}
- _sl.fh = fopen(filename, (mode == SL_SAVE) ? "wb" : "rb");
+ if(mode == SL_SAVE) {
+ _sl.fh = fopen(convert_to_fs_charset(filename), "wb");
+ } else {
+ _sl.fh = fopen(filename, "rb");
+ }
if (_sl.fh == NULL) {
DEBUG(misc, 0) ("Cannot open savegame for saving/loading.");
return SL_ERROR;
--- a/screenshot.c Wed Mar 22 21:24:26 2006 +0000
+++ b/screenshot.c Wed Mar 22 21:40:26 2006 +0000
@@ -12,6 +12,12 @@
#include "screenshot.h"
#include "variables.h"
+#if defined(__APPLE__) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3)
+extern const char *convert_to_fs_charset(const char *filename);
+#else
+#define convert_to_fs_charset(str) (str)
+#endif
+
char _screenshot_format_name[8];
uint _num_screenshot_formats;
uint _cur_screenshot_format;
@@ -73,7 +79,7 @@
if (pixelformat != 8)
return false;
- f = fopen(name, "wb");
+ f = fopen(convert_to_fs_charset(name), "wb");
if (f == NULL) return false;
// each scanline must be aligned on a 32bit boundary
@@ -177,7 +183,7 @@
if (pixelformat != 8)
return false;
- f = fopen(name, "wb");
+ f = fopen(convert_to_fs_charset(name), "wb");
if (f == NULL) return false;
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (char *)name, png_my_error, png_my_warning);
@@ -288,7 +294,7 @@
if (pixelformat != 8 || w == 0)
return false;
- f = fopen(name, "wb");
+ f = fopen(convert_to_fs_charset(name), "wb");
if (f == NULL) return false;
memset(&pcx, 0, sizeof(pcx));
--- a/unix.c Wed Mar 22 21:24:26 2006 +0000
+++ b/unix.c Wed Mar 22 21:40:26 2006 +0000
@@ -48,7 +48,6 @@
#include <SDL.h>
#endif
#endif
-
static char *_fios_path;
static char *_fios_save_path;
static char *_fios_scn_path;
@@ -604,3 +603,43 @@
}
#endif // __AMIGA__
}
+
+#if defined(__APPLE__) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3)
+/* FYI: This is not thread-safe.
+Assumptions:
+ - the 'from' charset is ISO-8859-15
+ - the 'to' charset is either the same, or UTF-8
+NOTE: iconv was added in OSX 10.3. 10.2.x will still have the invalid char issues. There aren't any easy fix for this
+*/
+#include <iconv.h>
+#include <locale.h>
+const char *convert_to_fs_charset(const char *filename)
+{
+ static char statout[1024], statin[1024];
+ static iconv_t convd;
+ static bool alreadyInited;
+ char *outbuf = statout;
+ const char *inbuf = statin;
+ size_t inlen = strlen(filename), outlen = 1023;
+ size_t retval = 0;
+ if(inbuf == NULL)
+ inbuf = statin;
+
+ setlocale(LC_ALL, "C-UTF-8");
+ strcpy(statout, filename);
+ strcpy(statin, filename);
+ inbuf = strrchr(statin, '/');
+ outbuf = strrchr(statout, '/');
+ if(alreadyInited == false)
+ {
+ convd = iconv_open("UTF-8", "ISO-8859-15");
+ if(convd == (iconv_t)(-1))
+ return filename;
+ alreadyInited = true;
+ }
+ retval = iconv(convd, NULL, NULL, NULL, NULL);
+ inlen = iconv(convd, &inbuf, &inlen, &outbuf, &outlen);
+ // FIX: invalid characters will abort conversion, but they shouldn't occur?
+ return statout;
+}
+#endif