Skip to content

Commit

Permalink
Convert Windows standalone from console app to win32 (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
mthierman authored and defiantnerd committed Feb 11, 2024
1 parent 0909abd commit eb27a65
Show file tree
Hide file tree
Showing 8 changed files with 378 additions and 224 deletions.
10 changes: 7 additions & 3 deletions cmake/wrap_standalone.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,18 @@ function(target_add_standalone_wrapper)
MACOS_EMBEDDED_CLAP_LOCATION ${SA_MACOS_EMBEDDED_CLAP_LOCATION})

elseif(WIN32 AND (CMAKE_CXX_COMPILER_ID MATCHES "MSVC" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
set_target_properties(${SA_TARGET} PROPERTIES
WIN32_EXECUTABLE TRUE
)

target_sources(${SA_TARGET} PRIVATE
${CLAP_WRAPPER_CMAKE_CURRENT_SOURCE_DIR}/src/wrapasstandalone.cpp
${CLAP_WRAPPER_CMAKE_CURRENT_SOURCE_DIR}/src/detail/standalone/windows/winutils.cpp
${CLAP_WRAPPER_CMAKE_CURRENT_SOURCE_DIR}/src/detail/standalone/windows/win32.manifest
)

target_compile_definitions(${SA_TARGET} PRIVATE
target_compile_definitions(${salib} PUBLIC
CLAP_WRAPPER_HAS_WIN32
WIN32_TITLE="${SA_OUTPUT_NAME}"
WIN32_NAME="${SA_OUTPUT_NAME}"
)

elseif(UNIX)
Expand Down
31 changes: 15 additions & 16 deletions src/detail/clap/fsutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,29 @@
namespace Clap
{
#if WIN
fs::path windows_path(const KNOWNFOLDERID &id)
fs::path get_known_folder(const KNOWNFOLDERID &id)
{
std::wstring path;
wchar_t *buffer;
wchar_t *buffer{nullptr};

if (SUCCEEDED(SHGetKnownFolderPath(id, 0, nullptr, &buffer)))
{
fs::path data = std::wstring(buffer);
fs::path data{std::wstring(buffer)};
CoTaskMemFree(buffer);

return data;
}

else
return fs::path{};
return {};
}

std::vector<std::wstring> split_clap_path(const std::wstring &in, const std::wstring &sep)
std::vector<std::string> split_clap_path(const std::string &in)
{
std::vector<std::wstring> res;
std::wstringstream ss(in);
std::wstring item;
std::vector<std::string> res;
std::stringstream ss(in);
std::string item;

while (std::getline(ss, item, L';')) res.push_back(item);
while (std::getline(ss, item, ';')) res.push_back(item);

return res;
}
Expand All @@ -74,20 +73,20 @@ std::vector<fs::path> getValidCLAPSearchPaths()
#endif

#if WIN
auto p{windows_path(FOLDERID_ProgramFilesCommon)};
auto p{get_known_folder(FOLDERID_ProgramFilesCommon)};
if (fs::exists(p)) res.emplace_back(p / "CLAP");

auto q{windows_path(FOLDERID_LocalAppData)};
auto q{get_known_folder(FOLDERID_LocalAppData)};
if (fs::exists(q)) res.emplace_back(q / "Programs" / "Common" / "CLAP");

std::wstring cp;
auto len{::GetEnvironmentVariableW(L"CLAP_PATH", NULL, 0)};
std::string cp;
auto len{::GetEnvironmentVariable("CLAP_PATH", nullptr, 0)};

if (len > 0)
{
cp.resize(len);
cp.resize(::GetEnvironmentVariableW(L"CLAP_PATH", &cp[0], len));
auto paths{split_clap_path(cp, L";")};
cp.resize(::GetEnvironmentVariable("CLAP_PATH", &cp[0], len));
auto paths{split_clap_path(cp)};

for (const auto &path : paths)
{
Expand Down
5 changes: 2 additions & 3 deletions src/detail/standalone/standalone_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
namespace freeaudio::clap_wrapper::standalone
{

#if CLAP_WRAPPER_HAS_WIN32
#if WIN && CLAP_WRAPPER_HAS_WIN32
std::optional<fs::path> getStandaloneSettingsPath()
{
std::wstring path;
wchar_t *buffer;
wchar_t *buffer{nullptr};

if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, nullptr, &buffer)))
{
Expand Down
Loading

0 comments on commit eb27a65

Please sign in to comment.