aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimei Yin2017-08-08 11:44:35 +0200
committerSimei Yin2017-08-08 14:08:29 +0200
commitcff1308ed1abecb70f5d2789cf813af25d24c372 (patch)
tree5960b50d3d6fe3797568fa0b58ff2acea28eae4b
parentc9e3747114a3fa583ea397ff1d76b88965e63f67 (diff)
downloadscummvm-rg350-cff1308ed1abecb70f5d2789cf813af25d24c372.tar.gz
scummvm-rg350-cff1308ed1abecb70f5d2789cf813af25d24c372.tar.bz2
scummvm-rg350-cff1308ed1abecb70f5d2789cf813af25d24c372.zip
SLUDGE: Implement fileExists built-in function
-rw-r--r--engines/sludge/builtin.cpp34
1 files changed, 14 insertions, 20 deletions
diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp
index ce66443268..a092518c26 100644
--- a/engines/sludge/builtin.cpp
+++ b/engines/sludge/builtin.cpp
@@ -283,32 +283,26 @@ builtIn(fileExists) {
trimStack(fun->stack);
Common::String aaaaa = encodeFilename(g_sludge->loadNow);
g_sludge->loadNow.clear();
+
if (failSecurityCheck(aaaaa))
return BR_ERROR;
-#if 0
- FILE *fp = fopen(aaaaa, "rb");
- if (!fp) {
- char currentDir[1000];
- if (!getcwd(currentDir, 998)) {
- debugOut("Can't get current directory.\n");
- }
- if (chdir(gamePath)) {
- debugOut("Error: Failed changing to directory %s\n", gamePath);
- }
- fp = fopen(aaaaa, "rb");
- if (chdir(currentDir)) {
- debugOut("Error: Failed changing to directory %s\n", currentDir);
+ bool exist = false;
+
+ Common::File fd;
+ if (fd.open(aaaaa)) {
+ exist = true;
+ fd.close();
+ } else {
+ Common::InSaveFile *fp = g_system->getSavefileManager()->openForLoading(aaaaa);
+ if (fp) {
+ exist = true;
+ delete fp;
}
}
-#endif
+
// Return value
- setVariable(fun->reg, SVT_INT, 0/*(fp != NULL)*/); //TODO:false value
-#if 0
- if (fp) fclose(fp);
- delete[] aaaaa;
- loadNow = NULL;
-#endif
+ setVariable(fun->reg, SVT_INT, exist);
return BR_CONTINUE;
}