Initial commit of IcarusDownloadManager
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
IcarusDownloadManager: src/Main.cpp src/Managers/FileManager.h src/Managers/FileManager.cpp src/Syncers/Upload.h src/Syncers/Upload.cpp src/Models/Song.h
|
||||
g++ -std=c++11 -I src/ src/Main.cpp src/Managers/FileManager.h src/Managers/FileManager.cpp src/Syncers/Upload.h src/Syncers/Upload.cpp src/Models/Song.h -o build/IcarusDownloadManager
|
||||
@@ -0,0 +1,46 @@
|
||||
#include<iostream>
|
||||
#include<string>
|
||||
|
||||
#include"Syncers/Upload.h"
|
||||
#include"Managers/FileManager.h"
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::string;
|
||||
|
||||
using Managers::FileManager;
|
||||
using Syncers::Upload;
|
||||
|
||||
string songPath;
|
||||
string newSongPath;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
cout<<"Argument size: "<<argc<<endl;
|
||||
switch(argc)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
break;
|
||||
case 3:
|
||||
songPath = argv[1];
|
||||
newSongPath = argv[2];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
cout<<"Song path: "<<songPath<<endl;
|
||||
Upload upS{songPath};
|
||||
upS.uploadSong();
|
||||
|
||||
FileManager fm{songPath};
|
||||
fm.saveFile(newSongPath);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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.
@@ -0,0 +1,5 @@
|
||||
#include"Song.h"
|
||||
|
||||
namespace Models
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef SONG_H_
|
||||
#define SONG_H_
|
||||
|
||||
#include<string>
|
||||
|
||||
#include<nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace Models
|
||||
{
|
||||
struct Song
|
||||
{
|
||||
int id;
|
||||
std::string title;
|
||||
std::string artist;
|
||||
std::string album;
|
||||
std::string genre;
|
||||
int year;
|
||||
int duration;
|
||||
char* songData;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,93 @@
|
||||
#include<iostream>
|
||||
#include<string>
|
||||
|
||||
#include<nlohmann/json.hpp>
|
||||
|
||||
#include"Upload.h"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::string;
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace Syncers
|
||||
{
|
||||
Upload::Upload() { }
|
||||
Upload::Upload(string filePath)
|
||||
{
|
||||
this->fMgr = Managers::FileManager{filePath};
|
||||
}
|
||||
|
||||
|
||||
void Upload::uploadSong()
|
||||
{
|
||||
configureSong();
|
||||
json jObj = serializeObject();
|
||||
printJsonData(jObj);
|
||||
|
||||
}
|
||||
|
||||
void Upload::configureSong()
|
||||
{
|
||||
int id = 0;
|
||||
string title = "What of it?";
|
||||
string artist = "Kuoth";
|
||||
string album = "I";
|
||||
string genre = "Untitled";
|
||||
int year = 2019;
|
||||
int duration = 260;
|
||||
|
||||
this->song = Models::Song{};
|
||||
this->song.id = id;
|
||||
this->song.title = title;
|
||||
this->song.artist = artist;
|
||||
this->song.album = album;
|
||||
this->song.genre = genre;
|
||||
this->song.year = year;
|
||||
this->song.duration = duration;
|
||||
this->song.songData = fMgr.retrieveFileBuffer();
|
||||
cout<<*song.songData<<endl;
|
||||
printSongDetails();
|
||||
}
|
||||
void Upload::printSongDetails()
|
||||
{
|
||||
cout<<"Song details: "<<endl;
|
||||
cout<<"Id: "<<song.id<<endl;
|
||||
cout<<"Title: "<<song.title<<endl;
|
||||
cout<<"Artist: "<<song.artist<<endl;
|
||||
cout<<"Album: "<<song.album<<endl;
|
||||
cout<<"Genre: "<<song.genre<<endl;
|
||||
cout<<"Year: "<<song.year<<endl;
|
||||
cout<<"Duration: "<<song.duration<<endl;
|
||||
}
|
||||
void Upload::printJsonData(json obj)
|
||||
{
|
||||
cout<<endl<<endl<<"JSon data: "<<endl;
|
||||
cout<<"id: "<<obj["id"]<<endl;
|
||||
cout<<"title: "<<obj["title"]<<endl;
|
||||
cout<<"artist: "<<obj["artist"]<<endl;
|
||||
cout<<"album: "<<obj["album"]<<endl;
|
||||
cout<<"genre: "<<obj["genre"]<<endl;
|
||||
cout<<"year: "<<obj["year"]<<endl;
|
||||
cout<<"duration: "<<obj["duration"]<<endl;
|
||||
cout<<"song_data: "<<obj["song_data"]<<endl;
|
||||
|
||||
cout<<endl<<endl;;
|
||||
}
|
||||
|
||||
json Upload::serializeObject()
|
||||
{
|
||||
json jObj{};
|
||||
jObj["id"] = song.id;
|
||||
jObj["title"] = song.title;
|
||||
jObj["artist"] = song.artist;
|
||||
jObj["album"] = song.album;
|
||||
jObj["genre"] = song.genre;
|
||||
jObj["year"] = song.year;
|
||||
jObj["duration"] = song.duration;
|
||||
jObj["song_data"] = *song.songData;
|
||||
|
||||
return jObj;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef UPLOAD_H_
|
||||
#define UPLOAD_H_
|
||||
|
||||
#include<string>
|
||||
|
||||
#include<nlohmann/json.hpp>
|
||||
|
||||
#include"Managers/FileManager.h"
|
||||
#include"Models/Song.h"
|
||||
|
||||
|
||||
namespace Syncers
|
||||
{
|
||||
class Upload
|
||||
{
|
||||
public:
|
||||
Upload();
|
||||
Upload(std::string);
|
||||
|
||||
void uploadSong();
|
||||
|
||||
private:
|
||||
Managers::FileManager fMgr;
|
||||
Models::Song song;
|
||||
std::string apiUrl{"http://192.168.1.24"};
|
||||
std::string apiEndPoint{"/api/song"};
|
||||
int port{9349};
|
||||
|
||||
void configureSong();
|
||||
void printSongDetails();
|
||||
void printJsonData(nlohmann::json);
|
||||
|
||||
nlohmann::json serializeObject();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
#include"Upload.h"
|
||||
|
||||
Upload::Upload()
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user