Fix paths of files that are supposed to be in the mc data dir (fixes #40)

This commit is contained in:
johni0702
2016-11-26 13:26:53 +01:00
parent e6a789d4f8
commit 00bcc9e65e
5 changed files with 27 additions and 6 deletions

View File

@@ -1,11 +1,17 @@
package com.replaymod.render;
import com.replaymod.core.ReplayMod;
import net.minecraft.crash.CrashReport;
import net.minecraft.util.ReportedException;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.Logger;
import java.io.File;
import java.io.IOException;
@Mod(modid = ReplayModRender.MOD_ID, useMetadata = true)
public class ReplayModRender {
public static final String MOD_ID = "replaymod-render";
@@ -32,6 +38,17 @@ public class ReplayModRender {
core.getSettingsRegistry().register(Setting.class);
}
public File getVideoFolder() {
String path = core.getSettingsRegistry().get(Setting.RENDER_PATH);
File folder = new File(path.startsWith("./") ? core.getMinecraft().mcDataDir : null, path);
try {
FileUtils.forceMkdir(folder);
} catch (IOException e) {
throw new ReportedException(CrashReport.makeCrashReport(e, "Cannot create video folder."));
}
return folder;
}
public Configuration getConfiguration() {
return configuration;
}

View File

@@ -49,7 +49,8 @@ public class VideoWriter implements FrameConsumer<RGBFrame> {
System.out.println("Starting " + settings.getExportCommand() + " with args: " + commandArgs);
String[] cmdline = new CommandLine(executable).addArguments(commandArgs).toStrings();
process = new ProcessBuilder(cmdline).directory(outputFolder).start();
OutputStream exportLogOut = new TeeOutputStream(new FileOutputStream("export.log"), ffmpegLog);
File exportLogFile = new File(Minecraft.getMinecraft().mcDataDir, "export.log");
OutputStream exportLogOut = new TeeOutputStream(new FileOutputStream(exportLogFile), ffmpegLog);
new StreamPipe(process.getInputStream(), exportLogOut).start();
new StreamPipe(process.getErrorStream(), exportLogOut).start();
outputStream = process.getOutputStream();

View File

@@ -7,7 +7,6 @@ import com.google.gson.GsonBuilder;
import com.google.gson.InstanceCreator;
import com.replaymod.render.RenderSettings;
import com.replaymod.render.ReplayModRender;
import com.replaymod.render.Setting;
import com.replaymod.render.rendering.VideoRenderer;
import com.replaymod.replay.ReplayHandler;
import com.replaymod.replaystudio.pathing.path.Timeline;
@@ -410,7 +409,7 @@ public class GuiRenderSettings extends GuiScreen implements Closeable {
private File generateOutputFile(RenderSettings.EncodingPreset encodingPreset) {
String fileName = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new Date());
File folder = new File(ReplayModRender.instance.getCore().getSettingsRegistry().get(Setting.RENDER_PATH));
File folder = ReplayModRender.instance.getVideoFolder();
return new File(folder, fileName + "." + encodingPreset.getFileExtension());
}