diff options
author | Piotr Dziwiński <piotrdz@gmail.com> | 2013-11-22 15:16:12 -0800 |
---|---|---|
committer | Piotr Dziwiński <piotrdz@gmail.com> | 2013-11-22 15:16:12 -0800 |
commit | 8ed542a8813b0275654ed6c8efa64a0149bb9d6f (patch) | |
tree | a2cd4b05865be1121dbfe0061d5d103fbcdd32da /src | |
parent | b3b80b5fbb0f0b4e1633c1a1ca1d2804b7a0ec59 (diff) | |
parent | 89e2855f9577a629d1ca67e87de588815829864e (diff) | |
download | colobot-8ed542a8813b0275654ed6c8efa64a0149bb9d6f.tar.gz colobot-8ed542a8813b0275654ed6c8efa64a0149bb9d6f.tar.bz2 colobot-8ed542a8813b0275654ed6c8efa64a0149bb9d6f.zip |
Merge pull request #250 from OdyX/dev-platform-enhancements-and-installers
MacOSX and Windows platform enhancements and installers
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 15 | ||||
-rw-r--r-- | src/app/app.cpp | 11 | ||||
-rw-r--r-- | src/app/system.cpp | 14 | ||||
-rw-r--r-- | src/app/system.h | 6 | ||||
-rw-r--r-- | src/app/system_macosx.cpp | 116 | ||||
-rw-r--r-- | src/app/system_macosx.h | 39 | ||||
-rw-r--r-- | src/common/config.h.cmake | 5 |
7 files changed, 193 insertions, 13 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2fab853..ef59973 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -56,21 +56,13 @@ if(PLATFORM_WINDOWS) set(RES_FILES "../desktop/colobot.rc") endif() -# Platform-dependent implementation of system.h -if(PLATFORM_WINDOWS) - set(SYSTEM_CPP_MODULE "system_windows.cpp") -elseif(PLATFORM_LINUX) - set(SYSTEM_CPP_MODULE "system_linux.cpp") -else() - set(SYSTEM_CPP_MODULE "system_other.cpp") -endif() - # Source files set(SOURCES app/app.cpp app/main.cpp app/system.cpp app/${SYSTEM_CPP_MODULE} +app/system_other.cpp common/event.cpp common/image.cpp common/iman.cpp @@ -237,5 +229,6 @@ add_executable(colobot ${SOURCES}) target_link_libraries(colobot ${LIBS}) install(TARGETS colobot RUNTIME DESTINATION ${COLOBOT_INSTALL_BIN_DIR}) -set_target_properties(colobot PROPERTIES INSTALL_RPATH ${COLOBOT_INSTALL_LIB_DIR}) - +if(NOT CBOT_STATIC) + set_target_properties(colobot PROPERTIES INSTALL_RPATH ${COLOBOT_INSTALL_LIB_DIR}) +endif() diff --git a/src/app/app.cpp b/src/app/app.cpp index e2405b8..ce97335 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -147,8 +147,8 @@ CApplication::CApplication() m_mouseButtonsState = 0; m_trackedKeys = 0; - m_dataPath = COLOBOT_DEFAULT_DATADIR; - m_langPath = COLOBOT_I18N_DIR; + m_dataPath = GetSystemUtils()->GetDataPath(); + m_langPath = GetSystemUtils()->GetLangPath(); m_texPackPath = ""; m_runSceneName = ""; @@ -423,7 +423,10 @@ bool CApplication::Create() return false; } +#if !defined(PLATFORM_MACOSX) + // On Mac OSX, the bundle can potentially change place, it doesn't make sense to cache it to the configuration file GetProfile().SetLocalProfileString("Resources", "Data", m_dataPath); +#endif SetLanguage(m_language); @@ -437,12 +440,16 @@ bool CApplication::Create() m_sound->Create(true); +#if !defined(PLATFORM_MACOSX) + // On Mac OSX, the bundle can potentially change place, it doesn't make sense to cache it to the configuration file + // Cache sound files if (defaultValues) { GetProfile().SetLocalProfileString("Resources", "Sound", GetDataSubdirPath(DIR_SOUND)); GetProfile().SetLocalProfileString("Resources", "Music", GetDataSubdirPath(DIR_MUSIC)); } +#endif if (!m_customDataPath && GetProfile().GetLocalProfileString("Resources", "Sound", path)) { diff --git a/src/app/system.cpp b/src/app/system.cpp index 2eb68ba..eaa9e4c 100644 --- a/src/app/system.cpp +++ b/src/app/system.cpp @@ -25,6 +25,8 @@ #include "app/system_windows.h" #elif defined(PLATFORM_LINUX) #include "app/system_linux.h" +#elif defined(PLATFORM_MACOSX) + #include "app/system_macosx.h" #else #include "app/system_other.h" #endif @@ -48,6 +50,8 @@ CSystemUtils* CSystemUtils::Create() m_instance = new CSystemUtilsWindows(); #elif defined(PLATFORM_LINUX) m_instance = new CSystemUtilsLinux(); +#elif defined(PLATFORM_MACOSX) + m_instance = new CSystemUtilsMacOSX(); #else m_instance = new CSystemUtilsOther(); #endif @@ -188,6 +192,16 @@ float CSystemUtils::TimeStampDiff(SystemTimeStamp *before, SystemTimeStamp *afte return result; } +std::string CSystemUtils::GetDataPath() +{ + return COLOBOT_DEFAULT_DATADIR; +} + +std::string CSystemUtils::GetLangPath() +{ + return COLOBOT_I18N_DIR; +} + std::string CSystemUtils::GetProfileFileLocation() { return std::string("colobot.ini"); diff --git a/src/app/system.h b/src/app/system.h index d22a519..c2125fe 100644 --- a/src/app/system.h +++ b/src/app/system.h @@ -130,6 +130,12 @@ public: /** The difference is \a after - \a before. */ virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) = 0; + //! Returns the data path (containing textures, levels, helpfiles, etc) + virtual std::string GetDataPath(); + + //! Returns the translations path + virtual std::string GetLangPath(); + //! Returns the profile (colobot.ini) file location virtual std::string GetProfileFileLocation(); diff --git a/src/app/system_macosx.cpp b/src/app/system_macosx.cpp new file mode 100644 index 0000000..68f5c79 --- /dev/null +++ b/src/app/system_macosx.cpp @@ -0,0 +1,116 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * Copyright (C) 2013, Polish Portal of Colobot (PPC) +// * +// * This program 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/. + +#include "app/system_macosx.h" + +#include "common/logger.h" + +#include <stdlib.h> + +// MacOS-specific headers +#include <CoreFoundation/CFBundle.h> +#include <CoreServices/CoreServices.h> + +#include <boost/filesystem.hpp> + +inline std::string CFStringRefToStdString(CFStringRef str) { + + std::string stdstr; + + char *fullPath; + CFStringEncoding encodingMethod = CFStringGetSystemEncoding(); + + // 1st try for English system + fullPath = const_cast<char*>(CFStringGetCStringPtr(str, encodingMethod)); + if( fullPath == NULL ) + { + // 2nd try for Japanese system + encodingMethod = kCFStringEncodingUTF8; + fullPath = const_cast<char*>(CFStringGetCStringPtr(str, encodingMethod)); + } + + // for safer operation. + if( fullPath == NULL ) + { + CFIndex length = CFStringGetLength(str); + fullPath = static_cast<char *>(malloc( length + 1 )); + + // TODO: Check boolean result of that conversion + CFStringGetCString(str, fullPath, length, kCFStringEncodingUTF8 ); + + stdstr = fullPath; + + free( fullPath ); + } + else + stdstr = fullPath; + + return stdstr; +} + +void CSystemUtilsMacOSX::Init() +{ + // These functions are a deprecated way to get the 'Application Support' folder, but they do work, in plain C++ + FSRef ref; + OSType folderType = kApplicationSupportFolderType; + char path[PATH_MAX]; + FSFindFolder( kUserDomain, folderType, kCreateFolder, &ref ); + FSRefMakePath( &ref, reinterpret_cast<UInt8*>(&path), PATH_MAX ); + + m_ASPath = path; + m_ASPath.append("/colobot/"); + + // Make sure the directory exists + boost::filesystem::create_directories(m_ASPath.c_str()); + + // Get the Resources bundle URL + CFBundleRef mainBundle = CFBundleGetMainBundle(); + CFURLRef resourcesURL = CFBundleCopyBundleURL(mainBundle); + CFStringRef str = CFURLCopyFileSystemPath( resourcesURL, kCFURLPOSIXPathStyle ); + CFRelease(resourcesURL); + + m_dataPath = CFStringRefToStdString(str); + m_dataPath += "/Contents/Resources"; +} + +std::string CSystemUtilsMacOSX::GetDataPath() +{ + return m_dataPath; +} + +std::string CSystemUtilsMacOSX::GetLangPath() +{ + return m_dataPath + "/i18n"; +} + +std::string CSystemUtilsMacOSX::GetProfileFileLocation() +{ + std::string profileFile = m_ASPath + "/colobot.ini"; + + GetLogger()->Trace("Profile file is %s\n", profileFile.c_str()); + return profileFile; +} + +std::string CSystemUtilsMacOSX::GetSavegameDirectoryLocation() +{ + std::string savegameDir = m_ASPath + "/savegame"; + boost::filesystem::create_directories(savegameDir.c_str()); + GetLogger()->Trace("Saved game files are going to %s\n", savegameDir.c_str()); + + return savegameDir; +} + diff --git a/src/app/system_macosx.h b/src/app/system_macosx.h new file mode 100644 index 0000000..b6a044b --- /dev/null +++ b/src/app/system_macosx.h @@ -0,0 +1,39 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * Copyright (C) 2012, Polish Portal of Colobot (PPC) +// * +// * This program 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/. + +/** + * \file app/system_macosx.h + * \brief MacOSX-specific implementation of system functions + */ + +#include "app/system.h" +#include "app/system_other.h" + +class CSystemUtilsMacOSX : public CSystemUtilsOther +{ +public: + virtual void Init() override; + + virtual std::string GetDataPath() override; + virtual std::string GetLangPath() override; + virtual std::string GetProfileFileLocation() override; + virtual std::string GetSavegameDirectoryLocation() override; +private: + std::string m_ASPath; + std::string m_dataPath; +}; + diff --git a/src/common/config.h.cmake b/src/common/config.h.cmake index 2f403fa..63cd93b 100644 --- a/src/common/config.h.cmake +++ b/src/common/config.h.cmake @@ -6,6 +6,11 @@ #cmakedefine PLATFORM_MACOSX @PLATFORM_MACOSX@ #cmakedefine PLATFORM_OTHER @PLATFORM_OTHER@ +#ifdef PLATFORM_MACOSX +// Assume we have the Mac OS X function CFLocaleCopyCurrent in the CoreFoundation framework +#define HAVE_CFLOCALECOPYCURRENT 1 +#endif + #cmakedefine GLEW_STATIC #cmakedefine OPENAL_SOUND |