From 55297e9d1b89f731142aaa81619470923d7b9b1f Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Wed, 5 Aug 2020 16:35:43 +0900 Subject: [PATCH] Update app.js, lib/system.js --- app.js | 10 ++++++---- lib/system.js | 24 ++++++++++++++++++------ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/app.js b/app.js index db27c0b..8c93795 100644 --- a/app.js +++ b/app.js @@ -95,15 +95,17 @@ function require(FN) { // get directory name var getDirName = function(path) { - var pos = path.lastIndexOf("\\"); - return path.substring(0, pos); + var delimiter = "\\"; + var pos = path.lastIndexOf(delimiter); + return (pos > -1 ? path.substring(0, pos) : ""); }; // get current script directory var getCurrentScriptDirectory = function() { if (typeof(WScript) !== "undefined") { - var path = WScript.ScriptFullName; - return getDirName(path); + return getDirName(WScript.ScriptFullName); + } else if (typeof(document) !== "undefined") { + return getDirName(document.location.pathname); } else { return "."; } diff --git a/lib/system.js b/lib/system.js index f300937..5c42902 100644 --- a/lib/system.js +++ b/lib/system.js @@ -99,21 +99,33 @@ exports.getCurrentWorkingDirectory = function() { } catch (e) {} }; -// "console only"; +exports.getDirName = function(path) { + var delimiter = "\\"; + var pos = path.lastIndexOf(delimiter); + return (pos > -1 ? path.substring(0, pos) : ""); +}; + +exports.getFileName = function(path) { + var delimiter = "\\"; + var pos = path.lastIndexOf(delimiter); + return (pos > -1 ? path.substring(pos + delimiter.length) : ""); +}; + exports.getCurrentScriptDirectory = function() { - if(typeof(WScript) !== "undefined") { - var path = WScript.ScriptFullName; - var pos = path.lastIndexOf("\\"); - return path.substring(0, pos); + if (typeof(WScript) !== "undefined") { + return exports.getDirName(WScript.ScriptFullName); + } else if (typeof(document) !== "undefined") { + return exports.getDirName(document.location.pathname); } else { return "."; } }; -// "console only"; exports.getCurrentScriptName = function() { if(typeof(WScript) !== "undefined") { return WScript.ScriptName; + } else if (typeof(document) !== "undefined") { + return exports.getFileName(document.location.pathname); } else { return ""; }