Advertisement
Guest User

Untitled

a guest
May 20th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (BOOL)mountManualPointWithDictionary:(NSDictionary *)theDict
  2. {
  3.     return [self mountManualPointWithDictionary:theDict softLink:TRUE returnString:nil];
  4. }
  5. - (BOOL)mountManualPointWithDictionary:(NSDictionary *)theDict returnString:(NSString * *)rstring
  6. {
  7.     return [self mountManualPointWithDictionary:theDict softLink:TRUE returnString:rstring];
  8. }
  9. - (BOOL)mountManualPointWithDictionary:(NSDictionary *)theDict softLink:(BOOL)link returnString:(NSString * *)rstring
  10. {
  11.     BRTextWithSpinnerController *theController = [[BRTextWithSpinnerController alloc]initWithTitle:BRLocalizedString(@"Mounting Volume",@"Mounting Volume")
  12.                                                                                               text:BRLocalizedString(@"Mounting Volume Please Wait...", @"text for spinning progress controller while waiting for mount to finish")];
  13.     [[[BRApplicationStackManager singleton] stack] pushController:theController];
  14.     NSDictionary *mountProps = theDict;
  15.     int mountTypes = [[mountProps valueForKey:@"mountType"] intValue];
  16.     int requiresAuth = [[mountProps valueForKey:@"requiresAuth"] intValue];
  17.     NSString *mountLocation = [mountProps valueForKey:@"mountAddress"];
  18.     NSString *userName = [mountProps valueForKey:@"userLogin"];
  19.     NSString *userPassword = [mountProps valueForKey:@"userPassword"];
  20.     NSString *volumeName = [mountProps valueForKey:@"mountVolume"];
  21.    
  22.     int customMount = [[mountProps valueForKey:@"customMount"] intValue];
  23.    
  24.     if (customMount == nil)
  25.         customMount = 0;
  26.     NSString *customPath = [mountProps valueForKey:@"customPath"];
  27.    
  28.     if (customPath == nil)
  29.         customPath = @"";
  30.  
  31.    
  32.    
  33.     NSString *newDevice = [@"/Volumes" stringByAppendingPathComponent:[volumeName lastPathComponent]];
  34.     NSString *newDir = [NSHomeDirectory() stringByAppendingPathComponent:@"Movies"];//[[RUIPreferenceManager sharedPreferences] stringForKey:@"mountLocation" forDomain:@"com.apple.frontrow.appliance.nitoTV"];
  35.     NSMutableString *mutString = [[NSMutableString alloc] init];
  36.    
  37.     switch (mountTypes) {
  38.            
  39.         case 0:
  40.             [mutString appendString:@"afp://"];
  41.             if (requiresAuth == 0)
  42.             {
  43. //                [mutString appendString:userName];
  44. //                [mutString appendString:@":"];
  45. //                [mutString appendString:userPassword];
  46. //                [mutString appendString:@"@"];
  47.                 [mutString appendString:[NSString stringWithFormat:@"%@:%@@",userName,userPassword,nil]];
  48.             }
  49.                  
  50.             [mutString appendString:mountLocation];
  51.             [mutString appendString:@"/"];
  52.             [mutString appendString:volumeName];
  53.             break;
  54.            
  55.         case 1:
  56.            
  57.             if (requiresAuth == 0)
  58.             {
  59.                 //[mutString appendString:userName];
  60.                 //[mutString appendString:@":"];
  61.                 //[mutString appendString:userPassword];
  62.                 //[mutString appendString:@"@"];
  63.             }
  64.             [mutString appendString:mountLocation];
  65.             [mutString appendString:@":"];
  66.             [mutString appendString:volumeName];
  67.             break;
  68.            
  69.         case 2:
  70.             [mutString appendString:@"//"];
  71.             if (requiresAuth == 0)
  72.             {
  73.                 [mutString appendString:userName];
  74.                 [mutString appendString:@":"];
  75.                 [mutString appendString:userPassword];
  76.                 [mutString appendString:@"@"];
  77.             }
  78.             [mutString appendString:mountLocation];
  79.             [mutString appendString:@"/"];
  80.             [mutString appendString:volumeName];
  81.             break;
  82.     }
  83.    
  84.    
  85.     //[mutString appendString:@" "];
  86.     //[mutString appendString:newDevice];
  87.    
  88.    
  89.    
  90.     //NSLog(@"mount_afp %@", mutString);
  91.     NSFileManager *man = [NSFileManager defaultManager];
  92.    
  93.     if (![man fileExistsAtPath:newDevice])
  94.         [man createDirectoryAtPath:newDevice attributes:nil];
  95.     //NSString *zstring;
  96.     BOOL success= [self mountPoint:mutString atPoint:newDevice ofType:mountTypes returnString:rstring];
  97.     [[[BRApplicationStackManager singleton]stack]popController];
  98.     //returnString=rstring;
  99.  
  100.     /*
  101.      *  Need to define Failure Response HERE
  102.      */
  103.    
  104.     if (!success) //mount failed
  105.     {
  106.         BRAlertController *alertController = [BRAlertController alertOfType:0
  107.                                                      titled:BRLocalizedString(@"Network Mount Failed!", @"alert when network mount fails")
  108.                                                 primaryText:*rstring
  109.                                               secondaryText:BRLocalizedString(@"Popping this Alert in 10 secs", @"secondary text when network mount fails")];
  110.         [alertController retain];
  111.         [[[BRApplicationStackManager singleton] stack] pushController:alertController];
  112.         [self performSelector:@selector(popController:) withObject:alertController afterDelay:10.0];
  113.         return FALSE;
  114.     }
  115.    
  116.    
  117.    
  118.     //NSLog(@"returnString: %@",*rstring);
  119.     if (customMount == 1)
  120.     {
  121.         newDevice = [newDevice stringByAppendingPathComponent:customPath];
  122.         //NSLog(@"customDir: %@", newDevice);
  123.     }
  124.     if (link) {
  125.         NSLog(@"linking %@ to %@",newDevice,newDir);
  126.         [self linkDirectory:newDevice toPath:newDir];
  127.     }
  128.     NSLog(@"ending");
  129.     return TRUE;
  130.    
  131. }
  132. - (BOOL)mountPoint:(NSString *)inpoint atPoint:(NSString *)outPoint ofType:(int)theType returnString:(NSString * *)rstring
  133. {
  134.     NSString *errorString = nil;
  135.     NSFileManager *man = [NSFileManager defaultManager];
  136.     NSTask *afpTask = [[NSTask alloc] init];
  137.     NSPipe *afpPipe = [[NSPipe alloc] init];
  138.     NSFileHandle *afpHandle = [afpPipe fileHandleForReading];
  139.     NSMutableArray *afpArray = [[NSMutableArray alloc] init];
  140.     NSString *mountTool = nil;
  141.     if (theType == SMAFPMount)
  142.     {
  143.         mountTool = @"/sbin/mount_afp";
  144.         if ([man fileExistsAtPath:mountTool])
  145.         {
  146.             [afpTask setLaunchPath:mountTool];
  147.         } else {
  148.             NSLog(@"FIXME: mount_afp missing, cannot mount");
  149.             return FALSE;
  150.         }
  151.        
  152.     } else if (theType == SMNFSMount) {
  153.         mountTool = @"/sbin/mount_nfs";
  154.         if ([man fileExistsAtPath:mountTool])
  155.         {
  156.             [afpTask setLaunchPath:mountTool];
  157.             [afpArray addObject:@"-T"];
  158.             [afpArray addObject:@"-b"];
  159.             [afpArray addObject:@"-R"];
  160.             [afpArray addObject:@"100"];
  161.         } else {
  162.             NSLog(@"FIXME: mount_nfs missing, cannot mount");
  163.             return FALSE;
  164.         }
  165.        
  166.        
  167.     } else if (theType == SMSMBMount) {
  168.         mountTool = @"/sbin/mount_smbfs";
  169.         if ([man fileExistsAtPath:mountTool])
  170.         {
  171.             [afpTask setLaunchPath:mountTool];
  172.         } else {
  173.             NSLog(@"FIXME: mount_smbfs missing, cannot mount");
  174.             return FALSE;
  175.         }
  176.        
  177.        
  178.     }
  179.     [afpArray addObject:inpoint];
  180.     [afpArray addObject:outPoint];
  181.     [afpTask setArguments:afpArray];
  182.     [afpTask setStandardError:afpPipe];
  183.     [afpTask setStandardOutput:afpPipe];
  184.     //NSLog(@"%@ %@", mountTool, [afpArray componentsJoinedByString:@" "]);
  185.     //NSLog(@"mount %@", [afpArray componentsJoinedByString:@" "]);
  186.     [afpTask launch];
  187.    
  188.     [afpTask waitUntilExit];
  189.     NSData *outData;
  190.     outData = [afpHandle readDataToEndOfFile];
  191.     NSString *temp = [[NSString alloc] initWithData:outData encoding:NSASCIIStringEncoding];
  192.     temp = [temp stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  193.     int theTerm = [afpTask terminationStatus];
  194.     NSLog(@"mountTask terminated with status: %i", theTerm);
  195.     [afpArray release];
  196.     [afpTask release];
  197.     afpTask = nil;
  198.     [afpPipe release];
  199.     afpPipe = nil;
  200.     if (rstring!=nil) {
  201.         *rstring=[NSString stringWithString:temp];
  202.     }
  203.     //[temp release];
  204.     switch (theTerm)
  205.     {
  206.         case 0: //success
  207.            
  208.             NSLog(@"mount success!");
  209.             return TRUE;
  210.             break;
  211.            
  212.         default: //anything BUT success
  213.             errorString = temp;
  214.             NSLog(@"failed with error: %@", temp);
  215.             return FALSE;
  216.            
  217.             break;
  218.            
  219.     }
  220.    
  221.  
  222.    
  223.     return FALSE;
  224.    
  225. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement