我一直在为一群 Minecrafters 和他们的 Modpack 编写程序,该程序是一个自定义启动器。问题是当 Mac-OSX 用户尝试使用该程序时,它的文件夹存在问题/Users/<username>/Library/Application Support/.melbvicminecraft/
,我知道这是一个权限问题,但我想找到一种方法让他们使用该应用程序而不需要他们拥有 root权限。
主.java:
public static File getMinecraftDir()
{
String os = getOS();
String userHome = System.getProperty("user.home", ".");
if(os == "win")
{
String appdata = System.getenv("APPDATA");
String location = appdata != null ? appdata : userHome;
return new File(location);
}
else if(os == "mac")
{
return new File(userHome, "Library/Application Support/");
}
else
return new File(userHome);
}
MinecraftLoginThread.java:
/**
* Make a new Minecraft login handler with the selected dir
*
* @param settings Settings file located on the <strong>server</strong>
* @param server The content server
* @param minecraftDir minecraftDir The selected Minecraft dir
*/
public MinecraftLoginThread(SettingsFile settings, String server, File minecraftDir)
{
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
}
catch (Exception e)
{
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e1)
{
e1.printStackTrace();
}
}
try
{
Main.logger.debug("Minecraft dir: " + minecraftDir.getAbsolutePath());
Main.logger.debug("Minecraft exists: " + minecraftDir.exists());
if(!minecraftDir.exists())
{
try
{
minecraftDir.setWritable(true);
minecraftDir.setReadable(true);
if(minecraftDir.mkdirs())
Main.logger.debug("Made new Minecraft dir: " + minecraftDir.getAbsolutePath());
else
Main.killError("Failed to make new Minecraft dir!");
}
catch (Exception e) { Main.killError(e.toString()); }
}
if(!(new File(minecraftDir, "lastLogin").exists()))
(new File(minecraftDir, "lastLogin")).createNewFile();
this.lastLogin = new SettingsFile((new File(minecraftDir, "lastLogin")));
this.lastLogin.load();
}
catch(Exception e)
{
e.printStackTrace();
}
this.settings = settings;
this.server = server;
this.backgroundManager = new BackgroundManager(server + settings.getSetting("net.melbvicmc.launcher.mlbl"));
this.mcDir = minecraftDir;
this.optionsDialog = new MinecraftOptionsDialog(this);
loadJFrameLayout();
}
这是来自 Mac 的日志:The log
该应用程序可以在这里找到:启动器下载