mirror of
https://github.com/praktimarc/kst4contest.git
synced 2026-03-30 04:31:04 +02:00
Using home directory now and copying resources if required.
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -23,7 +23,7 @@
|
|||||||
<link.name>${project.artifactId}</link.name>
|
<link.name>${project.artifactId}</link.name>
|
||||||
<launcher>${project.artifactId}</launcher>
|
<launcher>${project.artifactId}</launcher>
|
||||||
<appName>${project.artifactId}</appName>
|
<appName>${project.artifactId}</appName>
|
||||||
<main.class>kst4contest.view.Main</main.class>
|
<main.class>kst4contest.view.Kst4ContestApplication</main.class>
|
||||||
<java.version>17</java.version>
|
<java.version>17</java.version>
|
||||||
<required.maven.version>3.6.3</required.maven.version>
|
<required.maven.version>3.6.3</required.maven.version>
|
||||||
<jar.filename>${project.artifactId}-${project.version}</jar.filename>
|
<jar.filename>${project.artifactId}-${project.version}</jar.filename>
|
||||||
|
|||||||
8
src/main/java/kst4contest/ApplicationConstants.java
Normal file
8
src/main/java/kst4contest/ApplicationConstants.java
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package kst4contest;
|
||||||
|
|
||||||
|
public class ApplicationConstants {
|
||||||
|
/**
|
||||||
|
* Name of the Application.
|
||||||
|
*/
|
||||||
|
public static final String APPLICATION_NAME = "praktiKST";
|
||||||
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
package kst4contest.controller;
|
package kst4contest.controller;
|
||||||
|
|
||||||
import kst4contest.view.Main;
|
import kst4contest.view.Kst4ContestApplication;
|
||||||
|
|
||||||
public class AppRunner {
|
public class AppRunner {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
Main.main(args);
|
Kst4ContestApplication.main(args);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,15 +8,29 @@ import java.sql.SQLException;
|
|||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import kst4contest.ApplicationConstants;
|
||||||
import kst4contest.model.ChatMember;
|
import kst4contest.model.ChatMember;
|
||||||
|
import kst4contest.utils.ApplicationFileUtils;
|
||||||
|
|
||||||
public class DBController {
|
public class DBController {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of the database file.
|
||||||
|
*/
|
||||||
|
public static final String DATABASE_FILE = "praktiKST.db";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resource path for the database
|
||||||
|
*/
|
||||||
|
public static final String DATABASE_RESOURCE = "/praktiKST.db";
|
||||||
|
|
||||||
private static final DBController dbcontroller = new DBController();
|
private static final DBController dbcontroller = new DBController();
|
||||||
private static Connection connection;
|
private static Connection connection;
|
||||||
// private static final String DB_PATH = System.getProperty("praktiKST.db");
|
// private static final String DB_PATH = System.getProperty("praktiKST.db");
|
||||||
private static final String DB_PATH = ("praktiKST.db");
|
private static final String DB_PATH = ApplicationFileUtils.getFilePath(ApplicationConstants.APPLICATION_NAME, DATABASE_FILE);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
Class.forName("org.sqlite.JDBC");
|
Class.forName("org.sqlite.JDBC");
|
||||||
@@ -25,6 +39,7 @@ public class DBController {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
public DBController() {
|
public DBController() {
|
||||||
initDBConnection();
|
initDBConnection();
|
||||||
@@ -48,6 +63,11 @@ public class DBController {
|
|||||||
|
|
||||||
private void initDBConnection() {
|
private void initDBConnection() {
|
||||||
try {
|
try {
|
||||||
|
ApplicationFileUtils.copyResourceIfRequired(
|
||||||
|
ApplicationConstants.APPLICATION_NAME,
|
||||||
|
DATABASE_RESOURCE,
|
||||||
|
DATABASE_FILE
|
||||||
|
);
|
||||||
if (connection != null)
|
if (connection != null)
|
||||||
return;
|
return;
|
||||||
System.out.println("Creating Connection to Database...");
|
System.out.println("Creating Connection to Database...");
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ import javax.xml.transform.TransformerFactory;
|
|||||||
import javax.xml.transform.dom.DOMSource;
|
import javax.xml.transform.dom.DOMSource;
|
||||||
import javax.xml.transform.stream.StreamResult;
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
|
||||||
|
import kst4contest.ApplicationConstants;
|
||||||
|
import kst4contest.utils.ApplicationFileUtils;
|
||||||
import org.w3c.dom.Comment;
|
import org.w3c.dom.Comment;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
@@ -34,6 +36,16 @@ import javafx.collections.ObservableList;
|
|||||||
|
|
||||||
public class ChatPreferences {
|
public class ChatPreferences {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of file to store preferences in.
|
||||||
|
*/
|
||||||
|
public static final String PREFERENCES_FILE = "preferences.xml";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resource with the example properties xml file.
|
||||||
|
*/
|
||||||
|
public static final String PREFERENCE_RESOURCE = "/praktiKSTpreferences.xml";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor will set the default values (also for predefined texts
|
* Default constructor will set the default values (also for predefined texts
|
||||||
* and shorts) automatically at initialization
|
* and shorts) automatically at initialization
|
||||||
@@ -41,6 +53,7 @@ public class ChatPreferences {
|
|||||||
* TODO: delete this from the kst4contest.view/Main.java!
|
* TODO: delete this from the kst4contest.view/Main.java!
|
||||||
*/
|
*/
|
||||||
public ChatPreferences() {
|
public ChatPreferences() {
|
||||||
|
ApplicationFileUtils.copyResourceIfRequired(ApplicationConstants.APPLICATION_NAME, PREFERENCE_RESOURCE, PREFERENCES_FILE);
|
||||||
|
|
||||||
// shortcuts[2] = "pse";
|
// shortcuts[2] = "pse";
|
||||||
// shortcuts[3] = "turn";
|
// shortcuts[3] = "turn";
|
||||||
@@ -109,7 +122,7 @@ public class ChatPreferences {
|
|||||||
|
|
||||||
String programVersion = "Chat is powered by ON4KST \n\nUsage is free. You are welcome to support: \n\n- my project (donations, bugreports, good ideas are welcome), \n- ON4KST Servers, \n- AirScout developers and \n- OV3T (best AS-data provider of the world). \n\n73 de DO5AMF, Marc (DM5M / DARC X08)";
|
String programVersion = "Chat is powered by ON4KST \n\nUsage is free. You are welcome to support: \n\n- my project (donations, bugreports, good ideas are welcome), \n- ON4KST Servers, \n- AirScout developers and \n- OV3T (best AS-data provider of the world). \n\n73 de DO5AMF, Marc (DM5M / DARC X08)";
|
||||||
String logsynch_storeWorkedCallSignsFileNameUDPMessageBackup = "udpReaderBackup.txt";
|
String logsynch_storeWorkedCallSignsFileNameUDPMessageBackup = "udpReaderBackup.txt";
|
||||||
String storeAndRestorePreferencesFileName = "praktiKSTpreferences.xml";
|
String storeAndRestorePreferencesFileName = ApplicationFileUtils.getFilePath(ApplicationConstants.APPLICATION_NAME, PREFERENCES_FILE);
|
||||||
String chatState; // working variable only for use by primarystage (title bar)
|
String chatState; // working variable only for use by primarystage (title bar)
|
||||||
// ObservableStringValue chatState;
|
// ObservableStringValue chatState;
|
||||||
|
|
||||||
|
|||||||
69
src/main/java/kst4contest/utils/ApplicationFileUtils.java
Normal file
69
src/main/java/kst4contest/utils/ApplicationFileUtils.java
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
package kst4contest.utils;
|
||||||
|
|
||||||
|
import kst4contest.controller.DBController;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class has utility methods to handle application files inside the home directory.
|
||||||
|
*/
|
||||||
|
public class ApplicationFileUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the path of a file inside the home directory of the user.
|
||||||
|
* @param applicationName Name off the application which is used for the hidden directory
|
||||||
|
* @param fileName Name of the file.
|
||||||
|
* @return The full path inside the user home directory.
|
||||||
|
*/
|
||||||
|
public static String getFilePath(final String applicationName, final String fileName) {
|
||||||
|
return Path.of(System.getProperty("user.home"),
|
||||||
|
"." + applicationName,
|
||||||
|
fileName).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies a resource to the application folder if required.
|
||||||
|
* @param applicationName Name of the application.
|
||||||
|
* @param resourcePath Path of the resource.
|
||||||
|
* @param fileName Name of the target file.
|
||||||
|
*/
|
||||||
|
public static void copyResourceIfRequired(final String applicationName, final String resourcePath, final String fileName) {
|
||||||
|
File file = new File(getFilePath(applicationName, fileName));
|
||||||
|
|
||||||
|
if (file.exists()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
File parentDir = file.getParentFile();
|
||||||
|
if (!parentDir.exists()) {
|
||||||
|
parentDir.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
copyResourceToFile(resourcePath, file.getPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies a given resource at a resourcePath to the file path.
|
||||||
|
* @param resourcePath
|
||||||
|
* @param filePath
|
||||||
|
*/
|
||||||
|
public static void copyResourceToFile(String resourcePath, String filePath) {
|
||||||
|
try (InputStream resourceStream = ApplicationFileUtils.class.getResourceAsStream(resourcePath);
|
||||||
|
FileOutputStream fileOutputStream = new FileOutputStream(filePath)) {
|
||||||
|
|
||||||
|
if (resourceStream == null) {
|
||||||
|
throw new IllegalArgumentException("Resource not found: " + resourcePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
resourceStream.transferTo(fileOutputStream);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
System.err.println("Exception when copying Application file: " + ex.getMessage());
|
||||||
|
ex.printStackTrace(System.err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
3220
src/main/java/kst4contest/view/Kst4ContestApplication.java
Normal file
3220
src/main/java/kst4contest/view/Kst4ContestApplication.java
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user