21 #include <emscripten/val.h> 34 void UTF8ToUTF16(
wchar_t* utf16Str,
const char* utf8Str,
int maxLen)
36 int requiredSize = MultiByteToWideChar(CP_UTF8, 0, utf8Str, -1, NULL, 0);
38 if (requiredSize > 0 && requiredSize <= maxLen)
40 MultiByteToWideChar(CP_UTF8, 0, utf8Str, -1, utf16Str, requiredSize);
47 void UTF16ToUTF8(WDL_String& utf8Str,
const wchar_t* utf16Str)
49 int requiredSize = WideCharToMultiByte(CP_UTF8, 0, utf16Str, -1, NULL, 0, NULL, NULL);
51 if (requiredSize > 0 && utf8Str.SetLen(requiredSize))
53 WideCharToMultiByte(CP_UTF8, 0, utf16Str, -1, utf8Str.Get(), requiredSize, NULL, NULL);
61 void GetKnownFolder(WDL_String &path,
int identifier,
int flags = 0)
63 wchar_t wideBuffer[1024];
65 SHGetFolderPathW(NULL, identifier, NULL, flags, wideBuffer);
66 UTF16ToUTF8(path, wideBuffer);
69 static void GetModulePath(HMODULE hModule, WDL_String& path)
72 char pathCStr[MAX_WIN32_PATH_LEN];
74 if (GetModuleFileName(hModule, pathCStr, MAX_WIN32_PATH_LEN))
77 for (
int i = 0; i < strlen(pathCStr); ++i)
79 if (pathCStr[i] ==
'\\')
84 if (s >= 0 && s + 1 < strlen(pathCStr))
86 path.Set(pathCStr, s + 1);
91 void HostPath(WDL_String& path,
const char* bundleID)
93 GetModulePath(0, path);
96 void PluginPath(WDL_String& path, HMODULE pExtra)
98 GetModulePath(pExtra, path);
104 GetModulePath(pExtra, path);
106 path.SetLen(path.GetLength() - strlen(
"x86_64-win/"));
108 path.SetLen(path.GetLength() - strlen(
"x86-win/"));
110 path.Append(
"Resources\\");
116 GetKnownFolder(path, CSIDL_DESKTOP);
121 GetKnownFolder(path, CSIDL_PROFILE);
126 GetKnownFolder(path, isSystem ? CSIDL_COMMON_APPDATA : CSIDL_LOCAL_APPDATA);
129 void VST3PresetsPath(WDL_String& path,
const char* mfrName,
const char* pluginName,
bool isSystem)
132 GetKnownFolder(path, CSIDL_PERSONAL, SHGFP_TYPE_CURRENT);
136 path.AppendFormatted(MAX_WIN32_PATH_LEN,
"\\VST3 Presets\\%s\\%s", mfrName, pluginName);
144 void INIPath(WDL_String& path,
const char * pluginName)
146 GetKnownFolder(path, CSIDL_LOCAL_APPDATA);
148 path.AppendFormatted(MAX_WIN32_PATH_LEN,
"\\%s", pluginName);
151 static BOOL EnumResNameProc(HANDLE module, LPCTSTR type, LPTSTR name, LONG_PTR param)
153 if (IS_INTRESOURCE(name))
return true;
155 WDL_String* search = (WDL_String*)param;
156 if (search != 0 && name != 0)
159 WDL_String strippedName(strlwr(name + 1));
160 strippedName.SetLen(strippedName.GetLength() - 1);
162 if (strcmp(strlwr(search->Get()), strippedName.Get()) == 0)
164 search->SetFormatted(strippedName.GetLength() + 7,
"found: %s", strippedName.Get());
173 EResourceLocation
LocateResource(
const char* name,
const char* type, WDL_String& result,
const char*,
void* pHInstance,
const char*)
175 if (CStringHasContents(name))
177 WDL_String search(name);
178 WDL_String typeUpper(type);
180 HMODULE hInstance =
static_cast<HMODULE
>(pHInstance);
182 EnumResourceNames(hInstance, _strupr(typeUpper.Get()), (ENUMRESNAMEPROC)EnumResNameProc, (LONG_PTR)&search);
184 if (strstr(search.Get(), "found: ") != 0)
186 result.SetFormatted(MAX_PATH,
"\"%s\"", search.Get() + 7, search.GetLength() - 7);
187 return EResourceLocation::kWinBinary;
191 if (PathFileExists(name))
194 return EResourceLocation::kAbsolutePath;
198 return EResourceLocation::kNotFound;
201 const void*
LoadWinResource(
const char* resid,
const char* type,
int& sizeInBytes,
void* pHInstance)
203 WDL_String typeUpper(type);
205 HMODULE hInstance =
static_cast<HMODULE
>(pHInstance);
207 HRSRC hResource = FindResource(hInstance, resid, _strupr(typeUpper.Get()));
212 DWORD size = SizeofResource(hInstance, hResource);
217 HGLOBAL res = LoadResource(hInstance, hResource);
219 const void* pResourceData = LockResource(res);
229 return pResourceData;
239 #pragma mark - OS_WEB 243 path.Set(
"Settings");
248 path.Set(
"Settings");
256 void VST3PresetsPath(WDL_String& path,
const char* mfrName,
const char* pluginName,
bool isSystem)
261 EResourceLocation
LocateResource(
const char* name,
const char* type, WDL_String& result,
const char*,
void*,
const char*)
263 if (CStringHasContents(name))
265 WDL_String plusSlash;
266 WDL_String path(name);
267 const char* file = path.get_filepart();
269 bool foundResource =
false;
273 if(strcmp(type,
"png") == 0) {
274 plusSlash.SetFormatted(strlen(
"/resources/img/") + strlen(file) + 1,
"/resources/img/%s", file);
275 foundResource = emscripten::val::global(
"Module")[
"preloadedImages"].call<
bool>(
"hasOwnProperty", std::string(plusSlash.Get()));
277 else if(strcmp(type,
"ttf") == 0) {
278 plusSlash.SetFormatted(strlen(
"/resources/fonts/") + strlen(file) + 1,
"/resources/fonts/%s", file);
279 foundResource =
true;
281 else if(strcmp(type,
"svg") == 0) {
282 plusSlash.SetFormatted(strlen(
"/resources/img/") + strlen(file) + 1,
"/resources/img/%s", file);
283 foundResource =
true;
288 result.Set(plusSlash.Get());
289 return EResourceLocation::kAbsolutePath;
292 return EResourceLocation::kNotFound;
const void * LoadWinResource(const char *resID, const char *type, int &sizeInBytes, void *pHInstance)
Load a resource from the binary (windows only).
Common paths useful for plug-ins.
void BundleResourcePath(WDL_String &path, PluginIDType pExtra=0)
Get the path to the plug-in bundle resource path.
void SandboxSafeAppSupportPath(WDL_String &path, const char *appGroupID="")
void AppSupportPath(WDL_String &path, bool isSystem=false)
IPlug Constant definitions, Types, magic numbers.
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 INIPath(WDL_String &path, const char *pluginName)
Get the path to the folder where the App's settings.ini file is stored.
void VST3PresetsPath(WDL_String &path, const char *mfrName, const char *pluginName, bool isSystem=true)
void HostPath(WDL_String &path, const char *bundleID=0)
Get the path to the host binary.
void PluginPath(WDL_String &path, PluginIDType pExtra)
Get the path to the plug-in binary.
void DesktopPath(WDL_String &path)