Blob Blame History Raw
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 993a996..01e2ddc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -63,6 +63,7 @@ FIND_PACKAGE(ICU QUIET)
 FIND_PACKAGE(CURL QUIET)
 FIND_PACKAGE(PkgConfig QUIET)
 FIND_PACKAGE(Regex QUIET)
+FIND_PACKAGE(Glib QUIET REQUIRED)
 
 ###########################################################################################
 # Based on user input and the results of the above tests, we may need to mux with the source
@@ -228,12 +229,14 @@ IF(REGEX_FOUND AND CROSS_COMPILE_MINGW32)
 	SET(SWORD_LINK_LIBRARIES ${SWORD_LINK_LIBRARIES} ${REGEX_LIBRARY})
 ENDIF(REGEX_FOUND AND CROSS_COMPILE_MINGW32)
 
+INCLUDE_DIRECTORIES(${Glib_INCLUDE_DIRS})
+
 IF(BUILDING_SHARED)
-	TARGET_LINK_LIBRARIES(sword ${SWORD_LINK_LIBRARIES})
+	TARGET_LINK_LIBRARIES(sword ${SWORD_LINK_LIBRARIES} ${Glib_LIBRARIES})
 ENDIF(BUILDING_SHARED)
 
 IF(BUILDING_STATIC)
-	TARGET_LINK_LIBRARIES(sword_static ${SWORD_LINK_LIBRARIES})
+	TARGET_LINK_LIBRARIES(sword_static ${SWORD_LINK_LIBRARIES} ${Glib_LIBRARIES})
 ENDIF(BUILDING_STATIC)
 
 MESSAGE(STATUS "Setting link libraries to ${SWORD_LINK_LIBRARIES}")
