#include <iostream>

#include "datfile.h"
using namespace LOTRO_DAT;

int main() {
    std::string dat_file_path;
    std::string target_file_path;
    int file_id;
    int is_import;
    FILE_TYPE file_type;

    std::cout << "Enter path to .dat file: ";
    std::cin >> dat_file_path;

     DatFile file(0);
    if (!file.Init(dat_file_path)) {
        std::cout << "Failed to open .dat file!" << std::endl;
        system("pause");
        return 0;
    }

    std::cout << "Import or export? (enter 1 for import, 0 for export) ";
    std::cin >> is_import;

    std::cout << "Enter file_id (decimal): ";
    std::cin >> file_id;

    if (is_import) {
        std::string file_type_str;
        std::cout << "Enter file type (supported: txt, jpg, dds, wav, ogg, fontbin, unknown): ";
        std::cin >> file_type_str;
        file_type = FileTypeFromString("." + file_type_str);
    }

    std::cout << "Enter target file path (without spaces!): ";
    std::cin >> target_file_path;

    if (is_import == 1) {
        std::cout << "IMPORTING!" << std::endl;
        file.PatchFile(file_id, file_type, target_file_path);
    } else {
        std::cout << "EXPORTING!" << std::endl;
        file.ExportFileById(file_id, target_file_path);
    }
    file.Deinit();
    return 0;
}