pull/982/head
Mikael Finstad 5 years ago
parent 6926df5f00
commit e777aba0d1
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26

@ -66,7 +66,8 @@ import { adjustRate } from './util/rate-calculator';
import { askForOutDir, askForImportChapters, createNumSegments, createFixedDurationSegments, promptTimeOffset, askForHtml5ifySpeed, askForFileOpenAction, confirmExtractAllStreamsDialog, cleanupFilesDialog, showDiskFull, showCutFailedDialog, labelSegmentDialog, openYouTubeChaptersDialog, openAbout, showEditableJsonDialog } from './dialogs';
import { openSendReportDialog } from './reporting';
import { fallbackLng } from './i18n';
import { createSegment, getCleanCutSegments, getSegApparentStart, findSegmentsAtCursor, sortSegments, invertSegments, getSegmentTags, getOutSegError as getOutSegErrorRaw } from './segments';
import { createSegment, getCleanCutSegments, getSegApparentStart, findSegmentsAtCursor, sortSegments, invertSegments, getSegmentTags } from './segments';
import { getOutSegError as getOutSegErrorRaw } from './util/outputNameTemplate';
const isDev = window.require('electron-is-dev');

@ -1,11 +1,5 @@
import { v4 as uuidv4 } from 'uuid';
import sortBy from 'lodash/sortBy';
import i18n from 'i18next';
import { isMac, isWindows, hasDuplicates } from './util';
const { sep: pathSep, join: pathJoin, normalize: pathNormalize } = window.require('path');
const isDev = window.require('electron-is-dev');
export const createSegment = ({ start, end, name, tags, segIndex } = {}) => ({
start,
@ -86,45 +80,3 @@ export function invertSegments(sortedCutSegments, duration) {
// https://github.com/mifi/lossless-cut/issues/909
return ret.filter(({ start, end }) => end == null || start == null || end > start);
}
export function getOutSegError({ fileNames, filePath, outputDir }) {
if (hasDuplicates(fileNames)) return i18n.t('Template results in duplicate file names');
let error;
// eslint-disable-next-line no-restricted-syntax
for (const fileName of fileNames) {
if (!filePath) {
error = 'No file path';
break;
}
const invalidChars = [pathSep];
// Colon is invalid on windows https://github.com/mifi/lossless-cut/issues/631 and on MacOS, but not Linux https://github.com/mifi/lossless-cut/issues/830
if (isMac || isWindows) invalidChars.push(':');
const outPath = pathNormalize(pathJoin(outputDir, fileName));
const sameAsInputPath = outPath === pathNormalize(filePath);
const windowsMaxPathLength = 259;
const shouldCheckPathLength = isWindows || isDev;
if (fileName.length === 0) {
error = i18n.t('At least one resulting file name has no length');
break;
}
if (invalidChars.some((c) => fileName.includes(c))) {
error = i18n.t('At least one resulting file name contains invalid characters');
break;
}
if (sameAsInputPath) {
error = i18n.t('At least one resulting file name is the same as the input path');
break;
}
if (shouldCheckPathLength && outPath.length >= windowsMaxPathLength) {
error = i18n.t('At least one resulting file will have a too long path');
break;
}
}
return error;
}

@ -0,0 +1,49 @@
import i18n from 'i18next';
import { isMac, isWindows, hasDuplicates } from '../util';
const { sep: pathSep, join: pathJoin, normalize: pathNormalize } = window.require('path');
const isDev = window.require('electron-is-dev');
// eslint-disable-next-line import/prefer-default-export
export function getOutSegError({ fileNames, filePath, outputDir }) {
if (hasDuplicates(fileNames)) return i18n.t('Template results in duplicate file names');
let error;
// eslint-disable-next-line no-restricted-syntax
for (const fileName of fileNames) {
if (!filePath) {
error = 'No file path';
break;
}
const invalidChars = [pathSep];
// Colon is invalid on windows https://github.com/mifi/lossless-cut/issues/631 and on MacOS, but not Linux https://github.com/mifi/lossless-cut/issues/830
if (isMac || isWindows) invalidChars.push(':');
const outPath = pathNormalize(pathJoin(outputDir, fileName));
const sameAsInputPath = outPath === pathNormalize(filePath);
const windowsMaxPathLength = 259;
const shouldCheckPathLength = isWindows || isDev;
if (fileName.length === 0) {
error = i18n.t('At least one resulting file name has no length');
break;
}
if (invalidChars.some((c) => fileName.includes(c))) {
error = i18n.t('At least one resulting file name contains invalid characters');
break;
}
if (sameAsInputPath) {
error = i18n.t('At least one resulting file name is the same as the input path');
break;
}
if (shouldCheckPathLength && outPath.length >= windowsMaxPathLength) {
error = i18n.t('At least one resulting file will have a too long path');
break;
}
}
return error;
}
Loading…
Cancel
Save