B4J Question Folders, Files for Business Progs on Windows, Mac and Linux

BPak

Active Member
Licensed User
Longtime User
Most of my programs are written as Business Applications.
The program is installed in Program Files on the C:\ drive of Windows computers.
Programs for Mac OS X Lion are installed to Applications Folder on Macintosh HD drive.

I need to have the programs have permission to write and read data to and from the drive.

On Windows this should be done in the Users folder/s. Mac also has a Users section.

I have made a small utility program to test out Windows, Mac and Linux.

On Windows the Folders are pre created as -
C:\
C:\Users\
C:\Users\Public

This test program can work with these folders and create a Folder under C:\Users\Public where

I can place my PDF files and Database files, and so on. Any User can have access to this

Folder and its files.

On Macintosh the Folders are pre created as -
/
/Users
/Users/Shared

This test program can work the same here as it does in Windows with Folders and Files.

I do not have a Linux OS installed and would like some help from Users to finish the Coding

of this Test Program.

Any help would be appreciated.
 

Attachments

  • Folders.zip
    35.4 KB · Views: 227

dilettante

Active Member
Licensed User
Longtime User
The special folder Public (Windows Vista and later) is a user folder much like Desktop or Documents. It isn't meant to be used for program data such as a database. This works as a hack when desperate, but applications are really expected to use a unique subfolder created under the ProgramData (Common App Data) folder that your installer creates and sets the desired security on.

Files created for direct user fiddling (PDF document, etc.) should be sited by the user based on something like a Common Dialog (GetSaveFileName call or similar).

Dealing with these issues in a multiplatform manner is tough, I agree. However just dumping stuff into locations owned by the users isn't a best practice.
 
Upvote 0

dilettante

Active Member
Licensed User
Longtime User
Special folder names are also localized, i.e.:

C:\Users\Username\Documents

.. on a German system is:

C:\Benutzer\Username\Dokumente
 
Upvote 0

BPak

Active Member
Licensed User
Longtime User
Thanks for the info Dilettante. That covers Windows...

In the past I have used the following for data for individual users on Windows.
C:\Users\UserName\AppData\Local\[SubFolder for App data]
 
Upvote 0

rboeck

Well-Known Member
Licensed User
Longtime User
Special folder names are also localized, i.e.:

C:\Users\Username\Documents

.. on a German system is:

C:\Benutzer\Username\Dokumente

A small comment: since vista the folder names are NOT localized, try to use cmd.exe and you will find c:\users, even on german systems. The localization was transfered to the explorer, but the file system is now all the same (i can ony check german systems... )
 
Upvote 0

BPak

Active Member
Licensed User
Longtime User
On Windows you can find the "app data" folder with:
B4X:
Log(File.Combine(GetEnvironmentVariable("APPDATA", ""), "YourApp\")) 'C:\Users\<user name>\AppData\Roaming\YourApp

This is a good place to write files. It doesn't require admin permissions (like Program Files for example).

Does the sub folder [Roaming] maintain its files - not subject to deleting files when using a file cleaning program?
 
Upvote 0

dilettante

Active Member
Licensed User
Longtime User
Unless you understand roaming profiles and make a conscious decision to have your data roam this is a poor choice. It is not a desireable location for most application data.
 
Upvote 0

BPak

Active Member
Licensed User
Longtime User
If the UserName could be obtained then the placing of Data into a folder under the Users profile would be more easily done?
System.getProperty("user.name");
 
Upvote 0

BPak

Active Member
Licensed User
Longtime User
It works on the Mac and returns the UserName that is logged in.
Hopefully it will work on Linux. If so I have a common reference area for Files.
 
Upvote 0

BPak

Active Member
Licensed User
Longtime User
Did some research on a Forum for Mac to get more info for Folders and Files.

B4X:
I am rather new at the Mac and would like to know the correct place to Install my released Programs and their Files to.
The program is to go under the APPLICATIONS Folder but where would a SQLite Database belonging to the Program be installed?
Is there a special place on the Mac for installation of Files belonging to a Program?
Any reference links?
-REPLY----------------------------------------------------------------------------------------
There are several choices depending on your needs.

1) Place it in the application folder. One database for all users and a new one with a new version of your program. 
I think Contents/SharedSupport would be appropriate, but check the apple developer docs.

2) Place it in /Library/Application Support/Name of your Program/. 
One database for all users, but it remains, when you update the program.

3) Place it in ~/Library/Application Support/Name of your Program/. 
Each user has its own database and the database remains, when you update it.

Maybe read FileSystemProgrammingGuide of the Developer pages as well as http://cocoadev.com/ApplicationSupportFolder

MiSchi
 
Upvote 0
Top