google drive integration part 1.1

This commit is contained in:
Seil0 2017-04-17 01:02:43 +02:00
parent cdf9496d02
commit d0360931fe
4 changed files with 184 additions and 177 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,177 +1,184 @@
/** /**
* cemu_UI * cemu_UI
* *
* Copyright 2017 <@Seil0> * Copyright 2017 <@Seil0>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA. * MA 02110-1301, USA.
* *
*/ */
package application; package application;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.nio.channels.Channels; import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel; import java.nio.channels.ReadableByteChannel;
import java.util.Optional; import java.util.Optional;
import javafx.application.Application; import javafx.application.Application;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.stage.DirectoryChooser; import javafx.stage.DirectoryChooser;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType; import javafx.scene.control.ButtonType;
import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Alert.AlertType;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
public class Main extends Application { public class Main extends Application {
Stage primaryStage; Stage primaryStage;
private MainWindowController mainWindowController; private MainWindowController mainWindowController;
private String dirWin = System.getProperty("user.home") + "/Documents/cemu_UI"; //Windows: C:/Users/"User"/Documents/HomeFlix CloudController cloudController;
private String dirLinux = System.getProperty("user.home") + "/cemu_UI"; //Linux: /home/"User"/HomeFlix private String dirWin = System.getProperty("user.home") + "/Documents/cemu_UI"; //Windows: C:/Users/"User"/Documents/HomeFlix
private String gamesDBdownloadURL = "https://github.com/Seil0/cemu_UI/raw/master/downloadContent/games.db"; private String dirLinux = System.getProperty("user.home") + "/cemu_UI"; //Linux: /home/"User"/HomeFlix
private File directory; private String gamesDBdownloadURL = "https://github.com/Seil0/cemu_UI/raw/master/downloadContent/games.db";
private File configFile; private File directory;
private File gamesDBFile; private File configFile;
@SuppressWarnings("unused") private File gamesDBFile;
private File localDB; @SuppressWarnings("unused")
private File pictureCache; private File localDB;
private File pictureCache;
@Override
public void start(Stage primaryStage) { @Override
this.primaryStage = primaryStage; public void start(Stage primaryStage) {
mainWindow(); this.primaryStage = primaryStage;
} cloudController = new CloudController(this);
mainWindow();
private void mainWindow(){ }
try {
FXMLLoader loader = new FXMLLoader(Main.class.getResource("MainWindow.fxml")); private void mainWindow(){
AnchorPane pane = loader.load(); try {
primaryStage.setResizable(false); FXMLLoader loader = new FXMLLoader(Main.class.getResource("MainWindow.fxml"));
primaryStage.setTitle("cemu_UI"); AnchorPane pane = loader.load();
// primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("/recources/Homeflix_Icon_64x64.png"))); //adds application icon primaryStage.setResizable(false);
primaryStage.setTitle("cemu_UI");
mainWindowController = loader.getController(); //Link of FXMLController and controller class // primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("/recources/Homeflix_Icon_64x64.png"))); //adds application icon
mainWindowController.setMain(this); //call setMain
mainWindowController = loader.getController(); //Link of FXMLController and controller class
//get OS and the right paths mainWindowController.setMain(this); //call setMain
if(System.getProperty("os.name").equals("Linux")){
directory = new File(dirLinux); //get os and the right paths
configFile = new File(dirLinux + "/config.xml"); if(System.getProperty("os.name").equals("Linux")){
gamesDBFile = new File(dirLinux + "/games.db"); directory = new File(dirLinux);
localDB = new File(dirLinux+"/localRoms.db"); configFile = new File(dirLinux + "/config.xml");
pictureCache= new File(dirLinux+"/picture_cache"); gamesDBFile = new File(dirLinux + "/games.db");
}else{ localDB = new File(dirLinux+"/localRoms.db");
directory = new File(dirWin); pictureCache= new File(dirLinux+"/picture_cache");
configFile = new File(dirWin + "/config.xml"); }else{
gamesDBFile = new File(dirWin + "/games.db"); directory = new File(dirWin);
localDB = new File(dirWin+"/localRoms.db"); configFile = new File(dirWin + "/config.xml");
pictureCache= new File(dirWin+"/picture_cache"); gamesDBFile = new File(dirWin + "/games.db");
} localDB = new File(dirWin+"/localRoms.db");
pictureCache= new File(dirWin+"/picture_cache");
//startup checks }
System.out.println(directory.exists());
System.out.println(configFile.exists()); //startup checks
if(directory.exists() != true){ System.out.println(directory.exists());
System.out.println("mkdir all"); System.out.println(configFile.exists());
directory.mkdir(); if(directory.exists() != true){
pictureCache.mkdir(); System.out.println("mkdir all");
} directory.mkdir();
pictureCache.mkdir();
if(configFile.exists() != true){ }
System.out.println("firststart");
firstStart(); if(configFile.exists() != true){
mainWindowController.setColor("00a8cc"); System.out.println("firststart");
mainWindowController.setxPosHelper(0); firstStart();
mainWindowController.saveSettings(); mainWindowController.setColor("00a8cc");
Runtime.getRuntime().exec("java -jar cemu_UI.jar"); //start again (preventing Bugs) mainWindowController.setxPosHelper(0);
System.exit(0); //finishes itself mainWindowController.saveSettings();
} Runtime.getRuntime().exec("java -jar cemu_UI.jar"); //start again (preventing Bugs)
System.exit(0); //finishes itself
if(pictureCache.exists() != true){ }
pictureCache.mkdir();
} if(pictureCache.exists() != true){
pictureCache.mkdir();
if(gamesDBFile.exists() != true){ }
try {
System.out.print("downloading games.db... "); if(gamesDBFile.exists() != true){
URL website = new URL(gamesDBdownloadURL); try {
ReadableByteChannel rbc = Channels.newChannel(website.openStream()); System.out.print("downloading games.db... ");
FileOutputStream fos = new FileOutputStream(gamesDBFile); URL website = new URL(gamesDBdownloadURL);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); ReadableByteChannel rbc = Channels.newChannel(website.openStream());
fos.close(); FileOutputStream fos = new FileOutputStream(gamesDBFile);
System.out.println("done!"); fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
} catch (Exception e) { fos.close();
e.printStackTrace(); System.out.println("done!");
} } catch (Exception e) {
} e.printStackTrace();
}
//loading settings and initialize UI }
mainWindowController.loadSettings();
mainWindowController.dbController.main(); //loading settings and initialize UI, dbController.main() loads all databases
mainWindowController.addUIData(); mainWindowController.loadSettings();
mainWindowController.initActions(); if(mainWindowController.isCloudSync()) {
mainWindowController.initUI(); cloudController.initializeConnection(mainWindowController.getCloudService(), mainWindowController.getCemuPath());
cloudController.sync(mainWindowController.getCloudService(), mainWindowController.getCemuPath());
Scene scene = new Scene(pane); //create new scene, append pane to scene mainWindowController.saveSettings();//TODO find a better way
scene.getStylesheets().add(Main.class.getResource("MainWindows.css").toExternalForm()); }
primaryStage.setScene(scene); //append scene to stage mainWindowController.dbController.main();
primaryStage.show(); //show stage mainWindowController.addUIData();
} catch (IOException e) { mainWindowController.initActions();
e.printStackTrace(); mainWindowController.initUI();
}
} Scene scene = new Scene(pane); //create new scene, append pane to scene
scene.getStylesheets().add(Main.class.getResource("MainWindows.css").toExternalForm());
private void firstStart(){ primaryStage.setScene(scene); //append scene to stage
Alert alert = new Alert(AlertType.CONFIRMATION); //new alert with file-chooser primaryStage.show(); //show stage
alert.setTitle("cemu_UI"); } catch (IOException e) {
alert.setHeaderText("cemu installation"); e.printStackTrace();
alert.setContentText("please select your cemu installation"); }
}
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == ButtonType.OK){ private void firstStart(){
DirectoryChooser directoryChooser = new DirectoryChooser(); Alert alert = new Alert(AlertType.CONFIRMATION); //new alert with file-chooser
File selectedDirectory = directoryChooser.showDialog(primaryStage); alert.setTitle("cemu_UI");
mainWindowController.setCemuPath(selectedDirectory.getAbsolutePath()); alert.setHeaderText("cemu installation");
alert.setContentText("please select your cemu installation");
} else {
mainWindowController.setCemuPath(null); Optional<ButtonType> result = alert.showAndWait();
} if (result.get() == ButtonType.OK){
DirectoryChooser directoryChooser = new DirectoryChooser();
Alert alert2 = new Alert(AlertType.CONFIRMATION); //new alert with file-chooser File selectedDirectory = directoryChooser.showDialog(primaryStage);
alert2.setTitle("cemu_UI"); mainWindowController.setCemuPath(selectedDirectory.getAbsolutePath());
alert2.setHeaderText("rom directory");
alert2.setContentText("please select your rom directory"); } else {
mainWindowController.setCemuPath(null);
Optional<ButtonType> result2 = alert2.showAndWait(); }
if (result2.get() == ButtonType.OK){
DirectoryChooser directoryChooser = new DirectoryChooser(); Alert alert2 = new Alert(AlertType.CONFIRMATION); //new alert with file-chooser
File selectedDirectory = directoryChooser.showDialog(primaryStage); alert2.setTitle("cemu_UI");
mainWindowController.setRomPath(selectedDirectory.getAbsolutePath()); alert2.setHeaderText("rom directory");
alert2.setContentText("please select your rom directory");
} else {
mainWindowController.setRomPath(null); Optional<ButtonType> result2 = alert2.showAndWait();
} if (result2.get() == ButtonType.OK){
} DirectoryChooser directoryChooser = new DirectoryChooser();
File selectedDirectory = directoryChooser.showDialog(primaryStage);
public static void main(String[] args) { mainWindowController.setRomPath(selectedDirectory.getAbsolutePath());
launch(args);
} } else {
} mainWindowController.setRomPath(null);
}
}
public static void main(String[] args) {
launch(args);
}
}