21#include <emscripten/val.h>
34void GetKnownFolder(WDL_String &path,
int identifier,
int flags = 0)
36 wchar_t wideBuffer[1024];
38 SHGetFolderPathW(NULL, identifier, NULL, flags, wideBuffer);
39 UTF16ToUTF8(path, wideBuffer);
42static void GetModulePath(HMODULE hModule, WDL_String& path)
44 wchar_t pathCStrW[MAX_WIN32_PATH_LEN] = {
'\0'};
48 if (GetModuleFileNameW(hModule, pathCStrW, MAX_WIN32_PATH_LEN))
50 UTF16AsUTF8 pathTemp(pathCStrW);
53 for (
int i = 0; i < strlen(pathTemp.Get()); ++i)
55 if (pathTemp.Get()[i] ==
'\\')
60 if (s >= 0 && s + 1 < strlen(pathTemp.Get()))
62 path.Set(pathTemp.Get(), s + 1);
67void HostPath(WDL_String& path,
const char* bundleID)
69 GetModulePath(0, path);
72void PluginPath(WDL_String& path, HMODULE pExtra)
74 GetModulePath(pExtra, path);
80 GetModulePath(pExtra, path);
82 path.SetLen(path.GetLength() - strlen(
"x86_64-win/"));
84 path.SetLen(path.GetLength() - strlen(
"x86-win/"));
86 path.Append(
"Resources\\");
92 GetKnownFolder(path, CSIDL_DESKTOP);
97 GetKnownFolder(path, CSIDL_PROFILE);
102 GetKnownFolder(path, isSystem ? CSIDL_COMMON_APPDATA : CSIDL_LOCAL_APPDATA);
105void VST3PresetsPath(WDL_String& path,
const char* mfrName,
const char* pluginName,
bool isSystem)
108 GetKnownFolder(path, CSIDL_PERSONAL, SHGFP_TYPE_CURRENT);
112 path.AppendFormatted(MAX_WIN32_PATH_LEN,
"\\VST3 Presets\\%s\\%s", mfrName, pluginName);
115void INIPath(WDL_String& path,
const char * pluginName)
117 GetKnownFolder(path, CSIDL_LOCAL_APPDATA);
119 path.AppendFormatted(MAX_WIN32_PATH_LEN,
"\\%s", pluginName);
124 GetKnownFolder(path, CSIDL_APPDATA);
125 path.Append(
"\\iPlug2\\WebViewCache");
128struct WinResourceSearch
130 WinResourceSearch(
const char* name)
132 UTF16ToUTF8(mName, UTF8AsUTF16(name).ToLowerCase().Get());
139static BOOL CALLBACK EnumResNameProc(HMODULE module, LPCWSTR type, LPWSTR name, LONG_PTR param)
141 if (IS_INTRESOURCE(name))
145 WinResourceSearch* search =
reinterpret_cast<WinResourceSearch*
>(param);
147 if (search !=
nullptr && name !=
nullptr)
149 WDL_String searchName(search->mName);
152 WDL_String strippedName((UTF16AsUTF8(name).Get() + 1));
153 strippedName.SetLen(strippedName.GetLength() - 1);
156 UTF16ToUTF8(strippedName, UTF8AsUTF16(strippedName).ToLowerCase().Get());
158 if (strcmp(searchName.Get(), strippedName.Get()) == 0)
160 UTF16ToUTF8(search->mName, name);
161 search->mFound =
true;
170static UTF8AsUTF16 TypeToUpper(
const char* type)
172 return UTF8AsUTF16(type).ToUpperCase();
175EResourceLocation
LocateResource(
const char* name,
const char* type, WDL_String& result,
const char*,
void* pHInstance,
const char*)
177 if (CStringHasContents(name))
179 WinResourceSearch search(name);
180 auto typeUpper = TypeToUpper(type);
182 HMODULE hInstance =
static_cast<HMODULE
>(pHInstance);
184 EnumResourceNamesW(hInstance, typeUpper.Get(), EnumResNameProc, (LONG_PTR) &search);
188 result.Set(search.mName.Get());
189 return EResourceLocation::kWinBinary;
193 if (PathFileExistsW(UTF8AsUTF16(name).Get()))
196 return EResourceLocation::kAbsolutePath;
200 return EResourceLocation::kNotFound;
203const void*
LoadWinResource(
const char* resid,
const char* type,
int& sizeInBytes,
void* pHInstance)
205 auto typeUpper = TypeToUpper(type);
207 HMODULE hInstance =
static_cast<HMODULE
>(pHInstance);
209 HRSRC hResource = FindResourceW(hInstance, UTF8AsUTF16(resid).Get(), typeUpper.Get());
214 DWORD size = SizeofResource(hInstance, hResource);
219 HGLOBAL res = LoadResource(hInstance, hResource);
221 const void* pResourceData = LockResource(res);
231 return pResourceData;
240 path.Set(
"Settings");
248void VST3PresetsPath(WDL_String& path,
const char* mfrName,
const char* pluginName,
bool isSystem)
253EResourceLocation
LocateResource(
const char* name,
const char* type, WDL_String& result,
const char*,
void*,
const char*)
255 if (CStringHasContents(name))
257 WDL_String plusSlash;
258 WDL_String path(name);
259 const char* file = path.get_filepart();
261 bool foundResource =
false;
265 if(strcmp(type,
"png") == 0) {
266 plusSlash.SetFormatted(strlen(
"/resources/img/") + strlen(file) + 1,
"/resources/img/%s", file);
267 foundResource = emscripten::val::global(
"Browser")[
"preloadedImages"].call<
bool>(
"hasOwnProperty", std::string(plusSlash.Get()));
269 else if(strcmp(type,
"ttf") == 0) {
270 plusSlash.SetFormatted(strlen(
"/resources/fonts/") + strlen(file) + 1,
"/resources/fonts/%s", file);
271 foundResource =
true;
273 else if(strcmp(type,
"svg") == 0) {
274 plusSlash.SetFormatted(strlen(
"/resources/img/") + strlen(file) + 1,
"/resources/img/%s", file);
275 foundResource =
true;
280 result.Set(plusSlash.Get());
281 return EResourceLocation::kAbsolutePath;
284 return EResourceLocation::kNotFound;
IPlug Constant definitions, Types, magic numbers.
Common paths useful for plug-ins.
const void * LoadWinResource(const char *resID, const char *type, int &sizeInBytes, void *pHInstance)
Load a resource from the binary (windows only).
void UserHomePath(WDL_String &path)
EResourceLocation LocateResource(const char *fileNameOrResID, const char *type, WDL_String &result, const char *bundleID, void *pHInstance, const char *sharedResourcesSubPath)
Find the absolute path of a resource based on it's file name (e.g.
void VST3PresetsPath(WDL_String &path, const char *mfrName, const char *pluginName, bool isSystem=true)
void PluginPath(WDL_String &path, PluginIDType pExtra)
Get the path to the plug-in binary.
void DesktopPath(WDL_String &path)
void HostPath(WDL_String &path, const char *bundleID=0)
Get the path to the host binary.
void AppSupportPath(WDL_String &path, bool isSystem=false)
void BundleResourcePath(WDL_String &path, PluginIDType pExtra=0)
Get the path to the plug-in bundle resource path.
void INIPath(WDL_String &path, const char *pluginName)
Get the path to the folder where the App's settings.ini file is stored.
void WebViewCachePath(WDL_String &path)
Get the path to the folder where the Plug-in's ICoreWebView2 userdata folder should be (Windows WebVi...