diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common/resources/resourcestreambuffer.cpp | 1 | ||||
-rw-r--r-- | src/graphics/engine/modelfile.cpp | 6 | ||||
-rw-r--r-- | src/graphics/engine/modelmanager.cpp | 2 | ||||
-rw-r--r-- | src/object/robotmain.cpp | 13 | ||||
-rw-r--r-- | src/script/script.cpp | 24 |
5 files changed, 26 insertions, 20 deletions
diff --git a/src/common/resources/resourcestreambuffer.cpp b/src/common/resources/resourcestreambuffer.cpp index e7be51d..ed6e738 100644 --- a/src/common/resources/resourcestreambuffer.cpp +++ b/src/common/resources/resourcestreambuffer.cpp @@ -27,6 +27,7 @@ CResourceStreamBuffer::CResourceStreamBuffer(size_t buffer_size) : m_buffer_size } m_buffer = new char[buffer_size]; + m_file = nullptr; } diff --git a/src/graphics/engine/modelfile.cpp b/src/graphics/engine/modelfile.cpp index 0e3cbf8..5f10ff1 100644 --- a/src/graphics/engine/modelfile.cpp +++ b/src/graphics/engine/modelfile.cpp @@ -436,7 +436,7 @@ bool CModelFile::ReadModel(const std::string& fileName) CInputStream stream; stream.open(fileName.c_str()); - if (!stream.good()) + if (!stream.is_open()) { GetLogger()->Error("Could not open file '%s'\n", fileName.c_str()); return false; @@ -827,7 +827,7 @@ bool CModelFile::ReadTextModel(const std::string& fileName) { CInputStream stream; stream.open(fileName.c_str()); - if (!stream.good()) + if (!stream.is_open()) { GetLogger()->Error("Could not open file '%s'\n", fileName.c_str()); return false; @@ -1024,7 +1024,7 @@ bool CModelFile::ReadBinaryModel(const std::string& fileName) { CInputStream stream; stream.open(fileName.c_str()); - if (!stream.good()) + if (!stream.is_open()) { GetLogger()->Error("Could not open file '%s'\n", fileName.c_str()); return false; diff --git a/src/graphics/engine/modelmanager.cpp b/src/graphics/engine/modelmanager.cpp index fc201fa..6ee0b86 100644 --- a/src/graphics/engine/modelmanager.cpp +++ b/src/graphics/engine/modelmanager.cpp @@ -47,7 +47,7 @@ bool CModelManager::LoadModel(const std::string& fileName, bool mirrored) if (CApplication::GetInstance().IsDebugModeActive(DEBUG_MODELS)) modelFile.SetPrintDebugInfo(true); - if (!modelFile.ReadModel(fileName)) + if (!modelFile.ReadModel("models/" + fileName)) { GetLogger()->Error("Loading model '%s' failed\n", fileName.c_str()); return false; diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 1c75137..87cd5fc 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -29,6 +29,8 @@ #include "common/profile.h" #include "common/restext.h" +#include "common/resources/inputstream.h" + #include "graphics/engine/camera.h" #include "graphics/engine/cloud.h" #include "graphics/engine/engine.h" @@ -4009,8 +4011,11 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) std::string tempLine; m_dialog->BuildSceneName(tempLine, base, rank); strcpy(filename, tempLine.c_str()); - FILE* file = fopen(filename, "r"); - if (file == NULL) return; + + CInputStream stream; + stream.open(filename); + + if (!stream.is_open()) return; int rankObj = 0; int rankGadget = 0; @@ -4023,7 +4028,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) * may speed up loading */ - while (fgets(line, 500, file) != NULL) + while (stream.getline(line, 500)) { lineNum++; for (int i = 0; i < 500; i++) @@ -5062,7 +5067,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) GetLogger()->Error("Syntax error in file '%s' (line %d): Unknown command: %s", filename, lineNum, line); // Don't add \n at the end of log message - it's included in line variable } - fclose(file); + stream.close(); if (read[0] == 0) CompileScript(soluce); // compiles all scripts diff --git a/src/script/script.cpp b/src/script/script.cpp index 11aa5c1..f59d27e 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -24,6 +24,9 @@ #include "common/restext.h" #include "common/stringutils.h" +#include "common/resources/inputstream.h" +#include "common/resources/resourcemanager.h" + #include "graphics/engine/terrain.h" #include "graphics/engine/water.h" #include "graphics/engine/text.h" @@ -50,6 +53,7 @@ #include "ui/edit.h" #include "ui/list.h" #include "ui/displaytext.h" +#include <test/cbot/CBot_console/CClass.h> #include <stdio.h> @@ -4363,7 +4367,6 @@ void CScript::GetError(std::string& error) void CScript::New(Ui::CEdit* edit, const char* name) { - FILE *file = NULL; char res[100]; char text[100]; char script[500]; @@ -4407,17 +4410,17 @@ void CScript::New(Ui::CEdit* edit, const char* name) if ( sf[0] != 0 ) // Load an empty program specific? { std::string filename = sf; - file = fopen(filename.c_str(), "rb"); - if ( file != NULL ) + CInputStream stream; + stream.open(filename); + + if (stream.is_open()) { - fseek(file, 0, SEEK_END); - len = ftell(file); - fseek(file, 0, SEEK_SET); + len = stream.size(); if ( len > 500-1 ) len = 500-1; - fread(buffer, 1, len, file); + stream.read(buffer, len); buffer[len] = 0; - fclose(file); + stream.close(); cursor1 = 0; i = 0; @@ -4494,12 +4497,9 @@ bool CScript::SendScript(const char* text) bool CScript::ReadScript(const char* filename) { - FILE* file; Ui::CEdit* edit; - file = fopen(filename, "rb"); - if ( file == NULL ) return false; - fclose(file); + if (!CResourceManager::Exists(filename)) return false; delete[] m_script; m_script = nullptr; |