Files
eUi/include/simpleTools/fileManager.cpp
T
2025-08-25 15:53:05 +08:00

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;
}