try {
// Check whether this day program is known
int version = (int) file.length();
int knownStatus = mTvDataInventory.getKnownStatus(date, channel, version);
OnDemandDayProgramFile oldProgFile = getCacheEntry(date, channel, false, false);
MutableChannelDayProgram checkProg = (MutableChannelDayProgram)getDayProgram(date,channel,true);
boolean somethingChanged = calculateMissingLengths(checkProg);
Object oldProg = null;
if((oldProg = mNewDayProgramsAfterUpdate.remove(key)) != null) {
// Inform the listeners about deleting the old program
if (oldProg instanceof ChannelDayProgram) {
fireDayProgramDeleted((ChannelDayProgram)oldProg);
}
// Inform the listeners about adding the new program
fireDayProgramAdded(checkProg);
}
else if(somethingChanged){
fireDayProgramAdded(checkProg);
}
if (checkProg.getAndResetChangedByPluginState() || somethingChanged) {
// Some missing lengths could now be calculated
// -> Try to save the changes
// We use a temporary file. If saving succeeds we rename it
File tempFile = new File(file.getAbsolutePath() + ".changed");
try {
// Try to save the changed program
OnDemandDayProgramFile newProgFile = new OnDemandDayProgramFile(
tempFile, checkProg);
newProgFile.saveDayProgram();
// Saving the changed version succeed -> Delete the original
file.delete();
// Use the changed version now
tempFile.renameTo(file);
// If the old version was known -> Set the new version to known too
if (knownStatus == TvDataInventory.KNOWN) {
version = (int) file.length();
mTvDataInventory.setKnown(date, channel, version);
}
} catch (Exception exc) {
// Saving the changes failed
// -> remove the temp file and keep the old one
tempFile.delete();
}
// We have to load the file again to get the new data positions
OnDemandDayProgramFile progFile = new OnDemandDayProgramFile(file, date, channel);
progFile.loadDayProgram(false);
// Invalidate the old program file from the cache
if (oldProgFile != null) {
oldProgFile.setValid(false);
// Remove the old entry from the cache (if it exists)
removeCacheEntry(key);
}
// Put the new program file in the real cache
addCacheEntry(key, progFile);
} else if(oldProgFile != null) {
oldProgFile.calculateTimeLimits();
}
// Inform the listeners about adding the new program
if(oldProg != null || somethingChanged) {
OnDemandDayProgramFile dayProgramFile = getCacheEntry(date, channel, true, false);
ChannelDayProgram dayProgram = dayProgramFile.getDayProgram();
if(oldProg instanceof ChannelDayProgram) {
fireDayProgramTouched((ChannelDayProgram)oldProg,dayProgram);
}
else {