[Scummvm-git-logs] scummvm master -> 301377a605db188901265e5424b54c9d2f95c85d
sev-
noreply at scummvm.org
Mon Mar 14 20:19:24 UTC 2022
This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
498b2ca3a0 COMMON: Added firstPathComponents() method.
ab0f56d932 DIRECTOR: LINGO: Attempt to read game files in FileIO XLib
301377a605 DIRECTOR: LINGO: Do not error out when b_do() was provided with empty scripts
Commit: 498b2ca3a0096161f668563762b688a9d88fddb6
https://github.com/scummvm/scummvm/commit/498b2ca3a0096161f668563762b688a9d88fddb6
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-03-14T21:16:03+01:00
Commit Message:
COMMON: Added firstPathComponents() method.
A better name is welcome
Changed paths:
common/str.cpp
common/str.h
diff --git a/common/str.cpp b/common/str.cpp
index b2e12fdc10d..4685f1ac2b8 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -543,6 +543,29 @@ String lastPathComponent(const String &path, const char sep) {
return String(first, last);
}
+String firstPathComponents(const String &path, const char sep) {
+ const char *str = path.c_str();
+ const char *last = str + path.size();
+
+ // Skip over trailing slashes
+ while (last > str && *(last - 1) == sep)
+ --last;
+
+ // Path consisted of only slashes -> return empty string
+ if (last == str)
+ return String();
+
+ // Now scan the whole component
+ const char *first = last - 1;
+ while (first > str && *first != sep)
+ --first;
+
+ if (*first == sep)
+ first++;
+
+ return String(str, first);
+}
+
String normalizePath(const String &path, const char sep) {
if (path.empty())
return path;
diff --git a/common/str.h b/common/str.h
index ee05e64de36..4043ac906b9 100644
--- a/common/str.h
+++ b/common/str.h
@@ -290,6 +290,20 @@ extern char *trim(char *t);
*/
String lastPathComponent(const String &path, const char sep);
+/**
+ * Returns the first components of a given path (complementary to lastPathComponent)
+ *
+ * Examples:
+ * /foo/bar.txt would return '/foo/'
+ * /foo/bar/ would return '/foo/'
+ * /foo/./bar// would return '/foo/./'
+ *
+ * @param path the path of which we want to know the last component
+ * @param sep character used to separate path components
+ * @return The all the components of the path except the last one.
+ */
+String firstPathComponents(const String &path, const char sep);
+
/**
* Normalize a given path to a canonical form. In particular:
* - trailing separators are removed: /foo/bar/ -> /foo/bar
Commit: ab0f56d932330bb41ab13afa904f4183ce411e3c
https://github.com/scummvm/scummvm/commit/ab0f56d932330bb41ab13afa904f4183ce411e3c
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-03-14T21:16:03+01:00
Commit Message:
DIRECTOR: LINGO: Attempt to read game files in FileIO XLib
Changed paths:
engines/director/lingo/xlibs/fileio.cpp
engines/director/lingo/xlibs/fileio.h
diff --git a/engines/director/lingo/xlibs/fileio.cpp b/engines/director/lingo/xlibs/fileio.cpp
index 317269aa952..fd7de383fa5 100644
--- a/engines/director/lingo/xlibs/fileio.cpp
+++ b/engines/director/lingo/xlibs/fileio.cpp
@@ -82,7 +82,6 @@ void FileIO::close(int type) {
FileObject::FileObject(ObjectType objType) : Object<FileObject>("FileIO") {
_objType = objType;
_filename = nullptr;
- _inFile = nullptr;
_inStream = nullptr;
_outFile = nullptr;
_outStream = nullptr;
@@ -90,7 +89,6 @@ FileObject::FileObject(ObjectType objType) : Object<FileObject>("FileIO") {
FileObject::FileObject(const FileObject &obj) : Object<FileObject>(obj) {
_filename = nullptr;
- _inFile = nullptr;
_inStream = nullptr;
_outFile = nullptr;
_outStream = nullptr;
@@ -105,11 +103,8 @@ void FileObject::clear() {
delete _filename;
_filename = nullptr;
}
- if (_inFile) {
- delete _inFile;
- if (_inStream != _inFile)
- delete _inStream;
- _inFile = nullptr;
+ if (_inStream) {
+ delete _inStream;
_inStream = nullptr;
}
if (_outFile) {
@@ -145,7 +140,8 @@ void FileIO::m_new(int nargs) {
Common::SaveFileManager *saves = g_system->getSavefileManager();
Common::String option = d1.asString();
- Common::String filename = d2.asString();
+ Common::String path = d2.asString();
+ Common::String origpath = path;
Common::String prefix = g_director->getTargetName() + '-';
@@ -158,24 +154,31 @@ void FileIO::m_new(int nargs) {
g_lingo->push(Datum(kErrorFileNotFound));
return;
}
- filename = browser.getResult();
- } else if (!filename.hasSuffixIgnoreCase(".txt")) {
- filename += ".txt";
+ path = browser.getResult();
+ } else if (!path.hasSuffixIgnoreCase(".txt")) {
+ path += ".txt";
}
// Enforce target to the created files so they do not mix up
- if (!option.hasPrefix("?") || option.equalsIgnoreCase("write")) {
- if (!filename.hasPrefixIgnoreCase(prefix))
- filename = prefix + filename;
- }
+ Common::String filename = lastPathComponent(path, '/');
+ Common::String dir = firstPathComponents(path, '/');
+
+ if (!filename.hasPrefixIgnoreCase(prefix))
+ filename = dir + prefix + filename;
if (option.equalsIgnoreCase("read")) {
- me->_inFile = saves->openForLoading(filename);
- me->_inStream = me->_inFile;
- if (!me->_inFile) {
- saveFileError();
- me->dispose();
- return;
+ me->_inStream = saves->openForLoading(filename);
+ if (!me->_inStream) {
+ // Maybe we're trying to read one of the game files
+ Common::File *f = new Common::File;
+
+ if (!f->open(origpath)) {
+ delete f;
+ saveFileError();
+ me->dispose();
+ return;
+ }
+ me->_inStream = f;
}
} else if (option.equalsIgnoreCase("write")) {
// OutSaveFile is not seekable so create a separate seekable stream
@@ -188,19 +191,25 @@ void FileIO::m_new(int nargs) {
return;
}
} else if (option.equalsIgnoreCase("append")) {
- Common::InSaveFile *_inFile = saves->openForLoading(filename);
- if (!_inFile) {
- saveFileError();
- me->dispose();
- return;
+ Common::SeekableReadStream *inFile = saves->openForLoading(filename);
+ if (!inFile) {
+ Common::File *f = new Common::File;
+
+ if (!f->open(origpath)) {
+ delete f;
+ saveFileError();
+ me->dispose();
+ return;
+ }
+ inFile = f;
}
me->_outStream = new Common::MemoryWriteStreamDynamic(DisposeAfterUse::YES);
- byte b = _inFile->readByte();
- while (!_inFile->eos() && !_inFile->err()) {
+ byte b = inFile->readByte();
+ while (!inFile->eos() && !inFile->err()) {
me->_outStream->writeByte(b);
- b = _inFile->readByte();
+ b = inFile->readByte();
}
- delete _inFile;
+ delete inFile;
me->_outFile = saves->openForSaving(filename, false);
if (!me->_outFile) {
saveFileError();
diff --git a/engines/director/lingo/xlibs/fileio.h b/engines/director/lingo/xlibs/fileio.h
index 68bd282f465..0f4400d0cb6 100644
--- a/engines/director/lingo/xlibs/fileio.h
+++ b/engines/director/lingo/xlibs/fileio.h
@@ -52,7 +52,6 @@ enum FileIOError {
class FileObject : public Object<FileObject> {
public:
Common::String *_filename;
- Common::InSaveFile *_inFile;
Common::SeekableReadStream *_inStream;
Common::OutSaveFile *_outFile;
Common::MemoryWriteStreamDynamic *_outStream;
Commit: 301377a605db188901265e5424b54c9d2f95c85d
https://github.com/scummvm/scummvm/commit/301377a605db188901265e5424b54c9d2f95c85d
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-03-14T21:16:03+01:00
Commit Message:
DIRECTOR: LINGO: Do not error out when b_do() was provided with empty scripts
Changed paths:
engines/director/lingo/lingo-builtins.cpp
diff --git a/engines/director/lingo/lingo-builtins.cpp b/engines/director/lingo/lingo-builtins.cpp
index 54f2658b966..5be29118c47 100644
--- a/engines/director/lingo/lingo-builtins.cpp
+++ b/engines/director/lingo/lingo-builtins.cpp
@@ -1228,6 +1228,11 @@ void LB::b_do(int nargs) {
Common::String code = g_lingo->pop().asString();
ScriptContext *sc = g_lingo->_compiler->compileAnonymous(code);
Symbol sym = sc->_eventHandlers[kEventGeneric];
+
+ // Check if we have anything to execute
+ if (sym.type == VOIDSYM)
+ return;
+
LC::call(sym, 0, false);
}
More information about the Scummvm-git-logs
mailing list