Remove settings

This commit is contained in:
Iwan Timmer
2014-01-10 19:08:16 +01:00
parent e96db6764d
commit d5e691540b
3 changed files with 1 additions and 340 deletions

View File

@@ -10,7 +10,6 @@ import com.limelight.nvstream.NvConnectionListener;
import com.limelight.nvstream.StreamConfiguration;
import com.limelight.nvstream.av.video.VideoDecoderRenderer;
import com.limelight.nvstream.http.NvHTTP;
import com.limelight.settings.PreferencesManager.Preferences.Resolution;
import java.io.FileNotFoundException;
import java.net.InetAddress;
import java.net.SocketException;
@@ -105,26 +104,6 @@ public class Limelight implements NvConnectionListener {
}
}
/*
* Creates a StreamConfiguration given a Resolution.
* Used to specify what kind of stream will be used.
*/
private static StreamConfiguration createConfiguration(Resolution res) {
switch(res) {
case RES_720_30:
return new StreamConfiguration(1280, 720, 30);
case RES_720_60:
return new StreamConfiguration(1280, 720, 60);
case RES_1080_30:
return new StreamConfiguration(1920, 1080, 30);
case RES_1080_60:
return new StreamConfiguration(1920, 1080, 60);
default:
// this should never happen, if it does we want the NPE to occur so we know something is wrong
return null;
}
}
/**
* The entry point for the application. <br>
* Does some initializations and then creates the main frame.
@@ -184,19 +163,7 @@ public class Limelight implements NvConnectionListener {
} else
host = args[args.length-1];
Resolution streamRes = Resolution.RES_720_30;
if (resolution == 720 && refresh == 30) {
streamRes = Resolution.RES_720_30;
} else if (resolution == 720 && refresh == 60) {
streamRes = Resolution.RES_720_60;
} else if (resolution == 1080 && refresh == 30) {
streamRes = Resolution.RES_1080_30;
} else if (resolution == 1080 && refresh == 60) {
streamRes = Resolution.RES_1080_60;
}
StreamConfiguration streamConfig = createConfiguration(streamRes);
StreamConfiguration streamConfig = new StreamConfiguration((resolution/9)*16, resolution, refresh);
Limelight limelight = new Limelight(host);
if (!pair)

View File

@@ -1,145 +0,0 @@
package com.limelight.settings;
import java.io.File;
import java.io.Serializable;
/**
* Manages user preferences
* @author Diego Waxemberg
*/
public abstract class PreferencesManager {
private static Preferences cachedPreferences = null;
/**
* Writes the specified preferences to the preferences file and updates the cached preferences.
* @param prefs the preferences to be written out
*/
public static void writePreferences(Preferences prefs) {
System.out.println("Writing Preferences");
File prefFile = SettingsManager.getInstance().getSettingsFile();
SettingsManager.writeSettings(prefFile, prefs);
cachedPreferences = prefs;
}
/**
* Reads the user preferences from the preferences file and caches them
* @return the user preferences
*/
public static Preferences getPreferences() {
if (cachedPreferences == null) {
System.out.println("Reading Preferences");
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;
}
/**
* Represents a user's preferences
* @author Diego Waxemberg
*/
public static class Preferences implements Serializable {
private static final long serialVersionUID = -5575445156215348048L;
/**
* The possible resolutions for the stream
*/
public enum Resolution { RES_720_30("1280x720 (30Hz)"), RES_720_60("1280x720 (60Hz)"),
RES_1080_30("1920x1080 (30Hz)"), RES_1080_60("1920x1080 (60Hz)");
public String name;
/*
* Creates a new resolution with the specified name
*/
private Resolution(String name) {
this.name = name;
}
/**
* Gets the specified name for this resolution
* @return the specified name of this resolution
*/
@Override
public String toString() {
return name;
}
};
private Resolution res;
private boolean fullscreen;
private String host;
/**
* constructs default preferences: 720p 30Hz fullscreen
*/
public Preferences() {
this(Resolution.RES_720_30, true);
}
/**
* Constructs a preference with the specified values
* @param res the <code>Resolution</code> to use
* @param fullscreen whether to start the stream in fullscreen
*/
public Preferences(Resolution res, boolean fullscreen) {
this.res = res;
this.fullscreen = fullscreen;
this.host = "GeForce PC host";
}
/**
* The saved host in this preference
* @return the last used host
*/
public String getHost() {
return host;
}
/**
* Sets the host for this preference
* @param host the host to save
*/
public void setHost(String host) {
this.host = host;
}
/**
* Gets the resolution in this preference
* @return the stored resolution
*/
public Resolution getResolution() {
return res;
}
/**
* Gets whether to use fullscreen
* @return the stored fullscreen mode
*/
public boolean getFullscreen() {
return fullscreen;
}
/**
* Sets the resolution in this preference
* @param res the resolution to save
*/
public void setResolution(Resolution res) {
this.res = res;
}
/**
* Sets the fullscreen mode of this preference
* @param fullscreen whether to use fullscreen
*/
public void setFullscreen(boolean fullscreen) {
this.fullscreen = fullscreen;
}
}
}

View File

@@ -1,161 +0,0 @@
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;
/**
* Manages the settings files
* @author Diego Waxemberg
*/
public class SettingsManager {
/**
* Directory to which settings will be saved
*/
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;
/*
* Constructs a manager that initializes the settings files
*/
private SettingsManager() {
settingsFile = new File(SETTINGS_DIR + File.separator + "settings.lime");
gamepadFile = new File(SETTINGS_DIR + File.separator + "gamepad.lime");
settingsDir = new File(SETTINGS_DIR);
}
/**
* Gets an instance of the manager, this is a singleton
* @return the instance of the manager
*/
public static SettingsManager getInstance() {
if (manager == null) {
manager = new SettingsManager();
}
return manager;
}
/**
* Gets the gamepad preference file, if the file does not exist, it is created first
* @return the gamepad preference file
*/
public File getGamepadFile() {
if (!settingsDir.exists()) {
settingsDir.mkdirs();
}
if (!gamepadFile.exists()) {
try {
gamepadFile.createNewFile();
} catch (IOException e) {
System.out.println("Unable to create gamepad file");
return null;
}
}
return gamepadFile;
}
/**
* Gets the settings file (user preferences), if the file does not exist, it is created first
* @return the settings file
*/
public File getSettingsFile() {
if (!settingsDir.exists()) {
settingsDir.mkdirs();
}
if (!settingsFile.exists()) {
try {
settingsFile.createNewFile();
} catch (IOException e) {
System.out.println("Unable to create setting file");
return null;
}
}
return settingsFile;
}
/**
* Reads the specified file as a settings file and returns the result.
* <br>A settings file must be a java serialized object
* @param file the file to read in
* @return the settings represented in this file
*/
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;
}
/**
* Writes the specified settings to the desired file
* @param file the file to write the settings to
* @param settings the settings to be written out
*/
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();
}
}
}
}
}