diff --git a/src/main/java/kst4contest/ApplicationConstants.java b/src/main/java/kst4contest/ApplicationConstants.java index 07f0606..25b02a7 100644 --- a/src/main/java/kst4contest/ApplicationConstants.java +++ b/src/main/java/kst4contest/ApplicationConstants.java @@ -6,6 +6,14 @@ public class ApplicationConstants { */ public static final String APPLICATION_NAME = "praktiKST"; + /** + * Name of file to store preferences in. + */ + public static final double APPLICATION_CURRENTVERSIONNUMBER = 0.9; + + public static final String VERSIONINFOURLFORUPDATES_KST4CONTEST = "https://do5amf.funkerportal.de/kst4ContestVersionInfo.xml"; + public static final String VERSIONINFDOWNLOADEDLOCALFILE = "kst4ContestVersionInfo.xml"; + public static final String DISCSTRING_DISCONNECT_AND_CLOSE = "CLOSEALL"; public static final String DISCSTRING_DISCONNECT_DUE_PAWWORDERROR = "JUSTDSICCAUSEPWWRONG"; public static final String DISCSTRING_DISCONNECTONLY = "ONLYDISCONNECT"; diff --git a/src/main/java/kst4contest/controller/ChatController.java b/src/main/java/kst4contest/controller/ChatController.java index cdada79..e5ea14b 100644 --- a/src/main/java/kst4contest/controller/ChatController.java +++ b/src/main/java/kst4contest/controller/ChatController.java @@ -16,11 +16,7 @@ import javafx.beans.value.ObservableStringValue; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import kst4contest.ApplicationConstants; -import kst4contest.model.ChatCategory; -import kst4contest.model.ChatMember; -import kst4contest.model.ChatMessage; -import kst4contest.model.ChatPreferences; -import kst4contest.model.ClusterMessage; +import kst4contest.model.*; import kst4contest.utils.PlayAudioUtils; import java.io.*; @@ -45,6 +41,7 @@ public class ChatController { */ // private int category = ChatCategory.VUHF; + private UpdateInformation updateInformation; private ChatPreferences chatPreferences; private ChatCategory category; @@ -61,6 +58,14 @@ public class ChatController { this.disconnectionPerformedByUser = disconnectionPerformedByUser; } + public UpdateInformation getUpdateInformation() { + return updateInformation; + } + + public void setUpdateInformation(UpdateInformation updateInformation) { + this.updateInformation = updateInformation; + } + public String getChatState() { return chatState; } @@ -284,7 +289,6 @@ public class ChatController { private String chatState; private String hostname = "109.90.0.130"; -// private String praktiKSTVersion = "wtKST 3.1.4.6"; private String praktiKSTVersion = "praktiKST 0.9b"; private String praktiKSTVersionInfo = "2022-10 - 2022-12\ndeveloped by DO5AMF, Marc\nContact: praktimarc@gmail.com\nDonations via paypal are welcome"; @@ -506,9 +510,9 @@ public class ChatController { } public ChatController() { - super(); - category = new ChatCategory(2); + super(); +category = new ChatCategory(2); ownChatMemberObject = new ChatMember(); ownChatMemberObject.setCallSign(userName); ownChatMemberObject.setName(showedName); @@ -528,6 +532,13 @@ public class ChatController { */ public ChatController(ChatMember setOwnChatMemberObject) { super(); + + UpdateChecker checkForUpdates = new UpdateChecker(this); + + if (checkForUpdates.downloadLatestVersionInfoXML()) { + updateInformation = checkForUpdates.parseUpdateXMLFile(); + }; + dbHandler = new DBController(); chatPreferences = new ChatPreferences(); diff --git a/src/main/java/kst4contest/controller/UpdateChecker.java b/src/main/java/kst4contest/controller/UpdateChecker.java new file mode 100644 index 0000000..5e0c4f0 --- /dev/null +++ b/src/main/java/kst4contest/controller/UpdateChecker.java @@ -0,0 +1,133 @@ +package kst4contest.controller; + +import java.io.InputStream; + +import kst4contest.ApplicationConstants; + +import kst4contest.model.UpdateInformation; +import kst4contest.utils.ApplicationFileUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import javax.xml.XMLConstants; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import java.io.File; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; + +public class UpdateChecker { + + public static void main(String[] args) { +// new UpdateChecker(null).parseUpdateXMLFile(); + + if (new UpdateChecker(null).downloadLatestVersionInfoXML()) { +// ApplicationFileUtils.copyResourceIfRequired(ApplicationConstants.APPLICATION_NAME,ApplicationConstants.VERSIONINFDOWNLOADEDLOCALFILE,ApplicationConstants.VERSIONINFDOWNLOADEDLOCALFILE); + } + new UpdateChecker(null).parseUpdateXMLFile(); + } + + public UpdateChecker(ChatController chatController) { + + + System.out.println("[Updatechecker: checking for updates...]"); + double currentVersionNumber = ApplicationConstants.APPLICATION_CURRENTVERSIONNUMBER; + + } + + String versionInfoDownloadedFromServerFileName = ApplicationFileUtils.getFilePath(ApplicationConstants.APPLICATION_NAME, ApplicationConstants.VERSIONINFDOWNLOADEDLOCALFILE); + String versionInfoXMLURLAtServer = ApplicationConstants.VERSIONINFOURLFORUPDATES_KST4CONTEST; + double currentVersion = ApplicationConstants.APPLICATION_CURRENTVERSIONNUMBER; + //DOWNLOAD from URL, then parse, then do anything with it... + + /** + * Downloads the versioninfo-xml-file from a webserver to local. Returns true if download was successful, else false + * + * @return true if successful + */ + public boolean downloadLatestVersionInfoXML() { + + try { + + InputStream in = new URL(versionInfoXMLURLAtServer).openStream(); + Files.copy(in, Paths.get(ApplicationFileUtils.getFilePath(ApplicationConstants.APPLICATION_NAME, "/"+ApplicationConstants.VERSIONINFDOWNLOADEDLOCALFILE)), StandardCopyOption.REPLACE_EXISTING); + + in.close(); + +// System.out.println(ApplicationFileUtils.getFilePath(ApplicationConstants.APPLICATION_NAME, "/"+ApplicationConstants.VERSIONINFDOWNLOADEDLOCALFILE)); +// ApplicationFileUtils.copyResourceIfRequired(ApplicationConstants.APPLICATION_NAME,ApplicationFileUtils.get,ApplicationConstants.VERSIONINFDOWNLOADEDLOCALFILE); + + } catch (Exception e) { + System.out.println("ERROR DOWNLOADING!" + e); + return false; + } + return true; + } + + public UpdateInformation parseUpdateXMLFile() { + + UpdateInformation updateInfos = new UpdateInformation(); + + + ApplicationFileUtils.copyResourceIfRequired(ApplicationConstants.APPLICATION_NAME,"/"+ApplicationConstants.VERSIONINFDOWNLOADEDLOCALFILE,ApplicationConstants.VERSIONINFDOWNLOADEDLOCALFILE); + +// System.out.println("[Updatecker, Info]: restoring prefs from file " + versionInfoDownloadedFromServerFileName); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + try { + dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); + } catch (ParserConfigurationException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + try { + + File xmlConfigFile = new File(versionInfoDownloadedFromServerFileName); + + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = db.parse(xmlConfigFile); + + /** + * latestVersion on server + */ + NodeList list = doc.getElementsByTagName("latestVersion"); + if (list.getLength() != 0) { + + for (int temp = 0; temp < list.getLength(); temp++) { + + Node node = list.item(temp); + + if (node.getNodeType() == Node.ELEMENT_NODE) { + + Element element = (Element) node; + updateInfos.setLatestVersionNumberOnServer(Double.parseDouble(element.getElementsByTagName("versionNumber").item(0).getTextContent())); + updateInfos.setAdminMessage(element.getElementsByTagName("adminMessage").item(0).getTextContent()); + updateInfos.setMajorChanges(element.getElementsByTagName("majorChanges").item(0) + .getTextContent()); + updateInfos.setLatestVersionPathOnWebserver(element.getElementsByTagName("latestVersionPathOnWebserver").item(0).getTextContent()); +// System.out.println(updateInfos.toString()); + } + } + } + } catch (Exception e) { + System.out.println(e.getMessage()); + } + + return updateInfos; + } + + @Override + public String toString() { + String toString = ""; + + toString += this.currentVersion; + + return toString; + } +} \ No newline at end of file diff --git a/src/main/java/kst4contest/model/ChatPreferences.java b/src/main/java/kst4contest/model/ChatPreferences.java index 781c511..a08b031 100644 --- a/src/main/java/kst4contest/model/ChatPreferences.java +++ b/src/main/java/kst4contest/model/ChatPreferences.java @@ -46,6 +46,8 @@ public class ChatPreferences { */ public static final String PREFERENCE_RESOURCE = "/praktiKSTpreferences.xml"; + + /** * Default constructor will set the default values (also for predefined texts * and shorts) automatically at initialization @@ -209,6 +211,8 @@ public class ChatPreferences { // } + + public boolean isLoginAFKState() { return loginAFKState; } diff --git a/src/main/java/kst4contest/model/UpdateInformation.java b/src/main/java/kst4contest/model/UpdateInformation.java new file mode 100644 index 0000000..ee99bf2 --- /dev/null +++ b/src/main/java/kst4contest/model/UpdateInformation.java @@ -0,0 +1,67 @@ +package kst4contest.model; + +import java.util.ArrayList; + +public class UpdateInformation { + double latestVersionNumberOnServer; + String adminMessage, majorChanges,latestVersionPathOnWebserver; + ArrayList needUpdateResourcesSinceLastVersion; + ArrayList featureRequest; + ArrayList bugRequests; + + public double getLatestVersionNumberOnServer() { + return latestVersionNumberOnServer; + } + + public void setLatestVersionNumberOnServer(double latestVersionNumberOnServer) { + this.latestVersionNumberOnServer = latestVersionNumberOnServer; + } + + public String getAdminMessage() { + return adminMessage; + } + + public void setAdminMessage(String adminMessage) { + this.adminMessage = adminMessage; + } + + public String getMajorChanges() { + return majorChanges; + } + + public void setMajorChanges(String majorChanges) { + this.majorChanges = majorChanges; + } + + public String getLatestVersionPathOnWebserver() { + return latestVersionPathOnWebserver; + } + + public void setLatestVersionPathOnWebserver(String latestVersionPathOnWebserver) { + this.latestVersionPathOnWebserver = latestVersionPathOnWebserver; + } + + public ArrayList getNeedUpdateResourcesSinceLastVersion() { + return needUpdateResourcesSinceLastVersion; + } + + public void setNeedUpdateResourcesSinceLastVersion(ArrayList needUpdateResourcesSinceLastVersion) { + this.needUpdateResourcesSinceLastVersion = needUpdateResourcesSinceLastVersion; + } + + public ArrayList getFeatureRequest() { + return featureRequest; + } + + public void setFeatureRequest(ArrayList featureRequest) { + this.featureRequest = featureRequest; + } + + public ArrayList getBugRequests() { + return bugRequests; + } + + public void setBugRequests(ArrayList bugRequests) { + this.bugRequests = bugRequests; + } +} diff --git a/src/main/java/kst4contest/view/Kst4ContestApplication.java b/src/main/java/kst4contest/view/Kst4ContestApplication.java index 3a0f731..a7f1bfb 100644 --- a/src/main/java/kst4contest/view/Kst4ContestApplication.java +++ b/src/main/java/kst4contest/view/Kst4ContestApplication.java @@ -6,6 +6,7 @@ import java.net.URISyntaxException; import java.util.*; import javafx.beans.value.ObservableStringValue; +import javafx.scene.control.*; import javafx.scene.media.Media; import javafx.scene.media.MediaPlayer; import kst4contest.ApplicationConstants; @@ -28,31 +29,10 @@ import javafx.geometry.Pos; import javafx.geometry.VPos; import javafx.scene.Node; import javafx.scene.Scene; -import javafx.scene.control.Alert; import javafx.scene.control.Alert.AlertType; -import javafx.scene.control.Button; -import javafx.scene.control.ButtonType; -import javafx.scene.control.CheckBox; -import javafx.scene.control.ChoiceBox; -import javafx.scene.control.ContextMenu; -import javafx.scene.control.Label; -import javafx.scene.control.Menu; -import javafx.scene.control.MenuBar; -import javafx.scene.control.MenuItem; -import javafx.scene.control.PasswordField; -import javafx.scene.control.SelectionMode; -import javafx.scene.control.Separator; -import javafx.scene.control.SplitPane; -import javafx.scene.control.Tab; -import javafx.scene.control.TabPane; -import javafx.scene.control.TableCell; -import javafx.scene.control.TableColumn; import javafx.scene.control.TableColumn.CellDataFeatures; import javafx.scene.control.TableColumn.CellEditEvent; -import javafx.scene.control.TableView; import javafx.scene.control.TableView.TableViewSelectionModel; -import javafx.scene.control.TextField; -import javafx.scene.control.Tooltip; import javafx.scene.control.cell.TextFieldTableCell; import javafx.scene.input.KeyCode; import javafx.scene.input.KeyEvent; @@ -1742,7 +1722,7 @@ public class Kst4ContestApplication extends Application { help5.setDisable(true); MenuItem help6 = new MenuItem("Contact the author using default mail app"); MenuItem help8 = new MenuItem("Join kst4Contest newsgroup"); - MenuItem help9 = new MenuItem("Download the changelog / roadmap"); +// MenuItem help9 = new MenuItem("Download the changelog / roadmap"); // Changelog // https://e.pcloud.link/publink/show?code=XZwAoWZIap9DYqDlhhwncqAxLbU6STOh2PV @@ -1752,12 +1732,7 @@ public class Kst4ContestApplication extends Application { getHostServices().showDocument("https://www.paypal.com/paypalme/do5amf"); -// Alert a = new Alert(AlertType.INFORMATION); -// -// a.setTitle("About this software"); -// a.setHeaderText("Who made it and how can you support it?"); -// a.setContentText(chatcontroller.getChatPreferences().getProgramVersion()); -// a.show(); + } }); @@ -1766,12 +1741,6 @@ public class Kst4ContestApplication extends Application { getHostServices().showDocument("http://www.x08.de"); -// Alert a = new Alert(AlertType.INFORMATION); -// -// a.setTitle("About this software"); -// a.setHeaderText("Who made it and how can you support it?"); -// a.setContentText(chatcontroller.getChatPreferences().getProgramVersion()); -// a.show(); } }); @@ -1791,14 +1760,14 @@ public class Kst4ContestApplication extends Application { } }); - help9.setOnAction(new EventHandler() { - public void handle(ActionEvent event) { - - getHostServices() - .showDocument("https://e.pcloud.link/publink/show?code=XZwAoWZIap9DYqDlhhwncqAxLbU6STOh2PV"); - - } - }); +// help9.setOnAction(new EventHandler() { +// public void handle(ActionEvent event) { +// +// getHostServices() +// .showDocument("https://e.pcloud.link/publink/show?code=XZwAoWZIap9DYqDlhhwncqAxLbU6STOh2PV"); +// +// } +// }); MenuItem help10 = new MenuItem("About..."); help10.setOnAction(new EventHandler() { @@ -1807,14 +1776,14 @@ public class Kst4ContestApplication extends Application { Alert a = new Alert(AlertType.INFORMATION); a.setTitle("About kst4contest"); - a.setHeaderText("ON4KST Chatclient by DO5AMF"); + a.setHeaderText("kst4Contest " + ApplicationConstants.APPLICATION_CURRENTVERSIONNUMBER + ": ON4KST Chatclient by DO5AMF"); a.setContentText(chatcontroller.getChatPreferences().getProgramVersion()); a.show(); } }); // helpMenu.getItems().add(help1); - helpMenu.getItems().addAll(help2, help4, help5, help6, help8, help9, help10); + helpMenu.getItems().addAll(help2, help4, help5, help6, help8, help10); // helpMenu.getItems().add(help2); // helpMenu.getItems().add(help4); @@ -1843,6 +1812,8 @@ public class Kst4ContestApplication extends Application { Stage clusterAndQSOMonStage; + Stage stage_updateStage; + Stage settingsStage; @@ -2675,6 +2646,9 @@ public class Kst4ContestApplication extends Application { e.printStackTrace(); } + /** + * Window Cluster & qso of the other + */ clusterAndQSOMonStage = new Stage(); // clusterAndQSOMonStage.initStyle(StageStyle.UTILITY); clusterAndQSOMonStage.setTitle("Cluster & QSO of the other"); @@ -2686,11 +2660,104 @@ public class Kst4ContestApplication extends Application { clusterAndQSOMonStage.setScene(new Scene(pnl_directedMSGWin, 700, 500)); clusterAndQSOMonStage.show(); + /** + * end Window Cluster & qso of the other + */ + + /** + * Window updates + */ + stage_updateStage = new Stage(); +// clusterAndQSOMonStage.initStyle(StageStyle.UTILITY); + stage_updateStage.setTitle("Update information"); +// SplitPane pnl_directedMSGWin = new SplitPane(); +// apnl_directedMSGWin.setOrientation(Orientation.VERTICAL); + +// pnl_directedMSGWin.getItems().addAll(initDXClusterTable(), initChatToOtherMSGTable()); + + stage_updateStage.setAlwaysOnTop(true); + + Label lblUpdateInfo = new Label("Update aviable!"); + Label lblUpdateInfo2 = new Label("Your Software version: "); + Label lblUpdateInfo3 = new Label("Newest Software version: "); + Label lblUpdateInfoChanges = new Label("Major Changes: "); + Label lblUpdateInfoAdminMessage = new Label("Admin Message: "); + Label lblUpdateInfoDownload = new Label("Downloadable here: " ); + + + TreeView treeView = new TreeView(); + + GridPane upd_gridPaneUpd = new GridPane(); + + upd_gridPaneUpd.setPadding(new Insets(10, 10, 10, 10)); + upd_gridPaneUpd.setVgap(5); + upd_gridPaneUpd.setHgap(5); + + + VBox vbxUpdateWindow = new VBox(); + vbxUpdateWindow.setSpacing(30); + + + vbxUpdateWindow.getChildren().add(upd_gridPaneUpd); + upd_gridPaneUpd.add(lblUpdateInfo, 0,0,1,1); + upd_gridPaneUpd.add(lblUpdateInfo2, 0,1,1,1); + upd_gridPaneUpd.add(new Label("kst4Contest " + ApplicationConstants.APPLICATION_CURRENTVERSIONNUMBER+""), 1,1,1,1); + upd_gridPaneUpd.add(lblUpdateInfo3, 0,2,1,1); + upd_gridPaneUpd.add(new Label("kst4Contest " + chatcontroller.getUpdateInformation().getLatestVersionNumberOnServer()+""), 1,2,1,1); + upd_gridPaneUpd.add(lblUpdateInfoChanges, 0,3,1,1); + upd_gridPaneUpd.add(new Label(chatcontroller.getUpdateInformation().getMajorChanges()), 1,3,1,1); + upd_gridPaneUpd.add(lblUpdateInfoAdminMessage, 0,4,1,1); + upd_gridPaneUpd.add(new Label(chatcontroller.getUpdateInformation().getAdminMessage()), 1,4,1,1); + upd_gridPaneUpd.add(lblUpdateInfoDownload, 0,5,1,1); + + Hyperlink link = new Hyperlink("Download here"); + link.setOnAction(e -> { + getHostServices().showDocument(chatcontroller.getUpdateInformation().getLatestVersionPathOnWebserver()); +// System.out.println("The Hyperlink was clicked!"); + }); + +// TextField upd_txtfldUpdateDownloadLink = new TextField(chatcontroller.getUpdateInformation().getLatestVersionPathOnWebserver()); +// upd_txtfldUpdateDownloadLink.setEditable(false); + + upd_gridPaneUpd.add(link, 1,5,1,1); + + + +// vbxUpdateWindow.getChildren().addAll(lblUpdateInfo, lblUpdateInfo2, lblUpdateInfo3, lblUpdateInfoChanges, lblUpdateInfoAdminMessage, lblUpdateInfoDownload); + vbxUpdateWindow.getChildren().add(treeView); + + TreeItem rootItem = new TreeItem(ApplicationConstants.APPLICATION_NAME); + TreeItem latestVersionNumber = new TreeItem<>(chatcontroller.getUpdateInformation().getLatestVersionNumberOnServer()); + TreeItem adminMessage = new TreeItem<>(chatcontroller.getUpdateInformation().getAdminMessage()); + TreeItem majorChanges = new TreeItem<>(chatcontroller.getUpdateInformation().getMajorChanges()); + TreeItem latestVersionPathOnWebserver = new TreeItem<>(chatcontroller.getUpdateInformation().getLatestVersionPathOnWebserver()); + + + + rootItem.getChildren().add(latestVersionNumber); + rootItem.getChildren().add(adminMessage); + rootItem.getChildren().add(majorChanges); + rootItem.getChildren().add(latestVersionPathOnWebserver); + + treeView.setRoot(rootItem); + + stage_updateStage.setScene(new Scene(vbxUpdateWindow, 640, 480)); + + if (chatcontroller.getUpdateInformation().getLatestVersionNumberOnServer() > ApplicationConstants.APPLICATION_CURRENTVERSIONNUMBER) { + stage_updateStage.show(); + } else { + //nothing to do + } + + /** + * end Window Update + */ + + /***************************************************************************** * * Settings Scene - * - * + * ****************************************************************************/ settingsStage = new Stage(); settingsStage.setTitle("Change Client seetings");