diff --git a/framework/csharp/stream.hpp b/framework/csharp/stream.hpp index 9e72787..4b3fad6 100644 --- a/framework/csharp/stream.hpp +++ b/framework/csharp/stream.hpp @@ -11,7 +11,7 @@ namespace xna { class Stream { public: virtual Int Length() = 0; - virtual Long Position() = 0; + virtual Long Position() = 0; virtual void Close() = 0; virtual Long Seek(Long offset, SeekOrigin const& origin, xna_error_nullarg) = 0; virtual Int Read(Byte* buffer, Int bufferLength, Int offset, Int count, xna_error_nullarg) = 0; @@ -68,8 +68,8 @@ namespace xna { FileStream(std::string const& path){ int flags = std::fstream::in | std::fstream::out - | std::fstream::binary - | std::fstream::ate; + | std::fstream::binary; + //| std::fstream::ate; const auto exists = std::filesystem::exists(path); @@ -78,24 +78,20 @@ namespace xna { _fstream.open(path.c_str(), flags); - if (_fstream.is_open()) { - _filesize = _fstream.tellg(); - _fstream.seekg(0); - } - else { + if (!_fstream.is_open()) _closed = true; - } } ~FileStream() { Close(); - } + } - virtual constexpr Int Length() override { + virtual Int Length() override { if (_closed) return 0; - return static_cast(_filesize); + const auto end = endOfFile(); + return end; } virtual Long Position() override { @@ -124,6 +120,19 @@ namespace xna { std::streampos _filesize{ 0 }; std::fstream _fstream; bool _closed{ false }; + + Int endOfFile() { + if (_closed) + return 0; + + const auto pos = _fstream.tellg(); + _fstream.seekg(0, std::ios_base::end); + + const auto end = _fstream.tellg(); + _fstream.seekg(pos); + + return static_cast(end); + } }; } diff --git a/framework/xna.cpp b/framework/xna.cpp index 5a8a552..6261fae 100644 --- a/framework/xna.cpp +++ b/framework/xna.cpp @@ -26,8 +26,11 @@ class Game1 : public Game { }; int APIENTRY WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow) { - /*Game game; - game.Run();*/ + FileStream stream("D:/VS_EXPBSLN_x64_enu.CAB"); + auto pos = stream.Position(); + auto len = stream.Length(); + pos = stream.Position(); + Game1 game; game.Run(); return 0; diff --git a/framework/xna.h b/framework/xna.h index 4949622..c21405b 100644 --- a/framework/xna.h +++ b/framework/xna.h @@ -10,5 +10,6 @@ #include "platform/window-dx.hpp" #include "platform/device-dx.hpp" #include "platform/game-dx.hpp" +#include "csharp/stream.hpp" // TODO: Reference additional headers your program requires here.