@@ -92,7 +92,7 @@ export class LicensingClient {
9292 switch ( process . platform ) {
9393 case 'win32' :
9494 // %PROGRAMDATA%\Unity\Config
95- servicesConfigDirectory = path . join ( process . env . PROGRAMDATA || '' , 'Unity' , 'Config' ) ;
95+ servicesConfigDirectory = path . join ( process . env . PROGRAMDATA || 'C:\\ProgramData ' , 'Unity' , 'Config' ) ;
9696 break ;
9797 case 'darwin' :
9898 // /Library/Application Support/Unity/config
@@ -119,6 +119,45 @@ export class LicensingClient {
119119 return path . join ( servicesConfigDirectory , 'services-config.json' ) ;
120120 }
121121
122+ private tryParseJson ( content : string | undefined ) : string | undefined {
123+ if ( ! content ) {
124+ return undefined ;
125+ }
126+
127+ try {
128+ JSON . parse ( content ) ;
129+ return content ;
130+ } catch {
131+ return undefined ;
132+ }
133+ }
134+
135+ private resolveServicesConfigContent ( input : string ) : string {
136+ const trimmedInput = input . trim ( ) ;
137+
138+ if ( trimmedInput . length === 0 ) {
139+ throw new Error ( 'Services config value is empty. Provide a file path, JSON, or base64 encoded JSON string.' ) ;
140+ }
141+
142+ const directJson = this . tryParseJson ( trimmedInput ) ;
143+
144+ if ( directJson ) {
145+ return directJson ;
146+ }
147+
148+ const base64Regex = / ^ [ A - Z a - z 0 - 9 + / ] * = { 0 , 2 } $ / ;
149+ if ( base64Regex . test ( trimmedInput ) ) {
150+ const decoded = Buffer . from ( trimmedInput , 'base64' ) . toString ( 'utf-8' ) . trim ( ) ;
151+ const decodedJson = this . tryParseJson ( decoded ) ;
152+
153+ if ( decodedJson ) {
154+ return decodedJson ;
155+ }
156+ }
157+
158+ throw new Error ( 'Services config value is not a valid JSON string or base64 encoded JSON string.' ) ;
159+ }
160+
122161 /**
123162 * Gets the path to the Unity Licensing Client log file.
124163 * @see https://docs.unity.com/en-us/licensing-server/troubleshooting-client#logs
@@ -441,7 +480,8 @@ export class LicensingClient {
441480 fs . copyFileSync ( options . servicesConfig , servicesConfigPath ) ;
442481 }
443482 else {
444- fs . writeFileSync ( servicesConfigPath , Buffer . from ( options . servicesConfig , 'base64' ) ) ;
483+ const configContent = this . resolveServicesConfigContent ( options . servicesConfig ) ;
484+ fs . writeFileSync ( servicesConfigPath , configContent , { encoding : 'utf-8' } ) ;
445485 }
446486
447487 if ( process . platform !== 'win32' ) {
0 commit comments