diff --git a/cmake/FindGlib.cmake b/cmake/FindGlib.cmake
new file mode 100644
index 0000000..d4b73af
--- /dev/null
+++ b/cmake/FindGlib.cmake
@@ -0,0 +1,43 @@
+# - Try to find Glib-2.0 (with gobject)
+# Once done, this will define
+#
+#  Glib_FOUND - system has Glib
+#  Glib_INCLUDE_DIRS - the Glib include directories
+#  Glib_LIBRARIES - link these to use Glib
+
+include(LibFindMacros)
+
+# Use pkg-config to get hints about paths
+libfind_pkg_check_modules(Glib_PKGCONF glib-2.0)
+
+# Main include dir
+find_path(Glib_INCLUDE_DIR
+  NAMES glib.h
+  PATHS ${Glib_PKGCONF_INCLUDE_DIRS}
+  PATH_SUFFIXES glib-2.0
+)
+
+# Glib-related libraries also use a separate config header, which is in lib dir
+find_path(GlibConfig_INCLUDE_DIR
+  NAMES glibconfig.h
+  PATHS ${Glib_PKGCONF_INCLUDE_DIRS} /usr
+  PATH_SUFFIXES lib/glib-2.0/include
+)
+
+# Finally the library itself
+find_library(Glib_LIBRARY
+  NAMES glib-2.0
+  PATHS ${Glib_PKGCONF_LIBRARY_DIRS}
+)
+find_library(Gobject_LIBRARY
+  NAMES gobject-2.0
+  PATHS ${Glib_PKGCONF_LIBRARY_DIRS}
+)
+
+# Set the include dir variables and the libraries and let libfind_process do the rest.
+# NOTE: Singular variables for this library, plural for libraries this this lib depends on.
+set(Glib_PROCESS_INCLUDES Glib_INCLUDE_DIR GlibConfig_INCLUDE_DIR)
+set(Glib_PROCESS_LIBS Glib_LIBRARY Gobject_LIBRARY)
+libfind_process(Glib)
+
+
diff --git a/cmake/LibFindMacros.cmake b/cmake/LibFindMacros.cmake
new file mode 100644
index 0000000..69975c5
--- /dev/null
+++ b/cmake/LibFindMacros.cmake
@@ -0,0 +1,99 @@
+# Works the same as find_package, but forwards the "REQUIRED" and "QUIET" arguments
+# used for the current package. For this to work, the first parameter must be the
+# prefix of the current package, then the prefix of the new package etc, which are
+# passed to find_package.
+macro (libfind_package PREFIX)
+  set (LIBFIND_PACKAGE_ARGS ${ARGN})
+  if (${PREFIX}_FIND_QUIETLY)
+    set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET)
+  endif (${PREFIX}_FIND_QUIETLY)
+  if (${PREFIX}_FIND_REQUIRED)
+    set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED)
+  endif (${PREFIX}_FIND_REQUIRED)
+  find_package(${LIBFIND_PACKAGE_ARGS})
+endmacro (libfind_package)
+
+# CMake developers made the UsePkgConfig system deprecated in the same release (2.6)
+# where they added pkg_check_modules. Consequently I need to support both in my scripts
+# to avoid those deprecated warnings. Here's a helper that does just that.
+# Works identically to pkg_check_modules, except that no checks are needed prior to use.
+macro (libfind_pkg_check_modules PREFIX PKGNAME)
+  if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
+    include(UsePkgConfig)
+    pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS)
+  else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
+    find_package(PkgConfig)
+    if (PKG_CONFIG_FOUND)
+      pkg_check_modules(${PREFIX} ${PKGNAME})
+    endif (PKG_CONFIG_FOUND)
+  endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
+endmacro (libfind_pkg_check_modules)
+
+# Do the final processing once the paths have been detected.
+# If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain
+# all the variables, each of which contain one include directory.
+# Ditto for ${PREFIX}_PROCESS_LIBS and library files.
+# Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES.
+# Also handles errors in case library detection was required, etc.
+macro (libfind_process PREFIX)
+  # Skip processing if already processed during this run
+  if (NOT ${PREFIX}_FOUND)
+    # Start with the assumption that the library was found
+    set (${PREFIX}_FOUND TRUE)
+
+    # Process all includes and set _FOUND to false if any are missing
+    foreach (i ${${PREFIX}_PROCESS_INCLUDES})
+      if (${i})
+        set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}})
+        mark_as_advanced(${i})
+      else (${i})
+        set (${PREFIX}_FOUND FALSE)
+      endif (${i})
+    endforeach (i)
+
+    # Process all libraries and set _FOUND to false if any are missing
+    foreach (i ${${PREFIX}_PROCESS_LIBS})
+      if (${i})
+        set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}})
+        mark_as_advanced(${i})
+      else (${i})
+        set (${PREFIX}_FOUND FALSE)
+      endif (${i})
+    endforeach (i)
+
+    # Print message and/or exit on fatal error
+    if (${PREFIX}_FOUND)
+      if (NOT ${PREFIX}_FIND_QUIETLY)
+        message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}")
+      endif (NOT ${PREFIX}_FIND_QUIETLY)
+    else (${PREFIX}_FOUND)
+      if (${PREFIX}_FIND_REQUIRED)
+        foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS})
+          message("${i}=${${i}}")
+        endforeach (i)
+        message (FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall the library (dev version) and try again. If the library is already installed, use ccmake to set the missing variables manually.")
+      endif (${PREFIX}_FIND_REQUIRED)
+    endif (${PREFIX}_FOUND)
+  endif (NOT ${PREFIX}_FOUND)
+endmacro (libfind_process)
+
+macro(libfind_library PREFIX basename)
+  set(TMP "")
+  if(MSVC80)
+    set(TMP -vc80)
+  endif(MSVC80)
+  if(MSVC90)
+    set(TMP -vc90)
+  endif(MSVC90)
+  set(${PREFIX}_LIBNAMES ${basename}${TMP})
+  if(${ARGC} GREATER 2)
+    set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2})
+    string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES})
+    set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP})
+  endif(${ARGC} GREATER 2)
+  find_library(${PREFIX}_LIBRARY
+    NAMES ${${PREFIX}_LIBNAMES}
+    PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS}
+  )
+endmacro(libfind_library)
+
diff --git a/src/mgr/curlftpt.cpp b/src/mgr/curlftpt.cpp
index 165c054..1157b95 100644
--- a/src/mgr/curlftpt.cpp
+++ b/src/mgr/curlftpt.cpp
@@ -29,6 +29,8 @@
 
 #include <swlog.h>
 
