Index: /cpp/common/Convert.cpp
===================================================================
--- /cpp/common/Convert.cpp	(revision 280)
+++ /cpp/common/Convert.cpp	(revision 281)
@@ -128,2 +128,41 @@
 	return string(ret, 24); //24 znaki z pominieciem ostatniego \n
 }
+
+string Convert::wstrToUtf8(const wchar_t *str)
+{
+	if (str == NULL) return "";
+	string res;
+	wchar_t *wcp = (wchar_t*)str;
+	while (*wcp != 0)
+	{
+		int c = *wcp;
+		if (c < 0x80) res += c;
+		else if (c < 0x800) { res += 192 + c / 64; res += 128 + c % 64; }
+		else if (c - 0xd800u < 0x800) res += "<ERROR-CHAR>";
+		else if (c < 0x10000) { res += 224 + c / 4096; res += 128 + c / 64 % 64; res += 128 + c % 64; }
+		else if (c < 0x110000) { res += 240 + c / 262144; res += 128 + c / 4096 % 64; res += 128 + c / 64 % 64; res += 128 + c % 64; }
+		else res += "<ERROR-CHAR>";
+		wcp++;
+	}
+	return res;
+}
+
+#ifdef _WIN32
+wstring Convert::utf8ToUtf16(const char *str)
+{
+	wstring wstr;
+	int nOffset = 0;
+	int nDataLen = strlen(str) + 1; //including ending \0
+	int nLenWide = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)(str + nOffset),
+		(int)(nDataLen - nOffset), NULL, 0);
+	wstr.resize(nLenWide);
+	if (MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)(str + nOffset),
+		(int)(nDataLen - nOffset),
+		&wstr[0], nLenWide) != nLenWide)
+	{
+		//ASSERT(false); //some conversion error
+		return wstr;
+	}
+	return wstr;
+}
+#endif
Index: /cpp/common/Convert.h
===================================================================
--- /cpp/common/Convert.h	(revision 280)
+++ /cpp/common/Convert.h	(revision 281)
@@ -72,23 +72,8 @@
 	}
 
-	static string wstrTOutf8(const wchar_t *s)
-	{
-		if (s == NULL) return "";
-		string res;
-		wchar_t *wcp = (wchar_t*)s;
-		while (*wcp != 0)
-		{
-			int c = *wcp;
-			if (c < 0x80) res += c;
-			else if (c < 0x800) { res += 192 + c / 64; res += 128 + c % 64; }
-			else if (c - 0xd800u < 0x800) res += "<ERR-CHAR>";
-			else if (c < 0x10000) { res += 224 + c / 4096; res += 128 + c / 64 % 64; res += 128 + c % 64; }
-			else if (c < 0x110000) { res += 240 + c / 262144; res += 128 + c / 4096 % 64; res += 128 + c / 64 % 64; res += 128 + c % 64; }
-			else res += "<ERR-CHAR>";
-			wcp++;
-		}
-		return res;
-	}
-	//#endif
+	static string wstrToUtf8(const wchar_t *str);
+#ifdef _WIN32
+	static wstring utf8ToUtf16(const char *str);
+#endif
 };
 
Index: /cpp/common/nonstd_stdio.cpp
===================================================================
--- /cpp/common/nonstd_stdio.cpp	(revision 280)
+++ /cpp/common/nonstd_stdio.cpp	(revision 281)
@@ -5,29 +5,37 @@
 #include "nonstd_stdio.h"
 #include "nonstd.h"
-#include "Convert.h" //strTOwstr()
+#include "Convert.h" //utf8ToUtf16()
 #include <common/stl-util.h>
 
 #if defined _WIN32 && !defined SHP
