mirror of https://github.com/zlatinb/muwire
persistence of WatchedDirectory object
parent
f0c8c11094
commit
244ce43794
|
@ -1,9 +1,37 @@
|
||||||
package com.muwire.core.files.directories
|
package com.muwire.core.files.directories
|
||||||
|
|
||||||
|
import com.muwire.core.util.DataUtil
|
||||||
|
|
||||||
|
import net.i2p.data.Base64
|
||||||
|
|
||||||
class WatchedDirectory {
|
class WatchedDirectory {
|
||||||
File directory
|
final File directory
|
||||||
|
final String encodedName
|
||||||
boolean autoWatch
|
boolean autoWatch
|
||||||
int syncInterval
|
int syncInterval
|
||||||
long lastSync
|
long lastSync
|
||||||
|
|
||||||
|
WatchedDirectory(File directory) {
|
||||||
|
this.directory = directory.getCanonicalFile()
|
||||||
|
this.encodedName = Base64.encode(DataUtil.encodei18nString(directory.getAbsolutePath()))
|
||||||
|
}
|
||||||
|
|
||||||
|
def toJson() {
|
||||||
|
def rv = [:]
|
||||||
|
rv.directory = encodedName
|
||||||
|
rv.autoWatch = autoWatch
|
||||||
|
rv.syncInterval = syncInterval
|
||||||
|
rv.lastSync = lastSync
|
||||||
|
rv
|
||||||
|
}
|
||||||
|
|
||||||
|
static WatchedDirectory fromJson(def json) {
|
||||||
|
String dirName = DataUtil.readi18nString(Base64.decode(json.directory))
|
||||||
|
File dir = new File(dirName)
|
||||||
|
def rv = new WatchedDirectory(dir)
|
||||||
|
rv.autoWatch = json.autoWatch
|
||||||
|
rv.syncInterval = json.syncInterval
|
||||||
|
rv.lastSync = json.lastSync
|
||||||
|
rv
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,5 +3,7 @@ package com.muwire.core.files.directories
|
||||||
import com.muwire.core.Event
|
import com.muwire.core.Event
|
||||||
|
|
||||||
class WatchedDirectoryConfigurationEvent extends Event {
|
class WatchedDirectoryConfigurationEvent extends Event {
|
||||||
WatchedDirectory directory
|
File directory
|
||||||
|
boolean autoWatch
|
||||||
|
int syncInterval
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,7 @@ class WatchedDirectoryConverter {
|
||||||
core.getMuOptions().getWatchedDirectories().each {
|
core.getMuOptions().getWatchedDirectories().each {
|
||||||
File directory = new File(it)
|
File directory = new File(it)
|
||||||
directory = directory.getCanonicalFile()
|
directory = directory.getCanonicalFile()
|
||||||
WatchedDirectory watched = new WatchedDirectory(directory : directory, autoWatch : true)
|
core.eventBus.publish(new WatchedDirectoryConfigurationEvent(directory : directory, autoWatch: true))
|
||||||
core.eventBus.publish(new WatchedDirectoryConfigurationEvent(directory : watched))
|
|
||||||
}
|
}
|
||||||
core.getMuOptions().getWatchedDirectories().clear()
|
core.getMuOptions().getWatchedDirectories().clear()
|
||||||
core.saveMuSettings()
|
core.saveMuSettings()
|
||||||
|
|
|
@ -13,7 +13,6 @@ class WatchedDirectoryManager {
|
||||||
private final EventBus eventBus
|
private final EventBus eventBus
|
||||||
private final FileManager fileManager
|
private final FileManager fileManager
|
||||||
|
|
||||||
|
|
||||||
private final ExecutorService diskIO = Executors.newSingleThreadExecutor({r ->
|
private final ExecutorService diskIO = Executors.newSingleThreadExecutor({r ->
|
||||||
Thread t = new Thread(r, "disk-io")
|
Thread t = new Thread(r, "disk-io")
|
||||||
t.setDaemon(true)
|
t.setDaemon(true)
|
||||||
|
@ -22,8 +21,10 @@ class WatchedDirectoryManager {
|
||||||
|
|
||||||
private final Timer timer = new Timer("directory-timer", true)
|
private final Timer timer = new Timer("directory-timer", true)
|
||||||
|
|
||||||
|
private boolean converting = true
|
||||||
|
|
||||||
WatchedDirectoryManager(File home, EventBus eventBus, FileManager fileManager) {
|
WatchedDirectoryManager(File home, EventBus eventBus, FileManager fileManager) {
|
||||||
this.home = home
|
this.home = new File(home, "directories")
|
||||||
this.eventBus = eventBus
|
this.eventBus = eventBus
|
||||||
this.fileManager = fileManager
|
this.fileManager = fileManager
|
||||||
}
|
}
|
||||||
|
@ -34,10 +35,15 @@ class WatchedDirectoryManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
void onWatchedDirectoryConfigurationEvent(WatchedDirectoryConfigurationEvent e) {
|
void onWatchedDirectoryConfigurationEvent(WatchedDirectoryConfigurationEvent e) {
|
||||||
// persist
|
if (!converting) {
|
||||||
|
// update state
|
||||||
|
}
|
||||||
|
|
||||||
|
// always persist
|
||||||
}
|
}
|
||||||
|
|
||||||
void onWatchedDirectoryConvertedEvent(WatchedDirectoryConvertedEvent e) {
|
void onWatchedDirectoryConvertedEvent(WatchedDirectoryConvertedEvent e) {
|
||||||
|
converting = false
|
||||||
// load
|
// load
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue