Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

trey5498

macrumors regular
Original poster
Jun 16, 2008
191
0
I have decided to use the FileManager built in with Xcode for the checking and coping of files.

Will this code work correctly? I ask here because I haven't gotten that far in the gui to test it and I took a break from that frustration to work on the behind the sceens.

Code:
NSString *source = @"/Library/Printers/PPDs/Contents/Resources/HP DesignJet 1055CM PS3.gz"; 
NSString *tmpsource = @"/tmp/HP DesignJet 1055CM PS3.gz";

dvrchk = [[NSFileManager defaultManager] fileExistsAtPath:source];

if (dvrchk == NO)
{
     [fileManager copyPath:tmpsource toPath:@"/Library/Printers/PPDs/Contents/Resources/" handler:nil];
}


I also have this for the next button that will open the new window and close the current window. However the interface building will only let me have one window action for the button though:

Code:
- (IBAction)NextButton:(ID)sender {
  [prnSelector performClose:self];
  [prnOverview orderFront:self];
}

What did I do wrong on the new window and will this prvent me from calling another sub that will check the checkboxes and placing them in an array?

and is the following coded correctly:

Code:
if([checkboxname isEqualToString:@"Printer1"]  == YES) {

  printerarray[i] = Printer1;
} else if{
the other 17 checkboxes
}
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Code:
NSString *source = @"/Library/Printers/PPDs/Contents/Resources/HP DesignJet 1055CM PS3.gz"; 
NSString *tmpsource = @"/tmp/HP DesignJet 1055CM PS3.gz";

dvrchk = [[NSFileManager defaultManager] fileExistsAtPath:source];

if (dvrchk == NO)
{
     [fileManager copyPath:tmpsource toPath:@"/Library/Printers/PPDs/Contents/Resources/" handler:nil];
}

This won't do what you expect. The toPath: has to be the complete path you want to copy the file to including the filename, not just the directory you want to copy into.
 

trey5498

macrumors regular
Original poster
Jun 16, 2008
191
0
Code:
[fileManager copyPath:tmpsource toPath:@"/Library/Printers/PPDs/Contents/Resources/HP DesignJet 1055CM PS3.gz" handler:nil];

would that work and do what I need it to?

What about the other questions.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Code:
[fileManager copyPath:tmpsource toPath:@"/Library/Printers/PPDs/Contents/Resources/HP DesignJet 1055CM PS3.gz" handler:nil];

would that work and do what I need it to?

What about the other questions.

Should do as long as fileManager is valid. You don't seem to have declared it or initialised it anywhere...
 

trey5498

macrumors regular
Original poster
Jun 16, 2008
191
0
Crap,

didnt notice where to declare it.

How do I declare the FileManager?
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Assuming that it's meant to be a pointer to the global NSFileManager object then

Code:
NSFileManager *fileManager = [NSFileManager defaultManager];

If you do it above the bit where you check the existence of the file then you can use the variable in place of the [NSFileManager defaultManager] code you currently have too.
 

trey5498

macrumors regular
Original poster
Jun 16, 2008
191
0
So this will work correctly? I just want to make sure.



Code:
//
//  DvrChk.m
//  Circa Printer Installer
//
//  Created by treyb on 6/19/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "DvrChk.h"


@implementation DvrChk
NSFileManager *fileManager = [dvrchk];
NSString *sourceplotter1 = @"/Library/Printers/PPDs/Contents/Resources/HP DesignJet 1055CM PS3.gz"; 
NSString *sourcepplotter2 = @"/Library/Printers/PPDs/Contents/Resources/HP DesignJet T1100ps 44in.gz";
NSString *sourcebw = @"/Library/Printers/PPDs/Contents/Resources/HP LaserJet 4250.gz";
NSString *sourcecolor = @"/Library/Printers/PPDs/Contents/Resources/Xerox Phaser 7700GX.gz";

NSString *tmpsourcep1 = @"/tmp/HP DesignJet 1055CM PS3.gz";
NSString *tmpsourcep2 = @"/tmp/HP DesignJet T1100ps 44in.gz";
NSString *tmpsourcebw = @"/tmp/HP LaserJet 4250.gz";
NSString *tmpsourcec = @"/tmp/Xerox Phaser 7700GX.gz";

- (void)Plotter1
{

	dvrchk = [[NSFileManager defaultManager] fileExistsAtPath:sourceplotter1];

	if (dvrchk == NO)
	{
		[fileManager copyPath:tmpsourcep1 toPath:@"/Library/Printers/PPDs/Contents/Resources/HP DesignJet 1055CM PS3.gz" handler:nil];
	}

}

- (void)Plotter2
{

	dvrchk = [[NSFileManager defaultManager] fileExistsAtPath:sourceplotter2];

	if (dvrchk == NO)
	{
		[fileManager copyPath:tmpsourcep2 toPath:@"/Library/Printers/PPDs/Contents/Resources/HP DesignJet T1100ps 44in.gz" handler:nil];
	}

}

- (void)BWQ
{

	dvrchk = [[NSFileManager defaultManager] fileExistsAtPath:sourcebw];

	if (dvrchk == NO)
	{
		[fileManager copyPath:tmpsourcebw toPath:@"/Library/Printers/PPDs/Contents/Resources/HP LaserJet 4250.gz" handler:nil];
	}

}

