File oldDir = null;
// move, rename and tag the audio files
for (int i = 0; i < count; i++) {
DataSet dataset = datasets.get(i);
MyFile oldFile = files.get(i);
File newFile = getNewFile(dataset, oldFile);
// store the old directory, so that we can delete
// it after renaming the files
oldDir = oldFile.getParentFile();
// change file state to renaming
oldFile.setRenaming();
notifyObservers();
notifyRowObservers(oldFile, i, RowObserver.UPDATE);
// move the file
try {
Ant.moveFile(oldFile, newFile);
} catch (BuildException e) {
oldFile.setFailed();
notifyObservers();
notifyRowObservers(oldFile, i, RowObserver.UPDATE);
logger.warn(I18N.translate("error.rename_file", new Object[] {oldFile, newFile}), e);
continue;
}
// update the file table
MyFile file = new MyFile(newFile);
files.set(i, file);
file.setOK();
// tag the file
FilePlugin plugin = suffixToPlugin.get(file.getSuffix());
try {
plugin.setMetaData(file, dataset);
} catch (Exception e) {
logger.warn("Couldn't save metadata to file", e);
file.setMetaFailed();
}
notifyObservers();
notifyRowObservers(file, i, RowObserver.UPDATE);
}