files.cpp 1.4 KB
Newer Older
Matteo's avatar
update  
Matteo committed
1
2
#include "files.h"

Matteo's avatar
Matteo committed
3
4
#include <iostream>

Matteo's avatar
update  
Matteo committed
5
6
7
using std::cout, std::endl, std::cerr, std::ofstream, std::ios;

void files::saveFile(std::filesystem::path fileName, std::string content, bool append) {
Matteo's avatar
Matteo committed
8
9
10
11
12
13
14
15
    ofstream outputFile;
    if (append) {
        outputFile.open(fileName, ios::app);
    } else {
        outputFile.open(fileName);
    }
    outputFile << content << endl;
    outputFile.close();
Matteo's avatar
update  
Matteo committed
16
17
18
}

void files::findFileNameFromPath(std::string* path, std::string* fileName, std::string* extension) {
Matteo's avatar
Matteo committed
19
20
21
22
23
    *path = path->substr(path->find_last_of("'") + 1, path->size());
    std::string path_without_extension = path->substr(0, path->find_last_of("."));
    *fileName =
        path_without_extension.substr(path_without_extension.find_last_of("/") + 1, path_without_extension.size());
    *extension = path->substr(path->find_last_of(".") + 1, path->size());
Matteo's avatar
update  
Matteo committed
24
25
}

Matteo's avatar
Matteo committed
26
int files::findFileName(std::string videoPath, std::string& fileName, std::string& extension) {
Matteo's avatar
update  
Matteo committed
27
28
29
30
31
32
33
34
35
36
37
38
    files::findFileNameFromPath(&videoPath, &fileName, &extension);

    if (extension.compare("avi") != 0 && extension.compare("mp4") != 0 && extension.compare("mov") != 0) {
        cerr << "Input file extension must be \"avi\", \"mp4\" or \"mov\"." << endl;
        return -1;
    } else {
        cout << "Video to be analysed: " << endl;
        cout << "    File name:  " << fileName << endl;
        cout << "    Extension:  " << extension << endl;
    }
    return 0;
}