Index: cpp/common/nonstd.h
===================================================================
--- cpp/common/nonstd.h	(revision 294)
+++ cpp/common/nonstd.h	(revision 295)
@@ -61,64 +61,4 @@
 #endif
 
-#ifdef IPHONE
- #include <string>
- std::string getAppHome();
- std::string getAppResources();
- #define GET_APP_HOME getAppHome()
- #define GET_APP_RESOURCES getAppResources()
-#endif
-
-#ifdef SHP
- #define GET_APP_HOME "/Home/"
- #define GET_APP_RESOURCES "/Res/"
-#endif
-
-#ifdef TIZEN
- #define GET_APP_HOME "/data/"
- #define GET_APP_RESOURCES "/res/"
-#endif
-
-#ifdef __ANDROID__
- #define GET_APP_HOME getAppHome()
- #define GET_APP_RESOURCES "/resrc/" //inside APK, resources are kept in the "assets" subdirectory (in the "res" subdirectory there is no support for subdirectories nor accessing files by name). The prefix /resrc/ is just an indication that lets mfile easily discriminate between HOME (r/w) and RESOURCES (r) locations
-#endif
-
-#ifdef LINUX
- #define GET_APP_HOME "./"
- #define GET_APP_RESOURCES "./"
-#endif
-
-#ifdef MACOS
-#ifdef MACOS_APP_DIR //separate home/resources
- #include <string>
- std::string getAppHome();
- #define GET_APP_HOME getAppHome()
-#else //old style
- #define GET_APP_HOME "./"
-#endif
- #define GET_APP_RESOURCES "./"
-#endif
-
-#if defined(_WIN32) && !defined(SHP)
-    #define GET_APP_HOME ".\\"
-    #define GET_APP_RESOURCES ".\\"
-#endif
-
-#ifdef INITIAL_DIR_IS_HOME
- #include "cwd.h"
- #ifdef GET_APP_HOME
-  #undef GET_APP_HOME
- #endif
- #define GET_APP_HOME getAppHome()
-#endif
-
-#ifdef INITIAL_DIR_IS_RES
- #include "cwd.h"
- #ifdef GET_APP_RESOURCES
-  #undef GET_APP_RESOURCES
- #endif
- #define GET_APP_RESOURCES getAppResources()
-#endif
-
 //typedef unsigned char boolean; //niestety nie mozna uzyc 'bool' bo VC w rpcndr.h wlasnie tak definiuje booleana, jako unsigned char
 //typedef char byte; //rozne srodowiska c++ definiuja byte jako unsigned char! w javie jest inaczej -> trzeba i tak zmienic w portowanych zrodlach byte na char.
Index: cpp/common/nonstd_stdio.cpp
===================================================================
--- cpp/common/nonstd_stdio.cpp	(revision 294)
+++ cpp/common/nonstd_stdio.cpp	(revision 295)
@@ -8,7 +8,9 @@
 #include <common/stl-util.h>
 
-#if defined _WIN32 && !defined SHP
-//<unistd.h> not needed for unlink()
+#ifdef _WIN32
 #include "Shlwapi.h" //PathIsRelative()
+#ifdef __BORLANDC__
+#pragma link "Shlwapi.lib" //PathIsRelative()
+#endif
 #include <sys/stat.h> //_stat
 #else
@@ -29,7 +31,27 @@
 }
 
-bool directoryExists(const char* path)
+#ifdef _WIN32
+bool isDirWritable(const char* path) //dir must not end with '\'
+{
+	wstring dir = Convert::utf8ToUtf16(path);
+	CreateDirectoryW(dir.c_str(), 0);
+	dir += L"\\test_file.write";
+	_wunlink(dir.c_str());
+	FILE *f = _wfopen(dir.c_str(), L"wt");
+	if (f)
+	{
+		fclose(f);
+		_wunlink(dir.c_str());
+		return true;
+	}
+	else
+		return false;
+}
+#endif
+
+bool directoryExists(const char* path, bool is_writable)
 {
 	struct _stat s;
+	if (path[0] == 0) path = ".";
 #ifdef _WIN32
 	if (_wstat(Convert::utf8ToUtf16(path).c_str(), &s) != 0) return false;
@@ -37,5 +59,28 @@
 	if (_stat(path, &s) != 0) return false;
 #endif
-	return S_ISDIR(s.st_mode);
+	if (S_ISDIR(s.st_mode))
+	{
+		if (is_writable)
+		{
+#ifdef _WIN32
+#ifndef W_OK
+#define W_OK 2 //http://msdn.microsoft.com/en-us/library/1w06ktdy.aspx
+#endif
+			//under Windows, access() is not a reliable way to check if a directory is writable
+			//http://stackoverflow.com/questions/198071/code-for-checking-write-permissions-for-directories-in-win2k-xp
+			//bool writable_access = _waccess(Convert::utf8ToUtf16(path).c_str(), W_OK) == 0;
+			bool writable_trial = isDirWritable(path);
+			//printf("Checking '%s' for writing(%d) using access(): result=%d\n", path, is_writable, writable_access);
+			//printf("File creation test: result=%d\n", writable_trial);
+			//return writable_access;
+			return writable_trial;
+#else
+			return access(path, W_OK) == 0;
+#endif
+		}
+		else
+			return true;
+	}
+	return false;
 }
 
@@ -51,5 +96,5 @@
 bool makeDirectories(const char* path)
 {
-	if (directoryExists(path)) return true;
+	if (directoryExists(path,false)) return true;
 	string parentdir = getFileDir(path);
 	if (!makeDirectories(parentdir.c_str())) return false;
@@ -92,5 +137,5 @@
 {
 	if (fname == NULL) return false; //SplitFileSystem never passes NULL but this function is public so we never know
-#if defined _WIN32
+#ifdef _WIN32
 	return PathIsRelativeW(Convert::utf8ToUtf16(fname).c_str()) == FALSE; //http://msdn.microsoft.com/en-us/library/bb773660%28v=vs.85%29.aspx
 #else
@@ -201,7 +246,7 @@
 MFILE *mfopen(const char *path, const char *mode)
 {
-	string respath=GET_APP_RESOURCES; //the macro can be char* or std::string, we don't know (nonstd.h, INITIAL_DIR_IS_RES, cwd.cpp) so we convert it to std::string
+	string respath=getAppResources();
 	//printFM("Opening '%s', mode='%s'",path,mode);
-	//printFM("GET_APP_RESOURCES='%s'",respath.c_str());
+	//printFM("getAppResources()='%s'",respath.c_str());
 	NvFile *rfile=NULL; //can only read
 	FILE *rwfile=NULL;
Index: cpp/common/nonstd_stdio.h
===================================================================
--- cpp/common/nonstd_stdio.h	(revision 294)
+++ cpp/common/nonstd_stdio.h	(revision 295)
@@ -7,5 +7,5 @@
 
 bool fileExists(const char* path);
-bool directoryExists(const char* path);
+bool directoryExists(const char* path,bool is_writable);
 bool makeDirectory(const char* path);
 bool makeDirectories(const char* path);
