mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 17:56:44 +02:00
Initial add of PowerRename from SmartRename repo (#499)
* Initial add of PowerRename from SmartRename repo
This commit is contained in:
73
src/modules/powerrename/unittests/TestFileHelper.cpp
Normal file
73
src/modules/powerrename/unittests/TestFileHelper.cpp
Normal 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user