Skip to content

Commit

Permalink
- Helpers: in case saving a file throws an error due to long paths (+…
Browse files Browse the repository at this point in the history
…255 chars) a warning popup will be shown.

- Helpers: updated helpers.
  • Loading branch information
regorxxx committed Oct 9, 2024
1 parent 4609bef commit 0ca4595
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions helpers/helpers_xxx_console.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
//09/08/24
//09/10/24

include(fb.ComponentPath + 'docs\\Codepages.js');
/* global convertCharsetToCodepage:readable */
Expand Down Expand Up @@ -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, '\\');
Expand Down
16 changes: 8 additions & 8 deletions helpers/helpers_xxx_file.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit 0ca4595

Please sign in to comment.