21 #if defined(OS_IOS) || defined(OS_MAC) 22 #import <Foundation/Foundation.h> 23 #include <TargetConditionals.h> 26 #ifdef IGRAPHICS_METAL 27 extern std::map<std::string, void*> gTextureMap;
33 void HostPath(WDL_String& path,
const char* bundleID)
37 NSBundle* pBundle = [NSBundle bundleWithIdentifier: [NSString stringWithCString:bundleID encoding:NSUTF8StringEncoding]];
41 NSString* pPath = [pBundle executablePath];
44 path.Set([pPath UTF8String]);
50 void PluginPath(WDL_String& path, PluginIDType bundleID)
54 NSBundle* pBundle = [NSBundle bundleWithIdentifier: [NSString stringWithCString:bundleID encoding:NSUTF8StringEncoding]];
58 NSString* pPath = [[pBundle bundlePath] stringByDeletingLastPathComponent];
62 path.Set([pPath UTF8String]);
73 NSBundle* pBundle = [NSBundle bundleWithIdentifier:[NSString stringWithCString:bundleID encoding:NSUTF8StringEncoding]];
74 NSString* pResPath = [pBundle resourcePath];
76 path.Set([pResPath UTF8String]);
82 NSArray* pPaths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES);
83 NSString* pDesktopDirectory = [pPaths objectAtIndex:0];
84 path.Set([pDesktopDirectory UTF8String]);
89 NSString* pHomeDir = NSHomeDirectory();
90 path.Set([pHomeDir UTF8String]);
93 void VST3PresetsPath(WDL_String& path,
const char* mfrName,
const char* pluginName,
bool isSystem)
97 pPaths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSLocalDomainMask, YES);
99 pPaths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
101 NSString* pApplicationSupportDirectory = [pPaths objectAtIndex:0];
102 path.SetFormatted(MAX_MACOS_PATH_LEN,
"%s/Audio/Presets/%s/%s/", [pApplicationSupportDirectory UTF8String], mfrName, pluginName);
105 void INIPath(WDL_String& path,
const char* pluginName)
108 path.AppendFormatted(MAX_MACOS_PATH_LEN,
"/%s", pluginName);
116 pPaths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSSystemDomainMask, YES);
118 pPaths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
120 NSString *pApplicationSupportDirectory = [pPaths objectAtIndex:0];
121 path.Set([pApplicationSupportDirectory UTF8String]);
126 NSArray* pPaths = NSSearchPathForDirectoriesInDomains(NSMusicDirectory, NSUserDomainMask, YES);
127 NSString* pUserMusicDirectory = [pPaths objectAtIndex:0];
128 path.Set([pUserMusicDirectory UTF8String]);
131 bool GetResourcePathFromBundle(
const char* fileName,
const char* searchExt, WDL_String& fullPath,
const char* bundleID)
135 const char* ext = fileName+strlen(fileName)-1;
136 while (ext >= fileName && *ext !=
'.') --ext;
139 bool isCorrectType = !strcasecmp(ext, searchExt);
141 NSBundle* pBundle = [NSBundle bundleWithIdentifier:[NSString stringWithCString:bundleID encoding:NSUTF8StringEncoding]];
142 NSString* pFile = [[[NSString stringWithCString:fileName encoding:NSUTF8StringEncoding] lastPathComponent] stringByDeletingPathExtension];
144 if (isCorrectType && pBundle && pFile)
146 NSString* pPath = [pBundle pathForResource:pFile ofType:[NSString stringWithCString:searchExt encoding:NSUTF8StringEncoding]];
150 pFile = [[NSString stringWithCString:fileName encoding:NSUTF8StringEncoding] stringByDeletingPathExtension];
151 pPath = [pBundle pathForResource:pFile ofType:[NSString stringWithCString:searchExt encoding:NSUTF8StringEncoding]];
156 if([[NSFileManager defaultManager] fileExistsAtPath : pPath] == YES)
158 fullPath.Set([pPath cString]);
169 bool GetResourcePathFromSharedLocation(
const char* fileName,
const char* searchExt, WDL_String& fullPath,
const char* subfolder)
173 const char* ext = fileName+strlen(fileName)-1;
174 while (ext >= fileName && *ext !=
'.') --ext;
177 bool isCorrectType = !strcasecmp(ext, searchExt);
179 NSString* pExt = [NSString stringWithCString:searchExt encoding:NSUTF8StringEncoding];
180 NSString* pFile = [[[NSString stringWithCString:fileName encoding:NSUTF8StringEncoding] lastPathComponent] stringByDeletingPathExtension];
182 if (isCorrectType && pFile)
184 WDL_String musicFolder;
189 NSString* pPluginName = [NSString stringWithCString: subfolder encoding:NSUTF8StringEncoding];
190 NSString* pMusicLocation = [NSString stringWithCString: musicFolder.Get() encoding:NSUTF8StringEncoding];
191 NSString* pPath = [[[[pMusicLocation stringByAppendingPathComponent:pPluginName] stringByAppendingPathComponent:
@"Resources"] stringByAppendingPathComponent: pFile] stringByAppendingPathExtension:pExt];
193 if([[NSFileManager defaultManager] fileExistsAtPath : pPath] == YES)
195 fullPath.Set([pPath cString]);
206 EResourceLocation
LocateResource(
const char* name,
const char* type, WDL_String& result,
const char* bundleID,
void*,
const char* sharedResourcesSubPath)
208 if(CStringHasContents(name))
211 if(GetResourcePathFromBundle(name, type, result, bundleID))
212 return EResourceLocation::kAbsolutePath;
215 if(GetResourcePathFromSharedLocation(name, type, result, sharedResourcesSubPath))
216 return EResourceLocation::kAbsolutePath;
219 NSString* pPath = [NSString stringWithCString:name encoding:NSUTF8StringEncoding];
221 if([[NSFileManager defaultManager] fileExistsAtPath : pPath] == YES)
223 result.Set([pPath UTF8String]);
224 return EResourceLocation::kAbsolutePath;
227 return EResourceLocation::kNotFound;
232 NSString* pHomeDir = NSHomeDirectory();
234 if ([pHomeDir containsString:
@"Library/Containers/"])
243 void HostPath(WDL_String& path,
const char* bundleID)
247 void PluginPath(WDL_String& path, PluginIDType bundleID)
253 NSBundle* pBundle = [NSBundle mainBundle];
255 if(IsAuv3AppExtension())
256 pBundle = [NSBundle bundleWithPath: [[[pBundle bundlePath] stringByDeletingLastPathComponent] stringByDeletingLastPathComponent]];
258 path.Set([[pBundle resourcePath] UTF8String]);
267 NSFileManager* mgr = [NSFileManager defaultManager];
268 NSURL* url = [mgr containerURLForSecurityApplicationGroupIdentifier:[NSString stringWithUTF8String:appGroupID]];
269 path.Set([[url path] UTF8String]);
276 void VST3PresetsPath(WDL_String& path,
const char* mfrName,
const char* pluginName,
bool isSystem)
281 void INIPath(WDL_String& path,
const char* pluginName)
286 bool GetResourcePathFromBundle(
const char* fileName,
const char* searchExt, WDL_String& fullPath,
const char* bundleID)
290 const char* ext = fileName+strlen(fileName)-1;
291 while (ext >= fileName && *ext !=
'.') --ext;
294 bool isCorrectType = !strcasecmp(ext, searchExt);
296 bool isAppExtension =
false;
298 NSBundle* pBundle = [NSBundle mainBundle];
300 if([[pBundle bundleIdentifier] containsString:
@"AUv3"])
301 isAppExtension =
true;
304 pBundle = [NSBundle bundleWithIdentifier:[NSString stringWithCString:bundleID encoding:NSUTF8StringEncoding]];
306 NSString* pFile = [[NSString stringWithCString:fileName encoding:NSUTF8StringEncoding] stringByDeletingPathExtension];
307 NSString* pExt = [NSString stringWithCString:searchExt encoding:NSUTF8StringEncoding];
309 if (isCorrectType && pBundle && pFile)
314 pRootPath = [[[pBundle bundlePath] stringByDeletingLastPathComponent] stringByDeletingLastPathComponent];
317 #ifdef TARGET_OS_MACCATALYST 318 pRootPath = [pBundle resourcePath];
320 pRootPath = [pBundle bundlePath];
324 NSString* pPath = [[[[pRootPath stringByAppendingString:
@"/"] stringByAppendingString:pFile] stringByAppendingString:
@"."] stringByAppendingString:pExt];
328 fullPath.Set([pPath cStringUsingEncoding:NSUTF8StringEncoding]);
338 EResourceLocation
LocateResource(
const char* name,
const char* type, WDL_String& result,
const char* bundleID,
void*,
const char*)
340 if(CStringHasContents(name))
342 #ifdef IGRAPHICS_METAL 343 auto itr = gTextureMap.find(name);
345 if (itr != gTextureMap.end())
348 return EResourceLocation::kPreloadedTexture;
352 if(GetResourcePathFromBundle(name, type, result, bundleID))
353 return EResourceLocation::kAbsolutePath;
356 return EResourceLocation::kNotFound;
364 bool IsAuv3AppExtension()
366 return ([[[NSBundle mainBundle] bundleIdentifier] containsString:
@"AUv3"]);
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)
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)