Audacity 3.2.0
Classes | Functions | Variables
VST3::Hosting::anonymous_namespace{module_win32.cpp} Namespace Reference

Classes

struct  Ole
 
class  Win32Module
 

Functions

bool checkVST3Package (filesystem::path &p)
 
bool isFolderSymbolicLink (const filesystem::path &p)
 
Optional< std::string > getKnownFolder (REFKNOWNFOLDERID folderID)
 
VST3::Optional< filesystem::path > resolveShellLink (const filesystem::path &p)
 
void findFilesWithExt (const filesystem::path &path, const std::string &ext, Module::PathList &pathList, bool recursive=true)
 
void findModules (const filesystem::path &path, Module::PathList &pathList)
 
Optional< filesystem::path > getContentsDirectoryFromModuleExecutablePath (const std::string &modulePath)
 

Variables

constexpr auto architectureString = "x86-win"
 

Function Documentation

◆ checkVST3Package()

bool VST3::Hosting::anonymous_namespace{module_win32.cpp}::checkVST3Package ( filesystem::path &  p)

Definition at line 201 of file module_win32.cpp.

202{
203 auto filename = p.filename ();
204 p /= "Contents";
206 p /= filename;
207 auto hFile = CreateFileW (reinterpret_cast<LPCWSTR> (p.c_str ()), GENERIC_READ, FILE_SHARE_READ,
208 nullptr, OPEN_EXISTING, 0, nullptr);
209 if (hFile != INVALID_HANDLE_VALUE)
210 {
211 CloseHandle (hFile);
212 return true;
213 }
214 return false;
215}

References architectureString.

Referenced by findFilesWithExt().

Here is the caller graph for this function:

◆ findFilesWithExt()

void VST3::Hosting::anonymous_namespace{module_win32.cpp}::findFilesWithExt ( const filesystem::path &  path,
const std::string &  ext,
Module::PathList &  pathList,
bool  recursive = true 
)

Definition at line 297 of file module_win32.cpp.

