OLD | NEW |
---|---|
1 /* ***** BEGIN LICENSE BLOCK ***** | 1 /* ***** BEGIN LICENSE BLOCK ***** |
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
3 * | 3 * |
4 * The contents of this file are subject to the Mozilla Public License Version | 4 * The contents of this file are subject to the Mozilla Public License Version |
5 * 1.1 (the "License"); you may not use this file except in compliance with | 5 * 1.1 (the "License"); you may not use this file except in compliance with |
6 * the License. You may obtain a copy of the License at | 6 * the License. You may obtain a copy of the License at |
7 * http://www.mozilla.org/MPL/ | 7 * http://www.mozilla.org/MPL/ |
8 * | 8 * |
9 * Software distributed under the License is distributed on an "AS IS" basis, | 9 * Software distributed under the License is distributed on an "AS IS" basis, |
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 | 72 |
73 resRef = FSOpenResFile(&ref, fsRdPerm); | 73 resRef = FSOpenResFile(&ref, fsRdPerm); |
74 | 74 |
75 if (resRef != -1) { // Has resouce fork. | 75 if (resRef != -1) { // Has resouce fork. |
76 Handle urlResHandle; | 76 Handle urlResHandle; |
77 | 77 |
78 if ((urlResHandle = Get1Resource('url ', 256))) { // Has 'url ' resource w ith ID 256. | 78 if ((urlResHandle = Get1Resource('url ', 256))) { // Has 'url ' resource w ith ID 256. |
79 long size; | 79 long size; |
80 | 80 |
81 size = GetMaxResourceSize(urlResHandle); | 81 size = GetMaxResourceSize(urlResHandle); |
82 ret = [NSURL URLWithString:[NSString stringWithCString:(char *)*urlResHa ndle length:size]]; | 82 // Begin Google Modified |
83 // ret = [NSURL URLWithString:[NSString stringWithCString:(char *)*urlRes Handle length:size]]; | |
84 NSString *urlString = [[[NSString alloc] initWithBytes:(void *)*urlResHa ndle | |
85 length:size | |
86 encoding:NSMacOSRomanStrin gEncoding] // best guess here | |
87 autorelease]; | |
88 ret = [NSURL URLWithString:urlString]; | |
89 // End Google Modified | |
83 } | 90 } |
84 | 91 |
85 CloseResFile(resRef); | 92 CloseResFile(resRef); |
86 } | 93 } |
87 | 94 |
88 if (!ret) { // Look for valid plist data. | 95 if (!ret) { // Look for valid plist data. |
89 NSDictionary *plist; | 96 NSDictionary *plist; |
90 if ((plist = [[NSDictionary alloc] initWithContentsOfFile:inFile])) { | 97 if ((plist = [[NSDictionary alloc] initWithContentsOfFile:inFile])) { |
91 ret = [NSURL URLWithString:[plist objectForKey:@"URL"]]; | 98 ret = [NSURL URLWithString:[plist objectForKey:@"URL"]]; |
92 [plist release]; | 99 [plist release]; |
93 } | 100 } |
94 } | 101 } |
95 } | 102 } |
96 | 103 |
97 return ret; | 104 return ret; |
98 } | 105 } |
99 | 106 |
100 // | 107 // |
101 // Reads the URL from a .url file. | 108 // Reads the URL from a .url file. |
102 // Returns the URL or nil on failure. | 109 // Returns the URL or nil on failure. |
103 // | 110 // |
104 +(NSURL*)URLFromIEURLFile:(NSString*)inFile | 111 +(NSURL*)URLFromIEURLFile:(NSString*)inFile |
105 { | 112 { |
106 NSURL *ret = nil; | 113 NSURL *ret = nil; |
107 | 114 |
108 // Is this really an IE .url file? | 115 // Is this really an IE .url file? |
109 if (inFile) { | 116 if (inFile) { |
110 NSCharacterSet *newlines = [NSCharacterSet characterSetWithCharactersInStrin g:@"\r\n"]; | 117 NSCharacterSet *newlines = [NSCharacterSet characterSetWithCharactersInStrin g:@"\r\n"]; |
111 NSScanner *scanner = [NSScanner scannerWithString:[NSString stringWithConten tsOfFile:inFile]]; | 118 // Begin Google Modified |
119 // NSScanner *scanner = [NSScanner scannerWithString:[NSString stringWithCont entsOfFile:inFile]]; | |
120 NSString *fileString = [NSString stringWithContentsOfFile:inFile | |
121 encoding:NSWindowsCP1252Str ingEncoding // best guess here | |
pink (ping after 24hrs)
2009/07/17 19:36:57
IE here is Mac IE 5, not winIE. The encoding is pr
Avi (use Gerrit)
2009/07/17 19:52:18
Really, though? Mac IE 5 hasn't been around since
| |
122 error:nil]; | |
123 NSScanner *scanner = [NSScanner scannerWithString:fileString]; | |
124 // End Google Modified | |
112 [scanner scanUpToString:@"[InternetShortcut]" intoString:nil]; | 125 [scanner scanUpToString:@"[InternetShortcut]" intoString:nil]; |
113 | 126 |
114 if ([scanner scanString:@"[InternetShortcut]" intoString:nil]) { | 127 if ([scanner scanString:@"[InternetShortcut]" intoString:nil]) { |
115 // Scan each non-empty line in this section. We don't need to explicitly s can the newlines or | 128 // Scan each non-empty line in this section. We don't need to explicitly s can the newlines or |
116 // whitespace because NSScanner ignores these by default. | 129 // whitespace because NSScanner ignores these by default. |
117 NSString *line; | 130 NSString *line; |
118 | 131 |
119 while ([scanner scanUpToCharactersFromSet:newlines intoString:&line]) { | 132 while ([scanner scanUpToCharactersFromSet:newlines intoString:&line]) { |
120 if ([line hasPrefix:@"URL="]) { | 133 if ([line hasPrefix:@"URL="]) { |
121 ret = [NSURL URLWithString:[line substringFromIndex:4]]; | 134 ret = [NSURL URLWithString:[line substringFromIndex:4]]; |
122 break; | 135 break; |
123 } | 136 } |
124 else if ([line hasPrefix:@"["]) { | 137 else if ([line hasPrefix:@"["]) { |
125 // This is the start of a new section, so if we haven't found an URL y et, we should bail. | 138 // This is the start of a new section, so if we haven't found an URL y et, we should bail. |
126 break; | 139 break; |
127 } | 140 } |
128 } | 141 } |
129 } | 142 } |
130 } | 143 } |
131 | 144 |
132 return ret; | 145 return ret; |
133 } | 146 } |
134 | 147 |
135 @end | 148 @end |
OLD | NEW |