From fb8fc54bb1c11c8112d2b6e6945abe4f29aa7204 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 27 Feb 2015 13:29:41 -0500 Subject: [PATCH] Use App IDs for app lookups and deprecate the old name-based lookup function --- .../com/limelight/nvstream/NvConnection.java | 18 +++++++++++---- .../nvstream/StreamConfiguration.java | 22 ++++++++++++++----- .../com/limelight/nvstream/http/NvHTTP.java | 19 +++++++++++++--- 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/moonlight-common/src/com/limelight/nvstream/NvConnection.java b/moonlight-common/src/com/limelight/nvstream/NvConnection.java index e24205ef..4c3f1161 100644 --- a/moonlight-common/src/com/limelight/nvstream/NvConnection.java +++ b/moonlight-common/src/com/limelight/nvstream/NvConnection.java @@ -139,10 +139,20 @@ public class NvConnection { context.connListener.displayMessage("Device not paired with computer"); return false; } - - NvApp app = h.getApp(context.streamConfig.getApp()); + + NvApp app; + + // If the client provided an exact app ID, use that to find the app object + if (context.streamConfig.getAppId() != StreamConfiguration.INVALID_APP_ID) { + app = h.getAppById(context.streamConfig.getAppId()); + } + else { + LimeLog.info("Using deprecated app lookup method - Please specify an app ID in your StreamConfiguration instead"); + app = h.getAppByName(context.streamConfig.getAppName()); + } + if (app == null) { - context.connListener.displayMessage("The app " + context.streamConfig.getApp() + " is not in GFE app list"); + context.connListener.displayMessage("The app " + context.streamConfig.getAppName() + " is not in GFE app list"); return false; } @@ -266,7 +276,7 @@ public class NvConnection { if (currentStage == NvConnectionListener.Stage.LAUNCH_APP) { // Display the app name instead of the stage name - currentStage.setName(context.streamConfig.getApp()); + currentStage.setName(context.streamConfig.getAppName()); } context.connListener.stageStarting(currentStage); diff --git a/moonlight-common/src/com/limelight/nvstream/StreamConfiguration.java b/moonlight-common/src/com/limelight/nvstream/StreamConfiguration.java index 332ce308..4b3627ec 100644 --- a/moonlight-common/src/com/limelight/nvstream/StreamConfiguration.java +++ b/moonlight-common/src/com/limelight/nvstream/StreamConfiguration.java @@ -1,7 +1,10 @@ package com.limelight.nvstream; public class StreamConfiguration { - private String app; + public static final int INVALID_APP_ID = 0; + + private String appName; + private int appId = INVALID_APP_ID; private int width, height; private int refreshRate; private int bitrate; @@ -15,7 +18,12 @@ public class StreamConfiguration { private StreamConfiguration config = new StreamConfiguration(); public StreamConfiguration.Builder setApp(String app) { - config.app = app; + config.appName = app; + return this; + } + + public StreamConfiguration.Builder setAppId(int appId) { + config.appId = appId; return this; } @@ -67,7 +75,7 @@ public class StreamConfiguration { private StreamConfiguration() { // Set default attributes - this.app = "Steam"; + this.appName = "Steam"; this.width = 1280; this.height = 720; this.refreshRate = 60; @@ -97,8 +105,12 @@ public class StreamConfiguration { return maxPacketSize; } - public String getApp() { - return app; + public String getAppName() { + return appName; + } + + public int getAppId() { + return appId; } public boolean getSops() { diff --git a/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java b/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java index ea05c29e..ab7fd4cb 100644 --- a/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java +++ b/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java @@ -304,11 +304,24 @@ public class NvHTTP { return Integer.parseInt(game); } - public NvApp getApp(String app) throws IOException, - XmlPullParserException { + public NvApp getAppById(int appId) throws IOException, XmlPullParserException { LinkedList appList = getAppList(); for (NvApp appFromList : appList) { - if (appFromList.getAppName().equals(app)) { + if (appFromList.getAppId() == appId) { + return appFromList; + } + } + return null; + } + + /* NOTE: Only use this function if you know what you're doing. + * It's totally valid to have two apps named the same thing, + * or even nothing at all! Look apps up by ID if at all possible + * using the above function */ + public NvApp getAppByName(String appName) throws IOException, XmlPullParserException { + LinkedList appList = getAppList(); + for (NvApp appFromList : appList) { + if (appFromList.getAppName().equals(appName)) { return appFromList; } }