have an option to save temp files on different drive (#110)

This commit is contained in:
death-claw
2023-09-01 00:09:49 +01:00
committed by GitHub
parent 70e7a87189
commit 206b305ae6
10 changed files with 36 additions and 12 deletions
@@ -4,10 +4,11 @@ import org.apache.http.client.protocol.HttpClientContext
import me.mnlr.vripper.SpringContext
import me.mnlr.vripper.entities.ImageDownloadState
import me.mnlr.vripper.entities.PostDownloadState
import me.mnlr.vripper.model.Settings
import me.mnlr.vripper.repositories.ImageRepository
import me.mnlr.vripper.repositories.PostDownloadStateRepository
class ImageDownloadContext(val imageId: Long) {
class ImageDownloadContext(val imageId: Long, val settings: Settings) {
private val imageRepository: ImageRepository =
SpringContext.getBean(ImageRepository::class.java)
@@ -30,7 +30,7 @@ class ImageDownloadRunnable(
private val dataTransaction: DataTransaction = SpringContext.getBean(DataTransaction::class.java)
private val pathService: PathService = SpringContext.getBean(PathService::class.java)
val context: ImageDownloadContext = ImageDownloadContext(imageInternalId)
val context: ImageDownloadContext = ImageDownloadContext(imageInternalId, settings)
private val image: ImageDownloadState
get() = context.image
private var stopped: Boolean
@@ -1,21 +1,19 @@
package me.mnlr.vripper.host
import org.apache.http.Header
import org.apache.http.client.HttpClient
import org.apache.http.client.methods.CloseableHttpResponse
import org.apache.http.client.protocol.HttpClientContext
import org.apache.http.util.EntityUtils
import org.w3c.dom.Document
import me.mnlr.vripper.delegate.LoggerDelegate
import me.mnlr.vripper.download.ImageDownloadContext
import me.mnlr.vripper.exception.DownloadException
import me.mnlr.vripper.exception.HostException
import me.mnlr.vripper.getFileNameWithoutExtension
import me.mnlr.vripper.services.*
import java.io.FileOutputStream
import org.apache.http.Header
import org.apache.http.client.HttpClient
import org.apache.http.client.methods.CloseableHttpResponse
import org.apache.http.client.protocol.HttpClientContext
import org.apache.http.util.EntityUtils
import org.w3c.dom.Document
import java.nio.file.Files
import java.nio.file.Path
import kotlin.io.path.pathString
abstract class Host(
private val httpService: HTTPService,
@@ -84,10 +82,10 @@ abstract class Host(
val mimeType = getImageMimeType(response.allHeaders)
?: throw HostException("Unsupported image type ${response.getFirstHeader("content-type")}")
val tempImage = Files.createTempFile("vripper", "tmp")
val tempImage = Files.createTempFile(Path.of(context.settings.downloadSettings.tempPath), "vripper_", ".tmp")
return response.entity.content.use { inputStream ->
try {
FileOutputStream(tempImage.pathString).use { fos ->
Files.newOutputStream(tempImage).use { fos ->
val image = context.image
image.total = response.entity.contentLength
dataTransaction.update(image)
@@ -18,6 +18,7 @@ data class ViperSettings(
data class DownloadSettings(
var downloadPath: String = System.getProperty("user.home"),
var tempPath: String = System.getProperty("java.io.tmpdir"),
var autoStart: Boolean = true,
var autoQueueThreshold: Int = 1,
var forceOrder: Boolean = false,
@@ -37,6 +37,7 @@ class SettingsController : Controller() {
settingsService.newSettings(Settings().apply {
downloadSettings = DownloadSettings(
downloadSettingsModel.downloadPath,
downloadSettingsModel.tempPath,
downloadSettingsModel.autoStart,
downloadSettingsModel.autoQueueThreshold,
downloadSettingsModel.forceOrder,
@@ -7,6 +7,9 @@ class DownloadSettingsModel {
val downloadPathProperty = SimpleStringProperty()
var downloadPath: String by downloadPathProperty
val tempPathProperty = SimpleStringProperty()
var tempPath: String by tempPathProperty
val autoStartProperty = SimpleBooleanProperty()
var autoStart: Boolean by autoStartProperty
@@ -13,6 +13,7 @@ class DownloadSettingsView : View("Download Settings") {
override fun onDock() {
val downloadSettings = settingsController.findDownloadSettings()
downloadSettingsModel.downloadPath = downloadSettings.downloadPath
downloadSettingsModel.tempPath = downloadSettings.tempPath
downloadSettingsModel.autoStart = downloadSettings.autoStart
downloadSettingsModel.autoQueueThreshold = downloadSettings.autoQueueThreshold
downloadSettingsModel.forceOrder = downloadSettings.forceOrder
@@ -38,6 +39,19 @@ class DownloadSettingsView : View("Download Settings") {
}
}
}
field("Temporary Path") {
textfield(downloadSettingsModel.tempPathProperty) {
isEditable = false
}
button("Browse") {
action {
val directory = chooseDirectory(title = "Select temporary folder")
if(directory != null) {
downloadSettingsModel.tempPathProperty.set(directory.path)
}
}
}
}
field("Auto start downloads") {
checkbox {
bind(downloadSettingsModel.autoStartProperty)
@@ -14,6 +14,7 @@ export interface ConnectionSettings {
export interface DownloadSettings {
downloadPath: string;
tempPath: string;
autoStart: boolean;
autoQueueThreshold: number;
forceOrder: boolean;
@@ -22,6 +22,10 @@
name="downloadPath"
required />
</mat-form-field>
<mat-form-field appearance="outline">
<mat-label>Temporary Path</mat-label>
<input formControlName="tempPath" matInput name="tempPath" required />
</mat-form-field>
<mat-form-field appearance="outline">
<mat-label
@@ -62,6 +62,7 @@ export class SettingsComponent {
downloadSettingsForm = new FormGroup({
downloadPath: new FormControl(''),
tempPath: new FormControl(''),
autoStart: new FormControl(false),
autoQueueThreshold: new FormControl(0),
forceOrder: new FormControl(false),