コード例 #1
2
ファイル: brfilexbox360.cpp プロジェクト: cometdlut/burgerlib
Word Burger::File::SetCreationTime(const TimeDate_t *pInput)
{
	Word uResult = FILENOTFOUND;
	HANDLE fp = m_pFile;
	if (fp) {
		FILETIME CreationTime;
		pInput->Store(&CreationTime);
		// Set the file creation time
		BOOL bFileInfoResult = SetFileTime(fp,&CreationTime,NULL,NULL);
		if (bFileInfoResult) {
			uResult = OKAY;
		}
	}
	return uResult;
}
コード例 #2
1
ファイル: save_map.c プロジェクト: svn2github/Brany_Skeldalu
static char set_date_time(char *filename, unsigned long date, unsigned long time)
  {
#if 0
  HANDLE h=CreateFile(filename,0,0,NULL,OPEN_EXISTING,0,NULL);
  FILETIME WriteTime;
  char err=0;
  if (h==NULL) return 1;
  WriteTime.dwHighDateTime=date;
  WriteTime.dwLowDateTime=time;
  err=SetFileTime(h,NULL,NULL,&WriteTime)==1;
  CloseHandle(h);
  return err;
#endif
  return 0;
  }
コード例 #3
0
bool os_set_file_time(const std::string& fn, int64 created, int64 last_modified, int64 accessed)
{
	HANDLE hFile = CreateFileW(ConvertToWchar(fn).c_str(), FILE_WRITE_ATTRIBUTES, FILE_SHARE_WRITE|FILE_SHARE_READ, NULL,
		OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);

	if(hFile!=INVALID_HANDLE_VALUE)
	{
		FILETIME* pcreation_time = NULL;
		FILETIME creation_time;
		if (created != 0)
		{
			LARGE_INTEGER li;
			li.QuadPart=os_to_windows_filetime(created);

			
			creation_time.dwHighDateTime=li.HighPart;
			creation_time.dwLowDateTime=li.LowPart;	

			pcreation_time = &creation_time;
		}
		
		LARGE_INTEGER li;
		li.QuadPart = os_to_windows_filetime(last_modified);
		FILETIME modified_time;
		modified_time.dwHighDateTime=li.HighPart;
		modified_time.dwLowDateTime=li.LowPart;

		li.QuadPart=os_to_windows_filetime(accessed);

		FILETIME accessed_time;
		accessed_time.dwHighDateTime = li.HighPart;
		accessed_time.dwLowDateTime = li.LowPart;

		if(SetFileTime(hFile, pcreation_time, &accessed_time, &modified_time))
		{
			CloseHandle(hFile);
			return true;
		}
		else
		{
			CloseHandle(hFile);
			return false;
		}
	}
	else
	{
		return false;
	}
}
コード例 #4
0
ファイル: fs.cpp プロジェクト: rcombs/Aegisub
void Touch(path const& file) {
    CreateDirectory(file.parent_path());

    SYSTEMTIME st;
    FILETIME ft;
    GetSystemTime(&st);
    if(!SystemTimeToFileTime(&st, &ft))
        throw EnvironmentError("SystemTimeToFileTime failed with error: " + util::ErrorString(GetLastError()));

    scoped_holder<HANDLE, BOOL (__stdcall *)(HANDLE)>
    h(CreateFile(file.c_str(), GENERIC_WRITE, 0, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr), CloseHandle);
    // error handling etc.
    if (!SetFileTime(h, nullptr, nullptr, &ft))
        throw EnvironmentError("SetFileTime failed with error: " + util::ErrorString(GetLastError()));
}
コード例 #5
0
ファイル: Time.c プロジェクト: xpika/winhugs
static void hugsprim_SetFileTime_12(HugsStackPtr hugs_root)
{
    HsPtr arg1;
    HsPtr arg2;
    HsPtr arg3;
    HsPtr arg4;
    HsBool res1;
    arg1 = hugs->getPtr();
    arg2 = hugs->getPtr();
    arg3 = hugs->getPtr();
    arg4 = hugs->getPtr();
    res1 = SetFileTime(arg1, arg2, arg3, arg4);
    hugs->putBool(res1);
    hugs->returnIO(hugs_root,1);
}
コード例 #6
0
ファイル: tools.cpp プロジェクト: DouglasHeriot/zipper
void changeFileDate(const std::string& filename, uLong dosdate, tm_unz tmu_date)
{
#ifdef _WIN32
	HANDLE hFile;
	FILETIME ftm, ftLocal, ftCreate, ftLastAcc, ftLastWrite;

	hFile = CreateFileA(filename.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
	if (hFile != INVALID_HANDLE_VALUE)
	{
		GetFileTime(hFile, &ftCreate, &ftLastAcc, &ftLastWrite);
		DosDateTimeToFileTime((WORD)(dosdate >> 16), (WORD)dosdate, &ftLocal);
		LocalFileTimeToFileTime(&ftLocal, &ftm);
		SetFileTime(hFile, &ftm, &ftLastAcc, &ftm);
		CloseHandle(hFile);
	}
コード例 #7
0
ファイル: ZipUtilsCP.cpp プロジェクト: ONLYOFFICE/core
  /* change_file_date : change the date/time of a file
     filename : the filename of the file where date/time must be modified
     dosdate : the new date at the MSDos format (4 bytes)
     tmu_date : the SAME new date at the tm_unz format */
  static void change_file_date( const wchar_t *filename, uLong dosdate, tm_unz tmu_date )
  {
#if defined(_WIN32) || defined (_WIN64)
    HANDLE hFile;
    FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite;

    hFile = CreateFileW(filename,GENERIC_READ | GENERIC_WRITE,
                        0,NULL,OPEN_EXISTING,0,NULL);
    GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite);
    DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal);
    LocalFileTimeToFileTime(&ftLocal,&ftm);
    SetFileTime(hFile,&ftm,&ftLastAcc,&ftm);
    CloseHandle(hFile);
#endif
  }
