2015-08-30 15:29:13 +02:00
|
|
|
/*
|
2015-08-30 16:21:54 +02:00
|
|
|
* BetterDiscordApp Installer v0.2 for Discord 0.0.277
|
2015-08-30 15:29:13 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
var asar = require('asar');
|
2015-08-30 16:21:54 +02:00
|
|
|
var wrench = require('wrench');
|
2015-08-30 15:29:13 +02:00
|
|
|
var fs = require('fs');
|
2015-08-30 16:21:54 +02:00
|
|
|
var readline = require('readline');
|
|
|
|
var util = require('util');
|
2015-08-30 15:29:13 +02:00
|
|
|
|
|
|
|
var _discordPath;
|
|
|
|
var _appFolder = "\\app";
|
|
|
|
var _appArchive = "\\app.asar";
|
|
|
|
var _packageJson = _appFolder + "\\package.json";
|
|
|
|
var _index = _appFolder + "\\app\\index.js";
|
|
|
|
|
2015-08-30 16:21:54 +02:00
|
|
|
function install() {
|
2015-08-30 15:29:13 +02:00
|
|
|
|
|
|
|
_discordPath = process.env.LOCALAPPDATA + "\\Discord\\app-0.0.277\\resources";
|
|
|
|
console.log("Looking for discord resources at: " + _discordPath);
|
|
|
|
|
|
|
|
fs.exists(_discordPath, function(exists) {
|
2015-08-30 16:21:54 +02:00
|
|
|
|
2015-08-30 15:29:13 +02:00
|
|
|
if(exists) {
|
2015-08-30 16:21:54 +02:00
|
|
|
console.log("Discord resources found at: " + _discordPath + "\nLooking for app folder");
|
2015-08-30 15:29:13 +02:00
|
|
|
|
2015-08-30 16:21:54 +02:00
|
|
|
if(fs.existsSync(_discordPath + _appFolder)) {
|
|
|
|
console.log("Deleting " + _discordPath + _appFolder + " folder.");
|
|
|
|
wrench.rmdirSyncRecursive(_discordPath + _appFolder);
|
|
|
|
console.log("Deleted " + _discordPath + _appFolder + " folder.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(fs.existsSync(_discordPath + "\\node_modules")) {
|
|
|
|
console.log("Deleting " + _discordPath + "\\node_modules" + " folder.");
|
|
|
|
wrench.rmdirSyncRecursive(_discordPath + "\\node_modules");
|
|
|
|
console.log("Deleted " + _discordPath + "\\node_modules" + " folder.");
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("Copying BetterDiscord");
|
2015-08-30 15:29:13 +02:00
|
|
|
|
2015-08-30 16:21:54 +02:00
|
|
|
fs.mkdirSync(_discordPath + "\\node_modules");
|
|
|
|
wrench.copyDirSyncRecursive(__dirname + "\\BetterDiscord\\", _discordPath + "\\node_modules\\BetterDiscord\\");
|
2015-08-30 15:29:13 +02:00
|
|
|
|
2015-08-30 16:21:54 +02:00
|
|
|
console.log("Looking for app archive");
|
|
|
|
if(fs.existsSync(_discordPath + _appArchive)) {
|
|
|
|
console.log("App archive found at: " + _discordPath + _appArchive);
|
|
|
|
} else {
|
|
|
|
console.log("Failed to locate app archive at: " + _discordPath + _appArchive);
|
|
|
|
process.exit();
|
|
|
|
}
|
2015-08-30 15:29:13 +02:00
|
|
|
|
2015-08-30 16:21:54 +02:00
|
|
|
console.log("Extracting app archive");
|
|
|
|
|
|
|
|
asar.extractAll(_discordPath + _appArchive, _discordPath + _appFolder);
|
|
|
|
|
|
|
|
fs.exists(_discordPath + _appFolder, function(exists) {
|
|
|
|
if(exists) {
|
|
|
|
console.log("Extracted to: " + _discordPath + _appFolder);
|
|
|
|
console.log("Injecting index.js");
|
2015-08-30 15:29:13 +02:00
|
|
|
|
2015-08-30 16:21:54 +02:00
|
|
|
var data = fs.readFileSync(_discordPath + _index).toString().split("\n");
|
|
|
|
data.splice(80, 0, 'var _betterDiscord = require(\'betterdiscord\');\n');
|
|
|
|
data.splice(363, 0, '_betterDiscord = new _betterDiscord.BetterDiscord(mainWindow); \n _betterDiscord.init(); \n');
|
2015-08-30 15:29:13 +02:00
|
|
|
|
|
|
|
|
2015-08-30 16:21:54 +02:00
|
|
|
fs.writeFile(_discordPath + _index, data.join("\n"), function(err) {
|
|
|
|
if(err) return console.log(err);
|
2015-08-30 15:29:13 +02:00
|
|
|
|
2015-08-30 16:21:54 +02:00
|
|
|
console.log("Injected index.js");
|
|
|
|
console.log("Injecting package.json");
|
2015-08-30 15:29:13 +02:00
|
|
|
|
2015-08-30 16:21:54 +02:00
|
|
|
var data = fs.readFileSync(_discordPath + _packageJson).toString().split("\n");
|
|
|
|
data.splice(9, 0, ',"betterdiscord":"^0.1.2"');
|
2015-08-30 15:29:13 +02:00
|
|
|
|
2015-08-30 16:21:54 +02:00
|
|
|
fs.writeFile(_discordPath + _packageJson, data.join("\n"), function(err) {
|
|
|
|
if(err) return console.log(err);
|
2015-08-30 15:29:13 +02:00
|
|
|
|
2015-08-30 16:21:54 +02:00
|
|
|
console.log("Injected package.json");
|
|
|
|
console.log("Looks like were done here :)");
|
2015-08-30 15:29:13 +02:00
|
|
|
process.exit();
|
2015-08-30 16:21:54 +02:00
|
|
|
});
|
2015-08-30 15:29:13 +02:00
|
|
|
});
|
2015-08-30 16:21:54 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
console.log("Something went wrong, rerun.");
|
|
|
|
process.exit();
|
2015-08-30 15:29:13 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-08-30 16:21:54 +02:00
|
|
|
|
|
|
|
|
2015-08-30 15:29:13 +02:00
|
|
|
} else {
|
|
|
|
console.log("Discord resources not found at: " + _discordPath);
|
2015-08-30 16:21:54 +02:00
|
|
|
process.exit();
|
2015-08-30 15:29:13 +02:00
|
|
|
}
|
2015-08-30 16:21:54 +02:00
|
|
|
|
2015-08-30 15:29:13 +02:00
|
|
|
});
|
2015-08-30 16:21:54 +02:00
|
|
|
|
2015-08-30 15:29:13 +02:00
|
|
|
}
|
|
|
|
|
2015-08-30 16:21:54 +02:00
|
|
|
function init() {
|
|
|
|
|
|
|
|
console.log("BetterDiscord Simple Installer v0.1 for Discord 0.0.277 by Jiiks.");
|
|
|
|
console.log("If Discord has updated then download the latest installer.");
|
2015-08-30 15:29:13 +02:00
|
|
|
|
2015-08-30 16:21:54 +02:00
|
|
|
var rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
|
|
|
|
|
|
rl.question("The following directories will be deleted if they exists: discorpath\\app, discordpath\\node_modules, is this ok? Y/N", function(answer) {
|
|
|
|
|
|
|
|
var alc = answer.toLowerCase();
|
|
|
|
|
|
|
|
switch(alc) {
|
|
|
|
case "y":
|
|
|
|
install();
|
|
|
|
break;
|
|
|
|
case "yes":
|
|
|
|
install();
|
|
|
|
break;
|
|
|
|
case "n":
|
|
|
|
process.exit();
|
|
|
|
break;
|
|
|
|
case "no":
|
|
|
|
process.exit();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-08-30 15:29:13 +02:00
|
|
|
|
|
|
|
init();
|