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 193 of file module_win32.cpp.

194{
195 auto filename = p.filename ();
196 p /= "Contents";
198 p /= filename;
199 auto hFile = CreateFileW (reinterpret_cast<LPCWSTR> (p.c_str ()), GENERIC_READ, FILE_SHARE_READ,
200 nullptr, OPEN_EXISTING, 0, nullptr);
201 if (hFile != INVALID_HANDLE_VALUE)
202 {
203 CloseHandle (hFile);
204 return true;
205 }
206 return false;
207}

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 289 of file module_win32.cpp.

291{
292 for (auto& p : filesystem::directory_iterator (path))
293 {
294#if USE_FILESYSTEM
295 filesystem::path finalPath (p);
296 if (isFolderSymbolicLink (p))
297 {
298 if (auto res = resolveShellLink (p))
299 {
300 finalPath = *res;
301 if (!filesystem::exists (finalPath))
302 continue;
303 }
304 else
305 continue;
306 }
307 const auto& cpExt = finalPath.extension ();
308 if (cpExt == ext)
309 {
310 filesystem::path vstPath (finalPath);
311 if (checkVST3Package (vstPath))
312 {
313 pathList.push_back (vstPath.generic_string ());
314 continue;
315 }
316 }
317
318 if (filesystem::is_directory (finalPath))
319 {
320 if (recursive)
321 findFilesWithExt (finalPath, ext, pathList, recursive);
322 }
323 else if (cpExt == ext)
324 pathList.push_back (finalPath.generic_string ());
325#else
326 const auto& cp = p.path ();
327 const auto& cpExt = cp.extension ();
328 if (cpExt == ext)
329 {
330 if ((p.status ().type () == filesystem::file_type::directory) ||
332 {
333 filesystem::path finalPath (p);
334 if (checkVST3Package (finalPath))
335 {
336 pathList.push_back (finalPath.generic_u8string ());
337 continue;
338 }
339 findFilesWithExt (cp, ext, pathList, recursive);
340 }
341 else
342 pathList.push_back (cp.generic_u8string ());
343 }
344 else if (recursive)
345 {
346 if (p.status ().type () == filesystem::file_type::directory)
347 {
348 findFilesWithExt (cp, ext, pathList, recursive);
349 }
350 else if (cpExt == ".lnk")
351 {
352 if (auto resolvedLink = resolveShellLink (cp))
353 {
354 if (resolvedLink->extension () == ext)
355 {
356 if (filesystem::is_directory (*resolvedLink) ||
357 isFolderSymbolicLink (*resolvedLink))
358 {
359 filesystem::path finalPath (*resolvedLink);
360 if (checkVST3Package (finalPath))
361 {
362 pathList.push_back (finalPath.generic_u8string ());
363 continue;
364 }
365 findFilesWithExt (*resolvedLink, ext, pathList, recursive);
366 }
367 else
368 pathList.push_back (resolvedLink->generic_u8string ());
369 }
370 else if (filesystem::is_directory (*resolvedLink))
371 {
372 const auto& str = resolvedLink->generic_u8string ();
373 if (cp.generic_u8string ().compare (0, str.size (), str.data (),
374 str.size ()) != 0)
375 findFilesWithExt (*resolvedLink, ext, pathList, recursive);
376 }
377 }
378 }
379 }
380#endif
381 }
382}
#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 385 of file module_win32.cpp.

386{
387 if (filesystem::exists (path))
388 findFilesWithExt (path, ".vst3", pathList);
389}

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 392 of file module_win32.cpp.

394{
395 filesystem::path path (modulePath);
396
397 path = path.parent_path ();
398 if (path.filename () != architectureString)
399 return {};
400 path = path.parent_path ();
401 if (path.filename () != "Contents")
402 return {};
403
404 return Optional<filesystem::path> {std::move (path)};
405}

References architectureString.

◆ getKnownFolder()

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

Definition at line 232 of file module_win32.cpp.

233{
234 PWSTR wideStr {};
235 if (FAILED (SHGetKnownFolderPath (folderID, 0, nullptr, &wideStr)))
236 return {};
237 return StringConvert::convert (wideStr);
238}

◆ isFolderSymbolicLink()

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

Definition at line 210 of file module_win32.cpp.

211{
212#if USE_FILESYSTEM
213 if (/*filesystem::exists (p) &&*/ filesystem::is_symlink (p))
214 return true;
215#else
216 std::wstring wString = p.generic_wstring ();
217 auto attrib = GetFileAttributesW (reinterpret_cast<LPCWSTR> (wString.c_str ()));
218 if (attrib & FILE_ATTRIBUTE_REPARSE_POINT)
219 {
220 auto hFile = CreateFileW (reinterpret_cast<LPCWSTR> (wString.c_str ()), GENERIC_READ,
221 FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr);
222 if (hFile == INVALID_HANDLE_VALUE)
223 return true;
224 else
225 CloseHandle (hFile);
226 }
227#endif
228 return false;
229}

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 241 of file module_win32.cpp.

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

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