src/win32.cpp
branchgamebalance
changeset 9913 e79cd19772dd
parent 9912 1ac8aac92385
equal deleted inserted replaced
9912:1ac8aac92385 9913:e79cd19772dd
    21 #include <fcntl.h>
    21 #include <fcntl.h>
    22 #include <shlobj.h> // SHGetFolderPath
    22 #include <shlobj.h> // SHGetFolderPath
    23 #include "variables.h"
    23 #include "variables.h"
    24 #include "win32.h"
    24 #include "win32.h"
    25 #include "fios.h" // opendir/readdir/closedir
    25 #include "fios.h" // opendir/readdir/closedir
       
    26 #include "fileio.h"
    26 #include <ctype.h>
    27 #include <ctype.h>
    27 #include <tchar.h>
    28 #include <tchar.h>
    28 #include <errno.h>
    29 #include <errno.h>
    29 #include <sys/types.h>
    30 #include <sys/types.h>
    30 #include <sys/stat.h>
    31 #include <sys/stat.h>
       
    32 #include <shlobj.h>
    31 
    33 
    32 static bool _has_console;
    34 static bool _has_console;
    33 
    35 
    34 #if defined(__MINGW32__)
    36 #if defined(__MINGW32__)
    35 	#include <stdint.h>
    37 	#include <stdint.h>
   222 	_T("Be aware that critical parts of the internal game state may have become ")
   224 	_T("Be aware that critical parts of the internal game state may have become ")
   223 	_T("corrupted. The saved game is not guaranteed to work.");
   225 	_T("corrupted. The saved game is not guaranteed to work.");
   224 
   226 
   225 static bool EmergencySave()
   227 static bool EmergencySave()
   226 {
   228 {
   227 	SaveOrLoad("crash.sav", SL_SAVE);
   229 	SaveOrLoad("crash.sav", SL_SAVE, BASE_DIR);
   228 	return true;
   230 	return true;
   229 }
   231 }
   230 
   232 
   231 /* Disable the crash-save submit code as it's not used */
   233 /* Disable the crash-save submit code as it's not used */
   232 #if 0
   234 #if 0
   956 	GetCurrentDirectory(size, buf);
   958 	GetCurrentDirectory(size, buf);
   957 #endif
   959 #endif
   958 	return buf;
   960 	return buf;
   959 }
   961 }
   960 
   962 
   961 extern char *BuildWithFullPath(const char *dir);
       
   962 
   963 
   963 void DetermineBasePaths(const char *exe)
   964 void DetermineBasePaths(const char *exe)
   964 {
   965 {
   965 	_paths.personal_dir = MallocT<char>(MAX_PATH);
   966 	char tmp[MAX_PATH];
   966 	getcwd(_paths.personal_dir, MAX_PATH);
   967 	TCHAR path[MAX_PATH];
   967 
   968 #ifdef WITH_PERSONAL_DIR
   968 	_paths.game_data_dir = BuildWithFullPath(GAME_DATA_DIR);
   969 	SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, path);
   969 #if defined(SECOND_DATA_DIR)
   970 	strncpy(tmp, WIDE_TO_MB_BUFFER(path, tmp, lengthof(tmp)), lengthof(tmp));
   970 	_paths.second_data_dir = BuildWithFullPath(SECOND_DATA_DIR);
   971 	AppendPathSeparator(tmp, MAX_PATH);
       
   972 	ttd_strlcat(tmp, PERSONAL_DIR, MAX_PATH);
       
   973 	AppendPathSeparator(tmp, MAX_PATH);
       
   974 	_searchpaths[SP_PERSONAL_DIR] = strdup(tmp);
       
   975 
       
   976 	SHGetFolderPath(NULL, CSIDL_COMMON_DOCUMENTS, NULL, SHGFP_TYPE_CURRENT, path);
       
   977 	strncpy(tmp, WIDE_TO_MB_BUFFER(path, tmp, lengthof(tmp)), lengthof(tmp));
       
   978 	AppendPathSeparator(tmp, MAX_PATH);
       
   979 	ttd_strlcat(tmp, PERSONAL_DIR, MAX_PATH);
       
   980 	AppendPathSeparator(tmp, MAX_PATH);
       
   981 	_searchpaths[SP_SHARED_DIR] = strdup(tmp);
   971 #else
   982 #else
   972 	_paths.second_data_dir = NULL;
   983 	_searchpaths[SP_PERSONAL_DIR] = NULL;
   973 #endif
   984 	_searchpaths[SP_SHARED_DIR]   = NULL;
   974 
   985 #endif
   975 	_paths.personal_dir[0] = toupper(_paths.personal_dir[0]);
   986 
   976 	AppendPathSeparator(_paths.personal_dir,  MAX_PATH);
   987 	/* Get the path to working directory of OpenTTD */
       
   988 	getcwd(tmp, lengthof(tmp));
       
   989 	AppendPathSeparator(tmp, MAX_PATH);
       
   990 	_searchpaths[SP_WORKING_DIR] = strdup(tmp);
       
   991 
       
   992 	if (!GetModuleFileName(NULL, path, lengthof(path))) {
       
   993 		DEBUG(misc, 0, "GetModuleFileName failed (%d)\n", GetLastError());
       
   994 		_searchpaths[SP_BINARY_DIR] = NULL;
       
   995 	} else {
       
   996 		TCHAR exec_dir[MAX_PATH];
       
   997 		_tcsncpy(path, MB_TO_WIDE_BUFFER(exe, path, lengthof(path)), lengthof(path));
       
   998 		if (!GetFullPathName(path, lengthof(exec_dir), exec_dir, NULL)) {
       
   999 			DEBUG(misc, 0, "GetFullPathName failed (%d)\n", GetLastError());
       
  1000 			_searchpaths[SP_BINARY_DIR] = NULL;
       
  1001 		} else {
       
  1002 			strncpy(tmp, WIDE_TO_MB_BUFFER(exec_dir, tmp, lengthof(tmp)), lengthof(tmp));
       
  1003 			char *s = strrchr(tmp, PATHSEPCHAR);
       
  1004 			*(s + 1) = '\0';
       
  1005 			_searchpaths[SP_BINARY_DIR] = strdup(tmp);
       
  1006 		}
       
  1007 	}
       
  1008 
       
  1009 	_searchpaths[SP_INSTALLATION_DIR]       = NULL;
       
  1010 	_searchpaths[SP_APPLICATION_BUNDLE_DIR] = NULL;
   977 }
  1011 }
   978 
  1012 
   979 /**
  1013 /**
   980  * Insert a chunk of text from the clipboard onto the textbuffer. Get TEXT clipboard
  1014  * Insert a chunk of text from the clipboard onto the textbuffer. Get TEXT clipboard
   981  * and append this up to the maximum length (either absolute or screenlength). If maxlength
  1015  * and append this up to the maximum length (either absolute or screenlength). If maxlength