2016-03-14 23:09:57 -04: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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-03-15 23:49:18 -04:00
|
|
|
#include "common/file.h"
|
2016-04-03 16:16:35 -04:00
|
|
|
#include "titanic/support/files_manager.h"
|
2016-03-14 23:09:57 -04:00
|
|
|
#include "titanic/game_manager.h"
|
|
|
|
|
|
|
|
namespace Titanic {
|
|
|
|
|
2016-05-09 21:03:21 -04:00
|
|
|
CFilesManager::CFilesManager() : _gameManager(nullptr), _assetsPath("Assets"),
|
|
|
|
_field0(0), _drive(-1), _field18(0), _field1C(0), _field3C(0) {
|
2016-05-15 18:44:47 -04:00
|
|
|
loadResourceIndex();
|
2016-04-03 15:51:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
CFilesManager::~CFilesManager() {
|
2016-05-15 18:44:47 -04:00
|
|
|
_datFile.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFilesManager::loadResourceIndex() {
|
|
|
|
if (!_datFile.open("titanic.dat"))
|
|
|
|
error("Could not find titanic.dat data file");
|
|
|
|
|
|
|
|
uint headerId = _datFile.readUint32BE();
|
|
|
|
uint version = _datFile.readUint16LE();
|
|
|
|
if (headerId != MKTAG('S', 'V', 'T', 'N') || version < 1)
|
|
|
|
error("Invalid data file");
|
|
|
|
|
|
|
|
// Read in entries
|
|
|
|
uint offset, size;
|
|
|
|
char c;
|
|
|
|
Common::String resourceName;
|
|
|
|
for (;;) {
|
|
|
|
offset = _datFile.readUint32LE();
|
|
|
|
size = _datFile.readUint32LE();
|
|
|
|
if (size == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
Common::String resName;
|
|
|
|
while ((c = _datFile.readByte()) != '\0')
|
|
|
|
resName += c;
|
|
|
|
|
|
|
|
_resources[resName] = ResourceEntry(offset, size);
|
|
|
|
}
|
2016-03-14 23:09:57 -04:00
|
|
|
}
|
|
|
|
|
2016-03-16 21:01:01 -04:00
|
|
|
bool CFilesManager::fileExists(const CString &name) {
|
|
|
|
Common::File f;
|
|
|
|
return f.exists(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CFilesManager::scanForFile(const CString &name) {
|
2016-03-14 23:09:57 -04:00
|
|
|
if (name.empty())
|
2016-03-16 21:01:01 -04:00
|
|
|
return false;
|
2016-03-14 23:09:57 -04:00
|
|
|
|
2016-03-16 21:01:01 -04:00
|
|
|
CString filename = name;
|
|
|
|
filename.toLowercase();
|
2016-03-14 23:09:57 -04:00
|
|
|
|
2016-03-16 21:01:01 -04:00
|
|
|
if (filename[0] == 'y' || filename[0] == 'z')
|
|
|
|
return true;
|
|
|
|
else if (filename[0] < 'a' || filename[0] > 'c')
|
|
|
|
return false;
|
2016-03-14 23:09:57 -04:00
|
|
|
|
2016-03-16 21:01:01 -04:00
|
|
|
CString fname = filename;
|
|
|
|
int idx = fname.indexOf('#');
|
2016-03-14 23:09:57 -04:00
|
|
|
if (idx >= 0) {
|
2016-03-16 21:01:01 -04:00
|
|
|
fname = fname.left(idx);
|
|
|
|
fname += ".st";
|
2016-03-14 23:09:57 -04:00
|
|
|
}
|
|
|
|
|
2016-07-18 21:47:19 -04:00
|
|
|
// Return true if the file exists
|
|
|
|
if (fileExists(fname))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Couldn't find file. Start by calling the game manager's viewChange
|
|
|
|
// method, which handles all active scene objects freeing their resources
|
2016-03-19 18:19:45 -04:00
|
|
|
if (_gameManager)
|
|
|
|
_gameManager->viewChange();
|
|
|
|
|
2016-07-18 21:47:19 -04:00
|
|
|
return false;
|
2016-03-14 23:09:57 -04:00
|
|
|
}
|
|
|
|
|
2016-03-20 00:01:40 -04:00
|
|
|
void CFilesManager::loadDrive() {
|
|
|
|
assert(_drive == -1);
|
|
|
|
resetView();
|
2016-03-18 21:34:04 -04:00
|
|
|
}
|
|
|
|
|
2016-03-19 18:19:45 -04:00
|
|
|
void CFilesManager::debug(CScreenManager *screenManager) {
|
|
|
|
warning("TODO: CFilesManager::debug");
|
|
|
|
}
|
|
|
|
|
2016-03-20 00:01:40 -04:00
|
|
|
void CFilesManager::resetView() {
|
|
|
|
if (_gameManager) {
|
2016-03-31 22:31:13 -04:00
|
|
|
_gameManager->_gameState.setMode(GSMODE_SELECTED);
|
2016-03-20 00:01:40 -04:00
|
|
|
_gameManager->initBounds();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-23 20:51:42 -04:00
|
|
|
void CFilesManager::fn4(const CString &name) {
|
|
|
|
warning("TODO: CFilesManager::fn4");
|
|
|
|
}
|
|
|
|
|
2016-05-04 20:30:52 -04:00
|
|
|
void CFilesManager::preload(const CString &name) {
|
|
|
|
// We don't currently do any preloading of resources
|
2016-03-22 07:44:45 -04:00
|
|
|
}
|
|
|
|
|
2016-05-15 18:44:47 -04:00
|
|
|
Common::SeekableReadStream *CFilesManager::getResource(const CString &str) {
|
|
|
|
ResourceEntry resEntry = _resources[str];
|
|
|
|
_datFile.seek(resEntry._offset);
|
|
|
|
|
|
|
|
return _datFile.readStream(resEntry._size);
|
2016-04-03 15:51:42 -04:00
|
|
|
}
|
|
|
|
|
2016-03-14 23:09:57 -04:00
|
|
|
} // End of namespace Titanic
|