Merge branch 'blueprints-downloads' of https://github.com/Prototik/BuildCraft into Prototik-blueprints-downloads
This commit is contained in:
commit
41358a2f5f
1 changed files with 37 additions and 6 deletions
|
@ -8,7 +8,9 @@
|
||||||
*/
|
*/
|
||||||
package buildcraft;
|
package buildcraft;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
import net.minecraft.entity.item.EntityItemFrame;
|
import net.minecraft.entity.item.EntityItemFrame;
|
||||||
import net.minecraft.entity.item.EntityMinecartChest;
|
import net.minecraft.entity.item.EntityMinecartChest;
|
||||||
|
@ -146,6 +148,8 @@ public class BuildCraftBuilders extends BuildCraftMod {
|
||||||
public static BlueprintDatabase serverDB;
|
public static BlueprintDatabase serverDB;
|
||||||
public static BlueprintDatabase clientDB;
|
public static BlueprintDatabase clientDB;
|
||||||
|
|
||||||
|
private static String downloadsDir;
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
public void loadConfiguration(FMLPreInitializationEvent evt) {
|
public void loadConfiguration(FMLPreInitializationEvent evt) {
|
||||||
File bptMainDir = new File(new File(evt.getModConfigurationDirectory(), "buildcraft"), "blueprints");
|
File bptMainDir = new File(new File(evt.getModConfigurationDirectory(), "buildcraft"), "blueprints");
|
||||||
|
@ -166,8 +170,8 @@ public class BuildCraftBuilders extends BuildCraftMod {
|
||||||
// legacy beta BuildCraft
|
// legacy beta BuildCraft
|
||||||
"\"$MINECRAFT" + File.separator + "config" + File.separator + "buildcraft" + File.separator
|
"\"$MINECRAFT" + File.separator + "config" + File.separator + "buildcraft" + File.separator
|
||||||
+ "blueprints" + File.separator + "client\"",
|
+ "blueprints" + File.separator + "client\"",
|
||||||
// default Windows download location
|
// default user's downloads location
|
||||||
"\"$HOME" + File.separator + "Downloads\""
|
"\"$DOWNLOADS\""
|
||||||
}
|
}
|
||||||
).getStringList().clone();
|
).getStringList().clone();
|
||||||
|
|
||||||
|
@ -192,14 +196,41 @@ public class BuildCraftBuilders extends BuildCraftMod {
|
||||||
clientDB.init(blueprintLibraryInput, blueprintLibraryOutput);
|
clientDB.init(blueprintLibraryInput, blueprintLibraryOutput);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getDownloadsDir() {
|
||||||
|
if (downloadsDir != null) {
|
||||||
|
return downloadsDir;
|
||||||
|
}
|
||||||
|
final String os = System.getProperty("os.name").toLowerCase();
|
||||||
|
if (os.contains("nix") || os.contains("lin") || os.contains("mac")) {
|
||||||
|
// Linux, Mac or other UNIX
|
||||||
|
// According XDG specification every user-specified folder can be localized
|
||||||
|
// or even moved to any destination, so we obtain real path with xdg-user-dir
|
||||||
|
try {
|
||||||
|
Process process = Runtime.getRuntime().exec(new String[] {"xdg-user-dir", "DOWNLOAD"});
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), "utf-8"));
|
||||||
|
process.waitFor();
|
||||||
|
String line = reader.readLine().trim();
|
||||||
|
reader.close();
|
||||||
|
if (line.length() > 0) {
|
||||||
|
return downloadsDir = line;
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
// Very bad, we have a error while obtaining xdg dir :(
|
||||||
|
// Just ignore, uses default dir
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Windows or unknown system
|
||||||
|
return downloadsDir = "$HOME" + File.separator + "Downloads";
|
||||||
|
}
|
||||||
|
|
||||||
private String replacePathVariables(String path) {
|
private String replacePathVariables(String path) {
|
||||||
String result = path.replaceAll("\\$HOME", System.getProperty("user.home").replaceAll("\\\\", "\\\\\\\\"));
|
String result = path.replace("$DOWNLOADS", getDownloadsDir());
|
||||||
|
result = result.replace("$HOME", System.getProperty("user.home"));
|
||||||
|
|
||||||
if (Launch.minecraftHome == null) {
|
if (Launch.minecraftHome == null) {
|
||||||
result = result.replaceAll("\\$MINECRAFT", new File(".").getAbsolutePath().replaceAll("\\\\", "\\\\\\\\"));
|
result = result.replace("$MINECRAFT", new File(".").getAbsolutePath());
|
||||||
} else {
|
} else {
|
||||||
result = result.replaceAll("\\$MINECRAFT",
|
result = result.replace("$MINECRAFT", Launch.minecraftHome.getAbsolutePath());
|
||||||
Launch.minecraftHome.getAbsolutePath().replaceAll("\\\\", "\\\\\\\\"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Reference in a new issue