从Path创建TFENode

时间:2014-05-08 10:47:33

标签: objective-c macos osx-mavericks finder

如何从路径创建TFENode?


编辑:

我有点兴奋,TGlobalWindowController中有一种方法:

struct TString {
    struct TRef<const __CFString *, TRetainReleasePolicy<CFStringRef>> fString;
};

...

+ (struct TFENode)nodeForUrl:(const struct TString *)arg1;

很遗憾,我无法创建TString


EDIT2:
经过研究,我发现这种方法有效:

struct TString {
//struct TRef<CFStringRef, TRetainReleasePolicy<CFStringRef>> fString;
CFStringRef fString;
};

NSString *path = [[NSString alloc] initWithString:@"file:///"];
struct TString *tstr = (struct TString *)malloc(sizeof(struct TString*));
tstr->fString = (CFStringRef)path;
id node = [NSClassFromString(@"TGlobalWindowController") performSelector:NSSelectorFromString(@"nodeForUrl:") withObject:(id)tstr];
free(tstr);
[path release];

节点是正确的,但是一旦下一个垃圾收集过程开始,查找程序就会崩溃。

1 个答案:

答案 0 :(得分:1)

找到答案:

+ (char*) nodeForPath:(NSURL*)url node:(char*) node
{
    memset(node, 0, 0x204);

    int *v6;
    void* v7;

    if ( (double)NSAppKitVersionNumber < 1110.0 )
    {
        v6 = (int *)[url absoluteString];
    }
    else
    {
        v7 = [url absoluteString];
        v6 = (int *)&v7;
    }
    objc_msgSend_stret((id)node,NSClassFromString(@"TGlobalWindowController"), NSSelectorFromString(@"nodeForUrl:"), v6);
    return node;
}