Fixed installer issues

- Moved app.asar extraction before BetterDiscord directory mv
- Fixed issue with errors being thrown by installer when emote files did
  not exist in library preferences directory
This commit is contained in:
jzanutto 2016-02-13 19:46:18 -05:00
parent 4cab5e6067
commit 6f3026fff5
1 changed files with 120 additions and 104 deletions

110
NodeInstaller/index.js Normal file → Executable file
View File

@ -68,12 +68,6 @@ function install() {
console.log("Deleted " + _discordPath + "/node_modules/BetterDiscord" + " folder."); console.log("Deleted " + _discordPath + "/node_modules/BetterDiscord" + " folder.");
} }
console.log("Copying BetterDiscord");
fs.mkdirSync(_discordPath + "/node_modules/BetterDiscord");
wrench.copyDirSyncRecursive(__dirname + "/BetterDiscord/", _discordPath + "/node_modules/BetterDiscord/", {forceDelete: true});
console.log("Looking for app archive"); console.log("Looking for app archive");
if(fs.existsSync(_discordPath + _appArchive)) { if(fs.existsSync(_discordPath + _appArchive)) {
console.log("App archive found at: " + _discordPath + _appArchive); console.log("App archive found at: " + _discordPath + _appArchive);
@ -83,10 +77,14 @@ function install() {
} }
console.log("Extracting app archive"); console.log("Extracting app archive");
asar.extractAll(_discordPath + _appArchive, _discordPath + _appFolder); asar.extractAll(_discordPath + _appArchive, _discordPath + _appFolder);
console.log("Copying BetterDiscord");
fs.mkdirSync(_discordPath + "/node_modules/BetterDiscord");
wrench.copyDirSyncRecursive(__dirname + "/BetterDiscord/", _discordPath + _appFolder + "/node_modules/BetterDiscord/", {forceDelete: true});
if(!fs.existsSync("splice")) { if(!fs.existsSync("splice")) {
console.log("Missing splice file"); console.log("Missing splice file");
process.exit(); process.exit();
@ -111,66 +109,86 @@ function install() {
console.log("Deleting old cache files"); console.log("Deleting old cache files");
var counter = 0; var counter = 0;
var _prefsPath = '/Library/Preferences/BetterDiscord/';
fs.exists(process.env.HOME + '/Library/Preferences/BetterDiscord/emotes_twitch_global.json', (exists) => { var emotes_twitch_global = 'emotes_twitch_global.json';
console.log("Deleting emotes_twitch_global.json") fs.exists(process.env.HOME + _prefsPath + emotes_twitch_global, (exists) => {
fs.unlink(process.env.HOME + '/Library/Preferences/BetterDiscord/emotes_twitch_global.json', (err) => { if (exists) {
console.log("Deleting " + emotes_twitch_global);
fs.unlinkSync(process.env.HOME + _prefsPath + emotes_twitch_global, (err) => {
if(err) throw err; if(err) throw err;
console.log("Deleted emotes_twitch_global.json"); });
console.log("Deleted " + emotes_twitch_global);
}
counter++;
finished();
});
var emotes_twitch_subscriber = 'emotes_twitch_subscriber.json';
fs.exists(process.env.HOME + _prefsPath + emotes_twitch_subscriber, (exists) => {
if (exists) {
console.log("Deleting " + emotes_twitch_subscriber);
fs.unlinkSync(process.env.HOME + _prefsPath + emotes_twitch_subscriber, (err) => {
if(err) throw err;
});
console.log("Deleted " + emotes_twitch_subscriber);
}
counter++; counter++;
finished(); finished();
}); });
});
fs.exists(process.env.HOME + '/Library/Preferences/BetterDiscord/emotes_twitch_subscriber.json', (exists) => { var emotes_bttv = 'emotes_bttv.json';
console.log("Deleting emotes_twitch_subscriber.json") fs.exists(process.env.HOME + _prefsPath + emotes_bttv, (exists) => {
fs.unlink(process.env.HOME + '/Library/Preferences/BetterDiscord/emotes_twitch_subscriber.json', (err) => { if (exists) {
console.log("Deleting " + emotes_bttv);
fs.unlinkSync(process.env.HOME + _prefsPath + emotes_bttv, (err) => {
if(err) throw err; if(err) throw err;
console.log("Deleted emotes_twitch_subscriber.json"); });
console.log("Deleted " + emotes_bttv);
}
counter++; counter++;
finished(); finished();
}); });
});
fs.exists(process.env.HOME + '/Library/Preferences/BetterDiscord/emotes_bttv.json', (exists) => { var emotes_bttv_2 = "emotes_bttv_2.json";
console.log("Deleting emotes_bttv.json") fs.exists(process.env.HOME + _prefsPath + emotes_bttv_2, (exists) => {
fs.unlink(process.env.HOME + '/Library/Preferences/BetterDiscord/emotes_bttv.json', (err) => { if (exists) {
console.log("Deleting " + emotes_bttv_2);
fs.unlinkSync(process.env.HOME + _prefsPath + emotes_bttv_2, (err) => {
if(err) throw err; if(err) throw err;
console.log("Deleted emotes_bttv.json"); });
console.log("Deleted " + emotes_bttv_2);
}
counter++; counter++;
finished(); finished();
}); });
});
fs.exists(process.env.HOME + '/Library/Preferences/BetterDiscord/emotes_bttv_2.json', (exists) => { var emotes_ffz = "emotes_ffz.json";
console.log("Deleting emotes_bttv_2.json") fs.exists(process.env.HOME + _prefsPath + emotes_ffz, (exists) => {
fs.unlink(process.env.HOME + '/Library/Preferences/BetterDiscord/emotes_bttv_2.json', (err) => { if (exists) {
console.log("Deleting " + emotes_ffz);
fs.unlinkSync(process.env.HOME + _prefsPath + emotes_ffz, (err) => {
if(err) throw err; if(err) throw err;
console.log("Deleted emotes_bttv_2.json"); });
console.log("Deleted " + emotes_ffz);
}
counter++; counter++;
finished(); finished();
});
});
fs.exists(process.env.HOME + '/Library/Preferences/BetterDiscord/emotes_ffz.json', (exists) => { });
console.log("Deleting emotes_ffz.json") var user_pref = "user.json";
fs.unlink(process.env.HOME + '/Library/Preferences/BetterDiscord/emotes_ffz.json', (err) => { fs.exists(process.env.HOME + _prefsPath + user_pref, (exists) => {
if (exists) {
console.log("Deleting " + user_pref);
fs.unlinkSync(process.env.HOME + _prefsPath + user_pref, (err) => {
if(err) throw err; if(err) throw err;
console.log("Deleted emotes_ffz.json"); });
console.log("Deleted " + user_pref);
}
counter++; counter++;
finished(); finished();
}); });
});
fs.exists(process.env.HOME + '/Library/Preferences/BetterDiscord/user.json', (exists) => {
console.log("Deleting user.json")
fs.unlink(process.env.HOME + '/Library/Preferences/BetterDiscord/user.json', (err) => {
if(err) throw err;
console.log("Deleted user.json");
counter++;
finished();
});
});
function finished() { function finished() {
if(counter => 6) { if(counter => 6) {
@ -178,12 +196,10 @@ function install() {
process.exit(); process.exit();
} }
} }
}); });
} else { } else {
console.log("Something went wrong, rerun."); console.log("Something went wrong. Please try again.");
process.exit(); process.exit();
} }
}); });