diff --git a/src/common/cutscenes/movieplayer.cpp b/src/common/cutscenes/movieplayer.cpp index dfb7d3a4c7..d9b02541ef 100644 --- a/src/common/cutscenes/movieplayer.cpp +++ b/src/common/cutscenes/movieplayer.cpp @@ -515,7 +515,7 @@ public: } else if (soundtrack >= 0) { - FileReader reader = fileSystem.OpenFileReader(soundtrack); + FileReader reader = fileSystem.ReopenFileReader(soundtrack); if (reader.isOpen()) { MusicStream = ZMusic_OpenSong(GetMusicReader(reader), MDEV_DEFAULT, nullptr); @@ -838,10 +838,10 @@ MoviePlayer* OpenMovie(const char* filename, TArray& ans, const int* framet { auto fn = StripExtension(filename); DefaultExtension(fn, ".ivf"); - fr = fileSystem.OpenFileReader(fn.GetChars()); + fr = fileSystem.ReopenFileReader(fn.GetChars()); } - if (!fr.isOpen()) fr = fileSystem.OpenFileReader(filename); + if (!fr.isOpen()) fr = fileSystem.ReopenFileReader(filename); if (!fr.isOpen()) { size_t nLen = strlen(filename); @@ -849,7 +849,7 @@ MoviePlayer* OpenMovie(const char* filename, TArray& ans, const int* framet if (nLen >= 3 && isalpha(filename[0]) && filename[1] == ':' && filename[2] == '/') { filename += 3; - fr = fileSystem.OpenFileReader(filename); + fr = fileSystem.ReopenFileReader(filename); } if (!fr.isOpen()) { diff --git a/src/common/engine/sc_man.cpp b/src/common/engine/sc_man.cpp index e8423178d9..9849c2e21e 100644 --- a/src/common/engine/sc_man.cpp +++ b/src/common/engine/sc_man.cpp @@ -200,10 +200,10 @@ void FScanner :: OpenLumpNum (int lump) { Close (); { - auto mem = fileSystem.OpenFileReader(lump); - auto buff = ScriptBuffer.LockNewBuffer(mem.GetLength()); - mem.Read(buff, mem.GetLength()); - buff[mem.GetLength()] = 0; + auto len = fileSystem.FileLength(lump); + auto buff = ScriptBuffer.LockNewBuffer(len); + fileSystem.ReadFile(lump, buff); + buff[len] = 0; ScriptBuffer.UnlockBuffer(); } ScriptName = fileSystem.GetFileFullPath(lump).c_str(); diff --git a/src/common/filesystem/include/fs_filesystem.h b/src/common/filesystem/include/fs_filesystem.h index a40ee92fbc..4d7ca8c153 100644 --- a/src/common/filesystem/include/fs_filesystem.h +++ b/src/common/filesystem/include/fs_filesystem.h @@ -96,6 +96,7 @@ public: FileReader OpenFileReader(int lump); // opens a reader that redirects to the containing file's one. FileReader ReopenFileReader(int lump, bool alwayscache = false); // opens an independent reader. FileReader OpenFileReader(const char* name); + FileReader ReopenFileReader(const char* name, bool alwayscache = false); int FindLump (const char *name, int *lastlump, bool anyns=false); // [RH] Find lumps with duplication int FindLumpMulti (const char **names, int *lastlump, bool anyns = false, int *nameindex = NULL); // same with multiple possible names diff --git a/src/common/filesystem/source/filesystem.cpp b/src/common/filesystem/source/filesystem.cpp index 966e3de38d..fe58918992 100644 --- a/src/common/filesystem/source/filesystem.cpp +++ b/src/common/filesystem/source/filesystem.cpp @@ -1329,9 +1329,18 @@ FileReader FileSystem::ReopenFileReader(int lump, bool alwayscache) FileReader FileSystem::OpenFileReader(const char* name) { + FileReader fr; auto lump = CheckNumForFullName(name); - if (lump < 0) return FileReader(); - else return OpenFileReader(lump); + if (lump >= 0) fr = OpenFileReader(lump); + return fr; +} + +FileReader FileSystem::ReopenFileReader(const char* name, bool alwayscache) +{ + FileReader fr; + auto lump = CheckNumForFullName(name); + if (lump >= 0) fr = ReopenFileReader(lump, alwayscache); + return fr; } //========================================================================== diff --git a/src/common/rendering/gl/gl_shaderprogram.cpp b/src/common/rendering/gl/gl_shaderprogram.cpp index d5e8dd3210..1c4fd48a4d 100644 --- a/src/common/rendering/gl/gl_shaderprogram.cpp +++ b/src/common/rendering/gl/gl_shaderprogram.cpp @@ -89,7 +89,6 @@ void FShaderProgram::Compile(ShaderType type, const char *lumpName, const char * { int lump = fileSystem.CheckNumForFullName(lumpName); if (lump == -1) I_FatalError("Unable to load '%s'", lumpName); - auto sp = fileSystem.ReadFile(lump); FString code = GetStringFromLump(lump); Compile(type, lumpName, code, defines, maxGlslVersion); diff --git a/src/common/rendering/gles/gles_shader.cpp b/src/common/rendering/gles/gles_shader.cpp index f037e3e4a1..dba9a233a6 100644 --- a/src/common/rendering/gles/gles_shader.cpp +++ b/src/common/rendering/gles/gles_shader.cpp @@ -383,11 +383,9 @@ bool FShader::Load(const char * name, const char * vert_prog_lump_, const char * int vp_lump = fileSystem.CheckNumForFullName(vert_prog_lump.GetChars(), 0); if (vp_lump == -1) I_Error("Unable to load '%s'", vert_prog_lump.GetChars()); - auto vp_data = fileSystem.ReadFile(vp_lump); int fp_lump = fileSystem.CheckNumForFullName(frag_prog_lump.GetChars(), 0); if (fp_lump == -1) I_Error("Unable to load '%s'", frag_prog_lump.GetChars()); - auto fp_data = fileSystem.ReadFile(fp_lump); @@ -422,7 +420,6 @@ bool FShader::Load(const char * name, const char * vert_prog_lump_, const char * { int pp_lump = fileSystem.CheckNumForFullName(proc_prog_lump.GetChars()); if (pp_lump == -1) I_Error("Unable to load '%s'", proc_prog_lump.GetChars()); - auto ppf = fileSystem.ReadFile(pp_lump); FString pp_data = GetStringFromLump(pp_lump); if (pp_data.IndexOf("ProcessMaterial") < 0 && pp_data.IndexOf("SetupMaterial") < 0) diff --git a/src/common/rendering/gles/gles_shaderprogram.cpp b/src/common/rendering/gles/gles_shaderprogram.cpp index a6f0453c28..efc94c71df 100644 --- a/src/common/rendering/gles/gles_shaderprogram.cpp +++ b/src/common/rendering/gles/gles_shaderprogram.cpp @@ -89,7 +89,6 @@ void FShaderProgram::Compile(ShaderType type, const char *lumpName, const char * { int lump = fileSystem.CheckNumForFullName(lumpName); if (lump == -1) I_FatalError("Unable to load '%s'", lumpName); - auto sp = fileSystem.ReadFile(lump); FString code = GetStringFromLump(lump); Compile(type, lumpName, code, defines, maxGlslVersion); } diff --git a/src/common/rendering/vulkan/shaders/vk_ppshader.cpp b/src/common/rendering/vulkan/shaders/vk_ppshader.cpp index dc4ace0f95..dcf72a06d2 100644 --- a/src/common/rendering/vulkan/shaders/vk_ppshader.cpp +++ b/src/common/rendering/vulkan/shaders/vk_ppshader.cpp @@ -69,7 +69,6 @@ FString VkPPShader::LoadShaderCode(const FString &lumpName, const FString &defin { int lump = fileSystem.CheckNumForFullName(lumpName.GetChars()); if (lump == -1) I_FatalError("Unable to load '%s'", lumpName.GetChars()); - auto sp = fileSystem.ReadFile(lump); FString code = GetStringFromLump(lump); FString patchedCode; diff --git a/src/common/rendering/vulkan/shaders/vk_shader.cpp b/src/common/rendering/vulkan/shaders/vk_shader.cpp index 227b8cca6c..618fa2ca9b 100644 --- a/src/common/rendering/vulkan/shaders/vk_shader.cpp +++ b/src/common/rendering/vulkan/shaders/vk_shader.cpp @@ -475,7 +475,6 @@ FString VkShaderManager::LoadPrivateShaderLump(const char *lumpname) { int lump = fileSystem.CheckNumForFullName(lumpname, 0); if (lump == -1) I_Error("Unable to load '%s'", lumpname); - auto data = fileSystem.ReadFile(lump); return GetStringFromLump(lump); } diff --git a/src/d_main.cpp b/src/d_main.cpp index 6e7155840d..8b26b1a36c 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -4009,3 +4009,14 @@ CCMD(fs_dir) Printf(PRINT_HIGH | PRINT_NONOTIFY, "%s%-64s %-15s (%5d) %10d %s %s\n", hidden ? TEXTCOLOR_RED : TEXTCOLOR_UNTRANSLATED, fn1, fns, fnid, length, container, hidden ? "(h)" : ""); } } + +CCMD(type) +{ + if (argv.argc() < 2) return; + int lump = fileSystem.CheckNumForFullName(argv[1]); + if (lump >= 0) + { + auto data = fileSystem.ReadFile(lump); + Printf("%.*s\n", data.size(), data.string()); + } +} \ No newline at end of file