diff --git a/CMakeLists.txt b/CMakeLists.txt index 5bba807..0ce5db6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,9 +3,8 @@ project(vatsim-manager) set(CMAKE_CXX_STANDARD 14) -add_executable(vatsim-manager main.cpp utils.cpp utils.h download.cpp download.h clientstate.cpp clientstate.h global.h) +add_executable(vatsim-manager main.cpp utils.cpp utils.h download.cpp download.h global.h) find_package(PkgConfig) pkg_check_modules(libcurl REQUIRED IMPORTED_TARGET libcurl>=7.68.0) -pkg_check_modules(jsoncpp REQUIRED IMPORTED_TARGET jsoncpp>=1.7.4) -target_link_libraries(vatsim-manager PUBLIC PkgConfig::libcurl PkgConfig::jsoncpp) \ No newline at end of file +target_link_libraries(vatsim-manager PUBLIC PkgConfig::libcurl) \ No newline at end of file diff --git a/README.md b/README.md index 9796e54..d8635fd 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,9 @@ Created by Cian Ormond with no endorsements by VATSIM staff members. For more in * Manage `winetricks` and `wine` settings in a custom `WINEPREFIX` for ATC clients ### Included clients -* xPilot 2.0.0 beta -* Swift beta +![xPilot version](https://img.shields.io/github/v/release/xpilot-project/xpilot?include_prereleases&label=xPilot&style=flat-square) +![Swift version](https://img.shields.io/github/v/release/swift-project/pilotclient?include_prereleases&label=Swift&style=flat-square) + ### Dependencies * libCURL >=7.68.0 diff --git a/clientstate.cpp b/clientstate.cpp deleted file mode 100644 index e3e3239..0000000 --- a/clientstate.cpp +++ /dev/null @@ -1,123 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -#include "clientstate.h" -#include "utils.h" -#include "global.h" - - -utils ut_cs; -global gl_cs; - -int clientstate::findHome() { - if ((homedir = getenv("HOME")).c_str() == NULL) { - homedir = getpwuid(getuid())->pw_dir; - } - return 0; -} - -int clientstate::createState() { - - std::string write = gl_cs.version + '\n'; - std::vector> input = checkClients(); - - Json::Value stateOut; - - std::time_t result = std::time(nullptr); - stateOut["time"] = result; - - stateOut["installed"] = vectorToJson(input.at(0)); - stateOut["paths"] = vectorToJson(input.at(1)); - stateOut["versions"] = vectorToJson(input.at(2)); - - std::ofstream out; - out.open((homedir + "/.local/share/vatsim-manager/state.json").c_str()); - out << stateOut; - out.close(); - -} - -std::vector> clientstate::checkClients() { - std::vector> res; - std::vector installed; - std::vector paths; - std::vector versions; - - //xpilot path from ~/.local/share/org.vatsim.xpilot/lastinstallpath.txt - system("find ~/.local/share/org.vatsim.xpilot -name lastinstallpath.txt > /tmp/vatsim-manager/findres 2>&1"); - if (ut_cs.iequals(ut_cs.readFile("/tmp/vatsim-manager/findres"), homedir + "/.local/share/org.vatsim.xpilot/lastinstallpath.txt")) { - //TODO only mark xpilot as installed if there is an appimage - installed.push_back("xpilot"); - - paths.push_back(ut_cs.readFile((homedir + "/.local/share/org.vatsim.xpilot/lastinstallpath.txt").c_str())); - - //TODO xpilot version will be from a flag in the next update - system((paths.at(0) + "/xPilot.AppImage --appimage-version > /tmp/vatsim-manager/findres 2>&1").c_str()); - versions.push_back(ut_cs.readFile("/tmp/vatsim-manager/findres")); - } - - //swift path and version from ~/.local/share/org.swiftproject/apps.json - system("find ~/.local/share/org.swiftproject/ -name apps.json > /tmp/vatsim-manager/findres 2>&1"); - if (ut_cs.iequals(ut_cs.readFile("/tmp/vatsim-manager/findres"), homedir + "/.local/share/org.swiftproject/apps.json")) { - - Json::Value swiftJson; - std::ifstream swiftFile((homedir + "/.local/share/org.swiftproject/apps.json").c_str(), std::ifstream::binary); - swiftFile >> swiftJson; - - installed.push_back("swift"); - //TODO remove /bin - paths.push_back(swiftJson["containerbase"][0].get("exePath", "n").asString()); - versions.push_back(swiftJson["containerbase"][0].get("version", "n").asString()); - - } - - - res.push_back(installed); - res.push_back(paths); - res.push_back(versions); - - return res; -} - -std::vector> clientstate::parseState() { - std::vector> res; - Json::Value stateJson; - std::ifstream stateFile((homedir + "/.local/share/vatsim-manager/state.json").c_str(), std::ifstream::binary); - stateFile >> stateJson; - - for (int i = 0; i < 3; i++) { - std::vector temp; - - std::string arrayName; - switch (i) { - case 0: - arrayName = "installed"; - break; - case 1: - arrayName = "paths"; - break; - case 2: - arrayName = "versions"; - break; - } - - for (int i = 0; i < stateJson[arrayName].size(); i++) { - temp.push_back(stateJson[arrayName].get(i, "").asString()); - } - - res.push_back(temp); - } - - - return res; -} - - -//store vatsim-manager version -//store client name and version \ No newline at end of file diff --git a/clientstate.h b/clientstate.h deleted file mode 100644 index 831ae37..0000000 --- a/clientstate.h +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include -#include - -#ifndef VATSIM_MANAGER_CLIENTSTATE_H -#define VATSIM_MANAGER_CLIENTSTATE_H - - -class clientstate { -public: - int findHome(); - int createState(); - std::vector> parseState(); - std::string homedir; -private: - std::vector> checkClients(); - - //https://stackoverflow.com/questions/26773043/how-to-write-a-template-converts-vector-to-jsonvalue-jsoncpp - template - Json::Value vectorToJson(Iterable const& cont) { - Json::Value v; - for (auto&& element: cont) { - v.append(element); - } - return v; - } - -}; - - -#endif //VATSIM_MANAGER_CLIENTSTATE_H diff --git a/main.cpp b/main.cpp index 44d534f..0a44892 100644 --- a/main.cpp +++ b/main.cpp @@ -7,16 +7,12 @@ #include "utils.h" #include "download.h" #include "global.h" -#include "clientstate.h" using namespace std; utils ut; download dl; global gl; -clientstate cs; - -vector> state; //TODO keep track of installed programs and add --refresh option @@ -39,37 +35,35 @@ int install(const char* program, bool forceDownload) { string cmdOut; if (ut.askForConfirmation(programName.c_str())) { system(("find /tmp/vatsim-manager/" + programName + ".run > /tmp/vatsim-manager/findinstaller 2>&1") - .c_str()); + .c_str()); if (!ut.iequals(ut.readFile("/tmp/vatsim-manager/findres"), "/tmp/vatsim-manager/" + - programName + ".run") || forceDownload) { + programName + ".run") || forceDownload) { dl.downloadPilotClient(programIndex); } else { //TODO detect old versions cout << "Found installer in /tmp/vatsim-manager/" << endl << "If you encounter errors or this is an old " << - "installer, use --force-download" << endl << endl; + "installer, use --force-download" << endl << endl; } system(("chmod +x /tmp/vatsim-manager/" + programName + ".run").c_str()); system(("/tmp/vatsim-manager/" + programName + ".run").c_str()); - cs.createState(); } return 0; } -//TODO change to directory in state.json int remove(const char* program) { if (ut.iequals(program, "xpilot")) { system("rm -rf \"$HOME/.cache/Justin Shannon\""); + cout << "Launching uninstaller" << endl; system("$(find $HOME -name xPilot)/uninstall > /dev/null 2>&1"); } else if (ut.iequals(program, "swift")) { //doesn't work if the qt sdk is installed system("$(find $HOME -name swift-*)/uninstall > /dev/null 2>&1"); } else { - cout << "Program name not recognised." << endl << endl; + cout << "Program name not recognised/program not installed." << endl << endl; return 1; } - cs.createState(); return 0; } @@ -88,38 +82,19 @@ void showLicense() { void showCommands() { cout << "-h - displays this page" << endl; - cout << "-l - lists installed clients" << endl; cout << "-L - displays license information" << endl; cout << "-i - installs a pilot/ATC client from the following list - " << endl; cout << " xPilot 2.0.0 beta (X-Plane 11), Swift (X-Plane 11, FlightGear)" << endl; cout << "-r - uninstalls a pilot/ATC client from the above list" << endl << endl; } -void showClients() { - std::string programName; - for (int i = 0; i < state.at(0).size(); i++) { - if (ut.iequals(state.at(0).at(i), "xpilot")) { programName = "xPilot"; } - if (ut.iequals(state.at(0).at(i), "Swift")) { programName = "Swift"; } - - cout << programName << endl << " " << state.at(1).at(i) << endl << " " << state.at(2).at(i) << endl << endl; - } -} - int main(int argc, char** argv) { cout << endl << "VATSIM Program Manager version " << gl.version << " by Cian Ormond" << endl; cout << "Licensed under GPL3. For licensing of programs included, use -L." << endl << endl; - //TODO move this somewhere else - cs.findHome(); - system("mkdir -p /tmp/vatsim-manager ~/.local/share/vatsim-manager"); - system("find ~/.local/share/vatsim-manager/ -name state.json > /tmp/vatsim-manager/findres 2>&1"); - if (ut.iequals(ut.readFile("/tmp/vatsim-manager/findres"), cs.homedir + "/.local/share/vatsim-manager/state.json")) { - state = cs.parseState(); - } else { cs.createState(); } - //TODO clean this up if (argc > 1) { @@ -138,7 +113,8 @@ int main(int argc, char** argv) { } else { //TODO only show uninstalled programs - cout << "Please specify a program to install. Available options are xPilot and Swift." << endl << endl; + cout << "Please specify a program to install. Available options are xPilot and Swift." << endl << + endl; } } else if (strcmp(argv[1], "-r") == 0) { @@ -152,7 +128,9 @@ int main(int argc, char** argv) { } else if (strcmp(argv[1], "-h") == 0) {showCommands();} else if (strcmp(argv[1], "-L") == 0) {showLicense();} - else if (strcmp(argv[1], "-l") == 0) {showClients();} + else { + cout << "Command not recognised. Use the -h flag for a command list" << endl << endl; + } } else { cout << "No command specified. Use the -h flag for a command list." << endl << endl; diff --git a/utils.cpp b/utils.cpp index 5b15dce..c9706be 100644 --- a/utils.cpp +++ b/utils.cpp @@ -53,6 +53,5 @@ int utils::findInVector(std::vector arr, std::string item) { if (iequals(arr[i], item)) return i; } - return -1; } \ No newline at end of file