Przeprawiona klasa tworzenia kontenerów. Dodano funkcję która wygodnie dobiera odpowiednie działanie dla danych
This commit is contained in:
parent
31f08e52d0
commit
8402ce1b65
7 changed files with 84 additions and 33 deletions
|
|
@ -90,6 +90,12 @@ bool CreateCargo::Create(const std::string& path, int8_t flag)
|
|||
return false;
|
||||
}
|
||||
|
||||
// Zapisywanie klucza szyfruj¹cego
|
||||
if (flag == 2 || flag == 3)
|
||||
{
|
||||
crypt.saveKey(catalogPath);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -171,30 +177,28 @@ void CreateCargo::computingBytes(const int8_t& flag, std::vector<char>& input, s
|
|||
//Przeciwnie kompresuje dane
|
||||
CompressingManager cm;
|
||||
|
||||
// Kompresja
|
||||
if (flag == 1)
|
||||
switch (flag)
|
||||
{
|
||||
case 1:
|
||||
std::cout << "COMPRESSING" << std::endl;
|
||||
output = cm.compress(input);
|
||||
}
|
||||
break;
|
||||
|
||||
// Szyfrowanie
|
||||
if (flag == 2)
|
||||
{
|
||||
case 2:
|
||||
std::cout << "ENCRYPTION" << std::endl;
|
||||
output = crypt.encrypt(input);
|
||||
}
|
||||
break;
|
||||
|
||||
// Kompresja i szyfrowanie
|
||||
if (flag == 3)
|
||||
{
|
||||
case 3:
|
||||
std::cout << "ZIP ENC" << std::endl;
|
||||
output = crypt.encrypt(cm.compress(input));
|
||||
}
|
||||
break;
|
||||
|
||||
// Zwraca surowe dane
|
||||
std::cout << "RAW" << std::endl;
|
||||
output = std::move(input);
|
||||
default:
|
||||
std::cout << "RAW" << std::endl;
|
||||
output = std::move(input);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -478,9 +482,6 @@ bool CreateCargo::WriteCargo()
|
|||
|
||||
cargo.close();
|
||||
|
||||
// Zapisywanie klucza szyfrujšcego
|
||||
//crypt.saveKey(catalogPath);
|
||||
|
||||
std::cout << "The container was successfully created! " << cargoFile << std::endl;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -132,6 +132,33 @@ bool ExtractCargo::HashValid(const std::vector<char>& data, const uint64_t& crc)
|
|||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Magiczna funkcja do dekompresji i deszyfracji danych
|
||||
//-----------------------------------------------------------------------------
|
||||
void ExtractCargo::computingBytes(const std::vector<char>& input, std::vector<char>& output, const int8_t& flag)
|
||||
{
|
||||
CompressingManager cm;
|
||||
|
||||
switch (flag)
|
||||
{
|
||||
case 1:
|
||||
output = cm.decompress(input);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
output = eman.decrypt(input);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
output = cm.decompress(eman.decrypt(input));
|
||||
break;
|
||||
|
||||
default:
|
||||
output = std::move(input);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Pobieranie nagłówków plików
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -180,7 +207,8 @@ void ExtractCargo::ExtractingFilesFromCargo()
|
|||
|
||||
cargoFile.read(buffor.data(), fh.size);
|
||||
|
||||
std::vector<char> rawBuffor = fh.flag ? cm.decompress(buffor) : buffor;
|
||||
std::vector<char> rawBuffor;
|
||||
computingBytes(buffor, rawBuffor, fh.size);
|
||||
|
||||
if (!HashValid(rawBuffor, fh.crc))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -75,4 +75,7 @@ private:
|
|||
// Utwórz katalog
|
||||
void CreateDirections(std::filesystem::path);
|
||||
|
||||
// Magiczna funkcja do dekompresji i deszyfracji danych
|
||||
void computingBytes(const std::vector<char>&, std::vector<char>&, const int8_t&);
|
||||
|
||||
};
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 851 KiB After Width: | Height: | Size: 851 KiB |
49
voidcmd.cpp
49
voidcmd.cpp
|
|
@ -40,33 +40,32 @@ void RenderHelp()
|
|||
const std::string HelpInstruction =
|
||||
"pakcmd <parametr> <catalog> \n"
|
||||
" \n"
|
||||
" -c Pack and compress with LZ4 \n"
|
||||
" -p Pack files from the specified directory \n"
|
||||
" -e Pack and encrypted from the specified directory \n"
|
||||
" -f Pack the files according to the guidelines given in the <directory>.txt \n"
|
||||
" -s Pack and encrypted \n"
|
||||
" -cs Pack and compress \n"
|
||||
" \-c Compressing \n"
|
||||
" \-r Raw files \n"
|
||||
" \-e Encrypted \n"
|
||||
" \-s Compressing and Encrypted \n"
|
||||
" \-f Pack the files according to the guidelines given in the \<directory\>.json \n"
|
||||
" \n"
|
||||
"Extracting: \n"
|
||||
" -x Extract files from the specified container \n"
|
||||
" \n"
|
||||
"Others: \n"
|
||||
" -ls List files stored in a container \n"
|
||||
" \n"
|
||||
" \n"
|
||||
"<catalog>.txt \n"
|
||||
"<catalog>.json \n"
|
||||
" \n"
|
||||
"Keys: \n"
|
||||
" \n"
|
||||
" {compress} - Compressing files \n"
|
||||
" {crypt} - Encrypted files with ChaCha20 \n"
|
||||
" {compress} - Compressing files \n"
|
||||
" {crypt} - Encrypted files \n"
|
||||
" {ignore} - Ignoring concrete files \n"
|
||||
" \n"
|
||||
" /path/to/file.ext - Concrete file \n"
|
||||
" *.ext - All files with concrete extension \n"
|
||||
" *.* - All files !NOT WORKING WITH {ignore} KEY! \n"
|
||||
" \n";
|
||||
" *.* - All files !NOT WORKING WITH {ignore} KEY! \n";
|
||||
|
||||
Interface tui;
|
||||
tui.TextBorder(HelpTitle, HelpInstruction);
|
||||
//Interface tui;
|
||||
//tui.TextBorder(HelpTitle, HelpInstruction);
|
||||
}
|
||||
|
||||
bool EmptyPath(std::string path)
|
||||
|
|
@ -118,7 +117,7 @@ int main(int argc, char* argv[]) {
|
|||
i++;
|
||||
}
|
||||
|
||||
if (arg == "-p" && i + 1 < argc)
|
||||
if (arg == "-r" && i + 1 < argc)
|
||||
{
|
||||
path = argv[i + 1];
|
||||
if (!cargo.Create(path, 0))
|
||||
|
|
@ -128,6 +127,26 @@ int main(int argc, char* argv[]) {
|
|||
i++;
|
||||
}
|
||||
|
||||
if (arg == "-e" && i + 1 < argc)
|
||||
{
|
||||
path = argv[i + 1];
|
||||
if (!cargo.Create(path, 2))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if (arg == "-s" && i + 1 < argc)
|
||||
{
|
||||
path = argv[i + 1];
|
||||
if (!cargo.Create(path, 3))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if (arg == "-f" && i + 1 < argc)
|
||||
{
|
||||
path = argv[i + 1];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue