package fileIO;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import engine.Game;

/*  ------------- Nihilne ------------
    * Created by Mitch Weaver - 2016 *
      ~~~~ All Rights Reserved ~~~~ */

public final class Saving {

	public static final synchronized SettingsSaveFile readSettingsSaveFile() {
		try {
			final File in = new File(System.getProperty("user.home"), "settings.nihil");
			final FileInputStream fis = new FileInputStream(in);
			final ObjectInputStream ois = new ObjectInputStream(fis);
			final SettingsSaveFile readSettingsSaveFile = (SettingsSaveFile) ois.readObject();
			fis.close(); return readSettingsSaveFile;
		} catch (Exception e) {
			System.out.println("WARNING: Unable to read settings save file.");
			return null;
		}
	}

	public static final synchronized void saveSettingsSaveFile(final SettingsSaveFile saveFile) {
		try {
			final File out = new File(System.getProperty("user.home"), "settings.nihil");
			final ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(out));
			oos.writeObject(saveFile); oos.close();
		} catch (Exception e) {
			e.printStackTrace();
			Game.cleanUp();
		}
	}

}
