Skip to content

Commit

Permalink
WindowsFileSystem::GetLocalAppDataDirectory: use process name when nu…
Browse files Browse the repository at this point in the history
…ll AppName is given
  • Loading branch information
TheMostDiligent committed Jun 24, 2023
1 parent b5850fd commit bb987d6
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions Platforms/Win32/src/Win32FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,14 +596,31 @@ std::string GetLocalAppDataDirectoryImpl(const char* AppName, bool Create)
{
VERIFY_EXPR(Path != nullptr);
AppDataDir = NarrowString(Path);
if (!WindowsFileSystem::IsSlash(AppDataDir.back()))
AppDataDir.push_back(WindowsFileSystem::SlashSymbol);

if (AppName != nullptr)
{
if (!WindowsFileSystem::IsSlash(AppDataDir.back()))
AppDataDir.push_back(WindowsFileSystem::SlashSymbol);
AppDataDir.append(AppName);
if (Create && !WindowsFileSystem::PathExists(AppDataDir.c_str()))
CreateDirectoryImpl(AppDataDir.c_str());
}
else
{
CHAR ExeFilePath[MAX_PATH];
// If the GetModuleFileNameA succeeds, the return value is the length of the string that is
// copied to the buffer, in characters, not including the terminating null character.
if (GetModuleFileNameA(NULL, ExeFilePath, MAX_PATH) > 0)
{
std::string FileName;
WindowsFileSystem::GetPathComponents(ExeFilePath, nullptr, &FileName);
// Remove extension
auto DotPos = FileName.find_last_of('.');
if (DotPos != std::string::npos)
FileName.resize(DotPos);
AppDataDir.append(FileName);
}
}
if (Create && !WindowsFileSystem::PathExists(AppDataDir.c_str()))
CreateDirectoryImpl(AppDataDir.c_str());
}

if (Path != nullptr)
Expand Down

0 comments on commit bb987d6

Please sign in to comment.