Otettu Path.of() käyttöön tiedostojen luvussa (käyttöjärjestelmä riippumattomuus)
This commit is contained in:
Generated
-6
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="SqlDialectMappings">
|
|
||||||
<file url="PROJECT" dialect="SQLite" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@@ -1,12 +1,17 @@
|
|||||||
package fi.lpam;
|
package fi.lpam;
|
||||||
|
|
||||||
import java.io.IOException;
|
import org.apache.commons.lang3.SystemUtils;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static boolean dev;
|
public static boolean dev;
|
||||||
public static Properties properties;
|
public static Properties properties;
|
||||||
|
|
||||||
|
public static final File asetustiedosto = Path.of(SystemUtils.getUserHome().getAbsolutePath(), "OneDrive", "Kuljetusruokasovellus", "asetukset.properties").toFile();
|
||||||
|
|
||||||
static void main(String[] args) {
|
static void main(String[] args) {
|
||||||
//noinspection RedundantIfStatement
|
//noinspection RedundantIfStatement
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
@@ -17,13 +22,24 @@ public class Main {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
properties = new Properties();
|
properties = new Properties();
|
||||||
properties.load(Main.class.getClassLoader().getResourceAsStream("app.properties"));
|
properties.load(Main.class.getClassLoader().getResourceAsStream("defaults.properties"));
|
||||||
|
properties.load(new FileInputStream(asetustiedosto));
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
//noinspection CallToPrintStackTrace
|
//noinspection CallToPrintStackTrace
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
properties.forEach((key, value) -> {
|
||||||
|
System.out.println(key + ": " + value);
|
||||||
|
});
|
||||||
|
|
||||||
App.main();
|
App.main();
|
||||||
|
|
||||||
|
try (OutputStream os = new FileOutputStream(asetustiedosto)) {
|
||||||
|
properties.store(os, "");
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package fi.lpam.dataluokat;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class Asetukset extends Properties {
|
||||||
|
private static Asetukset asetukset;
|
||||||
|
|
||||||
|
private Asetukset() {
|
||||||
|
super();
|
||||||
|
asetukset = this;
|
||||||
|
System.out.println("Luotu asetukset");
|
||||||
|
try (InputStream is = new FileInputStream("defaults.properties")) {
|
||||||
|
asetukset.load(is);
|
||||||
|
asetukset.forEach((k, v) -> {
|
||||||
|
System.out.println(k + ": " + v);
|
||||||
|
});
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Properties get() {
|
||||||
|
if (asetukset == null) {new Properties();}
|
||||||
|
return asetukset;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,23 +6,23 @@ import fi.lpam.Main;
|
|||||||
import org.apache.commons.lang3.SystemUtils;
|
import org.apache.commons.lang3.SystemUtils;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class Tietokanta {
|
public class Tietokanta {
|
||||||
private static String osoite;
|
private static String osoite;
|
||||||
private static String dbPath = SystemUtils.getUserHome().getAbsolutePath() + "\\OneDrive\\Kuljetusruokasovellus\\tietokanta.db";
|
private static File tietokantatiedosto = Path.of(SystemUtils.getUserHome().getAbsolutePath(), "OneDrive", "Kuljetusruokasovellus", "tietokanta.db").toFile();
|
||||||
|
|
||||||
public Tietokanta(boolean dev) {
|
public Tietokanta(boolean dev) {
|
||||||
if (dev) dbPath = "testikanta.db";
|
if (dev) tietokantatiedosto = new File("testikanta.db");
|
||||||
File file = new File(dbPath);
|
|
||||||
try {
|
try {
|
||||||
boolean _ = file.getParentFile().mkdirs();
|
boolean _ = tietokantatiedosto.getParentFile().mkdirs();
|
||||||
boolean _ = file.createNewFile();
|
boolean _ = tietokantatiedosto.createNewFile();
|
||||||
}
|
}
|
||||||
catch (Exception _) {}
|
catch (Exception _) {}
|
||||||
|
|
||||||
osoite = "jdbc:sqlite:" + file.getAbsolutePath();
|
osoite = "jdbc:sqlite:" + tietokantatiedosto.getAbsolutePath();
|
||||||
|
|
||||||
|
|
||||||
try (Connection conn = haeYhteys()) {
|
try (Connection conn = haeYhteys()) {
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
version=${project.version}
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
version=${project.version}
|
||||||
|
|
||||||
|
viimeisinVersio=0.0.0
|
||||||
Reference in New Issue
Block a user