Save in/out windows

Just starting out? Need help? Post your questions and find answers here.
User avatar
SPH
Enthusiast
Enthusiast
Posts: 573
Joined: Tue Jan 04, 2011 6:21 pm

Save in/out windows

Post by SPH »

Hi everyone,

I've noticed a problem that I hope can be fixed...
Here it is: if I install my PB game in the "usual" Windows location (c:\Program Files (x86)\), and if, during the game, I save the game, the save isn't saved in the "save" directory I had planned in my game folders.
The save is saved in a hidden location in a Windows directory, and so, if I restart the game, my save isn't found (since my PB code looks for it in the "save" directory of my game)...

By the way: if I install my game in a different directory, there's no problem with my saves...

Well, for Windows, I think this is "normal" behavior. But are there any PB instructions that address this problem?

Thanks 8)

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
User avatar
mk-soft
Always Here
Always Here
Posts: 6253
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Save in/out windows

Post by mk-soft »

According to the new Windows security guidelines, users are not allowed to write data in the programme directory.
There are certain directories for this purpose

Link: https://www.purebasic.fr/english/viewtopic.php?t=74233
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: Save in/out windows

Post by Marc56us »

No write acces in ProgramFile for normal user in Windows.
Save your datas in:

GetHomeDirectory()
or
GetUserDirectory() (PB 5.60+)

See help for details.
User avatar
gally
User
User
Posts: 41
Joined: Thu May 28, 2009 9:07 pm
Location: France
Contact:

Re: Save in/out windows

Post by gally »

Hello,

For me :

Code: Select all

CompilerIf #PB_Compiler_Debugger
  Define.s directory = GetCurrentDirectory()
CompilerElse
  Define.s directory = GetPathPart(ProgramFilename())
  If directory = #Null$
    directory = GetCurrentDirectory()
  EndIf
CompilerEndIf
Define savedirectory.s = directory + "save\"
If directory <> #Null$
  If Right(directory, 1) <> "\"
    directory + "\"
  EndIf
  If FileSize(savedirectory) <> -2
    CreateDirectory(savedirectory)
  EndIf
EndIf

;le répertoire de lecture et de sauvegarde est "savedirectory"
Fred
Administrator
Administrator
Posts: 18248
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Save in/out windows

Post by Fred »

You should never save in the executable directory especially if you allow the game to be installed in "program files". Use GetUserDirectory(#PB_Directory_ProgramData) and create a subpath for your game.
User avatar
mk-soft
Always Here
Always Here
Posts: 6253
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Save in/out windows

Post by mk-soft »

I found it again.
It is important that the subdirectories for your data are created correctly.

So with CompanyName and ApplicationName.

Note:
Modules creates directories!

Link: Module PathHelper
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply