Differences From Artifact [c3602b309c]:
- File
utils/ofarc/LHAArchive.m
— part of check-in
[51343e2dfc]
at
2018-06-17 16:16:34
on branch trunk
— Rename ofzip to ofarc
It supports more than just ZIP now, so the name was no longer
appropriate. (user: js, size: 9639) [annotate] [blame] [check-ins using]
To Artifact [776323ff54]:
- File utils/ofarc/LHAArchive.m — part of check-in [bf8788d709] at 2018-06-17 16:32:44 on branch trunk — ofarc: Add LHA write and append support (user: js, size: 12356) [annotate] [blame] [check-ins using]
︙ | |||
366 367 368 369 370 371 372 373 374 | 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | for (OFString *file in files) { [of_stderr writeLine: OF_LOCALIZED(@"file_not_in_archive", @"File %[file] is not in the archive!", @"file", file)]; app->_exitStatus = 1; } } - (void)addFiles: (OFArray OF_GENERIC(OFString *) *)files { OFFileManager *fileManager = [OFFileManager defaultManager]; if ([files count] < 1) { [of_stderr writeLine: OF_LOCALIZED(@"add_no_file_specified", @"Need one or more files to add!")]; app->_exitStatus = 1; return; } for (OFString *fileName in files) { void *pool = objc_autoreleasePoolPush(); of_file_attributes_t attributes; of_file_type_t type; OFMutableLHAArchiveEntry *entry; OFStream *output; if (app->_outputLevel >= 0) [of_stdout writeString: OF_LOCALIZED(@"adding_file", @"Adding %[file]...", @"file", fileName)]; attributes = [fileManager attributesOfItemAtPath: fileName]; type = [attributes fileType]; entry = [OFMutableLHAArchiveEntry entryWithFileName: fileName]; #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS [entry setMode: [OFNumber numberWithUInt16: [attributes filePOSIXPermissions]]]; #endif [entry setDate: [attributes fileModificationDate]]; #ifdef OF_FILE_MANAGER_SUPPORTS_OWNER [entry setUID: [OFNumber numberWithUInt16: [attributes filePOSIXUID]]]; [entry setGID: [OFNumber numberWithUInt16: [attributes filePOSIXGID]]]; [entry setOwner: [attributes fileOwner]]; [entry setGroup: [attributes fileGroup]]; #endif if ([type isEqual: of_file_type_directory]) [entry setCompressionMethod: @"-lhd-"]; output = [_archive streamForWritingEntry: entry]; if ([type isEqual: of_file_type_regular]) { size_t written = 0, size = [attributes fileSize]; int8_t percent = -1, newPercent; OFFile *input = [OFFile fileWithPath: fileName mode: @"r"]; while (![input isAtEndOfStream]) { ssize_t length = [app copyBlockFromStream: input toStream: output fileName: fileName]; if (length < 0) { app->_exitStatus = 1; goto outer_loop_end; } written += length; newPercent = (written == size ? 100 : (int8_t)(written * 100 / size)); if (app->_outputLevel >= 0 && percent != newPercent) { OFString *percentString; percent = newPercent; percentString = [OFString stringWithFormat: @"%3u", percent]; [of_stdout writeString: @"\r"]; [of_stdout writeString: OF_LOCALIZED( @"adding_file_percent", @"Adding %[file]... %[percent]%", @"file", fileName, @"percent", percentString)]; } } } if (app->_outputLevel >= 0) { [of_stdout writeString: @"\r"]; [of_stdout writeLine: OF_LOCALIZED( @"adding_file_done", @"Adding %[file]... done", @"file", fileName)]; } [output close]; outer_loop_end: objc_autoreleasePoolPop(pool); } [_archive close]; } @end |