From 75999ecdfd9c44f3082e1fd91e0522a8f2e4f424 Mon Sep 17 00:00:00 2001 From: Prcuvu Date: Wed, 21 Feb 2018 20:19:51 +0800 Subject: [PATCH] fix(render.js): use ADO stream to handle UTF-8 encoding --- render.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/render.js b/render.js index 0a00ca6b8..732acec89 100644 --- a/render.js +++ b/render.js @@ -19,20 +19,23 @@ })(); // main -var fso = WScript.CreateObject("Scripting.FileSystemObject"); +var objStream = WScript.CreateObject("ADODB.Stream"); var shell = WScript.CreateObject("Wscript.Shell"); var env = shell.Environment("Process"); function Render(filename, params) { - var ForReading = 1; - var templateFile = fso.OpenTextFile(filename + '.template', ForReading); - var input = templateFile.ReadAll(); - templateFile.Close(); + objStream.Charset = "utf-8"; + objStream.Open(); + objStream.LoadFromFile(filename + '.template'); + var input = objStream.ReadText(); + objStream.Close(); var output = input.template(params); - var outputFile = fso.CreateTextFile(filename, true); - outputFile.Write(output); - outputFile.Close(); + objStream.Charset = "utf-8"; + objStream.Open(); + objStream.WriteText(output); + objStream.SaveToFile(filename, 2); + objStream.Close(); } if (WScript.Arguments.length == 0) {