136 lines
3.5 KiB
C++
136 lines
3.5 KiB
C++
/*
|
|
* This file is part of VoidArchiveTool.
|
|
*
|
|
* Copyright (C) 2025 Yanczi
|
|
*
|
|
* Void Archive Toolis free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <iostream>
|
|
#include <cstdint>
|
|
#include <filesystem>
|
|
#include <algorithm>
|
|
#include <vector>
|
|
#include <fstream>
|
|
#include <lz4.h>
|
|
#include <stdexcept>
|
|
#include <utility>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <boost/crc.hpp>
|
|
|
|
#include "DataStruct.h"
|
|
#include "Txtpp.h"
|
|
#include "xxhash.h"
|
|
#include "CompressingManager.h"
|
|
#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_CRYPT "CRYPT" // Plili które maj¹ byæ zaszyfrowane
|
|
|
|
#define ALL_FILE ".*" // Wszystkie pliki
|
|
|
|
|
|
class CreateCargo {
|
|
public:
|
|
CreateCargo();
|
|
virtual ~CreateCargo();
|
|
|
|
// Punk wejœcia do tworzenia archivum
|
|
bool Create(const std::string&, bool, bool);
|
|
|
|
private:
|
|
bool compressingFlag;
|
|
bool filteringFlag;
|
|
const std::string signature;
|
|
const std::string extension;
|
|
const uint8_t version;
|
|
|
|
|
|
std::string catalogPath;
|
|
std::string tempFile;
|
|
std::string cargoFile;
|
|
|
|
std::vector<std::string> filesList;
|
|
|
|
EncryptionManager crypt;
|
|
|
|
// listy wyj¹tków
|
|
std::vector<std::string> ignoreList;
|
|
std::vector<std::string> zipList;
|
|
|
|
|
|
std::ofstream cargo;
|
|
uint64_t offset;
|
|
|
|
|
|
|
|
// Tworzenie listy plików do spakowania
|
|
bool GetFileList(const std::string&);
|
|
|
|
// Konwersja œcie¿ki na unix like
|
|
std::string PathToUnixLike(std::string);
|
|
|
|
// Kasowanie wskazanego katalogu ze œcie¿ki
|
|
std::string RemoveStartPath(const std::filesystem::path&);
|
|
|
|
// Trworzenie archiwum
|
|
bool WriteCargo();
|
|
|
|
// Tworzenie nag³owka pliku
|
|
CargoHead CreateCargoHead(const uint32_t&, const uint64_t&);
|
|
|
|
// Przygotowanie nag³ówków i plików
|
|
std::vector<FilesTable> ComputingHeadFiles();
|
|
|
|
// Sprawdzanie czy plik znajduje siê na liœcie
|
|
bool FilteringData(const std::string&);
|
|
|
|
// Wczytanie filtrów wyj¹tków
|
|
void GetFilters(const std::string&);
|
|
|
|
// Sprawdza czy plik znajduje siê na liœcie
|
|
uint8_t CheckFileOnTheList(const std::string&, std::vector<char>&, std::vector<char>&);
|
|
|
|
// Kasowanie z listy plików ignorow
|
|
bool CheckIgnorePath(const std::string&);
|
|
|
|
// Sprawdzanie rozsze¿eñ plików
|
|
bool CheckFileExtension(const std::filesystem::path&, const std::vector<std::string>&);
|
|
|
|
// Zamieñ ca³y ci¹g na du¿e litery
|
|
std::string UpperString(std::string);
|
|
|
|
// Wygenerój FNV-1a HASH
|
|
uint64_t fnv64(const std::string& data);
|
|
|
|
// CRC
|
|
uint32_t crc32(const std::vector<char>&);
|
|
|
|
// Rozdzielanie paternu od œcie¿ki
|
|
void ExtPatternAndPathDetection(const std::vector<std::string>&, std::vector<std::string>&, std::vector<std::string>&);
|
|
|
|
// ZnajdŸ wskazany element na liœcie
|
|
bool FindOnTheList(const std::vector<std::string>&, const std::string&);
|
|
};
|
|
|