From 0b8d6cd03a00e15ca1cb6bbeaba1c01ba4f2e8bf Mon Sep 17 00:00:00 2001 From: Bruce McLean Date: Mon, 11 Mar 2024 09:28:45 -0400 Subject: [PATCH] Bugfix / fix tn import (#7566) * add fixes for invalid localization (#7564) (#7565) Co-authored-by: PhotoNomad0 * add fixes for tn import and migration errors * add fixes for tn import --------- Co-authored-by: PhotoNomad0 --- package-lock.json | 14 +-- package.json | 2 +- src/js/helpers/ResourcesHelpers.js | 188 +++++++++++++++-------------- 3 files changed, 104 insertions(+), 100 deletions(-) diff --git a/package-lock.json b/package-lock.json index bac1688ea2..0059b121b8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -74,7 +74,7 @@ "string-punctuation-tokenizer": "^2.2.0", "sudo-prompt": "6.2.1", "tc-electron-env": "0.10.0", - "tc-source-content-updater": "1.4.23", + "tc-source-content-updater": "1.4.24", "tc-strings": "0.1.7", "tc-tool": "4.1.0", "tc-ui-toolkit": "6.2.8", @@ -24454,9 +24454,9 @@ } }, "node_modules/tc-source-content-updater": { - "version": "1.4.23", - "resolved": "https://registry.npmjs.org/tc-source-content-updater/-/tc-source-content-updater-1.4.23.tgz", - "integrity": "sha512-GSOLojiFNyT2IK+xEVUUa2MG9wE4waqFxi5SkhRxRrEE61OGahKBHUZ0A9iQ9saWN0k8z9XyzNxuUjtUp1I1vQ==", + "version": "1.4.24", + "resolved": "https://registry.npmjs.org/tc-source-content-updater/-/tc-source-content-updater-1.4.24.tgz", + "integrity": "sha512-7/zk3kSieuhhdiAHz0jXsel+gSEQaqF/rIqF+/n2ZvdmlZvAS+YrNJIcIxCSt7zl/rrGLoYOgSp1RPiFluQgJA==", "dependencies": { "adm-zip": "^0.4.11", "agentkeepalive": "4.1.0", @@ -47861,9 +47861,9 @@ } }, "tc-source-content-updater": { - "version": "1.4.23", - "resolved": "https://registry.npmjs.org/tc-source-content-updater/-/tc-source-content-updater-1.4.23.tgz", - "integrity": "sha512-GSOLojiFNyT2IK+xEVUUa2MG9wE4waqFxi5SkhRxRrEE61OGahKBHUZ0A9iQ9saWN0k8z9XyzNxuUjtUp1I1vQ==", + "version": "1.4.24", + "resolved": "https://registry.npmjs.org/tc-source-content-updater/-/tc-source-content-updater-1.4.24.tgz", + "integrity": "sha512-7/zk3kSieuhhdiAHz0jXsel+gSEQaqF/rIqF+/n2ZvdmlZvAS+YrNJIcIxCSt7zl/rrGLoYOgSp1RPiFluQgJA==", "requires": { "adm-zip": "^0.4.11", "agentkeepalive": "4.1.0", diff --git a/package.json b/package.json index a8869b32de..1a7c152f72 100644 --- a/package.json +++ b/package.json @@ -186,7 +186,7 @@ "string-punctuation-tokenizer": "^2.2.0", "sudo-prompt": "6.2.1", "tc-electron-env": "0.10.0", - "tc-source-content-updater": "1.4.23", + "tc-source-content-updater": "1.4.24", "tc-strings": "0.1.7", "tc-tool": "4.1.0", "tc-ui-toolkit": "6.2.8", diff --git a/src/js/helpers/ResourcesHelpers.js b/src/js/helpers/ResourcesHelpers.js index 5096d6a685..5495338c81 100644 --- a/src/js/helpers/ResourcesHelpers.js +++ b/src/js/helpers/ResourcesHelpers.js @@ -1416,114 +1416,118 @@ export function preserveNeededOrigLangVersions(languageId, resourceId, resourceP * restores missing resources by language and bible and lexicon */ export function getMissingResources() { - const tcResourcesLanguages = getFilteredSubFolders(STATIC_RESOURCES_PATH); - - for ( const languageId of tcResourcesLanguages) { - LogHighlighted(` Checking for missing ${languageId} resources`); - const staticLanguageResource = path.join(STATIC_RESOURCES_PATH, languageId); - const userLanguageResource = path.join(USER_RESOURCES_PATH, languageId); - const resourceTypes = getFilteredSubFolders(staticLanguageResource); - - for ( const resourceType of resourceTypes) {// resourceType: bibles, lexicons or translationHelps - const resourceTypePath = path.join(staticLanguageResource, resourceType); - const resourceIds = getFilteredSubFolders(resourceTypePath); - - for ( const resourceId of resourceIds) {// resourceId: udb, ult, ugl, translationWords, translationNotes - const userResourcePath = path.join(userLanguageResource, resourceType, resourceId); - const staticResourcePath = path.join(staticLanguageResource, resourceType, resourceId); - - if (resourceType === 'lexicons') { - // check for lexicons packaged with tc executable. - checkForNewLexicons(languageId); - extractZippedResourceContent(userResourcePath, resourceType === 'bibles'); - } else if (!fs.existsSync(userResourcePath)) {// if resource isn't found in user resources folder. - copyAndExtractResource(staticResourcePath, userResourcePath, languageId, resourceId, resourceType); - } else { // compare resources manifest modified time - const owners = ResourceAPI.getLatestVersionsAndOwners(staticResourcePath) || {}; - const ownersKeys = Object.keys(owners); - - if (!ownersKeys || !ownersKeys.length) { - console.warn(`getMissingResources() - Could not find latest for ${staticResourcePath}`); - } - - for (const owner of ownersKeys) { - if (!owner) { - console.error(`getMissingResources() - skipping empty owner for ${staticResourcePath}`); - continue; + try { + const tcResourcesLanguages = getFilteredSubFolders(STATIC_RESOURCES_PATH); + + for (const languageId of tcResourcesLanguages) { + LogHighlighted(` Checking for missing ${languageId} resources`); + const staticLanguageResource = path.join(STATIC_RESOURCES_PATH, languageId); + const userLanguageResource = path.join(USER_RESOURCES_PATH, languageId); + const resourceTypes = getFilteredSubFolders(staticLanguageResource); + + for (const resourceType of resourceTypes) {// resourceType: bibles, lexicons or translationHelps + const resourceTypePath = path.join(staticLanguageResource, resourceType); + const resourceIds = getFilteredSubFolders(resourceTypePath); + + for (const resourceId of resourceIds) {// resourceId: udb, ult, ugl, translationWords, translationNotes + const userResourcePath = path.join(userLanguageResource, resourceType, resourceId); + const staticResourcePath = path.join(staticLanguageResource, resourceType, resourceId); + + if (resourceType === 'lexicons') { + // check for lexicons packaged with tc executable. + checkForNewLexicons(languageId); + extractZippedResourceContent(userResourcePath, resourceType === 'bibles'); + } else if (!fs.existsSync(userResourcePath)) {// if resource isn't found in user resources folder. + copyAndExtractResource(staticResourcePath, userResourcePath, languageId, resourceId, resourceType); + } else { // compare resources manifest modified time + const owners = ResourceAPI.getLatestVersionsAndOwners(staticResourcePath) || {}; + const ownersKeys = Object.keys(owners); + + if (!ownersKeys || !ownersKeys.length) { + console.warn(`getMissingResources() - Could not find latest for ${staticResourcePath}`); } - const staticResourceVersionPath = owners[owner]; - const version = path.basename(staticResourceVersionPath); - const userResourceVersionPath = path.join(userResourcePath, version); - const userResourceExists = fs.existsSync(userResourceVersionPath); - let isOldResource = false; - const filename = 'manifest.json'; - const staticResourceManifestPath = path.join(staticResourceVersionPath, filename); - - if (userResourceExists) { - const userResourceManifestPath = path.join(userResourceVersionPath, filename); - - if (fs.existsSync(userResourceManifestPath) && fs.existsSync(staticResourceManifestPath)) { - const { catalog_modified_time: userModifiedTime } = fs.readJsonSync(userResourceManifestPath) || {}; - const { catalog_modified_time: staticModifiedTime } = fs.readJsonSync(staticResourceManifestPath) || {}; - isOldResource = !userModifiedTime || (userModifiedTime < staticModifiedTime); - - if (isOldResource) { - console.log('getMissingResources() - userModifiedTime: ' + userModifiedTime); - console.log('getMissingResources() - staticModifiedTime: ' + staticModifiedTime); - } - } else if (!fs.existsSync(userResourceManifestPath)) { - if (fs.existsSync(staticResourceManifestPath)) { - console.log('getMissingResources() - missing user manifest: ' + userResourceManifestPath); - console.log('getMissingResources() - but found static manifest: ' + staticResourceManifestPath); - isOldResource = true; - } else { // if no manifest.json, fall back to checking versions - const userVersion = path.basename(userResourceVersionPath); - const staticVersion = path.basename(staticResourceVersionPath); - isOldResource = ResourceAPI.compareVersions(userVersion, staticVersion) < 0; + for (const owner of ownersKeys) { + if (!owner) { + console.error(`getMissingResources() - skipping empty owner for ${staticResourcePath}`); + continue; + } + + const staticResourceVersionPath = owners[owner]; + const version = path.basename(staticResourceVersionPath); + const userResourceVersionPath = path.join(userResourcePath, version); + const userResourceExists = fs.existsSync(userResourceVersionPath); + let isOldResource = false; + const filename = 'manifest.json'; + const staticResourceManifestPath = path.join(staticResourceVersionPath, filename); + + if (userResourceExists) { + const userResourceManifestPath = path.join(userResourceVersionPath, filename); + + if (fs.existsSync(userResourceManifestPath) && fs.existsSync(staticResourceManifestPath)) { + const { catalog_modified_time: userModifiedTime } = fs.readJsonSync(userResourceManifestPath) || {}; + const { catalog_modified_time: staticModifiedTime } = fs.readJsonSync(staticResourceManifestPath) || {}; + isOldResource = !userModifiedTime || (userModifiedTime < staticModifiedTime); if (isOldResource) { - console.log('getMissingResources() - userVersion: ' + userVersion); - console.log('getMissingResources() - staticVersion: ' + staticVersion); + console.log('getMissingResources() - userModifiedTime: ' + userModifiedTime); + console.log('getMissingResources() - staticModifiedTime: ' + staticModifiedTime); + } + } else if (!fs.existsSync(userResourceManifestPath)) { + if (fs.existsSync(staticResourceManifestPath)) { + console.log('getMissingResources() - missing user manifest: ' + userResourceManifestPath); + console.log('getMissingResources() - but found static manifest: ' + staticResourceManifestPath); + isOldResource = true; + } else { // if no manifest.json, fall back to checking versions + const userVersion = path.basename(userResourceVersionPath); + const staticVersion = path.basename(staticResourceVersionPath); + isOldResource = ResourceAPI.compareVersions(userVersion, staticVersion) < 0; + + if (isOldResource) { + console.log('getMissingResources() - userVersion: ' + userVersion); + console.log('getMissingResources() - staticVersion: ' + staticVersion); + } } } + } else { // resource folder was empty + isOldResource = true; } - } else { // resource folder was empty - isOldResource = true; - } - preserveNeededOrigLangVersions(languageId, resourceId, userResourcePath, USER_RESOURCES_PATH); - - if (isOldResource) { - console.log(`getMissingResources() - checking ${languageId} ${resourceId} ${owner} - no resource found`); - - // if (deleteOldResources) { - // console.log('getMissingResources() - deleting old resources folder: ' + userResourcePath); - // fs.removeSync(userResourcePath); - // } - console.log('getMissingResources() - unzipping static resources'); - copyAndExtractResource(staticResourcePath, userResourcePath, languageId, resourceId, resourceType, owner); - } else { // if folder empty, then copy over current resource - const versions = ResourceAPI.listVersions(userResourcePath, owner); - const emptyResourceFolder = !versions.length; - let installResource = emptyResourceFolder; - - if (!emptyResourceFolder) { // make sure bundled version is installed - const staticResourceVersionPath = ResourceAPI.getLatestVersion(staticResourcePath, owner); - const bundledVersion = path.basename(staticResourceVersionPath); - const destinationPath = path.join(userResourcePath, bundledVersion); - installResource = !fs.existsSync(destinationPath); - } + preserveNeededOrigLangVersions(languageId, resourceId, userResourcePath, USER_RESOURCES_PATH); + + if (isOldResource) { + console.log(`getMissingResources() - checking ${languageId} ${resourceId} ${owner} - no resource found`); - if (installResource) { - console.log('getMissingResources() - unzipping missing static resources'); + // if (deleteOldResources) { + // console.log('getMissingResources() - deleting old resources folder: ' + userResourcePath); + // fs.removeSync(userResourcePath); + // } + console.log('getMissingResources() - unzipping static resources'); copyAndExtractResource(staticResourcePath, userResourcePath, languageId, resourceId, resourceType, owner); + } else { // if folder empty, then copy over current resource + const versions = ResourceAPI.listVersions(userResourcePath, owner); + const emptyResourceFolder = !versions.length; + let installResource = emptyResourceFolder; + + if (!emptyResourceFolder) { // make sure bundled version is installed + const staticResourceVersionPath = ResourceAPI.getLatestVersion(staticResourcePath, owner); + const bundledVersion = path.basename(staticResourceVersionPath); + const destinationPath = path.join(userResourcePath, bundledVersion); + installResource = !fs.existsSync(destinationPath); + } + + if (installResource) { + console.log('getMissingResources() - unzipping missing static resources'); + copyAndExtractResource(staticResourcePath, userResourcePath, languageId, resourceId, resourceType, owner); + } } } } } } } + } catch (e) { + console.error(`getMissingResources() - exception occurred`, e); } }