Skip to content

Commit

Permalink
Merge pull request #18 from karoterra/feat/#15_exedit_filter_list
Browse files Browse the repository at this point in the history
✨ feat: プラグイン情報出力時に拡張編集フィルタの情報も出力
  • Loading branch information
karoterra authored May 17, 2024
2 parents 2a46575 + ec55813 commit 2eda569
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 59 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ add_library(ShowLimit SHARED
src/NamesBuffer.hpp
src/ScriptsOption.hpp
src/LanguagePlugin.hpp
src/ProfileHelper.hpp
)
target_include_directories(ShowLimit PRIVATE
vendor/aviutl_exedit_sdk
Expand Down
57 changes: 4 additions & 53 deletions src/AviUtlProfiler.cpp
Original file line number Diff line number Diff line change
@@ -1,66 +1,14 @@
#include "AviUtlProfiler.hpp"

#include <filesystem>
#include <string_view>
#include <vector>
#include <stdexcept>
#include <TlHelp32.h>

#include "Sha256Hasher.hpp"
#include "ProfileHelper.hpp"

namespace fs = std::filesystem;
using namespace std::literals::string_literals;

constexpr std::string_view kBullet1{ "" };
constexpr std::string_view kBullet2{ "" };
constexpr std::string_view kBulletE{ " " };
constexpr std::string_view kIndent{ " " };

template<typename T>
bool HasFlag(T x, T flag)
{
return (static_cast<uint32_t>(x) & static_cast<uint32_t>(flag)) != 0;
}

void WritePluginData(
std::ostream& dest, Sha256Hasher& hasher, const PluginsOption& opt,
const fs::path& aviutl_dir,
const char* name, const char* info, const char* path)
{
std::vector<std::string> lines;
if (opt.enable_name) {
lines.push_back("名前: ");
if (name != nullptr) lines.back().append(name);
}
if (opt.enable_info) {
lines.push_back("詳細: ");
if (info != nullptr) lines.back().append(info);
}
if (opt.enable_path) {
lines.push_back("パス: ");
if (path != nullptr) {
lines.back().append(fs::relative(path, aviutl_dir).generic_string());
}
}
if (opt.enable_hash) {
lines.push_back("SHA256: ");
if (path != nullptr) {
try {
lines.back().append(hasher.getFileHash(path));
}
catch (const std::runtime_error& e) {
OutputDebugStringA(e.what());
}
}
}

dest << kIndent << kBullet2 << lines[0] << "\n";
for (size_t i = 1; i < lines.size(); i++) {
dest << kIndent << kBulletE << lines[i] << "\n";
}
if (opt.enable_count > 1)
dest << "\n";
}

void AviUtlProfiler::WritePluginsProfile(std::ostream& dest, const PluginsOption& opt)
{
Expand Down Expand Up @@ -178,5 +126,8 @@ void AviUtlProfiler::WriteOtherPluginsProfile(std::ostream& dest, const PluginsO
plugin_path.string().c_str());
} while (Module32Next(snapshot, &me32) != FALSE);

if (opt.enable_count == 1)
dest << "\n";

CloseHandle(snapshot);
}
30 changes: 24 additions & 6 deletions src/ExEditProfiler.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
#include "ExEditProfiler.hpp"

#include <algorithm>
#include <filesystem>
#include <vector>
#include <iomanip>

#include <exedit.hpp>

#include "Sha256Hasher.hpp"
#include "NamesBuffer.hpp"
#include "ProfileHelper.hpp"

namespace fs = std::filesystem;

constexpr std::string_view kBullet1{ "" };
constexpr std::string_view kBullet2{ "" };
constexpr std::string_view kBulletE{ " " };
constexpr std::string_view kIndent{ " " };

constexpr std::string_view kLuaLibName{ "lua51.dll" };

const std::vector<std::string> defaultAnm{
Expand Down Expand Up @@ -181,3 +179,23 @@ void ExEditProfiler::WriteExEditDetail(std::ostream& dest)
fs::path lua_path = exedit_path.parent_path().append(kLuaLibName);
dest << kIndent << kIndent << "SHA256: " << hasher.getFileHash(lua_path.string().c_str()) << "\n";
}

