2015-02-01 04:26:47 -05:00
|
|
|
//
|
|
|
|
|
// AppListResponse.m
|
2015-05-12 21:48:30 -04:00
|
|
|
// Moonlight
|
2015-02-01 04:26:47 -05:00
|
|
|
//
|
|
|
|
|
// Created by Diego Waxemberg on 2/1/15.
|
2015-05-12 21:48:30 -04:00
|
|
|
// Copyright (c) 2015 Moonlight Stream. All rights reserved.
|
2015-02-01 04:26:47 -05:00
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import "AppListResponse.h"
|
2015-09-30 20:34:52 -07:00
|
|
|
#import "TemporaryApp.h"
|
2015-07-10 21:22:57 -07:00
|
|
|
#import "DataManager.h"
|
2015-02-01 04:26:47 -05:00
|
|
|
#import <libxml2/libxml/xmlreader.h>
|
|
|
|
|
|
|
|
|
|
@implementation AppListResponse {
|
2015-12-01 20:56:08 -08:00
|
|
|
NSMutableSet* _appList;
|
2015-02-01 04:26:47 -05:00
|
|
|
}
|
2015-07-11 18:47:05 -07:00
|
|
|
@synthesize data, statusCode, statusMessage;
|
2015-02-01 04:26:47 -05:00
|
|
|
|
|
|
|
|
static const char* TAG_APP = "App";
|
|
|
|
|
static const char* TAG_APP_TITLE = "AppTitle";
|
|
|
|
|
static const char* TAG_APP_ID = "ID";
|
2018-06-02 12:32:12 -07:00
|
|
|
static const char* TAG_HDR_SUPPORTED = "IsHdrSupported";
|
2019-09-08 18:55:59 -07:00
|
|
|
static const char* TAG_APP_INSTALL_PATH = "AppInstallPath";
|
2015-02-01 04:26:47 -05:00
|
|
|
|
|
|
|
|
- (void)populateWithData:(NSData *)xml {
|
|
|
|
|
self.data = xml;
|
2015-12-01 20:56:08 -08:00
|
|
|
_appList = [[NSMutableSet alloc] init];
|
2015-02-01 04:26:47 -05:00
|
|
|
[self parseData];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) parseData {
|
|
|
|
|
xmlDocPtr docPtr = xmlParseMemory([self.data bytes], (int)[self.data length]);
|
|
|
|
|
if (docPtr == NULL) {
|
2015-02-10 21:26:55 -05:00
|
|
|
Log(LOG_W, @"An error occured trying to parse xml.");
|
2015-02-01 04:26:47 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xmlNodePtr node = xmlDocGetRootElement(docPtr);
|
|
|
|
|
if (node == NULL) {
|
2015-02-10 21:26:55 -05:00
|
|
|
Log(LOG_W, @"No root XML element.");
|
2015-02-01 04:26:47 -05:00
|
|
|
xmlFreeDoc(docPtr);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xmlChar* statusStr = xmlGetProp(node, (const xmlChar*)[TAG_STATUS_CODE UTF8String]);
|
|
|
|
|
if (statusStr != NULL) {
|
2020-04-23 20:07:52 -07:00
|
|
|
int status = (int)[[NSString stringWithUTF8String:(const char*)statusStr] longLongValue];
|
2015-02-01 04:26:47 -05:00
|
|
|
xmlFree(statusStr);
|
|
|
|
|
self.statusCode = status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xmlChar* statusMsgXml = xmlGetProp(node, (const xmlChar*)[TAG_STATUS_MESSAGE UTF8String]);
|
|
|
|
|
NSString* statusMsg;
|
|
|
|
|
if (statusMsgXml != NULL) {
|
|
|
|
|
statusMsg = [NSString stringWithUTF8String:(const char*)statusMsgXml];
|
|
|
|
|
xmlFree(statusMsgXml);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
statusMsg = @"Server Error";
|
|
|
|
|
}
|
|
|
|
|
self.statusMessage = statusMsg;
|
|
|
|
|
|
|
|
|
|
node = node->children;
|
|
|
|
|
|
|
|
|
|
while (node != NULL) {
|
2015-02-10 21:26:55 -05:00
|
|
|
//Log(LOG_D, @"node: %s", node->name);
|
2015-02-01 04:26:47 -05:00
|
|
|
if (!xmlStrcmp(node->name, (xmlChar*)TAG_APP)) {
|
|
|
|
|
xmlNodePtr appInfoNode = node->xmlChildrenNode;
|
2015-07-11 00:10:13 -07:00
|
|
|
NSString* appName = @"";
|
|
|
|
|
NSString* appId = nil;
|
2018-06-02 12:32:12 -07:00
|
|
|
NSString* hdrSupported = @"0";
|
2019-09-08 18:55:59 -07:00
|
|
|
NSString* appInstallPath = nil;
|
2015-02-01 04:26:47 -05:00
|
|
|
while (appInfoNode != NULL) {
|
|
|
|
|
if (!xmlStrcmp(appInfoNode->name, (xmlChar*)TAG_APP_TITLE)) {
|
|
|
|
|
xmlChar* nodeVal = xmlNodeListGetString(docPtr, appInfoNode->xmlChildrenNode, 1);
|
2015-02-10 15:48:29 -05:00
|
|
|
if (nodeVal != NULL) {
|
|
|
|
|
appName = [[NSString alloc] initWithCString:(const char*)nodeVal encoding:NSUTF8StringEncoding];
|
|
|
|
|
xmlFree(nodeVal);
|
|
|
|
|
}
|
2015-02-01 04:26:47 -05:00
|
|
|
} else if (!xmlStrcmp(appInfoNode->name, (xmlChar*)TAG_APP_ID)) {
|
|
|
|
|
xmlChar* nodeVal = xmlNodeListGetString(docPtr, appInfoNode->xmlChildrenNode, 1);
|
2015-02-10 15:48:29 -05:00
|
|
|
if (nodeVal != NULL) {
|
|
|
|
|
appId = [[NSString alloc] initWithCString:(const char*)nodeVal encoding:NSUTF8StringEncoding];
|
|
|
|
|
xmlFree(nodeVal);
|
|
|
|
|
}
|
2018-06-02 12:32:12 -07:00
|
|
|
} else if (!xmlStrcmp(appInfoNode->name, (xmlChar*)TAG_HDR_SUPPORTED)) {
|
|
|
|
|
xmlChar* nodeVal = xmlNodeListGetString(docPtr, appInfoNode->xmlChildrenNode, 1);
|
|
|
|
|
if (nodeVal != NULL) {
|
|
|
|
|
hdrSupported = [[NSString alloc] initWithCString:(const char*)nodeVal encoding:NSUTF8StringEncoding];
|
|
|
|
|
xmlFree(nodeVal);
|
|
|
|
|
}
|
2019-09-08 18:55:59 -07:00
|
|
|
} else if (!xmlStrcmp(appInfoNode->name, (xmlChar*)TAG_APP_INSTALL_PATH)) {
|
|
|
|
|
xmlChar* nodeVal = xmlNodeListGetString(docPtr, appInfoNode->xmlChildrenNode, 1);
|
|
|
|
|
if (nodeVal != NULL) {
|
|
|
|
|
appInstallPath = [[NSString alloc] initWithCString:(const char*)nodeVal encoding:NSUTF8StringEncoding];
|
|
|
|
|
xmlFree(nodeVal);
|
|
|
|
|
}
|
2015-02-01 04:26:47 -05:00
|
|
|
}
|
2019-09-08 18:55:59 -07:00
|
|
|
|
2015-02-01 04:26:47 -05:00
|
|
|
appInfoNode = appInfoNode->next;
|
|
|
|
|
}
|
2015-07-11 00:10:13 -07:00
|
|
|
if (appId != nil) {
|
2015-09-30 20:34:52 -07:00
|
|
|
TemporaryApp* app = [[TemporaryApp alloc] init];
|
2015-07-11 00:10:13 -07:00
|
|
|
app.name = appName;
|
|
|
|
|
app.id = appId;
|
2018-06-02 12:32:12 -07:00
|
|
|
app.hdrSupported = [hdrSupported intValue] != 0;
|
2019-09-08 18:55:59 -07:00
|
|
|
app.installPath = appInstallPath;
|
2015-02-10 15:48:29 -05:00
|
|
|
[_appList addObject:app];
|
|
|
|
|
}
|
2015-02-01 04:26:47 -05:00
|
|
|
}
|
|
|
|
|
node = node->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xmlFreeDoc(docPtr);
|
2019-06-04 18:37:52 -07:00
|
|
|
|
2020-08-30 16:43:56 -07:00
|
|
|
#ifdef ENABLE_APP_STORE_RESTRICTIONS
|
2019-06-04 18:37:52 -07:00
|
|
|
// APP STORE REVIEW COMPLIANCE
|
|
|
|
|
//
|
|
|
|
|
// Remove default Steam entry from the app list to comply with Apple App Store Guideline 4.2.7d:
|
|
|
|
|
//
|
|
|
|
|
// The UI appearing on the client does not resemble an iOS or App Store view, does not provide a store-like interface,
|
|
|
|
|
// or include the ability to browse, select, or purchase software not already owned or licensed by the user.
|
|
|
|
|
//
|
|
|
|
|
// However, if the user manually adds Steam themselves, then we will display it.
|
|
|
|
|
TemporaryApp* officialSteamApp = nil;
|
|
|
|
|
TemporaryApp* manuallyAddedSteamApp = nil;
|
|
|
|
|
for (TemporaryApp* app in _appList) {
|
2019-09-22 10:31:23 -07:00
|
|
|
if (app.installPath != nil && [[app.installPath lowercaseString] hasSuffix:@"\\steam\\"]) {
|
2019-09-08 18:55:59 -07:00
|
|
|
// The official Steam app is marked as HDR supported, while manually added ones are not.
|
|
|
|
|
if ([app.name isEqualToString:@"Steam"] && app.hdrSupported) {
|
|
|
|
|
officialSteamApp = app;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
manuallyAddedSteamApp = app;
|
|
|
|
|
}
|
2019-06-04 18:37:52 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// To be safe, don't do anything if we didn't find an HDR-enabled Steam app.
|
|
|
|
|
if (officialSteamApp != nil) {
|
|
|
|
|
// If we didn't find a manually added Steam app, remove the official one to
|
|
|
|
|
// comply with the App Store guidelines.
|
|
|
|
|
if (manuallyAddedSteamApp == nil) {
|
|
|
|
|
[_appList removeObject:officialSteamApp];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
[_appList removeObject:manuallyAddedSteamApp];
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-30 16:43:56 -07:00
|
|
|
#endif
|
2015-02-01 04:26:47 -05:00
|
|
|
}
|
|
|
|
|
|
2015-12-01 20:56:08 -08:00
|
|
|
- (NSSet*) getAppList {
|
2015-02-01 04:26:47 -05:00
|
|
|
return _appList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) isStatusOk {
|
|
|
|
|
return self.statusCode == 200;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|