Skip to content

Commit

Permalink
Add open/save dialogs for choosing files for converting
Browse files Browse the repository at this point in the history
  • Loading branch information
perlmunger committed Aug 9, 2012
1 parent 1bda296 commit 6e249a6
Show file tree
Hide file tree
Showing 13 changed files with 1,323 additions and 1,414 deletions.
11 changes: 11 additions & 0 deletions .gitignore
@@ -0,0 +1,11 @@
build
xcuserdata
*.mode*
*pbxuser
*.perspectivev3
project.xcworkspace
*.xcuserstate
*tmproj
~*
.DS_Store
*.orig
Expand Up @@ -13,22 +13,32 @@
B36E03B51500889E00AE9C13 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = B36E03B31500889E00AE9C13 /* Credits.rtf */; };
B36E03B81500889E00AE9C13 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = B36E03B71500889E00AE9C13 /* AppDelegate.m */; };
B36E03BB1500889F00AE9C13 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = B36E03B91500889E00AE9C13 /* MainMenu.xib */; };
B39FF32615008E2900768855 /* NSData+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = B39FF32515008E2900768855 /* NSData+Additions.m */; };
B39FF32A15008E5B00768855 /* NSString+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = B39FF32915008E5B00768855 /* NSString+Additions.m */; };
B39FF32C1500985F00768855 /* video.html in Resources */ = {isa = PBXBuildFile; fileRef = B39FF32B1500985F00768855 /* video.html */; };
B3C7D26715009AF800ECE445 /* part2.html in Resources */ = {isa = PBXBuildFile; fileRef = B3C7D26615009AF800ECE445 /* part2.html */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
B36E03A01500889D00AE9C13 /* Encoder.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Encoder.app; sourceTree = BUILT_PRODUCTS_DIR; };
B36E03A01500889D00AE9C13 /* Base 64 Video Encoder.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Base 64 Video Encoder.app"; sourceTree = BUILT_PRODUCTS_DIR; };
B36E03A41500889D00AE9C13 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
B36E03A71500889D00AE9C13 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
B36E03A81500889D00AE9C13 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
B36E03A91500889D00AE9C13 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
B36E03AC1500889E00AE9C13 /* Encoder-Info.plist */ = {isa = PBXFileReference; path = "Encoder-Info.plist"; sourceTree = "<group>"; };
B36E03AC1500889E00AE9C13 /* Base 64 Video Encoder-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Base 64 Video Encoder-Info.plist"; sourceTree = "<group>"; };
B36E03AE1500889E00AE9C13 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
B36E03B01500889E00AE9C13 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
B36E03B21500889E00AE9C13 /* Encoder-Prefix.pch */ = {isa = PBXFileReference; path = "Encoder-Prefix.pch"; sourceTree = "<group>"; };
B36E03B21500889E00AE9C13 /* Base 64 Video Encoder-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Base 64 Video Encoder-Prefix.pch"; sourceTree = "<group>"; };
B36E03B41500889E00AE9C13 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = en; path = en.lproj/Credits.rtf; sourceTree = "<group>"; };
B36E03B61500889E00AE9C13 /* AppDelegate.h */ = {isa = PBXFileReference; path = AppDelegate.h; sourceTree = "<group>"; };
B36E03B61500889E00AE9C13 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
B36E03B71500889E00AE9C13 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
B36E03BA1500889F00AE9C13 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/MainMenu.xib; sourceTree = "<group>"; };
B39FF32415008E2900768855 /* NSData+Additions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+Additions.h"; sourceTree = "<group>"; };
B39FF32515008E2900768855 /* NSData+Additions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+Additions.m"; sourceTree = "<group>"; };
B39FF32815008E5B00768855 /* NSString+Additions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+Additions.h"; sourceTree = "<group>"; };
B39FF32915008E5B00768855 /* NSString+Additions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+Additions.m"; sourceTree = "<group>"; };
B39FF32B1500985F00768855 /* video.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = video.html; path = Encoder/video.html; sourceTree = "<group>"; };
B3C7D26615009AF800ECE445 /* part2.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = part2.html; path = Encoder/part2.html; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -46,6 +56,8 @@
B36E03951500889D00AE9C13 = {
isa = PBXGroup;
children = (
B39FF32B1500985F00768855 /* video.html */,
B3C7D26615009AF800ECE445 /* part2.html */,
B36E03AA1500889D00AE9C13 /* Encoder */,
B36E03A31500889D00AE9C13 /* Frameworks */,
B36E03A11500889D00AE9C13 /* Products */,
Expand All @@ -55,7 +67,7 @@
B36E03A11500889D00AE9C13 /* Products */ = {
isa = PBXGroup;
children = (
B36E03A01500889D00AE9C13 /* Encoder.app */,
B36E03A01500889D00AE9C13 /* Base 64 Video Encoder.app */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -86,17 +98,21 @@
B36E03B71500889E00AE9C13 /* AppDelegate.m */,
B36E03B91500889E00AE9C13 /* MainMenu.xib */,
B36E03AB1500889E00AE9C13 /* Supporting Files */,
B39FF32415008E2900768855 /* NSData+Additions.h */,
B39FF32515008E2900768855 /* NSData+Additions.m */,
B39FF32815008E5B00768855 /* NSString+Additions.h */,
B39FF32915008E5B00768855 /* NSString+Additions.m */,
);
path = Encoder;
sourceTree = "<group>";
};
B36E03AB1500889E00AE9C13 /* Supporting Files */ = {
isa = PBXGroup;
children = (
B36E03AC1500889E00AE9C13 /* Encoder-Info.plist */,
B36E03AC1500889E00AE9C13 /* Base 64 Video Encoder-Info.plist */,
B36E03AD1500889E00AE9C13 /* InfoPlist.strings */,
B36E03B01500889E00AE9C13 /* main.m */,
B36E03B21500889E00AE9C13 /* Encoder-Prefix.pch */,
B36E03B21500889E00AE9C13 /* Base 64 Video Encoder-Prefix.pch */,
B36E03B31500889E00AE9C13 /* Credits.rtf */,
);
name = "Supporting Files";
Expand All @@ -105,9 +121,9 @@
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
B36E039F1500889D00AE9C13 /* Encoder */ = {
B36E039F1500889D00AE9C13 /* Base 64 Video Encoder */ = {
isa = PBXNativeTarget;
buildConfigurationList = B36E03BE1500889F00AE9C13 /* Build configuration list for PBXNativeTarget "Encoder" */;
buildConfigurationList = B36E03BE1500889F00AE9C13 /* Build configuration list for PBXNativeTarget "Base 64 Video Encoder" */;
buildPhases = (
B36E039C1500889D00AE9C13 /* Sources */,
B36E039D1500889D00AE9C13 /* Frameworks */,
Expand All @@ -117,9 +133,9 @@
);
dependencies = (
);
name = Encoder;
name = "Base 64 Video Encoder";
productName = Encoder;
productReference = B36E03A01500889D00AE9C13 /* Encoder.app */;
productReference = B36E03A01500889D00AE9C13 /* Base 64 Video Encoder.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
Expand All @@ -128,10 +144,10 @@
B36E03971500889D00AE9C13 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0420;
LastUpgradeCheck = 0440;
ORGANIZATIONNAME = "Skye Road Systems, Inc.";
};
buildConfigurationList = B36E039A1500889D00AE9C13 /* Build configuration list for PBXProject "Encoder" */;
buildConfigurationList = B36E039A1500889D00AE9C13 /* Build configuration list for PBXProject "Base 64 Video Encoder" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
Expand All @@ -143,7 +159,7 @@
projectDirPath = "";
projectRoot = "";
targets = (
B36E039F1500889D00AE9C13 /* Encoder */,
B36E039F1500889D00AE9C13 /* Base 64 Video Encoder */,
);
};
/* End PBXProject section */
Expand All @@ -156,6 +172,8 @@
B36E03AF1500889E00AE9C13 /* InfoPlist.strings in Resources */,
B36E03B51500889E00AE9C13 /* Credits.rtf in Resources */,
B36E03BB1500889F00AE9C13 /* MainMenu.xib in Resources */,
B39FF32C1500985F00768855 /* video.html in Resources */,
B3C7D26715009AF800ECE445 /* part2.html in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -168,6 +186,8 @@
files = (
B36E03B11500889E00AE9C13 /* main.m in Sources */,
B36E03B81500889E00AE9C13 /* AppDelegate.m in Sources */,
B39FF32615008E2900768855 /* NSData+Additions.m in Sources */,
B39FF32A15008E5B00768855 /* NSString+Additions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -251,29 +271,31 @@
B36E03BF1500889F00AE9C13 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
COMBINE_HIDPI_IMAGES = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Encoder/Encoder-Prefix.pch";
INFOPLIST_FILE = "Encoder/Encoder-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
GCC_PREFIX_HEADER = "Encoder/Base 64 Video Encoder-Prefix.pch";
INFOPLIST_FILE = "Encoder/Base 64 Video Encoder-Info.plist";
PRODUCT_NAME = "Base 64 Video Encoder";
WRAPPER_EXTENSION = app;
};
name = Debug;
};
B36E03C01500889F00AE9C13 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
COMBINE_HIDPI_IMAGES = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Encoder/Encoder-Prefix.pch";
INFOPLIST_FILE = "Encoder/Encoder-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
GCC_PREFIX_HEADER = "Encoder/Base 64 Video Encoder-Prefix.pch";
INFOPLIST_FILE = "Encoder/Base 64 Video Encoder-Info.plist";
PRODUCT_NAME = "Base 64 Video Encoder";
WRAPPER_EXTENSION = app;
};
name = Release;
};
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
B36E039A1500889D00AE9C13 /* Build configuration list for PBXProject "Encoder" */ = {
B36E039A1500889D00AE9C13 /* Build configuration list for PBXProject "Base 64 Video Encoder" */ = {
isa = XCConfigurationList;
buildConfigurations = (
B36E03BC1500889F00AE9C13 /* Debug */,
Expand All @@ -282,13 +304,14 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
B36E03BE1500889F00AE9C13 /* Build configuration list for PBXNativeTarget "Encoder" */ = {
B36E03BE1500889F00AE9C13 /* Build configuration list for PBXNativeTarget "Base 64 Video Encoder" */ = {
isa = XCConfigurationList;
buildConfigurations = (
B36E03BF1500889F00AE9C13 /* Debug */,
B36E03C01500889F00AE9C13 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
13 changes: 13 additions & 0 deletions Encoder/AppDelegate.h
Expand Up @@ -12,4 +12,17 @@

@property (assign) IBOutlet NSWindow *window;

@property (weak) IBOutlet NSTextField *videoInputFilePathLabel;
@property (weak) IBOutlet NSTextField *htmlOutputFilePathLabel;
@property (weak) IBOutlet NSTextField *videoOutputFilePathLabel;
@property (weak) IBOutlet NSTextField *htmlInputFilePathLabel;

@property (copy) NSString *videoInputFilePath;
@property (copy) NSString *htmlOutputFilePath;
@property (copy) NSString *videoOutputFilePath;
@property (copy) NSString *htmlInputFilePath;

- (void)updateLabels;


@end
106 changes: 106 additions & 0 deletions Encoder/AppDelegate.m
Expand Up @@ -7,14 +7,120 @@
//

#import "AppDelegate.h"
#import "NSData+Additions.h"
#import "NSString+Additions.h"

@implementation AppDelegate

@synthesize window = _window;


@synthesize videoInputFilePathLabel;
@synthesize htmlOutputFilePathLabel;
@synthesize videoOutputFilePathLabel;
@synthesize htmlInputFilePathLabel;
@synthesize videoInputFilePath;
@synthesize htmlOutputFilePath;
@synthesize videoOutputFilePath;
@synthesize htmlInputFilePath;

static NSString *start = @"<html>"
"<head><title>Video</title></head>"
"<body>"
"<video controls height=\"576\" width=\"1024\" src=\"data:video/mp4;base64,";

static NSString *end = @"\"></video>"
"</body>"
"</html>";

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{

// Insert code here to initialize your application
}

- (IBAction)didClickChooseInputFileButton:(id)sender
{
NSOpenPanel *openPanel;

openPanel = [NSOpenPanel openPanel];
[openPanel setCanChooseDirectories:NO];
[openPanel setAllowsMultipleSelection:NO];
[openPanel setResolvesAliases:YES];

if ([openPanel runModal] == NSOKButton) {
if ([sender tag] == 10000) {
[self setVideoInputFilePath:[[openPanel URL] path]];
} else if ([sender tag] == 10002) {
[self setHtmlInputFilePath:[[openPanel URL] path]];
}
[self updateLabels];
}
}

- (IBAction)didClickChooseOutputFileButton:(id)sender
{
NSSavePanel *savePanel;

savePanel = [NSSavePanel savePanel];

if( [savePanel runModal] == NSOKButton) {
if ([sender tag] == 10001) {
[self setHtmlOutputFilePath:[[savePanel URL] path]];
} else if ([sender tag] == 10003) {
[self setVideoOutputFilePath:[[savePanel URL] path]];
}
[self updateLabels];
}
}

- (IBAction)didClickConvertButton:(id)sender
{
if ([sender tag] == 10005) {
if (![self videoInputFilePath] || ![self htmlOutputFilePath] || [[self videoInputFilePath] length] <= 0 || [[self htmlOutputFilePath] length] <= 0)
return;
NSData *data = [NSData dataWithContentsOfFile:[self videoInputFilePath]];

NSString *encoded = [data base64String];

NSString *output = [NSString stringWithFormat:@"%@%@%@", start, encoded, end];

NSError *error = nil;
if (![output writeToFile:[self htmlOutputFilePath] atomically:YES encoding:NSUTF8StringEncoding error:&error]) {
NSLog(@"Couldn't write file: %@", [error localizedDescription]);
}

} else if ([sender tag] == 10006) {
if (![self videoOutputFilePath] || ![self htmlInputFilePath] || [[self videoOutputFilePath] length] <= 0 || [[self htmlInputFilePath] length] <= 0)
return;

NSError *error = nil;
NSString *encoded = [NSString stringWithContentsOfFile:[self htmlInputFilePath] encoding:NSUTF8StringEncoding error:&error];

if (!encoded) {
NSLog(@"Couldn't load file: %@", [error localizedDescription]);
}

// Strip off the html if any
encoded = [encoded stringByReplacingOccurrencesOfString:start withString:@""];
encoded = [encoded stringByReplacingOccurrencesOfString:end withString:@""];

NSData *decoded = [encoded base64Data];

if (![decoded writeToFile:[self videoOutputFilePath] atomically:YES]) {
NSLog(@"Couldn't write file");
}

}

}

- (void)updateLabels
{
[[self videoInputFilePathLabel] setStringValue:[self videoInputFilePath]];
[[self htmlOutputFilePathLabel] setStringValue:[self htmlOutputFilePath]];
[[self videoOutputFilePathLabel] setStringValue:[self videoOutputFilePath]];
[[self htmlInputFilePathLabel] setStringValue:[self htmlInputFilePath]];
}

@end
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions Encoder/NSData+Additions.h
@@ -0,0 +1,19 @@
//
// NSData+Additions.h
// Encoder
//
// Created by Matt Long on 3/1/12.
// Copyright (c) 2012 Skye Road Systems, Inc. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CommonCrypto/CommonDigest.h>

@interface NSData (Additions)

- (NSString*)ga_digest;
+ (NSData*)base64DataFromString:(NSString*)string;
- (NSString*)base64String;
- (NSString*)base64StringOfLength:(unsigned long)length;

@end

0 comments on commit 6e249a6

Please sign in to comment.