-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstorage.cpp
42 lines (33 loc) · 912 Bytes
/
storage.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "virtual_machine.h"
virtual_machine::storage::storage()
{
std::filesystem::path current_path{ std::filesystem::current_path() };
std::filesystem::space_info space{ std::filesystem::space( current_path ) };
if ( open_stream( std::ios::in | std::ios::out | std::ios::app ) == false )
{
return;
}
max_size = space.available / 100;
storage_stream.ignore( max_size );
in_use = storage_stream.gcount();
close_stream();
path = ( current_path /= "storage.vm" ).generic_string();
}
bool virtual_machine::storage::open_stream( std::ios::openmode open_mode )
{
storage_stream.open( "storage.vm", open_mode );
storage_stream.clear();
if ( storage_stream.is_open() == false )
{
return false;
}
storage_stream.seekg( 0, std::ios::beg );
return true;
}
void virtual_machine::storage::close_stream()
{
if ( storage_stream.is_open() )
{
storage_stream.close();
}
}