2627 |
2627 |
2628 |fileName changeInStream outStream chunk chunk2 sawExcla separator encoding| |
2628 |fileName changeInStream outStream chunk chunk2 sawExcla separator encoding| |
2629 |
2629 |
2630 changeInStream := self streamForChange:changeNr. |
2630 changeInStream := self streamForChange:changeNr. |
2631 changeInStream isNil ifTrue:[ |
2631 changeInStream isNil ifTrue:[ |
2632 self warn:'Cannot read change'. |
2632 self warn:'Cannot read change'. |
2633 ^ false |
2633 ^ false |
2634 ]. |
2634 ]. |
2635 changeInStream skipSeparators. |
2635 changeInStream skipSeparators. |
2636 |
2636 |
2637 separator := changeInStream class chunkSeparator. |
2637 separator := changeInStream class chunkSeparator. |
2638 |
2638 |
2639 (self changeIsFollowupMethodChange:changeNr) ifTrue:[ |
2639 (self changeIsFollowupMethodChange:changeNr) ifTrue:[ |
2640 sawExcla := true. |
2640 sawExcla := true. |
2641 chunk := changeChunks at:changeNr. |
2641 chunk := changeChunks at:changeNr. |
2642 ] ifFalse:[ |
2642 ] ifFalse:[ |
2643 sawExcla := changeInStream peekFor:separator. |
2643 sawExcla := changeInStream peekFor:separator. |
2644 chunk := changeInStream nextChunk. |
2644 chunk := changeInStream nextChunk. |
2645 ]. |
2645 ]. |
2646 chunk withoutSeparators isEmpty ifTrue:[ |
2646 chunk withoutSeparators isEmpty ifTrue:[ |
2647 self error:'Empty chunk - should not happen'. |
2647 self error:'Empty chunk - should not happen' mayProceed:true. |
|
2648 ^ false. |
2648 ]. |
2649 ]. |
2649 |
2650 |
2650 fileName := aFileNameOrFileNameString asFilename. |
2651 fileName := aFileNameOrFileNameString asFilename. |
2651 fileName exists ifTrue:[ |
2652 fileName exists ifTrue:[ |
2652 encoding := CharacterEncoder guessEncodingOfFile:fileName. |
2653 encoding := CharacterEncoder guessEncodingOfFile:fileName. |
2653 ] ifFalse:[ |
2654 ] ifFalse:[ |
2654 encoding := #utf8. |
2655 encoding := #utf8. |
2655 ]. |
2656 ]. |
2656 |
2657 |
2657 [ |
2658 [ |
2658 outStream := fileName readWriteStream. |
2659 outStream := fileName readWriteStream. |
2659 ] on:FileStream openErrorSignal do:[:ex| |
2660 ] on:FileStream openErrorSignal do:[:ex| |
2660 self warn:'Cannot update file: ''%1''' with:fileName. |
2661 self warn:'Cannot update file: ''%1''' with:fileName. |
2661 ^ false |
2662 ^ false |
2662 ]. |
2663 ]. |
2663 |
2664 |
2664 encoding notNil ifTrue:[ |
2665 encoding notNil ifTrue:[ |
2665 outStream := EncodedStream stream:outStream encoder:(CharacterEncoder encoderFor:encoding). |
2666 outStream := EncodedStream stream:outStream encoder:(CharacterEncoder encoderFor:encoding). |
2666 outStream nextPutLine:'"{ Encoding: utf8 }" !!'. |
2667 outStream nextPutLine:'"{ Encoding: utf8 }" !!'. |
2667 ]. |
2668 ]. |
2668 |
2669 |
2669 outStream setToEnd. |
2670 outStream setToEnd. |
2670 |
2671 |
2671 sawExcla ifTrue:[ |
2672 sawExcla ifTrue:[ |
2672 outStream nextPut:separator |
2673 outStream nextPut:separator |
2673 ]. |
2674 ]. |
2674 outStream nextChunkPut:chunk; cr. |
2675 outStream nextChunkPut:chunk; cr. |
2675 sawExcla ifTrue:[ |
2676 sawExcla ifTrue:[ |
2676 chunk2 := changeInStream nextChunk. |
2677 chunk2 := changeInStream nextChunk. |
2677 chunk2 withoutSeparators isEmpty ifTrue:[ |
2678 chunk2 withoutSeparators isEmpty ifTrue:[ |
2678 self error:'Empty chunk - should not happen'. |
2679 self error:'Empty chunk - should not happen'. |
2679 ]. |
2680 ]. |
2680 outStream nextChunkPut:chunk2; space |
2681 outStream nextChunkPut:chunk2; space |
2681 ]. |
2682 ]. |
2682 sawExcla ifTrue:[ |
2683 sawExcla ifTrue:[ |
2683 outStream nextPut:separator |
2684 outStream nextPut:separator |
2684 ]. |
2685 ]. |
2685 outStream cr. |
2686 outStream cr. |
2686 |
2687 |
2687 changeInStream close. |
2688 changeInStream close. |
2688 outStream close. |
2689 outStream close. |