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 |