Alias ans Shortcut resolution

Hi Jules,

I took a look at the juce::File API and it do not seem to be a way
to resolve a Windows shortcut or a Mac alias. Am I missing something ?

If you plan to add support for this, I have some code for Windows and Mac, if you need.

Thanks,

True, that is missing. And sure, if you’ve got code for it, I’d be interested in seeing what’s involved, thanks.

may not compile, as I’ve modify my old code to fit juce class instead of our own.

The OSX version would look like this

bool File::ResolveLink()
{
  bool res = false;
  FSRef ref;
  OSStatus status = FSPathMakeRef((const UInt8*)getFullPathName().toUTF8(), &ref, NULL);
  if (status == noErr)
  {
    Boolean targetIsAFolder;
    Boolean wasAliased;

    OSErr err = ::FSResolveAliasFileWithMountFlags(&ref,  true, &targetIsAFolder, &wasAliased, 0);
    if ( (err == noErr) && (wasAliased) )
    {
       char buffer[1024];
       FSRefMakePath(&ref, (UInt8*)buffer, 1024);
       *this = buffer;
       res = true;
    }
  }
  return res;
}

and the windows version

bool File::ResolveLink()
{
  char tmpPath[MAX_PATH];
  if (access(getFullPathName().toUTF8(), 0) == -1) 
  {
    strcpy(tmpPath, getFullPathName().toUTF8());
    strcat(tmpPath,".lnk");
  }
  else 
  {
    if (getFileExtension()  != ".lnk")
    {
      return false;
    }
    strcpy(tmpPath, getFullPathName().toUTF8());
  }

  HRESULT hres;
  IShellLink *pShLink = NULL;

  wchar_t wsz[MAX_PATH];
  char resolvedPath[MAX_PATH];

  CoInitialize(NULL);

  bool res = false;

  hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *)&pShLink);

  if (SUCCEEDED(hres))
  {
    IPersistFile *ppf;

    // The IShellLink Interface supports the IPersistFile
    // interface. Get an interface pointer to it.
    hres = pShLink->QueryInterface(IID_IPersistFile, (LPVOID *)&ppf);
    if (SUCCEEDED(hres))
    {
      // Convert the given link name string to a wide character string.
      MultiByteToWideChar(CP_ACP, 0, tmpPath, -1, wsz, MAX_PATH);

      // Load the file.
      hres = ppf->Load(wsz, STGM_READ);
      if (SUCCEEDED(hres))
      {
        // Resolve the link by calling the Resolve() interface function.
        // This enables us to find the file the link points to even if
        // it has been moved or renamed.
        hres = pShLink->Resolve(NULL, SLR_ANY_MATCH | SLR_NO_UI);

        if (SUCCEEDED(hres))
        {
          WIN32_FIND_DATA winFindData;
          // Get the path of the file the link points to.
          hres = pShLink->GetPath(resolvedPath, MAX_PATH, &winFindData, SLGP_UNCPRIORITY);
          if (SUCCEEDED(hres))
          {
            *this = resolvedPath;
            res = true;
          }
        }
      }
      ppf->Release();
    }
    pShLink->Release();
  }
  return res;
}

HTH

Cool, thanks. I’ll take a look as soon as I can.