diff --git a/common/project/project_archiver.cpp b/common/project/project_archiver.cpp index 76f747c2e5..b520c1e644 100644 --- a/common/project/project_archiver.cpp +++ b/common/project/project_archiver.cpp @@ -32,6 +32,7 @@ #include <wildcards_and_files_ext.h> #include <wxstream_helper.h> #include <wx/log.h> +#include <kiplatform/io.h> #include <set> @@ -191,7 +192,10 @@ bool PROJECT_ARCHIVER::Archive( const wxString& aSrcDir, const wxString& aDestFi wxString msg; wxString oldCwd = wxGetCwd(); - wxSetWorkingDirectory( aSrcDir ); + wxFileName sourceDir( aSrcDir ); + KIPLATFORM::IO::LongPathAdjustment( sourceDir ); + + wxSetWorkingDirectory( sourceDir.GetFullPath() ); wxFFileOutputStream ostream( aDestFile ); @@ -210,12 +214,12 @@ bool PROJECT_ARCHIVER::Archive( const wxString& aSrcDir, const wxString& aDestFi wxArrayString files; for( unsigned ii = 0; ii < arrayDim( extensionList ); ii++ ) - wxDir::GetAllFiles( aSrcDir, &files, extensionList[ii] ); + wxDir::GetAllFiles( sourceDir.GetFullPath(), &files, extensionList[ii] ); if( aIncludeExtraFiles ) { for( unsigned ii = 0; ii < arrayDim( extraExtensionList ); ii++ ) - wxDir::GetAllFiles( aSrcDir, &files, extraExtensionList[ii] ); + wxDir::GetAllFiles( sourceDir.GetFullPath(), &files, extraExtensionList[ii] ); } for( unsigned ii = 0; ii < files.GetCount(); ++ii ) @@ -225,6 +229,7 @@ bool PROJECT_ARCHIVER::Archive( const wxString& aSrcDir, const wxString& aDestFi wxFileName package( files[ ii ] ); package.MakeRelativeTo( aSrcDir ); package.SetExt( wxS( "pkg" ) ); + KIPLATFORM::IO::LongPathAdjustment( package ); if( package.Exists() ) files.push_back( package.GetFullName() ); @@ -250,11 +255,13 @@ bool PROJECT_ARCHIVER::Archive( const wxString& aSrcDir, const wxString& aDestFi wxFileSystem fsfile; wxFileName curr_fn( files[ii] ); - curr_fn.MakeRelativeTo( aSrcDir ); + KIPLATFORM::IO::LongPathAdjustment( curr_fn ); + curr_fn.MakeRelativeTo( sourceDir.GetFullPath() ); + currFilename = curr_fn.GetFullPath(); // Read input file and add it to the zip file: - wxFSFile* infile = fsfile.OpenFile( wxFileSystem::FileNameToURL( curr_fn ) ); + wxFSFile* infile = fsfile.OpenFile( currFilename ); if( infile ) { diff --git a/common/settings/settings_manager.cpp b/common/settings/settings_manager.cpp index 0e8e9d0f9f..b1383260b5 100644 --- a/common/settings/settings_manager.cpp +++ b/common/settings/settings_manager.cpp @@ -32,6 +32,7 @@ #include <dialogs/dialog_migrate_settings.h> #include <gestfich.h> #include <kiplatform/environment.h> +#include <kiplatform/io.h> #include <kiway.h> #include <lockfile.h> #include <macros.h> @@ -1236,6 +1237,10 @@ bool SETTINGS_MANAGER::BackupProject( REPORTER& aReporter, wxFileName& aTarget ) aTarget.SetExt( FILEEXT::ArchiveFileExtension ); } + KIPLATFORM::IO::LongPathAdjustment( aTarget ); + + wxString test = aTarget.GetPath(); + if( !aTarget.DirExists() && !wxMkdir( aTarget.GetPath() ) ) { wxLogTrace( traceSettings, wxT( "Could not create project backup path %s" ), diff --git a/libs/kiplatform/os/windows/io.cpp b/libs/kiplatform/os/windows/io.cpp index d6039b50cf..b0ec4527f6 100644 --- a/libs/kiplatform/os/windows/io.cpp +++ b/libs/kiplatform/os/windows/io.cpp @@ -137,10 +137,22 @@ void KIPLATFORM::IO::LongPathAdjustment( wxFileName& aFilename ) aFilename.SetVolume( "\\\\?\\" + aFilename.GetVolume() + ":" ); else if( aFilename.GetVolume().Length() > 1 && aFilename.GetVolume().StartsWith( wxT( "\\\\" ) ) - && !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) ); + aFilename.SetVolume( "\\\\?\\UNC" + aFilename.GetVolume().Mid( 1 ) ); + else if( aFilename.GetVolume().StartsWith( wxT( "\\\\?" ) ) + && aFilename.GetDirs().size() >= 2 + && aFilename.GetDirs()[0] == "UNC" ) + { + // wxWidgets can parse \\?\UNC\<server> into a mess + // UNC gets stored into a directory + // volume gets reduced to just \\? + // so we need to repair it + aFilename.SetVolume( "\\\\?\\UNC\\" + aFilename.GetDirs()[1] ); + aFilename.RemoveDir( 0 ); + aFilename.RemoveDir( 0 ); + } } \ No newline at end of file