稳定版本备份
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user