2007-05-30 21:56:52 +00:00
|
|
|
/* 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.
|
2003-11-02 10:18:10 +00:00
|
|
|
*
|
2021-12-26 17:47:58 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2014-02-18 01:34:18 +00:00
|
|
|
*
|
2003-11-02 10:18:10 +00:00
|
|
|
* 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.
|
2014-02-18 01:34:18 +00:00
|
|
|
*
|
2003-11-02 10:18:10 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-12-26 17:47:58 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2003-11-02 10:18:10 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-06-06 13:39:05 +00:00
|
|
|
#define FORBIDDEN_SYMBOL_EXCEPTION_exit
|
2010-11-18 19:12:14 +00:00
|
|
|
|
2003-11-02 10:18:10 +00:00
|
|
|
#include "common/system.h"
|
2011-06-06 13:51:46 +00:00
|
|
|
#include "common/events.h"
|
2011-06-06 13:30:21 +00:00
|
|
|
#include "common/fs.h"
|
2023-02-24 20:08:59 +00:00
|
|
|
#include "common/file.h"
|
2011-06-08 09:44:08 +00:00
|
|
|
#include "common/savefile.h"
|
2011-06-06 13:51:46 +00:00
|
|
|
#include "common/str.h"
|
2011-06-16 15:24:38 +00:00
|
|
|
#include "common/taskbar.h"
|
2011-07-07 00:47:46 +00:00
|
|
|
#include "common/updates.h"
|
2018-11-19 14:57:50 +00:00
|
|
|
#include "common/dialogs.h"
|
2022-06-12 23:06:56 +00:00
|
|
|
#include "common/str-enc.h"
|
2011-06-06 13:02:33 +00:00
|
|
|
#include "common/textconsole.h"
|
2019-07-10 08:49:29 +00:00
|
|
|
#include "common/text-to-speech.h"
|
2011-06-06 13:02:33 +00:00
|
|
|
|
|
|
|
#include "backends/audiocd/default/default-audiocd.h"
|
2011-06-08 09:44:08 +00:00
|
|
|
#include "backends/fs/fs-factory.h"
|
2011-06-06 21:25:37 +00:00
|
|
|
#include "backends/timer/default/default-timer.h"
|
2023-07-08 03:00:12 +00:00
|
|
|
#include "backends/dlc/store.h"
|
2006-10-22 15:42:29 +00:00
|
|
|
|
2018-04-05 18:25:28 +00:00
|
|
|
OSystem *g_system = nullptr;
|
2003-11-02 10:18:10 +00:00
|
|
|
|
2007-03-17 00:07:34 +00:00
|
|
|
OSystem::OSystem() {
|
2018-04-05 18:25:28 +00:00
|
|
|
_audiocdManager = nullptr;
|
|
|
|
_eventManager = nullptr;
|
|
|
|
_timerManager = nullptr;
|
|
|
|
_savefileManager = nullptr;
|
2011-06-16 15:24:38 +00:00
|
|
|
#if defined(USE_TASKBAR)
|
2018-04-05 18:25:28 +00:00
|
|
|
_taskbarManager = nullptr;
|
2011-07-07 00:47:46 +00:00
|
|
|
#endif
|
|
|
|
#if defined(USE_UPDATES)
|
2018-04-05 18:25:28 +00:00
|
|
|
_updateManager = nullptr;
|
2018-11-19 14:57:50 +00:00
|
|
|
#endif
|
2019-07-10 08:49:29 +00:00
|
|
|
_textToSpeechManager = nullptr;
|
2018-11-19 14:57:50 +00:00
|
|
|
#if defined(USE_SYSDIALOGS)
|
|
|
|
_dialogManager = nullptr;
|
2011-06-16 15:24:38 +00:00
|
|
|
#endif
|
2018-04-05 18:25:28 +00:00
|
|
|
_fsFactory = nullptr;
|
2023-07-01 20:37:49 +00:00
|
|
|
_dlcStore = nullptr;
|
2018-07-06 23:58:52 +00:00
|
|
|
_backendInitialized = false;
|
2007-03-17 00:07:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OSystem::~OSystem() {
|
2011-06-06 13:02:33 +00:00
|
|
|
delete _audiocdManager;
|
2018-04-05 18:25:28 +00:00
|
|
|
_audiocdManager = nullptr;
|
2011-06-06 13:51:46 +00:00
|
|
|
|
|
|
|
delete _eventManager;
|
2018-04-05 18:25:28 +00:00
|
|
|
_eventManager = nullptr;
|
2011-06-06 21:25:37 +00:00
|
|
|
|
|
|
|
delete _timerManager;
|
2018-04-05 18:25:28 +00:00
|
|
|
_timerManager = nullptr;
|
2011-06-06 21:25:37 +00:00
|
|
|
|
2011-06-16 15:24:38 +00:00
|
|
|
#if defined(USE_TASKBAR)
|
|
|
|
delete _taskbarManager;
|
2018-04-05 18:25:28 +00:00
|
|
|
_taskbarManager = nullptr;
|
2011-06-16 15:24:38 +00:00
|
|
|
#endif
|
|
|
|
|
2011-07-07 00:47:46 +00:00
|
|
|
#if defined(USE_UPDATES)
|
|
|
|
delete _updateManager;
|
2018-04-05 18:25:28 +00:00
|
|
|
_updateManager = nullptr;
|
2011-07-07 00:47:46 +00:00
|
|
|
#endif
|
|
|
|
|
2019-07-10 08:49:29 +00:00
|
|
|
delete _textToSpeechManager;
|
2021-04-25 05:05:02 +00:00
|
|
|
_textToSpeechManager = nullptr;
|
2019-07-10 08:49:29 +00:00
|
|
|
|
2018-11-19 14:57:50 +00:00
|
|
|
#if defined(USE_SYSDIALOGS)
|
|
|
|
delete _dialogManager;
|
|
|
|
_dialogManager = nullptr;
|
|
|
|
#endif
|
|
|
|
|
2011-06-06 21:25:37 +00:00
|
|
|
delete _savefileManager;
|
2018-04-05 18:25:28 +00:00
|
|
|
_savefileManager = nullptr;
|
2011-06-06 21:25:37 +00:00
|
|
|
|
|
|
|
delete _fsFactory;
|
2018-04-05 18:25:28 +00:00
|
|
|
_fsFactory = nullptr;
|
2023-07-01 20:37:49 +00:00
|
|
|
|
|
|
|
delete _dlcStore;
|
|
|
|
_dlcStore = nullptr;
|
2011-06-06 13:02:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem::initBackend() {
|
2011-06-06 21:25:37 +00:00
|
|
|
// Verify all managers has been set
|
|
|
|
if (!_audiocdManager)
|
|
|
|
error("Backend failed to instantiate audio CD manager");
|
2011-06-06 13:51:46 +00:00
|
|
|
if (!_eventManager)
|
2011-06-06 21:25:37 +00:00
|
|
|
error("Backend failed to instantiate event manager");
|
2013-05-16 21:18:09 +00:00
|
|
|
if (!getTimerManager())
|
2011-06-06 21:25:37 +00:00
|
|
|
error("Backend failed to instantiate timer manager");
|
2011-06-07 11:06:21 +00:00
|
|
|
|
2020-06-01 21:47:20 +00:00
|
|
|
if (!_savefileManager)
|
|
|
|
error("Backend failed to instantiate savefile manager");
|
2011-06-07 11:06:21 +00:00
|
|
|
|
|
|
|
// TODO: We currently don't check _fsFactory because not all ports
|
|
|
|
// set it.
|
2011-06-06 21:25:37 +00:00
|
|
|
// if (!_fsFactory)
|
|
|
|
// error("Backend failed to instantiate fs factory");
|
2018-07-06 23:58:52 +00:00
|
|
|
|
|
|
|
_backendInitialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem::destroy() {
|
|
|
|
_backendInitialized = false;
|
2018-07-07 00:03:04 +00:00
|
|
|
Common::String::releaseMemoryPoolMutex();
|
2022-06-12 23:06:56 +00:00
|
|
|
Common::releaseCJKTables();
|
2018-07-06 23:58:52 +00:00
|
|
|
delete this;
|
2007-03-17 00:07:34 +00:00
|
|
|
}
|
|
|
|
|
2023-02-24 20:08:59 +00:00
|
|
|
void OSystem::updateStartSettings(const Common::String &executable, Common::String &command, Common::StringMap &settings, Common::StringArray& additionalArgs) {
|
|
|
|
// If a command was explicitly passed on the command line, do not override it
|
|
|
|
if (!command.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool autodetect = false;
|
|
|
|
|
|
|
|
// Check executable name
|
|
|
|
if (executable.equalsIgnoreCase("scummvm-auto")) {
|
|
|
|
warning("Will run in autodetection mode");
|
|
|
|
autodetect = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for the autorun file
|
|
|
|
if (Common::File::exists("scummvm-autorun")) {
|
|
|
|
// Okay, the file exists. We open it and if it is empty, then run in the autorun mode
|
|
|
|
// If the file is not empty, we read command line arguments from it, one per line
|
|
|
|
warning("Autorun file is detected");
|
|
|
|
|
|
|
|
Common::File autorun;
|
|
|
|
Common::String line;
|
|
|
|
Common::String res;
|
|
|
|
|
|
|
|
if (autorun.open("scummvm-autorun")) {
|
|
|
|
while (!autorun.eos()) {
|
|
|
|
line = autorun.readLine();
|
|
|
|
if (!line.empty() && line[0] != '#') {
|
|
|
|
additionalArgs.push_back(line);
|
|
|
|
res += Common::String::format("\"%s\" ", line.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!res.empty())
|
|
|
|
warning("Autorun command: %s", res.c_str());
|
|
|
|
else
|
|
|
|
warning("Empty autorun file");
|
|
|
|
|
|
|
|
autorun.close();
|
|
|
|
autodetect = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (autodetect && additionalArgs.empty()) {
|
|
|
|
warning("Running autodetection");
|
|
|
|
command = "auto-detect";
|
|
|
|
if (!settings.contains("path"))
|
|
|
|
settings["path"] = ".";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-24 22:39:42 +00:00
|
|
|
bool OSystem::setGraphicsMode(const char *name) {
|
|
|
|
if (!name)
|
|
|
|
return false;
|
|
|
|
|
2006-02-02 20:35:21 +00:00
|
|
|
// Special case for the 'default' filter
|
2004-02-24 22:39:42 +00:00
|
|
|
if (!scumm_stricmp(name, "normal") || !scumm_stricmp(name, "default")) {
|
2004-03-15 00:45:45 +00:00
|
|
|
return setGraphicsMode(getDefaultGraphicsMode());
|
2004-02-24 22:39:42 +00:00
|
|
|
}
|
|
|
|
|
2004-03-15 00:45:45 +00:00
|
|
|
const GraphicsMode *gm = getSupportedGraphicsModes();
|
|
|
|
|
2004-02-24 22:39:42 +00:00
|
|
|
while (gm->name) {
|
|
|
|
if (!scumm_stricmp(gm->name, name)) {
|
|
|
|
return setGraphicsMode(gm->id);
|
|
|
|
}
|
|
|
|
gm++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2003-11-02 10:18:10 +00:00
|
|
|
}
|
2010-11-18 19:12:14 +00:00
|
|
|
|
2018-07-01 18:24:25 +00:00
|
|
|
bool OSystem::setStretchMode(const char *name) {
|
|
|
|
if (!name)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Special case for the 'default' filter
|
|
|
|
if (!scumm_stricmp(name, "default")) {
|
|
|
|
return setStretchMode(getDefaultStretchMode());
|
|
|
|
}
|
|
|
|
|
|
|
|
const GraphicsMode *sm = getSupportedStretchModes();
|
|
|
|
|
|
|
|
while (sm->name) {
|
|
|
|
if (!scumm_stricmp(sm->name, name)) {
|
|
|
|
return setStretchMode(sm->id);
|
|
|
|
}
|
|
|
|
sm++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-11-18 19:12:14 +00:00
|
|
|
void OSystem::fatalError() {
|
|
|
|
quit();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2011-06-06 21:25:37 +00:00
|
|
|
FilesystemFactory *OSystem::getFilesystemFactory() {
|
|
|
|
assert(_fsFactory);
|
|
|
|
return _fsFactory;
|
|
|
|
}
|
|
|
|
|
2011-06-06 13:30:21 +00:00
|
|
|
Common::SeekableReadStream *OSystem::createConfigReadStream() {
|
|
|
|
Common::FSNode file(getDefaultConfigFileName());
|
|
|
|
return file.createReadStream();
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::WriteStream *OSystem::createConfigWriteStream() {
|
|
|
|
#ifdef __DC__
|
2018-04-05 18:25:28 +00:00
|
|
|
return nullptr;
|
2011-06-06 13:30:21 +00:00
|
|
|
#else
|
|
|
|
Common::FSNode file(getDefaultConfigFileName());
|
|
|
|
return file.createWriteStream();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-09-02 17:22:08 +00:00
|
|
|
Common::Path OSystem::getDefaultConfigFileName() {
|
2011-06-06 13:30:21 +00:00
|
|
|
return "scummvm.ini";
|
|
|
|
}
|
|
|
|
|
2010-11-28 02:12:33 +00:00
|
|
|
Common::String OSystem::getSystemLanguage() const {
|
|
|
|
return "en_US";
|
2010-11-25 18:40:56 +00:00
|
|
|
}
|
2013-05-16 21:18:09 +00:00
|
|
|
|
2019-06-20 20:14:04 +00:00
|
|
|
bool OSystem::isConnectionLimited() {
|
|
|
|
warning("OSystem::isConnectionLimited(): not limited by default");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-16 21:18:09 +00:00
|
|
|
Common::TimerManager *OSystem::getTimerManager() {
|
|
|
|
return _timerManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::SaveFileManager *OSystem::getSavefileManager() {
|
2013-07-06 04:31:28 +00:00
|
|
|
return _savefileManager;
|
2013-05-16 21:18:09 +00:00
|
|
|
}
|