Distributing Applications by creation of .dmg file

Discussion in 'Mac Programming' started by petron, Jan 7, 2010.

  1. petron macrumors member

    Joined:
    May 22, 2009
    Location:
    Malmo, Sweden
    #1
    Hi,
    Until now I have used tar.gz combination for distribution of software.
    But the use of .dmg file is a better and more convinient way for the Mac OS X world in order to distribute a software.

    My question is how I can control that some files placed into the new created disk image can be installed in a specific folder when running the "instalation" by accessing the .dmg file.

    I would like to place some application support files in a specific folder.

    For instance I want to place file1.db into:

    ~/Library/Application Support/My_Software/file1.db

    I appreciate the help.
    /petron
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    You can't. Although you can't really do that with a tar.gz structure either. You have two options: put an Installer package in the dmg or include the file in your apps resources and if it's not where you expect when you run copy it there.
     
  3. petron thread starter macrumors member

    Joined:
    May 22, 2009
    Location:
    Malmo, Sweden
    #3
    Hi robbieduncan,
    Thanks for the info. It at least explains why I could not make it.

    Installer Package - Never done it yet, may be it is time to do it now.

    Do you mean, I Just create a small App that creates the folder and copies over the resource file there ?

    /petron
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    No: either create a real Apple Installer package (rolling your own doesn't work with management tools like ARD). If you don't want to do that then the main application you are distributing should just copy the file from it's own Resources folder to wherever you need it.

    In general if you need this file for you application to run then it should not be in Application Support: as per the documentation "A support file is any type of file that supports the application but is not required for the application to run. Document templates and sample files are simple examples of support files." If you absolutely require this file and it's read-only then it belongs within the application itself. If it's read/write then somewhere in ~/Library/ (but not Application Support by the book, although many would say it's OK).
     
  5. alienapp macrumors member

    Joined:
    Jan 5, 2010
  6. petron thread starter macrumors member

    Joined:
    May 22, 2009
    Location:
    Malmo, Sweden
    #6
    Hi Robbieduncan,
    Thanks for more explanations.

    I will probably implement functionality in my App to create the folder and to move the file I need there. It should not be a big problem.

    Regarding the placement/location of the folder I am not sure what to choose. I am a bit confused and seems that I need to read a bit on this subject.

    Generally my App has no problem at all to start up without that extra file. When starting without it I currently show an Alert informing that the file is missing. There is only some extra functionality that will be blocked. At the same time I need a location folder for user entered information stored in an database file. The idea was to put it in the same location. Both files can be extracted and transferred to other users in order to share the information. It would be convenient.

    Personally I do not have strong feelings where to put it.
    I would be either:
    ~/Library/Application Support/myFolder
    or
    ~/Library/myFolder

    Do you have any comments ?

    /petron
     
  7. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #7
    If it's not required then I'd say ~/Library/Application Support/myFolder where myFolder should be the name of your application. If the file could be shared between users you should probably also check /Library/Application Support/myFolder (but if it has per-user data then don't bother).
     
  8. petron thread starter macrumors member

    Joined:
    May 22, 2009
    Location:
    Malmo, Sweden
    #8
    Hi Robbieduncan,

    A Note:
    The database files do not need to be shared but can be exchanged between different users on different computers, not necessary on the same computer. I will stay then at ~/

    I made the changes and it works nearly nicely. I have got a small exception.

    As long as I put the application into the /Applications folder all works fine, but the user can even start/place the application from other places.

    How can I get the path to the
    /<NotApplication>/MyApp.app/Contents/Resources

    Is there a method to get that path over ?

    Thank you in advance
    /petron
     
  9. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #9
    You should never assume that your application is in /Applications. Use NSBundle to get the correct path (with mainBundle and pathForResource:eek:fType:)
     
  10. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #10
    Thats for sure. For instance, I place third party apps in a subfolder of the Applications folder. Well, when they, or other application does make that silly assumption. Handbrake assumes VLC is in the the Applications folder.
     
  11. petron thread starter macrumors member

    Joined:
    May 22, 2009
    Location:
    Malmo, Sweden
    #11
    Thanks again...

    I got it now and it works.

    Code:
      NSBundle *myBundle = [NSBundle bundleForClass:[self class]];
      NSString *srcPath = [myBundle pathForResource:@"cfgTemp" ofType:@"xml"];
    

    /petron
     

Share This Page