[55629] branches/gsoc09-gui/MPGUI/PreferencesController.m

juanger at macports.org juanger at macports.org
Fri Aug 14 18:19:13 PDT 2009


Revision: 55629
          http://trac.macports.org/changeset/55629
Author:   juanger at macports.org
Date:     2009-08-14 18:19:12 -0700 (Fri, 14 Aug 2009)
Log Message:
-----------
Validation for macports path in Preferences panel.

Modified Paths:
--------------
    branches/gsoc09-gui/MPGUI/PreferencesController.m

Modified: branches/gsoc09-gui/MPGUI/PreferencesController.m
===================================================================
--- branches/gsoc09-gui/MPGUI/PreferencesController.m	2009-08-15 01:17:39 UTC (rev 55628)
+++ branches/gsoc09-gui/MPGUI/PreferencesController.m	2009-08-15 01:19:12 UTC (rev 55629)
@@ -19,11 +19,27 @@
     NSInteger result = [openPanel runModalForDirectory:[defaults objectForKey:@"NSNavLastCurrentDirectory"] file:nil types:nil];
     if(result == NSOKButton) {
         NSString *path = [[openPanel filenames] objectAtIndex:0];
-        [defaults setObject:path forKey:@"PKGPath"];
-        NSLog(@"PATH: %@", path);
-        [MPMacPorts setPKGPath:path];
-        [[MPActionLauncher sharedInstance] 
-                    performSelectorInBackground:@selector(loadPorts) withObject:nil];
+        // Validate Directory
+        NSFileManager *fileManager = [NSFileManager defaultManager];
+        BOOL existsAsDirectory;
+        NSString *macportsDir = [path stringByAppendingPathComponent:@"macports1.0"];
+        NSString *macportsFile = [macportsDir stringByAppendingPathComponent:@"macports.tcl"];
+        BOOL containsMacPortsTcl;
+        [fileManager fileExistsAtPath:macportsDir isDirectory:&existsAsDirectory];
+        containsMacPortsTcl = [fileManager fileExistsAtPath:macportsFile isDirectory:nil];
+        if(existsAsDirectory && containsMacPortsTcl) {
+            [defaults setObject:path forKey:@"PKGPath"];
+            [MPMacPorts setPKGPath:path];
+            [[MPActionLauncher sharedInstance] 
+             performSelectorInBackground:@selector(loadPorts) withObject:nil];
+        } else {
+            NSAlert *alert = [NSAlert alertWithMessageText:@"You selected an invalid directory" 
+                                    defaultButton:@"OK" 
+                                    alternateButton:nil 
+                                    otherButton:nil 
+                                    informativeTextWithFormat:@"You have to use the directory where macports1.0 was installed by MacPorts.\n\nGenerally it should be /Library/Tcl"];
+            [alert runModal];
+        }
     }
 }
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20090814/4bf04fc4/attachment.html>


More information about the macports-changes mailing list