| 1 |
/* |
| 2 |
* Copyright (c) 2004-2005 The Lupin Project. All rights reserved. |
| 3 |
* |
| 4 |
* Redistribution and use in source and binary forms, with or without modification, are permitted |
| 5 |
* provided that the following conditions are met: |
| 6 |
* |
| 7 |
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions |
| 8 |
* and the following disclaimer. |
| 9 |
* |
| 10 |
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of |
| 11 |
* conditions and the following disclaimer in the documentation and/or other materials provided |
| 12 |
* with the distribution. |
| 13 |
* |
| 14 |
* THIS SOFTWARE IS PROVIDED BY THE LUPIN PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, |
| 15 |
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LUPIN PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| 17 |
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 18 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 19 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 20 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 21 |
* POSSIBILITY OF SUCH DAMAGE. |
| 22 |
*/ |
| 23 |
|
| 24 |
#import "LPDocument.h" |
| 25 |
|
| 26 |
@implementation LPDocument |
| 27 |
|
| 28 |
- (id)init |
| 29 |
{ |
| 30 |
self = [super init]; |
| 31 |
if (self) { |
| 32 |
// Add your subclass-specific initialization here. |
| 33 |
// If an error occurs here, send a [self release] message and return nil. |
| 34 |
_archiveAllUncompressMode = NO; |
| 35 |
} |
| 36 |
return self; |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
- (void)dealloc |
| 41 |
{ |
| 42 |
if (_plugins) [_plugins release]; |
| 43 |
if (_plugin) [_plugin release]; |
| 44 |
if (_infoDict) [_infoDict release]; |
| 45 |
if (_droppedTemporaryPath) [_droppedTemporaryPath release]; |
| 46 |
if (_selectedArray) [_selectedArray release]; |
| 47 |
[super dealloc]; |
| 48 |
} |
| 49 |
|
| 50 |
// make and add WindowController |
| 51 |
- (void)makeWindowControllers |
| 52 |
{ |
| 53 |
NSLog(@"makeWindowControllers"); |
| 54 |
NSLog([self fileType]); |
| 55 |
LPMainWindowController* windowController; |
| 56 |
if ([[self fileType] isEqualToString:@"LupinCompressType"]) { |
| 57 |
windowController = [[LPMainWindowController alloc] initWithWindowNibName:@"LPProgressDocument"]; |
| 58 |
} else if ([[self fileType] isEqualToString:@"LupinUncompressType"]) { |
| 59 |
windowController = [[LPMainWindowController alloc] initWithWindowNibName:@"LPProgressDocument"]; |
| 60 |
} else { |
| 61 |
windowController = [[LPMainWindowController alloc] initWithWindowNibName:@"LPBrowseDocument"]; |
| 62 |
} |
| 63 |
[self addWindowController:windowController]; |
| 64 |
[windowController release]; |
| 65 |
} |
| 66 |
|
| 67 |
/* |
| 68 |
- (NSString *)windowNibName |
| 69 |
{ |
| 70 |
// If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead. |
| 71 |
return @"LPBrowseDocument"; |
| 72 |
} |
| 73 |
*/ |
| 74 |
|
| 75 |
/* |
| 76 |
- (void)windowControllerDidLoadNib:(NSWindowController *) aController |
| 77 |
{ |
| 78 |
NSLog(@"windowControllerDidLoadNib"); |
| 79 |
[super windowControllerDidLoadNib:aController]; |
| 80 |
} |
| 81 |
*/ |
| 82 |
|
| 83 |
- (NSData *)dataRepresentationOfType:(NSString *)aType |
| 84 |
{ |
| 85 |
// Insert code here to write your document from the given data. You can also choose to override -fileWrapperRepresentationOfType: or -writeToFile:ofType: instead. |
| 86 |
return nil; |
| 87 |
} |
| 88 |
|
| 89 |
/* |
| 90 |
- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType |
| 91 |
{ |
| 92 |
// Insert code here to read your document from the given data. You can also choose to override -loadFileWrapperRepresentation:ofType: or -readFromFile:ofType: instead. |
| 93 |
return YES; |
| 94 |
} |
| 95 |
*/ |
| 96 |
|
| 97 |
//��������������������������������������������������������������������������������� |
| 98 |
- (BOOL)readFromFile:(NSString *)fileName ofType:(NSString *)docType |
| 99 |
{ |
| 100 |
NSLog(@"fileName=%@ type=%@",fileName,docType); |
| 101 |
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; |
| 102 |
LPFile* infoDict; |
| 103 |
BOOL hierarchy = [defaults boolForKey:@"inspectIsHierarchy"]; |
| 104 |
int result; |
| 105 |
if ([docType isEqualToString:@"LupinCompressType"]) { |
| 106 |
return YES; |
| 107 |
} |
| 108 |
|
| 109 |
_plugins = [[[NSDocumentController sharedDocumentController] pluginsController] acceptablePlugins:fileName]; |
| 110 |
[_plugins retain]; |
| 111 |
|
| 112 |
if ([docType isEqualToString:@"LupinUncompressType"]) { |
| 113 |
if ([_plugins count] != 0) { |
| 114 |
_plugin = [_plugins lastObject]; |
| 115 |
[_plugin retain]; |
| 116 |
[_plugins removeLastObject]; |
| 117 |
} |
| 118 |
if (!_plugin) { |
| 119 |
return NO; |
| 120 |
} |
| 121 |
return YES; |
| 122 |
} else if ([docType isEqualToString:@"LupinInspectType"]) { |
| 123 |
NSEnumerator* enumerator = [_plugins objectEnumerator]; |
| 124 |
while (_plugin = [enumerator nextObject]) { |
| 125 |
infoDict = [self buildArchiveInfoDictFromPlugin:_plugin hierarchy:hierarchy]; |
| 126 |
if (infoDict) break; |
| 127 |
} |
| 128 |
if (!infoDict) { |
| 129 |
return NO; |
| 130 |
} else { |
| 131 |
_infoDict = infoDict; |
| 132 |
[_infoDict retain]; |
| 133 |
[_plugin retain]; |
| 134 |
return YES; |
| 135 |
} |
| 136 |
} else if ([_plugins count] == 0) { |
| 137 |
// ���������������������������������������������������������������������������������������������������NO������������ |
| 138 |
switch ([defaults integerForKey:@"generalFileDropped"]) { |
| 139 |
case 1: |
| 140 |
break; |
| 141 |
case 2: |
| 142 |
result = NSRunAlertPanel(NSLocalizedString(@"DialogCompressChooseArchiveTitle",nil), |
| 143 |
[NSString stringWithFormat:NSLocalizedString(@"DialogAskCreateArchiveMessage",nil),fileName], |
| 144 |
NSLocalizedString(@"DialogYes",nil), |
| 145 |
NSLocalizedString(@"DialogNo",nil), |
| 146 |
nil); |
| 147 |
if (result == NSCancelButton) |
| 148 |
break; |
| 149 |
case 0: |
| 150 |
[[NSDocumentController sharedDocumentController] compressFiles:[NSArray arrayWithObject:fileName]]; |
| 151 |
} |
| 152 |
return NO; |
| 153 |
} |
| 154 |
switch ([defaults integerForKey:@"generalArchiveDropped"]) { |
| 155 |
case 0: |
| 156 |
break; |
| 157 |
case 2: |
| 158 |
result = NSRunAlertPanel(NSLocalizedString(@"DialogAskUncompressOrInspectTitle",nil), |
| 159 |
[NSString stringWithFormat:NSLocalizedString(@"DialogAskUncompressOrInspectMessage",nil),fileName], |
| 160 |
NSLocalizedString(@"DialogInspect",nil), |
| 161 |
NSLocalizedString(@"DialogUncompress",nil), |
| 162 |
nil); |
| 163 |
if (result == NSOKButton) break; |
| 164 |
case 1: |
| 165 |
[[NSDocumentController sharedDocumentController] uncompressFile:fileName]; |
| 166 |
return NO; |
| 167 |
} |
| 168 |
//������������������������������������ |
| 169 |
NSEnumerator* enumerator = [_plugins objectEnumerator]; |
| 170 |
while (_plugin = [enumerator nextObject]) { |
| 171 |
infoDict = [self buildArchiveInfoDictFromPlugin:_plugin hierarchy:hierarchy]; |
| 172 |
if (infoDict) break; |
| 173 |
} |
| 174 |
if (!infoDict) { |
| 175 |
return NO; |
| 176 |
} else { |
| 177 |
_infoDict = infoDict; |
| 178 |
[_infoDict retain]; |
| 179 |
[_plugin retain]; |
| 180 |
return YES; |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
- (LPFile*)buildArchiveInfoDictFromPlugin:(NSObject<LupinPluginProtocol>*)plugin hierarchy:(BOOL)hierarchy |
| 185 |
{ |
| 186 |
LPFile* infoDict; |
| 187 |
infoDict = [plugin buildArchiveInfoDict:hierarchy password:NULL]; |
| 188 |
if (infoDict) { |
| 189 |
return infoDict; |
| 190 |
} else { |
| 191 |
return NULL; |
| 192 |
} |
| 193 |
} |
| 194 |
|
| 195 |
/* |
| 196 |
//������������������������������������������������������������������������������ |
| 197 |
- (void)archiveInfoDictDidBuild:(LPFile*)infoDict error:(LPError)error |
| 198 |
{ |
| 199 |
NSLog(@"archiveInfoDictDidBuild"); |
| 200 |
if (error == LPErrorNotImplementMethod || error == LPErrorNotSupportFormat) { |
| 201 |
[_plugin release]; |
| 202 |
if ([_plugins count] > 0) { |
| 203 |
_plugin = [_plugins lastObject]; |
| 204 |
[_plugin retain]; |
| 205 |
[_plugins removeLastObject]; |
| 206 |
[_plugin buildArchiveInfoDict:[self fileName] hierarchy:[[NSUserDefaults standardUserDefaults] boolForKey:@"inspectIsHierarchy"] password:nil delegate:self selector:@selector(archiveInfoDictDidBuild:error:)]; |
| 207 |
return; |
| 208 |
} |
| 209 |
} else if (error == LPErrorRequestPassword || error == LPErrorBadPassword) { |
| 210 |
NSLog(@"asking password"); |
| 211 |
NSString* password = [[self mainWindowController] askPassword]; |
| 212 |
if (password) { |
| 213 |
[_plugin buildArchiveInfoDict:[self fileName] hierarchy:[[NSUserDefaults standardUserDefaults] boolForKey:@"inspectIsHierarchy"] password:password delegate:self selector:@selector(archiveInfoDictDidBuild:error:)]; |
| 214 |
return; |
| 215 |
} |
| 216 |
} |
| 217 |
if (error != LPErrorNoError) { |
| 218 |
[[self mainWindowController] showErrorAlertWithErrorID:error]; |
| 219 |
} |
| 220 |
if (!infoDict) { |
| 221 |
NSLog(@"Can't load archive!"); |
| 222 |
[self close]; |
| 223 |
return; |
| 224 |
} |
| 225 |
_infoDict = infoDict; |
| 226 |
[_infoDict retain]; |
| 227 |
[[self mainWindowController] archiveInfoDictDidBuild]; |
| 228 |
} |
| 229 |
*/ |
| 230 |
|
| 231 |
- (LPFile*)infoDict |
| 232 |
{ |
| 233 |
return _infoDict; |
| 234 |
} |
| 235 |
|
| 236 |
- (LPMainWindowController*)mainWindowController |
| 237 |
{ |
| 238 |
return [[self windowControllers] objectAtIndex:0]; |
| 239 |
} |
| 240 |
|
| 241 |
- (void)setPlugin:(NSObject<LupinPluginProtocol>*)plugin |
| 242 |
{ |
| 243 |
_plugin = plugin; |
| 244 |
[_plugin retain]; |
| 245 |
} |
| 246 |
|
| 247 |
- (NSObject<LupinPluginProtocol>*)plugin |
| 248 |
{ |
| 249 |
return _plugin; |
| 250 |
} |
| 251 |
|
| 252 |
#pragma mark - |
| 253 |
#pragma mark Drag&Drop |
| 254 |
|
| 255 |
- (void)setSelectedArray:(NSArray*)selectedArray |
| 256 |
{ |
| 257 |
if (_selectedArray) [_selectedArray release]; |
| 258 |
_selectedArray = [NSArray arrayWithArray:selectedArray]; |
| 259 |
[_selectedArray retain]; |
| 260 |
} |
| 261 |
|
| 262 |
#pragma mark - |
| 263 |
#pragma mark Uncompress |
| 264 |
|
| 265 |
- (void)archiveUncompress:(NSString*)dropPath |
| 266 |
{ |
| 267 |
NSFileManager *manager = [NSFileManager defaultManager]; |
| 268 |
NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys: |
| 269 |
[NSDate date],NSFileModificationDate, |
| 270 |
@"owner",@"NSFileOwnerAccountName", |
| 271 |
@"group",@"NSFileGroupOwnerAccountName", |
| 272 |
nil,@"NSFilePosixPermissions", |
| 273 |
[NSNumber numberWithBool:YES],@"NSFileExtensionHidden", |
| 274 |
nil]; |
| 275 |
|
| 276 |
[manager changeCurrentDirectoryPath:dropPath]; |
| 277 |
NSString* temporaryDirectoryName = @"Lupin"; |
| 278 |
int random; |
| 279 |
srand(time(NULL)); |
| 280 |
while (1) { |
| 281 |
random = rand(); |
| 282 |
if ([manager fileExistsAtPath:temporaryDirectoryName]) |
| 283 |
temporaryDirectoryName = [NSString stringWithFormat:@"Lupin%d",random]; |
| 284 |
else |
| 285 |
break; |
| 286 |
} |
| 287 |
_droppedTemporaryPath = [dropPath stringByAppendingPathComponent:temporaryDirectoryName]; |
| 288 |
if (![manager createDirectoryAtPath:temporaryDirectoryName attributes:dic]) { |
| 289 |
NSLog(@"Can't create directory at %@",temporaryDirectoryName); |
| 290 |
[[self mainWindowController] showErrorAlert:NSLocalizedString(@"DialogCantCreateDirectoryTitle",nil) |
| 291 |
info:[NSString stringWithFormat:NSLocalizedString(@"DialogCantCreateDirectoryInfo",nil),_droppedTemporaryPath]]; |
| 292 |
[[self mainWindowController] archiveDidUncompress]; //! ��������������� |
| 293 |
return; |
| 294 |
} |
| 295 |
//��������������������������������������������������������������������������������������������� |
| 296 |
[[NSDocumentController sharedDocumentController] addDirectory:_droppedTemporaryPath]; |
| 297 |
|
| 298 |
[_droppedTemporaryPath retain]; |
| 299 |
[[self mainWindowController] archiveWillUncompress]; |
| 300 |
[_plugin archiveUncompress:_droppedTemporaryPath files:_selectedArray password:nil delegate:self selector:@selector(archiveDidUncompress:)]; |
| 301 |
[self showProcessWindow]; |
| 302 |
} |
| 303 |
|
| 304 |
- (void)archiveAllUncompress:(NSString*)dropPath |
| 305 |
{ |
| 306 |
NSFileManager *manager = [NSFileManager defaultManager]; |
| 307 |
NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys: |
| 308 |
[NSDate date],NSFileModificationDate, |
| 309 |
@"owner",@"NSFileOwnerAccountName", |
| 310 |
@"group",@"NSFileGroupOwnerAccountName", |
| 311 |
nil,@"NSFilePosixPermissions", |
| 312 |
[NSNumber numberWithBool:YES],@"NSFileExtensionHidden", |
| 313 |
nil]; |
| 314 |
|
| 315 |
[manager changeCurrentDirectoryPath:dropPath]; |
| 316 |
NSString* temporaryDirectoryName = @"Lupin"; |
| 317 |
int random; |
| 318 |
srand(time(NULL)); |
| 319 |
while (1) { |
| 320 |
random = rand(); |
| 321 |
if ([manager fileExistsAtPath:temporaryDirectoryName]) |
| 322 |
temporaryDirectoryName = [NSString stringWithFormat:@"Lupin%d",random]; |
| 323 |
else |
| 324 |
break; |
| 325 |
} |
| 326 |
_droppedTemporaryPath = [dropPath stringByAppendingPathComponent:temporaryDirectoryName]; |
| 327 |
if (![manager createDirectoryAtPath:temporaryDirectoryName attributes:dic]) { |
| 328 |
NSLog(@"Can't create directory at %@",temporaryDirectoryName); |
| 329 |
[[self mainWindowController] showErrorAlert:NSLocalizedString(@"DialogCantCreateDirectoryTitle",nil) |
| 330 |
info:[NSString stringWithFormat:NSLocalizedString(@"DialogCantCreateDirectoryInfo",nil),_droppedTemporaryPath]]; |
| 331 |
[[self mainWindowController] archiveDidUncompress]; //! ��������������� |
| 332 |
return; |
| 333 |
} |
| 334 |
//��������������������������������������������������������������������������������������������� |
| 335 |
[[NSDocumentController sharedDocumentController] addDirectory:_droppedTemporaryPath]; |
| 336 |
|
| 337 |
[_droppedTemporaryPath retain]; |
| 338 |
[[self mainWindowController] archiveWillUncompress]; |
| 339 |
_archiveAllUncompressMode = YES; |
| 340 |
[_plugin archiveAllUncompress:_droppedTemporaryPath exclude:nil password:nil delegate:self selector:@selector(archiveDidUncompress:)]; |
| 341 |
[self showProcessWindow]; |
| 342 |
} |
| 343 |
|
| 344 |
- (void)archiveDidUncompress:(LPError)error |
| 345 |
{ |
| 346 |
NSLog(@"archiveDidUncompress"); |
| 347 |
NSLog(@"Uncompressing Error #%d",error); |
| 348 |
if (error == LPErrorNotImplementMethod || error == LPErrorNotSupportFormat) { |
| 349 |
[_plugin release]; |
| 350 |
if ([_plugins count] > 0) { |
| 351 |
_plugin = [_plugins lastObject]; |
| 352 |
[_plugin retain]; |
| 353 |
[_plugins removeLastObject]; |
| 354 |
[_plugin archiveAllUncompress:_droppedTemporaryPath exclude:nil password:nil delegate:self selector:@selector(archiveDidUncompress:)]; |
| 355 |
return; |
| 356 |
} |
| 357 |
} else if (error == LPErrorRequestPassword || error == LPErrorBadPassword) { |
| 358 |
NSLog(@"asking password"); |
| 359 |
NSString* password = [[self mainWindowController] askPassword]; |
| 360 |
if (password) { |
| 361 |
if (_archiveAllUncompressMode) |
| 362 |
[_plugin archiveAllUncompress:_droppedTemporaryPath exclude:nil password:password delegate:self selector:@selector(archiveDidUncompress:)]; |
| 363 |
else |
| 364 |
[_plugin archiveUncompress:_droppedTemporaryPath files:_selectedArray password:password delegate:self selector:@selector(archiveDidUncompress:)]; |
| 365 |
return; |
| 366 |
} |
| 367 |
} |
| 368 |
if (error != LPErrorNoError) { |
| 369 |
[[self mainWindowController] showErrorAlertWithErrorID:error]; |
| 370 |
} |
| 371 |
[_progressTimer invalidate]; |
| 372 |
[_progressTimer release]; |
| 373 |
NSFileManager* manager = [NSFileManager defaultManager]; |
| 374 |
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; |
| 375 |
NSEnumerator* enumerator; |
| 376 |
NSMutableArray* array; |
| 377 |
NSString* filePath; |
| 378 |
|
| 379 |
array = [NSMutableArray array]; |
| 380 |
if (_archiveAllUncompressMode) { |
| 381 |
_archiveAllUncompressMode = NO; |
| 382 |
//_droppedTemporaryPath������������������������������_droppedTemporaryPath������������������������������������������ |
| 383 |
enumerator = [[manager directoryContentsAtPath:_droppedTemporaryPath] objectEnumerator]; |
| 384 |
while ((filePath = [enumerator nextObject])) { |
| 385 |
[array addObject:[_droppedTemporaryPath stringByAppendingPathComponent:filePath]]; |
| 386 |
} |
| 387 |
} else { |
| 388 |
enumerator = [_selectedArray objectEnumerator]; |
| 389 |
LPFile* file; |
| 390 |
while ((file = [enumerator nextObject])) { |
| 391 |
[array addObject:[_droppedTemporaryPath stringByAppendingPathComponent:[file path]]]; |
| 392 |
} |
| 393 |
} |
| 394 |
enumerator = [array objectEnumerator]; |
| 395 |
NSString* toPath; |
| 396 |
BOOL allOverwrite = ([defaults integerForKey:@"uncompressExistMatrix"] == 1); |
| 397 |
while (((filePath = [enumerator nextObject]) && [manager fileExistsAtPath:filePath])) { |
| 398 |
toPath = [[_droppedTemporaryPath stringByDeletingLastPathComponent] stringByAppendingPathComponent:[filePath lastPathComponent]]; |
| 399 |
if ([self moveFileFrom:filePath to:toPath onlyFile:([defaults integerForKey:@"uncompressOverwriteMatrix"] == 0) allOverwrite:&allOverwrite] == LPDialogCancel) |
| 400 |
break; |
| 401 |
} |
| 402 |
// ��������������������������������������� |
| 403 |
// ������������������[NSUserDefaults standardUserDefaults]������������������������������������������������ |
| 404 |
// ������������������������������������������������������������ |
| 405 |
if ([manager removeFileAtPath:_droppedTemporaryPath handler:nil]) |
| 406 |
[[NSDocumentController sharedDocumentController] removeDirectory:_droppedTemporaryPath]; |
| 407 |
else |
| 408 |
[[self mainWindowController] showErrorAlert:NSLocalizedString(@"DialogCantRemoveTemporaryFolderTitle",nil) |
| 409 |
info:[NSString stringWithFormat:NSLocalizedString(@"DialogCantRemoveTemporaryFolderInfo",nil),_droppedTemporaryPath]]; |
| 410 |
[[self mainWindowController] archiveDidUncompress]; |
| 411 |
} |
| 412 |
|
| 413 |
// onlyFile���NO���������������Mac OS X������YES������������Windows������������������������������������������������ |
| 414 |
// NO��������������������������������������������������������������������������������������������������������������������� |
| 415 |
// YES������������������������������������������������������������������������������������������������������������������������������������������������ |
| 416 |
- (LPDialogResult)moveFileFrom:(NSString*)fromPath to:(NSString*)toPath onlyFile:(BOOL)onlyFile allOverwrite:(BOOL*)allOverwrite |
| 417 |
{ |
| 418 |
NSFileManager* manager = [NSFileManager defaultManager]; |
| 419 |
BOOL result,isDir; |
| 420 |
LPDialogResult dialogResult = LPDialogYES; |
| 421 |
if (![manager fileExistsAtPath:fromPath isDirectory:&isDir]) //! ������������������������������������������������������������������������������������������������������ |
| 422 |
return LPDialogNO; |
| 423 |
if (![manager fileExistsAtPath:toPath]) { //! ��������������������������������� |
| 424 |
result = [manager movePath:fromPath toPath:toPath handler:nil]; |
| 425 |
if (!result) { |
| 426 |
NSLog(@"Failed(1) to move from %@ to %@",fromPath,toPath); |
| 427 |
return LPDialogNO; |
| 428 |
} |
| 429 |
} else if (!onlyFile || !isDir) { //! ��������������������������������������������������������������������������������������������������������� |
| 430 |
if (!*allOverwrite) //! ��������������������������������������������������������������������������������������� |
| 431 |
dialogResult = [[self mainWindowController] showChoiceAlert:allOverwrite |
| 432 |
title:NSLocalizedString(@"DialogAlreadyExistsTitle",nil) |
| 433 |
defaultButton:NSLocalizedString(@"DialogYes",nil) |
| 434 |
alternateButton:NSLocalizedString(@"DialogNo",nil) |
| 435 |
otherButton:NSLocalizedString(@"DialogCancel",nil) |
| 436 |
message:[NSString stringWithFormat:NSLocalizedString(@"DialogAlreadyExistsInfo",nil),toPath]]; |
| 437 |
if (allOverwrite || dialogResult == LPDialogYES) |
| 438 |
[manager removeFileAtPath:toPath handler:nil]; |
| 439 |
else if (dialogResult == LPDialogCancel) //! ������������������������������������������������������������������������������ |
| 440 |
return LPDialogCancel; |
| 441 |
result = [manager movePath:fromPath toPath:toPath handler:nil]; |
| 442 |
if (!result) { |
| 443 |
NSLog(@"Failed(2) to move from %@ to %@",fromPath,toPath); |
| 444 |
return LPDialogNO; |
| 445 |
} |
| 446 |
} else { //! ������������������������������������������������������ |
| 447 |
NSEnumerator* enumerator = [[manager subpathsAtPath:fromPath] objectEnumerator]; |
| 448 |
NSString* filePath; |
| 449 |
while (filePath = [enumerator nextObject]) { |
| 450 |
if ([self moveFileFrom:[fromPath stringByAppendingPathComponent:filePath] to:[toPath stringByAppendingPathComponent:filePath] onlyFile:onlyFile allOverwrite:allOverwrite] == LPDialogCancel) |
| 451 |
return LPDialogCancel; |
| 452 |
} |
| 453 |
} |
| 454 |
return LPDialogYES; |
| 455 |
} |
| 456 |
|
| 457 |
#pragma mark - |
| 458 |
#pragma mark Compress |
| 459 |
|
| 460 |
- (void)archiveCompress:(NSString*)archiveName files:(NSArray*)files exclude:(NSArray*)exclude currentPath:(NSString*)currentPath compress:(LPCompress*)compress option:(NSDictionary*)option |
| 461 |
{ |
| 462 |
NSLog([files description]); |
| 463 |
[[self mainWindowController] archiveWillCompress]; |
| 464 |
[_plugin archiveCompress:archiveName files:files exclude:exclude currentPath:currentPath compress:compress option:option delegate:self selector:@selector(archiveDidCompress:)]; |
| 465 |
[self showProcessWindow]; |
| 466 |
} |
| 467 |
|
| 468 |
- (void)archiveDidCompress:(LPError)error |
| 469 |
{ |
| 470 |
NSLog(@"Compressing Error #%d",error); |
| 471 |
if (error != LPErrorNoError) |
| 472 |
[[self mainWindowController] showErrorAlertWithErrorID:error]; |
| 473 |
[_progressTimer invalidate]; |
| 474 |
[_progressTimer release]; |
| 475 |
[[self mainWindowController] archiveDidCompress]; |
| 476 |
} |
| 477 |
|
| 478 |
#pragma mark - |
| 479 |
#pragma mark Showing Information |
| 480 |
|
| 481 |
- (void)showProcessWindow |
| 482 |
{ |
| 483 |
NSLog(@"showProcessWindow"); |
| 484 |
_progressTimer = [[NSTimer scheduledTimerWithTimeInterval:0.05 // ������������ |
| 485 |
target:[self mainWindowController] // ��������������������������������� |
| 486 |
selector:@selector(progressUpdate) // ������������������������������ |
| 487 |
userInfo:nil // ��������������������� |
| 488 |
repeats:YES] retain]; // ��������������������� |
| 489 |
|
| 490 |
[_progressTimer fire]; |
| 491 |
} |
| 492 |
|
| 493 |
#pragma mark - |
| 494 |
#pragma mark IBOutlet |
| 495 |
- (void)uncompress:(id)sender |
| 496 |
{ |
| 497 |
NSLog(@"(LPDocument) Uncompress selected."); |
| 498 |
|
| 499 |
[[self mainWindowController] archiveWillUncompress]; |
| 500 |
|
| 501 |
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; |
| 502 |
NSString* destination = NULL; |
| 503 |
switch ([defaults integerForKey:@"uncompressCreateAtMatrix"]) { |
| 504 |
case 0: |
| 505 |
destination = [[self fileName] stringByDeletingLastPathComponent]; |
| 506 |
break; |
| 507 |
case 1: |
| 508 |
destination = [NSHomeDirectory() stringByAppendingPathComponent:@"Desktop"]; |
| 509 |
break; |
| 510 |
case 2: |
| 511 |
destination = NSHomeDirectory(); |
| 512 |
break; |
| 513 |
case 3: |
| 514 |
break; |
| 515 |
case 4: |
| 516 |
destination = [defaults objectForKey:@"uncompressCreateAt"]; |
| 517 |
break; |
| 518 |
} |
| 519 |
if (destination) { |
| 520 |
[self archiveAllUncompress:destination]; |
| 521 |
return; |
| 522 |
} |
| 523 |
NSOpenPanel* openPanel = [NSOpenPanel openPanel]; |
| 524 |
[openPanel setTitle:NSLocalizedString(@"DialogUncompressChooseDestinationTitle",nil)]; |
| 525 |
[openPanel setMessage:NSLocalizedString(@"DialogUncompressChooseDestinationMessage",nil)]; |
| 526 |
[openPanel setPrompt:NSLocalizedString(@"DialogChooseFolderButtonTitle",nil)]; |
| 527 |
[openPanel setCanChooseDirectories:YES]; |
| 528 |
[openPanel setCanChooseFiles:NO]; |
| 529 |
[openPanel beginSheetForDirectory:NSHomeDirectory() file:nil types:[NSArray arrayWithObjects:@"txt",nil] modalForWindow:[[self mainWindowController] window] modalDelegate:self didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:) contextInfo:NULL]; |
| 530 |
} |
| 531 |
|
| 532 |
- (void)openPanelDidEnd:(NSOpenPanel *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo |
| 533 |
{ |
| 534 |
NSLog(@"panelDidEnd"); |
| 535 |
NSLog([sheet filename]); |
| 536 |
[sheet close]; //! ���������������������archiveAllUncompress������������������������������������������������������������������������������������������������������ |
| 537 |
if (returnCode == NSOKButton) { |
| 538 |
[self archiveAllUncompress:[sheet filename]]; |
| 539 |
} else if ([[self fileType] isEqualToString:@"LupinUncompressType"]) { |
| 540 |
//��������������������������������������������������������������������������� |
| 541 |
[self close]; |
| 542 |
} |
| 543 |
} |
| 544 |
@end |