Permalink
Browse files

Added zip for folders -- use as your own risk

  • Loading branch information...
1 parent 822b059 commit 5dfda145da7292f2fac448a9db425111fee68de3 @ars ars committed Mar 19, 2009
Showing with 107 additions and 4 deletions.
  1. +47 −4 ShareController.m
  2. +59 −0 iBrowser.xcodeproj/project.pbxproj
  3. +1 −0 nuzip
View
@@ -8,6 +8,7 @@
#import "ShareController.h"
#import "Utilities.h"
#import "MIMEHelper.h"
+#import "NuZip.h"
@implementation ShareController
@@ -58,7 +59,7 @@ - (void) youCanStartService
- (NSString *) css
{
- return @"<style>/* based on iui.css (c) 2007 by iUI Project Members */ body { margin: 0; font-family: Helvetica; background: #FFFFFF; color: #000000; overflow-x: hidden; -webkit-user-select: none; -webkit-text-size-adjust: none; } body > *:not(.toolbar) { display: none; position: absolute; margin: 0; padding: 0; left: 0; top: 45px; width: 100%; min-height: 372px; } body > *[selected=\"true\"] { display: block; } a[selected], a:active { background-color: #194fdb !important; background-repeat: no-repeat, repeat-x; background-position: right center, left top; color: #FFFFFF !important; } body > .toolbar { box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; border-bottom: 1px solid #2d3642; border-top: 1px solid #6d84a2; padding: 10px; height: 45px; background: #6d84a2 repeat-x; } .toolbar > h1 { position: absolute; overflow: hidden; font-size: 20px; text-align: center; font-weight: bold; text-shadow: rgba(0, 0, 0, 0.4) 0px -1px 0; text-overflow: ellipsis; white-space: nowrap; color: #FFFFFF; margin: 1px 0 0 -120px; left: 50%; width: 240px; height: 45px; } body > ul > li { position: relative; margin: 0; border-bottom: 1px solid #E0E0E0; padding: 8px 0 8px 10px; font-size: 20px; font-weight: bold; list-style: none; } body > ul > li > a { display: block; margin: -8px 0 -8px -10px; padding: 8px 32px 8px 10px; text-decoration: none; color: inherit; } a[target=\"_replace\"] { box-sizing: border-box; -webkit-box-sizing: border-box; padding-top: 25px; padding-bottom: 25px; font-size: 18px; color: cornflowerblue; background-color: #FFFFFF; background-image: none; } body > .dialog { top: 0; width: 100%; min-height: 417px; z-index: 2; background: rgba(0, 0, 0, 0.8); padding: 0; text-align: right; } .dialog > fieldset { box-sizing: border-box; -webkit-box-sizing: border-box; width: 100%; margin: 0; border: none; border-top: 1px solid #6d84a2; padding: 10px 6px; background: #7388a5 repeat-x; } .dialog > fieldset > h1 { margin: 0 10px 0 10px; padding: 0; font-size: 20px; font-weight: bold; color: #FFFFFF; text-shadow: rgba(0, 0, 0, 0.4) 0px -1px 0; text-align: center; } .dialog > fieldset > label { position: absolute; margin: 16px 0 0 6px; font-size: 14px; color: #999999; } p { font-family: Helvetica; background: #FFFFFF; color: #000000; padding:15px; font-size: 20px; margin-left: 15%; margin-right: 15%; text-align: center; } </style>";
+ return @"<style>/* based on iui.css (c) 2007 by iUI Project Members */ body { margin: 0; font-family: Helvetica; background: #FFFFFF; color: #000000; overflow-x: hidden; -webkit-user-select: none; -webkit-text-size-adjust: none; } body > *:not(.toolbar) { display: none; position: absolute; margin: 0; padding: 0; left: 0; top: 45px; width: 100%; min-height: 372px; } body > *[selected=\"true\"] { display: block; } a[selected], a:active { background-color: #194fdb !important; background-repeat: no-repeat, repeat-x; background-position: right center, left top; color: #FFFFFF !important; } body > .toolbar { box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; border-bottom: 1px solid #2d3642; border-top: 1px solid #6d84a2; padding: 10px; height: 45px; background: #6d84a2 repeat-x; } .toolbar > h1 { position: absolute; overflow: hidden; font-size: 20px; text-align: center; font-weight: bold; text-shadow: rgba(0, 0, 0, 0.4) 0px -1px 0; text-overflow: ellipsis; white-space: nowrap; color: #FFFFFF; margin: 1px 0 0 -120px; left: 50%; width: 240px; height: 45px; } body > ul > li { position: relative; margin: 0; border-bottom: 1px solid #E0E0E0; padding: 8px 0 8px 10px; font-size: 20px; font-weight: bold; list-style: none; } body > ul > li > a { margin: -8px 0 -8px -10px; padding: 8px 32px 8px 10px; text-decoration: none; color: inherit; } a[target=\"_replace\"] { box-sizing: border-box; -webkit-box-sizing: border-box; padding-top: 25px; padding-bottom: 25px; font-size: 18px; color: cornflowerblue; background-color: #FFFFFF; background-image: none; } body > .dialog { top: 0; width: 100%; min-height: 417px; z-index: 2; background: rgba(0, 0, 0, 0.8); padding: 0; text-align: right; } .dialog > fieldset { box-sizing: border-box; -webkit-box-sizing: border-box; width: 100%; margin: 0; border: none; border-top: 1px solid #6d84a2; padding: 10px 6px; background: #7388a5 repeat-x; } .dialog > fieldset > h1 { margin: 0 10px 0 10px; padding: 0; font-size: 20px; font-weight: bold; color: #FFFFFF; text-shadow: rgba(0, 0, 0, 0.4) 0px -1px 0; text-align: center; } .dialog > fieldset > label { position: absolute; margin: 16px 0 0 6px; font-size: 14px; color: #999999; } p { font-family: Helvetica; background: #FFFFFF; color: #000000; padding:15px; font-size: 20px; margin-left: 15%; margin-right: 15%; text-align: center; } </style>";
}
- (NSString *) createindex
@@ -92,11 +93,12 @@ - (NSString *) createindex
BOOL isDir;
NSString *cpath = [wd stringByAppendingPathComponent:fname];
[[NSFileManager defaultManager] fileExistsAtPath:cpath isDirectory:&isDir];
- [outdata appendFormat:@"<li><a href=\"%@%@\">%@%@</a></li>\n",
+ [outdata appendFormat:@"<li><a href=\"%@%@\">%@%@</a>%@</li>\n",
cpath,
isDir ? @"/" : @"",
fname,
- isDir ? @"/" : @""
+ isDir ? @"/" : @"",
+ isDir ? [NSString stringWithFormat:@"<a href=\"zzzzip%@.zip\">[zip]</a>", cpath] : @""
];
[cpath release];
}
@@ -118,7 +120,7 @@ - (void) produceError: (NSString *) errorString forFD: (int) fd
[outdata appendString:[self css]];
[outdata appendString:@"</head><body>"];
[outdata appendString:@"<div class=\"toolbar\"> <h1 id=\"pageTitle\">Error</h1> <a id=\"backButton\" class=\"button\" href=\"#\"></a> </div>"];
- [outdata appendFormat:@"<p id=\"ErrorPara\" selected=\"true\"><br />%@<br /><br />Return to <a href=\"upload.html\">upload page</a> or <a href=\"/\">iPocket browser</a></p>", errorString];
+ [outdata appendFormat:@"<p id=\"ErrorPara\" selected=\"true\"><br />%@<br /><br />Return to <a href=\"upload.html\">upload page</a> or <a href=\"/\">Main browser</a></p>", errorString];
[outdata appendString:@"</body></html>\n"];
write (fd, [outdata UTF8String], [outdata length]);
@@ -192,6 +194,47 @@ - (void) handleWebRequest:(int) fd
return;
}
+ NSRange r = [filereq rangeOfString:@"zzzzip"];
+ if (r.location != NSNotFound)
+ {
+ NSString *path1 = [filereq substringFromIndex:r.location + 6];
+ NSString *path = [path1 substringToIndex:[path1 length] - 4];
+ printf("Zip request: %s\n", [path UTF8String]);
+
+ NSString *zipRequest = @"zip -o archive.zip";
+ NSDirectoryEnumerator *direnum = [[NSFileManager defaultManager] enumeratorAtPath:path];
+
+ NSString *eachFile;
+ while (eachFile = [direnum nextObject])
+ {
+ BOOL isDir;
+ NSString *fpath = [path stringByAppendingPathComponent:eachFile];
+ [[NSFileManager defaultManager] fileExistsAtPath:fpath isDirectory:&isDir];
+ if (!isDir) zipRequest = [zipRequest stringByAppendingFormat:@" %@",
+ [fpath stringByReplacingOccurrencesOfString:@" " withString: @"\\ "]];
+ }
+
+ // CFShow(zipRequest);
+ chdir([DOCUMENTS_FOLDER UTF8String]);
+ [NuZip zip:zipRequest];
+
+ // Output the file
+ NSString *outcontent = @"HTTP/1.0 200 OK\r\nContent-Type:application/x-compressed\r\n\r\n";
+ write (fd, [outcontent UTF8String], [outcontent length]);
+ NSData *data = [NSData dataWithContentsOfFile:@"archive.zip"];
+ if (!data)
+ {
+ printf("Error: file not found.\n");
+ [self produceError:@"File was not found. Please check the requested path and try again." forFD:fd];
+ return;
+ }
+ printf("Writing %d bytes from file\n", [data length]);
+ write(fd, [data bytes], [data length]);
+ close(fd);
+
+ return;
+ }
+
// Output the file
NSString *outcontent = [NSString stringWithFormat:@"HTTP/1.0 200 OK\r\nContent-Type: %@\r\n\r\n", mime];
write (fd, [outcontent UTF8String], [outcontent length]);
@@ -20,6 +20,11 @@
8EE2F9180F72D69F0089C887 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8EE2F9160F72D69F0089C887 /* Foundation.framework */; };
8EE2F9880F72D6AE0089C887 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8EE2F9870F72D6AE0089C887 /* CoreLocation.framework */; };
8EE2F9930F72D6B80089C887 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8EE2F9920F72D6B80089C887 /* QuartzCore.framework */; };
+ 8EE2FA730F72E0960089C887 /* ioapi.c in Sources */ = {isa = PBXBuildFile; fileRef = 8EE2FA680F72E0950089C887 /* ioapi.c */; };
+ 8EE2FA740F72E0960089C887 /* mztools.c in Sources */ = {isa = PBXBuildFile; fileRef = 8EE2FA6A0F72E0950089C887 /* mztools.c */; };
+ 8EE2FA750F72E0960089C887 /* unzip.c in Sources */ = {isa = PBXBuildFile; fileRef = 8EE2FA6C0F72E0950089C887 /* unzip.c */; };
+ 8EE2FA760F72E0960089C887 /* zip.c in Sources */ = {isa = PBXBuildFile; fileRef = 8EE2FA6E0F72E0950089C887 /* zip.c */; };
+ 8EE2FA770F72E0960089C887 /* NuZip.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EE2FA720F72E0960089C887 /* NuZip.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -42,6 +47,17 @@
8EE2F9160F72D69F0089C887 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
8EE2F9870F72D6AE0089C887 /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; };
8EE2F9920F72D6B80089C887 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
+ 8EE2FA670F72E0950089C887 /* crypt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = crypt.h; sourceTree = "<group>"; };
+ 8EE2FA680F72E0950089C887 /* ioapi.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ioapi.c; sourceTree = "<group>"; };
+ 8EE2FA690F72E0950089C887 /* ioapi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ioapi.h; sourceTree = "<group>"; };
+ 8EE2FA6A0F72E0950089C887 /* mztools.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mztools.c; sourceTree = "<group>"; };
+ 8EE2FA6B0F72E0950089C887 /* mztools.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mztools.h; sourceTree = "<group>"; };
+ 8EE2FA6C0F72E0950089C887 /* unzip.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = unzip.c; sourceTree = "<group>"; };
+ 8EE2FA6D0F72E0950089C887 /* unzip.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = unzip.h; sourceTree = "<group>"; };
+ 8EE2FA6E0F72E0950089C887 /* zip.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip.c; sourceTree = "<group>"; };
+ 8EE2FA6F0F72E0950089C887 /* zip.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = zip.h; sourceTree = "<group>"; };
+ 8EE2FA710F72E0960089C887 /* NuZip.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NuZip.h; sourceTree = "<group>"; };
+ 8EE2FA720F72E0960089C887 /* NuZip.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NuZip.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -74,6 +90,7 @@
29B97314FDCFA39411CA2CEA /* CustomTemplate */ = {
isa = PBXGroup;
children = (
+ 8EE2FA630F72E07F0089C887 /* nuzip */,
8EE2F7AD0F72D48F0089C887 /* AdMob */,
8D1107310486CEB800E47090 /* Info.plist */,
29B97316FDCFA39411CA2CEA /* main.m */,
@@ -105,6 +122,42 @@
name = Frameworks;
sourceTree = "<group>";
};
+ 8EE2FA630F72E07F0089C887 /* nuzip */ = {
+ isa = PBXGroup;
+ children = (
+ 8EE2FA700F72E0950089C887 /* objc */,
+ 8EE2FA660F72E0950089C887 /* unzip101e-src */,
+ );
+ name = nuzip;
+ sourceTree = "<group>";
+ };
+ 8EE2FA660F72E0950089C887 /* unzip101e-src */ = {
+ isa = PBXGroup;
+ children = (
+ 8EE2FA670F72E0950089C887 /* crypt.h */,
+ 8EE2FA680F72E0950089C887 /* ioapi.c */,
+ 8EE2FA690F72E0950089C887 /* ioapi.h */,
+ 8EE2FA6A0F72E0950089C887 /* mztools.c */,
+ 8EE2FA6B0F72E0950089C887 /* mztools.h */,
+ 8EE2FA6C0F72E0950089C887 /* unzip.c */,
+ 8EE2FA6D0F72E0950089C887 /* unzip.h */,
+ 8EE2FA6E0F72E0950089C887 /* zip.c */,
+ 8EE2FA6F0F72E0950089C887 /* zip.h */,
+ );
+ name = "unzip101e-src";
+ path = "nuzip/unzip101e-src";
+ sourceTree = "<group>";
+ };
+ 8EE2FA700F72E0950089C887 /* objc */ = {
+ isa = PBXGroup;
+ children = (
+ 8EE2FA710F72E0960089C887 /* NuZip.h */,
+ 8EE2FA720F72E0960089C887 /* NuZip.m */,
+ );
+ name = objc;
+ path = nuzip/objc;
+ sourceTree = "<group>";
+ };
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@@ -169,6 +222,11 @@
8EAECCFB0F72C52800C6F597 /* ShareController.m in Sources */,
8EAECCFC0F72C52800C6F597 /* MIMEHelper.m in Sources */,
8EAECCFD0F72C52800C6F597 /* Utilities.m in Sources */,
+ 8EE2FA730F72E0960089C887 /* ioapi.c in Sources */,
+ 8EE2FA740F72E0960089C887 /* mztools.c in Sources */,
+ 8EE2FA750F72E0960089C887 /* unzip.c in Sources */,
+ 8EE2FA760F72E0960089C887 /* zip.c in Sources */,
+ 8EE2FA770F72E0960089C887 /* NuZip.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -190,6 +248,7 @@
"$(inherited)",
"\"$(SRCROOT)/AdMob\"",
);
+ OTHER_LDFLAGS = "-lZ";
PRODUCT_NAME = iBrowser;
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "A2FA5C45-7EC1-4FE4-A834-590BCF399409";
};
1 nuzip
Submodule nuzip added at af06f0

0 comments on commit 5dfda14

Please sign in to comment.