diff --git a/Main/src/HFE.cpp b/Main/src/HFE.cpp index 98160927..f9bd10e4 100644 --- a/Main/src/HFE.cpp +++ b/Main/src/HFE.cpp @@ -295,10 +295,9 @@ formatError: ::SetLastError(ERROR_BAD_FORMAT); rit.FlushSectorBuffers(); PBYTE p=result; CTrackReader tr=rit; - for( tr.RewindToIndexAndResetProfile(0); tr; ){ + for( tr.RewindToIndexAndResetProfile(0); tr && p-result CContentLayout; CContentLayout contentLayout; // key = position in file, value>0 = Track length, value<0 = unused gap size if (savingToCurrentFile){ @@ -338,9 +338,16 @@ formatError: ::SetLastError(ERROR_BAD_FORMAT); if (cylInfos[cyl].IsValid()) // Cylinder actually existed in the file before? if (!AnyTrackModified(cyl)) // not Modified or not even read Cylinder? contentLayout.insert( - std::make_pair( cylInfos[cyl].nBlocksOffset*sizeof(TBlock), (LONG)cylInfos[cyl].nBytesLength ) + std::make_pair( cylInfos[cyl].nBlocksOffset*sizeof(TBlock), Utils::RoundUpToMuls(cylInfos[cyl].nBytesLength,sizeof(TBlock)) ) ); // . adding gaps (value<0) + if (contentLayout.size()>0){ // some Cylinders left untouched in the Image? + const auto itLastCyl=contentLayout.crbegin(); + const auto lastCylEnd=itLastCyl->first+itLastCyl->second; + contentLayout.insert( + std::make_pair( lastCylEnd, lastCylEnd-fTarget.GetLength() ) + ); + } CContentLayout gaps; DWORD prevTrackEnd=sizeof(UHeader)+Utils::RoundUpToMuls(header.nCylinders*sizeof(TCylinderInfo), sizeof(TBlock) ); for each( const auto &kvp in contentLayout ){ @@ -349,16 +356,13 @@ formatError: ::SetLastError(ERROR_BAD_FORMAT); prevTrackEnd=kvp.first+kvp.second; } contentLayout.insert( gaps.cbegin(), gaps.cend() ); - } + }else + fTarget.SetLength( nRequiredBytesHeaderAndCylInfos ); // - saving - CFile &fTarget= savingToCurrentFile ? f : fTmp; - if (!savingToCurrentFile) - fTarget.SetLength( nRequiredBytesHeaderAndCylInfos ); auto sub=ap.CreateSubactionProgress( ARRAYSIZE(cylInfos), ARRAYSIZE(cylInfos) ); - CTrackBytes invalidTrackBytes(1); - invalidTrackBytes.Invalidate(); + CTrackBytes invalidTrackBytes(1); + invalidTrackBytes.Invalidate(); for( TCylinder cyl=0; cyl( fPosition, sizeof(TBlock) ); - cylInfos[cyl].nBytesLength=nBytesCylinder; + cylInfos[cyl].nBytesLength=nBytesLongerTrack*2; if (fTarget.Seek( fPosition, CFile::begin )