-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Override system.yaml path to fix problems introduced by the new LCU p…
…atcher
- Loading branch information
Showing
5 changed files
with
408 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "rift-explorer", | ||
"version": "5.0.0", | ||
"version": "6.0.0", | ||
"description": "Always up to date documentation for the League Client API", | ||
"main": "app.js", | ||
"scripts": { | ||
|
@@ -10,6 +10,8 @@ | |
"author": "Robert Manolea <[email protected]>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"execa": "^1.0.0", | ||
"fkill": "^6.1.0", | ||
"fs-extra": "^7.0.1", | ||
"lcu-connector": "^2.0.0", | ||
"mixin-deep": "^2.0.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,74 @@ | ||
const cp = require('child_process'); | ||
const path = require('path'); | ||
const fs = require('fs-extra'); | ||
const yaml = require('yaml'); | ||
const fkill = require('fkill'); | ||
const execa = require('execa'); | ||
|
||
const IS_WIN = process.platform === 'win32'; | ||
const LEAGUE_PROCESS = IS_WIN ? 'LeagueClient.exe' : 'LeagueClient'; | ||
|
||
module.exports.getLCUPathFromProcess = () => { | ||
function getLCUExecutableFromProcess() { | ||
return new Promise(resolve => { | ||
const command = IS_WIN ? | ||
`WMIC PROCESS WHERE name='LeagueClientUx.exe' GET ExecutablePath` : | ||
`ps x -o comm= | grep 'LeagueClientUx$'`; | ||
`WMIC PROCESS WHERE name='${LEAGUE_PROCESS}' GET ExecutablePath` : | ||
`ps x -o comm= | grep '${LEAGUE_PROCESS}$'`; | ||
|
||
cp.exec(command, (err, stdout, stderr) => { | ||
if (err || !stdout || stderr) { | ||
resolve(); | ||
cp.exec(command, (error, stdout, stderr) => { | ||
if (error || !stdout || stderr) { | ||
reject(error || stderr); | ||
return; | ||
} | ||
|
||
let normalizedPath = path.normalize(stdout); | ||
const normalizedPath = path.normalize(stdout); | ||
resolve(IS_WIN ? normalizedPath.split(/\n|\n\r/)[1] : normalizedPath); | ||
}); | ||
}); | ||
}; | ||
|
||
|
||
// On MAC we need to go up a few levels to reach `deploy` | ||
// This script also assumes that only Riot Games managed regions are provided | ||
// Hasn't been tested on Garena | ||
normalizedPath = IS_WIN ? normalizedPath.split(/\n|\n\r/)[1] : path.join(normalizedPath, '../../../'); | ||
normalizedPath = path.dirname(normalizedPath); | ||
async function duplicateSystemYaml() { | ||
const LCUExePath = await getLCUExecutableFromProcess(); | ||
const LCUDir = path.dirname(LCUExePath); | ||
|
||
resolve(normalizedPath); | ||
}); | ||
const originalSystemFile = path.join(LCUDir, 'system.yaml'); | ||
const overrideSystemFile = path.join(LCUDir, 'Config', 'rift-explorer', 'system.yaml'); | ||
|
||
// File doesn't exist, do nothing | ||
if (!(await fs.exists(originalSystemFile))) { | ||
throw new Error('system.yaml not found'); | ||
} | ||
|
||
const file = await fs.readFile(originalSystemFile, 'utf8'); | ||
const fileParsed = yaml.parse(file); | ||
|
||
fileParsed.enable_swagger = true; | ||
|
||
const stringifiedFile = yaml.stringify(fileParsed); | ||
// Rito's file is prefixed with --- newline | ||
await fs.outputFile(overrideSystemFile, `---\n${stringifiedFile}`); | ||
} | ||
|
||
function restartLCUWithOverride() { | ||
return new Promise(async (resolve, reject) => { | ||
const LCUExePath = await getLCUExecutableFromProcess(); | ||
const LCUDir = path.dirname(LCUExePath); | ||
const overrideSystemFile = path.join(LCUDir, 'Config', 'rift-explorer', 'system.yaml'); | ||
|
||
// Windows is unable to kill the child processes for some reason so we have to force kill it | ||
await fkill(LEAGUE_PROCESS, { force: true }); | ||
|
||
// By force killing it the LeagueClient doesn't cleanup the lockfile so we gotta do it manually | ||
await fs.remove(path.join(LCUDir, 'lockfile')); | ||
|
||
// Give it some time to do cleanup | ||
execa(LCUExePath, [`--system-yaml-override=${overrideSystemFile}`], { detached: true }); | ||
resolve(); | ||
}); | ||
}; | ||
} | ||
|
||
module.exports = { | ||
getLCUExecutableFromProcess, | ||
duplicateSystemYaml, | ||
restartLCUWithOverride, | ||
}; |
Oops, something went wrong.