mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Implementações em stream
This commit is contained in:
parent
1613ed905f
commit
c590f0dde4
@ -11,7 +11,7 @@ namespace xna {
|
|||||||
class Stream {
|
class Stream {
|
||||||
public:
|
public:
|
||||||
virtual Int Length() = 0;
|
virtual Int Length() = 0;
|
||||||
virtual Long Position() = 0;
|
virtual Long Position() = 0;
|
||||||
virtual void Close() = 0;
|
virtual void Close() = 0;
|
||||||
virtual Long Seek(Long offset, SeekOrigin const& origin, xna_error_nullarg) = 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;
|
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){
|
FileStream(std::string const& path){
|
||||||
int flags = std::fstream::in
|
int flags = std::fstream::in
|
||||||
| std::fstream::out
|
| std::fstream::out
|
||||||
| std::fstream::binary
|
| std::fstream::binary;
|
||||||
| std::fstream::ate;
|
//| std::fstream::ate;
|
||||||
|
|
||||||
const auto exists = std::filesystem::exists(path);
|
const auto exists = std::filesystem::exists(path);
|
||||||
|
|
||||||
@ -78,24 +78,20 @@ namespace xna {
|
|||||||
|
|
||||||
_fstream.open(path.c_str(), flags);
|
_fstream.open(path.c_str(), flags);
|
||||||
|
|
||||||
if (_fstream.is_open()) {
|
if (!_fstream.is_open())
|
||||||
_filesize = _fstream.tellg();
|
|
||||||
_fstream.seekg(0);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
_closed = true;
|
_closed = true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~FileStream() {
|
~FileStream() {
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual constexpr Int Length() override {
|
virtual Int Length() override {
|
||||||
if (_closed)
|
if (_closed)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return static_cast<Int>(_filesize);
|
const auto end = endOfFile();
|
||||||
|
return end;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Long Position() override {
|
virtual Long Position() override {
|
||||||
@ -124,6 +120,19 @@ namespace xna {
|
|||||||
std::streampos _filesize{ 0 };
|
std::streampos _filesize{ 0 };
|
||||||
std::fstream _fstream;
|
std::fstream _fstream;
|
||||||
bool _closed{ false };
|
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<Int>(end);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,8 +26,11 @@ class Game1 : public Game {
|
|||||||
};
|
};
|
||||||
|
|
||||||
int APIENTRY WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow) {
|
int APIENTRY WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow) {
|
||||||
/*Game game;
|
FileStream stream("D:/VS_EXPBSLN_x64_enu.CAB");
|
||||||
game.Run();*/
|
auto pos = stream.Position();
|
||||||
|
auto len = stream.Length();
|
||||||
|
pos = stream.Position();
|
||||||
|
|
||||||
Game1 game;
|
Game1 game;
|
||||||
game.Run();
|
game.Run();
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -10,5 +10,6 @@
|
|||||||
#include "platform/window-dx.hpp"
|
#include "platform/window-dx.hpp"
|
||||||
#include "platform/device-dx.hpp"
|
#include "platform/device-dx.hpp"
|
||||||
#include "platform/game-dx.hpp"
|
#include "platform/game-dx.hpp"
|
||||||
|
#include "csharp/stream.hpp"
|
||||||
|
|
||||||
// TODO: Reference additional headers your program requires here.
|
// TODO: Reference additional headers your program requires here.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user