@@ -4235,41 +4235,42 @@ class UnityEditor {
42354235 this.version = version;
42364236 }
42374237 this.autoAddNoGraphics = this.version.isGreaterThan('2018.0.0');
4238- // check if we have permissions to write to this file
4239- try {
4240- fs.accessSync(this.editorRootPath, fs.constants.W_OK);
4241- }
4242- catch (error) {
4243- return;
4244- }
42454238 // ensure metadata.hub.json exists and has a productName entry
42464239 const hubMetaDataPath = path.join(this.editorRootPath, 'metadata.hub.json');
4247- if (!fs.existsSync(hubMetaDataPath)) {
4248- const metadata = {
4249- productName: `Unity ${this.version.version.toString()}`,
4250- entitlements: [],
4251- releaseStream: '',
4252- isLTS: null
4253- };
4254- fs.writeFileSync(hubMetaDataPath, JSON.stringify(metadata), { encoding: 'utf-8' });
4255- }
4256- else {
4257- const metadataContent = fs.readFileSync(hubMetaDataPath, { encoding: 'utf-8' });
4258- const metadata = JSON.parse(metadataContent);
4259- if (!metadata.productName) {
4260- // projectName must be the first property
4261- const newMetadata = {
4262- productName: `Unity ${this.version.version.toString()}`
4240+ try {
4241+ // check if we have permissions to write to this file
4242+ fs.accessSync(hubMetaDataPath, fs.constants.W_OK);
4243+ if (!fs.existsSync(hubMetaDataPath)) {
4244+ const metadata = {
4245+ productName: `Unity ${this.version.version.toString()}`,
4246+ entitlements: [],
4247+ releaseStream: '',
4248+ isLTS: null
42634249 };
4264- Object.keys(metadata).forEach(key => {
4265- if (key === 'productName') {
4266- return;
4267- }
4268- newMetadata[key] = metadata[key];
4269- });
4270- fs.writeFileSync(hubMetaDataPath, JSON.stringify(newMetadata), { encoding: 'utf-8' });
4250+ fs.writeFileSync(hubMetaDataPath, JSON.stringify(metadata), { encoding: 'utf-8' });
4251+ }
4252+ else {
4253+ const metadataContent = fs.readFileSync(hubMetaDataPath, { encoding: 'utf-8' });
4254+ const metadata = JSON.parse(metadataContent);
4255+ if (!metadata.productName) {
4256+ // projectName must be the first property
4257+ const newMetadata = {
4258+ productName: `Unity ${this.version.version.toString()}`
4259+ };
4260+ Object.keys(metadata).forEach(key => {
4261+ if (key === 'productName') {
4262+ return;
4263+ }
4264+ newMetadata[key] = metadata[key];
4265+ });
4266+ fs.writeFileSync(hubMetaDataPath, JSON.stringify(newMetadata), { encoding: 'utf-8' });
4267+ }
42714268 }
42724269 }
4270+ catch (error) {
4271+ // ignore - we just won't be able to update the metadata file
4272+ this.logger.debug(`No write access to Unity editor root path: ${this.editorRootPath}`);
4273+ }
42734274 }
42744275 /**
42754276 * Get the full path to a Unity project template based on the provided template name or regex pattern.
0 commit comments