mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-04-10 09:56:23 +00:00
more gamepad stuff
- now have settings files - now read/write gamepad settings to file - now map button/axis for gamepads
This commit is contained in:
83
src/com/limelight/settings/GamepadSettingsManager.java
Normal file
83
src/com/limelight/settings/GamepadSettingsManager.java
Normal file
@@ -0,0 +1,83 @@
|
||||
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.GamepadSettings;
|
||||
|
||||
public class GamepadSettingsManager {
|
||||
private static GamepadSettings cachedSettings;
|
||||
|
||||
|
||||
public static GamepadSettings getSettings() {
|
||||
if (cachedSettings == null) {
|
||||
File gamepadFile = SettingsManager.getInstance().getGamepadFile();
|
||||
ObjectInputStream ois = null;
|
||||
|
||||
try {
|
||||
ois = new ObjectInputStream(new FileInputStream(gamepadFile));
|
||||
GamepadSettings savedSettings = (GamepadSettings)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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return cachedSettings;
|
||||
}
|
||||
|
||||
public static void writeSettings(GamepadSettings settings) {
|
||||
cachedSettings = 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
65
src/com/limelight/settings/SettingsManager.java
Normal file
65
src/com/limelight/settings/SettingsManager.java
Normal file
@@ -0,0 +1,65 @@
|
||||
package com.limelight.settings;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class SettingsManager {
|
||||
|
||||
public static String SETTINGS_DIR = System.getProperty("user.home") + File.separator + "Limelight";
|
||||
|
||||
//directory to hold limelight settings
|
||||
private File settingsDir;
|
||||
|
||||
private File settingsFile;
|
||||
private File gamepadFile;
|
||||
|
||||
private static SettingsManager manager;
|
||||
|
||||
private SettingsManager() {
|
||||
settingsFile = new File(SETTINGS_DIR + "settings");
|
||||
gamepadFile = new File(SETTINGS_DIR + "gamepad");
|
||||
settingsDir = new File(SETTINGS_DIR);
|
||||
}
|
||||
|
||||
public static SettingsManager getInstance() {
|
||||
if (manager == null) {
|
||||
manager = new SettingsManager();
|
||||
}
|
||||
return manager;
|
||||
}
|
||||
|
||||
public File getGamepadFile() {
|
||||
if (!settingsDir.exists()) {
|
||||
settingsFile.mkdirs();
|
||||
}
|
||||
|
||||
if (!gamepadFile.exists()) {
|
||||
try {
|
||||
gamepadFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Unable to create gamepad file");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return gamepadFile;
|
||||
}
|
||||
|
||||
public File getSettingsFile() {
|
||||
if (!settingsDir.exists()) {
|
||||
settingsFile.mkdirs();
|
||||
}
|
||||
|
||||
if (!settingsFile.exists()) {
|
||||
try {
|
||||
settingsFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Unable to create setting file");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return settingsFile;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user