Cocoa
Old Code for copying (backup and restore)
0BACKUP
case PT_FILE_KEY :
{
// copy files to lcoation
NSFileManager * fileManager = [NSFileManager defaultManager];
NSEnumerator * filesEnum = [files objectEnumerator];
NSString * path;
while ( path = [filesEnum nextObject] )
{
if ([fileManager fileExistsAtPath:path]) {
NSString * destination = [[[NSString alloc] initWithString:[[set locations] absolutePath] ] stringByAppendingPathComponent:[path lastPathComponent] ];
[fileManager copyPath:path toPath:destination handler:nil];
} else {
// log to console
// file does not exist
[[LogHandler sharedInstance] message:[NSString stringWithFormat:@"Path '%@' is not a file or folder.", path]
withType:LH_ERROR
fromObject:self];
}
}
}
RESTORE
case PT_FILE_KEY :
{
// copy files to location
NSFileManager * fileManager = [NSFileManager defaultManager];
NSEnumerator * filesEnum = [files objectEnumerator];
NSString * path;
while ( path = [filesEnum nextObject] )
{
if ([fileManager fileExistsAtPath:path]) {
NSString * destination = [[[NSString alloc] initWithString:[[set locations] absolutePath] ] stringByAppendingPathComponent:[path lastPathComponent] ];
[fileManager copyPath:path toPath:destination handler:nil];
} else {
// log to console
// file does not exist
[[LogHandler sharedInstance] message:[NSString stringWithFormat:@"Path '%@' is not a file or folder.", path]
withType:LH_ERROR
fromObject:self];
}
}
}
technorati tags:cocoa, NSFileManager
Found some nice Cocoa Frameworks
0NetClasses -> http://netclasses.aeruder.net/
Chart -> http://www.nachob.tk/
Narrative plotting -> http://sourceforge.net/projects/narrative/
MathKit -> http://sourceforge.net/projects/mathkit
Blocks (plugins)-> http://www.hogbaysoftware.com/project/blocks
GraphX -> http://blog.oofn.net/projects/graphx
I found them on http://osx.hyperjeff.net/Apps/apps.php?p=7&f=frameworks
Simple Use of NSTimers in Cocoa
0[cocoa]
#pragma mark Timer for the progress indicator and status updates
- (void)destroyDelayTimer
{
[mDelayTimer invalidate];
[mDelayTimer release];
mDelayTimer = nil;
}
- (void)fireUploadTimer:(NSTimer*)timer
{
totalTransferTime += timerUpdateTime;
// workaround for longlong to float conversion problem
float transferSpeed = [[[NSString alloc] initWithFormat:@”%d”, [con transferSpeed]] floatValue];
if ([con numberOfTransfers] < 1) {
[self destroyDelayTimer];
[self BroadcastToObjects:[NSDictionary dictionaryWithObject:@"100.0" forKey:@"progressNumber"]
:@”ConnectionStatusProgressIndicator”];
[self BroadcastToObjects:[NSDictionary dictionaryWithObject:@"Transfer finished..." forKey:@"text"]
:@”ConnectionStatusTextField”];
[self BroadcastToObjects:[NSDictionary dictionaryWithObject:@"true" forKey:@"progressCancel"]
:@”ConnectionStatusProgressIndicator”];
}
if(transferSpeed >= 1.0f) {
NSString *transferMessage = [[NSString alloc] initWithFormat:@”Uploading at %1.2f Kilobytes per second”, [[[UnitConvertor alloc] convertKiloForBase:[[NSNumber alloc] initWithFloat:transferSpeed]] doubleValue]];
[self BroadcastToObjects:[NSDictionary dictionaryWithObject:transferMessage forKey:@"text"]
:@”ConnectionStatusTextField”];
if (lastTransferSpeed >= 1.0f) {
float percentsTransfered;
percentsTransfered = roundf( ( (totalTransferTime * lastTransferSpeed) / fileSize ) * 100.0f );
if ( ( lastValueForPercentsTransfered < percentsTransfered ) && (percentsTransfered <= 100.0f) ) {
// NSLog(@”percentsTransfered: %1.2f”,percentsTransfered);
// set percents transfered
[self BroadcastToObjects:[NSDictionary dictionaryWithObject:[[NSString alloc] initWithFormat:@”%1.2f”, percentsTransfered] forKey:@”progressNumber”]
:@”ConnectionStatusProgressIndicator”];
lastValueForPercentsTransfered = percentsTransfered;
}
}
lastTransferSpeed = transferSpeed;
}
}
- (void)fireDownloadTimer:(NSTimer*)timer
{
totalTransferTime += timerUpdateTime;
// workaround for longlong to float conversion problem
float transferSpeed = [[[NSString alloc] initWithFormat:@”%d”, [con transferSpeed]] floatValue];
if ([con numberOfTransfers] < 1) {
[self destroyDelayTimer];
[self BroadcastToObjects:[NSDictionary dictionaryWithObject:@"100.0" forKey:@"progressNumber"]
:@”ConnectionStatusProgressIndicator”];
[self BroadcastToObjects:[NSDictionary dictionaryWithObject:@"Transfer finished..." forKey:@"text"]
:@”ConnectionStatusTextField”];
[self BroadcastToObjects:[NSDictionary dictionaryWithObject:@"true" forKey:@"progressCancel"]
:@”ConnectionStatusProgressIndicator”];
}
NSLog(@”Dl: %f”,transferSpeed);
if(transferSpeed >= 1.0f) {
NSString *transferMessage = [[NSString alloc] initWithFormat:@”Downloading at %1.2f Kilobytes per second”, [[[UnitConvertor alloc] convertKiloForBase:[[NSNumber alloc] initWithFloat:transferSpeed]] doubleValue]];
[self BroadcastToObjects:[NSDictionary dictionaryWithObject:transferMessage forKey:@"text"]
:@”ConnectionStatusTextField”];
if (lastTransferSpeed >= 1.0f) {
float percentsTransfered;
percentsTransfered = roundf( ( (totalTransferTime * lastTransferSpeed) / fileSize ) * 100.0f );
if ( ( lastValueForPercentsTransfered < percentsTransfered ) && (percentsTransfered <= 100.0f) ) {
// NSLog(@”percentsTransfered: %1.2f”,percentsTransfered);
// set percents transfered
[self BroadcastToObjects:[NSDictionary dictionaryWithObject:[[NSString alloc] initWithFormat:@”%1.2f”, percentsTransfered] forKey:@”progressNumber”]
:@”ConnectionStatusProgressIndicator”];
lastValueForPercentsTransfered = percentsTransfered;
}
}
lastTransferSpeed = transferSpeed;
}
}
[/cocoa]