//
// Created by kikab on 10.06.2018.
//

#include <LotroDat.h>
using namespace LOTRO_DAT;

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <ctime>

int main() {
    std::cout << "Gi1dor's LotRO .dat patcher ver. " << LOTRO_DAT_VERSION << std::endl;
    freopen("patcher_errors.log", "w", stderr);

    setbuf(stdout, nullptr);
    setbuf(stderr, nullptr);

    setvbuf (stdout, nullptr, _IONBF, BUFSIZ);
    setvbuf (stderr, nullptr, _IONBF, BUFSIZ);

    DatFile file;
    std::ifstream in("dat_file_path.txt");

    if (in.fail())
        return 0;

    std::string filename;
    std::getline(in, filename);
    std::cout << "Opening file " << filename << std::endl;
    auto operation = file.Initialise(filename, 0);
    if (operation.result != SUCCESS) {
        std::cout << "Unable to initialize file. DatFile message: " << operation.msg;
        system("pause");
        return 0;
    }

    operation = file.GatherInformation("info.txt");
    if (operation.result != SUCCESS)
        std::cout << "Gather information wasn't successfully completed. DatFile message: " << operation.msg;
    else
        std::cout << "DatFile information gathered successfully!";
    system("pause");
    return 0;
}