mirror of https://github.com/zlatinb/muwire
add ability to choose the incompletes location
parent
d954387e41
commit
ab323db62a
|
@ -22,6 +22,7 @@ class MuWireSettings {
|
||||||
String updateType
|
String updateType
|
||||||
String nickname
|
String nickname
|
||||||
File downloadLocation
|
File downloadLocation
|
||||||
|
File incompleteLocation
|
||||||
CrawlerResponse crawlerResponse
|
CrawlerResponse crawlerResponse
|
||||||
boolean shareDownloadedFiles
|
boolean shareDownloadedFiles
|
||||||
boolean shareHiddenFiles
|
boolean shareHiddenFiles
|
||||||
|
@ -50,6 +51,9 @@ class MuWireSettings {
|
||||||
nickname = props.getProperty("nickname","MuWireUser")
|
nickname = props.getProperty("nickname","MuWireUser")
|
||||||
downloadLocation = new File((String)props.getProperty("downloadLocation",
|
downloadLocation = new File((String)props.getProperty("downloadLocation",
|
||||||
System.getProperty("user.home")))
|
System.getProperty("user.home")))
|
||||||
|
String incompleteLocationProp = props.getProperty("incompleteLocation")
|
||||||
|
if (incompleteLocationProp != null)
|
||||||
|
incompleteLocation = new File(incompleteLocationProp)
|
||||||
downloadRetryInterval = Integer.parseInt(props.getProperty("downloadRetryInterval","60"))
|
downloadRetryInterval = Integer.parseInt(props.getProperty("downloadRetryInterval","60"))
|
||||||
updateCheckInterval = Integer.parseInt(props.getProperty("updateCheckInterval","24"))
|
updateCheckInterval = Integer.parseInt(props.getProperty("updateCheckInterval","24"))
|
||||||
autoDownloadUpdate = Boolean.parseBoolean(props.getProperty("autoDownloadUpdate","true"))
|
autoDownloadUpdate = Boolean.parseBoolean(props.getProperty("autoDownloadUpdate","true"))
|
||||||
|
@ -91,6 +95,8 @@ class MuWireSettings {
|
||||||
props.setProperty("crawlerResponse", crawlerResponse.toString())
|
props.setProperty("crawlerResponse", crawlerResponse.toString())
|
||||||
props.setProperty("nickname", nickname)
|
props.setProperty("nickname", nickname)
|
||||||
props.setProperty("downloadLocation", downloadLocation.getAbsolutePath())
|
props.setProperty("downloadLocation", downloadLocation.getAbsolutePath())
|
||||||
|
if (incompleteLocation != null)
|
||||||
|
props.setProperty("incompleteLocation", incompleteLocation.getAbsolutePath())
|
||||||
props.setProperty("downloadRetryInterval", String.valueOf(downloadRetryInterval))
|
props.setProperty("downloadRetryInterval", String.valueOf(downloadRetryInterval))
|
||||||
props.setProperty("updateCheckInterval", String.valueOf(updateCheckInterval))
|
props.setProperty("updateCheckInterval", String.valueOf(updateCheckInterval))
|
||||||
props.setProperty("autoDownloadUpdate", String.valueOf(autoDownloadUpdate))
|
props.setProperty("autoDownloadUpdate", String.valueOf(autoDownloadUpdate))
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class DownloadManager {
|
||||||
private final MuWireSettings muSettings
|
private final MuWireSettings muSettings
|
||||||
private final I2PConnector connector
|
private final I2PConnector connector
|
||||||
private final Executor executor
|
private final Executor executor
|
||||||
private final File incompletes, home
|
private final File home
|
||||||
private final Persona me
|
private final Persona me
|
||||||
|
|
||||||
private final Map<InfoHash, Downloader> downloaders = new ConcurrentHashMap<>()
|
private final Map<InfoHash, Downloader> downloaders = new ConcurrentHashMap<>()
|
||||||
|
@ -46,12 +46,9 @@ public class DownloadManager {
|
||||||
this.meshManager = meshManager
|
this.meshManager = meshManager
|
||||||
this.muSettings = muSettings
|
this.muSettings = muSettings
|
||||||
this.connector = connector
|
this.connector = connector
|
||||||
this.incompletes = new File(home,"incompletes")
|
|
||||||
this.home = home
|
this.home = home
|
||||||
this.me = me
|
this.me = me
|
||||||
|
|
||||||
incompletes.mkdir()
|
|
||||||
|
|
||||||
this.executor = Executors.newCachedThreadPool({ r ->
|
this.executor = Executors.newCachedThreadPool({ r ->
|
||||||
Thread rv = new Thread(r)
|
Thread rv = new Thread(r)
|
||||||
rv.setName("download-worker")
|
rv.setName("download-worker")
|
||||||
|
@ -63,6 +60,11 @@ public class DownloadManager {
|
||||||
|
|
||||||
public void onUIDownloadEvent(UIDownloadEvent e) {
|
public void onUIDownloadEvent(UIDownloadEvent e) {
|
||||||
|
|
||||||
|
File incompletes = muSettings.incompleteLocation
|
||||||
|
if (incompletes == null)
|
||||||
|
incompletes = new File(home, "incompletes")
|
||||||
|
incompletes.mkdirs()
|
||||||
|
|
||||||
def size = e.result[0].size
|
def size = e.result[0].size
|
||||||
def infohash = e.result[0].infohash
|
def infohash = e.result[0].infohash
|
||||||
def pieceSize = e.result[0].pieceSize
|
def pieceSize = e.result[0].pieceSize
|
||||||
|
@ -126,6 +128,10 @@ public class DownloadManager {
|
||||||
boolean sequential = false
|
boolean sequential = false
|
||||||
if (json.sequential != null)
|
if (json.sequential != null)
|
||||||
sequential = json.sequential
|
sequential = json.sequential
|
||||||
|
|
||||||
|
File incompletes = this.incompletes
|
||||||
|
if (json.incompletes != null)
|
||||||
|
incompletes = new File(DataUtil.readi18nString(Base64.decode(json.incompletes)))
|
||||||
|
|
||||||
Pieces pieces = getPieces(infoHash, (long)json.length, json.pieceSizePow2, sequential)
|
Pieces pieces = getPieces(infoHash, (long)json.length, json.pieceSizePow2, sequential)
|
||||||
|
|
||||||
|
@ -195,6 +201,8 @@ public class DownloadManager {
|
||||||
|
|
||||||
json.sequential = downloader.pieces.ratio == 0f
|
json.sequential = downloader.pieces.ratio == 0f
|
||||||
|
|
||||||
|
json.incompletes = Base64.encode(DataUtil.encodei18nString(downloader.incompletes.getAbsolutePath()))
|
||||||
|
|
||||||
writer.println(JsonOutput.toJson(json))
|
writer.println(JsonOutput.toJson(json))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,7 @@ public class Downloader {
|
||||||
private final I2PConnector connector
|
private final I2PConnector connector
|
||||||
private final Set<Destination> destinations
|
private final Set<Destination> destinations
|
||||||
private final int nPieces
|
private final int nPieces
|
||||||
|
private final File incompletes
|
||||||
private final File piecesFile
|
private final File piecesFile
|
||||||
private final File incompleteFile
|
private final File incompleteFile
|
||||||
final int pieceSizePow2
|
final int pieceSizePow2
|
||||||
|
@ -76,6 +77,7 @@ public class Downloader {
|
||||||
this.length = length
|
this.length = length
|
||||||
this.connector = connector
|
this.connector = connector
|
||||||
this.destinations = destinations
|
this.destinations = destinations
|
||||||
|
this.incompletes = incompletes
|
||||||
this.piecesFile = new File(incompletes, file.getName()+".pieces")
|
this.piecesFile = new File(incompletes, file.getName()+".pieces")
|
||||||
this.incompleteFile = new File(incompletes, file.getName()+".part")
|
this.incompleteFile = new File(incompletes, file.getName()+".part")
|
||||||
this.pieceSizePow2 = pieceSizePow2
|
this.pieceSizePow2 = pieceSizePow2
|
||||||
|
|
|
@ -93,6 +93,9 @@ class OptionsController {
|
||||||
|
|
||||||
String downloadLocation = model.downloadLocation
|
String downloadLocation = model.downloadLocation
|
||||||
settings.downloadLocation = new File(downloadLocation)
|
settings.downloadLocation = new File(downloadLocation)
|
||||||
|
|
||||||
|
String incompleteLocation = model.incompleteLocation
|
||||||
|
settings.incompleteLocation = new File(incompleteLocation)
|
||||||
|
|
||||||
if (settings.embeddedRouter) {
|
if (settings.embeddedRouter) {
|
||||||
text = view.inBwField.text
|
text = view.inBwField.text
|
||||||
|
@ -174,7 +177,18 @@ class OptionsController {
|
||||||
int rv = chooser.showOpenDialog(null)
|
int rv = chooser.showOpenDialog(null)
|
||||||
if (rv == JFileChooser.APPROVE_OPTION)
|
if (rv == JFileChooser.APPROVE_OPTION)
|
||||||
model.downloadLocation = chooser.getSelectedFile().getAbsolutePath()
|
model.downloadLocation = chooser.getSelectedFile().getAbsolutePath()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ControllerAction
|
||||||
|
void incompleteLocation() {
|
||||||
|
def chooser = new JFileChooser()
|
||||||
|
chooser.setFileHidingEnabled(false)
|
||||||
|
chooser.setDialogTitle("Select location for downloaded files")
|
||||||
|
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY)
|
||||||
|
int rv = chooser.showOpenDialog(null)
|
||||||
|
if (rv == JFileChooser.APPROVE_OPTION)
|
||||||
|
model.incompleteLocation = chooser.getSelectedFile().getAbsolutePath()
|
||||||
|
}
|
||||||
|
|
||||||
@ControllerAction
|
@ControllerAction
|
||||||
void automaticFontAction() {
|
void automaticFontAction() {
|
||||||
|
|
|
@ -45,9 +45,12 @@ class Ready extends AbstractLifecycleHandler {
|
||||||
props.load(it)
|
props.load(it)
|
||||||
}
|
}
|
||||||
props = new MuWireSettings(props)
|
props = new MuWireSettings(props)
|
||||||
|
if (props.incompleteLocation == null)
|
||||||
|
props.incompleteLocation = new File(home, "incompletes")
|
||||||
} else {
|
} else {
|
||||||
log.info("creating new properties")
|
log.info("creating new properties")
|
||||||
props = new MuWireSettings()
|
props = new MuWireSettings()
|
||||||
|
props.incompleteLocation = new File(home, "incompletes")
|
||||||
props.embeddedRouter = Boolean.parseBoolean(System.getProperties().getProperty("embeddedRouter"))
|
props.embeddedRouter = Boolean.parseBoolean(System.getProperties().getProperty("embeddedRouter"))
|
||||||
props.updateType = System.getProperty("updateType","jar")
|
props.updateType = System.getProperty("updateType","jar")
|
||||||
def nickname
|
def nickname
|
||||||
|
|
|
@ -15,6 +15,7 @@ class OptionsModel {
|
||||||
@Observable boolean shareDownloadedFiles
|
@Observable boolean shareDownloadedFiles
|
||||||
@Observable boolean shareHiddenFiles
|
@Observable boolean shareHiddenFiles
|
||||||
@Observable String downloadLocation
|
@Observable String downloadLocation
|
||||||
|
@Observable String incompleteLocation
|
||||||
@Observable boolean searchComments
|
@Observable boolean searchComments
|
||||||
@Observable boolean browseFiles
|
@Observable boolean browseFiles
|
||||||
|
|
||||||
|
@ -56,6 +57,7 @@ class OptionsModel {
|
||||||
shareDownloadedFiles = settings.shareDownloadedFiles
|
shareDownloadedFiles = settings.shareDownloadedFiles
|
||||||
shareHiddenFiles = settings.shareHiddenFiles
|
shareHiddenFiles = settings.shareHiddenFiles
|
||||||
downloadLocation = settings.downloadLocation.getAbsolutePath()
|
downloadLocation = settings.downloadLocation.getAbsolutePath()
|
||||||
|
incompleteLocation = settings.incompleteLocation.getAbsolutePath()
|
||||||
searchComments = settings.searchComments
|
searchComments = settings.searchComments
|
||||||
browseFiles = settings.browseFiles
|
browseFiles = settings.browseFiles
|
||||||
|
|
||||||
|
|
|
@ -100,6 +100,10 @@ class OptionsView {
|
||||||
label(text : "Save downloaded files to:", constraints: gbc(gridx:0, gridy:7))
|
label(text : "Save downloaded files to:", constraints: gbc(gridx:0, gridy:7))
|
||||||
button(text : "Choose", constraints : gbc(gridx : 1, gridy:7), downloadLocationAction)
|
button(text : "Choose", constraints : gbc(gridx : 1, gridy:7), downloadLocationAction)
|
||||||
label(text : bind {model.downloadLocation}, constraints: gbc(gridx:0, gridy:8, gridwidth:2))
|
label(text : bind {model.downloadLocation}, constraints: gbc(gridx:0, gridy:8, gridwidth:2))
|
||||||
|
|
||||||
|
label(text : "Store incomplete files in:", constraints: gbc(gridx:0, gridy:9))
|
||||||
|
button(text : "Choose", constraints : gbc(gridx : 1, gridy:9), incompleteLocationAction)
|
||||||
|
label(text : bind {model.incompleteLocation}, constraints: gbc(gridx:0, gridy:10, gridwidth:2))
|
||||||
|
|
||||||
}
|
}
|
||||||
i = builder.panel {
|
i = builder.panel {
|
||||||
|
|
Loading…
Reference in New Issue