From 72271a0c742c91cf1f1bd58c4565b05f50186e27 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Tue, 21 Oct 2014 13:46:05 -0400 Subject: [PATCH] Don't crash if no PC is selected when a button is pressed --- .../ViewControllers/MainFrameViewController.m | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Limelight/ViewControllers/MainFrameViewController.m b/Limelight/ViewControllers/MainFrameViewController.m index 14a323b..06a234a 100644 --- a/Limelight/ViewControllers/MainFrameViewController.m +++ b/Limelight/ViewControllers/MainFrameViewController.m @@ -34,6 +34,12 @@ static StreamConfiguration* streamConfig; _selectedHost = [[Computer alloc] initWithIp:self.hostTextField.text]; NSLog(@"Using custom host: %@", self.hostTextField.text); } + + if (![self validatePcSelected]) { + NSLog(@"No valid PC selected"); + return; + } + [CryptoManager generateKeyPairUsingSSl]; NSString* uniqueId = [CryptoManager getUniqueID]; NSData* cert = [CryptoManager readCertFromFile]; @@ -74,6 +80,12 @@ static StreamConfiguration* streamConfig; _selectedHost = [[Computer alloc] initWithIp:self.hostTextField.text]; NSLog(@"Using custom host: %@", self.hostTextField.text); } + + if (![self validatePcSelected]) { + NSLog(@"No valid PC selected"); + return; + } + streamConfig = [[StreamConfiguration alloc] init]; streamConfig.host = _selectedHost.hostName; streamConfig.hostAddr = [Utils resolveHost:_selectedHost.hostName]; @@ -195,6 +207,19 @@ static StreamConfiguration* streamConfig; [self setSelectedHost:[self.HostPicker selectedRowInComponent:0]]; } +- (BOOL)validatePcSelected { + if (_selectedHost == NULL) { + UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"No PC Selected" + message:@"You must select a PC to continue." + preferredStyle:UIAlertControllerStyleAlert]; + [alert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDestructive handler:nil]]; + [self presentViewController:alert animated:YES completion:nil]; + return FALSE; + } + + return TRUE; +} + - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning];