Utility to get the resource path of the plugin bundle

This commit is contained in:
Jean Pierre Cimalando 2021-04-09 00:52:17 +02:00
parent 8b7761e615
commit 7a78e7627f
5 changed files with 79 additions and 1 deletions

View file

@ -56,6 +56,8 @@ add_library(sfizz_editor STATIC EXCLUDE_FROM_ALL
src/editor/ImageHelpers.cpp
src/editor/NativeHelpers.h
src/editor/NativeHelpers.cpp
src/editor/VSTGUIHelpers.h
src/editor/VSTGUIHelpers.cpp
src/editor/layout/main.hpp
src/editor/layout/about.hpp
src/editor/utility/vstgui_after.h
@ -74,7 +76,8 @@ if(APPLE)
find_library(APPLE_CORESERVICES_LIBRARY "CoreServices")
find_library(APPLE_FOUNDATION_LIBRARY "Foundation")
target_sources(sfizz_editor PRIVATE
src/editor/NativeHelpers.mm)
src/editor/NativeHelpers.mm
src/editor/VSTGUIHelpers.mm)
target_link_libraries(sfizz_editor PRIVATE
"${APPLE_APPKIT_LIBRARY}"
"${APPLE_CORESERVICES_LIBRARY}"

View file

@ -13,6 +13,7 @@
#include "DlgAbout.h"
#include "ImageHelpers.h"
#include "NativeHelpers.h"
#include "VSTGUIHelpers.h"
#include "BitArray.h"
#include "plugin/MessageUtils.h"
#include <absl/strings/string_view.h>
@ -274,6 +275,9 @@ void Editor::open(CFrame& frame)
{
Impl& impl = *impl_;
fprintf(stderr, "[sfizz] The resource path of the bundle is %s\n",
getResourceBasePath().u8string().c_str());
impl.frame_ = &frame;
frame.addView(impl.mainView_.get());

View file

@ -0,0 +1,35 @@
// SPDX-License-Identifier: BSD-2-Clause
// This code is part of the sfizz library and is licensed under a BSD 2-clause
// license. You should have receive a LICENSE.md file along with the code.
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
#include "VSTGUIHelpers.h"
#include "utility/vstgui_before.h"
#include "vstgui/lib/platform/platformfactory.h"
#if defined(_WIN32)
# include "vstgui/lib/platform/win32/win32factory.h"
#elif defined(__APPLE__)
#else
# include "vstgui/lib/platform/linux/linuxfactory.h"
#endif
#include "utility/vstgui_after.h"
using namespace VSTGUI;
#if defined(_WIN32)
fs::path getResourceBasePath()
{
Optional<UTF8String> optionalPath = getPlatformFactory().asWin32Factory()->getResourceBasePath();
if (!optionalPath)
return fs::path();
return fs::u8path(optionalPath->getString());
}
#elif defined(__APPLE__)
// implemented in VSTGUIHelpers.mm
#else
fs::path getResourceBasePath()
{
return fs::u8path(getPlatformFactory().asLinuxFactory()->getResourcePath());
}
#endif

View file

@ -0,0 +1,10 @@
// SPDX-License-Identifier: BSD-2-Clause
// This code is part of the sfizz library and is licensed under a BSD 2-clause
// license. You should have receive a LICENSE.md file along with the code.
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
#pragma once
#include <ghc/fs_std.hpp>
fs::path getResourceBasePath();

View file

@ -0,0 +1,26 @@
// SPDX-License-Identifier: BSD-2-Clause
// This code is part of the sfizz library and is licensed under a BSD 2-clause
// license. You should have receive a LICENSE.md file along with the code.
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
#include "VSTGUIHelpers.h"
#if defined(__APPLE__)
#include "vstgui/lib/platform/mac/macfactory.h"
#import <Foundation/Foundation.h>
#import <CoreFoundation/CoreFoundation.h>
fs::path getResourceBasePath()
{
CFBundleRef bundle = VSTGUI::getPlatformFactory().asMacFactory()->getBundle();
if (!bundle)
return fs::path();
NSURL* url = (__bridge_transfer NSURL*)CFBundleCopyResourcesDirectoryURL(bundle);
if (!url || ![url isFileURL])
return fs::path();
return fs::u8path([[url path] UTF8String]);
}
#endif