SWFファイル内の画像を表示/書き出しするGUIツール
修订版 | c22673fd7f0c390897eadc4e95def8c184fe5f25 (tree) |
---|---|
时间 | 2016-10-02 09:24:27 |
作者 | masakih <masakih@user...> |
Commiter | masakih |
HMSwfDocumentをSwiftに書き換えた
@@ -9,16 +9,15 @@ | ||
9 | 9 | /* Begin PBXBuildFile section */ |
10 | 10 | F42ADB271D9A91D300407165 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = F42ADB261D9A91D300407165 /* AppDelegate.m */; }; |
11 | 11 | F42ADB2A1D9A91D300407165 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = F42ADB291D9A91D300407165 /* main.m */; }; |
12 | - F42ADB2D1D9A91D300407165 /* HMSwfDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = F42ADB2C1D9A91D300407165 /* HMSwfDocument.m */; }; | |
13 | 12 | F42ADB301D9A91D400407165 /* HMSwfDocument.xib in Resources */ = {isa = PBXBuildFile; fileRef = F42ADB2E1D9A91D400407165 /* HMSwfDocument.xib */; }; |
14 | 13 | F42ADB321D9A91D400407165 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F42ADB311D9A91D400407165 /* Assets.xcassets */; }; |
15 | 14 | F42ADB351D9A91D400407165 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = F42ADB331D9A91D400407165 /* MainMenu.xib */; }; |
16 | 15 | F42ADB401D9A942A00407165 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = F42ADB421D9A942A00407165 /* InfoPlist.strings */; }; |
17 | 16 | F42ADB451D9A96ED00407165 /* HMSwfImage.m in Sources */ = {isa = PBXBuildFile; fileRef = F42ADB441D9A96ED00407165 /* HMSwfImage.m */; }; |
18 | 17 | F42ADB4C1D9AA56000407165 /* KanColleGraphicDivider in Resources */ = {isa = PBXBuildFile; fileRef = F42ADB4B1D9AA56000407165 /* KanColleGraphicDivider */; }; |
19 | - F42ADB4F1D9AC37600407165 /* NSString-extensions.m in Sources */ = {isa = PBXBuildFile; fileRef = F42ADB4E1D9AC37600407165 /* NSString-extensions.m */; }; | |
20 | 18 | F42ADB651D9BFDED00407165 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = F42ADB631D9BFDED00407165 /* Localizable.strings */; }; |
21 | 19 | F42ADB681D9D5F1300407165 /* HMTemporaryDirectory.m in Sources */ = {isa = PBXBuildFile; fileRef = F42ADB671D9D5F1300407165 /* HMTemporaryDirectory.m */; }; |
20 | + F42ADB6C1D9FC7FD00407165 /* HMSwfDocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = F42ADB6B1D9FC7FD00407165 /* HMSwfDocument.swift */; }; | |
22 | 21 | /* End PBXBuildFile section */ |
23 | 22 | |
24 | 23 | /* Begin PBXContainerItemProxy section */ |
@@ -43,8 +42,6 @@ | ||
43 | 42 | F42ADB251D9A91D300407165 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; }; |
44 | 43 | F42ADB261D9A91D300407165 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; }; |
45 | 44 | F42ADB291D9A91D300407165 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; }; |
46 | - F42ADB2B1D9A91D300407165 /* HMSwfDocument.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HMSwfDocument.h; sourceTree = "<group>"; }; | |
47 | - F42ADB2C1D9A91D300407165 /* HMSwfDocument.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HMSwfDocument.m; sourceTree = "<group>"; }; | |
48 | 45 | F42ADB2F1D9A91D400407165 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/HMSwfDocument.xib; sourceTree = "<group>"; }; |
49 | 46 | F42ADB311D9A91D400407165 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; |
50 | 47 | F42ADB341D9A91D400407165 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = "<group>"; }; |
@@ -56,13 +53,13 @@ | ||
56 | 53 | F42ADB441D9A96ED00407165 /* HMSwfImage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMSwfImage.m; sourceTree = "<group>"; }; |
57 | 54 | F42ADB471D9AA3EA00407165 /* KanColleGraphicDivider */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; name = KanColleGraphicDivider; path = "../../Library/Developer/Xcode/DerivedData/KoreNoKaraSu-azymafwtbfcomieoipkjtpgiffzd/Build/Products/Debug/KanColleGraphicDivider"; sourceTree = "<group>"; }; |
58 | 55 | F42ADB4B1D9AA56000407165 /* KanColleGraphicDivider */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; path = KanColleGraphicDivider; sourceTree = BUILT_PRODUCTS_DIR; }; |
59 | - F42ADB4D1D9AC37600407165 /* NSString-extensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString-extensions.h"; sourceTree = "<group>"; }; | |
60 | - F42ADB4E1D9AC37600407165 /* NSString-extensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString-extensions.m"; sourceTree = "<group>"; }; | |
61 | 56 | F42ADB581D9BFCD100407165 /* KanColleGraphicDivider.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = KanColleGraphicDivider.xcodeproj; path = KanColleGraphicDivider/KanColleGraphicDivider.xcodeproj; sourceTree = "<group>"; }; |
62 | 57 | F42ADB611D9BFD5600407165 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text; name = ja; path = ja.lproj/Localizable.strings.sed; sourceTree = "<group>"; }; |
63 | 58 | F42ADB641D9BFDED00407165 /* ja */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/Localizable.strings; sourceTree = "<group>"; }; |
64 | 59 | F42ADB661D9D5F1300407165 /* HMTemporaryDirectory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMTemporaryDirectory.h; sourceTree = "<group>"; }; |
65 | 60 | F42ADB671D9D5F1300407165 /* HMTemporaryDirectory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMTemporaryDirectory.m; sourceTree = "<group>"; }; |
61 | + F42ADB6A1D9FC7FC00407165 /* KoreNoKaraSu-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "KoreNoKaraSu-Bridging-Header.h"; sourceTree = "<group>"; }; | |
62 | + F42ADB6B1D9FC7FD00407165 /* HMSwfDocument.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMSwfDocument.swift; sourceTree = "<group>"; }; | |
66 | 63 | /* End PBXFileReference section */ |
67 | 64 | |
68 | 65 | /* Begin PBXFrameworksBuildPhase section */ |
@@ -100,15 +97,12 @@ | ||
100 | 97 | children = ( |
101 | 98 | F42ADB251D9A91D300407165 /* AppDelegate.h */, |
102 | 99 | F42ADB261D9A91D300407165 /* AppDelegate.m */, |
103 | - F42ADB2B1D9A91D300407165 /* HMSwfDocument.h */, | |
104 | - F42ADB2C1D9A91D300407165 /* HMSwfDocument.m */, | |
100 | + F42ADB6B1D9FC7FD00407165 /* HMSwfDocument.swift */, | |
105 | 101 | F42ADB2E1D9A91D400407165 /* HMSwfDocument.xib */, |
106 | 102 | F42ADB431D9A96ED00407165 /* HMSwfImage.h */, |
107 | 103 | F42ADB441D9A96ED00407165 /* HMSwfImage.m */, |
108 | 104 | F42ADB661D9D5F1300407165 /* HMTemporaryDirectory.h */, |
109 | 105 | F42ADB671D9D5F1300407165 /* HMTemporaryDirectory.m */, |
110 | - F42ADB4D1D9AC37600407165 /* NSString-extensions.h */, | |
111 | - F42ADB4E1D9AC37600407165 /* NSString-extensions.m */, | |
112 | 106 | F42ADB311D9A91D400407165 /* Assets.xcassets */, |
113 | 107 | F42ADB331D9A91D400407165 /* MainMenu.xib */, |
114 | 108 | F42ADB361D9A91D400407165 /* Info.plist */, |
@@ -116,6 +110,7 @@ | ||
116 | 110 | F42ADB601D9BFD5600407165 /* Localizable.strings.sed */, |
117 | 111 | F42ADB631D9BFDED00407165 /* Localizable.strings */, |
118 | 112 | F42ADB281D9A91D300407165 /* Supporting Files */, |
113 | + F42ADB6A1D9FC7FC00407165 /* KoreNoKaraSu-Bridging-Header.h */, | |
119 | 114 | ); |
120 | 115 | path = KoreNoKaraSu; |
121 | 116 | sourceTree = "<group>"; |
@@ -176,6 +171,7 @@ | ||
176 | 171 | TargetAttributes = { |
177 | 172 | F42ADB211D9A91D300407165 = { |
178 | 173 | CreatedOnToolsVersion = 8.0; |
174 | + LastSwiftMigration = 0800; | |
179 | 175 | ProvisioningStyle = Automatic; |
180 | 176 | }; |
181 | 177 | }; |
@@ -236,10 +232,9 @@ | ||
236 | 232 | isa = PBXSourcesBuildPhase; |
237 | 233 | buildActionMask = 2147483647; |
238 | 234 | files = ( |
239 | - F42ADB2D1D9A91D300407165 /* HMSwfDocument.m in Sources */, | |
235 | + F42ADB6C1D9FC7FD00407165 /* HMSwfDocument.swift in Sources */, | |
240 | 236 | F42ADB2A1D9A91D300407165 /* main.m in Sources */, |
241 | 237 | F42ADB681D9D5F1300407165 /* HMTemporaryDirectory.m in Sources */, |
242 | - F42ADB4F1D9AC37600407165 /* NSString-extensions.m in Sources */, | |
243 | 238 | F42ADB271D9A91D300407165 /* AppDelegate.m in Sources */, |
244 | 239 | F42ADB451D9A96ED00407165 /* HMSwfImage.m in Sources */, |
245 | 240 | ); |
@@ -394,11 +389,15 @@ | ||
394 | 389 | isa = XCBuildConfiguration; |
395 | 390 | buildSettings = { |
396 | 391 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; |
392 | + CLANG_ENABLE_MODULES = YES; | |
397 | 393 | COMBINE_HIDPI_IMAGES = YES; |
398 | 394 | INFOPLIST_FILE = KoreNoKaraSu/Info.plist; |
399 | 395 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; |
400 | 396 | PRODUCT_BUNDLE_IDENTIFIER = com.masakih.KoreNoKaraSu; |
401 | 397 | PRODUCT_NAME = "$(TARGET_NAME)"; |
398 | + SWIFT_OBJC_BRIDGING_HEADER = "KoreNoKaraSu/KoreNoKaraSu-Bridging-Header.h"; | |
399 | + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; | |
400 | + SWIFT_VERSION = 3.0; | |
402 | 401 | }; |
403 | 402 | name = Debug; |
404 | 403 | }; |
@@ -406,11 +405,14 @@ | ||
406 | 405 | isa = XCBuildConfiguration; |
407 | 406 | buildSettings = { |
408 | 407 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; |
408 | + CLANG_ENABLE_MODULES = YES; | |
409 | 409 | COMBINE_HIDPI_IMAGES = YES; |
410 | 410 | INFOPLIST_FILE = KoreNoKaraSu/Info.plist; |
411 | 411 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; |
412 | 412 | PRODUCT_BUNDLE_IDENTIFIER = com.masakih.KoreNoKaraSu; |
413 | 413 | PRODUCT_NAME = "$(TARGET_NAME)"; |
414 | + SWIFT_OBJC_BRIDGING_HEADER = "KoreNoKaraSu/KoreNoKaraSu-Bridging-Header.h"; | |
415 | + SWIFT_VERSION = 3.0; | |
414 | 416 | }; |
415 | 417 | name = Release; |
416 | 418 | }; |
@@ -5,7 +5,7 @@ | ||
5 | 5 | <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11201"/> |
6 | 6 | </dependencies> |
7 | 7 | <objects> |
8 | - <customObject id="-2" userLabel="File's Owner" customClass="HMSwfDocument"> | |
8 | + <customObject id="-2" userLabel="File's Owner" customClass="HMSwfDocument" customModule="KoreNoKaraSu"> | |
9 | 9 | <connections> |
10 | 10 | <outlet property="imagesController" destination="UYM-GR-Pyx" id="blM-N9-Oui"/> |
11 | 11 | <outlet property="tableView" destination="NMJ-z5-Ntb" id="GRu-aX-QKs"/> |
@@ -163,14 +163,14 @@ | ||
163 | 163 | <menuItem title="Copy" id="d9p-PZ-3gg"> |
164 | 164 | <modifierMask key="keyEquivalentModifierMask"/> |
165 | 165 | <connections> |
166 | - <action selector="copy:" target="-2" id="ggr-15-tiC"/> | |
166 | + <action selector="copy:" target="-2" id="DrN-sI-Lay"/> | |
167 | 167 | </connections> |
168 | 168 | </menuItem> |
169 | 169 | <menuItem isSeparatorItem="YES" id="fON-ES-Oye"/> |
170 | 170 | <menuItem title="Export…" id="IWB-MT-07s"> |
171 | 171 | <modifierMask key="keyEquivalentModifierMask"/> |
172 | 172 | <connections> |
173 | - <action selector="exportSelection:" target="-2" id="2AZ-lX-15U"/> | |
173 | + <action selector="exportSelection:" target="-2" id="svI-u6-z6K"/> | |
174 | 174 | </connections> |
175 | 175 | </menuItem> |
176 | 176 | </items> |
@@ -1,16 +0,0 @@ | ||
1 | -// | |
2 | -// Document.h | |
3 | -// KoreNoKaraSu | |
4 | -// | |
5 | -// Created by Hori,Masaki on 2016/09/27. | |
6 | -// Copyright © 2016年 Hori,Masaki. All rights reserved. | |
7 | -// | |
8 | - | |
9 | -#import <Cocoa/Cocoa.h> | |
10 | - | |
11 | -@interface HMSwfDocument : NSDocument | |
12 | - | |
13 | -- (IBAction)exportSelection:(id)sender; | |
14 | - | |
15 | -@end | |
16 | - |
@@ -1,163 +0,0 @@ | ||
1 | -// | |
2 | -// Document.m | |
3 | -// KoreNoKaraSu | |
4 | -// | |
5 | -// Created by Hori,Masaki on 2016/09/27. | |
6 | -// Copyright © 2016年 Hori,Masaki. All rights reserved. | |
7 | -// | |
8 | - | |
9 | -#import "HMSwfDocument.h" | |
10 | -#import "HMTemporaryDirectory.h" | |
11 | - | |
12 | -#import "HMSwfImage.h" | |
13 | - | |
14 | -#import "NSString-extensions.h" | |
15 | - | |
16 | - | |
17 | -@interface HMSwfDocument () | |
18 | - | |
19 | -@property (weak, nonatomic) IBOutlet NSTableView *tableView; | |
20 | -@property (weak, nonatomic) IBOutlet NSArrayController *imagesController; | |
21 | - | |
22 | -@property (copy) NSArray<HMSwfImage *> *swfImages; | |
23 | - | |
24 | -@property (strong) HMTemporaryDirectory *temporaryDirectorhy; | |
25 | - | |
26 | -@property BOOL didExtract; | |
27 | -@end | |
28 | - | |
29 | -@implementation HMSwfDocument | |
30 | - | |
31 | -- (NSString *)windowNibName { | |
32 | - return @"HMSwfDocument"; | |
33 | -} | |
34 | - | |
35 | -- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError { | |
36 | - | |
37 | - NSBundle *mainBundle = [NSBundle mainBundle]; | |
38 | - NSString *path = [mainBundle pathForResource:@"KanColleGraphicDivider" ofType:nil]; | |
39 | - if(!path) { | |
40 | - NSBeep(); | |
41 | - return NO; | |
42 | - } | |
43 | - | |
44 | - self.temporaryDirectorhy = [HMTemporaryDirectory temporaryDirectoryWithName:self.fileURL.path.lastPathComponent.stringByDeletingPathExtension]; | |
45 | - if(!self.temporaryDirectorhy) { | |
46 | - NSLog(@"can not create HMTemporaryDirectory."); | |
47 | - NSBeep(); | |
48 | - return NO; | |
49 | - } | |
50 | - | |
51 | - NSTask *task = [NSTask new]; | |
52 | - task.launchPath = path; | |
53 | - task.arguments = @[ | |
54 | - @"-o", | |
55 | - self.temporaryDirectorhy.fullpath, | |
56 | - self.fileURL.path | |
57 | - ]; | |
58 | - | |
59 | - task.terminationHandler = ^(NSTask *task) { | |
60 | - NSFileManager *fm = [NSFileManager defaultManager]; | |
61 | - NSArray<NSURL *> *imageURLs = [fm contentsOfDirectoryAtURL:self.temporaryDirectorhy.URL | |
62 | - includingPropertiesForKeys:nil | |
63 | - options:0 | |
64 | - error:NULL]; | |
65 | - NSMutableArray<HMSwfImage *> *images = [NSMutableArray array]; | |
66 | - for(NSURL *imageURL in imageURLs) { | |
67 | - NSImage *image = [[NSImage alloc] initWithContentsOfURL:imageURL]; | |
68 | - if(!image) { | |
69 | - NSLog(@"can not create image from %@", imageURL.path); | |
70 | - continue; | |
71 | - } | |
72 | - HMSwfImage *swfImage = [HMSwfImage new]; | |
73 | - swfImage.image = image; | |
74 | - swfImage.filepath = imageURL.path; | |
75 | - | |
76 | - [images addObject:swfImage]; | |
77 | - } | |
78 | - | |
79 | - NSArray<HMSwfImage *> *swfImages = [images sortedArrayUsingComparator:^NSComparisonResult(HMSwfImage * _Nonnull obj1, HMSwfImage * _Nonnull obj2) { | |
80 | - return [obj1.name numericCompare:obj2.name]; | |
81 | - }]; | |
82 | - | |
83 | - dispatch_async(dispatch_get_main_queue(), ^{ | |
84 | - self.swfImages = swfImages; | |
85 | - self.didExtract = YES; | |
86 | - }); | |
87 | - }; | |
88 | - | |
89 | - [task launch]; | |
90 | - | |
91 | - return YES; | |
92 | -} | |
93 | - | |
94 | -- (HMSwfImage *)actionTarget | |
95 | -{ | |
96 | - HMSwfImage *swfImage = nil; | |
97 | - | |
98 | - NSInteger row = [self.tableView clickedRow]; | |
99 | - if(row != -1 || row < self.swfImages.count) { | |
100 | - swfImage = self.swfImages[row]; | |
101 | - } | |
102 | - | |
103 | - if(!swfImage) { | |
104 | - NSIndexSet *selectionIndexes = self.imagesController.selectionIndexes; | |
105 | - NSArray *selection = [self.swfImages objectsAtIndexes:selectionIndexes]; | |
106 | - if(selection.count == 0) return nil; | |
107 | - swfImage = selection[0]; | |
108 | - } | |
109 | - | |
110 | - return swfImage; | |
111 | -} | |
112 | - | |
113 | -- (IBAction)exportSelection:(id)sender | |
114 | -{ | |
115 | - HMSwfImage *swfImage = [self actionTarget]; | |
116 | - if(!swfImage) return; | |
117 | - | |
118 | - NSSavePanel *panel = [NSSavePanel savePanel]; | |
119 | - panel.allowedFileTypes = @[swfImage.filepath.pathExtension]; | |
120 | - panel.prompt = [NSString stringWithFormat:NSLocalizedString(@"Export", @"Save Panel - Export")]; | |
121 | - panel.message = [NSString stringWithFormat:NSLocalizedString(@"Export image of %@", @"Save Panel - Message"), swfImage.name]; | |
122 | - | |
123 | - [panel beginSheetModalForWindow:self.windowForSheet | |
124 | - completionHandler:^(NSInteger result) { | |
125 | - if(result == NSModalResponseCancel) return; | |
126 | - | |
127 | - NSFileManager *fm = [NSFileManager defaultManager]; | |
128 | - NSError *error = nil; | |
129 | - | |
130 | - if([fm fileExistsAtPath:panel.URL.path]) { | |
131 | - if(![fm removeItemAtURL:panel.URL | |
132 | - error:&error]) { | |
133 | - if(error) { | |
134 | - NSLog(@"%@", error); | |
135 | - return; | |
136 | - } | |
137 | - NSLog(@"Fail remove item"); | |
138 | - return; | |
139 | - } | |
140 | - } | |
141 | - | |
142 | - error = nil; | |
143 | - if(![fm copyItemAtURL:[NSURL fileURLWithPath:swfImage.filepath] | |
144 | - toURL:panel.URL | |
145 | - error:&error]) { | |
146 | - if(error) { | |
147 | - NSLog(@"%@", error); | |
148 | - return; | |
149 | - } | |
150 | - NSLog(@"Fail copy item"); | |
151 | - } | |
152 | - }]; | |
153 | -} | |
154 | - | |
155 | -- (IBAction)copy:(id)sender | |
156 | -{ | |
157 | - HMSwfImage *swfImage = [self actionTarget]; | |
158 | - NSPasteboard *pb = [NSPasteboard generalPasteboard]; | |
159 | - [pb clearContents]; | |
160 | - [pb writeObjects:@[swfImage.image]]; | |
161 | -} | |
162 | - | |
163 | -@end |
@@ -0,0 +1,132 @@ | ||
1 | +// | |
2 | +// HMSwfDocument.swift | |
3 | +// KoreNoKaraSu | |
4 | +// | |
5 | +// Created by Hori,Masaki on 2016/10/01. | |
6 | +// Copyright © 2016年 Hori,Masaki. All rights reserved. | |
7 | +// | |
8 | + | |
9 | +import Cocoa | |
10 | + | |
11 | +enum HMSwfDocumentError : Error { | |
12 | + case CanNotOpenResource | |
13 | + case NotFoundBaseName | |
14 | + case CanNotCreateTemporaryDirectory | |
15 | +} | |
16 | + | |
17 | +extension String { | |
18 | + func numericCompare(_ str: String, order: ComparisonResult = .orderedAscending) -> Bool { | |
19 | + return compare(str, options: .numeric, range: nil, locale: nil) == order ? true : false | |
20 | + } | |
21 | +} | |
22 | + | |
23 | +extension Collection { | |
24 | + func objects(atIndexes: IndexSet) -> [Self.Iterator.Element] { | |
25 | + return enumerated().filter { atIndexes.contains($0.0) }.map { $0.1 } | |
26 | + } | |
27 | +} | |
28 | + | |
29 | +class HMSwfDocument: NSDocument { | |
30 | + @IBOutlet var tableView: NSTableView? | |
31 | + @IBOutlet var imagesController: NSArrayController? | |
32 | + dynamic var swfImages: [HMSwfImage]? | |
33 | + dynamic var didExtract = false | |
34 | + | |
35 | + private var temporaryDirectory: HMTemporaryDirectory? | |
36 | + | |
37 | + override var windowNibName: String? { | |
38 | + get { | |
39 | + return "HMSwfDocument" | |
40 | + } | |
41 | + } | |
42 | + | |
43 | + override func read(from url: URL, ofType typeName: String) throws { | |
44 | + guard let path = Bundle.main.path(forResource: "KanColleGraphicDivider", ofType: nil) else { | |
45 | + throw HMSwfDocumentError.CanNotOpenResource | |
46 | + } | |
47 | + guard let basename = fileURL?.deletingPathExtension().lastPathComponent else { | |
48 | + throw HMSwfDocumentError.NotFoundBaseName | |
49 | + } | |
50 | + temporaryDirectory = HMTemporaryDirectory(name: basename) | |
51 | + guard temporaryDirectory != nil else { | |
52 | + Swift.print("can not create HMTemporaryDirectory.") | |
53 | + throw HMSwfDocumentError.CanNotCreateTemporaryDirectory | |
54 | + } | |
55 | + | |
56 | + let task = Process() | |
57 | + task.launchPath = path | |
58 | + task.arguments = ["-o", | |
59 | + temporaryDirectory!.fullpath, | |
60 | + fileURL!.path | |
61 | + ] | |
62 | + task.terminationHandler = { (task: Process) in | |
63 | + let fm = FileManager.`default` | |
64 | + guard let imageURLs = try? fm.contentsOfDirectory(at: self.temporaryDirectory!.url, | |
65 | + includingPropertiesForKeys: nil, | |
66 | + options: .skipsSubdirectoryDescendants) | |
67 | + else { return } | |
68 | + let images: [HMSwfImage] = imageURLs.flatMap { | |
69 | + guard let image = NSImage(contentsOf: $0) else { | |
70 | + Swift.print("can not create image from \($0.path)") | |
71 | + return nil | |
72 | + } | |
73 | + let swfImage = HMSwfImage() | |
74 | + swfImage.image = image | |
75 | + swfImage.filepath = $0.path | |
76 | + | |
77 | + return swfImage | |
78 | + }.sorted { | |
79 | + $0.name.numericCompare($1.name) | |
80 | + } | |
81 | + DispatchQueue.main.async { | |
82 | + self.swfImages = images | |
83 | + self.didExtract = true | |
84 | + } | |
85 | + } | |
86 | + task.launch() | |
87 | + } | |
88 | + | |
89 | + func actionTarget() -> HMSwfImage? { | |
90 | + guard swfImages != nil else { return nil } | |
91 | + | |
92 | + let row = tableView!.clickedRow | |
93 | + if row != -1 || row < swfImages!.count { | |
94 | + return swfImages![row] | |
95 | + } | |
96 | + | |
97 | + let selectionIndexes = imagesController!.selectionIndexes | |
98 | + let selection = swfImages!.objects(atIndexes: selectionIndexes) | |
99 | + guard selection.count != 0 else { return nil } | |
100 | + return selection[0] | |
101 | + } | |
102 | + | |
103 | + @IBAction func exportSelection(_ sender: AnyObject) { | |
104 | + guard let target = actionTarget() else { return } | |
105 | + | |
106 | + let panel = NSSavePanel() | |
107 | + panel.allowedFileTypes = [target.url.pathExtension] | |
108 | + panel.prompt = NSLocalizedString("Export", comment: "Save Panel - Export") | |
109 | + panel.message = NSString(format: NSLocalizedString("Export image of %@", comment: "Save Panel - Message") as NSString, target.name) as String! | |
110 | + panel.beginSheetModal(for: windowForSheet!) { | |
111 | + guard $0 != NSModalResponseCancel else { return } | |
112 | + | |
113 | + if FileManager().fileExists(atPath: panel.url!.path) { | |
114 | + guard let _ = try? FileManager().removeItem(at: panel.url!) else { | |
115 | + Swift.print("Fail to remove item.") | |
116 | + return | |
117 | + } | |
118 | + } | |
119 | + guard let _ = try? FileManager().copyItem(at: target.url, to: panel.url!) else { | |
120 | + Swift.print("Fail to copy item") | |
121 | + return | |
122 | + } | |
123 | + } | |
124 | + } | |
125 | + | |
126 | + @IBAction func copy(_ sender: AnyObject) { | |
127 | + guard let target = actionTarget() else { return } | |
128 | + let pasteboard = NSPasteboard.general() | |
129 | + pasteboard.clearContents() | |
130 | + pasteboard.writeObjects([target.image]) | |
131 | + } | |
132 | +} |
@@ -15,5 +15,5 @@ | ||
15 | 15 | |
16 | 16 | @property (readonly) NSString *name; |
17 | 17 | @property (readonly) NSString *typeName; |
18 | - | |
18 | +@property (readonly) NSURL *URL; | |
19 | 19 | @end |
@@ -19,4 +19,8 @@ | ||
19 | 19 | |
20 | 20 | return filename; |
21 | 21 | } |
22 | +- (NSURL *)URL | |
23 | +{ | |
24 | + return [NSURL fileURLWithPath:self.filepath]; | |
25 | +} | |
22 | 26 | @end |
@@ -22,7 +22,7 @@ | ||
22 | 22 | <key>CFBundleTypeRole</key> |
23 | 23 | <string>Viewer</string> |
24 | 24 | <key>NSDocumentClass</key> |
25 | - <string>HMSwfDocument</string> | |
25 | + <string>$(PRODUCT_MODULE_NAME).HMSwfDocument</string> | |
26 | 26 | </dict> |
27 | 27 | </array> |
28 | 28 | <key>CFBundleExecutable</key> |
@@ -0,0 +1,6 @@ | ||
1 | +// | |
2 | +// Use this file to import your target's public headers that you would like to expose to Swift. | |
3 | +// | |
4 | + | |
5 | +#import "HMSwfImage.h" | |
6 | +#import "HMTemporaryDirectory.h" |
@@ -1,14 +0,0 @@ | ||
1 | -// | |
2 | -// NSString-extensions.h | |
3 | -// KoreNoKaraSu | |
4 | -// | |
5 | -// Created by Hori,Masaki on 2016/09/28. | |
6 | -// Copyright © 2016年 Hori,Masaki. All rights reserved. | |
7 | -// | |
8 | - | |
9 | -#import <Foundation/Foundation.h> | |
10 | - | |
11 | -@interface NSString (HMNSStringExtensions) | |
12 | -- (NSComparisonResult)numericCompare:(NSString *)string; | |
13 | - | |
14 | -@end |
@@ -1,16 +0,0 @@ | ||
1 | -// | |
2 | -// NSString-extensions.m | |
3 | -// KoreNoKaraSu | |
4 | -// | |
5 | -// Created by Hori,Masaki on 2016/09/28. | |
6 | -// Copyright © 2016年 Hori,Masaki. All rights reserved. | |
7 | -// | |
8 | - | |
9 | -#import "NSString-extensions.h" | |
10 | - | |
11 | -@implementation NSString (HMNSStringExtensions) | |
12 | -- (NSComparisonResult)numericCompare:(NSString *)string | |
13 | -{ | |
14 | - return [self compare:string options:NSNumericSearch]; | |
15 | -} | |
16 | -@end |