56 lines
1.5 KiB
C++
56 lines
1.5 KiB
C++
|
|
#include "VrPathUtils.h"
|
||
|
|
|
||
|
|
#ifdef _WIN32
|
||
|
|
#include <windows.h>
|
||
|
|
#include <shlobj.h>
|
||
|
|
#pragma comment(lib, "Shell32.lib")
|
||
|
|
#else
|
||
|
|
#include <unistd.h>
|
||
|
|
#endif
|
||
|
|
|
||
|
|
namespace VrPathUtils
|
||
|
|
{
|
||
|
|
std::string GetLogDirectory()
|
||
|
|
{
|
||
|
|
std::string appName = "YJApp";
|
||
|
|
#ifdef _WIN32
|
||
|
|
char exePath[MAX_PATH] = {};
|
||
|
|
if (GetModuleFileNameA(nullptr, exePath, MAX_PATH) != 0)
|
||
|
|
{
|
||
|
|
const std::string fullPath(exePath);
|
||
|
|
const size_t separator = fullPath.find_last_of("\\");
|
||
|
|
if (separator != std::string::npos)
|
||
|
|
{
|
||
|
|
const std::string fileName = fullPath.substr(separator + 1);
|
||
|
|
const size_t dot = fileName.find_last_of('.');
|
||
|
|
appName = dot == std::string::npos ? fileName : fileName.substr(0, dot);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
char userPath[MAX_PATH] = {};
|
||
|
|
if (SHGetFolderPathA(nullptr, CSIDL_PERSONAL, nullptr, SHGFP_TYPE_CURRENT, userPath) == S_OK)
|
||
|
|
{
|
||
|
|
return std::string(userPath) + "\\" + appName + "\\Log";
|
||
|
|
}
|
||
|
|
return ".\\" + appName + "\\Log";
|
||
|
|
#else
|
||
|
|
char exePath[1024] = {};
|
||
|
|
const ssize_t length = readlink("/proc/self/exe", exePath, sizeof(exePath) - 1);
|
||
|
|
if (length > 0)
|
||
|
|
{
|
||
|
|
exePath[length] = '\0';
|
||
|
|
const std::string fullPath(exePath);
|
||
|
|
const size_t separator = fullPath.find_last_of('/');
|
||
|
|
if (separator != std::string::npos && separator + 1 < fullPath.size())
|
||
|
|
{
|
||
|
|
appName = fullPath.substr(separator + 1);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
#ifdef __ANDROID__
|
||
|
|
return "/sdcard/" + appName + "/Log";
|
||
|
|
#else
|
||
|
|
return appName + "/Log";
|
||
|
|
#endif
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
}
|