Skip to content

Instantly share code, notes, and snippets.

@xaoseric
Created March 17, 2017 00:57
Show Gist options
  • Save xaoseric/224f7ea7100a438052e7ef679fa8e8ef to your computer and use it in GitHub Desktop.
Save xaoseric/224f7ea7100a438052e7ef679fa8e8ef to your computer and use it in GitHub Desktop.
JPlayerInstaller.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package net.jplayer.installer;
import java.io.File;
import java.io.IOException;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import static jdk.nashorn.internal.objects.NativeRegExp.source;
import org.apache.commons.io.FileUtils;
import net.jimmc.jshortcut.JShellLink;
/**
*
* @author 1081312
*/
public class JPlayerInstaller extends Application {
final Float[] values = new Float[] { -1.0f, 0f, 0.6f, 1.0f };
final Label statusLabel = new Label();
final ProgressBar pb = new ProgressBar();
final ProgressIndicator pin = new ProgressIndicator();
final HBox hb = new HBox();
private JShellLink link;
private File filePath;
@Override
public void start(Stage stage) {
Group root = new Group();
Scene scene = new Scene(root, 350, 60);
stage.setScene(scene);
stage.setTitle("JPlayer Installer");
pb.setMinWidth(300);
pb.setProgress(-1.0f);
pb.setStyle("-fx-padding: 10 0 0 0;");
hb.setSpacing(5);
hb.setAlignment(Pos.CENTER);
hb.getChildren().addAll(pb);
statusLabel.setText("Prepairing to install...");
statusLabel.setAlignment(Pos.CENTER);
final HBox labelHB = new HBox();
labelHB.setSpacing(5);
labelHB.setAlignment(Pos.CENTER);
labelHB.getChildren().addAll(statusLabel);
final VBox vb = new VBox();
vb.setSpacing(5);
vb.getChildren().addAll(hb, labelHB);
scene.setRoot(vb);
stage.show();
doInstall();
}
public void doInstall() {
updateProgress(0);
statusLabel.setText("Creating JPlayer directories...");
//run the install
String path = System.getenv("ProgramFiles");
File appDir = new File(path + File.separator + "JPlayer");
if (!appDir.exists()) {
appDir.mkdirs();
updateProgress((float) 0.1);
}
File mainJar = new File("C:\\Users\\1081312\\Documents\\NetBeansProjects\\JVideoPlayer\\dist\\JVideoPlayer.jar");
File libDir = new File("C:\\Users\\1081312\\Documents\\NetBeansProjects\\JVideoPlayer\\dist\\lib");
try {
statusLabel.setText("Installing JPlayer...");
FileUtils.copyFileToDirectory(mainJar, appDir);
updateProgress((float)0.2);
FileUtils.copyDirectoryToDirectory(libDir, appDir);
updateProgress((float)0.3);
} catch (IOException e) {
e.printStackTrace();
}
try {
link = new JShellLink();
filePath = new File(appDir, "JVideoPlayer.jar");
link.setFolder(JShellLink.getDirectory("desktop"));
link.setName("JVideoPlayer");
link.setPath(filePath.toPath().toString());
link.save();
} catch (Exception e) {
}
}
public void updateProgress(float progress) {
pb.setProgress(progress);
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment