137 lines
3.5 KiB
C++
137 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 <xxhash.h>
|
|
#include <nlohmann/json.hpp>
|
|
|
|
#include "DataStruct.h"
|
|
#include "CompressingManager.h"
|
|
#include "EncryptionManager.h"
|
|
|
|
|
|
#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;
|
|
int16_t parameter;
|
|
};
|
|
|
|
class CreateCargo {
|
|
public:
|
|
CreateCargo();
|
|
virtual ~CreateCargo();
|
|
|
|
// Punk wejœcia do tworzenia archivum
|
|
bool Create(const std::string&, const int16_t&);
|
|
|
|
private:
|
|
const std::string signature;
|
|
const std::string extension;
|
|
const short version;
|
|
|
|
short methodFlags;
|
|
|
|
|
|
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::vector<std::string> encList;
|
|
|
|
// G³ówna lista plików z parametrami
|
|
std::vector<PathConf> filesPaths;
|
|
|
|
|
|
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
|
|
void computingBytes(const int16_t&, 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::string&, 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);
|
|
|
|
// 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&);
|
|
};
|
|
|