- (void)Color
{

	dvrchk = [[NSFileManager defaultManager] fileExistsAtPath:sourcecolor];

	if (dvrchk == NO)
	{
		[fileManager copyPath:tmpsourcec toPath:@"/Library/Printers/PPDs/Contents/Resources/Xerox Phaser 7700GX.gz" handler:nil];
	}

}
@end
 

trey5498

macrumors regular
Original poster
Jun 16, 2008
191
0
Assuming that it's meant to be a pointer to the global NSFileManager object then

Code:
NSFileManager *fileManager = [NSFileManager defaultManager];

If you do it above the bit where you check the existence of the file then you can use the variable in place of the [NSFileManager defaultManager] code you currently have too.

Was attempting to use where you said I could use the variable. I get a weird token error before the ']' and it also gave me that dvrchk was not declared however when I delcare it as:

Code:
BOOL *dvrchk;


I get a warning about variable without a cast. I that line where I declared the filemaneger seems to not be correct.

However I may have the wrong variable in that line that you were talking about. I now believe you meant change the variable in the lower code to:

Code:
dvrchk = [[fileManager] fileExistsAtPath:sourceplotter1];

However when that is changed I still get the "error:syntax error before ']' token", two of them at the NSFileManager *fileManager = [NSFileManager defaultManager]; line and I get two "warning: assignment makes pointer from integer without a cast at the dvrchk = [[fileManager] fileExistsAtPath:sourceplotter1]; line
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Right lets look at this.

Code:
BOOL *dvrchk;

Declares a pointer to a BOOL. At this stage it's not pointing at anything. It can only be used to point at a BOOL, not an int, not an NSString, not an NSFileManager etc.

Code:
[dvrchk]

is illegal syntax. It is the correct syntax to send a message to an object pointed to by dvrchk, but no message is specified and dvrchk can't point to an object anyway as it's declared as a pointer to a BOOL.

Here's a version that at least makes sense and will work assuming that you have other code to call this

Code:
//
//  DvrChk.m
//  Circa Printer Installer
//
//  Created by treyb on 6/19/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "DvrChk.h"


@implementation DvrChk
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *sourceplotter1 = @"/Library/Printers/PPDs/Contents/Resources/HP DesignJet 1055CM PS3.gz"; 
NSString *sourcepplotter2 = @"/Library/Printers/PPDs/Contents/Resources/HP DesignJet T1100ps 44in.gz";
NSString *sourcebw = @"/Library/Printers/PPDs/Contents/Resources/HP LaserJet 4250.gz";
NSString *sourcecolor = @"/Library/Printers/PPDs/Contents/Resources/Xerox Phaser 7700GX.gz";

NSString *tmpsourcep1 = @"/tmp/HP DesignJet 1055CM PS3.gz";
NSString *tmpsourcep2 = @"/tmp/HP DesignJet T1100ps 44in.gz";
NSString *tmpsourcebw = @"/tmp/HP LaserJet 4250.gz";
NSString *tmpsourcec = @"/tmp/Xerox Phaser 7700GX.gz";

- (void)Plotter1
{

	dvrchk = [fileManager fileExistsAtPath:sourceplotter1];

	if (dvrchk == NO)
	{
		[fileManager copyPath:tmpsourcep1 toPath:@"/Library/Printers/PPDs/Contents/Resources/HP DesignJet 1055CM PS3.gz" handler:nil];
	}

}

- (void)Plotter2
{

	dvrchk = [fileManager fileExistsAtPath:sourceplotter2];

	if (dvrchk == NO)
	{
		[fileManager copyPath:tmpsourcep2 toPath:@"/Library/Printers/PPDs/Contents/Resources/HP DesignJet T1100ps 44in.gz" handler:nil];
	}

}

- (void)BWQ
{

	dvrchk = [fileManager fileExistsAtPath:sourcebw];

	if (dvrchk == NO)
	{
		[fileManager copyPath:tmpsourcebw toPath:@"/Library/Printers/PPDs/Contents/Resources/HP LaserJet 4250.gz" handler:nil];
	}

}

- (void)Color
{

	dvrchk = [fileManager fileExistsAtPath:sourcecolor];

	if (dvrchk == NO)
	{
		[fileManager copyPath:tmpsourcec toPath:@"/Library/Printers/PPDs/Contents/Resources/Xerox Phaser 7700GX.gz" handler:nil];
	}

}
@end

Note that you need to change the declaration of dvrchk to

Code:
BOOL dvrchk;

It doesn't need to be a pointer, simply a BOOL.
 

trey5498

macrumors regular
Original poster
Jun 16, 2008
191
0
Code:
NSFileManager *fileManager = [NSFileManager defaultManager];

Yields an error: "error: initializer element is not a constant

And BTW, Thank you ever so much for your help and patience ;)
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Code:
NSFileManager *fileManager = [NSFileManager defaultManager];

Yields an error: "error: initializer element is not a constant

And BTW, Thank you ever so much for your help and patience ;)

Probably because it's just inline. Should be in an init method really:

Code:
@implementation DvrChk
NSFileManager *fileManager;

-(id) init
{
if ([super init])
{
  fileManager = [NSFileManager defaultManager];
}
return self;
}
 

trey5498

macrumors regular
Original poster
Jun 16, 2008
191
0
That worked. Thank you again for your patience for my ignorance.

Know any good sites for tutorials or code examples that I can rip apart to learn a little more on my own?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.