BlinkenArea - GitList
Repositories
Blog
Wiki
Blinker
Code
Commits
Branches
Tags
Search
Tree:
3e57fe4
Branches
Tags
master
Blinker
src
windows
File.cpp
implement file and time for Windows
Stefan Schuermans
commited
3e57fe4
at 2017-09-24 11:03:40
File.cpp
Blame
History
Raw
/* Blinker Copyright 2011-2014 Stefan Schuermans <stefan@blinkenarea.org> Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html a blinkenarea.org project */ #include <string> #include <windows.h> #include "File.h" #include "Time.h" namespace Blinker { /** * @brief constructor from path * @param[in] path path to file */ File::File(const std::string &path): m_path(path) { // get modification time checkModified(); } /** * @brief get path to file * @return path to file */ const std::string & File::getPath() { return m_path; } /** * @brief check if file has been modified * @return if file has been modified since last check */ bool File::checkModified() { // get handle to file HANDLE handle = CreateFile(m_path.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (handle == INVALID_HANDLE_VALUE) { return false; // cannot open -> silently ignore } // get last write time FILETIME wrTime; if (! GetFileTime(handle, NULL, NULL, &wrTime)) { CloseHandle(handle); return false; // cannot get last write time -> silently ignore } // close handle CloseHandle(handle); // modification time is last write time Time modifyTime; modifyTime.fromFileTime(wrTime); // consider file modified if modify time changed since last check bool mod = modifyTime > m_lastModifyTime; // remember new modify time m_lastModifyTime = modifyTime; return mod; } } // namespace Blinker