From fcd4a482f759cd58ee319a51082d0146b7e426e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 9 Apr 2016 23:51:01 +0200 Subject: [PATCH] NOISSUE tiny skeleton for a CLI wonko client --- CMakeLists.txt | 1 + wonkoclient/CMakeLists.txt | 10 +++++ wonkoclient/WonkoClient.cpp | 85 +++++++++++++++++++++++++++++++++++++ wonkoclient/WonkoClient.h | 36 ++++++++++++++++ wonkoclient/main.cpp | 29 +++++++++++++ 5 files changed, 161 insertions(+) create mode 100644 wonkoclient/CMakeLists.txt create mode 100644 wonkoclient/WonkoClient.cpp create mode 100644 wonkoclient/WonkoClient.h create mode 100644 wonkoclient/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 9cd3cf47..5739f923 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,3 +119,4 @@ include(Coverity) add_subdirectory(tests) add_subdirectory(logic) add_subdirectory(application) +add_subdirectory(wonkoclient) diff --git a/wonkoclient/CMakeLists.txt b/wonkoclient/CMakeLists.txt new file mode 100644 index 00000000..3638f69b --- /dev/null +++ b/wonkoclient/CMakeLists.txt @@ -0,0 +1,10 @@ +project(wonkoclient) + +SET( SRC_FILES +main.cpp +WonkoClient.cpp +WonkoClient.h +) + +add_executable(WonkoClient ${SRC_FILES}) +target_link_libraries(WonkoClient MultiMC_logic) diff --git a/wonkoclient/WonkoClient.cpp b/wonkoclient/WonkoClient.cpp new file mode 100644 index 00000000..83efb285 --- /dev/null +++ b/wonkoclient/WonkoClient.cpp @@ -0,0 +1,85 @@ +// +// Created by robotbrain on 3/27/16. +// + +#include +#include +#include +#include +#include +#include +#include +#include +#include "WonkoClient.h" +#include + + +WonkoClient &WonkoClient::getInstance() { + static WonkoClient instance; + return instance; +} + +void WonkoClient::registerLists() { + ENV.initHttpMetaCache(); + auto mcList = std::make_shared(); + ENV.registerVersionList("net.minecraft", mcList); + runTask(mcList->getLoadTask()); + auto llList = std::make_shared(); + ENV.registerVersionList("com.mumfrey.liteloader", llList); + runTask(llList->getLoadTask()); + auto forgeList = std::make_shared(); + ENV.registerVersionList("net.minecraftforge", forgeList); + runTask(forgeList->getLoadTask()); + auto lwjglList = std::make_shared(); + ENV.registerVersionList("org.lwjgl.legacy", lwjglList); + runTask(lwjglList->getLoadTask()); + auto javaList = std::make_shared(); + ENV.registerVersionList("com.java", javaList); +} + +WonkoClient::WonkoClient() { + m_settings.reset(new INISettingsObject("multimc.cfg", this)); + m_instanceList.reset(new InstanceList(m_settings, ".", this)); +} + +void WonkoClient::runTask(Task *pTask) { + if (pTask == nullptr) + return; + QEventLoop loop; + QObject::connect(pTask, &Task::finished, &loop, &QEventLoop::quit); + pTask->start(); + loop.exec(); + delete pTask; +} + +void WonkoClient::initGlobalSettings() +{ + m_settings->registerSetting("ShowConsole", true); + m_settings->registerSetting("RaiseConsole", true); + m_settings->registerSetting("AutoCloseConsole", true); + m_settings->registerSetting("LogPrePostOutput", true); + // Window Size + m_settings->registerSetting({"LaunchMaximized", "MCWindowMaximize"}, false); + m_settings->registerSetting({"MinecraftWinWidth", "MCWindowWidth"}, 854); + m_settings->registerSetting({"MinecraftWinHeight", "MCWindowHeight"}, 480); + + // Memory + m_settings->registerSetting({"MinMemAlloc", "MinMemoryAlloc"}, 512); + m_settings->registerSetting({"MaxMemAlloc", "MaxMemoryAlloc"}, 1024); + m_settings->registerSetting("PermGen", 128); + + // Java Settings + m_settings->registerSetting("JavaPath", ""); + m_settings->registerSetting("JavaTimestamp", 0); + m_settings->registerSetting("JavaVersion", ""); + m_settings->registerSetting("LastHostname", ""); + m_settings->registerSetting("JavaDetectionHack", ""); + m_settings->registerSetting("JvmArgs", ""); + + // Wrapper command for launch + m_settings->registerSetting("WrapperCommand", ""); + + // Custom Commands + m_settings->registerSetting({"PreLaunchCommand", "PreLaunchCmd"}, ""); + m_settings->registerSetting({"PostExitCommand", "PostExitCmd"}, ""); +} diff --git a/wonkoclient/WonkoClient.h b/wonkoclient/WonkoClient.h new file mode 100644 index 00000000..e6b35805 --- /dev/null +++ b/wonkoclient/WonkoClient.h @@ -0,0 +1,36 @@ +// +// Created by robotbrain on 3/27/16. +// + +#pragma once + +#include +#include + +#if defined(MMCC) +#undef MMCC +#endif +#define MMCC (WonkoClient::getInstance()) + +class WonkoClient : public QObject { +Q_OBJECT + +private: + WonkoClient(); + +public: + static WonkoClient &getInstance(); + + void registerLists(); + void initGlobalSettings(); + + std::shared_ptr instances() const { + return m_instanceList; + } + +private: + std::shared_ptr m_instanceList; + std::shared_ptr m_settings; + + void runTask(Task *pTask); +}; diff --git a/wonkoclient/main.cpp b/wonkoclient/main.cpp new file mode 100644 index 00000000..1ee6d881 --- /dev/null +++ b/wonkoclient/main.cpp @@ -0,0 +1,29 @@ +// +// Created by robotbrain on 3/26/16. +// + +#include "WonkoClient.h" +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + if (a.arguments().contains("-d")) + { + int i = a.arguments().lastIndexOf("-d") + 1; + if (i < a.arguments().length()) + { + QDir dir = QDir::current(); + dir.cd(a.arguments()[i]); + QDir::setCurrent(dir.absolutePath()); + qDebug() << "Using " << dir.absolutePath(); + } + } + MMCC.initGlobalSettings(); + MMCC.registerLists(); + return a.exec(); +}