fix paths checked for adb tools

This commit is contained in:
Max Myers
2021-11-04 13:52:01 -04:00
parent 3c64958da0
commit 7237aa0e5a
2 changed files with 53 additions and 16 deletions
+19 -10
View File
@@ -372,18 +372,27 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
}); });
} }
isAdbDownloaded() { isAdbDownloaded() {
let downloaded = true; try {
if (!this.doesFileExist(this.adbPath)) { let downloaded = true;
if (!this.doesFileExist(this.adbPath)) {
return false;
}
let source_files = this.appService.fs.readdirSync(this.appService.getPlatformToolsSeedPath());
if (source_files === null) {
return false;
}
let dest_files = this.appService.fs.readdirSync(this.adbPath);
source_files.forEach(d => {
if (dest_files.indexOf(d) === -1) {
downloaded = false;
}
});
return downloaded; // this.doesFileExist(this.appService.path.join(this.adbPath, this.getAdbBinary()));
} catch (e) {
console.error('Error checking for ADB being installed', e);
return false; return false;
} }
let source_files = this.appService.fs.readdirSync(this.appService.path.join(process.cwd(), 'build', 'platform-tools'));
let dest_files = this.appService.fs.readdirSync(this.adbPath);
source_files.forEach(d => {
if (dest_files.indexOf(d) === -1) {
downloaded = false;
}
});
return downloaded; // this.doesFileExist(this.appService.path.join(this.adbPath, this.getAdbBinary()));
} }
setPermission(packageName: string, permission: string, isRevoke?: boolean) { setPermission(packageName: string, permission: string, isRevoke?: boolean) {
return this.adbCommand('shell', { return this.adbCommand('shell', {
+34 -6
View File
@@ -225,11 +225,36 @@ export class AppService {
break; break;
} }
} }
private foundSeedToolsPath: string | null = null;
getPlatformToolsSeedPath() {
if (this.foundSeedToolsPath !== null) {
return this.foundSeedToolsPath;
}
let ogSourcesPath = this.path.join(process.resourcesPath, 'build', 'platform-tools');
let sourcesPath = ogSourcesPath;
if (!this.doesFileExist(sourcesPath)) {
sourcesPath = sourcesPath.replace('app.asar', 'app.asar.unpacked');
}
if (!this.doesFileExist(sourcesPath)) {
sourcesPath = this.path.join(process.resourcesPath, 'app.asar.unpacked', 'build', 'platform-tools');
}
if (!this.doesFileExist(sourcesPath)) {
sourcesPath = this.path.join(process.cwd(), 'build', 'platform-tools');
}
if (!this.doesFileExist(sourcesPath)) {
return null;
}
this.foundSeedToolsPath = sourcesPath;
return sourcesPath;
}
seedPlatformTools() { seedPlatformTools() {
return new Promise(async resolve => { return new Promise<void>(async resolve => {
let sourcesPath = this.path.join(__dirname, '..', 'platform-tools'); let sourcesPath = this.getPlatformToolsSeedPath();
if (!this.fs.existsSync(sourcesPath)) { if (sourcesPath == null) {
sourcesPath = this.path.join(process.cwd(), 'build', 'platform-tools'); console.error('Unable to locate platform tools! Try reinstalling sidequest.');
resolve();
return;
} }
await this.mkdir(this.path.join(this.appData, 'platform-tools')); await this.mkdir(this.path.join(this.appData, 'platform-tools'));
try { try {
@@ -247,7 +272,10 @@ export class AppService {
} else { } else {
setTimeout(() => resolve(), 5000); setTimeout(() => resolve(), 5000);
} }
} catch (e) {} } catch (e) {
console.error('Error seeding platform tools! ', e);
resolve();
}
}); });
} }
makeFolders() { makeFolders() {
@@ -262,7 +290,7 @@ export class AppService {
}); });
} }
setExecutable(path) { setExecutable(path) {
return new Promise(resolve => { return new Promise<void>(resolve => {
const ls = this.spawn('chmod', ['+x', path]); const ls = this.spawn('chmod', ['+x', path]);
ls.stdout.on('data', res => { ls.stdout.on('data', res => {
console.log(res); console.log(res);