mirror of
https://github.com/fofolee/uTools-ProcessKiller.git
synced 2025-09-28 07:05:04 +08:00
v0.0.2
This commit is contained in:
3
node_modules/icon-extractor/.npmignore
generated
vendored
Normal file
3
node_modules/icon-extractor/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
IconExtractor
|
||||
.gitignore
|
||||
win-iconExtractor-test.js
|
35
node_modules/icon-extractor/README.md
generated
vendored
Normal file
35
node_modules/icon-extractor/README.md
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
# IconExtractor
|
||||
|
||||
A nodejs package that returns base64 image data for a path's icon.
|
||||
|
||||
This is a simple nodejs wrapper around a .net executable that will extract icon image data from a given path and return it.
|
||||
|
||||
Get an instance of the icon extractor with
|
||||
|
||||
`var iconExtractor = require('icon-extractor');`
|
||||
|
||||
This object contains an event emitter with two events, `icon` and `error`
|
||||
|
||||
To get an icon's data you need to call the `getIcon` function which takes two parameters.
|
||||
The first is a context parameter. This will return with the icon data so you can have some information about what the return
|
||||
data is for. The second parameter is the path of the file you want the icon for.
|
||||
|
||||
Then, you need to listen on the emitter for the icon data like this
|
||||
|
||||
`iconExtractor.emitter.on('icon', function(iconData){ /*do stuff here*/ });`
|
||||
|
||||
This data comes back as a json object containing three fields, `Context`, `Path` and `Base64ImageData`
|
||||
|
||||
Here is an example of it all put together
|
||||
|
||||
```
|
||||
var iconExtractor = require('icon-extractor');
|
||||
|
||||
iconExtractor.emitter.on('icon', function(data){
|
||||
console.log('Here is my context: ' + data.Context);
|
||||
console.log('Here is the path it was for: ' + data.Path);
|
||||
console.log('Here is the base64 image: ' + data.Base64ImageData);
|
||||
});
|
||||
|
||||
iconExtractor.getIcon('SomeContextLikeAName','c:\myexecutable.exe');
|
||||
```
|
BIN
node_modules/icon-extractor/bin/IconExtractor.exe
generated
vendored
Normal file
BIN
node_modules/icon-extractor/bin/IconExtractor.exe
generated
vendored
Normal file
Binary file not shown.
BIN
node_modules/icon-extractor/bin/Newtonsoft.Json.dll
generated
vendored
Normal file
BIN
node_modules/icon-extractor/bin/Newtonsoft.Json.dll
generated
vendored
Normal file
Binary file not shown.
55
node_modules/icon-extractor/package.json
generated
vendored
Normal file
55
node_modules/icon-extractor/package.json
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
{
|
||||
"_from": "icon-extractor",
|
||||
"_id": "icon-extractor@1.0.3",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-CBiqpREFGraSRCu+I8o9K40WTw0=",
|
||||
"_location": "/icon-extractor",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "tag",
|
||||
"registry": true,
|
||||
"raw": "icon-extractor",
|
||||
"name": "icon-extractor",
|
||||
"escapedName": "icon-extractor",
|
||||
"rawSpec": "",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "latest"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/icon-extractor/-/icon-extractor-1.0.3.tgz",
|
||||
"_shasum": "0818aaa511051ab692442bbe23ca3d2b8d164f0d",
|
||||
"_spec": "icon-extractor",
|
||||
"_where": "C:\\Users\\fofol\\OneDrive\\Configs\\ProcessKiller",
|
||||
"author": {
|
||||
"name": "Justin Basinger"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/ScienceVikings/IconExtractor/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"lodash": "^3.10.1"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Given a path, return base64 data of the icon used for that file",
|
||||
"homepage": "https://github.com/ScienceVikings/IconExtractor#readme",
|
||||
"keywords": [
|
||||
"icon",
|
||||
"extractor",
|
||||
"windows"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "win-iconExtractor.js",
|
||||
"name": "icon-extractor",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/ScienceVikings/IconExtractor.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"version": "1.0.3"
|
||||
}
|
78
node_modules/icon-extractor/win-iconExtractor.js
generated
vendored
Normal file
78
node_modules/icon-extractor/win-iconExtractor.js
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
var EventEmitter = require('events');
|
||||
var fs = require('fs');
|
||||
var child_process = require('child_process');
|
||||
var _ = require('lodash');
|
||||
var os = require('os');
|
||||
var path = require('path');
|
||||
|
||||
var emitter = new EventEmitter();
|
||||
|
||||
function IconExtractor(){
|
||||
|
||||
var self = this;
|
||||
var iconDataBuffer = "";
|
||||
|
||||
this.emitter = new EventEmitter();
|
||||
this.iconProcess = child_process.spawn(getPlatformIconProcess(),['-x']);
|
||||
|
||||
this.getIcon = function(context, path){
|
||||
var json = JSON.stringify({context: context, path: path}) + "\n";
|
||||
self.iconProcess.stdin.write(json);
|
||||
}
|
||||
|
||||
this.iconProcess.stdout.on('data', function(data){
|
||||
|
||||
var str = (new Buffer(data, 'utf8')).toString('utf8');
|
||||
|
||||
iconDataBuffer += str;
|
||||
|
||||
//Bail if we don't have a complete string to parse yet.
|
||||
if (!_.endsWith(str, '\n')){
|
||||
return;
|
||||
}
|
||||
|
||||
//We might get more than one in the return, so we need to split that too.
|
||||
_.each(iconDataBuffer.split('\n'), function(buf){
|
||||
|
||||
if(!buf || buf.length == 0){
|
||||
return;
|
||||
}
|
||||
|
||||
try{
|
||||
self.emitter.emit('icon', JSON.parse(buf));
|
||||
} catch(ex){
|
||||
self.emitter.emit('error', ex);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
this.iconProcess.on('error', function(err){
|
||||
self.emitter.emit('error', err.toString());
|
||||
});
|
||||
|
||||
this.iconProcess.stderr.on('data', function(err){
|
||||
self.emitter.emit('error', err.toString());
|
||||
});
|
||||
|
||||
function getPlatformIconProcess(){
|
||||
if (os.type() == 'Windows_NT') {
|
||||
|
||||
let exeSrc = path.join(__dirname,'/bin/IconExtractor.exe');
|
||||
let exeDst = path.join(os.tmpdir(), 'IconExtractor.exe');
|
||||
let dllSrc = path.join(__dirname,'/bin/Newtonsoft.Json.dll');
|
||||
let dllDst = path.join(os.tmpdir(), 'Newtonsoft.Json.dll');
|
||||
if (!fs.existsSync(exeDst)) {
|
||||
fs.writeFileSync(exeDst, fs.readFileSync(exeSrc));
|
||||
fs.writeFileSync(dllDst, fs.readFileSync(dllSrc));
|
||||
}
|
||||
return exeDst;
|
||||
//Do stuff here to get the icon that doesn't have the shortcut thing on it
|
||||
} else {
|
||||
throw('This platform (' + os.type() + ') is unsupported =(');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = new IconExtractor();
|
Reference in New Issue
Block a user