From b751d4b47f4bc847dab0a8cea149491d44dc6a59 Mon Sep 17 00:00:00 2001 From: CaS Date: Mon, 6 Jun 2005 18:27:22 +0000 Subject: [PATCH] implement local mount point listing as drive listing under mingw git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@21288 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 +++ Source/NSWorkspace.m | 76 ++++++++++++++++++++++++++++++++++---------- 2 files changed, 64 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index ff5e5813b..b3815f70d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-06-06 Richard Frith-Macdonald + + * Source/NSWorkspace.m: ([-mountedLocalVovumePaths]) implemented + for mingw as a listing of all device names. + 2005-06-06 Adrian Robert * Headers/AppKit/NSApplication.h diff --git a/Source/NSWorkspace.m b/Source/NSWorkspace.m index ba8cae90b..4e32c9964 100644 --- a/Source/NSWorkspace.m +++ b/Source/NSWorkspace.m @@ -1215,25 +1215,29 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath - (NSArray*) mountedRemovableMedia { - NSArray *volumes = [self mountedLocalVolumePaths]; - NSMutableArray *names = [NSMutableArray arrayWithCapacity: [volumes count]]; - unsigned i; + NSArray *volumes; + NSMutableArray *names; + unsigned count; + unsigned i; - for (i = 0; i < [volumes count]; i++) + volumes = [self mountedLocalVolumePaths]; + count = [volumes count]; + names = [NSMutableArray arrayWithCapacity: count]; + for (i = 0; i < count; i++) { - BOOL removableFlag; - BOOL writableFlag; - BOOL unmountableFlag; - NSString *description; - NSString *fileSystemType; - NSString *name = [volumes objectAtIndex: i]; + BOOL removableFlag; + BOOL writableFlag; + BOOL unmountableFlag; + NSString *description; + NSString *fileSystemType; + NSString *name = [volumes objectAtIndex: i]; if ([self getFileSystemInfoForPath: name - isRemovable: &removableFlag - isWritable: &writableFlag - isUnmountable: &unmountableFlag - description: &description - type: &fileSystemType] && removableFlag) + isRemovable: &removableFlag + isWritable: &writableFlag + isUnmountable: &unmountableFlag + description: &description + type: &fileSystemType] && removableFlag) { [names addObject: name]; } @@ -1244,12 +1248,50 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath - (NSArray*) mountedLocalVolumePaths { + NSMutableArray *names; + NSFileManager *mgr = [NSFileManager defaultManager]; +#ifdef __MINGW__ + unsigned max = BUFSIZ; + unichar buf[max]; + unichar *base = buf; + unichar *ptr; + unichar *end; + unsigned len; + + len = GetLogicalDriveStringsW(max-1, base); + while (len >= max) + { + base = NSZoneMalloc(NSDefaultMallocZone(), (len+1) * sizeof(unichar)); + max = len; + len = GetLogicalDriveStringsW(max-1, base); + } + for (ptr = base; *ptr != 0; ptr = end + 1) + { + NSString *path; + + end = ptr; + while (*end != 0) + { + end++; + } + len = (end - ptr) * sizeof(unichar); + path = [mgr stringWithFileSystemRepresentation: (char*)ptr length: len]; + [names addObject: path]; + } + if (base != buf) + { + NSZoneFree(NSDefaultMallocZone(), base); + } + +#else + // FIXME This is system specific NSString *mtab = [NSString stringWithContentsOfFile: @"/etc/mtab"]; NSArray *mounts = [mtab componentsSeparatedByString: @"\n"]; - NSMutableArray *names = [NSMutableArray arrayWithCapacity: [mounts count]]; + NSMutableArray *names; unsigned int i; + names = [NSMutableArray arrayWithCapacity: [mounts count]]; for (i = 0; i < [mounts count]; i++) { NSString *mount = [mounts objectAtIndex: i]; @@ -1271,7 +1313,7 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath } } } - +#endif return names; }