Poprawione flagowanie metody pakowania
This commit is contained in:
parent
66e776ee87
commit
31f08e52d0
10 changed files with 287 additions and 200 deletions
|
|
@ -75,6 +75,10 @@ bool CreateCargo::Create(const std::string& path, int8_t flag)
|
|||
}
|
||||
GetFilters(filterFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Dodaj tu coœ mordo
|
||||
}
|
||||
|
||||
// Utworzenie kontenera
|
||||
cargo.open(cargoFile, std::ios::binary);
|
||||
|
|
@ -105,12 +109,15 @@ bool CreateCargo::GetFileList(const std::string& path)
|
|||
{
|
||||
if (CheckIgnorePath(tmpPath))
|
||||
{
|
||||
filesList.push_back(PathToUnixLike(tmpPath));
|
||||
PathConf pc;
|
||||
pc.path = PathToUnixLike(tmpPath);
|
||||
pc.parameter = methodFlags;
|
||||
filesPaths.push_back(pc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return filesList.size() > 0 ? true : false;
|
||||
return filesPaths.size() > 0 ? true : false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -158,40 +165,36 @@ CargoHead CreateCargo::CreateCargoHead(const uint32_t& filesLen, const uint64_t&
|
|||
//-----------------------------------------------------------------------------
|
||||
// Sprawdza czy plik znajduje siê na liœcie
|
||||
//-----------------------------------------------------------------------------
|
||||
uint8_t CreateCargo::CheckFileOnTheList(const std::string& path, std::vector<char>& input, std::vector<char>& output)
|
||||
void CreateCargo::computingBytes(const int8_t& flag, std::vector<char>& input, std::vector<char>& output)
|
||||
{
|
||||
//Flaga aktywna sprawdza czy plik jest na liœcie. Jeœli jest to zwraca surowedane
|
||||
//Przeciwnie kompresuje dane
|
||||
CompressingManager cm;
|
||||
|
||||
// Kompresja
|
||||
if (methodFlags == 1)
|
||||
if (flag == 1)
|
||||
{
|
||||
std::cout << "COMPRESSING" << std::endl;
|
||||
output = cm.compress(input);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Szyfrowanie
|
||||
if (methodFlags == 2)
|
||||
if (flag == 2)
|
||||
{
|
||||
std::cout << "ENCRYPTION" << std::endl;
|
||||
output = crypt.encrypt(input);
|
||||
return 2;
|
||||
}
|
||||
|
||||
// Kompresja i szyfrowanie
|
||||
if (methodFlags == 3)
|
||||
if (flag == 3)
|
||||
{
|
||||
std::cout << "ZIP ENC" << std::endl;
|
||||
output = crypt.encrypt(cm.compress(input));
|
||||
return 3;
|
||||
}
|
||||
|
||||
// Zwraca surowe dane
|
||||
std::cout << "RAW" << std::endl;
|
||||
output = std::move(input);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -203,7 +206,7 @@ std::vector<FilesTable> CreateCargo::ComputingHeadFiles()
|
|||
CargoHead cargoHead = CreateCargoHead(0, 0);
|
||||
offset += cargoHead.signature.length() + sizeof(cargoHead.version) + sizeof(cargoHead.files) + sizeof(cargoHead.table);
|
||||
|
||||
//Zapisanie TMP nag³owka do pliku
|
||||
//Zapisanie tymczasowego nag³owka jako rezerwacja miejsca
|
||||
cargo.write(cargoHead.signature.data(), cargoHead.signature.length());
|
||||
cargo.write(reinterpret_cast<const char*>(&cargoHead.version), sizeof(cargoHead.version));
|
||||
cargo.write(reinterpret_cast<const char*>(&cargoHead.files), sizeof(cargoHead.files));
|
||||
|
|
@ -211,11 +214,11 @@ std::vector<FilesTable> CreateCargo::ComputingHeadFiles()
|
|||
|
||||
std::vector<FilesTable> filesTable;
|
||||
|
||||
//Tworzenie nag³ówków plików
|
||||
for (const auto& file : filesList)
|
||||
//Tworzenie nag³ówków plików jednoczeœnie zapisywanie plików
|
||||
for (const auto& file : filesPaths)
|
||||
{
|
||||
std::string path = PathToUnixLike(RemoveStartPath(file));
|
||||
std::ifstream f(file, std::ios::binary | std::ios::ate);
|
||||
std::string path = PathToUnixLike(RemoveStartPath(file.path));
|
||||
std::ifstream f(file.path, std::ios::binary | std::ios::ate);
|
||||
|
||||
//Obliczanie rozmiaru pliku
|
||||
size_t size = f.tellg();
|
||||
|
|
@ -231,7 +234,7 @@ std::vector<FilesTable> CreateCargo::ComputingHeadFiles()
|
|||
|
||||
//Kompresjia
|
||||
std::vector<char> pakBuffer;
|
||||
uint8_t method = CheckFileOnTheList(path, buffer, pakBuffer);
|
||||
computingBytes(file.parameter, buffer, pakBuffer);
|
||||
|
||||
FilesTable ft;
|
||||
ft.nameFile = path;
|
||||
|
|
@ -239,7 +242,7 @@ std::vector<FilesTable> CreateCargo::ComputingHeadFiles()
|
|||
ft.hashName = fnv64(path);
|
||||
ft.offset = offset;
|
||||
ft.size = pakBuffer.size();
|
||||
ft.flag = method;
|
||||
ft.flag = file.parameter;
|
||||
ft.crc = crc;
|
||||
|
||||
cargo.write(reinterpret_cast<const char*>(pakBuffer.data()), pakBuffer.size());
|
||||
|
|
@ -435,7 +438,7 @@ bool CreateCargo::WriteCargo()
|
|||
{
|
||||
std::cout << "Packing files..." << std::endl;
|
||||
|
||||
uint32_t filesLen = filesList.size();
|
||||
uint32_t filesLen = filesPaths.size();
|
||||
|
||||
//Przygotowanie nag³ówków plików i przetworzenie danych
|
||||
std::vector<FilesTable> filesHead = ComputingHeadFiles();
|
||||
|
|
@ -458,7 +461,7 @@ bool CreateCargo::WriteCargo()
|
|||
cargo.write(reinterpret_cast<const char*>(&head.offset), sizeof(head.offset));
|
||||
cargo.write(reinterpret_cast<const char*>(&head.size), sizeof(head.size));
|
||||
cargo.write(reinterpret_cast<const char*>(&head.crc), sizeof(head.crc));
|
||||
cargo.write(reinterpret_cast<const char*>(&head.isZip), sizeof(head.isZip));
|
||||
cargo.write(reinterpret_cast<const char*>(&head.flag), sizeof(head.flag));
|
||||
}
|
||||
|
||||
//Cofnij siê na pocz¹tek pliku
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue