diff options
author | Strangerke | 2011-06-29 16:15:41 +0200 |
---|---|---|
committer | Strangerke | 2011-06-29 16:15:41 +0200 |
commit | b0c9c9122fc678074aba30068e5b36d347208e65 (patch) | |
tree | 79a99db08ec985f2e5f1e216823b1104d5b753fb /common | |
parent | f2f3124246a77036f843dee2d83ad28084234ebc (diff) | |
parent | c32a3ea0d30336771bab460ecccb58c4614e6294 (diff) | |
download | scummvm-rg350-b0c9c9122fc678074aba30068e5b36d347208e65.tar.gz scummvm-rg350-b0c9c9122fc678074aba30068e5b36d347208e65.tar.bz2 scummvm-rg350-b0c9c9122fc678074aba30068e5b36d347208e65.zip |
Merge branch 'master' of github.com:scummvm/scummvm into soltys_wip2
Diffstat (limited to 'common')
-rw-r--r-- | common/archive.h | 2 | ||||
-rw-r--r-- | common/array.h | 7 | ||||
-rw-r--r-- | common/config-file.cpp | 6 | ||||
-rw-r--r-- | common/config-manager.cpp | 14 | ||||
-rw-r--r-- | common/config-manager.h | 2 | ||||
-rw-r--r-- | common/debug.cpp | 13 | ||||
-rw-r--r-- | common/error.cpp | 3 | ||||
-rw-r--r-- | common/error.h | 2 | ||||
-rw-r--r-- | common/forbidden.h | 7 | ||||
-rw-r--r-- | common/macresman.cpp | 30 | ||||
-rw-r--r-- | common/ptr.h | 2 | ||||
-rw-r--r-- | common/quicktime.cpp | 4 | ||||
-rw-r--r-- | common/scummsys.h | 13 | ||||
-rw-r--r-- | common/str.cpp | 26 | ||||
-rw-r--r-- | common/str.h | 13 | ||||
-rw-r--r-- | common/system.cpp | 74 | ||||
-rw-r--r-- | common/system.h | 114 | ||||
-rw-r--r-- | common/taskbar.h | 133 | ||||
-rw-r--r-- | common/textconsole.cpp | 9 | ||||
-rw-r--r-- | common/translation.cpp | 55 | ||||
-rw-r--r-- | common/util.h | 5 | ||||
-rw-r--r-- | common/winexe_ne.cpp | 2 | ||||
-rw-r--r-- | common/winexe_pe.h | 2 | ||||
-rw-r--r-- | common/xmlparser.cpp | 10 | ||||
-rw-r--r-- | common/xmlparser.h | 2 |
25 files changed, 413 insertions, 137 deletions
diff --git a/common/archive.h b/common/archive.h index 3c75970d60..8400c56d69 100644 --- a/common/archive.h +++ b/common/archive.h @@ -143,7 +143,7 @@ class SearchSet : public Archive { ArchiveNodeList::iterator find(const String &name); ArchiveNodeList::const_iterator find(const String &name) const; - // Add an archive keeping the list sorted by ascending priorities. + // Add an archive keeping the list sorted by descending priority. void insert(const Node& node); public: diff --git a/common/array.h b/common/array.h index 7ab4a1b042..e5434091fb 100644 --- a/common/array.h +++ b/common/array.h @@ -252,6 +252,13 @@ public: _size = newSize; } + void assign(const_iterator first, const_iterator last) { + resize(distance(first, last)); // FIXME: ineffective? + T *dst = _storage; + while (first != last) + *dst++ = *first++; + } + protected: static uint roundUpCapacity(uint capacity) { // Round up capacity to the next power of 2; diff --git a/common/config-file.cpp b/common/config-file.cpp index 55941131ac..ea3feff8ae 100644 --- a/common/config-file.cpp +++ b/common/config-file.cpp @@ -38,7 +38,7 @@ namespace Common { */ bool ConfigFile::isValidName(const Common::String &name) { const char *p = name.c_str(); - while (*p && (isalnum(*p) || *p == '-' || *p == '_' || *p == '.')) + while (*p && (isalnum(static_cast<unsigned char>(*p)) || *p == '-' || *p == '_' || *p == '.')) p++; return *p == 0; } @@ -116,7 +116,7 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) { // is, verify that it only consists of alphanumerics, // periods, dashes and underscores). Mohawk Living Books games // can have periods in their section names. - while (*p && (isalnum(*p) || *p == '-' || *p == '_' || *p == '.')) + while (*p && (isalnum(static_cast<unsigned char>(*p)) || *p == '-' || *p == '_' || *p == '.')) p++; if (*p == '\0') @@ -139,7 +139,7 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) { // Skip leading whitespaces const char *t = line.c_str(); - while (isspace(*t)) + while (isspace(static_cast<unsigned char>(*t))) t++; // Skip empty lines / lines with only whitespace diff --git a/common/config-manager.cpp b/common/config-manager.cpp index 03fcb20abf..a9d8c89035 100644 --- a/common/config-manager.cpp +++ b/common/config-manager.cpp @@ -31,7 +31,7 @@ DECLARE_SINGLETON(Common::ConfigManager); static bool isValidDomainName(const Common::String &domName) { const char *p = domName.c_str(); - while (*p && (isalnum(*p) || *p == '-' || *p == '_')) + while (*p && (isalnum(static_cast<unsigned char>(*p)) || *p == '-' || *p == '_')) p++; return *p == 0; } @@ -187,7 +187,7 @@ void ConfigManager::loadFromStream(SeekableReadStream &stream) { // Get the domain name, and check whether it's valid (that // is, verify that it only consists of alphanumerics, // dashes and underscores). - while (*p && (isalnum(*p) || *p == '-' || *p == '_')) + while (*p && (isalnum(static_cast<unsigned char>(*p)) || *p == '-' || *p == '_')) p++; if (*p == '\0') @@ -205,7 +205,7 @@ void ConfigManager::loadFromStream(SeekableReadStream &stream) { // Skip leading whitespaces const char *t = line.c_str(); - while (isspace(*t)) + while (isspace(static_cast<unsigned char>(*t))) t++; // Skip empty lines / lines with only whitespace @@ -491,11 +491,9 @@ int ConfigManager::getInt(const String &key, const String &domName) const { bool ConfigManager::getBool(const String &key, const String &domName) const { String value(get(key, domName)); - - if ((value == "true") || (value == "yes") || (value == "1")) - return true; - if ((value == "false") || (value == "no") || (value == "0")) - return false; + bool val; + if (Common::parseBool(value, val)) + return val; error("ConfigManager::getBool(%s,%s): '%s' is not a valid bool", key.c_str(), domName.c_str(), value.c_str()); diff --git a/common/config-manager.h b/common/config-manager.h index 6f3f554459..78a62b9808 100644 --- a/common/config-manager.h +++ b/common/config-manager.h @@ -147,7 +147,7 @@ public: static void defragment(); // move in memory to reduce fragmentation void copyFrom(ConfigManager &source); - + private: friend class Singleton<SingletonBaseType>; ConfigManager(); diff --git a/common/debug.cpp b/common/debug.cpp index dbbb204deb..0dae344bb2 100644 --- a/common/debug.cpp +++ b/common/debug.cpp @@ -107,18 +107,13 @@ bool DebugManager::isDebugChannelEnabled(uint32 channel) { #ifndef DISABLE_TEXT_CONSOLE static void debugHelper(const char *s, va_list va, bool caret = true) { - char buf[STRINGBUFLEN]; + Common::String buf = Common::String::vformat(s, va); - vsnprintf(buf, STRINGBUFLEN, s, va); - buf[STRINGBUFLEN-1] = '\0'; - - if (caret) { - buf[STRINGBUFLEN-2] = '\0'; - strcat(buf, "\n"); - } + if (caret) + buf += '\n'; if (g_system) - g_system->logMessage(LogMessageType::kDebug, buf); + g_system->logMessage(LogMessageType::kDebug, buf.c_str()); // TODO: Think of a good fallback in case we do not have // any OSystem yet. } diff --git a/common/error.cpp b/common/error.cpp index a6c52a0ce9..78178f8e27 100644 --- a/common/error.cpp +++ b/common/error.cpp @@ -67,6 +67,9 @@ static String errorToString(ErrorCode errorCode) { case kEnginePluginNotSupportSaves: return _s("Engine plugin does not support save states"); + case kUserCanceled: + return _s("User canceled"); + case kUnknownError: default: return _s("Unknown error"); diff --git a/common/error.h b/common/error.h index 23c12b67e4..7043862eea 100644 --- a/common/error.h +++ b/common/error.h @@ -62,6 +62,8 @@ enum ErrorCode { kEnginePluginNotFound, ///< Failed to find plugin to handle target kEnginePluginNotSupportSaves, ///< Failed if plugin does not support listing save states + kUserCanceled, ///< User has canceled the launching of the game + kUnknownError ///< Catch-all error, used if no other error code matches }; diff --git a/common/forbidden.h b/common/forbidden.h index 9cba19cf5e..95c1a47d65 100644 --- a/common/forbidden.h +++ b/common/forbidden.h @@ -29,7 +29,7 @@ * infrastructure code do not make use of certain "forbidden" APIs, such * as fopen(), setjmp(), etc. * This is achieved by re-#defining various symbols to a "garbage" - * string which then trigers a compiler error. + * string which then triggers a compiler error. * * Backend files may #define FORBIDDEN_SYMBOL_ALLOW_ALL if they * have to access functions like fopen, fread etc. @@ -203,6 +203,11 @@ #define exit(a) FORBIDDEN_SYMBOL_REPLACEMENT #endif +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_abort +#undef abort +#define abort() FORBIDDEN_SYMBOL_REPLACEMENT +#endif + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_getenv #undef getenv #define getenv(a) FORBIDDEN_SYMBOL_REPLACEMENT diff --git a/common/macresman.cpp b/common/macresman.cpp index 6cbc08da19..c1cab8b96a 100644 --- a/common/macresman.cpp +++ b/common/macresman.cpp @@ -107,14 +107,17 @@ bool MacResManager::open(String filename) { #ifdef MACOSX // Check the actual fork on a Mac computer String fullPath = ConfMan.get("path") + "/" + filename + "/..namedfork/rsrc"; - SeekableReadStream *macResForkRawStream = FSNode(fullPath).createReadStream();; + FSNode resFsNode = FSNode(fullPath); + if (resFsNode.exists()) { + SeekableReadStream *macResForkRawStream = resFsNode.createReadStream();; - if (macResForkRawStream && loadFromRawFork(*macResForkRawStream)) { - _baseFileName = filename; - return true; - } + if (macResForkRawStream && loadFromRawFork(*macResForkRawStream)) { + _baseFileName = filename; + return true; + } - delete macResForkRawStream; + delete macResForkRawStream; + } #endif File *file = new File(); @@ -167,14 +170,17 @@ bool MacResManager::open(FSNode path, String filename) { #ifdef MACOSX // Check the actual fork on a Mac computer String fullPath = path.getPath() + "/" + filename + "/..namedfork/rsrc"; - SeekableReadStream *macResForkRawStream = FSNode(fullPath).createReadStream(); + FSNode resFsNode = FSNode(fullPath); + if (resFsNode.exists()) { + SeekableReadStream *macResForkRawStream = resFsNode.createReadStream();; - if (macResForkRawStream && loadFromRawFork(*macResForkRawStream)) { - _baseFileName = filename; - return true; - } + if (macResForkRawStream && loadFromRawFork(*macResForkRawStream)) { + _baseFileName = filename; + return true; + } - delete macResForkRawStream; + delete macResForkRawStream; + } #endif // First, let's try to see if the Mac converted name exists diff --git a/common/ptr.h b/common/ptr.h index e0d026f964..fc272d3d41 100644 --- a/common/ptr.h +++ b/common/ptr.h @@ -240,7 +240,7 @@ public: operator bool() const { return _pointer != 0; } ~ScopedPtr() { - delete _pointer; + delete _pointer; } /** diff --git a/common/quicktime.cpp b/common/quicktime.cpp index 57534b301a..ee49b092a4 100644 --- a/common/quicktime.cpp +++ b/common/quicktime.cpp @@ -728,7 +728,7 @@ int QuickTimeParser::readESDS(Atom atom) { byte tag; int length; - + readMP4Desc(_fd, tag, length); _fd->readUint16BE(); // id if (tag == kMP4ESDescTag) @@ -736,7 +736,7 @@ int QuickTimeParser::readESDS(Atom atom) { // Check if we've got the Config MPEG-4 header readMP4Desc(_fd, tag, length); - if (tag != kMP4DecConfigDescTag) + if (tag != kMP4DecConfigDescTag) return 0; track->objectTypeMP4 = _fd->readByte(); diff --git a/common/scummsys.h b/common/scummsys.h index a425befecf..9d4b6a9677 100644 --- a/common/scummsys.h +++ b/common/scummsys.h @@ -302,6 +302,19 @@ #define MAXPATHLEN 256 #endif +#ifndef scumm_va_copy + #if defined(va_copy) + #define scumm_va_copy va_copy + #elif defined(__va_copy) + #define scumm_va_copy __va_copy + #elif defined(_MSC_VER) + #define scumm_va_copy(dst, src) ((dst) = (src)) + #else + #error scumm_va_copy undefined for this port + #endif +#endif + + // // Typedef our system types unless they have already been defined by config.h, diff --git a/common/str.cpp b/common/str.cpp index 223188bdd6..32f4b44e79 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -25,8 +25,6 @@ #include "common/str.h" #include "common/util.h" -#include <stdarg.h> - namespace Common { MemoryPool *g_refCountPool = 0; // FIXME: This is never freed right now @@ -407,7 +405,7 @@ void String::trim() { makeUnique(); // Trim trailing whitespace - while (_size >= 1 && isspace(_str[_size - 1])) + while (_size >= 1 && isspace(static_cast<unsigned char>(_str[_size - 1]))) --_size; _str[_size] = 0; @@ -429,10 +427,22 @@ uint String::hash() const { // static String String::format(const char *fmt, ...) { String output; - assert(output.isStorageIntern()); va_list va; va_start(va, fmt); + output = String::vformat(fmt, va); + va_end(va); + + return output; +} + +// static +String String::vformat(const char *fmt, va_list args) { + String output; + assert(output.isStorageIntern()); + + va_list va; + scumm_va_copy(va, args); int len = vsnprintf(output._str, _builtinCapacity, fmt, va); va_end(va); @@ -457,7 +467,7 @@ String String::format(const char *fmt, ...) { assert(!output.isStorageIntern()); size = output._extern._capacity; - va_start(va, fmt); + scumm_va_copy(va, args); len = vsnprintf(output._str, size, fmt, va); va_end(va); } while (len == -1 || len >= size - 1); @@ -468,7 +478,7 @@ String String::format(const char *fmt, ...) { } else { // vsnprintf didn't have enough space, so grow buffer output.ensureCapacity(len, false); - va_start(va, fmt); + scumm_va_copy(va, args); int len2 = vsnprintf(output._str, len+1, fmt, va); va_end(va); assert(len == len2); @@ -596,14 +606,14 @@ String operator+(const String &x, char y) { } char *ltrim(char *t) { - while (isspace(*t)) + while (isspace(static_cast<unsigned char>(*t))) t++; return t; } char *rtrim(char *t) { int l = strlen(t) - 1; - while (l >= 0 && isspace(t[l])) + while (l >= 0 && isspace(static_cast<unsigned char>(t[l]))) t[l--] = 0; return t; } diff --git a/common/str.h b/common/str.h index 7b97dfe945..8e07b6233d 100644 --- a/common/str.h +++ b/common/str.h @@ -24,6 +24,8 @@ #include "common/scummsys.h" +#include <stdarg.h> + namespace Common { /** @@ -213,10 +215,19 @@ public: uint hash() const; /** - * Printf-like function. Returns a formatted String. + * Print formatted data into a String object. Similar to sprintf, + * except that it stores the result in (variably sized) String + * instead of a fixed size buffer. */ static Common::String format(const char *fmt, ...) GCC_PRINTF(1,2); + /** + * Print formatted data into a String object. Similar to vsprintf, + * except that it stores the result in (variably sized) String + * instead of a fixed size buffer. + */ + static Common::String vformat(const char *fmt, va_list args); + public: typedef char * iterator; typedef const char * const_iterator; diff --git a/common/system.cpp b/common/system.cpp index cd6ee46335..8d5bfd39cd 100644 --- a/common/system.cpp +++ b/common/system.cpp @@ -21,25 +21,30 @@ */ #define FORBIDDEN_SYMBOL_EXCEPTION_exit -#define FORBIDDEN_SYMBOL_EXCEPTION_FILE -#define FORBIDDEN_SYMBOL_EXCEPTION_fputs -#define FORBIDDEN_SYMBOL_EXCEPTION_fflush -#define FORBIDDEN_SYMBOL_EXCEPTION_stdout -#define FORBIDDEN_SYMBOL_EXCEPTION_stderr #include "common/system.h" #include "common/events.h" #include "common/fs.h" +#include "common/savefile.h" #include "common/str.h" +#include "common/taskbar.h" #include "common/textconsole.h" #include "backends/audiocd/default/default-audiocd.h" +#include "backends/fs/fs-factory.h" +#include "backends/timer/default/default-timer.h" OSystem *g_system = 0; OSystem::OSystem() { _audiocdManager = 0; _eventManager = 0; + _timerManager = 0; + _savefileManager = 0; +#if defined(USE_TASKBAR) + _taskbarManager = 0; +#endif + _fsFactory = 0; } OSystem::~OSystem() { @@ -48,20 +53,42 @@ OSystem::~OSystem() { delete _eventManager; _eventManager = 0; + + delete _timerManager; + _timerManager = 0; + +#if defined(USE_TASKBAR) + delete _taskbarManager; + _taskbarManager = 0; +#endif + + delete _savefileManager; + _savefileManager = 0; + + delete _fsFactory; + _fsFactory = 0; } void OSystem::initBackend() { - // Init AudioCD manager -#ifndef DISABLE_DEFAULT_AUDIOCD_MANAGER - if (!_audiocdManager) - _audiocdManager = new DefaultAudioCDManager(); -#endif + // Verify all managers has been set if (!_audiocdManager) - error("Backend failed to instantiate AudioCD manager"); - - // Verify Event manager has been set + error("Backend failed to instantiate audio CD manager"); if (!_eventManager) - error("Backend failed to instantiate Event manager"); + error("Backend failed to instantiate event manager"); + if (!_timerManager) + error("Backend failed to instantiate timer manager"); + + // TODO: We currently don't check _savefileManager, because at least + // on the Nintendo DS, it is possible that none is set. That should + // probably be treated as "saving is not possible". Or else the NDS + // port needs to be changed to always set a _savefileManager +// if (!_savefileManager) +// error("Backend failed to instantiate savefile manager"); + + // TODO: We currently don't check _fsFactory because not all ports + // set it. +// if (!_fsFactory) +// error("Backend failed to instantiate fs factory"); } bool OSystem::setGraphicsMode(const char *name) { @@ -90,6 +117,11 @@ void OSystem::fatalError() { exit(1); } +FilesystemFactory *OSystem::getFilesystemFactory() { + assert(_fsFactory); + return _fsFactory; +} + Common::SeekableReadStream *OSystem::createConfigReadStream() { Common::FSNode file(getDefaultConfigFileName()); return file.createReadStream(); @@ -108,20 +140,6 @@ Common::String OSystem::getDefaultConfigFileName() { return "scummvm.ini"; } -void OSystem::logMessage(LogMessageType::Type type, const char *message) { -#if !defined(__PLAYSTATION2__) && !defined(__DS__) - FILE *output = 0; - - if (type == LogMessageType::kInfo || type == LogMessageType::kDebug) - output = stdout; - else - output = stderr; - - fputs(message, output); - fflush(output); -#endif -} - Common::String OSystem::getSystemLanguage() const { return "en_US"; } diff --git a/common/system.h b/common/system.h index 780e5fcc7d..15fbe386b1 100644 --- a/common/system.h +++ b/common/system.h @@ -42,6 +42,9 @@ struct Rect; class SaveFileManager; class SearchSet; class String; +#if defined(USE_TASKBAR) +class TaskbarManager; +#endif class TimerManager; class SeekableReadStream; class WriteStream; @@ -98,36 +101,79 @@ protected: protected: /** - * For backend authors only, this pointer may be set by OSystem - * subclasses to an AudioCDManager instance. This is only useful - * if your backend does not want to use the DefaultAudioCDManager. + * @name Module slots + * + * For backend authors only, the following pointers (= "slots) to various + * subsystem managers / factories / etc. can and should be set to + * a suitable instance of the respective type. * - * This instance is returned by OSystem::getAudioCDManager(), - * and it is deleted by the OSystem destructor. + * For some of the slots, a default instance is set if your backend + * does not do so. For details, please look at the documentation of + * each slot. * - * A backend may set this pointer in its initBackend() method, - * its constructor or somewhere in between; but it must - * set it no later than in its initBackend() implementation, because - * OSystem::initBackend() will by default create a DefaultAudioCDManager - * instance if _audiocdManager has not yet been set. + * A backend may setup slot values in its initBackend() method, + * its constructor or somewhere in between. But it must a slot's value + * no later than in its initBackend() implementation, because + * OSystem::initBackend() will create any default instances if + * none has been set yet (and for other slots, will verify that + * one has been set; if not, an error may be generated). */ - AudioCDManager *_audiocdManager; + //@{ /** - * For backend authors only, this pointer may be set by OSystem - * subclasses to an EventManager instance. This is only useful - * if your backend does not want to use the DefaultEventManager. + * No default value is provided for _audiocdManager by OSystem. + * However, BaseBackend::initBackend() does set a default value + * if none has been set before. * - * This instance is returned by OSystem::getEventManager(), - * and it is deleted by the OSystem destructor. + * @note _audiocdManager is deleted by the OSystem destructor. + */ + AudioCDManager *_audiocdManager; + + /** + * No default value is provided for _eventManager by OSystem. + * However, BaseBackend::initBackend() does set a default value + * if none has been set before. * - * A backend may set this pointer in its initBackend() method, - * its constructor or somewhere in between; but it must - * set it no later than in its initBackend() implementation, because - * OSystem::initBackend() will by default create a DefaultEventManager - * instance if _eventManager has not yet been set. + * @note _eventManager is deleted by the OSystem destructor. */ Common::EventManager *_eventManager; + + /** + * No default value is provided for _timerManager by OSystem. + * + * @note _timerManager is deleted by the OSystem destructor. + */ + Common::TimerManager *_timerManager; + + /** + * No default value is provided for _savefileManager by OSystem. + * + * @note _savefileManager is deleted by the OSystem destructor. + */ + Common::SaveFileManager *_savefileManager; + +#if defined(USE_TASKBAR) + /** + * No default value is provided for _savefileManager by OSystem. + * + * @note _savefileManager is deleted by the OSystem destructor. + */ + Common::TaskbarManager *_taskbarManager; +#endif + + /** + * No default value is provided for _fsFactory by OSystem. + * + * Note that _fsFactory is typically required very early on, + * so it usually should be set in the backends constructor or shortly + * thereafter, and before initBackend() is called. + * + * @note _fsFactory is deleted by the OSystem destructor. + */ + FilesystemFactory *_fsFactory; + + //@} + public: /** @@ -423,7 +469,7 @@ public: * reset the scale to x1 so the screen will not be too big when starting * the game. */ - virtual void resetGraphicsScale() = 0; + virtual void resetGraphicsScale() {} #ifdef USE_RGB_COLOR /** @@ -857,7 +903,9 @@ public: * Return the timer manager singleton. For more information, refer * to the TimerManager documentation. */ - virtual Common::TimerManager *getTimerManager() = 0; + inline Common::TimerManager *getTimerManager() { + return _timerManager; + } /** * Return the event manager singleton. For more information, refer @@ -1007,14 +1055,28 @@ public: * and other modifiable persistent game data. For more information, * refer to the SaveFileManager documentation. */ - virtual Common::SaveFileManager *getSavefileManager() = 0; + inline Common::SaveFileManager *getSavefileManager() { + return _savefileManager; + } + +#if defined(USE_TASKBAR) + /** + * Returns the TaskbarManager, used to handle progress bars, + * icon overlay, tasks and recent items list on the taskbar. + * + * @return the TaskbarManager for the current architecture + */ + virtual Common::TaskbarManager *getTaskbarManager() { + return _taskbarManager; + } +#endif /** * Returns the FilesystemFactory object, depending on the current architecture. * * @return the FSNode factory for the current architecture */ - virtual FilesystemFactory *getFilesystemFactory() = 0; + virtual FilesystemFactory *getFilesystemFactory(); /** * Add system specific Common::Archive objects to the given SearchSet. @@ -1063,7 +1125,7 @@ public: * @param type the type of the message * @param message the message itself */ - virtual void logMessage(LogMessageType::Type type, const char *message); + virtual void logMessage(LogMessageType::Type type, const char *message) = 0; /** * Open the log file in a way that allows the user to review it, diff --git a/common/taskbar.h b/common/taskbar.h new file mode 100644 index 0000000000..023227e5e0 --- /dev/null +++ b/common/taskbar.h @@ -0,0 +1,133 @@ +/* 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. + * + * $URL$ + * $Id$ + */ + +#ifndef COMMON_TASKBAR_MANAGER_H +#define COMMON_TASKBAR_MANAGER_H + +#include "common/scummsys.h" +#include "common/str.h" + +#if defined(USE_TASKBAR) + +namespace Common { + +/** + * The TaskbarManager allows interaction with the ScummVM application icon: + * - in the taskbar on Windows 7 and later + * - in the launcher for Unity + * - in the dock on MacOSX + * - ... + * + * This allows GUI code and engines to display a progress bar, an overlay icon and/or count + * associated with the ScummVM icon as well as add the started engine to the recent items + * list (so that the user can start the engine directly in one click). + * + * Examples of use: + * - Track search progress and found engines when running the Mass Add dialog + * - Add an entry to the recent items when starting an engine + * - Show the current running engine icon as an overlay + * + * @note functionality will vary between supported platforms (due to API limitations) + * and some of the methods will just be no-ops or approximate the functionality + * as best as possible + */ +class TaskbarManager { +public: + /** + * Values representing the taskbar progress state + */ + enum TaskbarProgressState { + kTaskbarNoProgress = 0, + kTaskbarIndeterminate = 1, + kTaskbarNormal = 2, + kTaskbarError = 4, + kTaskbarPaused = 8 + }; + + TaskbarManager() {} + virtual ~TaskbarManager() {} + + /** + * Sets an overlay icon on the taskbar icon + * + * When an empty name is given, no icon is shown + * and the current overlay icon (if any) is removed + * + * @param name Path to the icon + * @param description The description + * + * @note on Windows, the icon should be an ICO file + */ + virtual void setOverlayIcon(const String &name, const String &description) {} + + /** + * Sets a progress value on the taskbar icon + * + * @param completed The current progress value. + * @param total The maximum progress value. + */ + virtual void setProgressValue(int completed, int total) {} + + /** + * Sets the progress state on the taskbar icon + * + * State can be any of the following: + * - NoProgress: disable display of progress state + * - Indeterminate + * - Normal + * - Error + * - Paused + * + * @param state The progress state + */ + virtual void setProgressState(TaskbarProgressState state) {} + + /** + * Sets the count number associated with the icon as an overlay + * + * @param count The count + * + * @note Setting a count of 0 will hide the count + */ + virtual void setCount(int count) {} + + /** + * Adds an engine to the recent items list + * + * Path is automatically set to the current executable path, + * an icon name is generated (with fallback to default icon) + * and the command line is set to start the engine on click. + * + * @param name The target name. + * @param description The description. + */ + virtual void addRecent(const String &name, const String &description) {} + +}; + +} // End of namespace Common + +#endif + +#endif // COMMON_TASKBAR_MANAGER_H diff --git a/common/textconsole.cpp b/common/textconsole.cpp index f2325ac9ad..ffa42e63a0 100644 --- a/common/textconsole.cpp +++ b/common/textconsole.cpp @@ -46,14 +46,14 @@ void setErrorHandler(ErrorHandler handler) { #ifndef DISABLE_TEXT_CONSOLE void warning(const char *s, ...) { - char buf[STRINGBUFLEN]; + Common::String output; va_list va; va_start(va, s); - vsnprintf(buf, STRINGBUFLEN, s, va); + output = Common::String::vformat(s, va); va_end(va); - Common::String output = Common::String::format("WARNING: %s!\n", buf); + output = "WARNING: " + output + "!\n"; if (g_system) g_system->logMessage(LogMessageType::kWarning, output.c_str()); @@ -64,6 +64,9 @@ void warning(const char *s, ...) { #endif void NORETURN_PRE error(const char *s, ...) { + // We don't use String::vformat here, as that require + // using the heap, and that might be impossible at this + // point, e.g. if the error was an "out-of-memory" error. char buf_input[STRINGBUFLEN]; char buf_output[STRINGBUFLEN]; va_list va; diff --git a/common/translation.cpp b/common/translation.cpp index dc71ddc52f..e456f733fd 100644 --- a/common/translation.cpp +++ b/common/translation.cpp @@ -223,13 +223,21 @@ String TranslationManager::getLangById(int id) const { } bool TranslationManager::openTranslationsFile(File& inFile) { - // First try to open it directly (i.e. using the SearchMan). - if (inFile.open("translations.dat")) + // First look in the Themepath if we can find the file. + if (ConfMan.hasKey("themepath") && openTranslationsFile(FSNode(ConfMan.get("themepath")), inFile)) return true; - // Then look in the Themepath if we can find the file. - if (ConfMan.hasKey("themepath")) - return openTranslationsFile(FSNode(ConfMan.get("themepath")), inFile); + // Then try to open it using the SearchMan. + ArchiveMemberList fileList; + SearchMan.listMatchingMembers(fileList, "translations.dat"); + for (ArchiveMemberList::iterator it = fileList.begin(); it != fileList.end(); ++it) { + SeekableReadStream *stream = it->get()->createReadStream(); + if (stream && inFile.open(stream, it->get()->getName())) { + if (checkHeader(inFile)) + return true; + inFile.close(); + } + } return false; } @@ -243,8 +251,11 @@ bool TranslationManager::openTranslationsFile(const FSNode &node, File& inFile, // necessary to make them here. But it avoid printing warnings. FSNode fileNode = node.getChild("translations.dat"); if (fileNode.exists() && fileNode.isReadable() && !fileNode.isDirectory()) { - if (inFile.open(fileNode)) - return true; + if (inFile.open(fileNode)) { + if (checkHeader(inFile)) + return true; + inFile.close(); + } } // Check if we exceeded the given recursion depth @@ -268,13 +279,10 @@ bool TranslationManager::openTranslationsFile(const FSNode &node, File& inFile, void TranslationManager::loadTranslationsInfoDat() { File in; if (!openTranslationsFile(in)) { - warning("You are missing the 'translations.dat' file. GUI translation will not be available"); + warning("You are missing a valid 'translations.dat' file. GUI translation will not be available"); return; } - if (!checkHeader(in)) - return; - char buf[256]; int len; @@ -302,8 +310,13 @@ void TranslationManager::loadTranslationsInfoDat() { _messageIds.resize(numMessages); for (int i = 0; i < numMessages; ++i) { len = in.readUint16BE(); - in.read(buf, len); - _messageIds[i] = String(buf, len - 1); + String msg; + while (len > 0) { + in.read(buf, len > 256 ? 256 : len); + msg += String(buf, len > 256 ? 256 : len - 1); + len -= 256; + } + _messageIds[i] = msg; } } @@ -321,9 +334,6 @@ void TranslationManager::loadLanguageDat(int index) { if (!openTranslationsFile(in)) return; - if (!checkHeader(in)) - return; - char buf[1024]; int len; @@ -357,8 +367,13 @@ void TranslationManager::loadLanguageDat(int index) { for (int i = 0; i < nbMessages; ++i) { _currentTranslationMessages[i].msgid = in.readUint16BE(); len = in.readUint16BE(); - in.read(buf, len); - _currentTranslationMessages[i].msgstr = String(buf, len - 1); + String msg; + while (len > 0) { + in.read(buf, len > 256 ? 256 : len); + msg += String(buf, len > 256 ? 256 : len - 1); + len -= 256; + } + _currentTranslationMessages[i].msgstr = msg; len = in.readUint16BE(); if (len > 0) { in.read(buf, len); @@ -376,7 +391,7 @@ bool TranslationManager::checkHeader(File &in) { // Check header if (strcmp(buf, "TRANSLATIONS")) { - warning("Your 'translations.dat' file is corrupt. GUI translation will not be available"); + warning("File '%s' is not a valid translations data file. Skipping this file", in.getName()); return false; } @@ -384,7 +399,7 @@ bool TranslationManager::checkHeader(File &in) { ver = in.readByte(); if (ver != TRANSLATIONS_DAT_VER) { - warning("Your 'translations.dat' file has a mismatching version, expected was %d but you got %d. GUI translation will not be available", TRANSLATIONS_DAT_VER, ver); + warning("File '%s' has a mismatching version, expected was %d but you got %d. Skipping this file", in.getName(), TRANSLATIONS_DAT_VER, ver); return false; } diff --git a/common/util.h b/common/util.h index 5837c8beab..cd890c970f 100644 --- a/common/util.h +++ b/common/util.h @@ -208,11 +208,6 @@ enum RenderMode { kRenderAmiga = 5 }; -enum HerculesDimensions { - kHercW = 720, - kHercH = 350 -}; - struct RenderModeDescription { const char *code; const char *description; diff --git a/common/winexe_ne.cpp b/common/winexe_ne.cpp index 80266ba87e..8690f6795b 100644 --- a/common/winexe_ne.cpp +++ b/common/winexe_ne.cpp @@ -136,7 +136,7 @@ bool NEResources::loadFromCompressedEXE(const String &fileName) { matchPos &= 0xFFF; } } - + } } diff --git a/common/winexe_pe.h b/common/winexe_pe.h index cc1d0c9770..b38f2f78f5 100644 --- a/common/winexe_pe.h +++ b/common/winexe_pe.h @@ -107,7 +107,7 @@ private: uint32 offset; uint32 size; }; - + typedef HashMap<WinResourceID, Resource, WinResourceID_Hash, WinResourceID_EqualTo> LangMap; typedef HashMap<WinResourceID, LangMap, WinResourceID_Hash, WinResourceID_EqualTo> NameMap; typedef HashMap<WinResourceID, NameMap, WinResourceID_Hash, WinResourceID_EqualTo> TypeMap; diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp index 5217c4e82c..623619914a 100644 --- a/common/xmlparser.cpp +++ b/common/xmlparser.cpp @@ -263,7 +263,7 @@ bool XMLParser::vparseIntegerKey(const char *key, int count, va_list args) { int *num_ptr; while (count--) { - while (isspace(*key)) + while (isspace(static_cast<unsigned char>(*key))) key++; num_ptr = va_arg(args, int*); @@ -271,7 +271,7 @@ bool XMLParser::vparseIntegerKey(const char *key, int count, va_list args) { key = parseEnd; - while (isspace(*key)) + while (isspace(static_cast<unsigned char>(*key))) key++; if (count && *key++ != ',') @@ -463,10 +463,10 @@ bool XMLParser::parse() { } bool XMLParser::skipSpaces() { - if (!isspace(_char)) + if (!isspace(static_cast<unsigned char>(_char))) return false; - while (_char && isspace(_char)) + while (_char && isspace(static_cast<unsigned char>(_char))) _char = _stream->readByte(); return true; @@ -516,7 +516,7 @@ bool XMLParser::parseToken() { _char = _stream->readByte(); } - return isspace(_char) != 0 || _char == '>' || _char == '=' || _char == '/'; + return isspace(static_cast<unsigned char>(_char)) != 0 || _char == '>' || _char == '=' || _char == '/'; } } // End of namespace Common diff --git a/common/xmlparser.h b/common/xmlparser.h index 7923e43a37..40c779b87e 100644 --- a/common/xmlparser.h +++ b/common/xmlparser.h @@ -294,7 +294,7 @@ protected: * in their name. */ virtual inline bool isValidNameChar(char c) { - return isalnum(c) || c == '_'; + return isalnum(static_cast<unsigned char>(c)) || c == '_'; } /** |