Where to save user data, per OS?

Everything else that doesn't fall into one of the other PB categories.
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Where to save user data, per OS?

Post by kenmo »

Lately I've been getting into cross-platform programming, after writing exclusively for Windows for years. In fact I typically write for my own home computer, with Windows XP Pro, in which I have full admin privileges.

But for Vista/Win7 and Mac and Linux, I am wondering if I will run into problems with where to save program files. Usually I just save them into my program's current directory, or a subdirectory.

On Vista/Win7, isn't Windows more strict about where you are allowed to save files? (Maybe just non-admins?) Is it okay to save in the program's own folder, or should I play it safe and only save to GetHomeDirectory() + "\whatever"? And what should "whatever" be, "Application Data\MyProgramName", "Local Settings\AppData\MyProgramName", etc.?

The same questions apply to Mac/Linux. I have heard about programs failing App Store approval because they write to "Documents/MyProgramName" rather than "Documents/AppData/MyProgramName" or similar.

This typically applies to files unseen by the user (like preference files). Hopefully I don't have to worrying about the user selecting a disallowed folder to save user-created files, like images in an image editor?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Where to save user data, per OS?

Post by ts-soft »

GetHomeDirectory
You can use this on all OS, but typically is on windows APPDATA used.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: Where to save user data, per OS?

Post by jesperbrannmark »

I will probably be beaten in public on this forum for this.
The only place I would save random datafiles created by my software would be "my documents" folder. When Microsoft released Vista and all my datafiles was moved to "virtualstore" I was a bit fed up. My Documents folder is not likely to change rights, but for all other you never know what their next move is.

For Mac.... I have asked myself the same question (including how can I find my documents folder?) but have no answer. Someone might be able to fill me in here?
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: Where to save user data, per OS?

Post by kenmo »

ts-soft, I know about GetHomeDirectory(), I mentioned it in my post, but I'm looking for specifics...

For example, on my Win XP, various software has saved to
[home]\Application Data\[name]\
[home]\Local Settings\Application Data\[name]\
[home]\Local Settings\Apps\[name]\

On Windows 7 right now, I have
[home]\AppData\Local\[name]\
[home]\AppData\LocalLow\[name]\ (??)
[home]\AppData\Roaming\[name]\ (??)

I don't have a Mac, but I believe the recommended path is also like
[home]/AppData/[name]/

Linux I have no idea what the standard software paths are....

Maybe I should worry about this later when I am in testing stages?
Last edited by kenmo on Sat Aug 13, 2011 8:55 pm, edited 1 time in total.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Where to save user data, per OS?

Post by ts-soft »

for linux is it the right path, but you have add your applicationdir with a dot at the beginning, to hide the dir.

I use something like this on all os:

Code: Select all

Procedure.s GetPrefFile()
  Protected PrefFile.s = GetHomeDirectory()

  PrefFile = ReplaceString(PrefFile, "\", "/")
  PrefFile + ".ts-soft"
  If FileSize(PrefFile) <> - 2
    CreateDirectory(PrefFile)
    CompilerIf #PB_Compiler_OS = #PB_OS_Windows
      SetFileAttributes(PrefFile, #PB_FileSystem_Hidden)
    CompilerEndIf
  EndIf
  PrefFile + "/ProgramName"
  If FileSize(PrefFile) <> - 2
    CreateDirectory(PrefFile)
  EndIf
  PrefFile + "/ProgramName.prefs"

  ProcedureReturn PrefFile
EndProcedure
and put all required stuff in it.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: Where to save user data, per OS?

Post by kenmo »

Hmm, good suggestion, I did not know that a "." prefix makes a file hidden on Linux. Good tip. Is it only hidden from GUI interfaces, or even from "ls" terminal calls? (There's probably a "ls" flag to include/exclude hidden files.)

On Windows, I'm not too worried about hiding my data, so long as it's neatly tucked away in its own AppData\subdir.
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Where to save user data, per OS?

Post by luis »

kenmo wrote:Hmm, good suggestion, I did not know that a "." prefix makes a file hidden on Linux. Good tip. Is it only hidden from GUI interfaces, or even from "ls" terminal calls? (There's probably a "ls" flag to include/exclude hidden files.)
It's similar to the +H attribute on windows, you can view a hidden file specifying the right switch for the console command.
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: Where to save user data, per OS?

Post by J. Baker »

Mac OS X

/Users/name/Library/Application Support/yourfolder

Change "name" and "yourfolder". ;)
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: Where to save user data, per OS?

Post by jesperbrannmark »

/Users/name/Library/Application Support/yourfolder
Change name to what?
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Where to save user data, per OS?

Post by luis »

jesperbrannmark wrote:Change name to what?
I'll take a wild, bold guess: "name" under the users folder... hmmm..... HMMMMM.... maybe the user's name ? Too bold ?
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: Where to save user data, per OS?

Post by J. Baker »

luis wrote:
jesperbrannmark wrote:Change name to what?
I'll take a wild, bold guess: "name" under the users folder... hmmm..... HMMMMM.... maybe the user's name ? Too bold ?
Bingo! It's the users name. I'm sure there's some code to get the users name but haven't tried myself yet.
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: Where to save user data, per OS?

Post by kenmo »

Thanks for that J.

What does GetHomeDirectory() return on your (or any) Mac? Probably the "/Users/[name]/" that you mentioned?

So it's probably smart to create and write to GetHomeDirectory() + "Library/Application Support/[appname]/"?

Maybe if everyone agrees on these 'standard' locations, they could be added to the FAQ thread.
WilliamL
Addict
Addict
Posts: 1215
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: Where to save user data, per OS?

Post by WilliamL »

That makes sense to me but I would add that the files in the Application Support folder should be in a folder of the App name.

GetHomeDirectory()+ "Library/Application Support/"+[app name folder]/file

Of course, preferences go in the GetHomeDirectory()+ "Library/Preferences/" folder and resources stay with the app in the App/Contents/[Resources/] folder.
MacBook Pro-M1 (2021), Sonoma 14.3.1 (CLT 15.3), PB 6.10b7 M1
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: Where to save user data, per OS?

Post by J. Baker »

kenmo wrote:Thanks for that J.

What does GetHomeDirectory() return on your (or any) Mac? Probably the "/Users/[name]/" that you mentioned?

So it's probably smart to create and write to GetHomeDirectory() + "Library/Application Support/[appname]/"?

Maybe if everyone agrees on these 'standard' locations, they could be added to the FAQ thread.
It does return "/Users/YourName/" like you stated. ;)
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
buddymatkona
Enthusiast
Enthusiast
Posts: 252
Joined: Mon Aug 16, 2010 4:29 am

Re: Where to save user data, per OS?

Post by buddymatkona »

This might be a good place to mention all PB tools should be changed to put files in the USER area rather than the Program Files area. Pbcompiler.exe may still try to write PureBasic.asm in the compiler directory. You can run into trouble trying to see ASM output from a Windows 7 command window with all default settings.
Post Reply