diff --git a/libs/kiplatform/include/kiplatform/io.h b/libs/kiplatform/include/kiplatform/io.h index b7a38e8671..ad23eea635 100644 --- a/libs/kiplatform/include/kiplatform/io.h +++ b/libs/kiplatform/include/kiplatform/io.h @@ -23,6 +23,7 @@ #include <stdio.h> class wxString; +class wxFileName; namespace KIPLATFORM { @@ -50,6 +51,12 @@ namespace IO * @return true if the file attribut is set. */ bool IsFileHidden( const wxString& aFileName ); + + /** + * Adjusts a filename to be a long path compatible. + * This is a no-op on non-Windows platforms. + */ + void LongPathAdjustment( wxFileName& aFilename ); } // namespace IO } // namespace KIPLATFORM diff --git a/libs/kiplatform/os/apple/io.mm b/libs/kiplatform/os/apple/io.mm index 6e62a37f67..04411d4ad4 100644 --- a/libs/kiplatform/os/apple/io.mm +++ b/libs/kiplatform/os/apple/io.mm @@ -49,16 +49,16 @@ bool KIPLATFORM::IO::DuplicatePermissions(const wxString& sourceFilePath, const NSNumber *permissions = sourceAttributes[NSFilePosixPermissions]; - if (permissions == nil) + if (permissions == nil) { return false; } - if ([fileManager setAttributes:@{NSFilePosixPermissions: permissions} ofItemAtPath:destPath error:&error]) + if ([fileManager setAttributes:@{NSFilePosixPermissions: permissions} ofItemAtPath:destPath error:&error]) { return true; - } - else + } + else { NSLog(@"Error assigning permissions: %@", error); return false; @@ -71,3 +71,9 @@ bool KIPLATFORM::IO::IsFileHidden( const wxString& aFileName ) return fn.GetName().StartsWith( wxT( "." ) ); } + + +void KIPLATFORM::IO::LongPathAdjustment( wxFileName& aFilename ) +{ + // no-op +} \ No newline at end of file diff --git a/libs/kiplatform/os/unix/io.cpp b/libs/kiplatform/os/unix/io.cpp index 26d0d53f99..0f1c9f1c3d 100644 --- a/libs/kiplatform/os/unix/io.cpp +++ b/libs/kiplatform/os/unix/io.cpp @@ -66,3 +66,9 @@ bool KIPLATFORM::IO::IsFileHidden( const wxString& aFileName ) return fn.GetName().StartsWith( wxT( "." ) ); } + + +void KIPLATFORM::IO::LongPathAdjustment( wxFileName& aFilename ) +{ + // no-op +} \ No newline at end of file diff --git a/libs/kiplatform/os/windows/io.cpp b/libs/kiplatform/os/windows/io.cpp index 3160218f0a..d6039b50cf 100644 --- a/libs/kiplatform/os/windows/io.cpp +++ b/libs/kiplatform/os/windows/io.cpp @@ -21,7 +21,7 @@ #include <wx/string.h> #include <wx/wxcrt.h> - +#include <wx/filename.h> #include <windows.h> // Define USE_MSYS2_FALlBACK if the code for _MSC_VER does not compile on msys2 @@ -123,4 +123,24 @@ bool KIPLATFORM::IO::IsFileHidden( const wxString& aFileName ) result = true; return result; +} + + +void KIPLATFORM::IO::LongPathAdjustment( wxFileName& aFilename ) +{ + // dont shortcut this for shorter lengths as there are uses like directory + // paths that exceed the path length when you start traversing their subdirectories + // so we want to start with the long path prefix all the time + + if( aFilename.GetVolume().Length() == 1 ) + // assume single letter == drive volume + aFilename.SetVolume( "\\\\?\\" + aFilename.GetVolume() + ":" ); + else if( aFilename.GetVolume().Length() > 1 + && aFilename.GetVolume().StartsWith( wxT( "\\\\" ) ) + && !aFilename.GetVolume().StartsWith( wxT( "\\\\?\\" ) ) ) + // unc path aka network share, wx returns with \\ already + // so skip the first slash and combine with the prefix + // which in the case of UNCs is actually \\?\UNC\<server>\<share> + // where UNC is literally the text UNC + aFilename.SetVolume( "\\\\?\\UNC" + aFilename.GetVolume().Mid(1) ); } \ No newline at end of file