Skip to content

Commit

Permalink
Merge branch 'rene-dev' of git://github.com/renep/DTFoundation
Browse files Browse the repository at this point in the history
Conflicts:
	Core/Source/DTVersion.m
  • Loading branch information
odrobnik committed Sep 24, 2012
2 parents 4f3f596 + 1bee817 commit ea0dab1
Show file tree
Hide file tree
Showing 8 changed files with 320 additions and 123 deletions.
1 change: 1 addition & 0 deletions Core/DTFoundation-Prefix.pch
Expand Up @@ -3,6 +3,7 @@
// //


#import <TargetConditionals.h> #import <TargetConditionals.h>
#import <Availability.h>


#ifdef __OBJC__ #ifdef __OBJC__


Expand Down
8 changes: 8 additions & 0 deletions Core/Source/DTDownload.h
Expand Up @@ -161,6 +161,13 @@ typedef void (^DTDownloadCompletionHandler)(DTDownload *);


- (BOOL)isLoading; - (BOOL)isLoading;


/**
* Removes the downloaded file or the incomplete file if the download is currently running.
* Note: Also the download is cancelled if necessary
*/
- (void)cleanup;


/**------------------------------------------------------------------------------------- /**-------------------------------------------------------------------------------------
@name Block Handlers @name Block Handlers
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
Expand All @@ -171,6 +178,7 @@ typedef void (^DTDownloadCompletionHandler)(DTDownload *);
*/ */
@property (nonatomic, copy) DTDownloadResponseHandler responseHandler; @property (nonatomic, copy) DTDownloadResponseHandler responseHandler;



/** /**
Sets the block to execute as soon as the download has completed. Sets the block to execute as soon as the download has completed.
*/ */
Expand Down
13 changes: 13 additions & 0 deletions Core/Source/DTDownload.m
Expand Up @@ -249,6 +249,9 @@ - (void)startWithResume:(BOOL)shouldResume


- (void)cancel - (void)cancel
{ {
if (_cancelled) {
return;
}
_cancelled = YES; _cancelled = YES;
self.delegate = nil; self.delegate = nil;


Expand Down Expand Up @@ -530,6 +533,16 @@ - (BOOL)isLoading
return _isLoading; return _isLoading;
} }


- (void)cleanup
{
[self cancel];

// remove cached file
NSFileManager *fileManager = [[NSFileManager alloc] init];
[fileManager removeItemAtPath:self.internalDownloadFolder error:nil];
}


@synthesize URL = _URL, internalDownloadFolder, downloadEntityTag, folderForDownloading, lastPaketTimestamp, delegate, lastModifiedDate; @synthesize URL = _URL, internalDownloadFolder, downloadEntityTag, folderForDownloading, lastPaketTimestamp, delegate, lastModifiedDate;
@synthesize MIMEType = _MIMEType; @synthesize MIMEType = _MIMEType;
@synthesize totalBytes = _totalBytes; @synthesize totalBytes = _totalBytes;
Expand Down
159 changes: 102 additions & 57 deletions Core/Source/DTVersion.h
Expand Up @@ -3,110 +3,155 @@
// DTFoundation // DTFoundation
// //
// Created by Oliver Drobnik on 11/25/11. // Created by Oliver Drobnik on 11/25/11.
// Copyright (c) 2011 Cocoanetics. All rights reserved. // Copyright (c) 2012 Cocoanetics. All rights reserved.
//



/** /**
Class that represents a version number comprised of major, minor and maintenance number separarated by dots. For example "1.2.2". Class that represents a version number comprised of major, minor and maintenance number separarated by dots. For example "1.2.2".
This encapsulation simplifies comparing versions against each other. Sub-numbers that are omitted on creating a `DTVersion` are assumed to be 0.
This encapsulation simplifies comparing versions against each other. Sub-numbers that are omitted on creating a `DTVersion` are assumed to be 0.
*/ */
@interface DTVersion : NSObject @interface DTVersion : NSObject
{ {
NSUInteger _majorVersion; NSUInteger _major;
NSUInteger _minorVersion; NSUInteger _minor;
NSUInteger _maintenanceVersion; NSUInteger _maintenance;
NSUInteger _build;
} }


/**-------------------------------------------------------------------------------------
@name Properties
---------------------------------------------------------------------------------------
*/

/** /**
The receiver's major version number. The major version number
*/ */
@property (nonatomic, readonly) NSUInteger majorVersion; @property (nonatomic, readonly) NSUInteger major;


/** /**
The receiver's minor version number. The minor version number
*/ */
@property (nonatomic, readonly) NSUInteger minorVersion; @property (nonatomic, readonly) NSUInteger minor;



/** /**
The receiver's maintenance version number. The maintenance/hotfix version number
*/ */
@property (nonatomic, readonly) NSUInteger maintenanceVersion; @property (nonatomic, readonly) NSUInteger maintenance;

/**
The build number
*/
@property (nonatomic, readonly) NSUInteger build;


/**------------------------------------------------------------------------------------- /**-------------------------------------------------------------------------------------
@name Creating Versions @name Creating Versions
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
*/ */


/** /**
creates and returns a `DTVersion` object initialized using the provided string Initializes the receiver with major, minor and maintenance version.
@param major The major version number
@param versionString A string with a version number. @param minor The minor version number
@returns A `DTVersion` object or `nil` if the string is not a valid version number @param maintenance The maintainance/hotfix version number
@see initWithMajor:minor:maintenance: @returns The initialized `DTVersion`
*/ */
+ (DTVersion *)versionWithString:(NSString *)versionString; - (DTVersion *)initWithMajor:(NSUInteger)major minor:(NSUInteger)minor maintenance:(NSUInteger)maintenance;


