Page 1 of 1

Save in/out windows

Posted: Tue Apr 08, 2025 12:22 pm
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)

Re: Save in/out windows

Posted: Tue Apr 08, 2025 12:45 pm
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

Re: Save in/out windows

Posted: Tue Apr 08, 2025 1:14 pm
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.

Re: Save in/out windows

Posted: Tue Apr 08, 2025 1:22 pm
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"

Re: Save in/out windows

Posted: Tue Apr 08, 2025 1:53 pm
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.

Re: Save in/out windows

Posted: Tue Apr 08, 2025 4:18 pm
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