copy(ClassLoader.getSystemResourceAsStream("emptyPrefs.xml"), new FileOutputStream(f), EMPTY_PREFS_XML_FILESIZE); copy(ClassLoader.getSystemResourceAsStream("preferences.dtd"), new FileOutputStream(new File(f.getAbsoluteFile() .getParent() + File.separatorChar + "preferences.dtd")), PREFERENCES_DTD_FILESIZE);
try { copy(ClassLoader .getSystemResourceAsStream("emptyPrefs.xml"), new FileOutputStream(f), EMPTY_PREFS_XML_FILESIZE); } catch (NullPointerException e) { JOptionPane.showMessageDialog(null, "The file emptyPrefs.xml was not found.\n" + "It should be in the root of the .jar\n" + "file or in the same directory as it.\n" + "Please try redownloading PK Hack.\n" + "If you have already done so, report the\n" + "error to AnyoneEB.", "ERROR: File not found", JOptionPane.ERROR_MESSAGE); } try { copy(ClassLoader .getSystemResourceAsStream("preferences.dtd"), new FileOutputStream(new File(f.getAbsoluteFile() .getParent() + File.separatorChar + "preferences.dtd")), PREFERENCES_DTD_FILESIZE); } catch (NullPointerException e) { JOptionPane.showMessageDialog(null, "The file preferences.dtd was not found.\n" + "It should be in the root of the .jar\n" + "file or in the same directory as it.\n" + "Please try redownloading PK Hack.\n" + "If you have already done so, report the\n" + "error to AnyoneEB.", "ERROR: File not found", JOptionPane.ERROR_MESSAGE); }
    public XMLPreferences(File f, HashMap defaults)    {        this.f = f;        File preferencesDTD = new File(f.getAbsoluteFile().getParent()            + File.separatorChar + "preferences.dtd");        if (!preferencesDTD.exists())        {            try            {                copy(ClassLoader.getSystemResourceAsStream("preferences.dtd"),                    new FileOutputStream(preferencesDTD),                    PREFERENCES_DTD_FILESIZE);            }            catch (FileNotFoundException e)            {                e.printStackTrace();            }            catch (IOException e)            {                e.printStackTrace();            }        }        if ((dom = parseFile(f)) == null)        {            try            {                File g = new File(f.toString());                if (g.exists())                    g.renameTo(new File(g.toString() + ".old"));                copy(ClassLoader.getSystemResourceAsStream("emptyPrefs.xml"),                    new FileOutputStream(f), EMPTY_PREFS_XML_FILESIZE);                copy(ClassLoader.getSystemResourceAsStream("preferences.dtd"),                    new FileOutputStream(new File(f.getAbsoluteFile()                        .getParent()                        + File.separatorChar + "preferences.dtd")),                    PREFERENCES_DTD_FILESIZE);            }            catch (FileNotFoundException e)            {                System.out.println("Some idiot didn't include emptyPrefs.xml"                    + " or preferences.dtd in the .jar.");                e.printStackTrace();            }            catch (IOException e)            {                e.printStackTrace();            }            dom = parseFile(f);            Object[] defs = defaults.entrySet().toArray();            for (int i = 0; i < defs.length; i++)            {                String[] s = defs[i].toString().split("=");                setValue(s[0], s[1]);            }        }        else        {            Object[] defs = defaults.entrySet().toArray();            for (int i = 0; i < defs.length; i++)            {                String[] s = defs[i].toString().split("=");                if (getValue(s[0]) == null)                    setValue(s[0], s[1]);            }        }    }