Fixes #1, Save All Sources does not work, zip file is not created

This commit is contained in:
emmanue1 2015-03-26 20:47:46 +01:00
parent 0934ee13a5
commit 19a6ca8054
4 changed files with 21 additions and 5 deletions

3
.gitignore vendored
View File

@ -27,3 +27,6 @@ target/
# Gradle
.gradle/
build/
# WinMerge
*.bak

View File

@ -36,8 +36,8 @@ class SaveAllSourcesController implements SourcesSavable.Controller, SourcesSava
// Show
this.saveAllSourcesView.show(file)
// Execute background task
executor.submit(new Callable<Void>() {
Void call() throws Exception {
executor.execute(new Runnable() {
void run() {
int fileCount = savable.fileCount
int quotient = (fileCount / 100)
@ -56,10 +56,15 @@ class SaveAllSourcesController implements SourcesSavable.Controller, SourcesSava
def path = Paths.get(file.toURI())
Files.deleteIfExists(path)
savable.save(api, this as SourcesSavable.Controller, this as SourcesSavable.Listener, path)
try {
savable.save(api, this as SourcesSavable.Controller, this as SourcesSavable.Listener, path)
} catch (Exception e) {
saveAllSourcesView.showActionFailedDialog()
cancel = true
}
if (cancel) {
Files.delete(path)
Files.deleteIfExists(path)
}
saveAllSourcesView.hide()

View File

@ -9,6 +9,8 @@ import groovy.swing.SwingBuilder
import jd.gui.api.API
import jd.gui.model.configuration.Configuration
import javax.swing.JDialog
import javax.swing.JOptionPane
import java.awt.event.WindowAdapter
import java.awt.event.WindowEvent
@ -73,4 +75,9 @@ class SaveAllSourcesView {
saveAllSourcesDialog.visible = false
}
}
void showActionFailedDialog() {
JOptionPane.showMessageDialog(
swing.saveAllSourcesDialog, '"Save All Sources" action failed.', 'Error', JOptionPane.ERROR_MESSAGE)
}
}

View File

@ -12,6 +12,7 @@ import jd.gui.spi.SourceSaver
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.StandardCopyOption
import java.util.regex.Pattern
class FileSourceSaverProvider implements SourceSaver {
@ -28,7 +29,7 @@ class FileSourceSaverProvider implements SourceSaver {
listener.pathSaved(path)
entry.inputStream.withStream { InputStream is ->
Files.copy(is, path)
Files.copy(is, path, StandardCopyOption.REPLACE_EXISTING)
}
}
}