Feature request: DirectoryContentsList - follow shortcut/alias links

Jules, please, would it be possible to update the DirectoryContentsList  code so it will follow up on shortcut/alias links to folders? I think the problem is the directory iterator and how DirectoryContentsList uses the Relative path too, if I understand right.

Just asking, hope it doesn't hurt to... ;-)

Thanks!

Yes, I guess so. On unix it'll already do that, I guess it's just Windows where it'd need to explicitly follow a link file. I'm a bit busy though - could you suggest a change?

Ok, thanks Jules, I will check the code today and see what needs changing and send you a change list, (what lines should be changed to what) and the new files that I updated so you can check with your files.

BTW: I tried creating an alias on MAC, and it did not follow, but I will try again, just in case...

Unis link are not the same as Mac Alias.

 

You need dedicated code to do this as opposed to an Unix link (ln -s)

Got it, thanks, I already found where changes must be made: NativeIterator

So I'm checking those out and will report later on.

Edit: Oops, sorry about that, removing the bad code. ;-)

Woah there, no - that's not the place to do it! The DirectoryIterator is a low-level file class, you definitely don't want to mess with that. The only place to change would be the FileListTreeItem class.

Jules, I'm terrible sorry, you are right, is just how my crazy brain works... ;-)

Ok, here's the fix, I hope I did it right this time...

juce_FileTreeComponent.cpp

class FileListTreeItem   : public TreeViewItem,
                           private TimeSliceClient,
                           private AsyncUpdater,
                           private ChangeListener
{
public:
    FileListTreeItem (FileTreeComponent& treeComp,
                      DirectoryContentsList* const parentContents,
                      const int indexInContents,
                      const File& f,
                      TimeSliceThread& t)
          : file(f.getLinkedTarget()), // Changed by WilliamK - before was just: file(f),
          owner (treeComp),
          parentContentsList (parentContents),
          indexInContentsList (indexInContents),
          subContentsList (nullptr, false),
          thread (t)
    {
        DirectoryContentsList::FileInfo fileInfo;

        if (parentContents != nullptr
             && parentContents->getFileInfo (indexInContents, fileInfo))
        {
            fileSize = File::descriptionOfSizeInBytes (fileInfo.fileSize);
            modTime = fileInfo.modificationTime.formatted ("%d %b '%y %H:%M");
            isDirectory = fileInfo.isDirectory;
        }
        else
        {
            isDirectory = true;
        }

        if (f.isLink() && f.getLinkedTarget().isDirectory()) isDirectory = true; // Added by WilliamK
    }

(...)

Another thing, the File() createlink is only for Windows, do you have plans on a MAC code too? Otherwise I will google this info...

Didn't have any plans to add that, but on other OSes you can just call the posix command to do it.

Surely something more like this?


    FileListTreeItem (FileTreeComponent& treeComp,
                      DirectoryContentsList* const parentContents,
                      const int indexInContents,
                      const File& f,
                      TimeSliceThread& t)
        : file (f.getLinkedTarget()),
          owner (treeComp),
          parentContentsList (parentContents),
          indexInContentsList (indexInContents),
          subContentsList (nullptr, false),
          thread (t)
    {
        DirectoryContentsList::FileInfo fileInfo;

        if (parentContents != nullptr
              && parentContents->getFileInfo (indexInContents, fileInfo))
        {
            if (file != f) // i.e. if it's a symbolic link
            {
                fileInfo.fileSize = file.getSize();
                fileInfo.modificationTime = file.getLastModificationTime();
                fileInfo.isDirectory = file.isDirectory();
            }

            fileSize = File::descriptionOfSizeInBytes (fileInfo.fileSize);
            modTime = fileInfo.modificationTime.formatted ("%d %b '%y %H:%M");
            isDirectory = fileInfo.isDirectory;
        }
        else
        {
            isDirectory = true;
        }
    }