-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
34 lines (27 loc) · 876 Bytes
/
main.cpp
File metadata and controls
34 lines (27 loc) · 876 Bytes
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
#include <iostream>
#include <string>
#include "huffman.hpp"
#include "progress.hpp"
int main(int argc, char const *argv[]) {
std::string path;
bool fileExists = false;
// Ask the user for the file path until a valid file is provided
while (!fileExists) {
std::cout << "Enter the file path: ";
std::getline(std::cin, path);
// Check if file exists
FILE *f = fopen(path.c_str(), "r");
if (f != nullptr) {
fileExists = true;
fclose(f);
} else
std::cerr << "There's no such file, please try again." << std::endl;
}
// Check if the path is valid and if it ends with .huf
bool is_compressed =
(path.size() > 4 && path.substr(path.size() - 4) == ".huf");
// To compress or not to compress!
is_compressed ? fDecompress(path, fDisplayProgress)
: fCompress(path, fDisplayProgress);
return 0;
}