Guest User

Untitled

a guest
Jun 19th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. //
  2. // PortsController.m
  3. // Porton
  4. //
  5. // Created by Juan Germán Castañeda Echevarría on 3/28/09.
  6. // Copyright 2009 UNAM. All rights reserved.
  7. //
  8.  
  9. #import "PortsController.h"
  10.  
  11.  
  12. @implementation PortsController
  13.  
  14. - (void)awakeFromNib
  15. {
  16. [self setLoaded:NO];
  17. [self setBusy:YES];
  18. }
  19.  
  20. - (void)loadIndex
  21. {
  22. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  23. [self setBusy:YES];
  24. portsIndex = [MPIndex new];
  25. NSArray *ports = [portsIndex ports];
  26. [portsList addObjects: ports];
  27. [self setLoaded:YES];
  28. [self setBusy:NO];
  29. [pool release];
  30. }
  31.  
  32. - (void)install
  33. {
  34. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  35. [self setBusy:YES];
  36.  
  37. NSArray *ports = [portsList selectedObjects];
  38. for (int i = 0; i < [ports count]; i++) {
  39. NSError * error;
  40. MPPort * port = [ports objectAtIndex:i];
  41. [port installWithOptions:nil variants:nil error:&error];
  42.  
  43. if (error != nil) {
  44. NSLog(@"\n\nInstallation of %@ failed with error %@", [port name], error);
  45. [[NSAlert alertWithMessageText:@"Port Installation Failed"
  46. defaultButton:@"OK"
  47. alternateButton:nil
  48. otherButton:nil
  49. informativeTextWithFormat:@"Installation of %@ failed with error %@", [port name], error] runModal];
  50. } else {
  51. [port setState:MPPortStateInstalled];
  52. [[NSAlert alertWithMessageText:@"Port Installed"
  53. defaultButton:@"OK"
  54. alternateButton:nil
  55. otherButton:nil
  56. informativeTextWithFormat:@"You have succesfully installed %@", [port name]] runModal];
  57. }
  58. }
  59. [self setMessage:@""];
  60. [self setBusy:NO];
  61. [pool release];
  62. }
  63.  
  64. - (void)uninstall
  65. {
  66. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  67. [self setBusy:YES];
  68.  
  69. NSArray *ports = [portsList selectedObjects];
  70. for (int i = 0; i < [ports count]; i++) {
  71. NSError * error;
  72. MPPort * port = [ports objectAtIndex:i];
  73. [port uninstallWithVersion:nil error:&error];
  74.  
  75. if (error != nil) {
  76. NSLog(@"\n\nUninstallation of %@ failed with error %@", [port name], error);
  77. } else {
  78. [port setState:MPPortStateNotInstalled];
  79. [[NSAlert alertWithMessageText:@"Port Uninstalled"
  80. defaultButton:@"OK"
  81. alternateButton:nil
  82. otherButton:nil
  83. informativeTextWithFormat:@"You have succesfully uninstalled %@", [port name]] runModal];
  84. }
  85. }
  86. [self setMessage:@""];
  87. [self setBusy:NO];
  88. [pool release];
  89. }
  90.  
  91. #pragma mark Bindings
  92.  
  93. - (void)setLoaded:(BOOL)newLoaded
  94. {
  95. loaded = newLoaded;
  96. }
  97.  
  98. - (BOOL)loaded
  99. {
  100. return loaded;
  101. }
  102.  
  103. - (void)setBusy:(BOOL)newBusy
  104. {
  105. busy = newBusy;
  106. }
  107.  
  108. - (BOOL)busy
  109. {
  110. return busy;
  111. }
  112.  
  113. - (void)setMessage:(NSString*)newMsg
  114. {
  115. message = newMsg;
  116. }
  117.  
  118. - (NSString*)message
  119. {
  120. return message;
  121. }
  122.  
  123. @end
Add Comment
Please, Sign In to add comment