Where to save user data, per OS?
Where to save user data, per OS?
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?
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?
Re: Where to save user data, per OS?
GetHomeDirectory
You can use this on all OS, but typically is on windows APPDATA used.
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.
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
-
- Enthusiast
- Posts: 536
- Joined: Mon Feb 16, 2009 10:42 am
- Location: sweden
- Contact:
Re: Where to save user data, per OS?
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?
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?
Re: Where to save user data, per OS?
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?
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.
Re: Where to save user data, per OS?
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: and put all required stuff in it.
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
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.
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Re: Where to save user data, per OS?
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.
On Windows, I'm not too worried about hiding my data, so long as it's neatly tucked away in its own AppData\subdir.
Re: Where to save user data, per OS?
It's similar to the +H attribute on windows, you can view a hidden file specifying the right switch for the console command.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.)
"Have you tried turning it off and on again ?"
A little PureBasic review
A little PureBasic review
Re: Where to save user data, per OS?
Mac OS X
/Users/name/Library/Application Support/yourfolder
Change "name" and "yourfolder".
/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.
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.
-
- Enthusiast
- Posts: 536
- Joined: Mon Feb 16, 2009 10:42 am
- Location: sweden
- Contact:
Re: Where to save user data, per OS?
Change name to what?/Users/name/Library/Application Support/yourfolder
Re: Where to save user data, per OS?
I'll take a wild, bold guess: "name" under the users folder... hmmm..... HMMMMM.... maybe the user's name ? Too bold ?jesperbrannmark wrote:Change name to what?
"Have you tried turning it off and on again ?"
A little PureBasic review
A little PureBasic review
Re: Where to save user data, per OS?
Bingo! It's the users name. I'm sure there's some code to get the users name but haven't tried myself yet.luis wrote:I'll take a wild, bold guess: "name" under the users folder... hmmm..... HMMMMM.... maybe the user's name ? Too bold ?jesperbrannmark wrote:Change name to what?
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.
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.
Re: Where to save user data, per OS?
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.
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.
Re: Where to save user data, per OS?
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.
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
Re: Where to save user data, per OS?
It does return "/Users/YourName/" like you stated.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.
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.
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.
-
- Enthusiast
- Posts: 252
- Joined: Mon Aug 16, 2010 4:29 am
Re: Where to save user data, per OS?
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.