Index: src/OFFileManager.m ================================================================== --- src/OFFileManager.m +++ src/OFFileManager.m @@ -289,14 +289,23 @@ - (OFURL *)currentDirectoryURL { OFMutableURL *URL = [OFMutableURL URL]; void *pool = objc_autoreleasePoolPush(); + OFString *path; [URL setScheme: @"file"]; - [URL setPath: [[[self currentDirectoryPath] pathComponents] - componentsJoinedByString: @"/"]]; + +#if OF_PATH_DELIMITER != '/' + path = [[[self currentDirectoryPath] pathComponents] + componentsJoinedByString: @"/"]; +#else + path = [self currentDirectoryPath]; +#endif + + [URL setPath: [path stringByAppendingString: @"/"]]; + [URL makeImmutable]; objc_autoreleasePoolPop(pool); return URL; Index: src/OFURL.h ================================================================== --- src/OFURL.h +++ src/OFURL.h @@ -98,17 +98,19 @@ * @return A new, autoreleased OFURL */ + (instancetype)URLWithString: (OFString *)string relativeToURL: (OFURL *)URL; +#ifdef OF_HAVE_FILES /*! * @brief Creates a new URL with the specified local file path. * * @param path The local file path * @return A new, autoreleased OFURL */ + (instancetype)fileURLWithPath: (OFString *)path; +#endif - (instancetype)init OF_UNAVAILABLE; /*! * @brief Initializes an already allocated OFURL with the specified string. Index: src/OFURL.m ================================================================== --- src/OFURL.m +++ src/OFURL.m @@ -20,10 +20,13 @@ #include #import "OFURL.h" #import "OFURL+Private.h" #import "OFArray.h" +#ifdef OF_HAVE_FILES +# import "OFFileManager.h" +#endif #import "OFNumber.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFInvalidArgumentException.h" @@ -46,24 +49,35 @@ { return [[[self alloc] initWithString: string relativeToURL: URL] autorelease]; } +#ifdef OF_HAVE_FILES + (instancetype)fileURLWithPath: (OFString *)path { - OFMutableURL *URL = [OFMutableURL URL]; void *pool = objc_autoreleasePoolPush(); + OFFileManager *fileManager = [OFFileManager defaultManager]; + OFURL *currentDirectoryURL, *URL; - [URL setScheme: @"file"]; - [URL setPath: [[path pathComponents] componentsJoinedByString: @"/"]]; + if (![path hasSuffix: OF_PATH_DELIMITER_STRING] && + [fileManager directoryExistsAtPath: path]) + path = [path stringByAppendingString: @"/"]; - [URL makeImmutable]; +# if OF_PATH_DELIMITER != '/' + path = [[path pathComponents] componentsJoinedByString: @"/"]; +# endif + + currentDirectoryURL = + [[OFFileManager defaultManager] currentDirectoryURL]; + URL = [[OFURL alloc] initWithString: path + relativeToURL: currentDirectoryURL]; objc_autoreleasePoolPop(pool); - return URL; + return [URL autorelease]; } +#endif - (instancetype)init { OF_INVALID_INIT_METHOD }