/*
 * 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 <vector>
#include <fstream>
#include <filesystem>
#include <algorithm>
#include <stdexcept>
#include <sstream>
#include <cstdint>
#include <string>
#include <utility>
#include <xxhash.h>

#include "DataStruct.h"
#include "EncryptionManager.h"
#include "CompressionManager.h"

class ExtractCargo {
public:
	ExtractCargo();
	virtual ~ExtractCargo();

	// Punkt wejścia
	bool Extract(const std::string&);

private:
	std::filesystem::path cargoFileName;

	uint32_t filesLen;
	uint64_t tablePosition;
	XXH64_state_t* xxhState;

	const std::string signature;

	std::vector<FilesTable> filesHeads;


	std::ifstream cargoFile;

	EncryptionManager eman;
	CompressionManager cman;

	// Sprawdzenie poprawności archiwum
	bool CheckCargoFile();

	// Wypakowywanie plików
	void ExtractingFilesFromCargo();

	// Pobieranie nagłówków plików
	void LoadFilesTable();

	// Utwórz katalog
	void CreateDirections(std::filesystem::path);

};
