13
0

Disambiguate export filename early on

When exporting multiple formats with identical filename
extension for the same time-span, the format-name needs
to be added.

Previously that was done internally when starting to export.
The Export-Dialog did not show correct filenames nor
warn of existing files that will be overwritten.
This commit is contained in:
Robin Gareus 2021-04-08 06:34:28 +02:00
parent 75829d20f2
commit df47da4e55
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
3 changed files with 48 additions and 2 deletions

View File

@ -187,6 +187,7 @@ ExportFilename::get_path (ExportFormatSpecPtr format) const
&& !include_revision
&& !include_timespan
&& !include_channel_config
&& !include_format_name
&& !include_channel
&& !include_date) {
with_timespan = true;

View File

@ -237,15 +237,19 @@ ExportHandler::handle_duplicate_format_extensions()
ExtCountMap counts;
for (ConfigMap::iterator it = timespan_bounds.first; it != timespan_bounds.second; ++it) {
std::string pfx;
if (it->second.filename->include_timespan) {
pfx = it->first->name();
}
if (it->second.filename->include_channel_config && it->second.channel_config) {
/* stem-export has multiple files in the same timestamp, but a different channel_config for each.
* However channel_config is only set in ExportGraphBuilder::Encoder::init_writer()
* so we cannot yet use it->second.filename->get_path(it->second.format).
* We have to explicily check uniqueness of "channel-config + extension" here:
*/
counts[it->second.channel_config->name() + it->second.format->extension()]++;
counts[pfx + it->second.channel_config->name() + it->second.format->extension()]++;
} else {
counts[it->second.format->extension()]++;
counts[pfx + it->second.format->extension()]++;
}
}
@ -256,6 +260,7 @@ ExportHandler::handle_duplicate_format_extensions()
// Set this always, as the filenames are shared...
for (ConfigMap::iterator it = timespan_bounds.first; it != timespan_bounds.second; ++it) {
assert (it->second.filename->include_format_name == duplicates_found);
it->second.filename->include_format_name = duplicates_found;
}
}

View File

@ -888,6 +888,46 @@ ExportProfileManager::get_warnings ()
/*** Check files ***/
/* handle_duplicate_format_extensions */
for (TimespanList::iterator t1 = timespans->begin(); t1 != timespans->end(); ++t1) {
typedef std::map<std::string, int> ExtCountMap;
ExtCountMap counts;
FormatStateList::const_iterator format_it;
FilenameStateList::const_iterator filename_it;
for (format_it = formats.begin(), filename_it = filenames.begin();
format_it != formats.end() && filename_it != filenames.end();
++format_it, ++filename_it) {
ExportFilenamePtr filename = (*filename_it)->filename;
filename->include_channel_config = (_type == StemExport) || (channel_configs.size() > 1);
for(ChannelConfigStateList::iterator cc_it = channel_configs.begin(); cc_it != channel_configs.end(); ++cc_it) {
if (filename->include_channel_config && (*cc_it)->config) {
counts[(*cc_it)->config->name() + (*format_it)->format->extension()]++;
} else {
counts[(*format_it)->format->extension()]++;
}
}
}
bool duplicates_found = false;
for (ExtCountMap::iterator it = counts.begin(); it != counts.end(); ++it) {
if (it->second > 1) {
duplicates_found = true;
}
}
for (format_it = formats.begin(), filename_it = filenames.begin();
format_it != formats.end() && filename_it != filenames.end();
++format_it, ++filename_it) {
ExportFilenamePtr filename = (*filename_it)->filename;
filename->include_format_name = duplicates_found;
}
}
bool folder_ok = true;
if (channel_config_state) {