1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "mm/shared/xeen/file.h"
#ifdef ENABLE_XEEN
#include "mm/xeen/files.h"
#include "mm/xeen/xeen.h"
#endif
namespace MM {
namespace Shared {
namespace Xeen {
File::File(const Common::Path &filename) {
File::open(filename);
}
File::File(const Common::Path &filename, Common::Archive &archive) {
File::open(filename, archive);
}
#ifdef ENABLE_XEEN
File::File(const Common::Path &filename, int ccMode) {
File::open(filename, ccMode);
}
#endif
bool File::open(const Common::Path &filename) {
#ifdef ENABLE_XEEN
MM::Xeen::XeenEngine *engine = dynamic_cast<MM::Xeen::XeenEngine *>(g_engine);
if (engine) {
MM::Xeen::FileManager &fm = *engine->_files;
if (!fm._currentSave || !Common::File::open(filename, *fm._currentSave)) {
if (!fm._currentArchive || !Common::File::open(filename, *fm._currentArchive)) {
// Could not find in current archive, so try intro.cc or in folder
if (!Common::File::open(filename))
error("Could not open file - %s", filename.toString(Common::Path::kNativeSeparator).c_str());
}
}
} else {
if (!Common::File::open(filename))
error("Could not open file - %s", filename.toString(Common::Path::kNativeSeparator).c_str());
}
#else
if (!Common::File::open(filename))
error("Could not open file - %s", filename.toString(Common::Path::kNativeSeparator).c_str());
#endif
return true;
}
bool File::open(const Common::Path &filename, Common::Archive &archive) {
if (!Common::File::open(filename, archive))
error("Could not open file - %s", filename.toString(Common::Path::kNativeSeparator).c_str());
return true;
}
#ifdef ENABLE_XEEN
bool File::open(const Common::Path &filename, int ccMode) {
MM::Xeen::XeenEngine *engine = dynamic_cast<MM::Xeen::XeenEngine *>(g_engine);
assert(engine);
MM::Xeen::FileManager &fm = *engine->_files;
int oldNum = fm._ccNum;
fm.setGameCc(ccMode);
if (File::exists(filename, *fm._currentArchive))
File::open(filename, *fm._currentArchive);
else
File::open(filename);
fm.setGameCc(oldNum);
return true;
}
void File::setCurrentArchive(int ccMode) {
MM::Xeen::XeenEngine *engine = dynamic_cast<MM::Xeen::XeenEngine *>(g_engine);
assert(engine);
MM::Xeen::FileManager &fm = *engine->_files;
switch (ccMode) {
case 0:
fm._currentArchive = fm._xeenCc;
fm._currentSave = fm._xeenSave;
break;
case 1:
fm._currentArchive = fm._darkCc;
fm._currentSave = fm._darkSave;
break;
case 2:
fm._currentArchive = fm._introCc;
fm._currentSave = nullptr;
break;
default:
break;
}
assert(fm._currentArchive);
}
#endif
Common::String File::readString() {
Common::String result;
char c;
while (pos() < size() && (c = (char)readByte()) != '\0')
result += c;
return result;
}
bool File::exists(const Common::Path &filename) {
#ifdef ENABLE_XEEN
MM::Xeen::XeenEngine *engine = dynamic_cast<MM::Xeen::XeenEngine *>(g_engine);
if (engine) {
MM::Xeen::FileManager &fm = *engine->_files;
if (!fm._currentSave || !fm._currentSave->hasFile(filename)) {
if (!fm._currentArchive->hasFile(filename)) {
// Could not find in current archive, so try intro.cc or in folder
return Common::File::exists(filename);
}
}
return true;
} else {
return Common::File::exists(filename);
}
#else
return Common::File::exists(filename);
#endif
}
#ifdef ENABLE_XEEN
bool File::exists(const Common::Path &filename, int ccMode) {
MM::Xeen::XeenEngine *engine = dynamic_cast<MM::Xeen::XeenEngine *>(g_engine);
assert(engine);
MM::Xeen::FileManager &fm = *engine->_files;
int oldNum = fm._ccNum;
fm.setGameCc(ccMode);
bool result = exists(filename);
fm.setGameCc(oldNum);
return result;
}
#endif
bool File::exists(const Common::Path &filename, Common::Archive &archive) {
return archive.hasFile(filename);
}
void File::syncBitFlags(Common::Serializer &s, bool *startP, bool *endP) {
byte data = 0;
int bitCounter = 0;
for (bool *p = startP; p < endP; ++p, bitCounter = (bitCounter + 1) % 8) {
if (bitCounter == 0) {
if (s.isLoading() || p != startP)
s.syncAsByte(data);
if (s.isSaving())
data = 0;
}
if (s.isLoading())
*p = ((data >> bitCounter) & 1) != 0;
else if (*p)
data |= 1 << bitCounter;
}
if (s.isSaving())
s.syncAsByte(data);
}
} // namespace Xeen
} // namespace Shared
} // namespace MM
|