[ver 0.2.0] added options
| @@ -9,6 +9,7 @@ | ||
| 9 | 9 | |
| 10 | 10 | #import "CRDropView.h" |
| 11 | 11 | #import <Foundation/Foundation.h> |
| 12 | +#import "NSImage+data.h" | |
| 12 | 13 | |
| 13 | 14 | @implementation CRDropView |
| 14 | 15 |
| @@ -37,69 +38,7 @@ | ||
| 37 | 38 | // Drawing code here. |
| 38 | 39 | } |
| 39 | 40 | |
| 40 | -//画像ファイルのチェック | |
| 41 | -- (BOOL)isImageFile:(NSString*)filePath | |
| 42 | -{ | |
| 43 | - BOOL isImageFile = NO; | |
| 44 | - LSItemInfoRecord info; | |
| 45 | - CFStringRef uti = NULL; | |
| 46 | - @try { | |
| 47 | 41 | |
| 48 | - CFURLRef url = CFURLCreateWithFileSystemPath(NULL, | |
| 49 | - (CFStringRef)filePath, kCFURLPOSIXPathStyle, FALSE); | |
| 50 | - | |
| 51 | - if (LSCopyItemInfoForURL(url, kLSRequestExtension | | |
| 52 | - kLSRequestTypeCreator, &info) == noErr) | |
| 53 | - { | |
| 54 | - if (info.extension != NULL) | |
| 55 | - { | |
| 56 | - uti = | |
| 57 | - UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, | |
| 58 | - info.extension, kUTTypeData); | |
| 59 | - CFRelease(info.extension); | |
| 60 | - } | |
| 61 | - | |
| 62 | - if (uti == NULL) | |
| 63 | - { | |
| 64 | - CFStringRef typeString = | |
| 65 | - UTCreateStringForOSType(info.filetype); | |
| 66 | - if ( typeString != NULL) | |
| 67 | - { | |
| 68 | - uti = | |
| 69 | - UTTypeCreatePreferredIdentifierForTag(kUTTagClassOSType, | |
| 70 | - typeString, kUTTypeData); | |
| 71 | - CFRelease(typeString); | |
| 72 | - } | |
| 73 | - } | |
| 74 | - | |
| 75 | - if (uti != NULL) | |
| 76 | - { | |
| 77 | - CFArrayRef supportedTypes = | |
| 78 | - CGImageSourceCopyTypeIdentifiers(); | |
| 79 | - CFIndex i, typeCount = CFArrayGetCount(supportedTypes); | |
| 80 | - | |
| 81 | - for (i = 0; i < typeCount; i++) | |
| 82 | - { | |
| 83 | - if (UTTypeConformsTo(uti, | |
| 84 | - (CFStringRef)CFArrayGetValueAtIndex(supportedTypes, i))) | |
| 85 | - { | |
| 86 | - isImageFile = YES; | |
| 87 | - break; | |
| 88 | - } | |
| 89 | - } | |
| 90 | - } | |
| 91 | - } | |
| 92 | - | |
| 93 | - } | |
| 94 | - @catch (NSException *exception) { | |
| 95 | - | |
| 96 | - } | |
| 97 | - @finally { | |
| 98 | - } | |
| 99 | - | |
| 100 | - return isImageFile; | |
| 101 | -} | |
| 102 | - | |
| 103 | 42 | - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender |
| 104 | 43 | { |
| 105 | 44 | if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) |
| @@ -176,19 +115,18 @@ | ||
| 176 | 115 | |
| 177 | 116 | for (NSString *filename in array) { |
| 178 | 117 | filename = [path stringByAppendingPathComponent:filename]; |
| 179 | - if ([self isImageFile:filename]) { | |
| 118 | + if ([NSImage isImageFile:filename]) { | |
| 180 | 119 | NSLog(@"%@", filename); |
| 181 | 120 | [self._files addObject:filename]; |
| 182 | 121 | } |
| 183 | 122 | } |
| 184 | 123 | } else { |
| 185 | - if ([self isImageFile:path]) { | |
| 124 | + if ([NSImage isImageFile:path]) { | |
| 186 | 125 | [self._files addObject:path]; |
| 187 | 126 | } |
| 188 | 127 | } |
| 189 | 128 | |
| 190 | 129 | } |
| 191 | - | |
| 192 | 130 | } |
| 193 | 131 | |
| 194 | 132 | //ファイルがドロップされた事への通知、これでTableViewが更新される |
| @@ -209,4 +147,5 @@ | ||
| 209 | 147 | return YES; |
| 210 | 148 | } |
| 211 | 149 | |
| 150 | + | |
| 212 | 151 | @end |
| @@ -0,0 +1,185 @@ | ||
| 1 | +// | |
| 2 | +// NSImage+data.m | |
| 3 | +// ImageSplitter | |
| 4 | +// | |
| 5 | +// Created by hiroshi tomioka on 13/02/14. | |
| 6 | +// Copyright (c) 2013年 hiroshi tomioka. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import "NSImage+data.h" | |
| 10 | + | |
| 11 | +@implementation NSImage (data) | |
| 12 | + | |
| 13 | +//画像ファイルのチェック | |
| 14 | ++ (BOOL)isImageFile:(NSString*)filePath | |
| 15 | +{ | |
| 16 | + BOOL isImageFile = NO; | |
| 17 | + LSItemInfoRecord info; | |
| 18 | + CFStringRef uti = NULL; | |
| 19 | + @try { | |
| 20 | + | |
| 21 | + CFURLRef url = CFURLCreateWithFileSystemPath(NULL, | |
| 22 | + (CFStringRef)filePath, kCFURLPOSIXPathStyle, FALSE); | |
| 23 | + | |
| 24 | + if (LSCopyItemInfoForURL(url, kLSRequestExtension | | |
| 25 | + kLSRequestTypeCreator, &info) == noErr) | |
| 26 | + { | |
| 27 | + if (info.extension != NULL) | |
| 28 | + { | |
| 29 | + uti = | |
| 30 | + UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, | |
| 31 | + info.extension, kUTTypeData); | |
| 32 | + CFRelease(info.extension); | |
| 33 | + } | |
| 34 | + | |
| 35 | + if (uti == NULL) | |
| 36 | + { | |
| 37 | + CFStringRef typeString = | |
| 38 | + UTCreateStringForOSType(info.filetype); | |
| 39 | + if ( typeString != NULL) | |
| 40 | + { | |
| 41 | + uti = | |
| 42 | + UTTypeCreatePreferredIdentifierForTag(kUTTagClassOSType, | |
| 43 | + typeString, kUTTypeData); | |
| 44 | + CFRelease(typeString); | |
| 45 | + } | |
| 46 | + } | |
| 47 | + | |
| 48 | + if (uti != NULL) | |
| 49 | + { | |
| 50 | + CFArrayRef supportedTypes = | |
| 51 | + CGImageSourceCopyTypeIdentifiers(); | |
| 52 | + CFIndex i, typeCount = CFArrayGetCount(supportedTypes); | |
| 53 | + | |
| 54 | + for (i = 0; i < typeCount; i++) | |
| 55 | + { | |
| 56 | + if (UTTypeConformsTo(uti, | |
| 57 | + (CFStringRef)CFArrayGetValueAtIndex(supportedTypes, i))) | |
| 58 | + { | |
| 59 | + isImageFile = YES; | |
| 60 | + break; | |
| 61 | + } | |
| 62 | + } | |
| 63 | + } | |
| 64 | + } | |
| 65 | + | |
| 66 | + } | |
| 67 | + @catch (NSException *exception) { | |
| 68 | + | |
| 69 | + } | |
| 70 | + @finally { | |
| 71 | + } | |
| 72 | + | |
| 73 | + return isImageFile; | |
| 74 | +} | |
| 75 | + | |
| 76 | +- (NSImage*)trimImageByRect:(NSRect)trimRect { | |
| 77 | + NSBitmapImageRep* imageRep = [NSBitmapImageRep imageRepWithData:[self TIFFRepresentation] ]; | |
| 78 | + NSSize pointSize = NSMakeSize(imageRep.pixelsWide, imageRep.pixelsHigh); | |
| 79 | + | |
| 80 | + [self setSize:pointSize]; | |
| 81 | + | |
| 82 | + NSRect newRect = NSZeroRect; | |
| 83 | + newRect.size = trimRect.size; | |
| 84 | + NSImage *newImage = [[[NSImage alloc] initWithSize:newRect.size] autorelease]; | |
| 85 | + | |
| 86 | + [newImage lockFocus]; | |
| 87 | + [NSGraphicsContext saveGraphicsState]; | |
| 88 | + | |
| 89 | + [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh]; | |
| 90 | + | |
| 91 | + [self drawAtPoint:NSZeroPoint fromRect:trimRect operation:NSCompositeSourceOver fraction:1.0]; | |
| 92 | + [NSGraphicsContext restoreGraphicsState]; | |
| 93 | + [newImage unlockFocus]; | |
| 94 | + | |
| 95 | + return newImage; | |
| 96 | +} | |
| 97 | + | |
| 98 | +- (NSImage*)fitImageInSize:(NSSize)fitSize { | |
| 99 | + NSBitmapImageRep* imageRep = [NSBitmapImageRep imageRepWithData:[self TIFFRepresentation] ]; | |
| 100 | + NSSize pointSize = NSMakeSize(imageRep.pixelsWide, imageRep.pixelsHigh); | |
| 101 | + | |
| 102 | + [self setSize:pointSize]; | |
| 103 | + | |
| 104 | + NSRect originalRect = NSZeroRect; | |
| 105 | + originalRect.size = pointSize; | |
| 106 | + NSImage *newImage = [[[NSImage alloc] initWithSize:fitSize] autorelease]; | |
| 107 | + | |
| 108 | + [newImage lockFocus]; | |
| 109 | + [NSGraphicsContext saveGraphicsState]; | |
| 110 | + | |
| 111 | + [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh]; | |
| 112 | + | |
| 113 | + | |
| 114 | + double scale = MIN(fitSize.width / originalRect.size.width, fitSize.height / originalRect.size.height); | |
| 115 | + | |
| 116 | + | |
| 117 | + NSRect newRect = NSMakeRect((fitSize.width - originalRect.size.width * scale) / 2.0, (fitSize.height - originalRect.size.height * scale) / 2.0, originalRect.size.width * scale, originalRect.size.height * scale); | |
| 118 | + | |
| 119 | + [self drawInRect:newRect fromRect:originalRect operation:NSCompositeSourceOver fraction:1.0]; | |
| 120 | + | |
| 121 | + // NSZeroPoint fromRect:trimRect operation:NSCompositeSourceOver fraction:1.0]; | |
| 122 | + [NSGraphicsContext restoreGraphicsState]; | |
| 123 | + [newImage unlockFocus]; | |
| 124 | + | |
| 125 | + return newImage; | |
| 126 | +} | |
| 127 | + | |
| 128 | +- (NSData*)JPEGDataWithQuality:(float)quality | |
| 129 | +{ | |
| 130 | + NSBitmapImageRep *bitmapImageRep; | |
| 131 | + NSData *newData; | |
| 132 | + NSDictionary *properties; | |
| 133 | + | |
| 134 | + bitmapImageRep = [NSBitmapImageRep imageRepWithData:[self TIFFRepresentation]]; | |
| 135 | + properties = [NSDictionary | |
| 136 | + dictionaryWithObject:[NSNumber numberWithFloat:quality] | |
| 137 | + forKey:NSImageCompressionFactor]; | |
| 138 | + newData = [bitmapImageRep representationUsingType:NSJPEGFileType | |
| 139 | + properties:properties]; | |
| 140 | + return newData; | |
| 141 | +} | |
| 142 | + | |
| 143 | +- (NSData*)JPEG2000DataWithQuality:(float)quality | |
| 144 | +{ | |
| 145 | + NSBitmapImageRep *bitmapImageRep; | |
| 146 | + NSData *newData; | |
| 147 | + NSDictionary *properties; | |
| 148 | + | |
| 149 | + bitmapImageRep = [NSBitmapImageRep imageRepWithData:[self TIFFRepresentation]]; | |
| 150 | + properties = [NSDictionary | |
| 151 | + dictionaryWithObject:[NSNumber numberWithFloat:quality] | |
| 152 | + forKey:NSImageCompressionFactor]; | |
| 153 | + newData = [bitmapImageRep representationUsingType:NSJPEG2000FileType | |
| 154 | + properties:properties]; | |
| 155 | + return newData; | |
| 156 | +} | |
| 157 | + | |
| 158 | + | |
| 159 | +- (NSData*)PNGDataWithInterlaced:(BOOL)interlaced | |
| 160 | +{ | |
| 161 | + NSBitmapImageRep *bitmapImageRep; | |
| 162 | + NSData *newData; | |
| 163 | + NSDictionary *properties; | |
| 164 | + | |
| 165 | + bitmapImageRep = [NSBitmapImageRep imageRepWithData:[self TIFFRepresentation]]; | |
| 166 | + properties = [NSDictionary | |
| 167 | + dictionaryWithObject:[NSNumber numberWithBool:interlaced] | |
| 168 | + forKey:NSImageInterlaced]; | |
| 169 | + newData = [bitmapImageRep representationUsingType:NSPNGFileType | |
| 170 | + properties:properties]; | |
| 171 | + return newData; | |
| 172 | +} | |
| 173 | + | |
| 174 | +- (NSData*)BMPData | |
| 175 | +{ | |
| 176 | + NSBitmapImageRep *bitmapImageRep; | |
| 177 | + NSData *newData; | |
| 178 | + | |
| 179 | + bitmapImageRep = [NSBitmapImageRep imageRepWithData:[self TIFFRepresentation]]; | |
| 180 | + newData = [bitmapImageRep representationUsingType:NSBMPFileType | |
| 181 | + properties:nil]; | |
| 182 | + return newData; | |
| 183 | +} | |
| 184 | + | |
| 185 | +@end |
| @@ -7,10 +7,11 @@ | ||
| 7 | 7 | // |
| 8 | 8 | |
| 9 | 9 | #import <Cocoa/Cocoa.h> |
| 10 | +#import "CRBehaviorsWindowController.h" | |
| 10 | 11 | |
| 11 | 12 | @interface CRAppDelegate : NSObject <NSApplicationDelegate> |
| 12 | 13 | |
| 13 | 14 | @property (assign) IBOutlet NSWindow *window; |
| 15 | +@property (assign) CRBehaviorsWindowController *_controller; | |
| 14 | 16 | |
| 15 | - | |
| 16 | 17 | @end |
| @@ -0,0 +1,13 @@ | ||
| 1 | +// | |
| 2 | +// CRBehaviorsWindowController.h | |
| 3 | +// ImageSplitter | |
| 4 | +// | |
| 5 | +// Created by hiroshi tomioka on 13/02/13. | |
| 6 | +// Copyright (c) 2013年 hiroshi tomioka. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import <Cocoa/Cocoa.h> | |
| 10 | + | |
| 11 | +@interface CRBehaviorsWindowController : NSWindowController | |
| 12 | + | |
| 13 | +@end |
| @@ -8,7 +8,9 @@ | ||
| 8 | 8 | |
| 9 | 9 | #import "CRAppDelegate.h" |
| 10 | 10 | |
| 11 | + | |
| 11 | 12 | @implementation CRAppDelegate |
| 13 | +@synthesize _controller; | |
| 12 | 14 | |
| 13 | 15 | - (void)dealloc |
| 14 | 16 | { |
| @@ -20,4 +22,40 @@ | ||
| 20 | 22 | // Insert code here to initialize your application |
| 21 | 23 | } |
| 22 | 24 | |
| 25 | +//- (void)sheetDidEnd:(NSWindow*)sheet | |
| 26 | +// returnCode:(int)returnCode | |
| 27 | +// contextInfo:(void*)contextInfo | |
| 28 | +//{ | |
| 29 | +// [sheet orderOut:self]; | |
| 30 | +// NSLog(@"returnCode %d",returnCode); | |
| 31 | +//} | |
| 32 | + | |
| 33 | +- (IBAction)onBehaviorsButton:(id)sender | |
| 34 | +{ | |
| 35 | + NSLog(@"Behaviors"); | |
| 36 | + if (!_controller) { | |
| 37 | + _controller = [[CRBehaviorsWindowController alloc] init]; | |
| 38 | + [NSBundle loadNibNamed:@"CRBehaviorsWindowController" owner:_controller]; | |
| 39 | + } | |
| 40 | + [_controller showWindow:self]; | |
| 41 | + [[_controller window] makeKeyAndOrderFront:self]; | |
| 42 | + | |
| 43 | + | |
| 44 | +// [NSApp stopModal]; | |
| 45 | +// | |
| 46 | +// CRBehaviorsWindowController *controller = [[CRBehaviorsWindowController alloc] init]; | |
| 47 | +// | |
| 48 | +// [NSApp beginSheet:controller.window | |
| 49 | +// modalForWindow:self.window | |
| 50 | +// modalDelegate:self | |
| 51 | +// didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) | |
| 52 | +// contextInfo:nil | |
| 53 | +// ]; | |
| 54 | +// | |
| 55 | + | |
| 56 | +// CRBehaviorsWindowController *controller = [[CRBehaviorsWindowController alloc] init]; | |
| 57 | +// [self.window setContentView: controller.view]; | |
| 58 | + //[controller presentModalViewController:controller]; | |
| 59 | +} | |
| 60 | + | |
| 23 | 61 | @end |
| @@ -7,7 +7,7 @@ | ||
| 7 | 7 | <key>CFBundleExecutable</key> |
| 8 | 8 | <string>${EXECUTABLE_NAME}</string> |
| 9 | 9 | <key>CFBundleIconFile</key> |
| 10 | - <string></string> | |
| 10 | + <string>icon_kb</string> | |
| 11 | 11 | <key>CFBundleIdentifier</key> |
| 12 | 12 | <string>net.crestra.${PRODUCT_NAME:rfc1034identifier}</string> |
| 13 | 13 | <key>CFBundleInfoDictionaryVersion</key> |
| @@ -17,11 +17,11 @@ | ||
| 17 | 17 | <key>CFBundlePackageType</key> |
| 18 | 18 | <string>APPL</string> |
| 19 | 19 | <key>CFBundleShortVersionString</key> |
| 20 | - <string>1.0</string> | |
| 20 | + <string>0.2.0</string> | |
| 21 | 21 | <key>CFBundleSignature</key> |
| 22 | 22 | <string>????</string> |
| 23 | 23 | <key>CFBundleVersion</key> |
| 24 | - <string>1</string> | |
| 24 | + <string>0.2.0</string> | |
| 25 | 25 | <key>LSApplicationCategoryType</key> |
| 26 | 26 | <string>public.app-category.utilities</string> |
| 27 | 27 | <key>LSMinimumSystemVersion</key> |
| @@ -0,0 +1,146 @@ | ||
| 1 | +// | |
| 2 | +// CRBehaviorsWindowController.m | |
| 3 | +// ImageSplitter | |
| 4 | +// | |
| 5 | +// Created by hiroshi tomioka on 13/02/13. | |
| 6 | +// Copyright (c) 2013年 hiroshi tomioka. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import "CRBehaviorsWindowController.h" | |
| 10 | + | |
| 11 | +@interface CRBehaviorsWindowController () { | |
| 12 | + IBOutlet NSTextField *_qualityField; | |
| 13 | + IBOutlet NSSlider *_qualitySlider; | |
| 14 | + IBOutlet NSTextField *_qualityJpegField; | |
| 15 | + IBOutlet NSSlider *_qualityJpegSlider; | |
| 16 | + IBOutlet NSSegmentedControl *_imageTypeSegment; | |
| 17 | + IBOutlet NSButton *_zipOnOffButton; | |
| 18 | + IBOutlet NSSegmentedControl *_fitSegment; | |
| 19 | + IBOutlet NSFormCell *_widthFormCell; | |
| 20 | + IBOutlet NSFormCell *_heightFormCell; | |
| 21 | +} | |
| 22 | +@end | |
| 23 | + | |
| 24 | +@implementation CRBehaviorsWindowController | |
| 25 | + | |
| 26 | +- (id)initWithWindow:(NSWindow *)window | |
| 27 | +{ | |
| 28 | + self = [super initWithWindow:window]; | |
| 29 | + if (self) { | |
| 30 | + // Initialization code here. | |
| 31 | + | |
| 32 | + } | |
| 33 | + | |
| 34 | + return self; | |
| 35 | +} | |
| 36 | + | |
| 37 | +- (void)windowDidLoad | |
| 38 | +{ | |
| 39 | + [super windowDidLoad]; | |
| 40 | + | |
| 41 | + //[[NSUserDefaults standardUserDefaults] setDouble:0.5 forKey:@"jpeg2000 quality"]; | |
| 42 | + | |
| 43 | + // [[NSUserDefaults standardUserDefaults] synchronize]; | |
| 44 | + // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. | |
| 45 | +} | |
| 46 | + | |
| 47 | +- (void)awakeFromNib { | |
| 48 | + BOOL initialized = [[NSUserDefaults standardUserDefaults] boolForKey:@"applicatiopn initialized"]; | |
| 49 | + if (initialized) { | |
| 50 | + } else { | |
| 51 | + [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"applicatiopn initialized"]; | |
| 52 | + [[NSUserDefaults standardUserDefaults] setDouble:0.6 forKey:@"jpeg2000 quality"]; | |
| 53 | + [[NSUserDefaults standardUserDefaults] setDouble:0.6 forKey:@"jpeg quality"]; | |
| 54 | + [[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"image type"]; | |
| 55 | + [[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"zip flag"]; | |
| 56 | + [[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"fit size"]; | |
| 57 | + [[NSUserDefaults standardUserDefaults] setInteger:768 forKey:@"fit width"]; | |
| 58 | + [[NSUserDefaults standardUserDefaults] setInteger:1004 forKey:@"fit height"]; | |
| 59 | + [[NSUserDefaults standardUserDefaults] synchronize]; | |
| 60 | + | |
| 61 | + } | |
| 62 | + double val = [[NSUserDefaults standardUserDefaults] doubleForKey:@"jpeg2000 quality"]; | |
| 63 | + [_qualityField setStringValue:[NSString stringWithFormat:@"%.2f", val]]; | |
| 64 | + [_qualitySlider setDoubleValue:val]; | |
| 65 | + | |
| 66 | + double valJpeg = [[NSUserDefaults standardUserDefaults] doubleForKey:@"jpeg quality"]; | |
| 67 | + [_qualityJpegField setStringValue:[NSString stringWithFormat:@"%.2f", valJpeg]]; | |
| 68 | + [_qualityJpegSlider setDoubleValue:valJpeg]; | |
| 69 | + | |
| 70 | + NSInteger selected = [[NSUserDefaults standardUserDefaults] integerForKey:@"image type"]; | |
| 71 | + [_imageTypeSegment setSelectedSegment:selected]; | |
| 72 | + | |
| 73 | + NSInteger zipFlag = [[NSUserDefaults standardUserDefaults] integerForKey:@"zip flag"]; | |
| 74 | + [_zipOnOffButton setIntValue:(int)zipFlag]; | |
| 75 | + | |
| 76 | + NSInteger sizeFlag = [[NSUserDefaults standardUserDefaults] integerForKey:@"fit size"]; | |
| 77 | + [_fitSegment setSelectedSegment:(int)sizeFlag]; | |
| 78 | + | |
| 79 | + int fitWidth = (int)[[NSUserDefaults standardUserDefaults] integerForKey:@"fit width"]; | |
| 80 | + [_widthFormCell setStringValue:[NSString stringWithFormat:@"%d", fitWidth]]; | |
| 81 | + | |
| 82 | + int fitHeight = (int)[[NSUserDefaults standardUserDefaults] integerForKey:@"fit height"]; | |
| 83 | + [_heightFormCell setStringValue:[NSString stringWithFormat:@"%d", fitHeight]]; | |
| 84 | +} | |
| 85 | + | |
| 86 | + | |
| 87 | +-(IBAction)sliderMove:(NSSlider*)sender{ | |
| 88 | + NSLog(@"move! %f", sender.doubleValue); | |
| 89 | + [[NSUserDefaults standardUserDefaults] setDouble:sender.doubleValue forKey:@"jpeg2000 quality"]; | |
| 90 | + | |
| 91 | + [_qualityField setStringValue:[NSString stringWithFormat:@"%.2f", sender.doubleValue]]; | |
| 92 | + [[NSUserDefaults standardUserDefaults] synchronize]; | |
| 93 | +} | |
| 94 | + | |
| 95 | +-(IBAction)sliderJpegMove:(NSSlider*)sender{ | |
| 96 | + NSLog(@"sliderJpegMove! %f", sender.doubleValue); | |
| 97 | + [[NSUserDefaults standardUserDefaults] setDouble:sender.doubleValue forKey:@"jpeg quality"]; | |
| 98 | + | |
| 99 | + [_qualityJpegField setStringValue:[NSString stringWithFormat:@"%.2f", sender.doubleValue]]; | |
| 100 | + [[NSUserDefaults standardUserDefaults] synchronize]; | |
| 101 | +} | |
| 102 | + | |
| 103 | +-(IBAction)imageTypeChanged:(NSSegmentedControl*)sender{ | |
| 104 | + NSLog(@"imageTypeChanged! %d", (int)sender.selectedSegment); | |
| 105 | + [[NSUserDefaults standardUserDefaults] setInteger:sender.selectedSegment forKey:@"image type"]; | |
| 106 | + | |
| 107 | + [[NSUserDefaults standardUserDefaults] synchronize]; | |
| 108 | +} | |
| 109 | + | |
| 110 | +-(IBAction)zipOnOffChanged:(NSButton*)sender{ | |
| 111 | + NSLog(@"zipOnOffChanged! %d", sender.intValue); | |
| 112 | + [[NSUserDefaults standardUserDefaults] setInteger:sender.intValue forKey:@"zip flag"]; | |
| 113 | + [[NSUserDefaults standardUserDefaults] synchronize]; | |
| 114 | +} | |
| 115 | + | |
| 116 | +-(IBAction)fitChanged:(NSSegmentedControl*)sender{ | |
| 117 | + NSLog(@"fitChanged! %d", (int)sender.selectedSegment); | |
| 118 | + | |
| 119 | + [_widthFormCell setEnabled:(0 == sender.selectedSegment)]; | |
| 120 | + [_heightFormCell setEnabled:(0 == sender.selectedSegment)]; | |
| 121 | + | |
| 122 | + [[NSUserDefaults standardUserDefaults] setInteger:sender.selectedSegment forKey:@"fit size"]; | |
| 123 | + | |
| 124 | + [[NSUserDefaults standardUserDefaults] synchronize]; | |
| 125 | +} | |
| 126 | + | |
| 127 | +-(IBAction)widthFormCellChanged:(NSFormCell*)sender{ | |
| 128 | + NSLog(@"widthFormCellChanged! %@", [sender stringValue]); | |
| 129 | + NSInteger val = [[sender stringValue] intValue]; | |
| 130 | + | |
| 131 | + [[NSUserDefaults standardUserDefaults] setInteger:val forKey:@"fit width"]; | |
| 132 | + [[NSUserDefaults standardUserDefaults] synchronize]; | |
| 133 | +} | |
| 134 | + | |
| 135 | +-(IBAction)heightFormCellChanged:(NSFormCell*)sender{ | |
| 136 | + NSLog(@"heightFormCellChanged! %@", [sender stringValue]); | |
| 137 | + NSInteger val = [[sender stringValue] intValue]; | |
| 138 | + | |
| 139 | + [[NSUserDefaults standardUserDefaults] setInteger:val forKey:@"fit height"]; | |
| 140 | + [[NSUserDefaults standardUserDefaults] synchronize]; | |
| 141 | +} | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | +@end |
| @@ -0,0 +1,51 @@ | ||
| 1 | +Read the license: | |
| 2 | +http://creativecommons.org/licenses/by/3.0/ * | |
| 3 | + | |
| 4 | +- If your project is open source include this license file. | |
| 5 | +- Nothing is needed in the front facing project (UNLESS you | |
| 6 | + are using any of the icons listed below in the attribution section). | |
| 7 | +- Commercial use is not only allowed but encouraged. Do not worry you | |
| 8 | + do not have to attribute, I know how much of a pain that is. If it is | |
| 9 | + an icon in the attribution list below, you still need to attribute those! | |
| 10 | +- Do not distribute the entire package (I've allowed this dozens of | |
| 11 | + times for open source projects, but email me first). | |
| 12 | + | |
| 13 | +Creator | |
| 14 | +- Austin Andrews (@templarian) | |
| 15 | + | |
| 16 | +Contributor** | |
| 17 | +- Oren Nachman | |
| 18 | + - appbar.chevron.down | |
| 19 | + - appbar.chevron.up | |
| 20 | + - appbar.chevron.left | |
| 21 | + - appbar.chevron.right | |
| 22 | + | |
| 23 | +Attribution*** | |
| 24 | +- Kris Vandermotten (@kvandermotten) | |
| 25 | + - appbar.medical.pulse | |
| 26 | +- Constantin Kichinsky (@kichinsky) | |
| 27 | + - appbar.currency.rubles | |
| 28 | + - appbar.currency.grivna | |
| 29 | +- Massimo Savazzi (@msavazzi) | |
| 30 | + - List of missing exported icons | |
| 31 | +- Proletkult Graphik, from The Noun Project | |
| 32 | + - appbar.draw.pen (inspired) | |
| 33 | +- Olivier Guin, from The Noun Project | |
| 34 | + - appbar.draw.marker | |
| 35 | +- Gibran Bisio, from The Noun Project | |
| 36 | + - appbar.draw.bucket | |
| 37 | +Andrew Forrester, from The Noun Project | |
| 38 | + - appbar.fingerprint | |
| 39 | + | |
| 40 | +** Developers and designers that emailed Templarian the source .design icons to be added into the package. PNGs also accepted, but may take longer to be added. | |
| 41 | +*** Icons I've copied so closely you want to attribute them and are also under the CC license. | |
| 42 | + | |
| 43 | +Contact | |
| 44 | +- http://templarian.com/ | |
| 45 | +- admin[@]templarian[.]com | |
| 46 | + | |
| 47 | +* Does not apply to copyrighted logos | |
| 48 | +- Skype | |
| 49 | ||
| 50 | ||
| 51 | +- etc... |
| @@ -0,0 +1,177 @@ | ||
| 1 | +/* ioapi.c -- IO base function header for compress/uncompress .zip | |
| 2 | + files using zlib + zip or unzip API | |
| 3 | + | |
| 4 | + Version 1.01e, February 12th, 2005 | |
| 5 | + | |
| 6 | + Copyright (C) 1998-2005 Gilles Vollant | |
| 7 | +*/ | |
| 8 | + | |
| 9 | +#include <stdio.h> | |
| 10 | +#include <stdlib.h> | |
| 11 | +#include <string.h> | |
| 12 | + | |
| 13 | +#include "zlib.h" | |
| 14 | +#include "ioapi.h" | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | +/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ | |
| 19 | + | |
| 20 | +#ifndef SEEK_CUR | |
| 21 | +#define SEEK_CUR 1 | |
| 22 | +#endif | |
| 23 | + | |
| 24 | +#ifndef SEEK_END | |
| 25 | +#define SEEK_END 2 | |
| 26 | +#endif | |
| 27 | + | |
| 28 | +#ifndef SEEK_SET | |
| 29 | +#define SEEK_SET 0 | |
| 30 | +#endif | |
| 31 | + | |
| 32 | +voidpf ZCALLBACK fopen_file_func OF(( | |
| 33 | + voidpf opaque, | |
| 34 | + const char* filename, | |
| 35 | + int mode)); | |
| 36 | + | |
| 37 | +uLong ZCALLBACK fread_file_func OF(( | |
| 38 | + voidpf opaque, | |
| 39 | + voidpf stream, | |
| 40 | + void* buf, | |
| 41 | + uLong size)); | |
| 42 | + | |
| 43 | +uLong ZCALLBACK fwrite_file_func OF(( | |
| 44 | + voidpf opaque, | |
| 45 | + voidpf stream, | |
| 46 | + const void* buf, | |
| 47 | + uLong size)); | |
| 48 | + | |
| 49 | +long ZCALLBACK ftell_file_func OF(( | |
| 50 | + voidpf opaque, | |
| 51 | + voidpf stream)); | |
| 52 | + | |
| 53 | +long ZCALLBACK fseek_file_func OF(( | |
| 54 | + voidpf opaque, | |
| 55 | + voidpf stream, | |
| 56 | + uLong offset, | |
| 57 | + int origin)); | |
| 58 | + | |
| 59 | +int ZCALLBACK fclose_file_func OF(( | |
| 60 | + voidpf opaque, | |
| 61 | + voidpf stream)); | |
| 62 | + | |
| 63 | +int ZCALLBACK ferror_file_func OF(( | |
| 64 | + voidpf opaque, | |
| 65 | + voidpf stream)); | |
| 66 | + | |
| 67 | + | |
| 68 | +voidpf ZCALLBACK fopen_file_func (opaque, filename, mode) | |
| 69 | + voidpf opaque; | |
| 70 | + const char* filename; | |
| 71 | + int mode; | |
| 72 | +{ | |
| 73 | + FILE* file = NULL; | |
| 74 | + const char* mode_fopen = NULL; | |
| 75 | + if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) | |
| 76 | + mode_fopen = "rb"; | |
| 77 | + else | |
| 78 | + if (mode & ZLIB_FILEFUNC_MODE_EXISTING) | |
| 79 | + mode_fopen = "r+b"; | |
| 80 | + else | |
| 81 | + if (mode & ZLIB_FILEFUNC_MODE_CREATE) | |
| 82 | + mode_fopen = "wb"; | |
| 83 | + | |
| 84 | + if ((filename!=NULL) && (mode_fopen != NULL)) | |
| 85 | + file = fopen(filename, mode_fopen); | |
| 86 | + return file; | |
| 87 | +} | |
| 88 | + | |
| 89 | + | |
| 90 | +uLong ZCALLBACK fread_file_func (opaque, stream, buf, size) | |
| 91 | + voidpf opaque; | |
| 92 | + voidpf stream; | |
| 93 | + void* buf; | |
| 94 | + uLong size; | |
| 95 | +{ | |
| 96 | + uLong ret; | |
| 97 | + ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); | |
| 98 | + return ret; | |
| 99 | +} | |
| 100 | + | |
| 101 | + | |
| 102 | +uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size) | |
| 103 | + voidpf opaque; | |
| 104 | + voidpf stream; | |
| 105 | + const void* buf; | |
| 106 | + uLong size; | |
| 107 | +{ | |
| 108 | + uLong ret; | |
| 109 | + ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); | |
| 110 | + return ret; | |
| 111 | +} | |
| 112 | + | |
| 113 | +long ZCALLBACK ftell_file_func (opaque, stream) | |
| 114 | + voidpf opaque; | |
| 115 | + voidpf stream; | |
| 116 | +{ | |
| 117 | + long ret; | |
| 118 | + ret = ftell((FILE *)stream); | |
| 119 | + return ret; | |
| 120 | +} | |
| 121 | + | |
| 122 | +long ZCALLBACK fseek_file_func (opaque, stream, offset, origin) | |
| 123 | + voidpf opaque; | |
| 124 | + voidpf stream; | |
| 125 | + uLong offset; | |
| 126 | + int origin; | |
| 127 | +{ | |
| 128 | + int fseek_origin=0; | |
| 129 | + long ret; | |
| 130 | + switch (origin) | |
| 131 | + { | |
| 132 | + case ZLIB_FILEFUNC_SEEK_CUR : | |
| 133 | + fseek_origin = SEEK_CUR; | |
| 134 | + break; | |
| 135 | + case ZLIB_FILEFUNC_SEEK_END : | |
| 136 | + fseek_origin = SEEK_END; | |
| 137 | + break; | |
| 138 | + case ZLIB_FILEFUNC_SEEK_SET : | |
| 139 | + fseek_origin = SEEK_SET; | |
| 140 | + break; | |
| 141 | + default: return -1; | |
| 142 | + } | |
| 143 | + ret = 0; | |
| 144 | + fseek((FILE *)stream, offset, fseek_origin); | |
| 145 | + return ret; | |
| 146 | +} | |
| 147 | + | |
| 148 | +int ZCALLBACK fclose_file_func (opaque, stream) | |
| 149 | + voidpf opaque; | |
| 150 | + voidpf stream; | |
| 151 | +{ | |
| 152 | + int ret; | |
| 153 | + ret = fclose((FILE *)stream); | |
| 154 | + return ret; | |
| 155 | +} | |
| 156 | + | |
| 157 | +int ZCALLBACK ferror_file_func (opaque, stream) | |
| 158 | + voidpf opaque; | |
| 159 | + voidpf stream; | |
| 160 | +{ | |
| 161 | + int ret; | |
| 162 | + ret = ferror((FILE *)stream); | |
| 163 | + return ret; | |
| 164 | +} | |
| 165 | + | |
| 166 | +void fill_fopen_filefunc (pzlib_filefunc_def) | |
| 167 | + zlib_filefunc_def* pzlib_filefunc_def; | |
| 168 | +{ | |
| 169 | + pzlib_filefunc_def->zopen_file = fopen_file_func; | |
| 170 | + pzlib_filefunc_def->zread_file = fread_file_func; | |
| 171 | + pzlib_filefunc_def->zwrite_file = fwrite_file_func; | |
| 172 | + pzlib_filefunc_def->ztell_file = ftell_file_func; | |
| 173 | + pzlib_filefunc_def->zseek_file = fseek_file_func; | |
| 174 | + pzlib_filefunc_def->zclose_file = fclose_file_func; | |
| 175 | + pzlib_filefunc_def->zerror_file = ferror_file_func; | |
| 176 | + pzlib_filefunc_def->opaque = NULL; | |
| 177 | +} |
| @@ -0,0 +1,1219 @@ | ||
| 1 | +/* zip.c -- IO on .zip files using zlib | |
| 2 | + Version 1.01e, February 12th, 2005 | |
| 3 | + | |
| 4 | + 27 Dec 2004 Rolf Kalbermatter | |
| 5 | + Modification to zipOpen2 to support globalComment retrieval. | |
| 6 | + | |
| 7 | + Copyright (C) 1998-2005 Gilles Vollant | |
| 8 | + | |
| 9 | + Read zip.h for more info | |
| 10 | +*/ | |
| 11 | + | |
| 12 | + | |
| 13 | +#include <stdio.h> | |
| 14 | +#include <stdlib.h> | |
| 15 | +#include <string.h> | |
| 16 | +#include <time.h> | |
| 17 | +#include "zlib.h" | |
| 18 | +#include "zip.h" | |
| 19 | + | |
| 20 | +#ifdef STDC | |
| 21 | +# include <stddef.h> | |
| 22 | +# include <string.h> | |
| 23 | +# include <stdlib.h> | |
| 24 | +#endif | |
| 25 | +#ifdef NO_ERRNO_H | |
| 26 | + extern int errno; | |
| 27 | +#else | |
| 28 | +# include <errno.h> | |
| 29 | +#endif | |
| 30 | + | |
| 31 | + | |
| 32 | +#ifndef local | |
| 33 | +# define local static | |
| 34 | +#endif | |
| 35 | +/* compile with -Dlocal if your debugger can't find static symbols */ | |
| 36 | + | |
| 37 | +#ifndef VERSIONMADEBY | |
| 38 | +# define VERSIONMADEBY (0x0) /* platform depedent */ | |
| 39 | +#endif | |
| 40 | + | |
| 41 | +#ifndef Z_BUFSIZE | |
| 42 | +#define Z_BUFSIZE (16384) | |
| 43 | +#endif | |
| 44 | + | |
| 45 | +#ifndef Z_MAXFILENAMEINZIP | |
| 46 | +#define Z_MAXFILENAMEINZIP (256) | |
| 47 | +#endif | |
| 48 | + | |
| 49 | +#ifndef ALLOC | |
| 50 | +# define ALLOC(size) (malloc(size)) | |
| 51 | +#endif | |
| 52 | +#ifndef TRYFREE | |
| 53 | +# define TRYFREE(p) {if (p) free(p);} | |
| 54 | +#endif | |
| 55 | + | |
| 56 | +/* | |
| 57 | +#define SIZECENTRALDIRITEM (0x2e) | |
| 58 | +#define SIZEZIPLOCALHEADER (0x1e) | |
| 59 | +*/ | |
| 60 | + | |
| 61 | +/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ | |
| 62 | + | |
| 63 | +#ifndef SEEK_CUR | |
| 64 | +#define SEEK_CUR 1 | |
| 65 | +#endif | |
| 66 | + | |
| 67 | +#ifndef SEEK_END | |
| 68 | +#define SEEK_END 2 | |
| 69 | +#endif | |
| 70 | + | |
| 71 | +#ifndef SEEK_SET | |
| 72 | +#define SEEK_SET 0 | |
| 73 | +#endif | |
| 74 | + | |
| 75 | +#ifndef DEF_MEM_LEVEL | |
| 76 | +#if MAX_MEM_LEVEL >= 8 | |
| 77 | +# define DEF_MEM_LEVEL 8 | |
| 78 | +#else | |
| 79 | +# define DEF_MEM_LEVEL MAX_MEM_LEVEL | |
| 80 | +#endif | |
| 81 | +#endif | |
| 82 | +const char zip_copyright[] = | |
| 83 | + " zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; | |
| 84 | + | |
| 85 | + | |
| 86 | +#define SIZEDATA_INDATABLOCK (4096-(4*4)) | |
| 87 | + | |
| 88 | +#define LOCALHEADERMAGIC (0x04034b50) | |
| 89 | +#define CENTRALHEADERMAGIC (0x02014b50) | |
| 90 | +#define ENDHEADERMAGIC (0x06054b50) | |
| 91 | + | |
| 92 | +#define FLAG_LOCALHEADER_OFFSET (0x06) | |
| 93 | +#define CRC_LOCALHEADER_OFFSET (0x0e) | |
| 94 | + | |
| 95 | +#define SIZECENTRALHEADER (0x2e) /* 46 */ | |
| 96 | + | |
| 97 | +typedef struct linkedlist_datablock_internal_s | |
| 98 | +{ | |
| 99 | + struct linkedlist_datablock_internal_s* next_datablock; | |
| 100 | + uLong avail_in_this_block; | |
| 101 | + uLong filled_in_this_block; | |
| 102 | + uLong unused; /* for future use and alignement */ | |
| 103 | + unsigned char data[SIZEDATA_INDATABLOCK]; | |
| 104 | +} linkedlist_datablock_internal; | |
| 105 | + | |
| 106 | +typedef struct linkedlist_data_s | |
| 107 | +{ | |
| 108 | + linkedlist_datablock_internal* first_block; | |
| 109 | + linkedlist_datablock_internal* last_block; | |
| 110 | +} linkedlist_data; | |
| 111 | + | |
| 112 | + | |
| 113 | +typedef struct | |
| 114 | +{ | |
| 115 | + z_stream stream; /* zLib stream structure for inflate */ | |
| 116 | + int stream_initialised; /* 1 is stream is initialised */ | |
| 117 | + uInt pos_in_buffered_data; /* last written byte in buffered_data */ | |
| 118 | + | |
| 119 | + uLong pos_local_header; /* offset of the local header of the file | |
| 120 | + currenty writing */ | |
| 121 | + char* central_header; /* central header data for the current file */ | |
| 122 | + uLong size_centralheader; /* size of the central header for cur file */ | |
| 123 | + uLong flag; /* flag of the file currently writing */ | |
| 124 | + | |
| 125 | + int method; /* compression method of file currenty wr.*/ | |
| 126 | + int raw; /* 1 for directly writing raw data */ | |
| 127 | + Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/ | |
| 128 | + uLong dosDate; | |
| 129 | + uLong crc32; | |
| 130 | + int encrypt; | |
| 131 | +#ifndef NOCRYPT | |
| 132 | + unsigned long keys[3]; /* keys defining the pseudo-random sequence */ | |
| 133 | + const unsigned long* pcrc_32_tab; | |
| 134 | + int crypt_header_size; | |
| 135 | +#endif | |
| 136 | +} curfile_info; | |
| 137 | + | |
| 138 | +typedef struct | |
| 139 | +{ | |
| 140 | + zlib_filefunc_def z_filefunc; | |
| 141 | + voidpf filestream; /* io structore of the zipfile */ | |
| 142 | + linkedlist_data central_dir;/* datablock with central dir in construction*/ | |
| 143 | + int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/ | |
| 144 | + curfile_info ci; /* info on the file curretly writing */ | |
| 145 | + | |
| 146 | + uLong begin_pos; /* position of the beginning of the zipfile */ | |
| 147 | + uLong add_position_when_writting_offset; | |
| 148 | + uLong number_entry; | |
| 149 | +#ifndef NO_ADDFILEINEXISTINGZIP | |
| 150 | + char *globalcomment; | |
| 151 | +#endif | |
| 152 | +} zip_internal; | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | +#ifndef NOCRYPT | |
| 157 | +#define INCLUDECRYPTINGCODE_IFCRYPTALLOWED | |
| 158 | +#include "crypt.h" | |
| 159 | +#endif | |
| 160 | + | |
| 161 | +local linkedlist_datablock_internal* allocate_new_datablock() | |
| 162 | +{ | |
| 163 | + linkedlist_datablock_internal* ldi; | |
| 164 | + ldi = (linkedlist_datablock_internal*) | |
| 165 | + ALLOC(sizeof(linkedlist_datablock_internal)); | |
| 166 | + if (ldi!=NULL) | |
| 167 | + { | |
| 168 | + ldi->next_datablock = NULL ; | |
| 169 | + ldi->filled_in_this_block = 0 ; | |
| 170 | + ldi->avail_in_this_block = SIZEDATA_INDATABLOCK ; | |
| 171 | + } | |
| 172 | + return ldi; | |
| 173 | +} | |
| 174 | + | |
| 175 | +local void free_datablock(ldi) | |
| 176 | + linkedlist_datablock_internal* ldi; | |
| 177 | +{ | |
| 178 | + while (ldi!=NULL) | |
| 179 | + { | |
| 180 | + linkedlist_datablock_internal* ldinext = ldi->next_datablock; | |
| 181 | + TRYFREE(ldi); | |
| 182 | + ldi = ldinext; | |
| 183 | + } | |
| 184 | +} | |
| 185 | + | |
| 186 | +local void init_linkedlist(ll) | |
| 187 | + linkedlist_data* ll; | |
| 188 | +{ | |
| 189 | + ll->first_block = ll->last_block = NULL; | |
| 190 | +} | |
| 191 | + | |
| 192 | +local void free_linkedlist(ll) | |
| 193 | + linkedlist_data* ll; | |
| 194 | +{ | |
| 195 | + free_datablock(ll->first_block); | |
| 196 | + ll->first_block = ll->last_block = NULL; | |
| 197 | +} | |
| 198 | + | |
| 199 | + | |
| 200 | +local int add_data_in_datablock(ll,buf,len) | |
| 201 | + linkedlist_data* ll; | |
| 202 | + const void* buf; | |
| 203 | + uLong len; | |
| 204 | +{ | |
| 205 | + linkedlist_datablock_internal* ldi; | |
| 206 | + const unsigned char* from_copy; | |
| 207 | + | |
| 208 | + if (ll==NULL) | |
| 209 | + return ZIP_INTERNALERROR; | |
| 210 | + | |
| 211 | + if (ll->last_block == NULL) | |
| 212 | + { | |
| 213 | + ll->first_block = ll->last_block = allocate_new_datablock(); | |
| 214 | + if (ll->first_block == NULL) | |
| 215 | + return ZIP_INTERNALERROR; | |
| 216 | + } | |
| 217 | + | |
| 218 | + ldi = ll->last_block; | |
| 219 | + from_copy = (unsigned char*)buf; | |
| 220 | + | |
| 221 | + while (len>0) | |
| 222 | + { | |
| 223 | + uInt copy_this; | |
| 224 | + uInt i; | |
| 225 | + unsigned char* to_copy; | |
| 226 | + | |
| 227 | + if (ldi->avail_in_this_block==0) | |
| 228 | + { | |
| 229 | + ldi->next_datablock = allocate_new_datablock(); | |
| 230 | + if (ldi->next_datablock == NULL) | |
| 231 | + return ZIP_INTERNALERROR; | |
| 232 | + ldi = ldi->next_datablock ; | |
| 233 | + ll->last_block = ldi; | |
| 234 | + } | |
| 235 | + | |
| 236 | + if (ldi->avail_in_this_block < len) | |
| 237 | + copy_this = (uInt)ldi->avail_in_this_block; | |
| 238 | + else | |
| 239 | + copy_this = (uInt)len; | |
| 240 | + | |
| 241 | + to_copy = &(ldi->data[ldi->filled_in_this_block]); | |
| 242 | + | |
| 243 | + for (i=0;i<copy_this;i++) | |
| 244 | + *(to_copy+i)=*(from_copy+i); | |
| 245 | + | |
| 246 | + ldi->filled_in_this_block += copy_this; | |
| 247 | + ldi->avail_in_this_block -= copy_this; | |
| 248 | + from_copy += copy_this ; | |
| 249 | + len -= copy_this; | |
| 250 | + } | |
| 251 | + return ZIP_OK; | |
| 252 | +} | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | +/****************************************************************************/ | |
| 257 | + | |
| 258 | +#ifndef NO_ADDFILEINEXISTINGZIP | |
| 259 | +/* =========================================================================== | |
| 260 | + Inputs a long in LSB order to the given file | |
| 261 | + nbByte == 1, 2 or 4 (byte, short or long) | |
| 262 | +*/ | |
| 263 | + | |
| 264 | +local int ziplocal_putValue OF((const zlib_filefunc_def* pzlib_filefunc_def, | |
| 265 | + voidpf filestream, uLong x, int nbByte)); | |
| 266 | +local int ziplocal_putValue (pzlib_filefunc_def, filestream, x, nbByte) | |
| 267 | + const zlib_filefunc_def* pzlib_filefunc_def; | |
| 268 | + voidpf filestream; | |
| 269 | + uLong x; | |
| 270 | + int nbByte; | |
| 271 | +{ | |
| 272 | + unsigned char buf[4]; | |
| 273 | + int n; | |
| 274 | + for (n = 0; n < nbByte; n++) | |
| 275 | + { | |
| 276 | + buf[n] = (unsigned char)(x & 0xff); | |
| 277 | + x >>= 8; | |
| 278 | + } | |
| 279 | + if (x != 0) | |
| 280 | + { /* data overflow - hack for ZIP64 (X Roche) */ | |
| 281 | + for (n = 0; n < nbByte; n++) | |
| 282 | + { | |
| 283 | + buf[n] = 0xff; | |
| 284 | + } | |
| 285 | + } | |
| 286 | + | |
| 287 | + if (ZWRITE(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte) | |
| 288 | + return ZIP_ERRNO; | |
| 289 | + else | |
| 290 | + return ZIP_OK; | |
| 291 | +} | |
| 292 | + | |
| 293 | +local void ziplocal_putValue_inmemory OF((void* dest, uLong x, int nbByte)); | |
| 294 | +local void ziplocal_putValue_inmemory (dest, x, nbByte) | |
| 295 | + void* dest; | |
| 296 | + uLong x; | |
| 297 | + int nbByte; | |
| 298 | +{ | |
| 299 | + unsigned char* buf=(unsigned char*)dest; | |
| 300 | + int n; | |
| 301 | + for (n = 0; n < nbByte; n++) { | |
| 302 | + buf[n] = (unsigned char)(x & 0xff); | |
| 303 | + x >>= 8; | |
| 304 | + } | |
| 305 | + | |
| 306 | + if (x != 0) | |
| 307 | + { /* data overflow - hack for ZIP64 */ | |
| 308 | + for (n = 0; n < nbByte; n++) | |
| 309 | + { | |
| 310 | + buf[n] = 0xff; | |
| 311 | + } | |
| 312 | + } | |
| 313 | +} | |
| 314 | + | |
| 315 | +/****************************************************************************/ | |
| 316 | + | |
| 317 | + | |
| 318 | +local uLong ziplocal_TmzDateToDosDate(ptm,dosDate) | |
| 319 | + const tm_zip* ptm; | |
| 320 | + uLong dosDate; | |
| 321 | +{ | |
| 322 | + uLong year = (uLong)ptm->tm_year; | |
| 323 | + if (year>1980) | |
| 324 | + year-=1980; | |
| 325 | + else if (year>80) | |
| 326 | + year-=80; | |
| 327 | + return | |
| 328 | + (uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) | | |
| 329 | + ((ptm->tm_sec/2) + (32* ptm->tm_min) + (2048 * (uLong)ptm->tm_hour)); | |
| 330 | +} | |
| 331 | + | |
| 332 | + | |
| 333 | +/****************************************************************************/ | |
| 334 | + | |
| 335 | +local int ziplocal_getByte OF(( | |
| 336 | + const zlib_filefunc_def* pzlib_filefunc_def, | |
| 337 | + voidpf filestream, | |
| 338 | + int *pi)); | |
| 339 | + | |
| 340 | +local int ziplocal_getByte(pzlib_filefunc_def,filestream,pi) | |
| 341 | + const zlib_filefunc_def* pzlib_filefunc_def; | |
| 342 | + voidpf filestream; | |
| 343 | + int *pi; | |
| 344 | +{ | |
| 345 | + unsigned char c; | |
| 346 | + int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1); | |
| 347 | + if (err==1) | |
| 348 | + { | |
| 349 | + *pi = (int)c; | |
| 350 | + return ZIP_OK; | |
| 351 | + } | |
| 352 | + else | |
| 353 | + { | |
| 354 | + if (ZERROR(*pzlib_filefunc_def,filestream)) | |
| 355 | + return ZIP_ERRNO; | |
| 356 | + else | |
| 357 | + return ZIP_EOF; | |
| 358 | + } | |
| 359 | +} | |
| 360 | + | |
| 361 | + | |
| 362 | +/* =========================================================================== | |
| 363 | + Reads a long in LSB order from the given gz_stream. Sets | |
| 364 | +*/ | |
| 365 | +local int ziplocal_getShort OF(( | |
| 366 | + const zlib_filefunc_def* pzlib_filefunc_def, | |
| 367 | + voidpf filestream, | |
| 368 | + uLong *pX)); | |
| 369 | + | |
| 370 | +local int ziplocal_getShort (pzlib_filefunc_def,filestream,pX) | |
| 371 | + const zlib_filefunc_def* pzlib_filefunc_def; | |
| 372 | + voidpf filestream; | |
| 373 | + uLong *pX; | |
| 374 | +{ | |
| 375 | + uLong x ; | |
| 376 | + int i; | |
| 377 | + int err; | |
| 378 | + | |
| 379 | + err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); | |
| 380 | + x = (uLong)i; | |
| 381 | + | |
| 382 | + if (err==ZIP_OK) | |
| 383 | + err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); | |
| 384 | + x += ((uLong)i)<<8; | |
| 385 | + | |
| 386 | + if (err==ZIP_OK) | |
| 387 | + *pX = x; | |
| 388 | + else | |
| 389 | + *pX = 0; | |
| 390 | + return err; | |
| 391 | +} | |
| 392 | + | |
| 393 | +local int ziplocal_getLong OF(( | |
| 394 | + const zlib_filefunc_def* pzlib_filefunc_def, | |
| 395 | + voidpf filestream, | |
| 396 | + uLong *pX)); | |
| 397 | + | |
| 398 | +local int ziplocal_getLong (pzlib_filefunc_def,filestream,pX) | |
| 399 | + const zlib_filefunc_def* pzlib_filefunc_def; | |
| 400 | + voidpf filestream; | |
| 401 | + uLong *pX; | |
| 402 | +{ | |
| 403 | + uLong x ; | |
| 404 | + int i; | |
| 405 | + int err; | |
| 406 | + | |
| 407 | + err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); | |
| 408 | + x = (uLong)i; | |
| 409 | + | |
| 410 | + if (err==ZIP_OK) | |
| 411 | + err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); | |
| 412 | + x += ((uLong)i)<<8; | |
| 413 | + | |
| 414 | + if (err==ZIP_OK) | |
| 415 | + err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); | |
| 416 | + x += ((uLong)i)<<16; | |
| 417 | + | |
| 418 | + if (err==ZIP_OK) | |
| 419 | + err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); | |
| 420 | + x += ((uLong)i)<<24; | |
| 421 | + | |
| 422 | + if (err==ZIP_OK) | |
| 423 | + *pX = x; | |
| 424 | + else | |
| 425 | + *pX = 0; | |
| 426 | + return err; | |
| 427 | +} | |
| 428 | + | |
| 429 | +#ifndef BUFREADCOMMENT | |
| 430 | +#define BUFREADCOMMENT (0x400) | |
| 431 | +#endif | |
| 432 | +/* | |
| 433 | + Locate the Central directory of a zipfile (at the end, just before | |
| 434 | + the global comment) | |
| 435 | +*/ | |
| 436 | +local uLong ziplocal_SearchCentralDir OF(( | |
| 437 | + const zlib_filefunc_def* pzlib_filefunc_def, | |
| 438 | + voidpf filestream)); | |
| 439 | + | |
| 440 | +local uLong ziplocal_SearchCentralDir(pzlib_filefunc_def,filestream) | |
| 441 | + const zlib_filefunc_def* pzlib_filefunc_def; | |
| 442 | + voidpf filestream; | |
| 443 | +{ | |
| 444 | + unsigned char* buf; | |
| 445 | + uLong uSizeFile; | |
| 446 | + uLong uBackRead; | |
| 447 | + uLong uMaxBack=0xffff; /* maximum size of global comment */ | |
| 448 | + uLong uPosFound=0; | |
| 449 | + | |
| 450 | + if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) | |
| 451 | + return 0; | |
| 452 | + | |
| 453 | + | |
| 454 | + uSizeFile = ZTELL(*pzlib_filefunc_def,filestream); | |
| 455 | + | |
| 456 | + if (uMaxBack>uSizeFile) | |
| 457 | + uMaxBack = uSizeFile; | |
| 458 | + | |
| 459 | + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); | |
| 460 | + if (buf==NULL) | |
| 461 | + return 0; | |
| 462 | + | |
| 463 | + uBackRead = 4; | |
| 464 | + while (uBackRead<uMaxBack) | |
| 465 | + { | |
| 466 | + uLong uReadSize,uReadPos ; | |
| 467 | + int i; | |
| 468 | + if (uBackRead+BUFREADCOMMENT>uMaxBack) | |
| 469 | + uBackRead = uMaxBack; | |
| 470 | + else | |
| 471 | + uBackRead+=BUFREADCOMMENT; | |
| 472 | + uReadPos = uSizeFile-uBackRead ; | |
| 473 | + | |
| 474 | + uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? | |
| 475 | + (BUFREADCOMMENT+4) : (uSizeFile-uReadPos); | |
| 476 | + if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) | |
| 477 | + break; | |
| 478 | + | |
| 479 | + if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) | |
| 480 | + break; | |
| 481 | + | |
| 482 | + for (i=(int)uReadSize-3; (i--)>0;) | |
| 483 | + if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && | |
| 484 | + ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) | |
| 485 | + { | |
| 486 | + uPosFound = uReadPos+i; | |
| 487 | + break; | |
| 488 | + } | |
| 489 | + | |
| 490 | + if (uPosFound!=0) | |
| 491 | + break; | |
| 492 | + } | |
| 493 | + TRYFREE(buf); | |
| 494 | + return uPosFound; | |
| 495 | +} | |
| 496 | +#endif /* !NO_ADDFILEINEXISTINGZIP*/ | |
| 497 | + | |
| 498 | +/************************************************************/ | |
| 499 | +extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc_def) | |
| 500 | + const char *pathname; | |
| 501 | + int append; | |
| 502 | + zipcharpc* globalcomment; | |
| 503 | + zlib_filefunc_def* pzlib_filefunc_def; | |
| 504 | +{ | |
| 505 | + zip_internal ziinit; | |
| 506 | + zip_internal* zi; | |
| 507 | + int err=ZIP_OK; | |
| 508 | + | |
| 509 | + | |
| 510 | + if (pzlib_filefunc_def==NULL) | |
| 511 | + fill_fopen_filefunc(&ziinit.z_filefunc); | |
| 512 | + else | |
| 513 | + ziinit.z_filefunc = *pzlib_filefunc_def; | |
| 514 | + | |
| 515 | + ziinit.filestream = (*(ziinit.z_filefunc.zopen_file)) | |
| 516 | + (ziinit.z_filefunc.opaque, | |
| 517 | + pathname, | |
| 518 | + (append == APPEND_STATUS_CREATE) ? | |
| 519 | + (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) : | |
| 520 | + (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING)); | |
| 521 | + | |
| 522 | + if (ziinit.filestream == NULL) | |
| 523 | + return NULL; | |
| 524 | + ziinit.begin_pos = ZTELL(ziinit.z_filefunc,ziinit.filestream); | |
| 525 | + ziinit.in_opened_file_inzip = 0; | |
| 526 | + ziinit.ci.stream_initialised = 0; | |
| 527 | + ziinit.number_entry = 0; | |
| 528 | + ziinit.add_position_when_writting_offset = 0; | |
| 529 | + init_linkedlist(&(ziinit.central_dir)); | |
| 530 | + | |
| 531 | + | |
| 532 | + zi = (zip_internal*)ALLOC(sizeof(zip_internal)); | |
| 533 | + if (zi==NULL) | |
| 534 | + { | |
| 535 | + ZCLOSE(ziinit.z_filefunc,ziinit.filestream); | |
| 536 | + return NULL; | |
| 537 | + } | |
| 538 | + | |
| 539 | + /* now we add file in a zipfile */ | |
| 540 | +# ifndef NO_ADDFILEINEXISTINGZIP | |
| 541 | + ziinit.globalcomment = NULL; | |
| 542 | + if (append == APPEND_STATUS_ADDINZIP) | |
| 543 | + { | |
| 544 | + uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ | |
| 545 | + | |
| 546 | + uLong size_central_dir; /* size of the central directory */ | |
| 547 | + uLong offset_central_dir; /* offset of start of central directory */ | |
| 548 | + uLong central_pos,uL; | |
| 549 | + | |
| 550 | + uLong number_disk; /* number of the current dist, used for | |
| 551 | + spaning ZIP, unsupported, always 0*/ | |
| 552 | + uLong number_disk_with_CD; /* number the the disk with central dir, used | |
| 553 | + for spaning ZIP, unsupported, always 0*/ | |
| 554 | + uLong number_entry; | |
| 555 | + uLong number_entry_CD; /* total number of entries in | |
| 556 | + the central dir | |
| 557 | + (same than number_entry on nospan) */ | |
| 558 | + uLong size_comment; | |
| 559 | + | |
| 560 | + central_pos = ziplocal_SearchCentralDir(&ziinit.z_filefunc,ziinit.filestream); | |
| 561 | + if (central_pos==0) | |
| 562 | + err=ZIP_ERRNO; | |
| 563 | + | |
| 564 | + if (ZSEEK(ziinit.z_filefunc, ziinit.filestream, | |
| 565 | + central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) | |
| 566 | + err=ZIP_ERRNO; | |
| 567 | + | |
| 568 | + /* the signature, already checked */ | |
| 569 | + if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&uL)!=ZIP_OK) | |
| 570 | + err=ZIP_ERRNO; | |
| 571 | + | |
| 572 | + /* number of this disk */ | |
| 573 | + if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_disk)!=ZIP_OK) | |
| 574 | + err=ZIP_ERRNO; | |
| 575 | + | |
| 576 | + /* number of the disk with the start of the central directory */ | |
| 577 | + if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_disk_with_CD)!=ZIP_OK) | |
| 578 | + err=ZIP_ERRNO; | |
| 579 | + | |
| 580 | + /* total number of entries in the central dir on this disk */ | |
| 581 | + if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_entry)!=ZIP_OK) | |
| 582 | + err=ZIP_ERRNO; | |
| 583 | + | |
| 584 | + /* total number of entries in the central dir */ | |
| 585 | + if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_entry_CD)!=ZIP_OK) | |
| 586 | + err=ZIP_ERRNO; | |
| 587 | + | |
| 588 | + if ((number_entry_CD!=number_entry) || | |
| 589 | + (number_disk_with_CD!=0) || | |
| 590 | + (number_disk!=0)) | |
| 591 | + err=ZIP_BADZIPFILE; | |
| 592 | + | |
| 593 | + /* size of the central directory */ | |
| 594 | + if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&size_central_dir)!=ZIP_OK) | |
| 595 | + err=ZIP_ERRNO; | |
| 596 | + | |
| 597 | + /* offset of start of central directory with respect to the | |
| 598 | + starting disk number */ | |
| 599 | + if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&offset_central_dir)!=ZIP_OK) | |
| 600 | + err=ZIP_ERRNO; | |
| 601 | + | |
| 602 | + /* zipfile global comment length */ | |
| 603 | + if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&size_comment)!=ZIP_OK) | |
| 604 | + err=ZIP_ERRNO; | |
| 605 | + | |
| 606 | + if ((central_pos<offset_central_dir+size_central_dir) && | |
| 607 | + (err==ZIP_OK)) | |
| 608 | + err=ZIP_BADZIPFILE; | |
| 609 | + | |
| 610 | + if (err!=ZIP_OK) | |
| 611 | + { | |
| 612 | + ZCLOSE(ziinit.z_filefunc, ziinit.filestream); | |
| 613 | + return NULL; | |
| 614 | + } | |
| 615 | + | |
| 616 | + if (size_comment>0) | |
| 617 | + { | |
| 618 | + ziinit.globalcomment = ALLOC(size_comment+1); | |
| 619 | + if (ziinit.globalcomment) | |
| 620 | + { | |
| 621 | + size_comment = ZREAD(ziinit.z_filefunc, ziinit.filestream,ziinit.globalcomment,size_comment); | |
| 622 | + ziinit.globalcomment[size_comment]=0; | |
| 623 | + } | |
| 624 | + } | |
| 625 | + | |
| 626 | + byte_before_the_zipfile = central_pos - | |
| 627 | + (offset_central_dir+size_central_dir); | |
| 628 | + ziinit.add_position_when_writting_offset = byte_before_the_zipfile; | |
| 629 | + | |
| 630 | + { | |
| 631 | + uLong size_central_dir_to_read = size_central_dir; | |
| 632 | + size_t buf_size = SIZEDATA_INDATABLOCK; | |
| 633 | + void* buf_read = (void*)ALLOC(buf_size); | |
| 634 | + if (ZSEEK(ziinit.z_filefunc, ziinit.filestream, | |
| 635 | + offset_central_dir + byte_before_the_zipfile, | |
| 636 | + ZLIB_FILEFUNC_SEEK_SET) != 0) | |
| 637 | + err=ZIP_ERRNO; | |
| 638 | + | |
| 639 | + while ((size_central_dir_to_read>0) && (err==ZIP_OK)) | |
| 640 | + { | |
| 641 | + uLong read_this = SIZEDATA_INDATABLOCK; | |
| 642 | + if (read_this > size_central_dir_to_read) | |
| 643 | + read_this = size_central_dir_to_read; | |
| 644 | + if (ZREAD(ziinit.z_filefunc, ziinit.filestream,buf_read,read_this) != read_this) | |
| 645 | + err=ZIP_ERRNO; | |
| 646 | + | |
| 647 | + if (err==ZIP_OK) | |
| 648 | + err = add_data_in_datablock(&ziinit.central_dir,buf_read, | |
| 649 | + (uLong)read_this); | |
| 650 | + size_central_dir_to_read-=read_this; | |
| 651 | + } | |
| 652 | + TRYFREE(buf_read); | |
| 653 | + } | |
| 654 | + ziinit.begin_pos = byte_before_the_zipfile; | |
| 655 | + ziinit.number_entry = number_entry_CD; | |
| 656 | + | |
| 657 | + if (ZSEEK(ziinit.z_filefunc, ziinit.filestream, | |
| 658 | + offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0) | |
| 659 | + err=ZIP_ERRNO; | |
| 660 | + } | |
| 661 | + | |
| 662 | + if (globalcomment) | |
| 663 | + { | |
| 664 | + *globalcomment = ziinit.globalcomment; | |
| 665 | + } | |
| 666 | +# endif /* !NO_ADDFILEINEXISTINGZIP*/ | |
| 667 | + | |
| 668 | + if (err != ZIP_OK) | |
| 669 | + { | |
| 670 | +# ifndef NO_ADDFILEINEXISTINGZIP | |
| 671 | + TRYFREE(ziinit.globalcomment); | |
| 672 | +# endif /* !NO_ADDFILEINEXISTINGZIP*/ | |
| 673 | + TRYFREE(zi); | |
| 674 | + return NULL; | |
| 675 | + } | |
| 676 | + else | |
| 677 | + { | |
| 678 | + *zi = ziinit; | |
| 679 | + return (zipFile)zi; | |
| 680 | + } | |
| 681 | +} | |
| 682 | + | |
| 683 | +extern zipFile ZEXPORT zipOpen (pathname, append) | |
| 684 | + const char *pathname; | |
| 685 | + int append; | |
| 686 | +{ | |
| 687 | + return zipOpen2(pathname,append,NULL,NULL); | |
| 688 | +} | |
| 689 | + | |
| 690 | +extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi, | |
| 691 | + extrafield_local, size_extrafield_local, | |
| 692 | + extrafield_global, size_extrafield_global, | |
| 693 | + comment, method, level, raw, | |
| 694 | + windowBits, memLevel, strategy, | |
| 695 | + password, crcForCrypting) | |
| 696 | + zipFile file; | |
| 697 | + const char* filename; | |
| 698 | + const zip_fileinfo* zipfi; | |
| 699 | + const void* extrafield_local; | |
| 700 | + uInt size_extrafield_local; | |
| 701 | + const void* extrafield_global; | |
| 702 | + uInt size_extrafield_global; | |
| 703 | + const char* comment; | |
| 704 | + int method; | |
| 705 | + int level; | |
| 706 | + int raw; | |
| 707 | + int windowBits; | |
| 708 | + int memLevel; | |
| 709 | + int strategy; | |
| 710 | + const char* password; | |
| 711 | + uLong crcForCrypting; | |
| 712 | +{ | |
| 713 | + zip_internal* zi; | |
| 714 | + uInt size_filename; | |
| 715 | + uInt size_comment; | |
| 716 | + uInt i; | |
| 717 | + int err = ZIP_OK; | |
| 718 | + | |
| 719 | +# ifdef NOCRYPT | |
| 720 | + if (password != NULL) | |
| 721 | + return ZIP_PARAMERROR; | |
| 722 | +# endif | |
| 723 | + | |
| 724 | + if (file == NULL) | |
| 725 | + return ZIP_PARAMERROR; | |
| 726 | + if ((method!=0) && (method!=Z_DEFLATED)) | |
| 727 | + return ZIP_PARAMERROR; | |
| 728 | + | |
| 729 | + zi = (zip_internal*)file; | |
| 730 | + | |
| 731 | + if (zi->in_opened_file_inzip == 1) | |
| 732 | + { | |
| 733 | + err = zipCloseFileInZip (file); | |
| 734 | + if (err != ZIP_OK) | |
| 735 | + return err; | |
| 736 | + } | |
| 737 | + | |
| 738 | + | |
| 739 | + if (filename==NULL) | |
| 740 | + filename="-"; | |
| 741 | + | |
| 742 | + if (comment==NULL) | |
| 743 | + size_comment = 0; | |
| 744 | + else | |
| 745 | + size_comment = (uInt)strlen(comment); | |
| 746 | + | |
| 747 | + size_filename = (uInt)strlen(filename); | |
| 748 | + | |
| 749 | + if (zipfi == NULL) | |
| 750 | + zi->ci.dosDate = 0; | |
| 751 | + else | |
| 752 | + { | |
| 753 | + if (zipfi->dosDate != 0) | |
| 754 | + zi->ci.dosDate = zipfi->dosDate; | |
| 755 | + else zi->ci.dosDate = ziplocal_TmzDateToDosDate(&zipfi->tmz_date,zipfi->dosDate); | |
| 756 | + } | |
| 757 | + | |
| 758 | + zi->ci.flag = 0; | |
| 759 | + if ((level==8) || (level==9)) | |
| 760 | + zi->ci.flag |= 2; | |
| 761 | + if ((level==2)) | |
| 762 | + zi->ci.flag |= 4; | |
| 763 | + if ((level==1)) | |
| 764 | + zi->ci.flag |= 6; | |
| 765 | + if (password != NULL) | |
| 766 | + zi->ci.flag |= 1; | |
| 767 | + | |
| 768 | + zi->ci.crc32 = 0; | |
| 769 | + zi->ci.method = method; | |
| 770 | + zi->ci.encrypt = 0; | |
| 771 | + zi->ci.stream_initialised = 0; | |
| 772 | + zi->ci.pos_in_buffered_data = 0; | |
| 773 | + zi->ci.raw = raw; | |
| 774 | + zi->ci.pos_local_header = ZTELL(zi->z_filefunc,zi->filestream) ; | |
| 775 | + zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + | |
| 776 | + size_extrafield_global + size_comment; | |
| 777 | + zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader); | |
| 778 | + | |
| 779 | + ziplocal_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4); | |
| 780 | + /* version info */ | |
| 781 | + ziplocal_putValue_inmemory(zi->ci.central_header+4,(uLong)VERSIONMADEBY,2); | |
| 782 | + ziplocal_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2); | |
| 783 | + ziplocal_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2); | |
| 784 | + ziplocal_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2); | |
| 785 | + ziplocal_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4); | |
| 786 | + ziplocal_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/ | |
| 787 | + ziplocal_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/ | |
| 788 | + ziplocal_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/ | |
| 789 | + ziplocal_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2); | |
| 790 | + ziplocal_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2); | |
| 791 | + ziplocal_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2); | |
| 792 | + ziplocal_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/ | |
| 793 | + | |
| 794 | + if (zipfi==NULL) | |
| 795 | + ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2); | |
| 796 | + else | |
| 797 | + ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2); | |
| 798 | + | |
| 799 | + if (zipfi==NULL) | |
| 800 | + ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4); | |
| 801 | + else | |
| 802 | + ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4); | |
| 803 | + | |
| 804 | + ziplocal_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header- zi->add_position_when_writting_offset,4); | |
| 805 | + | |
| 806 | + for (i=0;i<size_filename;i++) | |
| 807 | + *(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i); | |
| 808 | + | |
| 809 | + for (i=0;i<size_extrafield_global;i++) | |
| 810 | + *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+i) = | |
| 811 | + *(((const char*)extrafield_global)+i); | |
| 812 | + | |
| 813 | + for (i=0;i<size_comment;i++) | |
| 814 | + *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+ | |
| 815 | + size_extrafield_global+i) = *(comment+i); | |
| 816 | + if (zi->ci.central_header == NULL) | |
| 817 | + return ZIP_INTERNALERROR; | |
| 818 | + | |
| 819 | + /* write the local header */ | |
| 820 | + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC,4); | |
| 821 | + | |
| 822 | + if (err==ZIP_OK) | |
| 823 | + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);/* version needed to extract */ | |
| 824 | + if (err==ZIP_OK) | |
| 825 | + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2); | |
| 826 | + | |
| 827 | + if (err==ZIP_OK) | |
| 828 | + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2); | |
| 829 | + | |
| 830 | + if (err==ZIP_OK) | |
| 831 | + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4); | |
| 832 | + | |
| 833 | + if (err==ZIP_OK) | |
| 834 | + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */ | |
| 835 | + if (err==ZIP_OK) | |
| 836 | + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* compressed size, unknown */ | |
| 837 | + if (err==ZIP_OK) | |
| 838 | + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */ | |
| 839 | + | |
| 840 | + if (err==ZIP_OK) | |
| 841 | + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2); | |
| 842 | + | |
| 843 | + if (err==ZIP_OK) | |
| 844 | + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield_local,2); | |
| 845 | + | |
| 846 | + if ((err==ZIP_OK) && (size_filename>0)) | |
| 847 | + if (ZWRITE(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename) | |
| 848 | + err = ZIP_ERRNO; | |
| 849 | + | |
| 850 | + if ((err==ZIP_OK) && (size_extrafield_local>0)) | |
| 851 | + if (ZWRITE(zi->z_filefunc,zi->filestream,extrafield_local,size_extrafield_local) | |
| 852 | + !=size_extrafield_local) | |
| 853 | + err = ZIP_ERRNO; | |
| 854 | + | |
| 855 | + zi->ci.stream.avail_in = (uInt)0; | |
| 856 | + zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; | |
| 857 | + zi->ci.stream.next_out = zi->ci.buffered_data; | |
| 858 | + zi->ci.stream.total_in = 0; | |
| 859 | + zi->ci.stream.total_out = 0; | |
| 860 | + | |
| 861 | + if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) | |
| 862 | + { | |
| 863 | + zi->ci.stream.zalloc = (alloc_func)0; | |
| 864 | + zi->ci.stream.zfree = (free_func)0; | |
| 865 | + zi->ci.stream.opaque = (voidpf)0; | |
| 866 | + | |
| 867 | + if (windowBits>0) | |
| 868 | + windowBits = -windowBits; | |
| 869 | + | |
| 870 | + err = deflateInit2(&zi->ci.stream, level, | |
| 871 | + Z_DEFLATED, windowBits, memLevel, strategy); | |
| 872 | + | |
| 873 | + if (err==Z_OK) | |
| 874 | + zi->ci.stream_initialised = 1; | |
| 875 | + } | |
| 876 | +# ifndef NOCRYPT | |
| 877 | + zi->ci.crypt_header_size = 0; | |
| 878 | + if ((err==Z_OK) && (password != NULL)) | |
| 879 | + { | |
| 880 | + unsigned char bufHead[RAND_HEAD_LEN]; | |
| 881 | + unsigned int sizeHead; | |
| 882 | + zi->ci.encrypt = 1; | |
| 883 | + zi->ci.pcrc_32_tab = get_crc_table(); | |
| 884 | + /*init_keys(password,zi->ci.keys,zi->ci.pcrc_32_tab);*/ | |
| 885 | + | |
| 886 | + sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting); | |
| 887 | + zi->ci.crypt_header_size = sizeHead; | |
| 888 | + | |
| 889 | + if (ZWRITE(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead) | |
| 890 | + err = ZIP_ERRNO; | |
| 891 | + } | |
| 892 | +# endif | |
| 893 | + | |
| 894 | + if (err==Z_OK) | |
| 895 | + zi->in_opened_file_inzip = 1; | |
| 896 | + return err; | |
| 897 | +} | |
| 898 | + | |
| 899 | +extern int ZEXPORT zipOpenNewFileInZip2(file, filename, zipfi, | |
| 900 | + extrafield_local, size_extrafield_local, | |
| 901 | + extrafield_global, size_extrafield_global, | |
| 902 | + comment, method, level, raw) | |
| 903 | + zipFile file; | |
| 904 | + const char* filename; | |
| 905 | + const zip_fileinfo* zipfi; | |
| 906 | + const void* extrafield_local; | |
| 907 | + uInt size_extrafield_local; | |
| 908 | + const void* extrafield_global; | |
| 909 | + uInt size_extrafield_global; | |
| 910 | + const char* comment; | |
| 911 | + int method; | |
| 912 | + int level; | |
| 913 | + int raw; | |
| 914 | +{ | |
| 915 | + return zipOpenNewFileInZip3 (file, filename, zipfi, | |
| 916 | + extrafield_local, size_extrafield_local, | |
| 917 | + extrafield_global, size_extrafield_global, | |
| 918 | + comment, method, level, raw, | |
| 919 | + -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, | |
| 920 | + NULL, 0); | |
| 921 | +} | |
| 922 | + | |
| 923 | +extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi, | |
| 924 | + extrafield_local, size_extrafield_local, | |
| 925 | + extrafield_global, size_extrafield_global, | |
| 926 | + comment, method, level) | |
| 927 | + zipFile file; | |
| 928 | + const char* filename; | |
| 929 | + const zip_fileinfo* zipfi; | |
| 930 | + const void* extrafield_local; | |
| 931 | + uInt size_extrafield_local; | |
| 932 | + const void* extrafield_global; | |
| 933 | + uInt size_extrafield_global; | |
| 934 | + const char* comment; | |
| 935 | + int method; | |
| 936 | + int level; | |
| 937 | +{ | |
| 938 | + return zipOpenNewFileInZip2 (file, filename, zipfi, | |
| 939 | + extrafield_local, size_extrafield_local, | |
| 940 | + extrafield_global, size_extrafield_global, | |
| 941 | + comment, method, level, 0); | |
| 942 | +} | |
| 943 | + | |
| 944 | +local int zipFlushWriteBuffer(zi) | |
| 945 | + zip_internal* zi; | |
| 946 | +{ | |
| 947 | + int err=ZIP_OK; | |
| 948 | + | |
| 949 | + if (zi->ci.encrypt != 0) | |
| 950 | + { | |
| 951 | +#ifndef NOCRYPT | |
| 952 | + uInt i; | |
| 953 | + int t; | |
| 954 | + for (i=0;i<zi->ci.pos_in_buffered_data;i++) | |
| 955 | + zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab, | |
| 956 | + zi->ci.buffered_data[i],t); | |
| 957 | +#endif | |
| 958 | + } | |
| 959 | + if (ZWRITE(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,zi->ci.pos_in_buffered_data) | |
| 960 | + !=zi->ci.pos_in_buffered_data) | |
| 961 | + err = ZIP_ERRNO; | |
| 962 | + zi->ci.pos_in_buffered_data = 0; | |
| 963 | + return err; | |
| 964 | +} | |
| 965 | + | |
| 966 | +extern int ZEXPORT zipWriteInFileInZip (file, buf, len) | |
| 967 | + zipFile file; | |
| 968 | + const void* buf; | |
| 969 | + unsigned len; | |
| 970 | +{ | |
| 971 | + zip_internal* zi; | |
| 972 | + int err=ZIP_OK; | |
| 973 | + | |
| 974 | + if (file == NULL) | |
| 975 | + return ZIP_PARAMERROR; | |
| 976 | + zi = (zip_internal*)file; | |
| 977 | + | |
| 978 | + if (zi->in_opened_file_inzip == 0) | |
| 979 | + return ZIP_PARAMERROR; | |
| 980 | + | |
| 981 | + zi->ci.stream.next_in = (void*)buf; | |
| 982 | + zi->ci.stream.avail_in = len; | |
| 983 | + zi->ci.crc32 = crc32(zi->ci.crc32,buf,len); | |
| 984 | + | |
| 985 | + while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0)) | |
| 986 | + { | |
| 987 | + if (zi->ci.stream.avail_out == 0) | |
| 988 | + { | |
| 989 | + if (zipFlushWriteBuffer(zi) == ZIP_ERRNO) | |
| 990 | + err = ZIP_ERRNO; | |
| 991 | + zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; | |
| 992 | + zi->ci.stream.next_out = zi->ci.buffered_data; | |
| 993 | + } | |
| 994 | + | |
| 995 | + | |
| 996 | + if(err != ZIP_OK) | |
| 997 | + break; | |
| 998 | + | |
| 999 | + if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) | |
| 1000 | + { | |
| 1001 | + uLong uTotalOutBefore = zi->ci.stream.total_out; | |
| 1002 | + err=deflate(&zi->ci.stream, Z_NO_FLUSH); | |
| 1003 | + zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; | |
| 1004 | + | |
| 1005 | + } | |
| 1006 | + else | |
| 1007 | + { | |
| 1008 | + uInt copy_this,i; | |
| 1009 | + if (zi->ci.stream.avail_in < zi->ci.stream.avail_out) | |
| 1010 | + copy_this = zi->ci.stream.avail_in; | |
| 1011 | + else | |
| 1012 | + copy_this = zi->ci.stream.avail_out; | |
| 1013 | + for (i=0;i<copy_this;i++) | |
| 1014 | + *(((char*)zi->ci.stream.next_out)+i) = | |
| 1015 | + *(((const char*)zi->ci.stream.next_in)+i); | |
| 1016 | + { | |
| 1017 | + zi->ci.stream.avail_in -= copy_this; | |
| 1018 | + zi->ci.stream.avail_out-= copy_this; | |
| 1019 | + zi->ci.stream.next_in+= copy_this; | |
| 1020 | + zi->ci.stream.next_out+= copy_this; | |
| 1021 | + zi->ci.stream.total_in+= copy_this; | |
| 1022 | + zi->ci.stream.total_out+= copy_this; | |
| 1023 | + zi->ci.pos_in_buffered_data += copy_this; | |
| 1024 | + } | |
| 1025 | + } | |
| 1026 | + } | |
| 1027 | + | |
| 1028 | + return err; | |
| 1029 | +} | |
| 1030 | + | |
| 1031 | +extern int ZEXPORT zipCloseFileInZipRaw (file, uncompressed_size, crc32) | |
| 1032 | + zipFile file; | |
| 1033 | + uLong uncompressed_size; | |
| 1034 | + uLong crc32; | |
| 1035 | +{ | |
| 1036 | + zip_internal* zi; | |
| 1037 | + uLong compressed_size; | |
| 1038 | + int err=ZIP_OK; | |
| 1039 | + | |
| 1040 | + if (file == NULL) | |
| 1041 | + return ZIP_PARAMERROR; | |
| 1042 | + zi = (zip_internal*)file; | |
| 1043 | + | |
| 1044 | + if (zi->in_opened_file_inzip == 0) | |
| 1045 | + return ZIP_PARAMERROR; | |
| 1046 | + zi->ci.stream.avail_in = 0; | |
| 1047 | + | |
| 1048 | + if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) | |
| 1049 | + while (err==ZIP_OK) | |
| 1050 | + { | |
| 1051 | + uLong uTotalOutBefore; | |
| 1052 | + if (zi->ci.stream.avail_out == 0) | |
| 1053 | + { | |
| 1054 | + if (zipFlushWriteBuffer(zi) == ZIP_ERRNO) | |
| 1055 | + err = ZIP_ERRNO; | |
| 1056 | + zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; | |
| 1057 | + zi->ci.stream.next_out = zi->ci.buffered_data; | |
| 1058 | + } | |
| 1059 | + uTotalOutBefore = zi->ci.stream.total_out; | |
| 1060 | + err=deflate(&zi->ci.stream, Z_FINISH); | |
| 1061 | + zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; | |
| 1062 | + } | |
| 1063 | + | |
| 1064 | + if (err==Z_STREAM_END) | |
| 1065 | + err=ZIP_OK; /* this is normal */ | |
| 1066 | + | |
| 1067 | + if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK)) | |
| 1068 | + if (zipFlushWriteBuffer(zi)==ZIP_ERRNO) | |
| 1069 | + err = ZIP_ERRNO; | |
| 1070 | + | |
| 1071 | + if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) | |
| 1072 | + { | |
| 1073 | + err=deflateEnd(&zi->ci.stream); | |
| 1074 | + zi->ci.stream_initialised = 0; | |
| 1075 | + } | |
| 1076 | + | |
| 1077 | + if (!zi->ci.raw) | |
| 1078 | + { | |
| 1079 | + crc32 = (uLong)zi->ci.crc32; | |
| 1080 | + uncompressed_size = (uLong)zi->ci.stream.total_in; | |
| 1081 | + } | |
| 1082 | + compressed_size = (uLong)zi->ci.stream.total_out; | |
| 1083 | +# ifndef NOCRYPT | |
| 1084 | + compressed_size += zi->ci.crypt_header_size; | |
| 1085 | +# endif | |
| 1086 | + | |
| 1087 | + ziplocal_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/ | |
| 1088 | + ziplocal_putValue_inmemory(zi->ci.central_header+20, | |
| 1089 | + compressed_size,4); /*compr size*/ | |
| 1090 | + if (zi->ci.stream.data_type == Z_ASCII) | |
| 1091 | + ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2); | |
| 1092 | + ziplocal_putValue_inmemory(zi->ci.central_header+24, | |
| 1093 | + uncompressed_size,4); /*uncompr size*/ | |
| 1094 | + | |
| 1095 | + if (err==ZIP_OK) | |
| 1096 | + err = add_data_in_datablock(&zi->central_dir,zi->ci.central_header, | |
| 1097 | + (uLong)zi->ci.size_centralheader); | |
| 1098 | + free(zi->ci.central_header); | |
| 1099 | + | |
| 1100 | + if (err==ZIP_OK) | |
| 1101 | + { | |
| 1102 | + long cur_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream); | |
| 1103 | + if (ZSEEK(zi->z_filefunc,zi->filestream, | |
| 1104 | + zi->ci.pos_local_header + 14,ZLIB_FILEFUNC_SEEK_SET)!=0) | |
| 1105 | + err = ZIP_ERRNO; | |
| 1106 | + | |
| 1107 | + if (err==ZIP_OK) | |
| 1108 | + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */ | |
| 1109 | + | |
| 1110 | + if (err==ZIP_OK) /* compressed size, unknown */ | |
| 1111 | + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4); | |
| 1112 | + | |
| 1113 | + if (err==ZIP_OK) /* uncompressed size, unknown */ | |
| 1114 | + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4); | |
| 1115 | + | |
| 1116 | + if (ZSEEK(zi->z_filefunc,zi->filestream, | |
| 1117 | + cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0) | |
| 1118 | + err = ZIP_ERRNO; | |
| 1119 | + } | |
| 1120 | + | |
| 1121 | + zi->number_entry ++; | |
| 1122 | + zi->in_opened_file_inzip = 0; | |
| 1123 | + | |
| 1124 | + return err; | |
| 1125 | +} | |
| 1126 | + | |
| 1127 | +extern int ZEXPORT zipCloseFileInZip (file) | |
| 1128 | + zipFile file; | |
| 1129 | +{ | |
| 1130 | + return zipCloseFileInZipRaw (file,0,0); | |
| 1131 | +} | |
| 1132 | + | |
| 1133 | +extern int ZEXPORT zipClose (file, global_comment) | |
| 1134 | + zipFile file; | |
| 1135 | + const char* global_comment; | |
| 1136 | +{ | |
| 1137 | + zip_internal* zi; | |
| 1138 | + int err = 0; | |
| 1139 | + uLong size_centraldir = 0; | |
| 1140 | + uLong centraldir_pos_inzip; | |
| 1141 | + uInt size_global_comment; | |
| 1142 | + if (file == NULL) | |
| 1143 | + return ZIP_PARAMERROR; | |
| 1144 | + zi = (zip_internal*)file; | |
| 1145 | + | |
| 1146 | + if (zi->in_opened_file_inzip == 1) | |
| 1147 | + { | |
| 1148 | + err = zipCloseFileInZip (file); | |
| 1149 | + } | |
| 1150 | + | |
| 1151 | +#ifndef NO_ADDFILEINEXISTINGZIP | |
| 1152 | + if (global_comment==NULL) | |
| 1153 | + global_comment = zi->globalcomment; | |
| 1154 | +#endif | |
| 1155 | + if (global_comment==NULL) | |
| 1156 | + size_global_comment = 0; | |
| 1157 | + else | |
| 1158 | + size_global_comment = (uInt)strlen(global_comment); | |
| 1159 | + | |
| 1160 | + centraldir_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream); | |
| 1161 | + if (err==ZIP_OK) | |
| 1162 | + { | |
| 1163 | + linkedlist_datablock_internal* ldi = zi->central_dir.first_block ; | |
| 1164 | + while (ldi!=NULL) | |
| 1165 | + { | |
| 1166 | + if ((err==ZIP_OK) && (ldi->filled_in_this_block>0)) | |
| 1167 | + if (ZWRITE(zi->z_filefunc,zi->filestream, | |
| 1168 | + ldi->data,ldi->filled_in_this_block) | |
| 1169 | + !=ldi->filled_in_this_block ) | |
| 1170 | + err = ZIP_ERRNO; | |
| 1171 | + | |
| 1172 | + size_centraldir += ldi->filled_in_this_block; | |
| 1173 | + ldi = ldi->next_datablock; | |
| 1174 | + } | |
| 1175 | + } | |
| 1176 | + free_datablock(zi->central_dir.first_block); | |
| 1177 | + | |
| 1178 | + if (err==ZIP_OK) /* Magic End */ | |
| 1179 | + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4); | |
| 1180 | + | |
| 1181 | + if (err==ZIP_OK) /* number of this disk */ | |
| 1182 | + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2); | |
| 1183 | + | |
| 1184 | + if (err==ZIP_OK) /* number of the disk with the start of the central directory */ | |
| 1185 | + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2); | |
| 1186 | + | |
| 1187 | + if (err==ZIP_OK) /* total number of entries in the central dir on this disk */ | |
| 1188 | + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2); | |
| 1189 | + | |
| 1190 | + if (err==ZIP_OK) /* total number of entries in the central dir */ | |
| 1191 | + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2); | |
| 1192 | + | |
| 1193 | + if (err==ZIP_OK) /* size of the central directory */ | |
| 1194 | + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4); | |
| 1195 | + | |
| 1196 | + if (err==ZIP_OK) /* offset of start of central directory with respect to the | |
| 1197 | + starting disk number */ | |
| 1198 | + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream, | |
| 1199 | + (uLong)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4); | |
| 1200 | + | |
| 1201 | + if (err==ZIP_OK) /* zipfile comment length */ | |
| 1202 | + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2); | |
| 1203 | + | |
| 1204 | + if ((err==ZIP_OK) && (size_global_comment>0)) | |
| 1205 | + if (ZWRITE(zi->z_filefunc,zi->filestream, | |
| 1206 | + global_comment,size_global_comment) != size_global_comment) | |
| 1207 | + err = ZIP_ERRNO; | |
| 1208 | + | |
| 1209 | + if (ZCLOSE(zi->z_filefunc,zi->filestream) != 0) | |
| 1210 | + if (err == ZIP_OK) | |
| 1211 | + err = ZIP_ERRNO; | |
| 1212 | + | |
| 1213 | +#ifndef NO_ADDFILEINEXISTINGZIP | |
| 1214 | + TRYFREE(zi->globalcomment); | |
| 1215 | +#endif | |
| 1216 | + TRYFREE(zi); | |
| 1217 | + | |
| 1218 | + return err; | |
| 1219 | +} |
| @@ -0,0 +1,1598 @@ | ||
| 1 | +/* unzip.c -- IO for uncompress .zip files using zlib | |
| 2 | + Version 1.01e, February 12th, 2005 | |
| 3 | + | |
| 4 | + Copyright (C) 1998-2005 Gilles Vollant | |
| 5 | + | |
| 6 | + Read unzip.h for more info | |
| 7 | +*/ | |
| 8 | + | |
| 9 | +/* Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of | |
| 10 | +compatibility with older software. The following is from the original crypt.c. Code | |
| 11 | +woven in by Terry Thorsen 1/2003. | |
| 12 | +*/ | |
| 13 | +/* | |
| 14 | + Copyright (c) 1990-2000 Info-ZIP. All rights reserved. | |
| 15 | + | |
| 16 | + See the accompanying file LICENSE, version 2000-Apr-09 or later | |
| 17 | + (the contents of which are also included in zip.h) for terms of use. | |
| 18 | + If, for some reason, all these files are missing, the Info-ZIP license | |
| 19 | + also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html | |
| 20 | +*/ | |
| 21 | +/* | |
| 22 | + crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h] | |
| 23 | + | |
| 24 | + The encryption/decryption parts of this source code (as opposed to the | |
| 25 | + non-echoing password parts) were originally written in Europe. The | |
| 26 | + whole source package can be freely distributed, including from the USA. | |
| 27 | + (Prior to January 2000, re-export from the US was a violation of US law.) | |
| 28 | + */ | |
| 29 | + | |
| 30 | +/* | |
| 31 | + This encryption code is a direct transcription of the algorithm from | |
| 32 | + Roger Schlafly, described by Phil Katz in the file appnote.txt. This | |
| 33 | + file (appnote.txt) is distributed with the PKZIP program (even in the | |
| 34 | + version without encryption capabilities). | |
| 35 | + */ | |
| 36 | + | |
| 37 | + | |
| 38 | +#include <stdio.h> | |
| 39 | +#include <stdlib.h> | |
| 40 | +#include <string.h> | |
| 41 | +#include "zlib.h" | |
| 42 | +#include "unzip.h" | |
| 43 | + | |
| 44 | +#ifdef STDC | |
| 45 | +# include <stddef.h> | |
| 46 | +# include <string.h> | |
| 47 | +# include <stdlib.h> | |
| 48 | +#endif | |
| 49 | +#ifdef NO_ERRNO_H | |
| 50 | + extern int errno; | |
| 51 | +#else | |
| 52 | +# include <errno.h> | |
| 53 | +#endif | |
| 54 | + | |
| 55 | + | |
| 56 | +#ifndef local | |
| 57 | +# define local static | |
| 58 | +#endif | |
| 59 | +/* compile with -Dlocal if your debugger can't find static symbols */ | |
| 60 | + | |
| 61 | + | |
| 62 | +#ifndef CASESENSITIVITYDEFAULT_NO | |
| 63 | +# if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) | |
| 64 | +# define CASESENSITIVITYDEFAULT_NO | |
| 65 | +# endif | |
| 66 | +#endif | |
| 67 | + | |
| 68 | + | |
| 69 | +#ifndef UNZ_BUFSIZE | |
| 70 | +#define UNZ_BUFSIZE (16384) | |
| 71 | +#endif | |
| 72 | + | |
| 73 | +#ifndef UNZ_MAXFILENAMEINZIP | |
| 74 | +#define UNZ_MAXFILENAMEINZIP (256) | |
| 75 | +#endif | |
| 76 | + | |
| 77 | +#ifndef ALLOC | |
| 78 | +# define ALLOC(size) (malloc(size)) | |
| 79 | +#endif | |
| 80 | +#ifndef TRYFREE | |
| 81 | +# define TRYFREE(p) {if (p) free(p);} | |
| 82 | +#endif | |
| 83 | + | |
| 84 | +#define SIZECENTRALDIRITEM (0x2e) | |
| 85 | +#define SIZEZIPLOCALHEADER (0x1e) | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | +const char unz_copyright[] = | |
| 91 | + " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; | |
| 92 | + | |
| 93 | +/* unz_file_info_interntal contain internal info about a file in zipfile*/ | |
| 94 | +typedef struct unz_file_info_internal_s | |
| 95 | +{ | |
| 96 | + uLong offset_curfile;/* relative offset of local header 4 bytes */ | |
| 97 | +} unz_file_info_internal; | |
| 98 | + | |
| 99 | + | |
| 100 | +/* file_in_zip_read_info_s contain internal information about a file in zipfile, | |
| 101 | + when reading and decompress it */ | |
| 102 | +typedef struct | |
| 103 | +{ | |
| 104 | + char *read_buffer; /* internal buffer for compressed data */ | |
| 105 | + z_stream stream; /* zLib stream structure for inflate */ | |
| 106 | + | |
| 107 | + uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ | |
| 108 | + uLong stream_initialised; /* flag set if stream structure is initialised*/ | |
| 109 | + | |
| 110 | + uLong offset_local_extrafield;/* offset of the local extra field */ | |
| 111 | + uInt size_local_extrafield;/* size of the local extra field */ | |
| 112 | + uLong pos_local_extrafield; /* position in the local extra field in read*/ | |
| 113 | + | |
| 114 | + uLong crc32; /* crc32 of all data uncompressed */ | |
| 115 | + uLong crc32_wait; /* crc32 we must obtain after decompress all */ | |
| 116 | + uLong rest_read_compressed; /* number of byte to be decompressed */ | |
| 117 | + uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/ | |
| 118 | + zlib_filefunc_def z_filefunc; | |
| 119 | + voidpf filestream; /* io structore of the zipfile */ | |
| 120 | + uLong compression_method; /* compression method (0==store) */ | |
| 121 | + uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ | |
| 122 | + int raw; | |
| 123 | +} file_in_zip_read_info_s; | |
| 124 | + | |
| 125 | + | |
| 126 | +/* unz_s contain internal information about the zipfile | |
| 127 | +*/ | |
| 128 | +typedef struct | |
| 129 | +{ | |
| 130 | + zlib_filefunc_def z_filefunc; | |
| 131 | + voidpf filestream; /* io structore of the zipfile */ | |
| 132 | + unz_global_info gi; /* public global information */ | |
| 133 | + uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ | |
| 134 | + uLong num_file; /* number of the current file in the zipfile*/ | |
| 135 | + uLong pos_in_central_dir; /* pos of the current file in the central dir*/ | |
| 136 | + uLong current_file_ok; /* flag about the usability of the current file*/ | |
| 137 | + uLong central_pos; /* position of the beginning of the central dir*/ | |
| 138 | + | |
| 139 | + uLong size_central_dir; /* size of the central directory */ | |
| 140 | + uLong offset_central_dir; /* offset of start of central directory with | |
| 141 | + respect to the starting disk number */ | |
| 142 | + | |
| 143 | + unz_file_info cur_file_info; /* public info about the current file in zip*/ | |
| 144 | + unz_file_info_internal cur_file_info_internal; /* private info about it*/ | |
| 145 | + file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current | |
| 146 | + file if we are decompressing it */ | |
| 147 | + int encrypted; | |
| 148 | +# ifndef NOUNCRYPT | |
| 149 | + unsigned long keys[3]; /* keys defining the pseudo-random sequence */ | |
| 150 | + const unsigned long* pcrc_32_tab; | |
| 151 | +# endif | |
| 152 | +} unz_s; | |
| 153 | + | |
| 154 | + | |
| 155 | +#ifndef NOUNCRYPT | |
| 156 | +#include "crypt.h" | |
| 157 | +#endif | |
| 158 | + | |
| 159 | +/* =========================================================================== | |
| 160 | + Read a byte from a gz_stream; update next_in and avail_in. Return EOF | |
| 161 | + for end of file. | |
| 162 | + IN assertion: the stream s has been sucessfully opened for reading. | |
| 163 | +*/ | |
| 164 | + | |
| 165 | + | |
| 166 | +local int unzlocal_getByte OF(( | |
| 167 | + const zlib_filefunc_def* pzlib_filefunc_def, | |
| 168 | + voidpf filestream, | |
| 169 | + int *pi)); | |
| 170 | + | |
| 171 | +local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi) | |
| 172 | + const zlib_filefunc_def* pzlib_filefunc_def; | |
| 173 | + voidpf filestream; | |
| 174 | + int *pi; | |
| 175 | +{ | |
| 176 | + unsigned char c; | |
| 177 | + int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1); | |
| 178 | + if (err==1) | |
| 179 | + { | |
| 180 | + *pi = (int)c; | |
| 181 | + return UNZ_OK; | |
| 182 | + } | |
| 183 | + else | |
| 184 | + { | |
| 185 | + if (ZERROR(*pzlib_filefunc_def,filestream)) | |
| 186 | + return UNZ_ERRNO; | |
| 187 | + else | |
| 188 | + return UNZ_EOF; | |
| 189 | + } | |
| 190 | +} | |
| 191 | + | |
| 192 | + | |
| 193 | +/* =========================================================================== | |
| 194 | + Reads a long in LSB order from the given gz_stream. Sets | |
| 195 | +*/ | |
| 196 | +local int unzlocal_getShort OF(( | |
| 197 | + const zlib_filefunc_def* pzlib_filefunc_def, | |
| 198 | + voidpf filestream, | |
| 199 | + uLong *pX)); | |
| 200 | + | |
| 201 | +local int unzlocal_getShort (pzlib_filefunc_def,filestream,pX) | |
| 202 | + const zlib_filefunc_def* pzlib_filefunc_def; | |
| 203 | + voidpf filestream; | |
| 204 | + uLong *pX; | |
| 205 | +{ | |
| 206 | + uLong x ; | |
| 207 | + int i; | |
| 208 | + int err; | |
| 209 | + | |
| 210 | + err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); | |
| 211 | + x = (uLong)i; | |
| 212 | + | |
| 213 | + if (err==UNZ_OK) | |
| 214 | + err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); | |
| 215 | + x += ((uLong)i)<<8; | |
| 216 | + | |
| 217 | + if (err==UNZ_OK) | |
| 218 | + *pX = x; | |
| 219 | + else | |
| 220 | + *pX = 0; | |
| 221 | + return err; | |
| 222 | +} | |
| 223 | + | |
| 224 | +local int unzlocal_getLong OF(( | |
| 225 | + const zlib_filefunc_def* pzlib_filefunc_def, | |
| 226 | + voidpf filestream, | |
| 227 | + uLong *pX)); | |
| 228 | + | |
| 229 | +local int unzlocal_getLong (pzlib_filefunc_def,filestream,pX) | |
| 230 | + const zlib_filefunc_def* pzlib_filefunc_def; | |
| 231 | + voidpf filestream; | |
| 232 | + uLong *pX; | |
| 233 | +{ | |
| 234 | + uLong x ; | |
| 235 | + int i; | |
| 236 | + int err; | |
| 237 | + | |
| 238 | + err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); | |
| 239 | + x = (uLong)i; | |
| 240 | + | |
| 241 | + if (err==UNZ_OK) | |
| 242 | + err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); | |
| 243 | + x += ((uLong)i)<<8; | |
| 244 | + | |
| 245 | + if (err==UNZ_OK) | |
| 246 | + err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); | |
| 247 | + x += ((uLong)i)<<16; | |
| 248 | + | |
| 249 | + if (err==UNZ_OK) | |
| 250 | + err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); | |
| 251 | + x += ((uLong)i)<<24; | |
| 252 | + | |
| 253 | + if (err==UNZ_OK) | |
| 254 | + *pX = x; | |
| 255 | + else | |
| 256 | + *pX = 0; | |
| 257 | + return err; | |
| 258 | +} | |
| 259 | + | |
| 260 | + | |
| 261 | +/* My own strcmpi / strcasecmp */ | |
| 262 | +local int strcmpcasenosensitive_internal (fileName1,fileName2) | |
| 263 | + const char* fileName1; | |
| 264 | + const char* fileName2; | |
| 265 | +{ | |
| 266 | + for (;;) | |
| 267 | + { | |
| 268 | + char c1=*(fileName1++); | |
| 269 | + char c2=*(fileName2++); | |
| 270 | + if ((c1>='a') && (c1<='z')) | |
| 271 | + c1 -= 0x20; | |
| 272 | + if ((c2>='a') && (c2<='z')) | |
| 273 | + c2 -= 0x20; | |
| 274 | + if (c1=='\0') | |
| 275 | + return ((c2=='\0') ? 0 : -1); | |
| 276 | + if (c2=='\0') | |
| 277 | + return 1; | |
| 278 | + if (c1<c2) | |
| 279 | + return -1; | |
| 280 | + if (c1>c2) | |
| 281 | + return 1; | |
| 282 | + } | |
| 283 | +} | |
| 284 | + | |
| 285 | + | |
| 286 | +#ifdef CASESENSITIVITYDEFAULT_NO | |
| 287 | +#define CASESENSITIVITYDEFAULTVALUE 2 | |
| 288 | +#else | |
| 289 | +#define CASESENSITIVITYDEFAULTVALUE 1 | |
| 290 | +#endif | |
| 291 | + | |
| 292 | +#ifndef STRCMPCASENOSENTIVEFUNCTION | |
| 293 | +#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal | |
| 294 | +#endif | |
| 295 | + | |
| 296 | +/* | |
| 297 | + Compare two filename (fileName1,fileName2). | |
| 298 | + If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) | |
| 299 | + If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi | |
| 300 | + or strcasecmp) | |
| 301 | + If iCaseSenisivity = 0, case sensitivity is defaut of your operating system | |
| 302 | + (like 1 on Unix, 2 on Windows) | |
| 303 | + | |
| 304 | +*/ | |
| 305 | +extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity) | |
| 306 | + const char* fileName1; | |
| 307 | + const char* fileName2; | |
| 308 | + int iCaseSensitivity; | |
| 309 | +{ | |
| 310 | + if (iCaseSensitivity==0) | |
| 311 | + iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; | |
| 312 | + | |
| 313 | + if (iCaseSensitivity==1) | |
| 314 | + return strcmp(fileName1,fileName2); | |
| 315 | + | |
| 316 | + return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2); | |
| 317 | +} | |
| 318 | + | |
| 319 | +#ifndef BUFREADCOMMENT | |
| 320 | +#define BUFREADCOMMENT (0x400) | |
| 321 | +#endif | |
| 322 | + | |
| 323 | +/* | |
| 324 | + Locate the Central directory of a zipfile (at the end, just before | |
| 325 | + the global comment) | |
| 326 | +*/ | |
| 327 | +local uLong unzlocal_SearchCentralDir OF(( | |
| 328 | + const zlib_filefunc_def* pzlib_filefunc_def, | |
| 329 | + voidpf filestream)); | |
| 330 | + | |
| 331 | +local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream) | |
| 332 | + const zlib_filefunc_def* pzlib_filefunc_def; | |
| 333 | + voidpf filestream; | |
| 334 | +{ | |
| 335 | + unsigned char* buf; | |
| 336 | + uLong uSizeFile; | |
| 337 | + uLong uBackRead; | |
| 338 | + uLong uMaxBack=0xffff; /* maximum size of global comment */ | |
| 339 | + uLong uPosFound=0; | |
| 340 | + | |
| 341 | + if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) | |
| 342 | + return 0; | |
| 343 | + | |
| 344 | + | |
| 345 | + uSizeFile = ZTELL(*pzlib_filefunc_def,filestream); | |
| 346 | + | |
| 347 | + if (uMaxBack>uSizeFile) | |
| 348 | + uMaxBack = uSizeFile; | |
| 349 | + | |
| 350 | + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); | |
| 351 | + if (buf==NULL) | |
| 352 | + return 0; | |
| 353 | + | |
| 354 | + uBackRead = 4; | |
| 355 | + while (uBackRead<uMaxBack) | |
| 356 | + { | |
| 357 | + uLong uReadSize,uReadPos ; | |
| 358 | + int i; | |
| 359 | + if (uBackRead+BUFREADCOMMENT>uMaxBack) | |
| 360 | + uBackRead = uMaxBack; | |
| 361 | + else | |
| 362 | + uBackRead+=BUFREADCOMMENT; | |
| 363 | + uReadPos = uSizeFile-uBackRead ; | |
| 364 | + | |
| 365 | + uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? | |
| 366 | + (BUFREADCOMMENT+4) : (uSizeFile-uReadPos); | |
| 367 | + if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) | |
| 368 | + break; | |
| 369 | + | |
| 370 | + if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) | |
| 371 | + break; | |
| 372 | + | |
| 373 | + for (i=(int)uReadSize-3; (i--)>0;) | |
| 374 | + if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && | |
| 375 | + ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) | |
| 376 | + { | |
| 377 | + uPosFound = uReadPos+i; | |
| 378 | + break; | |
| 379 | + } | |
| 380 | + | |
| 381 | + if (uPosFound!=0) | |
| 382 | + break; | |
| 383 | + } | |
| 384 | + TRYFREE(buf); | |
| 385 | + return uPosFound; | |
| 386 | +} | |
| 387 | + | |
| 388 | +/* | |
| 389 | + Open a Zip file. path contain the full pathname (by example, | |
| 390 | + on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer | |
| 391 | + "zlib/zlib114.zip". | |
| 392 | + If the zipfile cannot be opened (file doesn't exist or in not valid), the | |
| 393 | + return value is NULL. | |
| 394 | + Else, the return value is a unzFile Handle, usable with other function | |
| 395 | + of this unzip package. | |
| 396 | +*/ | |
| 397 | +extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def) | |
| 398 | + const char *path; | |
| 399 | + zlib_filefunc_def* pzlib_filefunc_def; | |
| 400 | +{ | |
| 401 | + unz_s us; | |
| 402 | + unz_s *s; | |
| 403 | + uLong central_pos,uL; | |
| 404 | + | |
| 405 | + uLong number_disk; /* number of the current dist, used for | |
| 406 | + spaning ZIP, unsupported, always 0*/ | |
| 407 | + uLong number_disk_with_CD; /* number the the disk with central dir, used | |
| 408 | + for spaning ZIP, unsupported, always 0*/ | |
| 409 | + uLong number_entry_CD; /* total number of entries in | |
| 410 | + the central dir | |
| 411 | + (same than number_entry on nospan) */ | |
| 412 | + | |
| 413 | + int err=UNZ_OK; | |
| 414 | + | |
| 415 | + if (unz_copyright[0]!=' ') | |
| 416 | + return NULL; | |
| 417 | + | |
| 418 | + if (pzlib_filefunc_def==NULL) | |
| 419 | + fill_fopen_filefunc(&us.z_filefunc); | |
| 420 | + else | |
| 421 | + us.z_filefunc = *pzlib_filefunc_def; | |
| 422 | + | |
| 423 | + us.filestream= (*(us.z_filefunc.zopen_file))(us.z_filefunc.opaque, | |
| 424 | + path, | |
| 425 | + ZLIB_FILEFUNC_MODE_READ | | |
| 426 | + ZLIB_FILEFUNC_MODE_EXISTING); | |
| 427 | + if (us.filestream==NULL) | |
| 428 | + return NULL; | |
| 429 | + | |
| 430 | + central_pos = unzlocal_SearchCentralDir(&us.z_filefunc,us.filestream); | |
| 431 | + if (central_pos==0) | |
| 432 | + err=UNZ_ERRNO; | |
| 433 | + | |
| 434 | + if (ZSEEK(us.z_filefunc, us.filestream, | |
| 435 | + central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) | |
| 436 | + err=UNZ_ERRNO; | |
| 437 | + | |
| 438 | + /* the signature, already checked */ | |
| 439 | + if (unzlocal_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) | |
| 440 | + err=UNZ_ERRNO; | |
| 441 | + | |
| 442 | + /* number of this disk */ | |
| 443 | + if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) | |
| 444 | + err=UNZ_ERRNO; | |
| 445 | + | |
| 446 | + /* number of the disk with the start of the central directory */ | |
| 447 | + if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) | |
| 448 | + err=UNZ_ERRNO; | |
| 449 | + | |
| 450 | + /* total number of entries in the central dir on this disk */ | |
| 451 | + if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK) | |
| 452 | + err=UNZ_ERRNO; | |
| 453 | + | |
| 454 | + /* total number of entries in the central dir */ | |
| 455 | + if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK) | |
| 456 | + err=UNZ_ERRNO; | |
| 457 | + | |
| 458 | + if ((number_entry_CD!=us.gi.number_entry) || | |
| 459 | + (number_disk_with_CD!=0) || | |
| 460 | + (number_disk!=0)) | |
| 461 | + err=UNZ_BADZIPFILE; | |
| 462 | + | |
| 463 | + /* size of the central directory */ | |
| 464 | + if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK) | |
| 465 | + err=UNZ_ERRNO; | |
| 466 | + | |
| 467 | + /* offset of start of central directory with respect to the | |
| 468 | + starting disk number */ | |
| 469 | + if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK) | |
| 470 | + err=UNZ_ERRNO; | |
| 471 | + | |
| 472 | + /* zipfile comment length */ | |
| 473 | + if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK) | |
| 474 | + err=UNZ_ERRNO; | |
| 475 | + | |
| 476 | + if ((central_pos<us.offset_central_dir+us.size_central_dir) && | |
| 477 | + (err==UNZ_OK)) | |
| 478 | + err=UNZ_BADZIPFILE; | |
| 479 | + | |
| 480 | + if (err!=UNZ_OK) | |
| 481 | + { | |
| 482 | + ZCLOSE(us.z_filefunc, us.filestream); | |
| 483 | + return NULL; | |
| 484 | + } | |
| 485 | + | |
| 486 | + us.byte_before_the_zipfile = central_pos - | |
| 487 | + (us.offset_central_dir+us.size_central_dir); | |
| 488 | + us.central_pos = central_pos; | |
| 489 | + us.pfile_in_zip_read = NULL; | |
| 490 | + us.encrypted = 0; | |
| 491 | + | |
| 492 | + | |
| 493 | + s=(unz_s*)ALLOC(sizeof(unz_s)); | |
| 494 | + *s=us; | |
| 495 | + unzGoToFirstFile((unzFile)s); | |
| 496 | + return (unzFile)s; | |
| 497 | +} | |
| 498 | + | |
| 499 | + | |
| 500 | +extern unzFile ZEXPORT unzOpen (path) | |
| 501 | + const char *path; | |
| 502 | +{ | |
| 503 | + return unzOpen2(path, NULL); | |
| 504 | +} | |
| 505 | + | |
| 506 | +/* | |
| 507 | + Close a ZipFile opened with unzipOpen. | |
| 508 | + If there is files inside the .Zip opened with unzipOpenCurrentFile (see later), | |
| 509 | + these files MUST be closed with unzipCloseCurrentFile before call unzipClose. | |
| 510 | + return UNZ_OK if there is no problem. */ | |
| 511 | +extern int ZEXPORT unzClose (file) | |
| 512 | + unzFile file; | |
| 513 | +{ | |
| 514 | + unz_s* s; | |
| 515 | + if (file==NULL) | |
| 516 | + return UNZ_PARAMERROR; | |
| 517 | + s=(unz_s*)file; | |
| 518 | + | |
| 519 | + if (s->pfile_in_zip_read!=NULL) | |
| 520 | + unzCloseCurrentFile(file); | |
| 521 | + | |
| 522 | + ZCLOSE(s->z_filefunc, s->filestream); | |
| 523 | + TRYFREE(s); | |
| 524 | + return UNZ_OK; | |
| 525 | +} | |
| 526 | + | |
| 527 | + | |
| 528 | +/* | |
| 529 | + Write info about the ZipFile in the *pglobal_info structure. | |
| 530 | + No preparation of the structure is needed | |
| 531 | + return UNZ_OK if there is no problem. */ | |
| 532 | +extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info) | |
| 533 | + unzFile file; | |
| 534 | + unz_global_info *pglobal_info; | |
| 535 | +{ | |
| 536 | + unz_s* s; | |
| 537 | + if (file==NULL) | |
| 538 | + return UNZ_PARAMERROR; | |
| 539 | + s=(unz_s*)file; | |
| 540 | + *pglobal_info=s->gi; | |
| 541 | + return UNZ_OK; | |
| 542 | +} | |
| 543 | + | |
| 544 | + | |
| 545 | +/* | |
| 546 | + Translate date/time from Dos format to tm_unz (readable more easilty) | |
| 547 | +*/ | |
| 548 | +local void unzlocal_DosDateToTmuDate (ulDosDate, ptm) | |
| 549 | + uLong ulDosDate; | |
| 550 | + tm_unz* ptm; | |
| 551 | +{ | |
| 552 | + uLong uDate; | |
| 553 | + uDate = (uLong)(ulDosDate>>16); | |
| 554 | + ptm->tm_mday = (uInt)(uDate&0x1f) ; | |
| 555 | + ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ; | |
| 556 | + ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ; | |
| 557 | + | |
| 558 | + ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800); | |
| 559 | + ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ; | |
| 560 | + ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ; | |
| 561 | +} | |
| 562 | + | |
| 563 | +/* | |
| 564 | + Get Info about the current file in the zipfile, with internal only info | |
| 565 | +*/ | |
| 566 | +local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file, | |
| 567 | + unz_file_info *pfile_info, | |
| 568 | + unz_file_info_internal | |
| 569 | + *pfile_info_internal, | |
| 570 | + char *szFileName, | |
| 571 | + uLong fileNameBufferSize, | |
| 572 | + void *extraField, | |
| 573 | + uLong extraFieldBufferSize, | |
| 574 | + char *szComment, | |
| 575 | + uLong commentBufferSize)); | |
| 576 | + | |
| 577 | +local int unzlocal_GetCurrentFileInfoInternal (file, | |
| 578 | + pfile_info, | |
| 579 | + pfile_info_internal, | |
| 580 | + szFileName, fileNameBufferSize, | |
| 581 | + extraField, extraFieldBufferSize, | |
| 582 | + szComment, commentBufferSize) | |
| 583 | + unzFile file; | |
| 584 | + unz_file_info *pfile_info; | |
| 585 | + unz_file_info_internal *pfile_info_internal; | |
| 586 | + char *szFileName; | |
| 587 | + uLong fileNameBufferSize; | |
| 588 | + void *extraField; | |
| 589 | + uLong extraFieldBufferSize; | |
| 590 | + char *szComment; | |
| 591 | + uLong commentBufferSize; | |
| 592 | +{ | |
| 593 | + unz_s* s; | |
| 594 | + unz_file_info file_info; | |
| 595 | + unz_file_info_internal file_info_internal; | |
| 596 | + int err=UNZ_OK; | |
| 597 | + uLong uMagic; | |
| 598 | + long lSeek=0; | |
| 599 | + | |
| 600 | + if (file==NULL) | |
| 601 | + return UNZ_PARAMERROR; | |
| 602 | + s=(unz_s*)file; | |
| 603 | + if (ZSEEK(s->z_filefunc, s->filestream, | |
| 604 | + s->pos_in_central_dir+s->byte_before_the_zipfile, | |
| 605 | + ZLIB_FILEFUNC_SEEK_SET)!=0) | |
| 606 | + err=UNZ_ERRNO; | |
| 607 | + | |
| 608 | + | |
| 609 | + /* we check the magic */ | |
| 610 | + if (err==UNZ_OK) | |
| 611 | + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) | |
| 612 | + err=UNZ_ERRNO; | |
| 613 | + else if (uMagic!=0x02014b50) | |
| 614 | + err=UNZ_BADZIPFILE; | |
| 615 | + | |
| 616 | + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK) | |
| 617 | + err=UNZ_ERRNO; | |
| 618 | + | |
| 619 | + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK) | |
| 620 | + err=UNZ_ERRNO; | |
| 621 | + | |
| 622 | + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK) | |
| 623 | + err=UNZ_ERRNO; | |
| 624 | + | |
| 625 | + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK) | |
| 626 | + err=UNZ_ERRNO; | |
| 627 | + | |
| 628 | + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK) | |
| 629 | + err=UNZ_ERRNO; | |
| 630 | + | |
| 631 | + unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); | |
| 632 | + | |
| 633 | + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK) | |
| 634 | + err=UNZ_ERRNO; | |
| 635 | + | |
| 636 | + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK) | |
| 637 | + err=UNZ_ERRNO; | |
| 638 | + | |
| 639 | + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK) | |
| 640 | + err=UNZ_ERRNO; | |
| 641 | + | |
| 642 | + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK) | |
| 643 | + err=UNZ_ERRNO; | |
| 644 | + | |
| 645 | + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK) | |
| 646 | + err=UNZ_ERRNO; | |
| 647 | + | |
| 648 | + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK) | |
| 649 | + err=UNZ_ERRNO; | |
| 650 | + | |
| 651 | + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK) | |
| 652 | + err=UNZ_ERRNO; | |
| 653 | + | |
| 654 | + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK) | |
| 655 | + err=UNZ_ERRNO; | |
| 656 | + | |
| 657 | + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK) | |
| 658 | + err=UNZ_ERRNO; | |
| 659 | + | |
| 660 | + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK) | |
| 661 | + err=UNZ_ERRNO; | |
| 662 | + | |
| 663 | + lSeek+=file_info.size_filename; | |
| 664 | + if ((err==UNZ_OK) && (szFileName!=NULL)) | |
| 665 | + { | |
| 666 | + uLong uSizeRead ; | |
| 667 | + if (file_info.size_filename<fileNameBufferSize) | |
| 668 | + { | |
| 669 | + *(szFileName+file_info.size_filename)='\0'; | |
| 670 | + uSizeRead = file_info.size_filename; | |
| 671 | + } | |
| 672 | + else | |
| 673 | + uSizeRead = fileNameBufferSize; | |
| 674 | + | |
| 675 | + if ((file_info.size_filename>0) && (fileNameBufferSize>0)) | |
| 676 | + if (ZREAD(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead) | |
| 677 | + err=UNZ_ERRNO; | |
| 678 | + lSeek -= uSizeRead; | |
| 679 | + } | |
| 680 | + | |
| 681 | + | |
| 682 | + if ((err==UNZ_OK) && (extraField!=NULL)) | |
| 683 | + { | |
| 684 | + uLong uSizeRead ; | |
| 685 | + if (file_info.size_file_extra<extraFieldBufferSize) | |
| 686 | + uSizeRead = file_info.size_file_extra; | |
| 687 | + else | |
| 688 | + uSizeRead = extraFieldBufferSize; | |
| 689 | + | |
| 690 | + if (lSeek!=0) | |
| 691 | + if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) | |
| 692 | + lSeek=0; | |
| 693 | + else | |
| 694 | + err=UNZ_ERRNO; | |
| 695 | + if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) | |
| 696 | + if (ZREAD(s->z_filefunc, s->filestream,extraField,uSizeRead)!=uSizeRead) | |
| 697 | + err=UNZ_ERRNO; | |
| 698 | + lSeek += file_info.size_file_extra - uSizeRead; | |
| 699 | + } | |
| 700 | + else | |
| 701 | + lSeek+=file_info.size_file_extra; | |
| 702 | + | |
| 703 | + | |
| 704 | + if ((err==UNZ_OK) && (szComment!=NULL)) | |
| 705 | + { | |
| 706 | + uLong uSizeRead ; | |
| 707 | + if (file_info.size_file_comment<commentBufferSize) | |
| 708 | + { | |
| 709 | + *(szComment+file_info.size_file_comment)='\0'; | |
| 710 | + uSizeRead = file_info.size_file_comment; | |
| 711 | + } | |
| 712 | + else | |
| 713 | + uSizeRead = commentBufferSize; | |
| 714 | + | |
| 715 | + if (lSeek!=0) | |
| 716 | + if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) | |
| 717 | + lSeek=0; | |
| 718 | + else | |
| 719 | + err=UNZ_ERRNO; | |
| 720 | + if ((file_info.size_file_comment>0) && (commentBufferSize>0)) | |
| 721 | + if (ZREAD(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead) | |
| 722 | + err=UNZ_ERRNO; | |
| 723 | + lSeek+=file_info.size_file_comment - uSizeRead; | |
| 724 | + } | |
| 725 | + else | |
| 726 | + lSeek+=file_info.size_file_comment; | |
| 727 | + | |
| 728 | + if ((err==UNZ_OK) && (pfile_info!=NULL)) | |
| 729 | + *pfile_info=file_info; | |
| 730 | + | |
| 731 | + if ((err==UNZ_OK) && (pfile_info_internal!=NULL)) | |
| 732 | + *pfile_info_internal=file_info_internal; | |
| 733 | + | |
| 734 | + return err; | |
| 735 | +} | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | +/* | |
| 740 | + Write info about the ZipFile in the *pglobal_info structure. | |
| 741 | + No preparation of the structure is needed | |
| 742 | + return UNZ_OK if there is no problem. | |
| 743 | +*/ | |
| 744 | +extern int ZEXPORT unzGetCurrentFileInfo (file, | |
| 745 | + pfile_info, | |
| 746 | + szFileName, fileNameBufferSize, | |
| 747 | + extraField, extraFieldBufferSize, | |
| 748 | + szComment, commentBufferSize) | |
| 749 | + unzFile file; | |
| 750 | + unz_file_info *pfile_info; | |
| 751 | + char *szFileName; | |
| 752 | + uLong fileNameBufferSize; | |
| 753 | + void *extraField; | |
| 754 | + uLong extraFieldBufferSize; | |
| 755 | + char *szComment; | |
| 756 | + uLong commentBufferSize; | |
| 757 | +{ | |
| 758 | + return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL, | |
| 759 | + szFileName,fileNameBufferSize, | |
| 760 | + extraField,extraFieldBufferSize, | |
| 761 | + szComment,commentBufferSize); | |
| 762 | +} | |
| 763 | + | |
| 764 | +/* | |
| 765 | + Set the current file of the zipfile to the first file. | |
| 766 | + return UNZ_OK if there is no problem | |
| 767 | +*/ | |
| 768 | +extern int ZEXPORT unzGoToFirstFile (file) | |
| 769 | + unzFile file; | |
| 770 | +{ | |
| 771 | + int err=UNZ_OK; | |
| 772 | + unz_s* s; | |
| 773 | + if (file==NULL) | |
| 774 | + return UNZ_PARAMERROR; | |
| 775 | + s=(unz_s*)file; | |
| 776 | + s->pos_in_central_dir=s->offset_central_dir; | |
| 777 | + s->num_file=0; | |
| 778 | + err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, | |
| 779 | + &s->cur_file_info_internal, | |
| 780 | + NULL,0,NULL,0,NULL,0); | |
| 781 | + s->current_file_ok = (err == UNZ_OK); | |
| 782 | + return err; | |
| 783 | +} | |
| 784 | + | |
| 785 | +/* | |
| 786 | + Set the current file of the zipfile to the next file. | |
| 787 | + return UNZ_OK if there is no problem | |
| 788 | + return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. | |
| 789 | +*/ | |
| 790 | +extern int ZEXPORT unzGoToNextFile (file) | |
| 791 | + unzFile file; | |
| 792 | +{ | |
| 793 | + unz_s* s; | |
| 794 | + int err; | |
| 795 | + | |
| 796 | + if (file==NULL) | |
| 797 | + return UNZ_PARAMERROR; | |
| 798 | + s=(unz_s*)file; | |
| 799 | + if (!s->current_file_ok) | |
| 800 | + return UNZ_END_OF_LIST_OF_FILE; | |
| 801 | + if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */ | |
| 802 | + if (s->num_file+1==s->gi.number_entry) | |
| 803 | + return UNZ_END_OF_LIST_OF_FILE; | |
| 804 | + | |
| 805 | + s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + | |
| 806 | + s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ; | |
| 807 | + s->num_file++; | |
| 808 | + err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, | |
| 809 | + &s->cur_file_info_internal, | |
| 810 | + NULL,0,NULL,0,NULL,0); | |
| 811 | + s->current_file_ok = (err == UNZ_OK); | |
| 812 | + return err; | |
| 813 | +} | |
| 814 | + | |
| 815 | + | |
| 816 | +/* | |
| 817 | + Try locate the file szFileName in the zipfile. | |
| 818 | + For the iCaseSensitivity signification, see unzipStringFileNameCompare | |
| 819 | + | |
| 820 | + return value : | |
| 821 | + UNZ_OK if the file is found. It becomes the current file. | |
| 822 | + UNZ_END_OF_LIST_OF_FILE if the file is not found | |
| 823 | +*/ | |
| 824 | +extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity) | |
| 825 | + unzFile file; | |
| 826 | + const char *szFileName; | |
| 827 | + int iCaseSensitivity; | |
| 828 | +{ | |
| 829 | + unz_s* s; | |
| 830 | + int err; | |
| 831 | + | |
| 832 | + /* We remember the 'current' position in the file so that we can jump | |
| 833 | + * back there if we fail. | |
| 834 | + */ | |
| 835 | + unz_file_info cur_file_infoSaved; | |
| 836 | + unz_file_info_internal cur_file_info_internalSaved; | |
| 837 | + uLong num_fileSaved; | |
| 838 | + uLong pos_in_central_dirSaved; | |
| 839 | + | |
| 840 | + | |
| 841 | + if (file==NULL) | |
| 842 | + return UNZ_PARAMERROR; | |
| 843 | + | |
| 844 | + if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) | |
| 845 | + return UNZ_PARAMERROR; | |
| 846 | + | |
| 847 | + s=(unz_s*)file; | |
| 848 | + if (!s->current_file_ok) | |
| 849 | + return UNZ_END_OF_LIST_OF_FILE; | |
| 850 | + | |
| 851 | + /* Save the current state */ | |
| 852 | + num_fileSaved = s->num_file; | |
| 853 | + pos_in_central_dirSaved = s->pos_in_central_dir; | |
| 854 | + cur_file_infoSaved = s->cur_file_info; | |
| 855 | + cur_file_info_internalSaved = s->cur_file_info_internal; | |
| 856 | + | |
| 857 | + err = unzGoToFirstFile(file); | |
| 858 | + | |
| 859 | + while (err == UNZ_OK) | |
| 860 | + { | |
| 861 | + char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; | |
| 862 | + err = unzGetCurrentFileInfo(file,NULL, | |
| 863 | + szCurrentFileName,sizeof(szCurrentFileName)-1, | |
| 864 | + NULL,0,NULL,0); | |
| 865 | + if (err == UNZ_OK) | |
| 866 | + { | |
| 867 | + if (unzStringFileNameCompare(szCurrentFileName, | |
| 868 | + szFileName,iCaseSensitivity)==0) | |
| 869 | + return UNZ_OK; | |
| 870 | + err = unzGoToNextFile(file); | |
| 871 | + } | |
| 872 | + } | |
| 873 | + | |
| 874 | + /* We failed, so restore the state of the 'current file' to where we | |
| 875 | + * were. | |
| 876 | + */ | |
| 877 | + s->num_file = num_fileSaved ; | |
| 878 | + s->pos_in_central_dir = pos_in_central_dirSaved ; | |
| 879 | + s->cur_file_info = cur_file_infoSaved; | |
| 880 | + s->cur_file_info_internal = cur_file_info_internalSaved; | |
| 881 | + return err; | |
| 882 | +} | |
| 883 | + | |
| 884 | + | |
| 885 | +/* | |
| 886 | +/////////////////////////////////////////// | |
| 887 | +// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net) | |
| 888 | +// I need random access | |
| 889 | +// | |
| 890 | +// Further optimization could be realized by adding an ability | |
| 891 | +// to cache the directory in memory. The goal being a single | |
| 892 | +// comprehensive file read to put the file I need in a memory. | |
| 893 | +*/ | |
| 894 | + | |
| 895 | +/* | |
| 896 | +typedef struct unz_file_pos_s | |
| 897 | +{ | |
| 898 | + uLong pos_in_zip_directory; // offset in file | |
| 899 | + uLong num_of_file; // # of file | |
| 900 | +} unz_file_pos; | |
| 901 | +*/ | |
| 902 | + | |
| 903 | +extern int ZEXPORT unzGetFilePos(file, file_pos) | |
| 904 | + unzFile file; | |
| 905 | + unz_file_pos* file_pos; | |
| 906 | +{ | |
| 907 | + unz_s* s; | |
| 908 | + | |
| 909 | + if (file==NULL || file_pos==NULL) | |
| 910 | + return UNZ_PARAMERROR; | |
| 911 | + s=(unz_s*)file; | |
| 912 | + if (!s->current_file_ok) | |
| 913 | + return UNZ_END_OF_LIST_OF_FILE; | |
| 914 | + | |
| 915 | + file_pos->pos_in_zip_directory = s->pos_in_central_dir; | |
| 916 | + file_pos->num_of_file = s->num_file; | |
| 917 | + | |
| 918 | + return UNZ_OK; | |
| 919 | +} | |
| 920 | + | |
| 921 | +extern int ZEXPORT unzGoToFilePos(file, file_pos) | |
| 922 | + unzFile file; | |
| 923 | + unz_file_pos* file_pos; | |
| 924 | +{ | |
| 925 | + unz_s* s; | |
| 926 | + int err; | |
| 927 | + | |
| 928 | + if (file==NULL || file_pos==NULL) | |
| 929 | + return UNZ_PARAMERROR; | |
| 930 | + s=(unz_s*)file; | |
| 931 | + | |
| 932 | + /* jump to the right spot */ | |
| 933 | + s->pos_in_central_dir = file_pos->pos_in_zip_directory; | |
| 934 | + s->num_file = file_pos->num_of_file; | |
| 935 | + | |
| 936 | + /* set the current file */ | |
| 937 | + err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, | |
| 938 | + &s->cur_file_info_internal, | |
| 939 | + NULL,0,NULL,0,NULL,0); | |
| 940 | + /* return results */ | |
| 941 | + s->current_file_ok = (err == UNZ_OK); | |
| 942 | + return err; | |
| 943 | +} | |
| 944 | + | |
| 945 | +/* | |
| 946 | +// Unzip Helper Functions - should be here? | |
| 947 | +/////////////////////////////////////////// | |
| 948 | +*/ | |
| 949 | + | |
| 950 | +/* | |
| 951 | + Read the local header of the current zipfile | |
| 952 | + Check the coherency of the local header and info in the end of central | |
| 953 | + directory about this file | |
| 954 | + store in *piSizeVar the size of extra info in local header | |
| 955 | + (filename and size of extra field data) | |
| 956 | +*/ | |
| 957 | +local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar, | |
| 958 | + poffset_local_extrafield, | |
| 959 | + psize_local_extrafield) | |
| 960 | + unz_s* s; | |
| 961 | + uInt* piSizeVar; | |
| 962 | + uLong *poffset_local_extrafield; | |
| 963 | + uInt *psize_local_extrafield; | |
| 964 | +{ | |
| 965 | + uLong uMagic,uData,uFlags; | |
| 966 | + uLong size_filename; | |
| 967 | + uLong size_extra_field; | |
| 968 | + int err=UNZ_OK; | |
| 969 | + | |
| 970 | + *piSizeVar = 0; | |
| 971 | + *poffset_local_extrafield = 0; | |
| 972 | + *psize_local_extrafield = 0; | |
| 973 | + | |
| 974 | + if (ZSEEK(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile + | |
| 975 | + s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0) | |
| 976 | + return UNZ_ERRNO; | |
| 977 | + | |
| 978 | + | |
| 979 | + if (err==UNZ_OK) | |
| 980 | + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) | |
| 981 | + err=UNZ_ERRNO; | |
| 982 | + else if (uMagic!=0x04034b50) | |
| 983 | + err=UNZ_BADZIPFILE; | |
| 984 | + | |
| 985 | + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) | |
| 986 | + err=UNZ_ERRNO; | |
| 987 | +/* | |
| 988 | + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) | |
| 989 | + err=UNZ_BADZIPFILE; | |
| 990 | +*/ | |
| 991 | + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK) | |
| 992 | + err=UNZ_ERRNO; | |
| 993 | + | |
| 994 | + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) | |
| 995 | + err=UNZ_ERRNO; | |
| 996 | + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) | |
| 997 | + err=UNZ_BADZIPFILE; | |
| 998 | + | |
| 999 | + if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && | |
| 1000 | + (s->cur_file_info.compression_method!=Z_DEFLATED)) | |
| 1001 | + err=UNZ_BADZIPFILE; | |
| 1002 | + | |
| 1003 | + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */ | |
| 1004 | + err=UNZ_ERRNO; | |
| 1005 | + | |
| 1006 | + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */ | |
| 1007 | + err=UNZ_ERRNO; | |
| 1008 | + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && | |
| 1009 | + ((uFlags & 8)==0)) | |
| 1010 | + err=UNZ_BADZIPFILE; | |
| 1011 | + | |
| 1012 | + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */ | |
| 1013 | + err=UNZ_ERRNO; | |
| 1014 | + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && | |
| 1015 | + ((uFlags & 8)==0)) | |
| 1016 | + err=UNZ_BADZIPFILE; | |
| 1017 | + | |
| 1018 | + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */ | |
| 1019 | + err=UNZ_ERRNO; | |
| 1020 | + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && | |
| 1021 | + ((uFlags & 8)==0)) | |
| 1022 | + err=UNZ_BADZIPFILE; | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK) | |
| 1026 | + err=UNZ_ERRNO; | |
| 1027 | + else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) | |
| 1028 | + err=UNZ_BADZIPFILE; | |
| 1029 | + | |
| 1030 | + *piSizeVar += (uInt)size_filename; | |
| 1031 | + | |
| 1032 | + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK) | |
| 1033 | + err=UNZ_ERRNO; | |
| 1034 | + *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + | |
| 1035 | + SIZEZIPLOCALHEADER + size_filename; | |
| 1036 | + *psize_local_extrafield = (uInt)size_extra_field; | |
| 1037 | + | |
| 1038 | + *piSizeVar += (uInt)size_extra_field; | |
| 1039 | + | |
| 1040 | + return err; | |
| 1041 | +} | |
| 1042 | + | |
| 1043 | +/* | |
| 1044 | + Open for reading data the current file in the zipfile. | |
| 1045 | + If there is no error and the file is opened, the return value is UNZ_OK. | |
| 1046 | +*/ | |
| 1047 | +extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password) | |
| 1048 | + unzFile file; | |
| 1049 | + int* method; | |
| 1050 | + int* level; | |
| 1051 | + int raw; | |
| 1052 | + const char* password; | |
| 1053 | +{ | |
| 1054 | + int err=UNZ_OK; | |
| 1055 | + uInt iSizeVar; | |
| 1056 | + unz_s* s; | |
| 1057 | + file_in_zip_read_info_s* pfile_in_zip_read_info; | |
| 1058 | + uLong offset_local_extrafield; /* offset of the local extra field */ | |
| 1059 | + uInt size_local_extrafield; /* size of the local extra field */ | |
| 1060 | +# ifndef NOUNCRYPT | |
| 1061 | + char source[12]; | |
| 1062 | +# else | |
| 1063 | + if (password != NULL) | |
| 1064 | + return UNZ_PARAMERROR; | |
| 1065 | +# endif | |
| 1066 | + | |
| 1067 | + if (file==NULL) | |
| 1068 | + return UNZ_PARAMERROR; | |
| 1069 | + s=(unz_s*)file; | |
| 1070 | + if (!s->current_file_ok) | |
| 1071 | + return UNZ_PARAMERROR; | |
| 1072 | + | |
| 1073 | + if (s->pfile_in_zip_read != NULL) | |
| 1074 | + unzCloseCurrentFile(file); | |
| 1075 | + | |
| 1076 | + if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar, | |
| 1077 | + &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK) | |
| 1078 | + return UNZ_BADZIPFILE; | |
| 1079 | + | |
| 1080 | + pfile_in_zip_read_info = (file_in_zip_read_info_s*) | |
| 1081 | + ALLOC(sizeof(file_in_zip_read_info_s)); | |
| 1082 | + if (pfile_in_zip_read_info==NULL) | |
| 1083 | + return UNZ_INTERNALERROR; | |
| 1084 | + | |
| 1085 | + pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE); | |
| 1086 | + pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield; | |
| 1087 | + pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield; | |
| 1088 | + pfile_in_zip_read_info->pos_local_extrafield=0; | |
| 1089 | + pfile_in_zip_read_info->raw=raw; | |
| 1090 | + | |
| 1091 | + if (pfile_in_zip_read_info->read_buffer==NULL) | |
| 1092 | + { | |
| 1093 | + TRYFREE(pfile_in_zip_read_info); | |
| 1094 | + return UNZ_INTERNALERROR; | |
| 1095 | + } | |
| 1096 | + | |
| 1097 | + pfile_in_zip_read_info->stream_initialised=0; | |
| 1098 | + | |
| 1099 | + if (method!=NULL) | |
| 1100 | + *method = (int)s->cur_file_info.compression_method; | |
| 1101 | + | |
| 1102 | + if (level!=NULL) | |
| 1103 | + { | |
| 1104 | + *level = 6; | |
| 1105 | + switch (s->cur_file_info.flag & 0x06) | |
| 1106 | + { | |
| 1107 | + case 6 : *level = 1; break; | |
| 1108 | + case 4 : *level = 2; break; | |
| 1109 | + case 2 : *level = 9; break; | |
| 1110 | + } | |
| 1111 | + } | |
| 1112 | + | |
| 1113 | + if ((s->cur_file_info.compression_method!=0) && | |
| 1114 | + (s->cur_file_info.compression_method!=Z_DEFLATED)) | |
| 1115 | + err=UNZ_BADZIPFILE; | |
| 1116 | + | |
| 1117 | + pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc; | |
| 1118 | + pfile_in_zip_read_info->crc32=0; | |
| 1119 | + pfile_in_zip_read_info->compression_method = | |
| 1120 | + s->cur_file_info.compression_method; | |
| 1121 | + pfile_in_zip_read_info->filestream=s->filestream; | |
| 1122 | + pfile_in_zip_read_info->z_filefunc=s->z_filefunc; | |
| 1123 | + pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile; | |
| 1124 | + | |
| 1125 | + pfile_in_zip_read_info->stream.total_out = 0; | |
| 1126 | + | |
| 1127 | + if ((s->cur_file_info.compression_method==Z_DEFLATED) && | |
| 1128 | + (!raw)) | |
| 1129 | + { | |
| 1130 | + pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; | |
| 1131 | + pfile_in_zip_read_info->stream.zfree = (free_func)0; | |
| 1132 | + pfile_in_zip_read_info->stream.opaque = (voidpf)0; | |
| 1133 | + pfile_in_zip_read_info->stream.next_in = (voidpf)0; | |
| 1134 | + pfile_in_zip_read_info->stream.avail_in = 0; | |
| 1135 | + | |
| 1136 | + err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); | |
| 1137 | + if (err == Z_OK) | |
| 1138 | + pfile_in_zip_read_info->stream_initialised=1; | |
| 1139 | + else | |
| 1140 | + { | |
| 1141 | + TRYFREE(pfile_in_zip_read_info); | |
| 1142 | + return err; | |
| 1143 | + } | |
| 1144 | + /* windowBits is passed < 0 to tell that there is no zlib header. | |
| 1145 | + * Note that in this case inflate *requires* an extra "dummy" byte | |
| 1146 | + * after the compressed stream in order to complete decompression and | |
| 1147 | + * return Z_STREAM_END. | |
| 1148 | + * In unzip, i don't wait absolutely Z_STREAM_END because I known the | |
| 1149 | + * size of both compressed and uncompressed data | |
| 1150 | + */ | |
| 1151 | + } | |
| 1152 | + pfile_in_zip_read_info->rest_read_compressed = | |
| 1153 | + s->cur_file_info.compressed_size ; | |
| 1154 | + pfile_in_zip_read_info->rest_read_uncompressed = | |
| 1155 | + s->cur_file_info.uncompressed_size ; | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + pfile_in_zip_read_info->pos_in_zipfile = | |
| 1159 | + s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + | |
| 1160 | + iSizeVar; | |
| 1161 | + | |
| 1162 | + pfile_in_zip_read_info->stream.avail_in = (uInt)0; | |
| 1163 | + | |
| 1164 | + s->pfile_in_zip_read = pfile_in_zip_read_info; | |
| 1165 | + | |
| 1166 | +# ifndef NOUNCRYPT | |
| 1167 | + if (password != NULL) | |
| 1168 | + { | |
| 1169 | + int i; | |
| 1170 | + s->pcrc_32_tab = get_crc_table(); | |
| 1171 | + init_keys(password,s->keys,s->pcrc_32_tab); | |
| 1172 | + if (ZSEEK(s->z_filefunc, s->filestream, | |
| 1173 | + s->pfile_in_zip_read->pos_in_zipfile + | |
| 1174 | + s->pfile_in_zip_read->byte_before_the_zipfile, | |
| 1175 | + SEEK_SET)!=0) | |
| 1176 | + return UNZ_INTERNALERROR; | |
| 1177 | + if(ZREAD(s->z_filefunc, s->filestream,source, 12)<12) | |
| 1178 | + return UNZ_INTERNALERROR; | |
| 1179 | + | |
| 1180 | + for (i = 0; i<12; i++) | |
| 1181 | + zdecode(s->keys,s->pcrc_32_tab,source[i]); | |
| 1182 | + | |
| 1183 | + s->pfile_in_zip_read->pos_in_zipfile+=12; | |
| 1184 | + s->encrypted=1; | |
| 1185 | + } | |
| 1186 | +# endif | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + return UNZ_OK; | |
| 1190 | +} | |
| 1191 | + | |
| 1192 | +extern int ZEXPORT unzOpenCurrentFile (file) | |
| 1193 | + unzFile file; | |
| 1194 | +{ | |
| 1195 | + return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL); | |
| 1196 | +} | |
| 1197 | + | |
| 1198 | +extern int ZEXPORT unzOpenCurrentFilePassword (file, password) | |
| 1199 | + unzFile file; | |
| 1200 | + const char* password; | |
| 1201 | +{ | |
| 1202 | + return unzOpenCurrentFile3(file, NULL, NULL, 0, password); | |
| 1203 | +} | |
| 1204 | + | |
| 1205 | +extern int ZEXPORT unzOpenCurrentFile2 (file,method,level,raw) | |
| 1206 | + unzFile file; | |
| 1207 | + int* method; | |
| 1208 | + int* level; | |
| 1209 | + int raw; | |
| 1210 | +{ | |
| 1211 | + return unzOpenCurrentFile3(file, method, level, raw, NULL); | |
| 1212 | +} | |
| 1213 | + | |
| 1214 | +/* | |
| 1215 | + Read bytes from the current file. | |
| 1216 | + buf contain buffer where data must be copied | |
| 1217 | + len the size of buf. | |
| 1218 | + | |
| 1219 | + return the number of byte copied if somes bytes are copied | |
| 1220 | + return 0 if the end of file was reached | |
| 1221 | + return <0 with error code if there is an error | |
| 1222 | + (UNZ_ERRNO for IO error, or zLib error for uncompress error) | |
| 1223 | +*/ | |
| 1224 | +extern int ZEXPORT unzReadCurrentFile (file, buf, len) | |
| 1225 | + unzFile file; | |
| 1226 | + voidp buf; | |
| 1227 | + unsigned len; | |
| 1228 | +{ | |
| 1229 | + int err=UNZ_OK; | |
| 1230 | + uInt iRead = 0; | |
| 1231 | + unz_s* s; | |
| 1232 | + file_in_zip_read_info_s* pfile_in_zip_read_info; | |
| 1233 | + if (file==NULL) | |
| 1234 | + return UNZ_PARAMERROR; | |
| 1235 | + s=(unz_s*)file; | |
| 1236 | + pfile_in_zip_read_info=s->pfile_in_zip_read; | |
| 1237 | + | |
| 1238 | + if (pfile_in_zip_read_info==NULL) | |
| 1239 | + return UNZ_PARAMERROR; | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + if ((pfile_in_zip_read_info->read_buffer == NULL)) | |
| 1243 | + return UNZ_END_OF_LIST_OF_FILE; | |
| 1244 | + if (len==0) | |
| 1245 | + return 0; | |
| 1246 | + | |
| 1247 | + pfile_in_zip_read_info->stream.next_out = (Bytef*)buf; | |
| 1248 | + | |
| 1249 | + pfile_in_zip_read_info->stream.avail_out = (uInt)len; | |
| 1250 | + | |
| 1251 | + if ((len>pfile_in_zip_read_info->rest_read_uncompressed) && | |
| 1252 | + (!(pfile_in_zip_read_info->raw))) | |
| 1253 | + pfile_in_zip_read_info->stream.avail_out = | |
| 1254 | + (uInt)pfile_in_zip_read_info->rest_read_uncompressed; | |
| 1255 | + | |
| 1256 | + if ((len>pfile_in_zip_read_info->rest_read_compressed+ | |
| 1257 | + pfile_in_zip_read_info->stream.avail_in) && | |
| 1258 | + (pfile_in_zip_read_info->raw)) | |
| 1259 | + pfile_in_zip_read_info->stream.avail_out = | |
| 1260 | + (uInt)pfile_in_zip_read_info->rest_read_compressed+ | |
| 1261 | + pfile_in_zip_read_info->stream.avail_in; | |
| 1262 | + | |
| 1263 | + while (pfile_in_zip_read_info->stream.avail_out>0) | |
| 1264 | + { | |
| 1265 | + if ((pfile_in_zip_read_info->stream.avail_in==0) && | |
| 1266 | + (pfile_in_zip_read_info->rest_read_compressed>0)) | |
| 1267 | + { | |
| 1268 | + uInt uReadThis = UNZ_BUFSIZE; | |
| 1269 | + if (pfile_in_zip_read_info->rest_read_compressed<uReadThis) | |
| 1270 | + uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed; | |
| 1271 | + if (uReadThis == 0) | |
| 1272 | + return UNZ_EOF; | |
| 1273 | + if (ZSEEK(pfile_in_zip_read_info->z_filefunc, | |
| 1274 | + pfile_in_zip_read_info->filestream, | |
| 1275 | + pfile_in_zip_read_info->pos_in_zipfile + | |
| 1276 | + pfile_in_zip_read_info->byte_before_the_zipfile, | |
| 1277 | + ZLIB_FILEFUNC_SEEK_SET)!=0) | |
| 1278 | + return UNZ_ERRNO; | |
| 1279 | + if (ZREAD(pfile_in_zip_read_info->z_filefunc, | |
| 1280 | + pfile_in_zip_read_info->filestream, | |
| 1281 | + pfile_in_zip_read_info->read_buffer, | |
| 1282 | + uReadThis)!=uReadThis) | |
| 1283 | + return UNZ_ERRNO; | |
| 1284 | + | |
| 1285 | + | |
| 1286 | +# ifndef NOUNCRYPT | |
| 1287 | + if(s->encrypted) | |
| 1288 | + { | |
| 1289 | + uInt i; | |
| 1290 | + for(i=0;i<uReadThis;i++) | |
| 1291 | + pfile_in_zip_read_info->read_buffer[i] = | |
| 1292 | + zdecode(s->keys,s->pcrc_32_tab, | |
| 1293 | + pfile_in_zip_read_info->read_buffer[i]); | |
| 1294 | + } | |
| 1295 | +# endif | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + pfile_in_zip_read_info->pos_in_zipfile += uReadThis; | |
| 1299 | + | |
| 1300 | + pfile_in_zip_read_info->rest_read_compressed-=uReadThis; | |
| 1301 | + | |
| 1302 | + pfile_in_zip_read_info->stream.next_in = | |
| 1303 | + (Bytef*)pfile_in_zip_read_info->read_buffer; | |
| 1304 | + pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis; | |
| 1305 | + } | |
| 1306 | + | |
| 1307 | + if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw)) | |
| 1308 | + { | |
| 1309 | + uInt uDoCopy,i ; | |
| 1310 | + | |
| 1311 | + if ((pfile_in_zip_read_info->stream.avail_in == 0) && | |
| 1312 | + (pfile_in_zip_read_info->rest_read_compressed == 0)) | |
| 1313 | + return (iRead==0) ? UNZ_EOF : iRead; | |
| 1314 | + | |
| 1315 | + if (pfile_in_zip_read_info->stream.avail_out < | |
| 1316 | + pfile_in_zip_read_info->stream.avail_in) | |
| 1317 | + uDoCopy = pfile_in_zip_read_info->stream.avail_out ; | |
| 1318 | + else | |
| 1319 | + uDoCopy = pfile_in_zip_read_info->stream.avail_in ; | |
| 1320 | + | |
| 1321 | + for (i=0;i<uDoCopy;i++) | |
| 1322 | + *(pfile_in_zip_read_info->stream.next_out+i) = | |
| 1323 | + *(pfile_in_zip_read_info->stream.next_in+i); | |
| 1324 | + | |
| 1325 | + pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, | |
| 1326 | + pfile_in_zip_read_info->stream.next_out, | |
| 1327 | + uDoCopy); | |
| 1328 | + pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy; | |
| 1329 | + pfile_in_zip_read_info->stream.avail_in -= uDoCopy; | |
| 1330 | + pfile_in_zip_read_info->stream.avail_out -= uDoCopy; | |
| 1331 | + pfile_in_zip_read_info->stream.next_out += uDoCopy; | |
| 1332 | + pfile_in_zip_read_info->stream.next_in += uDoCopy; | |
| 1333 | + pfile_in_zip_read_info->stream.total_out += uDoCopy; | |
| 1334 | + iRead += uDoCopy; | |
| 1335 | + } | |
| 1336 | + else | |
| 1337 | + { | |
| 1338 | + uLong uTotalOutBefore,uTotalOutAfter; | |
| 1339 | + const Bytef *bufBefore; | |
| 1340 | + uLong uOutThis; | |
| 1341 | + int flush=Z_SYNC_FLUSH; | |
| 1342 | + | |
| 1343 | + uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; | |
| 1344 | + bufBefore = pfile_in_zip_read_info->stream.next_out; | |
| 1345 | + | |
| 1346 | + /* | |
| 1347 | + if ((pfile_in_zip_read_info->rest_read_uncompressed == | |
| 1348 | + pfile_in_zip_read_info->stream.avail_out) && | |
| 1349 | + (pfile_in_zip_read_info->rest_read_compressed == 0)) | |
| 1350 | + flush = Z_FINISH; | |
| 1351 | + */ | |
| 1352 | + err=inflate(&pfile_in_zip_read_info->stream,flush); | |
| 1353 | + | |
| 1354 | + if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL)) | |
| 1355 | + err = Z_DATA_ERROR; | |
| 1356 | + | |
| 1357 | + uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; | |
| 1358 | + uOutThis = uTotalOutAfter-uTotalOutBefore; | |
| 1359 | + | |
| 1360 | + pfile_in_zip_read_info->crc32 = | |
| 1361 | + crc32(pfile_in_zip_read_info->crc32,bufBefore, | |
| 1362 | + (uInt)(uOutThis)); | |
| 1363 | + | |
| 1364 | + pfile_in_zip_read_info->rest_read_uncompressed -= | |
| 1365 | + uOutThis; | |
| 1366 | + | |
| 1367 | + iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); | |
| 1368 | + | |
| 1369 | + if (err==Z_STREAM_END) | |
| 1370 | + return (iRead==0) ? UNZ_EOF : iRead; | |
| 1371 | + if (err!=Z_OK) | |
| 1372 | + break; | |
| 1373 | + } | |
| 1374 | + } | |
| 1375 | + | |
| 1376 | + if (err==Z_OK) | |
| 1377 | + return iRead; | |
| 1378 | + return err; | |
| 1379 | +} | |
| 1380 | + | |
| 1381 | + | |
| 1382 | +/* | |
| 1383 | + Give the current position in uncompressed data | |
| 1384 | +*/ | |
| 1385 | +extern z_off_t ZEXPORT unztell (file) | |
| 1386 | + unzFile file; | |
| 1387 | +{ | |
| 1388 | + unz_s* s; | |
| 1389 | + file_in_zip_read_info_s* pfile_in_zip_read_info; | |
| 1390 | + if (file==NULL) | |
| 1391 | + return UNZ_PARAMERROR; | |
| 1392 | + s=(unz_s*)file; | |
| 1393 | + pfile_in_zip_read_info=s->pfile_in_zip_read; | |
| 1394 | + | |
| 1395 | + if (pfile_in_zip_read_info==NULL) | |
| 1396 | + return UNZ_PARAMERROR; | |
| 1397 | + | |
| 1398 | + return (z_off_t)pfile_in_zip_read_info->stream.total_out; | |
| 1399 | +} | |
| 1400 | + | |
| 1401 | + | |
| 1402 | +/* | |
| 1403 | + return 1 if the end of file was reached, 0 elsewhere | |
| 1404 | +*/ | |
| 1405 | +extern int ZEXPORT unzeof (file) | |
| 1406 | + unzFile file; | |
| 1407 | +{ | |
| 1408 | + unz_s* s; | |
| 1409 | + file_in_zip_read_info_s* pfile_in_zip_read_info; | |
| 1410 | + if (file==NULL) | |
| 1411 | + return UNZ_PARAMERROR; | |
| 1412 | + s=(unz_s*)file; | |
| 1413 | + pfile_in_zip_read_info=s->pfile_in_zip_read; | |
| 1414 | + | |
| 1415 | + if (pfile_in_zip_read_info==NULL) | |
| 1416 | + return UNZ_PARAMERROR; | |
| 1417 | + | |
| 1418 | + if (pfile_in_zip_read_info->rest_read_uncompressed == 0) | |
| 1419 | + return 1; | |
| 1420 | + else | |
| 1421 | + return 0; | |
| 1422 | +} | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | +/* | |
| 1427 | + Read extra field from the current file (opened by unzOpenCurrentFile) | |
| 1428 | + This is the local-header version of the extra field (sometimes, there is | |
| 1429 | + more info in the local-header version than in the central-header) | |
| 1430 | + | |
| 1431 | + if buf==NULL, it return the size of the local extra field that can be read | |
| 1432 | + | |
| 1433 | + if buf!=NULL, len is the size of the buffer, the extra header is copied in | |
| 1434 | + buf. | |
| 1435 | + the return value is the number of bytes copied in buf, or (if <0) | |
| 1436 | + the error code | |
| 1437 | +*/ | |
| 1438 | +extern int ZEXPORT unzGetLocalExtrafield (file,buf,len) | |
| 1439 | + unzFile file; | |
| 1440 | + voidp buf; | |
| 1441 | + unsigned len; | |
| 1442 | +{ | |
| 1443 | + unz_s* s; | |
| 1444 | + file_in_zip_read_info_s* pfile_in_zip_read_info; | |
| 1445 | + uInt read_now; | |
| 1446 | + uLong size_to_read; | |
| 1447 | + | |
| 1448 | + if (file==NULL) | |
| 1449 | + return UNZ_PARAMERROR; | |
| 1450 | + s=(unz_s*)file; | |
| 1451 | + pfile_in_zip_read_info=s->pfile_in_zip_read; | |
| 1452 | + | |
| 1453 | + if (pfile_in_zip_read_info==NULL) | |
| 1454 | + return UNZ_PARAMERROR; | |
| 1455 | + | |
| 1456 | + size_to_read = (pfile_in_zip_read_info->size_local_extrafield - | |
| 1457 | + pfile_in_zip_read_info->pos_local_extrafield); | |
| 1458 | + | |
| 1459 | + if (buf==NULL) | |
| 1460 | + return (int)size_to_read; | |
| 1461 | + | |
| 1462 | + if (len>size_to_read) | |
| 1463 | + read_now = (uInt)size_to_read; | |
| 1464 | + else | |
| 1465 | + read_now = (uInt)len ; | |
| 1466 | + | |
| 1467 | + if (read_now==0) | |
| 1468 | + return 0; | |
| 1469 | + | |
| 1470 | + if (ZSEEK(pfile_in_zip_read_info->z_filefunc, | |
| 1471 | + pfile_in_zip_read_info->filestream, | |
| 1472 | + pfile_in_zip_read_info->offset_local_extrafield + | |
| 1473 | + pfile_in_zip_read_info->pos_local_extrafield, | |
| 1474 | + ZLIB_FILEFUNC_SEEK_SET)!=0) | |
| 1475 | + return UNZ_ERRNO; | |
| 1476 | + | |
| 1477 | + if (ZREAD(pfile_in_zip_read_info->z_filefunc, | |
| 1478 | + pfile_in_zip_read_info->filestream, | |
| 1479 | + buf,read_now)!=read_now) | |
| 1480 | + return UNZ_ERRNO; | |
| 1481 | + | |
| 1482 | + return (int)read_now; | |
| 1483 | +} | |
| 1484 | + | |
| 1485 | +/* | |
| 1486 | + Close the file in zip opened with unzipOpenCurrentFile | |
| 1487 | + Return UNZ_CRCERROR if all the file was read but the CRC is not good | |
| 1488 | +*/ | |
| 1489 | +extern int ZEXPORT unzCloseCurrentFile (file) | |
| 1490 | + unzFile file; | |
| 1491 | +{ | |
| 1492 | + int err=UNZ_OK; | |
| 1493 | + | |
| 1494 | + unz_s* s; | |
| 1495 | + file_in_zip_read_info_s* pfile_in_zip_read_info; | |
| 1496 | + if (file==NULL) | |
| 1497 | + return UNZ_PARAMERROR; | |
| 1498 | + s=(unz_s*)file; | |
| 1499 | + pfile_in_zip_read_info=s->pfile_in_zip_read; | |
| 1500 | + | |
| 1501 | + if (pfile_in_zip_read_info==NULL) | |
| 1502 | + return UNZ_PARAMERROR; | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) && | |
| 1506 | + (!pfile_in_zip_read_info->raw)) | |
| 1507 | + { | |
| 1508 | + if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait) | |
| 1509 | + err=UNZ_CRCERROR; | |
| 1510 | + } | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + TRYFREE(pfile_in_zip_read_info->read_buffer); | |
| 1514 | + pfile_in_zip_read_info->read_buffer = NULL; | |
| 1515 | + if (pfile_in_zip_read_info->stream_initialised) | |
| 1516 | + inflateEnd(&pfile_in_zip_read_info->stream); | |
| 1517 | + | |
| 1518 | + pfile_in_zip_read_info->stream_initialised = 0; | |
| 1519 | + TRYFREE(pfile_in_zip_read_info); | |
| 1520 | + | |
| 1521 | + s->pfile_in_zip_read=NULL; | |
| 1522 | + | |
| 1523 | + return err; | |
| 1524 | +} | |
| 1525 | + | |
| 1526 | + | |
| 1527 | +/* | |
| 1528 | + Get the global comment string of the ZipFile, in the szComment buffer. | |
| 1529 | + uSizeBuf is the size of the szComment buffer. | |
| 1530 | + return the number of byte copied or an error code <0 | |
| 1531 | +*/ | |
| 1532 | +extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf) | |
| 1533 | + unzFile file; | |
| 1534 | + char *szComment; | |
| 1535 | + uLong uSizeBuf; | |
| 1536 | +{ | |
| 1537 | + int err=UNZ_OK; | |
| 1538 | + unz_s* s; | |
| 1539 | + uLong uReadThis ; | |
| 1540 | + if (file==NULL) | |
| 1541 | + return UNZ_PARAMERROR; | |
| 1542 | + s=(unz_s*)file; | |
| 1543 | + | |
| 1544 | + uReadThis = uSizeBuf; | |
| 1545 | + if (uReadThis>s->gi.size_comment) | |
| 1546 | + uReadThis = s->gi.size_comment; | |
| 1547 | + | |
| 1548 | + if (ZSEEK(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0) | |
| 1549 | + return UNZ_ERRNO; | |
| 1550 | + | |
| 1551 | + if (uReadThis>0) | |
| 1552 | + { | |
| 1553 | + *szComment='\0'; | |
| 1554 | + if (ZREAD(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis) | |
| 1555 | + return UNZ_ERRNO; | |
| 1556 | + } | |
| 1557 | + | |
| 1558 | + if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment)) | |
| 1559 | + *(szComment+s->gi.size_comment)='\0'; | |
| 1560 | + return (int)uReadThis; | |
| 1561 | +} | |
| 1562 | + | |
| 1563 | +/* Additions by RX '2004 */ | |
| 1564 | +extern uLong ZEXPORT unzGetOffset (file) | |
| 1565 | + unzFile file; | |
| 1566 | +{ | |
| 1567 | + unz_s* s; | |
| 1568 | + | |
| 1569 | + if (file==NULL) | |
| 1570 | + return UNZ_PARAMERROR; | |
| 1571 | + s=(unz_s*)file; | |
| 1572 | + if (!s->current_file_ok) | |
| 1573 | + return 0; | |
| 1574 | + if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff) | |
| 1575 | + if (s->num_file==s->gi.number_entry) | |
| 1576 | + return 0; | |
| 1577 | + return s->pos_in_central_dir; | |
| 1578 | +} | |
| 1579 | + | |
| 1580 | +extern int ZEXPORT unzSetOffset (file, pos) | |
| 1581 | + unzFile file; | |
| 1582 | + uLong pos; | |
| 1583 | +{ | |
| 1584 | + unz_s* s; | |
| 1585 | + int err; | |
| 1586 | + | |
| 1587 | + if (file==NULL) | |
| 1588 | + return UNZ_PARAMERROR; | |
| 1589 | + s=(unz_s*)file; | |
| 1590 | + | |
| 1591 | + s->pos_in_central_dir = pos; | |
| 1592 | + s->num_file = s->gi.number_entry; /* hack */ | |
| 1593 | + err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, | |
| 1594 | + &s->cur_file_info_internal, | |
| 1595 | + NULL,0,NULL,0,NULL,0); | |
| 1596 | + s->current_file_ok = (err == UNZ_OK); | |
| 1597 | + return err; | |
| 1598 | +} |
| @@ -0,0 +1,75 @@ | ||
| 1 | +/* ioapi.h -- IO base function header for compress/uncompress .zip | |
| 2 | + files using zlib + zip or unzip API | |
| 3 | + | |
| 4 | + Version 1.01e, February 12th, 2005 | |
| 5 | + | |
| 6 | + Copyright (C) 1998-2005 Gilles Vollant | |
| 7 | +*/ | |
| 8 | + | |
| 9 | +#ifndef _ZLIBIOAPI_H | |
| 10 | +#define _ZLIBIOAPI_H | |
| 11 | + | |
| 12 | + | |
| 13 | +#define ZLIB_FILEFUNC_SEEK_CUR (1) | |
| 14 | +#define ZLIB_FILEFUNC_SEEK_END (2) | |
| 15 | +#define ZLIB_FILEFUNC_SEEK_SET (0) | |
| 16 | + | |
| 17 | +#define ZLIB_FILEFUNC_MODE_READ (1) | |
| 18 | +#define ZLIB_FILEFUNC_MODE_WRITE (2) | |
| 19 | +#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) | |
| 20 | + | |
| 21 | +#define ZLIB_FILEFUNC_MODE_EXISTING (4) | |
| 22 | +#define ZLIB_FILEFUNC_MODE_CREATE (8) | |
| 23 | + | |
| 24 | + | |
| 25 | +#ifndef ZCALLBACK | |
| 26 | + | |
| 27 | +#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) | |
| 28 | +#define ZCALLBACK CALLBACK | |
| 29 | +#else | |
| 30 | +#define ZCALLBACK | |
| 31 | +#endif | |
| 32 | +#endif | |
| 33 | + | |
| 34 | +#ifdef __cplusplus | |
| 35 | +extern "C" { | |
| 36 | +#endif | |
| 37 | + | |
| 38 | +typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); | |
| 39 | +typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); | |
| 40 | +typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); | |
| 41 | +typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); | |
| 42 | +typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); | |
| 43 | +typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); | |
| 44 | +typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); | |
| 45 | + | |
| 46 | +typedef struct zlib_filefunc_def_s | |
| 47 | +{ | |
| 48 | + open_file_func zopen_file; | |
| 49 | + read_file_func zread_file; | |
| 50 | + write_file_func zwrite_file; | |
| 51 | + tell_file_func ztell_file; | |
| 52 | + seek_file_func zseek_file; | |
| 53 | + close_file_func zclose_file; | |
| 54 | + testerror_file_func zerror_file; | |
| 55 | + voidpf opaque; | |
| 56 | +} zlib_filefunc_def; | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | +void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); | |
| 61 | + | |
| 62 | +#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size)) | |
| 63 | +#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size)) | |
| 64 | +#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream)) | |
| 65 | +#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode)) | |
| 66 | +#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream)) | |
| 67 | +#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream)) | |
| 68 | + | |
| 69 | + | |
| 70 | +#ifdef __cplusplus | |
| 71 | +} | |
| 72 | +#endif | |
| 73 | + | |
| 74 | +#endif | |
| 75 | + |
| @@ -0,0 +1,132 @@ | ||
| 1 | +/* crypt.h -- base code for crypt/uncrypt ZIPfile | |
| 2 | + | |
| 3 | + | |
| 4 | + Version 1.01e, February 12th, 2005 | |
| 5 | + | |
| 6 | + Copyright (C) 1998-2005 Gilles Vollant | |
| 7 | + | |
| 8 | + This code is a modified version of crypting code in Infozip distribution | |
| 9 | + | |
| 10 | + The encryption/decryption parts of this source code (as opposed to the | |
| 11 | + non-echoing password parts) were originally written in Europe. The | |
| 12 | + whole source package can be freely distributed, including from the USA. | |
| 13 | + (Prior to January 2000, re-export from the US was a violation of US law.) | |
| 14 | + | |
| 15 | + This encryption code is a direct transcription of the algorithm from | |
| 16 | + Roger Schlafly, described by Phil Katz in the file appnote.txt. This | |
| 17 | + file (appnote.txt) is distributed with the PKZIP program (even in the | |
| 18 | + version without encryption capabilities). | |
| 19 | + | |
| 20 | + If you don't need crypting in your application, just define symbols | |
| 21 | + NOCRYPT and NOUNCRYPT. | |
| 22 | + | |
| 23 | + This code support the "Traditional PKWARE Encryption". | |
| 24 | + | |
| 25 | + The new AES encryption added on Zip format by Winzip (see the page | |
| 26 | + http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong | |
| 27 | + Encryption is not supported. | |
| 28 | +*/ | |
| 29 | + | |
| 30 | +#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) | |
| 31 | + | |
| 32 | +/*********************************************************************** | |
| 33 | + * Return the next byte in the pseudo-random sequence | |
| 34 | + */ | |
| 35 | +static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab) | |
| 36 | +{ | |
| 37 | + unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an | |
| 38 | + * unpredictable manner on 16-bit systems; not a problem | |
| 39 | + * with any known compiler so far, though */ | |
| 40 | + | |
| 41 | + temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; | |
| 42 | + return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); | |
| 43 | +} | |
| 44 | + | |
| 45 | +/*********************************************************************** | |
| 46 | + * Update the encryption keys with the next byte of plain text | |
| 47 | + */ | |
| 48 | +static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c) | |
| 49 | +{ | |
| 50 | + (*(pkeys+0)) = CRC32((*(pkeys+0)), c); | |
| 51 | + (*(pkeys+1)) += (*(pkeys+0)) & 0xff; | |
| 52 | + (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; | |
| 53 | + { | |
| 54 | + register int keyshift = (int)((*(pkeys+1)) >> 24); | |
| 55 | + (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift); | |
| 56 | + } | |
| 57 | + return c; | |
| 58 | +} | |
| 59 | + | |
| 60 | + | |
| 61 | +/*********************************************************************** | |
| 62 | + * Initialize the encryption keys and the random header according to | |
| 63 | + * the given password. | |
| 64 | + */ | |
| 65 | +static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab) | |
| 66 | +{ | |
| 67 | + *(pkeys+0) = 305419896L; | |
| 68 | + *(pkeys+1) = 591751049L; | |
| 69 | + *(pkeys+2) = 878082192L; | |
| 70 | + while (*passwd != '\0') { | |
| 71 | + update_keys(pkeys,pcrc_32_tab,(int)*passwd); | |
| 72 | + passwd++; | |
| 73 | + } | |
| 74 | +} | |
| 75 | + | |
| 76 | +#define zdecode(pkeys,pcrc_32_tab,c) \ | |
| 77 | + (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab))) | |
| 78 | + | |
| 79 | +#define zencode(pkeys,pcrc_32_tab,c,t) \ | |
| 80 | + (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) | |
| 81 | + | |
| 82 | +#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED | |
| 83 | + | |
| 84 | +#define RAND_HEAD_LEN 12 | |
| 85 | + /* "last resort" source for second part of crypt seed pattern */ | |
| 86 | +# ifndef ZCR_SEED2 | |
| 87 | +# define ZCR_SEED2 3141592654UL /* use PI as default pattern */ | |
| 88 | +# endif | |
| 89 | + | |
| 90 | +static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting) | |
| 91 | + const char *passwd; /* password string */ | |
| 92 | + unsigned char *buf; /* where to write header */ | |
| 93 | + int bufSize; | |
| 94 | + unsigned long* pkeys; | |
| 95 | + const unsigned long* pcrc_32_tab; | |
| 96 | + unsigned long crcForCrypting; | |
| 97 | +{ | |
| 98 | + int n; /* index in random header */ | |
| 99 | + int t; /* temporary */ | |
| 100 | + int c; /* random byte */ | |
| 101 | + unsigned char header[RAND_HEAD_LEN-2]; /* random header */ | |
| 102 | + static unsigned calls = 0; /* ensure different random header each time */ | |
| 103 | + | |
| 104 | + if (bufSize<RAND_HEAD_LEN) | |
| 105 | + return 0; | |
| 106 | + | |
| 107 | + /* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the | |
| 108 | + * output of rand() to get less predictability, since rand() is | |
| 109 | + * often poorly implemented. | |
| 110 | + */ | |
| 111 | + if (++calls == 1) | |
| 112 | + { | |
| 113 | + srand((unsigned)(time(NULL) ^ ZCR_SEED2)); | |
| 114 | + } | |
| 115 | + init_keys(passwd, pkeys, pcrc_32_tab); | |
| 116 | + for (n = 0; n < RAND_HEAD_LEN-2; n++) | |
| 117 | + { | |
| 118 | + c = (rand() >> 7) & 0xff; | |
| 119 | + header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t); | |
| 120 | + } | |
| 121 | + /* Encrypt random header (last two bytes is high word of crc) */ | |
| 122 | + init_keys(passwd, pkeys, pcrc_32_tab); | |
| 123 | + for (n = 0; n < RAND_HEAD_LEN-2; n++) | |
| 124 | + { | |
| 125 | + buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); | |
| 126 | + } | |
| 127 | + buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); | |
| 128 | + buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); | |
| 129 | + return n; | |
| 130 | +} | |
| 131 | + | |
| 132 | +#endif |
| @@ -0,0 +1,235 @@ | ||
| 1 | +/* zip.h -- IO for compress .zip files using zlib | |
| 2 | + Version 1.01e, February 12th, 2005 | |
| 3 | + | |
| 4 | + Copyright (C) 1998-2005 Gilles Vollant | |
| 5 | + | |
| 6 | + This unzip package allow creates .ZIP file, compatible with PKZip 2.04g | |
| 7 | + WinZip, InfoZip tools and compatible. | |
| 8 | + Multi volume ZipFile (span) are not supported. | |
| 9 | + Encryption compatible with pkzip 2.04g only supported | |
| 10 | + Old compressions used by old PKZip 1.x are not supported | |
| 11 | + | |
| 12 | + For uncompress .zip file, look at unzip.h | |
| 13 | + | |
| 14 | + | |
| 15 | + I WAIT FEEDBACK at mail info@winimage.com | |
| 16 | + Visit also http://www.winimage.com/zLibDll/unzip.html for evolution | |
| 17 | + | |
| 18 | + Condition of use and distribution are the same than zlib : | |
| 19 | + | |
| 20 | + This software is provided 'as-is', without any express or implied | |
| 21 | + warranty. In no event will the authors be held liable for any damages | |
| 22 | + arising from the use of this software. | |
| 23 | + | |
| 24 | + Permission is granted to anyone to use this software for any purpose, | |
| 25 | + including commercial applications, and to alter it and redistribute it | |
| 26 | + freely, subject to the following restrictions: | |
| 27 | + | |
| 28 | + 1. The origin of this software must not be misrepresented; you must not | |
| 29 | + claim that you wrote the original software. If you use this software | |
| 30 | + in a product, an acknowledgment in the product documentation would be | |
| 31 | + appreciated but is not required. | |
| 32 | + 2. Altered source versions must be plainly marked as such, and must not be | |
| 33 | + misrepresented as being the original software. | |
| 34 | + 3. This notice may not be removed or altered from any source distribution. | |
| 35 | + | |
| 36 | + | |
| 37 | +*/ | |
| 38 | + | |
| 39 | +/* for more info about .ZIP format, see | |
| 40 | + http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip | |
| 41 | + http://www.info-zip.org/pub/infozip/doc/ | |
| 42 | + PkWare has also a specification at : | |
| 43 | + ftp://ftp.pkware.com/probdesc.zip | |
| 44 | +*/ | |
| 45 | + | |
| 46 | +#ifndef _zip_H | |
| 47 | +#define _zip_H | |
| 48 | + | |
| 49 | +#ifdef __cplusplus | |
| 50 | +extern "C" { | |
| 51 | +#endif | |
| 52 | + | |
| 53 | +#ifndef _ZLIB_H | |
| 54 | +#include "zlib.h" | |
| 55 | +#endif | |
| 56 | + | |
| 57 | +#ifndef _ZLIBIOAPI_H | |
| 58 | +#include "ioapi.h" | |
| 59 | +#endif | |
| 60 | + | |
| 61 | +#if defined(STRICTZIP) || defined(STRICTZIPUNZIP) | |
| 62 | +/* like the STRICT of WIN32, we define a pointer that cannot be converted | |
| 63 | + from (void*) without cast */ | |
| 64 | +typedef struct TagzipFile__ { int unused; } zipFile__; | |
| 65 | +typedef zipFile__ *zipFile; | |
| 66 | +#else | |
| 67 | +typedef voidp zipFile; | |
| 68 | +#endif | |
| 69 | + | |
| 70 | +#define ZIP_OK (0) | |
| 71 | +#define ZIP_EOF (0) | |
| 72 | +#define ZIP_ERRNO (Z_ERRNO) | |
| 73 | +#define ZIP_PARAMERROR (-102) | |
| 74 | +#define ZIP_BADZIPFILE (-103) | |
| 75 | +#define ZIP_INTERNALERROR (-104) | |
| 76 | + | |
| 77 | +#ifndef DEF_MEM_LEVEL | |
| 78 | +# if MAX_MEM_LEVEL >= 8 | |
| 79 | +# define DEF_MEM_LEVEL 8 | |
| 80 | +# else | |
| 81 | +# define DEF_MEM_LEVEL MAX_MEM_LEVEL | |
| 82 | +# endif | |
| 83 | +#endif | |
| 84 | +/* default memLevel */ | |
| 85 | + | |
| 86 | +/* tm_zip contain date/time info */ | |
| 87 | +typedef struct tm_zip_s | |
| 88 | +{ | |
| 89 | + uInt tm_sec; /* seconds after the minute - [0,59] */ | |
| 90 | + uInt tm_min; /* minutes after the hour - [0,59] */ | |
| 91 | + uInt tm_hour; /* hours since midnight - [0,23] */ | |
| 92 | + uInt tm_mday; /* day of the month - [1,31] */ | |
| 93 | + uInt tm_mon; /* months since January - [0,11] */ | |
| 94 | + uInt tm_year; /* years - [1980..2044] */ | |
| 95 | +} tm_zip; | |
| 96 | + | |
| 97 | +typedef struct | |
| 98 | +{ | |
| 99 | + tm_zip tmz_date; /* date in understandable format */ | |
| 100 | + uLong dosDate; /* if dos_date == 0, tmu_date is used */ | |
| 101 | +/* uLong flag; */ /* general purpose bit flag 2 bytes */ | |
| 102 | + | |
| 103 | + uLong internal_fa; /* internal file attributes 2 bytes */ | |
| 104 | + uLong external_fa; /* external file attributes 4 bytes */ | |
| 105 | +} zip_fileinfo; | |
| 106 | + | |
| 107 | +typedef const char* zipcharpc; | |
| 108 | + | |
| 109 | + | |
| 110 | +#define APPEND_STATUS_CREATE (0) | |
| 111 | +#define APPEND_STATUS_CREATEAFTER (1) | |
| 112 | +#define APPEND_STATUS_ADDINZIP (2) | |
| 113 | + | |
| 114 | +extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append)); | |
| 115 | +/* | |
| 116 | + Create a zipfile. | |
| 117 | + pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on | |
| 118 | + an Unix computer "zlib/zlib113.zip". | |
| 119 | + if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip | |
| 120 | + will be created at the end of the file. | |
| 121 | + (useful if the file contain a self extractor code) | |
| 122 | + if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will | |
| 123 | + add files in existing zip (be sure you don't add file that doesn't exist) | |
| 124 | + If the zipfile cannot be opened, the return value is NULL. | |
| 125 | + Else, the return value is a zipFile Handle, usable with other function | |
| 126 | + of this zip package. | |
| 127 | +*/ | |
| 128 | + | |
| 129 | +/* Note : there is no delete function into a zipfile. | |
| 130 | + If you want delete file into a zipfile, you must open a zipfile, and create another | |
| 131 | + Of couse, you can use RAW reading and writing to copy the file you did not want delte | |
| 132 | +*/ | |
| 133 | + | |
| 134 | +extern zipFile ZEXPORT zipOpen2 OF((const char *pathname, | |
| 135 | + int append, | |
| 136 | + zipcharpc* globalcomment, | |
| 137 | + zlib_filefunc_def* pzlib_filefunc_def)); | |
| 138 | + | |
| 139 | +extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, | |
| 140 | + const char* filename, | |
| 141 | + const zip_fileinfo* zipfi, | |
| 142 | + const void* extrafield_local, | |
| 143 | + uInt size_extrafield_local, | |
| 144 | + const void* extrafield_global, | |
| 145 | + uInt size_extrafield_global, | |
| 146 | + const char* comment, | |
| 147 | + int method, | |
| 148 | + int level)); | |
| 149 | +/* | |
| 150 | + Open a file in the ZIP for writing. | |
| 151 | + filename : the filename in zip (if NULL, '-' without quote will be used | |
| 152 | + *zipfi contain supplemental information | |
| 153 | + if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local | |
| 154 | + contains the extrafield data the the local header | |
| 155 | + if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global | |
| 156 | + contains the extrafield data the the local header | |
| 157 | + if comment != NULL, comment contain the comment string | |
| 158 | + method contain the compression method (0 for store, Z_DEFLATED for deflate) | |
| 159 | + level contain the level of compression (can be Z_DEFAULT_COMPRESSION) | |
| 160 | +*/ | |
| 161 | + | |
| 162 | + | |
| 163 | +extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file, | |
| 164 | + const char* filename, | |
| 165 | + const zip_fileinfo* zipfi, | |
| 166 | + const void* extrafield_local, | |
| 167 | + uInt size_extrafield_local, | |
| 168 | + const void* extrafield_global, | |
| 169 | + uInt size_extrafield_global, | |
| 170 | + const char* comment, | |
| 171 | + int method, | |
| 172 | + int level, | |
| 173 | + int raw)); | |
| 174 | + | |
| 175 | +/* | |
| 176 | + Same than zipOpenNewFileInZip, except if raw=1, we write raw file | |
| 177 | + */ | |
| 178 | + | |
| 179 | +extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file, | |
| 180 | + const char* filename, | |
| 181 | + const zip_fileinfo* zipfi, | |
| 182 | + const void* extrafield_local, | |
| 183 | + uInt size_extrafield_local, | |
| 184 | + const void* extrafield_global, | |
| 185 | + uInt size_extrafield_global, | |
| 186 | + const char* comment, | |
| 187 | + int method, | |
| 188 | + int level, | |
| 189 | + int raw, | |
| 190 | + int windowBits, | |
| 191 | + int memLevel, | |
| 192 | + int strategy, | |
| 193 | + const char* password, | |
| 194 | + uLong crcForCtypting)); | |
| 195 | + | |
| 196 | +/* | |
| 197 | + Same than zipOpenNewFileInZip2, except | |
| 198 | + windowBits,memLevel,,strategy : see parameter strategy in deflateInit2 | |
| 199 | + password : crypting password (NULL for no crypting) | |
| 200 | + crcForCtypting : crc of file to compress (needed for crypting) | |
| 201 | + */ | |
| 202 | + | |
| 203 | + | |
| 204 | +extern int ZEXPORT zipWriteInFileInZip OF((zipFile file, | |
| 205 | + const void* buf, | |
| 206 | + unsigned len)); | |
| 207 | +/* | |
| 208 | + Write data in the zipfile | |
| 209 | +*/ | |
| 210 | + | |
| 211 | +extern int ZEXPORT zipCloseFileInZip OF((zipFile file)); | |
| 212 | +/* | |
| 213 | + Close the current file in the zipfile | |
| 214 | +*/ | |
| 215 | + | |
| 216 | +extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, | |
| 217 | + uLong uncompressed_size, | |
| 218 | + uLong crc32)); | |
| 219 | +/* | |
| 220 | + Close the current file in the zipfile, for fiel opened with | |
| 221 | + parameter raw=1 in zipOpenNewFileInZip2 | |
| 222 | + uncompressed_size and crc32 are value for the uncompressed size | |
| 223 | +*/ | |
| 224 | + | |
| 225 | +extern int ZEXPORT zipClose OF((zipFile file, | |
| 226 | + const char* global_comment)); | |
| 227 | +/* | |
| 228 | + Close the zipfile | |
| 229 | +*/ | |
| 230 | + | |
| 231 | +#ifdef __cplusplus | |
| 232 | +} | |
| 233 | +#endif | |
| 234 | + | |
| 235 | +#endif /* _zip_H */ |
| @@ -0,0 +1,281 @@ | ||
| 1 | +/* | |
| 2 | + Additional tools for Minizip | |
| 3 | + Code: Xavier Roche '2004 | |
| 4 | + License: Same as ZLIB (www.gzip.org) | |
| 5 | +*/ | |
| 6 | + | |
| 7 | +/* Code */ | |
| 8 | +#include <stdio.h> | |
| 9 | +#include <stdlib.h> | |
| 10 | +#include <string.h> | |
| 11 | +#include "zlib.h" | |
| 12 | +#include "unzip.h" | |
| 13 | + | |
| 14 | +#define READ_8(adr) ((unsigned char)*(adr)) | |
| 15 | +#define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) ) | |
| 16 | +#define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) ) | |
| 17 | + | |
| 18 | +#define WRITE_8(buff, n) do { \ | |
| 19 | + *((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \ | |
| 20 | +} while(0) | |
| 21 | +#define WRITE_16(buff, n) do { \ | |
| 22 | + WRITE_8((unsigned char*)(buff), n); \ | |
| 23 | + WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \ | |
| 24 | +} while(0) | |
| 25 | +#define WRITE_32(buff, n) do { \ | |
| 26 | + WRITE_16((unsigned char*)(buff), (n) & 0xffff); \ | |
| 27 | + WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \ | |
| 28 | +} while(0) | |
| 29 | + | |
| 30 | +extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered) | |
| 31 | +const char* file; | |
| 32 | +const char* fileOut; | |
| 33 | +const char* fileOutTmp; | |
| 34 | +uLong* nRecovered; | |
| 35 | +uLong* bytesRecovered; | |
| 36 | +{ | |
| 37 | + int err = Z_OK; | |
| 38 | + FILE* fpZip = fopen(file, "rb"); | |
| 39 | + FILE* fpOut = fopen(fileOut, "wb"); | |
| 40 | + FILE* fpOutCD = fopen(fileOutTmp, "wb"); | |
| 41 | + if (fpZip != NULL && fpOut != NULL) { | |
| 42 | + int entries = 0; | |
| 43 | + uLong totalBytes = 0; | |
| 44 | + char header[30]; | |
| 45 | + char filename[256]; | |
| 46 | + char extra[1024]; | |
| 47 | + int offset = 0; | |
| 48 | + int offsetCD = 0; | |
| 49 | + while ( fread(header, 1, 30, fpZip) == 30 ) { | |
| 50 | + int currentOffset = offset; | |
| 51 | + | |
| 52 | + /* File entry */ | |
| 53 | + if (READ_32(header) == 0x04034b50) { | |
| 54 | + unsigned int version = READ_16(header + 4); | |
| 55 | + unsigned int gpflag = READ_16(header + 6); | |
| 56 | + unsigned int method = READ_16(header + 8); | |
| 57 | + unsigned int filetime = READ_16(header + 10); | |
| 58 | + unsigned int filedate = READ_16(header + 12); | |
| 59 | + unsigned int crc = READ_32(header + 14); /* crc */ | |
| 60 | + unsigned int cpsize = READ_32(header + 18); /* compressed size */ | |
| 61 | + unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */ | |
| 62 | + unsigned int fnsize = READ_16(header + 26); /* file name length */ | |
| 63 | + unsigned int extsize = READ_16(header + 28); /* extra field length */ | |
| 64 | + filename[0] = extra[0] = '\0'; | |
| 65 | + | |
| 66 | + /* Header */ | |
| 67 | + if (fwrite(header, 1, 30, fpOut) == 30) { | |
| 68 | + offset += 30; | |
| 69 | + } else { | |
| 70 | + err = Z_ERRNO; | |
| 71 | + break; | |
| 72 | + } | |
| 73 | + | |
| 74 | + /* Filename */ | |
| 75 | + if (fnsize > 0) { | |
| 76 | + if (fread(filename, 1, fnsize, fpZip) == fnsize) { | |
| 77 | + if (fwrite(filename, 1, fnsize, fpOut) == fnsize) { | |
| 78 | + offset += fnsize; | |
| 79 | + } else { | |
| 80 | + err = Z_ERRNO; | |
| 81 | + break; | |
| 82 | + } | |
| 83 | + } else { | |
| 84 | + err = Z_ERRNO; | |
| 85 | + break; | |
| 86 | + } | |
| 87 | + } else { | |
| 88 | + err = Z_STREAM_ERROR; | |
| 89 | + break; | |
| 90 | + } | |
| 91 | + | |
| 92 | + /* Extra field */ | |
| 93 | + if (extsize > 0) { | |
| 94 | + if (fread(extra, 1, extsize, fpZip) == extsize) { | |
| 95 | + if (fwrite(extra, 1, extsize, fpOut) == extsize) { | |
| 96 | + offset += extsize; | |
| 97 | + } else { | |
| 98 | + err = Z_ERRNO; | |
| 99 | + break; | |
| 100 | + } | |
| 101 | + } else { | |
| 102 | + err = Z_ERRNO; | |
| 103 | + break; | |
| 104 | + } | |
| 105 | + } | |
| 106 | + | |
| 107 | + /* Data */ | |
| 108 | + { | |
| 109 | + int dataSize = cpsize; | |
| 110 | + if (dataSize == 0) { | |
| 111 | + dataSize = uncpsize; | |
| 112 | + } | |
| 113 | + if (dataSize > 0) { | |
| 114 | + char* data = malloc(dataSize); | |
| 115 | + if (data != NULL) { | |
| 116 | + if ((int)fread(data, 1, dataSize, fpZip) == dataSize) { | |
| 117 | + if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) { | |
| 118 | + offset += dataSize; | |
| 119 | + totalBytes += dataSize; | |
| 120 | + } else { | |
| 121 | + err = Z_ERRNO; | |
| 122 | + } | |
| 123 | + } else { | |
| 124 | + err = Z_ERRNO; | |
| 125 | + } | |
| 126 | + free(data); | |
| 127 | + if (err != Z_OK) { | |
| 128 | + break; | |
| 129 | + } | |
| 130 | + } else { | |
| 131 | + err = Z_MEM_ERROR; | |
| 132 | + break; | |
| 133 | + } | |
| 134 | + } | |
| 135 | + } | |
| 136 | + | |
| 137 | + /* Central directory entry */ | |
| 138 | + { | |
| 139 | + char header[46]; | |
| 140 | + char* comment = ""; | |
| 141 | + int comsize = (int) strlen(comment); | |
| 142 | + WRITE_32(header, 0x02014b50); | |
| 143 | + WRITE_16(header + 4, version); | |
| 144 | + WRITE_16(header + 6, version); | |
| 145 | + WRITE_16(header + 8, gpflag); | |
| 146 | + WRITE_16(header + 10, method); | |
| 147 | + WRITE_16(header + 12, filetime); | |
| 148 | + WRITE_16(header + 14, filedate); | |
| 149 | + WRITE_32(header + 16, crc); | |
| 150 | + WRITE_32(header + 20, cpsize); | |
| 151 | + WRITE_32(header + 24, uncpsize); | |
| 152 | + WRITE_16(header + 28, fnsize); | |
| 153 | + WRITE_16(header + 30, extsize); | |
| 154 | + WRITE_16(header + 32, comsize); | |
| 155 | + WRITE_16(header + 34, 0); /* disk # */ | |
| 156 | + WRITE_16(header + 36, 0); /* int attrb */ | |
| 157 | + WRITE_32(header + 38, 0); /* ext attrb */ | |
| 158 | + WRITE_32(header + 42, currentOffset); | |
| 159 | + /* Header */ | |
| 160 | + if (fwrite(header, 1, 46, fpOutCD) == 46) { | |
| 161 | + offsetCD += 46; | |
| 162 | + | |
| 163 | + /* Filename */ | |
| 164 | + if (fnsize > 0) { | |
| 165 | + if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) { | |
| 166 | + offsetCD += fnsize; | |
| 167 | + } else { | |
| 168 | + err = Z_ERRNO; | |
| 169 | + break; | |
| 170 | + } | |
| 171 | + } else { | |
| 172 | + err = Z_STREAM_ERROR; | |
| 173 | + break; | |
| 174 | + } | |
| 175 | + | |
| 176 | + /* Extra field */ | |
| 177 | + if (extsize > 0) { | |
| 178 | + if (fwrite(extra, 1, extsize, fpOutCD) == extsize) { | |
| 179 | + offsetCD += extsize; | |
| 180 | + } else { | |
| 181 | + err = Z_ERRNO; | |
| 182 | + break; | |
| 183 | + } | |
| 184 | + } | |
| 185 | + | |
| 186 | + /* Comment field */ | |
| 187 | + if (comsize > 0) { | |
| 188 | + if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) { | |
| 189 | + offsetCD += comsize; | |
| 190 | + } else { | |
| 191 | + err = Z_ERRNO; | |
| 192 | + break; | |
| 193 | + } | |
| 194 | + } | |
| 195 | + | |
| 196 | + | |
| 197 | + } else { | |
| 198 | + err = Z_ERRNO; | |
| 199 | + break; | |
| 200 | + } | |
| 201 | + } | |
| 202 | + | |
| 203 | + /* Success */ | |
| 204 | + entries++; | |
| 205 | + | |
| 206 | + } else { | |
| 207 | + break; | |
| 208 | + } | |
| 209 | + } | |
| 210 | + | |
| 211 | + /* Final central directory */ | |
| 212 | + { | |
| 213 | + int entriesZip = entries; | |
| 214 | + char header[22]; | |
| 215 | + char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools"; | |
| 216 | + int comsize = (int) strlen(comment); | |
| 217 | + if (entriesZip > 0xffff) { | |
| 218 | + entriesZip = 0xffff; | |
| 219 | + } | |
| 220 | + WRITE_32(header, 0x06054b50); | |
| 221 | + WRITE_16(header + 4, 0); /* disk # */ | |
| 222 | + WRITE_16(header + 6, 0); /* disk # */ | |
| 223 | + WRITE_16(header + 8, entriesZip); /* hack */ | |
| 224 | + WRITE_16(header + 10, entriesZip); /* hack */ | |
| 225 | + WRITE_32(header + 12, offsetCD); /* size of CD */ | |
| 226 | + WRITE_32(header + 16, offset); /* offset to CD */ | |
| 227 | + WRITE_16(header + 20, comsize); /* comment */ | |
| 228 | + | |
| 229 | + /* Header */ | |
| 230 | + if (fwrite(header, 1, 22, fpOutCD) == 22) { | |
| 231 | + | |
| 232 | + /* Comment field */ | |
| 233 | + if (comsize > 0) { | |
| 234 | + if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) { | |
| 235 | + err = Z_ERRNO; | |
| 236 | + } | |
| 237 | + } | |
| 238 | + | |
| 239 | + } else { | |
| 240 | + err = Z_ERRNO; | |
| 241 | + } | |
| 242 | + } | |
| 243 | + | |
| 244 | + /* Final merge (file + central directory) */ | |
| 245 | + fclose(fpOutCD); | |
| 246 | + if (err == Z_OK) { | |
| 247 | + fpOutCD = fopen(fileOutTmp, "rb"); | |
| 248 | + if (fpOutCD != NULL) { | |
| 249 | + int nRead; | |
| 250 | + char buffer[8192]; | |
| 251 | + while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) { | |
| 252 | + if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) { | |
| 253 | + err = Z_ERRNO; | |
| 254 | + break; | |
| 255 | + } | |
| 256 | + } | |
| 257 | + fclose(fpOutCD); | |
| 258 | + } | |
| 259 | + } | |
| 260 | + | |
| 261 | + /* Close */ | |
| 262 | + fclose(fpZip); | |
| 263 | + fclose(fpOut); | |
| 264 | + | |
| 265 | + /* Wipe temporary file */ | |
| 266 | + (void)remove(fileOutTmp); | |
| 267 | + | |
| 268 | + /* Number of recovered entries */ | |
| 269 | + if (err == Z_OK) { | |
| 270 | + if (nRecovered != NULL) { | |
| 271 | + *nRecovered = entries; | |
| 272 | + } | |
| 273 | + if (bytesRecovered != NULL) { | |
| 274 | + *bytesRecovered = totalBytes; | |
| 275 | + } | |
| 276 | + } | |
| 277 | + } else { | |
| 278 | + err = Z_STREAM_ERROR; | |
| 279 | + } | |
| 280 | + return err; | |
| 281 | +} |
| @@ -0,0 +1,354 @@ | ||
| 1 | +/* unzip.h -- IO for uncompress .zip files using zlib | |
| 2 | + Version 1.01e, February 12th, 2005 | |
| 3 | + | |
| 4 | + Copyright (C) 1998-2005 Gilles Vollant | |
| 5 | + | |
| 6 | + This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g | |
| 7 | + WinZip, InfoZip tools and compatible. | |
| 8 | + | |
| 9 | + Multi volume ZipFile (span) are not supported. | |
| 10 | + Encryption compatible with pkzip 2.04g only supported | |
| 11 | + Old compressions used by old PKZip 1.x are not supported | |
| 12 | + | |
| 13 | + | |
| 14 | + I WAIT FEEDBACK at mail info@winimage.com | |
| 15 | + Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution | |
| 16 | + | |
| 17 | + Condition of use and distribution are the same than zlib : | |
| 18 | + | |
| 19 | + This software is provided 'as-is', without any express or implied | |
| 20 | + warranty. In no event will the authors be held liable for any damages | |
| 21 | + arising from the use of this software. | |
| 22 | + | |
| 23 | + Permission is granted to anyone to use this software for any purpose, | |
| 24 | + including commercial applications, and to alter it and redistribute it | |
| 25 | + freely, subject to the following restrictions: | |
| 26 | + | |
| 27 | + 1. The origin of this software must not be misrepresented; you must not | |
| 28 | + claim that you wrote the original software. If you use this software | |
| 29 | + in a product, an acknowledgment in the product documentation would be | |
| 30 | + appreciated but is not required. | |
| 31 | + 2. Altered source versions must be plainly marked as such, and must not be | |
| 32 | + misrepresented as being the original software. | |
| 33 | + 3. This notice may not be removed or altered from any source distribution. | |
| 34 | + | |
| 35 | + | |
| 36 | +*/ | |
| 37 | + | |
| 38 | +/* for more info about .ZIP format, see | |
| 39 | + http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip | |
| 40 | + http://www.info-zip.org/pub/infozip/doc/ | |
| 41 | + PkWare has also a specification at : | |
| 42 | + ftp://ftp.pkware.com/probdesc.zip | |
| 43 | +*/ | |
| 44 | + | |
| 45 | +#ifndef _unz_H | |
| 46 | +#define _unz_H | |
| 47 | + | |
| 48 | +#ifdef __cplusplus | |
| 49 | +extern "C" { | |
| 50 | +#endif | |
| 51 | + | |
| 52 | +#ifndef _ZLIB_H | |
| 53 | +#include "zlib.h" | |
| 54 | +#endif | |
| 55 | + | |
| 56 | +#ifndef _ZLIBIOAPI_H | |
| 57 | +#include "ioapi.h" | |
| 58 | +#endif | |
| 59 | + | |
| 60 | +#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) | |
| 61 | +/* like the STRICT of WIN32, we define a pointer that cannot be converted | |
| 62 | + from (void*) without cast */ | |
| 63 | +typedef struct TagunzFile__ { int unused; } unzFile__; | |
| 64 | +typedef unzFile__ *unzFile; | |
| 65 | +#else | |
| 66 | +typedef voidp unzFile; | |
| 67 | +#endif | |
| 68 | + | |
| 69 | + | |
| 70 | +#define UNZ_OK (0) | |
| 71 | +#define UNZ_END_OF_LIST_OF_FILE (-100) | |
| 72 | +#define UNZ_ERRNO (Z_ERRNO) | |
| 73 | +#define UNZ_EOF (0) | |
| 74 | +#define UNZ_PARAMERROR (-102) | |
| 75 | +#define UNZ_BADZIPFILE (-103) | |
| 76 | +#define UNZ_INTERNALERROR (-104) | |
| 77 | +#define UNZ_CRCERROR (-105) | |
| 78 | + | |
| 79 | +/* tm_unz contain date/time info */ | |
| 80 | +typedef struct tm_unz_s | |
| 81 | +{ | |
| 82 | + uInt tm_sec; /* seconds after the minute - [0,59] */ | |
| 83 | + uInt tm_min; /* minutes after the hour - [0,59] */ | |
| 84 | + uInt tm_hour; /* hours since midnight - [0,23] */ | |
| 85 | + uInt tm_mday; /* day of the month - [1,31] */ | |
| 86 | + uInt tm_mon; /* months since January - [0,11] */ | |
| 87 | + uInt tm_year; /* years - [1980..2044] */ | |
| 88 | +} tm_unz; | |
| 89 | + | |
| 90 | +/* unz_global_info structure contain global data about the ZIPfile | |
| 91 | + These data comes from the end of central dir */ | |
| 92 | +typedef struct unz_global_info_s | |
| 93 | +{ | |
| 94 | + uLong number_entry; /* total number of entries in | |
| 95 | + the central dir on this disk */ | |
| 96 | + uLong size_comment; /* size of the global comment of the zipfile */ | |
| 97 | +} unz_global_info; | |
| 98 | + | |
| 99 | + | |
| 100 | +/* unz_file_info contain information about a file in the zipfile */ | |
| 101 | +typedef struct unz_file_info_s | |
| 102 | +{ | |
| 103 | + uLong version; /* version made by 2 bytes */ | |
| 104 | + uLong version_needed; /* version needed to extract 2 bytes */ | |
| 105 | + uLong flag; /* general purpose bit flag 2 bytes */ | |
| 106 | + uLong compression_method; /* compression method 2 bytes */ | |
| 107 | + uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ | |
| 108 | + uLong crc; /* crc-32 4 bytes */ | |
| 109 | + uLong compressed_size; /* compressed size 4 bytes */ | |
| 110 | + uLong uncompressed_size; /* uncompressed size 4 bytes */ | |
| 111 | + uLong size_filename; /* filename length 2 bytes */ | |
| 112 | + uLong size_file_extra; /* extra field length 2 bytes */ | |
| 113 | + uLong size_file_comment; /* file comment length 2 bytes */ | |
| 114 | + | |
| 115 | + uLong disk_num_start; /* disk number start 2 bytes */ | |
| 116 | + uLong internal_fa; /* internal file attributes 2 bytes */ | |
| 117 | + uLong external_fa; /* external file attributes 4 bytes */ | |
| 118 | + | |
| 119 | + tm_unz tmu_date; | |
| 120 | +} unz_file_info; | |
| 121 | + | |
| 122 | +extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, | |
| 123 | + const char* fileName2, | |
| 124 | + int iCaseSensitivity)); | |
| 125 | +/* | |
| 126 | + Compare two filename (fileName1,fileName2). | |
| 127 | + If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) | |
| 128 | + If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi | |
| 129 | + or strcasecmp) | |
| 130 | + If iCaseSenisivity = 0, case sensitivity is defaut of your operating system | |
| 131 | + (like 1 on Unix, 2 on Windows) | |
| 132 | +*/ | |
| 133 | + | |
| 134 | + | |
| 135 | +extern unzFile ZEXPORT unzOpen OF((const char *path)); | |
| 136 | +/* | |
| 137 | + Open a Zip file. path contain the full pathname (by example, | |
| 138 | + on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer | |
| 139 | + "zlib/zlib113.zip". | |
| 140 | + If the zipfile cannot be opened (file don't exist or in not valid), the | |
| 141 | + return value is NULL. | |
| 142 | + Else, the return value is a unzFile Handle, usable with other function | |
| 143 | + of this unzip package. | |
| 144 | +*/ | |
| 145 | + | |
| 146 | +extern unzFile ZEXPORT unzOpen2 OF((const char *path, | |
| 147 | + zlib_filefunc_def* pzlib_filefunc_def)); | |
| 148 | +/* | |
| 149 | + Open a Zip file, like unzOpen, but provide a set of file low level API | |
| 150 | + for read/write the zip file (see ioapi.h) | |
| 151 | +*/ | |
| 152 | + | |
| 153 | +extern int ZEXPORT unzClose OF((unzFile file)); | |
| 154 | +/* | |
| 155 | + Close a ZipFile opened with unzipOpen. | |
| 156 | + If there is files inside the .Zip opened with unzOpenCurrentFile (see later), | |
| 157 | + these files MUST be closed with unzipCloseCurrentFile before call unzipClose. | |
| 158 | + return UNZ_OK if there is no problem. */ | |
| 159 | + | |
| 160 | +extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, | |
| 161 | + unz_global_info *pglobal_info)); | |
| 162 | +/* | |
| 163 | + Write info about the ZipFile in the *pglobal_info structure. | |
| 164 | + No preparation of the structure is needed | |
| 165 | + return UNZ_OK if there is no problem. */ | |
| 166 | + | |
| 167 | + | |
| 168 | +extern int ZEXPORT unzGetGlobalComment OF((unzFile file, | |
| 169 | + char *szComment, | |
| 170 | + uLong uSizeBuf)); | |
| 171 | +/* | |
| 172 | + Get the global comment string of the ZipFile, in the szComment buffer. | |
| 173 | + uSizeBuf is the size of the szComment buffer. | |
| 174 | + return the number of byte copied or an error code <0 | |
| 175 | +*/ | |
| 176 | + | |
| 177 | + | |
| 178 | +/***************************************************************************/ | |
| 179 | +/* Unzip package allow you browse the directory of the zipfile */ | |
| 180 | + | |
| 181 | +extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); | |
| 182 | +/* | |
| 183 | + Set the current file of the zipfile to the first file. | |
| 184 | + return UNZ_OK if there is no problem | |
| 185 | +*/ | |
| 186 | + | |
| 187 | +extern int ZEXPORT unzGoToNextFile OF((unzFile file)); | |
| 188 | +/* | |
| 189 | + Set the current file of the zipfile to the next file. | |
| 190 | + return UNZ_OK if there is no problem | |
| 191 | + return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. | |
| 192 | +*/ | |
| 193 | + | |
| 194 | +extern int ZEXPORT unzLocateFile OF((unzFile file, | |
| 195 | + const char *szFileName, | |
| 196 | + int iCaseSensitivity)); | |
| 197 | +/* | |
| 198 | + Try locate the file szFileName in the zipfile. | |
| 199 | + For the iCaseSensitivity signification, see unzStringFileNameCompare | |
| 200 | + | |
| 201 | + return value : | |
| 202 | + UNZ_OK if the file is found. It becomes the current file. | |
| 203 | + UNZ_END_OF_LIST_OF_FILE if the file is not found | |
| 204 | +*/ | |
| 205 | + | |
| 206 | + | |
| 207 | +/* ****************************************** */ | |
| 208 | +/* Ryan supplied functions */ | |
| 209 | +/* unz_file_info contain information about a file in the zipfile */ | |
| 210 | +typedef struct unz_file_pos_s | |
| 211 | +{ | |
| 212 | + uLong pos_in_zip_directory; /* offset in zip file directory */ | |
| 213 | + uLong num_of_file; /* # of file */ | |
| 214 | +} unz_file_pos; | |
| 215 | + | |
| 216 | +extern int ZEXPORT unzGetFilePos( | |
| 217 | + unzFile file, | |
| 218 | + unz_file_pos* file_pos); | |
| 219 | + | |
| 220 | +extern int ZEXPORT unzGoToFilePos( | |
| 221 | + unzFile file, | |
| 222 | + unz_file_pos* file_pos); | |
| 223 | + | |
| 224 | +/* ****************************************** */ | |
| 225 | + | |
| 226 | +extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, | |
| 227 | + unz_file_info *pfile_info, | |
| 228 | + char *szFileName, | |
| 229 | + uLong fileNameBufferSize, | |
| 230 | + void *extraField, | |
| 231 | + uLong extraFieldBufferSize, | |
| 232 | + char *szComment, | |
| 233 | + uLong commentBufferSize)); | |
| 234 | +/* | |
| 235 | + Get Info about the current file | |
| 236 | + if pfile_info!=NULL, the *pfile_info structure will contain somes info about | |
| 237 | + the current file | |
| 238 | + if szFileName!=NULL, the filemane string will be copied in szFileName | |
| 239 | + (fileNameBufferSize is the size of the buffer) | |
| 240 | + if extraField!=NULL, the extra field information will be copied in extraField | |
| 241 | + (extraFieldBufferSize is the size of the buffer). | |
| 242 | + This is the Central-header version of the extra field | |
| 243 | + if szComment!=NULL, the comment string of the file will be copied in szComment | |
| 244 | + (commentBufferSize is the size of the buffer) | |
| 245 | +*/ | |
| 246 | + | |
| 247 | +/***************************************************************************/ | |
| 248 | +/* for reading the content of the current zipfile, you can open it, read data | |
| 249 | + from it, and close it (you can close it before reading all the file) | |
| 250 | + */ | |
| 251 | + | |
| 252 | +extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); | |
| 253 | +/* | |
| 254 | + Open for reading data the current file in the zipfile. | |
| 255 | + If there is no error, the return value is UNZ_OK. | |
| 256 | +*/ | |
| 257 | + | |
| 258 | +extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, | |
| 259 | + const char* password)); | |
| 260 | +/* | |
| 261 | + Open for reading data the current file in the zipfile. | |
| 262 | + password is a crypting password | |
| 263 | + If there is no error, the return value is UNZ_OK. | |
| 264 | +*/ | |
| 265 | + | |
| 266 | +extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, | |
| 267 | + int* method, | |
| 268 | + int* level, | |
| 269 | + int raw)); | |
| 270 | +/* | |
| 271 | + Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) | |
| 272 | + if raw==1 | |
| 273 | + *method will receive method of compression, *level will receive level of | |
| 274 | + compression | |
| 275 | + note : you can set level parameter as NULL (if you did not want known level, | |
| 276 | + but you CANNOT set method parameter as NULL | |
| 277 | +*/ | |
| 278 | + | |
| 279 | +extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, | |
| 280 | + int* method, | |
| 281 | + int* level, | |
| 282 | + int raw, | |
| 283 | + const char* password)); | |
| 284 | +/* | |
| 285 | + Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) | |
| 286 | + if raw==1 | |
| 287 | + *method will receive method of compression, *level will receive level of | |
| 288 | + compression | |
| 289 | + note : you can set level parameter as NULL (if you did not want known level, | |
| 290 | + but you CANNOT set method parameter as NULL | |
| 291 | +*/ | |
| 292 | + | |
| 293 | + | |
| 294 | +extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); | |
| 295 | +/* | |
| 296 | + Close the file in zip opened with unzOpenCurrentFile | |
| 297 | + Return UNZ_CRCERROR if all the file was read but the CRC is not good | |
| 298 | +*/ | |
| 299 | + | |
| 300 | +extern int ZEXPORT unzReadCurrentFile OF((unzFile file, | |
| 301 | + voidp buf, | |
| 302 | + unsigned len)); | |
| 303 | +/* | |
| 304 | + Read bytes from the current file (opened by unzOpenCurrentFile) | |
| 305 | + buf contain buffer where data must be copied | |
| 306 | + len the size of buf. | |
| 307 | + | |
| 308 | + return the number of byte copied if somes bytes are copied | |
| 309 | + return 0 if the end of file was reached | |
| 310 | + return <0 with error code if there is an error | |
| 311 | + (UNZ_ERRNO for IO error, or zLib error for uncompress error) | |
| 312 | +*/ | |
| 313 | + | |
| 314 | +extern z_off_t ZEXPORT unztell OF((unzFile file)); | |
| 315 | +/* | |
| 316 | + Give the current position in uncompressed data | |
| 317 | +*/ | |
| 318 | + | |
| 319 | +extern int ZEXPORT unzeof OF((unzFile file)); | |
| 320 | +/* | |
| 321 | + return 1 if the end of file was reached, 0 elsewhere | |
| 322 | +*/ | |
| 323 | + | |
| 324 | +extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, | |
| 325 | + voidp buf, | |
| 326 | + unsigned len)); | |
| 327 | +/* | |
| 328 | + Read extra field from the current file (opened by unzOpenCurrentFile) | |
| 329 | + This is the local-header version of the extra field (sometimes, there is | |
| 330 | + more info in the local-header version than in the central-header) | |
| 331 | + | |
| 332 | + if buf==NULL, it return the size of the local extra field | |
| 333 | + | |
| 334 | + if buf!=NULL, len is the size of the buffer, the extra header is copied in | |
| 335 | + buf. | |
| 336 | + the return value is the number of bytes copied in buf, or (if <0) | |
| 337 | + the error code | |
| 338 | +*/ | |
| 339 | + | |
| 340 | +/***************************************************************************/ | |
| 341 | + | |
| 342 | +/* Get the current file offset */ | |
| 343 | +extern uLong ZEXPORT unzGetOffset (unzFile file); | |
| 344 | + | |
| 345 | +/* Set the current file offset */ | |
| 346 | +extern int ZEXPORT unzSetOffset (unzFile file, uLong pos); | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | +#ifdef __cplusplus | |
| 351 | +} | |
| 352 | +#endif | |
| 353 | + | |
| 354 | +#endif /* _unz_H */ |
| @@ -0,0 +1,31 @@ | ||
| 1 | +/* | |
| 2 | + Additional tools for Minizip | |
| 3 | + Code: Xavier Roche '2004 | |
| 4 | + License: Same as ZLIB (www.gzip.org) | |
| 5 | +*/ | |
| 6 | + | |
| 7 | +#ifndef _zip_tools_H | |
| 8 | +#define _zip_tools_H | |
| 9 | + | |
| 10 | +#ifdef __cplusplus | |
| 11 | +extern "C" { | |
| 12 | +#endif | |
| 13 | + | |
| 14 | +#ifndef _ZLIB_H | |
| 15 | +#include "zlib.h" | |
| 16 | +#endif | |
| 17 | + | |
| 18 | +#include "unzip.h" | |
| 19 | + | |
| 20 | +/* Repair a ZIP file (missing central directory) | |
| 21 | + file: file to recover | |
| 22 | + fileOut: output file after recovery | |
| 23 | + fileOutTmp: temporary file name used for recovery | |
| 24 | +*/ | |
| 25 | +extern int ZEXPORT unzRepair(const char* file, | |
| 26 | + const char* fileOut, | |
| 27 | + const char* fileOutTmp, | |
| 28 | + uLong* nRecovered, | |
| 29 | + uLong* bytesRecovered); | |
| 30 | + | |
| 31 | +#endif |
| @@ -0,0 +1,48 @@ | ||
| 1 | +// | |
| 2 | +// ZipArchive.h | |
| 3 | +// | |
| 4 | +// | |
| 5 | +// Created by aish on 08-9-11. | |
| 6 | +// acsolu@gmail.com | |
| 7 | +// Copyright 2008 Inc. All rights reserved. | |
| 8 | +// | |
| 9 | +// History: | |
| 10 | +// 09-11-2008 version 1.0 release | |
| 11 | +// 10-18-2009 version 1.1 support password protected zip files | |
| 12 | +// 10-21-2009 version 1.2 fix date bug | |
| 13 | + | |
| 14 | +//#import <UIKit/UIKit.h> | |
| 15 | + | |
| 16 | +#include "minizip/zip.h" | |
| 17 | +#include "minizip/unzip.h" | |
| 18 | + | |
| 19 | + | |
| 20 | +@protocol ZipArchiveDelegate <NSObject> | |
| 21 | +@optional | |
| 22 | +-(void) ErrorMessage:(NSString*) msg; | |
| 23 | +-(BOOL) OverWriteOperation:(NSString*) file; | |
| 24 | + | |
| 25 | +@end | |
| 26 | + | |
| 27 | + | |
| 28 | +@interface ZipArchive : NSObject { | |
| 29 | +@private | |
| 30 | + zipFile _zipFile; | |
| 31 | + unzFile _unzFile; | |
| 32 | + | |
| 33 | + NSString* _password; | |
| 34 | + id _delegate; | |
| 35 | +} | |
| 36 | + | |
| 37 | +@property (nonatomic, retain) id delegate; | |
| 38 | + | |
| 39 | +-(BOOL) CreateZipFile2:(NSString*) zipFile; | |
| 40 | +-(BOOL) CreateZipFile2:(NSString*) zipFile Password:(NSString*) password; | |
| 41 | +-(BOOL) addFileToZip:(NSString*) file newname:(NSString*) newname; | |
| 42 | +-(BOOL) CloseZipFile2; | |
| 43 | + | |
| 44 | +-(BOOL) UnzipOpenFile:(NSString*) zipFile; | |
| 45 | +-(BOOL) UnzipOpenFile:(NSString*) zipFile Password:(NSString*) password; | |
| 46 | +-(BOOL) UnzipFileTo:(NSString*) path overWrite:(BOOL) overwrite; | |
| 47 | +-(BOOL) UnzipCloseFile; | |
| 48 | +@end |
| @@ -9,12 +9,13 @@ | ||
| 9 | 9 | #import "CRTableViewController.h" |
| 10 | 10 | #import <Cocoa/Cocoa.h> |
| 11 | 11 | #import "CRDropView.h" |
| 12 | +#import "NSImage+data.h" | |
| 13 | +#import "ZipArchive.h" | |
| 12 | 14 | |
| 13 | 15 | @implementation CRTableViewController { |
| 14 | 16 | NSMutableArray *_dataArray; |
| 15 | 17 | IBOutlet CRDropView *mainView; |
| 16 | 18 | IBOutlet NSTableView *_tableView; |
| 17 | - IBOutlet NSTextField *_textField; | |
| 18 | 19 | IBOutlet NSProgressIndicator *_indicator; |
| 19 | 20 | } |
| 20 | 21 | @synthesize _dirPath; |
| @@ -71,33 +72,86 @@ | ||
| 71 | 72 | [_tableView reloadData]; |
| 72 | 73 | } |
| 73 | 74 | |
| 74 | -NSImage* trimImageByRect(NSImage *image, NSRect trimRect) { | |
| 75 | - NSBitmapImageRep* imageRep = [NSBitmapImageRep imageRepWithData:[image TIFFRepresentation] ]; | |
| 76 | - NSSize pointSize = NSMakeSize(imageRep.pixelsWide, imageRep.pixelsHigh); | |
| 75 | +- (NSString*)imageTypeExp:(NSInteger)type { | |
| 76 | + NSString *exp = @""; | |
| 77 | + switch (type) { | |
| 78 | + case IMAGE_TYPE_JPEG: | |
| 79 | + exp = @"jpg"; | |
| 80 | + break; | |
| 81 | + case IMAGE_TYPE_PNG: | |
| 82 | + exp = @"png"; | |
| 83 | + break; | |
| 84 | + case IMAGE_TYPE_TIFF: | |
| 85 | + exp = @"tif"; | |
| 86 | + break; | |
| 87 | + case IMAGE_TYPE_JPEG2000: | |
| 88 | + exp = @"jpg"; | |
| 89 | + break; | |
| 90 | + case IMAGE_TYPE_BMP: | |
| 91 | + exp = @"bmp"; | |
| 92 | + break; | |
| 93 | + } | |
| 94 | + return exp; | |
| 95 | +} | |
| 77 | 96 | |
| 78 | - [image setSize:pointSize]; | |
| 97 | +- (IBAction)buildButton:(id)sender { | |
| 98 | + NSLog(@"pushed"); | |
| 99 | + BOOL isDirectory; | |
| 100 | + NSInteger imageType = [[NSUserDefaults standardUserDefaults] integerForKey:@"image type"]; | |
| 101 | + NSInteger zipFlag = [[NSUserDefaults standardUserDefaults] integerForKey:@"zip flag"]; | |
| 102 | + NSInteger sizeFlag = [[NSUserDefaults standardUserDefaults] integerForKey:@"fit size"]; | |
| 103 | + int fitWidth = (int)[[NSUserDefaults standardUserDefaults] integerForKey:@"fit width"]; | |
| 104 | + int fitHeight = (int)[[NSUserDefaults standardUserDefaults] integerForKey:@"fit height"]; | |
| 105 | + double qualityJpeg2000 = [[NSUserDefaults standardUserDefaults] doubleForKey:@"jpeg2000 quality"]; | |
| 106 | + double qualityJpeg = [[NSUserDefaults standardUserDefaults] doubleForKey:@"jpeg quality"]; | |
| 107 | + | |
| 108 | + NSString *dir = NSTemporaryDirectory(); | |
| 109 | + NSLog(@"dir %@", dir); | |
| 110 | + | |
| 111 | + if (0 == zipFlag) { | |
| 112 | + NSInteger result; | |
| 113 | + NSOpenPanel* openPanel; | |
| 114 | + | |
| 115 | + openPanel = [NSOpenPanel openPanel]; | |
| 116 | + [openPanel setCanChooseDirectories:YES]; | |
| 117 | + [openPanel setCanCreateDirectories:YES]; | |
| 118 | + result = [openPanel runModal]; | |
| 119 | + if(result == NSOKButton) { | |
| 120 | + NSString* dirPath = [[openPanel URL] path]; | |
| 121 | + BOOL isDirectory; | |
| 122 | + if ([[NSFileManager defaultManager] fileExistsAtPath:dirPath isDirectory:&isDirectory]) { | |
| 123 | + if (isDirectory) { | |
| 124 | + self._dirPath = dirPath; | |
| 125 | + dir = dirPath; | |
| 126 | + } else { | |
| 127 | + NSRunAlertPanel(@"info", @"set a folder", | |
| 128 | + nil, nil, nil); | |
| 129 | + } | |
| 130 | + } | |
| 131 | + } | |
| 132 | + } else { | |
| 133 | + | |
| 134 | + NSInteger result; | |
| 135 | + NSSavePanel* savePanel; | |
| 136 | + | |
| 137 | + savePanel = [NSSavePanel savePanel]; | |
| 138 | + NSArray *allowedFileTypes = [NSArray arrayWithObjects:@"zip",@"'ZIP'",nil]; | |
| 139 | + [savePanel setAllowedFileTypes:allowedFileTypes]; | |
| 140 | + | |
| 141 | + [savePanel setCanCreateDirectories:YES]; | |
| 142 | + result = [savePanel runModal]; | |
| 143 | + if(result == NSOKButton) { | |
| 144 | + NSString* dirPath = [[savePanel URL] path]; | |
| 145 | + self._dirPath = dirPath; | |
| 146 | + } | |
| 147 | + } | |
| 79 | 148 | |
| 80 | - NSRect newRect = NSZeroRect; | |
| 81 | - newRect.size = trimRect.size; | |
| 82 | - NSImage *newImage = [ [NSImage alloc] initWithSize:newRect.size]; | |
| 83 | 149 | |
| 84 | - [newImage lockFocus]; | |
| 85 | - [NSGraphicsContext saveGraphicsState]; | |
| 150 | + | |
| 86 | 151 | |
| 87 | - [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh]; | |
| 88 | 152 | |
| 89 | - [image drawAtPoint:NSZeroPoint fromRect:trimRect operation:NSCompositeSourceOver fraction:1.0]; | |
| 90 | - [NSGraphicsContext restoreGraphicsState]; | |
| 91 | - [newImage unlockFocus]; | |
| 92 | - | |
| 93 | - return newImage; | |
| 94 | -} | |
| 95 | - | |
| 96 | -- (IBAction)buildButton:(id)sender { | |
| 97 | - NSLog(@"pushed"); | |
| 98 | - BOOL isDirectory; | |
| 99 | 153 | [_indicator setDoubleValue:0]; |
| 100 | - if ([[NSFileManager defaultManager] fileExistsAtPath:self._dirPath isDirectory:&isDirectory]) { | |
| 154 | + if ([[NSFileManager defaultManager] fileExistsAtPath:dir isDirectory:&isDirectory]) { | |
| 101 | 155 | if (isDirectory) { |
| 102 | 156 | _indicator.minValue = 0; |
| 103 | 157 | _indicator.maxValue = [mainView._files count] * 2; |
| @@ -117,56 +171,109 @@ | ||
| 117 | 171 | |
| 118 | 172 | if (pointSize.width < pointSize.height) { |
| 119 | 173 | NSString *filename; |
| 120 | - NSData *newData; | |
| 121 | - NSDictionary *properties; | |
| 122 | - float quality; | |
| 174 | + filename = [dir stringByAppendingFormat:@"/%06d.%@", count++, [self imageTypeExp:imageType]]; | |
| 123 | 175 | |
| 124 | - filename = [self._dirPath stringByAppendingFormat:@"/%06d.jpg", count++]; | |
| 125 | - quality = 0.86; | |
| 176 | + NSImage *newImage = image; | |
| 177 | + if (0 == sizeFlag) { | |
| 178 | + newImage = [image fitImageInSize:NSMakeSize(fitWidth, fitHeight)]; | |
| 179 | + } | |
| 180 | + switch (imageType) { | |
| 181 | + case IMAGE_TYPE_JPEG: | |
| 182 | + [[newImage JPEGDataWithQuality:qualityJpeg] writeToFile:filename atomically:YES]; | |
| 183 | + break; | |
| 184 | + case IMAGE_TYPE_PNG: | |
| 185 | + [[newImage PNGDataWithInterlaced:YES] writeToFile:filename atomically:YES]; | |
| 186 | + break; | |
| 187 | + case IMAGE_TYPE_TIFF: | |
| 188 | + [[newImage TIFFRepresentation] writeToFile:filename atomically:YES]; | |
| 189 | + break; | |
| 190 | + case IMAGE_TYPE_JPEG2000: | |
| 191 | + [[newImage JPEG2000DataWithQuality:qualityJpeg2000] writeToFile:filename atomically:YES]; | |
| 192 | + break; | |
| 193 | + case IMAGE_TYPE_BMP: | |
| 194 | + [[newImage BMPData] writeToFile:filename atomically:YES]; | |
| 195 | + break; | |
| 196 | + } | |
| 126 | 197 | |
| 127 | - properties = [NSDictionary | |
| 128 | - dictionaryWithObject:[NSNumber numberWithFloat:quality] | |
| 129 | - forKey:NSImageCompressionFactor]; | |
| 130 | - newData = [bitmapImageRep representationUsingType:NSJPEGFileType | |
| 131 | - properties:properties]; | |
| 132 | - [newData writeToFile:filename atomically:YES]; | |
| 133 | - | |
| 134 | 198 | progress += 2; |
| 135 | 199 | [_indicator setDoubleValue:progress]; |
| 136 | 200 | } else { |
| 137 | 201 | for (int j = 0; j < 2; j++) { |
| 138 | 202 | NSString *filename; |
| 139 | - NSImage *newImage; | |
| 140 | - NSData *newData; | |
| 141 | - NSDictionary *properties; | |
| 142 | - float quality; | |
| 143 | - | |
| 203 | + filename = [dir stringByAppendingFormat:@"/%06d.%@", count++, [self imageTypeExp:imageType]]; | |
| 144 | 204 | NSRect rc = NSMakeRect((pointSize.width / 2.0 * (1 - j)), 0, pointSize.width / 2.0, pointSize.height); |
| 145 | - newImage = trimImageByRect(image, rc); | |
| 205 | + | |
| 206 | + NSImage *newImage = [image trimImageByRect:rc]; | |
| 207 | + if (0 == sizeFlag) { | |
| 208 | + newImage = [newImage fitImageInSize:NSMakeSize(fitWidth, fitHeight)]; | |
| 209 | + } | |
| 210 | + switch (imageType) { | |
| 211 | + case IMAGE_TYPE_JPEG: | |
| 212 | + [[newImage JPEGDataWithQuality:qualityJpeg] writeToFile:filename atomically:YES]; | |
| 213 | + break; | |
| 214 | + case IMAGE_TYPE_PNG: | |
| 215 | + [[newImage PNGDataWithInterlaced:YES] writeToFile:filename atomically:YES]; | |
| 216 | + break; | |
| 217 | + case IMAGE_TYPE_TIFF: | |
| 218 | + [[newImage TIFFRepresentation] writeToFile:filename atomically:YES]; | |
| 219 | + break; | |
| 220 | + case IMAGE_TYPE_JPEG2000: | |
| 221 | + [[newImage JPEG2000DataWithQuality:qualityJpeg2000] writeToFile:filename atomically:YES]; | |
| 222 | + break; | |
| 223 | + case IMAGE_TYPE_BMP: | |
| 224 | + [[newImage BMPData] writeToFile:filename atomically:YES]; | |
| 225 | + break; | |
| 226 | + } | |
| 146 | 227 | |
| 147 | - filename = [self._dirPath stringByAppendingFormat:@"/%06d.jpg", count++]; | |
| 148 | - quality = 0.86; | |
| 149 | - | |
| 150 | - newData = [newImage TIFFRepresentation]; | |
| 151 | - bitmapImageRep = [NSBitmapImageRep imageRepWithData:newData]; | |
| 152 | - properties = [NSDictionary | |
| 153 | - dictionaryWithObject:[NSNumber numberWithFloat:quality] | |
| 154 | - forKey:NSImageCompressionFactor]; | |
| 155 | - newData = [bitmapImageRep representationUsingType:NSJPEGFileType | |
| 156 | - properties:properties]; | |
| 157 | - [newData writeToFile:filename atomically:YES]; | |
| 158 | - | |
| 159 | - [newImage release]; | |
| 160 | - | |
| 161 | 228 | progress++; |
| 162 | 229 | [_indicator setDoubleValue:progress]; |
| 163 | 230 | } |
| 164 | 231 | } |
| 165 | 232 | [image release]; |
| 166 | - | |
| 233 | + | |
| 167 | 234 | } |
| 235 | + | |
| 236 | +// NSError *error; | |
| 237 | +// for (int i = 0; i < count; i++) { | |
| 238 | +// NSString* atPath = [dir stringByAppendingFormat:@"/%06d.jpg", i]; | |
| 239 | +// NSString* toPath = [self._dirPath stringByAppendingFormat:@"/a%06d.jpg", i]; | |
| 240 | +// if (![[NSFileManager defaultManager] moveItemAtPath:atPath toPath:toPath error:&error]) { | |
| 241 | +// | |
| 242 | +// NSRunAlertPanel(@"info", error.debugDescription, | |
| 243 | +// nil, nil, nil); | |
| 244 | +// break; | |
| 245 | +// } | |
| 246 | +// } | |
| 247 | + | |
| 248 | + if (0 != zipFlag) { | |
| 249 | + NSString* zipFile = self._dirPath; | |
| 250 | + ZipArchive* archiver = [[ZipArchive alloc] init]; | |
| 251 | + [archiver CreateZipFile2:zipFile]; | |
| 252 | + | |
| 253 | + for (int i = 0; i < count; i++) { | |
| 254 | + NSString* atPath = [dir stringByAppendingFormat:@"/%06d.%@", i, [self imageTypeExp:imageType]]; | |
| 255 | + NSString* toPath = [NSString stringWithFormat:@"%06d.%@", i, [self imageTypeExp:imageType]]; | |
| 256 | + [archiver addFileToZip:atPath | |
| 257 | + newname:toPath]; | |
| 258 | + } | |
| 259 | + [archiver CloseZipFile2]; | |
| 260 | + [archiver release]; | |
| 261 | + | |
| 262 | + for (int i = 0; i < count; i++) { | |
| 263 | + NSError *error; | |
| 264 | + NSString* atPath = [dir stringByAppendingFormat:@"/%06d.%@", i, [self imageTypeExp:imageType]]; | |
| 265 | + | |
| 266 | + if (![[NSFileManager defaultManager] removeItemAtPath:atPath error:&error]) { | |
| 267 | + NSLog(@"error %@", error.debugDescription); | |
| 268 | + } | |
| 269 | + } | |
| 270 | + } | |
| 271 | + | |
| 168 | 272 | NSRunAlertPanel(@"info", @"finish", |
| 169 | 273 | nil, nil, nil); |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 170 | 277 | } |
| 171 | 278 | } else { |
| 172 | 279 | NSRunAlertPanel(@"info", @"set a folder", |
| @@ -174,35 +281,108 @@ | ||
| 174 | 281 | } |
| 175 | 282 | } |
| 176 | 283 | |
| 177 | -- (IBAction)onSelectSaveAs:(id)sender | |
| 284 | +- (IBAction)onClearButton:(id)sender | |
| 178 | 285 | { |
| 179 | - NSInteger result; | |
| 180 | - NSOpenPanel* openPanel; | |
| 286 | + [mainView._files removeAllObjects]; | |
| 287 | + _dataArray = [[NSMutableArray alloc] init]; | |
| 288 | + [_tableView reloadData]; | |
| 289 | +} | |
| 290 | + | |
| 291 | +- (IBAction)onOpenButton:(id)sender | |
| 292 | +{ | |
| 293 | + NSInteger result; | |
| 294 | + NSOpenPanel* openPanel; | |
| 181 | 295 | |
| 182 | - openPanel = [NSOpenPanel openPanel]; | |
| 183 | - [openPanel setCanChooseDirectories:YES]; | |
| 296 | + openPanel = [NSOpenPanel openPanel]; | |
| 297 | + [openPanel setCanChooseDirectories:YES]; | |
| 184 | 298 | [openPanel setCanCreateDirectories:YES]; |
| 185 | - result = [openPanel runModal]; | |
| 186 | - if(result == NSOKButton) { | |
| 187 | - NSString* dirPath = [[openPanel URL] path]; | |
| 188 | - BOOL isDirectory; | |
| 189 | - if ([[NSFileManager defaultManager] fileExistsAtPath:dirPath isDirectory:&isDirectory]) { | |
| 190 | - if (isDirectory) { | |
| 191 | - self._dirPath = dirPath; | |
| 192 | - [_textField setStringValue:dirPath]; | |
| 193 | - } else { | |
| 194 | - NSRunAlertPanel(@"info", @"set a folder", | |
| 195 | - nil, nil, nil); | |
| 299 | + [openPanel setAllowsMultipleSelection:YES]; | |
| 300 | + | |
| 301 | + result = [openPanel runModal]; | |
| 302 | + if(result == NSOKButton) { | |
| 303 | + | |
| 304 | + | |
| 305 | + for (NSURL *url in [openPanel URLs]) { | |
| 306 | + NSString *path = [url path]; | |
| 307 | + | |
| 308 | + BOOL isDirectory; | |
| 309 | + if ([[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDirectory]) { | |
| 310 | + if (isDirectory) { | |
| 311 | + NSArray* array = [[NSFileManager defaultManager] subpathsAtPath:path]; | |
| 312 | + array = [array sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; | |
| 313 | + | |
| 314 | + for (NSString *filename in array) { | |
| 315 | + filename = [path stringByAppendingPathComponent:filename]; | |
| 316 | + if ([NSImage isImageFile:filename]) { | |
| 317 | + NSLog(@"%@", filename); | |
| 318 | + [mainView._files addObject:filename]; | |
| 319 | + } | |
| 320 | + } | |
| 321 | + } else { | |
| 322 | + if ([NSImage isImageFile:path]) { | |
| 323 | + [mainView._files addObject:path]; | |
| 324 | + } | |
| 325 | + } | |
| 326 | + | |
| 196 | 327 | } |
| 197 | 328 | } |
| 198 | 329 | } |
| 199 | -} | |
| 200 | - | |
| 201 | -- (IBAction)onClearButton:(id)sender | |
| 202 | -{ | |
| 203 | - [mainView._files removeAllObjects]; | |
| 330 | + | |
| 331 | + NSArray *files = mainView._files; | |
| 332 | + | |
| 204 | 333 | _dataArray = [[NSMutableArray alloc] init]; |
| 334 | + for (int i = 0; i < [files count]; i++) { | |
| 335 | + NSDictionary *data = @{@"title": [files[i] lastPathComponent], | |
| 336 | + @"description": files[i]}; | |
| 337 | + [_dataArray addObject:data]; | |
| 338 | + } | |
| 205 | 339 | [_tableView reloadData]; |
| 206 | 340 | } |
| 207 | 341 | |
| 342 | +- (IBAction)onInfo:(id)sender { | |
| 343 | + if (0 < [mainView._files count] && 0 <= [_tableView selectedRow]) { | |
| 344 | + NSString *selectedStringValue = [mainView._files objectAtIndex:[_tableView selectedRow]]; | |
| 345 | + if (selectedStringValue) { | |
| 346 | + if ([[NSWorkspace sharedWorkspace] openFile:selectedStringValue]) { //withApplication | |
| 347 | + return; | |
| 348 | + } | |
| 349 | + } | |
| 350 | + } | |
| 351 | + NSRunAlertPanel(@"info", @"can't open", | |
| 352 | + nil, nil, nil); | |
| 353 | +} | |
| 354 | + | |
| 355 | +//- (IBAction)savePDF:(id)sender | |
| 356 | +//{ | |
| 357 | +// // (1) setup filename | |
| 358 | +// NSArray *paths = NSSearchPathForDirectoriesInDomains( | |
| 359 | +// NSDesktopDirectory, NSUserDomainMask, YES); | |
| 360 | +// NSString* path = [NSString stringWithFormat:@"%@/test.pdf", | |
| 361 | +// [paths objectAtIndex:0], nil]; | |
| 362 | +// | |
| 363 | +// // (2) setup WebView | |
| 364 | +// NSView* view = [[[_web_view mainFrame] frameView] documentView]; | |
| 365 | +// | |
| 366 | +// // (3) setup NSDictionary for NSPrintInfo | |
| 367 | +// NSMutableDictionary* p_dict = [NSMutableDictionary | |
| 368 | +// dictionaryWithDictionary:[[NSPrintInfo sharedPrintInfo] dictionary]]; | |
| 369 | +// [p_dict setObject:NSPrintSaveJob forKey:NSPrintJobDisposition]; | |
| 370 | +// [p_dict setObject:path forKey:NSPrintSavePath]; | |
| 371 | +// | |
| 372 | +// // (4) setup NSPrintInfo | |
| 373 | +// NSPrintInfo* p_info = [[NSPrintInfo alloc] initWithDictionary:p_dict]; | |
| 374 | +// [p_info setHorizontalPagination:NSAutoPagination]; | |
| 375 | +// [p_info setVerticalPagination:NSAutoPagination]; | |
| 376 | +// [p_info setVerticallyCentered:NO]; | |
| 377 | +// | |
| 378 | +// // (5) setup NSPrintOperation | |
| 379 | +// NSPrintOperation* p_ope = | |
| 380 | +// [NSPrintOperation printOperationWithView:view | |
| 381 | +// printInfo:p_info]; | |
| 382 | +// [p_ope setShowsPrintPanel:NO]; | |
| 383 | +// | |
| 384 | +// // (6) print it | |
| 385 | +// [p_ope runOperation]; | |
| 386 | +//} | |
| 387 | + | |
| 208 | 388 | @end |
| @@ -0,0 +1,20 @@ | ||
| 1 | +// | |
| 2 | +// NSImage+data.h | |
| 3 | +// ImageSplitter | |
| 4 | +// | |
| 5 | +// Created by hiroshi tomioka on 13/02/14. | |
| 6 | +// Copyright (c) 2013年 hiroshi tomioka. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import <Cocoa/Cocoa.h> | |
| 10 | + | |
| 11 | +@interface NSImage (data) | |
| 12 | ++ (BOOL)isImageFile:(NSString*)filePath; | |
| 13 | +- (NSImage*)trimImageByRect:(NSRect)trimRect; | |
| 14 | +- (NSImage*)fitImageInSize:(NSSize)fitSize; | |
| 15 | +- (NSData*)JPEGDataWithQuality:(float)quality; | |
| 16 | +- (NSData*)JPEG2000DataWithQuality:(float)quality; | |
| 17 | +- (NSData*)PNGDataWithInterlaced:(BOOL)interlaced; | |
| 18 | +- (NSData*)BMPData; | |
| 19 | + | |
| 20 | +@end |