@@ -246,22 +246,22 @@ private static void WriteNames(DataWriter writer, IEnumerable<Node> nodes) {
246246 }
247247
248248 private static void WriteFolders ( DataWriter writer , IEnumerable < Node > folders ) {
249- foreach ( var node in folders ) {
249+ foreach ( var tags in folders . Select ( x => x . Tags ) ) {
250250 var attributes = 0x00000010 ;
251251
252- if ( node . Tags . TryGetValue ( "DirectoryInfo" , out var directoryInfo ) ) {
252+ if ( tags . TryGetValue ( "DirectoryInfo" , out var directoryInfo ) ) {
253253 DirectoryInfo info = directoryInfo ;
254254 attributes = ( int ) info . Attributes ;
255255 }
256256
257- if ( node . Tags . TryGetValue ( "Attributes" , out var attrs ) ) {
257+ if ( tags . TryGetValue ( "Attributes" , out var attrs ) ) {
258258 attributes = ( int ) attrs ;
259259 }
260260
261- writer . Write ( ( int ) node . Tags [ "FolderCount" ] ) ;
262- writer . Write ( ( int ) node . Tags [ "FirstFolderIndex" ] ) ;
263- writer . Write ( ( int ) node . Tags [ "FileCount" ] ) ;
264- writer . Write ( ( int ) node . Tags [ "FirstFileIndex" ] ) ;
261+ writer . Write ( ( int ) tags [ "FolderCount" ] ) ;
262+ writer . Write ( ( int ) tags [ "FirstFolderIndex" ] ) ;
263+ writer . Write ( ( int ) tags [ "FileCount" ] ) ;
264+ writer . Write ( ( int ) tags [ "FirstFileIndex" ] ) ;
265265 writer . Write ( attributes ) ;
266266 writer . Write ( 0x00000000 ) ;
267267 writer . Write ( 0x00000000 ) ;
@@ -275,39 +275,33 @@ private static void WriteFiles(DataWriter writer, IEnumerable<Node> files, long
275275 foreach ( var node in files ) {
276276 var parFile = node . GetFormatAs < ParFile > ( ) ;
277277
278- if ( parFile == null ) {
278+ if ( parFile == null )
279279 continue ;
280- }
281-
282- if ( node . Stream ! . Length > 2048 ) {
283- blockSize = 2048 + ( - node . Stream . Length % 2048 ) ;
280+
281+ var streamLength = node . Stream ! . Length ;
282+
283+ if ( streamLength > 2048 || streamLength >= blockSize ) {
284+ blockSize = 2048 + ( - streamLength % 2048 ) ;
284285 dataPosition = Align ( dataPosition , 2048 ) ;
285286 } else {
286- if ( node . Stream . Length < blockSize ) {
287- blockSize -= node . Stream . Length ;
288- } else {
289- blockSize = 2048 + ( - node . Stream . Length % 2048 ) ;
290- dataPosition = Align ( dataPosition , 2048 ) ;
291- }
287+ blockSize -= streamLength ;
292288 }
293289
294290 ulong seconds = 0 ;
295291 var attributes = parFile . Attributes ;
296292
297293 if ( ! parameters . ResetFileDates ) {
298294 var date = parFile . FileDate ;
299- var baseDate = new DateTime ( 1970 , 1 , 1 ) ;
295+ var baseDate = DateTime . UnixEpoch ;
300296
301297 if ( node . Tags . TryGetValue ( "Timestamp" , out var timestamp ) ) {
302298 date = baseDate . AddSeconds ( timestamp ) ;
303299 }
304300
305- if ( node . Tags . TryGetValue ( "FileInfo" , out var fileInfo ) ) {
306- if ( fileInfo is FileInfo info ) {
307- attributes = HandleAttributes ( info ) ;
308-
309- date = info . LastWriteTime ;
310- }
301+ if ( node . Tags . TryGetValue ( "FileInfo" , out var fileInfo ) && fileInfo is FileInfo info ) {
302+ attributes = HandleAttributes ( info ) ;
303+
304+ date = info . LastWriteTime ;
311305 }
312306
313307 seconds = ( ulong ) ( date - baseDate ) . TotalSeconds ;
0 commit comments