Allow replays to be started by "replay://" URIs (e.g. from browser)

This commit is contained in:
johni0702
2015-07-06 19:59:20 +02:00
parent 948803571d
commit 2d96cd9cc2
5 changed files with 267 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
package eu.crushedpixel.replaymod.online.urischeme;
import eu.crushedpixel.replaymod.ReplayMod;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.StringBuilderWriter;
import java.io.IOException;
public class WindowsUriScheme extends UriScheme {
@Override
public void install() throws IOException, InterruptedException {
String path = ReplayMod.getContainer().getSource().getAbsolutePath().replace("\\", "\\\\").replace("\"", "\\\"");
regAdd("\\replaymod /f /ve /d \"URL:replaymod Protocol\"");
regAdd("\\replaymod /f /v \"URL Protocol\" /d \"\"");
regAdd("\\replaymod\\shell\\open\\command /f /ve /d \"java -cp \\\"" + path + "\\\" " + UriScheme.class.getName() + " \\\"%1\\\"\"");
}
private void regAdd(String args) throws IOException, InterruptedException {
Process process = Runtime.getRuntime().exec("REG ADD HKCU\\Software\\Classes" + args);
try {
if (process.waitFor() != 0) {
StringBuilderWriter writer = new StringBuilderWriter();
IOUtils.copy(process.getInputStream(), writer);
IOUtils.copy(process.getErrorStream(), writer);
throw new IOException(writer.toString());
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}