Skip navigation.
 
mlRe: Does this caution need fixed? (newb)
FROM : Chris Paveglio
DATE : Wed Jul 09 16:44:48 2008

I'm trying to make sure that this part of my code is good and clean and not leaking. I believe that I have it right (but still think I have something wrong).
This code makes a list of file paths, and then copies the files or folders from their location to the destination the user selected. If the item already exists in the destination, I delete it first (to overwrite with new data, yes this is what I intend and the user is aware of how the app works).
I've read all your previous responses (Thanks) and it seems like since I am just using "normal" strings that they will be autoreleased on their own. There are now no compiler cautions and the app seems to work OK.
A side issue is that I want to add a 2 second delay before closing the sheet that is displayed, is NSTimer the correct item to use?
Chris



#import "MyExporter.h"

@implementation MyExporter

- (IBAction)exportPrefs:(id)sender
{
NSOpenPanel *theOpenPanel = [NSOpenPanel openPanel];
[theOpenPanel setTitle:@"Choose a folder to save your prefs into:"];
[theOpenPanel setCanChooseDirectories:YES];
[theOpenPanel setCanChooseFiles:NO];

if ([theOpenPanel runModal] == NSOKButton)
//if user chooses a folder
   {
       NSString *theDestination = [theOpenPanel filename]; //get name
       NSFileManager *theManager = [NSFileManager defaultManager]; //make an NSFM
       
       //if files dont exist on user machine it just seems to bypass copying them
       NSString *string1  = @"Library/Preferences/Adobe Photoshop CS3 Settings";
       NSString *string1a = @"Adobe Photoshop CS3 Settings";
       NSString *string2  = @"Library/Preferences/Adobe Illustrator CS3 Settings";
       NSString *string2a = @"Adobe Illustrator CS3 Settings";
       NSString *string3  = @"Library/Preferences/Adobe InDesign/Version 5.0";
       NSString *string3a = @"Version 5.0";
       NSString *string4  = @"Library/Preferences/CDFinder Preferences";
       NSString *string4a = @"CDFinder Preferences";
       NSString *string5  = @"Library/Application Support/Firefox";
       NSString *string5a = @"Firefox";
       NSString *string6  = @"Library/Safari";
       NSString *string6a = @"Safari";
       NSString *string7  = @"Library/Application Support/Adobe/Adobe PDF/Settings";
       NSString *string7a = @"Settings";
       NSString *string8  = @"Library/Preferences/Acrobat Distiller Prefs";
       NSString *string8a = @"Acrobat Distiller Prefs";
       NSString *string9  = @"Documents/Microsoft User Data";
       NSString *string9a = @"Microsoft User Data";
       
       //make 2 arrays with locations of orig prefs, and then short version to save in folder
       NSArray *myPrefs;
       myPrefs = [NSArray arrayWithObjects: string1, string2, string3, string4, string5, string6, string7, string8, string9, nil];
       
       NSArray *myPrefsSaved;
       myPrefsSaved = [NSArray arrayWithObjects: string1a, string2a, string3a, string4a, string5a, string6a, string7a, string8a, string9a, nil];
       
       //start panel here
       [NSApp beginSheet:exportSheet modalForWindow:mainWindow modalDelegate:self didEndSelector:NULL contextInfo:nil];

       [exportProgressBar setDoubleValue:(double)3.0]; //fake ourselves some progress
       [exportProgressBar displayIfNeeded];

       int i;
       for (i = 0; i < 8; i++) //skip string9 for testing, takes too long to copy
       {        
           NSString *theSettings = [NSHomeDirectory() stringByAppendingPathComponent:[myPrefs objectAtIndex:i]];
           //change/set out variable to this data
       
           //loop with each item saving into our destination folder
           NSString *theDestinationFile = [theDestination stringByAppendingPathComponent:[myPrefsSaved objectAtIndex:i]];
           
           [exportCurrentFileName setStringValue:(@"%@",[myPrefsSaved objectAtIndex:i])];
           [exportCurrentFileName displayIfNeeded]; //give a kick to our text box dammit!
           
           //delete the old pref file
           [theManager removeFileAtPath:theDestinationFile handler:nil];
       
           //copy the file
           [theManager copyPath:theSettings toPath:theDestinationFile handler:nil];
           
           [exportProgressBar incrementBy:(double)11.0]; //11 is arbitrary progress (100 divided by 9 items)
           [exportProgressBar displayIfNeeded];
           
       }
       [exportProgressBar setDoubleValue:100.0];
       [exportProgressBar displayIfNeeded];
       //end sheet here
       [exportSheet orderOut:nil];
       [NSApp endSheet:exportSheet];
   }
}



@end

Related mailsAuthorDate
mlDoes this caution need fixed? (newb) Chris Paveglio Jul 3, 18:40
mlRe: Does this caution need fixed? (newb) Andy Lee Jul 3, 19:35
mlRe: Does this caution need fixed? (newb) Kyle Sluder Jul 3, 19:47
mlRe: Does this caution need fixed? (newb) Chris Paveglio Jul 3, 20:57
mlRe: Does this caution need fixed? (newb) Sherm Pendley Jul 3, 21:08
mlRe: Does this caution need fixed? (newb) Jason Stephenson Jul 3, 21:22
mlRe: Does this caution need fixed? (newb) Michael Watson Jul 3, 21:29
mlRe: Does this caution need fixed? (newb) Andy Lee Jul 3, 21:43
mlRe: Does this caution need fixed? (newb) Chris Paveglio Jul 3, 22:09
mlRe: Does this caution need fixed? (newb) Steve Christensen Jul 3, 22:46
mlRe: Does this caution need fixed? (newb) Steve Christensen Jul 3, 22:53
mlRe: Does this caution need fixed? (newb) Sean McBride Jul 3, 23:04
mlRe: Does this caution need fixed? (newb) Jason Stephenson Jul 4, 02:22
mlRe: Does this caution need fixed? (newb) Chris Paveglio Jul 9, 16:44
mlRe: Does this caution need fixed? (newb) Jens Alfke Jul 9, 17:27
mlRe: Does this caution need fixed? (newb) Brian Stern Jul 9, 21:39