Skip to content

Commit

Permalink
directory creates now
Browse files Browse the repository at this point in the history
  • Loading branch information
EvilLord666 committed Mar 30, 2020
1 parent 7eaec70 commit b29ec2a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,20 @@ DWORD WINAPI TimerThreadFunc (LPVOID lpParam)
// 3.1 Getting timestamped filename
TCHAR* timestampedFileName = MossbauerLab::Utils::Windows::FileInfoHelper::getFileNameWithTimestamp(searchResult->getFileName());
TCHAR* fileNameWithoutExt = MossbauerLab::Utils::Windows::FileInfoHelper::getFileNameWithoutExt(searchResult->getFileName());
TCHAR archiveDirWithSubDir[MAX_PATH];
// 3.2 Combine with autosaveDir
memset(fullOutputName, 0, MAX_PATH * sizeof(TCHAR));
memset(archiveDirWithSubDir, 0, MAX_PATH * sizeof(TCHAR));
#if WINVER >= 0x0500
_stprintf_s(fullOutputName, MAX_PATH, _T("%s\\%s"), config->getArchiveDir().c_str(), timestampedFileName);
_stprintf_s(archiveDirWithSubDir, MAX_PATH, _T("%s\\%s"), config->getArchiveDir().c_str(), fileNameWithoutExt);
_stprintf_s(fullOutputName, MAX_PATH, _T("%s\\%s"), archiveDirWithSubDir, timestampedFileName);
#else
_stprintf(fullOutputName, _T("%s\\%s"), config->getArchiveDir().c_str(), timestampedFileName);
_stprintf(archiveDirWithSubDir, _T("%s\\%s"), config->getArchiveDir().c_str(), fileNameWithoutExt);
_stprintf(fullOutputName, _T("%s\\%s"), archiveDirWithSubDir, timestampedFileName);
#endif
// 3.3 Save
// 3.3.1 Create Sub Directory if not Exists
CreateDirectory(archiveDirWithSubDir, NULL);
CopyFile(searchResult->getFilePath(), fullOutputName, false);
delete[] timestampedFileName;
delete[] fileNameWithoutExt;
Expand Down Expand Up @@ -142,7 +148,7 @@ DWORD WINAPI TimerThreadFunc (LPVOID lpParam)
_stprintf_s(outputDir, sizeof(outputDir)/sizeof(TCHAR), _T("%hs"),
config->getOutputDir().c_str());
#else
sprintf(outputDir, _T("%hs"), config->getOutputDir().c_str());
_stprintf(outputDir, _T("%hs"), config->getOutputDir().c_str());
#endif
MossbauerLab::Utils::Windows::FileSearchResult* searchResult = MossbauerLab::Utils::Windows::FileInfoHelper::getLastChangedFile(outputDir, _T("\\*.spc"));
if (searchResult->getResult())
Expand All @@ -151,14 +157,22 @@ DWORD WINAPI TimerThreadFunc (LPVOID lpParam)
// 3.1 Getting timestamped filename
TCHAR* timestampedFileName = MossbauerLab::Utils::Windows::FileInfoHelper::getFileNameWithTimestamp(searchResult->getFileName());
TCHAR* fileNameWithoutExt = MossbauerLab::Utils::Windows::FileInfoHelper::getFileNameWithoutExt(searchResult->getFileName());
TCHAR archiveDirWithSubDir[MAX_PATH];
memset(archiveDirWithSubDir, 0, MAX_PATH * sizeof(TCHAR));
// 3.2 Combine with autosaveDir
memset(fullOutputName, 0, MAX_PATH * sizeof(TCHAR));
#if WINVER >= 0x0500
_stprintf_s(fullOutputName, MAX_PATH, _T("%s\\%s"), config->getArchiveDir().c_str(), timestampedFileName);
_stprintf_s(archiveDirWithSubDir, MAX_PATH, _T("%s\\%s"),
config->getArchiveDir().c_str(), fileNameWithoutExt);
_stprintf_s(fullOutputName, MAX_PATH, _T("%s\\%s"),
archiveDirWithSubDir, timestampedFileName);
#else
_stprintf(fullOutputName, _T("%s\\%s"), config->getArchiveDir().c_str(), timestampedFileName);
_stprintf(archiveDirWithSubDir, _T("%s\\%s"), config->getArchiveDir().c_str(), fileNameWithoutExt);
_stprintf(fullOutputName, _T("%s\\%s"), archiveDirWithSubDir, timestampedFileName);
#endif
// 3.3 Save
// 3.3.1 Create Sub Directory
CreateDirectory(archiveDirWithSubDir, NULL);
CopyFile(searchResult->getFilePath(), fullOutputName, false);
delete[] timestampedFileName;
delete[] fileNameWithoutExt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ TCHAR* MossbauerLab::Utils::Windows::FileInfoHelper::getFileNameWithoutExt(const
else
length = index > 0 ? separatorIndex - index - 1 : separatorIndex;
TCHAR* fileNameBuffer = new TCHAR[length + 1];
_tcsncpy_s(fileNameBuffer, length + 1, fileName, length);
memset(fileNameBuffer, 0, (length + 1) * sizeof(TCHAR));
#if WINVER >= 0x0500
_tcsncpy_s(fileNameBuffer, length + 1, fileName, length);
#else
_tcsncpy(fileNameBuffer, fileName, length);
#endif
return fileNameBuffer;
}

0 comments on commit b29ec2a

Please sign in to comment.