teleport/server/tp_web/src/ts_env.cpp

96 lines
2.2 KiB
C++
Raw Normal View History

#include "ts_env.h"
TsEnv g_env;
TsEnv::TsEnv()
{}
TsEnv::~TsEnv()
{}
bool TsEnv::init(void)
{
EXLOG_LEVEL(EX_LOG_LEVEL_INFO);
ex_exec_file(m_exec_file);
m_exec_path = m_exec_file;
ex_dirname(m_exec_path);
// <20><>λ log, etc, www ·<><C2B7>
// Ĭ<><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD><C2A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼<C4BF><C2BC>λ<EFBFBD>ڱ<EFBFBD><DAB1><EFBFBD>ִ<EFBFBD>г<EFBFBD><D0B3><EFBFBD><EFBFBD><EFBFBD> ../ <20><><EFBFBD><EFBFBD>λ<EFBFBD>ã<EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD><C7BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD>ֿ<EFBFBD><D6BF><EFBFBD>Ŀ¼<C4BF>µ<EFBFBD>shareĿ¼<C4BF>в<EFBFBD><D0B2>ҡ<EFBFBD>
ex_wstr base_path = m_exec_path;
ex_path_join(base_path, true, L"..", NULL);
ex_wstr conf_file = base_path;
2017-01-16 13:28:13 +00:00
ex_path_join(conf_file, false, L"etc", L"web.ini", NULL);
if (ex_is_file_exists(conf_file.c_str()))
{
m_www_path = base_path;
ex_path_join(m_www_path, false, L"www", NULL);
}
else
{
EXLOGW("===== DEVELOPMENT MODE =====\n");
base_path = m_exec_path;
ex_path_join(base_path, true, L"..", L"..", L"..", L"..", L"server", L"share", NULL);
conf_file = base_path;
2017-01-16 13:28:13 +00:00
ex_path_join(conf_file, false, L"etc", L"web.ini", NULL);
m_www_path = m_exec_path;
ex_path_join(m_www_path, true, L"..", L"..", L"..", L"..", L"server", L"www", NULL);
}
if (!ex_is_file_exists(conf_file.c_str()))
{
EXLOGE("[tpweb] web.conf not found.\n");
return false;
}
ExIniFile cfg;
if (!cfg.LoadFromFile(conf_file))
{
2017-01-16 13:28:13 +00:00
EXLOGE("[tpweb] can not load web.ini.\n");
return false;
}
ex_wstr log_file;
ExIniSection* ps = cfg.GetDumySection();
if (!ps->GetStr(L"log_file", log_file))
{
ex_wstr log_path = base_path;
2017-01-10 16:02:33 +00:00
ex_path_join(log_path, false, L"log", NULL);
EXLOG_FILE(L"tpweb.log", log_path.c_str());
}
else
{
ex_remove_white_space(log_file);
if (log_file[0] == L'"' || log_file[0] == L'\'')
log_file.erase(0, 1);
if (log_file[ log_file.length() - 1 ] == L'"' || log_file[log_file.length() - 1] == L'\'')
log_file.erase(log_file.length() - 1, 1);
ex_wstr log_path = log_file;
ex_dirname(log_path);
ex_wstr file_name;
file_name.assign(log_file, log_path.length() + 1, log_file.length());
EXLOG_FILE(file_name.c_str(), log_path.c_str());
}
int log_level = EX_LOG_LEVEL_INFO;
if (ps->GetInt(L"log_level", log_level))
{
EXLOGV("[tpweb] log-level: %d\n", log_level);
EXLOG_LEVEL(log_level);
}
EXLOGI("==============================\n");
EXLOGI("[tpweb] start...\n");
return true;
}