22 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 |
*/ |
*/ |
24 |
|
|
|
|
|
25 |
#include <Foundation/Foundation.h> |
#include <Foundation/Foundation.h> |
26 |
#include <AppKit/AppKit.h> |
#include <AppKit/AppKit.h> |
27 |
#include <math.h> |
#include <math.h> |
64 |
|
|
65 |
@implementation GWorkspace |
@implementation GWorkspace |
66 |
|
|
67 |
#define byname 0 |
#ifndef byname |
68 |
#define bykind 1 |
#define byname 0 |
69 |
#define bydate 2 |
#define bykind 1 |
70 |
#define bysize 3 |
#define bydate 2 |
71 |
#define byowner 4 |
#define bysize 3 |
72 |
|
#define byowner 4 |
73 |
#define CACHED_MAX 20; |
#endif |
74 |
|
|
75 |
|
#ifndef CACHED_MAX |
76 |
|
#define CACHED_MAX 20; |
77 |
|
#endif |
78 |
|
|
79 |
// |
// |
80 |
// GWProtocol |
// GWProtocol |
312 |
|
|
313 |
} |
} |
314 |
|
|
315 |
|
- (BOOL)existsAndIsDirectoryFileAtPath:(NSString *)path |
316 |
|
{ |
317 |
|
BOOL isDir; |
318 |
|
return ([fm fileExistsAtPath: path isDirectory: &isDir] && isDir); |
319 |
|
} |
320 |
|
|
321 |
|
- (NSString *)typeOfFileAt:(NSString *)path |
322 |
|
{ |
323 |
|
NSString *defApp, *type; |
324 |
|
[ws getInfoForFile: path application: &defApp type: &type]; |
325 |
|
return type; |
326 |
|
} |
327 |
|
|
328 |
|
- (BOOL)isWritableFileAtPath:(NSString *)path |
329 |
|
{ |
330 |
|
return [fm isWritableFileAtPath: path]; |
331 |
|
} |
332 |
|
|
333 |
- (BOOL)isPakageAtPath:(NSString *)path |
- (BOOL)isPakageAtPath:(NSString *)path |
334 |
{ |
{ |
335 |
NSString *defApp, *type; |
NSString *defApp, *type; |
348 |
return NO; |
return NO; |
349 |
} |
} |
350 |
|
|
351 |
|
- (NSArray *)sortedDirectoryContentsAtPath:(NSString *)path |
352 |
|
{ |
353 |
|
NSMutableDictionary *contentsDict = [self cachedRepresentationForPath: path]; |
354 |
|
|
355 |
|
if (contentsDict) { |
356 |
|
return [contentsDict objectForKey: @"files"]; |
357 |
|
|
358 |
|
} else { |
359 |
|
NSArray *files = [fm directoryContentsAtPath: path]; |
360 |
|
int stype = [self sortTypeForDirectoryAtPath: path]; |
361 |
|
int count = [files count]; |
362 |
|
NSMutableArray *paths = [NSMutableArray arrayWithCapacity: count]; |
363 |
|
NSMutableArray *sortfiles = [NSMutableArray arrayWithCapacity: count]; |
364 |
|
NSArray *sortPaths = nil; |
365 |
|
NSDictionary *attributes = nil; |
366 |
|
NSDate *date = nil; |
367 |
|
SEL appendPathCompSel = @selector(stringByAppendingPathComponent:); |
368 |
|
IMP appendPathComp = [[NSString class] instanceMethodForSelector: appendPathCompSel]; |
369 |
|
SEL lastPathCompSel = @selector(lastPathComponent); |
370 |
|
IMP lastPathComp = [[NSString class] instanceMethodForSelector: lastPathCompSel]; |
371 |
|
int i; |
372 |
|
|
373 |
|
for (i = 0; i < count; i++) { |
374 |
|
NSString *s = (*appendPathComp)(path, appendPathCompSel, [files objectAtIndex: i]); |
375 |
|
[paths addObject: s]; |
376 |
|
} |
377 |
|
|
378 |
|
sortPaths = [paths sortedArrayUsingFunction: (int (*)(id, id, void*))comparePaths |
379 |
|
context: (void *)stype]; |
380 |
|
|
381 |
|
for (i = 0; i < count; i++) { |
382 |
|
NSString *s = (*lastPathComp)([sortPaths objectAtIndex: i], lastPathCompSel); |
383 |
|
[sortfiles addObject: s]; |
384 |
|
} |
385 |
|
|
386 |
|
contentsDict = [NSMutableDictionary dictionary]; |
387 |
|
[contentsDict setObject: [NSDate date] forKey: @"datestamp"]; |
388 |
|
attributes = [fm fileAttributesAtPath: path traverseLink: YES]; |
389 |
|
date = [attributes fileModificationDate]; |
390 |
|
[contentsDict setObject: date forKey: @"moddate"]; |
391 |
|
[contentsDict setObject: sortfiles forKey: @"files"]; |
392 |
|
|
393 |
|
if ([cachedContents count] >= cachedMax) { |
394 |
|
[self removeOlderCache]; |
395 |
|
} |
396 |
|
|
397 |
|
[self addCachedRepresentation: contentsDict ofDirectory: path]; |
398 |
|
|
399 |
|
return sortfiles; |
400 |
|
} |
401 |
|
|
402 |
|
return nil; |
403 |
|
} |
404 |
|
|
405 |
|
- (NSArray *)checkHiddenFiles:(NSArray *)files atPath:(NSString *)path |
406 |
|
{ |
407 |
|
NSArray *checkedFiles; |
408 |
|
NSArray *hiddenFiles; |
409 |
|
NSString *h; |
410 |
|
|
411 |
|
h = [path stringByAppendingPathComponent: @".hidden"]; |
412 |
|
if ([fm fileExistsAtPath: h]) { |
413 |
|
h = [NSString stringWithContentsOfFile: h]; |
414 |
|
hiddenFiles = [h componentsSeparatedByString: @"\n"]; |
415 |
|
} else { |
416 |
|
hiddenFiles = nil; |
417 |
|
} |
418 |
|
|
419 |
|
if (hiddenFiles != nil || hideSysFiles) { |
420 |
|
NSMutableArray *mutableFiles = AUTORELEASE ([files mutableCopy]); |
421 |
|
|
422 |
|
if (hiddenFiles != nil) { |
423 |
|
[mutableFiles removeObjectsInArray: hiddenFiles]; |
424 |
|
} |
425 |
|
|
426 |
|
if (hideSysFiles) { |
427 |
|
int j = [mutableFiles count] - 1; |
428 |
|
|
429 |
|
while (j >= 0) { |
430 |
|
NSString *file = (NSString *)[mutableFiles objectAtIndex: j]; |
431 |
|
|
432 |
|
if ([file hasPrefix: @"."]) { |
433 |
|
[mutableFiles removeObjectAtIndex: j]; |
434 |
|
} |
435 |
|
j--; |
436 |
|
} |
437 |
|
} |
438 |
|
|
439 |
|
checkedFiles = mutableFiles; |
440 |
|
|
441 |
|
} else { |
442 |
|
checkedFiles = files; |
443 |
|
} |
444 |
|
|
445 |
|
return checkedFiles; |
446 |
|
} |
447 |
|
|
448 |
- (int)sortTypeForDirectoryAtPath:(NSString *)aPath |
- (int)sortTypeForDirectoryAtPath:(NSString *)aPath |
449 |
{ |
{ |
450 |
if ([fm isWritableFileAtPath: aPath]) { |
if ([fm isWritableFileAtPath: aPath]) { |
746 |
{ |
{ |
747 |
return contestualMenu; |
return contestualMenu; |
748 |
} |
} |
|
|
|
|
// |
|
|
// GWProtocol methods used (also) by GWRemote |
|
|
// |
|
|
- (void)performFileOperationWithDictionary:(id)opdict |
|
|
fromSourceHost:(NSString *)fromName |
|
|
toDestinationHost:(NSString *)toName |
|
|
{ |
|
|
[self performFileOperationWithDictionary: opdict]; |
|
|
} |
|
|
|
|
|
- (BOOL)server:(NSString *)serverName isPakageAtPath:(NSString *)path |
|
|
{ |
|
|
return [self isPakageAtPath: path]; |
|
|
} |
|
|
|
|
|
- (BOOL)server:(NSString *)serverName fileExistsAtPath:(NSString *)path |
|
|
{ |
|
|
return [fm fileExistsAtPath: path]; |
|
|
} |
|
|
|
|
|
- (BOOL)server:(NSString *)serverName isWritableFileAtPath:(NSString *)path |
|
|
{ |
|
|
return [fm isWritableFileAtPath: path]; |
|
|
} |
|
|
|
|
|
- (BOOL)server:(NSString *)serverName |
|
|
existsAndIsDirectoryFileAtPath:(NSString *)path |
|
|
{ |
|
|
BOOL isDir; |
|
|
return ([fm fileExistsAtPath: path isDirectory: &isDir] && isDir); |
|
|
} |
|
|
|
|
|
- (NSString *)server:(NSString *)serverName typeOfFileAt:(NSString *)path |
|
|
{ |
|
|
NSString *defApp, *type; |
|
|
[ws getInfoForFile: path application: &defApp type: &type]; |
|
|
return type; |
|
|
} |
|
|
|
|
|
- (int)server:(NSString *)serverName sortTypeForPath:(NSString *)aPath |
|
|
{ |
|
|
return [self sortTypeForDirectoryAtPath: aPath]; |
|
|
} |
|
|
|
|
|
- (void)server:(NSString *)serverName |
|
|
setSortType:(int)type |
|
|
atPath:(NSString *)aPath |
|
|
{ |
|
|
[self setSortType: type forDirectoryAtPath: aPath]; |
|
|
} |
|
|
|
|
|
- (NSArray *)server:(NSString *)serverName |
|
|
checkHiddenFiles:(NSArray *)files |
|
|
atPath:(NSString *)path |
|
|
{ |
|
|
NSArray *checkedFiles; |
|
|
NSArray *hiddenFiles; |
|
|
NSString *h; |
|
|
|
|
|
h = [path stringByAppendingPathComponent: @".hidden"]; |
|
|
if ([fm fileExistsAtPath: h]) { |
|
|
h = [NSString stringWithContentsOfFile: h]; |
|
|
hiddenFiles = [h componentsSeparatedByString: @"\n"]; |
|
|
} else { |
|
|
hiddenFiles = nil; |
|
|
} |
|
|
|
|
|
if (hiddenFiles != nil || hideSysFiles) { |
|
|
NSMutableArray *mutableFiles = AUTORELEASE ([files mutableCopy]); |
|
|
|
|
|
if (hiddenFiles != nil) { |
|
|
[mutableFiles removeObjectsInArray: hiddenFiles]; |
|
|
} |
|
|
|
|
|
if (hideSysFiles) { |
|
|
int j = [mutableFiles count] - 1; |
|
|
|
|
|
while (j >= 0) { |
|
|
NSString *file = (NSString *)[mutableFiles objectAtIndex: j]; |
|
|
|
|
|
if ([file hasPrefix: @"."]) { |
|
|
[mutableFiles removeObjectAtIndex: j]; |
|
|
} |
|
|
j--; |
|
|
} |
|
|
} |
|
|
|
|
|
checkedFiles = mutableFiles; |
|
|
|
|
|
} else { |
|
|
checkedFiles = files; |
|
|
} |
|
|
|
|
|
return checkedFiles; |
|
|
} |
|
|
|
|
|
- (NSArray *)server:(NSString *)serverName |
|
|
sortedDirectoryContentsAtPath:(NSString *)path |
|
|
{ |
|
|
NSMutableDictionary *contentsDict = [self cachedRepresentationForPath: path]; |
|
|
|
|
|
if (contentsDict) { |
|
|
return [contentsDict objectForKey: @"files"]; |
|
|
|
|
|
} else { |
|
|
NSArray *files = [fm directoryContentsAtPath: path]; |
|
|
int stype = [self sortTypeForDirectoryAtPath: path]; |
|
|
int count = [files count]; |
|
|
NSMutableArray *paths = [NSMutableArray arrayWithCapacity: count]; |
|
|
NSMutableArray *sortfiles = [NSMutableArray arrayWithCapacity: count]; |
|
|
NSArray *sortPaths = nil; |
|
|
NSDictionary *attributes = nil; |
|
|
NSDate *date = nil; |
|
|
SEL appendPathCompSel = @selector(stringByAppendingPathComponent:); |
|
|
IMP appendPathComp = [[NSString class] instanceMethodForSelector: appendPathCompSel]; |
|
|
SEL lastPathCompSel = @selector(lastPathComponent); |
|
|
IMP lastPathComp = [[NSString class] instanceMethodForSelector: lastPathCompSel]; |
|
|
int i; |
|
|
|
|
|
for (i = 0; i < count; i++) { |
|
|
NSString *s = (*appendPathComp)(path, appendPathCompSel, [files objectAtIndex: i]); |
|
|
[paths addObject: s]; |
|
|
} |
|
|
|
|
|
sortPaths = [paths sortedArrayUsingFunction: (int (*)(id, id, void*))comparePaths |
|
|
context: (void *)stype]; |
|
|
|
|
|
for (i = 0; i < count; i++) { |
|
|
NSString *s = (*lastPathComp)([sortPaths objectAtIndex: i], lastPathCompSel); |
|
|
[sortfiles addObject: s]; |
|
|
} |
|
|
|
|
|
contentsDict = [NSMutableDictionary dictionary]; |
|
|
[contentsDict setObject: [NSDate date] forKey: @"datestamp"]; |
|
|
attributes = [fm fileAttributesAtPath: path traverseLink: YES]; |
|
|
date = [attributes fileModificationDate]; |
|
|
[contentsDict setObject: date forKey: @"moddate"]; |
|
|
[contentsDict setObject: sortfiles forKey: @"files"]; |
|
|
|
|
|
if ([cachedContents count] >= cachedMax) { |
|
|
[self removeOlderCache]; |
|
|
} |
|
|
|
|
|
[self addCachedRepresentation: contentsDict ofDirectory: path]; |
|
|
|
|
|
return sortfiles; |
|
|
} |
|
|
|
|
|
return nil; |
|
|
} |
|
|
|
|
|
- (void)server:(NSString *)serverName setSelectedPaths:(NSArray *)paths |
|
|
{ |
|
|
} |
|
|
|
|
|
- (NSArray *)selectedPathsForServerWithName:(NSString *)serverName |
|
|
{ |
|
|
return selectedPaths; |
|
|
} |
|
|
|
|
|
- (NSString *)homeDirectoryForServerWithName:(NSString *)serverName |
|
|
{ |
|
|
return NSHomeDirectory(); |
|
|
} |
|
|
|
|
|
- (BOOL)server:(NSString *)serverName isLockedPath:(NSString *)aPath |
|
|
{ |
|
|
return [self isLockedPath: aPath]; |
|
|
} |
|
|
|
|
|
- (void)server:(NSString *)serverName addWatcherForPath:(NSString *)path |
|
|
{ |
|
|
[self addWatcherForPath: path]; |
|
|
} |
|
|
|
|
|
- (void)server:(NSString *)serverName removeWatcherForPath:(NSString *)path |
|
|
{ |
|
|
[self removeWatcherForPath: path]; |
|
|
} |
|
|
|
|
|
- (void)server:(NSString *)serverName |
|
|
renamePath:(NSString *)oldname |
|
|
toNewName:(NSString *)newname |
|
|
{ |
|
|
} |
|
|
|
|
749 |
// |
// |
750 |
// end of GWProtocol |
// end of GWProtocol |
751 |
// |
// |