2018-04-27 09:48:44 -07:00
|
|
|
/* Copyright (C) 2018 Wildfire Games.
|
2009-04-18 10:00:33 -07:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
|
*
|
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2007-05-07 09:33:24 -07:00
|
|
|
#ifndef INCLUDED_JSI_VFS
|
|
|
|
|
#define INCLUDED_JSI_VFS
|
2006-04-23 16:14:18 -07:00
|
|
|
|
2014-01-04 02:14:53 -08:00
|
|
|
#include "scriptinterface/ScriptInterface.h"
|
2006-04-23 16:14:18 -07:00
|
|
|
|
|
|
|
|
namespace JSI_VFS
|
|
|
|
|
{
|
|
|
|
|
// Return an array of pathname strings, one for each matching entry in the
|
|
|
|
|
// specified directory.
|
2017-12-04 15:46:55 -08:00
|
|
|
JS::Value BuildDirEntList(ScriptInterface::CxPrivate* pCxPrivate, const std::vector<CStrW>& validPaths, const std::wstring& path, const std::wstring& filterStr, bool recurse);
|
2006-04-23 16:14:18 -07:00
|
|
|
|
2013-11-07 12:07:24 -08:00
|
|
|
// Return true iff the file exists
|
2017-12-04 16:22:03 -08:00
|
|
|
bool FileExists(ScriptInterface::CxPrivate* pCxPrivate, const std::vector<CStrW>& validPaths, const CStrW& filename);
|
2013-11-07 12:07:24 -08:00
|
|
|
|
2006-04-23 16:14:18 -07:00
|
|
|
// Return time [seconds since 1970] of the last modification to the specified file.
|
2016-01-23 07:17:56 -08:00
|
|
|
double GetFileMTime(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename);
|
2006-04-23 16:14:18 -07:00
|
|
|
|
|
|
|
|
// Return current size of file.
|
2016-01-23 07:17:56 -08:00
|
|
|
unsigned int GetFileSize(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename);
|
2006-04-23 16:14:18 -07:00
|
|
|
|
|
|
|
|
// Return file contents in a string.
|
2016-01-23 07:17:56 -08:00
|
|
|
JS::Value ReadFile(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename);
|
2006-04-23 16:14:18 -07:00
|
|
|
|
|
|
|
|
// Return file contents as an array of lines.
|
2016-01-23 07:17:56 -08:00
|
|
|
JS::Value ReadFileLines(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename);
|
2017-09-07 21:01:26 -07:00
|
|
|
|
2017-09-11 15:21:34 -07:00
|
|
|
// Return file contents parsed as a JS Object
|
2017-12-03 15:02:27 -08:00
|
|
|
JS::Value ReadJSONFile(ScriptInterface::CxPrivate* pCxPrivate, const std::vector<CStrW>& validPaths, const CStrW& filePath);
|
2017-09-11 15:21:34 -07:00
|
|
|
|
|
|
|
|
// Save given JS Object to a JSON file
|
|
|
|
|
void WriteJSONFile(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filePath, JS::HandleValue val1);
|
|
|
|
|
|
2017-12-03 15:02:27 -08:00
|
|
|
// Tests whether the current script context is allowed to read from the given directory
|
|
|
|
|
bool PathRestrictionMet(ScriptInterface::CxPrivate* pCxPrivate, const std::vector<CStrW>& validPaths, const CStrW& filePath);
|
|
|
|
|
|
|
|
|
|
void RegisterScriptFunctions_GUI(const ScriptInterface& scriptInterface);
|
|
|
|
|
void RegisterScriptFunctions_Simulation(const ScriptInterface& scriptInterface);
|
|
|
|
|
void RegisterScriptFunctions_Maps(const ScriptInterface& scriptInterface);
|
2006-12-15 17:01:15 -08:00
|
|
|
}
|
2006-04-23 16:14:18 -07:00
|
|
|
|
2018-04-27 09:48:44 -07:00
|
|
|
#endif // INCLUDED_JSI_VFS
|