ScummVM API documentation
packagemanager.h
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 modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (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, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * This code is based on Broken Sword 2.5 engine
24  *
25  * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
26  *
27  * Licensed under GNU GPL v2
28  *
29  */
30 
31 /*
32  * BS_PackageManager
33  * -----------------
34  * This is the package manager interface, that contains all the methods that a package manager
35  * must implement.
36  * In the package manager, note the following:
37  * 1. It creates a completely new (virtual) directory tree in the packages and directories
38  * can be mounted.
39  * 2. To separate elements of a directory path '/' must be used rather than '\'
40  * 3. LoadDirectoryAsPackage should only be used for testing. The final release will be
41  * have all files in packages.
42  *
43  * Autor: Malte Thiesen, $author$
44  */
45 
46 #ifndef SWORD25_PACKAGE_MANAGER_H
47 #define SWORD25_PACKAGE_MANAGER_H
48 
49 #include "common/archive.h"
50 #include "common/array.h"
51 #include "common/fs.h"
52 #include "common/str.h"
53 
54 #include "sword25/kernel/common.h"
55 #include "sword25/kernel/kernel.h"
56 #include "sword25/kernel/service.h"
57 
58 namespace Sword25 {
59 
60 // Class definitions
61 
71 class PackageManager : public Service {
72 private:
73  class ArchiveEntry {
74  public:
75  Common::Archive *archive;
76  Common::String _mountPath;
77 
78  ArchiveEntry(Common::Archive *archive_, const Common::String &mountPath_):
79  archive(archive_), _mountPath(mountPath_) {
80  }
81  ~ArchiveEntry() {
82  delete archive;
83  }
84  };
85 
86  Common::String _currentDirectory;
87  Common::FSNode _rootFolder;
88  Common::List<ArchiveEntry *> _archiveList;
89  bool _extractedFiles;
90  Common::Path _directoryName;
91 
92  bool _useEnglishSpeech;
93  Common::String ensureSpeechLang(const Common::String &fileName);
94 
95  Common::ArchiveMemberPtr getArchiveMember(const Common::String &fileName);
96 
97 public:
98  PackageManager(Kernel *pKernel);
99  ~PackageManager() override;
100 
101  enum FILE_TYPES {
102  FT_DIRECTORY = (1 << 0),
103  FT_FILE = (1 << 1)
104  };
105 
110  void setRunWithExtractedFiles(const Common::Path &directoryName) {
111  _extractedFiles = true;
112  _directoryName = directoryName;
113  }
114 
121  bool loadPackage(const Common::Path &fileName, const Common::String &mountPosition);
128  bool loadDirectoryAsPackage(const Common::Path &directoryName, const Common::String &mountPosition);
136  byte *getFile(const Common::String &fileName, uint *pFileSize = NULL);
137 
152  char *getXmlFile(const Common::String &fileName, uint *pFileSize = NULL) {
153  const char *versionStr = "<?xml version=\"1.0\"?>";
154  uint fileSize;
155  char *data = (char *)getFile(fileName, &fileSize);
156  size_t resultSize = fileSize + strlen(versionStr) + 1;
157  char *result = (char *)malloc(resultSize);
158  if (!result)
159  error("[PackageManager::getXmlFile] Cannot allocate memory");
160 
161  Common::strcpy_s(result, resultSize, versionStr);
162  Common::copy(data, data + fileSize, result + strlen(versionStr));
163  result[resultSize - 1] = '\0';
164 
165  delete[] data;
166  if (pFileSize)
167  *pFileSize = fileSize + strlen(versionStr);
168 
169  return result;
170  }
171 
178  Common::String getCurrentDirectory() { return _currentDirectory; }
185  bool changeDirectory(const Common::String &directory);
204  int doSearch(Common::ArchiveMemberList &list, const Common::String &filter, const Common::String &path, uint typeFilter = FT_DIRECTORY | FT_FILE);
205 
211  bool fileExists(const Common::String &FileName);
212 
213 private:
214  bool registerScriptBindings();
215 };
216 
217 } // End of namespace Sword25
218 
219 #endif
bool loadPackage(const Common::Path &fileName, const Common::String &mountPosition)
Definition: str.h:59
Definition: packagemanager.h:71
bool fileExists(const Common::String &FileName)
Definition: list.h:44
Common::SeekableReadStream * getStream(const Common::String &fileName)
Common::String getCurrentDirectory()
Definition: packagemanager.h:178
Definition: path.h:52
Definition: stream.h:745
Definition: archive.h:141
Definition: service.h:54
Out copy(In first, In last, Out dst)
Definition: algorithm.h:52
bool loadDirectoryAsPackage(const Common::Path &directoryName, const Common::String &mountPosition)
Definition: console.h:27
Definition: kernel.h:72
byte * getFile(const Common::String &fileName, uint *pFileSize=NULL)
Definition: fs.h:69
bool changeDirectory(const Common::String &directory)
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
char * getXmlFile(const Common::String &fileName, uint *pFileSize=NULL)
Definition: packagemanager.h:152
Common::String getAbsolutePath(const Common::String &fileName)
void strcpy_s(char *dst, size_t size, const char *src)
int doSearch(Common::ArchiveMemberList &list, const Common::String &filter, const Common::String &path, uint typeFilter=FT_DIRECTORY|FT_FILE)
void setRunWithExtractedFiles(const Common::Path &directoryName)
Definition: packagemanager.h:110