Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HiddenFilePathFilter: Fix hidden sequences #5831

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
1.3.16.x (relative to 1.3.16.1)
========

Fixes
-----

- File Browser : Windows only : Fixed bug in `HiddenFilePathFilter` that caused sequences to be treated as though they are hidden files (#5810).


1.3.16.1 (relative to 1.3.16.0)
Expand Down
51 changes: 51 additions & 0 deletions python/GafferTest/HiddenFilePathFilterTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import subprocess
import unittest

import IECore

import Gaffer
import GafferTest

Expand Down Expand Up @@ -72,6 +74,55 @@ def test( self ) :

self.assertEqual( p.children(), [ visibleFile ] )

def testSequence( self ) :

hiddenSequence = IECore.FileSequence( ( self.temporaryDirectory() / ".hidden.#.txt 1-3" ).as_posix() )
visibleSequence = IECore.FileSequence( ( self.temporaryDirectory() / "visible.#.txt 1-3" ).as_posix() )

for frame in range( 3 ) :
hiddenFile = Gaffer.FileSystemPath( hiddenSequence.fileNameForFrame( frame ) )
with open( hiddenFile.nativeString(), "w", encoding = "utf-8" ) as f :
f.write( "Hidden sequence")
if os.name == "nt" :
subprocess.check_call( [ "attrib", "+H", hiddenFile.nativeString() ] )

visibleFile = Gaffer.FileSystemPath( visibleSequence.fileNameForFrame( frame ) )
with open( visibleFile.nativeString(), "w", encoding = "utf-8" ) as f :
f.write( "Visible sequence" )

p = Gaffer.FileSystemPath( pathlib.Path( hiddenSequence.fileName ).parent, None, True )

self.assertEqual(
sorted( [ str( i ) for i in p.children() ] ),
sorted(
[ hiddenSequence.fileNameForFrame( i ) for i in range( 3 ) ] +
[ visibleSequence.fileNameForFrame( i ) for i in range( 3 ) ] +
[ hiddenSequence.fileName, visibleSequence.fileName ]
)
)

h = Gaffer.HiddenFilePathFilter()
p.setFilter( h )

self.assertEqual(
sorted( [ str( i ) for i in p.children() ] ),
sorted(
[ hiddenSequence.fileNameForFrame( i ) for i in range( 3 ) ] +
[ hiddenSequence.fileName ]
)
)

h.setInverted( True )

self.assertEqual(
sorted( [ str( i ) for i in p.children() ] ),
sorted(
[ visibleSequence.fileNameForFrame( i ) for i in range( 3 ) ] +
[ visibleSequence.fileName ]
)
)



if __name__ == "__main__":
unittest.main()
23 changes: 20 additions & 3 deletions src/Gaffer/HiddenFilePathFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@

#include "Gaffer/Path.h"

#include "IECore/FileSequenceFunctions.h"

#ifdef _MSC_VER

#include <windows.h>

#endif

using namespace Gaffer;
using namespace IECore;

IE_CORE_DEFINERUNTIMETYPED( HiddenFilePathFilter );

Expand Down Expand Up @@ -105,10 +108,24 @@ bool HiddenFilePathFilter::remove( PathPtr path ) const
}
return invert( true );
#else
DWORD fileAttributes = GetFileAttributes( path->string().c_str() );
if( fileAttributes & FILE_ATTRIBUTE_HIDDEN )
if( const auto filePath = runTimeCast<FileSystemPath>( path.get() ) )
{
return invert( false );
std::string file;
if( const auto sequence = filePath->fileSequence() )
{
std::vector<FrameList::Frame> frames;
sequence->getFrameList()->asList( frames );
file = sequence->fileNameForFrame( frames[0] );
}
else
{
file = path->string();
}
DWORD fileAttributes = GetFileAttributes( file.c_str() );
if( fileAttributes & FILE_ATTRIBUTE_HIDDEN )
{
return invert( false );
}
}
return invert( true );
#endif
Expand Down
Loading