編集区間へ入る処理を走査スレッドへ集約した
このコミットが含まれているのは:
5ファイル変更
+153
-134
検索条件に一致するファイルはありません
+115
-101
@@ -12,6 +12,7 @@
|
||||
#include "HostContext.h"
|
||||
#include "Log.h"
|
||||
#include "ExportGuard.h"
|
||||
#include "ProxyStore.h"
|
||||
#include "Notify.h"
|
||||
#include "ProxyBuilder.h"
|
||||
#include "ProxyFormat.h"
|
||||
@@ -20,15 +21,10 @@
|
||||
|
||||
namespace pe {
|
||||
|
||||
ScanResult ApplyProxies();
|
||||
ScanResult RestoreOriginals();
|
||||
ScanResult RestoreFailed(const std::vector<std::wstring>& proxies);
|
||||
|
||||
namespace {
|
||||
|
||||
const wchar_t* kEffect = L"動画ファイル";
|
||||
const wchar_t* kItem = L"ファイル";
|
||||
std::atomic<bool> g_scanning{false};
|
||||
std::atomic<bool> g_suspended{false};
|
||||
std::atomic<int> g_pending{0};
|
||||
std::atomic<bool> g_stop{false};
|
||||
@@ -41,10 +37,13 @@ enum RequestKind {
|
||||
kRequestApply = 2,
|
||||
kRequestRestore = 4,
|
||||
kRequestRestoreFailed = 8,
|
||||
kRequestExportRestore = 16,
|
||||
kRequestDelete = 32,
|
||||
};
|
||||
|
||||
std::mutex g_report_lock;
|
||||
std::vector<std::wstring> g_failed_proxies;
|
||||
std::vector<std::wstring> g_delete_list;
|
||||
std::vector<Unsupported> g_unsupported;
|
||||
|
||||
void Post(int kind) {
|
||||
@@ -151,84 +150,8 @@ bool Eligible(const std::wstring& path, const MEDIA_INFO& info) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void ScanWorker() {
|
||||
while (true) {
|
||||
int taken = 0;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(g_wake_lock);
|
||||
g_wake.wait(lock, [] { return g_stop.load() || g_pending.load() != 0; });
|
||||
if (g_stop.load()) return;
|
||||
taken = g_pending.exchange(0);
|
||||
}
|
||||
if (taken & kRequestRestoreFailed) {
|
||||
std::vector<std::wstring> proxies;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_report_lock);
|
||||
proxies.swap(g_failed_proxies);
|
||||
}
|
||||
ScanResult result = RestoreFailed(proxies);
|
||||
if (result.restored > 0) {
|
||||
Say(L"生成に失敗したので元素材へ戻しました: %d 件", result.restored);
|
||||
}
|
||||
PublishStateChange();
|
||||
}
|
||||
if (taken & kRequestRestore) {
|
||||
ScanResult result = RestoreOriginals();
|
||||
Say(L"元素材へ戻しました: %d 件", result.restored);
|
||||
PublishStateChange();
|
||||
}
|
||||
if (taken & kRequestApply) {
|
||||
ScanResult result = ApplyProxies();
|
||||
Say(L"プロキシへ差し替えました: 対象 %d 件、差し替え %d 件、対象外 %d 件", result.eligible,
|
||||
result.swapped, result.rejected);
|
||||
if (result.unsupported > 0) {
|
||||
Warn(L"プロキシを作れない素材が %d 件あります。本体は読めますがこのプラグインの復号が対応していない形式です",
|
||||
result.unsupported);
|
||||
}
|
||||
PublishStateChange();
|
||||
} else if ((taken & kRequestAutomatic) && CurrentSettings().enabled &&
|
||||
!g_suspended.load()) {
|
||||
ScanResult result = ApplyProxies();
|
||||
if (result.swapped > 0) {
|
||||
Say(L"自動でプロキシへ差し替えました: %d 件", result.swapped);
|
||||
}
|
||||
PublishStateChange();
|
||||
(void)result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnHostEvent(void*) {
|
||||
NoticeEditActivity();
|
||||
Post(kRequestAutomatic);
|
||||
}
|
||||
|
||||
void OnEditMenuApply(EDIT_SECTION*) {
|
||||
Post(kRequestApply);
|
||||
}
|
||||
|
||||
void OnEditMenuRestore(EDIT_SECTION*) {
|
||||
Post(kRequestRestore);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool IsProxyPath(const std::wstring& path) {
|
||||
if (path.size() < 4) return false;
|
||||
return _wcsicmp(path.c_str() + path.size() - 4, L".pxy") == 0;
|
||||
}
|
||||
|
||||
std::wstring SourceOfProxy(const std::wstring& path) {
|
||||
ProxyReader reader;
|
||||
if (!reader.Open(path)) return std::wstring();
|
||||
std::wstring source = reader.Header().source_path;
|
||||
reader.Close();
|
||||
return source;
|
||||
}
|
||||
|
||||
ScanResult ApplyProxies() {
|
||||
ScanResult result;
|
||||
if (g_scanning.exchange(true)) return result;
|
||||
Collected collected;
|
||||
collected.layers = std::max(EditInfo().layer_max + 1, 1);
|
||||
CallReadSection(&collected, CollectObjects);
|
||||
@@ -306,7 +229,6 @@ ScanResult ApplyProxies() {
|
||||
std::lock_guard<std::mutex> lock(g_report_lock);
|
||||
g_unsupported = unsupported;
|
||||
}
|
||||
g_scanning.store(false);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -373,10 +295,121 @@ ScanResult RestoreFailed(const std::vector<std::wstring>& proxies) {
|
||||
return result;
|
||||
}
|
||||
|
||||
void ScanWorker() {
|
||||
while (true) {
|
||||
int taken = 0;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(g_wake_lock);
|
||||
g_wake.wait(lock, [] { return g_stop.load() || g_pending.load() != 0; });
|
||||
if (g_stop.load()) return;
|
||||
taken = g_pending.exchange(0);
|
||||
}
|
||||
if (taken & kRequestExportRestore) {
|
||||
ScanResult result = RestoreOriginals();
|
||||
if (result.restored > 0) {
|
||||
Say(L"出力のため元素材へ戻しました: %d 件", result.restored);
|
||||
}
|
||||
PublishStateChange();
|
||||
ExportRestoreFinished(result.restored > 0);
|
||||
}
|
||||
if (taken & kRequestDelete) {
|
||||
std::vector<std::wstring> proxies;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_report_lock);
|
||||
proxies.swap(g_delete_list);
|
||||
}
|
||||
RestoreFailed(proxies);
|
||||
for (const std::wstring& proxy : proxies) {
|
||||
std::wstring source = SourceOfProxy(proxy);
|
||||
if (!source.empty()) DiscardSource(source);
|
||||
RemoveProxy(proxy);
|
||||
}
|
||||
if (!proxies.empty()) Say(L"プロキシを削除しました: %d 件", (int)proxies.size());
|
||||
PublishStateChange();
|
||||
}
|
||||
if (taken & kRequestRestoreFailed) {
|
||||
std::vector<std::wstring> proxies;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_report_lock);
|
||||
proxies.swap(g_failed_proxies);
|
||||
}
|
||||
ScanResult result = RestoreFailed(proxies);
|
||||
if (result.restored > 0) {
|
||||
Say(L"生成に失敗したので元素材へ戻しました: %d 件", result.restored);
|
||||
}
|
||||
PublishStateChange();
|
||||
}
|
||||
if (taken & kRequestRestore) {
|
||||
ScanResult result = RestoreOriginals();
|
||||
Say(L"元素材へ戻しました: %d 件", result.restored);
|
||||
PublishStateChange();
|
||||
}
|
||||
if (taken & kRequestApply) {
|
||||
ScanResult result = ApplyProxies();
|
||||
Say(L"プロキシへ差し替えました: 対象 %d 件、差し替え %d 件、対象外 %d 件", result.eligible,
|
||||
result.swapped, result.rejected);
|
||||
if (result.unsupported > 0) {
|
||||
Warn(L"プロキシを作れない素材が %d 件あります。本体は読めますがこのプラグインの復号が対応していない形式です",
|
||||
result.unsupported);
|
||||
}
|
||||
PublishStateChange();
|
||||
} else if ((taken & kRequestAutomatic) && CurrentSettings().enabled &&
|
||||
!g_suspended.load()) {
|
||||
ScanResult result = ApplyProxies();
|
||||
if (result.swapped > 0) {
|
||||
Say(L"自動でプロキシへ差し替えました: %d 件", result.swapped);
|
||||
}
|
||||
PublishStateChange();
|
||||
(void)result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnHostEvent(void*) {
|
||||
NoticeEditActivity();
|
||||
Post(kRequestAutomatic);
|
||||
}
|
||||
|
||||
void OnEditMenuApply(EDIT_SECTION*) {
|
||||
Post(kRequestApply);
|
||||
}
|
||||
|
||||
void OnEditMenuRestore(EDIT_SECTION*) {
|
||||
Post(kRequestRestore);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool IsProxyPath(const std::wstring& path) {
|
||||
if (path.size() < 4) return false;
|
||||
return _wcsicmp(path.c_str() + path.size() - 4, L".pxy") == 0;
|
||||
}
|
||||
|
||||
std::wstring SourceOfProxy(const std::wstring& path) {
|
||||
ProxyReader reader;
|
||||
if (!reader.Open(path)) return std::wstring();
|
||||
std::wstring source = reader.Header().source_path;
|
||||
reader.Close();
|
||||
return source;
|
||||
}
|
||||
|
||||
void RequestApply() {
|
||||
Post(kRequestApply);
|
||||
}
|
||||
|
||||
void RequestExportRestore() {
|
||||
Post(kRequestExportRestore);
|
||||
}
|
||||
|
||||
void RequestDeleteProxies(const std::vector<std::wstring>& proxies) {
|
||||
if (proxies.empty()) return;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_report_lock);
|
||||
for (const std::wstring& proxy : proxies) g_delete_list.push_back(proxy);
|
||||
}
|
||||
Post(kRequestDelete);
|
||||
}
|
||||
|
||||
void RequestRestoreProxy(const std::wstring& proxy) {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_report_lock);
|
||||
@@ -388,30 +421,11 @@ void RequestRestoreProxy(const std::wstring& proxy) {
|
||||
Post(kRequestRestoreFailed);
|
||||
}
|
||||
|
||||
int RestoreProxiesNow(const std::vector<std::wstring>& proxies) {
|
||||
ScanResult result = RestoreFailed(proxies);
|
||||
if (result.restored > 0) PublishStateChange();
|
||||
return result.restored;
|
||||
}
|
||||
|
||||
std::vector<Unsupported> UnsupportedSources() {
|
||||
std::lock_guard<std::mutex> lock(g_report_lock);
|
||||
return g_unsupported;
|
||||
}
|
||||
|
||||
int RestoreForExport() {
|
||||
ScanResult result = RestoreOriginals();
|
||||
if (result.restored > 0) Say(L"出力のため元素材へ戻しました: %d 件", result.restored);
|
||||
PublishStateChange();
|
||||
return result.restored;
|
||||
}
|
||||
|
||||
void ApplyAfterExport() {
|
||||
ScanResult result = ApplyProxies();
|
||||
if (result.swapped > 0) Say(L"出力が終わったのでプロキシへ戻しました: %d 件", result.swapped);
|
||||
PublishStateChange();
|
||||
}
|
||||
|
||||
void SuspendAutomaticScan(bool suspend) {
|
||||
g_suspended.store(suspend);
|
||||
}
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする