33import com .snoworange .mousse .Main ;
44import com .snoworange .mousse .module .Module ;
55import com .snoworange .mousse .module .ModuleManager ;
6+ import com .snoworange .mousse .setting .Setting ;
67import com .snoworange .mousse .setting .settings .BooleanSetting ;
78import com .snoworange .mousse .setting .settings .KeyBindSetting ;
89import com .snoworange .mousse .setting .settings .ModeSetting ;
@@ -21,13 +22,13 @@ public class FileUtils {
2122 public static void saveAll () {
2223 saveActiveModules (mousse );
2324 saveBinds (mousse );
24- saveModuleSetting (mousse );
25+ saveSettings (mousse );
2526 }
2627
2728 public static void loadAll () {
2829 loadActiveModules (mousse );
2930 loadBinds (mousse );
30- loadModuleSetting (mousse );
31+ loadSettings (mousse );
3132 }
3233
3334 public static void createDirectory () {
@@ -137,103 +138,65 @@ public static void loadBinds(final File file) {
137138 ex .printStackTrace ();
138139 }
139140
140- public static void saveModuleSetting (final File directory ) {
141-
142- File setting = config ;
143-
144- if (!directory .exists ()){
145- directory .mkdir ();
146- }
147- if (!setting .exists ()){
148- setting .mkdir ();
149- }
150-
151- try {
152- for (Module m : Main .moduleManager .getModuleList ()){
153- File module = new File (setting , m .getName ());
154- if (!module .exists ()) {
155- module .createNewFile ();
141+ public static void saveSettings (final File file ) {
142+ Exception ex ;
143+ try {
144+ final File settings = new File (file .getAbsolutePath (), "Settings.txt" );
145+ final BufferedWriter bw = new BufferedWriter (new FileWriter (settings ));
146+ for (final Module m : ModuleManager .instance .getModuleList ()) {
147+ bw .write (m .getName () + ":" );
148+ for (final Setting <?> s : m .settings ) {
149+ bw .write (s .name + "-" + s .value + ":" );
156150 }
157-
158- PrintWriter pw = new PrintWriter (module );
159-
160- final String [] str = {"" };
161-
162- str [0 ] += m .isToggled ()?"1" :"0" ;
163- str [0 ] += "\n " ;
164-
165- m .settings .forEach (s -> {
166- if (s instanceof KeyBindSetting ){
167- str [0 ] += "0" +String .valueOf (((KeyBindSetting ) s ).getKeyCode ());
168- }
169- if (s instanceof BooleanSetting ){
170- str [0 ] += ((BooleanSetting )s ).isEnable ()?"11" :"10" ;
171- }
172- if (s instanceof ModeSetting ){
173- str [0 ] += "2" + ((ModeSetting ) s ).index ;
174- }
175- if (s instanceof NumberSetting ){
176- str [0 ] += "3" + String .valueOf (((NumberSetting ) s ).value );
177- }
178- str [0 ] += "\n " ;
179- });
180-
181- pw .print (str [0 ]);
182- pw .close ();
151+ bw .write ("\r \n " );
183152 }
184- } catch ( IOException e ){
185-
153+ bw . close ();
154+ return ;
186155 }
156+ catch (Exception e ) {
157+ ex = e ;
158+ }
159+ ex .printStackTrace ();
187160 }
188161
189- public static void loadModuleSetting (final File directory ) {
190-
191- File setting = config ;
192-
193- if (setting .isDirectory ()){
194- for (Module m : Main .moduleManager .getModuleList ()) {
195- File SettingFile = new File (setting , m .getName ());
196- try {
197- FileReader filereader = new FileReader (SettingFile );
198- int ch ;
199- String str = "" ;
200- while ((ch = filereader .read ()) != -1 ){
201- str += String .valueOf ((char )ch );
202- }
203- int i = 0 ;
204- for (String val : Arrays .asList (str .split ("\n " ))) {
205- if (i == 0 ) {
206- //m.setToggled(val.equals("1")?true:false);
207- System .out .println ("Balls" );
208- }else {
209-
210- String dat = val .substring (1 );
211- if (val .startsWith ("0" )) {
212- KeyBindSetting bind = (KeyBindSetting )m .settings .get (i -1 );
213- bind .keyCode = Integer .parseInt (dat );
214- }
215- if (val .startsWith ("1" )) {
216- BooleanSetting bind = (BooleanSetting )m .settings .get (i -1 );
217- bind .setEnable (val .equals ("1" ));
218- }
219- if (val .startsWith ("2" )) {
220- ModeSetting bind = (ModeSetting )m .settings .get (i -1 );
221- bind .index = Integer .parseInt (dat );
222- }
223- if (val .startsWith ("3" )) {
224- NumberSetting bind = (NumberSetting )m .settings .get (i -1 );
225- bind .value = Double .parseDouble (dat );
226- }
162+ public static void loadSettings (final File file ) {
163+ Exception ex ;
164+ try {
165+ final File settings = new File (file .getAbsolutePath (), "Settings.txt" );
166+ if (!settings .exists ()) {
167+ settings .createNewFile ();
168+ return ;
169+ }
170+ final BufferedReader br = new BufferedReader (new FileReader (settings ));
171+ final List <String > linezz = Files .readAllLines (settings .toPath ());
172+ for (final String line : linezz ) {
173+ final String [] regex = line .split (":" );
174+ for (final Module m : ModuleManager .instance .getModuleList ()) {
175+ for (int i = 1 ; i < regex .length ; ++i ) {
176+ final String term = regex [i ];
177+ final String [] pair = term .split ("-" );
178+ final Setting <?> s = (Setting <?>) m .settings ;
179+ if (s instanceof BooleanSetting ) {
180+ final BooleanSetting sb = (BooleanSetting ) s ;
181+ sb .setEnable (Boolean .parseBoolean (pair [1 ]));
182+ }
183+ if (s instanceof NumberSetting ) {
184+ final NumberSetting sd = (NumberSetting ) s ;
185+ sd .setValue (Double .parseDouble (pair [1 ]));
186+ }
187+ if (s instanceof ModeSetting ) {
188+ final ModeSetting sm = (ModeSetting ) s ;
189+ sm .is (pair [1 ]);
227190 }
228- i ++;
229191 }
230- } catch (FileNotFoundException e ) {
231- e .printStackTrace ();
232- } catch (IOException | ClassCastException | StringIndexOutOfBoundsException e ) {
233- e .printStackTrace ();
234- SettingFile .delete ();
235192 }
236193 }
194+ br .close ();
195+ return ;
237196 }
197+ catch (Exception e ) {
198+ ex = e ;
199+ }
200+ ex .printStackTrace ();
238201 }
239202}
0 commit comments