Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refact(skyrim-platform): get rid of PCH.h in skyrim_platform_entry #1724

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion skyrim-platform/src/platform_se/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ if(NOT "${SKIP_SKYRIM_PLATFORM_BUILDING}")
target_include_directories(skyrim_platform_entry PRIVATE "${third_party}")
target_include_directories(skyrim_platform_entry PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include)
target_link_libraries(skyrim_platform_entry PRIVATE CommonLibSSE::CommonLibSSE)
target_precompile_headers(skyrim_platform_entry PRIVATE skyrim_platform_entry/PCH.h)
apply_default_settings(TARGETS skyrim_platform_entry)

set_target_properties(skyrim_platform SkyrimPlatformCEF skyrim_platform_entry PROPERTIES
Expand Down
70 changes: 0 additions & 70 deletions skyrim-platform/src/platform_se/skyrim_platform_entry/PCH.h

This file was deleted.

55 changes: 45 additions & 10 deletions skyrim-platform/src/platform_se/skyrim_platform_entry/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
#include <SKSE/SKSE.h>

#include <Windows.h>
#include <cassert>
#include <filesystem>
#include <span>

#include "Version.h"

typedef void (*IpcMessageCallback)(const uint8_t* data, uint32_t length,
void* state);

Expand Down Expand Up @@ -82,6 +91,30 @@ class PlatformImplInterface
}
}

void AppendToPathEnv(const std::filesystem::path& p)
{
if (!p.is_absolute()) {
throw std::logic_error("An absolute path expected: " + p.string());
}

if (!std::filesystem::is_directory(p)) {
throw std::logic_error("Expected path to be a directory: " + p.string());
}

std::vector<wchar_t> path;
path.resize(GetEnvironmentVariableW(L"PATH", nullptr, 0));
GetEnvironmentVariableW(L"PATH", &path[0], path.size());

std::wstring newPath = path.data();
newPath += L';';
newPath += p.wstring();

if (!SetEnvironmentVariableW(L"PATH", newPath.data())) {
throw std::runtime_error("Failed to modify PATH env: Error " +
std::to_string(GetLastError()));
}
}

SKSEPlugin_Load_Impl load = nullptr;
SkyrimPlatform_IpcSubscribe_Impl ipcSubscribe = nullptr;
SkyrimPlatform_IpcSend_Impl ipcSend = nullptr;
Expand All @@ -91,8 +124,8 @@ class PlatformImplInterface
extern "C" {

#ifdef SKYRIMSE
DLLEXPORT bool SKSEPlugin_Query(const SKSE::QueryInterface* skse,
SKSE::PluginInfo* info)
__declspec(dllexport) bool SKSEPlugin_Query(const SKSE::QueryInterface* skse,
SKSE::PluginInfo* info)
{
info->infoVersion = SKSE::PluginInfo::kVersion;
info->name = "SkyrimPlatform";
Expand All @@ -106,7 +139,7 @@ DLLEXPORT bool SKSEPlugin_Query(const SKSE::QueryInterface* skse,
}

#else
DLLEXPORT constinit auto SKSEPlugin_Version = []() {
__declspec(dllexport) constinit auto SKSEPlugin_Version = []() {
SKSE::PluginVersionData v;
v.PluginVersion(Version::ASINT);
v.PluginName("SkyrimPlatform");
Expand All @@ -119,27 +152,29 @@ DLLEXPORT constinit auto SKSEPlugin_Version = []() {

#endif

DLLEXPORT uint32_t SkyrimPlatform_IpcSubscribe(const char* systemName,
IpcMessageCallback callback,
void* state)
__declspec(dllexport) uint32_t
SkyrimPlatform_IpcSubscribe(const char* systemName,
IpcMessageCallback callback, void* state)
{
return PlatformImplInterface::GetSingleton().IpcSubscribe(systemName,
callback, state);
}

DLLEXPORT void SkyrimPlatform_IpcUnsubscribe(uint32_t subscriptionId)
__declspec(dllexport) void SkyrimPlatform_IpcUnsubscribe(
uint32_t subscriptionId)
{
return PlatformImplInterface::GetSingleton().IpcUnsubscribe(subscriptionId);
}

DLLEXPORT void SkyrimPlatform_IpcSend(const char* systemName,
const uint8_t* data, uint32_t length)
__declspec(dllexport) void SkyrimPlatform_IpcSend(const char* systemName,
const uint8_t* data,
uint32_t length)
{
return PlatformImplInterface::GetSingleton().IpcSend(systemName, data,
length);
}

DLLEXPORT bool SKSEPlugin_Load(void* skse)
__declspec(dllexport) bool SKSEPlugin_Load(void* skse)
{
try {
return PlatformImplInterface::GetSingleton().Load(skse);
Expand Down