• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

IllustratorPackageのWindows版をPerlで作成中


Commit MetaInfo

Revision0efddb0421cd7faffd8da8281821f8e52cf5bcda (tree)
Zeit2012-10-21 18:16:31
Autormacneko_ayu <macneko.ayu@gmai...>
Commitermacneko_ayu

Log Message

Version 1.0 released.

Ändern Zusammenfassung

Diff

--- a/.project
+++ b/.project
@@ -1,6 +1,6 @@
11 <?xml version="1.0" encoding="UTF-8"?>
22 <projectDescription>
3- <name>practice</name>
3+ <name>IllustratorPackage_for_Windows</name>
44 <comment></comment>
55 <projects>
66 </projects>
--- a/IllustratorPackage_perl.pl
+++ b/IllustratorPackage_perl.pl
@@ -13,16 +13,17 @@ fileparse_set_fstype('MSWin32');
1313 #ファイルを引数で受け取り繰り返し処理させるメインルーチン
1414 sub main {
1515 foreach my $file (@_) {
16- my $errcount = 0; #カウントのための変数を初期化
1716 my @linkfilepath = (); #収集するファイルのパスを入れる配列
17+# my @errorlog = ();
18+
1819 push(@linkfilepath, $file);
1920 @linkfilepath = &openfile($file,\@linkfilepath);
20- $errcount = &copy_linkfile(\@linkfilepath,$errcount);
21+ my $result = &copy_linkfile(@linkfilepath);
2122
22- if ($errcount == 0){
23- print "Successful!\n";
23+ if ($result == 0){
24+ print "$file successful!!!\n";
2425 } else {
25- print "Done! but can't collected files : $errcount files\n";
26+ print "$file error!!! Look collected directory. This programs maked error log.\n";
2627 }
2728 }
2829 }
@@ -49,39 +50,73 @@ sub openfile {
4950 }
5051
5152 sub copy_linkfile {
52- my ($linkfilepath,$errcount) = @_;
53- if ($#$linkfilepath > -1) { #配列が空じゃなかったら
53+ my @linkfilepath = @_;
54+ my $errorlog = "";
55+# my $errcount = 0; #カウントのための変数を初期化
56+ my @errorfile_array = (); #エラーファイル名を入れる配列を準備
57+
58+ if ($#linkfilepath > -1) { #配列が空じゃなかったら
5459 my $newdir = &mkdir_localtime();
5560 my $newdir_CP932 = &encode_CP932($newdir); #encodeした変数を準備
61+ print $newdir_CP932."\n";
5662
57- foreach my $item (@$linkfilepath){
63+ foreach my $item (@linkfilepath){
5864 my $item_CP932 = &encode_CP932($item); #encodeした変数を準備
5965
6066 if (-f $item_CP932){ #encode_CP932した結果ファイルが存在していたら(-fでファイルの存在確認)
6167 unless (copy($item_CP932, $newdir_CP932)){ #copyに失敗したら
62- print "Can't copy from \"$item_CP932\" to \"".$newdir_CP932."\": $!\n";
68+# print "Can't copy from \"$item_CP932\" to \"".$newdir_CP932."\": $!\n";
69+ push(@errorfile_array,basename($item)); #エラーファイル名を配列に
70+# $errcount ++;
6371 }
6472 } elsif (-f $item){ #encode_CP932しないでファイルが存在していたら
6573 unless (copy($item, $newdir_CP932)){ #copyに失敗したら
66- print "Can't copy from \"$item\" to \"".$newdir_CP932."\": $!\n";
74+# print "Can't copy from \"$item\" to \"".$newdir_CP932."\": $!\n";
75+ push(@errorfile_array,basename($item));
76+# $errcount ++;
6777 }
6878
6979 } else { #ファイルが存在しなかったらIlustratorファイル直下から探す
70- my $filedir = dirname($$linkfilepath[0]); #Illustratorファイルの親ディレクトリ取得
80+ my $filedir = dirname($linkfilepath[0]); #Illustratorファイルの親ディレクトリ取得
7181 my $linkpath = basename($item); #配置ファイルの名前を取得
7282 my $linkfile = File::Spec->catfile($filedir,$linkpath); #結合してファイルパスにする
7383 $linkfile = &decode_utf8($linkfile); #内部文字列(utf8)にdecodeする
7484 my $linkfile_CP932 = &encode_CP932($linkfile);
7585 unless (copy($linkfile_CP932, $newdir_CP932)){
76- #print "Can't copy from \"$linkfile_CP932\" to \"$newdir_CP932\"";
77- print "Can't copy from \"$linkfile_CP932\" to \"".$newdir_CP932."\": $!\n";
78- $errcount ++;
86+# print "Can't copy from \"$linkfile_CP932\" to \"".$newdir_CP932."\": $!\n";
87+ push(@errorfile_array,basename($item));
88+# $errcount ++;
7989 }
8090 }
8191 }
92+
93+ #エラーログの書き出し処理
94+ if ($#errorfile_array > -1) {
95+ my $documentname = basename($linkfilepath[0]); #ドキュメント名を取得
96+ my $errorfile = join("\n",@errorfile_array); #ファイル名を改行で結合
97+ $errorfile = &decode_utf8($errorfile); #内部文字列にデコード
98+ $errorfile = &encode_CP932($errorfile); #外部文字列にエンコード
99+ $errorlog = $documentname.&encode_CP932("を処理中にエラーが発生しました。下記ファイルが収集されていない可能性があります。\n\n").$errorfile;
100+
101+ mkdir $newdir_CP932."/log"; #収集したディレクトリの中にlogディレクトリ作成
102+ my $logdir = $newdir_CP932."/log"; #上記を変数でも持っておく
103+ my $errorlogpath = File::Spec->catfile($logdir,'log.txt'); #上記をもとにファイルパスを作成
104+
105+ #エラーログ用のファイルを書き込みモードで開く
106+ open my $fh, ">", $errorlogpath
107+ or die "can't maked $errorlogpath: $!";
108+
109+ print $fh $errorlog; #書き込む
110+ close $fh;
111+ return 1;
112+ } else {
113+ return 0;
114+ }
82115 }
83116 }
84117
118+
119+
85120 #CP932でencode
86121 sub encode_CP932 {
87122 my $target = $_[0];
@@ -108,7 +143,27 @@ sub mkdir_localtime {
108143 my ($sec, $min, $hour, $mday, $mon, $year, $wday) = localtime();
109144 $year += 1900;
110145 $mon += 1;
146+ if (length($sec) == 1) {$sec = '0'.$sec}; #1桁は0を頭につける
147+ if (length($min) == 1) {$min = '0'.$min};
148+ if (length($hour) == 1) {$hour = '0'.$hour};
149+ if (length($mday) == 1) {$mday = '0'.$mday};
150+ if (length($mon) == 1) {$mon = '0'.$mon};
111151 my $time = "$year-$mon-$mday $hour-$min-$sec";
152+
153+ if (-d $ENV{USERPROFILE}.&encode_CP932('/デスクトップ/').$time) { #同名フォルダが存在したら
154+ sleep 1;
155+ my ($sec, $min, $hour, $mday, $mon, $year, $wday) = localtime();
156+ $year += 1900;
157+ $mon += 1;
158+ if (length($sec) == 1) {$sec = '0'.$sec}; #1桁は0を頭につける
159+ if (length($min) == 1) {$min = '0'.$min};
160+ if (length($hour) == 1) {$hour = '0'.$hour};
161+ if (length($mday) == 1) {$mday = '0'.$mday};
162+ if (length($mon) == 1) {$mon = '0'.$mon};
163+ $time = "$year-$mon-$mday $hour-$min-$sec";
164+ mkdir $ENV{USERPROFILE}.&encode_CP932('/デスクトップ/').$time;
165+ return $ENV{USERPROFILE}.'/デスクトップ/'.$time; #戻り値はエンコードしない
166+ }
112167 mkdir $ENV{USERPROFILE}.&encode_CP932('/デスクトップ/').$time;
113168 return $ENV{USERPROFILE}.'/デスクトップ/'.$time; #戻り値はエンコードしない
114169 }
--- a/README.txt
+++ b/README.txt
@@ -15,16 +15,18 @@ Illustratorファイル内のXMPタグを正規表現で検索し配置画像の
1515 2.perl IllustratorPackage_perl.plのパス Illustratorファイルのパス
1616  と入力。
1717  ファイルをコマンドプロンプトにドラッグ&ドロップすればそのファイルへのフルパスが自動的に記入されます。
18+ 複数ファイルの処理を行う場合は複数ファイルをドロップしてください。
1819 3.enterを押す。
1920 4.デスクトップにPerl起動時の日時を名前としたディレクトリが作成されてその中にファイルが収集されます。
20- 「Successful!」と表示されれば全ファイル収集済み。
21- 「Done! but can't collected files : xx files」と表示されればxxファイル分収集できなかったという意味です。
22- 後者の場合「"Can't copy from "コピー元のフルパス" to "コピー先のディレクトリ"」というエラーも表示されるので、必ず確認してください。
21+ 「(Illustratorのドキュメント名)successful!!!」と表示された場合は全ファイル収集済み。
22+ 「(Illustratorのドキュメント名) error!!! Look collected directory. This programs maked error log.」と表示された場合は収集できなかったファイルがあります。
23+ 後者の場合デスクトップに作成されたディレクトリの中の「log」ディレクトリの中に「log.txt」が作成されます。
24+ 「log.txt」には収集できなかったファイル名が記載されていますので、確認してください。
2325
2426 <今後の予定>
2527 ●サブルーチン化 ← 2012.10.16完了
2628 ●複数のIllustratorファイルに対応 ← 2012.10.16完了
27-●エラーログをUTF-8形式のファイルで収集先のディレクトリ内に作成
29+●エラーログをUTF-8形式のファイルで収集先のディレクトリ内に作成 ← 2012.10.21完了
2830 ●すべて一つのフォルダ内に収集できる仕様も加える
2931
3032 <謝罪>