2014-10-06 18:36:58 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* Copyright (c) 2014 Ted John
|
|
|
|
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
|
|
|
*
|
|
|
|
* This file is part of OpenRCT2.
|
|
|
|
*
|
|
|
|
* OpenRCT2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
|
|
#include <windows.h>
|
2015-04-12 23:26:07 +02:00
|
|
|
#include <shlobj.h>
|
2015-02-12 21:51:40 +01:00
|
|
|
#include <SDL_syswm.h>
|
2015-06-22 13:49:35 +02:00
|
|
|
#include <sys/stat.h>
|
2014-10-09 01:30:22 +02:00
|
|
|
#include "../addresses.h"
|
|
|
|
#include "../cmdline.h"
|
|
|
|
#include "../openrct2.h"
|
2015-02-19 20:40:14 +01:00
|
|
|
#include "../localisation/language.h"
|
|
|
|
#include "../localisation/currency.h"
|
|
|
|
#include "../config.h"
|
2014-12-07 22:45:42 +01:00
|
|
|
#include "platform.h"
|
2014-10-09 01:30:22 +02:00
|
|
|
|
2014-10-09 15:03:54 +02:00
|
|
|
// The name of the mutex used to prevent multiple instances of the game from running
|
|
|
|
#define SINGLE_INSTANCE_MUTEX_NAME "RollerCoaster Tycoon 2_GSKMUTEX"
|
|
|
|
|
2014-10-09 01:30:22 +02:00
|
|
|
LPSTR *CommandLineToArgvA(LPSTR lpCmdLine, int *argc);
|
2014-10-06 18:36:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Windows entry point to OpenRCT2 without a console window.
|
|
|
|
*/
|
|
|
|
// int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
|
|
|
|
// {
|
|
|
|
// return 0;
|
|
|
|
// }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Windows entry point to OpenRCT2 with a console window using a traditional C main function.
|
|
|
|
*/
|
|
|
|
// int main(char *argv[], int argc)
|
|
|
|
// {
|
|
|
|
// return 0;
|
|
|
|
// }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Entry point for when the DLL is loaded. This will be removed when OpenRCT2 can be built as a stand alone application.
|
|
|
|
*/
|
|
|
|
BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The function that is called directly from the host application (rct2.exe)'s WinMain. This will be removed when OpenRCT2 can
|
|
|
|
* be built as a stand alone application.
|
|
|
|
*/
|
2014-10-09 01:30:22 +02:00
|
|
|
__declspec(dllexport) int StartOpenRCT(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
|
|
|
|
{
|
|
|
|
int argc, runGame;
|
|
|
|
char **argv;
|
|
|
|
|
|
|
|
RCT2_GLOBAL(RCT2_ADDRESS_HINSTANCE, HINSTANCE) = hInstance;
|
|
|
|
RCT2_GLOBAL(RCT2_ADDRESS_CMDLINE, LPSTR) = lpCmdLine;
|
|
|
|
|
|
|
|
// Get command line arguments in standard form
|
|
|
|
argv = CommandLineToArgvA(lpCmdLine, &argc);
|
|
|
|
runGame = cmdline_run(argv, argc);
|
2015-01-18 21:56:08 +01:00
|
|
|
GlobalFree(argv);
|
2014-10-09 01:30:22 +02:00
|
|
|
|
|
|
|
if (runGame)
|
|
|
|
openrct2_launch();
|
|
|
|
|
2015-05-29 00:04:02 +02:00
|
|
|
exit(gExitCode);
|
2014-10-09 01:30:22 +02:00
|
|
|
return gExitCode;
|
|
|
|
}
|
2014-10-06 18:36:58 +02:00
|
|
|
|
|
|
|
char platform_get_path_separator()
|
|
|
|
{
|
|
|
|
return '\\';
|
|
|
|
}
|
|
|
|
|
2014-10-09 15:03:54 +02:00
|
|
|
int platform_file_exists(const char *path)
|
|
|
|
{
|
2015-06-24 22:30:40 +02:00
|
|
|
return !(GetFileAttributes(path) == INVALID_FILE_ATTRIBUTES && (GetLastError() == ERROR_FILE_NOT_FOUND || GetLastError() == ERROR_PATH_NOT_FOUND));
|
2014-10-09 15:03:54 +02:00
|
|
|
}
|
|
|
|
|
2014-10-06 18:36:58 +02:00
|
|
|
int platform_directory_exists(const char *path)
|
|
|
|
{
|
|
|
|
DWORD dwAttrib = GetFileAttributes(path);
|
|
|
|
return dwAttrib != INVALID_FILE_ATTRIBUTES && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY);
|
|
|
|
}
|
|
|
|
|
2015-06-24 16:28:06 +02:00
|
|
|
int platform_original_game_data_exists(const char *path)
|
|
|
|
{
|
|
|
|
char checkPath[MAX_PATH];
|
|
|
|
sprintf(checkPath, "%s%c%s%c%s", path, platform_get_path_separator(), "data", platform_get_path_separator(), "g1.dat");
|
2015-06-24 18:16:22 +02:00
|
|
|
return platform_file_exists(checkPath);
|
2015-06-24 16:28:06 +02:00
|
|
|
}
|
|
|
|
|
2014-10-06 18:36:58 +02:00
|
|
|
int platform_ensure_directory_exists(const char *path)
|
|
|
|
{
|
|
|
|
if (platform_directory_exists(path))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return CreateDirectory(path, NULL);
|
|
|
|
}
|
|
|
|
|
2015-06-24 18:22:12 +02:00
|
|
|
int platform_directory_delete(const char *path)
|
|
|
|
{
|
|
|
|
char pszFrom[MAX_PATH];
|
|
|
|
strcpy(pszFrom, path);
|
|
|
|
// Needs to be double-null terminated for some weird reason
|
|
|
|
pszFrom[strlen(path) + 1] = 0;
|
|
|
|
|
|
|
|
SHFILEOPSTRUCTA fileop;
|
|
|
|
fileop.hwnd = NULL; // no status display
|
|
|
|
fileop.wFunc = FO_DELETE; // delete operation
|
|
|
|
fileop.pFrom = pszFrom; // source file name as double null terminated string
|
|
|
|
fileop.pTo = NULL; // no destination needed
|
|
|
|
fileop.fFlags = FOF_NOCONFIRMATION|FOF_SILENT; // do not prompt the user
|
|
|
|
|
|
|
|
fileop.fAnyOperationsAborted = FALSE;
|
|
|
|
fileop.lpszProgressTitle = NULL;
|
|
|
|
fileop.hNameMappings = NULL;
|
|
|
|
|
|
|
|
int ret = SHFileOperationA(&fileop);
|
|
|
|
return (ret == 0);
|
|
|
|
}
|
|
|
|
|
2014-10-09 15:03:54 +02:00
|
|
|
int platform_lock_single_instance()
|
|
|
|
{
|
|
|
|
HANDLE mutex, status;
|
|
|
|
|
|
|
|
// Check if operating system mutex exists
|
|
|
|
mutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, SINGLE_INSTANCE_MUTEX_NAME);
|
|
|
|
if (mutex == NULL) {
|
|
|
|
// Create new mutex
|
|
|
|
status = CreateMutex(NULL, FALSE, SINGLE_INSTANCE_MUTEX_NAME);
|
|
|
|
if (status == NULL)
|
2015-06-14 13:03:32 +02:00
|
|
|
log_error("unable to create mutex\n");
|
2014-10-09 15:03:54 +02:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
// Already running
|
|
|
|
CloseHandle(mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-17 04:22:45 +02:00
|
|
|
typedef struct {
|
|
|
|
char active;
|
|
|
|
char pattern[MAX_PATH];
|
|
|
|
HANDLE handle;
|
|
|
|
WIN32_FIND_DATAA data;
|
|
|
|
} enumerate_file_info;
|
|
|
|
static enumerate_file_info _enumerateFileInfoList[8] = { 0 };
|
|
|
|
|
|
|
|
int platform_enumerate_files_begin(const char *pattern)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
enumerate_file_info *enumFileInfo;
|
|
|
|
|
|
|
|
for (i = 0; i < countof(_enumerateFileInfoList); i++) {
|
|
|
|
enumFileInfo = &_enumerateFileInfoList[i];
|
|
|
|
if (!enumFileInfo->active) {
|
|
|
|
strncpy(enumFileInfo->pattern, pattern, MAX_PATH);
|
|
|
|
enumFileInfo->handle = NULL;
|
|
|
|
enumFileInfo->active = 1;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-07 22:45:42 +01:00
|
|
|
return INVALID_HANDLE;
|
2014-10-17 04:22:45 +02:00
|
|
|
}
|
|
|
|
|
2014-12-07 22:45:42 +01:00
|
|
|
int platform_enumerate_files_next(int handle, file_info *outFileInfo)
|
2014-10-17 04:22:45 +02:00
|
|
|
{
|
|
|
|
int result;
|
|
|
|
enumerate_file_info *enumFileInfo;
|
|
|
|
HANDLE findFileHandle;
|
|
|
|
|
|
|
|
enumFileInfo = &_enumerateFileInfoList[handle];
|
|
|
|
|
|
|
|
if (enumFileInfo->handle == NULL) {
|
|
|
|
findFileHandle = FindFirstFile(enumFileInfo->pattern, &enumFileInfo->data);
|
|
|
|
if (findFileHandle != INVALID_HANDLE_VALUE) {
|
|
|
|
enumFileInfo->handle = findFileHandle;
|
|
|
|
result = 1;
|
|
|
|
} else {
|
|
|
|
result = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result = FindNextFile(enumFileInfo->handle, &enumFileInfo->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result) {
|
2014-12-07 22:45:42 +01:00
|
|
|
outFileInfo->path = enumFileInfo->data.cFileName;
|
|
|
|
outFileInfo->size = ((uint64)enumFileInfo->data.nFileSizeHigh << 32ULL) | (uint64)enumFileInfo->data.nFileSizeLow;
|
|
|
|
outFileInfo->last_modified = ((uint64)enumFileInfo->data.ftLastWriteTime.dwHighDateTime << 32ULL) | (uint64)enumFileInfo->data.ftLastWriteTime.dwLowDateTime;
|
2014-10-17 04:22:45 +02:00
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void platform_enumerate_files_end(int handle)
|
|
|
|
{
|
|
|
|
enumerate_file_info *enumFileInfo;
|
|
|
|
|
|
|
|
enumFileInfo = &_enumerateFileInfoList[handle];
|
|
|
|
if (enumFileInfo->handle != NULL) {
|
|
|
|
FindClose(enumFileInfo->handle);
|
|
|
|
enumFileInfo->handle = NULL;
|
|
|
|
}
|
|
|
|
enumFileInfo->active = 0;
|
|
|
|
}
|
|
|
|
|
2015-02-14 22:59:58 +01:00
|
|
|
int platform_enumerate_directories_begin(const char *directory)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
enumerate_file_info *enumFileInfo;
|
|
|
|
|
|
|
|
if (strlen(directory) + 3 >= MAX_PATH)
|
|
|
|
return INVALID_HANDLE;
|
|
|
|
|
|
|
|
for (i = 0; i < countof(_enumerateFileInfoList); i++) {
|
|
|
|
enumFileInfo = &_enumerateFileInfoList[i];
|
|
|
|
if (!enumFileInfo->active) {
|
|
|
|
strncpy(enumFileInfo->pattern, directory, MAX_PATH);
|
|
|
|
strncat(enumFileInfo->pattern, "*", MAX_PATH);
|
|
|
|
enumFileInfo->handle = NULL;
|
|
|
|
enumFileInfo->active = 1;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int platform_enumerate_directories_next(int handle, char *path)
|
|
|
|
{
|
|
|
|
enumerate_file_info *enumFileInfo;
|
|
|
|
HANDLE fileHandle;
|
|
|
|
|
|
|
|
enumFileInfo = &_enumerateFileInfoList[handle];
|
|
|
|
|
|
|
|
if (enumFileInfo->handle == NULL) {
|
|
|
|
fileHandle = FindFirstFile(enumFileInfo->pattern, &enumFileInfo->data);
|
|
|
|
if (fileHandle != 0) {
|
|
|
|
enumFileInfo->handle = fileHandle;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
2015-02-15 15:20:19 +01:00
|
|
|
if (!FindNextFile(enumFileInfo->handle, &enumFileInfo->data)) {
|
2015-02-14 22:59:58 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-15 18:31:16 +01:00
|
|
|
while (
|
|
|
|
(enumFileInfo->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0
|
|
|
|
|| strchr(enumFileInfo->data.cFileName, '.') != NULL
|
|
|
|
) {
|
2015-02-15 15:20:19 +01:00
|
|
|
if (!FindNextFile(enumFileInfo->handle, &enumFileInfo->data)) {
|
2015-02-14 22:59:58 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(path, '\0', MAX_PATH);
|
2015-02-15 15:20:19 +01:00
|
|
|
strncpy(path, enumFileInfo->data.cFileName, MAX_PATH);
|
2015-02-14 22:59:58 +01:00
|
|
|
strncat(path, "\\", MAX_PATH);
|
|
|
|
return 1;
|
|
|
|
}
|
2015-02-15 18:31:16 +01:00
|
|
|
|
|
|
|
void platform_enumerate_directories_end(int handle)
|
2015-02-14 22:59:58 +01:00
|
|
|
{
|
|
|
|
enumerate_file_info *enumFileInfo;
|
|
|
|
|
|
|
|
enumFileInfo = &_enumerateFileInfoList[handle];
|
|
|
|
if (enumFileInfo->handle != NULL) {
|
|
|
|
FindClose(enumFileInfo->handle);
|
|
|
|
enumFileInfo->handle = NULL;
|
|
|
|
}
|
|
|
|
enumFileInfo->active = 0;
|
|
|
|
}
|
|
|
|
|
2015-06-22 15:55:57 +02:00
|
|
|
int platform_get_drives(){
|
|
|
|
return GetLogicalDrives();
|
|
|
|
}
|
|
|
|
|
2015-02-14 03:16:03 +01:00
|
|
|
int platform_file_copy(const char *srcPath, const char *dstPath)
|
|
|
|
{
|
|
|
|
return CopyFileA(srcPath, dstPath, TRUE);
|
|
|
|
}
|
|
|
|
|
2015-02-12 21:51:40 +01:00
|
|
|
int platform_file_move(const char *srcPath, const char *dstPath)
|
|
|
|
{
|
|
|
|
return MoveFileA(srcPath, dstPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
int platform_file_delete(const char *path)
|
|
|
|
{
|
|
|
|
return DeleteFileA(path);
|
|
|
|
}
|
|
|
|
|
2014-11-10 23:37:55 +01:00
|
|
|
void platform_hide_cursor()
|
|
|
|
{
|
|
|
|
ShowCursor(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void platform_show_cursor()
|
|
|
|
{
|
|
|
|
ShowCursor(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void platform_get_cursor_position(int *x, int *y)
|
|
|
|
{
|
|
|
|
POINT point;
|
|
|
|
|
|
|
|
if (GetCursorPos(&point)) {
|
|
|
|
*x = point.x;
|
|
|
|
*y = point.y;
|
|
|
|
} else {
|
|
|
|
*x = INT32_MIN;
|
|
|
|
*y = INT32_MIN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void platform_set_cursor_position(int x, int y)
|
|
|
|
{
|
|
|
|
SetCursorPos(x, y);
|
|
|
|
}
|
|
|
|
|
2014-11-30 21:26:53 +01:00
|
|
|
unsigned int platform_get_ticks()
|
|
|
|
{
|
|
|
|
return GetTickCount();
|
|
|
|
}
|
|
|
|
|
2015-02-14 03:16:03 +01:00
|
|
|
void platform_get_user_directory(char *outPath, const char *subDirectory)
|
2015-02-12 21:51:40 +01:00
|
|
|
{
|
2015-06-24 12:41:19 +02:00
|
|
|
char separator[2] = { platform_get_path_separator(), 0 };
|
2015-02-14 03:16:03 +01:00
|
|
|
|
|
|
|
if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_PERSONAL | CSIDL_FLAG_CREATE, NULL, 0, outPath))) {
|
2015-06-24 12:41:19 +02:00
|
|
|
strcat(outPath, separator);
|
2015-02-14 03:16:03 +01:00
|
|
|
strcat(outPath, "OpenRCT2");
|
2015-06-24 12:41:19 +02:00
|
|
|
strcat(outPath, separator);
|
2015-02-14 03:16:03 +01:00
|
|
|
if (subDirectory != NULL && subDirectory[0] != 0) {
|
|
|
|
strcat(outPath, subDirectory);
|
2015-06-24 12:41:19 +02:00
|
|
|
strcat(outPath, separator);
|
2015-02-14 03:16:03 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
outPath[0] = 0;
|
2015-02-12 21:51:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void platform_show_messagebox(char *message)
|
|
|
|
{
|
|
|
|
MessageBoxA(windows_get_window_handle(), message, "OpenRCT2", MB_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x004080EA
|
|
|
|
*/
|
2015-07-29 20:56:50 +02:00
|
|
|
int platform_open_common_file_dialog(int type, utf8 *title, utf8 *filename, utf8 *filterPattern, utf8 *filterName)
|
2015-02-12 21:51:40 +01:00
|
|
|
{
|
2015-07-29 20:56:50 +02:00
|
|
|
wchar_t wctitle[256], wcfilename[MAX_PATH], wcfilterPattern[256], wcfilterName[256];
|
|
|
|
wchar_t initialDirectory[MAX_PATH], *dotAddress, *slashAddress;
|
|
|
|
OPENFILENAMEW openFileName;
|
2015-02-12 21:51:40 +01:00
|
|
|
BOOL result;
|
|
|
|
int tmp;
|
|
|
|
DWORD commonFlags;
|
|
|
|
|
2015-07-29 20:56:50 +02:00
|
|
|
MultiByteToWideChar(CP_UTF8, 0, title, -1, wctitle, countof(wctitle));
|
|
|
|
MultiByteToWideChar(CP_UTF8, 0, filename, -1, wcfilename, countof(wcfilename));
|
|
|
|
MultiByteToWideChar(CP_UTF8, 0, filterPattern, -1, wcfilterPattern, countof(wcfilterPattern));
|
|
|
|
MultiByteToWideChar(CP_UTF8, 0, filterName, -1, wcfilterName, countof(wcfilterName));
|
|
|
|
|
2015-02-12 21:51:40 +01:00
|
|
|
// Get directory path from given filename
|
2015-07-29 20:56:50 +02:00
|
|
|
lstrcpyW(initialDirectory, wcfilename);
|
|
|
|
dotAddress = wcsrchr(initialDirectory, '.');
|
2015-02-12 21:51:40 +01:00
|
|
|
if (dotAddress != NULL) {
|
2015-07-29 20:56:50 +02:00
|
|
|
slashAddress = wcsrchr(initialDirectory, '\\');
|
2015-02-12 21:51:40 +01:00
|
|
|
if (slashAddress < dotAddress)
|
|
|
|
*(slashAddress + 1) = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear filename
|
|
|
|
if (type != 0)
|
2015-07-29 20:56:50 +02:00
|
|
|
wcfilename[0] = 0;
|
2015-02-12 21:51:40 +01:00
|
|
|
|
|
|
|
// Set open file name options
|
2015-07-29 20:56:50 +02:00
|
|
|
memset(&openFileName, 0, sizeof(OPENFILENAMEW));
|
|
|
|
openFileName.lStructSize = sizeof(OPENFILENAMEW);
|
2015-02-12 21:51:40 +01:00
|
|
|
openFileName.hwndOwner = windows_get_window_handle();
|
2015-07-29 20:56:50 +02:00
|
|
|
openFileName.lpstrFile = wcfilename;
|
2015-02-12 21:51:40 +01:00
|
|
|
openFileName.nMaxFile = MAX_PATH;
|
|
|
|
openFileName.lpstrInitialDir = initialDirectory;
|
2015-07-29 20:56:50 +02:00
|
|
|
openFileName.lpstrTitle = wctitle;
|
2015-02-12 21:51:40 +01:00
|
|
|
|
|
|
|
// Copy filter name
|
2015-07-29 20:56:50 +02:00
|
|
|
lstrcpyW((wchar_t*)0x01423800, wcfilterName);
|
2015-02-12 21:51:40 +01:00
|
|
|
|
|
|
|
// Copy filter pattern
|
2015-08-01 17:40:15 +02:00
|
|
|
int wcfilterNameLength = lstrlenW(wcfilterName);
|
|
|
|
int wcfilterPatternLength = lstrlenW(wcfilterPattern);
|
|
|
|
|
|
|
|
lstrcpyW((wchar_t*)0x01423800 + wcfilterNameLength + 1, wcfilterPattern);
|
|
|
|
*((wchar_t*)((wchar_t*)0x01423800 + wcfilterNameLength + 1 + wcfilterPatternLength + 1)) = 0;
|
2015-07-29 20:56:50 +02:00
|
|
|
openFileName.lpstrFilter = (wchar_t*)0x01423800;
|
2015-02-12 21:51:40 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
tmp = RCT2_GLOBAL(0x009E2C74, uint32);
|
|
|
|
if (RCT2_GLOBAL(0x009E2BB8, uint32) == 2 && RCT2_GLOBAL(0x009E1AF8, uint32) == 1)
|
|
|
|
RCT2_GLOBAL(0x009E2C74, uint32) = 1;
|
|
|
|
|
|
|
|
// Open dialog
|
|
|
|
commonFlags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_NOCHANGEDIR;
|
|
|
|
if (type == 0) {
|
|
|
|
openFileName.Flags = commonFlags | OFN_CREATEPROMPT | OFN_OVERWRITEPROMPT;
|
2015-07-29 20:56:50 +02:00
|
|
|
result = GetSaveFileNameW(&openFileName);
|
2015-02-12 21:51:40 +01:00
|
|
|
} else if (type == 1) {
|
|
|
|
openFileName.Flags = commonFlags | OFN_NONETWORKBUTTON | OFN_FILEMUSTEXIST;
|
2015-07-29 20:56:50 +02:00
|
|
|
result = GetOpenFileNameW(&openFileName);
|
2015-02-12 21:51:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
RCT2_GLOBAL(0x009E2C74, uint32) = tmp;
|
|
|
|
|
2015-07-29 20:56:50 +02:00
|
|
|
WideCharToMultiByte(CP_UTF8, 0, wcfilename, countof(wcfilename), filename, MAX_PATH, NULL, NULL);
|
|
|
|
|
2015-02-12 21:51:40 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-08-01 17:40:15 +02:00
|
|
|
utf8 *platform_open_directory_browser(utf8 *title)
|
2015-02-12 21:51:40 +01:00
|
|
|
{
|
2015-08-01 17:40:15 +02:00
|
|
|
BROWSEINFOW bi;
|
|
|
|
wchar_t pszBuffer[MAX_PATH], wctitle[256];
|
2015-02-12 21:51:40 +01:00
|
|
|
LPITEMIDLIST pidl;
|
|
|
|
LPMALLOC lpMalloc;
|
|
|
|
|
2015-08-01 17:40:15 +02:00
|
|
|
MultiByteToWideChar(CP_UTF8, 0, title, -1, wctitle, countof(wctitle));
|
|
|
|
|
2015-02-12 21:51:40 +01:00
|
|
|
// Initialize COM
|
|
|
|
if (FAILED(CoInitializeEx(0, COINIT_APARTMENTTHREADED))) {
|
|
|
|
CoUninitialize();
|
|
|
|
|
|
|
|
log_error("Error opening directory browse window");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get a pointer to the shell memory allocator
|
|
|
|
if (FAILED(SHGetMalloc(&lpMalloc))) {
|
|
|
|
CoUninitialize();
|
|
|
|
|
|
|
|
log_error("Error opening directory browse window");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bi.hwndOwner = NULL;
|
|
|
|
bi.pidlRoot = NULL;
|
|
|
|
bi.pszDisplayName = pszBuffer;
|
2015-08-01 17:40:15 +02:00
|
|
|
bi.lpszTitle = wctitle;
|
2015-02-12 21:51:40 +01:00
|
|
|
bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
|
|
|
|
bi.lpfn = NULL;
|
|
|
|
bi.lParam = 0;
|
|
|
|
|
2015-08-01 17:40:15 +02:00
|
|
|
utf8 *outPath = NULL;
|
2015-02-12 21:51:40 +01:00
|
|
|
|
2015-08-01 17:40:15 +02:00
|
|
|
if (pidl = SHBrowseForFolderW(&bi)) {
|
2015-02-12 21:51:40 +01:00
|
|
|
// Copy the path directory to the buffer
|
2015-08-01 17:40:15 +02:00
|
|
|
if (SHGetPathFromIDListW(pidl, pszBuffer)) {
|
2015-02-12 21:51:40 +01:00
|
|
|
// Store pszBuffer (and the path) in the outPath
|
2015-08-01 17:40:15 +02:00
|
|
|
int outPathCapacity = lstrlenW(pszBuffer) * 4 + 1;
|
|
|
|
outPath = (utf8*)malloc(outPathCapacity);
|
|
|
|
WideCharToMultiByte(CP_UTF8, 0, pszBuffer, countof(pszBuffer), outPath, outPathCapacity, NULL, NULL);
|
2015-02-12 21:51:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
CoUninitialize();
|
|
|
|
return outPath;
|
|
|
|
}
|
|
|
|
|
2015-02-11 23:17:49 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x00407978
|
|
|
|
*/
|
|
|
|
int windows_get_registry_install_info(rct2_install_info *installInfo, char *source, char *font, uint8 charset)
|
|
|
|
{
|
|
|
|
char subkeyInfogrames[MAX_PATH], subkeyFishTechGroup[MAX_PATH], keyName[100];
|
|
|
|
LOGFONTA lf;
|
|
|
|
HKEY hKey;
|
|
|
|
DWORD type, size;
|
|
|
|
|
|
|
|
strcpy(subkeyInfogrames, "Software\\Infogrames\\");
|
|
|
|
strcat(subkeyInfogrames, source);
|
|
|
|
strcpy(subkeyFishTechGroup, "Software\\Fish Technology Group\\");
|
|
|
|
strcat(subkeyFishTechGroup, source);
|
|
|
|
|
|
|
|
memset(&lf, 0, sizeof(lf));
|
|
|
|
lf.lfCharSet = charset;
|
|
|
|
lf.lfHeight = 12;
|
|
|
|
lf.lfWeight = 400;
|
|
|
|
strcpy(lf.lfFaceName, font);
|
|
|
|
|
|
|
|
RCT2_GLOBAL(RCT2_ADDRESS_HFONT, HFONT) = CreateFontIndirectA(&lf);
|
|
|
|
|
|
|
|
if (RegOpenKeyA(HKEY_LOCAL_MACHINE, subkeyInfogrames, &hKey) != ERROR_SUCCESS)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (RegOpenKeyA(HKEY_LOCAL_MACHINE, subkeyFishTechGroup, &hKey) != ERROR_SUCCESS)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
size = 260;
|
|
|
|
RegQueryValueExA(hKey, "Title", 0, &type, installInfo->title, &size);
|
|
|
|
|
|
|
|
size = 260;
|
|
|
|
RegQueryValueExA(hKey, "Path", 0, &type, installInfo->path, &size);
|
|
|
|
|
|
|
|
installInfo->var_20C = 235960;
|
|
|
|
|
|
|
|
size = 4;
|
|
|
|
RegQueryValueExA(hKey, "InstallLevel", 0, &type, (LPBYTE)&installInfo->installLevel, &size);
|
|
|
|
for (int i = 0; i <= 15; i++) {
|
|
|
|
sprintf(keyName, "AddonPack%d", i);
|
|
|
|
size = sizeof(installInfo->expansionPackNames[i]);
|
|
|
|
if (RegQueryValueExA(hKey, keyName, 0, &type, installInfo->expansionPackNames[i], &size) == ERROR_SUCCESS)
|
|
|
|
installInfo->activeExpansionPacks |= (1 << i);
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-02-12 21:51:40 +01:00
|
|
|
HWND windows_get_window_handle()
|
|
|
|
{
|
|
|
|
SDL_SysWMinfo wmInfo;
|
|
|
|
|
|
|
|
if (gWindow == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
SDL_VERSION(&wmInfo.version);
|
|
|
|
if (SDL_GetWindowWMInfo(gWindow, &wmInfo) != SDL_TRUE) {
|
|
|
|
log_error("SDL_GetWindowWMInfo failed %s", SDL_GetError());
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
return wmInfo.info.win.window;
|
|
|
|
}
|
|
|
|
|
2014-10-09 01:30:22 +02:00
|
|
|
/**
|
|
|
|
* http://alter.org.ua/en/docs/win/args/
|
|
|
|
*/
|
|
|
|
PCHAR *CommandLineToArgvA(PCHAR CmdLine, int *_argc)
|
|
|
|
{
|
|
|
|
PCHAR* argv;
|
|
|
|
PCHAR _argv;
|
|
|
|
ULONG len;
|
|
|
|
ULONG argc;
|
|
|
|
CHAR a;
|
|
|
|
ULONG i, j;
|
|
|
|
|
|
|
|
BOOLEAN in_QM;
|
|
|
|
BOOLEAN in_TEXT;
|
|
|
|
BOOLEAN in_SPACE;
|
|
|
|
|
|
|
|
len = strlen(CmdLine);
|
|
|
|
i = ((len + 2) / 2)*sizeof(PVOID) + sizeof(PVOID);
|
|
|
|
|
|
|
|
argv = (PCHAR*)GlobalAlloc(GMEM_FIXED,
|
2015-01-18 21:56:08 +01:00
|
|
|
i + (len + 2)*sizeof(CHAR) + 1);
|
2014-10-09 01:30:22 +02:00
|
|
|
|
|
|
|
_argv = (PCHAR)(((PUCHAR)argv) + i);
|
|
|
|
|
2015-01-18 21:56:08 +01:00
|
|
|
// Add in virtual 1st command line argument, process path, for arg_parse's sake.
|
|
|
|
argv[0] = 0;
|
|
|
|
argc = 1;
|
2014-10-09 01:30:22 +02:00
|
|
|
argv[argc] = _argv;
|
|
|
|
in_QM = FALSE;
|
|
|
|
in_TEXT = FALSE;
|
|
|
|
in_SPACE = TRUE;
|
|
|
|
i = 0;
|
|
|
|
j = 0;
|
|
|
|
|
|
|
|
while (a = CmdLine[i]) {
|
|
|
|
if (in_QM) {
|
|
|
|
if (a == '\"') {
|
|
|
|
in_QM = FALSE;
|
|
|
|
} else {
|
|
|
|
_argv[j] = a;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (a) {
|
|
|
|
case '\"':
|
|
|
|
in_QM = TRUE;
|
|
|
|
in_TEXT = TRUE;
|
|
|
|
if (in_SPACE) {
|
|
|
|
argv[argc] = _argv + j;
|
|
|
|
argc++;
|
|
|
|
}
|
|
|
|
in_SPACE = FALSE;
|
|
|
|
break;
|
|
|
|
case ' ':
|
|
|
|
case '\t':
|
|
|
|
case '\n':
|
|
|
|
case '\r':
|
|
|
|
if (in_TEXT) {
|
|
|
|
_argv[j] = '\0';
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
in_TEXT = FALSE;
|
|
|
|
in_SPACE = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
in_TEXT = TRUE;
|
|
|
|
if (in_SPACE) {
|
|
|
|
argv[argc] = _argv + j;
|
|
|
|
argc++;
|
|
|
|
}
|
|
|
|
_argv[j] = a;
|
|
|
|
j++;
|
|
|
|
in_SPACE = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
_argv[j] = '\0';
|
|
|
|
argv[argc] = NULL;
|
|
|
|
|
|
|
|
(*_argc) = argc;
|
|
|
|
return argv;
|
|
|
|
}
|
|
|
|
|
2015-02-19 20:40:14 +01:00
|
|
|
uint16 platform_get_locale_language(){
|
2015-02-21 17:13:15 +01:00
|
|
|
CHAR langCode[4];
|
2015-02-19 20:40:14 +01:00
|
|
|
|
2015-02-21 00:09:02 +01:00
|
|
|
if (GetLocaleInfo(LOCALE_USER_DEFAULT,
|
2015-02-19 20:40:14 +01:00
|
|
|
LOCALE_SABBREVLANGNAME,
|
2015-02-21 17:13:15 +01:00
|
|
|
(LPSTR)&langCode,
|
|
|
|
sizeof(langCode)) == 0){
|
2015-02-19 20:40:14 +01:00
|
|
|
return LANGUAGE_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
2015-02-21 17:13:15 +01:00
|
|
|
if (strcmp(langCode, "ENG") == 0){
|
2015-02-19 20:40:14 +01:00
|
|
|
return LANGUAGE_ENGLISH_UK;
|
|
|
|
}
|
2015-02-21 17:13:15 +01:00
|
|
|
else if (strcmp(langCode, "ENU") == 0){
|
2015-02-19 20:40:14 +01:00
|
|
|
return LANGUAGE_ENGLISH_US;
|
|
|
|
}
|
2015-02-21 17:13:15 +01:00
|
|
|
else if (strcmp(langCode, "DEU") == 0){
|
2015-02-19 20:40:14 +01:00
|
|
|
return LANGUAGE_GERMAN;
|
|
|
|
}
|
2015-02-21 17:13:15 +01:00
|
|
|
else if (strcmp(langCode, "NLD") == 0){
|
2015-02-19 20:40:14 +01:00
|
|
|
return LANGUAGE_DUTCH;
|
|
|
|
}
|
2015-02-21 17:13:15 +01:00
|
|
|
else if (strcmp(langCode, "FRA") == 0){
|
2015-02-19 20:40:14 +01:00
|
|
|
return LANGUAGE_FRENCH;
|
|
|
|
}
|
2015-02-21 17:13:15 +01:00
|
|
|
else if (strcmp(langCode, "HUN") == 0){
|
2015-02-19 20:40:14 +01:00
|
|
|
return LANGUAGE_HUNGARIAN;
|
|
|
|
}
|
2015-02-21 17:13:15 +01:00
|
|
|
else if (strcmp(langCode, "PLK") == 0){
|
2015-02-19 20:40:14 +01:00
|
|
|
return LANGUAGE_POLISH;
|
|
|
|
}
|
2015-02-21 17:13:15 +01:00
|
|
|
else if (strcmp(langCode, "ESP") == 0){
|
2015-02-19 20:40:14 +01:00
|
|
|
return LANGUAGE_SPANISH;
|
|
|
|
}
|
2015-02-21 17:13:15 +01:00
|
|
|
else if (strcmp(langCode, "SVE") == 0){
|
2015-02-19 20:40:14 +01:00
|
|
|
return LANGUAGE_SWEDISH;
|
|
|
|
}
|
2015-06-10 12:57:57 +02:00
|
|
|
else if (strcmp(langCode, "ITA") == 0){
|
|
|
|
return LANGUAGE_ITALIAN;
|
|
|
|
}
|
2015-06-21 15:13:40 +02:00
|
|
|
else if (strcmp(langCode, "POR") == 0){
|
|
|
|
return LANGUAGE_PORTUGUESE_BR;
|
|
|
|
}
|
2015-02-19 20:40:14 +01:00
|
|
|
return LANGUAGE_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
2015-06-22 13:49:35 +02:00
|
|
|
time_t platform_file_get_modified_time(char* path){
|
2015-06-25 19:46:48 +02:00
|
|
|
WIN32_FILE_ATTRIBUTE_DATA data;
|
|
|
|
if (!GetFileAttributesEx(path, GetFileExInfoStandard, &data))
|
|
|
|
return 0;
|
|
|
|
ULARGE_INTEGER ull;
|
|
|
|
ull.LowPart = data.ftLastWriteTime.dwLowDateTime;
|
|
|
|
ull.HighPart = data.ftLastWriteTime.dwHighDateTime;
|
|
|
|
return ull.QuadPart / 10000000ULL - 11644473600ULL;
|
2015-06-22 13:49:35 +02:00
|
|
|
}
|
|
|
|
|
2015-02-19 20:40:14 +01:00
|
|
|
uint8 platform_get_locale_currency(){
|
2015-02-21 17:13:15 +01:00
|
|
|
CHAR currCode[4];
|
2015-02-19 20:40:14 +01:00
|
|
|
|
2015-02-21 00:09:02 +01:00
|
|
|
if (GetLocaleInfo(LOCALE_USER_DEFAULT,
|
2015-02-19 20:40:14 +01:00
|
|
|
LOCALE_SINTLSYMBOL,
|
2015-02-21 17:13:15 +01:00
|
|
|
(LPSTR)&currCode,
|
|
|
|
sizeof(currCode)) == 0){
|
2015-02-19 20:40:14 +01:00
|
|
|
return CURRENCY_POUNDS;
|
|
|
|
}
|
2015-02-21 17:26:38 +01:00
|
|
|
if (strcmp(currCode, "GBP") == 0){
|
2015-02-19 20:40:14 +01:00
|
|
|
return CURRENCY_POUNDS;
|
|
|
|
}
|
2015-02-21 17:13:15 +01:00
|
|
|
else if (strcmp(currCode, "USD") == 0){
|
2015-02-19 20:40:14 +01:00
|
|
|
return CURRENCY_DOLLARS;
|
|
|
|
}
|
2015-02-21 17:13:15 +01:00
|
|
|
else if (strcmp(currCode, "EUR") == 0){
|
2015-02-19 20:40:14 +01:00
|
|
|
return CURRENCY_EUROS;
|
|
|
|
}
|
2015-02-21 17:13:15 +01:00
|
|
|
else if (strcmp(currCode, "SEK") == 0){
|
2015-02-19 20:40:14 +01:00
|
|
|
return CURRENCY_KRONA;
|
|
|
|
}
|
2015-02-21 17:13:15 +01:00
|
|
|
else if (strcmp(currCode, "DEM") == 0){
|
|
|
|
return CURRENCY_DEUTSCHMARK;
|
2015-02-19 20:40:14 +01:00
|
|
|
}
|
2015-02-21 17:13:15 +01:00
|
|
|
else if (strcmp(currCode, "ITL") == 0){
|
2015-02-19 20:40:14 +01:00
|
|
|
return CURRENCY_LIRA;
|
|
|
|
}
|
2015-02-21 17:13:15 +01:00
|
|
|
else if (strcmp(currCode, "JPY") == 0){
|
2015-02-19 20:40:14 +01:00
|
|
|
return CURRENCY_YEN;
|
|
|
|
}
|
2015-02-21 17:13:15 +01:00
|
|
|
else if (strcmp(currCode, "ESP") == 0){
|
2015-02-19 20:40:14 +01:00
|
|
|
return CURRENCY_PESETA;
|
|
|
|
}
|
2015-02-21 17:13:15 +01:00
|
|
|
else if (strcmp(currCode, "FRF") == 0){
|
2015-02-19 20:40:14 +01:00
|
|
|
return CURRENCY_FRANC;
|
|
|
|
}
|
2015-02-21 17:13:15 +01:00
|
|
|
else if (strcmp(currCode, "NLG") == 0){
|
2015-02-19 20:40:14 +01:00
|
|
|
return CURRENCY_GUILDERS;
|
|
|
|
}
|
|
|
|
return CURRENCY_POUNDS;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8 platform_get_locale_measurement_format(){
|
|
|
|
UINT measurement_system;
|
2015-02-21 00:09:02 +01:00
|
|
|
if (GetLocaleInfo(LOCALE_USER_DEFAULT,
|
2015-02-19 20:40:14 +01:00
|
|
|
LOCALE_IMEASURE | LOCALE_RETURN_NUMBER,
|
2015-02-21 17:13:15 +01:00
|
|
|
(LPSTR)&measurement_system,
|
2015-02-19 20:40:14 +01:00
|
|
|
sizeof(measurement_system)) == 0){
|
|
|
|
return MEASUREMENT_FORMAT_IMPERIAL;
|
|
|
|
}
|
|
|
|
switch (measurement_system){
|
|
|
|
case 0:
|
|
|
|
return MEASUREMENT_FORMAT_METRIC;
|
|
|
|
case 1:
|
|
|
|
default:
|
|
|
|
return MEASUREMENT_FORMAT_IMPERIAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8 platform_get_locale_temperature_format(){
|
|
|
|
// There does not seem to be a function to obtain this, just check the countries
|
|
|
|
UINT country;
|
2015-02-21 00:09:02 +01:00
|
|
|
if (GetLocaleInfo(LOCALE_USER_DEFAULT,
|
2015-02-19 20:40:14 +01:00
|
|
|
LOCALE_IMEASURE | LOCALE_RETURN_NUMBER,
|
2015-02-21 17:13:15 +01:00
|
|
|
(LPSTR)&country,
|
2015-02-19 20:40:14 +01:00
|
|
|
sizeof(country)) == 0){
|
|
|
|
return TEMPERATURE_FORMAT_C;
|
|
|
|
}
|
|
|
|
switch (country){
|
|
|
|
case CTRY_UNITED_STATES:
|
|
|
|
case CTRY_BELIZE:
|
|
|
|
return TEMPERATURE_FORMAT_F;
|
|
|
|
default:
|
|
|
|
return TEMPERATURE_FORMAT_C;
|
|
|
|
}
|
2015-02-20 08:59:09 +01:00
|
|
|
}
|
2015-02-21 00:09:02 +01:00
|
|
|
#endif
|