- //<unistd.h> not needed for unlink()
- #include "Shlwapi.h" //PathIsRelative()
- #include <sys/stat.h> //_stat
-#else
- #include <unistd.h>
+//<unistd.h> not needed for unlink()
+#include "Shlwapi.h" //PathIsRelative()
+#include <sys/stat.h> //_stat
+#else
+#include <unistd.h>
 #endif
 
 bool fileExists(const char* path)
 {
-//lepiej gdyby uzywalo stat bo mfopen mogloby cos niepotrzebnie wczytywac przy otwarciu pliku ale mfopen wiadomo ze zadziala wszedzie tak samo
-MFILE *f=mfopen(path,FOPEN_READ_BINARY);
-if (f==NULL) return false;
-mfclose(f);
-return true;
+	//lepiej gdyby uzywalo stat bo mfopen mogloby cos niepotrzebnie wczytywac przy otwarciu pliku ale mfopen wiadomo ze zadziala wszedzie tak samo
+#ifdef _WIN32
+	MFILE *f = mfopen(Convert::utf8ToUtf16(path).c_str(), Convert::strTOwstr(FOPEN_READ_BINARY).c_str());
+#else
+	MFILE *f = mfopen(path, FOPEN_READ_BINARY);
+#endif
+	if (f == NULL) return false;
+	mfclose(f);
+	return true;
 }
 
 bool directoryExists(const char* path)
 {
-struct _stat s;
-if (_stat(path,&s)!=0) return false;
-return S_ISDIR(s.st_mode);
+	struct _stat s;
+#ifdef _WIN32
+	if (_wstat(Convert::utf8ToUtf16(path).c_str(), &s) != 0) return false;
+#else
+	if (_stat(path, &s) != 0) return false;
+#endif
+	return S_ISDIR(s.st_mode);
 }
 
@@ -35,7 +43,7 @@
 {
 #ifdef _WIN32
-return mkdir(path)==0;
-#else
-return mkdir(path,0777)==0;
+	return _wmkdir(Convert::utf8ToUtf16(path).c_str()) == 0;
+#else
+	return mkdir(path,0777) == 0;
 #endif
 }
@@ -43,32 +51,40 @@
 bool makeDirectories(const char* path)
 {
-if (directoryExists(path)) return true;
-string parentdir=getFileDir(path);
-if (!makeDirectories(parentdir.c_str())) return false;
-return makeDirectory(path);
+	if (directoryExists(path)) return true;
+	string parentdir = getFileDir(path);
+	if (!makeDirectories(parentdir.c_str())) return false;
+	return makeDirectory(path);
 }
 
 int getFileSize(const char* path)
 {
-int size;
-MFILE *f=mfopen(path,FOPEN_READ_BINARY);
-if (f==NULL) return -1;
-size=getFileSize(f);
-mfclose(f);
-return size;
+	int size;
+#ifdef _WIN32
+	MFILE *f = mfopen(Convert::utf8ToUtf16(path).c_str(), Convert::strTOwstr(FOPEN_READ_BINARY).c_str());
+#else
+	MFILE *f = mfopen(path, FOPEN_READ_BINARY);
+#endif
+	if (f == NULL) return -1;
+	size = getFileSize(f);
+	mfclose(f);
+	return size;
 }
 
 int getFileSize(MFILE *f)
 {
-  int saved_pos = mftell(f);
-  mfseek(f, 0, SEEK_END);
-  int size = mftell(f);
-  mfseek(f, saved_pos, SEEK_SET);
-  return size;
+	int saved_pos = mftell(f);
+	mfseek(f, 0, SEEK_END);
+	int size = mftell(f);
+	mfseek(f, saved_pos, SEEK_SET);
+	return size;
 }
 
 bool removeFile(const char* path)
 {
-  return _unlink(path)==0; //VS: "The POSIX name is deprecated. Instead, use the ISO C++ conformant name: _unlink"
+#ifdef _WIN32
+	return _wunlink(Convert::utf8ToUtf16(path).c_str()) == 0;
+#else
+	return _unlink(path) == 0; //VS: "The POSIX name is deprecated. Instead, use the ISO C++ conformant name: _unlink"
+#endif
 }
 
