Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/unity-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
unity-cli --version
- name: Setup Unity
shell: bash
timeout-minutes: 30
run: |
unity-cli hub-install --auto-update
unity-cli setup-unity --unity-version "${{ matrix.unity-version }}" --build-targets "${{ matrix.build-target }}" --json
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rage-against-the-pixel/unity-cli",
"version": "1.3.2",
"version": "1.3.3",
"description": "A command line utility for the Unity Game Engine.",
"author": "RageAgainstThePixel",
"license": "MIT",
Expand Down
18 changes: 15 additions & 3 deletions src/android-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { spawn } from 'child_process';
import { Logger } from './logging';
import { UnityEditor } from './unity-editor';
import {
isProcessElevated,
ReadFileContents,
ResolveGlobToPath
} from './utilities';
Expand Down Expand Up @@ -124,10 +125,21 @@ async function execSdkManager(sdkManagerPath: string, javaPath: string, args: st

try {
exitCode = await new Promise<number>((resolve, reject) => {
const child = spawn(sdkManagerPath, args, {
let cmd = sdkManagerPath;
let cmdArgs = args;

if (process.platform === 'win32') {
if (!isProcessElevated()) {
throw new Error('Android SDK installation requires elevated (administrator) privileges. Please rerun as Administrator.');
}

cmd = 'cmd.exe';
cmdArgs = ['/c', sdkManagerPath, ...args];
}

const child = spawn(cmd, cmdArgs, {
stdio: ['pipe', 'pipe', 'pipe'],
env: {
...process.env,
JAVA_HOME: process.platform === 'win32' ? `"${javaPath}"` : javaPath
}
});
Expand All @@ -147,7 +159,7 @@ async function execSdkManager(sdkManagerPath: string, javaPath: string, args: st
function handleDataStream(data: Buffer) {
const chunk = data.toString();
output += chunk;
process.stderr.write(chunk);
process.stdout.write(chunk);
}
const acceptBuffer = Buffer.from(Array(10).fill('y').join(os.EOL), 'utf8');
child.stdin.write(acceptBuffer);
Expand Down
15 changes: 14 additions & 1 deletion src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as path from 'path';
import * as https from 'https';
import * as readline from 'readline';
import { glob } from 'glob';
import { spawn } from 'child_process';
import { spawn, spawnSync } from 'child_process';
import { Logger, LogLevel } from './logging';

const logger = Logger.instance;
Expand Down Expand Up @@ -572,4 +572,17 @@ export async function KillChildProcesses(procInfo: ProcInfo): Promise<void> {
} catch (error) {
logger.error(`Failed to kill child processes of pid ${procInfo.pid}:\n${JSON.stringify(error)}`);
}
}

/**
* Checks if the current process is running with elevated (administrator) privileges.
* @returns True if the process is elevated, false otherwise.
*/
export function isProcessElevated(): boolean {
if (process.platform !== 'win32') { return true; } // We can sudo easily on non-windows platforms
const probe = spawnSync('powershell.exe', [
'-NoLogo', '-NoProfile', '-Command',
"[Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent().IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)"
], { encoding: 'utf8' });
return probe.status === 0 && probe.stdout.trim().toLowerCase() === 'true';
}
Loading