299{
300 for (auto& p : filesystem::directory_iterator (path))
301 {
302#if USE_FILESYSTEM
303 filesystem::path finalPath (p);
304 if (isFolderSymbolicLink (p))
305 {
306 if (auto res = resolveShellLink (p))
307 {
308 finalPath = *res;
309 if (!filesystem::exists (finalPath))
310 continue;
311 }
312 else
313 continue;
314 }
315 const auto& cpExt = finalPath.extension ();
316 if (cpExt == ext)
317 {
318 filesystem::path vstPath (finalPath);
319 if (checkVST3Package (vstPath))
320 {
321 pathList.push_back (vstPath.generic_string ());
322 continue;
323 }
324 }
325
326 if (filesystem::is_directory (finalPath))
327 {
328 if (recursive)
329 findFilesWithExt (finalPath, ext, pathList, recursive);
330 }
331 else if (cpExt == ext)
332 pathList.push_back (finalPath.generic_string ());
333#else
334 const auto& cp = p.path ();
335 const auto& cpExt = cp.extension ();
336 if (cpExt == ext)
337 {
338 if ((p.status ().type () == filesystem::file_type::directory) ||
340 {
341 filesystem::path finalPath (p);
342 if (checkVST3Package (finalPath))
343 {
344 pathList.push_back (finalPath.generic_u8string ());
345 continue;
346 }
347 findFilesWithExt (cp, ext, pathList, recursive);
348 }
349 else
350 pathList.push_back (cp.generic_u8string ());
351 }
352 else if (recursive)
353 {
354 if (p.status ().type () == filesystem::file_type::directory)
355 {
356 findFilesWithExt (cp, ext, pathList, recursive);
357 }
358 else if (cpExt == ".lnk")
359 {
360 if (auto resolvedLink = resolveShellLink (cp))
361 {
362 if (resolvedLink->extension () == ext)
363 {
364 if (filesystem::is_directory (*resolvedLink) ||
365 isFolderSymbolicLink (*resolvedLink))
366 {
367 filesystem::path finalPath (*resolvedLink);
368 if (checkVST3Package (finalPath))
369 {
370 pathList.push_back (finalPath.generic_u8string ());
371 continue;
372 }
373 findFilesWithExt (*resolvedLink, ext, pathList, recursive);
374 }
375 else
376 pathList.push_back (resolvedLink->generic_u8string ());
377 }
378 else if (filesystem::is_directory (*resolvedLink))
379 {
380 const auto& str = resolvedLink->generic_u8string ();
381 if (cp.generic_u8string ().compare (0, str.size (), str.data (),
382 str.size ()) != 0)
383 findFilesWithExt (*resolvedLink, ext, pathList, recursive);
384 }
385 }
386 }
387 }
388#endif
389 }
390}
#define str(a)
VST3::Optional< filesystem::path > resolveShellLink(const filesystem::path &p)
void findFilesWithExt(const filesystem::path &path, const std::string &ext, Module::PathList &pathList, bool recursive=true)
bool isFolderSymbolicLink(const filesystem::path &p)

References checkVST3Package(), findFilesWithExt(), isFolderSymbolicLink(), resolveShellLink(), and str.

Referenced by findFilesWithExt(), and findModules().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ findModules()

void VST3::Hosting::anonymous_namespace{module_win32.cpp}::findModules ( const filesystem::path &  path,
Module::PathList &  pathList 
)

Definition at line 393 of file module_win32.cpp.

394{
395 if (filesystem::exists (path))
396 findFilesWithExt (path, ".vst3", pathList);
397}

References findFilesWithExt().

Here is the call graph for this function:

◆ getContentsDirectoryFromModuleExecutablePath()

Optional< filesystem::path > VST3::Hosting::anonymous_namespace{module_win32.cpp}::getContentsDirectoryFromModuleExecutablePath ( const std::string &  modulePath)

Definition at line 400 of file module_win32.cpp.

402{
403 filesystem::path path (modulePath);
404
405 path = path.parent_path ();
406 if (path.filename () != architectureString)
407 return {};
408 path = path.parent_path ();
409 if (path.filename () != "Contents")
410 return {};
411
412 return Optional<filesystem::path> {std::move (path)};
413}

References architectureString.

◆ getKnownFolder()

Optional< std::string > VST3::Hosting::anonymous_namespace{module_win32.cpp}::getKnownFolder ( REFKNOWNFOLDERID  folderID)

Definition at line 240 of file module_win32.cpp.

241{
242 PWSTR wideStr {};
243 if (FAILED (SHGetKnownFolderPath (folderID, 0, nullptr, &wideStr)))
244 return {};
245 return ConvertToUTF8(wideStr);
246}
std::string ConvertToUTF8(const T *str)

References ConvertToUTF8().

Here is the call graph for this function:

◆ isFolderSymbolicLink()

bool VST3::Hosting::anonymous_namespace{module_win32.cpp}::isFolderSymbolicLink ( const filesystem::path &  p)

Definition at line 218 of file module_win32.cpp.

219{
220#if USE_FILESYSTEM
221 if (/*filesystem::exists (p) &&*/ filesystem::is_symlink (p))
222 return true;
223#else
224 std::wstring wString = p.generic_wstring ();
225 auto attrib = GetFileAttributesW (reinterpret_cast<LPCWSTR> (wString.c_str ()));
226 if (attrib & FILE_ATTRIBUTE_REPARSE_POINT)
227 {
228 auto hFile = CreateFileW (reinterpret_cast<LPCWSTR> (wString.c_str ()), GENERIC_READ,
229 FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr);
230 if (hFile == INVALID_HANDLE_VALUE)
231 return true;
232 else
233 CloseHandle (hFile);
234 }
235#endif
236 return false;
237}

Referenced by findFilesWithExt().

Here is the caller graph for this function:

◆ resolveShellLink()

VST3::Optional< filesystem::path > VST3::Hosting::anonymous_namespace{module_win32.cpp}::resolveShellLink ( const filesystem::path &  p)

Definition at line 249 of file module_win32.cpp.

250{
251#if USE_FILESYSTEM
252 return {filesystem::read_symlink (p)};
253#else
254#if USE_OLE
255 Ole::instance ();
256
257 IShellLink* shellLink = nullptr;
258 if (!SUCCEEDED (CoCreateInstance (CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER,
259 IID_IShellLink, reinterpret_cast<LPVOID*> (&shellLink))))
260 return {};
261
262 IPersistFile* persistFile = nullptr;
263 if (!SUCCEEDED (
264 shellLink->QueryInterface (IID_IPersistFile, reinterpret_cast<void**> (&persistFile))))
265 return {};
266
267 if (!SUCCEEDED (persistFile->Load (p.wstring ().data (), STGM_READ)))
268 return {};
269
270 if (!SUCCEEDED (shellLink->Resolve (nullptr, MAKELONG (SLR_NO_UI, 500))))
271 return {};
272
273 WCHAR resolvedPath[MAX_PATH];
274 if (!SUCCEEDED (shellLink->GetPath (resolvedPath, MAX_PATH, nullptr, SLGP_SHORTPATH)))
275 return {};
276
277 std::wstring longPath;
278 longPath.resize (MAX_PATH);
279 auto numChars =
280 GetLongPathNameW (resolvedPath, const_cast<wchar_t*> (longPath.data ()), MAX_PATH);
281 if (!numChars)
282 return {};
283 longPath.resize (numChars);
284
285 persistFile->Release ();
286 shellLink->Release ();
287
288 return {filesystem::path (longPath)};
289#else
290 // TODO for ARM
291 return {};
292#endif
293#endif
294}

Referenced by findFilesWithExt().

Here is the caller graph for this function:

Variable Documentation

◆ architectureString

constexpr auto VST3::Hosting::anonymous_namespace{module_win32.cpp}::architectureString = "x86-win"
constexpr