• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqtwindows誰得cocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

swfから画像を抽出するコマンドラインアプリケーション


Commit MetaInfo

Revisione1ce39baee7f3d05c99d3df42bd23d7ee5e555ac (tree)
Zeit2016-09-18 16:45:42
Autormasakih <masakih@user...>
Commitermasakih

Log Message

コマンドラインオプションを付けた

Ändern Zusammenfassung

Diff

--- a/KanColleGraphicDivider.xcodeproj/xcuserdata/masaki.xcuserdatad/xcschemes/KanColleGraphicDivider.xcscheme
+++ b/KanColleGraphicDivider.xcodeproj/xcuserdata/masaki.xcuserdatad/xcschemes/KanColleGraphicDivider.xcscheme
@@ -67,6 +67,14 @@
6767 argument = "2016HarunaKaiMizugi.swf"
6868 isEnabled = "YES">
6969 </CommandLineArgument>
70+ <CommandLineArgument
71+ argument = "-o asdf"
72+ isEnabled = "NO">
73+ </CommandLineArgument>
74+ <CommandLineArgument
75+ argument = "-h"
76+ isEnabled = "NO">
77+ </CommandLineArgument>
7078 </CommandLineArguments>
7179 <AdditionalOptions>
7280 </AdditionalOptions>
--- a/KanColleGraphicDivider/main.m
+++ b/KanColleGraphicDivider/main.m
@@ -10,9 +10,9 @@
1010 #include "SWFStructure.h"
1111 #import "HMZlibData.h"
1212
13+#include <getopt.h>
1314
14-
15-static NSString *sCurrentDir = nil;
15+static NSString *sOutputDir = nil;
1616 static NSString *sOriginalName = nil;
1717
1818 #if 0
@@ -37,9 +37,37 @@ void printHex(const unsigned char *p) {
3737 }
3838
3939
40+const char *toolName;
41+const char *versionString = "1.0";
42+
43+const char *toolNameStr(const char *argv0)
44+{
45+ return [[[NSString stringWithFormat:@"%s", argv0] lastPathComponent] fileSystemRepresentation];
46+}
47+
48+static void usage(int exitVal, FILE *fp)
49+{
50+ fprintf(fp, "Usage: %s [OPTIONS] input-swf-file\n", toolName);
51+
52+ fprintf(fp, "\n");
53+ fprintf(fp, " -o output-directory, --output=output-directory\n");
54+ fprintf(fp, "\textracted images output to output-directory.\n");
55+ fprintf(fp, " -v, --version\n");
56+ fprintf(fp, "\toutput version information and exit.\n");
57+ fprintf(fp, " -h, --help\n");
58+ fprintf(fp, "\tdisplay this help and text.\n");
59+
60+ exit(exitVal);
61+}
62+static void version()
63+{
64+ printf("KanColleGraphicDivider %s\n", versionString);
65+ exit(EXIT_SUCCESS);
66+}
67+
4068 void saveDataWithExtension(id data, NSString *extention, int tagCount) {
4169 NSString *path = [NSString stringWithFormat:@"%@-%d.%@", sOriginalName, tagCount, extention];
42- path = [sCurrentDir stringByAppendingPathComponent:path];
70+ path = [sOutputDir stringByAppendingPathComponent:path];
4371 NSURL *url = [NSURL fileURLWithPath:path];
4472 [data writeToURL:url atomically:YES];
4573 }
@@ -235,28 +263,71 @@ void storeBitsLossless2(const unsigned char *p, UInt32 length, int tagCount) {
235263 saveImageAsPNG(imageRef, tagCount);
236264 }
237265
238-int main(int argc, const char * argv[]) {
266+int main(int argc, char * const *argv) {
239267 @autoreleasepool {
240- NSProcessInfo *pInfo = [NSProcessInfo processInfo];
241- NSArray<NSString *> *args = pInfo.arguments;
242- if(args.count < 2) {
243- fprintf(stderr, "Few argument\n");
244- exit(-1);
268+
269+
270+ int opt;
271+ char *filename = NULL;
272+ char *oFilename = NULL;
273+
274+ toolName = toolNameStr(argv[0]);
275+
276+#define SHORTOPTS "ho:v"
277+ static struct option longopts[] = {
278+ {"output", required_argument, NULL, 'o'},
279+// {"tag", required_argument, NULL, 't'},
280+ {"version", no_argument, NULL, 'v'},
281+ {"help", no_argument, NULL, 'h'},
282+ {NULL, 0, NULL, 0}
283+ };
284+
285+
286+ while((opt = getopt_long(argc, argv, SHORTOPTS, longopts, NULL)) != -1) {
287+ switch(opt) {
288+ case 'o':
289+ oFilename = optarg;
290+ break;
291+ case 'h':
292+ usage(EXIT_SUCCESS, stdout);
293+ break;
294+ case 'v':
295+ version();
296+ break;
297+ default:
298+ usage(EXIT_FAILURE, stderr);
299+ break;
300+ }
301+ }
302+
303+ if(optind < argc) {
304+ filename = argv[optind];
245305 }
246306
247- NSFileManager *fm = [NSFileManager defaultManager];
248- sCurrentDir = fm.currentDirectoryPath;
307+ if(oFilename) {
308+ sOutputDir = [NSString stringWithFormat:@"%s", oFilename];
309+ NSFileManager *fm = [NSFileManager defaultManager];
310+ BOOL isDir = NO;
311+ if(![fm fileExistsAtPath:sOutputDir isDirectory:&isDir] || !isDir) {
312+ fprintf(stderr, "Output directory:%s is not found or not directory.", sOutputDir.fileSystemRepresentation);
313+ exit(EXIT_FAILURE);
314+ }
315+ } else {
316+ NSFileManager *fm = [NSFileManager defaultManager];
317+ sOutputDir = fm.currentDirectoryPath;
318+ }
249319
250- NSString *filePath = args[1];
320+ NSString *filePath = [NSString stringWithFormat:@"%s", filename];
251321 if(![filePath hasPrefix:@"/"]) {
252- filePath = [sCurrentDir stringByAppendingPathComponent:filePath];
322+ NSFileManager *fm = [NSFileManager defaultManager];
323+ filePath = [fm.currentDirectoryPath stringByAppendingPathComponent:filePath];
253324 }
254325
255326 NSURL *url = [NSURL fileURLWithPath:filePath];
256327 NSData *data = [NSData dataWithContentsOfURL:url];
257328 if(!data) {
258- fprintf(stderr, "Can not open %s.\n", args[1].UTF8String);
259- exit(-1);
329+ fprintf(stderr, "Can not open %s.\n", filename);
330+ exit(EXIT_FAILURE);
260331 }
261332
262333 sOriginalName = [filePath lastPathComponent];