lib/file: Fix isOpen not being set properly when closing and reopening; add destructor

Soda
BodgeMaster 2022-10-05 05:02:58 +02:00
parent 39c5940200
commit 4cb1206839
2 changed files with 8 additions and 1 deletions

View File

@ -28,9 +28,13 @@ File::File(std::string path, char mode, uint64_t cursorPosition): mode(mode), pa
std::filesystem::path filePath = path;
this->size = ErrorOr<uint64_t>(std::filesystem::file_size(filePath));
this->open();
this->isOpen = true;
}
File::~File() {
if (this->isOpen) {
this->fileStream.close();
}
}
void File::open(){
switch(this->mode){
@ -49,6 +53,7 @@ void File::open(){
break;
}
this->isOpen = this->fileStream.is_open();
}
void File::close(){

View File

@ -45,6 +45,8 @@ class File {
ErrorOr<uint64_t> size;
File() {};
~File();
void open();
void close();