File size: 3,351 Bytes
4d3af08
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#NoTrayIcon
FileEncoding, UTF-8-RAW
#SingleInstance OFF

file_paths := ""
Loop, %0% {
	path := %A_Index%
	file_paths = %file_paths%%path%|
}
if (file_paths == "") {
	default_path := GetDefaultPath()
	FileSelectFile, paths, 7, %default_path%, Please select a .tex or .png file, Supported files(*.tex;*.png)
	if (ErrorLevel == 1) {
		ExitApp
	}
	StringSplit, $, paths, `n
	if (2 < $0) {
		Loop, Parse, paths, `n, `r
		{
			if (A_LoopField == "") {
				continue
			}
			if (A_Index == 1) {
				dir := A_LoopField
			}
			else {
				file_paths = %file_paths%%dir%\%A_LoopField%|
			}
		}
	}
	else {
		file_paths := paths
		file_paths := RTrim(file_paths, "`n`r")
	}
}
file_paths := RTrim(file_paths, "|")

Loop, Parse, file_paths, |
{
	file_path := A_LoopField
	file := FileOpen(file_path, "r")
	
	ext := file.ReadInt()
	if (ext == 1196314761) {
		tex_path := RegExReplace(file_path, "\.\w+$", ".tex")
		if (file_path == tex_path) {
			tex_path = %file_path%.tex
		}
		/*
		if (FileExist(tex_path) != "") {
			MsgBox, 4, , A tex file with the same name exists, Are you sure you want to overwrite it?
			IfMsgBox, No
			{
				ExitApp
			}
		}
		*/
		default_path = assets/texture/
		sub_path := RegExReplace(file_path, "\.\w+$", ".tex")
		if (file_path != sub_path) {
			if (FileExist(sub_path) != "") {
				sub_file := FileOpen(sub_path, "r")
				num := sub_file.ReadChar()
				ext := sub_file.Read(num)
				if (ext == "CM3D2_TEX") {
					sub_file.ReadInt()
					num := sub_file.ReadChar()
					default_path := sub_file.Read(num)
				}
			}
		}
		if (RegExMatch(file_path, "\\texture[^\\]*\\texture\\") != 0) {
			default_path := RegExReplace(file_path, "^.+(\\texture[^\\]*\\texture\\)", "$1")
			default_path = assets%default_path%
			StringReplace, default_path, default_path, \, /, All
		}
		SplitPath, file_path, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
		InputBox, path, , %OutFileName%Please specify the texture path, , 800, 130, , , , , %default_path%
		if (ErrorLevel != 0) {
			ExitApp
		}
		tex_file := FileOpen(tex_path, "w")
		tex_file.WriteChar(9)
		tex_file.Write("CM3D2_TEX")
		tex_file.WriteInt(1000)
		tex_file.WriteChar(StrLen(path))
		tex_file.Write(path)
		tex_file.WriteInt(file.Length)
		file.Seek(0)
		file.RawRead(png_data, file.Length)
		tex_file.RawWrite(png_data, file.Length)
		
		continue
	}
	
	file.Seek(0)
	num := file.ReadChar()
	ext := file.Read(num)
	if (ext == "CM3D2_TEX") {
		png_path := RegExReplace(file_path, "\.\w+$", ".png")
		if (file_path == png_path) {
			png_path = %file_path%.png
		}
		/*
		if (FileExist(png_path) != "") {
			MsgBox, 4, , The png file with the same name exists, Do you want to overwrite?
			IfMsgBox, No
			{
				ExitApp
			}
		}
		*/
		ver := file.ReadInt()
		num := file.ReadChar()
		path := file.Read(num)
		size := file.ReadInt()
		file.RawRead(png_data, size)
		png_file := FileOpen(png_path, "w")
		png_file.RawWrite(png_data, size)
		/*
		MsgBox, 4, , Are you sure you want to copy the path to the clipboard?`n(%path%)
		IfMsgBox, Yes
		{
			Clipboard := path
		}
		*/
		Clipboard := path
		
		continue
	}
	
	Msgbox, %file_path%`nUnkown Format
}
ExitApp

GetDefaultPath() {
	RegRead, path, HKEY_CURRENT_USER, Software\KISS\カスタムメイド3D2, InstallPath
	if (ErrorLevel == 0) {
		path = %path%GameData\
	}
	else {
		path := A_ScriptDir
	}
	return path
}