void rab::WriteRegistryFiles( Options const& options, Config const& config, FolderInfo::FileInfos_t const& fileInfos, dung::Action::Enum action, Path_t const& relativePath, OutputContext& output ) { for( FolderInfo::FileInfos_t::const_iterator i = fileInfos.begin(); i != fileInfos.end(); ++i ) { FileInfo const& fileInfo = **i; dung::Action::Enum fileAction = fileInfo.isDifferent ? dung::Action::APPLY_DIFF : action; if( fileAction == dung::Action::NEW && config.newFileLimit > 0 && fileInfo.newSize >= config.newFileLimit ) fileAction = dung::Action::NEW_BUT_NOT_INCLUDED; if( fileAction == dung::Action::NEW && MatchName( config.newOverrideFiles_regex, fileInfo.name ) ) fileAction = dung::Action::OVERRIDE; if( fileAction == dung::Action::DELETE && MatchName( config.oldPreserveRemoved_regex, fileInfo.name ) ) fileAction = dung::Action::NONE; if( fileAction == dung::Action::APPLY_DIFF && MatchName( config.oldSkipChanged_regex, fileInfo.name ) ) fileAction = dung::Action::NONE; output.stream << _T("file") << endl; output.stream << _T("{") << endl; output.stream << _T("\t") << _T("action=") << dung::ActionToString(fileAction) << endl; if( fileAction != dung::Action::DELETE && fileAction != dung::Action::NONE ) { output.stream << _T("\t") << _T("new_path=") << quote << GenericString( relativePath / fileInfo.name ) << quote << endl; output.stream << _T("\t") << _T("new_size=") << fileInfo.newSize << endl; output.stream << _T("\t") << _T("new_sha1=") << quote << dung::SHA1_TO_TSTRING(fileInfo.newSha1) << quote << endl; } if( fileAction != dung::Action::NEW && fileAction != dung::Action::OVERRIDE && fileAction != dung::Action::NEW_BUT_NOT_INCLUDED ) { output.stream << _T("\t") << _T("old_path=") << quote << GenericString( relativePath / fileInfo.name ) << quote << endl; output.stream << _T("\t") << _T("old_size=") << fileInfo.oldSize << endl; output.stream << _T("\t") << _T("old_sha1=") << quote << dung::SHA1_TO_TSTRING(fileInfo.oldSha1) << quote << endl; } if( fileAction == dung::Action::APPLY_DIFF ) { output.stream << _T("\t") << _T("diff_path=") << quote << GenericString( relativePath / DiffFileName(fileInfo.name, config) ) << quote << endl; output.stream << _T("\t") << _T("diff_method=") << fileInfo.diffMethod << endl; } output.stream << _T("}") << endl; } }
const Path Instance::GetLongPath(wcstring const shortPath) { Path longPath; longPath.Reserve( 255 ); uint length = ::GetLongPathName( shortPath, longPath.Ptr(), longPath.Capacity() + 1 ); if (length > longPath.Capacity() + 1) { longPath.Reserve( length - 1 ); length = ::GetLongPathName( shortPath, longPath.Ptr(), longPath.Capacity() + 1 ); } if (!length) return shortPath; const wchar_t slashed = GenericString(shortPath).Back(); longPath.ShrinkTo( length ); longPath.MakePretty( slashed == '\\' || slashed == '/' ); return longPath; }
bool rab::CreateDiffFile( Options const& options, DiffEncoders const &diffEncoders, FileInfo& fileInfo, Path_t const& fullNew, Path_t const& fullOld, Path_t const& relativeTemp, dung::MemoryBlock const& newFile, dung::MemoryBlock const& oldFile, PackageOutput_t &package, LogOutput_t& out ) { Path_t fullTemp = relativeTemp.filename(); if( options.produceTemp ) { fullTemp = options.pathToTemp / relativeTemp; fs::create_directories( fullTemp.parent_path() ); } dung::DiffEncoder_i* pEncoder = diffEncoders.FindEncoder( fileInfo.name, fileInfo.diffMethod ); if( pEncoder != NULL ) { out << "Encoding " << fileInfo.diffMethod << " diff file " << GenericString( relativeTemp ) << std::endl; dung::MemoryBlock deltaFile; if( !pEncoder->EncodeDiffMemoryBlock( newFile.pBlock, newFile.size, oldFile.pBlock, oldFile.size, deltaFile.pBlock, deltaFile.size ) ) { _tstring errorMessage; pEncoder->GetErrorMessage( errorMessage ); out << "Encoding error: " << errorMessage << std::endl; return false; } if( options.produceTemp ) { if( !WriteWholeFile( fullTemp.wstring(), deltaFile ) ) { out << "Can't write file " << GenericString( fullTemp ) << std::endl; return false; } } if( !package.WriteFile( GenericString( relativeTemp ), deltaFile.pBlock, deltaFile.size ) ) { out << "Can't write file " << GenericString( relativeTemp ) << " to package. Size=" << deltaFile.size << std::endl; return false; } } else { dung::DiffEncoderExternal_i* pExternalEncoder = diffEncoders.FindExternalEncoder( fileInfo.name, fileInfo.diffMethod ); if( pExternalEncoder != NULL ) { out << "Encoding " << fileInfo.diffMethod << " diff file " << GenericString( relativeTemp ) << std::endl; if( !pExternalEncoder->EncodeDiffFile( GenericString(fullNew).c_str(), GenericString(fullOld).c_str(), GenericString(fullTemp).c_str() ) ) { _tstring errorMessage; pExternalEncoder->GetErrorMessage( errorMessage ); out << "Encoding error: " << errorMessage << std::endl; return false; } dung::MemoryBlock deltaFile; if( !ReadWholeFile( fullTemp.generic_string(), deltaFile ) ) { out << "Can't read file " << GenericString(fullTemp) << std::endl; return false; } if( !options.produceTemp ) fs::remove( fullTemp ); if( !package.WriteFile( GenericString(relativeTemp), deltaFile.pBlock, deltaFile.size ) ) { out << "Can't write file " << GenericString(relativeTemp) << " to package. Size=" << deltaFile.size << std::endl; return false; } } else { out << "Can't file encoder for file " << fileInfo.name << std::endl; return false; } } return true; }
Screen::~Screen() { if (callback) callback( GenericString(Ptr(),Length()), time ); }