String PixInsightX11Installer::Unquoted( const String& s ) { String r = s; if ( s.BeginsWith( '\"' ) ) if ( s.EndsWith( '\"' ) ) { r.DeleteRight( r.UpperBound() ); r.DeleteLeft( 1 ); } if ( s.BeginsWith( '\'' ) ) if ( s.EndsWith( '\'' ) ) { r.DeleteRight( r.UpperBound() ); r.DeleteLeft( 1 ); } return r; }
void PixInsightX11Installer::CopyFiles( const String& targetDir, const String& sourceDir ) { if ( !targetDir.BeginsWith( '/' ) ) throw Error( "CopyFiles(): Relative target directory." ); if ( !sourceDir.BeginsWith( '/' ) ) throw Error( "CopyFiles(): Relative source directory." ); if ( targetDir.EndsWith( '/' ) || sourceDir.EndsWith( '/' ) ) throw Error( "CopyFiles(): Incorrectly terminated directories." ); if ( !File::DirectoryExists( targetDir ) ) throw Error( "CopyFiles(): Nonexistent target directory." ); if ( !File::DirectoryExists( sourceDir ) ) throw Error( "CopyFiles(): Nonexistent source directory." ); StringList sourceItems = SearchDirectory( sourceDir ); size_type sourceDirLen = sourceDir.Length(); for ( StringList::const_iterator i = sourceItems.Begin(); i != sourceItems.End(); ++i ) { String relSourcePath = *i; relSourcePath.DeleteLeft( sourceDirLen ); String targetPath = targetDir + relSourcePath; if ( targetPath.EndsWith( '/' ) ) { /* * Create a subdirectory */ targetPath.Delete( targetPath.UpperBound() ); if ( !File::DirectoryExists( targetPath ) ) { File::CreateDirectory( targetPath ); String sourcePath = *i; sourcePath.Delete( sourcePath.UpperBound() ); File::CopyTimesAndPermissions( targetPath, sourcePath ); } } else { /* * Copy a file */ /* * ### N.B. We don't have to create subdirectories here becase they * have been reported by SearchDirectory(), and we are creating them * before copying files. SearchDirectory() promises that all * subdirectories are reported before their contained files. */ /* String targetSubdir = File::ExtractDirectory( targetPath ); if ( targetSubdir.EndsWith( '/' ) ) targetSubdir.Delete( targetSubdir.UpperBound() ); if ( !File::DirectoryExists( targetSubdir ) ) File::CreateDirectory( targetSubdir ); */ File::CopyFile( targetPath, *i ); } } }