Professional Web Applications Themes

Accessing files from carbon - Mac Programming

Hi, I'm buiding a small Carbon (with nibs) app using project builder on OS X 10.2.8. I would like to use a file to store (and retrieve) information entered via my app. The file would only be accessed from my app. 1) Where is the best place to store this file? (I'd like to keep it in the same folder as the application itself, but a common folder e.g /Library/Preferences or /System.... would work too) 2) How do I find/access the file? I can find my Volume Reference and a directory id (Using FindFolder or a GetApplicationDirectory function found at ...

  1. #1

    Default Accessing files from carbon

    Hi,

    I'm buiding a small Carbon (with nibs) app using project builder on OS X
    10.2.8. I would like to use a file to store (and retrieve) information
    entered via my app. The file would only be accessed from my app.

    1) Where is the best place to store this file?
    (I'd like to keep it in the same folder as the application itself, but a
    common folder e.g /Library/Preferences or /System.... would work too)

    2) How do I find/access the file?
    I can find my Volume Reference and a directory id (Using FindFolder or a
    GetApplicationDirectory function found at
    http://developer.apple.com/qa/fl/fl14.html).

    The volume reference comes back as -100 and I get a number for the
    directoryID as well. However I can't create a FSSpec using FSMakeFSSpec.

    The most I have been able to do so far is vary my error message by
    changing the fileName parameter as follows:

    fileName = "myFile" returns -35 (volume not found)
    fileName = "\pconfig" returns -43 (file not found, incomplete path name)

    I have tried putting in the full path to a known file as the filename
    (which should cause FSMakeFSSpec ignore the Volume and DirID parameters)
    but to no avail.

    Any help would be appreciated

    Thanks

    Dave

    Dave Guest

  2. #2

    Default Re: Accessing files from carbon

    In article <com>, Dave <com>
    wrote:
     

    Use

    FindFolder(kOnSystemDisk, kPreferencesFolderType,
    true, &theVRef, &theDirID);

    // note: this will return -43 if the file doesn't already exist,
    // but that is OK.
    FSMakeFSSpec(theVRef, theDirID, "\pMy App Prefs", &fs);

    // then create the file: will return an error if the file already exists
    FSpCreate(&fs, kMyAppCreatorType, 'pref', smRoman);

    // finally, open it with:

    FSpOpenDF(&fs, fsRdWrPerm, &ref);
    FSWrite(...);
    FSClose(ref);
    David Guest

  3. #3

    Default Re: Accessing files from carbon

    Thanks a million

    I was mis-reading the meaning of the error codes!

    /Dave

    David Phillip Oster wrote: 
    >
    >
    > Use
    >
    > FindFolder(kOnSystemDisk, kPreferencesFolderType,
    > true, &theVRef, &theDirID);
    >
    > // note: this will return -43 if the file doesn't already exist,
    > // but that is OK.
    > FSMakeFSSpec(theVRef, theDirID, "\pMy App Prefs", &fs);
    >
    > // then create the file: will return an error if the file already exists
    > FSpCreate(&fs, kMyAppCreatorType, 'pref', smRoman);
    >
    > // finally, open it with:
    >
    > FSpOpenDF(&fs, fsRdWrPerm, &ref);
    > FSWrite(...);
    > FSClose(ref);[/ref]


    Dave Guest

  4. #4

    Default Re: Accessing files from carbon

    In article <com>, Dave <com>
    wrote:
     

    What's in the file? Are they user-created doents? preferences?
    Sean Guest

Similar Threads

  1. Urgent: Online files accessing local files Issue
    By Gunjan Gupta in forum Macromedia Flash Player
    Replies: 3
    Last Post: June 7th, 08:49 PM
  2. memory mapped files under Carbon
    By Jedidja Bourgeois in forum Mac Programming
    Replies: 1
    Last Post: September 10th, 08:11 PM
  3. Resource files and Carbon - PLEASE HELP!
    By Vern Jensen in forum Mac Programming
    Replies: 1
    Last Post: August 9th, 09:11 AM
  4. Accessing Outlook files
    By Tom Russell in forum Windows XP/2000/ME
    Replies: 0
    Last Post: July 15th, 12:29 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139