-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
1,042 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef FILEACTION_H | ||
#define FILEACTION_H | ||
|
||
namespace Nickvision::Aura::Filesystem | ||
{ | ||
/** | ||
* @brief Actions that cause a file to change. | ||
*/ | ||
enum class FileAction | ||
{ | ||
Added = 1, | ||
Removed, | ||
Modified, | ||
Renamed | ||
}; | ||
} | ||
|
||
#endif //FILEACTION_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#ifndef FILESYSTEMCHANGEDEVENTARGS_H | ||
#define FILESYSTEMCHANGEDEVENTARGS_H | ||
|
||
#include <filesystem> | ||
#include "fileaction.h" | ||
#include "events/eventargs.h" | ||
|
||
namespace Nickvision::Aura::Filesystem | ||
{ | ||
/** | ||
* @brief Event args for when a file system object is changed. | ||
*/ | ||
class FileSystemChangedEventArgs : public Events::EventArgs | ||
{ | ||
public: | ||
/** | ||
* @brief Constructs a FileSystemChangedEventArgs. | ||
* @param path The path of the file/folder that changed | ||
* @param why The action that caused the file to change | ||
*/ | ||
FileSystemChangedEventArgs(const std::filesystem::path& path, FileAction why); | ||
/** | ||
* @brief Gets the path of the changed file system object. | ||
* @return The path of the changed file/folder | ||
*/ | ||
const std::filesystem::path& getPath() const; | ||
/** | ||
* @brief Gets the action that caused the file to change. | ||
* @return The action that caused the file to change | ||
*/ | ||
FileAction getWhy() const; | ||
|
||
private: | ||
std::filesystem::path m_path; | ||
FileAction m_why; | ||
}; | ||
} | ||
|
||
#endif //FILESYSTEMCHANGEDEVENTARGS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#ifndef FILESYSTEMWATCHER_H | ||
#define FILESYSTEMWATCHER_H | ||
|
||
#include <filesystem> | ||
#include <mutex> | ||
#include <thread> | ||
#include <vector> | ||
#include "filesystemchangedeventargs.h" | ||
#include "watcherflags.h" | ||
#include "events/event.h" | ||
#ifdef _WIN32 | ||
#include <windows.h> | ||
#endif | ||
|
||
namespace Nickvision::Aura::Filesystem | ||
{ | ||
/** | ||
* @brief A watcher of a file system folder. | ||
*/ | ||
class FileSystemWatcher | ||
{ | ||
public: | ||
/** | ||
* @brief Constructs a FileSystemWatcher. | ||
* @param path The path of the folder to watch | ||
* @param includeSubdirectories Whether or not to include subdirectories for the folder | ||
* @param watcherFlags The flags of what to watch changes for | ||
* @exception std::runtime_error Thrown if unable to initialize watcher | ||
*/ | ||
FileSystemWatcher(const std::filesystem::path& path, bool includeSubdirectories, WatcherFlags watcherFlags = WatcherFlags::FileName | WatcherFlags::DirectoryName | WatcherFlags::Attributes | WatcherFlags::Size | WatcherFlags::LastWrite | WatcherFlags::LastAccess); | ||
/** | ||
* @brief Deconstructs a FileSystemWatcher. | ||
*/ | ||
~FileSystemWatcher(); | ||
/** | ||
* @brief Gets the path of the file system object being watched. | ||
* @return The path of the folder being watched | ||
*/ | ||
const std::filesystem::path& getPath() const; | ||
/** | ||
* @brief Gets the flags of what to watch changed for. | ||
* @return The flags of watched properties | ||
*/ | ||
WatcherFlags getWatcherFlags() const; | ||
/** | ||
* @brief Gets whether or not subdirectories of the folder are watched. | ||
* @return True if subdirectories watched, else false | ||
*/ | ||
bool getIncludeSubdirectories() const; | ||
/** | ||
* @brief Gets the event for when the watched file system object is changed. | ||
* @return The changed event | ||
*/ | ||
Events::Event<FileSystemChangedEventArgs>& changed(); | ||
/** | ||
* @brief Gets whether or not the file extension is being watched. | ||
* @param extension The file extension to check | ||
* @return True if watched, else false | ||
*/ | ||
bool containsExtension(const std::filesystem::path& extension); | ||
/** | ||
* @brief Adds an extension of a file to watch for changes in the folder. | ||
* @param extension The file extension to add | ||
* @return True if successful, else false | ||
*/ | ||
bool addExtensionFilter(const std::filesystem::path& extension); | ||
/** | ||
* @brief Removes an extension of a file to watch for changes in the folder. | ||
* @param extension The file extension to remove | ||
* @return True if successful, else false | ||
*/ | ||
bool removeExtensionFilter(const std::filesystem::path& extension); | ||
/** | ||
* @brief Clears all extensions to watch. | ||
* @return True if successful, else false | ||
*/ | ||
bool clearExtensionFilters(); | ||
|
||
private: | ||
/** | ||
* @brief Runs the loop to watch a folder for changes. | ||
*/ | ||
void watch(); | ||
mutable std::mutex m_mutex; | ||
std::filesystem::path m_path; | ||
bool m_includeSubdirectories; | ||
WatcherFlags m_watcherFlags; | ||
Events::Event<FileSystemChangedEventArgs> m_changed; | ||
bool m_watching; | ||
std::vector<std::filesystem::path> m_extensionFilters; | ||
std::jthread m_watchThread; | ||
#ifdef _WIN32 | ||
HANDLE m_terminateEvent; | ||
#elif defined(__linux__) | ||
int m_notify; | ||
#endif | ||
}; | ||
} | ||
|
||
#endif //FILESYSTEMWATCHER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef WATCHERFLAGS_H | ||
#define WATCHERFLAGS_H | ||
|
||
#include "enumflags.h" | ||
|
||
namespace Nickvision::Aura::Filesystem | ||
{ | ||
/** | ||
* @brief Flags to describe properties of a file system object that can change. | ||
*/ | ||
enum class WatcherFlags | ||
{ | ||
FileName = 1, | ||
DirectoryName = 2, | ||
Attributes = 4, | ||
Size = 8, | ||
LastWrite = 16, | ||
LastAccess = 32 | ||
}; | ||
|
||
DEFINE_ENUM_FLAG_OPERATORS(WatcherFlags); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef PROGRESSSTATE_H | ||
#define PROGRESSSTATE_H | ||
|
||
namespace Nickvision::Aura::Taskbar | ||
{ | ||
/** | ||
* @brief States of progress on a taskbar button. | ||
*/ | ||
enum class ProgressState | ||
{ | ||
NoProgress = 0, | ||
Indeterminate = 1, | ||
Normal = 2, | ||
Error = 4, | ||
Paused = 8 | ||
}; | ||
} | ||
|
||
#endif //PROGRESSSTATE_H |
Oops, something went wrong.