예제 #1
0
 /**
  * called every time a setting is changed saves settings file to
  * .minecraft/mods/$backendname/guiconfig.properties coming soon: set name of config file
  *
  * @param context The context to save.
  */
 @SuppressWarnings("rawtypes")
 public void save(String context) {
   if (!settingsLoaded) {
     return;
   }
   try {
     File path =
         ModSettings.getAppDir(
             "/" + ModSettings.contextDatadirs.get(context) + "/" + backendname + "/");
     ModSettings.dbgout(
         "saving context "
             + context
             + " ("
             + path.getAbsolutePath()
             + " ["
             + ModSettings.contextDatadirs.get(context)
             + "])");
     if (!path.exists()) {
       path.mkdirs();
     }
     File file = new File(path, "guiconfig.properties");
     Properties p = new Properties();
     for (int i = 0; i < Settings.size(); i++) {
       Setting z = Settings.get(i);
       p.put(z.backendName, z.toString(context));
     }
     FileOutputStream out = new FileOutputStream(file);
     p.store(out, "");
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
예제 #2
0
 /**
  * must be called after all settings are added for loading/saving to work. loads from
  * .minecraft/mods/$backendname/guiconfig.properties if it exists. coming soon: set name of config
  * file
  *
  * @param context The context to load from.
  */
 @SuppressWarnings("rawtypes")
 public void load(String context) {
   for (; ; ) {
     try {
       if (ModSettings.contextDatadirs.get(context) == null) {
         break;
       }
       File path =
           ModSettings.getAppDir(
               "/" + ModSettings.contextDatadirs.get(context) + "/" + backendname + "/");
       if (!path.exists()) {
         break;
       }
       File file = new File(path, "guiconfig.properties");
       if (!file.exists()) {
         break;
       }
       Properties p = new Properties();
       p.load(new FileInputStream(file));
       for (int i = 0; i < Settings.size(); i++) {
         ModSettings.dbgout("setting load");
         Setting z = Settings.get(i);
         if (p.containsKey(z.backendName)) {
           ModSettings.dbgout("setting " + (String) p.get(z.backendName));
           z.fromString((String) p.get(z.backendName), context);
         }
       }
       break;
     } catch (Exception e) {
       System.out.println(e);
       break;
     }
   }
 }