From 89ef73695499662d90b7b410822f3d28cb90ce45 Mon Sep 17 00:00:00 2001 From: localhorst Date: Sat, 8 Jun 2019 14:20:48 +0200 Subject: [PATCH] alert if import failed --- .../controller/RootController.kt | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/controller/RootController.kt b/client/src/main/kotlin/org/hso/texturesyncclient/controller/RootController.kt index 8a9e61e..46db4d4 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/controller/RootController.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/controller/RootController.kt @@ -51,7 +51,7 @@ class RootController : Controller() { * @param tags all tags for the file */ fun importTexture(path: String, name: String, tags: ObservableList) { - val data = Files.readAllBytes(File(path).toPath()) // this is the image as byte array + var data = Files.readAllBytes(File(path).toPath()) // this is the image as byte array val uuid = UUID.randomUUID() val format = if (File(path).extension.toLowerCase() == "png") TextureFormat.PNG else TextureFormat.JPEG @@ -60,15 +60,33 @@ class RootController : Controller() { val cal = Calendar.getInstance() //calendar obj with current time val hash = Sha256(data) - //Todo free image + + val alertImportHash = JFXInfoAlert( + "Upload fehlgeschlagen", + "Die Textur wurde nicht fehlerfrei übertragen", + "-fx-button-type: RAISED; -fx-background-color: #2b7bbb; -fx-text-fill: #000000;" + ) + + val alertImport = JFXInfoAlert( + "Upload fehlgeschlagen", + "Mögliche Ursachen:" + + "\n- Textur existiert bereits" + + "\n- Server nicht bereit", + "-fx-button-type: RAISED; -fx-background-color: #2b7bbb; -fx-text-fill: #000000;" + ) + + data = null //Free image val newTexture = Texture(uuid, name, tags.toTypedArray(), format, resolution, cal, hash) try { con.uploadTexture(newTexture, data) println("Texture upload successful") - } catch (e: Exception) { + } catch (e: IllegalArgumentException) { println(e) + alertImportHash.showAndWait() + } catch (e: Exception) { + alertImport.showAndWait() } } @@ -180,8 +198,8 @@ class RootController : Controller() { val alertExport = JFXInfoAlert( "Exporterien fehlgeschlagen", "Mögliche Ursachen:" + - "\n-Datei existiert bereits" + - "\n-Ordner nicht beschreibbar", + "\n- Datei existiert bereits" + + "\n- Ordner nicht beschreibbar", "-fx-button-type: RAISED; -fx-background-color: #2b7bbb; -fx-text-fill: #000000;" )