This commit is contained in:
Namhyeon Go 2020-11-18 17:46:26 +09:00
parent 5f6489f6ac
commit e902cc8625
4 changed files with 111 additions and 67 deletions

View File

@ -3,6 +3,7 @@
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
var SHELL = require("lib/shell"); var SHELL = require("lib/shell");
var SYS = require("lib/system"); var SYS = require("lib/system");
var FILE = require("lib/file");
var ChromeObject = function() { var ChromeObject = function() {
this.workingDirectory = SYS.getEnvString("PROGRAMFILES") + "\\Google\\:profileName\\Application"; this.workingDirectory = SYS.getEnvString("PROGRAMFILES") + "\\Google\\:profileName\\Application";
@ -36,6 +37,11 @@ var ChromeObject = function() {
this.open = function(url) { this.open = function(url) {
this.setProfileName(this.profileName); this.setProfileName(this.profileName);
if (!FILE.fileExists(this.binPath)) {
console.error("ChromeObject.open() -> '" + this.profileName + "' 존재하지 않는 프로파일입니다. 생성 후 사용해주세요.");
return this;
}
var process; var process;
while (this.processID == 0) { while (this.processID == 0) {
try { try {
@ -68,6 +74,7 @@ var ChromeObject = function() {
shell.release(); shell.release();
} catch (e) { } catch (e) {
console.error("ChromeObject.open() -> " + e.message); console.error("ChromeObject.open() -> " + e.message);
sleep(1000);
} }
} }

View File

@ -9,6 +9,68 @@
var LIB = require('lib/std'); 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 // Private APIs / Utility functions
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
@ -17,28 +79,6 @@ exports.VERSIONINFO = "File Lib (file.js) version 0.2";
exports.global = global; exports.global = global;
exports.require = global.require; 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 // exports.fileGet
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////

View File

@ -11,28 +11,31 @@ exports.require = global.require;
exports.getList = function() { exports.getList = function() {
var data = []; var data = [];
var cmd = [ var commands = [
SYS.getEnvString("SYSTEMDRIVE") + "/LDPlayer/LDPlayer3.0/ldconsole.exe", [SYS.getEnvString("SYSTEMDRIVE") + "/LDPlayer/LDPlayer4.0/ldconsole.exe", "list2"],
"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++) { for(var k = 0; k < lines.length; k++) {
var row = lines[i].split(','); var row = lines[k].split(',');
if(row.length == 7) { if(row.length == 7) {
data.push({ data.push({
index: row[0], index: row[0],
title: row[1], title: row[1],
topWindowHandle: row[2], topWindowHandle: row[2],
binddWindowHandle: row[3], binddWindowHandle: row[3],
androidStarted: row[4], androidStarted: row[4],
PID: parseInt(row[5]), PID: parseInt(row[5]),
PIDVBox: parseInt(row[6]) PIDVBox: parseInt(row[6])
}); });
}
} }
} }
return data; return data;
}; };

View File

@ -41,9 +41,7 @@ for (var i = 0; i < items.length; i++) {
if (name in Apps) { if (name in Apps) {
Apps[name][uniqueId] = ipAddress; Apps[name][uniqueId] = ipAddress;
} }
} catch(e) { } catch (e) {}
console.error(e.message);
}
} }
// App 1. LDPlayer // App 1. LDPlayer
@ -59,7 +57,7 @@ var check_LDPlayer = function() {
AppsMutex.push(pid); AppsMutex.push(pid);
if (title in Apps.LDPlayer) { if (title in Apps.LDPlayer) {
var ss = SS.create.connect(Apps.LDPlayer[title]); var ss = SS.connect(Apps.LDPlayer[title]);
ssPort = ss.listenPort; ssPort = ss.listenPort;
ssPID = ss.processID; ssPID = ss.processID;
} else { } else {
@ -104,7 +102,7 @@ var check_NoxPlayer = function() {
AppsMutex.push(pid); AppsMutex.push(pid);
if (hostname in Apps.NoxPlayer) { if (hostname in Apps.NoxPlayer) {
var ss = SS.create.connect(Apps.NoxPlayer[hostname]); var ss = SS.connect(Apps.NoxPlayer[hostname]);
ssPort = ss.listenPort; ssPort = ss.listenPort;
ssPID = ss.processID; ssPID = ss.processID;
} else { } else {
@ -141,38 +139,37 @@ var check_Chrome = function() {
for (var uniqueId in Apps.Chrome) { for (var uniqueId in Apps.Chrome) {
if (AppsMutex.indexOf("chrome_" + uniqueId) < 0) { if (AppsMutex.indexOf("chrome_" + uniqueId) < 0) {
console.info("Starting Google Chrome: " + uniqueId); console.info("Starting Google Chrome: " + uniqueId);
var ss = SS.connect(Apps.Chrome[uniqueId]); var ss = SS.connect(Apps.Chrome[uniqueId]);
ssPort = ss.listenPort; ssPort = ss.listenPort;
ssPID = ss.processID; ssPID = ss.processID;
var chromePID = Chrome.start("https://www.showmyip.com/", ssPort, uniqueId); console.info("Wait 10 seconds...")
//AppsPID.push([ssPID, chromePID]); sleep(10000);
AppsPID.push([ssPID]);
AppsMutex.push("chrome_" + uniqueId); Chrome.start("https://whatismyipaddress.com/", ssPort, uniqueId);
AppsPID.push([ssPID]);
AppsMutex.push("chrome_" + uniqueId);
} }
} }
}; };
// Check dead processes // Check dead processes
var check_Exits = function() { var check_Exits = function() {
var availablePIDs = []; var alivePIDList = SYS.getProcessList().reduce(function(acc, process) {
var processes = SYS.getProcesses(); acc.push(process.ProcessID);
}, []);
for (var i = 0; i < processes.length; i++) {
availablePIDs.push(processes[i].ProcessID);
}
AppsPID.forEach(function(v1) { AppsPID.forEach(function(v1) {
v1.forEach(function(v2) { v1.forEach(function(v2) {
if (availablePIDs.indexOf(v2) < 0) { if (alivePIDList.indexOf(v2) < 0) {
//console.warn("Detected dead process: " + v2); console.warn("Detected dead process: " + v2);
//console.warn("Will be kill related processes."); console.warn("Will be kill related processes.");
//v1.forEach(function(v2) { v1.forEach(function(v2) {
// SYS.killProcess(v2); SYS.killProcess(v2);
//}); });
return; return;
} }
@ -191,10 +188,7 @@ var main = function() {
check_NoxPlayer(); check_NoxPlayer();
sleep(3000); sleep(3000);
check_Chrome(); check_Chrome();
sleep(3000);
check_Exits();
} }
}; };