]> git.saurik.com Git - patcyh.git/blob - patcyh.mm
Impactor has the ability to stash individual apps.
[patcyh.git] / patcyh.mm
1 /* patcyh - you should pronounce it like patch
2 * Copyright (C) 2015 Jay Freeman (saurik)
3 */
4
5 /* GNU General Public License, Version 3 {{{ */
6 /*
7 * Cydia is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation, either version 3 of the License,
10 * or (at your option) any later version.
11 *
12 * Cydia is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Cydia. If not, see <http://www.gnu.org/licenses/>.
19 **/
20 /* }}} */
21
22 #include <objc/runtime.h>
23 #include <Foundation/Foundation.h>
24
25 @interface MIFileManager
26 + (MIFileManager *) defaultManager;
27 - (NSURL *) destinationOfSymbolicLinkAtURL:(NSURL *)url error:(NSError *)error;
28 @end
29
30 static Class $MIFileManager;
31
32 static NSArray *(*_MIFileManager$urlsForItemsInDirectoryAtURL$ignoringSymlinks$error$)(MIFileManager *self, SEL _cmd, NSURL *url, BOOL ignoring, NSError *error);
33
34 static NSArray *$MIFileManager$urlsForItemsInDirectoryAtURL$ignoringSymlinks$error$(MIFileManager *self, SEL _cmd, NSURL *url, BOOL ignoring, NSError *error) {
35 MIFileManager *manager(reinterpret_cast<MIFileManager *>([$MIFileManager defaultManager]));
36 NSURL *destiny([manager destinationOfSymbolicLinkAtURL:url error:NULL]);
37 if (destiny == nil)
38 return _MIFileManager$urlsForItemsInDirectoryAtURL$ignoringSymlinks$error$(self, _cmd, url, NO, error);
39
40 NSArray *prefix([url pathComponents]);
41 size_t skip([[destiny pathComponents] count]);
42 NSMutableArray *items([NSMutableArray array]);
43 for (NSURL *item in _MIFileManager$urlsForItemsInDirectoryAtURL$ignoringSymlinks$error$(self, _cmd, destiny, NO, error)) {
44 NSArray *components([item pathComponents]);
45 [items addObject:[NSURL fileURLWithPathComponents:[prefix arrayByAddingObjectsFromArray:[components subarrayWithRange:NSMakeRange(skip, [components count] - skip)]]]];
46 }
47
48 return items;
49 }
50
51 __attribute__((__constructor__))
52 static void initialize() {
53 $MIFileManager = objc_getClass("MIFileManager");
54 SEL sel(@selector(urlsForItemsInDirectoryAtURL:ignoringSymlinks:error:));
55 Method method(class_getInstanceMethod($MIFileManager, sel));
56 _MIFileManager$urlsForItemsInDirectoryAtURL$ignoringSymlinks$error$ = reinterpret_cast<NSArray *(*)(MIFileManager *, SEL, NSURL *, BOOL, NSError *)>(method_getImplementation(method));
57 method_setImplementation(method, reinterpret_cast<IMP>(&$MIFileManager$urlsForItemsInDirectoryAtURL$ignoringSymlinks$error$));
58 }