@@ -17,14 +17,21 @@ #include "config.h" #import "OFCreateSymbolicLinkFailedException.h" #import "OFString.h" -#ifdef OF_HAVE_SYMLINK +#if defined(OF_HAVE_SYMLINK) || defined(OF_WINDOWS) @implementation OFCreateSymbolicLinkFailedException @synthesize sourcePath = _sourcePath, destinationPath = _destinationPath; @synthesize errNo = _errNo; + ++ (instancetype)exceptionWithSourcePath: (OFString*)sourcePath + destinationPath: (OFString*)destinationPath +{ + return [[[self alloc] initWithSourcePath: sourcePath + destinationPath: destinationPath] autorelease]; +} + (instancetype)exceptionWithSourcePath: (OFString*)sourcePath destinationPath: (OFString*)destinationPath errNo: (int)errNo { @@ -35,10 +42,26 @@ - init { OF_INVALID_INIT_METHOD } + +- initWithSourcePath: (OFString*)sourcePath + destinationPath: (OFString*)destinationPath +{ + self = [super init]; + + @try { + _sourcePath = [sourcePath copy]; + _destinationPath = [destinationPath copy]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} - initWithSourcePath: (OFString*)sourcePath destinationPath: (OFString*)destinationPath errNo: (int)errNo { @@ -64,11 +87,17 @@ [super dealloc]; } - (OFString*)description { - return [OFString stringWithFormat: - @"Failed to symlink file %@ to %@: %@", - _sourcePath, _destinationPath, of_strerror(_errNo)]; + if (_errNo != 0) + return [OFString stringWithFormat: + @"Failed to create symbolic link %@ with destination " + @"%@: %@", _destinationPath, _sourcePath, + of_strerror(_errNo)]; + else + return [OFString stringWithFormat: + @"Failed to create symbolic link %@ with destination %@!", + _destinationPath, _sourcePath]; } @end #endif