@@ -76,10 +92,6 @@
 {
 	if (fname == NULL) return false; //SplitFileSystem never passes NULL but this function is public so we never know
-#if defined _WIN32 && !defined SHP
- #ifdef __BORLANDC__
-	return PathIsRelative(fname) == FALSE; //no wide char for old borland compiler
- #else
-	return PathIsRelative(Convert::strTOwstr(fname).c_str()) == FALSE; //http://msdn.microsoft.com/en-us/library/bb773660%28v=vs.85%29.aspx
- #endif
+#if defined _WIN32
+	return PathIsRelativeW(Convert::utf8ToUtf16(fname).c_str()) == FALSE; //http://msdn.microsoft.com/en-us/library/bb773660%28v=vs.85%29.aspx
 #else
 	return fname[0] == PATH_SEPARATOR_CHAR;
Index: /cpp/common/nonstd_stdio.h
===================================================================
--- /cpp/common/nonstd_stdio.h	(revision 280)
+++ /cpp/common/nonstd_stdio.h	(revision 281)
@@ -20,24 +20,19 @@
  #include <dir.h>
 #else
- #ifndef MOBILE2D
  #include <direct.h>
- #endif
  #define mkdir _mkdir
+ #define S_ISDIR(m)	(((m)&S_IFDIR)==S_IFDIR)
 #endif
 
-#ifndef MOBILE2D
- #include <io.h> //borland compiler: include <io.h> before <dir.h> causes the SimWorld class in "simul.h" be unrecognized, for unknown reason :O moreover, this problem is only pertinent to the CLI project, not GUI. Maybe this is caused by global defines like NOVCL, NO_STRICT etc.?
+#include <io.h> //borland compiler: include <io.h> before <dir.h> causes the SimWorld class in "simul.h" be unrecognized, for unknown reason :O moreover, this problem is only pertinent to the CLI project, not GUI. Maybe this is caused by global defines like NOVCL, NO_STRICT etc.?
 // #define makeDirectory(name) mkdir(name)
-#endif
-
- #define S_ISDIR(x) ((x & _S_IFDIR)==_S_IFDIR)
 
 #else
 
- #include <unistd.h>
- #include <sys/stat.h>
+#include <unistd.h>
+#include <sys/stat.h>
 // #define makeDirectory(name) mkdir(name,0777)
- #define _unlink unlink //_unlink jest ISO-conformant, unlink jest POSIX-deprecated
- #define _stat stat
+#define _unlink unlink //_unlink jest ISO-conformant, unlink jest POSIX-deprecated
+#define _stat stat
 #endif
 
@@ -49,18 +44,18 @@
 #ifdef __ANDROID__
 #include <nv_file/nv_file.h>
- struct rwFILE //jedno z dwoch pol jest zainicjowane w zaleznosci od tego gdzie jest plik
- { //nvidia uses a similar trick in nv_file.h (STD_FILE and APK_FILE), maybe doing a similar thing here is redundant? but their trick uses some trial-and-error code (see NvFOpen())
+struct rwFILE //jedno z dwoch pol jest zainicjowane w zaleznosci od tego gdzie jest plik
+{ //nvidia uses a similar trick in nv_file.h (STD_FILE and APK_FILE), maybe doing a similar thing here is redundant? but their trick uses some trial-and-error code (see NvFOpen())
 	NvFile *rfile; //can only read
 	FILE *rwfile;
 	rwFILE() {rfile=rwfile=NULL;}
- };
- typedef rwFILE MFILE;
+};
+typedef rwFILE MFILE;
 #else //SHP:
- //z <stdio.h> wzielismy sprintfy i inne ktore dzia³aj¹...
- #include <FIo.h>
- // wklejone z sailora w ramach integracji frams+engine
- // ale to nie sprawia ze framsy korzystaja z mfile - potrzebna jest implementacja virtfile dla bady! (patrz: stdiofile.h)
- // i wtedy bedzie mozna mfile wywalic tez z sailora
- typedef Osp::Io::File MFILE;
+//z <stdio.h> wzielismy sprintfy i inne ktore dzia³aj¹...
+#include <FIo.h>
+// wklejone z sailora w ramach integracji frams+engine
+// ale to nie sprawia ze framsy korzystaja z mfile - potrzebna jest implementacja virtfile dla bady! (patrz: stdiofile.h)
+// i wtedy bedzie mozna mfile wywalic tez z sailora
+typedef Osp::Io::File MFILE;
 #endif
 
@@ -82,14 +77,18 @@
 
 #else
- typedef FILE MFILE;
+typedef FILE MFILE;
+#ifdef _WIN32
+ #define mfopen _wfopen
+#else
  #define mfopen fopen
- #define mfclose fclose
- #define mfread fread
- #define mfwrite fwrite
- #define mfputs fputs
- #define mfgets fgets
- #define mfeof feof
- #define mfseek fseek
- #define mftell ftell
+#endif
+#define mfclose fclose
+#define mfread fread
+#define mfwrite fwrite
+#define mfputs fputs
+#define mfgets fgets
+#define mfeof feof
+#define mfseek fseek
+#define mftell ftell
 #endif
 
Index: /cpp/common/stl-util.cpp
===================================================================
--- /cpp/common/stl-util.cpp	(revision 280)
+++ /cpp/common/stl-util.cpp	(revision 281)
@@ -7,4 +7,5 @@
 #include <stdlib.h>
 #include "nonstd_stdio.h"
+#include "Convert.h"
 #include "nonstd.h"
 #include "framsg.h"
@@ -91,5 +92,9 @@
 #endif
 	{
+#ifdef _WIN32
+		MFILE *f = mfopen(Convert::utf8ToUtf16(filename).c_str(), Convert::strTOwstr(FOPEN_READ_BINARY).c_str());
+#else
 		MFILE *f = mfopen(filename, FOPEN_READ_BINARY);
+#endif
 		if (f)
 		{
@@ -119,5 +124,9 @@
 bool writeCompleteFile(const char* filename, const string& text, bool warn_on_fail)
 {
+#ifdef _WIN32
+	MFILE *f = mfopen(Convert::utf8ToUtf16(filename).c_str(), Convert::strTOwstr(FOPEN_WRITE_BINARY).c_str());
+#else
 	MFILE *f = mfopen(filename, FOPEN_WRITE_BINARY);
+#endif
 	bool ok = f != NULL;
 	if (f)
Index: /cpp/frams/virtfile/stdiofile.cpp
===================================================================
--- /cpp/frams/virtfile/stdiofile.cpp	(revision 280)
+++ /cpp/frams/virtfile/stdiofile.cpp	(revision 281)
@@ -7,15 +7,20 @@
 #include <common/nonstd_stdio.h>
 #include <common/framsg.h>
+#include <common/Convert.h>
 
-VirtFILE* StdioFileSystem::Vfopen(const char* path,const char*mode)
+VirtFILE* StdioFileSystem::Vfopen(const char *path, const char *mode)
 {
 	//printFM("Vfopen %s %s",path,mode);
 #ifdef USE_MFILE
-	MFILE *f=mfopen(path,mode);
+	MFILE *f = mfopen(path, mode);
 #else
-	FILE *f=fopen(path,mode);
+#ifdef _WIN32
+	FILE *f = _wfopen(Convert::utf8ToUtf16(path).c_str(), Convert::strTOwstr(mode).c_str());
+#else
+	FILE *f = fopen(path, mode);
+#endif
 #endif
 	//printFM("%p",f);
-	if (f) return new StdioFILE(f,path); else return 0;
+	if (f) return new StdioFILE(f, path); else return 0;
 }
 
@@ -23,5 +28,9 @@
 {
 	//printFM("Vopendir %s",path);
-	DIR *d=opendir(path);
+#ifdef _WIN32
+	DIRTYPE *d = wopendir(Convert::utf8ToUtf16(path).c_str());
+#else
+	DIR *d = opendir(path);
+#endif
 	//printFM("%p",d);
 	if (d) return new StdioDIR(d); else return 0;
@@ -48,4 +57,11 @@
 {
 	//printFM("Vreaddir %s",dir);
+#ifdef _WIN32
+	wdirent *wde=wreaddir(dir);
+	if (wde==NULL) return NULL;
+	strcpy(de.d_name, Convert::wstrToUtf8(wde->d_name).c_str());
+	return &de;
+#else
 	return readdir(dir);
+#endif
 }
Index: /cpp/frams/virtfile/stdiofile.h
===================================================================
--- /cpp/frams/virtfile/stdiofile.h	(revision 280)
+++ /cpp/frams/virtfile/stdiofile.h	(revision 281)
@@ -15,81 +15,103 @@
 #include <common/nonstd_dir.h>
 
-class StdioFileSystem: public VirtFileSystem
+class StdioFileSystem : public VirtFileSystem
 {
 public:
-VirtFILE *Vfopen(const char* path,const char*mode);
-int Vfexists(const char* path);
-VirtDIR *Vopendir(const char* path);
+	VirtFILE *Vfopen(const char *path, const char *mode);
+	int Vfexists(const char* path);
+	VirtDIR *Vopendir(const char* path);
 };
 
 #ifdef USE_MFILE
-class StdioFILE: public VirtFILE
+class StdioFILE : public VirtFILE
 {
-  protected:
-MFILE *file;
-SString path;
-  public:
-StdioFILE(MFILE *f) {file=f;}
-StdioFILE(MFILE *f,const SString& p) {file=f;path=p;}
-static void setStdio();
-size_t Vread(void *ptr, size_t size, size_t nmemb) {return mfread(ptr,size,nmemb,file);}
-size_t Vwrite(const void *ptr, size_t size, size_t nmemb) {return mfwrite(ptr,size,nmemb,file);}
-int Veof() {return mfeof(file);}
-int Vputs(const char *s) {return mfputs(s,file);}
-char *Vgets(char *s, int size) {return mfgets(s,size,file);}
-int Vseek(long offset, int whence) {return mfseek(file,offset,whence);}
-long Vtell() {return mftell(file);}
-int Vflush() {return 0;/*NOT IMPLEMENTED!*/;}
-const char* VgetPath() {return path;}
+protected:
+	MFILE *file;
+	SString path;
+public:
+	StdioFILE(MFILE *f) { file = f; }
+	StdioFILE(MFILE *f, const SString& p) { file = f; path = p; }
+	static void setStdio();
+	size_t Vread(void *ptr, size_t size, size_t nmemb) { return mfread(ptr, size, nmemb, file); }
+	size_t Vwrite(const void *ptr, size_t size, size_t nmemb) { return mfwrite(ptr, size, nmemb, file); }
+	int Veof() { return mfeof(file); }
+	int Vputs(const char *s) { return mfputs(s, file); }
+	char *Vgets(char *s, int size) { return mfgets(s, size, file); }
+	int Vseek(long offset, int whence) { return mfseek(file, offset, whence); }
+	long Vtell() { return mftell(file); }
+	int Vflush() { return 0; /*NOT IMPLEMENTED!*/ }
+	const char* VgetPath() { return path; }
 
-~StdioFILE() {if (file) mfclose(file);}
+	~StdioFILE() { if (file) mfclose(file); }
 };
 #else
-class StdioFILE: public VirtFILE
+class StdioFILE : public VirtFILE
 {
-  protected:
-FILE *file;
-SString path;
-  public:
-StdioFILE(FILE *f) {file=f;}
-StdioFILE(FILE *f,const SString& p) {file=f;path=p;}
-static void setStdio();
-size_t Vread(void *ptr, size_t size, size_t nmemb) {return fread(ptr,size,nmemb,file);}
-size_t Vwrite(const void *ptr, size_t size, size_t nmemb) {return fwrite(ptr,size,nmemb,file);}
-int Veof() {return feof(file);}
-int Vputc(int c) {return fputc(c,file);}
-int Vputs(const char *s) {return fputs(s,file);}
-int Vgetc() {return fgetc(file);}
-char *Vgets(char *s, int size) {return fgets(s,size,file);}
-int Vprintf(const char *format, va_list args) { return vfprintf(file,format,args); }
-int Vseek(long offset, int whence) {return fseek(file,offset,whence);}
-long Vtell() {return ftell(file);}
-void Vrewind() {rewind(file);}
-int Vflush() {return fflush(file);}
-const char* VgetPath() {return path;}
+protected:
+	FILE *file;
+	SString path;
+public:
+	StdioFILE(FILE *f) { file = f; }
+	StdioFILE(FILE *f, const SString& p) { file = f; path = p; }
+	static void setStdio();
+	size_t Vread(void *ptr, size_t size, size_t nmemb) { return fread(ptr, size, nmemb, file); }
+	size_t Vwrite(const void *ptr, size_t size, size_t nmemb) { return fwrite(ptr, size, nmemb, file); }
+	int Veof() { return feof(file); }
+	int Vputc(int c) { return fputc(c, file); }
+	int Vputs(const char *s) { return fputs(s, file); }
+	int Vgetc() { return fgetc(file); }
+	char *Vgets(char *s, int size) { return fgets(s, size, file); }
+	int Vprintf(const char *format, va_list args) { return vfprintf(file, format, args); }
+	int Vseek(long offset, int whence) { return fseek(file, offset, whence); }
+	long Vtell() { return ftell(file); }
+	void Vrewind() { rewind(file); }
+	int Vflush() { return fflush(file); }
+	const char* VgetPath() { return path; }
 
-~StdioFILE() {if (file) fclose(file);}
+	~StdioFILE() { if (file) fclose(file); }
 };
 #endif
 
-class StdioDIR: public VirtDIR
+
+#ifdef _WIN32
+#ifdef __BORLANDC__
+ typedef wDIR DIRTYPE;
+#else
+ typedef WDIR DIRTYPE;
+#endif
+#else
+ typedef DIR DIRTYPE;
+#endif
+
+class StdioDIR : public VirtDIR
 {
-DIR *dir;
-  public:
-StdioDIR(DIR* d):dir(d) {}
-~StdioDIR() {if (dir) closedir(dir);}
-dirent* Vreaddir();
+	DIRTYPE *dir;
+#ifdef _WIN32
+	dirent de; //only used to convert wide string names (wdirent) to utf8 (dirent)
+#endif
+public:
+	StdioDIR(DIRTYPE *d) : dir(d) {}
+	~StdioDIR()
+	{
+#ifdef _WIN32
+		if (dir) wclosedir(dir);
+#else
+		if (dir) closedir(dir);
+#endif
+	}
+	dirent* Vreaddir();
 };
 
-class StdioFILEDontClose: public StdioFILE
+class StdioFILEDontClose : public StdioFILE
 {
-  public:
+public:
 #ifdef USE_MFILE
-StdioFILEDontClose(MFILE *f):StdioFILE(f) {}
+	StdioFILEDontClose(MFILE *f) : StdioFILE(f) {}
 #else
-StdioFILEDontClose(FILE *f):StdioFILE(f) {}
+	StdioFILEDontClose(FILE *f) : StdioFILE(f) {}
 #endif
-~StdioFILEDontClose() {file=0;}
+	~StdioFILEDontClose() { file = 0; }
 };
 
 #endif
+