+#include <glib.h>
+#include <glib/gstdio.h>
 
 SWORD_NAMESPACE_START
 
@@ -58,7 +60,7 @@ namespace {
 		struct FtpFile *out=(struct FtpFile *)stream;
 		if (out && !out->stream && !out->destBuf) {
 			/* open file for writing */
-			out->stream=fopen(out->filename, "wb");
+			out->stream=g_fopen(out->filename, "wb");
 			if (!out->stream)
 				return -1; /* failure, can't open file to write */
 		}
diff --git a/src/mgr/curlhttpt.cpp b/src/mgr/curlhttpt.cpp
index 2974fdc..36501d7 100644
--- a/src/mgr/curlhttpt.cpp
+++ b/src/mgr/curlhttpt.cpp
@@ -34,6 +34,8 @@
 
 using std::vector;
 
+#include <glib.h>
+#include <glib/gstdio.h>
 
 SWORD_NAMESPACE_START
 
@@ -50,7 +52,7 @@ namespace {
 		struct FtpFile *out=(struct FtpFile *)stream;
 		if (out && !out->stream && !out->destBuf) {
 			/* open file for writing */
-			out->stream=fopen(out->filename, "wb");
+			out->stream=g_fopen(out->filename, "wb");
 			if (!out->stream)
 				return -1; /* failure, can't open file to write */
 		}
diff --git a/src/mgr/filemgr.cpp b/src/mgr/filemgr.cpp
index fc4afd9..9ff12d8 100644
--- a/src/mgr/filemgr.cpp
+++ b/src/mgr/filemgr.cpp
@@ -23,6 +23,8 @@
 
 #include <filemgr.h>
 #include <utilstr.h>
+#include <glib.h>
+#include <glib/gstdio.h>
 
 #include <dirent.h>
 #include <fcntl.h>
@@ -124,7 +126,7 @@ FileDesc::FileDesc(FileMgr *parent, const char *path, int mode, int perms, bool
 
 FileDesc::~FileDesc() {
 	if (fd > 0)
-		close(fd);
+		::close(fd);
 		
 	if (path)
 		delete [] path;
@@ -226,14 +228,23 @@ int FileMgr::sysOpen(FileDesc *file) {
 				file->next = files;
 				files = file;
 			}
-			if ((!access(file->path, 04)) || ((file->mode & O_CREAT) == O_CREAT)) {	// check for at least file exists / read access before we try to open
-				char tries = (((file->mode & O_RDWR) == O_RDWR) && (file->tryDowngrade)) ? 2 : 1;  // try read/write if possible
+			if ((!g_access(file->path, 04)) || ((file->mode & O_CREAT) == O_CREAT)) {	// check for at least file exists / read access before we try to open
+//				char tries = (((file->mode & O_RDWR) == O_RDWR) && (file->tryDowngrade)) ? 2 : 1;  // try read/write if possible
+
+				// xiphos glib damage compat hack.
+				// recent g_open interferes, preventing open(RDWR) when
+				// an instance of that file is already open RDWR.
+				// this may damage something in sword - not sure - but this
+				// hack makes genbooks work again.  genbooks is all that
+				// fails to work without this hack.
+				char tries = 2;
+
 				for (int i = 0; i < tries; i++) {
 					if (i > 0) {
 						file->mode = (file->mode & ~O_RDWR);	// remove write access
 						file->mode = (file->mode | O_RDONLY);// add read access
 					}
-					file->fd = ::open(file->path, file->mode|O_BINARY, file->perms);
+					file->fd = g_open(file->path, file->mode|O_BINARY, file->perms);
 
 					if (file->fd >= 0)
 						break;
@@ -276,7 +287,7 @@ signed char FileMgr::trunc(FileDesc *file) {
 		if (i == 9999)
 			return -2;
 
-		int fd = ::open(buf, O_CREAT|O_RDWR, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
+		int fd = g_open(buf, O_CREAT|O_RDWR, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
 		if (fd < 0)
 			return -3;
 	
@@ -290,7 +301,7 @@ signed char FileMgr::trunc(FileDesc *file) {
 		if (size < 1) {
 			// zero out the file
 			::close(file->fd);
-			file->fd = ::open(file->path, O_TRUNC, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
+			file->fd = g_open(file->path, O_TRUNC, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
 			::close(file->fd);
 			file->fd = -77;	// force file open by filemgr
 			// copy tmp file back (dumb, but must preserve file permissions)
@@ -328,7 +339,7 @@ signed char FileMgr::existsFile(const char *ipath, const char *ifileName)
 		ch = path + strlen(path);
 		sprintf(ch, "/%s", ifileName);
 	}
-	signed char retVal = !access(path, 04);
+	signed char retVal = !g_access(path, 04);
 	delete [] path;
 	return retVal;
 }
@@ -350,7 +361,7 @@ signed char FileMgr::existsDir(const char *ipath, const char *idirName)
 		ch = path + strlen(path);
 		sprintf(ch, "/%s", idirName);
 	}
-	signed char retVal = !access(path, 04);
+	signed char retVal = !g_access(path, 04);
 	delete [] path;
 	return retVal;
 }
@@ -369,17 +380,13 @@ int FileMgr::createParent(const char *pName) {
 	}
 	buf[end] = 0;
 	if (strlen(buf)>0) {
-		if (access(buf, 02)) {  // not exists with write access?
-			if ((retCode = mkdir(buf
-#ifndef WIN32
+		if (g_access(buf, 02)) {  // not exists with write access?
+			if ((retCode = g_mkdir(buf
 					, 0755
-#endif
 					))) {
 				createParent(buf);
-				retCode = mkdir(buf
-#ifndef WIN32
+				retCode = g_mkdir(buf
 					, 0755
-#endif
 					);
 			}
 		}
@@ -391,7 +398,7 @@ int FileMgr::createParent(const char *pName) {
 	
 
 int FileMgr::openFileReadOnly(const char *fName) {
-	int fd = ::open(fName, O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
+	int fd = g_open(fName, O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
 	return fd;
 }
 
@@ -399,10 +406,10 @@ int FileMgr::openFileReadOnly(const char *fName) {
 int FileMgr::createPathAndFile(const char *fName) {
 	int fd;
 	
-	fd = ::open(fName, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
+	fd = g_open(fName, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
 	if (fd < 1) {
 		createParent(fName);
-		fd = ::open(fName, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
+		fd = g_open(fName, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
 	}
 	return fd;
 }
@@ -412,7 +419,7 @@ int FileMgr::copyFile(const char *sourceFile, const char *targetFile) {
 	int sfd, dfd, len;
 	char buf[4096];
 
-	if ((sfd = ::open(sourceFile, O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH)) < 1)
+	if ((sfd = g_open(sourceFile, O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH)) < 1)
 		return -1;
 	if ((dfd = createPathAndFile(targetFile)) < 1)
 		return -1;
@@ -430,7 +437,7 @@ int FileMgr::copyFile(const char *sourceFile, const char *targetFile) {
 
 
 int FileMgr::removeFile(const char *fName) {
-	return ::remove(fName);
+	return g_remove(fName);
 }
 
 char FileMgr::getLine(FileDesc *fDesc, SWBuf &line) {
@@ -507,14 +514,14 @@ char FileMgr::isDirectory(const char *path) {
 
 
 int FileMgr::copyDir(const char *srcDir, const char *destDir) {
-	DIR *dir;
-	struct dirent *ent;
-	if ((dir = opendir(srcDir))) {
-		rewinddir(dir);
-		while ((ent = readdir(dir))) {
-			if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) {
-				SWBuf srcPath  = (SWBuf)srcDir  + (SWBuf)"/" + ent->d_name;
-				SWBuf destPath = (SWBuf)destDir + (SWBuf)"/" + ent->d_name;
+	GDir *dir;
+	const gchar *ent;
+	if ((dir = g_dir_open(srcDir, 0, NULL))) {
+	  g_dir_rewind(dir);
+	  while ((ent = g_dir_read_name(dir))) {
+			if ((strcmp(ent, ".")) && (strcmp(ent, ".."))) {
+				SWBuf srcPath  = (SWBuf)srcDir  + (SWBuf)"/" + ent;
+				SWBuf destPath = (SWBuf)destDir + (SWBuf)"/" + ent;
 				if (!isDirectory(srcPath.c_str())) {
 					copyFile(srcPath.c_str(), destPath.c_str());
 				}
@@ -523,20 +530,20 @@ int FileMgr::copyDir(const char *srcDir, const char *destDir) {
 				}
 			}
 		}
-		closedir(dir);
+		g_dir_close(dir);
 	}
 	return 0;
 }
 
 
 int FileMgr::removeDir(const char *targetDir) {
-	DIR *dir = opendir(targetDir);
-	struct dirent *ent;
+  GDir *dir = g_dir_open(targetDir, 0, NULL);
+	const gchar *ent;
 	if (dir) {
-		rewinddir(dir);
-		while ((ent = readdir(dir))) {
-			if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) {
-				SWBuf targetPath = (SWBuf)targetDir + (SWBuf)"/" + ent->d_name;
+	  g_dir_rewind(dir);
+	  while ((ent = g_dir_read_name(dir))) {
+			if ((strcmp(ent, ".")) && (strcmp(ent, ".."))) {
+				SWBuf targetPath = (SWBuf)targetDir + (SWBuf)"/" + ent;
 				if (!isDirectory(targetPath.c_str())) {
 					FileMgr::removeFile(targetPath.c_str());
 				}
@@ -545,7 +552,7 @@ int FileMgr::removeDir(const char *targetDir) {
 				}
 			}
 		}
-		closedir(dir);
+		g_dir_close(dir);
 		FileMgr::removeFile(targetDir);
 /*
 		int status = FileMgr::removeFile(targetDir);
diff --git a/src/mgr/installmgr.cpp b/src/mgr/installmgr.cpp
index 20020ea..18122fb 100644
--- a/src/mgr/installmgr.cpp
+++ b/src/mgr/installmgr.cpp
@@ -31,6 +31,8 @@ extern "C" {
 #include <utilstr.h>
 
 #include <fcntl.h>
+#include <glib.h>
+#include <glib/gstdio.h>
 
 #include <swmgr.h>
 #include <swmodule.h>
@@ -270,20 +272,19 @@ int InstallMgr::removeModule(SWMgr *manager, const char *moduleName) {
 		}
 		else {	//remove all files in DataPath directory
 
-			DIR *dir;
-			struct dirent *ent;
+			GDir *dir;
+			const gchar *ent;
 			ConfigEntMap::iterator entry;
 
 			FileMgr::removeDir(modDir.c_str());
 
-			if ((dir = opendir(manager->configPath))) {	// find and remove .conf file
-				rewinddir(dir);
-				while ((ent = readdir(dir))) {
-					if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) {
+			if ((dir = g_dir_open(manager->configPath, 0, NULL))) {	// find and remove .conf file
+			        g_dir_rewind(dir);
+				while ((ent =  g_dir_read_name(dir))) {
 						modFile = manager->configPath;
 						removeTrailingSlash(modFile);
 						modFile += "/";
-						modFile += ent->d_name;
+				  modFile += ent;
 						SWConfig *config = new SWConfig(modFile.c_str());
 						if (config->Sections.find(modName) != config->Sections.end()) {
 							delete config;
@@ -291,8 +292,8 @@ int InstallMgr::removeModule(SWMgr *manager, const char *moduleName) {
 						}
 						else	delete config;
 					}
-				}
-				closedir(dir);
+				g_dir_close(dir);
+				g_free(dir);
 			}
 		}
 		return 0;
@@ -401,8 +402,8 @@ int InstallMgr::installModule(SWMgr *destMgr, const char *fromLocation, const ch
 	SWBuf buffer;
 	bool aborted = false;
 	bool cipher = false;
-	DIR *dir;
-	struct dirent *ent;
+	GDir *dir;
+	const gchar *ent;
 	SWBuf modFile;
 
 	SWLog::getSystemLog()->logDebug("***** InstallMgr::installModule\n");
@@ -514,18 +515,18 @@ int InstallMgr::installModule(SWMgr *destMgr, const char *fromLocation, const ch
 		}
 		if (!aborted) {
 			SWBuf confDir = sourceDir + "mods.d/";
-			if ((dir = opendir(confDir.c_str()))) {	// find and copy .conf file
-				rewinddir(dir);
-				while ((ent = readdir(dir))) {
-					if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) {
+			if ((dir = g_dir_open(confDir.c_str(), 0, NULL))) {	// find and copy .conf file
+				g_dir_rewind(dir);
+				while ((ent = g_dir_read_name(dir))) {
+					if ((strcmp(ent, ".")) && (strcmp(ent, ".."))) {
 						modFile = confDir;
-						modFile += ent->d_name;
+						modFile += ent;
 						SWConfig *config = new SWConfig(modFile.c_str());
 						if (config->Sections.find(modName) != config->Sections.end()) {
 							SWBuf targetFile = destMgr->configPath; //"./mods.d/";
 							removeTrailingSlash(targetFile);
 							targetFile += "/";
-							targetFile += ent->d_name;
+							targetFile += ent;
 							FileMgr::copyFile(modFile.c_str(), targetFile.c_str());
 							if (cipher) {
 								if (getCipherCode(modName, config)) {
@@ -542,7 +543,7 @@ int InstallMgr::installModule(SWMgr *destMgr, const char *fromLocation, const ch
 						delete config;
 					}
 				}
-				closedir(dir);
+				g_dir_close(dir);
 			}
 		}
 		return (aborted) ? -1 : 0;
diff --git a/src/mgr/swmgr.cpp b/src/mgr/swmgr.cpp
index fe84189..edc23f9 100644
--- a/src/mgr/swmgr.cpp
+++ b/src/mgr/swmgr.cpp
@@ -23,6 +23,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <fcntl.h>
+#include <glib.h>
+#include <glib/gstdio.h>
 
 #include <sys/stat.h>
 #ifndef _MSC_VER
@@ -297,10 +299,10 @@ void SWMgr::init() {
 SWBuf SWMgr::getHomeDir() {
 
 	// figure out 'home' directory for app data
-	SWBuf homeDir = getenv("HOME");
+	SWBuf homeDir = g_getenv("HOME");
 	if (!homeDir.length()) {
 		// silly windows
-		homeDir = getenv("APPDATA");
+		homeDir = g_getenv("APPDATA");
 	}
 	if (homeDir.length()) {
 		if ((homeDir[homeDir.length()-1] != '\\') && (homeDir[homeDir.length()-1] != '/')) {
@@ -483,7 +485,7 @@ void SWMgr::findConfig(char *configType, char **prefixPath, char **configPath, s
 			// check environment variable SWORD_PATH
 			SWLog::getSystemLog()->logDebug("Checking $SWORD_PATH...");
 
-			SWBuf envsworddir = getenv("SWORD_PATH");
+			SWBuf envsworddir = g_getenv("SWORD_PATH");
 			if (envsworddir.length()) {
 				
 				SWLog::getSystemLog()->logDebug("found (%s).", envsworddir.c_str());
@@ -614,14 +616,15 @@ void SWMgr::findConfig(char *configType, char **prefixPath, char **configPath, s
 
 	SWLog::getSystemLog()->logDebug("Checking $ALLUSERSPROFILE/Application Data/sword/...");
 
-	SWBuf envallusersdir  = getenv("ALLUSERSPROFILE");
+	//SWBuf envallusersdir  = g_getenv("ALLUSERSPROFILE");
+	SWBuf envallusersdir = g_get_system_data_dirs()[0];
 	if (envallusersdir.length()) {
 		SWLog::getSystemLog()->logDebug("found (%s).", envallusersdir.c_str());
 		path = envallusersdir;
 		if ((!path.endsWith("\\")) && (!path.endsWith("/")))
 			path += "/";
 
-		path += "Application Data/sword/";
+		//path += "Application Data/sword/";
 		SWLog::getSystemLog()->logDebug("Checking %s for mods.d...", path.c_str());
 		if (FileMgr::existsDir(path.c_str(), "mods.d")) {
 			SWLog::getSystemLog()->logDebug("found.");
@@ -663,7 +666,7 @@ void SWMgr::findConfig(char *configType, char **prefixPath, char **configPath, s
 
 	if (homeDir.length()) {
 		path = homeDir;
-		path += ".sword/";
+		path += "sword/";
 		SWLog::getSystemLog()->logDebug("  Checking for %smods.conf...", path.c_str());
 		if (FileMgr::existsFile(path.c_str(), "mods.conf")) {
 			SWLog::getSystemLog()->logDebug("found.");
@@ -700,29 +703,29 @@ void SWMgr::findConfig(char *configType, char **prefixPath, char **configPath, s
 
 void SWMgr::loadConfigDir(const char *ipath)
 {
-	DIR *dir;
-	struct dirent *ent;
+	GDir *dir;
+	const gchar *ent;
 	SWBuf newmodfile;
  
-	if ((dir = opendir(ipath))) {
-		rewinddir(dir);
-		while ((ent = readdir(dir))) {
+	if ((dir = g_dir_open(ipath, 0, NULL))) {
+	  g_dir_rewind(dir);
+		while ((ent = g_dir_read_name(dir))) {
 			//check whether it ends with .conf, if it doesn't skip it!
-			if (!ent->d_name || (strlen(ent->d_name) <= 5) || strncmp(".conf", (ent->d_name + strlen(ent->d_name) - 5), 5 )) {
+			if (ent && (strlen(ent) > 5) && strncmp(".conf", (ent + strlen(ent) - 5), 5 )) {
 				continue;
 			}
 			
 			newmodfile = ipath;
 			if ((ipath[strlen(ipath)-1] != '\\') && (ipath[strlen(ipath)-1] != '/'))
 				newmodfile += "/";
-			newmodfile += ent->d_name;
+			newmodfile += ent;
 			if (config) {
 				SWConfig tmpConfig(newmodfile.c_str());
 				*config += tmpConfig;
 			}
 			else	config = myconfig = new SWConfig(newmodfile.c_str());
 		}
-		closedir(dir);
+		g_dir_close(dir);
 		
 		if (!config) {	// if no .conf file exist yet, create a default
 			newmodfile = ipath;
@@ -842,7 +845,7 @@ signed char SWMgr::Load() {
 			SWBuf homeDir = getHomeDir();
 			if (homeDir.length() && configType != 2) { // 2 = user only
 				SWBuf path = homeDir;
-				path += ".sword/";
+				path += "sword/";
 				augmentModules(path.c_str(), mgrModeMultiMod);
 				path = homeDir;
 				path += "sword/";
@@ -1331,21 +1334,21 @@ void SWMgr::deleteModule(const char *modName) {
 
 void SWMgr::InstallScan(const char *dirname)
 {
-   DIR *dir;
-   struct dirent *ent;
+   GDir *dir;
+   const gchar *ent;
    FileDesc *conffd = 0;
    SWBuf newmodfile;
    SWBuf targetName;
  
 	if (FileMgr::existsDir(dirname)) {
-		if ((dir = opendir(dirname))) {
-			rewinddir(dir);
-			while ((ent = readdir(dir))) {
-				if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) {
+	  if ((dir = g_dir_open(dirname, 0, NULL))) {
+	    g_dir_rewind(dir);
+			while ((ent = g_dir_read_name(dir))) {
+				if ((strcmp(ent, ".")) && (strcmp(ent, ".."))) {
 					newmodfile = dirname;
 					if ((dirname[strlen(dirname)-1] != '\\') && (dirname[strlen(dirname)-1] != '/'))
 						newmodfile += "/";
-					newmodfile += ent->d_name;
+					newmodfile += ent;
 
 					// mods.d
 					if (configType) {
@@ -1354,7 +1357,7 @@ void SWMgr::InstallScan(const char *dirname)
 						targetName = configPath;
 						if ((configPath[strlen(configPath)-1] != '\\') && (configPath[strlen(configPath)-1] != '/'))
 							targetName += "/";
-						targetName += ent->d_name;
+						targetName += ent;
 						conffd = FileMgr::getSystemFileMgr()->open(targetName.c_str(), FileMgr::WRONLY|FileMgr::CREAT, FileMgr::IREAD|FileMgr::IWRITE);
 					}
 
@@ -1376,7 +1379,7 @@ void SWMgr::InstallScan(const char *dirname)
 			}
 			if (conffd)
 				FileMgr::getSystemFileMgr()->close(conffd);
-			closedir(dir);
+			g_dir_close(dir);
 		}
 	}
 }
diff --git a/src/utilfuns/zlib/untgz.c b/src/utilfuns/zlib/untgz.c
index a7b7164..9da6131 100644
--- a/src/utilfuns/zlib/untgz.c
+++ b/src/utilfuns/zlib/untgz.c
@@ -5,6 +5,9 @@
  * adaptation to Unix by Jean-loup Gailly <jloup@gzip.org>
  */
 
+#include <glib.h>
+#include <glib/gstdio.h>
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -210,7 +213,7 @@ int makedir (char *newdir)
   if (buffer[len-1] == '/') {
     buffer[len-1] = '\0';
   }
-  if (mkdir(buffer, 0775) == 0)
+  if (g_mkdir(buffer, 0775) == 0)
     {
       free(buffer);
       return 1;
@@ -225,7 +228,7 @@ int makedir (char *newdir)
 	p++;
       hold = *p;
       *p = 0;
-      if ((mkdir(buffer, 0775) == -1) && (errno == ENOENT))
+      if ((g_mkdir(buffer, 0775) == -1) && (errno == ENOENT))
 	{
 	  fprintf(stderr,"%s: couldn't create directory %s\n",prog,buffer);
 	  free(buffer);
@@ -300,15 +303,15 @@ int untar (gzFile in, const char *dest) {
 			case AREGTYPE:
 				remaining = getoct(buffer.header.size,12);
 				if (remaining) {
-					outfile = fopen(fname,"wb");
+					outfile = g_fopen(fname,"wb");
 					if (outfile == NULL) {
 						// try creating directory
 						char *p = strrchr(fname, '/');
 						if (p != NULL) {
 							*p = '\0';
-							makedir(fname);
+							g_mkdir(fname, 0);
 							*p = '/';
-							outfile = fopen(fname,"wb");
+							outfile = g_fopen(fname,"wb");
 						}
 					}
 /*
@@ -353,7 +356,11 @@ int untar (gzFile in, const char *dest) {
 
 					localt = *localtime(&tartime);
 
-					hFile = CreateFile(fname, GENERIC_READ | GENERIC_WRITE,
+					hFile = CreateFileW(g_utf8_to_utf16(fname,
+									    -1,
+									    NULL,
+									    NULL,
+									    NULL), GENERIC_READ | GENERIC_WRITE,
 					0, NULL, OPEN_EXISTING, 0, NULL);
 		  
 					st.wYear = (WORD)localt.tm_year+1900;