swfから画像を抽出するコマンドラインアプリケーション
Revision | 011485a879d08e456fdaa26dc2aada2a9269fa3f (tree) |
---|---|
Time | 2018-05-23 00:43:36 |
Author | masakih <masakih@user...> |
Commiter | masakih |
f オプションを追加
f, force オプションを設定すると出力ファイルが存在しても上書きする。設定されていなければ、何もしない。
@@ -39,6 +39,13 @@ | ||
39 | 39 | path = [self.information.outputDir stringByAppendingPathComponent:path]; |
40 | 40 | NSURL *url = [NSURL fileURLWithPath:path]; |
41 | 41 | |
42 | + if( !self.information.forceOverWrite && [url checkResourceIsReachableAndReturnError:nil] ) { | |
43 | + | |
44 | + fprintf(stderr, "%s is already exist.\n", url.path.UTF8String); | |
45 | + | |
46 | + return; | |
47 | + } | |
48 | + | |
42 | 49 | [decoder.decodedData writeToURL:url atomically:YES]; |
43 | 50 | } |
44 | 51 |
@@ -16,6 +16,7 @@ | ||
16 | 16 | @property (copy) NSString *outputDir; |
17 | 17 | @property (copy) NSString *filename; |
18 | 18 | @property (copy) NSArray *charctorIds; |
19 | +@property BOOL forceOverWrite; | |
19 | 20 | |
20 | 21 | - (BOOL)skipCharactorID:(UInt16) chractorid; |
21 | 22 |
@@ -33,6 +33,8 @@ static void usage(int exitVal, FILE *fp) { | ||
33 | 33 | fprintf(fp, "\textracted images output to output-directory.\n"); |
34 | 34 | fprintf(fp, " -v, --version\n"); |
35 | 35 | fprintf(fp, "\toutput version information and exit.\n"); |
36 | + fprintf(fp, " -f, --force\n"); | |
37 | + fprintf(fp, "\tif set, force orver write outputfile.\n"); | |
36 | 38 | fprintf(fp, " -h, --help\n"); |
37 | 39 | fprintf(fp, "\tdisplay this help and text.\n"); |
38 | 40 |
@@ -48,6 +50,7 @@ int main(int argc, char * const *argv) { | ||
48 | 50 | |
49 | 51 | NSString *outputDir = nil; |
50 | 52 | NSArray *charactorIds = nil; |
53 | + BOOL forceOverwrite = NO; | |
51 | 54 | |
52 | 55 | @autoreleasepool { |
53 | 56 | // 引数の処理 |
@@ -57,10 +60,11 @@ int main(int argc, char * const *argv) { | ||
57 | 60 | |
58 | 61 | toolName = toolNameStr(argv[0]); |
59 | 62 | |
60 | -#define SHORTOPTS "ho:vc:" | |
63 | +#define SHORTOPTS "fho:vc:" | |
61 | 64 | static struct option longopts[] = { |
62 | 65 | {"output", required_argument, NULL, 'o'}, |
63 | 66 | {"charactorid", required_argument, NULL, 'c'}, |
67 | + {"force", no_argument, NULL, 'f'}, | |
64 | 68 | {"version", no_argument, NULL, 'v'}, |
65 | 69 | {"help", no_argument, NULL, 'h'}, |
66 | 70 | {NULL, 0, NULL, 0} |
@@ -75,6 +79,9 @@ int main(int argc, char * const *argv) { | ||
75 | 79 | case 'c': |
76 | 80 | charactorid = optarg; |
77 | 81 | break; |
82 | + case 'f': | |
83 | + forceOverwrite = YES; | |
84 | + break; | |
78 | 85 | case 'h': |
79 | 86 | usage(EXIT_SUCCESS, stdout); |
80 | 87 | break; |
@@ -133,6 +140,7 @@ int main(int argc, char * const *argv) { | ||
133 | 140 | info.outputDir = outputDir; |
134 | 141 | info.charctorIds = charactorIds; |
135 | 142 | info.filename = [[NSString alloc] initWithUTF8String:filename]; |
143 | + info.forceOverWrite = forceOverwrite; | |
136 | 144 | |
137 | 145 | dispatch_group_async(group, queue, ^{ |
138 | 146 |