Java中的Mac文件/目录创建问题

时间:2013-01-10 06:40:04

标签: java macos io

我一直在为一组Minecrafters和他们的Modpack编写一个程序,该程序是一个自定义启动器。问题是,当Mac-OSX用户尝试使用该程序时,它在/Users/<username>/Library/Application Support/.melbvicminecraft/中创建文件夹时出现问题,我知道这是一个权限问题,但我想找到一种让他们无需使用应用程序的方法让他们拥有root权限。

Main.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

可以在此处找到该应用程序:Launcher Download

0 个答案:

没有答案