Create any parent directory required for log file

This commit is contained in:
baldurk
2015-08-02 15:42:33 +02:00
parent ada7306e1a
commit 32ae45d992
4 changed files with 42 additions and 0 deletions
+2
View File
@@ -736,6 +736,8 @@ void RenderDoc::SetLogFile(const char *logFile)
if(m_LogFile.substr(m_LogFile.length()-4) == ".rdc")
m_LogFile = m_LogFile.substr(0, m_LogFile.length()-4);
FileIO::CreateParentDirectory(m_LogFile);
}
void RenderDoc::SetProgress(LoadProgressSection section, float delta)
+24
View File
@@ -145,6 +145,30 @@ namespace FileIO
return ret + filename;
}
void CreateParentDirectory(const string &filename)
{
string fn = dirname(filename);
// want trailing slash so that we create all directories
fn.push_back('/');
if(fn[0] != '/')
return;
size_t offs = fn.find('/', 1);
while(offs != string::npos)
{
// create directory path from 0 to offs by NULLing the
// / at offs, mkdir, then set it back
fn[offs] = 0;
mkdir(fn.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
fn[offs] = '/';
offs = fn.find_first_of('/', offs+1);
}
}
string GetFullPathname(const string &filename)
{
char path[512] = {0};
+2
View File
@@ -177,6 +177,8 @@ namespace FileIO
string GetAppFolderFilename(const string &filename);
string GetReplayAppFilename();
void CreateParentDirectory(const string &filename);
string GetFullPathname(const string &filename);
void GetExecutableFilename(string &selfName);
+14
View File
@@ -170,6 +170,20 @@ namespace FileIO
return StringFormat::Wide2UTF8(wstring(path));
}
void CreateParentDirectory(const string &filename)
{
wstring wfn = StringFormat::UTF82Wide(filename);
wfn = dirname(wfn);
// This function needs \\s not /s. So stupid!
for(size_t i=0; i < wfn.size(); i++)
if(wfn[i] == L'/')
wfn[i] = L'\\';
SHCreateDirectoryExW(NULL, wfn.c_str(), NULL);
}
string GetReplayAppFilename()
{
HMODULE hModule = NULL;