Kenmegne
7 days ago 494d349fb67be74da49caae2794fda702f595fb4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.megatim.fdxgenerator;
 
/**
 * https://github.com/vinumeris/updatefx
 * @author STEPHANIE
 */
public class AppUpdate {
//    
//    private static java.util.logging.Logger logger;
//    private static final Logger log = LoggerFactory.getLogger(App.class);
//    public static int VERSION = 1;
//    private static final String APP_NAME = "generateur";
//    
//    @Override
//    public void start(Stage primaryStage) throws FileNotFoundException, MalformedURLException, IOException {
//         // For some reason the JavaFX launch process results in us losing the thread context class loader: reset it.
//        Thread.currentThread().setContextClassLoader(App.class.getClassLoader());
//        // Must be done twice for the times when we come here via realMain.
//        AppDirectory.initAppDir(APP_NAME);
//
//        log.info("Hello World! This is version " + VERSION);
//
//       // ProgressIndicator indicator = showGiantProgressWheel(primaryStage);
//
//        List<ECPoint> pubkeys = Crypto.decode();
//        
//        Updater updater = new Updater(URI.create("http://localhost:8080/generateur-updates/index"), "generation-typefichier-" + VERSION,
//                AppDirectory.dir(), UpdateFX.findCodePath(App.class), pubkeys, 0) {
//            @Override
//            protected void updateProgress(long workDone, long max) {
//                super.updateProgress(workDone, max);
//                // Give UI a chance to show.
//                Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
//            }
//        };
//        
//        FXMLLoader loader = new FXMLLoader();
//        loader.setLocation(MainController.class.getResource("main.fxml"));
//        Parent root = loader.load();
//        MainController controller = loader.getController();
//        
//       ProgressIndicator indicator = controller.getIndicator();
//        indicator.progressProperty().bind(updater.progressProperty());
//        Label label = controller.getLabelVersion();
//       
//
//        log.info("Checking for updates!");
//        updater.setOnRunning(event -> {
//            label.setText("Mise à jour en cours");
//        });
//        updater.setOnSucceeded(event -> {
//            try {
//                UpdateSummary summary = updater.get();
//               Updates updates = summary.updates;
//               int count = updates.getUpdatesCount();
//               
//                if (!summary.descriptions.isEmpty()) {
//                    log.info("One liner: {}", summary.descriptions.get(0).getOneLiner());
//                    log.info("{}", summary.descriptions.get(0).getDescription());
//                }
//                if (summary.highestVersion > VERSION) {
//                    int nb = summary.highestVersion - VERSION;
//                    log.info("Restarting to get version " + summary.highestVersion);
//                    label.setText("Nombre de mise à jour trouvé : " + nb);
//                    if (UpdateFX.getVersionPin(AppDirectory.dir()) == 0) {
//                        log.info("before restartApp()");
//                        UpdateFX.restartApp();
//                    }
//                } else {
//                    label.setVisible(false);
//                    indicator.setVisible(false);
//                }
//            } catch (Throwable e) {
//                log.error("oops", e);
//            }
//        });
//        updater.setOnFailed(event -> {
//            label.setVisible(false);
//            indicator.setVisible(false);
//            
//            log.error("Update error: {}", updater.getException());
//            updater.getException().getMessage();
//            updater.getException().printStackTrace();
//        });
//
//        indicator.setOnMouseClicked(ev -> UpdateFX.restartApp());
//
//        new Thread(updater, "UpdateFX Thread").start();
//        
//        AbstractViewContext.getInstance().setAbstractEditDialogControllerURL(App.class.getResource("/generation/validateur/typefichier/abstracts/AbstractEditDialog.fxml"));
//        
//        
//
//        Scene scene = new Scene(root, 1100, 600);
//
//        primaryStage.setTitle("Générateur de fichiers de validation");
//        primaryStage.getIcons().add(new Image("images/icone_ins.png"));
//        primaryStage.setScene(scene);
//        primaryStage.setOnCloseRequest(e -> {
//            HibernateUtil.shutdown();
//           System.exit(0);
//        });
//        primaryStage.show();
//    }
//
//    /**
//     * @param args the command line arguments
//     */
//     public static void main(String[] args) throws IOException {
//        // We want to store updates in our app dir so must init that here.
//        AppDirectory.initAppDir(APP_NAME);
//        setupLogging();
//        // re-enter at realMain, but possibly running a newer version of the software i.e. after this point the
//        // rest of this code may be ignored.
//        UpdateFX.bootstrap(App.class, AppDirectory.dir(), args);
//        
//        String appId = "generation.validateur.typefichier.App";
//        boolean alreadyRunning;
//        try {
//            JUnique.acquireLock(appId);
//            alreadyRunning = false;
//        } catch (AlreadyLockedException e) {
//            alreadyRunning = true;
//        }
//        if (!alreadyRunning) {
//            launch(args);
//        } else {
//            System.exit(1);
//        }
//    }
//    
//    public static void realMain(String[] args) {
//        launch(args);
//    }
//     
//    private static void setupLogging() throws IOException {
//        logger = java.util.logging.Logger.getLogger("");
//        logger.getHandlers()[0].setFormatter(new BriefLogFormatter());
//        FileHandler handler = new FileHandler(AppDirectory.dir().resolve("log.txt").toString(), true);
//        handler.setFormatter(new BriefLogFormatter());
//        logger.addHandler(handler);
//    }
//    
//    private ProgressIndicator showGiantProgressWheel(Stage stage) {
//        ProgressIndicator indicator = new ProgressIndicator();
//        BorderPane borderPane = new BorderPane(indicator);
//        borderPane.setMinWidth(640);
//        borderPane.setMinHeight(480);
//        Button pinButton = new Button();
//        pinButton.setText("Pin to version "+VERSION);
//        pinButton.setOnAction(event -> {
//            UpdateFX.pinToVersion(AppDirectory.dir(), VERSION);
//            UpdateFX.restartApp();
//        });
//        HBox box = new HBox(new Label("Version " + VERSION), pinButton);
//        box.setSpacing(10);
//        box.setAlignment(Pos.CENTER_LEFT);
//        box.setPadding(new Insets(10));
//        borderPane.setTop(box);
//        Scene scene = new Scene(borderPane);
//        stage.setScene(scene);
//        
//        return indicator;
//    }
//    
//    private ProgressIndicator showGiantProgressWheel(MainController controller) {
//        ProgressIndicator indicator = controller.getIndicator();
//        
//        Label label = controller.getLabelVersion();
//        label.setText("Version "+VERSION);
//        
//        return indicator;
//    }
}