mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-02-06 06:54:58 +00:00
fix
This commit is contained in:
parent
5f6489f6ac
commit
e902cc8625
|
@ -3,6 +3,7 @@
|
|||
/////////////////////////////////////////////////////////////////////////////////
|
||||
var SHELL = require("lib/shell");
|
||||
var SYS = require("lib/system");
|
||||
var FILE = require("lib/file");
|
||||
|
||||
var ChromeObject = function() {
|
||||
this.workingDirectory = SYS.getEnvString("PROGRAMFILES") + "\\Google\\:profileName\\Application";
|
||||
|
@ -36,6 +37,11 @@ var ChromeObject = function() {
|
|||
this.open = function(url) {
|
||||
this.setProfileName(this.profileName);
|
||||
|
||||
if (!FILE.fileExists(this.binPath)) {
|
||||
console.error("ChromeObject.open() -> '" + this.profileName + "' 존재하지 않는 프로파일입니다. 생성 후 사용해주세요.");
|
||||
return this;
|
||||
}
|
||||
|
||||
var process;
|
||||
while (this.processID == 0) {
|
||||
try {
|
||||
|
@ -68,6 +74,7 @@ var ChromeObject = function() {
|
|||
shell.release();
|
||||
} catch (e) {
|
||||
console.error("ChromeObject.open() -> " + e.message);
|
||||
sleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
84
lib/file.js
84
lib/file.js
|
@ -9,6 +9,68 @@
|
|||
|
||||
var LIB = require('lib/std');
|
||||
|
||||
var FileObject = function() {
|
||||
this.interfaces = null;
|
||||
this.interface = null;
|
||||
this.filename = null;
|
||||
this.charset = "utf-8";
|
||||
this.isExists = false;
|
||||
this.isFile = false;
|
||||
this.isDirectory = false;
|
||||
|
||||
this.setInterface = function(interfaceName) {
|
||||
this.interface = this.interfaces[interfaceName];
|
||||
return this;
|
||||
};
|
||||
|
||||
this.setCharset = function(charset) {
|
||||
this.charset = charset;
|
||||
return this;
|
||||
};
|
||||
|
||||
this.create = function() {
|
||||
this.interfaces = {
|
||||
fso: CreateObject("Scripting.FileSystemObject"),
|
||||
ado: CreateObject("ADODB.Stream")
|
||||
};
|
||||
this.setInterface("fso");
|
||||
return this;
|
||||
};
|
||||
|
||||
this.exists = function() {
|
||||
try {
|
||||
if (this.interface.FileExists(this.filename)) {
|
||||
this.isExists = true;
|
||||
this.isFile = true;
|
||||
} else if (this.interface.folderExists(this.filename)) {
|
||||
this.isExists = true;
|
||||
this.isDirectory = true;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("FileObject.exists() -> " + e.message);
|
||||
}
|
||||
return this.isExists;
|
||||
};
|
||||
|
||||
this.open = function(filename) {
|
||||
this.filename = filename;
|
||||
if (!this.exists()) {
|
||||
console.warn("FileObject.open() -> The file does not exists.");
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
this.create();
|
||||
};
|
||||
|
||||
exports.fileExists = function(FN) {
|
||||
return (new FileObject()).open(FN).exists();
|
||||
};
|
||||
|
||||
exports.folderExists = function(FN) {
|
||||
return (new FileObject()).open(FN).exists();
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// Private APIs / Utility functions
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -17,28 +79,6 @@ exports.VERSIONINFO = "File Lib (file.js) version 0.2";
|
|||
exports.global = global;
|
||||
exports.require = global.require;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// exports.fileExists
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
exports.fileExists = function(FN) {
|
||||
var FSO = CreateObject("Scripting.FileSystemObject");
|
||||
var exists = FSO.FileExists(FN);
|
||||
FSO = null;
|
||||
return exists;
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// exports.folderExists
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
exports.folderExists = function(FN) {
|
||||
var FSO = CreateObject("Scripting.FileSystemObject");
|
||||
var exists = FSO.FolderExists(FN);
|
||||
FSO = null;
|
||||
return exists;
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// exports.fileGet
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -11,28 +11,31 @@ exports.require = global.require;
|
|||
|
||||
exports.getList = function() {
|
||||
var data = [];
|
||||
var cmd = [
|
||||
SYS.getEnvString("SYSTEMDRIVE") + "/LDPlayer/LDPlayer3.0/ldconsole.exe",
|
||||
"list2"
|
||||
var commands = [
|
||||
[SYS.getEnvString("SYSTEMDRIVE") + "/LDPlayer/LDPlayer4.0/ldconsole.exe", "list2"],
|
||||
[SYS.getEnvString("SYSTEMDRIVE") + "/LDPlayer/LDPlayer3.0/ldconsole.exe", "list2"]
|
||||
];
|
||||
var result = SHELL.exec(cmd);
|
||||
var lines = result.split(/\r?\n/);
|
||||
|
||||
for (var i = 0; i < commands.length; i++) {
|
||||
var result = SHELL.exec(commands[i]);
|
||||
var lines = result.split(/\r?\n/);
|
||||
|
||||
for(var i = 0; i < lines.length; i++) {
|
||||
var row = lines[i].split(',');
|
||||
|
||||
if(row.length == 7) {
|
||||
data.push({
|
||||
index: row[0],
|
||||
title: row[1],
|
||||
topWindowHandle: row[2],
|
||||
binddWindowHandle: row[3],
|
||||
androidStarted: row[4],
|
||||
PID: parseInt(row[5]),
|
||||
PIDVBox: parseInt(row[6])
|
||||
});
|
||||
for(var k = 0; k < lines.length; k++) {
|
||||
var row = lines[k].split(',');
|
||||
|
||||
if(row.length == 7) {
|
||||
data.push({
|
||||
index: row[0],
|
||||
title: row[1],
|
||||
topWindowHandle: row[2],
|
||||
binddWindowHandle: row[3],
|
||||
androidStarted: row[4],
|
||||
PID: parseInt(row[5]),
|
||||
PIDVBox: parseInt(row[6])
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return data;
|
||||
};
|
||||
|
|
46
shadow.js
46
shadow.js
|
@ -41,9 +41,7 @@ for (var i = 0; i < items.length; i++) {
|
|||
if (name in Apps) {
|
||||
Apps[name][uniqueId] = ipAddress;
|
||||
}
|
||||
} catch(e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
// App 1. LDPlayer
|
||||
|
@ -59,7 +57,7 @@ var check_LDPlayer = function() {
|
|||
AppsMutex.push(pid);
|
||||
|
||||
if (title in Apps.LDPlayer) {
|
||||
var ss = SS.create.connect(Apps.LDPlayer[title]);
|
||||
var ss = SS.connect(Apps.LDPlayer[title]);
|
||||
ssPort = ss.listenPort;
|
||||
ssPID = ss.processID;
|
||||
} else {
|
||||
|
@ -104,7 +102,7 @@ var check_NoxPlayer = function() {
|
|||
AppsMutex.push(pid);
|
||||
|
||||
if (hostname in Apps.NoxPlayer) {
|
||||
var ss = SS.create.connect(Apps.NoxPlayer[hostname]);
|
||||
var ss = SS.connect(Apps.NoxPlayer[hostname]);
|
||||
ssPort = ss.listenPort;
|
||||
ssPID = ss.processID;
|
||||
} else {
|
||||
|
@ -141,38 +139,37 @@ var check_Chrome = function() {
|
|||
for (var uniqueId in Apps.Chrome) {
|
||||
if (AppsMutex.indexOf("chrome_" + uniqueId) < 0) {
|
||||
console.info("Starting Google Chrome: " + uniqueId);
|
||||
|
||||
|
||||
var ss = SS.connect(Apps.Chrome[uniqueId]);
|
||||
ssPort = ss.listenPort;
|
||||
ssPID = ss.processID;
|
||||
|
||||
var chromePID = Chrome.start("https://www.showmyip.com/", ssPort, uniqueId);
|
||||
//AppsPID.push([ssPID, chromePID]);
|
||||
AppsPID.push([ssPID]);
|
||||
console.info("Wait 10 seconds...")
|
||||
sleep(10000);
|
||||
|
||||
AppsMutex.push("chrome_" + uniqueId);
|
||||
Chrome.start("https://whatismyipaddress.com/", ssPort, uniqueId);
|
||||
|
||||
AppsPID.push([ssPID]);
|
||||
AppsMutex.push("chrome_" + uniqueId);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Check dead processes
|
||||
var check_Exits = function() {
|
||||
var availablePIDs = [];
|
||||
var processes = SYS.getProcesses();
|
||||
|
||||
for (var i = 0; i < processes.length; i++) {
|
||||
availablePIDs.push(processes[i].ProcessID);
|
||||
}
|
||||
var alivePIDList = SYS.getProcessList().reduce(function(acc, process) {
|
||||
acc.push(process.ProcessID);
|
||||
}, []);
|
||||
|
||||
AppsPID.forEach(function(v1) {
|
||||
v1.forEach(function(v2) {
|
||||
if (availablePIDs.indexOf(v2) < 0) {
|
||||
//console.warn("Detected dead process: " + v2);
|
||||
//console.warn("Will be kill related processes.");
|
||||
if (alivePIDList.indexOf(v2) < 0) {
|
||||
console.warn("Detected dead process: " + v2);
|
||||
console.warn("Will be kill related processes.");
|
||||
|
||||
//v1.forEach(function(v2) {
|
||||
// SYS.killProcess(v2);
|
||||
//});
|
||||
v1.forEach(function(v2) {
|
||||
SYS.killProcess(v2);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -191,10 +188,7 @@ var main = function() {
|
|||
check_NoxPlayer();
|
||||
|
||||
sleep(3000);
|
||||
check_Chrome();
|
||||
|
||||
sleep(3000);
|
||||
check_Exits();
|
||||
check_Chrome();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user