1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-08-13 17:03:45 -04:00

* try to make sure we always start a new cache for each update (so we don't have to worry about outdated yet cached data)

This commit is contained in:
Reinhard Pointner 2014-01-13 04:11:05 +00:00
parent 50a92d3faa
commit bb32741af9
3 changed files with 36 additions and 3 deletions

View File

@ -1,3 +1,5 @@
Invoke-Expression 'filebot -clear-cache'
$app = Get-WmiObject -Query "SELECT * FROM Win32_Product WHERE Name = 'FileBot'"
echo $app

View File

@ -312,6 +312,10 @@ Section "$(Section_Name_MainProduct)" SECTIONID_MAINPRODUCT
Pop $MSI_STATUS # grab return value
${if} $MSI_STATUS == "0"
DetailPrint "Clear cache and temporary files"
nsExec::Exec `"C:\Program Files\FileBot\filebot.exe" -clear-cache`
nsExec::Exec `"C:\Program Files\FileBot\filebot.exe" -script "g:net.sourceforge.filebot.Main.warmupCachedResources()"`
# [OpenCandy]
; This section is hidden. It will always execute during installation
; but it won't appear on your component selection screen.
@ -320,7 +324,7 @@ Section "$(Section_Name_MainProduct)" SECTIONID_MAINPRODUCT
# [/OpenCandy]
${else}
DetailPrint "msiexec error $MSI_STATUS"
DetailPrint "Install failed."
DetailPrint "Install failed. Please download the .msi package manually."
Abort
${endif}
SectionEnd

View File

@ -23,6 +23,7 @@ import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.nio.charset.Charset;
import java.security.CodeSource;
import java.security.Permission;
import java.security.PermissionCollection;
@ -34,6 +35,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -458,13 +460,38 @@ public class Main {
throw new IOException("Failed to create cache dir: " + cache);
}
File lockFile = new File(cache, ".lock");
final File lockFile = new File(cache, ".lock");
final RandomAccessFile handle = new RandomAccessFile(lockFile, "rw");
final FileLock lock = handle.getChannel().tryLock();
final FileChannel channel = handle.getChannel();
final FileLock lock = channel.tryLock();
if (lock != null) {
// setup cache dir for ehcache
System.setProperty("ehcache.disk.store.dir", cache.getAbsolutePath());
int applicationRevision = getApplicationRevisionNumber();
int cacheRevision = 0;
try {
cacheRevision = new Scanner(channel, "UTF-8").nextInt();
} catch (Exception e) {
// ignore
}
if (cacheRevision != applicationRevision && applicationRevision > 0) {
System.out.format("Application (r%d) does not match cache (r%d): reset cache%n", applicationRevision, cacheRevision);
// delete all files related to previous cache instances
for (File it : cache.listFiles()) {
if (!it.equals(lockFile)) {
delete(cache);
}
}
// set new cache revision
channel.position(0);
channel.write(Charset.forName("UTF-8").encode(String.valueOf(applicationRevision)));
channel.truncate(channel.position());
}
// make sure to orderly shutdown cache
Runtime.getRuntime().addShutdownHook(new Thread() {