@@ -4,43 +4,52 @@ const fs = require('fs');
44module . exports = { activateLicense, activateManualLicense, returnLicense }
55
66async function activateLicense ( unityPath , username , password , serial ) {
7- let stdout = '' ;
8- await exec . exec ( `${ unityCmd ( unityPath ) } -batchmode -nographics -quit -logFile -projectPath ? -username "${ username } " -password "${ password } " -serial "${ serial } "` , [ ] , {
9- ignoreReturnCode : true ,
10- listeners : {
11- stdout : buffer => stdout += buffer . toString ( )
12- }
13- } ) ;
7+ await prepareForActivation ( ) ;
8+ const stdout = await execute ( `${ unityCmd ( unityPath ) } -batchmode -nographics -quit -logFile -projectPath ? -username "${ username } " -password "${ password } " -serial "${ serial } "` , true ) ;
149 if ( ! stdout . includes ( 'Next license update check is after' ) ) {
1510 throw new Error ( 'Activation failed' ) ;
1611 }
1712}
1813
1914async function activateManualLicense ( unityPath , manualLicense ) {
2015 fs . writeFileSync ( 'license.ulf' , manualLicense ) ;
21- let stdout = '' ;
22- await exec . exec ( `${ unityCmd ( unityPath ) } -batchmode -nographics -quit -logFile -projectPath ? -manualLicenseFile license.ulf` , [ ] , {
23- listeners : {
24- stdout : buffer => stdout += buffer . toString ( )
25- }
26- } ) ;
16+ await prepareForActivation ( ) ;
17+ const stdout = await execute ( `${ unityCmd ( unityPath ) } -batchmode -nographics -quit -logFile -projectPath ? -manualLicenseFile license.ulf` ) ;
2718 if ( ! stdout . includes ( 'Next license update check is after' ) ) {
2819 throw new Error ( 'Activation failed' ) ;
2920 }
3021}
3122
3223async function returnLicense ( unityPath ) {
33- await exec . exec ( `${ unityCmd ( unityPath ) } -batchmode -nographics -quit -logFile -returnlicense` ) ;
24+ await execute ( `${ unityCmd ( unityPath ) } -batchmode -nographics -quit -logFile -returnlicense` ) ;
25+ }
26+
27+ async function prepareForActivation ( ) {
28+ if ( process . platform === 'darwin' ) {
29+ await execute ( 'sudo mkdir -p "/Library/Application Support/Unity"' ) ;
30+ await execute ( `sudo chown -R ${ process . env . USER } "/Library/Application Support/Unity"` ) ;
31+ }
3432}
3533
3634function unityCmd ( unityPath ) {
3735 let unityCmd = '' ;
3836 if ( process . platform === 'linux' ) {
39- unityCmd = `sudo xvfb-run --auto-servernum "${ unityPath } "` ;
37+ unityCmd = `xvfb-run --auto-servernum "${ unityPath } "` ;
4038 } else if ( process . platform === 'darwin' ) {
41- unityCmd = `sudo "${ unityPath } "` ;
39+ unityCmd = `"${ unityPath } "` ;
4240 } else if ( process . platform === 'win32' ) {
4341 unityCmd = `"${ unityPath } "` ;
4442 }
4543 return unityCmd ;
44+ }
45+
46+ async function execute ( command , ignoreReturnCode ) {
47+ let stdout = '' ;
48+ await exec . exec ( command , [ ] , {
49+ ignoreReturnCode : ignoreReturnCode ,
50+ listeners : {
51+ stdout : buffer => stdout += buffer . toString ( )
52+ }
53+ } ) ;
54+ return stdout ;
4655}
0 commit comments