Pyrogenesis  trunk
JSInterface_VFS.h
Go to the documentation of this file.
1 /* Copyright (C) 2014 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 // JSInterface_VFS.h
19 //
20 // The JavaScript wrapper around useful snippets of the VFS
21 
22 #ifndef INCLUDED_JSI_VFS
23 #define INCLUDED_JSI_VFS
24 
26 
27 // these are registered in ScriptFunctions.cpp, hence the need for a header.
28 
29 namespace JSI_VFS
30 {
31  // Return an array of pathname strings, one for each matching entry in the
32  // specified directory.
33  //
34  // pathnames = buildDirEntList(start_path [, filter_string [, recursive ] ]);
35  // directory: VFS path
36  // filter_string: see match_wildcard; "" matches everything.
37  // recurse: should subdirectories be included in the search? default false.
38  //
39  // note: full pathnames of each file/subdirectory are returned,
40  // ready for use as a "filename" for the other functions.
41  JS::Value BuildDirEntList(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& path, const std::wstring& filterStr, bool recurse);
42 
43  // Return true iff the file exists
44  //
45  // if (fileExists(filename) { ... }
46  // filename: VFS filename (may include path)
47  bool FileExists(ScriptInterface::CxPrivate* pCxPrivate, const CStrW& filename);
48 
49  // Return time [seconds since 1970] of the last modification to the specified file.
50  //
51  // mtime = getFileMTime(filename);
52  // filename: VFS filename (may include path)
53  double GetFileMTime(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename);
54 
55  // Return current size of file.
56  //
57  // size = getFileSize(filename);
58  // filename: VFS filename (may include path)
59  unsigned int GetFileSize(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename);
60 
61  // Return file contents in a string.
62  //
63  // contents = readFile(filename);
64  // filename: VFS filename (may include path)
65  JS::Value ReadFile(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename);
66 
67  // Return file contents as an array of lines.
68  //
69  // lines = readFileLines(filename);
70  // filename: VFS filename (may include path)
71  JS::Value ReadFileLines(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename);
72 }
73 
74 #endif
unsigned int GetFileSize(ScriptInterface::CxPrivate *pCxPrivate, const std::wstring &filename)
Definition: JSInterface_VFS.cpp:132
bool FileExists(ScriptInterface::CxPrivate *pCxPrivate, const CStrW &filename)
Definition: JSInterface_VFS.cpp:108
JS::Value BuildDirEntList(ScriptInterface::CxPrivate *pCxPrivate, const std::wstring &path, const std::wstring &filterStr, bool recurse)
Definition: JSInterface_VFS.cpp:84
double GetFileMTime(ScriptInterface::CxPrivate *pCxPrivate, const std::wstring &filename)
Definition: JSInterface_VFS.cpp:118
Config::Value_type Value
Definition: json_spirit_value.h:181
JS::Value ReadFile(ScriptInterface::CxPrivate *pCxPrivate, const std::wstring &filename)
Definition: JSInterface_VFS.cpp:146
Definition: ScriptInterface.h:99
JS::Value ReadFileLines(ScriptInterface::CxPrivate *pCxPrivate, const std::wstring &filename)
Definition: JSInterface_VFS.cpp:171
Definition: JSInterface_VFS.h:29