void ExEditProfiler::WriteExEditFilterProfile(std::ostream& dest, const std::filesystem::path& aviutl_dir, const PluginsOption& opt)
{
if (!IsSupported()) return;

dest << kBullet1 << "拡張編集フィルタ\n";

const auto filters = GetPtr<ExEdit::Filter*>(kExEditFilterArrayOffset);
const auto filter_num = GetExEditFilterNum();
Sha256Hasher hasher;
for (size_t i = 0; i < filter_num; i++) {
const auto filter = filters[i];
if (!HasFlag(filter->flag, ExEdit::Filter::Flag::ExEditFilter) || !filter->dll_hinst)
continue;

char buf[MAX_PATH];
GetModuleFileName(reinterpret_cast<HMODULE>(filter->dll_hinst), buf, MAX_PATH);
WritePluginData(dest, hasher, opt, aviutl_dir, filter->name, filter->information, buf);
}
}
4 changes: 4 additions & 0 deletions src/ExEditProfiler.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#pragma once

#include <ostream>
#include <filesystem>
#include <string_view>

#include <aviutl.hpp>

#include "ScriptsOption.hpp"
#include "PluginsOption.hpp"

class ExEditProfiler
{
Expand Down Expand Up @@ -104,6 +106,8 @@ class ExEditProfiler

void WriteProfile(std::ostream& dest, const ScriptsOption& opt);

void WriteExEditFilterProfile(std::ostream& dest, const std::filesystem::path& aviutl_dir, const PluginsOption& opt);

private:
AviUtl::FilterPlugin* exedit_;

Expand Down
58 changes: 58 additions & 0 deletions src/ProfileHelper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#pragma once

#include <filesystem>
#include <string_view>

#include "Sha256Hasher.hpp"
#include "PluginsOption.hpp"

constexpr std::string_view kBullet1{ "" };
constexpr std::string_view kBullet2{ "" };
constexpr std::string_view kBulletE{ " " };
constexpr std::string_view kIndent{ " " };

template<typename T>
bool inline HasFlag(T x, T flag)
{
return (static_cast<uint32_t>(x) & static_cast<uint32_t>(flag)) != 0;
}

void inline WritePluginData(
std::ostream& dest, Sha256Hasher& hasher, const PluginsOption& opt,
const std::filesystem::path& aviutl_dir,
const char* name, const char* info, const char* path)
{
std::vector<std::string> lines;
if (opt.enable_name) {
lines.push_back("名前: ");
if (name != nullptr) lines.back().append(name);
}
if (opt.enable_info) {
lines.push_back("詳細: ");
if (info != nullptr) lines.back().append(info);
}
if (opt.enable_path) {
lines.push_back("パス: ");
if (path != nullptr) {
lines.back().append(std::filesystem::relative(path, aviutl_dir).generic_string());
}
}
if (opt.enable_hash) {
lines.push_back("SHA256: ");
if (path != nullptr) {
try {
lines.back().append(hasher.getFileHash(path));
}
catch (const std::runtime_error& e) {
OutputDebugStringA(e.what());
}
}
}

dest << kIndent << kBullet2 << lines[0] << "\n";
for (size_t i = 1; i < lines.size(); i++) {
dest << kIndent << kBulletE << lines[i] << "\n";
}
if (opt.enable_count > 1)
dest << "\n";
}
10 changes: 10 additions & 0 deletions src/show_limit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
#include <string>
#include <array>
#include <tuple>
#include <filesystem>

#include <aviutl.hpp>

#include "Sha256Hasher.hpp"
#include "AviUtlProfiler.hpp"
#include "ExEditProfiler.hpp"

namespace fs = std::filesystem;
using namespace std::literals::string_literals;
using AviUtl::FilterPlugin;

Expand Down Expand Up @@ -313,6 +315,10 @@ BOOL func_WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, AviUtl:
std::ostringstream os;
auto opt = GetPluginsOption();
g_aviutl_profiler.WritePluginsProfile(os, opt);

fs::path aviutl_path = g_aviutl_profiler.GetAviUtlPath();
fs::path aviutl_dir = aviutl_path.parent_path();
g_exedit_profiler.WriteExEditFilterProfile(os, aviutl_dir, opt);
CopyToClipboard(os.str());
break;
}
Expand All @@ -323,6 +329,10 @@ BOOL func_WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, AviUtl:
std::ofstream ofs(name);
auto opt = GetPluginsOption();
g_aviutl_profiler.WritePluginsProfile(ofs, opt);

fs::path aviutl_path = g_aviutl_profiler.GetAviUtlPath();
fs::path aviutl_dir = aviutl_path.parent_path();
g_exedit_profiler.WriteExEditFilterProfile(ofs, aviutl_dir, opt);
}
catch (const std::exception& e) {
std::ostringstream os;
Expand Down

0 comments on commit 2eda569

Please sign in to comment.