Index: Operation/FileOpInfo.h =================================================================== --- Operation/FileOpInfo.h (revision 38049) +++ Operation/FileOpInfo.h (working copy) @@ -43,6 +43,8 @@ - (void)sendDidChangeNotification; +- (void)removeProcessedFiles; + - (oneway void)endOperation; @end @@ -84,7 +86,7 @@ NSString *type; NSString *source; NSString *destination; - NSArray *files; + NSMutableArray *files; NSMutableArray *dupfiles; int ref; Index: Operation/FileOpInfo.m =================================================================== --- Operation/FileOpInfo.m (revision 38049) +++ Operation/FileOpInfo.m (working copy) @@ -118,7 +118,7 @@ ASSIGN (type, tp); ASSIGN (source, src); ASSIGN (destination, dst); - ASSIGN (files, fls); + files = [[NSMutableArray arrayWithArray:fls] retain]; dupfiles = [NSMutableArray new]; @@ -185,89 +185,114 @@ - (void)startOperation { - NSPort *port[2]; - NSArray *ports; + NSLog(@"startOperation"); + if (confirm) + { + NSString *title = nil; + NSString *msg = nil; + NSString *msg1 = nil; + NSString *msg2 = nil; + NSString *items; - if (confirm) { - NSString *title = nil; - NSString *msg = nil; - NSString *msg1 = nil; - NSString *msg2 = nil; - NSString *items; - - if ([files count] > 1) { - items = [NSString stringWithFormat: @"%lu %@", (unsigned long)[files count], NSLocalizedString(@"items", @"")]; - } else { - items = NSLocalizedString(@"one item", @""); - } + if ([files count] > 1) + { + items = [NSString stringWithFormat: @"%lu %@", (unsigned long)[files count], NSLocalizedString(@"items", @"")]; + } + else + { + items = NSLocalizedString(@"one item", @""); + } - if ([type isEqual: NSWorkspaceMoveOperation]) { - title = NSLocalizedString(@"Move", @""); - msg1 = [NSString stringWithFormat: @"%@ %@ %@: ", - NSLocalizedString(@"Move", @""), - items, - NSLocalizedString(@"from", @"")]; - msg2 = NSLocalizedString(@"\nto: ", @""); - msg = [NSString stringWithFormat: @"address@hidden@address@hidden@?", msg1, source, msg2, destination]; - } else if ([type isEqual: NSWorkspaceCopyOperation]) { - title = NSLocalizedString(@"Copy", @""); - msg1 = [NSString stringWithFormat: @"%@ %@ %@: ", - NSLocalizedString(@"Copy", @""), - items, - NSLocalizedString(@"from", @"")]; - msg2 = NSLocalizedString(@"\nto: ", @""); - msg = [NSString stringWithFormat: @"address@hidden@address@hidden@?", msg1, source, msg2, destination]; - } else if ([type isEqual: NSWorkspaceLinkOperation]) { - title = NSLocalizedString(@"Link", @""); - msg1 = [NSString stringWithFormat: @"%@ %@ %@: ", - NSLocalizedString(@"Link", @""), - items, - NSLocalizedString(@"from", @"")]; - msg2 = NSLocalizedString(@"\nto: ", @""); - msg = [NSString stringWithFormat: @"address@hidden@address@hidden@?", msg1, source, msg2, destination]; - } else if ([type isEqual: NSWorkspaceRecycleOperation]) { - title = NSLocalizedString(@"Recycler", @""); - msg1 = [NSString stringWithFormat: @"%@ %@ %@: ", - NSLocalizedString(@"Move", @""), - items, - NSLocalizedString(@"from", @"")]; - msg2 = NSLocalizedString(@"\nto the Recycler", @""); - msg = [NSString stringWithFormat: @"address@hidden@address@hidden", msg1, source, msg2]; - } else if ([type isEqual: @"GWorkspaceRecycleOutOperation"]) { - title = NSLocalizedString(@"Recycler", @""); - msg1 = [NSString stringWithFormat: @"%@ %@ %@ ", - NSLocalizedString(@"Move", @""), - items, - NSLocalizedString(@"from the Recycler", @"")]; - msg2 = NSLocalizedString(@"\nto: ", @""); - msg = [NSString stringWithFormat: @"address@hidden@address@hidden", msg1, msg2, destination]; - } else if ([type isEqual: @"GWorkspaceEmptyRecyclerOperation"]) { - title = NSLocalizedString(@"Recycler", @""); - msg = NSLocalizedString(@"Empty the Recycler?", @""); - } else if ([type isEqual: NSWorkspaceDestroyOperation]) { - title = NSLocalizedString(@"Delete", @""); - msg = NSLocalizedString(@"Delete the selected objects?", @""); - } else if ([type isEqual: NSWorkspaceDuplicateOperation]) { - title = NSLocalizedString(@"Duplicate", @""); - msg = NSLocalizedString(@"Duplicate the selected objects?", @""); - } - - if (NSRunAlertPanel(title, msg, - NSLocalizedString(@"OK", @""), - NSLocalizedString(@"Cancel", @""), - nil) != NSAlertDefaultReturn) { - [self endOperation]; - return; + if ([type isEqual: NSWorkspaceMoveOperation]) + { + title = NSLocalizedString(@"Move", @""); + msg1 = [NSString stringWithFormat: @"%@ %@ %@: ", + NSLocalizedString(@"Move", @""), + items, + NSLocalizedString(@"from", @"")]; + msg2 = NSLocalizedString(@"\nto: ", @""); + msg = [NSString stringWithFormat: @"address@hidden@address@hidden@?", msg1, source, msg2, destination]; + } + else if ([type isEqual: NSWorkspaceCopyOperation]) + { + title = NSLocalizedString(@"Copy", @""); + msg1 = [NSString stringWithFormat: @"%@ %@ %@: ", + NSLocalizedString(@"Copy", @""), + items, + NSLocalizedString(@"from", @"")]; + msg2 = NSLocalizedString(@"\nto: ", @""); + msg = [NSString stringWithFormat: @"address@hidden@address@hidden@?", msg1, source, msg2, destination]; + } + else if ([type isEqual: NSWorkspaceLinkOperation]) + { + title = NSLocalizedString(@"Link", @""); + msg1 = [NSString stringWithFormat: @"%@ %@ %@: ", + NSLocalizedString(@"Link", @""), + items, + NSLocalizedString(@"from", @"")]; + msg2 = NSLocalizedString(@"\nto: ", @""); + msg = [NSString stringWithFormat: @"address@hidden@address@hidden@?", msg1, source, msg2, destination]; + } + else if ([type isEqual: NSWorkspaceRecycleOperation]) + { + title = NSLocalizedString(@"Recycler", @""); + msg1 = [NSString stringWithFormat: @"%@ %@ %@: ", + NSLocalizedString(@"Move", @""), + items, + NSLocalizedString(@"from", @"")]; + msg2 = NSLocalizedString(@"\nto the Recycler", @""); + msg = [NSString stringWithFormat: @"address@hidden@address@hidden", msg1, source, msg2]; + } + else if ([type isEqual: @"GWorkspaceRecycleOutOperation"]) + { + title = NSLocalizedString(@"Recycler", @""); + msg1 = [NSString stringWithFormat: @"%@ %@ %@ ", + NSLocalizedString(@"Move", @""), + items, + NSLocalizedString(@"from the Recycler", @"")]; + msg2 = NSLocalizedString(@"\nto: ", @""); + msg = [NSString stringWithFormat: @"address@hidden@address@hidden", msg1, msg2, destination]; + } + else if ([type isEqual: @"GWorkspaceEmptyRecyclerOperation"]) + { + title = NSLocalizedString(@"Recycler", @""); + msg = NSLocalizedString(@"Empty the Recycler?", @""); + } + else if ([type isEqual: NSWorkspaceDestroyOperation]) + { + title = NSLocalizedString(@"Delete", @""); + msg = NSLocalizedString(@"Delete the selected objects?", @""); + } + else if ([type isEqual: NSWorkspaceDuplicateOperation]) + { + title = NSLocalizedString(@"Duplicate", @""); + msg = NSLocalizedString(@"Duplicate the selected objects?", @""); + } + + if (NSRunAlertPanel(title, msg, + NSLocalizedString(@"OK", @""), + NSLocalizedString(@"Cancel", @""), + nil) != NSAlertDefaultReturn) { + [self endOperation]; + return; + } } - } + [self detachOperationThread]; +} +-(void)detachOperationThread +{ + NSPort *port[2]; + NSArray *ports; + + NSLog(@"detach operation thread"); port[0] = (NSPort *)[NSPort port]; port[1] = (NSPort *)[NSPort port]; - + ports = [NSArray arrayWithObjects: port[1], port[0], nil]; execconn = [[NSConnection alloc] initWithReceivePort: port[0] - sendPort: port[1]]; + sendPort: port[1]]; [execconn setRootObject: self]; [execconn setDelegate: self]; @@ -281,6 +306,7 @@ [NSThread detachNewThreadSelector: @selector(setPorts:) toTarget: [FileOpExecutor class] withObject: ports]; + NSLog(@"thread detached"); } NS_HANDLER { @@ -317,6 +343,7 @@ { if (paused == NO) { + NSLog(@"start pause remaining files: %d", [files count]); [pauseButt setTitle: NSLocalizedString(@"Continue", @"")]; [stopButt setEnabled: NO]; paused = YES; @@ -323,10 +350,12 @@ } else { + NSLog(@"continue from pause"); + [self detachOperationThread]; [pauseButt setTitle: NSLocalizedString(@"Pause", @"")]; [stopButt setEnabled: YES]; paused = NO; - [executor performOperation]; + NSLog(@"performing operation...."); } } @@ -335,6 +364,44 @@ stopped = YES; } +- (void)removeProcessedFiles +{ + NSData *pFData; + NSArray *pFiles; + NSUInteger i; + + + NSLog(@"remove processed files"); + pFData = [executor processedFiles]; + pFiles = [NSUnarchiver unarchiveObjectWithData: pFData]; + + NSLog(@"remove files: %@", pFiles); + for (i = 0; i < [pFiles count]; i++) + { + NSDictionary *fi; + NSUInteger j; + BOOL found; + + j = 0; + found = NO; + while (j < [files count] && !found) + { + fi = [files objectAtIndex:j]; + + if ([[pFiles objectAtIndex:i] isEqualTo:[fi objectForKey:@"name"]]) + found = YES; + else + i++; + } + if (found) + { + NSLog(@"found! %@", fi); + [files removeObjectAtIndex:j]; + } + } + NSLog(@"removeFile - remaining files... %d", [files count]); +} + - (void)showProgressWin { if ([win isVisible] == NO) { @@ -652,7 +719,8 @@ NSPort *port[2]; NSConnection *conn; FileOpExecutor *executor; - + + NSLog(@"set ports start"); port[0] = [thePorts objectAtIndex: 0]; port[1] = [thePorts objectAtIndex: 1]; @@ -662,6 +730,7 @@ executor = [[self alloc] init]; [executor setFileop: thePorts]; [(id)[conn rootProxy] registerExecutor: executor]; + NSLog(@"setPorts stop"); RELEASE (executor); RELEASE (pool); @@ -860,7 +929,7 @@ - (oneway void)performOperation { canupdate = YES; - + NSLog(@"performOperation: %@", operation); if ([operation isEqual: NSWorkspaceMoveOperation] || [operation isEqual: @"GWorkspaceRecycleOutOperation"]) { @@ -954,10 +1023,12 @@ - (void)doCopy { + NSLog(@"start files... %d", [files count]); while (1) { CHECK_DONE; GET_FILENAME; + sleep(1); if ((samename == NO) || (samename && [self removeExisting: fileinfo])) { @@ -968,7 +1039,8 @@ [procfiles addObject: filename]; } } - [files removeObject: fileinfo]; + [files removeObject: fileinfo]; + NSLog(@"files... %d", [files count]); RELEASE (fileinfo); } @@ -975,7 +1047,12 @@ if (([files count] == 0) || stopped) { [self done]; - } + } + else if (paused) + { + NSLog(@"paused, communicating back that we processed: %d", [procfiles count]); + [fileOp removeProcessedFiles]; + } } - (void)doLink