Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions source/gameanalytics/GALogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ namespace gameanalytics
return;
}

std::string logFilePath = writablepath + "/" + LOG_FILE_NAME;
std::filesystem::path logFilePath = std::filesystem::u8path(writablepath);
logFilePath /= LOG_FILE_NAME;

logFile.open(logFilePath, std::ios::out | std::ios::trunc);
Comment on lines +93 to 96

if (!logFile.is_open())
{
ZF_LOGW("Failed to open log file %s", logFilePath.c_str());
std::cerr << "Failed to open log file:" << logFilePath << std::endl;
return;
}

Expand All @@ -105,10 +106,9 @@ namespace gameanalytics
logInitialized = true;
currentLogCount = 0;

GALogger::i("Log file added under: %s", logFilePath.c_str());
GALogger::i("Log file added under: %s", logFilePath.string().c_str());
}


void GALogger::sendNotificationMessage(std::string const& message, EGALoggerMessageType type)
{
if(customLogHandler)
Expand Down
10 changes: 6 additions & 4 deletions source/gameanalytics/GAStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,16 @@ namespace gameanalytics
{
constexpr const char* DATABASE_NAME = "ga.sqlite3";

std::filesystem::path p = device::GADevice::getWritablePath();
std::filesystem::path p = std::filesystem::u8path(device::GADevice::getWritablePath());

p /= state::GAState::getGameKey();

dbPath = (p / DATABASE_NAME).string();
if(!std::filesystem::exists(p))
dbPath = (p / DATABASE_NAME).u8string();
std::error_code ec;
if(!std::filesystem::exists(p, ec))
{
if(!std::filesystem::create_directory(p))
std::filesystem::create_directories(p, ec);
if(ec)
return false;
}

Expand Down
27 changes: 18 additions & 9 deletions source/gameanalytics/Platform/GALinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,28 @@ std::string gameanalytics::GAPlatformLinux::getBuildPlatform()

std::string gameanalytics::GAPlatformLinux::getPersistentPath()
{
std::string path = std::getenv("HOME");
path += "/GameAnalytics";

mode_t nMode = 0733;
int result = mkdir(path.c_str(), nMode);
if (result == 0 || errno == EEXIST)
std::string path = "GameAnalytics";
std::error_code ec;

const char* homeDir = std::getenv("HOME");
if(homeDir && strlen(homeDir))
{
return path;
if(std::filesystem::exists(homeDir, ec) && !ec)
{
path = std::string(homeDir) + "/" + path;
}
}
else

if(!std::filesystem::exists(path, ec))
{
return "";
std::filesystem::create_directories(path, ec);
if(ec)
{
return "";
}
}

return path;
}

std::string gameanalytics::GAPlatformLinux::getDeviceModel()
Expand Down
11 changes: 8 additions & 3 deletions source/gameanalytics/Platform/GAMacOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,24 @@ std::string gameanalytics::GAPlatformMacOS::getConnectionType()
std::string gameanalytics::GAPlatformMacOS::getPersistentPath()
{
std::string path = "GameAnalytics";
std::error_code ec;

const char* homeDir = std::getenv("HOME");
if(homeDir && strlen(homeDir))
{
if(std::filesystem::exists(homeDir))
if(std::filesystem::exists(homeDir, ec) && !ec)
{
path = std::string(homeDir) + "/" + path;
}
}

if(!std::filesystem::exists(path))
if(!std::filesystem::exists(path, ec))
{
std::filesystem::create_directory(path);
std::filesystem::create_directories(path, ec);
if(ec)
{
return "";
}
}

return path;
Expand Down
19 changes: 12 additions & 7 deletions source/gameanalytics/Platform/GAWin32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,25 @@ std::string GAPlatformWin32::getBuildPlatform()

std::string GAPlatformWin32::getPersistentPath()
{
std::string path = "GameAnalytics";
namespace fs = std::filesystem;

char* appData = std::getenv("LOCALAPPDATA");
if (appData && strlen(appData))
fs::path path = L"GameAnalytics";

wchar_t* appData = nullptr;
size_t length = 0;
if (_wdupenv_s(&appData, &length, L"LOCALAPPDATA") == 0 && appData && *appData)
{
path = std::string(appData) + '\\' + path;
path = fs::path(appData) / path;
}
free(appData);

if(!std::filesystem::exists(path))
std::error_code ec;
if (!fs::exists(path, ec))
{
std::filesystem::create_directories(path);
fs::create_directories(path, ec);
}

return path;
return ec ? "" : path.u8string();
}

std::string getRegistryKey(HKEY key, const TCHAR* subkey, const TCHAR* value)
Expand Down
4 changes: 2 additions & 2 deletions test/GAEventsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ using namespace gameanalytics;

namespace
{
constexpr const char* kGameKey = "bd624ee6f8e6efb32a054f8d7ba11618";
constexpr const char* kGameSecret = "7f5c3f682cbd217841efba92e92ffb1b3b6612bc";
constexpr const char* kGameKey = "0123456789abcdef0123456789abcdef";
constexpr const char* kGameSecret = "0123456789abcdef0123456789abcdef01234567";

class MockHttpClient : public GAHttpClient
{
Expand Down
Loading
Loading