@@ -230,12 +230,13 @@ if (mkdir([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], DIR_MODE)) #else if (mkdir([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) #endif - @throw [OFCreateDirectoryFailedException newWithClass: self - path: path]; + @throw [OFCreateDirectoryFailedException + exceptionWithClass: self + path: path]; } + (OFArray*)filesInDirectoryAtPath: (OFString*)path { OFAutoreleasePool *pool; @@ -245,12 +246,12 @@ DIR *dir; struct dirent *dirent; if ((dir = opendir([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) == NULL) - @throw [OFOpenFileFailedException newWithClass: self - path: path + @throw [OFOpenFileFailedException exceptionWithClass: self + path: path mode: @"r"]; @try { pool = [[OFAutoreleasePool alloc] init]; @@ -280,13 +281,13 @@ pool = [[OFAutoreleasePool alloc] init]; path = [path stringByAppendingString: @"\\*"]; if ((handle = FindFirstFile([path cString], &fd)) == INVALID_HANDLE_VALUE) - @throw [OFOpenFileFailedException newWithClass: self - path: path - mode: @"r"]; + @throw [OFOpenFileFailedException exceptionWithClass: self + path: path + mode: @"r"]; @try { OFAutoreleasePool *pool2 = [[OFAutoreleasePool alloc] init]; do { @@ -316,40 +317,44 @@ } + (void)changeToDirectory: (OFString*)path { if (chdir([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) - @throw [OFChangeDirectoryFailedException newWithClass: self - path: path]; + @throw [OFChangeDirectoryFailedException + exceptionWithClass: self + path: path]; } #ifndef _PSP + (void)changeModeOfFile: (OFString*)path toMode: (mode_t)mode { # ifndef _WIN32 if (chmod([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], mode)) - @throw [OFChangeFileModeFailedException newWithClass: self - path: path - mode: mode]; + @throw [OFChangeFileModeFailedException + exceptionWithClass: self + path: path + mode: mode]; # else DWORD attributes = GetFileAttributes([path cString]); if (attributes == INVALID_FILE_ATTRIBUTES) - @throw [OFChangeFileModeFailedException newWithClass: self - path: path - mode: mode]; + @throw [OFChangeFileModeFailedException + exceptionWithClass: self + path: path + mode: mode]; if ((mode / 100) & 2) attributes &= ~FILE_ATTRIBUTE_READONLY; else attributes |= FILE_ATTRIBUTE_READONLY; if (!SetFileAttributes([path cString], attributes)) - @throw [OFChangeFileModeFailedException newWithClass: self - path: path - mode: mode]; + @throw [OFChangeFileModeFailedException + exceptionWithClass: self + path: path + mode: mode]; # endif } #endif + (OFDate*)modificationDateOfFile: (OFString*)path @@ -357,13 +362,13 @@ struct stat s; if (stat([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], &s) == -1) /* FIXME: Maybe use another exception? */ - @throw [OFOpenFileFailedException newWithClass: self - path: path - mode: @"r"]; + @throw [OFOpenFileFailedException exceptionWithClass: self + path: path + mode: @"r"]; /* FIXME: We could be more precise on some OSes */ return [OFDate dateWithTimeIntervalSince1970: s.st_mtime]; } @@ -374,12 +379,12 @@ { uid_t uid = -1; gid_t gid = -1; if (owner == nil && group == nil) - @throw [OFInvalidArgumentException newWithClass: self - selector: _cmd]; + @throw [OFInvalidArgumentException exceptionWithClass: self + selector: _cmd]; # ifdef OF_THREADS [mutex lock]; @try { @@ -388,14 +393,14 @@ struct passwd *passwd; if ((passwd = getpwnam([owner cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) == NULL) @throw [OFChangeFileOwnerFailedException - newWithClass: self - path: path - owner: owner - group: group]; + exceptionWithClass: self + path: path + owner: owner + group: group]; uid = passwd->pw_uid; } if (group != nil) { @@ -402,14 +407,14 @@ struct group *group_; if ((group_ = getgrnam([group cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) == NULL) @throw [OFChangeFileOwnerFailedException - newWithClass: self - path: path - owner: owner - group: group]; + exceptionWithClass: self + path: path + owner: owner + group: group]; gid = group_->gr_gid; } # ifdef OF_THREADS } @finally { @@ -417,14 +422,15 @@ } # endif if (chown([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], uid, gid)) - @throw [OFChangeFileOwnerFailedException newWithClass: self - path: path - owner: owner - group: group]; + @throw [OFChangeFileOwnerFailedException + exceptionWithClass: self + path: path + owner: owner + group: group]; } #endif + (void)copyFileAtPath: (OFString*)source toPath: (OFString*)destination @@ -442,12 +448,12 @@ } override = [self fileExistsAtPath: destination]; if ((buffer = malloc(of_pagesize)) == NULL) - @throw [OFOutOfMemoryException newWithClass: self - requestedSize: of_pagesize]; + @throw [OFOutOfMemoryException exceptionWithClass: self + requestedSize: of_pagesize]; @try { sourceFile = [OFFile fileWithPath: source mode: @"rb"]; destinationFile = [OFFile fileWithPath: destination @@ -494,13 +500,14 @@ [destination cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) #else if (!MoveFile([source cStringWithEncoding: OF_STRING_ENCODING_NATIVE], [destination cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) #endif - @throw [OFRenameFileFailedException newWithClass: self - sourcePath: source - destinationPath: destination]; + @throw [OFRenameFileFailedException + exceptionWithClass: self + sourcePath: source + destinationPath: destination]; [pool release]; } + (void)deleteFileAtPath: (OFString*)path @@ -508,19 +515,20 @@ #ifndef _WIN32 if (unlink([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) #else if (!DeleteFile([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) #endif - @throw [OFDeleteFileFailedException newWithClass: self - path: path]; + @throw [OFDeleteFileFailedException exceptionWithClass: self + path: path]; } + (void)deleteDirectoryAtPath: (OFString*)path { if (rmdir([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) - @throw [OFDeleteDirectoryFailedException newWithClass: self - path: path]; + @throw [OFDeleteDirectoryFailedException + exceptionWithClass: self + path: path]; } #ifndef _WIN32 + (void)linkFileAtPath: (OFString*)source toPath: (OFString*)destination @@ -533,13 +541,13 @@ nil]; } if (link([source cStringWithEncoding: OF_STRING_ENCODING_NATIVE], [destination cStringWithEncoding: OF_STRING_ENCODING_NATIVE]) != 0) - @throw [OFLinkFailedException newWithClass: self - sourcePath: source - destinationPath: destination]; + @throw [OFLinkFailedException exceptionWithClass: self + sourcePath: source + destinationPath: destination]; [pool release]; } #endif @@ -555,24 +563,25 @@ nil]; } if (symlink([source cStringWithEncoding: OF_STRING_ENCODING_NATIVE], [destination cStringWithEncoding: OF_STRING_ENCODING_NATIVE]) != 0) - @throw [OFSymlinkFailedException newWithClass: self - sourcePath: source - destinationPath: destination]; + @throw [OFSymlinkFailedException + exceptionWithClass: self + sourcePath: source + destinationPath: destination]; [pool release]; } #endif - init { Class c = isa; [self release]; - @throw [OFNotImplementedException newWithClass: c - selector: _cmd]; + @throw [OFNotImplementedException exceptionWithClass: c + selector: _cmd]; } - initWithPath: (OFString*)path mode: (OFString*)mode { @@ -581,18 +590,20 @@ @try { int flags; if ((flags = parse_mode([mode cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) == -1) - @throw [OFInvalidArgumentException newWithClass: isa - selector: _cmd]; + @throw [OFInvalidArgumentException + exceptionWithClass: isa + selector: _cmd]; if ((fileDescriptor = open([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], flags, DEFAULT_MODE)) == -1) - @throw [OFOpenFileFailedException newWithClass: isa - path: path - mode: mode]; + @throw [OFOpenFileFailedException + exceptionWithClass: isa + path: path + mode: mode]; closable = YES; } @catch (id e) { [self release]; @throw e; @@ -622,13 +633,13 @@ intoBuffer: (void*)buffer { size_t ret; if (fileDescriptor == -1 || atEndOfStream) - @throw [OFReadFailedException newWithClass: isa - stream: self - requestedLength: length]; + @throw [OFReadFailedException exceptionWithClass: isa + stream: self + requestedLength: length]; if ((ret = read(fileDescriptor, buffer, length)) == 0) atEndOfStream = YES; return ret; @@ -637,46 +648,46 @@ - (void)_writeNBytes: (size_t)length fromBuffer: (const void*)buffer { if (fileDescriptor == -1 || atEndOfStream || write(fileDescriptor, buffer, length) < length) - @throw [OFWriteFailedException newWithClass: isa - stream: self - requestedLength: length]; + @throw [OFWriteFailedException exceptionWithClass: isa + stream: self + requestedLength: length]; } - (void)_seekToOffset: (off_t)offset { if (lseek(fileDescriptor, offset, SEEK_SET) == -1) - @throw [OFSeekFailedException newWithClass: isa - stream: self - offset: offset - whence: SEEK_SET]; + @throw [OFSeekFailedException exceptionWithClass: isa + stream: self + offset: offset + whence: SEEK_SET]; } - (off_t)_seekForwardWithOffset: (off_t)offset { off_t ret; if ((ret = lseek(fileDescriptor, offset, SEEK_CUR)) == -1) - @throw [OFSeekFailedException newWithClass: isa - stream: self - offset: offset - whence: SEEK_CUR]; + @throw [OFSeekFailedException exceptionWithClass: isa + stream: self + offset: offset + whence: SEEK_CUR]; return ret; } - (off_t)_seekToOffsetRelativeToEnd: (off_t)offset { off_t ret; if ((ret = lseek(fileDescriptor, offset, SEEK_END)) == -1) - @throw [OFSeekFailedException newWithClass: isa - stream: self - offset: offset - whence: SEEK_END]; + @throw [OFSeekFailedException exceptionWithClass: isa + stream: self + offset: offset + whence: SEEK_END]; return ret; } - (int)fileDescriptor @@ -705,12 +716,12 @@ - initWithPath: (OFString*)path mode: (OFString*)mode { Class c = isa; [self release]; - @throw [OFNotImplementedException newWithClass: c - selector: _cmd]; + @throw [OFNotImplementedException exceptionWithClass: c + selector: _cmd]; } - autorelease { return self; @@ -730,28 +741,28 @@ return OF_RETAIN_COUNT_MAX; } - (void)dealloc { - @throw [OFNotImplementedException newWithClass: isa - selector: _cmd]; + @throw [OFNotImplementedException exceptionWithClass: isa + selector: _cmd]; [super dealloc]; /* Get rid of stupid warning */ } - (void)_seekToOffset: (off_t)offset { - @throw [OFNotImplementedException newWithClass: isa - selector: _cmd]; + @throw [OFNotImplementedException exceptionWithClass: isa + selector: _cmd]; } - (off_t)_seekForwardWithOffset: (off_t)offset { - @throw [OFNotImplementedException newWithClass: isa - selector: _cmd]; + @throw [OFNotImplementedException exceptionWithClass: isa + selector: _cmd]; } - (off_t)_seekToOffsetRelativeToEnd: (off_t)offset { - @throw [OFNotImplementedException newWithClass: isa - selector: _cmd]; + @throw [OFNotImplementedException exceptionWithClass: isa + selector: _cmd]; } @end