コード例 #8
0
bool MkPath::writeFileDateTime(const QFileInfo &destination)
{
    ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"writeFileDateTime("+destination.absoluteFilePath()+")");
    /** Why not do it with Qt? Because it not support setModificationTime(), and get the time with Qt, that's mean use local time where in C is UTC time */
    #ifdef Q_OS_UNIX
        #ifdef Q_OS_LINUX
            return utime(destination.absoluteFilePath().toLatin1().data(),&butime)==0;
        #else //mainly for mac
            return utime(destination.absoluteFilePath().toLatin1().data(),&butime)==0;
        #endif
    #else
        #ifdef Q_OS_WIN32
            #ifdef ULTRACOPIER_PLUGIN_SET_TIME_UNIX_WAY
                return utime(destination.toLatin1().data(),&butime)==0;
            #else
                wchar_t filePath[65535];
                if(destination.absoluteFilePath().contains(regRead))
                    filePath[QDir::toNativeSeparators(QStringLiteral("\\\\?\\")+destination.absoluteFilePath()).toWCharArray(filePath)]=L'\0';
                else
                    filePath[QDir::toNativeSeparators(destination.absoluteFilePath()).toWCharArray(filePath)]=L'\0';
                HANDLE hFileDestination = CreateFileW(filePath, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
                if(hFileDestination == INVALID_HANDLE_VALUE)
                {
                    ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"open failed to write: "+QString::fromWCharArray(filePath)+", error: "+QString::number(GetLastError()));
                    return false;
                }
                FILETIME ftCreate, ftAccess, ftWrite;
                ftCreate.dwLowDateTime=this->ftCreateL;
                ftCreate.dwHighDateTime=this->ftCreateH;
                ftAccess.dwLowDateTime=this->ftAccessL;
                ftAccess.dwHighDateTime=this->ftAccessH;
                ftWrite.dwLowDateTime=this->ftWriteL;
                ftWrite.dwHighDateTime=this->ftWriteH;
                if(!SetFileTime(hFileDestination, &ftCreate, &ftAccess, &ftWrite))
                {
                    CloseHandle(hFileDestination);
                    ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"unable to set the file time");
                    return false;
                }
                CloseHandle(hFileDestination);
                return true;
            #endif
        #else
            return false;
        #endif
    #endif
    return false;
}
void CWE506_Embedded_Malicious_Code__w32_file_attrib_created_10_bad()
{
    if(globalTrue)
    {
        {
            FILETIME ftCreate;
            ULONGLONG qwResult;
            HANDLE hFile = INVALID_HANDLE_VALUE;
            do
            {
                hFile = CreateFile(TEXT("badFile.txt"),
                                   GENERIC_READ | GENERIC_WRITE, /* needed for SetFileTime to work properly */
                                   0,
                                   NULL,
                                   CREATE_ALWAYS,
                                   FILE_ATTRIBUTE_NORMAL, NULL);
                if (hFile == INVALID_HANDLE_VALUE)
                {
                    break;
                }
                if (GetFileTime(hFile,
                                &ftCreate,
                                NULL,
                                NULL) == 0)
                {
                    break;
                }
                /* adapted from http://support.microsoft.com/kb/188768 */
                qwResult = (((ULONGLONG) ftCreate.dwHighDateTime) << 32) + ftCreate.dwLowDateTime;
                /* Subtract 10 days from real creation date */
                qwResult -= 10 * _DAY;
                /* Copy result back into ftCreate */
                ftCreate.dwLowDateTime  = (DWORD)(qwResult & 0xFFFFFFFF);
                ftCreate.dwHighDateTime = (DWORD)(qwResult >> 32);
                /* FLAW: Modify the file's creation time */
                SetFileTime(hFile,
                            &ftCreate,
                            (LPFILETIME)NULL,
                            (LPFILETIME)NULL);
            }
            while (0);
            if (hFile != INVALID_HANDLE_VALUE)
            {
                CloseHandle(hFile);
            }
        }
    }
}
コード例 #10
0
ファイル: win32stm.cpp プロジェクト: Cpasjuste/nzbm
void ExtractStreams(Archive &Arc,const wchar *FileName,bool TestMode)
{
  wchar FullName[NM+2];
  if (FileName[0]!=0 && FileName[1]==0)
  {
    wcscpy(FullName,L".\\");
    wcsncpyz(FullName+2,FileName,ASIZE(FullName)-2);
  }
  else
    wcsncpyz(FullName,FileName,ASIZE(FullName));

  byte *Data=&Arc.SubHead.SubData[0];
  size_t DataSize=Arc.SubHead.SubData.Size();

  wchar StreamName[NM];
  GetStreamNameNTFS(Arc,StreamName,ASIZE(StreamName));
  if (*StreamName!=':')
  {
    uiMsg(UIERROR_STREAMBROKEN,Arc.FileName,FileName);
    ErrHandler.SetErrorCode(RARX_CRC);
    return;
  }

  if (TestMode)
  {
    Arc.ReadSubData(NULL,NULL);
    return;
  }

  wcsncatz(FullName,StreamName,ASIZE(FullName));

  FindData fd;
  bool Found=FindFile::FastFind(FileName,&fd);

  if ((fd.FileAttr & FILE_ATTRIBUTE_READONLY)!=0)
    SetFileAttr(FileName,fd.FileAttr & ~FILE_ATTRIBUTE_READONLY);
  File CurFile;
  if (CurFile.WCreate(FullName) && Arc.ReadSubData(NULL,&CurFile))
    CurFile.Close();
  File HostFile;
  if (Found && HostFile.Open(FileName,FMF_OPENSHARED|FMF_UPDATE))
    SetFileTime(HostFile.GetHandle(),&fd.ftCreationTime,&fd.ftLastAccessTime,
                &fd.ftLastWriteTime);

  // Restoring original file attributes. Important if file was read only
  // or did not have "Archive" attribute
  SetFileAttr(FileName,fd.FileAttr);
}
コード例 #11
0
ファイル: file.cpp プロジェクト: chicken1337/kx-audio-driver
void File::SetOpenFileTime(RarTime *ftm,RarTime *ftc,RarTime *fta)
{
#ifdef _WIN_32
  bool sm=ftm!=NULL && ftm->IsSet();
  bool sc=ftc!=NULL && ftc->IsSet();
  bool sa=fta!=NULL && fta->IsSet();
  FILETIME fm,fc,fa;
  if (sm)
    ftm->GetWin32(&fm);
  if (sc)
    ftc->GetWin32(&fc);
  if (sa)
    fta->GetWin32(&fa);
  SetFileTime(hFile,sc ? &fc:NULL,sa ? &fa:NULL,sm ? &fm:NULL);
#endif
}
コード例 #12
0
ファイル: file.cpp プロジェクト: ajnelson/bulk_extractor
/**
this is not needed for bulk_extractor
*/
void File::SetOpenFileTime(RarTime *ftm,RarTime *ftc,RarTime *fta)
{ //We probably don't need to worry about this at all
#ifdef _WIN_ALL
  bool sm=ftm!=NULL && ftm->IsSet();
  bool sc=ftc!=NULL && ftc->IsSet();
  bool sa=fta!=NULL && fta->IsSet();
  FILETIME fm,fc,fa;
  if (sm)
    ftm->GetWin32(&fm);
  if (sc)
    ftc->GetWin32(&fc);
  if (sa)
    fta->GetWin32(&fa);
  SetFileTime(hFile,sc ? &fc:NULL,sa ? &fa:NULL,sm ? &fm:NULL);
#endif
}
コード例 #13
0
ファイル: fsdb_mywin32.cpp プロジェクト: engur/WinUAE
static int setfiletime (const TCHAR *name, int days, int minute, int tick, int tolocal)
{
	FILETIME LocalFileTime, FileTime;
	HANDLE hFile;
	const TCHAR *namep;
	TCHAR path[MAX_DPATH];
	
	if (currprefs.win32_filesystem_mangle_reserved_names == false) {
		_tcscpy (path, PATHPREFIX);
		_tcscat (path, name);
		namep = path;
	} else {
		namep = name;
	}

	if ((hFile = CreateFile (namep, GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, NULL)) == INVALID_HANDLE_VALUE)
		return 0;

	for (;;) {
		ULARGE_INTEGER lft;

		lft.QuadPart = (((uae_u64)(377*365+91+days)*(uae_u64)1440+(uae_u64)minute)*(uae_u64)(60*50)+(uae_u64)tick)*(uae_u64)200000;
		LocalFileTime.dwHighDateTime = lft.HighPart;
		LocalFileTime.dwLowDateTime = lft.LowPart;
		if (tolocal) {
			if (!LocalFileTimeToFileTime (&LocalFileTime, &FileTime))
				FileTime = LocalFileTime;
		} else {
			FileTime = LocalFileTime;
		}
		if (!SetFileTime (hFile, &FileTime, &FileTime, &FileTime)) {
			if (days > 47846) { // > 2108-12-31 (fat limit)
				days = 47846;
				continue;
			}
			if (days < 730) { // < 1980-01-01 (fat limit)
				days = 730;
				continue;
			}
		}
		break;
	}

	CloseHandle (hFile);

	return 1;
}
コード例 #14
0
ファイル: winfstest.c プロジェクト: nkzxw/winfstest
static int do_SetFileTime(int argc, wchar_t **argv)
{
    if (argc != 5)
        fail("usage: SetFileTime FileName CreationTime LastAccessTime LastWriteTime");
    HANDLE h = CreateFileW(argv[1],
        FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
        0, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, 0);
    if (INVALID_HANDLE_VALUE == h)
        errprint(0);
    else
    {
        FILETIME *CreationTime = 0, *LastAccessTime = 0, *LastWriteTime = 0, ft[3];
        SYSTEMTIME systime;
        memset(&systime, 0, sizeof systime);
        systime.wMonth = systime.wDay = 1;
        if (0 < swscanf(argv[2], L"%hd-%02hd-%02hdT%02hd:%02hd:%02hd",
            &systime.wYear, &systime.wMonth, &systime.wDay,
            &systime.wHour, &systime.wMinute, &systime.wSecond))
        {
            if (SystemTimeToFileTime(&systime, &ft[0]))
                CreationTime = &ft[0];
        }
        memset(&systime, 0, sizeof systime);
        systime.wMonth = systime.wDay = 1;
        if (0 < swscanf(argv[3], L"%hd-%02hd-%02hdT%02hd:%02hd:%02hd",
            &systime.wYear, &systime.wMonth, &systime.wDay,
            &systime.wHour, &systime.wMinute, &systime.wSecond))
        {
            if (SystemTimeToFileTime(&systime, &ft[1]))
                LastAccessTime = &ft[1];
        }
        memset(&systime, 0, sizeof systime);
        systime.wMonth = systime.wDay = 1;
        if (0 < swscanf(argv[4], L"%hd-%02hd-%02hdT%02hd:%02hd:%02hd",
            &systime.wYear, &systime.wMonth, &systime.wDay,
            &systime.wHour, &systime.wMinute, &systime.wSecond))
        {
            if (SystemTimeToFileTime(&systime, &ft[2]))
                LastWriteTime = &ft[2];
        }
        BOOL r = SetFileTime(h, CreationTime, LastAccessTime, LastWriteTime);
        errprint(r);
        CloseHandle(h);
    }
    return 0;
}
コード例 #15
0
bool File::lastModified(time_t modtime)
{
# ifdef _WIN32
  HANDLE hf = CreateFile(pathname, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
  if (hf == INVALID_HANDLE_VALUE)
    return false;
  FILETIME cft = ::NetworkTimeToFileTime(modtime);
  BOOL bret = SetFileTime(hf, NULL, NULL, &cft);
  CloseHandle(hf);
  return bret == TRUE;    
# else
  utimbuf buf;
  buf.actime = (long)(lastAccessed() / 1000);
  buf.modtime = (long)(modtime / 1000);
  return ::utime(pathname, &buf) == 0;
# endif
}
コード例 #16
0
ファイル: system_win_stubs.c プロジェクト: Phylliade/Unison
CAMLprim value win_utimes (value path, value wpath, value atime, value mtime) {
  HANDLE h;
  BOOL res;
  ULARGE_INTEGER iatime, imtime;
  FILETIME fatime, fmtime;

  CAMLparam4(path, wpath, atime, mtime);

  iatime.QuadPart = Double_val(atime);
  imtime.QuadPart = Double_val(mtime);

  /* http://www.filewatcher.com/p/Win32-UTCFileTime-1.44.tar.gz.93147/Win32-UTCFileTime-1.44/UTCFileTime.xs.html */
  /* http://savannah.nongnu.org/bugs/?22781#comment0 */
  if (iatime.QuadPart || imtime.QuadPart) {
    iatime.QuadPart += 11644473600ull;
    iatime.QuadPart *= 10000000ull;
    fatime.dwLowDateTime = iatime.LowPart;
    fatime.dwHighDateTime = iatime.HighPart;
    imtime.QuadPart += 11644473600ull;
    imtime.QuadPart *= 10000000ull;
    fmtime.dwLowDateTime = imtime.LowPart;
    fmtime.dwHighDateTime = imtime.HighPart;
  } else {
    GetSystemTimeAsFileTime (&fatime);
    fmtime = fatime;
  }
  h = CreateFileW ((LPWSTR) wpath, FILE_WRITE_ATTRIBUTES,
		   FILE_SHARE_READ | FILE_SHARE_WRITE,
		   NULL, OPEN_EXISTING, 0, NULL);
  if (h == INVALID_HANDLE_VALUE) {
    win32_maperr (GetLastError ());
    uerror("utimes", path);
  }
  res = SetFileTime (h, NULL, &fatime, &fmtime);
  if (res == 0) {
    win32_maperr (GetLastError ());
    (void)CloseHandle (h);
    uerror("utimes", path);
  }
  res = CloseHandle (h);
  if (res == 0) {
    win32_maperr (GetLastError ());
    uerror("utimes", path);
  }
  CAMLreturn (Val_unit);
}
コード例 #17
0
//---------------------------------------------------------------------
// get a remote file -> local
bool Server::cmdGet(bstring const & remotePath, bstring const & localName, bool exists)
{
	DBGPRINT(("get '%s' '%s' %b\r\n", remotePath.c_str(), localName.c_str(), exists));
	bstring cmd = bstring(exists ? TEXT("reget \"") : TEXT("get \"")) + remotePath + TEXT("\" \"") + localName + TEXT("\"");

	if (!doCommand(cmd))
		return false;

	FILETIME ft;
	fxp_attrs * attr = currentMapper->getLastAttr();
	if (UnixTimeToFileTime(attr->mtime, &ft)) {
		HANDLE hf = CreateFile(localName.c_str(), GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
		SetFileTime(hf, &ft, &ft, &ft);
		CloseHandle(hf);
	}
	return true;
}
コード例 #18
0
BOOL OnApply ( HWND hwnd, PSHNOTIFY* phdr )
{
LPCTSTR  szFile = (LPCTSTR) GetWindowLong ( hwnd, GWL_USERDATA );
HANDLE   hFile;
FILETIME ftModified, ftAccessed, ftCreated;

    // Open the file.

    hFile = CreateFile ( szFile, GENERIC_WRITE, FILE_SHARE_READ, NULL,
                         OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );

    if ( INVALID_HANDLE_VALUE != hFile )
        {
        // Retrieve the dates/times from the DTP controls.

        GetCombinedDateTime ( hwnd, IDC_MODIFIED_DATE, IDC_MODIFIED_TIME,
                              &ftModified );

        GetCombinedDateTime ( hwnd, IDC_ACCESSED_DATE, 0,
                              &ftAccessed );

        GetCombinedDateTime ( hwnd, IDC_CREATED_DATE, IDC_CREATED_TIME,
                              &ftCreated );

        // Change the file's created, accessed, and last modified times.

        SetFileTime ( hFile, &ftCreated, &ftAccessed, &ftModified );
        CloseHandle ( hFile );
        }
    else
        {
        // Couldn't open the file!  Show an error message.

        std::strstream strMsg;

        strMsg << _T("Unable to open file \"") << szFile << _T("\" for writing.\n\n")
               << _T("Changes will not be saved.");

        MessageBox ( hwnd, strMsg.str(), _T("FileTime Extension"), MB_ICONERROR );
        }

    // Return PSNRET_NOERROR to allow the sheet to close if the user clicked OK.

    SetWindowLong ( hwnd, DWL_MSGRESULT, PSNRET_NOERROR );
    return TRUE;
}
コード例 #19
0
        STDMETHODIMP ArchiveExtractCallback::SetOperationResult(Int32 operationResult)
        {
            if (m_overwriteMode == OverwriteMode::kRollBack && operationResult != S_OK)
            {
                _ASSERT_EXPR(FALSE,L"begin rollback");
                bool succ = ProcessRollBack(); succ;
                _ASSERT_EXPR(succ, L"rollback error!");
                return E_FAIL;
            }
            

            if (m_absPath.empty())
            {
                wprintf_s(L"AllDone\n");
                if (m_callback)
                    m_callback->OnEnd(m_directory);
                return S_OK;
            }

            if (m_hasModifiedTime || m_hasAccessedTime || m_hasCreatedTime)
            {
                HANDLE fileHandle = CreateFile(m_absPath.c_str(), GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
                if (fileHandle != INVALID_HANDLE_VALUE)
                {
                    SetFileTime(fileHandle,
                        m_hasCreatedTime ? &m_createdTime : NULL,
                        m_hasAccessedTime ? &m_accessedTime : NULL,
                        m_hasModifiedTime ? &m_modifiedTime : NULL);
                    CloseHandle(fileHandle);
                }
            }

            if (m_hasAttrib)
            {
                SetFileAttributes(m_absPath.c_str(), m_attrib);
            }

            wprintf_s(L"FileDone:%s\n", m_absPath.c_str());
            if (m_callback)
            {
                if(!m_callback->OnFileDone(m_absPath, m_newFileSize))
                    return E_FAIL;
                m_callback->OnProgress(m_absPath, m_newFileSize);
            }
            return S_OK;
        }
コード例 #20
0
ファイル: CacheDlg.cpp プロジェクト: stahta01/wxTortoiseGit
void CCacheDlg::TouchFile(const CString& path)
{
	SetFileAttributes(path, FILE_ATTRIBUTE_NORMAL);
	HANDLE hFile = CreateFile(path, GENERIC_WRITE, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
	if (hFile == INVALID_HANDLE_VALUE)
		return;

	FILETIME ft;
	SYSTEMTIME st;

	GetSystemTime(&st);              // gets current time
	SystemTimeToFileTime(&st, &ft);  // converts to file time format
	SetFileTime(hFile,           // sets last-write time for file
		(LPFILETIME) NULL, (LPFILETIME) NULL, &ft);

	CloseHandle(hFile);
}
コード例 #21
0
ファイル: win_prim_file.c プロジェクト: HansN/otp
posix_errno_t efile_set_time(const efile_path_t *path, Sint64 a_time, Sint64 m_time, Sint64 c_time) {
    FILETIME accessed, modified, created;
    DWORD last_error, attributes;
    HANDLE handle;

    attributes = GetFileAttributesW((WCHAR*)path->data);

    if(attributes == INVALID_FILE_ATTRIBUTES) {
        return windows_to_posix_errno(GetLastError());
    }

    /* If the file is read-only, we have to make it temporarily writable while
     * setting new metadata. */
    if(attributes & FILE_ATTRIBUTE_READONLY) {
        DWORD without_readonly = attributes & ~FILE_ATTRIBUTE_READONLY;

        if(!SetFileAttributesW((WCHAR*)path->data, without_readonly)) {
            return windows_to_posix_errno(GetLastError());
        }
    }

    EPOCH_TO_FILETIME(modified, m_time);
    EPOCH_TO_FILETIME(accessed, a_time);
    EPOCH_TO_FILETIME(created, c_time);

    handle = CreateFileW((WCHAR*)path->data, GENERIC_READ | GENERIC_WRITE,
        FILE_SHARE_FLAGS, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
    last_error = GetLastError();

    if(handle != INVALID_HANDLE_VALUE) {
        if(SetFileTime(handle, &created, &accessed, &modified)) {
            last_error = ERROR_SUCCESS;
        } else {
            last_error = GetLastError();
        }

        CloseHandle(handle);
    }

    if(attributes & FILE_ATTRIBUTE_READONLY) {
        SetFileAttributesW((WCHAR*)path->data, attributes);
    }

    return windows_to_posix_errno(last_error);
}
コード例 #22
0
bool LoadOldXMLData(const Category cat, bool update_age) {
	TCHAR xml_data_filename[MAX_PATH];
	TCHAR *ts;
	mir_sntprintf(xml_data_filename, SIZEOF(xml_data_filename), _T("%s\\%s.xml"),
		options.data_folder, (ts = GetTString(category_files[cat])));
	mir_free(ts);

	if(pData[cat]) free(pData[cat]);
	pData[cat] = 0;
	dataLength[cat] = 0;

	// load 
	HANDLE hDataFile = CreateFile(xml_data_filename, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
	if(hDataFile != INVALID_HANDLE_VALUE) {
		dataLength[cat] = GetFileSize(hDataFile, 0);
		if(dataLength[cat]) {
			unsigned long bytes_read;
			pData[cat] = (BYTE *)malloc(dataLength[cat]);
			if(ReadFile(hDataFile, pData[cat], dataLength[cat], &bytes_read, 0))
				dataLength[cat] = bytes_read;
			else {
				free(pData[cat]);
				pData[cat] = 0;
				dataLength[cat] = 0;
			}

		}

		if(update_age) {
			FILETIME ft_now;
			SYSTEMTIME now;
			GetSystemTime(&now);
			SystemTimeToFileTime(&now, &ft_now);
			SetFileTime(hDataFile, 0, 0, &ft_now);
		}

		CloseHandle(hDataFile);
	}
	
	if(pData[cat] && dataLength[cat]) {
		doc[cat] = ezxml_parse_str((char*)pData[cat], dataLength[cat]);
		return doc[cat] != NULL;
	}
	return false;
}
コード例 #23
0
ファイル: fsdos.c プロジェクト: RealityFactory/Genesis3D
static	geBoolean	GENESISCC FSDos_SetTime(void *Handle, const geVFile_Time *Time)
{
	DosFile *	File;
	FILETIME	Win32Time;

	File = Handle;

	CHECK_HANDLE(File);

	assert(File->FileHandle != INVALID_HANDLE_VALUE);

	Win32Time.dwLowDateTime  = Time->Time1;
	Win32Time.dwHighDateTime = Time->Time2;
	if	(SetFileTime(File->FileHandle, &Win32Time, &Win32Time, &Win32Time) == FALSE)
		return GE_FALSE;

	return GE_TRUE;
}
コード例 #24
0
ファイル: FileHelper.cpp プロジェクト: fffonion/V8
		BOOL  SetFileTime(const std::wstring& sPath, LPFILETIME lpCreationTime, LPFILETIME lpLastAccessTime, LPFILETIME lpLastWriteTime)
		{
			WIN32_FIND_DATA FindFileData;	

			HANDLE hFile = CreateFile(sPath.c_str(), GENERIC_ALL, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
			if (hFile == INVALID_HANDLE_VALUE)
			{
				return FALSE ;
			}
			else
			{	
				
				SetFileTime(hFile,lpCreationTime,lpLastAccessTime,lpLastWriteTime);
				CloseHandle(hFile);
				return TRUE;

			}
		}
コード例 #25
0
ファイル: util-win32.cpp プロジェクト: UIKit0/git-crypt
void	touch_file (const std::string& filename)
{
	HANDLE	fh = CreateFileA(filename.c_str(), FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
	if (fh == INVALID_HANDLE_VALUE) {
		throw System_error("CreateFileA", filename, GetLastError());
	}
	SYSTEMTIME	system_time;
	GetSystemTime(&system_time);
	FILETIME	file_time;
	SystemTimeToFileTime(&system_time, &file_time);

	if (!SetFileTime(fh, NULL, NULL, &file_time)) {
		DWORD	error = GetLastError();
		CloseHandle(fh);
		throw System_error("SetFileTime", filename, error);
	}
	CloseHandle(fh);
}
コード例 #26
0
ファイル: ULTI_File.cpp プロジェクト: wizebin/ulti
int setFileTimes(const std::string& filename, unsigned long modified, unsigned long created, unsigned long accessed){
    // Create a FILETIME struct and convert our new SYSTEMTIME
    // over to the FILETIME struct for use in SetFileTime below
    FILETIME modtime,createtime,accesstime;

    UnixTimeToFileTime(created,&createtime);
    UnixTimeToFileTime(accessed,&accesstime);

    // Get a handle to our file and with file_write_attributes access
    HANDLE fhnd = CreateFileA(filename.c_str(), FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

    // Set the file time on the file
    int ret = SetFileTime(fhnd,&createtime,&accesstime,&modtime);

    // Close our handle.
    CloseHandle(fhnd);
	return ret;
}
コード例 #27
0
/* 
   If creation is false, the LastAccessTime will be set according to
   times->actime. Otherwise, CreationTime will be set. LastWriteTime
   is always set according to times->modtime.
*/
static int win_utime_creation(const char *path, const struct utimbuf *times,
			      int creation)
{
    wchar_t *winpath;
    int ret = 0;
    HANDLE h;
    ULARGE_INTEGER fti;
    FILETIME xtime, mtime;

    if (!strcmp("/", path)) {
	/* Emulate root */
	errno = EROFS;
	return -1;
    }

    winpath = intpath2winpath(path);
    if (!winpath) {
	errno = EINVAL;
	return -1;
    }

    /* Unfortunately, we cannot use utime(), since it doesn't support
       directories. */
    fti.QuadPart = UInt32x32To64(times->actime + FT70SEC, 10000000);
    xtime.dwHighDateTime = fti.HighPart;
    xtime.dwLowDateTime = fti.LowPart;
    fti.QuadPart = UInt32x32To64(times->modtime + FT70SEC, 10000000);
    mtime.dwHighDateTime = fti.HighPart;
    mtime.dwLowDateTime = fti.LowPart;

    h = CreateFileW(winpath, FILE_WRITE_ATTRIBUTES,
		    FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
		    FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, NULL);

    if (!SetFileTime
	(h, creation ? &xtime : NULL, creation ? NULL : &xtime, &mtime)) {
	errno = EACCES;
	ret = -1;
    }

    CloseHandle(h);
    free(winpath);
    return ret;
}
コード例 #28
0
ファイル: setfiletime.c プロジェクト: ArildF/masters
int __cdecl main(int argc, char **argv)
{

    FILETIME SetCreation, SetLastWrite, SetLastAccess;
    HANDLE TheFileHandle = NULL;
    BOOL result;
    
    if (0 != PAL_Initialize(argc,argv))
    {
        return FAIL;
    }

    /* Populate some FILETIME structures with values 
       These values are valid Creation, Access and Write times
       which I generated, and should work properly.
    */

    SetCreation.dwLowDateTime = 458108416;
    SetCreation.dwHighDateTime = 29436904;

    SetLastAccess.dwLowDateTime = 341368832;
    SetLastAccess.dwHighDateTime = 29436808;

    SetLastWrite.dwLowDateTime = -1995099136;
    SetLastWrite.dwHighDateTime = 29436915;

    
    /* Pass this function an invalid file HANDLE and it should
       fail.
    */
    
    result = SetFileTime(TheFileHandle,
                         &SetCreation,&SetLastAccess,&SetLastWrite);
    
    if(result != 0)
    {
        Fail("ERROR: Passed an invalid file HANDLE to SetFileTime, but it "
               "returned non-zero.  This should return zero for failure.");
    }
    

    PAL_Terminate();
    return PASS;
}
コード例 #29
0
void AttributesAndDateChangerThread::changeTimes(const WinFileInfo& fileInfo) const
{
    // TODO: time changes are not calculated in local time so the shift is not correct
    if(timesNeedChange())
    {
        HANDLE file;
        // Process needs admin rights to succeed here
        if((file = CreateFile(fileInfo.filePath().toStdWString().c_str(),
                              GENERIC_ALL,
                              FILE_SHARE_READ|FILE_SHARE_WRITE,
                              0,
                              OPEN_EXISTING,
                              0,
                              0)) != INVALID_HANDLE_VALUE)
        {
            FILETIME creationTime, lastAccessTime, lastModificationTime;

            WinFileInfo::timetToFileTime(properties_.changeCreationTime_
                                            ? properties_.creationTimestamp_
                                            : fileInfo.creationTime(),
                                         &creationTime);

            WinFileInfo::timetToFileTime(fileInfo.lastAccessTime(), &lastAccessTime);

            if(properties_.shiftModificationTime_)
            {
                time_t newModTime=fileInfo.lastModificationTime()+properties_.modificationTimeShiftInSeconds_;
                WinFileInfo::timetToFileTime(newModTime, &lastModificationTime);
                lastAccessTime=lastModificationTime;
            }
            else
            {
                WinFileInfo::timetToFileTime(properties_.changeLastModificationTime_
                                                ? properties_.lastModificationTimestamp_
                                                : fileInfo.lastModificationTime(),
                                             &lastModificationTime);
                lastAccessTime=lastModificationTime;
            }

            SetFileTime(file, &creationTime, &lastAccessTime, &lastModificationTime);
        }
        CloseHandle(file);
    }
}
コード例 #30
0
ファイル: file.c プロジェクト: BIGKAT/GDC
int File::append()
{
#if POSIX
    return 1;
#elif _WIN32
    HANDLE h;
    DWORD numwritten;
    char *name;

    name = this->name->toChars();
    h = CreateFileA(name,GENERIC_WRITE,0,NULL,OPEN_ALWAYS,
        FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,NULL);
    if (h == INVALID_HANDLE_VALUE)
        goto err;

#if 1
    SetFilePointer(h, 0, NULL, FILE_END);
#else // INVALID_SET_FILE_POINTER doesn't seem to have a definition
    if (SetFilePointer(h, 0, NULL, FILE_END) == INVALID_SET_FILE_POINTER)
        goto err;
#endif

    if (WriteFile(h,buffer,len,&numwritten,NULL) != TRUE)
        goto err2;

    if (len != numwritten)
        goto err2;

    if (touchtime) {
        SetFileTime(h, NULL, NULL, &((WIN32_FIND_DATAA *)touchtime)->ftLastWriteTime);
    }
    if (!CloseHandle(h))
        goto err;
    return 0;

err2:
    CloseHandle(h);
err:
    return 1;
#else
    assert(0);
#endif
}