mirror of
https://github.com/jpd002/Play-.git
synced 2025-04-28 13:47:57 +03:00
Add app_shared module.
This commit is contained in:
parent
f8fc40e8bc
commit
60b7951678
6 changed files with 107 additions and 101 deletions
|
@ -1,33 +0,0 @@
|
||||||
#include "AppConfig.h"
|
|
||||||
#include "PathUtils.h"
|
|
||||||
|
|
||||||
#define BASE_DATA_PATH ("Play Data Files")
|
|
||||||
#define CONFIG_FILENAME ("config.xml")
|
|
||||||
|
|
||||||
CAppConfig::CAppConfig()
|
|
||||||
: CConfig(BuildConfigPath())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Framework::CConfig::PathType CAppConfig::BuildConfigPath()
|
|
||||||
{
|
|
||||||
return GetBasePath() / CONFIG_FILENAME;
|
|
||||||
}
|
|
||||||
|
|
||||||
CAppConfigBasePath::CAppConfigBasePath()
|
|
||||||
{
|
|
||||||
if(fs::exists("portable.txt"))
|
|
||||||
{
|
|
||||||
m_basePath = BASE_DATA_PATH;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_basePath = Framework::PathUtils::GetPersonalDataPath() / BASE_DATA_PATH;
|
|
||||||
}
|
|
||||||
Framework::PathUtils::EnsurePathExists(m_basePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
fs::path CAppConfigBasePath::GetBasePath() const
|
|
||||||
{
|
|
||||||
return m_basePath;
|
|
||||||
}
|
|
14
Source/app_shared/AppConfig.cpp
Normal file
14
Source/app_shared/AppConfig.cpp
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#include "AppConfig.h"
|
||||||
|
#include "PathUtils.h"
|
||||||
|
|
||||||
|
#define CONFIG_FILENAME ("config.xml")
|
||||||
|
|
||||||
|
CAppConfig::CAppConfig()
|
||||||
|
: CConfig(BuildConfigPath())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Framework::CConfig::PathType CAppConfig::BuildConfigPath()
|
||||||
|
{
|
||||||
|
return GetBasePath() / CONFIG_FILENAME;
|
||||||
|
}
|
|
@ -3,22 +3,15 @@
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Singleton.h"
|
#include "Singleton.h"
|
||||||
|
|
||||||
class CAppConfigBasePath
|
class CAppConfig : public Framework::CConfig, public CSingleton<CAppConfig>
|
||||||
{
|
|
||||||
public:
|
|
||||||
CAppConfigBasePath();
|
|
||||||
fs::path GetBasePath() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
fs::path m_basePath;
|
|
||||||
};
|
|
||||||
|
|
||||||
class CAppConfig : public CAppConfigBasePath, public Framework::CConfig, public CSingleton<CAppConfig>
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CAppConfig();
|
CAppConfig();
|
||||||
virtual ~CAppConfig() = default;
|
virtual ~CAppConfig() = default;
|
||||||
|
|
||||||
|
//This needs to be implemented by every application/executable
|
||||||
|
fs::path GetBasePath() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CConfig::PathType BuildConfigPath();
|
CConfig::PathType BuildConfigPath();
|
||||||
};
|
};
|
32
Source/app_shared/CMakeLists.txt
Normal file
32
Source/app_shared/CMakeLists.txt
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
|
||||||
|
set(CMAKE_MODULE_PATH
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../../deps/Dependencies/cmake-modules
|
||||||
|
${CMAKE_MODULE_PATH}
|
||||||
|
)
|
||||||
|
include(Header)
|
||||||
|
|
||||||
|
project(app_shared)
|
||||||
|
|
||||||
|
if (NOT TARGET Framework)
|
||||||
|
add_subdirectory(
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Framework/build_cmake/Framework
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/Framework
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(TARGET_PLATFORM_ANDROID OR TARGET_PLATFORM_IOS OR TARGET_PLATFORM_JS)
|
||||||
|
list(APPEND APP_SHARED_DEFINITIONS_LIST LOGGING_ENABLED=0)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(COMMON_SRC_FILES
|
||||||
|
AppConfig.cpp
|
||||||
|
AppConfig.h
|
||||||
|
Log.cpp
|
||||||
|
Log.h
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(app_shared STATIC ${COMMON_SRC_FILES})
|
||||||
|
target_link_libraries(app_shared PUBLIC Framework)
|
||||||
|
target_include_directories(app_shared PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
target_compile_definitions(app_shared PUBLIC ${APP_SHARED_DEFINITIONS_LIST})
|
|
@ -1,57 +1,57 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "filesystem_def.h"
|
#include "filesystem_def.h"
|
||||||
#include "StdStream.h"
|
#include "StdStream.h"
|
||||||
#include "Singleton.h"
|
#include "Singleton.h"
|
||||||
|
|
||||||
#ifndef LOGGING_ENABLED
|
#ifndef LOGGING_ENABLED
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
#define LOGGING_ENABLED 1
|
#define LOGGING_ENABLED 1
|
||||||
#else
|
#else
|
||||||
#define LOGGING_ENABLED 0
|
#define LOGGING_ENABLED 0
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LOGGING_ENABLED
|
#if LOGGING_ENABLED
|
||||||
|
|
||||||
class CLog : public CSingleton<CLog>
|
class CLog : public CSingleton<CLog>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CLog();
|
CLog();
|
||||||
virtual ~CLog() = default;
|
virtual ~CLog() = default;
|
||||||
|
|
||||||
void Print(const char*, const char*, ...);
|
void Print(const char*, const char*, ...);
|
||||||
void Warn(const char*, const char*, ...);
|
void Warn(const char*, const char*, ...);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::map<std::string, Framework::CStdStream> LogMapType;
|
typedef std::map<std::string, Framework::CStdStream> LogMapType;
|
||||||
|
|
||||||
Framework::CStdStream& GetLog(const char*);
|
Framework::CStdStream& GetLog(const char*);
|
||||||
|
|
||||||
fs::path m_logBasePath;
|
fs::path m_logBasePath;
|
||||||
LogMapType m_logs;
|
LogMapType m_logs;
|
||||||
bool m_showPrints = false;
|
bool m_showPrints = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
class CLog
|
class CLog
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static CLog& GetInstance()
|
static CLog& GetInstance()
|
||||||
{
|
{
|
||||||
static CLog instance;
|
static CLog instance;
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Print(const char*, const char*, ...)
|
void Print(const char*, const char*, ...)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void Warn(const char*, const char*, ...)
|
void Warn(const char*, const char*, ...)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Add table
Add a link
Reference in a new issue