mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +00:00
Move VFS GUI script function registration to its interface file.
This was SVN commit r20133.
This commit is contained in:
@@ -1044,15 +1044,9 @@ void GuiScriptingInit(ScriptInterface& scriptInterface)
|
|||||||
JSI_Sound::RegisterScriptFunctions(scriptInterface);
|
JSI_Sound::RegisterScriptFunctions(scriptInterface);
|
||||||
JSI_L10n::RegisterScriptFunctions(scriptInterface);
|
JSI_L10n::RegisterScriptFunctions(scriptInterface);
|
||||||
JSI_Lobby::RegisterScriptFunctions(scriptInterface);
|
JSI_Lobby::RegisterScriptFunctions(scriptInterface);
|
||||||
|
JSI_VFS::RegisterScriptFunctions(scriptInterface);
|
||||||
JSI_VisualReplay::RegisterScriptFunctions(scriptInterface);
|
JSI_VisualReplay::RegisterScriptFunctions(scriptInterface);
|
||||||
|
|
||||||
// VFS (external)
|
|
||||||
scriptInterface.RegisterFunction<JS::Value, std::wstring, std::wstring, bool, &JSI_VFS::BuildDirEntList>("BuildDirEntList");
|
|
||||||
scriptInterface.RegisterFunction<bool, CStrW, JSI_VFS::FileExists>("FileExists");
|
|
||||||
scriptInterface.RegisterFunction<double, std::wstring, &JSI_VFS::GetFileMTime>("GetFileMTime");
|
|
||||||
scriptInterface.RegisterFunction<unsigned int, std::wstring, &JSI_VFS::GetFileSize>("GetFileSize");
|
|
||||||
scriptInterface.RegisterFunction<JS::Value, std::wstring, &JSI_VFS::ReadFile>("ReadFile");
|
|
||||||
scriptInterface.RegisterFunction<JS::Value, std::wstring, &JSI_VFS::ReadFileLines>("ReadFileLines");
|
|
||||||
// GUI manager functions:
|
// GUI manager functions:
|
||||||
scriptInterface.RegisterFunction<void, std::wstring, JS::HandleValue, &PushGuiPage>("PushGuiPage");
|
scriptInterface.RegisterFunction<void, std::wstring, JS::HandleValue, &PushGuiPage>("PushGuiPage");
|
||||||
scriptInterface.RegisterFunction<void, std::wstring, JS::HandleValue, &SwitchGuiPage>("SwitchGuiPage");
|
scriptInterface.RegisterFunction<void, std::wstring, JS::HandleValue, &SwitchGuiPage>("SwitchGuiPage");
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2012 Wildfire Games.
|
/* Copyright (C) 2017 Wildfire Games.
|
||||||
* This file is part of 0 A.D.
|
* This file is part of 0 A.D.
|
||||||
*
|
*
|
||||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||||
@@ -40,8 +40,6 @@
|
|||||||
/* else: success */
|
/* else: success */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// state held across multiple BuildDirEntListCB calls; init by BuildDirEntList.
|
// state held across multiple BuildDirEntListCB calls; init by BuildDirEntList.
|
||||||
struct BuildDirEntListState
|
struct BuildDirEntListState
|
||||||
{
|
{
|
||||||
@@ -102,19 +100,12 @@ JS::Value JSI_VFS::BuildDirEntList(ScriptInterface::CxPrivate* pCxPrivate, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return true iff the file exits
|
// Return true iff the file exits
|
||||||
//
|
|
||||||
// if (fileExists(filename)) { ... }
|
|
||||||
// filename: VFS filename (may include path)
|
|
||||||
bool JSI_VFS::FileExists(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const CStrW& filename)
|
bool JSI_VFS::FileExists(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const CStrW& filename)
|
||||||
{
|
{
|
||||||
return (g_VFS->GetFileInfo(filename, 0) == INFO::OK);
|
return (g_VFS->GetFileInfo(filename, 0) == INFO::OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Return time [seconds since 1970] of the last modification to the specified file.
|
// Return time [seconds since 1970] of the last modification to the specified file.
|
||||||
//
|
|
||||||
// mtime = getFileMTime(filename);
|
|
||||||
// filename: VFS filename (may include path)
|
|
||||||
double JSI_VFS::GetFileMTime(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& filename)
|
double JSI_VFS::GetFileMTime(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& filename)
|
||||||
{
|
{
|
||||||
CFileInfo fileInfo;
|
CFileInfo fileInfo;
|
||||||
@@ -124,11 +115,7 @@ double JSI_VFS::GetFileMTime(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), con
|
|||||||
return (double)fileInfo.MTime();
|
return (double)fileInfo.MTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Return current size of file.
|
// Return current size of file.
|
||||||
//
|
|
||||||
// size = getFileSize(filename);
|
|
||||||
// filename: VFS filename (may include path)
|
|
||||||
unsigned int JSI_VFS::GetFileSize(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& filename)
|
unsigned int JSI_VFS::GetFileSize(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& filename)
|
||||||
{
|
{
|
||||||
CFileInfo fileInfo;
|
CFileInfo fileInfo;
|
||||||
@@ -138,11 +125,7 @@ unsigned int JSI_VFS::GetFileSize(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)
|
|||||||
return (unsigned int)fileInfo.Size();
|
return (unsigned int)fileInfo.Size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Return file contents in a string. Assume file is UTF-8 encoded text.
|
// Return file contents in a string. Assume file is UTF-8 encoded text.
|
||||||
//
|
|
||||||
// contents = readFile(filename);
|
|
||||||
// filename: VFS filename (may include path)
|
|
||||||
JS::Value JSI_VFS::ReadFile(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename)
|
JS::Value JSI_VFS::ReadFile(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename)
|
||||||
{
|
{
|
||||||
JSContext* cx = pCxPrivate->pScriptInterface->GetContext();
|
JSContext* cx = pCxPrivate->pScriptInterface->GetContext();
|
||||||
@@ -163,18 +146,12 @@ JS::Value JSI_VFS::ReadFile(ScriptInterface::CxPrivate* pCxPrivate, const std::w
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Return file contents as an array of lines. Assume file is UTF-8 encoded text.
|
// Return file contents as an array of lines. Assume file is UTF-8 encoded text.
|
||||||
//
|
|
||||||
// lines = readFileLines(filename);
|
|
||||||
// filename: VFS filename (may include path)
|
|
||||||
JS::Value JSI_VFS::ReadFileLines(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename)
|
JS::Value JSI_VFS::ReadFileLines(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename)
|
||||||
{
|
{
|
||||||
JSContext* cx = pCxPrivate->pScriptInterface->GetContext();
|
JSContext* cx = pCxPrivate->pScriptInterface->GetContext();
|
||||||
JSAutoRequest rq(cx);
|
JSAutoRequest rq(cx);
|
||||||
//
|
|
||||||
// read file
|
|
||||||
//
|
|
||||||
CVFSFile file;
|
CVFSFile file;
|
||||||
if (file.Load(g_VFS, filename) != PSRETURN_OK)
|
if (file.Load(g_VFS, filename) != PSRETURN_OK)
|
||||||
return JSVAL_NULL;
|
return JSVAL_NULL;
|
||||||
@@ -184,10 +161,7 @@ JS::Value JSI_VFS::ReadFileLines(ScriptInterface::CxPrivate* pCxPrivate, const s
|
|||||||
// Fix CRLF line endings. (This function will only ever be used on text files.)
|
// Fix CRLF line endings. (This function will only ever be used on text files.)
|
||||||
contents.Replace("\r\n", "\n");
|
contents.Replace("\r\n", "\n");
|
||||||
|
|
||||||
//
|
|
||||||
// split into array of strings (one per line)
|
// split into array of strings (one per line)
|
||||||
//
|
|
||||||
|
|
||||||
std::stringstream ss(contents);
|
std::stringstream ss(contents);
|
||||||
JS::RootedObject line_array(cx, JS_NewArrayObject(cx, JS::HandleValueArray::empty()));
|
JS::RootedObject line_array(cx, JS_NewArrayObject(cx, JS::HandleValueArray::empty()));
|
||||||
std::string line;
|
std::string line;
|
||||||
@@ -203,3 +177,13 @@ JS::Value JSI_VFS::ReadFileLines(ScriptInterface::CxPrivate* pCxPrivate, const s
|
|||||||
|
|
||||||
return JS::ObjectValue(*line_array);
|
return JS::ObjectValue(*line_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JSI_VFS::RegisterScriptFunctions(const ScriptInterface& scriptInterface)
|
||||||
|
{
|
||||||
|
scriptInterface.RegisterFunction<JS::Value, std::wstring, std::wstring, bool, &JSI_VFS::BuildDirEntList>("BuildDirEntList");
|
||||||
|
scriptInterface.RegisterFunction<bool, CStrW, JSI_VFS::FileExists>("FileExists");
|
||||||
|
scriptInterface.RegisterFunction<double, std::wstring, &JSI_VFS::GetFileMTime>("GetFileMTime");
|
||||||
|
scriptInterface.RegisterFunction<unsigned int, std::wstring, &JSI_VFS::GetFileSize>("GetFileSize");
|
||||||
|
scriptInterface.RegisterFunction<JS::Value, std::wstring, &JSI_VFS::ReadFile>("ReadFile");
|
||||||
|
scriptInterface.RegisterFunction<JS::Value, std::wstring, &JSI_VFS::ReadFileLines>("ReadFileLines");
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2014 Wildfire Games.
|
/* Copyright (C) 2017 Wildfire Games.
|
||||||
* This file is part of 0 A.D.
|
* This file is part of 0 A.D.
|
||||||
*
|
*
|
||||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||||
@@ -41,34 +41,21 @@ namespace JSI_VFS
|
|||||||
JS::Value BuildDirEntList(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& path, const std::wstring& filterStr, bool recurse);
|
JS::Value BuildDirEntList(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& path, const std::wstring& filterStr, bool recurse);
|
||||||
|
|
||||||
// Return true iff the file exists
|
// Return true iff the file exists
|
||||||
//
|
|
||||||
// if (fileExists(filename) { ... }
|
|
||||||
// filename: VFS filename (may include path)
|
|
||||||
bool FileExists(ScriptInterface::CxPrivate* pCxPrivate, const CStrW& filename);
|
bool FileExists(ScriptInterface::CxPrivate* pCxPrivate, const CStrW& filename);
|
||||||
|
|
||||||
// Return time [seconds since 1970] of the last modification to the specified file.
|
// Return time [seconds since 1970] of the last modification to the specified file.
|
||||||
//
|
|
||||||
// mtime = getFileMTime(filename);
|
|
||||||
// filename: VFS filename (may include path)
|
|
||||||
double GetFileMTime(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename);
|
double GetFileMTime(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename);
|
||||||
|
|
||||||
// Return current size of file.
|
// Return current size of file.
|
||||||
//
|
|
||||||
// size = getFileSize(filename);
|
|
||||||
// filename: VFS filename (may include path)
|
|
||||||
unsigned int GetFileSize(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename);
|
unsigned int GetFileSize(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename);
|
||||||
|
|
||||||
// Return file contents in a string.
|
// Return file contents in a string.
|
||||||
//
|
|
||||||
// contents = readFile(filename);
|
|
||||||
// filename: VFS filename (may include path)
|
|
||||||
JS::Value ReadFile(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename);
|
JS::Value ReadFile(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename);
|
||||||
|
|
||||||
// Return file contents as an array of lines.
|
// Return file contents as an array of lines.
|
||||||
//
|
|
||||||
// lines = readFileLines(filename);
|
|
||||||
// filename: VFS filename (may include path)
|
|
||||||
JS::Value ReadFileLines(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename);
|
JS::Value ReadFileLines(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename);
|
||||||
|
|
||||||
|
void RegisterScriptFunctions(const ScriptInterface& scriptInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user