1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 /*
24 * This file is based on WME Lite.
25 * http://dead-code.org/redir.php?target=wmelite
26 * Copyright (c) 2011 Jan Nedoma
27 */
28
29 #include "engines/wintermute/base/scriptables/script_ext_directory.h"
30 #include "engines/wintermute/base/scriptables/script_stack.h"
31 #include "engines/wintermute/base/scriptables/script_value.h"
32 #include "engines/wintermute/base/base_engine.h"
33 #include "engines/wintermute/persistent.h"
34
35 namespace Wintermute {
36
37 //////////////////////////////////////////////////////////////////////
38 // Construction/Destruction
39 //////////////////////////////////////////////////////////////////////
40
41
IMPLEMENT_PERSISTENT(SXDirectory,true)42 IMPLEMENT_PERSISTENT(SXDirectory, true)
43
44 BaseScriptable *makeSXDirectory(BaseGame *inGame) {
45 return new SXDirectory(inGame);
46 }
47
48 //////////////////////////////////////////////////////////////////////////
SXDirectory(BaseGame * inGame)49 SXDirectory::SXDirectory(BaseGame *inGame) : BaseScriptable(inGame) {
50
51 }
52
53
54 //////////////////////////////////////////////////////////////////////////
~SXDirectory()55 SXDirectory::~SXDirectory() {
56
57 }
58
59
60 //////////////////////////////////////////////////////////////////////////
scCallMethod(ScScript * script,ScStack * stack,ScStack * thisStack,const char * name)61 bool SXDirectory::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) {
62 //////////////////////////////////////////////////////////////////////////
63 // Create
64 //////////////////////////////////////////////////////////////////////////
65 if (strcmp(name, "Create") == 0) {
66 stack->correctParams(1);
67 stack->pop()->getString();
68
69 if (BaseEngine::instance().getGameId() == "hamlet") {
70 // No need to actually create anything since "gamelet.save" is stored at SavefileManager
71 stack->pushBool(true);
72 } else {
73 warning("Directory.Create is not implemented! Returning false...");
74 stack->pushBool(false);
75 }
76
77 return STATUS_OK;
78 }
79
80 //////////////////////////////////////////////////////////////////////////
81 // Delete
82 //////////////////////////////////////////////////////////////////////////
83 else if (strcmp(name, "Delete") == 0) {
84 stack->correctParams(1);
85 stack->pop()->getString();
86
87 warning("Directory.Delete is not implemented! Returning false...");
88
89 stack->pushBool(false);
90 return STATUS_OK;
91 }
92
93 //////////////////////////////////////////////////////////////////////////
94 // GetFiles / GetDirectories
95 //////////////////////////////////////////////////////////////////////////
96 else if (strcmp(name, "GetFiles") == 0 || strcmp(name, "GetDirectories") == 0) {
97 stack->correctParams(2);
98 stack->pop()->getString();
99 stack->pop()->getString();
100
101 stack->pushInt(0);
102 BaseScriptable *array = makeSXArray(_gameRef, stack);
103
104 warning("Directory.%s is not implemented! Returning empty array...", name);
105
106 stack->pushNative(array, false);
107 return STATUS_OK;
108 }
109
110 //////////////////////////////////////////////////////////////////////////
111 // GetDrives
112 //////////////////////////////////////////////////////////////////////////
113 else if (strcmp(name, "GetDrives") == 0) {
114 stack->correctParams(0);
115
116 warning("Directory.GetDrives is not implemented! Returning empty array...");
117
118 stack->pushInt(0);
119 stack->pushNative(makeSXArray(_gameRef, stack), false);
120 return STATUS_OK;
121 } else {
122 return STATUS_FAILED;
123 }
124 }
125
126
127 //////////////////////////////////////////////////////////////////////////
scGetProperty(const Common::String & name)128 ScValue *SXDirectory::scGetProperty(const Common::String &name) {
129 _scValue->setNULL();
130
131 //////////////////////////////////////////////////////////////////////////
132 // Type
133 //////////////////////////////////////////////////////////////////////////
134 if (name == "Type") {
135 _scValue->setString("directory");
136 return _scValue;
137 }
138
139 //////////////////////////////////////////////////////////////////////////
140 // PathSeparator
141 //////////////////////////////////////////////////////////////////////////
142 else if (name == "PathSeparator") {
143 _scValue->setString("\\");
144 return _scValue;
145 }
146
147 //////////////////////////////////////////////////////////////////////////
148 // CurrentDirectory
149 //////////////////////////////////////////////////////////////////////////
150 else if (name == "CurrentDirectory") {
151 warning("Directory.CurrentDirectory is not implemented! Returning 'saves'...");
152 _scValue->setString(""); // See also: BaseGame::scGetProperty("SaveDirectory")
153 return _scValue;
154 }
155
156 //////////////////////////////////////////////////////////////////////////
157 // TempDirectory
158 //////////////////////////////////////////////////////////////////////////
159 else if (name == "TempDirectory") {
160 warning("Directory.TempDirectory is not implemented! Returning 'saves'...");
161 _scValue->setString("temp"); // See also: BaseGame::scGetProperty("SaveDirectory")
162 return _scValue;
163 } else {
164 return _scValue;
165 }
166 }
167
168
169 //////////////////////////////////////////////////////////////////////////
persist(BasePersistenceManager * persistMgr)170 bool SXDirectory::persist(BasePersistenceManager *persistMgr) {
171
172 BaseScriptable::persist(persistMgr);
173 return STATUS_OK;
174 }
175
176 } // End of namespace Wintermute
177