Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 76 lines (64 sloc) 2.964 kb
f7f96ef Convenience method for NSFileWrapper.
Mike authored
1 //
2 // KSFileWrapperExtensions.m
3 //
863123f @danwood update copyrights
danwood authored
4 // Copyright (c) 2011, Mike Abdullah and Karelia Software
20a1855 @mikeabdullah Settle on BSD license.
mikeabdullah authored
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 // DISCLAIMED. IN NO EVENT SHALL MIKE ABDULLAH OR KARELIA SOFTWARE BE LIABLE FOR ANY
19 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
f7f96ef Convenience method for NSFileWrapper.
Mike authored
25 //
26
27 #import "KSFileWrapperExtensions.h"
28
29
30 @implementation NSFileWrapper (KSFileWrapperExtensions)
31
32 - (NSString *)addFileWrapper:(NSFileWrapper *)wrapper subdirectory:(NSString *)subpath;
33 {
cb9ca2e @mikeabdullah docs
mikeabdullah authored
34 // Create any directories required by the subpath
f7f96ef Convenience method for NSFileWrapper.
Mike authored
35 NSArray *components = [subpath pathComponents];
36 NSFileWrapper *parentWrapper = self;
37
38 NSUInteger i, count = [components count];
39 for (i = 0; i < count; i++)
40 {
41 NSString *aComponent = [components objectAtIndex:i];
f5d1a64 @mikeabdullah Don't re-use the same variable name.
mikeabdullah authored
42 NSFileWrapper *aWrapper = [[parentWrapper fileWrappers] objectForKey:aComponent];
43 if (!aWrapper)
f7f96ef Convenience method for NSFileWrapper.
Mike authored
44 {
f5d1a64 @mikeabdullah Don't re-use the same variable name.
mikeabdullah authored
45 aWrapper = [[NSFileWrapper alloc] initDirectoryWithFileWrappers:nil];
46 [aWrapper setPreferredFilename:aComponent];
47 [parentWrapper addFileWrapper:aWrapper];
48 [aWrapper release];
f7f96ef Convenience method for NSFileWrapper.
Mike authored
49 }
50
f5d1a64 @mikeabdullah Don't re-use the same variable name.
mikeabdullah authored
51 parentWrapper = aWrapper;
f7f96ef Convenience method for NSFileWrapper.
Mike authored
52 }
53
cb9ca2e @mikeabdullah docs
mikeabdullah authored
54 // We finally have a suitable parent to add the wrapper to
f7f96ef Convenience method for NSFileWrapper.
Mike authored
55 return [parentWrapper addFileWrapper:wrapper];
56 }
57
a2e5cac @mikeabdullah -ks_removeAllVisibleFileWrappers convenience
mikeabdullah authored
58 - (void)ks_removeAllVisibleFileWrappers;
59 {
32b752e @mikeabdullah Copy -fileWrappers before enumerating it
mikeabdullah authored
60 // Leopard had a bug where -fileWrappers returns its own backing store, which means it will mutate while enumerating
61 NSDictionary *wrappers = [[self fileWrappers] copy];
62
a2e5cac @mikeabdullah -ks_removeAllVisibleFileWrappers convenience
mikeabdullah authored
63 for (NSString *aFilename in wrappers)
64 {
65 if (![aFilename hasPrefix:@"."])
66 {
67 NSFileWrapper *aWrapper = [wrappers objectForKey:aFilename];
68 [self removeFileWrapper:aWrapper];
69 }
70 }
32b752e @mikeabdullah Copy -fileWrappers before enumerating it
mikeabdullah authored
71
72 [wrappers release];
a2e5cac @mikeabdullah -ks_removeAllVisibleFileWrappers convenience
mikeabdullah authored
73 }
74
f7f96ef Convenience method for NSFileWrapper.
Mike authored
75 @end
Something went wrong with that request. Please try again.