Merge branch 'master' of github.com:QuasarApp/QuasarAppLib

This commit is contained in:
Andrei Yankovich 2020-04-19 13:04:45 +03:00
commit f5a6e542ea
3 changed files with 56 additions and 10 deletions

View File

@ -5,6 +5,14 @@
# of this license document, but changing it is not allowed.
#
if(DEFINED QUASARAPP_LIBRARY)
return()
else()
set(QUASARAPP_LIBRARY 1)
add_definitions(-DQUASARAPP_LIBRARY)
endif()
cmake_minimum_required(VERSION 3.1)
include(CMake/crossplatform/crossplatform.cmake)

View File

@ -20,11 +20,15 @@
#include <limits.h>
#endif
#define APP_PATH "appPath"
#define APP_NAME "appName"
using namespace QuasarAppUtils;
static QVariantMap params = QVariantMap();
static int _argc = 0;
bool Params::isEndable(const QString& key) {
return params.contains(key);
}
@ -33,7 +37,7 @@ void Params::log(const QString &log, VerboseLvl vLvl) {
writeLoginFile(log, vLvl);
auto lvl = static_cast<VerboseLvl>(getArg("verbose", DEFAULT_VERBOSE_LVL).toInt());
auto lvl = getVerboseLvl();
if (vLvl <= lvl) {
@ -75,10 +79,26 @@ void Params::showHelp(const Help::Charters &help) {
Help::print(help);
}
VerboseLvl Params::getVerboseLvl() {
return static_cast<VerboseLvl>(getArg("verbose", DEFAULT_VERBOSE_LVL).toInt());
}
bool Params::isDebug() {
return getVerboseLvl() >= VerboseLvl::Debug;
}
void Params::showHelp() {
Help::print(getparamsHelp());
}
QVariantMap Params::getUserParamsMap() {
auto result = params;
result.remove(APP_PATH);
result.remove(APP_NAME);
return result;
}
int Params::size() {
return params.size();
}
@ -121,7 +141,7 @@ std::string Params::lvlToString(VerboseLvl vLvl) {
bool Params::writeLoginFile(const QString &log, VerboseLvl vLvl) {
if (isEndable("fileLog")) {
QString path = getStrArg("appPath") + "/" + getStrArg("appName") + ".log";
QString path = getStrArg(APP_PATH) + "/" + getStrArg(APP_NAME) + ".log";
auto file = getStrArg("fileLog");
if (file.size()) {
QString path = file;
@ -166,8 +186,8 @@ bool Params::parseParams(const QStringList &paramsArray) {
memset(buffer, 0, sizeof buffer);
GetModuleFileNameA(nullptr, buffer, MAX_PATH);
params ["appPath"] = QFileInfo(buffer).absolutePath();
params ["appName"] = QFileInfo(buffer).fileName();
params [APP_PATH] = QFileInfo(buffer).absolutePath();
params [APP_NAME] = QFileInfo(buffer).fileName();
#else
char path[2048];
@ -178,12 +198,12 @@ bool Params::parseParams(const QStringList &paramsArray) {
QuasarAppUtils::Error);
return false;
}
params ["appPath"] = QFileInfo(path).absolutePath();
params ["appName"] = QFileInfo(path).fileName();
params [APP_PATH] = QFileInfo(path).absolutePath();
params [APP_NAME] = QFileInfo(path).fileName();
#endif
if (!getStrArg("appPath").size()) {
if (!getStrArg(APP_PATH).size()) {
return false;
}

View File

@ -19,10 +19,10 @@ namespace QuasarAppUtils {
*/
enum VerboseLvl {
Info = 0x0,
Error = 0x1,
Info = 0x0,
Error = 0x1,
Warning = 0x2,
Debug = 0x3,
Debug = 0x3,
};
@ -114,6 +114,18 @@ public:
*/
static void showHelp(const Help::Charters& help);
/**
* @brief getVerboseLvl
* @return verbose lvl
*/
static VerboseLvl getVerboseLvl();
/**
* @brief isDebug
* @return true if verbose lvl >= 3
*/
static bool isDebug();
/**
* @brief size
* @return size of all params array
@ -130,6 +142,12 @@ public:
* @brief showHelp - show base help section of QuasarAppLib
*/
static void showHelp();
/**
* @brief getUserParamsMap
* @return QVariantMap with user params
*/
static QVariantMap getUserParamsMap();
};
}