use gitea instead of github
* use gitea instead of github * use prepareStatement instead of statement
This commit is contained in:
parent
a23b87fcb8
commit
5e89faff49
|
@ -165,7 +165,7 @@ public class MainWindowController {
|
||||||
private boolean autoplay = false;
|
private boolean autoplay = false;
|
||||||
|
|
||||||
private final String version = "0.7.0";
|
private final String version = "0.7.0";
|
||||||
private final String buildNumber = "159";
|
private final String buildNumber = "161";
|
||||||
private final String versionName = "toothless dragon";
|
private final String versionName = "toothless dragon";
|
||||||
private String btnStyle;
|
private String btnStyle;
|
||||||
private String color;
|
private String color;
|
||||||
|
|
|
@ -321,7 +321,6 @@ public class DBController {
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private void checkAddEntry() throws SQLException, FileNotFoundException, IOException {
|
private void checkAddEntry() throws SQLException, FileNotFoundException, IOException {
|
||||||
Statement stmt = connection.createStatement();
|
|
||||||
PreparedStatement ps = connection.prepareStatement("insert into films values (?, ?, ?, ?, ?, ?, ?)");
|
PreparedStatement ps = connection.prepareStatement("insert into films values (?, ?, ?, ?, ?, ?, ?)");
|
||||||
LOGGER.info("checking for entrys to add to DB ...");
|
LOGGER.info("checking for entrys to add to DB ...");
|
||||||
|
|
||||||
|
@ -335,11 +334,14 @@ public class DBController {
|
||||||
if (file.isFile() && mimeType != null && mimeType.contains("video")) {
|
if (file.isFile() && mimeType != null && mimeType.contains("video")) {
|
||||||
// get all files (films)
|
// get all files (films)
|
||||||
if (!filmsdbStreamURL.contains(file.getPath())) {
|
if (!filmsdbStreamURL.contains(file.getPath())) {
|
||||||
stmt.executeUpdate("insert into films values ("
|
ps.setString(1, file.getPath());
|
||||||
+ "'" + file.getPath() + "',"
|
ps.setString(2, cutOffEnd(file.getName()));
|
||||||
+ "'" + cutOffEnd(file.getName()) + "', '', '', 0, 0, 0.0)");
|
ps.setString(3, "");
|
||||||
connection.commit();
|
ps.setString(4, "");
|
||||||
stmt.close();
|
ps.setInt(5, 0);
|
||||||
|
ps.setBoolean(6, false);
|
||||||
|
ps.setDouble(7, 0);
|
||||||
|
ps.addBatch(); // adds the entry
|
||||||
LOGGER.info("Added \"" + file.getName() + "\" to database");
|
LOGGER.info("Added \"" + file.getName() + "\" to database");
|
||||||
filmsdbStreamURL.add(file.getPath());
|
filmsdbStreamURL.add(file.getPath());
|
||||||
}
|
}
|
||||||
|
@ -351,12 +353,15 @@ public class DBController {
|
||||||
int ep = 1;
|
int ep = 1;
|
||||||
for (File episode : season.listFiles()) {
|
for (File episode : season.listFiles()) {
|
||||||
if (!filmsdbStreamURL.contains(episode.getPath())) {
|
if (!filmsdbStreamURL.contains(episode.getPath())) {
|
||||||
|
ps.setString(1, episode.getPath().replace("'", "''"));
|
||||||
|
ps.setString(2, cutOffEnd(file.getName()));
|
||||||
|
ps.setString(3, Integer.toString(sn));
|
||||||
|
ps.setString(4, Integer.toString(ep));
|
||||||
|
ps.setInt(5, 0);
|
||||||
|
ps.setBoolean(6, false);
|
||||||
|
ps.setDouble(7, 0);
|
||||||
|
ps.addBatch(); // adds the entry
|
||||||
LOGGER.info("Added \"" + file.getName() + "\", Episode: " + episode.getName() + " to database");
|
LOGGER.info("Added \"" + file.getName() + "\", Episode: " + episode.getName() + " to database");
|
||||||
stmt.executeUpdate("insert into films values ("
|
|
||||||
+ "'" + episode.getPath().replace("'", "''") + "',"
|
|
||||||
+ "'" + cutOffEnd(file.getName()) + "','" + sn + "','" + ep + "', 0, 0, 0.0)");
|
|
||||||
connection.commit();
|
|
||||||
stmt.close();
|
|
||||||
filmsStreamURL.add(episode.getPath());
|
filmsStreamURL.add(episode.getPath());
|
||||||
filmsdbStreamURL.add(episode.getPath());
|
filmsdbStreamURL.add(episode.getPath());
|
||||||
ep++;
|
ep++;
|
||||||
|
|
|
@ -45,18 +45,17 @@ import kellerkinder.HomeFlix.application.MainWindowController;
|
||||||
public class UpdateController implements Runnable {
|
public class UpdateController implements Runnable {
|
||||||
|
|
||||||
private MainWindowController mainWindowController;
|
private MainWindowController mainWindowController;
|
||||||
private String buildNumber;
|
private int buildNumber;
|
||||||
|
private int updateBuildNumber; // tag_name from gitea
|
||||||
private String apiOutput;
|
private String apiOutput;
|
||||||
private String updateBuildNumber; // tag_name from Github
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private String updateName;
|
private String updateName;
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private String updateChanges;
|
private String updateChanges;
|
||||||
private String browserDownloadUrl; // update download link
|
private String browserDownloadUrl; // update download link
|
||||||
private String githubApiRelease = "https://api.github.com/repos/Seil0/Project-HomeFlix/releases/latest";
|
private String giteaApiRelease = "https://git.mosad.xyz/api/v1/repos/Seil0/Project-HomeFlix/releases";
|
||||||
private String githubApiBeta = "https://api.github.com/repos/Seil0/Project-HomeFlix/releases";
|
private URL giteaApiUrl;
|
||||||
|
|
||||||
private URL githubApiUrl;
|
|
||||||
private boolean useBeta;
|
private boolean useBeta;
|
||||||
private static final Logger LOGGER = LogManager.getLogger(UpdateController.class.getName());
|
private static final Logger LOGGER = LogManager.getLogger(UpdateController.class.getName());
|
||||||
|
|
||||||
|
@ -68,7 +67,7 @@ public class UpdateController implements Runnable {
|
||||||
*/
|
*/
|
||||||
public UpdateController(MainWindowController mwc, String buildNumber, boolean useBeta) {
|
public UpdateController(MainWindowController mwc, String buildNumber, boolean useBeta) {
|
||||||
mainWindowController = mwc;
|
mainWindowController = mwc;
|
||||||
this.buildNumber = buildNumber;
|
this.buildNumber = Integer.parseInt(buildNumber);
|
||||||
this.useBeta = useBeta;
|
this.useBeta = useBeta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,57 +79,41 @@ public class UpdateController implements Runnable {
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
giteaApiUrl = new URL(giteaApiRelease);
|
||||||
|
|
||||||
if (useBeta) {
|
BufferedReader ina = new BufferedReader(new InputStreamReader(giteaApiUrl.openStream()));
|
||||||
githubApiUrl = new URL(githubApiBeta);
|
|
||||||
} else {
|
|
||||||
githubApiUrl = new URL(githubApiRelease);
|
|
||||||
}
|
|
||||||
|
|
||||||
// URL githubApiUrl = new URL(githubApiRelease);
|
|
||||||
BufferedReader ina = new BufferedReader(new InputStreamReader(githubApiUrl.openStream()));
|
|
||||||
apiOutput = ina.readLine();
|
apiOutput = ina.readLine();
|
||||||
ina.close();
|
ina.close();
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
LOGGER.error("could not check update version", e);
|
LOGGER.error("could not check update version", e);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useBeta) {
|
JsonArray objectArray = Json.parse("{\"items\": " + apiOutput + "}").asObject().get("items").asArray();
|
||||||
JsonArray objectArray = Json.parse("{\"items\": " + apiOutput + "}").asObject().get("items").asArray();
|
JsonValue object = objectArray.get(0).asObject(); // set to the latest release as default
|
||||||
JsonValue object = objectArray.get(0);
|
JsonObject objectAsset = object.asObject().get("assets").asArray().get(0).asObject();
|
||||||
JsonArray objectAssets = object.asObject().get("assets").asArray();
|
|
||||||
|
|
||||||
updateBuildNumber = object.asObject().getString("tag_name", "");
|
|
||||||
updateName = object.asObject().getString("name", "");
|
|
||||||
updateChanges = object.asObject().getString("body", "");
|
|
||||||
|
|
||||||
for (JsonValue asset : objectAssets) {
|
|
||||||
browserDownloadUrl = asset.asObject().getString("browser_download_url", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
JsonObject object = Json.parse(apiOutput).asObject();
|
|
||||||
JsonArray objectAssets = Json.parse(apiOutput).asObject().get("assets").asArray();
|
|
||||||
|
|
||||||
updateBuildNumber = object.getString("tag_name", "");
|
|
||||||
updateName = object.getString("name", "");
|
|
||||||
updateChanges = object.getString("body", "");
|
|
||||||
for (JsonValue asset : objectAssets) {
|
|
||||||
browserDownloadUrl = asset.asObject().getString("browser_download_url", "");
|
|
||||||
|
|
||||||
|
for(JsonValue objectIt : objectArray) {
|
||||||
|
if(objectIt.asObject().getBoolean("prerelease", false) == useBeta) {
|
||||||
|
// we found the needed release either beta or not
|
||||||
|
object = objectIt;
|
||||||
|
objectAsset = objectIt.asObject().get("assets").asArray().get(0).asObject();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateBuildNumber = Integer.parseInt(object.asObject().getString("tag_name", ""));
|
||||||
|
updateName = object.asObject().getString("name", "");
|
||||||
|
updateChanges = object.asObject().getString("body", "");
|
||||||
|
|
||||||
LOGGER.info("Build: " + buildNumber + ", Update: " + updateBuildNumber);
|
LOGGER.info("Build: " + buildNumber + ", Update: " + updateBuildNumber);
|
||||||
|
|
||||||
// Compares the program BuildNumber with the current BuildNumber if program
|
/**
|
||||||
// BuildNumber < current BuildNumber then perform a update
|
* Compare the program BuildNumber with the current BuildNumber
|
||||||
int iversion = Integer.parseInt(buildNumber);
|
* if buildNumber < updateBuildNumber then perform a update
|
||||||
int iaktVersion = Integer.parseInt(updateBuildNumber.replace(".", ""));
|
*/
|
||||||
|
if (buildNumber >= updateBuildNumber) {
|
||||||
if (iversion >= iaktVersion) {
|
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
mainWindowController.getUpdateBtn().setText(mainWindowController.getBundle().getString("updateBtnNoUpdateAvailable"));
|
mainWindowController.getUpdateBtn().setText(mainWindowController.getBundle().getString("updateBtnNoUpdateAvailable"));
|
||||||
});
|
});
|
||||||
|
@ -140,9 +123,11 @@ public class UpdateController implements Runnable {
|
||||||
mainWindowController.getUpdateBtn().setText(mainWindowController.getBundle().getString("updateBtnUpdateAvailable"));
|
mainWindowController.getUpdateBtn().setText(mainWindowController.getBundle().getString("updateBtnUpdateAvailable"));
|
||||||
});
|
});
|
||||||
LOGGER.info("update available");
|
LOGGER.info("update available");
|
||||||
|
browserDownloadUrl = objectAsset.getString("browser_download_url", "");
|
||||||
LOGGER.info("download link: " + browserDownloadUrl);
|
LOGGER.info("download link: " + browserDownloadUrl);
|
||||||
try {
|
try {
|
||||||
// open new Http connection, ProgressMonitorInputStream for downloading the data
|
// open new HTTP connection, ProgressMonitorInputStream for downloading the data
|
||||||
|
// FIXME the download progress dialog is not showing!
|
||||||
HttpURLConnection connection = (HttpURLConnection) new URL(browserDownloadUrl).openConnection();
|
HttpURLConnection connection = (HttpURLConnection) new URL(browserDownloadUrl).openConnection();
|
||||||
ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(null, "Downloading...", connection.getInputStream());
|
ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(null, "Downloading...", connection.getInputStream());
|
||||||
ProgressMonitor pm = pmis.getProgressMonitor();
|
ProgressMonitor pm = pmis.getProgressMonitor();
|
||||||
|
@ -151,6 +136,7 @@ public class UpdateController implements Runnable {
|
||||||
pm.setMinimum(0);// set beginning of the progress bar to 0
|
pm.setMinimum(0);// set beginning of the progress bar to 0
|
||||||
pm.setMaximum(connection.getContentLength());// set the end to the file length
|
pm.setMaximum(connection.getContentLength());// set the end to the file length
|
||||||
FileUtils.copyInputStreamToFile(pmis, new File("ProjectHomeFlix_update.jar")); // download update
|
FileUtils.copyInputStreamToFile(pmis, new File("ProjectHomeFlix_update.jar")); // download update
|
||||||
|
LOGGER.info("update download successful, restarting ...");
|
||||||
org.apache.commons.io.FileUtils.copyFile(new File("ProjectHomeFlix_update.jar"), new File("ProjectHomeFlix.jar"));
|
org.apache.commons.io.FileUtils.copyFile(new File("ProjectHomeFlix_update.jar"), new File("ProjectHomeFlix.jar"));
|
||||||
org.apache.commons.io.FileUtils.deleteQuietly(new File("ProjectHomeFlix_update.jar")); // delete update
|
org.apache.commons.io.FileUtils.deleteQuietly(new File("ProjectHomeFlix_update.jar")); // delete update
|
||||||
new ProcessBuilder("java", "-jar", "ProjectHomeFlix.jar").start(); // start the new application
|
new ProcessBuilder("java", "-jar", "ProjectHomeFlix.jar").start(); // start the new application
|
||||||
|
@ -161,7 +147,6 @@ public class UpdateController implements Runnable {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue