2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-11-23 05:12:05 +00:00

chore: only one header per modman platform handler

This commit is contained in:
Jan Laupetin
2025-11-02 19:01:22 +00:00
parent d964929681
commit 2aeaa417b6
21 changed files with 99 additions and 181 deletions

View File

@@ -1,6 +1,7 @@
#include "AssetHandlerWindows.h"
#include "Web/Platform/AssetHandler.h"
#include "Web/Platform/Platform.h"
#if defined(WEBVIEW_PLATFORM_WINDOWS) && defined(WEBVIEW_EDGE)
#ifdef PLATFORM_WINDOWS
#include "PlatformUtilsWindows.h"
#include "Web/UiAssets.h"
@@ -12,8 +13,6 @@
#include <webview/detail/backends/win32_edge.hh>
#include <wrl/event.h>
using namespace PLATFORM_NAMESPACE_WINDOWS;
namespace
{
constexpr auto LOCALHOST_PREFIX = "http://localhost:";
@@ -25,7 +24,7 @@ namespace
std::wstringstream wss;
wss << std::format(L"Content-Length: {}\n", contentLength);
wss << L"Content-Type: " << StringToWideString(ui::GetMimeTypeForFileName(assetName));
wss << L"Content-Type: " << utils::StringToWideString(ui::GetMimeTypeForFileName(assetName));
return wss.str();
}
@@ -65,7 +64,7 @@ namespace
Microsoft::WRL::ComPtr<ICoreWebView2WebResourceResponse> response;
const auto uri = WideStringToString(wUri);
const auto uri = utils::WideStringToString(wUri);
bool fileFound = false;
#ifdef _DEBUG
@@ -74,9 +73,9 @@ namespace
return S_OK;
#endif
if (uri.starts_with(URL_PREFIX))
if (uri.starts_with(ui::URL_PREFIX))
{
const auto asset = uri.substr(std::char_traits<char>::length(URL_PREFIX) - 1);
const auto asset = uri.substr(std::char_traits<char>::length(ui::URL_PREFIX) - 1);
const auto foundUiFile = assetLookup.find(asset);
if (foundUiFile != assetLookup.end())
@@ -117,7 +116,7 @@ namespace
}
} // namespace
namespace PLATFORM_NAMESPACE_WINDOWS
namespace ui
{
void InstallAssetHandler(webview::webview& wv)
{
@@ -157,6 +156,6 @@ namespace PLATFORM_NAMESPACE_WINDOWS
std::cerr << "Failed to add resource requested filter\n";
}
}
} // namespace PLATFORM_NAMESPACE_WINDOWS
} // namespace ui
#endif

View File

@@ -1,18 +0,0 @@
#pragma once
#include "Web/Platform/Platform.h"
#include <webview/macros.h>
#if defined(WEBVIEW_PLATFORM_WINDOWS) && defined(WEBVIEW_EDGE)
#include "Web/WebViewLib.h"
namespace PLATFORM_NAMESPACE_WINDOWS
{
constexpr auto URL_PREFIX = "http://modman.local/";
void InstallAssetHandler(webview::webview& wv);
} // namespace PLATFORM_NAMESPACE_WINDOWS
#endif

View File

@@ -1,6 +1,7 @@
#include "Web/Platform/DialogHandler.h"
#include "Web/Platform/Platform.h"
#ifdef _WIN32
#ifdef PLATFORM_WINDOWS
#include "PlatformUtilsWindows.h"
@@ -8,8 +9,6 @@
#include <thread>
#include <windows.h>
using namespace PLATFORM_NAMESPACE_WINDOWS;
namespace
{
bool SetFilters(IFileDialog* pFileOpen, const std::vector<ui::FileDialogFilter>& filters)
@@ -29,8 +28,8 @@ namespace
const auto& filter = filters[i];
COMDLG_FILTERSPEC filterSpec;
const auto& wName = filterStrings.emplace_back(StringToWideString(filter.m_name));
const auto& wSpec = filterStrings.emplace_back(StringToWideString(filter.m_filter));
const auto& wName = filterStrings.emplace_back(utils::StringToWideString(filter.m_name));
const auto& wSpec = filterStrings.emplace_back(utils::StringToWideString(filter.m_filter));
filterSpec.pszName = wName.c_str();
filterSpec.pszSpec = wSpec.c_str();
@@ -65,7 +64,7 @@ namespace
// Display the file name to the user.
if (SUCCEEDED(hr))
{
result = WideStringToString(pszFilePath);
result = utils::WideStringToString(pszFilePath);
CoTaskMemFree(pszFilePath);
resultType = ui::DialogCallbackResultType::SUCCESSFUL;

View File

@@ -1,6 +1,7 @@
#include "AssetHandlerWindows.h"
#include "Web/Platform/FaviconHandler.h"
#include "Web/Platform/Platform.h"
#if defined(WEBVIEW_PLATFORM_WINDOWS) && defined(WEBVIEW_EDGE)
#ifdef PLATFORM_WINDOWS
#include "PlatformUtilsWindows.h"
#include "Web/UiAssets.h"
@@ -13,8 +14,6 @@
#include <webview/detail/backends/win32_edge.hh>
#include <wrl/event.h>
using namespace PLATFORM_NAMESPACE_WINDOWS;
namespace
{
class UniqueHIcon
@@ -111,7 +110,7 @@ namespace
}
} // namespace
namespace PLATFORM_NAMESPACE_WINDOWS
namespace ui
{
void InstallFaviconHandler(webview::webview& wv)
{
@@ -146,6 +145,6 @@ namespace PLATFORM_NAMESPACE_WINDOWS
std::cerr << "Failed to add favicon handler\n";
}
}
} // namespace PLATFORM_NAMESPACE_WINDOWS
} // namespace ui
#endif

