제가 가진 지식을 나눠드리면 좋을 것 같아 quickbms를 활용한 데이터 분석 강좌를 꾸준히 작성했었지만, 기초편 넘어가니 읽어주시는 분들이 없더군요. 그리고 스크립트 툴 제작 강좌 자체가 없기 때문에 큰 도움될거라 믿고 야심차게 준비했으나.. 한글화 패치 인력이 모인 한식구 카페에서도 읽는 분들이 잘 없는 것 같습니다. ㅠㅠ
뭐, 아무튼 누군가에게는 도움이 되길 바랍니다. 궁금한 점이 있으면 질문주세요.
소스 코드와 예제 첨부 파일 http://blog.naver.com/physics1114/220958590835
바이너리 파일에서 CSV로 추출, 그리고 다시 원본으로 되돌리는 과정입니다.
<추출> - 기초편과 비슷한 구조입니다만, 하나의 파일에 여러가지 언어 정보를 담고 있습니다. 하여 임의로 array가 되도록 작성했습니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
#include <MsgBoxConstants.au3> $Path = FileOpenDialog("Select the -25 file", @ScriptDir, "dat files (*.-25)",1) If @error = 1 Then Exit $File = fileopen($Path,16) $Name = CompGetFileName($Path) FileSetPos($File,"0xF0",0) $Files = _BinaryToInt32(FileRead($File, 4)) Dim $Text $Text &= "분류" & @TAB & "영어"& @TAB & "스페인어"& @TAB & "카탈로니아어" & @TAB &"프랑스어" & @TAB & "이탈리아어" & @TAB & "독일어" & @TAB &"일본어" & @TAB & "폴란드어" & @TAB & "헝가리어" & @TAB & "러시아어" & @TAB & "중국어" & @CRLF Dim $Str For $i = 1 to $Files $Title_pos = FileGetPos($file) $Title_len = _BinaryToInt32(FileRead($File, 4)) $Str = BinaryToString(FileRead($File,$Title_len),4) $Text &= $Str & @TAB $jump = $Title_len - 4*int($Title_len / 4) ;ex) if $Title_len= 0x13 = 19=> 19 - 4*(19/4) = 19 - 4*4 = 3 If $jump <> 0 Then $jump = 4 - $jump ; 4 - 3 = 1만큼 $Title_pos에서 jump 해야 다음 스트링 len 시작지점 $offset = $Title_pos + 4 + $Title_len + $jump Filesetpos($file,$offset,0) EndIf $null = FileRead($File, 4) $category_pos = FileGetPos($file) $category_len = _BinaryToInt32(FileRead($File, 4)) If $category_len = 0 Then $languages = FileRead($File, 4) ; 0x0B000000 Else ;MsgBox(0,"Title",$category_len) $category = BinaryToString(FileRead($File,$category_len),4) $jump = $category_len - 4*int($category_len / 4) ;ex) if $Title_len= 0x13 = 19=> 19 - 4*(19/4) = 19 - 4*4 = 3 If $jump <> 0 Then $jump = 4 - $jump ; 4 - 3 = 1만큼 $Title_pos에서 jump 해야 다음 스트링 len 시작지점 $offset = $category_pos + 4 + $category_len + $jump Filesetpos($file,$offset,0) EndIf $languages = FileRead($File, 4) ; 0x0B000000 EndIf For $j = 1 to $languages $pos = FileGetPos($File) $len = _BinaryToInt32(FileRead($File, 4)) $Str = BinaryToString(FileRead($File,$len),4) $Str = StringRegExpReplace($Str,@CRLF,"<cf>") $Str = StringRegExpReplace($Str,@LF,"<lf>") $Str = StringRegExpReplace($Str,@CR,"<cr>") If $j = 11 Then $Text &= $Str & @CRLF Else $Text &= $Str & @TAB EndIf $jump_2 = $len - 4*int($len / 4) ;ex) if $Title_len= 0x13 = 19=> 19 - 4*(19/4) = 19 - 4*4 = 3 If $jump_2 <> 0 Then $jump_2 = 4 - $jump_2 ; 4 - 3 = 1만큼 $Title_pos에서 jump 해야 다음 스트링 len 시작지점 $offset_2 = $pos + 4 + $len + $jump_2 Filesetpos($file,$offset_2,0) EndIf Next $pos_tail_block = FileGetPos($File) $tail_block = FileRead($File, "0x40") ;MsgBox(0,"Title",$pos_tail_block) Next ;;;Lang category infor $Tail_pos = FileGetPos($file) $Tail = FileRead($File, "0xB8") ;;; $hFile = FileOpen ($Name&".csv", 2+256) FileWrite($hFile, $Text) FileClose($hFile) TrayTip("Exporter", "Finish!", 3) sleep(3000) Func CompGetFileName($Path) If StringLen($Path) < 4 Then Return -1 $ret = StringSplit($Path,"\",2) If IsArray($ret) Then Return $ret[UBound($ret)-1] EndIf If @error Then Return -1 EndFunc Func _BinaryToInt32($Binary) Return BitAND(Int(Binary($Binary)), 0xFFFFFFFF) EndFunc |
이렇게 하여 추출 후, csv 파일을 구글 시트에 업로드합니다.
필요없는 C~G열은 '열 숨기기'로 숨기고, 번역을 진행 한 후 폰트까지 만들어줍니다.
<도입> _DelimFile_To_Array2D 함수는 템플릿이니 array 배열 사용할 때 그대로 차용하면 됩니다.
아라가미의 경우 Array 배열이 11이 되도록 추출했으니 $Array = 11로 지정했습니다.
$NEWdata에서 템플릿 함수를 불러오도록 만들고.. 나머지 과정은 제가 만든 소스 코드를 읽어보시면 됩니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
#include <ArrayNaturalSort.au3> #include <File.au3> #include <Binary.au3> Dim $NEWdata, $Num = 2 $Array = 11 $Debug = false $TxtPath = FileOpenDialog("txt 파일을 선택하세요", @ScriptDir, "txt files (*.csv)",1) If @error = 1 Then Exit $NEWdata = _DelimFile_To_Array2D($TxtPath, @TAB, $Array + 1) ; 2 = colums, key + lang1 if $Debug Then _ArrayDisplay($NEWdata) $Name = StringTrimRight(CompGetFileName($TxtPath),4) $File = FileOpen($Name, 0+16) If $File = -1 Then MsgBox(0,"오류!",$Name & "파일을 열 수 없습니다.") Exit EndIf FileSetPos($File,"0xF0",0) $Files = _BinaryToInt32(FileRead($File, 4)) FileSetPos($File,0,0) Dim $New_Block Dim $Newtext Dim $tail_block Dim $Newfile $New_Header = FileRead($File, "0xF4") $Newfile &= $New_Header For $i = 1 to $Files $Title_pos = FileGetPos($file) $Title_len = _BinaryToInt32(FileRead($File, 4)) $jump = $Title_len - 4*int($Title_len / 4) If $jump = 0 Then $size = 4 + $Title_len Else $jump = 4 - $jump $size = 4 + $Title_len + $jump EndIf Filesetpos($file,$Title_pos,0) $Title = FileRead($File, $size) $New_Block &= $Title $null = FileRead($File, 4) $New_Block &= $null $category_pos = FileGetPos($file) $category_len = _BinaryToInt32(FileRead($File, 4)) If $category_len = 0 Then $New_Block &= "0x00000000" $languages = FileRead($File, 4) ; 0x0B000000 $New_Block &= $languages Else $category_jump = $category_len - 4*int($category_len / 4) If $category_jump = 0 Then $category_size = 4 + $category_len Else $category_jump = 4 - $category_jump $category_size = 4 + $category_len + $category_jump EndIf Filesetpos($file,$category_pos,0) $category = FileRead($File, $category_size) $New_Block &= $category $languages = FileRead($File, 4) ; 0x0B000000 $New_Block &= $languages EndIf ;read text For $x = 1 to $Array $ValueText = $NEWdata[$Num][$x] $ValueText = StringRegExpReplace($ValueText,"<cf>",@CRLF) $ValueText = StringRegExpReplace($ValueText,"<lf>",@LF) $ValueText = StringRegExpReplace($ValueText,"<cr>",@CR) $bNewText = StringToBinary($ValueText,4) $Newlen_for_cal = BinaryLen($bNewText) $Newlen = _binaryFromint32($Newlen_for_cal) $Newtext &= $Newlen $Newtext &= $bNewText $add_null_for_cal = $Newlen_for_cal - 4*int($Newlen_for_cal / 4) If $add_null_for_cal <> 0 Then $add_null_for_cal = 4 - $add_null_for_cal For $k = 1 to $add_null_for_cal $Newtext &= "0x00" Next EndIf Next $Num += 1 $New_Block &= $Newtext $Newtext = "0x" & StringRegExpReplace($Newtext,"0x","") ;read $file in order to bypass language data and get block_tail. For $w = 1 to 11 $pos = FileGetPos($File) $len = _BinaryToInt32(FileRead($File, 4)) $jump = $len - 4*int($len / 4) If $jump <> 0 Then $jump = 4 - $jump $offset = $pos + $len + 4 + $jump Else $offset = $pos + $len + 4 EndIf FileSetPos($file,$offset,0) Next $pos_tail_block = FileGetPos($File) $tail_block = FileRead($File, "0x40") $New_Block &= $tail_block $New_Block = "0x" & StringRegExpReplace($New_Block,"0x","") $Newfile &= $New_Block $New_Block = "" $Newtext = "" Next ;Lang category infor $Tail_pos = FileGetPos($file) $Tail = FileRead($File, "0xFC") $Newfile &= $Tail $Newfile = "0x" & StringRegExpReplace($Newfile,"0x","") $hNewfile = FileOpen ("NEW_"&$Name, 2+16) FileWrite ($hNewfile, $Newfile) FileClose ($hNewfile) TrayTip ("추출", "성공!", 3) sleep (3000) Func CompGetFileName($Path) If StringLen($Path) < 4 Then Return -1 $ret = StringSplit($Path,"\",2) If IsArray($ret) Then Return $ret[UBound($ret)-1] EndIf If @error Then Return -1 EndFunc Func _DelimFile_To_Array2D($s_file, $s_delim = @TAB, $i_max_2d = 0) Local $s_str = $s_file If FileExists($s_str) Then $s_str = FileRead($s_file) Local $i_enum_max = False If Int($i_max_2d) < 1 Then $i_enum_max = True $i_max_2d = 1 EndIf Local $a_split = StringSplit(StringStripCR($s_str), @LF) Local $a_ret[$a_split[0] + 1][$i_max_2d] = [[$a_split[0]]], $a_delim For $i = 1 To $a_split[0] $a_delim = StringSplit($a_split[$i], $s_delim, 1) If $i_enum_max And $i_max_2d < $a_delim[0] Then ReDim $a_ret[$a_split[0] + 1][$a_delim[0]] $i_max_2d = $a_delim[0] EndIf For $j = 1 To $a_delim[0] $a_ret[$i][$j - 1] = $a_delim[$j] Next Next Return $a_ret EndFunc |
이렇게 하여 리팩을 하면 번역문 길이에 제약받지 않는 한글 패치 제작이 가능해집니다.
여기까지 기본편이고, 기본 응용, 중급, 고급 과정은 따로 강좌를 더 작성할지는 잘 모르겠네요.
아무튼 한글화 도전하시는 분들께 도움이 되길 바랍니다.