24 lines
685 B
C++
24 lines
685 B
C++
#include <fileManager.h>
|
|
#include <Windows.h>
|
|
|
|
bool fileManager::setFileReadOnly(const std::string& filePath, bool readOnly) {
|
|
DWORD attributes = GetFileAttributes(filePath.c_str());
|
|
if (attributes == INVALID_FILE_ATTRIBUTES) {
|
|
std::cerr << "Error getting file attributes: " << GetLastError() << std::endl;
|
|
return false;
|
|
}
|
|
|
|
if (readOnly) {
|
|
attributes |= FILE_ATTRIBUTE_READONLY;
|
|
}
|
|
else {
|
|
attributes &= ~FILE_ATTRIBUTE_READONLY;
|
|
}
|
|
|
|
if (!SetFileAttributes(filePath.c_str(), attributes)) {
|
|
std::cerr << "Error setting file attributes: " << GetLastError() << std::endl;
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
} |