View File

@@ -1,16 +0,0 @@
#pragma once
#include "Web/Platform/Platform.h"
#include <webview/macros.h>
#if defined(WEBVIEW_PLATFORM_WINDOWS) && defined(WEBVIEW_EDGE)
#include "Web/WebViewLib.h"
namespace PLATFORM_NAMESPACE_WINDOWS
{
void InstallFaviconHandler(webview::webview& wv);
} // namespace PLATFORM_NAMESPACE_WINDOWS
#endif

View File

@@ -1,12 +1,12 @@
#include "PlatformUtilsWindows.h"
#ifdef _WIN32
#ifdef PLATFORM_WINDOWS
#include <Windows.h>
#include <exception>
#include <format>
namespace PLATFORM_NAMESPACE_WINDOWS
namespace utils
{
std::string WideStringToString(const std::wstring& wideString)
{
@@ -35,6 +35,6 @@ namespace PLATFORM_NAMESPACE_WINDOWS
MultiByteToWideChar(CP_UTF8, 0, string.data(), static_cast<int>(string.size()), result.data(), sizeNeeded);
return result;
}
} // namespace PLATFORM_NAMESPACE_WINDOWS
} // namespace utils
#endif

View File

@@ -1,16 +1,15 @@
#pragma once
#ifdef _WIN32
#include "Web/Platform/Platform.h"
#include <optional>
#ifdef PLATFORM_WINDOWS
#include <string>
namespace PLATFORM_NAMESPACE_WINDOWS
namespace utils
{
std::string WideStringToString(const std::wstring& wideString);
std::wstring StringToWideString(const std::string& string);
} // namespace PLATFORM_NAMESPACE_WINDOWS
} // namespace utils
#endif

View File

@@ -1,6 +1,7 @@
#include "AssetHandlerWindows.h"
#include "Web/Platform/Platform.h"
#include "Web/Platform/TitleHandler.h"
#if defined(WEBVIEW_PLATFORM_WINDOWS) && defined(WEBVIEW_EDGE)
#ifdef PLATFORM_WINDOWS
#include "PlatformUtilsWindows.h"
#include "Web/UiAssets.h"
@@ -12,8 +13,6 @@
#include <webview/detail/backends/win32_edge.hh>
#include <wrl/event.h>
using namespace PLATFORM_NAMESPACE_WINDOWS;
namespace
{
HRESULT HandleTitleChanged(ICoreWebView2* core, HWND window)
@@ -33,7 +32,7 @@ namespace
}
} // namespace
namespace PLATFORM_NAMESPACE_WINDOWS
namespace ui
{
void InstallTitleHandler(webview::webview& wv)
{
@@ -58,6 +57,6 @@ namespace PLATFORM_NAMESPACE_WINDOWS
std::cerr << "Failed to add title handler\n";
}
}
} // namespace PLATFORM_NAMESPACE_WINDOWS
} // namespace ui
#endif

View File

@@ -1,16 +0,0 @@
#pragma once
#include "Web/Platform/Platform.h"
#include <webview/macros.h>
#if defined(WEBVIEW_PLATFORM_WINDOWS) && defined(WEBVIEW_EDGE)
#include "Web/WebViewLib.h"
namespace PLATFORM_NAMESPACE_WINDOWS
{
void InstallTitleHandler(webview::webview& wv);
} // namespace PLATFORM_NAMESPACE_WINDOWS
#endif