Feature request: DirectoryContentsList - follow shortcut/alias links


#1

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!


#2

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?


#3

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.


#4

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


#5

Unis link are not the same as Mac Alias.

 

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


#6

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

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


#7

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


#8

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.


#9

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
    }

(...)

#10

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


#11

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


#12

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;
        }
    }