読了。音道シリーズは全部2回以上読んでるわけだが、この作品は再読。久しぶりなのでほとんど内容を忘れていて楽しめた。老人力にもいいところがある。
次はこれ。
天冥の標〈1〉―メニー・メニー・シープ〈上〉 (ハヤカワ文庫JA)
posted with amazlet at 11.08.10
小川 一水
早川書房
売り上げランキング: 116523
早川書房
売り上げランキング: 116523
やっぱ本はええなあ。
NSAnimationContext* current=[NSAnimationContext currentContext];
rect.origin.x-=250;
rect.size.width=300;
[current setDuration:0.5];
[[trasitionView animator] setFrame:rect];
こんなふうにも書いてみたが、ビヨーンと飛び出すふうにはならない。もう少し違う書き方をすればいいのか・・・。 NSError* error;
NSPropertyListFormat format;
NSString *plistPath;
NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
NSUserDomainMask, YES) objectAtIndex:0];
plistPath = [rootPath stringByAppendingPathComponent:@"Preferences/com.apple.dock.plist"];
if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath]) {
NSLog(@"What?");
}
NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
NSDictionary *temp = (NSDictionary *)[NSPropertyListSerialization
propertyListWithData:plistXML options:NSPropertyListMutableContainersAndLeaves format:&format error:&error];
if (!temp) {
NSLog(@"Error reading plist: %@, format: %lu", error, format);
}
NSArray* appArray=[temp objectForKey:@"persistent-apps"];
NSDictionary *appData=[appArray objectAtIndex:0];
//NSLog(@"paaData=%@",appData);
NSDictionary* tileData=[appData objectForKey:@"tile-data"];
//NSLog(@"tileData=%@",tileData);
NSDictionary* fileData=[tileData objectForKey:@"file-data"];
//NSLog(@"fileData=%@",fileData);
//NSLog(@"URL=%@",[fileData objectForKey:@"_CFURLString"]);
NSString *urlString=[fileData objectForKey:@"_CFURLString"];
NSURL* fileURL=[NSURL fileURLWithPath:urlString];
// NSURL* fileURL=[NSURL URLWithString:[fileData objectForKey:@"_CFURLString"]];
NSLog(@"URL=%@",[fileURL path]);
うるさく入っているNSLogは無視。NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
NSDictionary *temp = (NSDictionary *)[NSPropertyListSerialization
propertyListWithData:plistXML options:NSPropertyListMutableContainersAndLeaves format:&format error:&error];
-(void)changeFont:(id)sender{
NSFont* changedFont=[sender selectedFont];
[messageFontTextfield setStringValue:[NSString stringWithFormat:@"%@ %.1f",[changedFont displayName],[changedFont pointSize]]];
}
てな感じで、変更されたFontをNSTextFieldに表示してみた。Cocoa Tutorial: File Copy With Progress Indicator
#import "FileAsyncCopyer.h"
@implementation FileAsyncCopyer
@synthesize complateCopyBytes,isCopyDone;
-(id)initWithSorceURL:(NSURL*)sURL destURL:(NSURL*) dURL{
self=[super init];
if(self){
sourceURL=[sURL retain];
distURL=[dURL retain];
isCopyDone=NO;
}
return self;
}
- (void) controlCopyingState:(FSFileOperationRef) fileOp
FileOperationStage: (FSFileOperationStage) stage
Status:(OSStatus) error
DictionaryRef:(CFDictionaryRef)statusDictionary
{
if (error != noErr){
}
if (statusDictionary)
{
CFNumberRef bytesCompleted;
bytesCompleted = (CFNumberRef) CFDictionaryGetValue(statusDictionary, kFSOperationBytesCompleteKey);
CFNumberGetValue (bytesCompleted, kCFNumberMaxType, &complateCopyBytes);
NSLog(@"コピー済み:%@ %f Bytes",[sourceURL path] ,complateCopyBytes);
}
if (stage == kFSOperationStageComplete) {
NSLog(@"コピー完了 %@",[sourceURL path]);
isCopyDone=YES;
}
}
static void statusCallback (FSFileOperationRef fileOp,
const FSRef *currentItem,
FSFileOperationStage stage,
OSStatus error,
CFDictionaryRef statusDictionary,
void *info )
{
FileAsyncCopyer* entry=(FileAsyncCopyer *)info;
[entry controlCopyingState: fileOp FileOperationStage: stage Status: error DictionaryRef: statusDictionary];
}
-(void)startCopyAsync{
CFRunLoopRef runLoop = CFRunLoopGetCurrent();
FSFileOperationRef fileOp = FSFileOperationCreate(kCFAllocatorDefault);
OSStatus status = FSFileOperationScheduleWithRunLoop(fileOp, runLoop, kCFRunLoopDefaultMode);
if( status )
{
NSLog(@"Failed to schedule operation with run loop: %@", status);
return;
}
// Create a filesystem ref structure for the source and destination and
// populate them with their respective paths from our NSTextFields.
FSRef source;
FSRef destination;
FSPathMakeRef( (const UInt8 *)[[sourceURL path] fileSystemRepresentation], &source, NULL );
Boolean isDir = true;
FSPathMakeRef( (const UInt8 *)[[distURL path] fileSystemRepresentation], &destination, &isDir );
// Start the async copy.
FSFileOperationClientContext clientContext = {0};
clientContext.info = self;
status = FSCopyObjectAsync (fileOp,
&source,
&destination, // Full path to destination dir
NULL, // Use the same filename as source
kFSFileOperationDefaultOptions,
statusCallback,
1.0,
&clientContext);
CFRelease(fileOp);
if( status )
{
NSLog(@"Failed to begin asynchronous object copy: %@", status);
}
}
- (void)dealloc
{
[sourceURL release];
[distURL release];
[super dealloc];
}
@end
このクラスにコピー元、コピー先のURLを渡して非同期コピーをする。 FSCopyObjectAsync を起動する以外は、コピー済みbytesを記録するだけ。bytesCompleted = (CFNumberRef) CFDictionaryGetValue(statusDictionary, kFSOperationBytesCompleteKey);という風にコピー済みbyteを得ているが、複数ファイルをいっぺんに非同期コピーしていると「どのファイルが、どれだけコピー済みか」がわからない。
FileOperationStage: (FSFileOperationStage) stage
Status:(OSStatus) error
DictionaryRef:(CFDictionaryRef)statusDictionary
currentURL:(NSURL*)aURL{
最後のaURLが現在コピー中のファイルのURL。で、callbackが呼ばれるたびにこのURLの中身をNSLogしてみると、なんと、「コピー元」と「コピー先」の両方のファイルについて、それぞれcallbackが呼ばれていることがわかった。[copyComplatedbytesOfFiles setObject:compBytes forKey:[[aURL path] lastPathComponent]];
for(NSNumber* num in bytesArray){
allFileComplatedByte+=[num doubleValue];
}