mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-22 17:12:25 -05:00
Fix freezing on windows 98
This commit is contained in:
parent
5c6051c317
commit
db564a72f9
4 changed files with 42 additions and 28 deletions
|
@ -338,11 +338,14 @@ cc_uint64 Stopwatch_Measure(void) {
|
|||
#if defined CC_BUILD_WIN
|
||||
cc_result Directory_Create(const cc_string* path) {
|
||||
WCHAR str[NATIVE_STR_LEN];
|
||||
BOOL success;
|
||||
cc_result res;
|
||||
|
||||
Platform_EncodeUtf16(str, path);
|
||||
success = CreateDirectoryW(str, NULL);
|
||||
return success ? 0 : GetLastError();
|
||||
if (CreateDirectoryW(str, NULL)) return 0;
|
||||
if ((res = GetLastError()) != ERROR_CALL_NOT_IMPLEMENTED) return res;
|
||||
|
||||
Platform_Utf16ToAnsi(str);
|
||||
return CreateDirectoryA((LPCSTR)str, NULL) ? 0 : GetLastError();
|
||||
}
|
||||
|
||||
int File_Exists(const cc_string* path) {
|
||||
|
@ -408,7 +411,7 @@ static cc_result DoFile(cc_file* file, const cc_string* path, DWORD access, DWOR
|
|||
if ((res = GetLastError()) != ERROR_CALL_NOT_IMPLEMENTED) return res;
|
||||
|
||||
/* Windows 9x does not support W API functions */
|
||||
Platform_EncodeAnsi(str, path);
|
||||
Platform_Utf16ToAnsi(str);
|
||||
*file = CreateFileA((LPCSTR)str, access, FILE_SHARE_READ, NULL, createMode, 0, NULL);
|
||||
return *file != INVALID_HANDLE_VALUE ? 0 : GetLastError();
|
||||
}
|
||||
|
@ -1018,16 +1021,23 @@ cc_result Socket_Poll(cc_socket s, int mode, cc_bool* success) {
|
|||
*-----------------------------------------------------Process/Module------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
#if defined CC_BUILD_WIN
|
||||
static cc_result Process_RawStart(const WCHAR* path, WCHAR* args) {
|
||||
static cc_result Process_RawStart(WCHAR* path, WCHAR* args) {
|
||||
STARTUPINFOW si = { 0 };
|
||||
PROCESS_INFORMATION pi = { 0 };
|
||||
BOOL ok;
|
||||
|
||||
cc_result res;
|
||||
si.cb = sizeof(STARTUPINFOW);
|
||||
ok = CreateProcessW(path, args, NULL, NULL, false, 0, NULL, NULL, &si, &pi);
|
||||
if (!ok) return GetLastError();
|
||||
|
||||
/* Don't leak memory for proess return code */
|
||||
if (CreateProcessW(path, args, NULL, NULL,
|
||||
false, 0, NULL, NULL, &si, &pi)) goto success;
|
||||
//if ((res = GetLastError()) != ERROR_CALL_NOT_IMPLEMENTED) return res;
|
||||
|
||||
//Platform_Utf16ToAnsi(path);
|
||||
//if (CreateProcessA((LPCSTR)path, args, NULL, NULL,
|
||||
// false, 0, NULL, NULL, &si, &pi)) goto success;
|
||||
return GetLastError();
|
||||
|
||||
success:
|
||||
/* Don't leak memory for process return code */
|
||||
CloseHandle(pi.hProcess);
|
||||
CloseHandle(pi.hThread);
|
||||
return 0;
|
||||
|
@ -1551,13 +1561,12 @@ int Platform_EncodeUtf16(void* data, const cc_string* src) {
|
|||
return src->length * 2;
|
||||
}
|
||||
|
||||
int Platform_EncodeAnsi(void* data, const cc_string* src) {
|
||||
char* dst = (char*)data;
|
||||
if (src->length > FILENAME_SIZE) Logger_Abort("String too long to expand");
|
||||
void Platform_Utf16ToAnsi(void* data) {
|
||||
WCHAR* src = (WCHAR*)data;
|
||||
char* dst = (char*)data;
|
||||
|
||||
Mem_Copy(dst, src->buffer, src->length);
|
||||
dst[src->length] = '\0';
|
||||
return src->length;
|
||||
while (*src) { *dst++ = *src++; }
|
||||
*dst = '\0';
|
||||
}
|
||||
|
||||
static void Platform_InitStopwatch(void) {
|
||||
|
|
|
@ -35,9 +35,8 @@ extern const cc_result ReturnCode_DirectoryExists;
|
|||
/* Encodes a string in UTF16 format, also null terminating the string. */
|
||||
/* Returns the number of bytes written, excluding trailing NULL terminator. */
|
||||
int Platform_EncodeUtf16(void* data, const cc_string* src);
|
||||
/* Encodes a string in ansi format, also null terminating the string. */
|
||||
/* Returns the number of bytes written, excluding trailing NULL terminator. */
|
||||
int Platform_EncodeAnsi(void* data, const cc_string* src);
|
||||
/* Converts a null terminated WCHAR* to char* in-place */
|
||||
void Platform_Utf16ToAnsi(void* data);
|
||||
#else
|
||||
/* Encodes a string in UTF8 format, also null terminating the string. */
|
||||
/* Returns the number of bytes written, excluding trailing NULL terminator. */
|
||||
|
|
|
@ -344,7 +344,7 @@ static void ExtractFromFile(const cc_string* filename) {
|
|||
if (res) {
|
||||
/* Game shows a dialog if default.zip is missing */
|
||||
Game_DefaultZipMissing |= res == ReturnCode_FileNotFound
|
||||
&& String_CaselessEquals(filename, &defaultZip);
|
||||
&& String_CaselessEquals(filename, &defaultZip);
|
||||
Logger_SysWarn2(res, "opening", &path); return;
|
||||
}
|
||||
|
||||
|
|
22
src/Window.c
22
src/Window.c
|
@ -674,7 +674,7 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara
|
|||
|
||||
case WM_DESTROY:
|
||||
WindowInfo.Exists = false;
|
||||
UnregisterClass(CC_WIN_CLASSNAME, win_instance);
|
||||
UnregisterClassW(CC_WIN_CLASSNAME, win_instance);
|
||||
|
||||
if (win_DC) ReleaseDC(win_handle, win_DC);
|
||||
break;
|
||||
|
@ -837,7 +837,7 @@ void Window_Show(void) {
|
|||
}
|
||||
|
||||
int Window_GetWindowState(void) {
|
||||
DWORD s = GetWindowLong(win_handle, GWL_STYLE);
|
||||
DWORD s = GetWindowLongW(win_handle, GWL_STYLE);
|
||||
|
||||
if ((s & WS_MINIMIZE)) return WINDOW_STATE_MINIMISED;
|
||||
if ((s & WS_MAXIMIZE) && (s & WS_POPUP)) return WINDOW_STATE_FULLSCREEN;
|
||||
|
@ -851,7 +851,7 @@ static void ToggleFullscreen(cc_bool fullscreen, UINT finalShow) {
|
|||
suppress_resize = true;
|
||||
{
|
||||
ShowWindow(win_handle, SW_RESTORE); /* reset maximised state */
|
||||
SetWindowLong(win_handle, GWL_STYLE, style);
|
||||
SetWindowLongW(win_handle, GWL_STYLE, style);
|
||||
SetWindowPos(win_handle, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
|
||||
ShowWindow(win_handle, finalShow);
|
||||
Window_ProcessEvents();
|
||||
|
@ -881,7 +881,7 @@ cc_result Window_ExitFullscreen(void) {
|
|||
|
||||
|
||||
void Window_SetSize(int width, int height) {
|
||||
DWORD style = GetWindowLong(win_handle, GWL_STYLE);
|
||||
DWORD style = GetWindowLongW(win_handle, GWL_STYLE);
|
||||
RECT rect = { 0, 0, width, height };
|
||||
AdjustWindowRect(&rect, style, false);
|
||||
|
||||
|
@ -890,15 +890,21 @@ void Window_SetSize(int width, int height) {
|
|||
}
|
||||
|
||||
void Window_Close(void) {
|
||||
PostMessage(win_handle, WM_CLOSE, 0, 0);
|
||||
PostMessageW(win_handle, WM_CLOSE, 0, 0);
|
||||
}
|
||||
|
||||
void Window_ProcessEvents(void) {
|
||||
HWND foreground;
|
||||
MSG msg;
|
||||
while (PeekMessage(&msg, NULL, 0, 0, 1)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
|
||||
if (is_ansiWindow) {
|
||||
while (PeekMessageA(&msg, NULL, 0, 0, 1)) {
|
||||
TranslateMessage(&msg); DispatchMessageA(&msg);
|
||||
}
|
||||
} else {
|
||||
while (PeekMessageW(&msg, NULL, 0, 0, 1)) {
|
||||
TranslateMessage(&msg); DispatchMessageW(&msg);
|
||||
}
|
||||
}
|
||||
|
||||
foreground = GetForegroundWindow();
|
||||
|
|
Loading…
Reference in a new issue