-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiniSort.js
113 lines (101 loc) · 2.42 KB
/
iniSort.js
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
/* Sort the text in translated .ini file into its original order.
Author: maboroshin
Version: 0.4 (20200415) : incomplete
License: MIT
*/
// At first, You set below, and these file with UTF-16LE
var SourceFile = "Default.lng";
var CompareFile = "Japanese.lng";
/* incomplete
var lenArg = WScript.Arguments.length;
if (lenArg == 2)
drugAndDrop();
*/
var a = textToArray(SourceFile);
var b = textToArray(CompareFile);
//debug(a[5]);
//debug(b[5]);
var c = [];
var sEq = "=";
for (var i in a) {
var isSameAll = false;
var isSameName = false;
var currentSection = "";
var includeEq = (a[i].indexOf(sEq) != -1);
if (includeEq === false) {
if (a[i] === "") { // brank
c.push(a[i]);
continue;
}
else
for (var j in b)
if (a[i] == b[j]) {
isSameAll = true;
break;
}
}
else
for (var j in b) {
var tIndexName = a[i].split(sEq)[0];
if (tIndexName == b[j].split(sEq)[0]) {
isSameName = true;
break;
}
}
var sAt0 = a[i].charAt(0);
if (sAt0 == "[" && /\]$/.test(a[i]) ) { // find Section
if (isSameAll) {
c.push( b.splice(j, 1) );
}
else {
c.push(a[i]);
}
currentSection = a[i];
} else if (sAt0 == ";" ||
sAt0 == "#" ) { // find Comment
if (isSameAll)
c.push( b.splice(j, 1) );
else {
c.push(a[i]);
c.push( b.splice(j, 1) );
}
} else if (includeEq) {
if (isSameName)
c.push( b.splice(j, 1) );
else
c.push(tIndexName + sEq);
} else { // exception
debug(a[i]);
}
}
saveFile("Output.txt", c.join("\r\n"));
function debug(s) {
WScript.echo(s);
WScript.quit();
}
function textToArray(file) {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var ioMode = 1; // 1:read 2:write 8:append
var isCreate = false;
var isUnicode = -1; // 0:ascii -1:unicode
var a = [];
with (fso.OpenTextFile(file, ioMode, isCreate, isUnicode)) {
while (!AtEndOfStream)
a.push(ReadLine());
Close();
}
return a;
}
function saveFile(file, s) {
var fso = new ActiveXObject("Scripting.FileSystemObject");
with (fso.CreateTextFile(file, true, -1))
write(s), Close();
}
function drugAndDrop() { // incomplete
var fso = new ActiveXObject("Scripting.FileSystemObject");
var objArgs = WScript.Arguments;
for (var i = 0; i < objArgs.length; i++) {
var file = objArgs(i);
debug(fso.GetAbsolutePathName(file));
}
}