diff options
Diffstat (limited to 'backends/platform')
43 files changed, 579 insertions, 475 deletions
diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 798772cc24..4e4417400c 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -401,7 +401,8 @@ bool OSystem_Android::hasFeature(Feature f) { f == kFeatureAspectRatioCorrection || f == kFeatureCursorPalette || f == kFeatureVirtualKeyboard || - f == kFeatureOverlaySupportsAlpha); + f == kFeatureOverlaySupportsAlpha || + f == kFeatureOpenUrl); } void OSystem_Android::setFeatureState(Feature f, bool enable) { @@ -586,6 +587,10 @@ Common::String OSystem_Android::getSystemLanguage() const { getSystemProperty("persist.sys.country").c_str()); } +bool OSystem_Android::openUrl(const Common::String &url) { + return JNI::openUrl(url.c_str()); +} + Common::String OSystem_Android::getSystemProperty(const char *name) const { char value[PROP_VALUE_MAX]; diff --git a/backends/platform/android/android.h b/backends/platform/android/android.h index ade84dd42d..2935d96381 100644 --- a/backends/platform/android/android.h +++ b/backends/platform/android/android.h @@ -286,6 +286,7 @@ public: virtual void logMessage(LogMessageType::Type type, const char *message); virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0); + virtual bool openUrl(const Common::String &url); virtual Common::String getSystemLanguage() const; }; diff --git a/backends/platform/android/asset-archive.cpp b/backends/platform/android/asset-archive.cpp index 6680081c16..0ee6efc111 100644 --- a/backends/platform/android/asset-archive.cpp +++ b/backends/platform/android/asset-archive.cpp @@ -22,8 +22,6 @@ #if defined(__ANDROID__) -#include <jni.h> - #include <sys/types.h> #include <unistd.h> @@ -37,443 +35,112 @@ #include "backends/platform/android/jni.h" #include "backends/platform/android/asset-archive.h" -// Must match android.content.res.AssetManager.ACCESS_* -const jint ACCESS_UNKNOWN = 0; -const jint ACCESS_RANDOM = 1; +#include <android/asset_manager.h> +#include <android/asset_manager_jni.h> -// This might be useful to someone else. Assumes markSupported() == true. -class JavaInputStream : public Common::SeekableReadStream { +class AssetInputStream : public Common::SeekableReadStream { public: - JavaInputStream(JNIEnv *env, jobject is); - virtual ~JavaInputStream(); - - virtual bool eos() const { - return _eos; - } + AssetInputStream(AAssetManager *as, const Common::String &path); + virtual ~AssetInputStream(); - virtual bool err() const { - return _err; - } + virtual bool eos() const { return _eos; } - virtual void clearErr() { - _eos = _err = false; - } + virtual void clearErr() {_eos = false; } virtual uint32 read(void *dataPtr, uint32 dataSize); - virtual int32 pos() const { - return _pos; - } + virtual int32 pos() const { return _pos; } - virtual int32 size() const { - return _len; - } + virtual int32 size() const { return _len; } virtual bool seek(int32 offset, int whence = SEEK_SET); private: - void close(JNIEnv *env); - - jmethodID MID_mark; - jmethodID MID_available; - jmethodID MID_close; - jmethodID MID_read; - jmethodID MID_reset; - jmethodID MID_skip; + void close(); + AAsset *_asset; - jobject _input_stream; - jsize _buflen; - jbyteArray _buf; uint32 _pos; - jint _len; + uint32 _len; bool _eos; - bool _err; }; -JavaInputStream::JavaInputStream(JNIEnv *env, jobject is) : - _eos(false), - _err(false), - _pos(0) -{ - _input_stream = env->NewGlobalRef(is); - _buflen = 8192; - jobject buf = env->NewByteArray(_buflen); - _buf = (jbyteArray)env->NewGlobalRef(buf); - env->DeleteLocalRef(buf); - - jclass cls = env->GetObjectClass(_input_stream); - MID_mark = env->GetMethodID(cls, "mark", "(I)V"); - assert(MID_mark); - MID_available = env->GetMethodID(cls, "available", "()I"); - assert(MID_available); - MID_close = env->GetMethodID(cls, "close", "()V"); - assert(MID_close); - MID_read = env->GetMethodID(cls, "read", "([BII)I"); - assert(MID_read); - MID_reset = env->GetMethodID(cls, "reset", "()V"); - assert(MID_reset); - MID_skip = env->GetMethodID(cls, "skip", "(J)J"); - assert(MID_skip); - env->DeleteLocalRef(cls); - - // Mark start of stream, so we can reset back to it. - // readlimit is set to something bigger than anything we might - // want to seek within. - env->CallVoidMethod(_input_stream, MID_mark, 10 * 1024 * 1024); - _len = env->CallIntMethod(_input_stream, MID_available); +AssetInputStream::AssetInputStream(AAssetManager *as, const Common::String &path) : + _eos(false), _pos(0) { + _asset = AAssetManager_open(as, path.c_str(), AASSET_MODE_RANDOM); + _len = AAsset_getLength(_asset); } -JavaInputStream::~JavaInputStream() { - JNIEnv *env = JNI::getEnv(); - close(env); - - env->DeleteGlobalRef(_buf); - env->DeleteGlobalRef(_input_stream); +AssetInputStream::~AssetInputStream() { } -void JavaInputStream::close(JNIEnv *env) { - env->CallVoidMethod(_input_stream, MID_close); - - if (env->ExceptionCheck()) - env->ExceptionClear(); +void AssetInputStream::close() { + AAsset_close(_asset); } -uint32 JavaInputStream::read(void *dataPtr, uint32 dataSize) { - JNIEnv *env = JNI::getEnv(); - - if (_buflen < jint(dataSize)) { - _buflen = dataSize; - - env->DeleteGlobalRef(_buf); - jobject buf = env->NewByteArray(_buflen); - _buf = static_cast<jbyteArray>(env->NewGlobalRef(buf)); - env->DeleteLocalRef(buf); - } - - jint ret = env->CallIntMethod(_input_stream, MID_read, _buf, 0, dataSize); - - if (env->ExceptionCheck()) { - warning("Exception during JavaInputStream::read(%p, %d)", - dataPtr, dataSize); - - env->ExceptionDescribe(); - env->ExceptionClear(); - - _err = true; - ret = -1; - } else if (ret == -1) { +uint32 AssetInputStream::read(void *dataPtr, uint32 dataSize) { + uint32 readlen = AAsset_read(_asset, dataPtr, dataSize); + _pos += readlen; + if (readlen != dataSize) { _eos = true; - ret = 0; - } else { - env->GetByteArrayRegion(_buf, 0, ret, static_cast<jbyte *>(dataPtr)); - _pos += ret; } - - return ret; + return readlen; } -bool JavaInputStream::seek(int32 offset, int whence) { - JNIEnv *env = JNI::getEnv(); - uint32 newpos; - - switch (whence) { - case SEEK_SET: - newpos = offset; - break; - case SEEK_CUR: - newpos = _pos + offset; - break; - case SEEK_END: - newpos = _len + offset; - break; - default: - debug("Unknown 'whence' arg %d", whence); +bool AssetInputStream::seek(int32 offset, int whence) { + int res = AAsset_seek(_asset, offset, whence); + if (res == -1) { return false; } - - jlong skip_bytes; - if (newpos > _pos) { - skip_bytes = newpos - _pos; - } else { - // Can't skip backwards, so jump back to start and skip from there. - env->CallVoidMethod(_input_stream, MID_reset); - - if (env->ExceptionCheck()) { - warning("Failed to rewind to start of asset stream"); - - env->ExceptionDescribe(); - env->ExceptionClear(); - - return false; - } - - _pos = 0; - skip_bytes = newpos; - } - - while (skip_bytes > 0) { - jlong ret = env->CallLongMethod(_input_stream, MID_skip, skip_bytes); - - if (env->ExceptionCheck()) { - warning("Failed to skip %ld bytes into asset stream", - static_cast<long>(skip_bytes)); - - env->ExceptionDescribe(); - env->ExceptionClear(); - - return false; - } else if (ret == 0) { - warning("InputStream->skip(%ld) didn't skip any bytes. Aborting seek.", - static_cast<long>(skip_bytes)); - - // No point looping forever... - return false; - } - - _pos += ret; - skip_bytes -= ret; - } - - _eos = false; - return true; -} - -// Must match android.content.res.AssetFileDescriptor.UNKNOWN_LENGTH -const jlong UNKNOWN_LENGTH = -1; - -// Reading directly from a fd is so much more efficient, that it is -// worth optimising for. -class AssetFdReadStream : public Common::SeekableReadStream { -public: - AssetFdReadStream(JNIEnv *env, jobject assetfd); - virtual ~AssetFdReadStream(); - - virtual bool eos() const { - return _eos; - } - - virtual bool err() const { - return _err; - } - - virtual void clearErr() { - _eos = _err = false; - } - - virtual uint32 read(void *dataPtr, uint32 dataSize); - - virtual int32 pos() const { - return _pos; - } - - virtual int32 size() const { - return _declared_len; - } - - virtual bool seek(int32 offset, int whence = SEEK_SET); - -private: - void close(JNIEnv *env); - - int _fd; - jmethodID MID_close; - jobject _assetfd; - jlong _start_off; - jlong _declared_len; - uint32 _pos; - bool _eos; - bool _err; -}; - -AssetFdReadStream::AssetFdReadStream(JNIEnv *env, jobject assetfd) : - _eos(false), - _err(false), - _pos(0) -{ - _assetfd = env->NewGlobalRef(assetfd); - - jclass cls = env->GetObjectClass(_assetfd); - MID_close = env->GetMethodID(cls, "close", "()V"); - assert(MID_close); - - jmethodID MID_getStartOffset = - env->GetMethodID(cls, "getStartOffset", "()J"); - assert(MID_getStartOffset); - _start_off = env->CallLongMethod(_assetfd, MID_getStartOffset); - - jmethodID MID_getDeclaredLength = - env->GetMethodID(cls, "getDeclaredLength", "()J"); - assert(MID_getDeclaredLength); - _declared_len = env->CallLongMethod(_assetfd, MID_getDeclaredLength); - - jmethodID MID_getFileDescriptor = - env->GetMethodID(cls, "getFileDescriptor", - "()Ljava/io/FileDescriptor;"); - assert(MID_getFileDescriptor); - jobject javafd = env->CallObjectMethod(_assetfd, MID_getFileDescriptor); - assert(javafd); - - jclass fd_cls = env->GetObjectClass(javafd); - jfieldID FID_descriptor = env->GetFieldID(fd_cls, "descriptor", "I"); - assert(FID_descriptor); - env->DeleteLocalRef(fd_cls); - - _fd = env->GetIntField(javafd, FID_descriptor); - env->DeleteLocalRef(javafd); - - env->DeleteLocalRef(cls); -} - -AssetFdReadStream::~AssetFdReadStream() { - JNIEnv *env = JNI::getEnv(); - env->CallVoidMethod(_assetfd, MID_close); - - if (env->ExceptionCheck()) - env->ExceptionClear(); - - env->DeleteGlobalRef(_assetfd); -} - -uint32 AssetFdReadStream::read(void *dataPtr, uint32 dataSize) { - if (_declared_len != UNKNOWN_LENGTH) { - jlong cap = _declared_len - _pos; - if (dataSize > cap) - dataSize = cap; - } - - int ret = ::read(_fd, dataPtr, dataSize); - - if (ret == 0) - _eos = true; - else if (ret == -1) - _err = true; - else - _pos += ret; - - return ret; -} - -bool AssetFdReadStream::seek(int32 offset, int whence) { - if (whence == SEEK_SET) { - if (_declared_len != UNKNOWN_LENGTH && offset > _declared_len) - offset = _declared_len; - - offset += _start_off; - } else if (whence == SEEK_END && _declared_len != UNKNOWN_LENGTH) { - whence = SEEK_SET; - offset = _start_off + _declared_len + offset; + if (whence == SEEK_CUR) { + _pos += offset; + } else if (whence == SEEK_SET) { + _pos = offset; + } else if (whence == SEEK_END) { + _pos = _len + offset; } - - int ret = lseek(_fd, offset, whence); - - if (ret == -1) - return false; - - _pos = ret - _start_off; + assert(_pos <= _len); _eos = false; - return true; } -AndroidAssetArchive::AndroidAssetArchive(jobject am) { +AndroidAssetArchive::AndroidAssetArchive(jobject am) : _hasCached(false) { JNIEnv *env = JNI::getEnv(); - _am = env->NewGlobalRef(am); - jclass cls = env->GetObjectClass(_am); - MID_open = env->GetMethodID(cls, "open", - "(Ljava/lang/String;I)Ljava/io/InputStream;"); - assert(MID_open); - - MID_openFd = env->GetMethodID(cls, "openFd", "(Ljava/lang/String;)" - "Landroid/content/res/AssetFileDescriptor;"); - assert(MID_openFd); - - MID_list = env->GetMethodID(cls, "list", - "(Ljava/lang/String;)[Ljava/lang/String;"); - assert(MID_list); - env->DeleteLocalRef(cls); + _am = AAssetManager_fromJava(env, am); } AndroidAssetArchive::~AndroidAssetArchive() { - JNIEnv *env = JNI::getEnv(); - env->DeleteGlobalRef(_am); } bool AndroidAssetArchive::hasFile(const Common::String &name) const { - JNIEnv *env = JNI::getEnv(); - jstring path = env->NewStringUTF(name.c_str()); - jobject result = env->CallObjectMethod(_am, MID_open, path, ACCESS_UNKNOWN); - if (env->ExceptionCheck()) { - // Assume FileNotFoundException - //warning("Error while calling AssetManager->open(%s)", name.c_str()); - //env->ExceptionDescribe(); - env->ExceptionClear(); - env->DeleteLocalRef(path); - - return false; + AAsset *asset = AAssetManager_open(_am, name.c_str(), AASSET_MODE_RANDOM); + bool exists = false; + if (asset != NULL) { + exists = true; + AAsset_close(asset); } - - env->DeleteLocalRef(result); - env->DeleteLocalRef(path); - - return true; + return exists; } int AndroidAssetArchive::listMembers(Common::ArchiveMemberList &member_list) const { - JNIEnv *env = JNI::getEnv(); - Common::List<Common::String> dirlist; - dirlist.push_back(""); + if (_hasCached) { + member_list.insert(member_list.end(), _cachedMembers.begin(), _cachedMembers.end()); + return _cachedMembers.size(); + } int count = 0; - while (!dirlist.empty()) { - const Common::String dir = dirlist.back(); - dirlist.pop_back(); - - jstring jpath = env->NewStringUTF(dir.c_str()); - jobjectArray jpathlist = - (jobjectArray)env->CallObjectMethod(_am, MID_list, jpath); - - if (env->ExceptionCheck()) { - warning("Error while calling AssetManager->list(%s). Ignoring.", - dir.c_str()); - env->ExceptionDescribe(); - env->ExceptionClear(); - - // May as well keep going ... - continue; - } - - env->DeleteLocalRef(jpath); + AAssetDir *dir = AAssetManager_openDir(_am, ""); + const char *file = AAssetDir_getNextFileName(dir); - for (jsize i = 0; i < env->GetArrayLength(jpathlist); ++i) { - jstring elem = (jstring)env->GetObjectArrayElement(jpathlist, i); - const char *p = env->GetStringUTFChars(elem, 0); - - if (strlen(p)) { - Common::String thispath = dir; - - if (!thispath.empty()) - thispath += "/"; - - thispath += p; - - // Assume files have a . in them, and directories don't - if (strchr(p, '.')) { - member_list.push_back(getMember(thispath)); - ++count; - } else { - // AssetManager is ridiculously slow and we don't care - // about subdirectories at the moment, so ignore them. - // dirlist.push_back(thispath); - } - } - - env->ReleaseStringUTFChars(elem, p); - env->DeleteLocalRef(elem); - } - - env->DeleteLocalRef(jpathlist); + while (file) { + member_list.push_back(getMember(file)); + ++count; + file = AAssetDir_getNextFileName(dir); } + AAssetDir_close(dir); + + _cachedMembers = Common::ArchiveMemberList(member_list); + _hasCached = true; return count; } @@ -483,39 +150,10 @@ const Common::ArchiveMemberPtr AndroidAssetArchive::getMember(const Common::Stri } Common::SeekableReadStream *AndroidAssetArchive::createReadStreamForMember(const Common::String &path) const { - JNIEnv *env = JNI::getEnv(); - jstring jpath = env->NewStringUTF(path.c_str()); - - // Try openFd() first ... - jobject afd = env->CallObjectMethod(_am, MID_openFd, jpath); - - if (env->ExceptionCheck()) - env->ExceptionClear(); - else if (afd != 0) { - // success :) - Common::SeekableReadStream *stream = new AssetFdReadStream(env, afd); - env->DeleteLocalRef(jpath); - env->DeleteLocalRef(afd); - return stream; + if (!hasFile(path)) { + return nullptr; } - - // ... and fallback to normal open() if that doesn't work - jobject is = env->CallObjectMethod(_am, MID_open, jpath, ACCESS_RANDOM); - - if (env->ExceptionCheck()) { - // Assume FileNotFoundException - //warning("Error opening %s", path.c_str()); - //env->ExceptionDescribe(); - env->ExceptionClear(); - env->DeleteLocalRef(jpath); - - return 0; - } - - Common::SeekableReadStream *stream = new JavaInputStream(env, is); - env->DeleteLocalRef(jpath); - env->DeleteLocalRef(is); - return stream; + return new AssetInputStream(_am, path); } #endif diff --git a/backends/platform/android/asset-archive.h b/backends/platform/android/asset-archive.h index 6a0033d24e..8ae55b22c9 100644 --- a/backends/platform/android/asset-archive.h +++ b/backends/platform/android/asset-archive.h @@ -32,6 +32,8 @@ #include "common/util.h" #include "common/archive.h" +#include <android/asset_manager.h> + class AndroidAssetArchive : public Common::Archive { public: AndroidAssetArchive(jobject am); @@ -43,11 +45,9 @@ public: virtual Common::SeekableReadStream *createReadStreamForMember(const Common::String &name) const; private: - jmethodID MID_open; - jmethodID MID_openFd; - jmethodID MID_list; - - jobject _am; + AAssetManager *_am; + mutable Common::ArchiveMemberList _cachedMembers; + mutable bool _hasCached; }; #endif diff --git a/backends/platform/android/jni.cpp b/backends/platform/android/jni.cpp index 22e6a749c2..256ae09ef8 100644 --- a/backends/platform/android/jni.cpp +++ b/backends/platform/android/jni.cpp @@ -76,6 +76,8 @@ bool JNI::_ready_for_events = 0; jmethodID JNI::_MID_getDPI = 0; jmethodID JNI::_MID_displayMessageOnOSD = 0; +jmethodID JNI::_MID_openUrl = 0; +jmethodID JNI::_MID_isConnectionLimited = 0; jmethodID JNI::_MID_setWindowCaption = 0; jmethodID JNI::_MID_showVirtualKeyboard = 0; jmethodID JNI::_MID_getSysArchives = 0; @@ -232,6 +234,41 @@ void JNI::displayMessageOnOSD(const char *msg) { env->DeleteLocalRef(java_msg); } +bool JNI::openUrl(const char *url) { + bool success = true; + JNIEnv *env = JNI::getEnv(); + jstring javaUrl = env->NewStringUTF(url); + + env->CallVoidMethod(_jobj, _MID_openUrl, javaUrl); + + if (env->ExceptionCheck()) { + LOGE("Failed to open URL"); + + env->ExceptionDescribe(); + env->ExceptionClear(); + success = false; + } + + env->DeleteLocalRef(javaUrl); + return success; +} + +bool JNI::isConnectionLimited() { + bool limited = false; + JNIEnv *env = JNI::getEnv(); + limited = env->CallBooleanMethod(_jobj, _MID_isConnectionLimited); + + if (env->ExceptionCheck()) { + LOGE("Failed to check whether connection's limited"); + + env->ExceptionDescribe(); + env->ExceptionClear(); + limited = true; + } + + return limited; +} + void JNI::setWindowCaption(const char *caption) { JNIEnv *env = JNI::getEnv(); jstring java_caption = env->NewStringUTF(caption); @@ -411,6 +448,8 @@ void JNI::create(JNIEnv *env, jobject self, jobject asset_manager, FIND_METHOD(, setWindowCaption, "(Ljava/lang/String;)V"); FIND_METHOD(, getDPI, "([F)V"); FIND_METHOD(, displayMessageOnOSD, "(Ljava/lang/String;)V"); + FIND_METHOD(, openUrl, "(Ljava/lang/String;)V"); + FIND_METHOD(, isConnectionLimited, "()Z"); FIND_METHOD(, showVirtualKeyboard, "(Z)V"); FIND_METHOD(, getSysArchives, "()[Ljava/lang/String;"); FIND_METHOD(, initSurface, "()Ljavax/microedition/khronos/egl/EGLSurface;"); diff --git a/backends/platform/android/jni.h b/backends/platform/android/jni.h index 70feaaf72a..0798db448a 100644 --- a/backends/platform/android/jni.h +++ b/backends/platform/android/jni.h @@ -58,6 +58,8 @@ public: static void setWindowCaption(const char *caption); static void getDPI(float *values); static void displayMessageOnOSD(const char *msg); + static bool openUrl(const char *url); + static bool isConnectionLimited(); static void showVirtualKeyboard(bool enable); static void addSysArchivesToSearchSet(Common::SearchSet &s, int priority); @@ -89,6 +91,8 @@ private: static jmethodID _MID_getDPI; static jmethodID _MID_displayMessageOnOSD; + static jmethodID _MID_openUrl; + static jmethodID _MID_isConnectionLimited; static jmethodID _MID_setWindowCaption; static jmethodID _MID_showVirtualKeyboard; static jmethodID _MID_getSysArchives; diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVM.java b/backends/platform/android/org/scummvm/scummvm/ScummVM.java index 3b370a583d..47dcb32b22 100644 --- a/backends/platform/android/org/scummvm/scummvm/ScummVM.java +++ b/backends/platform/android/org/scummvm/scummvm/ScummVM.java @@ -53,6 +53,8 @@ public abstract class ScummVM implements SurfaceHolder.Callback, Runnable { // Callbacks from C++ peer instance abstract protected void getDPI(float[] values); abstract protected void displayMessageOnOSD(String msg); + abstract protected void openUrl(String url); + abstract protected boolean isConnectionLimited(); abstract protected void setWindowCaption(String caption); abstract protected void showVirtualKeyboard(boolean enable); abstract protected String[] getSysArchives(); diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java b/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java index 5b2dcae175..225496ca0d 100644 --- a/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java +++ b/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java @@ -2,9 +2,13 @@ package org.scummvm.scummvm; import android.app.Activity; import android.app.AlertDialog; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.media.AudioManager; +import android.net.Uri; +import android.net.wifi.WifiManager; +import android.net.wifi.WifiInfo; import android.os.Build; import android.os.Bundle; import android.os.Environment; @@ -75,6 +79,21 @@ public class ScummVMActivity extends Activity { } @Override + protected void openUrl(String url) { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); + } + + @Override + protected boolean isConnectionLimited() { + WifiManager wifiMgr = (WifiManager)getSystemService(Context.WIFI_SERVICE); + if (wifiMgr != null && wifiMgr.isWifiEnabled()) { + WifiInfo wifiInfo = wifiMgr.getConnectionInfo(); + return (wifiInfo == null || wifiInfo.getNetworkId() == -1); //WiFi is on, but it's not connected to any network + } + return true; + } + + @Override protected void setWindowCaption(final String caption) { runOnUiThread(new Runnable() { public void run() { diff --git a/backends/platform/dc/dc-fs.cpp b/backends/platform/dc/dc-fs.cpp index 77fe4143dd..4bd7e5a777 100644 --- a/backends/platform/dc/dc-fs.cpp +++ b/backends/platform/dc/dc-fs.cpp @@ -57,6 +57,7 @@ public: virtual Common::SeekableReadStream *createReadStream(); virtual Common::WriteStream *createWriteStream() { return 0; } + virtual bool create(bool isDirectory) { return false; } static AbstractFSNode *makeFileNodePath(const Common::String &path); }; diff --git a/backends/platform/dc/vmsave.cpp b/backends/platform/dc/vmsave.cpp index d896ba1299..5e8f50ca89 100644 --- a/backends/platform/dc/vmsave.cpp +++ b/backends/platform/dc/vmsave.cpp @@ -266,7 +266,7 @@ public: { return ::readSaveGame(buffer, _size, filename); } }; -class OutVMSave : public Common::OutSaveFile { +class OutVMSave : public Common::WriteStream { private: char *buffer; int _pos, size, committed; @@ -293,11 +293,24 @@ public: class VMSaveManager : public Common::SaveFileManager { public: + virtual void updateSavefilesList(Common::StringArray &lockedFiles) { + // TODO: implement this (locks files, preventing them from being listed, saved or loaded) + } - virtual Common::OutSaveFile *openForSaving(const Common::String &filename, bool compress = true) { - OutVMSave *s = new OutVMSave(filename.c_str()); - return compress ? Common::wrapCompressedWriteStream(s) : s; - } + virtual Common::InSaveFile *openRawFile(const Common::String &filename) { + InVMSave *s = new InVMSave(); + if (s->readSaveGame(filename.c_str())) { + return s; + } else { + delete s; + return NULL; + } + } + + virtual Common::OutSaveFile *openForSaving(const Common::String &filename, bool compress = true) { + OutVMSave *s = new OutVMSave(filename.c_str()); + return new Common::OutSaveFile(compress ? Common::wrapCompressedWriteStream(s) : s); + } virtual Common::InSaveFile *openForLoading(const Common::String &filename) { InVMSave *s = new InVMSave(); diff --git a/backends/platform/ds/arm9/source/gbampsave.cpp b/backends/platform/ds/arm9/source/gbampsave.cpp index ef6091e2a2..9991a3253a 100644 --- a/backends/platform/ds/arm9/source/gbampsave.cpp +++ b/backends/platform/ds/arm9/source/gbampsave.cpp @@ -45,6 +45,17 @@ static Common::String getSavePath() { // GBAMP Save File Manager ////////////////////////// +void GBAMPSaveFileManager::updateSavefilesList(Common::StringArray &lockedFiles) { + // TODO: implement this + // in this method manager should remember lockedFiles + // these files must not be opened for loading or saving, or listed by listSavefiles() +} + +Common::InSaveFile *GBAMPSaveFileManager::openRawFile(const Common::String &filename) { + // TODO: make sure it returns raw file, not uncompressed save contents + return openForLoading(filename); +} + Common::OutSaveFile *GBAMPSaveFileManager::openForSaving(const Common::String &filename, bool compress) { Common::String fileSpec = getSavePath(); if (fileSpec.lastChar() != '/') @@ -56,7 +67,7 @@ Common::OutSaveFile *GBAMPSaveFileManager::openForSaving(const Common::String &f Common::WriteStream *stream = DS::DSFileStream::makeFromPath(fileSpec, true); // Use a write buffer stream = Common::wrapBufferedWriteStream(stream, SAVE_BUFFER_SIZE); - return stream; + return new Common::OutSaveFile(stream); } Common::InSaveFile *GBAMPSaveFileManager::openForLoading(const Common::String &filename) { diff --git a/backends/platform/ds/arm9/source/gbampsave.h b/backends/platform/ds/arm9/source/gbampsave.h index d86db2ec70..d30e3ab177 100644 --- a/backends/platform/ds/arm9/source/gbampsave.h +++ b/backends/platform/ds/arm9/source/gbampsave.h @@ -27,6 +27,9 @@ class GBAMPSaveFileManager : public Common::SaveFileManager { public: + virtual void updateSavefilesList(Common::StringArray &lockedFiles); + virtual Common::InSaveFile *openRawFile(const Common::String &filename); + virtual Common::OutSaveFile *openForSaving(const Common::String &filename, bool compress = true); virtual Common::InSaveFile *openForLoading(const Common::String &filename); diff --git a/backends/platform/n64/framfs_save_manager.h b/backends/platform/n64/framfs_save_manager.h index 9bd4ee579e..24f9bf10ce 100644 --- a/backends/platform/n64/framfs_save_manager.h +++ b/backends/platform/n64/framfs_save_manager.h @@ -65,7 +65,7 @@ public: } }; -class OutFRAMSave : public Common::OutSaveFile { +class OutFRAMSave : public Common::WriteStream { private: FRAMFILE *fd; @@ -102,11 +102,26 @@ public: class FRAMSaveManager : public Common::SaveFileManager { public: + virtual void updateSavefilesList(Common::StringArray &lockedFiles) { + // this method is used to lock saves while cloud syncing + // as there is no network on N64, this method wouldn't be used + // thus it's not implemtented + } + + virtual Common::InSaveFile *openRawFile(const Common::String &filename) { + InFRAMSave *s = new InFRAMSave(); + if (s->readSaveGame(filename.c_str())) { + return s; + } else { + delete s; + return 0; + } + } virtual Common::OutSaveFile *openForSaving(const Common::String &filename, bool compress = true) { OutFRAMSave *s = new OutFRAMSave(filename.c_str()); if (!s->err()) { - return compress ? Common::wrapCompressedWriteStream(s) : s; + return new Common::OutSaveFile(compress ? Common::wrapCompressedWriteStream(s) : s); } else { delete s; return 0; diff --git a/backends/platform/n64/pakfs_save_manager.h b/backends/platform/n64/pakfs_save_manager.h index 0c08f0c506..8e16d1fce4 100644 --- a/backends/platform/n64/pakfs_save_manager.h +++ b/backends/platform/n64/pakfs_save_manager.h @@ -65,7 +65,7 @@ public: } }; -class OutPAKSave : public Common::OutSaveFile { +class OutPAKSave : public Common::WriteStream { private: PAKFILE *fd; @@ -104,11 +104,26 @@ public: class PAKSaveManager : public Common::SaveFileManager { public: + virtual void updateSavefilesList(Common::StringArray &lockedFiles) { + // this method is used to lock saves while cloud syncing + // as there is no network on N64, this method wouldn't be used + // thus it's not implemtented + } + + virtual Common::InSaveFile *openRawFile(const Common::String &filename) { + InPAKSave *s = new InPAKSave(); + if (s->readSaveGame(filename.c_str())) { + return s; + } else { + delete s; + return NULL; + } + } virtual Common::OutSaveFile *openForSaving(const Common::String &filename, bool compress = true) { OutPAKSave *s = new OutPAKSave(filename.c_str()); if (!s->err()) { - return compress ? Common::wrapCompressedWriteStream(s) : s; + return new Common::OutSaveFile(compress ? Common::wrapCompressedWriteStream(s) : s); } else { delete s; return NULL; diff --git a/backends/platform/ps2/eecodyvdfs.c b/backends/platform/ps2/eecodyvdfs.c index f410b0c8ec..a4d60a7501 100644 --- a/backends/platform/ps2/eecodyvdfs.c +++ b/backends/platform/ps2/eecodyvdfs.c @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/backends/platform/ps2/iop/CoDyVDfs/iop/codyvdfs.c b/backends/platform/ps2/iop/CoDyVDfs/iop/codyvdfs.c index 2a94560843..3fe0d408c4 100644 --- a/backends/platform/ps2/iop/CoDyVDfs/iop/codyvdfs.c +++ b/backends/platform/ps2/iop/CoDyVDfs/iop/codyvdfs.c @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/backends/platform/ps2/iop/CoDyVDfs/iop/fiofs.c b/backends/platform/ps2/iop/CoDyVDfs/iop/fiofs.c index 611211a715..dcf9074916 100644 --- a/backends/platform/ps2/iop/CoDyVDfs/iop/fiofs.c +++ b/backends/platform/ps2/iop/CoDyVDfs/iop/fiofs.c @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/backends/platform/ps2/iop/CoDyVDfs/iop/rpcfs.c b/backends/platform/ps2/iop/CoDyVDfs/iop/rpcfs.c index 983ae38716..6d12a451e3 100644 --- a/backends/platform/ps2/iop/CoDyVDfs/iop/rpcfs.c +++ b/backends/platform/ps2/iop/CoDyVDfs/iop/rpcfs.c @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/backends/platform/ps2/savefilemgr.cpp b/backends/platform/ps2/savefilemgr.cpp index 4fd2b1c72b..4cd988074e 100644 --- a/backends/platform/ps2/savefilemgr.cpp +++ b/backends/platform/ps2/savefilemgr.cpp @@ -82,7 +82,11 @@ void Ps2SaveFileManager::mcSplit(char *full, char *game, char *ext) { // TODO } -Common::InSaveFile *Ps2SaveFileManager::openForLoading(const Common::String &filename) { +void Ps2SaveFileManager::updateSavefilesList(Common::StringArray &lockedFiles) { + // TODO: implement this (locks files, preventing them from being listed, saved or loaded) +} + +Common::InSaveFile *Ps2SaveFileManager::openRawFile(const Common::String &filename) { Common::FSNode savePath(ConfMan.get("savepath")); // TODO: is this fast? Common::SeekableReadStream *sf; @@ -141,7 +145,12 @@ Common::InSaveFile *Ps2SaveFileManager::openForLoading(const Common::String &fil // _screen->wantAnim(false); - return Common::wrapCompressedReadStream(sf); + return sf; +} + +Common::InSaveFile *Ps2SaveFileManager::openForLoading(const Common::String &filename) { + Common::SeekableReadStream *sf = openRawFile(filename); + return (sf == NULL ? NULL : Common::wrapCompressedReadStream(sf)); } Common::OutSaveFile *Ps2SaveFileManager::openForSaving(const Common::String &filename, bool compress) { @@ -192,7 +201,7 @@ Common::OutSaveFile *Ps2SaveFileManager::openForSaving(const Common::String &fil } _screen->wantAnim(false); - return compress ? Common::wrapCompressedWriteStream(sf) : sf; + return new Common::OutSaveFile(compress ? Common::wrapCompressedWriteStream(sf) : sf); } bool Ps2SaveFileManager::removeSavefile(const Common::String &filename) { diff --git a/backends/platform/ps2/savefilemgr.h b/backends/platform/ps2/savefilemgr.h index 547f16fa77..3d45382c64 100644 --- a/backends/platform/ps2/savefilemgr.h +++ b/backends/platform/ps2/savefilemgr.h @@ -34,6 +34,9 @@ public: Ps2SaveFileManager(OSystem_PS2 *system, Gs2dScreen *screen); virtual ~Ps2SaveFileManager(); + virtual void updateSavefilesList(Common::StringArray &lockedFiles); + virtual Common::InSaveFile *openRawFile(const Common::String &filename); + virtual Common::InSaveFile *openForLoading(const Common::String &filename); virtual Common::OutSaveFile *openForSaving(const Common::String &filename, bool compress = true); virtual Common::StringArray listSavefiles(const Common::String &pattern); diff --git a/backends/platform/sdl/macosx/macosx.cpp b/backends/platform/sdl/macosx/macosx.cpp index 7652c0d833..212af6723e 100644 --- a/backends/platform/sdl/macosx/macosx.cpp +++ b/backends/platform/sdl/macosx/macosx.cpp @@ -33,6 +33,7 @@ #include "backends/platform/sdl/macosx/macosx.h" #include "backends/updates/macosx/macosx-updates.h" #include "backends/taskbar/macosx/macosx-taskbar.h" +#include "backends/platform/sdl/macosx/macosx_wrapper.h" #include "common/archive.h" #include "common/config-manager.h" @@ -106,7 +107,7 @@ void OSystem_MacOSX::addSysArchivesToSearchSet(Common::SearchSet &s, int priorit } bool OSystem_MacOSX::hasFeature(Feature f) { - if (f == kFeatureDisplayLogFile) + if (f == kFeatureDisplayLogFile || f == kFeatureClipboardSupport || f == kFeatureOpenUrl) return true; return OSystem_POSIX::hasFeature(f); } @@ -124,6 +125,21 @@ bool OSystem_MacOSX::displayLogFile() { return err != noErr; } +bool OSystem_MacOSX::hasTextInClipboard() { + return hasTextInClipboardMacOSX(); +} + +Common::String OSystem_MacOSX::getTextFromClipboard() { + return getTextFromClipboardMacOSX(); +} + +bool OSystem_MacOSX::openUrl(const Common::String &url) { + CFURLRef urlRef = CFURLCreateWithBytes (NULL, (UInt8*)url.c_str(), url.size(), kCFStringEncodingASCII, NULL); + OSStatus err = LSOpenCFURLRef(urlRef, NULL); + CFRelease(urlRef); + return err != noErr; +} + Common::String OSystem_MacOSX::getSystemLanguage() const { #if defined(USE_DETECTLANG) && defined(USE_TRANSLATION) CFArrayRef availableLocalizations = CFBundleCopyBundleLocalizations(CFBundleGetMainBundle()); diff --git a/backends/platform/sdl/macosx/macosx.h b/backends/platform/sdl/macosx/macosx.h index 6905284a5f..929f2f91fa 100644 --- a/backends/platform/sdl/macosx/macosx.h +++ b/backends/platform/sdl/macosx/macosx.h @@ -33,6 +33,11 @@ public: virtual bool displayLogFile(); + virtual bool hasTextInClipboard(); + virtual Common::String getTextFromClipboard(); + + virtual bool openUrl(const Common::String &url); + virtual Common::String getSystemLanguage() const; virtual void init(); diff --git a/backends/platform/sdl/macosx/macosx_wrapper.h b/backends/platform/sdl/macosx/macosx_wrapper.h new file mode 100644 index 0000000000..3b346fc486 --- /dev/null +++ b/backends/platform/sdl/macosx/macosx_wrapper.h @@ -0,0 +1,31 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef PLATFORM_SDL_MACOSX_WRAPPER_H +#define PLATFORM_SDL_MACOSX_WRAPPER_H + +#include <common/str.h> + +bool hasTextInClipboardMacOSX(); +Common::String getTextFromClipboardMacOSX(); + +#endif diff --git a/backends/platform/sdl/macosx/macosx_wrapper.mm b/backends/platform/sdl/macosx/macosx_wrapper.mm new file mode 100644 index 0000000000..8ec9eac5ac --- /dev/null +++ b/backends/platform/sdl/macosx/macosx_wrapper.mm @@ -0,0 +1,48 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +// Disable symbol overrides so that we can use system headers. +#define FORBIDDEN_SYMBOL_ALLOW_ALL + +#include "backends/platform/sdl/macosx/macosx_wrapper.h" + +#include <AppKit/NSPasteboard.h> +#include <Foundation/NSArray.h> + +bool hasTextInClipboardMacOSX() { + return [[NSPasteboard generalPasteboard] availableTypeFromArray:[NSArray arrayWithObject:NSStringPboardType]] != nil; +} + +Common::String getTextFromClipboardMacOSX() { + if (!hasTextInClipboardMacOSX()) + return Common::String(); + // Note: on OS X 10.6 and above it is recommanded to use NSPasteboardTypeString rather than NSStringPboardType. + // But since we still target older version use NSStringPboardType. + NSPasteboard *pb = [NSPasteboard generalPasteboard]; + NSString* str = [pb stringForType:NSStringPboardType]; + if (str == nil) + return Common::String(); + // If the string cannot be represented using the requested encoding we get a null pointer below. + // This is fine as ScummVM would not know what to do with non-ASCII characters (although maybe + // we should use NSISOLatin1StringEncoding?). + return Common::String([str cStringUsingEncoding:NSASCIIStringEncoding]); +} diff --git a/backends/platform/sdl/module.mk b/backends/platform/sdl/module.mk index 74dd506d31..84ce272d3c 100644 --- a/backends/platform/sdl/module.mk +++ b/backends/platform/sdl/module.mk @@ -14,6 +14,7 @@ ifdef MACOSX MODULE_OBJS += \ macosx/macosx-main.o \ macosx/macosx.o \ + macosx/macosx_wrapper.o \ macosx/appmenu_osx.o endif diff --git a/backends/platform/sdl/posix/posix.cpp b/backends/platform/sdl/posix/posix.cpp index 0d5f39736a..b805a452cf 100644 --- a/backends/platform/sdl/posix/posix.cpp +++ b/backends/platform/sdl/posix/posix.cpp @@ -25,6 +25,7 @@ #define FORBIDDEN_SYMBOL_EXCEPTION_exit #define FORBIDDEN_SYMBOL_EXCEPTION_unistd_h #define FORBIDDEN_SYMBOL_EXCEPTION_time_h //On IRIX, sys/stat.h includes sys/time.h +#define FORBIDDEN_SYMBOL_EXCEPTION_system #include "common/scummsys.h" @@ -40,6 +41,9 @@ #include "backends/audiocd/linux/linux-audiocd.h" #endif +#include "common/textconsole.h" + +#include <stdlib.h> #include <errno.h> #include <sys/stat.h> #include <sys/wait.h> @@ -78,7 +82,7 @@ void OSystem_POSIX::initBackend() { } bool OSystem_POSIX::hasFeature(Feature f) { - if (f == kFeatureDisplayLogFile) + if (f == kFeatureDisplayLogFile || f == kFeatureOpenUrl) return true; return OSystem_SDL::hasFeature(f); } @@ -261,6 +265,51 @@ bool OSystem_POSIX::displayLogFile() { return WIFEXITED(status) && WEXITSTATUS(status) == 0; } +bool OSystem_POSIX::openUrl(const Common::String &url) { + // inspired by Qt's "qdesktopservices_x11.cpp" + + // try "standards" + if (launchBrowser("xdg-open", url)) + return true; + if (launchBrowser(getenv("DEFAULT_BROWSER"), url)) + return true; + if (launchBrowser(getenv("BROWSER"), url)) + return true; + + // try desktop environment specific tools + if (launchBrowser("gnome-open", url)) // gnome + return true; + if (launchBrowser("kfmclient openURL", url)) // kde + return true; + if (launchBrowser("exo-open", url)) // xfce + return true; + + // try browser names + if (launchBrowser("firefox", url)) + return true; + if (launchBrowser("mozilla", url)) + return true; + if (launchBrowser("netscape", url)) + return true; + if (launchBrowser("opera", url)) + return true; + if (launchBrowser("chromium-browser", url)) + return true; + if (launchBrowser("google-chrome", url)) + return true; + + warning("openUrl() (POSIX) failed to open URL"); + return false; +} + +bool OSystem_POSIX::launchBrowser(const Common::String& client, const Common::String &url) { + // FIXME: system's input must be heavily escaped + // well, when url's specified by user + // it's OK now (urls are hardcoded somewhere in GUI) + Common::String cmd = client + " " + url; + return (system(cmd.c_str()) != -1); +} + AudioCDManager *OSystem_POSIX::createAudioCDManager() { #ifdef USE_LINUXCD diff --git a/backends/platform/sdl/posix/posix.h b/backends/platform/sdl/posix/posix.h index 050463c273..e5110ff632 100644 --- a/backends/platform/sdl/posix/posix.h +++ b/backends/platform/sdl/posix/posix.h @@ -35,6 +35,8 @@ public: virtual bool displayLogFile(); + virtual bool openUrl(const Common::String &url); + virtual void init(); virtual void initBackend(); @@ -63,6 +65,8 @@ protected: virtual Common::WriteStream *createLogFile(); virtual AudioCDManager *createAudioCDManager(); + + bool launchBrowser(const Common::String& client, const Common::String &url); }; #endif diff --git a/backends/platform/sdl/sdl-sys.h b/backends/platform/sdl/sdl-sys.h index 551605a4b4..9ebd123bb4 100644 --- a/backends/platform/sdl/sdl-sys.h +++ b/backends/platform/sdl/sdl-sys.h @@ -67,6 +67,57 @@ typedef struct { int FAKE; } FAKE_FILE; #define system FAKE_system #endif +// Fix compilation with MacPorts SDL 2 +// It needs various (usually forbidden) symbols from time.h +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_time_h + + #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_asctime) + #undef asctime + #define asctime FAKE_asctime + #endif + + #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_clock) + #undef clock + #define clock FAKE_clock + #endif + + #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_ctime) + #undef ctime + #define ctime FAKE_ctime + #endif + + #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_difftime) + #undef difftime + #define difftime FAKE_difftime + #endif + + #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_getdate) + #undef getdate + #define getdate FAKE_getdate + #endif + + #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_gmtime) + #undef gmtime + #define gmtime FAKE_gmtime + #endif + + #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_localtime) + #undef localtime + #define localtime FAKE_localtime + #endif + + #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_mktime) + #undef mktime + #define mktime FAKE_mktime + #endif + + #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_time) + #undef time + #define time FAKE_time + #endif + +#endif // FORBIDDEN_SYMBOL_EXCEPTION_time_h + // HACK: SDL might include windows.h which defines its own ARRAYSIZE. // However, we want to use the version from common/util.h. Thus, we make sure // that we actually have this definition after including the SDL headers. @@ -176,6 +227,56 @@ typedef struct { int FAKE; } FAKE_FILE; #define system(a) FORBIDDEN_SYMBOL_REPLACEMENT #endif +// re-forbid all those time.h symbols again (if they were forbidden) +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_time_h + + #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_asctime) + #undef asctime + #define asctime(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + + #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_clock) + #undef clock + #define clock() FORBIDDEN_SYMBOL_REPLACEMENT + #endif + + #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_ctime) + #undef ctime + #define ctime(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + + #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_difftime) + #undef difftime + #define difftime(a,b) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + + #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_getdate) + #undef getdate + #define getdate(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + + #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_gmtime) + #undef gmtime + #define gmtime(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + + #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_localtime) + #undef localtime + #define localtime(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + + #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_mktime) + #undef mktime + #define mktime(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + + #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_time) + #undef time + #define time(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + +#endif // FORBIDDEN_SYMBOL_EXCEPTION_time_h + // SDL 2 has major API changes. We redefine constants which got renamed to // ease the transition. This is sometimes dangerous because the values changed // too! diff --git a/backends/platform/sdl/sdl-window.cpp b/backends/platform/sdl/sdl-window.cpp index 6d35f77ae0..609186a061 100644 --- a/backends/platform/sdl/sdl-window.cpp +++ b/backends/platform/sdl/sdl-window.cpp @@ -150,7 +150,7 @@ bool SdlWindow::hasMouseFocus() const { void SdlWindow::warpMouseInWindow(uint x, uint y) { #if SDL_VERSION_ATLEAST(2, 0, 0) - if (_window) { + if (_window && hasMouseFocus()) { SDL_WarpMouseInWindow(_window, x, y); } #else diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index dca6891fef..18f2a49bdd 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -60,6 +60,14 @@ #endif // !WIN32 #endif +#ifdef USE_SDL_NET +#include <SDL_net.h> +#endif + +#if SDL_VERSION_ATLEAST(2, 0, 0) +#include <SDL_clipboard.h> +#endif + OSystem_SDL::OSystem_SDL() : #ifdef USE_OPENGL @@ -73,6 +81,9 @@ OSystem_SDL::OSystem_SDL() #endif _inited(false), _initedSDL(false), +#ifdef USE_SDL_NET + _initedSDLnet(false), +#endif _logger(0), _mixerManager(0), _eventSource(0), @@ -120,6 +131,10 @@ OSystem_SDL::~OSystem_SDL() { delete _logger; _logger = 0; +#ifdef USE_SDL_NET + if (_initedSDLnet) SDLNet_Quit(); +#endif + SDL_Quit(); } @@ -160,6 +175,13 @@ void OSystem_SDL::init() { } +bool OSystem_SDL::hasFeature(Feature f) { +#if SDL_VERSION_ATLEAST(2, 0, 0) + if (f == kFeatureClipboardSupport) return true; +#endif + return ModularBackend::hasFeature(f); +} + void OSystem_SDL::initBackend() { // Check if backend has not been initialized assert(!_inited); @@ -294,6 +316,17 @@ void OSystem_SDL::initSDL() { _initedSDL = true; } + +#ifdef USE_SDL_NET + // Check if SDL_net has not been initialized + if (!_initedSDLnet) { + // Initialize SDL_net + if (SDLNet_Init() == -1) + error("Could not initialize SDL_net: %s", SDLNet_GetError()); + + _initedSDLnet = true; + } +#endif } void OSystem_SDL::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) { @@ -431,6 +464,26 @@ Common::String OSystem_SDL::getSystemLanguage() const { #endif // USE_DETECTLANG } +bool OSystem_SDL::hasTextInClipboard() { +#if SDL_VERSION_ATLEAST(2, 0, 0) + return SDL_HasClipboardText() == SDL_TRUE; +#else + return false; +#endif +} + +Common::String OSystem_SDL::getTextFromClipboard() { + if (!hasTextInClipboard()) return ""; + +#if SDL_VERSION_ATLEAST(2, 0, 0) + char *text = SDL_GetClipboardText(); + if (text == nullptr) return ""; + return text; +#else + return ""; +#endif +} + uint32 OSystem_SDL::getMillis(bool skipRecord) { uint32 millis = SDL_GetTicks(); diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index 1fe670c5c3..17b4e9b001 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -55,6 +55,8 @@ public: */ virtual SdlMixerManager *getMixerManager(); + virtual bool hasFeature(Feature f); + // Override functions from ModularBackend and OSystem virtual void initBackend(); #if defined(USE_TASKBAR) @@ -69,6 +71,10 @@ public: virtual Common::String getSystemLanguage() const; + // Clipboard + virtual bool hasTextInClipboard(); + virtual Common::String getTextFromClipboard(); + virtual void setWindowCaption(const char *caption); virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0); virtual uint32 getMillis(bool skipRecord = false); @@ -81,6 +87,9 @@ public: protected: bool _inited; bool _initedSDL; +#ifdef USE_SDL_NET + bool _initedSDLnet; +#endif /** * Mixer manager that configures and setups SDL for diff --git a/backends/platform/sdl/win32/win32.cpp b/backends/platform/sdl/win32/win32.cpp index fcc0849624..99c71a49e0 100644 --- a/backends/platform/sdl/win32/win32.cpp +++ b/backends/platform/sdl/win32/win32.cpp @@ -94,7 +94,7 @@ void OSystem_Win32::initBackend() { bool OSystem_Win32::hasFeature(Feature f) { - if (f == kFeatureDisplayLogFile) + if (f == kFeatureDisplayLogFile || f == kFeatureOpenUrl) return true; return OSystem_SDL::hasFeature(f); @@ -135,6 +135,16 @@ bool OSystem_Win32::displayLogFile() { return false; } +bool OSystem_Win32::openUrl(const Common::String &url) { + const uint64 result = (uint64)ShellExecute(0, 0, /*(wchar_t*)nativeFilePath.utf16()*/url.c_str(), 0, 0, SW_SHOWNORMAL); + // ShellExecute returns a value greater than 32 if successful + if (result <= 32) { + warning("ShellExecute failed: error = %u", result); + return false; + } + return true; +} + Common::String OSystem_Win32::getDefaultConfigFileName() { char configFile[MAXPATHLEN]; diff --git a/backends/platform/sdl/win32/win32.h b/backends/platform/sdl/win32/win32.h index ca0843e834..636ebae88f 100644 --- a/backends/platform/sdl/win32/win32.h +++ b/backends/platform/sdl/win32/win32.h @@ -36,6 +36,8 @@ public: virtual bool displayLogFile(); + virtual bool openUrl(const Common::String &url); + protected: /** * The path of the currently open log file, if any. diff --git a/backends/platform/symbian/S60/scummvm-CVS-SymbianS60v1.pkg b/backends/platform/symbian/S60/scummvm-CVS-SymbianS60v1.pkg index da69d455d7..6ec03557be 100644 --- a/backends/platform/symbian/S60/scummvm-CVS-SymbianS60v1.pkg +++ b/backends/platform/symbian/S60/scummvm-CVS-SymbianS60v1.pkg @@ -8,12 +8,12 @@ ; modify it under the terms of the GNU General Public License ; as published by the Free Software Foundation; either version 2 ; 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, write to the Free Software ; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/backends/platform/symbian/S60/scummvm-CVS-SymbianS60v2.pkg b/backends/platform/symbian/S60/scummvm-CVS-SymbianS60v2.pkg index 0d22c9d016..fddf772b7f 100644 --- a/backends/platform/symbian/S60/scummvm-CVS-SymbianS60v2.pkg +++ b/backends/platform/symbian/S60/scummvm-CVS-SymbianS60v2.pkg @@ -8,12 +8,12 @@ ; modify it under the terms of the GNU General Public License ; as published by the Free Software Foundation; either version 2 ; 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, write to the Free Software ; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/backends/platform/symbian/S60v3/scummvm-CVS-SymbianS60v3.pkg b/backends/platform/symbian/S60v3/scummvm-CVS-SymbianS60v3.pkg index 4c83b32805..30d2aa3db6 100644 --- a/backends/platform/symbian/S60v3/scummvm-CVS-SymbianS60v3.pkg +++ b/backends/platform/symbian/S60v3/scummvm-CVS-SymbianS60v3.pkg @@ -7,12 +7,12 @@ ; modify it under the terms of the GNU General Public License ; as published by the Free Software Foundation; either version 2 ; 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, write to the Free Software ; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/backends/platform/symbian/S60v3/scummvm-CVS-SymbianS60v3_split.pkg b/backends/platform/symbian/S60v3/scummvm-CVS-SymbianS60v3_split.pkg index 3d55584d28..8c953d30ea 100644 --- a/backends/platform/symbian/S60v3/scummvm-CVS-SymbianS60v3_split.pkg +++ b/backends/platform/symbian/S60v3/scummvm-CVS-SymbianS60v3_split.pkg @@ -7,19 +7,16 @@ ; modify it under the terms of the GNU General Public License ; as published by the Free Software Foundation; either version 2 ; 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, write to the Free Software ; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ; -; $URL$ -; $Id$ -; ; ;;; diff --git a/backends/platform/symbian/S80/scummvm-CVS-SymbianS80.pkg b/backends/platform/symbian/S80/scummvm-CVS-SymbianS80.pkg index c3563b4041..cfff4be7c5 100644 --- a/backends/platform/symbian/S80/scummvm-CVS-SymbianS80.pkg +++ b/backends/platform/symbian/S80/scummvm-CVS-SymbianS80.pkg @@ -8,12 +8,12 @@ ; modify it under the terms of the GNU General Public License ; as published by the Free Software Foundation; either version 2 ; 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, write to the Free Software ; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/backends/platform/symbian/S90/scummvm-CVS-SymbianS90.pkg b/backends/platform/symbian/S90/scummvm-CVS-SymbianS90.pkg index 457f41998b..9057eb66a5 100644 --- a/backends/platform/symbian/S90/scummvm-CVS-SymbianS90.pkg +++ b/backends/platform/symbian/S90/scummvm-CVS-SymbianS90.pkg @@ -8,12 +8,12 @@ ; modify it under the terms of the GNU General Public License ; as published by the Free Software Foundation; either version 2 ; 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, write to the Free Software ; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/backends/platform/symbian/UIQ2/scummvm-CVS-SymbianUIQ2.pkg b/backends/platform/symbian/UIQ2/scummvm-CVS-SymbianUIQ2.pkg index e2b8a85162..26038f4875 100644 --- a/backends/platform/symbian/UIQ2/scummvm-CVS-SymbianUIQ2.pkg +++ b/backends/platform/symbian/UIQ2/scummvm-CVS-SymbianUIQ2.pkg @@ -8,12 +8,12 @@ ; modify it under the terms of the GNU General Public License ; as published by the Free Software Foundation; either version 2 ; 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, write to the Free Software ; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/backends/platform/symbian/UIQ2/scummvm-CVS-SymbianUIQ2_SE.pkg b/backends/platform/symbian/UIQ2/scummvm-CVS-SymbianUIQ2_SE.pkg index 8284f64611..7d1e2bc249 100644 --- a/backends/platform/symbian/UIQ2/scummvm-CVS-SymbianUIQ2_SE.pkg +++ b/backends/platform/symbian/UIQ2/scummvm-CVS-SymbianUIQ2_SE.pkg @@ -8,12 +8,12 @@ ; modify it under the terms of the GNU General Public License ; as published by the Free Software Foundation; either version 2 ; 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, write to the Free Software ; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/backends/platform/symbian/UIQ3/scummvm-CVS-SymbianUIQ3.pkg b/backends/platform/symbian/UIQ3/scummvm-CVS-SymbianUIQ3.pkg index 8ac6f97d9f..adb869f078 100644 --- a/backends/platform/symbian/UIQ3/scummvm-CVS-SymbianUIQ3.pkg +++ b/backends/platform/symbian/UIQ3/scummvm-CVS-SymbianUIQ3.pkg @@ -8,12 +8,12 @@ ; modify it under the terms of the GNU General Public License ; as published by the Free Software Foundation; either version 2 ; 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, write to the Free Software ; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/backends/platform/symbian/UIQ3/scummvm-CVS-SymbianUIQ3_split.pkg b/backends/platform/symbian/UIQ3/scummvm-CVS-SymbianUIQ3_split.pkg index 4c46be50a1..528e39adee 100644 --- a/backends/platform/symbian/UIQ3/scummvm-CVS-SymbianUIQ3_split.pkg +++ b/backends/platform/symbian/UIQ3/scummvm-CVS-SymbianUIQ3_split.pkg @@ -8,12 +8,12 @@ ; modify it under the terms of the GNU General Public License ; as published by the Free Software Foundation; either version 2 ; 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, write to the Free Software ; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |