mirror of https://github.com/axmolengine/axmol.git
Merge pull request #14260 from pyrosphere/add-app-version
Added Application::getVersion() to get the app version.
This commit is contained in:
commit
ac06c9f8bb
|
@ -136,6 +136,13 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual Platform getTargetPlatform() = 0;
|
virtual Platform getTargetPlatform() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Get application version.
|
||||||
|
* @js NA
|
||||||
|
* @lua NA
|
||||||
|
*/
|
||||||
|
virtual std::string getVersion() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Open url in default browser.
|
@brief Open url in default browser.
|
||||||
@param String with url to open.
|
@param String with url to open.
|
||||||
|
|
|
@ -200,6 +200,11 @@ Application::Platform Application::getTargetPlatform()
|
||||||
return Platform::OS_ANDROID;
|
return Platform::OS_ANDROID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Application::getVersion()
|
||||||
|
{
|
||||||
|
return getVersionJNI();
|
||||||
|
}
|
||||||
|
|
||||||
bool Application::openURL(const std::string &url)
|
bool Application::openURL(const std::string &url)
|
||||||
{
|
{
|
||||||
return openURLJNI(url.c_str());
|
return openURLJNI(url.c_str());
|
||||||
|
|
|
@ -84,6 +84,11 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual Platform getTargetPlatform();
|
virtual Platform getTargetPlatform();
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Get application version.
|
||||||
|
*/
|
||||||
|
virtual std::string getVersion() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Open url in default browser
|
@brief Open url in default browser
|
||||||
@param String with url to open.
|
@param String with url to open.
|
||||||
|
|
|
@ -212,6 +212,15 @@ public class Cocos2dxHelper {
|
||||||
sVibrateService.vibrate((long)(duration * 1000));
|
sVibrateService.vibrate((long)(duration * 1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getVersion() {
|
||||||
|
try {
|
||||||
|
String version = Cocos2dxActivity.getContext().getPackageManager().getPackageInfo(Cocos2dxActivity.getContext().getPackageName(), 0).versionName;
|
||||||
|
return version;
|
||||||
|
} catch(Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean openURL(String url) {
|
public static boolean openURL(String url) {
|
||||||
boolean ret = false;
|
boolean ret = false;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -205,6 +205,19 @@ void vibrateJni(float duration) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string getVersionJNI() {
|
||||||
|
JniMethodInfo t;
|
||||||
|
std::string ret("");
|
||||||
|
|
||||||
|
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "getVersion", "()Ljava/lang/String;")) {
|
||||||
|
jstring str = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID);
|
||||||
|
t.env->DeleteLocalRef(t.classID);
|
||||||
|
ret = JniHelper::jstring2string(str);
|
||||||
|
t.env->DeleteLocalRef(str);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
extern bool openURLJNI(const char* url) {
|
extern bool openURLJNI(const char* url) {
|
||||||
JniMethodInfo t;
|
JniMethodInfo t;
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ extern void disableAccelerometerJni();
|
||||||
extern void setAccelerometerIntervalJni(float interval);
|
extern void setAccelerometerIntervalJni(float interval);
|
||||||
extern void setKeepScreenOnJni(bool value);
|
extern void setKeepScreenOnJni(bool value);
|
||||||
extern void vibrateJni(float duration);
|
extern void vibrateJni(float duration);
|
||||||
|
extern std::string getVersionJNI();
|
||||||
extern bool openURLJNI(const char* url);
|
extern bool openURLJNI(const char* url);
|
||||||
// functions for UserDefault
|
// functions for UserDefault
|
||||||
extern bool getBoolForKeyJNI(const char* key, bool defaultValue);
|
extern bool getBoolForKeyJNI(const char* key, bool defaultValue);
|
||||||
|
|
|
@ -67,31 +67,36 @@ public:
|
||||||
@brief Callback by Director for limit FPS.
|
@brief Callback by Director for limit FPS.
|
||||||
@param interval The time, expressed in seconds, between current frame and next.
|
@param interval The time, expressed in seconds, between current frame and next.
|
||||||
*/
|
*/
|
||||||
virtual void setAnimationInterval(float interval);
|
virtual void setAnimationInterval(float interval) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Get current language config
|
@brief Get current language config
|
||||||
@return Current language config
|
@return Current language config
|
||||||
*/
|
*/
|
||||||
virtual LanguageType getCurrentLanguage();
|
virtual LanguageType getCurrentLanguage() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Get current language iso 639-1 code
|
@brief Get current language iso 639-1 code
|
||||||
@return Current language iso 639-1 code
|
@return Current language iso 639-1 code
|
||||||
*/
|
*/
|
||||||
virtual const char * getCurrentLanguageCode();
|
virtual const char * getCurrentLanguageCode() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Get target platform
|
@brief Get target platform
|
||||||
*/
|
*/
|
||||||
virtual Platform getTargetPlatform();
|
virtual Platform getTargetPlatform() override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Get application version.
|
||||||
|
*/
|
||||||
|
virtual std::string getVersion() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Open url in default browser
|
@brief Open url in default browser
|
||||||
@param String with url to open.
|
@param String with url to open.
|
||||||
@return true if the resource located by the URL was successfully opened; otherwise false.
|
@return true if the resource located by the URL was successfully opened; otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool openURL(const std::string &url);
|
virtual bool openURL(const std::string &url) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief This function will be called when the application screen size is changed.
|
@brief This function will be called when the application screen size is changed.
|
||||||
|
|
|
@ -139,6 +139,14 @@ Application::Platform Application::getTargetPlatform()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Application::getVersion() {
|
||||||
|
NSString* version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
|
||||||
|
if (version) {
|
||||||
|
return [version UTF8String];
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
bool Application::openURL(const std::string &url)
|
bool Application::openURL(const std::string &url)
|
||||||
{
|
{
|
||||||
NSString* msg = [NSString stringWithCString:url.c_str() encoding:NSUTF8StringEncoding];
|
NSString* msg = [NSString stringWithCString:url.c_str() encoding:NSUTF8StringEncoding];
|
||||||
|
|
|
@ -136,6 +136,11 @@ Application::Platform Application::getTargetPlatform()
|
||||||
return Platform::OS_LINUX;
|
return Platform::OS_LINUX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Application::getVersion()
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
bool Application::openURL(const std::string &url)
|
bool Application::openURL(const std::string &url)
|
||||||
{
|
{
|
||||||
std::string op = std::string("open ").append(url);
|
std::string op = std::string("open ").append(url);
|
||||||
|
|
|
@ -78,6 +78,11 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual const char * getCurrentLanguageCode();
|
virtual const char * getCurrentLanguageCode();
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Get application version
|
||||||
|
*/
|
||||||
|
virtual std::string getVersion() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Open url in default browser
|
@brief Open url in default browser
|
||||||
@param String with url to open.
|
@param String with url to open.
|
||||||
|
|
|
@ -52,7 +52,7 @@ public:
|
||||||
@brief Callback by Director for limit FPS.
|
@brief Callback by Director for limit FPS.
|
||||||
@param interval The time, which expressed in second in second, between current frame and next.
|
@param interval The time, which expressed in second in second, between current frame and next.
|
||||||
*/
|
*/
|
||||||
virtual void setAnimationInterval(float interval);
|
virtual void setAnimationInterval(float interval) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Get status bar rectangle in GLView window.
|
@brief Get status bar rectangle in GLView window.
|
||||||
|
@ -78,25 +78,30 @@ public:
|
||||||
@brief Get current language config
|
@brief Get current language config
|
||||||
@return Current language config
|
@return Current language config
|
||||||
*/
|
*/
|
||||||
virtual LanguageType getCurrentLanguage();
|
virtual LanguageType getCurrentLanguage() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Get current language iso 639-1 code
|
@brief Get current language iso 639-1 code
|
||||||
@return Current language iso 639-1 code
|
@return Current language iso 639-1 code
|
||||||
*/
|
*/
|
||||||
virtual const char * getCurrentLanguageCode();
|
virtual const char * getCurrentLanguageCode() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Get target platform
|
@brief Get target platform
|
||||||
*/
|
*/
|
||||||
virtual Platform getTargetPlatform();
|
virtual Platform getTargetPlatform() override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Get application version.
|
||||||
|
*/
|
||||||
|
virtual std::string getVersion() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Open url in default browser
|
@brief Open url in default browser
|
||||||
@param String with url to open.
|
@param String with url to open.
|
||||||
@return true if the resource located by the URL was successfully opened; otherwise false.
|
@return true if the resource located by the URL was successfully opened; otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool openURL(const std::string &url);
|
virtual bool openURL(const std::string &url) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the Resource root path.
|
* Sets the Resource root path.
|
||||||
|
|
|
@ -118,6 +118,14 @@ Application::Platform Application::getTargetPlatform()
|
||||||
return Platform::OS_MAC;
|
return Platform::OS_MAC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Application::getVersion() {
|
||||||
|
NSString* version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
|
||||||
|
if (version) {
|
||||||
|
return [version UTF8String];
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// static member function
|
// static member function
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -217,6 +217,11 @@ Application::Platform Application::getTargetPlatform()
|
||||||
return Platform::OS_WINDOWS;
|
return Platform::OS_WINDOWS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Application::getVersion()
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
bool Application::openURL(const std::string &url)
|
bool Application::openURL(const std::string &url)
|
||||||
{
|
{
|
||||||
WCHAR *temp = new WCHAR[url.size() + 1];
|
WCHAR *temp = new WCHAR[url.size() + 1];
|
||||||
|
|
|
@ -75,6 +75,11 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual Platform getTargetPlatform();
|
virtual Platform getTargetPlatform();
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Get application version
|
||||||
|
*/
|
||||||
|
virtual std::string getVersion() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Open url in default browser
|
@brief Open url in default browser
|
||||||
@param String with url to open.
|
@param String with url to open.
|
||||||
|
|
|
@ -36,6 +36,7 @@ using namespace Windows::Foundation;
|
||||||
#include "platform/CCFileUtils.h"
|
#include "platform/CCFileUtils.h"
|
||||||
#include "CCWinRTUtils.h"
|
#include "CCWinRTUtils.h"
|
||||||
#include "platform/CCApplication.h"
|
#include "platform/CCApplication.h"
|
||||||
|
#include "tinyxml2/tinyxml2.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief This function change the PVRFrame show/hide setting in register.
|
@brief This function change the PVRFrame show/hide setting in register.
|
||||||
|
@ -225,6 +226,25 @@ Application::Platform Application::getTargetPlatform()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
bool Application::openURL(const std::string &url)
|
bool Application::openURL(const std::string &url)
|
||||||
{
|
{
|
||||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_WINRT
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_WINRT
|
||||||
|
|
|
@ -64,6 +64,11 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual Platform getTargetPlatform() override;
|
virtual Platform getTargetPlatform() override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Get application version
|
||||||
|
*/
|
||||||
|
virtual std::string getVersion() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Open url in default browser
|
@brief Open url in default browser
|
||||||
@param String with url to open.
|
@param String with url to open.
|
||||||
|
|
Loading…
Reference in New Issue