-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Basic file watcher to make this process easier
- Loading branch information
1 parent
450308a
commit d585e31
Showing
11 changed files
with
120 additions
and
9 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,45 @@ | ||
#include "FileWatcher.h" | ||
|
||
namespace Arcane | ||
{ | ||
FileWatcher::FileWatcher(std::string path_to_watch, std::chrono::duration<int, std::milli> delay) | ||
{ | ||
m_Directory = path_to_watch; | ||
for (auto& file : std::filesystem::recursive_directory_iterator(path_to_watch)) { | ||
m_Paths[file.path().string()] = std::filesystem::last_write_time(file); | ||
} | ||
} | ||
|
||
void FileWatcher::Start(const std::function<void(std::string, FileStatus)>& action) | ||
{ | ||
auto it = m_Paths.begin(); | ||
while (it != m_Paths.end()) | ||
{ | ||
if (!std::filesystem::exists(it->first)) { | ||
action(it->first, FileStatus::Deleted); | ||
it = m_Paths.erase(it); | ||
} | ||
else { | ||
it++; | ||
} | ||
} | ||
|
||
for (auto& file : std::filesystem::recursive_directory_iterator(m_Directory)) { | ||
auto current_file_last_write_time = std::filesystem::last_write_time(file); | ||
|
||
if (!contains(file.path().string())) | ||
{ | ||
m_Paths[file.path().string()] = current_file_last_write_time; | ||
action(file.path().string(), FileStatus::Created); | ||
} | ||
else { | ||
if (m_Paths[file.path().string()] != current_file_last_write_time) { | ||
m_Paths[file.path().string()] = current_file_last_write_time; | ||
action(file.path().string(), FileStatus::Modified); | ||
} | ||
} | ||
} | ||
|
||
|
||
} | ||
} |
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,35 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <chrono> | ||
#include <filesystem> | ||
#include <map> | ||
#include <unordered_map> | ||
#include <functional> | ||
|
||
enum class FileStatus | ||
{ | ||
Created, | ||
Deleted, | ||
Modified | ||
}; | ||
|
||
namespace Arcane | ||
{ | ||
class FileWatcher | ||
{ | ||
public: | ||
FileWatcher(std::string path_to_watch, std::chrono::duration<int, std::milli> delay); | ||
void Start(const std::function<void(std::string, FileStatus)>& action); | ||
|
||
private: | ||
std::chrono::duration<int, std::milli> m_Delay; | ||
std::unordered_map<std::string, std::filesystem::file_time_type> m_Paths; | ||
std::string m_Directory; | ||
|
||
bool contains(const std::string & key) { | ||
auto el = m_Paths.find(key); | ||
return el != m_Paths.end(); | ||
} | ||
}; | ||
} |
Binary file not shown.
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,15 @@ | ||
#include "FileBrowser.h" | ||
|
||
FileBrowserPanel::FileBrowserPanel() | ||
{ | ||
m_Watcher = new Arcane::FileWatcher("./", std::chrono::milliseconds(5000)); | ||
} | ||
|
||
void FileBrowserPanel::OnUpdate() | ||
{ | ||
ImGui::Begin("File Browser"); | ||
{ | ||
|
||
} | ||
ImGui::End(); | ||
} |
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,14 @@ | ||
#pragma once | ||
#include <Arcane.h> | ||
#include <imgui.h> | ||
|
||
class FileBrowserPanel | ||
{ | ||
public: | ||
FileBrowserPanel(); | ||
|
||
void OnUpdate(); | ||
private: | ||
Arcane::FileWatcher* m_Watcher; | ||
|
||
}; |