swfから画像を抽出するコマンドラインアプリケーション
リビジョン | c6c66cb1da8c4760f0319a5da8a43111a88beefe (tree) |
---|---|
日時 | 2018-05-22 22:24:44 |
作者 | masakih <masakih@user...> |
コミッター | masakih |
Informationクラスが行うべき処理をInformationクラスに移動した
@@ -9,11 +9,14 @@ | ||
9 | 9 | #import <Foundation/Foundation.h> |
10 | 10 | |
11 | 11 | @interface Information: NSObject |
12 | -@property (copy) NSString *originalName; | |
12 | + | |
13 | +@property (readonly) NSURL *originalURL; | |
14 | +@property (copy, nonatomic, readonly) NSString *originalName; | |
15 | + | |
13 | 16 | @property (copy) NSString *outputDir; |
14 | 17 | @property (copy) NSString *filename; |
15 | 18 | @property (copy) NSArray *charctorIds; |
16 | 19 | |
17 | -- (bool)skipCharactorID:(UInt16) chractorid; | |
20 | +- (BOOL)skipCharactorID:(UInt16) chractorid; | |
18 | 21 | |
19 | 22 | @end |
@@ -8,8 +8,21 @@ | ||
8 | 8 | |
9 | 9 | #import "Information.h" |
10 | 10 | |
11 | + | |
12 | +@interface Information() | |
13 | + | |
14 | +@property (readwrite) NSURL *originalURL; | |
15 | + | |
16 | +@property (copy, nonatomic, readwrite) NSString *originalName; | |
17 | + | |
18 | +@end | |
19 | + | |
11 | 20 | @implementation Information |
12 | -- (bool)skipCharactorID:(UInt16) chractorid { | |
21 | + | |
22 | +@synthesize filename = _filename; | |
23 | + | |
24 | +- (BOOL)skipCharactorID:(UInt16) chractorid { | |
25 | + | |
13 | 26 | if(self.charctorIds.count == 0) return false; |
14 | 27 | |
15 | 28 | for(NSString *charID in self.charctorIds) { |
@@ -17,4 +30,26 @@ | ||
17 | 30 | } |
18 | 31 | return true; |
19 | 32 | } |
33 | + | |
34 | +- (void)setFilename:(NSString *)filename { | |
35 | + | |
36 | + _filename = [filename copy]; | |
37 | + | |
38 | + NSString *filePath = [filename copy]; | |
39 | + | |
40 | + if(![filePath hasPrefix:@"/"]) { | |
41 | + NSFileManager *fm = [NSFileManager defaultManager]; | |
42 | + filePath = [fm.currentDirectoryPath stringByAppendingPathComponent:filePath]; | |
43 | + } | |
44 | + | |
45 | + self.originalURL = [NSURL fileURLWithPath:filePath]; | |
46 | + | |
47 | + NSString *oName = [filename lastPathComponent]; | |
48 | + self.originalName = [oName stringByDeletingPathExtension]; | |
49 | +} | |
50 | + | |
51 | +- (NSString *)filename { | |
52 | + | |
53 | + return _filename; | |
54 | +} | |
20 | 55 | @end |
@@ -65,22 +65,13 @@ static void version() | ||
65 | 65 | } |
66 | 66 | |
67 | 67 | void extractImagesFromSWFFile(Information *info) { |
68 | - NSString *filePath = info.filename; | |
69 | - if(![filePath hasPrefix:@"/"]) { | |
70 | - NSFileManager *fm = [NSFileManager defaultManager]; | |
71 | - filePath = [fm.currentDirectoryPath stringByAppendingPathComponent:filePath]; | |
72 | - } | |
73 | 68 | |
74 | - NSURL *url = [NSURL fileURLWithPath:filePath]; | |
75 | - NSData *data = [NSData dataWithContentsOfURL:url]; | |
69 | + NSData *data = [NSData dataWithContentsOfURL:info.originalURL]; | |
76 | 70 | if(!data) { |
77 | 71 | fprintf(stderr, "Can not open %s.\n", info.filename.UTF8String); |
78 | 72 | return; |
79 | 73 | } |
80 | 74 | |
81 | - info.originalName = [filePath lastPathComponent]; | |
82 | - info.originalName = [info.originalName stringByDeletingPathExtension]; | |
83 | - | |
84 | 75 | SwfData *swf = [SwfData dataWithData:data]; |
85 | 76 | SwfContent *content = swf.firstContent; |
86 | 77 |