mirror of
https://github.com/glest/glest-source.git
synced 2025-08-16 05:13:59 +02:00
- allow loading of scenarios and tutorials when there are none (show an error message)
This commit is contained in:
@@ -70,7 +70,7 @@ void AutoTest::updateNewGame(Program *program, MainMenu *mainMenu) {
|
|||||||
mainMenu->setState(new MenuStateCustomGame(program, mainMenu, false, pNewGame, true, &gameSettings));
|
mainMenu->setState(new MenuStateCustomGame(program, mainMenu, false, pNewGame, true, &gameSettings));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mainMenu->setState(new MenuStateScenario(program, mainMenu,
|
mainMenu->setState(new MenuStateScenario(program, mainMenu, false,
|
||||||
Config::getInstance().getPathListForType(ptScenarios)));
|
Config::getInstance().getPathListForType(ptScenarios)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -356,6 +356,24 @@ void ScriptManager::init(World* world, GameCamera *gameCamera, const XmlNode *ro
|
|||||||
luaScript.loadCode("function " + script->getName() + "()" + script->getCode() + "end\n", script->getName());
|
luaScript.loadCode("function " + script->getName() + "()" + script->getCode() + "end\n", script->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//!!!
|
||||||
|
// string data_path= getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
|
||||||
|
// if(data_path != ""){
|
||||||
|
// endPathWithSlash(data_path);
|
||||||
|
// }
|
||||||
|
// string sandboxScriptFilename = data_path + "data/core/scripts/sandbox.lua";
|
||||||
|
// string sandboxLuaCode = getFileTextContents(sandboxScriptFilename);
|
||||||
|
//
|
||||||
|
// //luaScript.loadCode(sandboxLuaCode + "\n", "megaglest_lua_sandbox");
|
||||||
|
// luaScript.setSandboxWrapperFunctionName("runsandboxed");
|
||||||
|
// luaScript.setSandboxCode(sandboxLuaCode);
|
||||||
|
// luaScript.runCode(sandboxLuaCode);
|
||||||
|
|
||||||
|
// // Setup the lua security sandbox here
|
||||||
|
// luaScript.beginCall("megaglest_lua_sandbox");
|
||||||
|
// luaScript.endCall();
|
||||||
|
|
||||||
//setup message box
|
//setup message box
|
||||||
messageBox.init( Lang::getInstance().get("Ok") );
|
messageBox.init( Lang::getInstance().get("Ok") );
|
||||||
messageBox.setEnabled(false);
|
messageBox.setEnabled(false);
|
||||||
|
@@ -269,7 +269,8 @@ void Program::initScenario(WindowGl *window, string autoloadScenarioName) {
|
|||||||
init(window);
|
init(window);
|
||||||
mainMenu= new MainMenu(this);
|
mainMenu= new MainMenu(this);
|
||||||
setState(mainMenu);
|
setState(mainMenu);
|
||||||
mainMenu->setState(new MenuStateScenario(this, mainMenu, Config::getInstance().getPathListForType(ptScenarios),autoloadScenarioName));
|
mainMenu->setState(new MenuStateScenario(this, mainMenu, false,
|
||||||
|
Config::getInstance().getPathListForType(ptScenarios),autoloadScenarioName));
|
||||||
}
|
}
|
||||||
|
|
||||||
Program::~Program(){
|
Program::~Program(){
|
||||||
|
@@ -96,7 +96,8 @@ void MenuStateNewGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||||||
}
|
}
|
||||||
else if(buttonScenario.mouseClick(x, y)){
|
else if(buttonScenario.mouseClick(x, y)){
|
||||||
soundRenderer.playFx(coreData.getClickSoundB());
|
soundRenderer.playFx(coreData.getClickSoundB());
|
||||||
mainMenu->setState(new MenuStateScenario(program, mainMenu, Config::getInstance().getPathListForType(ptScenarios)));
|
mainMenu->setState(new MenuStateScenario(program, mainMenu, false,
|
||||||
|
Config::getInstance().getPathListForType(ptScenarios)));
|
||||||
}
|
}
|
||||||
else if(buttonJoinGame.mouseClick(x, y)){
|
else if(buttonJoinGame.mouseClick(x, y)){
|
||||||
soundRenderer.playFx(coreData.getClickSoundB());
|
soundRenderer.playFx(coreData.getClickSoundB());
|
||||||
@@ -108,7 +109,8 @@ void MenuStateNewGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||||||
}
|
}
|
||||||
else if(buttonTutorial.mouseClick(x, y)){
|
else if(buttonTutorial.mouseClick(x, y)){
|
||||||
soundRenderer.playFx(coreData.getClickSoundB());
|
soundRenderer.playFx(coreData.getClickSoundB());
|
||||||
mainMenu->setState(new MenuStateScenario(program, mainMenu, Config::getInstance().getPathListForType(ptTutorials)));
|
mainMenu->setState(new MenuStateScenario(program, mainMenu, true,
|
||||||
|
Config::getInstance().getPathListForType(ptTutorials)));
|
||||||
}
|
}
|
||||||
else if(buttonReturn.mouseClick(x, y)){
|
else if(buttonReturn.mouseClick(x, y)){
|
||||||
soundRenderer.playFx(coreData.getClickSoundB());
|
soundRenderer.playFx(coreData.getClickSoundB());
|
||||||
|
@@ -31,10 +31,13 @@ using namespace Shared::Xml;
|
|||||||
// class MenuStateScenario
|
// class MenuStateScenario
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
MenuStateScenario::MenuStateScenario(Program *program, MainMenu *mainMenu, const vector<string> &dirList, string autoloadScenarioName):
|
MenuStateScenario::MenuStateScenario(Program *program, MainMenu *mainMenu,
|
||||||
|
bool isTutorialMode, const vector<string> &dirList, string autoloadScenarioName) :
|
||||||
MenuState(program, mainMenu, "scenario")
|
MenuState(program, mainMenu, "scenario")
|
||||||
{
|
{
|
||||||
containerName = "Scenario";
|
containerName = "Scenario";
|
||||||
|
this->isTutorialMode = isTutorialMode;
|
||||||
|
|
||||||
enableScenarioTexturePreview = Config::getInstance().getBool("EnableScenarioTexturePreview","true");
|
enableScenarioTexturePreview = Config::getInstance().getBool("EnableScenarioTexturePreview","true");
|
||||||
scenarioLogoTexture=NULL;
|
scenarioLogoTexture=NULL;
|
||||||
previewLoadDelayTimer=time(NULL);
|
previewLoadDelayTimer=time(NULL);
|
||||||
@@ -88,7 +91,12 @@ MenuStateScenario::MenuStateScenario(Program *program, MainMenu *mainMenu, const
|
|||||||
buttonReturn.setText(lang.get("Return"));
|
buttonReturn.setText(lang.get("Return"));
|
||||||
buttonPlayNow.setText(lang.get("PlayNow"));
|
buttonPlayNow.setText(lang.get("PlayNow"));
|
||||||
|
|
||||||
labelScenario.setText(lang.get("Scenario"));
|
if(this->isTutorialMode == true) {
|
||||||
|
labelScenario.setText(lang.get("Tutorial"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
labelScenario.setText(lang.get("Scenario"));
|
||||||
|
}
|
||||||
|
|
||||||
//scenario listbox
|
//scenario listbox
|
||||||
findDirs(dirList, results);
|
findDirs(dirList, results);
|
||||||
@@ -96,7 +104,14 @@ MenuStateScenario::MenuStateScenario(Program *program, MainMenu *mainMenu, const
|
|||||||
//printf("scenarioFiles[0] [%s]\n",scenarioFiles[0].c_str());
|
//printf("scenarioFiles[0] [%s]\n",scenarioFiles[0].c_str());
|
||||||
|
|
||||||
if(results.empty() == true) {
|
if(results.empty() == true) {
|
||||||
throw megaglest_runtime_error("There are no scenarios found to load");
|
//throw megaglest_runtime_error("There are no scenarios found to load");
|
||||||
|
mainMessageBoxState=1;
|
||||||
|
if(this->isTutorialMode == true) {
|
||||||
|
showMessageBox( "Error: There are no tutorials found to load", "Error detected", false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
showMessageBox( "Error: There are no scenarios found to load", "Error detected", false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for(int i= 0; i<results.size(); ++i){
|
for(int i= 0; i<results.size(); ++i){
|
||||||
results[i] = formatString(results[i]);
|
results[i] = formatString(results[i]);
|
||||||
@@ -104,8 +119,10 @@ MenuStateScenario::MenuStateScenario(Program *program, MainMenu *mainMenu, const
|
|||||||
listBoxScenario.setItems(results);
|
listBoxScenario.setItems(results);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
loadScenarioInfo(Scenario::getScenarioPath(dirList, scenarioFiles[listBoxScenario.getSelectedItemIndex()]), &scenarioInfo );
|
if(listBoxScenario.getSelectedItemIndex() > 0) {
|
||||||
labelInfo.setText(scenarioInfo.desc);
|
loadScenarioInfo(Scenario::getScenarioPath(dirList, scenarioFiles[listBoxScenario.getSelectedItemIndex()]), &scenarioInfo );
|
||||||
|
labelInfo.setText(scenarioInfo.desc);
|
||||||
|
}
|
||||||
|
|
||||||
GraphicComponent::applyAllCustomProperties(containerName);
|
GraphicComponent::applyAllCustomProperties(containerName);
|
||||||
}
|
}
|
||||||
@@ -281,23 +298,25 @@ void MenuStateScenario::loadScenarioInfo(string file, ScenarioInfo *scenarioInfo
|
|||||||
|
|
||||||
void MenuStateScenario::loadScenarioPreviewTexture(){
|
void MenuStateScenario::loadScenarioPreviewTexture(){
|
||||||
if(enableScenarioTexturePreview == true) {
|
if(enableScenarioTexturePreview == true) {
|
||||||
GameSettings gameSettings;
|
if(listBoxScenario.getSelectedItemIndex() >= 0) {
|
||||||
loadGameSettings(&scenarioInfo, &gameSettings);
|
GameSettings gameSettings;
|
||||||
|
loadGameSettings(&scenarioInfo, &gameSettings);
|
||||||
|
|
||||||
string scenarioLogo = "";
|
string scenarioLogo = "";
|
||||||
bool loadingImageUsed = false;
|
bool loadingImageUsed = false;
|
||||||
|
|
||||||
Game::extractScenarioLogoFile(&gameSettings, scenarioLogo, loadingImageUsed);
|
Game::extractScenarioLogoFile(&gameSettings, scenarioLogo, loadingImageUsed);
|
||||||
|
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] scenarioLogo [%s]\n",__FILE__,__FUNCTION__,__LINE__,scenarioLogo.c_str());
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] scenarioLogo [%s]\n",__FILE__,__FUNCTION__,__LINE__,scenarioLogo.c_str());
|
||||||
|
|
||||||
if(scenarioLogo != "") {
|
if(scenarioLogo != "") {
|
||||||
cleanupPreviewTexture();
|
cleanupPreviewTexture();
|
||||||
scenarioLogoTexture = Renderer::findFactionLogoTexture(scenarioLogo);
|
scenarioLogoTexture = Renderer::findFactionLogoTexture(scenarioLogo);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cleanupPreviewTexture();
|
cleanupPreviewTexture();
|
||||||
scenarioLogoTexture = NULL;
|
scenarioLogoTexture = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -47,8 +47,10 @@ private:
|
|||||||
bool enableScenarioTexturePreview;
|
bool enableScenarioTexturePreview;
|
||||||
Texture2D *scenarioLogoTexture;
|
Texture2D *scenarioLogoTexture;
|
||||||
|
|
||||||
|
bool isTutorialMode;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MenuStateScenario(Program *program, MainMenu *mainMenu, const vector<string> &dirList, string autoloadScenarioName="");
|
MenuStateScenario(Program *program, MainMenu *mainMenu, bool isTutorialMode, const vector<string> &dirList, string autoloadScenarioName="");
|
||||||
virtual ~MenuStateScenario();
|
virtual ~MenuStateScenario();
|
||||||
|
|
||||||
void mouseClick(int x, int y, MouseButton mouseButton);
|
void mouseClick(int x, int y, MouseButton mouseButton);
|
||||||
|
@@ -39,6 +39,8 @@ private:
|
|||||||
int argumentCount;
|
int argumentCount;
|
||||||
string currentLuaFunction;
|
string currentLuaFunction;
|
||||||
bool currentLuaFunctionIsValid;
|
bool currentLuaFunctionIsValid;
|
||||||
|
string sandboxWrapperFunctionName;
|
||||||
|
string sandboxCode;
|
||||||
|
|
||||||
void DumpGlobals();
|
void DumpGlobals();
|
||||||
|
|
||||||
@@ -46,12 +48,16 @@ public:
|
|||||||
LuaScript();
|
LuaScript();
|
||||||
~LuaScript();
|
~LuaScript();
|
||||||
|
|
||||||
void loadCode(const string &code, const string &name);
|
void loadCode(string code, string name);
|
||||||
|
|
||||||
void beginCall(const string& functionName);
|
void beginCall(string functionName);
|
||||||
void endCall();
|
void endCall();
|
||||||
|
|
||||||
void registerFunction(LuaFunction luaFunction, const string &functionName);
|
int runCode(const string code);
|
||||||
|
void setSandboxWrapperFunctionName(string name);
|
||||||
|
void setSandboxCode(string code);
|
||||||
|
|
||||||
|
void registerFunction(LuaFunction luaFunction, string functionName);
|
||||||
|
|
||||||
void saveGame(XmlNode *rootNode);
|
void saveGame(XmlNode *rootNode);
|
||||||
void loadGame(const XmlNode *rootNode);
|
void loadGame(const XmlNode *rootNode);
|
||||||
|
@@ -265,6 +265,8 @@ string executable_path(string exeName,bool includeExeNameInPath=false);
|
|||||||
|
|
||||||
bool valid_utf8_file(const char* file_name);
|
bool valid_utf8_file(const char* file_name);
|
||||||
|
|
||||||
|
string getFileTextContents(string path);
|
||||||
|
|
||||||
class ValueCheckerVault {
|
class ValueCheckerVault {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@@ -50,6 +50,8 @@ LuaScript::LuaScript() {
|
|||||||
|
|
||||||
currentLuaFunction = "";
|
currentLuaFunction = "";
|
||||||
currentLuaFunctionIsValid = false;
|
currentLuaFunctionIsValid = false;
|
||||||
|
sandboxWrapperFunctionName = "";
|
||||||
|
sandboxCode = "";
|
||||||
luaState= luaL_newstate();
|
luaState= luaL_newstate();
|
||||||
|
|
||||||
luaL_openlibs(luaState);
|
luaL_openlibs(luaState);
|
||||||
@@ -409,7 +411,7 @@ LuaScript::~LuaScript() {
|
|||||||
lua_close(luaState);
|
lua_close(luaState);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::loadCode(const string &code, const string &name){
|
void LuaScript::loadCode(string code, string name){
|
||||||
Lua_STREFLOP_Wrapper streflopWrapper;
|
Lua_STREFLOP_Wrapper streflopWrapper;
|
||||||
|
|
||||||
//printf("Code [%s]\nName [%s]\n",code.c_str(),name.c_str());
|
//printf("Code [%s]\nName [%s]\n",code.c_str(),name.c_str());
|
||||||
@@ -443,7 +445,22 @@ void LuaScript::loadCode(const string &code, const string &name){
|
|||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] name [%s], errorCode = %d\n",__FILE__,__FUNCTION__,__LINE__,name.c_str(),errorCode);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] name [%s], errorCode = %d\n",__FILE__,__FUNCTION__,__LINE__,name.c_str(),errorCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::beginCall(const string& functionName) {
|
void LuaScript::setSandboxWrapperFunctionName(string name) {
|
||||||
|
sandboxWrapperFunctionName = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LuaScript::setSandboxCode(string code) {
|
||||||
|
sandboxCode = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LuaScript::runCode(string code) {
|
||||||
|
Lua_STREFLOP_Wrapper streflopWrapper;
|
||||||
|
|
||||||
|
int errorCode = luaL_dostring(luaState,code.c_str());
|
||||||
|
return errorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LuaScript::beginCall(string functionName) {
|
||||||
Lua_STREFLOP_Wrapper streflopWrapper;
|
Lua_STREFLOP_Wrapper streflopWrapper;
|
||||||
|
|
||||||
currentLuaFunction = functionName;
|
currentLuaFunction = functionName;
|
||||||
@@ -451,8 +468,19 @@ void LuaScript::beginCall(const string& functionName) {
|
|||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] functionName [%s]\n",__FILE__,__FUNCTION__,__LINE__,functionName.c_str());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] functionName [%s]\n",__FILE__,__FUNCTION__,__LINE__,functionName.c_str());
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] functionName [%s]\n",__FILE__,__FUNCTION__,__LINE__,functionName.c_str());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] functionName [%s]\n",__FILE__,__FUNCTION__,__LINE__,functionName.c_str());
|
||||||
|
|
||||||
|
//string funcLuaFunction = functionName;
|
||||||
|
// if(sandboxWrapperFunctionName != "" && sandboxCode != "") {
|
||||||
|
// int errorCode= runCode(sandboxCode);
|
||||||
|
// if(errorCode !=0 ) {
|
||||||
|
// throw megaglest_runtime_error("Error calling lua function [" + currentLuaFunction + "] error: " + errorToString(errorCode));
|
||||||
|
// }
|
||||||
|
// //functionName = sandboxWrapperFunctionName;
|
||||||
|
// }
|
||||||
lua_getglobal(luaState, functionName.c_str());
|
lua_getglobal(luaState, functionName.c_str());
|
||||||
|
|
||||||
currentLuaFunctionIsValid = lua_isfunction(luaState,lua_gettop(luaState));
|
currentLuaFunctionIsValid = lua_isfunction(luaState,lua_gettop(luaState));
|
||||||
|
|
||||||
|
//printf("currentLuaFunctionIsValid = %d functionName [%s]\n",currentLuaFunctionIsValid,functionName.c_str());
|
||||||
argumentCount= 0;
|
argumentCount= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -462,9 +490,32 @@ void LuaScript::endCall() {
|
|||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] currentLuaFunction [%s], currentLuaFunctionIsValid = %d\n",__FILE__,__FUNCTION__,__LINE__,currentLuaFunction.c_str(),currentLuaFunctionIsValid);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] currentLuaFunction [%s], currentLuaFunctionIsValid = %d\n",__FILE__,__FUNCTION__,__LINE__,currentLuaFunction.c_str(),currentLuaFunctionIsValid);
|
||||||
|
|
||||||
if(currentLuaFunctionIsValid == true) {
|
if(currentLuaFunctionIsValid == true) {
|
||||||
int errorCode= lua_pcall(luaState, argumentCount, 0, 0);
|
if(sandboxWrapperFunctionName != "" && sandboxCode != "") {
|
||||||
if(errorCode !=0 ) {
|
//lua_pushstring(luaState, currentLuaFunction.c_str()); // push 1st argument, the real lua function
|
||||||
throw megaglest_runtime_error("Error calling lua function [" + currentLuaFunction + "] error: " + errorToString(errorCode));
|
//argumentCount = 1;
|
||||||
|
|
||||||
|
string safeWrapper = sandboxWrapperFunctionName + " [[" + currentLuaFunction + "()]]";
|
||||||
|
printf("Trying to execute [%s]\n",safeWrapper.c_str());
|
||||||
|
int errorCode= runCode(safeWrapper);
|
||||||
|
if(errorCode !=0 ) {
|
||||||
|
throw megaglest_runtime_error("Error calling lua function [" + currentLuaFunction + "] error: " + errorToString(errorCode));
|
||||||
|
}
|
||||||
|
|
||||||
|
//printf("Trying to execute [%s]\n",currentLuaFunction.c_str());
|
||||||
|
//lua_getglobal(luaState, sandboxWrapperFunctionName.c_str());
|
||||||
|
//argumentCount = 1;
|
||||||
|
//lua_pushstring( luaState, currentLuaFunction.c_str() );
|
||||||
|
|
||||||
|
// int errorCode= lua_pcall(luaState, argumentCount, 0, 0);
|
||||||
|
// if(errorCode !=0 ) {
|
||||||
|
// throw megaglest_runtime_error("Error calling lua function [" + currentLuaFunction + "] error: " + errorToString(errorCode));
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int errorCode= lua_pcall(luaState, argumentCount, 0, 0);
|
||||||
|
if(errorCode !=0 ) {
|
||||||
|
throw megaglest_runtime_error("Error calling lua function [" + currentLuaFunction + "] error: " + errorToString(errorCode));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -473,7 +524,7 @@ void LuaScript::endCall() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::registerFunction(LuaFunction luaFunction, const string &functionName) {
|
void LuaScript::registerFunction(LuaFunction luaFunction, string functionName) {
|
||||||
Lua_STREFLOP_Wrapper streflopWrapper;
|
Lua_STREFLOP_Wrapper streflopWrapper;
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] functionName [%s]\n",__FILE__,__FUNCTION__,__LINE__,functionName.c_str());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] functionName [%s]\n",__FILE__,__FUNCTION__,__LINE__,functionName.c_str());
|
||||||
|
@@ -2114,6 +2114,33 @@ bool valid_utf8_file(const char* file_name) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string getFileTextContents(string path) {
|
||||||
|
#if defined(WIN32) && !defined(__MINGW32__)
|
||||||
|
FILE *fp = _wfopen(utf8_decode(path).c_str(), L"rb");
|
||||||
|
ifstream xmlFile(fp);
|
||||||
|
#else
|
||||||
|
ifstream xmlFile(path.c_str(),ios::binary);
|
||||||
|
#endif
|
||||||
|
if(xmlFile.is_open() == false) {
|
||||||
|
throw megaglest_runtime_error("Can not open file: [" + path + "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
xmlFile.unsetf(ios::skipws);
|
||||||
|
|
||||||
|
// Determine stream size
|
||||||
|
xmlFile.seekg(0, ios::end);
|
||||||
|
streampos size = xmlFile.tellg();
|
||||||
|
xmlFile.seekg(0);
|
||||||
|
|
||||||
|
// Load data and add terminating 0
|
||||||
|
vector<char> buffer;
|
||||||
|
buffer.resize(size + (streampos)1);
|
||||||
|
xmlFile.read(&buffer.front(), static_cast<streamsize>(size));
|
||||||
|
buffer[size] = 0;
|
||||||
|
|
||||||
|
return &buffer.front();
|
||||||
|
}
|
||||||
|
|
||||||
// =====================================
|
// =====================================
|
||||||
// ModeInfo
|
// ModeInfo
|
||||||
// =====================================
|
// =====================================
|
||||||
|
Reference in New Issue
Block a user