2014-03-29 03:52:16 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010-2013 cocos2d-x.org
|
|
|
|
Copyright (c) Microsoft Open Technologies, Inc.
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
2014-09-10 09:15:16 +08:00
|
|
|
#include "platform/CCPlatformConfig.h"
|
2014-03-29 03:52:16 +08:00
|
|
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_WINRT
|
2014-10-15 05:16:24 +08:00
|
|
|
#include "platform/winrt/CCGLViewImpl-winrt.h"
|
2014-11-26 02:05:02 +08:00
|
|
|
using namespace Windows::UI::Core;
|
|
|
|
using namespace Windows::Foundation;
|
|
|
|
|
2014-03-29 03:52:16 +08:00
|
|
|
#else
|
2014-09-10 09:22:11 +08:00
|
|
|
#include "platform/wp8/CCGLViewImpl-wp8.h"
|
2014-03-29 03:52:16 +08:00
|
|
|
#endif
|
2014-05-17 05:36:00 +08:00
|
|
|
#include "base/CCDirector.h"
|
2014-03-29 03:52:16 +08:00
|
|
|
#include <algorithm>
|
|
|
|
#include "platform/CCFileUtils.h"
|
2016-03-20 21:53:44 +08:00
|
|
|
#include "platform/winrt/CCWinRTUtils.h"
|
2015-10-03 09:49:41 +08:00
|
|
|
#include "platform/CCApplication.h"
|
2015-10-29 01:57:57 +08:00
|
|
|
#include "tinyxml2/tinyxml2.h"
|
2014-03-29 03:52:16 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief This function change the PVRFrame show/hide setting in register.
|
|
|
|
@param bEnable If true show the PVRFrame window, otherwise hide.
|
|
|
|
*/
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
// sharedApplication pointer
|
|
|
|
Application * Application::sm_pSharedApplication = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// implement Application
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// sharedApplication pointer
|
|
|
|
Application * s_pSharedApplication = 0;
|
|
|
|
|
2014-09-22 20:47:58 +08:00
|
|
|
Application::Application() :
|
|
|
|
m_openURLDelegate(nullptr)
|
2014-03-29 03:52:16 +08:00
|
|
|
{
|
|
|
|
m_nAnimationInterval.QuadPart = 0;
|
|
|
|
CC_ASSERT(! sm_pSharedApplication);
|
|
|
|
sm_pSharedApplication = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Application::~Application()
|
|
|
|
{
|
|
|
|
CC_ASSERT(this == sm_pSharedApplication);
|
|
|
|
sm_pSharedApplication = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Application::run()
|
|
|
|
{
|
|
|
|
// Initialize instance and cocos2d.
|
|
|
|
if (!applicationDidFinishLaunching())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-04 14:17:14 +08:00
|
|
|
GLViewImpl::sharedOpenGLView()->Run();
|
2014-03-29 03:52:16 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-06 14:57:42 +08:00
|
|
|
void Application::setAnimationInterval(float interval)
|
2014-03-29 03:52:16 +08:00
|
|
|
{
|
|
|
|
LARGE_INTEGER nFreq;
|
|
|
|
QueryPerformanceFrequency(&nFreq);
|
|
|
|
m_nAnimationInterval.QuadPart = (LONGLONG)(interval * nFreq.QuadPart);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// static member function
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
Application* Application::getInstance()
|
|
|
|
{
|
|
|
|
CC_ASSERT(sm_pSharedApplication);
|
|
|
|
return sm_pSharedApplication;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char * Application::getCurrentLanguageCode()
|
|
|
|
{
|
2014-11-26 03:21:56 +08:00
|
|
|
static std::string code = "en";
|
2014-03-29 03:52:16 +08:00
|
|
|
|
2014-11-26 03:21:56 +08:00
|
|
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_WINRT
|
|
|
|
auto languages = Windows::System::UserProfile::GlobalizationPreferences::Languages;
|
|
|
|
code = PlatformStringToString(languages->GetAt(0));
|
|
|
|
#else
|
|
|
|
ULONG numLanguages = 0;
|
|
|
|
DWORD cchLanguagesBuffer = 0;
|
|
|
|
BOOL result = GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &numLanguages, NULL, &cchLanguagesBuffer);
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
WCHAR* pwszLanguagesBuffer = new WCHAR[cchLanguagesBuffer];
|
|
|
|
result = GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &numLanguages, pwszLanguagesBuffer, &cchLanguagesBuffer);
|
|
|
|
if (result) {
|
|
|
|
|
2015-08-16 17:51:41 +08:00
|
|
|
code = StringWideCharToUtf8(pwszLanguagesBuffer);
|
2014-11-26 03:21:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pwszLanguagesBuffer)
|
|
|
|
{
|
2015-10-17 03:43:09 +08:00
|
|
|
delete [] pwszLanguagesBuffer;
|
2014-11-26 03:21:56 +08:00
|
|
|
}
|
2014-03-29 03:52:16 +08:00
|
|
|
}
|
|
|
|
|
2014-11-26 03:21:56 +08:00
|
|
|
|
|
|
|
#endif
|
2014-03-29 03:52:16 +08:00
|
|
|
return code.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LanguageType Application::getCurrentLanguage()
|
|
|
|
{
|
|
|
|
LanguageType ret = LanguageType::ENGLISH;
|
2014-12-25 18:02:03 +08:00
|
|
|
|
2014-03-29 03:52:16 +08:00
|
|
|
const char* code = getCurrentLanguageCode();
|
2014-12-25 18:02:03 +08:00
|
|
|
|
2014-11-26 03:21:56 +08:00
|
|
|
if (strncmp(code, "zh", 2) == 0)
|
2014-03-29 03:52:16 +08:00
|
|
|
{
|
|
|
|
ret = LanguageType::CHINESE;
|
|
|
|
}
|
2014-11-26 03:21:56 +08:00
|
|
|
else if (strncmp(code, "ja", 2) == 0)
|
2014-03-29 03:52:16 +08:00
|
|
|
{
|
|
|
|
ret = LanguageType::JAPANESE;
|
|
|
|
}
|
2014-11-26 03:21:56 +08:00
|
|
|
else if (strncmp(code, "fr", 2) == 0)
|
2014-03-29 03:52:16 +08:00
|
|
|
{
|
|
|
|
ret = LanguageType::FRENCH;
|
|
|
|
}
|
2014-11-26 03:21:56 +08:00
|
|
|
else if (strncmp(code, "it", 2) == 0)
|
2014-03-29 03:52:16 +08:00
|
|
|
{
|
|
|
|
ret = LanguageType::ITALIAN;
|
|
|
|
}
|
2014-11-26 03:21:56 +08:00
|
|
|
else if (strncmp(code, "de", 2) == 0)
|
2014-03-29 03:52:16 +08:00
|
|
|
{
|
|
|
|
ret = LanguageType::GERMAN;
|
|
|
|
}
|
2014-11-26 03:21:56 +08:00
|
|
|
else if (strncmp(code, "es", 2) == 0)
|
2014-03-29 03:52:16 +08:00
|
|
|
{
|
|
|
|
ret = LanguageType::SPANISH;
|
|
|
|
}
|
2014-11-26 03:21:56 +08:00
|
|
|
else if (strncmp(code, "nl", 2) == 0)
|
2014-03-29 03:52:16 +08:00
|
|
|
{
|
|
|
|
ret = LanguageType::DUTCH;
|
|
|
|
}
|
2014-11-26 03:21:56 +08:00
|
|
|
else if (strncmp(code, "ru", 2) == 0)
|
2014-03-29 03:52:16 +08:00
|
|
|
{
|
|
|
|
ret = LanguageType::RUSSIAN;
|
|
|
|
}
|
2014-11-26 03:21:56 +08:00
|
|
|
else if (strncmp(code, "hu", 2) == 0)
|
2014-03-29 03:52:16 +08:00
|
|
|
{
|
|
|
|
ret = LanguageType::HUNGARIAN;
|
|
|
|
}
|
2014-11-26 03:21:56 +08:00
|
|
|
else if (strncmp(code, "pt", 2) == 0)
|
2014-03-29 03:52:16 +08:00
|
|
|
{
|
|
|
|
ret = LanguageType::PORTUGUESE;
|
|
|
|
}
|
2014-11-26 03:21:56 +08:00
|
|
|
else if (strncmp(code, "ko", 2) == 0)
|
2014-03-29 03:52:16 +08:00
|
|
|
{
|
|
|
|
ret = LanguageType::KOREAN;
|
|
|
|
}
|
2014-11-26 03:21:56 +08:00
|
|
|
else if (strncmp(code, "ar", 2) == 0)
|
2014-03-29 03:52:16 +08:00
|
|
|
{
|
|
|
|
ret = LanguageType::ARABIC;
|
2014-12-25 18:02:03 +08:00
|
|
|
}
|
|
|
|
else if (strncmp(code, "nb", 2) == 0)
|
|
|
|
{
|
|
|
|
ret = LanguageType::NORWEGIAN;
|
|
|
|
}
|
|
|
|
else if (strncmp(code, "pl", 2) == 0)
|
|
|
|
{
|
|
|
|
ret = LanguageType::POLISH;
|
|
|
|
}
|
|
|
|
else if (strncmp(code, "tr", 2) == 0)
|
|
|
|
{
|
|
|
|
ret = LanguageType::TURKISH;
|
|
|
|
}
|
|
|
|
else if (strncmp(code, "uk", 2) == 0)
|
|
|
|
{
|
|
|
|
ret = LanguageType::UKRAINIAN;
|
|
|
|
}
|
2015-02-25 23:20:48 +08:00
|
|
|
else if (strncmp(code, "ro", 2) == 0)
|
|
|
|
{
|
|
|
|
ret = LanguageType::ROMANIAN;
|
|
|
|
}
|
2015-03-17 21:14:02 +08:00
|
|
|
else if (strncmp(code, "bg", 2) == 0)
|
|
|
|
{
|
|
|
|
ret = LanguageType::BULGARIAN;
|
|
|
|
}
|
2014-03-29 03:52:16 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
Application::Platform Application::getTargetPlatform()
|
|
|
|
{
|
2015-08-27 00:47:59 +08:00
|
|
|
if (isWindowsPhone())
|
|
|
|
{
|
|
|
|
return Platform::OS_WP8;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return Platform::OS_WINRT;
|
|
|
|
}
|
2014-03-29 03:52:16 +08:00
|
|
|
}
|
|
|
|
|
2015-10-29 01:57:57 +08:00
|
|
|
std::string Application::getVersion()
|
|
|
|
{
|
|
|
|
std::string r("");
|
|
|
|
std::string s = FileUtils::getInstance()->getStringFromFile("WMAppManifest.xml");
|
|
|
|
if (!s.empty()) {
|
|
|
|
tinyxml2::XMLDocument doc;
|
|
|
|
if (!doc.Parse(s.c_str())) {
|
|
|
|
tinyxml2::XMLElement *app = doc.RootElement()->FirstChildElement("App");
|
|
|
|
if (app) {
|
|
|
|
const char* version = app->Attribute("Version");
|
|
|
|
if (version) {
|
|
|
|
r = version;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2014-09-09 16:07:33 +08:00
|
|
|
bool Application::openURL(const std::string &url)
|
|
|
|
{
|
2014-11-26 02:05:02 +08:00
|
|
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_WINRT
|
|
|
|
auto dispatcher = cocos2d::GLViewImpl::sharedOpenGLView()->getDispatcher();
|
|
|
|
dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new DispatchedHandler([url]() {
|
|
|
|
auto uri = ref new Windows::Foundation::Uri(PlatformStringFromString(url));
|
|
|
|
concurrency::task<bool> launchUriOperation(Windows::System::Launcher::LaunchUriAsync(uri));
|
|
|
|
}));
|
|
|
|
return true;
|
|
|
|
#else
|
2014-09-22 20:47:58 +08:00
|
|
|
if (m_openURLDelegate)
|
|
|
|
{
|
|
|
|
m_openURLDelegate(PlatformStringFromString(url));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-11-26 02:05:02 +08:00
|
|
|
#endif
|
2014-09-09 16:07:33 +08:00
|
|
|
}
|
|
|
|
|
2014-03-29 03:52:16 +08:00
|
|
|
void Application::setResourceRootPath(const std::string& rootResDir)
|
|
|
|
{
|
|
|
|
m_resourceRootPath = rootResDir;
|
|
|
|
std::replace(m_resourceRootPath.begin(), m_resourceRootPath.end(), '\\', '/');
|
|
|
|
if (m_resourceRootPath[m_resourceRootPath.length() - 1] != '/')
|
|
|
|
{
|
|
|
|
m_resourceRootPath += '/';
|
|
|
|
}
|
|
|
|
FileUtils* pFileUtils = FileUtils::getInstance();
|
|
|
|
std::vector<std::string> searchPaths = pFileUtils->getSearchPaths();
|
|
|
|
searchPaths.insert(searchPaths.begin(), m_resourceRootPath);
|
|
|
|
pFileUtils->setSearchPaths(searchPaths);
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& Application::getResourceRootPath(void)
|
|
|
|
{
|
|
|
|
return m_resourceRootPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::setStartupScriptFilename(const std::string& startupScriptFile)
|
|
|
|
{
|
|
|
|
m_startupScriptFilename = startupScriptFile;
|
|
|
|
std::replace(m_startupScriptFilename.begin(), m_startupScriptFilename.end(), '\\', '/');
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
|