Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit b0b25c4ccc1b015ef9c2df63c64566c7abf7f749 Gennadiy Potapov committed Jun 30, 2010
@@ -0,0 +1,2 @@
+build
+*.zip
@@ -0,0 +1,15 @@
+/**
+ * Your Copyright Here
+ *
+ * Appcelerator Titanium is Copyright (c) 2009-2010 by Appcelerator, Inc.
+ * and licensed under the Apache Public License (version 2)
+ */
+#import "TiModule.h"
+#import "ZipArchive.h"
+
+@interface ZipFileModule : TiModule
+{
+
+}
+
+@end
@@ -0,0 +1,107 @@
+/**
+ * Your Copyright Here
+ *
+ * Appcelerator Titanium is Copyright (c) 2009-2010 by Appcelerator, Inc.
+ * and licensed under the Apache Public License (version 2)
+ */
+#import "ZipFileModule.h"
+#import "TiBase.h"
+#import "TiHost.h"
+#import "TiUtils.h"
+
+@implementation ZipFileModule
+
+#pragma mark Lifecycle
+
+-(void)startup
+{
+ // this method is called when the module is first loaded
+ // you *must* call the superclass
+ [super startup];
+
+ NSLog(@"[INFO] %@ loaded",self);
+}
+
+-(void)shutdown:(id)sender
+{
+ // this method is called when the module is being unloaded
+ // typically this is during shutdown. make sure you don't do too
+ // much processing here or the app will be quit forceably
+
+ // you *must* call the superclass
+ [super shutdown:sender];
+}
+
+#pragma mark Cleanup
+
+-(void)dealloc
+{
+ // release any resources that have been retained by the module
+ [super dealloc];
+}
+
+#pragma mark Internal Memory Management
+
+-(void)didReceiveMemoryWarning:(NSNotification*)notification
+{
+ // optionally release any resources that can be dynamically
+ // reloaded once memory is available - such as caches
+ [super didReceiveMemoryWarning:notification];
+}
+
+
+#pragma mark Listener Notifications
+
+-(void)_listenerAdded:(NSString *)type count:(int)count
+{
+ if (count == 1 && [type isEqualToString:@"my_event"])
+ {
+ // the first (of potentially many) listener is being added
+ // for event named 'my_event'
+ }
+}
+
+-(void)_listenerRemoved:(NSString *)type count:(int)count
+{
+ if (count == 0 && [type isEqualToString:@"my_event"])
+ {
+ // the last listener called for event named 'my_event' has
+ // been removed, we can optionally clean up any resources
+ // since no body is listening at this point for that event
+ }
+}
+
+#pragma Public APIs
+
+-(void)extract:(id)args
+{
+ NSString *file = [args objectAtIndex:0];
+ NSString *path = [args objectAtIndex:1];
+
+ NSFileManager *fileManager = [NSFileManager defaultManager];
+
+ if([fileManager fileExistsAtPath:file]) {
+ NSLog(@"[INFO] File exists at path");
+ } else {
+ NSLog(@"[INFO] File does not exists at path");
+ }
+
+ ZipArchive* zipArchive = [[ZipArchive alloc] init];
+ if([zipArchive UnzipOpenFile:file]) {
+ NSLog(@"[INFO] zip opened");
+ BOOL ret = [zipArchive UnzipFileTo:path overWrite: YES];
+ if (NO == ret){
+ NSLog(@"[INFO] failed to unzip");
+ } else {
+ NSLog(@"[INFO] file unziped");
+ }
+ [zipArchive UnzipCloseFile];
+ [fileManager removeItemAtPath:file error:nil];
+ } else {
+ NSLog(@"[INFO] can't open zip %@");
+ }
+ [ZipArchive release];
+ [fileManager release];
+}
+
+@end
@@ -0,0 +1,106 @@
+/**
+ * Your Copyright Here
+ *
+ * Appcelerator Titanium is Copyright (c) 2009-2010 by Appcelerator, Inc.
+ * and licensed under the Apache Public License (version 2)
+ */
+#import "ZipFileModule.h"
+#import "TiBase.h"
+#import "TiHost.h"
+#import "TiUtils.h"
+
+@implementation ZipFileModule
+
+#pragma mark Lifecycle
+
+-(void)startup
+{
+ // this method is called when the module is first loaded
+ // you *must* call the superclass
+ [super startup];
+
+ NSLog(@"[DEBUG] %@ loaded",self);
+}
+
+-(void)shutdown:(id)sender
+{
+ // this method is called when the module is being unloaded
+ // typically this is during shutdown. make sure you don't do too
+ // much processing here or the app will be quit forceably
+
+ // you *must* call the superclass
+ [super shutdown:sender];
+}
+
+#pragma mark Cleanup
+
+-(void)dealloc
+{
+ // release any resources that have been retained by the module
+ [super dealloc];
+}
+
+#pragma mark Internal Memory Management
+
+-(void)didReceiveMemoryWarning:(NSNotification*)notification
+{
+ // optionally release any resources that can be dynamically
+ // reloaded once memory is available - such as caches
+ [super didReceiveMemoryWarning:notification];
+}
+
+#pragma mark Listener Notifications
+
+-(void)_listenerAdded:(NSString *)type count:(int)count
+{
+ if (count == 1 && [type isEqualToString:@"my_event"])
+ {
+ // the first (of potentially many) listener is being added
+ // for event named 'my_event'
+ }
+}
+
+-(void)_listenerRemoved:(NSString *)type count:(int)count
+{
+ if (count == 0 && [type isEqualToString:@"my_event"])
+ {
+ // the last listener called for event named 'my_event' has
+ // been removed, we can optionally clean up any resources
+ // since no body is listening at this point for that event
+ }
+}
+
+#pragma Public APIs
+
+-(void)open:(id)args
+{
+ NSString *file = [args objectAtIndex:0];
+ NSString *path = [args objectAtIndex:1];
+
+
+ NSFileManager *fileManager = [NSFileManager defaultManager];
+
+ if(![fileManager fileExistsAtPath:file]) {
+ NSLog(@"[DEBUG] Can't find zip file");
+ }
+
+
+ ZipArchive *zipArchive = [[ZipArchive alloc] init];
+ if([zipArchive UnzipOpenFile:file]) {
+ NSLog(@"[DEBUG] zip opened");
+ BOOL ret = [zipArchive UnzipFileTo:path overWrite: YES];
+ if (NO == ret){
+ NSLog(@"[DEBUG] failed to unzip");
+ } else {
+ NSLog(@"[DEBUG] file unziped");
+ }
+ [zipArchive UnzipCloseFile];
+ [fileManager removeItemAtPath:file error:NULL];
+ } else {
+ NSLog(@"[DEBUG] can't open zip");
+ }
+ [zipArchive release];
+ [fileManager release];
+}
+
+@end
@@ -0,0 +1 @@
+TODO: place your license here and we'll include it in the module distribution
@@ -0,0 +1,87 @@
+Appcelerator Titanium iPhone Module Project
+===========================================
+
+This is a skeleton Titanium Mobile iPhone module project. Modules can be
+used to extend the functionality of Titanium by providing additional native
+code that is compiled into your application at build time and can expose certain
+APIs into JavaScript.
+
+MODULE NAMING
+--------------
+
+Choose a unique name for your module to not cause conflict with other third-party
+modules. Typically, we recommend prefixing your module with a token that identifies
+your organization. In the future, we may provide the ability to register your own
+top level namespaces. Currently, all modules will be available only via the
+Titanium namespace. For example, if your module is named `MyFirstModule`, you would
+access module APIs via the API: `Titanium.Myfirst`. The module in the name will
+automatically be removed when resolving your module. Also, all characters after the
+first are always lower-cased.
+
+COMPONENTS
+-----------
+
+Components that are exposed by your module must follow a special naming convention.
+A component (widget, proxy, etc) must be named with the pattern:
+
+ Ti<ModuleName><ComponentName>Proxy
+
+For example, if you component was called Foo, your proxy would be named:
+
+ TiMyfirstFooProxy
+
+For view proxies or widgets, you must create both a view proxy and a view implementation.
+If you widget was named proxy, you would create the following files:
+
+ TiMyfirstFooProxy.h
+ TiMyfirstFooProxy.m
+ TiMyfirstFoo.h
+ TiMyfirstFoo.m
+
+The view implementation is named the same except it does contain the suffix `Proxy`.
+
+View implementations extend the Titanium base class `TiUIView`. View Proxies extend the
+Titanium base class `TiUIViewProxy` or `TiUIWidgetProxy`.
+
+For proxies that are simply native objects that can be returned to JavaScript, you can
+simply extend `TiProxy` and no view implementation is required.
+
+
+GET STARTED
+------------
+
+1. Edit manifest with the appropriate details about your module.
+2. Edit LICENSE to add your license details.
+3. Place any assets (such as PNG files) that are required in the assets folder.
+4. Edit the titanium.xcconfig and make sure you're building for the right Titanium version.
+5. Code and build.
+
+INSTALL YOUR MODULE
+--------------------
+
+1. Run `build.py` which creates your distribution
+2. cd to `/Library/Application Support/Titanium`
+3. extract your zip into this folder
+
+REGISTER YOUR MODULE
+---------------------
+
+Register your module with your application by editing `tiapp.xml` and adding your module.
+Example:
+
+<modules>
+ <module version="0.1">mymodule</module>
+</modules>
+
+When you run your project, the compiler will know automatically compile in your module
+dependencies and copy appropriate image assets into the application.
+
+DISTRIBUTING YOUR MODULE
+-------------------------
+
+Currently, you will need to manually distribution your module distribution zip file directly.
+However, in the near future, we will make module distribution and sharing built-in to
+Titanium Developer!
+
+
+Cheers!
@@ -0,0 +1,48 @@
+//
+// ZipArchive.h
+//
+//
+// Created by aish on 08-9-11.
+// acsolu@gmail.com
+// Copyright 2008 Inc. All rights reserved.
+//
+// History:
+// 09-11-2008 version 1.0 release
+// 10-18-2009 version 1.1 support password protected zip files
+// 10-21-2009 version 1.2 fix date bug
+
+#import <UIKit/UIKit.h>
+
+#include "minizip/zip.h"
+#include "minizip/unzip.h"
+
+
+@protocol ZipArchiveDelegate <NSObject>
+@optional
+-(void) ErrorMessage:(NSString*) msg;
+-(BOOL) OverWriteOperation:(NSString*) file;
+
+@end
+
+
+@interface ZipArchive : NSObject {
+@private
+ zipFile _zipFile;
+ unzFile _unzFile;
+
+ NSString* _password;
+ id _delegate;
+}
+
+@property (nonatomic, retain) id delegate;
+
+-(BOOL) CreateZipFile2:(NSString*) zipFile;
+-(BOOL) CreateZipFile2:(NSString*) zipFile Password:(NSString*) password;
+-(BOOL) addFileToZip:(NSString*) file newname:(NSString*) newname;
+-(BOOL) CloseZipFile2;
+
+-(BOOL) UnzipOpenFile:(NSString*) zipFile;
+-(BOOL) UnzipOpenFile:(NSString*) zipFile Password:(NSString*) password;
+-(BOOL) UnzipFileTo:(NSString*) path overWrite:(BOOL) overwrite;
+-(BOOL) UnzipCloseFile;
+@end
Oops, something went wrong.

0 comments on commit b0b25c4

Please sign in to comment.