87 lines
1.8 KiB
C++
87 lines
1.8 KiB
C++
#include "../include/calibrationmanager.hpp"
|
|
|
|
#include <unistd.h>
|
|
#include <pwd.h>
|
|
|
|
#include "../include/exceptionhandler.hpp"
|
|
|
|
CalibrationManager::CalibrationManager(const std::string &hd)
|
|
: _hd(hd) {}
|
|
|
|
void CalibrationManager::execute()
|
|
{
|
|
const std::string fp = _hd + INSTALLED.GetPath();
|
|
|
|
/* If file exists */
|
|
if (access(std::move(fp).c_str(), F_OK) == 0)
|
|
{
|
|
std::cout << "Please uninstall any installed mods." << "\n";
|
|
throw ExceptionHandler(UNKNOWN_ERROR);
|
|
}
|
|
|
|
/* MD5 DIGEST VERIFICATION */
|
|
|
|
std::cout << "No mods installed! Calibrating files now..." << "\n";
|
|
|
|
/* Verifies the MD5 digest of each path */
|
|
_verify();
|
|
|
|
if (Calibrate::GetCount() > 0)
|
|
{
|
|
std::cout << "Number of files uncalibrated: " << Calibrate::GetCount() << "\n";
|
|
throw ExceptionHandler(CUSTOM_ERROR, "Please reinstall the game.");
|
|
}
|
|
|
|
std::cout << "All files are calibrated!" << "\n";
|
|
|
|
/* GAME FILE BACKUPS */
|
|
|
|
_backup();
|
|
|
|
std::cout << "The game is now ready to install mods." << "\n";
|
|
}
|
|
|
|
void CalibrationManager::_verify()
|
|
{
|
|
Calibrate::ClearCount();
|
|
|
|
for (auto &it : PATH_MD5_MAP)
|
|
{
|
|
const std::string fp = _hd + it.first;
|
|
unsigned char md5_local[MD5_DIGEST_LENGTH];
|
|
|
|
Calibrate calibrate_local(std::move(fp), it.second);
|
|
|
|
if (!calibrate_local.CompareMD5(md5_local))
|
|
{
|
|
bool blocal = true;
|
|
for (auto &i : CALIB_VERIFY_ARR)
|
|
{
|
|
if (i.CompareMD5(md5_local))
|
|
{
|
|
i.Execute();
|
|
blocal = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (blocal)
|
|
{
|
|
Calibrate::PlusCount();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void CalibrationManager::_backup()
|
|
{
|
|
std::cout << "Searching for backup files and directories..." << "\n";
|
|
|
|
for (auto &i : BACKUP_ARR)
|
|
{
|
|
i.Execute(_hd);
|
|
}
|
|
|
|
std::cout << "Critical game data is now backed up!" << "\n";
|
|
}
|