From b895bbad31ee86aa654cd870a3dc59c1031f3ede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Brammer?= Date: Mon, 12 Mar 2012 20:43:27 +0100 Subject: [PATCH] Consolidate some random platform abstraction functions into a single file That way, the windows variants can be used without requiring the Win32 C4Window implementation. --- CMakeLists.txt | 1 + Makefile.am | 1 + src/editor/C4Console.cpp | 1 - src/platform/C4App.cpp | 18 +------ src/platform/C4WindowWin32.cpp | 28 +---------- src/platform/PlatformAbstraction.cpp | 71 ++++++++++++++++++++++++++++ 6 files changed, 75 insertions(+), 45 deletions(-) create mode 100644 src/platform/PlatformAbstraction.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 5591d0454..49a18a6a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -500,6 +500,7 @@ set(OC_CLONK_SOURCES src/platform/C4Window.h src/platform/C4windowswrapper.h src/platform/GetTime.cpp + src/platform/PlatformAbstraction.cpp src/platform/PlatformAbstraction.h src/platform/StdD3D.cpp src/platform/StdD3D.h diff --git a/Makefile.am b/Makefile.am index 23420bdf5..c726c37b2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -474,6 +474,7 @@ src/platform/C4VideoPlayback.h \ src/platform/C4ViewportWindow.cpp \ src/platform/C4ViewportWindow.h \ src/platform/C4windowswrapper.h \ +src/platform/PlatformAbstraction.cpp \ src/platform/PlatformAbstraction.h \ src/platform/C4App.h \ src/platform/C4App.cpp \ diff --git a/src/editor/C4Console.cpp b/src/editor/C4Console.cpp index 713513871..9e20e1d30 100644 --- a/src/editor/C4Console.cpp +++ b/src/editor/C4Console.cpp @@ -609,6 +609,5 @@ void C4ToolsDlg::UpdateToolCtrls() {} bool C4Viewport::ScrollBarsByViewPosition() {return 0;} bool C4Viewport::TogglePlayerLock() {return 0;} void C4Window::RequestUpdate() {} -bool OpenURL(char const*) {return 0;} #include "C4ConsoleGUICommon.h" #endif diff --git a/src/platform/C4App.cpp b/src/platform/C4App.cpp index 4aa19ff8e..d00066292 100644 --- a/src/platform/C4App.cpp +++ b/src/platform/C4App.cpp @@ -3,6 +3,7 @@ * * Copyright (c) 2007 Alexander Post * Copyright (c) 2010 Martin Plicht + * * Portions might be copyrighted by other authors who have contributed * to OpenClonk. * @@ -38,23 +39,6 @@ bool C4AbstractApp::ScheduleProcs(int iTimeout) return StdScheduler::ScheduleProcs(iTimeout); } -#if !defined(__APPLE__) && !defined(_WIN32) - -bool IsGermanSystem() -{ - if (strstr(setlocale(LC_MESSAGES, 0), "de")) - return true; - else - return false; -} - -bool EraseItemSafe(const char *szFilename) -{ - return false; -} - -#endif - void C4Window::PerformUpdate() { } diff --git a/src/platform/C4WindowWin32.cpp b/src/platform/C4WindowWin32.cpp index 8be33a3eb..ddb8b0b22 100644 --- a/src/platform/C4WindowWin32.cpp +++ b/src/platform/C4WindowWin32.cpp @@ -1,9 +1,9 @@ /* * OpenClonk, http://www.openclonk.org * - * Copyright (c) 2001-2002, 2005-2007 Sven Eberhardt * Copyright (c) 2005-2006, 2008-2011 Günther Brammer * Copyright (c) 2005, 2007, 2009 Peter Wortmann + * Copyright (c) 2002, 2005-2007 Sven Eberhardt * Copyright (c) 2006, 2010 Armin Burgmeier * Copyright (c) 2009-2011 Nicolas Hake * Copyright (c) 2010 Benjamin Herr @@ -830,29 +830,3 @@ void C4Window::RequestUpdate() PerformUpdate(); } -bool OpenURL(const char *szURL) -{ - return (intptr_t)ShellExecuteW(NULL, L"open", GetWideChar(szURL), NULL, NULL, SW_SHOW) > 32; -} - -bool EraseItemSafe(const char *szFilename) -{ - char Filename[_MAX_PATH+1]; - SCopy(szFilename, Filename, _MAX_PATH); - Filename[SLen(Filename)+1]=0; - SHFILEOPSTRUCTW shs; - shs.hwnd=0; - shs.wFunc=FO_DELETE; - shs.pFrom=GetWideChar(Filename); - shs.pTo=NULL; - shs.fFlags=FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_SILENT; - shs.fAnyOperationsAborted=false; - shs.hNameMappings=0; - shs.lpszProgressTitle=NULL; - return !SHFileOperationW(&shs); -} - -bool IsGermanSystem() -{ - return PRIMARYLANGID(GetUserDefaultLangID()) == LANG_GERMAN; -} diff --git a/src/platform/PlatformAbstraction.cpp b/src/platform/PlatformAbstraction.cpp new file mode 100644 index 000000000..df719d24c --- /dev/null +++ b/src/platform/PlatformAbstraction.cpp @@ -0,0 +1,71 @@ +/* + * OpenClonk, http://www.openclonk.org + * + * Copyright (c) 2001 Sven Eberhardt + * Copyright (c) 2010 Martin Plicht + * Copyright (c) 2012 Günther Brammer + * + * Portions might be copyrighted by other authors who have contributed + * to OpenClonk. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * See isc_license.txt for full license and disclaimer. + * + * "Clonk" is a registered trademark of Matthes Bender. + * See clonk_trademark_license.txt for full license. + */ + +#include + +#ifdef _WIN32 +#include +#include +bool OpenURL(const char *szURL) +{ + return (intptr_t)ShellExecuteW(NULL, L"open", GetWideChar(szURL), NULL, NULL, SW_SHOW) > 32; +} + +bool EraseItemSafe(const char *szFilename) +{ + char Filename[_MAX_PATH+1]; + SCopy(szFilename, Filename, _MAX_PATH); + Filename[SLen(Filename)+1]=0; + SHFILEOPSTRUCTW shs; + shs.hwnd=0; + shs.wFunc=FO_DELETE; + shs.pFrom=GetWideChar(Filename); + shs.pTo=NULL; + shs.fFlags=FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_SILENT; + shs.fAnyOperationsAborted=false; + shs.hNameMappings=0; + shs.lpszProgressTitle=NULL; + return !SHFileOperationW(&shs); +} + +bool IsGermanSystem() +{ + return PRIMARYLANGID(GetUserDefaultLangID()) == LANG_GERMAN; +} +#elif !defined(__APPLE__) + +bool IsGermanSystem() +{ + if (strstr(setlocale(LC_MESSAGES, 0), "de")) + return true; + else + return false; +} + +bool EraseItemSafe(const char *szFilename) +{ + return false; +} + +#if !defined(USE_X11) +bool OpenURL(char const*) {return 0;} +#endif + +#endif +