Skip to content

Commit c5d4f6c

Browse files
add uninstall option
1 parent 3b7272e commit c5d4f6c

3 files changed

Lines changed: 59 additions & 0 deletions

File tree

.github/workflows/unity-build.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ jobs:
7979
run: |
8080
unity-cli run --unity-editor "${UNITY_EDITOR_PATH}" --unity-project "${UNITY_PROJECT_PATH}" --log-name Validate -quit -nographics -batchmode -executeMethod Utilities.Editor.BuildPipeline.UnityPlayerBuildTools.ValidateProject -importTMProEssentialsAsset
8181
unity-cli run --unity-editor "${UNITY_EDITOR_PATH}" --unity-project "${UNITY_PROJECT_PATH}" --log-name Build -quit -nographics -batchmode -executeMethod Utilities.Editor.BuildPipeline.UnityPlayerBuildTools.StartCommandLineBuild -sceneList Assets/Scenes/SampleScene.unity
82+
- name: Uninstall editor
83+
if: always()
84+
shell: bash
85+
run: |
86+
unity-cli uninstall-unity --unity-editor "${UNITY_EDITOR_PATH}"
8287
- name: Post Run
8388
if: always()
8489
shell: bash

src/cli.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,42 @@ program.command('setup-unity')
268268
}
269269
});
270270

271+
program.command('uninstall-unity')
272+
.description('Uninstall the specified Unity Editor version.')
273+
.option('-e, --unity-editor <unityEditorPath>', 'The path to the Unity Editor executable. If unspecified, -u, --unity-version or the UNITY_EDITOR_PATH environment variable must be set.')
274+
.option('-u, --unity-version <unityVersion>', 'The Unity version to get (e.g. 2020.3.1f1, 2021.x, 2022.1.*, 6000). If unspecified, then --unity-editor must be specified.')
275+
.option('-c, --changeset <changeset>', 'The Unity changeset to get (e.g. 1234567890ab).')
276+
.option('-a, --arch <architecture>', 'The Unity architecture to get (e.g. x86_64, arm64). Defaults to the architecture of the current process.')
277+
.option('--verbose', 'Enable verbose logging.')
278+
.action(async (options) => {
279+
if (options.verbose) {
280+
Logger.instance.logLevel = LogLevel.DEBUG;
281+
}
282+
283+
Logger.instance.debug(JSON.stringify(options));
284+
285+
let unityEditor: UnityEditor | undefined;
286+
const unityVersionStr = options.unityVersion?.toString()?.trim();
287+
288+
if (unityVersionStr) {
289+
const unityVersion = new UnityVersion(unityVersionStr, options.changeset, options.arch);
290+
const unityHub = new UnityHub();
291+
unityEditor = await unityHub.GetEditor(unityVersion);
292+
} else {
293+
const editorPath = options.unityEditor?.toString()?.trim() || process.env.UNITY_EDITOR_PATH || undefined;
294+
if (!editorPath || editorPath.length === 0) {
295+
throw new Error('You must specify a Unity version or editor path with -u, --unity-version, -e, --unity-editor.');
296+
}
297+
unityEditor = new UnityEditor(editorPath);
298+
}
299+
300+
if (!unityEditor) {
301+
throw new Error('The Unity Editor could not be found.');
302+
}
303+
304+
await unityEditor.Uninstall();
305+
});
306+
271307
program.commandsGroup('Unity Editor:');
272308

273309
program.command('open-project')

src/unity-editor.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
TailLogFile,
1515
LogTailResult,
1616
WaitForFileToBeCreatedAndReadable,
17+
Exec,
1718
} from './utilities';
1819

1920
export interface EditorCommand {
@@ -316,4 +317,21 @@ export class UnityEditor {
316317
fs.accessSync(editorRootPath, fs.constants.R_OK);
317318
return editorRootPath;
318319
}
320+
321+
public async Uninstall(): Promise<void> {
322+
switch (process.platform) {
323+
case 'darwin':
324+
case 'linux':
325+
await Exec('sudo', ['rm', '-rf', this.editorRootPath], { silent: true, showCommand: true });
326+
break;
327+
case 'win32':
328+
const uninstallPath = path.join(this.editorRootPath, 'Uninstall.exe');
329+
await Exec('powershell', [
330+
'-Command',
331+
`Start-Process -File "${uninstallPath}" -ArgumentList "/S" -NoNewWindow -Wait -Verb RunAs`
332+
], { silent: true, showCommand: true });
333+
break;
334+
}
335+
336+
}
319337
}

0 commit comments

Comments
 (0)