|
| 1 | +package com.avairebot.watchdog; |
| 2 | + |
| 3 | +import java.io.BufferedReader; |
| 4 | +import java.io.IOException; |
| 5 | +import java.io.InputStream; |
| 6 | +import java.io.InputStreamReader; |
| 7 | +import java.util.Arrays; |
| 8 | + |
| 9 | +class VersionFormatter { |
| 10 | + |
| 11 | + static void formatAndSend() { |
| 12 | + ProcessBuilder pb = new ProcessBuilder(); |
| 13 | + |
| 14 | + pb.command(Arrays.asList("java", "-jar", "AvaIre.jar", "--version", "--no-colors")); |
| 15 | + |
| 16 | + try { |
| 17 | + Process process = pb.start(); |
| 18 | + |
| 19 | + StringBuilder content = new StringBuilder(); |
| 20 | + try (InputStream inputStream = process.getInputStream()) { |
| 21 | + InputStreamReader streamReader = new InputStreamReader(inputStream); |
| 22 | + BufferedReader reader = new BufferedReader(streamReader); |
| 23 | + |
| 24 | + String line; |
| 25 | + while ((line = reader.readLine()) != null) { |
| 26 | + content.append(line).append("\n"); |
| 27 | + } |
| 28 | + } catch (IOException e) { |
| 29 | + e.printStackTrace(); |
| 30 | + } |
| 31 | + process.waitFor(); |
| 32 | + process.destroy(); |
| 33 | + |
| 34 | + if (content.toString().trim().isEmpty()) { |
| 35 | + System.out.println("No AvaIre.jar file were found, unable to show the version of Ava being used."); |
| 36 | + System.out.println("Watchdog is version: " + AppInfo.getAppInfo().getVersion()); |
| 37 | + return; |
| 38 | + } |
| 39 | + |
| 40 | + for (String line : content.toString().split("\n")) { |
| 41 | + System.out.println(line); |
| 42 | + if (line.contains("Version:")) { |
| 43 | + StringBuilder watchdogLine = new StringBuilder("\tWatchdog:"); |
| 44 | + int index = line.indexOf(line.trim().split("\\s+")[1]); |
| 45 | + while (watchdogLine.length() < index) { |
| 46 | + watchdogLine.append(" "); |
| 47 | + } |
| 48 | + System.out.println(watchdogLine.append(AppInfo.getAppInfo().getVersion()).toString()); |
| 49 | + } |
| 50 | + } |
| 51 | + } catch (IOException | InterruptedException e) { |
| 52 | + e.printStackTrace(); |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments