Skip to content

Commit c19e797

Browse files
author
noodlefighter
committed
自己实现GenericUI.iniToString()、GenericUI.iniFileToFile(),因为原先的实现,读出的项均为string类型;而现在当作json串处理,导入后依旧为原来的类型。
1 parent f004b36 commit c19e797

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

src/main.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,34 @@ let textReplaceReader = function (str: string) {
10851085
//
10861086
// 写入配置
10871087
//
1088+
let iniToString = function (ini) {
1089+
var str = '';
1090+
for (var idx in ini) {
1091+
if (idx.charAt(0) == '_') { // private stuff
1092+
continue;
1093+
}
1094+
if (idx == 'typename') {
1095+
continue;
1096+
}
1097+
if (idx == "noUI") { // GenericUI property
1098+
continue;
1099+
}
1100+
var val = ini[idx];
1101+
1102+
if (val == undefined) {
1103+
continue;
1104+
}
1105+
1106+
if (val.constructor == String) {
1107+
str += (idx + ": \"" + val.toString() + "\"\n");
1108+
}
1109+
else if (val.constructor == Number || val.constructor == Boolean) {
1110+
str += (idx + ": " + val.toString() + "\n");
1111+
}
1112+
}
1113+
return str;
1114+
};
1115+
10881116
let writeIni = function (iniFile: string, ini: LabelPlusInputOptions) {
10891117
//$.level = 1; debugger;
10901118
if (!ini || !iniFile) {
@@ -1099,7 +1127,7 @@ let writeIni = function (iniFile: string, ini: LabelPlusInputOptions) {
10991127
if (file.open("w", "TEXT", "????")) {
11001128
file.lineFeed = "unix";
11011129
file.encoding = 'UTF-8';
1102-
let str = GenericUI.iniToString(ini);
1130+
let str = iniToString(ini);
11031131
file.write(str);
11041132
file.close();
11051133
}
@@ -1134,7 +1162,8 @@ let readIni = function (iniFile: string, ini ?: LabelPlusInputOptions): LabelPlu
11341162
file.lineFeed = "unix";
11351163
file.encoding = 'UTF-8';
11361164
let str = file.read();
1137-
ini = GenericUI.iniFileToFile(str);
1165+
str = str.replace(/\n/g, ',');
1166+
ini = (Function('return {' + str + '}'))(); // note: 不使用GenericUI.iniFileToFile是因为它的实现读出的项均为string类型
11381167
file.close();
11391168
}
11401169

0 commit comments

Comments
 (0)