Initial commit of IcarusDownloadManager

This commit is contained in:
amazing-username
2019-03-17 17:05:27 -04:00
commit 9dcf70b157
12 changed files with 306 additions and 0 deletions
+65
View File
@@ -0,0 +1,65 @@
#include<iostream>
#include<fstream>
#include"FileManager.h"
using std::cout;
using std::endl;
using std::ifstream;
using std::ofstream;
using std::string;
namespace Managers
{
FileManager::FileManager() {}
FileManager::FileManager(string filePath)
{
this->filePath = filePath;
readFile();
}
void FileManager::saveFile(string newFilePath)
{
if (!fileRead)
readFile();
ofstream of{newFilePath, ofstream::binary};
of.write(fileBuffer, fileBufferLength);
of.close();
}
void FileManager::readFile()
{
ifstream is{filePath, ifstream::binary};
if (is)
{
is.seekg (0, is.end);
fileBufferLength = is.tellg();
is.seekg (0, is.beg);
fileBuffer = new char [fileBufferLength];
cout<< "Reading "<<fileBufferLength<<" characters... "<<endl;;
// read data as a block:
is.read (fileBuffer,fileBufferLength);
if (is)
cout<<"all characters read successfully.";
else
cout<<"error: only "<<is.gcount()<<" could be read";
cout<<endl;
is.close();
fileRead = true;
}
}
void FileManager::modifyFilePath(string filePath)
{
this->filePath = filePath;
}
char* FileManager::retrieveFileBuffer() const
{
return fileBuffer;
}
}
+28
View File
@@ -0,0 +1,28 @@
#ifndef FILEMANAGER_H_
#define FILEMANAGER_H_
#include<string>
namespace Managers
{
class FileManager
{
public:
FileManager();
FileManager(std::string);
void saveFile(std::string);
void modifyFilePath(std::string);
char* retrieveFileBuffer() const;
private:
void readFile();
std::string filePath;
char* fileBuffer;
bool fileRead;
int fileBufferLength;
};
}
#endif
Binary file not shown.