21#if defined(OS_IOS) || defined(OS_MAC)
22#import <Foundation/Foundation.h>
23#include <TargetConditionals.h>
27extern std::map<std::string, void*> gTextureMap;
35void HostPath(WDL_String& path,
const char* bundleID)
39 NSBundle* pBundle = [NSBundle bundleWithIdentifier: [NSString stringWithUTF8String:bundleID]];
43 NSString* pPath = [pBundle executablePath];
46 path.Set([pPath UTF8String]);
52void PluginPath(WDL_String& path, PluginIDType bundleID)
56 NSBundle* pBundle = [NSBundle bundleWithIdentifier: [NSString stringWithUTF8String:bundleID]];
60 NSString* pPath = [[pBundle bundlePath] stringByDeletingLastPathComponent];
64 path.Set([pPath UTF8String]);
75 NSBundle* pBundle = nil;
77 if (IsAUv3AppExtensionBundleID(bundleID))
81 NSString* frameworkBundleID = [[NSString stringWithUTF8String:bundleID] stringByAppendingString:
@"Framework"];
82 pBundle = [NSBundle bundleWithIdentifier:frameworkBundleID];
86 pBundle = [NSBundle bundleWithIdentifier:[NSString stringWithUTF8String:bundleID]];
89 NSString* pResPath = [pBundle resourcePath];
91 path.Set([pResPath UTF8String]);
97 NSArray* pPaths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES);
98 NSString* pDesktopDirectory = [pPaths objectAtIndex:0];
99 path.Set([pDesktopDirectory UTF8String]);
104 NSString* pHomeDir = NSHomeDirectory();
105 path.Set([pHomeDir UTF8String]);
108void VST3PresetsPath(WDL_String& path,
const char* mfrName,
const char* pluginName,
bool isSystem)
112 pPaths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSLocalDomainMask, YES);
114 pPaths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
116 NSString* pApplicationSupportDirectory = [pPaths objectAtIndex:0];
117 path.SetFormatted(MAX_MACOS_PATH_LEN,
"%s/Audio/Presets/%s/%s/", [pApplicationSupportDirectory UTF8String], mfrName, pluginName);
120void INIPath(WDL_String& path,
const char* pluginName)
123 path.AppendFormatted(MAX_MACOS_PATH_LEN,
"/%s", pluginName);
131 pPaths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSSystemDomainMask, YES);
133 pPaths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
135 NSString *pApplicationSupportDirectory = [pPaths objectAtIndex:0];
136 path.Set([pApplicationSupportDirectory UTF8String]);
139void AppGroupContainerPath(WDL_String& path,
const char* appGroupID)
141 NSFileManager* mgr = [NSFileManager defaultManager];
142 NSURL* url = [mgr containerURLForSecurityApplicationGroupIdentifier:[NSString stringWithUTF8String:appGroupID]];
143 path.Set([[url path] UTF8String]);
146void SharedMusicPath(WDL_String& path)
148 NSArray* pPaths = NSSearchPathForDirectoriesInDomains(NSMusicDirectory, NSUserDomainMask, YES);
149 NSString* pUserMusicDirectory = [pPaths objectAtIndex:0];
150 path.Set([pUserMusicDirectory UTF8String]);
153bool GetResourcePathFromBundle(
const char* fileName,
const char* searchExt, WDL_String& fullPath,
const char* bundleID)
157 const char* ext = fileName+strlen(fileName)-1;
158 while (ext >= fileName && *ext !=
'.') --ext;
161 bool isCorrectType = !strcasecmp(ext, searchExt);
163 bool isAppExtension = IsAUv3AppExtensionBundleID(bundleID);
165 NSBundle* pBundle = nil;
171 NSString* frameworkBundleID = [[NSString stringWithUTF8String:bundleID] stringByAppendingString:
@"Framework"];
172 pBundle = [NSBundle bundleWithIdentifier:frameworkBundleID];
176 pBundle = [NSBundle bundleWithIdentifier:[NSString stringWithUTF8String:bundleID]];
179 NSString* pFile = [[NSString stringWithUTF8String:fileName] stringByDeletingPathExtension];
180 NSString* pExt = [NSString stringWithUTF8String:searchExt];
182 if (isCorrectType && pBundle && pFile)
184 NSString* pBasePath = [[pBundle resourcePath] stringByAppendingString:
@"/"];
186 NSString* pPath = [[[pBasePath stringByAppendingString:pFile] stringByAppendingString:
@"."] stringByAppendingString:pExt];
188 if (pPath && [[NSFileManager defaultManager] fileExistsAtPath : pPath] == YES)
190 fullPath.Set([pPath UTF8String]);
200bool GetResourcePathFromSharedLocation(
const char* fileName,
const char* searchExt, WDL_String& fullPath,
const char* subfolder)
204 const char* ext = fileName+strlen(fileName)-1;
205 while (ext >= fileName && *ext !=
'.') --ext;
208 bool isCorrectType = !strcasecmp(ext, searchExt);
210 NSString* pExt = [NSString stringWithUTF8String:searchExt];
211 NSString* pFile = [[[NSString stringWithUTF8String:fileName] lastPathComponent] stringByDeletingPathExtension];
213 if (isCorrectType && pFile)
215 WDL_String musicPath;
216 SharedMusicPath(musicPath);
220 NSString* pPluginName = [NSString stringWithUTF8String:subfolder];
221 NSString* pMusicLocation = [NSString stringWithUTF8String:musicPath.Get()];
222 NSString* pPath = [[[[pMusicLocation stringByAppendingPathComponent: pPluginName] stringByAppendingPathComponent:
@"Resources"] stringByAppendingPathComponent: pFile] stringByAppendingPathExtension:pExt];
224 if ([[NSFileManager defaultManager] fileExistsAtPath : pPath] == YES)
226 fullPath.Set([pPath UTF8String]);
237EResourceLocation
LocateResource(
const char* name,
const char* type, WDL_String& result,
const char* bundleID,
void*,
const char* sharedResourcesSubPath)
239 if(CStringHasContents(name))
242 if(GetResourcePathFromBundle(name, type, result, bundleID))
243 return EResourceLocation::kAbsolutePath;
246 if(GetResourcePathFromSharedLocation(name, type, result, sharedResourcesSubPath))
247 return EResourceLocation::kAbsolutePath;
250 NSString* pPath = [NSString stringWithUTF8String:name];
252 if([[NSFileManager defaultManager] fileExistsAtPath : pPath] == YES)
254 result.Set([pPath UTF8String]);
255 return EResourceLocation::kAbsolutePath;
258 return EResourceLocation::kNotFound;
263 NSString* pHomeDir = NSHomeDirectory();
265 if ([pHomeDir containsString:
@"Library/Containers/"])
273 return ([[[NSProcessInfo processInfo] processName] containsString:
@"XPC"]);
276bool IsOOPAuv3AppExtension()
278 return ([[[NSBundle mainBundle] bundleIdentifier] containsString:
@"AUv3"]);
281bool IsAUv3AppExtensionBundleID(
const char* bundleID)
286 return [[NSString stringWithUTF8String:bundleID] containsString:
@".AUv3"];
292void HostPath(WDL_String& path,
const char* bundleID)
296void PluginPath(WDL_String& path, PluginIDType bundleID)
302 NSBundle* pBundle = [NSBundle mainBundle];
304 if(IsOOPAuv3AppExtension())
305 pBundle = [NSBundle bundleWithPath: [[[pBundle bundlePath] stringByDeletingLastPathComponent] stringByDeletingLastPathComponent]];
307 path.Set([[pBundle resourcePath] UTF8String]);
314void VST3PresetsPath(WDL_String& path,
const char* mfrName,
const char* pluginName,
bool isSystem)
319void INIPath(WDL_String& path,
const char* pluginName)
328void AppGroupContainerPath(WDL_String& path,
const char* appGroupID)
330 NSFileManager* mgr = [NSFileManager defaultManager];
331 NSURL* url = [mgr containerURLForSecurityApplicationGroupIdentifier:[NSString stringWithUTF8String:appGroupID]];
332 path.Set([[url path] UTF8String]);
335bool GetResourcePathFromBundle(
const char* fileName,
const char* searchExt, WDL_String& fullPath,
const char* bundleID)
339 const char* ext = fileName+strlen(fileName)-1;
340 while (ext >= fileName && *ext !=
'.') --ext;
343 bool isCorrectType = !strcasecmp(ext, searchExt);
345 bool isAppExtension = IsOOPAuv3AppExtension();
350 pBundle = [NSBundle bundleWithIdentifier:[NSString stringWithUTF8String:bundleID]];
352 pBundle = [NSBundle mainBundle];
354 NSString* pFile = [[NSString stringWithUTF8String:fileName] stringByDeletingPathExtension];
355 NSString* pExt = [NSString stringWithUTF8String:searchExt];
357 if (isCorrectType && pBundle && pFile)
363 pRootPath = [[[pBundle bundlePath] stringByDeletingLastPathComponent] stringByDeletingLastPathComponent];
364 #if TARGET_OS_MACCATALYST
365 pRootPath = [pRootPath stringByAppendingString:
@"/Resources"];
370 pRootPath = [pBundle resourcePath];
373 NSString* pPath = [[[[pRootPath stringByAppendingString:
@"/"] stringByAppendingString:pFile] stringByAppendingString:
@"."] stringByAppendingString:pExt];
375 if (pPath && [[NSFileManager defaultManager] fileExistsAtPath : pPath] == YES)
377 fullPath.Set([pPath UTF8String]);
387EResourceLocation
LocateResource(
const char* name,
const char* type, WDL_String& result,
const char* bundleID,
void*,
const char*)
389 if (CStringHasContents(name))
391#ifdef IGRAPHICS_METAL
392 auto itr = gTextureMap.find(name);
394 if (itr != gTextureMap.end())
397 return EResourceLocation::kPreloadedTexture;
401 if (GetResourcePathFromBundle(name, type, result, bundleID))
402 return EResourceLocation::kAbsolutePath;
405 return EResourceLocation::kNotFound;
419bool IsOOPAuv3AppExtension()
421 return ([[[NSBundle mainBundle] bundleIdentifier] containsString:
@"AUv3"]);
Common paths useful for plug-ins.
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.