Skip to content

Commit

Permalink
- Added option to skip soundtrack
Browse files Browse the repository at this point in the history
- Fixed potential resource leaks
  • Loading branch information
jrb0001 committed Mar 26, 2017
1 parent 6d2199b commit 3a2d67e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 27 deletions.
4 changes: 4 additions & 0 deletions src/main/java/de/_692b8c32/cdlauncher/OptionsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class OptionsController implements Initializable {
private TextField commandMono;
@FXML
private CheckBox rightBar;
@FXML
private CheckBox downloadSoundtrack;

private final Application application;
private final Preferences preferences;
Expand All @@ -60,6 +62,7 @@ public void initialize(URL location, ResourceBundle resources) {
commandMake.setText(preferences.get("commandMake", "make"));
commandMono.setText(preferences.get("commandMono", "mono"));
rightBar.setSelected(preferences.get("barMode", "bottombar").equals("rightbar"));
downloadSoundtrack.setSelected(preferences.getBoolean("downloadSoundtrack", true));

commandMake.disableProperty().bind(buildFromSources.selectedProperty().not());
}
Expand All @@ -73,6 +76,7 @@ public void save() {
preferences.put("commandMake", commandMake.getText());
preferences.put("commandMono", commandMono.getText());
preferences.put("barMode", rightBar.isSelected() ? "rightbar" : "bottombar");
preferences.putBoolean("downloadSoundtrack", downloadSoundtrack.isSelected());

FXUtils.showScene(application, "/fxml/main.fxml");
}
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/de/_692b8c32/cdlauncher/UpdateController.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,24 @@ public void initialize(URL location, ResourceBundle resources) {

TaskProgress downloadModTask = new GITUpdateTask("Mod (download)", cdCache, "https://github.com/DoGyAUT/cd.git", Arrays.asList());
TaskProgress checkoutModTask = new GITCheckoutTask("Mod (checkout)", cdCache, new File(destination, "mods/cd"), "master", "refs/remotes/origin/master", Arrays.asList(downloadModTask, oraFilesReadyTask)); // TODO: Use preferences.
TaskProgress downloadSoundtrackTask = new GITUpdateTask("Soundtrack (download)", stCache, "https://github.com/jrb0001/cdsoundtrack.git", Arrays.asList());
TaskProgress checkoutSoundtrackTask = new GITCheckoutTask("Soundtrack (checkout)", stCache, new File(destination, "mods/cd/audio/data/theme"), "master", "refs/remotes/origin/master", Arrays.asList(downloadSoundtrackTask, checkoutModTask)); // TODO: Use preferences.
TaskProgress setOptionsTask = new SetOptionsTask("Apply options", new File(destination, "mods/cd"), preferences.get("barMode", "bottombar"), Arrays.asList(checkoutModTask));

progressTable.getItems().addAll(FXCollections.observableList(Arrays.asList(
downloadModTask,
checkoutModTask,
downloadSoundtrackTask,
checkoutSoundtrackTask,
setOptionsTask
)));

if (preferences.getBoolean("downloadSoundtrack", true)) {
TaskProgress downloadSoundtrackTask = new GITUpdateTask("Soundtrack (download)", stCache, "https://github.com/jrb0001/cdsoundtrack.git", Arrays.asList());
TaskProgress checkoutSoundtrackTask = new GITCheckoutTask("Soundtrack (checkout)", stCache, new File(destination, "mods/cd/audio/data/theme"), "master", "refs/remotes/origin/master", Arrays.asList(downloadSoundtrackTask, checkoutModTask)); // TODO: Use preferences.

progressTable.getItems().addAll(FXCollections.observableList(Arrays.asList(
downloadSoundtrackTask,
checkoutSoundtrackTask
)));
}

progressTable.getItems().forEach(task -> new Thread(task, "Task " + task.getName()).start());

nameColumn.setCellValueFactory(cell -> new ReadOnlyObjectWrapper<>(cell.getValue().getName()));
Expand Down
27 changes: 14 additions & 13 deletions src/main/java/de/_692b8c32/cdlauncher/tasks/ExtractZipTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,21 @@ public void doWork() {

try {
FileUtils.delete(destinationDir, FileUtils.RECURSIVE | FileUtils.SKIP_MISSING);
ZipFile zipFile = new ZipFile(cacheFile);
zipFile.stream().filter(entry -> !entry.isDirectory()).forEach(entry -> {
try {
String name = entry.getName();
for (int i = 0; i < skipSourceParts; i++) {
name = name.substring(name.indexOf("/"));
try (ZipFile zipFile = new ZipFile(cacheFile)) {
zipFile.stream().filter(entry -> !entry.isDirectory()).forEach(entry -> {
try {
String name = entry.getName();
for (int i = 0; i < skipSourceParts; i++) {
name = name.substring(name.indexOf("/"));
}
File file = new File(destinationDir, name);
file.getParentFile().mkdirs();
Files.copy(zipFile.getInputStream(entry), file.toPath());
} catch (IOException ex) {
throw new RuntimeException("Failed to extract file from zip", ex);
}
File file = new File(destinationDir, name);
file.getParentFile().mkdirs();
Files.copy(zipFile.getInputStream(entry), file.toPath());
} catch (IOException ex) {
throw new RuntimeException("Failed to extract file from zip", ex);
}
});
});
}
} catch (IOException ex) {
throw new RuntimeException("Failed to extract zip", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
Expand Down Expand Up @@ -56,18 +57,22 @@ public void doWork() {
HttpClient client = HttpClients.createDefault();
String realUrl = null;
Pattern pattern = Pattern.compile("<a id=\"uc-download-link\" class=\"goog-inline-block jfk-button jfk-button-action\" href=\"([^\"]*)\">");
for (String line : new BufferedReader(new InputStreamReader(client.execute(new HttpGet(fileUrl)).getEntity().getContent())).lines().collect(Collectors.toList())) {
Matcher matcher = pattern.matcher(line);
if (matcher.find()) {
realUrl = fileUrl.substring(0, fileUrl.lastIndexOf('/')) + matcher.group(1).replace("&amp;", "&");
break;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(client.execute(new HttpGet(fileUrl)).getEntity().getContent()))) {
for (String line : reader.lines().collect(Collectors.toList())) {
Matcher matcher = pattern.matcher(line);
if (matcher.find()) {
realUrl = fileUrl.substring(0, fileUrl.lastIndexOf('/')) + matcher.group(1).replace("&amp;", "&");
break;
}
}
}

if (realUrl == null) {
throw new RuntimeException("Failed to find real url");
} else {
Files.copy(client.execute(new HttpGet(realUrl)).getEntity().getContent(), cacheFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
try (InputStream stream = client.execute(new HttpGet(realUrl)).getEntity().getContent()) {
Files.copy(stream, cacheFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
}
} catch (IOException ex) {
Logger.getLogger(GoogleDownloadTask.class.getName()).log(Level.SEVERE, null, ex);
Expand Down
11 changes: 7 additions & 4 deletions src/main/resources/fxml/options.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
Expand All @@ -59,10 +60,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
<TextField fx:id="commandMake" maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" GridPane.columnIndex="1" GridPane.hgrow="ALWAYS" GridPane.rowIndex="2" />
<Label layoutX="10.0" layoutY="77.0" maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" text="Command for mono (leave empty on Windows)" GridPane.hgrow="ALWAYS" GridPane.rowIndex="3" />
<TextField fx:id="commandMono" layoutX="110.0" layoutY="72.0" maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" GridPane.columnIndex="1" GridPane.hgrow="ALWAYS" GridPane.rowIndex="3" />
<Label layoutX="10.0" layoutY="47.0" maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" text="Use right bar UI" GridPane.rowIndex="4" />
<CheckBox fx:id="rightBar" layoutX="410.0" layoutY="46.0" maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<Button layoutX="410.0" layoutY="12.0" maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#cancel" text="Cancel" GridPane.hgrow="ALWAYS" GridPane.rowIndex="5" />
<Button layoutX="10.0" layoutY="132.0" maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#save" text="Save" GridPane.columnIndex="1" GridPane.hgrow="ALWAYS" GridPane.rowIndex="5" />
<Label layoutX="10.0" layoutY="47.0" maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" text="Use right bar UI" GridPane.hgrow="ALWAYS" GridPane.rowIndex="4" />
<CheckBox fx:id="rightBar" layoutX="410.0" layoutY="46.0" maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" GridPane.columnIndex="1" GridPane.hgrow="ALWAYS" GridPane.rowIndex="4" />
<Label layoutX="10.0" layoutY="137.0" maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" text="Download soundtrack" GridPane.hgrow="ALWAYS" GridPane.rowIndex="5" />
<CheckBox fx:id="downloadSoundtrack" layoutX="410.0" layoutY="136.0" maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" GridPane.columnIndex="1" GridPane.hgrow="ALWAYS" GridPane.rowIndex="5" />
<Button layoutX="410.0" layoutY="12.0" maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#cancel" text="Cancel" GridPane.hgrow="ALWAYS" GridPane.rowIndex="6" />
<Button layoutX="10.0" layoutY="132.0" maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#save" text="Save" GridPane.columnIndex="1" GridPane.hgrow="ALWAYS" GridPane.rowIndex="6" />
</children>
</GridPane>
</center>
Expand Down

0 comments on commit 3a2d67e

Please sign in to comment.