-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VideoCommon: watch texture pack folder for texture reloads (from dyna…
…mic input textures)
- Loading branch information
Showing
7 changed files
with
148 additions
and
7 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
57 changes: 57 additions & 0 deletions
57
Source/Core/VideoCommon/Assets/WatchableFilesystemAssetLibrary.cpp
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,57 @@ | ||
// Copyright 2024 Dolphin Emulator Project | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#include "VideoCommon/Assets/WatchableFilesystemAssetLibrary.h" | ||
|
||
#include "Common/Logging/Log.h" | ||
#include "Common/StringUtil.h" | ||
|
||
namespace VideoCommon | ||
{ | ||
void WatchableFilesystemAssetLibrary::Watch(const std::string& path) | ||
{ | ||
const auto [iter, inserted] = m_watched_paths.try_emplace(path, nullptr); | ||
if (inserted) | ||
{ | ||
iter->second = std::make_unique<wtr::watch>(path, [this](wtr::event e) { | ||
if (e.path_type == wtr::event::path_type::watcher) | ||
{ | ||
return; | ||
} | ||
|
||
if (e.effect_type == wtr::event::effect_type::create) | ||
{ | ||
const auto path = WithUnifiedPathSeparators(PathToString(e.path_name)); | ||
PathAdded(path); | ||
} | ||
else if (e.effect_type == wtr::event::effect_type::modify) | ||
{ | ||
const auto path = WithUnifiedPathSeparators(PathToString(e.path_name)); | ||
PathModified(path); | ||
} | ||
else if (e.effect_type == wtr::event::effect_type::rename) | ||
{ | ||
if (!e.associated) | ||
{ | ||
WARN_LOG_FMT(VIDEO, "Rename on path seen without association!"); | ||
return; | ||
} | ||
|
||
const auto old_path = WithUnifiedPathSeparators(PathToString(e.path_name)); | ||
const auto new_path = WithUnifiedPathSeparators(PathToString(e.associated->path_name)); | ||
PathRenamed(old_path, new_path); | ||
} | ||
else if (e.effect_type == wtr::event::effect_type::destroy) | ||
{ | ||
const auto path = WithUnifiedPathSeparators(PathToString(e.path_name)); | ||
PathDeleted(path); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
void WatchableFilesystemAssetLibrary::Unwatch(const std::string& path) | ||
{ | ||
m_watched_paths.erase(path); | ||
} | ||
} // namespace VideoCommon |
38 changes: 38 additions & 0 deletions
38
Source/Core/VideoCommon/Assets/WatchableFilesystemAssetLibrary.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,38 @@ | ||
// Copyright 2024 Dolphin Emulator Project | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#pragma once | ||
|
||
#include <map> | ||
#include <memory> | ||
#include <string> | ||
#include <string_view> | ||
|
||
#include <wtr/watcher.hpp> | ||
|
||
#include "VideoCommon/Assets/CustomAssetLibrary.h" | ||
|
||
namespace VideoCommon | ||
{ | ||
class WatchableFilesystemAssetLibrary : public CustomAssetLibrary | ||
{ | ||
public: | ||
void Watch(const std::string& path); | ||
void Unwatch(const std::string& path); | ||
|
||
private: | ||
// A new file or folder was added to one of the watched paths | ||
virtual void PathAdded(std::string_view path) {} | ||
|
||
// A file or folder was modified in one of the watched paths | ||
virtual void PathModified(std::string_view path) {} | ||
|
||
// A file or folder was renamed in one of the watched paths | ||
virtual void PathRenamed(std::string_view old_path, std::string_view new_path) {} | ||
|
||
// A file or folder was deleted in one of the watched paths | ||
virtual void PathDeleted(std::string_view path) {} | ||
|
||
std::map<std::string, std::unique_ptr<wtr::watch>> m_watched_paths; | ||
}; | ||
} // namespace VideoCommon |
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