Skip to content

Commit

Permalink
ItemSets are now removed after new patch
Browse files Browse the repository at this point in the history
- ItemSets are now removed after a new patch.
- Fixed few things
  • Loading branch information
Ryzzzen committed Jul 9, 2018
1 parent 499c489 commit 9d2e5fb
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 20 deletions.
4 changes: 3 additions & 1 deletion objects/ChampionSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class ChampionSelect extends EventEmitter {
super();
this.inChampionSelect = false;

ItemSetHandler.getItemSets().then(x => console.dir).catch(UI.error);

this.on('firstTick', async () => {
console.log('Entering Champion Select');

Expand Down Expand Up @@ -120,7 +122,7 @@ class ChampionSelect extends EventEmitter {

for (let itemset of old) {
itemset = await ItemSetHandler.parse(champion.key, itemset);
await itemset.remove();
await itemset.delete();
}

Mana.status(`Loading ${itemsets.length} sets for ${champion.name}`);
Expand Down
2 changes: 1 addition & 1 deletion objects/ItemSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ItemSet {
});
}

remove() {
delete() {
let p = this.path;
return new Promise((resolve, reject) => {
fs.unlink(p, err => {
Expand Down
49 changes: 32 additions & 17 deletions objects/handlers/ItemSetHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,34 @@ class ItemSetHandler {
return set;
}

static _readFile(path) {
return new Promise((resolve, reject) => {
fs.readFile(path, 'utf8', function (err, data) {
if (err) return reject(err);
resolve(JSON.parse(data));
});
});
}

static getItemSets() {
let self = this;
console.log(path.resolve(Mana.store.get('leaguePath') + `\\Config\\Champions\\`));
return new Promise((resolve, reject) => {
fs.readdir(path.resolve(Mana.store.get('leaguePath') + `\\Config\\Champions\\`), (err, dir) => {
if (err) return reject(err);
if (dir.length === 0) return resolve([]);
if (dir.length === 0) return reject(Error('Champions folder is empty?'));

let arr = [], res = [];

let arr = [];
for (let key of dir)
arr.push(self.getItemSetsByChampionKey(key));

Promise.all(arr).then(values => {
let array = [];
for (let x of values)
res = res.concat(x);

for (let x of array)
array = array.concat(x);

resolve(array);
resolve(res);
}).catch(reject);
});
});
}

static async deleteItemSets(list) {
for (let path of list)
await this._deleteFile(path);
}

static getItemSetsByChampionKey(key) {
key = key.toLowerCase();
return new Promise((resolve, reject) => {
Expand All @@ -53,12 +49,31 @@ class ItemSetHandler {

let arr = [];
for (let file of dir)
if (file.startsWith('MFLUX_')) arr.push(path.resolve(Mana.store.get('leaguePath'), `\\Config\\Champions\\${key}\\Recommended\\${file}`));
if (file.startsWith('MFLUX_')) arr.push(path.resolve(Mana.store.get('leaguePath') + `\\Config\\Champions\\${key}\\Recommended\\${file}`));

resolve(arr);
});
});
}

static _readFile(path) {
return new Promise((resolve, reject) => {
fs.readFile(path, 'utf8', function (err, data) {
if (err) return reject(err);
resolve(JSON.parse(data));
});
});
}

static _deleteFile(path) {
return new Promise((resolve, reject) => {
fs.unlink(path, err => {
if (err && err.code === 'ENOENT') resolve(false);
else if (err) reject(err);
else resolve(true);
});
});
}
}

module.exports = ItemSetHandler;
5 changes: 4 additions & 1 deletion renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

const request = require('request'), rp = require('request-promise-native');

const Store = require('electron-store');

const { dialog } = require('electron').remote;

const ItemSetHandler = require('./objects/handlers/ItemSetHandler');

Mana.version = require('./package.json').version;
Mana.status = str => {
$('.status').text(str + '...');
Expand Down Expand Up @@ -87,6 +88,8 @@ ipcRenderer.once('lcu-connected', (event, d) => {
if (Mana.store.get('gameVersion') !== ver) {
Mana.store.set('runes', {});
Mana.store.set('summonerspells', {});

ItemSetHandler.getItemSets().then(x => ItemSetHandler.deleteItemSets(x)).catch(UI.error);
}

Mana.store.set('gameVersion', ver);
Expand Down

0 comments on commit 9d2e5fb

Please sign in to comment.