/** /**
creates and retuns a `DTVersion` object initialized with the version information of the current application Initializes the receiver with major, minor and maintenance version.
@param major The major version number
@returns A `DTVersion` object or `nil` if the string of the current application is not a valid version number @param minor The minor version number
@param maintenance The maintainance/hotfix version number
@param build The build number
@returns The initialized `DTVersion`
*/ */
+ (DTVersion *)appBundleVersion; - (DTVersion *)initWithMajor:(NSUInteger)major minor:(NSUInteger)minor maintenance:(NSUInteger)maintenance build:(NSUInteger)build;


/** /**
creates and retuns a `DTVersion` object initialized with the version information of the operating system creates and returns a DTVersion object initialized using the provided string
@param versionString The `NSString` to create a `DTVersion` from
@returns A `DTVersion` object or `nil` if the string of the current application is not a valid version number @returns A DTVersion object or <code>nil</code> if the string is not a valid version number
*/ */
+ (DTVersion *)osVersion; + (DTVersion *)versionWithString:(NSString *)versionString;


/** /**
creates and returns a `DTVersion` object initialized using the provided string creates and retuns a DTVersion object initialized with the version information of the current application
@returns A DTVersion object or <code>nil</code> if the string of the current application is not a valid version number
@param major The major version number of the version.
@param minor The minor version number of the version.
@param maintenance The maintenance version number of the version.
@returns A `DTVersion` object or `nil` if the string is not a valid version number
*/ */
- (DTVersion *)initWithMajor:(NSUInteger)major minor:(NSUInteger)minor maintenance:(NSUInteger)maintenance; + (DTVersion *)appBundleVersion;

/**
creates and retuns a DTVersion object initialized with the version information of the operating system
@returns A DTVersion object or <code>nil</code> if the string of the current application is not a valid version number
*/
+ (DTVersion *)osVersion;


/**------------------------------------------------------------------------------------- /**-------------------------------------------------------------------------------------
@name Comparing Versions @name Comparing Versions
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
*/ */


/** /**
Returns a Boolean value that indicates whether a given `DTVersion` is equal to the receiver. @param versionString The OS version as `NSString` to compare the receiver to
@returns <code>true</code> if the given version string is valid and less then the osVersion
@param version The `DTVersion` instance to compare against. */
@returns `YES` if the other object is equal to the receiver + (BOOL)osVersionIsLessThen:(NSString *)versionString;
*/
- (BOOL) isEqualToVersion:(DTVersion *)version; /**
@param versionString The OS version as `NSString` to compare the receiver to
@returns <code>true</code> if the given version string is valid and greater then the osVersion
*/
+ (BOOL)osVersionIsGreaterThen:(NSString *)versionString;

/**
@param version The `DTVersion` to compare the receiver to
@returns <code>true</code> if the give version is less then this version
*/
- (BOOL)isLessThenVersion:(DTVersion *)version;


/** /**
Returns a Boolean value that indicates whether a given string is equal to the receiver. @param version The `DTVersion` to compare the receiver to
@returns <code>true</code> if the give version is greater then this version
@param versionString The string to compare the receiver against. */
@returns `YES` if the other object is equal to the receiver - (BOOL)isGreaterThenVersion:(DTVersion *)version;

/**
@param versionString The version as `NSString` to compare the receiver to
@returns <code>true</code> if the give version is less then this version string
*/
- (BOOL)isLessThenVersionString:(NSString *)versionString;

/**
@param versionString The version as `NSString` to compare the receiver to
* @returns <code>true</code> if the give version is greater then version string
*/
- (BOOL)isGreaterThenVersionString:(NSString *)versionString;

/**
Compares the receiver against a passed `DTVersion` instance
@param version The `DTVersion` to compare the receiver to
@returns `YES` is the versions are equal
*/ */
- (BOOL) isEqualToString:(NSString *)versionString; - (BOOL)isEqualToVersion:(DTVersion *)version;


/** /**
Returns a Boolean value that indicates whether a given object is equal to the receiver. Compares the receiver against a passed version as `NSString`
@param versionString The version as `NSString` to compare the receiver to
If the other object is an `NSString` then isEqualToString: is called. If it is a `DTVersion` instance isEqualToVersion: is called. @returns `YES` is the versions are equal
@param object An NSString or `DTVersion` to compare against.
@returns `YES` if the other object is equal to the receiver
*/ */
- (BOOL) isEqual:(id)object; - (BOOL)isEqualToString:(NSString *)versionString;


/** /**
Compares the receiver to object. Compares the receiver against a passed object
@param object An object of either `NSString` or `DTVersion`
@returns `YES` is the versions are equal
*/
- (BOOL)isEqual:(id)object;


@param version The `DTVersion` instance to compare the receiver with. /**
@returns `NSOrderedAscending` if the receiver precedes object in version ordering, `NSOrderedSame` if they are equal, and `NSOrderedDescending` if the receiver is higher than object. Compares the receiver against a passed `DTVersion` instance
@param version The `DTVersion` to compare the receiver to
@returns The comparison result
*/ */
- (NSComparisonResult)compare:(DTVersion *)version; - (NSComparisonResult)compare:(DTVersion *)version;


Expand Down

0 comments on commit ea0dab1

Please sign in to comment.