140 lines
2.6 KiB
C++
140 lines
2.6 KiB
C++
#include <unistd.h>
|
|
#include <pwd.h>
|
|
#include <iostream>
|
|
#include <fstream>
|
|
|
|
#include "../include/paths.hpp"
|
|
#include "../include/etw_lmm.hpp"
|
|
#include "../include/exceptionhandler.hpp"
|
|
#include "../include/etw-lmm_config.hpp"
|
|
#include "../include/calibrationmanager.hpp"
|
|
#include "../include/installationmanager.hpp"
|
|
|
|
ETW_LMM::ETW_LMM(int argc, char **argv)
|
|
{
|
|
for (unsigned int i = 0; i < argc; ++i)
|
|
{
|
|
_args.push_back(argv[i]);
|
|
}
|
|
|
|
_set_homedir();
|
|
}
|
|
|
|
unsigned int ETW_LMM::execute()
|
|
{
|
|
try
|
|
{
|
|
_menu();
|
|
}
|
|
catch (ExceptionHandler& e)
|
|
{
|
|
std::cerr << _args[0] << ": ";
|
|
e.GrabError();
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
void ETW_LMM::_menu()
|
|
{
|
|
if (_args.size() > 1)
|
|
{
|
|
if (_args[1] == "help") { _help(); }
|
|
else if (_args[1] == "calibrate") { _calibrate(); }
|
|
else if (_args[1] == "list") { _list(); }
|
|
else if (_args[1] == "install")
|
|
{
|
|
if (_args.size() < 3)
|
|
{
|
|
throw ExceptionHandler(NO_ARGUMENT_ERROR);
|
|
}
|
|
|
|
_install();
|
|
}
|
|
else if (_args[1] == "uninstall")
|
|
{
|
|
if (_args.size() < 3) // TO DO
|
|
{
|
|
throw ExceptionHandler(NO_ARGUMENT_ERROR);
|
|
}
|
|
|
|
// INSTALLATION
|
|
}
|
|
else
|
|
{
|
|
throw ExceptionHandler(INVALID_ARGUMENT_ERROR, _args[1]);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_help();
|
|
}
|
|
}
|
|
|
|
void ETW_LMM::_set_homedir()
|
|
{
|
|
/* Retrieve home directory */
|
|
char* char_homedir;
|
|
if ((char_homedir = getenv("HOME")) == NULL)
|
|
{
|
|
struct passwd *pw = getpwuid(getuid());
|
|
char_homedir = pw->pw_dir;
|
|
}
|
|
|
|
_hd = char_homedir;
|
|
}
|
|
|
|
void ETW_LMM::_help()
|
|
{
|
|
std::cout << "EMPIRE: TOTAL WAR -- LINUX MOD MANAGER "
|
|
<< etw_lmm_VERSION_MAJOR << "." << etw_lmm_VERSION_MINOR << "\n"
|
|
<< "Options:\n"
|
|
<< "\thelp\t\tShow this help message\n"
|
|
<< "\tinstall [MOD]\tInstall a mod\n"
|
|
<< "\tuninstall [MOD]\tUninstall a mod\n"
|
|
<< "\tcalibrate\tCalibrate original game files for modding\n"
|
|
<< "\tlist\t\tList installed mods\n"
|
|
<< "\n";
|
|
}
|
|
|
|
void ETW_LMM::_list()
|
|
{
|
|
const std::string fp = _hd + INSTALLED.GetPath();
|
|
|
|
/* If file doesn't exist */
|
|
if (access(std::move(fp).c_str(), F_OK) != 0)
|
|
{
|
|
std::cout << "No mods installed!";
|
|
}
|
|
else
|
|
{
|
|
std::ifstream ifs(std::move(fp));
|
|
std::string name;
|
|
|
|
while (std::getline(ifs, name))
|
|
{
|
|
if (name == "\0")
|
|
{
|
|
std::cout << "No mods installed!";
|
|
break;
|
|
}
|
|
std::cout << name << "\n";
|
|
}
|
|
|
|
ifs.close();
|
|
}
|
|
}
|
|
|
|
void ETW_LMM::_calibrate()
|
|
{
|
|
CalibrationManager cm(_hd);
|
|
cm.execute();
|
|
}
|
|
|
|
void ETW_LMM::_install()
|
|
{
|
|
InstallationManager im(_hd, _args[2]);
|
|
im.execute();
|
|
}
|