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 = [NSBundle bundleWithIdentifier:[NSString stringWithUTF8String:bundleID]];
76 NSString* pResPath = [pBundle resourcePath];
78 path.Set([pResPath UTF8String]);
84 NSArray* pPaths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES);
85 NSString* pDesktopDirectory = [pPaths objectAtIndex:0];
86 path.Set([pDesktopDirectory UTF8String]);
91 NSString* pHomeDir = NSHomeDirectory();
92 path.Set([pHomeDir UTF8String]);
95void VST3PresetsPath(WDL_String& path,
const char* mfrName,
const char* pluginName,
bool isSystem)
99 pPaths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSLocalDomainMask, YES);
101 pPaths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
103 NSString* pApplicationSupportDirectory = [pPaths objectAtIndex:0];
104 path.SetFormatted(MAX_MACOS_PATH_LEN,
"%s/Audio/Presets/%s/%s/", [pApplicationSupportDirectory UTF8String], mfrName, pluginName);
107void INIPath(WDL_String& path,
const char* pluginName)
110 path.AppendFormatted(MAX_MACOS_PATH_LEN,
"/%s", pluginName);
118 pPaths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSSystemDomainMask, YES);
120 pPaths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
122 NSString *pApplicationSupportDirectory = [pPaths objectAtIndex:0];
123 path.Set([pApplicationSupportDirectory UTF8String]);
126void AppGroupContainerPath(WDL_String& path,
const char* appGroupID)
128 NSFileManager* mgr = [NSFileManager defaultManager];
129 NSURL* url = [mgr containerURLForSecurityApplicationGroupIdentifier:[NSString stringWithUTF8String:appGroupID]];
130 path.Set([[url path] UTF8String]);
133void SharedMusicPath(WDL_String& path)
135 NSArray* pPaths = NSSearchPathForDirectoriesInDomains(NSMusicDirectory, NSUserDomainMask, YES);
136 NSString* pUserMusicDirectory = [pPaths objectAtIndex:0];
137 path.Set([pUserMusicDirectory UTF8String]);
140bool GetResourcePathFromBundle(
const char* fileName,
const char* searchExt, WDL_String& fullPath,
const char* bundleID)
144 const char* ext = fileName+strlen(fileName)-1;
145 while (ext >= fileName && *ext !=
'.') --ext;
148 bool isCorrectType = !strcasecmp(ext, searchExt);
150 bool isAppExtension = IsOOPAuv3AppExtension();
152 NSBundle* pBundle = [NSBundle bundleWithIdentifier:[NSString stringWithUTF8String:bundleID]];
154 NSString* pFile = [[NSString stringWithUTF8String:fileName] stringByDeletingPathExtension];
155 NSString* pExt = [NSString stringWithUTF8String:searchExt];
157 if (isCorrectType && pBundle && pFile)
162 pBasePath = [[[[pBundle bundlePath] stringByDeletingLastPathComponent] stringByDeletingLastPathComponent] stringByAppendingString:
@"/Resources/"];
164 pBasePath = [[pBundle resourcePath] stringByAppendingString:
@"/"];
166 NSString* pPath = [[[pBasePath stringByAppendingString:pFile] stringByAppendingString:
@"."] stringByAppendingString:pExt];
168 if (pPath && [[NSFileManager defaultManager] fileExistsAtPath : pPath] == YES)
170 fullPath.Set([pPath UTF8String]);
180bool GetResourcePathFromSharedLocation(
const char* fileName,
const char* searchExt, WDL_String& fullPath,
const char* subfolder)
184 const char* ext = fileName+strlen(fileName)-1;
185 while (ext >= fileName && *ext !=
'.') --ext;
188 bool isCorrectType = !strcasecmp(ext, searchExt);
190 NSString* pExt = [NSString stringWithUTF8String:searchExt];
191 NSString* pFile = [[[NSString stringWithUTF8String:fileName] lastPathComponent] stringByDeletingPathExtension];
193 if (isCorrectType && pFile)
195 WDL_String musicPath;
196 SharedMusicPath(musicPath);
200 NSString* pPluginName = [NSString stringWithUTF8String:subfolder];
201 NSString* pMusicLocation = [NSString stringWithUTF8String:musicPath.Get()];
202 NSString* pPath = [[[[pMusicLocation stringByAppendingPathComponent: pPluginName] stringByAppendingPathComponent:
@"Resources"] stringByAppendingPathComponent: pFile] stringByAppendingPathExtension:pExt];
204 if ([[NSFileManager defaultManager] fileExistsAtPath : pPath] == YES)
206 fullPath.Set([pPath UTF8String]);
217EResourceLocation
LocateResource(
const char* name,
const char* type, WDL_String& result,
const char* bundleID,
void*,
const char* sharedResourcesSubPath)
219 if(CStringHasContents(name))
223 if(GetResourcePathFromBundle(name, type, result, bundleID))
224 return EResourceLocation::kAbsolutePath;
228 if(GetResourcePathFromSharedLocation(name, type, result, sharedResourcesSubPath))
229 return EResourceLocation::kAbsolutePath;
232 NSString* pPath = [NSString stringWithUTF8String:name];
234 if([[NSFileManager defaultManager] fileExistsAtPath : pPath] == YES)
236 result.Set([pPath UTF8String]);
237 return EResourceLocation::kAbsolutePath;
240 return EResourceLocation::kNotFound;
245 NSString* pHomeDir = NSHomeDirectory();
247 if ([pHomeDir containsString:
@"Library/Containers/"])
255 return ([[[NSProcessInfo processInfo] processName] containsString:
@"XPC"]);
258bool IsOOPAuv3AppExtension()
260 return ([[[NSBundle mainBundle] bundleIdentifier] containsString:
@"AUv3"]);
266void HostPath(WDL_String& path,
const char* bundleID)
270void PluginPath(WDL_String& path, PluginIDType bundleID)
276 NSBundle* pBundle = [NSBundle mainBundle];
278 if(IsOOPAuv3AppExtension())
279 pBundle = [NSBundle bundleWithPath: [[[pBundle bundlePath] stringByDeletingLastPathComponent] stringByDeletingLastPathComponent]];
281 path.Set([[pBundle resourcePath] UTF8String]);
288void VST3PresetsPath(WDL_String& path,
const char* mfrName,
const char* pluginName,
bool isSystem)
293void INIPath(WDL_String& path,
const char* pluginName)
302void AppGroupContainerPath(WDL_String& path,
const char* appGroupID)
304 NSFileManager* mgr = [NSFileManager defaultManager];
305 NSURL* url = [mgr containerURLForSecurityApplicationGroupIdentifier:[NSString stringWithUTF8String:appGroupID]];
306 path.Set([[url path] UTF8String]);
309bool GetResourcePathFromBundle(
const char* fileName,
const char* searchExt, WDL_String& fullPath,
const char* bundleID)
313 const char* ext = fileName+strlen(fileName)-1;
314 while (ext >= fileName && *ext !=
'.') --ext;
317 bool isCorrectType = !strcasecmp(ext, searchExt);
319 bool isAppExtension = IsOOPAuv3AppExtension();
324 pBundle = [NSBundle bundleWithIdentifier:[NSString stringWithUTF8String:bundleID]];
326 pBundle = [NSBundle mainBundle];
328 NSString* pFile = [[NSString stringWithUTF8String:fileName] stringByDeletingPathExtension];
329 NSString* pExt = [NSString stringWithUTF8String:searchExt];
331 if (isCorrectType && pBundle && pFile)
337 pRootPath = [[[pBundle bundlePath] stringByDeletingLastPathComponent] stringByDeletingLastPathComponent];
338 #if TARGET_OS_MACCATALYST
339 pRootPath = [pRootPath stringByAppendingString:
@"/Resources"];
344 pRootPath = [pBundle resourcePath];
347 NSString* pPath = [[[[pRootPath stringByAppendingString:
@"/"] stringByAppendingString:pFile] stringByAppendingString:
@"."] stringByAppendingString:pExt];
349 if (pPath && [[NSFileManager defaultManager] fileExistsAtPath : pPath] == YES)
351 fullPath.Set([pPath UTF8String]);
361EResourceLocation
LocateResource(
const char* name,
const char* type, WDL_String& result,
const char* bundleID,
void*,
const char*)
363 if (CStringHasContents(name))
365#ifdef IGRAPHICS_METAL
366 auto itr = gTextureMap.find(name);
368 if (itr != gTextureMap.end())
371 return EResourceLocation::kPreloadedTexture;
375 if (GetResourcePathFromBundle(name, type, result, bundleID))
376 return EResourceLocation::kAbsolutePath;
379 return EResourceLocation::kNotFound;
393bool IsOOPAuv3AppExtension()
395 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.