設定の読み書きを追加
このコミットが含まれているのは:
4ファイル変更
+181
検索条件に一致するファイルはありません
@@ -95,11 +95,13 @@
|
||||
<ClCompile Include="src\HostContext.cpp" />
|
||||
<ClCompile Include="src\Log.cpp" />
|
||||
<ClCompile Include="src\Plugin.cpp" />
|
||||
<ClCompile Include="src\Settings.cpp" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\HostContext.h" />
|
||||
<ClInclude Include="src\Log.h" />
|
||||
<ClInclude Include="src\Settings.h" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
<ClCompile Include="src\Plugin.cpp">
|
||||
<Filter>ソース ファイル</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Settings.cpp">
|
||||
<Filter>ソース ファイル</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\HostContext.h">
|
||||
@@ -36,6 +39,9 @@
|
||||
<ClInclude Include="src\Log.h">
|
||||
<Filter>ヘッダー ファイル</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\Settings.h">
|
||||
<Filter>ヘッダー ファイル</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="sdk\cache2.h">
|
||||
<Filter>SDK</Filter>
|
||||
</ClInclude>
|
||||
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
#include "Settings.h"
|
||||
|
||||
#include <shlobj.h>
|
||||
#include <shlwapi.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <thread>
|
||||
|
||||
#include "HostContext.h"
|
||||
#include "Log.h"
|
||||
|
||||
namespace pe {
|
||||
|
||||
namespace {
|
||||
|
||||
Settings g_settings;
|
||||
bool g_loaded = false;
|
||||
|
||||
const wchar_t* kSection = L"ProxyEdit";
|
||||
|
||||
std::wstring AppDataPath() {
|
||||
CONFIG_HANDLE* config = Config();
|
||||
if (config && config->app_data_path) return std::wstring(config->app_data_path);
|
||||
wchar_t buffer[MAX_PATH];
|
||||
if (SHGetSpecialFolderPathW(nullptr, buffer, CSIDL_COMMON_APPDATA, FALSE)) {
|
||||
std::wstring path(buffer);
|
||||
path += L"\\aviutl2";
|
||||
return path;
|
||||
}
|
||||
return std::wstring(L".");
|
||||
}
|
||||
|
||||
int ReadInt(const wchar_t* key, int fallback) {
|
||||
return (int)GetPrivateProfileIntW(kSection, key, fallback, SettingsFilePath().c_str());
|
||||
}
|
||||
|
||||
long long ReadLongLong(const wchar_t* key, long long fallback) {
|
||||
wchar_t buffer[64];
|
||||
wchar_t initial[64];
|
||||
_snwprintf_s(initial, _TRUNCATE, L"%lld", fallback);
|
||||
GetPrivateProfileStringW(kSection, key, initial, buffer, 64, SettingsFilePath().c_str());
|
||||
return _wtoi64(buffer);
|
||||
}
|
||||
|
||||
std::wstring ReadText(const wchar_t* key) {
|
||||
wchar_t buffer[MAX_PATH];
|
||||
GetPrivateProfileStringW(kSection, key, L"", buffer, MAX_PATH, SettingsFilePath().c_str());
|
||||
return std::wstring(buffer);
|
||||
}
|
||||
|
||||
void WriteInt(const wchar_t* key, int value) {
|
||||
wchar_t buffer[64];
|
||||
_snwprintf_s(buffer, _TRUNCATE, L"%d", value);
|
||||
WritePrivateProfileStringW(kSection, key, buffer, SettingsFilePath().c_str());
|
||||
}
|
||||
|
||||
void WriteLongLong(const wchar_t* key, long long value) {
|
||||
wchar_t buffer[64];
|
||||
_snwprintf_s(buffer, _TRUNCATE, L"%lld", value);
|
||||
WritePrivateProfileStringW(kSection, key, buffer, SettingsFilePath().c_str());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const Settings& CurrentSettings() {
|
||||
if (!g_loaded) LoadSettings();
|
||||
return g_settings;
|
||||
}
|
||||
|
||||
void LoadSettings() {
|
||||
g_loaded = true;
|
||||
Settings fallback;
|
||||
g_settings.enabled = ReadInt(L"Enabled", fallback.enabled ? 1 : 0) != 0;
|
||||
g_settings.target_min_width = ReadInt(L"TargetMinWidth", fallback.target_min_width);
|
||||
g_settings.target_ten_bit = ReadInt(L"TargetTenBit", fallback.target_ten_bit ? 1 : 0) != 0;
|
||||
g_settings.target_min_mbps = ReadInt(L"TargetMinMbps", fallback.target_min_mbps);
|
||||
g_settings.scale_percent = std::clamp(ReadInt(L"ScalePercent", fallback.scale_percent), 20, 100);
|
||||
g_settings.quality = std::clamp(ReadInt(L"Quality", fallback.quality), 30, 98);
|
||||
g_settings.chunk_frames = std::clamp(ReadInt(L"ChunkFrames", fallback.chunk_frames), 24, 3600);
|
||||
g_settings.read_ahead_bytes = std::clamp(ReadInt(L"ReadAheadBytes", fallback.read_ahead_bytes),
|
||||
8 * 1024 * 1024, 512 * 1024 * 1024);
|
||||
g_settings.worker_count = std::clamp(ReadInt(L"WorkerCount", fallback.worker_count), 0, 32);
|
||||
g_settings.capacity_bytes = ReadLongLong(L"CapacityBytes", fallback.capacity_bytes);
|
||||
if (g_settings.capacity_bytes < 1024LL * 1024 * 1024) g_settings.capacity_bytes = 1024LL * 1024 * 1024;
|
||||
g_settings.store_path = ReadText(L"StorePath");
|
||||
}
|
||||
|
||||
void StoreSettings(const Settings& settings) {
|
||||
g_settings = settings;
|
||||
g_loaded = true;
|
||||
WriteInt(L"Enabled", settings.enabled ? 1 : 0);
|
||||
WriteInt(L"TargetMinWidth", settings.target_min_width);
|
||||
WriteInt(L"TargetTenBit", settings.target_ten_bit ? 1 : 0);
|
||||
WriteInt(L"TargetMinMbps", settings.target_min_mbps);
|
||||
WriteInt(L"ScalePercent", settings.scale_percent);
|
||||
WriteInt(L"Quality", settings.quality);
|
||||
WriteInt(L"ChunkFrames", settings.chunk_frames);
|
||||
WriteInt(L"ReadAheadBytes", settings.read_ahead_bytes);
|
||||
WriteInt(L"WorkerCount", settings.worker_count);
|
||||
WriteLongLong(L"CapacityBytes", settings.capacity_bytes);
|
||||
WritePrivateProfileStringW(kSection, L"StorePath", settings.store_path.c_str(),
|
||||
SettingsFilePath().c_str());
|
||||
}
|
||||
|
||||
std::wstring SettingsFilePath() {
|
||||
std::wstring path = AppDataPath();
|
||||
path += L"\\ProxyEdit.ini";
|
||||
return path;
|
||||
}
|
||||
|
||||
std::wstring DefaultStorePath() {
|
||||
std::wstring path = AppDataPath();
|
||||
path += L"\\ProxyEdit";
|
||||
return path;
|
||||
}
|
||||
|
||||
std::wstring EffectiveStorePath() {
|
||||
const Settings& settings = CurrentSettings();
|
||||
if (!settings.store_path.empty()) return settings.store_path;
|
||||
return DefaultStorePath();
|
||||
}
|
||||
|
||||
int EffectiveWorkerCount() {
|
||||
const Settings& settings = CurrentSettings();
|
||||
if (settings.worker_count > 0) return settings.worker_count;
|
||||
unsigned hardware = std::thread::hardware_concurrency();
|
||||
if (hardware == 0) hardware = 4;
|
||||
int count = (int)(hardware / 2);
|
||||
return std::clamp(count, 1, 8);
|
||||
}
|
||||
|
||||
int ReadAheadFrames(int width, int height) {
|
||||
if (width <= 0 || height <= 0) return 4;
|
||||
long long bytes = (long long)width * height * 2;
|
||||
if (bytes <= 0) return 4;
|
||||
int frames = (int)(CurrentSettings().read_ahead_bytes / bytes);
|
||||
return std::clamp(frames, 2, 24);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace pe {
|
||||
|
||||
struct Settings {
|
||||
bool enabled = true;
|
||||
int target_min_width = 1921;
|
||||
bool target_ten_bit = true;
|
||||
int target_min_mbps = 60;
|
||||
int scale_percent = 50;
|
||||
int quality = 80;
|
||||
int chunk_frames = 240;
|
||||
int read_ahead_bytes = 96 * 1024 * 1024;
|
||||
int worker_count = 0;
|
||||
long long capacity_bytes = 20LL * 1024 * 1024 * 1024;
|
||||
std::wstring store_path;
|
||||
};
|
||||
|
||||
const Settings& CurrentSettings();
|
||||
void LoadSettings();
|
||||
void StoreSettings(const Settings& settings);
|
||||
|
||||
std::wstring SettingsFilePath();
|
||||
std::wstring DefaultStorePath();
|
||||
std::wstring EffectiveStorePath();
|
||||
int EffectiveWorkerCount();
|
||||
int ReadAheadFrames(int width, int height);
|
||||
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする