Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
Added export
Browse files Browse the repository at this point in the history
Added export for all resources
Added custom export path
Added Icon
  • Loading branch information
ikorich committed Dec 21, 2014
1 parent 5b0229f commit 7edd618
Show file tree
Hide file tree
Showing 18 changed files with 118 additions and 61 deletions.
47 changes: 39 additions & 8 deletions Resources/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<customObject id="Voe-Tx-rLC" customClass="AppDelegate">
<connections>
<outlet property="collectionView" destination="Biv-Hp-2We" id="hgt-C5-ARe"/>
<outlet property="exportPath" destination="zYP-It-bHI" id="gM0-Zc-QFV"/>
<outlet property="spinerView" destination="WWy-px-EHy" id="NSC-zY-yfO"/>
<outlet property="window" destination="QvC-M9-y7g" id="mKP-zD-IdU"/>
</connections>
</customObject>
Expand Down Expand Up @@ -664,14 +666,14 @@
</menu>
<window title="iResource" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="QvC-M9-y7g">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<rect key="contentRect" x="335" y="390" width="480" height="360"/>
<rect key="contentRect" x="335" y="390" width="649" height="550"/>
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1058"/>
<view key="contentView" id="EiT-Mj-1SZ">
<rect key="frame" x="0.0" y="0.0" width="480" height="360"/>
<rect key="frame" x="0.0" y="-5" width="649" height="550"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<scrollView autohidesScrollers="YES" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" usesPredominantAxisScrolling="NO" id="86M-EY-7Zg">
<rect key="frame" x="20" y="20" width="440" height="320"/>
<rect key="frame" x="20" y="61" width="609" height="469"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<clipView key="contentView" id="VqR-zJ-nhk">
<rect key="frame" x="1" y="1" width="438" height="318"/>
Expand All @@ -696,9 +698,36 @@
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
<button verticalHuggingPriority="750" id="z1v-QW-x0W">
<rect key="frame" x="535" y="13" width="100" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
<buttonCell key="cell" type="push" title="Export All" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="uvh-ar-Znn">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="exportAllResources:" target="Voe-Tx-rLC" id="ZD4-gl-je8"/>
</connections>
</button>
<textField verticalHuggingPriority="750" id="zYP-It-bHI">
<rect key="frame" x="20" y="19" width="513" height="22"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="J0r-B4-RGE">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<binding destination="1w8-ck-fyZ" name="value" keyPath="values.ExportPath" id="lkA-Vx-rLe"/>
</connections>
</textField>
<progressIndicator horizontalHuggingPriority="750" verticalHuggingPriority="750" maxValue="100" displayedWhenStopped="NO" bezeled="NO" indeterminate="YES" style="spinning" id="WWy-px-EHy">
<rect key="frame" x="308" y="279" width="32" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
</progressIndicator>
</subviews>
</view>
<point key="canvasLocation" x="404" y="240"/>
<point key="canvasLocation" x="488.5" y="335"/>
</window>
<collectionViewItem id="98m-3m-C57" customClass="ResourceCollectionItem">
<connections>
Expand Down Expand Up @@ -729,11 +758,11 @@
<binding destination="98m-3m-C57" name="value" keyPath="representedObject.name" id="UuS-9d-A6F"/>
</connections>
</textField>
<button id="MXD-SX-N9I">
<rect key="frame" x="69" y="72" width="37" height="32"/>
<button hidden="YES" canDrawConcurrently="YES" focusRingType="none" id="MXD-SX-N9I">
<rect key="frame" x="71" y="70" width="26" height="26"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="bevel" bezelStyle="regularSquare" image="NSFollowLinkFreestandingTemplate" imagePosition="only" alignment="center" imageScaling="proportionallyDown" inset="2" id="89W-3K-TGk">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<buttonCell key="cell" type="bevel" bezelStyle="circular" image="NSFollowLinkFreestandingTemplate" imagePosition="only" alignment="center" alternateImage="NSFollowLinkFreestandingTemplate" focusRingType="none" inset="2" id="89W-3K-TGk">
<behavior key="behavior" pushIn="YES" changeContents="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
Expand All @@ -746,7 +775,9 @@
</connections>
</button>
</subviews>
<point key="canvasLocation" x="927" y="240"/>
</view>
<userDefaultsController representsSharedInstance="YES" id="1w8-ck-fyZ"/>
</objects>
<resources>
<image name="NSFollowLinkFreestandingTemplate" width="14" height="14"/>
Expand Down
30 changes: 20 additions & 10 deletions Resources/Images.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,53 +1,63 @@
{
"images" : [
{
"idiom" : "mac",
"size" : "16x16",
"idiom" : "mac",
"filename" : "icon16.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "16x16",
"idiom" : "mac",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "32x32",
"idiom" : "mac",
"filename" : "icon32.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "32x32",
"idiom" : "mac",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "128x128",
"idiom" : "mac",
"filename" : "icon128.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "128x128",
"idiom" : "mac",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "256x256",
"idiom" : "mac",
"filename" : "icon256.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "256x256",
"idiom" : "mac",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "512x512",
"idiom" : "mac",
"filename" : "icon512.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "512x512",
"idiom" : "mac",
"filename" : "[email protected]",
"scale" : "2x"
}
],
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 0 additions & 6 deletions iResource.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
A59626031A460BDB0056303D /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = A59625FD1A460BDB0056303D /* Credits.rtf */; };
A59626041A460BDB0056303D /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = A59625FF1A460BDB0056303D /* InfoPlist.strings */; };
A59626051A460BDB0056303D /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A59626011A460BDB0056303D /* Images.xcassets */; };
A59626081A460DE00056303D /* IGRResourceManager.m in Sources */ = {isa = PBXBuildFile; fileRef = A59626071A460DE00056303D /* IGRResourceManager.m */; };
A59626101A4610570056303D /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A596260D1A4610570056303D /* Cocoa.framework */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -47,8 +46,6 @@
A59625FE1A460BDB0056303D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = en; path = Credits.rtf; sourceTree = "<group>"; };
A59626001A460BDB0056303D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = InfoPlist.strings; sourceTree = "<group>"; };
A59626011A460BDB0056303D /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
A59626061A460DE00056303D /* IGRResourceManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGRResourceManager.h; sourceTree = "<group>"; };
A59626071A460DE00056303D /* IGRResourceManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGRResourceManager.m; sourceTree = "<group>"; };
A596260D1A4610570056303D /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
A596260E1A4610570056303D /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
A596260F1A4610570056303D /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -102,8 +99,6 @@
A59625F41A45FE8E0056303D /* ResourceEntities.m */,
A59625F51A45FE8E0056303D /* ResourceCollectionItemView.h */,
A59625F61A45FE8E0056303D /* ResourceCollectionItemView.m */,
A59626061A460DE00056303D /* IGRResourceManager.h */,
A59626071A460DE00056303D /* IGRResourceManager.m */,
A59625CA1A45F4250056303D /* Supporting Files */,
);
path = iResource;
Expand Down Expand Up @@ -257,7 +252,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
A59626081A460DE00056303D /* IGRResourceManager.m in Sources */,
A59625F71A45FE8E0056303D /* ResourceEntities.m in Sources */,
A59625D01A45F4250056303D /* main.m in Sources */,
A59625CE1A45F4250056303D /* AppDelegate.m in Sources */,
Expand Down
6 changes: 6 additions & 0 deletions iResource/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@

#import <Cocoa/Cocoa.h>

@class ResourceEntities;

@interface AppDelegate : NSObject <NSApplicationDelegate>

@property (weak) IBOutlet NSWindow *window;
@property (weak) IBOutlet NSCollectionView *collectionView;
@property (weak) IBOutlet NSProgressIndicator *spinerView;
@property (weak) IBOutlet NSTextField *exportPath;

- (void)saveResource:(ResourceEntities *)resourceEntity;

@end
55 changes: 50 additions & 5 deletions iResource/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ @interface AppDelegate ()
- (IBAction)openFile:(id)sender;

@property (nonatomic, strong) NSURL *resourceURL;
@property (nonatomic, strong) NSMutableArray *resourceData;

@end

Expand Down Expand Up @@ -91,14 +92,16 @@ - (void)gatherAppData
return;
};

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0);
self.resourceData = [[NSMutableArray alloc] init];

__weak typeof(self) weakSelf = self;

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{

ResType theType = 'PNG ';
ResourceCount count = CountResources(theType);

NSMutableArray *_appData = [[NSMutableArray alloc]init];

for (int x = 1; x <= count; ++x)
{
Handle resource = Get1IndResource(theType, x);
Expand All @@ -120,8 +123,8 @@ - (void)gatherAppData
item.image = result;
item.name = [NSString stringWithFormat:@"%@", @(theID)];

[_appData addObject:item];
[self performSelectorOnMainThread:@selector(updateData:) withObject:_appData waitUntilDone:YES];
[weakSelf.resourceData addObject:item];
[weakSelf performSelectorOnMainThread:@selector(updateData:) withObject:weakSelf.resourceData waitUntilDone:YES];
}

ReleaseResource(resource);
Expand All @@ -139,4 +142,46 @@ - (void)updateData:(NSMutableArray *)obj
[_collectionView setContent:obj];
}

- (IBAction)exportAllResources:(id)sender
{
[self.spinerView startAnimation:self];
[self.collectionView setHidden:YES];

for (ResourceEntities *item in self.resourceData)
{
[self saveResource:item];
}

[self.collectionView setHidden:NO];
[self.spinerView stopAnimation:self];
}

- (void)saveResource:(ResourceEntities *)resourceEntity
{
if (![[NSFileManager defaultManager] fileExistsAtPath:self.exportPath.stringValue isDirectory:nil])
{
[[NSFileManager defaultManager] createDirectoryAtPath:self.exportPath.stringValue withIntermediateDirectories:YES attributes:nil error:nil];
}

NSBitmapImageRep *imgRep = [[resourceEntity.image representations] objectAtIndex: 0];
NSData *data = [imgRep representationUsingType: NSPNGFileType properties: nil];

[data writeToFile: [NSString stringWithFormat:@"%@/%@.png", self.exportPath.stringValue, resourceEntity.name] atomically: NO];
}

#pragma mark - Preference
+ (void)initialize
{
// Create a dictionary
NSMutableDictionary *defaultValues = [NSMutableDictionary dictionary];

// Put defaults in the dictionary
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES );
NSString* theDesktopPath = [paths objectAtIndex:0];
defaultValues[@"ExportPath"] = theDesktopPath;

// Register the dictionary of defaults
[[NSUserDefaults standardUserDefaults] registerDefaults: defaultValues];
}

@end
13 changes: 0 additions & 13 deletions iResource/IGRResourceManager.h

This file was deleted.

13 changes: 0 additions & 13 deletions iResource/IGRResourceManager.m

This file was deleted.

9 changes: 3 additions & 6 deletions iResource/ResourceCollectionItemView.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "ResourceCollectionItemView.h"
#import "ResourceEntities.h"
#import "AppDelegate.h"

@implementation ResourceCollectionItemView

Expand Down Expand Up @@ -76,12 +77,8 @@ - (IBAction)exportFile:(id)sender
{
ResourceEntities *res = self.collectionView.content[self.collectionView.selectionIndexes.firstIndex];

NSBitmapImageRep *imgRep = [[res.image representations] objectAtIndex: 0];
NSData *data = [imgRep representationUsingType: NSPNGFileType properties: nil];

NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES );
NSString* theDesktopPath = [paths objectAtIndex:0];
[data writeToFile: [NSString stringWithFormat:@"%@/%@.png", theDesktopPath, res.name] atomically: NO];
AppDelegate *app = [[NSApplication sharedApplication] delegate];
[app saveResource:res];
}

@end

0 comments on commit 7edd618

Please sign in to comment.