From 0ca459549be6abfd3bdb34a5a49a854325c0962a Mon Sep 17 00:00:00 2001 From: regorxxx Date: Wed, 9 Oct 2024 17:31:22 +0200 Subject: [PATCH] - Helpers: in case saving a file throws an error due to long paths (+255 chars) a warning popup will be shown. - Helpers: updated helpers. --- CHANGELOG.md | 3 ++- helpers/helpers_xxx_console.js | 4 ++-- helpers/helpers_xxx_file.js | 16 ++++++++-------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25cd1ee..0a2f15b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,8 +52,9 @@ ### Added ### Changed - Configuration: changed the remove duplicates bias to prefer tracks containing 'BEST' within a 'TRACKDSP' tag. -- Helpers: updated helpers. - [JSplitter (SMP)](https://foobar2000.ru/forum/viewtopic.php?t=6378&start=360) support and ES2021 compatibility. +- Helpers: in case saving a file throws an error due to long paths (+255 chars) a warning popup will be shown. +- Helpers: updated helpers. ### Removed ### Fixed diff --git a/helpers/helpers_xxx_console.js b/helpers/helpers_xxx_console.js index 2525514..3106de8 100644 --- a/helpers/helpers_xxx_console.js +++ b/helpers/helpers_xxx_console.js @@ -1,5 +1,5 @@ 'use strict'; -//09/08/24 +//09/10/24 include(fb.ComponentPath + 'docs\\Codepages.js'); /* global convertCharsetToCodepage:readable */ @@ -89,7 +89,7 @@ console.formatArg = (arg) => { } } try { - val = (instance ? instance.name + ' ' : 'Object ') + JSON.stringify(val ? val : arg, (k, v) => { + val = (instance ? instance.name + ' ' : 'Object ') + JSON.stringify(val || arg, (k, v) => { if (typeof v !== 'undefined' && v !== null) { if (v.RawPath && v.Path) { return 'FbMetadbHandle ' + JSON.stringify({ FileSize: v.FileSize, Length: v.Length, Path: v.Path, RawPath: v.RawPath, SubSong: v.SubSong }, null, ' ').replace(/{\n /, '{').replace(/["\n]/g, '').replace(/\\\\/g, '\\'); diff --git a/helpers/helpers_xxx_file.js b/helpers/helpers_xxx_file.js index c9b648b..19b85fd 100644 --- a/helpers/helpers_xxx_file.js +++ b/helpers/helpers_xxx_file.js @@ -1,12 +1,10 @@ 'use strict'; -//09/08/24 +//09/10/24 /* exported _getNameSpacePath, _deleteFolder, _copyFile, _recycleFile, _restoreFile, _saveFSO, _saveSplitJson, _jsonParseFileSplit, _jsonParseFileCheck, _parseAttrFile, _explorer, getFiles, _run, _runHidden, _exec, editTextFile, findRecursivefile, findRelPathInAbsPath, sanitizePath, sanitize, UUID, created, getFileMeta, popup, getPathMeta, testPath, youTubeRegExp, _isNetwork */ include(fb.ComponentPath + 'docs\\Codepages.js'); /* global convertCharsetToCodepage:readable */ -include('helpers_xxx.js'); -/* global folders:readable, isCompatible:readable, lastStartup:readable, VK_SHIFT:readable */ include('helpers_xxx_basic_js.js'); /* global tryMethod:readable */ include('helpers_xxx_prototypes.js'); @@ -25,6 +23,9 @@ const fileSizeMask = new Map([['B', 1], ['KB', 1024], ['MB', 1024 ** 2], ['GB', const absPathRegExp = /[A-z]*:\\/; const youTubeRegExp = /(?:https?:\/\/)?(?:www\.|m\.)?youtu(?:\.be\/|be.com\/\S*(?:watch|embed)(?:(?:(?=\/[^&\s?]+(?!\S))\/)|(?:\S*v=|v\/)))([^&\s?]+)/; // NOSONAR +include('helpers_xxx.js'); +/* global folders:readable, isCompatible:readable, lastStartup:readable, VK_SHIFT:readable */ + // Create global folders _createFolder(folders.data); _createFolder(folders.userHelpers); @@ -304,6 +305,8 @@ function _save(file, value, bBOM = false) { if (round(roughSizeOfObject(value) / 1024 ** 2 / 2, 1) > 110) { console.popup('Data is bigger than 100 Mb, it may crash SMP. Report to use split JSON.', window.Name + ': JSON saving'); } if (_isFolder(filePath) && utils.WriteTextFile(file, value, bBOM)) { return true; + } else if (file.length > 255) { + fb.ShowPopupMessage('Script is trying to save a file in a path containing more than 256 chars which leads to problems on Windows systems.\n\nPath:\n' + file + '\n\nTo avoid this problem, install your foobar portable installation at another path (with less nesting).'); } console.log('Error saving to ' + file); return false; @@ -577,18 +580,15 @@ function testPath(path, relativeTo = '') { } return !bDead; } - -/* eslint-disable no-useless-escape */ function sanitize(value) { - return value && value.length ? value.replace(/[\/\\|:–]/g, '-').replace(/\*/g, 'x').replace(/"/g, '\'\'').replace(/[<>]/g, '_').replace(/\?/g, '').replace(/(?! )\s/g, '') : ''; + return value && value.length ? value.replace(/[/\\|:–]/g, '-').replace(/\*/g, 'x').replace(/"/g, '\'\'').replace(/[<>]/g, '_').replace(/\?/g, '').replace(/(?! )\s/g, '') : ''; } function sanitizePath(value) { // Sanitize illegal chars but skip drive if (!value || !value.length) { return ''; } const disk = (value.match(/^\w:\\/g) || [''])[0]; - return disk + (disk && disk.length ? value.replace(disk, '') : value).replace(/\//g, '\\').replace(/[|–‐—-]/g, '-').replace(/\*/g, 'x').replace(/"/g, '\'\'').replace(/[<>]/g, '_').replace(/[\?:]/g, '').replace(/(?! )\s/g, ''); + return disk + (disk && disk.length ? value.replace(disk, '') : value).replace(/\//g, '\\').replace(/[|–‐—-]/g, '-').replace(/\*/g, 'x').replace(/"/g, '\'\'').replace(/[<>]/g, '_').replace(/[?:]/g, '').replace(/(?! )\s/g, ''); } -/* eslint-enable no-useless-escape */ function UUID() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {