show alert if export fails
This commit is contained in:
		@ -4,6 +4,7 @@ import javafx.application.Platform
 | 
			
		||||
import javafx.collections.ObservableList
 | 
			
		||||
import javafx.event.EventHandler
 | 
			
		||||
import javafx.stage.DirectoryChooser
 | 
			
		||||
import org.hso.texturesyncclient.alerts.JFXInfoAlert
 | 
			
		||||
import org.hso.texturesyncclient.alerts.JFXOkayCancelAlert
 | 
			
		||||
import org.hso.texturesyncclient.controller.net.AutoConnect
 | 
			
		||||
import org.hso.texturesyncclient.controller.net.Connection
 | 
			
		||||
@ -26,11 +27,11 @@ import javax.imageio.ImageIO
 | 
			
		||||
import java.util.UUID
 | 
			
		||||
import java.nio.file.Files
 | 
			
		||||
import java.io.FileOutputStream
 | 
			
		||||
import java.io.IOException
 | 
			
		||||
import java.text.SimpleDateFormat
 | 
			
		||||
import java.text.DateFormat
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class RootController : Controller() {
 | 
			
		||||
 | 
			
		||||
    private val mvc: MainViewController by inject()
 | 
			
		||||
@ -175,15 +176,32 @@ class RootController : Controller() {
 | 
			
		||||
        directoryChooser.title = "Export Verzeichnis wählen"
 | 
			
		||||
        directoryChooser.initialDirectory = File(lastExportDir)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        val alertExport = JFXInfoAlert(
 | 
			
		||||
            "Exporterien fehlgeschlagen",
 | 
			
		||||
            "Mögliche Ursachen:" +
 | 
			
		||||
                    "\n-Datei existiert bereits" +
 | 
			
		||||
                    "\n-Ordner nicht beschreibbar",
 | 
			
		||||
            "-fx-button-type: RAISED; -fx-background-color: #2b7bbb; -fx-text-fill: #000000;"
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        val dir = directoryChooser.showDialog(primaryStage)
 | 
			
		||||
        if (dir != null) {
 | 
			
		||||
            val extension = if (data.format == TextureFormat.PNG) ".png" else ".jpeg" //get file format
 | 
			
		||||
            val filePath = "$dir/${data.name}$extension" //build absolute exported texture path
 | 
			
		||||
            val exportedFile = File(filePath) //create file
 | 
			
		||||
            val fileout = FileOutputStream(exportedFile)
 | 
			
		||||
            fileout.write(con.getTextureFile(data.textureHash)) //write bytes in file
 | 
			
		||||
            fileout.close()
 | 
			
		||||
 | 
			
		||||
            if (exportedFile.exists()) {
 | 
			
		||||
                alertExport.showAndWait()
 | 
			
		||||
            } else {
 | 
			
		||||
                try {
 | 
			
		||||
                    val fileout = FileOutputStream(exportedFile)
 | 
			
		||||
                    fileout.write(con.getTextureFile(data.textureHash)) //write bytes in file fileout.close()
 | 
			
		||||
                    fileout.close()
 | 
			
		||||
                } catch (e: IOException) {
 | 
			
		||||
                    alertExport.showAndWait()
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            lastExportDir = dir.absolutePath //store last user chosen dir
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@ -200,7 +218,12 @@ class RootController : Controller() {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        mvc.setMeta(data.name, "${data.resolution.first.toString()}px x ${data.resolution.second.toString()}px", data.format.toString(), sdf.format(data.addedOn.time))
 | 
			
		||||
        mvc.setMeta(
 | 
			
		||||
            data.name,
 | 
			
		||||
            "${data.resolution.first.toString()}px x ${data.resolution.second.toString()}px",
 | 
			
		||||
            data.format.toString(),
 | 
			
		||||
            sdf.format(data.addedOn.time)
 | 
			
		||||
        )
 | 
			
		||||
        mvc.setTags(data.tags.toList().observable())
 | 
			
		||||
        selectedTexture = data
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user