Fix crash with certain render output file values (fixes #396)
This commit is contained in:
@@ -129,7 +129,7 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
|||||||
public void run() {
|
public void run() {
|
||||||
GuiFileChooserPopup popup = GuiFileChooserPopup.openSaveGui(GuiRenderSettings.this, "replaymod.gui.save",
|
GuiFileChooserPopup popup = GuiFileChooserPopup.openSaveGui(GuiRenderSettings.this, "replaymod.gui.save",
|
||||||
encodingPresetDropdown.getSelectedValue().getFileExtension());
|
encodingPresetDropdown.getSelectedValue().getFileExtension());
|
||||||
popup.setFolder(outputFile.getParentFile());
|
popup.setFolder(getParentFile(outputFile));
|
||||||
popup.setFileName(outputFile.getName());
|
popup.setFileName(outputFile.getName());
|
||||||
Futures.addCallback(
|
Futures.addCallback(
|
||||||
popup.getFuture(),
|
popup.getFuture(),
|
||||||
@@ -538,13 +538,13 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
|||||||
bitRateUnit.setSelected(0);
|
bitRateUnit.setSelected(0);
|
||||||
}
|
}
|
||||||
File savedOutputFile = settings.getOutputFile();
|
File savedOutputFile = settings.getOutputFile();
|
||||||
if (savedOutputFile == null || !savedOutputFile.getParentFile().exists()) {
|
if (savedOutputFile == null || !getParentFile(savedOutputFile).exists()) {
|
||||||
this.outputFile = generateOutputFile(encodingPreset);
|
this.outputFile = generateOutputFile(encodingPreset);
|
||||||
userDefinedOutputFileName = false;
|
userDefinedOutputFileName = false;
|
||||||
} else if (savedOutputFile.exists()) {
|
} else if (savedOutputFile.exists()) {
|
||||||
String name = generateOutputFile(encodingPreset).getName();
|
String name = generateOutputFile(encodingPreset).getName();
|
||||||
boolean isFolder = savedOutputFile.isDirectory() && !savedOutputFile.getName().endsWith(".exr");
|
boolean isFolder = savedOutputFile.isDirectory() && !savedOutputFile.getName().endsWith(".exr");
|
||||||
this.outputFile = new File(isFolder ? savedOutputFile : savedOutputFile.getParentFile(), name);
|
this.outputFile = new File(isFolder ? savedOutputFile : getParentFile(savedOutputFile), name);
|
||||||
userDefinedOutputFileName = false;
|
userDefinedOutputFileName = false;
|
||||||
} else {
|
} else {
|
||||||
this.outputFile = conformExtension(savedOutputFile, encodingPreset);
|
this.outputFile = conformExtension(savedOutputFile, encodingPreset);
|
||||||
@@ -588,7 +588,7 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
|||||||
videoHeight.getInteger(),
|
videoHeight.getInteger(),
|
||||||
frameRateSlider.getValue() + 10,
|
frameRateSlider.getValue() + 10,
|
||||||
bitRateField.getInteger() << (10 * bitRateUnit.getSelected()),
|
bitRateField.getInteger() << (10 * bitRateUnit.getSelected()),
|
||||||
serialize && !userDefinedOutputFileName ? outputFile.getParentFile() : outputFile,
|
serialize && !userDefinedOutputFileName ? getParentFile(outputFile) : outputFile,
|
||||||
nametagCheckbox.isChecked(),
|
nametagCheckbox.isChecked(),
|
||||||
stabilizeYaw.isChecked() && (serialize || stabilizeYaw.isEnabled()),
|
stabilizeYaw.isChecked() && (serialize || stabilizeYaw.isEnabled()),
|
||||||
stabilizePitch.isChecked() && (serialize || stabilizePitch.isEnabled()),
|
stabilizePitch.isChecked() && (serialize || stabilizePitch.isEnabled()),
|
||||||
@@ -617,7 +617,7 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
|||||||
|
|
||||||
public void setOutputFileBaseName(String base) {
|
public void setOutputFileBaseName(String base) {
|
||||||
RenderSettings.EncodingPreset preset = encodingPresetDropdown.getSelectedValue();
|
RenderSettings.EncodingPreset preset = encodingPresetDropdown.getSelectedValue();
|
||||||
File file = new File(outputFile.getParentFile(), base + "." + preset.getFileExtension());
|
File file = new File(getParentFile(outputFile), base + "." + preset.getFileExtension());
|
||||||
// Ensure the file name is valid
|
// Ensure the file name is valid
|
||||||
try {
|
try {
|
||||||
//noinspection ResultOfMethodCallIgnored
|
//noinspection ResultOfMethodCallIgnored
|
||||||
@@ -634,7 +634,7 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
|||||||
if (name.contains(".")) {
|
if (name.contains(".")) {
|
||||||
name = name.substring(0, name.lastIndexOf('.'));
|
name = name.substring(0, name.lastIndexOf('.'));
|
||||||
}
|
}
|
||||||
return new File(file.getParentFile(), name + "." + preset.getFileExtension());
|
return new File(getParentFile(file), name + "." + preset.getFileExtension());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Path getSettingsPath() {
|
protected Path getSettingsPath() {
|
||||||
@@ -677,4 +677,10 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
|||||||
screen.setBackground(AbstractGuiScreen.Background.NONE);
|
screen.setBackground(AbstractGuiScreen.Background.NONE);
|
||||||
return screen;
|
return screen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static File getParentFile(File file) {
|
||||||
|
File parent = file.getParentFile();
|
||||||
|
// parent this can be null if file is just a name (i.e. in CWD)
|
||||||
|
return parent == null ? new File(".") : parent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user