искать строку с "====="
Code: Select all
static bool process_single_file(
string const& Name,
state const& Current,
state const& New,
function_ref<const string&(int)> const DateTimeAccessor,
bool& SkipErrors)
{
if (!New.Owner.empty() && !equal_icase(Current.Owner, New.Owner))
{
ESetFileOwner(Name, New.Owner, SkipErrors);
}
if (New.FindData.Attributes != Current.FindData.Attributes)
{
ESetFileCompression(Name, (New.FindData.Attributes & FILE_ATTRIBUTE_COMPRESSED) != 0, Current.FindData.Attributes, SkipErrors);
ESetFileEncryption(Name, (New.FindData.Attributes & FILE_ATTRIBUTE_ENCRYPTED) != 0, Current.FindData.Attributes, SkipErrors);
ESetFileSparse(Name, (New.FindData.Attributes & FILE_ATTRIBUTE_SPARSE_FILE) != 0, Current.FindData.Attributes, SkipErrors);
const auto IsChanged = [&](os::fs::attributes const Attributes)
{
return (New.FindData.Attributes & Attributes) != (Current.FindData.Attributes & Attributes);
};
if (IsChanged(FILE_ATTRIBUTE_REPARSE_POINT))
{
EDeleteReparsePoint(Name, Current.FindData.Attributes, SkipErrors);
}
const auto OtherAttributes = ~(FILE_ATTRIBUTE_ENCRYPTED | FILE_ATTRIBUTE_COMPRESSED | FILE_ATTRIBUTE_SPARSE_FILE | FILE_ATTRIBUTE_REPARSE_POINT);
if (IsChanged(OtherAttributes))
{
ESetFileAttributes(Name, New.FindData.Attributes & OtherAttributes, SkipErrors);
}
}
//========= инициализация (пока принимаются как исходные)
os::chrono::time_point WriteTime = Current.FindData.LastWriteTime;
os::chrono::time_point CreationTime = Current.FindData.CreationTime;
os::chrono::time_point AccessTime = Current.FindData.LastAccessTime;
os::chrono::time_point ChangeTime = Current.FindData.ChangeTime;
bool UserTimeSet = false; //======== флажок на изменения TimeStamp от user
std::array TimePointers{ &WriteTime, & CreationTime, & AccessTime, & ChangeTime };
for (const auto& [i, TimePointer] : zip(TimeMap, TimePointers))
{
const auto OriginalTime = std::invoke(i.Accessor, Current.FindData);
if (!construct_time(OriginalTime, *TimePointer, DateTimeAccessor(i.DateId), DateTimeAccessor(i.TimeId))
|| *TimePointer == OriginalTime)
{
*TimePointer = OriginalTime; //======= user не задал время-дата (construct_time=false)
}
else
{
UserTimeSet = true; //====== user задал хотя бы одно время-дата
}
}
if (!UserTimeSet) //======= user не задал ни одной даты, принять исходные (оригинальные) TimeStamps
{
WriteTime = Current.FindData.LastWriteTime;
CreationTime = Current.FindData.CreationTime;
AccessTime = Current.FindData.LastAccessTime;
ChangeTime = Current.FindData.ChangeTime;
}
//======= строго возвращаем TimeStamp, иначе Windows затрёт ChangeTime
ESetFileTime(Name, &WriteTime, &CreationTime, &AccessTime, &ChangeTime, Current.FindData.Attributes, SkipErrors);
return true;
}
искать строку с "====="
Code: Select all
static bool process_single_file(
const string& Computer,
string const& Name,
state const& Current,
state const& New,
function_ref<const string&(int)> const DateTimeAccessor,
bool const IsUTC,
bool& SkipErrors)
{
if (!New.Owner.empty() && !equal_icase(Current.Owner, New.Owner))
{
ESetFileOwner(Computer, Name, New.Owner, SkipErrors);
}
if (New.FindData.Attributes != Current.FindData.Attributes)
{
ESetFileCompression(Name, (New.FindData.Attributes & FILE_ATTRIBUTE_COMPRESSED) != 0, Current.FindData.Attributes, SkipErrors);
ESetFileEncryption(Name, (New.FindData.Attributes & FILE_ATTRIBUTE_ENCRYPTED) != 0, Current.FindData.Attributes, SkipErrors);
ESetFileSparse(Name, (New.FindData.Attributes & FILE_ATTRIBUTE_SPARSE_FILE) != 0, Current.FindData.Attributes, SkipErrors);
const auto IsChanged = [&](os::fs::attributes const Attributes)
{
return (New.FindData.Attributes & Attributes) != (Current.FindData.Attributes & Attributes);
};
if (IsChanged(FILE_ATTRIBUTE_REPARSE_POINT))
{
EDeleteReparsePoint(Name, Current.FindData.Attributes, SkipErrors);
}
const auto OtherAttributes = ~(FILE_ATTRIBUTE_ENCRYPTED | FILE_ATTRIBUTE_COMPRESSED | FILE_ATTRIBUTE_SPARSE_FILE | FILE_ATTRIBUTE_REPARSE_POINT);
if (IsChanged(OtherAttributes))
{
ESetFileAttributes(Name, New.FindData.Attributes & OtherAttributes, SkipErrors);
}
}
{
os::chrono::time_point Times[4]{};
bool UserTimeSet = false; //============ флажок на изменения TimeStamp от user
for (const auto& [i, Time]: zip(TimeMap, Times))
{
const auto OriginalTime = std::invoke(i.Accessor, Current.FindData);
if (const auto Result = (IsUTC? construct_time_from_utc : construct_time_from_localtime)(OriginalTime, DateTimeAccessor(i.DateId), DateTimeAccessor(i.TimeId)); Result && *Result != OriginalTime)
{
Time = *Result;
UserTimeSet = true; //======= user задал хотя бы одно время-дата
}
else
{
Time = OriginalTime; //========== user не задал время-дата (construct_time=false)
}
}
if (!UserTimeSet) //========= user не задал ни одной даты, принять исходные (оригинальные) TimeStamps
{
Times[label_to_time_map_index(SA_TEXT_LASTWRITE)] = Current.FindData.LastWriteTime;
Times[label_to_time_map_index(SA_TEXT_CREATION)] = Current.FindData.CreationTime;
Times[label_to_time_map_index(SA_TEXT_LASTACCESS)] = Current.FindData.LastAccessTime;
Times[label_to_time_map_index(SA_TEXT_CHANGE)] = Current.FindData.ChangeTime;
}
ESetFileTime(
Name,
Times[label_to_time_map_index(SA_TEXT_LASTWRITE)],
Times[label_to_time_map_index(SA_TEXT_CREATION)],
Times[label_to_time_map_index(SA_TEXT_LASTACCESS)],
Times[label_to_time_map_index(SA_TEXT_CHANGE)],
SkipErrors
);
}
return true;
}