WoW Model Viewer
Your premiere tool for viewing, equipping and animating World of Warcraft models.
Loading...
Searching...
No Matches
HardDriveFile.cpp
Go to the documentation of this file.
1#include "HardDriveFile.h"
2
3#include "Logger.h"
4
5HardDriveFile::HardDriveFile(std::string path, std::string real, int id)
6 : CASCFile(std::move(path), id), opened(false), realpath(std::move(real)), file(nullptr)
7{
8}
9
14
16{
17 file = new std::ifstream(realpath, std::ios::binary);
18
19 if (!file->is_open())
20 {
21 LOG_ERROR << "Opening" << filepath << "failed.";
22 delete file;
23 file = nullptr;
24 return false;
25 }
26
27 opened = true;
28 return true;
29}
30
32{
33 if (opened)
34 return true;
35 else
36 return false;
37}
38
39bool HardDriveFile::getFileSize(unsigned long long& s)
40{
41 if (!file || !file->is_open())
42 return false;
43
44 const auto cur = file->tellg();
45 file->seekg(0, std::ios::end);
46 s = static_cast<unsigned long long>(file->tellg());
47 file->seekg(cur);
48 return true;
49}
50
52{
53 if (!file || !file->is_open())
54 return 0;
55
56 file->seekg(0, std::ios::beg);
57 file->read(reinterpret_cast<char*>(buffer), size);
58 const unsigned long s = static_cast<unsigned long>(file->gcount());
59 file->close();
60 delete file;
61 file = nullptr;
62 return s;
63}
64
66{
67#ifdef DEBUG_READ
68 LOG_INFO << __FUNCTION__ << "Closing" << filepath;
69#endif
70 if (opened)
71 opened = false;
72
73 return true;
74}
#define LOG_ERROR
Definition Logger.h:11
#define LOG_INFO
Definition Logger.h:10
GameFile implementation that reads from a CASC storage archive.
Definition CASCFile.h:20
std::string filepath
Definition GameFile.h:84
unsigned char * buffer
Definition GameFile.h:82
unsigned long long size
Definition GameFile.h:83
bool close()
Close the file and release the internal buffer.
Definition GameFile.cpp:74
virtual bool isAlreadyOpened()
virtual bool getFileSize(unsigned long long &s)
virtual unsigned long readFile()
virtual bool openFile()
HardDriveFile(std::string path, std::string realpath, int id=-1)
virtual bool doPostCloseOperation()
std::string realpath
std::ifstream * file