Przeprawiona klasa tworzenia kontenerów. Dodano funkcję która wygodnie dobiera odpowiednie działanie dla danych

This commit is contained in:
yanczi 2025-11-07 16:38:19 +01:00
parent 31f08e52d0
commit 8402ce1b65
7 changed files with 84 additions and 33 deletions

View file

@ -90,6 +90,12 @@ bool CreateCargo::Create(const std::string& path, int8_t flag)
return false; return false;
} }
// Zapisywanie klucza szyfruj¹cego
if (flag == 2 || flag == 3)
{
crypt.saveKey(catalogPath);
}
return true; return true;
} }
@ -171,30 +177,28 @@ void CreateCargo::computingBytes(const int8_t& flag, std::vector<char>& input, s
//Przeciwnie kompresuje dane //Przeciwnie kompresuje dane
CompressingManager cm; CompressingManager cm;
// Kompresja switch (flag)
if (flag == 1)
{ {
case 1:
std::cout << "COMPRESSING" << std::endl; std::cout << "COMPRESSING" << std::endl;
output = cm.compress(input); output = cm.compress(input);
} break;
// Szyfrowanie case 2:
if (flag == 2)
{
std::cout << "ENCRYPTION" << std::endl; std::cout << "ENCRYPTION" << std::endl;
output = crypt.encrypt(input); output = crypt.encrypt(input);
} break;
// Kompresja i szyfrowanie case 3:
if (flag == 3)
{
std::cout << "ZIP ENC" << std::endl; std::cout << "ZIP ENC" << std::endl;
output = crypt.encrypt(cm.compress(input)); output = crypt.encrypt(cm.compress(input));
} break;
// Zwraca surowe dane default:
std::cout << "RAW" << std::endl; std::cout << "RAW" << std::endl;
output = std::move(input); output = std::move(input);
break;
}
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -478,9 +482,6 @@ bool CreateCargo::WriteCargo()
cargo.close(); cargo.close();
// Zapisywanie klucza szyfrujšcego
//crypt.saveKey(catalogPath);
std::cout << "The container was successfully created! " << cargoFile << std::endl; std::cout << "The container was successfully created! " << cargoFile << std::endl;
return true; return true;

View file

@ -132,6 +132,33 @@ bool ExtractCargo::HashValid(const std::vector<char>& data, const uint64_t& crc)
return true; 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 // Pobieranie nagłówków plików
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -180,7 +207,8 @@ void ExtractCargo::ExtractingFilesFromCargo()
cargoFile.read(buffor.data(), fh.size); 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)) if (!HashValid(rawBuffor, fh.crc))
{ {

View file

@ -75,4 +75,7 @@ private:
// Utwórz katalog // Utwórz katalog
void CreateDirections(std::filesystem::path); void CreateDirections(std::filesystem::path);
// Magiczna funkcja do dekompresji i deszyfracji danych
void computingBytes(const std::vector<char>&, std::vector<char>&, const int8_t&);
}; };

View file

Before

Width:  |  Height:  |  Size: 851 KiB

After

Width:  |  Height:  |  Size: 851 KiB

Before After
Before After

View file

@ -40,33 +40,32 @@ void RenderHelp()
const std::string HelpInstruction = const std::string HelpInstruction =
"pakcmd <parametr> <catalog> \n" "pakcmd <parametr> <catalog> \n"
" \n" " \n"
" -c Pack and compress with LZ4 \n" " \-c Compressing \n"
" -p Pack files from the specified directory \n" " \-r Raw files \n"
" -e Pack and encrypted from the specified directory \n" " \-e Encrypted \n"
" -f Pack the files according to the guidelines given in the <directory>.txt \n" " \-s Compressing and Encrypted \n"
" -s Pack and encrypted \n" " \-f Pack the files according to the guidelines given in the \<directory\>.json \n"
" -cs Pack and compress \n"
" \n" " \n"
"Extracting: \n" "Extracting: \n"
" -x Extract files from the specified container \n" " -x Extract files from the specified container \n"
" \n"
"Others: \n"
" -ls List files stored in a container \n" " -ls List files stored in a container \n"
" \n" " \n"
" \n" "<catalog>.json \n"
"<catalog>.txt \n"
" \n" " \n"
"Keys: \n" "Keys: \n"
" \n" " \n"
" {compress} - Compressing files \n" " {compress} - Compressing files \n"
" {crypt} - Encrypted files with ChaCha20 \n" " {crypt} - Encrypted files \n"
" {ignore} - Ignoring concrete files \n" " {ignore} - Ignoring concrete files \n"
" \n" " \n"
" /path/to/file.ext - Concrete file \n" " /path/to/file.ext - Concrete file \n"
" *.ext - All files with concrete extension \n" " *.ext - All files with concrete extension \n"
" *.* - All files !NOT WORKING WITH {ignore} KEY! \n" " *.* - All files !NOT WORKING WITH {ignore} KEY! \n";
" \n";
Interface tui; //Interface tui;
tui.TextBorder(HelpTitle, HelpInstruction); //tui.TextBorder(HelpTitle, HelpInstruction);
} }
bool EmptyPath(std::string path) bool EmptyPath(std::string path)
@ -118,7 +117,7 @@ int main(int argc, char* argv[]) {
i++; i++;
} }
if (arg == "-p" && i + 1 < argc) if (arg == "-r" && i + 1 < argc)
{ {
path = argv[i + 1]; path = argv[i + 1];
if (!cargo.Create(path, 0)) if (!cargo.Create(path, 0))
@ -128,6 +127,26 @@ int main(int argc, char* argv[]) {
i++; 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) if (arg == "-f" && i + 1 < argc)
{ {
path = argv[i + 1]; path = argv[i + 1];