@ -1,6 +1,6 @@
import React , { memo , useState , useCallback , useEffect , useMemo } from 'react' ;
import { useTranslation } from 'react-i18next' ;
import { IconButton, Alert , Checkbox , Dialog , Button , Paragraph } from 'evergreen-ui' ;
import { TextInput, IconButton, Alert , Checkbox , Dialog , Button , Paragraph } from 'evergreen-ui' ;
import { AiOutlineMergeCells } from 'react-icons/ai' ;
import { FaQuestionCircle , FaCheckCircle , FaExclamationTriangle } from 'react-icons/fa' ;
import i18n from 'i18next' ;
@ -12,6 +12,7 @@ import useFileFormatState from '../hooks/useFileFormatState';
import OutputFormatSelect from './OutputFormatSelect' ;
import useUserSettings from '../hooks/useUserSettings' ;
import { isMov } from '../util/streams' ;
import { getOutFileExtension , getFileBaseName } from '../util' ;
const { basename } = window . require ( 'path' ) ;
@ -36,6 +37,8 @@ const ConcatDialog = memo(({
const [ clearBatchFilesAfterConcat , setClearBatchFilesAfterConcat ] = useState ( false ) ;
const [ settingsVisible , setSettingsVisible ] = useState ( false ) ;
const [ enableReadFileMeta , setEnableReadFileMeta ] = useState ( false ) ;
const [ outFileName , setOutFileName ] = useState ( ) ;
const [ uniqueSuffix , setUniqueSuffix ] = useState ( ) ;
const { fileFormat , setFileFormat , detectedFileFormat , setDetectedFileFormat , isCustomFormatSelected } = useFileFormatState ( ) ;
@ -53,12 +56,14 @@ const ConcatDialog = memo(({
setFileMeta ( ) ;
setFileFormat ( ) ;
setDetectedFileFormat ( ) ;
setOutFileName ( ) ;
const fileMetaNew = await readFileMeta ( firstPath ) ;
const fileFormatNew = await getSmarterOutFormat ( { filePath : firstPath , fileMeta : fileMetaNew } ) ;
if ( aborted ) return ;
setFileMeta ( fileMetaNew ) ;
setFileFormat ( fileFormatNew ) ;
setDetectedFileFormat ( fileFormatNew ) ;
setUniqueSuffix ( new Date ( ) . getTime ( ) ) ;
} ) ( ) . catch ( console . error ) ;
return ( ) => {
@ -66,12 +71,23 @@ const ConcatDialog = memo(({
} ;
} , [ firstPath , isShown , setDetectedFileFormat , setFileFormat ] ) ;
useEffect ( ( ) => {
if ( fileFormat == null || firstPath == null ) {
setOutFileName ( ) ;
return ;
}
const ext = getOutFileExtension ( { isCustomFormatSelected , outFormat : fileFormat , filePath : firstPath } ) ;
setOutFileName ( ` ${ getFileBaseName ( firstPath ) } -merged- ${ uniqueSuffix } ${ ext } ` ) ;
} , [ fileFormat , firstPath , isCustomFormatSelected , uniqueSuffix ] ) ;
const allFilesMeta = useMemo ( ( ) => {
if ( paths . length === 0 ) return undefined ;
const filtered = paths . map ( ( path ) => [ path , allFilesMetaCache [ path ] ] ) . filter ( ( [ , it ] ) => it ) ;
return filtered . length === paths . length ? filtered : undefined ;
} , [ allFilesMetaCache , paths ] ) ;
const isOutFileNameValid = outFileName != null && outFileName . length > 0 ;
const problemsByFile = useMemo ( ( ) => {
if ( ! allFilesMeta ) return [ ] ;
const allFilesMetaExceptFirstFile = allFilesMeta . slice ( 1 ) ;
@ -136,7 +152,7 @@ const ConcatDialog = memo(({
const onOutputFormatUserChange = useCallback ( ( newFormat ) => setFileFormat ( newFormat ) , [ setFileFormat ] ) ;
const onConcatClick = useCallback ( ( ) => onConcat ( { paths , includeAllStreams , streams : fileMeta . streams , file Format, isCustomFormatSelected , clearBatchFilesAfterConcat } ) , [ clearBatchFilesAfterConcat , fileFormat , fileMeta , includeAllStreams , isCustomFormatSelected, onConcat , paths ] ) ;
const onConcatClick = useCallback ( ( ) => onConcat ( { paths , includeAllStreams , streams : fileMeta . streams , file Name: outFileName , fileFormat , clearBatchFilesAfterConcat } ) , [ clearBatchFilesAfterConcat , fileFormat , fileMeta , includeAllStreams , onConcat, outFileName , paths ] ) ;
return (
< >
@ -147,16 +163,22 @@ const ConcatDialog = memo(({
topOffset = "3vh"
width = "90vw"
footer = { (
< div style = { { display : 'flex' , alignItems : 'center' } } >
< Checkbox checked = { enableReadFileMeta } onChange = { ( e ) => setEnableReadFileMeta ( e . target . checked ) } label = { t ( 'Check files' ) } marginLeft = { 10 } marginRight = { 10 } / >
< Button iconBefore = { FaCheckCircle } onClick = { ( ) => setSettingsVisible ( true ) } > { t ( 'Options' ) } < / Button >
{ fileFormat && detectedFileFormat ? (
< OutputFormatSelect style = { { maxWidth : 180 } } detectedFileFormat = { detectedFileFormat } fileFormat = { fileFormat } onOutputFormatUserChange = { onOutputFormatUserChange } / >
) : (
< Button disabled isLoading > { t ( 'Loading' ) } < / Button >
) }
< Button iconBefore = { < AiOutlineMergeCells / > } isLoading = { detectedFileFormat == null } appearance = "primary" onClick = { onConcatClick } > { t ( 'Merge!' ) } < / Button >
< / div >
< >
< div style = { { display : 'flex' , alignItems : 'center' , flexWrap : 'wrap' , justifyContent : 'flex-end' } } >
< Checkbox checked = { enableReadFileMeta } onChange = { ( e ) => setEnableReadFileMeta ( e . target . checked ) } label = { t ( 'Check files' ) } marginLeft = { 10 } marginRight = { 10 } / >
< Button iconBefore = { FaCheckCircle } onClick = { ( ) => setSettingsVisible ( true ) } > { t ( 'Options' ) } < / Button >
{ fileFormat && detectedFileFormat ? (
< OutputFormatSelect style = { { maxWidth : 180 } } detectedFileFormat = { detectedFileFormat } fileFormat = { fileFormat } onOutputFormatUserChange = { onOutputFormatUserChange } / >
) : (
< Button disabled isLoading > { t ( 'Loading' ) } < / Button >
) }
< Button iconBefore = { < AiOutlineMergeCells / > } isLoading = { detectedFileFormat == null } disabled = { ! isOutFileNameValid } appearance = "primary" onClick = { onConcatClick } > { t ( 'Merge!' ) } < / Button >
< / div >
< div style = { { display : 'flex' , alignItems : 'center' , flexWrap : 'wrap' , justifyContent : 'flex-end' } } >
< Paragraph marginRight = ".5em" > { t ( 'Output file name' ) } : < / Paragraph >
< TextInput value = { outFileName || '' } onChange = { ( e ) => setOutFileName ( e . target . value ) } / >
< / div >
< / >
) }
>
< div style = { containerStyle } >