Podmiana zmiennych int8 na int16, Działa filtrowanie plików po przez podanie ścierzek

This commit is contained in:
yanczi 2025-11-11 13:46:56 +01:00
parent 293c1412ad
commit 621b4b6eb7
12 changed files with 66 additions and 81 deletions

9
.gitignore vendored
View file

@ -372,3 +372,12 @@ test.*
pest2.*
*.hh
*.key
test3/
test4/
test5/
test6/
test7/
test8/
test9/
test10/
testx/

View file

@ -60,7 +60,7 @@ std::vector<char> CompressingManager::compress(const std::vector<char>& raw)
std::vector<char> zip;
// Wstaw liczbê o iloœci bloków do vectora;
// Przekonpwertuj usigned int32 na ci¹g znkaów
//uint16_t blockLen = blockSizes .size();
// uint16_t blockLen = blockSizes .size();
addIntToVector<uint16_t>(zip, blockLen);
addIntToVector<uint32_t>(zip, maxBlockSize);
addIntToVector<uint32_t>(zip, lastChunkRawSize);

View file

@ -37,12 +37,14 @@ CreateCargo::~CreateCargo() {
//-----------------------------------------------------------------------------
// Punk wejścia do tworzenia archivum
//-----------------------------------------------------------------------------
bool CreateCargo::Create(const std::string& path, int8_t flag)
bool CreateCargo::Create(const std::string& path, const int16_t& flag)
{
cargoFile = path + "." + extension;
catalogPath = path;
methodFlags = flag;
std::cout << "#1 FLAG: " << flag << " - " << methodFlags << std::endl;
//Sprawdzanie pakowanego kontentu
if (!std::filesystem::is_directory(path))
{
@ -56,14 +58,6 @@ bool CreateCargo::Create(const std::string& path, int8_t flag)
return false;
}
//Pobieranie listy plików do spakowania
std::cout << "Creating a file list..." << std::endl;
if (!GetFileList(path))
{
std::cerr << "Error: The specified directory contains no files!" << std::endl;
return false;
}
// Pobieranie listy plików wyjątków
if (flag == -1)
{
@ -75,9 +69,13 @@ bool CreateCargo::Create(const std::string& path, int8_t flag)
}
GetFilters(filterFile);
}
else
//Pobieranie listy plików do spakowania
std::cout << "Creating a file list..." << std::endl;
if (!GetFileList(path))
{
// Dodaj tu coœ mordo
std::cerr << "Error: The specified directory contains no files!" << std::endl;
return false;
}
// Utworzenie kontenera
@ -104,6 +102,11 @@ bool CreateCargo::Create(const std::string& path, int8_t flag)
//-----------------------------------------------------------------------------
bool CreateCargo::GetFileList(const std::string& path)
{
for (const auto& el : encList)
{
std::cout << el << std::endl;
}
for (const auto& entry : std::filesystem::directory_iterator(path))
{
std::string tmpPath = entry.path().string();
@ -113,13 +116,36 @@ bool CreateCargo::GetFileList(const std::string& path)
}
else
{
std::string fileRef = RemoveStartPath(PathToUnixLike(tmpPath));
if (CheckIgnorePath(tmpPath))
{
std::cout << "FLAG: " << methodFlags << std::endl;
PathConf pc;
if (methodFlags > -1)
{
std::cout << "NO FLAG" << std::endl;
pc.path = PathToUnixLike(tmpPath);
pc.parameter = methodFlags;
filesPaths.push_back(pc);
}
else
{
if (!FindOnTheList(ignoreList, fileRef))
{
if (FindOnTheList(zipList, fileRef))
{
pc.parameter = FindOnTheList(encList, fileRef) ? 3 : 1;
}
else
{
pc.parameter = FindOnTheList(encList, fileRef) ? 2 : 0;
}
pc.path = PathToUnixLike(tmpPath);
std::cout << pc.parameter << std::endl;
filesPaths.push_back(pc);
}
}
}
}
}
@ -171,7 +197,7 @@ CargoHead CreateCargo::CreateCargoHead(const uint32_t& filesLen, const uint64_t&
//-----------------------------------------------------------------------------
// Sprawdza czy plik znajduje się na liście
//-----------------------------------------------------------------------------
void CreateCargo::computingBytes(const int8_t& flag, std::vector<char>& input, std::vector<char>& output)
void CreateCargo::computingBytes(const int16_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
@ -266,43 +292,15 @@ void CreateCargo::GetFilters(const std::string& filterFile)
file.close();
// Lista plików do skompresowania
std::vector<std::string> zip = jslist[KEY_ZIP].get<std::vector<std::string>>();
zipList = jslist[KEY_ZIP].get<std::vector<std::string>>();
// Lista plików do zaszyfrowania
std::vector<std::string> enc = jslist[KEY_ENCRYPT].get<std::vector<std::string>>();
encList = jslist[KEY_ENCRYPT].get<std::vector<std::string>>();
// Lista plików do pominięcia
std::vector<std::string> ignore = jslist[KEY_IGNORE].get<std::vector<std::string>>();
PrepareList(zip, enc, ignore);
ignoreList = jslist[KEY_IGNORE].get<std::vector<std::string>>();
}
//-----------------------------------------------------------------------------
// Przygotuj listê plików do spakowania
//-----------------------------------------------------------------------------
void CreateCargo::PrepareList(const std::vector<std::string>& zip, const std::vector<std::string>& enc, const std::vector<std::string>& ignore)
{
PathConf pc;
for (const auto& item : filesList)
{
if (!FindOnTheList(ignore, item))
{
if (FindOnTheList(zip, item))
{
pc.parameter = FindOnTheList(enc, item) ? 3 : 1;
}
else
{
pc.parameter = FindOnTheList(enc, item) ? 2 : 0;
}
pc.path = item;
filesPaths.push_back(pc);
}
}
}
//-----------------------------------------------------------------------------
// Znajdź wskazany element na liście
//-----------------------------------------------------------------------------

View file

@ -38,21 +38,17 @@
#include "EncryptionManager.h"
#define COMPRESSION_LEVEL 12 // Poziom kompresji plików (3 < 12)
#define KEY_ZIP "COMPRESS" // Pliki do skompresowania
#define KEY_RAW "RAW" // Pliki które maj¹ pozostaæ w oryginalnej formie
#define KEY_IGNORE "IGNORE" // Pliki pominiête przy pakowaniu
#define KEY_ENCRYPT "ENCRYPT" // Plili które maj¹ byæ zaszyfrowane
#define KEY_ZIP "compress" // Pliki do skompresowania
#define KEY_RAW "raw" // Pliki które maj¹ pozostaæ w oryginalnej formie
#define KEY_IGNORE "ignore" // Pliki pominiête przy pakowaniu
#define KEY_ENCRYPT "encrypt" // Plili które maj¹ byæ zaszyfrowane
#define ALL_FILE ".*" // Wszystkie pliki
struct PathConf
{
std::string path;
int8_t parameter;
int16_t parameter;
};
class CreateCargo {
@ -61,14 +57,14 @@ public:
virtual ~CreateCargo();
// Punk wejœcia do tworzenia archivum
bool Create(const std::string&, int8_t);
bool Create(const std::string&, const int16_t&);
private:
const std::string signature;
const std::string extension;
const short version;
int8_t methodFlags;
short methodFlags;
std::string catalogPath;
@ -82,6 +78,7 @@ private:
// listy wyj¹tków
std::vector<std::string> ignoreList;
std::vector<std::string> zipList;
std::vector<std::string> encList;
// G³ówna lista plików z parametrami
std::vector<PathConf> filesPaths;
@ -117,7 +114,7 @@ private:
void GetFilters(const std::string&);
// Sprawdza czy plik znajduje siê na liœcie
void computingBytes(const int8_t&, std::vector<char>&, std::vector<char>&);
void computingBytes(const int16_t&, std::vector<char>&, std::vector<char>&);
// Kasowanie z listy plików ignorow
bool CheckIgnorePath(const std::string&);
@ -136,8 +133,5 @@ private:
// ZnajdŸ wskazany element na liœcie
bool FindOnTheList(const std::vector<std::string>&, const std::string&);
// Przygotuj listê plików do spakowania
void PrepareList(const std::vector<std::string>&, const std::vector<std::string>&, const std::vector<std::string>&);
};

View file

@ -1 +0,0 @@
#include "CreateCargoEX.h"

View file

@ -1,8 +0,0 @@
#pragma once
class CreateCargoEX
{
public:
CreateCargoEX();
~CreateCargoEX() = default;
};

View file

@ -66,11 +66,11 @@ struct CargoHead
struct FilesTable
{
uint8_t nameLen;
int16_t nameLen;
std::string nameFile;
uint64_t hashName;
uint64_t offset;
uint32_t size;
uint64_t crc;
int8_t flag;
int16_t flag;
};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

View file

@ -134,7 +134,6 @@
<ItemGroup>
<ClCompile Include="CompressingManager.cpp" />
<ClCompile Include="CreateCargo.cpp" />
<ClCompile Include="CreateCargoEX.cpp" />
<ClCompile Include="EncryptionManager.cpp" />
<ClCompile Include="ExtractCargo.cpp" />
<ClCompile Include="Interface.cpp" />
@ -144,7 +143,6 @@
<ItemGroup>
<ClInclude Include="CompressingManager.h" />
<ClInclude Include="CreateCargo.h" />
<ClInclude Include="CreateCargoEX.h" />
<ClInclude Include="DataStruct.h" />
<ClInclude Include="EncryptionManager.h" />
<ClInclude Include="ExtractCargo.h" />

View file

@ -47,9 +47,6 @@
<ClInclude Include="ViewCargo.h">
<Filter>Pliki nagłówkowe</Filter>
</ClInclude>
<ClInclude Include="Txtpp.h">
<Filter>Pliki nagłówkowe</Filter>
</ClInclude>
<ClInclude Include="DataStruct.h">
<Filter>Pliki nagłówkowe</Filter>
</ClInclude>