OSDN Git Service

chore: increment Version to v1.3.6
[delesterandomselector/DelesteRandomSelector.git] / src / com / ranfa / main / DelesteRandomSelector.java
index 766ead5..9d4b605 100644 (file)
@@ -38,7 +38,7 @@ import com.ranfa.lib.Song;
 import com.ranfa.lib.TwitterIntegration;
 import com.ranfa.lib.Version;
 
-@Version(major = 1, minor = 2, patch = 2)
+@Version(major = 1, minor = 3, patch = 6)
 public class DelesteRandomSelector extends JFrame {
 
        private static ArrayList<Song> selectedSongsList = new ArrayList<Song>();
@@ -67,6 +67,7 @@ public class DelesteRandomSelector extends JFrame {
        private boolean integratorBool = false;
        private JTextArea textArea;
        private JScrollPane scrollPane;
+       private CompletableFuture<Void> softwareUpdateFuture = null;
 
        /**
         * Launch the application.
@@ -124,11 +125,14 @@ public class DelesteRandomSelector extends JFrame {
                                + "\nSong Limit: " + property.getSongLimit()
                                + "\nSaveScoreLog: " + property.isSaveScoreLog()
                                + "\nOutputDebugSentences: " + property.isOutputDebugSentences());
+               if(property.isCheckVersion()) {
+                       softwareUpdateFuture = CompletableFuture.runAsync(() -> CheckVersion.needToBeUpdated(), es);
+               }
                BiConsumer<ArrayList<Song>, ArrayList<Song>> updateConsumer = (list1, list2) -> {
                        LimitedLog.println(this.getClass() + ":[INFO]: " + "Checking database updates...");
                        if(list1.size() > list2.size()) {
                                long time = System.currentTimeMillis();
-                               LimitedLog.println(this.getClass() + ":[INFO]: " + "Update detected.");
+                               LimitedLog.println(this.getClass() + ":[INFO]: " + (list1.size() - list2.size()) + " Update detected.");
                                Scraping.writeToJson(list1);
                                LimitedLog.println(this.getClass() + ":[INFO]: " + "Update completed in " + (System.currentTimeMillis() - time) + "ms");
                                LimitedLog.println(this.getClass() + ":[INFO]: " + "Updated database size: " + list1.size());
@@ -137,16 +141,24 @@ public class DelesteRandomSelector extends JFrame {
                        }
                };
                Runnable setEnabled = () -> {
+                       try {
+                               Thread.sleep(1000);
+                       } catch (InterruptedException e1) {
+                               // TODO 自動生成された catch ブロック
+                               e1.printStackTrace();
+                       }
                        btnImport.setEnabled(true);
                        btnImport.setText("<html><body>楽曲<br>絞り込み</body></html>");
                };
                getWholeDataFuture.thenAcceptAsync(list -> LimitedLog.println(this.getClass() + ":[INFO]: Scraping data size:" + list.size()), es);
                getFromJsonFuture.thenAcceptAsync(list -> LimitedLog.println(this.getClass() + ":[INFO]: Currently database size:" + list.size()), es);
-               CompletableFuture<Void> updatedFuture = getWholeDataFuture.thenAcceptBothAsync(getFromJsonFuture, updateConsumer, es);
-               updatedFuture.thenRunAsync(setEnabled, es);
+               if(property.isCheckLibraryUpdates()) {
+                       CompletableFuture<Void> updatedFuture = getWholeDataFuture.thenAcceptBothAsync(getFromJsonFuture, updateConsumer, es);
+                       updatedFuture.thenRunAsync(setEnabled, es);
+               }
                LimitedLog.println(this.getClass() + ":[DEBUG]: " + "Version:" + CheckVersion.getVersion());
                setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-               setBounds(100, 100, 640, 360);
+               setBounds(100, 100, property.getWindowWidth(), property.getWindowHeight());
                contentPane = new JPanel();
                contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
                setContentPane(contentPane);
@@ -270,18 +282,14 @@ public class DelesteRandomSelector extends JFrame {
                btnStart.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                                Random random = new Random(System.currentTimeMillis());
-                               String[] tmp = new String[property.getSongLimit()];
+                               String paneString = "";
                                integratorArray = new String[property.getSongLimit()];
                                for(int i = 0; i < property.getSongLimit(); i++) {
                                        int randomInt = random.nextInt(selectedSongsList.size());
-                                       tmp[i] = (i + 1) + "曲目: " + selectedSongsList.get(randomInt).getAttribute() + " [" + selectedSongsList.get(randomInt).getDifficulty() + "]「" + selectedSongsList.get(randomInt).getName() + "」!(Lv:" + selectedSongsList.get(randomInt).getLevel() + ")\n\n";
+                                       paneString = paneString + (i + 1) + "曲目: " + selectedSongsList.get(randomInt).getAttribute() + " [" + selectedSongsList.get(randomInt).getDifficulty() + "]「" + selectedSongsList.get(randomInt).getName() + "」!(Lv:" + selectedSongsList.get(randomInt).getLevel() + ")\n\n";
                                        integratorArray[i] = selectedSongsList.get(randomInt).getName() + "(Lv" + selectedSongsList.get(randomInt).getLevel() + ")\n";
                                }
-                               String paneString = "";
-                               for (int i = 0; i < tmp.length; i++) {
-                                       paneString = paneString + tmp[i];
-                               }
-                               paneString = paneString + "この" + tmp.length + "曲をプレイしましょう!!!";
+                               paneString = paneString + "この" + property.getSongLimit() + "曲をプレイしましょう!!!";
                                textArea.setText(paneString);
                                integratorBool = true;
                                LimitedLog.println(this.getClass() + ":[INFO]: " + "show up completed.");
@@ -349,11 +357,11 @@ public class DelesteRandomSelector extends JFrame {
                                                                btnExit = new JButton("終了");
                                                                btnExit.addActionListener(new ActionListener() {
                                                                        public void actionPerformed(ActionEvent e) {
-                                                                               LimitedLog.println(this.getClass() + ":[INFO]: " +"Requested Exit by Button");
-                                                                               if(updatedFuture.isDone()) {
+                                                                               if(softwareUpdateFuture.isDone()) {
+                                                                                       LimitedLog.println(this.getClass() + ":[INFO]: " +"Requested Exit by Button");
                                                                                        System.exit(0);
                                                                                } else {
-                                                                                       JOptionPane.showMessageDialog(null, "非同期処理が完了していません。少し時間が経ってからやり直してください。");
+                                                                                       JOptionPane.showMessageDialog(null, "内部更新処理が完了していません。少し待ってからやり直してください。");
                                                                                }
                                                                        }
                                                                });
@@ -370,7 +378,7 @@ public class DelesteRandomSelector extends JFrame {
 
                scrollPane = new JScrollPane(textArea);
                panelCentre.add(scrollPane, BorderLayout.CENTER);
-               if(isFirst)
+               if(isFirst || !property.isCheckLibraryUpdates())
                        setEnabled.run();
        }