しかし軽くNSTableViewのカスタムCellに、NSProgressIndicatorを乗せる方法を調べてみて、やっぱり地道にdrawInteriorWithFrame:内で配置するしかなさそうなことを知る。ふーむ、茨の道じゃのお。
気をとり直してファイルの非同期コピーについてもう少し調べてみた。
FSCopyObjectAsyncで複数のファイルをコピーした場合、callback関数はどんな具合に呼ばれるのかNSLogしまくってみる。
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);
こんな感じでclientContextにselfを渡し、callbackはstatic void statusCallback (FSFileOperationRef fileOp,
const FSRef *currentItem,
FSFileOperationStage stage,
OSStatus error,
CFDictionaryRef statusDictionary,
void *info )
{
NSLog(@"Callback got called.");
NSLog(@"stage=%u",stage);
CFURLRef theURL = CFURLCreateFromFSRef( kCFAllocatorDefault, currentItem );
NSString* thePath = [(NSURL *)theURL path];
CFRelease ( theURL );
NSURL* aURL=[NSURL fileURLWithPath:thePath];
FileCopyManager* entry=(FileCopyManager*)info;
[entry controlCopyingState: fileOp FileOperationStage: stage Status: error DictionaryRef: statusDictionary currentURL:aURL];
}
とりあえずcontrolCopyingState:というメソッドを呼び出すだけにして、controlCopyingState:側で- (void) controlCopyingState:(FSFileOperationRef) fileOp
FileOperationStage: (FSFileOperationStage) stage
Status:(OSStatus) error
DictionaryRef:(CFDictionaryRef)statusDictionary
currentURL:(NSURL*)aURL{
if (error != noErr){
//エラー処理
}
if (statusDictionary)
{
CFNumberRef bytesCompleted;
bytesCompleted = (CFNumberRef) CFDictionaryGetValue(statusDictionary, kFSOperationBytesCompleteKey);
double doubleBytesCompleted;
CFNumberGetValue (bytesCompleted, kCFNumberMaxType, &doubleBytesCompleted);
[allFileIndicator setDoubleValue:doubleBytesCompleted];
NSLog(@"コピー済み:%@ %f Bytes",[aURL path], doubleBytesCompleted);
}
if (stage == kFSOperationStageComplete) {
NSLog(@"コピー完了 %@",[aURL path]);
}
}
あれこれ表示してみる、と。もともとのコードは以前紹介したObjective-Cで非同期ファイルコピー | ArukanSoftこちらのサイトのサンプルプロジェクトからいただいております。感謝。
しかし・・・やっぱりわからないことだらけだ。
0 件のコメント:
コメントを投稿