Initial add of PowerRename from SmartRename repo (#499)

* Initial add of PowerRename from SmartRename repo
This commit is contained in:
Chris Davis
2019-10-17 20:57:19 -07:00
committed by GitHub
parent 04b9422ea6
commit e1d5dd263a
63 changed files with 6055 additions and 1 deletions

View File

@@ -0,0 +1,73 @@
#include "stdafx.h"
#include "TestFileHelper.h"
#include <iostream>
#include <fstream>
#include <Objbase.h>
namespace fs = std::filesystem;
CTestFileHelper::CTestFileHelper()
{
_CreateTempDirectory();
}
CTestFileHelper::~CTestFileHelper()
{
_DeleteTempDirectory();
}
// Pass a relative path which will be appended to the temp directory path
bool CTestFileHelper::AddFile(_In_ const std::wstring path)
{
fs::path newFilePath = _tempDirectory;
newFilePath.append(path);
std::ofstream ofs(newFilePath);
ofs.close();
return true;
}
// Pass a relative path which will be appended to the temp directory path
bool CTestFileHelper::AddFolder(_In_ const std::wstring path)
{
fs::path newFolderPath = _tempDirectory;
newFolderPath.append(path);
return fs::create_directory(fs::path(newFolderPath));
}
fs::path CTestFileHelper::GetFullPath(_In_ const std::wstring path)
{
fs::path fullPath = _tempDirectory;
fullPath.append(path);
return fullPath;
}
bool CTestFileHelper::PathExists(_In_ const std::wstring path)
{
fs::path fullPath = _tempDirectory;
fullPath.append(path);
return fs::exists(fullPath);
}
bool CTestFileHelper::_CreateTempDirectory()
{
// Initialize to the temp directory
_tempDirectory = fs::temp_directory_path();
// Create a unique folder name
GUID guid = { 0 };
CoCreateGuid(&guid);
wchar_t uniqueName[MAX_PATH] = { 0 };
StringFromGUID2(guid, uniqueName, ARRAYSIZE(uniqueName));
_tempDirectory.append(uniqueName);
return fs::create_directory(_tempDirectory);
}
void CTestFileHelper::_DeleteTempDirectory()
{
fs::remove_all(_tempDirectory);
}