mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-04-12 10:56:04 +00:00
added a menu item for preferences and created a framework for preferences
still requires some implementation before fully functional.
This commit is contained in:
@@ -1,16 +1,10 @@
|
||||
package com.limelight.settings;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
import com.limelight.input.GamepadMapping;
|
||||
|
||||
public class GamepadSettingsManager {
|
||||
public abstract class GamepadSettingsManager {
|
||||
private static GamepadMapping cachedSettings;
|
||||
|
||||
|
||||
@@ -18,35 +12,8 @@ public class GamepadSettingsManager {
|
||||
if (cachedSettings == null) {
|
||||
System.out.println("Reading Gamepad Settings");
|
||||
File gamepadFile = SettingsManager.getInstance().getGamepadFile();
|
||||
ObjectInputStream ois = null;
|
||||
|
||||
try {
|
||||
ois = new ObjectInputStream(new FileInputStream(gamepadFile));
|
||||
GamepadMapping savedSettings = (GamepadMapping)ois.readObject();
|
||||
cachedSettings = savedSettings;
|
||||
|
||||
} catch (ClassNotFoundException e) {
|
||||
System.out.println("Saved file is not of the correct type. It might have been modified externally.");
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out.println("Could not find gamepad settings file");
|
||||
e.printStackTrace();
|
||||
|
||||
} catch (IOException e) {
|
||||
System.out.println("Could not read gamepad settings file");
|
||||
e.printStackTrace();
|
||||
|
||||
} finally {
|
||||
if (ois != null) {
|
||||
try {
|
||||
ois.close();
|
||||
|
||||
} catch (IOException e) {
|
||||
System.out.println("Could not close gamepad settings file");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
GamepadMapping savedMapping = (GamepadMapping)SettingsManager.readSettings(gamepadFile);
|
||||
cachedSettings = savedMapping;
|
||||
}
|
||||
if (cachedSettings == null) {
|
||||
System.out.println("Unable to get gamepad settings. Using an empty mapping instead.");
|
||||
@@ -61,31 +28,8 @@ public class GamepadSettingsManager {
|
||||
System.out.println("Writing Gamepad Settings");
|
||||
|
||||
File gamepadFile = SettingsManager.getInstance().getGamepadFile();
|
||||
|
||||
ObjectOutputStream ous = null;
|
||||
|
||||
try {
|
||||
ous = new ObjectOutputStream(new FileOutputStream(gamepadFile));
|
||||
ous.writeObject(settings);
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out.println("Could not find gamepad settings file");
|
||||
e.printStackTrace();
|
||||
|
||||
} catch (IOException e) {
|
||||
System.out.println("Could not write gamepad settings file");
|
||||
e.printStackTrace();
|
||||
|
||||
} finally {
|
||||
if (ous != null) {
|
||||
try {
|
||||
ous.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Unable to close gamepad settings file");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SettingsManager.writeSettings(gamepadFile, settings);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
66
src/com/limelight/settings/PreferencesManager.java
Normal file
66
src/com/limelight/settings/PreferencesManager.java
Normal file
@@ -0,0 +1,66 @@
|
||||
package com.limelight.settings;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
|
||||
public abstract class PreferencesManager {
|
||||
private static Preferences cachedPreferences = null;
|
||||
|
||||
public static void writePreferences(Preferences prefs) {
|
||||
File prefFile = SettingsManager.getInstance().getSettingsFile();
|
||||
|
||||
SettingsManager.writeSettings(prefFile, prefs);
|
||||
}
|
||||
|
||||
public static Preferences getPreferences() {
|
||||
if (cachedPreferences == null) {
|
||||
File prefFile = SettingsManager.getInstance().getSettingsFile();
|
||||
Preferences savedPref = (Preferences)SettingsManager.readSettings(prefFile);
|
||||
cachedPreferences = savedPref;
|
||||
}
|
||||
if (cachedPreferences == null) {
|
||||
System.out.println("Unabled to get preferences, using default");
|
||||
cachedPreferences = new Preferences();
|
||||
writePreferences(cachedPreferences);
|
||||
}
|
||||
return cachedPreferences;
|
||||
}
|
||||
|
||||
public static class Preferences implements Serializable {
|
||||
private static final long serialVersionUID = -5575445156215348048L;
|
||||
|
||||
public enum Resolution { RES_720, RES_1080 };
|
||||
|
||||
private Resolution res;
|
||||
private boolean fullscreen;
|
||||
|
||||
/**
|
||||
* construcs default preferences: 720p fullscreen
|
||||
*/
|
||||
public Preferences() {
|
||||
this.res = Resolution.RES_720;
|
||||
this.fullscreen = true;
|
||||
}
|
||||
|
||||
public Preferences(Resolution res, boolean fullscreen) {
|
||||
this.res = res;
|
||||
this.fullscreen = fullscreen;
|
||||
}
|
||||
|
||||
public Resolution getResolution() {
|
||||
return res;
|
||||
}
|
||||
|
||||
public boolean getFullscreen() {
|
||||
return fullscreen;
|
||||
}
|
||||
|
||||
public void setResolution(Resolution res) {
|
||||
this.res = res;
|
||||
}
|
||||
|
||||
public void setFullscreen(boolean fullscreen) {
|
||||
this.fullscreen = fullscreen;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,13 @@
|
||||
package com.limelight.settings;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class SettingsManager {
|
||||
|
||||
@@ -62,4 +68,62 @@ public class SettingsManager {
|
||||
return settingsFile;
|
||||
}
|
||||
|
||||
public static Object readSettings(File file) {
|
||||
ObjectInputStream ois = null;
|
||||
Object settings = null;
|
||||
try {
|
||||
ois = new ObjectInputStream(new FileInputStream(file));
|
||||
Object savedSettings = ois.readObject();
|
||||
settings = savedSettings;
|
||||
} catch (ClassNotFoundException e) {
|
||||
System.out.println("Saved file is not of the correct type. It might have been modified externally.");
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out.println("Could not find " + file.getName() + " settings file");
|
||||
e.printStackTrace();
|
||||
|
||||
} catch (IOException e) {
|
||||
System.out.println("Could not read " + file.getName() + " settings file");
|
||||
e.printStackTrace();
|
||||
|
||||
} finally {
|
||||
if (ois != null) {
|
||||
try {
|
||||
ois.close();
|
||||
|
||||
} catch (IOException e) {
|
||||
System.out.println("Could not close gamepad settings file");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
public static void writeSettings(File file, Serializable settings) {
|
||||
ObjectOutputStream ous = null;
|
||||
|
||||
try {
|
||||
ous = new ObjectOutputStream(new FileOutputStream(file));
|
||||
ous.writeObject(settings);
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out.println("Could not find " + file.getName() + " settings file");
|
||||
e.printStackTrace();
|
||||
|
||||
} catch (IOException e) {
|
||||
System.out.println("Could not write to " + file.getName() + " settings file");
|
||||
e.printStackTrace();
|
||||
|
||||
} finally {
|
||||
if (ous != null) {
|
||||
try {
|
||||
ous.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Unable to close " + file.getName() + " settings file");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user