Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 552 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Creating a Directory #476342
02/19/19 19:11
02/19/19 19:11
Joined: May 2005
Posts: 868
Chicago, IL
Dooley Offline OP
User
Dooley  Offline OP
User

Joined: May 2005
Posts: 868
Chicago, IL
My question has two parts: First, I am able to create a directory in my game's folder using a kind of hack:

Quote:
str_cpy(save_dir,level_string);

compatibility = 8;

galaxy_write = file_open_write("Save_Test.txt");

file_str_write(galaxy_write,"SAVE TEST");//creates a file in order to actually create the folder
file_str_write(galaxy_write,",");

file_close(galaxy_write);

compatibility = 10;//resumes normal compatibility


However, this seems to create other problems in my game.

Is there a way to do it without changing the compatibility?

Second, I can't seem to create a directory in the "ProgramData" folder. I can write a file into an existing folder, but I can't create a new one, with or without the compatibility hack.

I'm thinking I would need to use the windows.h API thing, but I am unsure how to do that.

Re: Creating a Directory [Re: Dooley] #476343
02/19/19 19:22
02/19/19 19:22
Joined: May 2005
Posts: 868
Chicago, IL
Dooley Offline OP
User
Dooley  Offline OP
User

Joined: May 2005
Posts: 868
Chicago, IL
Ah ... got it!

Code:
CreateDirectory("C:\ProgramData\FolderName",0.000);



(it's not showing double backslash for some reason )

Fairly self explanatory, it requires windows.h to be included of course. You would think something like this would be in the manual.

Is there a separate manual somewhere that describes the Windows API?

Last edited by Dooley; 02/19/19 19:27.
Re: Creating a Directory [Re: Dooley] #476344
02/19/19 19:43
02/19/19 19:43
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
https://docs.microsoft.com/en-us/windows/desktop/api/index

Check SHGetFolderPath too. Sorry, I read it is mostly deprecated. Check SHGetKnownFolderPath instead.

Salud!

Last edited by txesmi; 02/19/19 19:59.
Re: Creating a Directory [Re: txesmi] #476345
02/19/19 22:06
02/19/19 22:06
Joined: May 2005
Posts: 868
Chicago, IL
Dooley Offline OP
User
Dooley  Offline OP
User

Joined: May 2005
Posts: 868
Chicago, IL
What is deprecated? The one I used or the one you are suggesting?

Re: Creating a Directory [Re: Dooley] #476346
02/19/19 22:49
02/19/19 22:49
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
The one I sugested first (and striked out)

Re: Creating a Directory [Re: txesmi] #476386
02/21/19 22:04
02/21/19 22:04
Joined: Jul 2007
Posts: 619
Turkey, Izmir
Emre Offline
User
Emre  Offline
User

Joined: Jul 2007
Posts: 619
Turkey, Izmir
Txesmi is right. But SHGetKnownFolderPath is seems a bit tricky to integrate.

I used SHGetFolderPath years ago. it no needs dll. but i'm unable to use SHGetKnownFolderPath without dll.

So, if you will follow this path, here is example for you:

plugin:
Code:
#include <wchar.h>
#include <KnownFolders.h>
#include <shlobj.h>
#include <comdef.h> 

wchar_t* path = new wchar_t[128];
DLLFUNC void  SHGetKnownFolderPathProgramData(char* str)
{
	
	SHGetKnownFolderPath(FOLDERID_ProgramData, 0, NULL, &path);
	_bstr_t b(path);
	const char* c = b;

	strcpy((char*)str, (char*)c);

}



lite-c

Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
#include <windows.h>



char* savedir_str="";
void SHGetKnownFolderPathProgramData(str);
void on_1_event()
{	
	SHGetKnownFolderPathProgramData(savedir_str);
	printf(_chr(savedir_str));
}

void main()
{
	fps_max = 60;
	level_load(NULL);

}



i'm not sure my codes are totally correct. i'm just showing the way.

And here is the sample with dll. There are two function in it. FOLDERID_LocalAppData and FOLDERID_ProgramData.

Good luck!

edit: btw, it's not for create directory, it's for get the correct directory on every pc.

Last edited by Emre; 02/21/19 22:08.
Re: Creating a Directory [Re: Emre] #476392
02/22/19 05:46
02/22/19 05:46
Joined: May 2005
Posts: 868
Chicago, IL
Dooley Offline OP
User
Dooley  Offline OP
User

Joined: May 2005
Posts: 868
Chicago, IL
Thanks!

The one I used seems to work fine. I was able to enhance it even more by using the "_chr()" function, so I can create the name of the folder in-game...

Code:
CreateDirectory(_chr(str_directory_name),0.000);



Previously, I was creating the folder right in the game folder, which is fine, until people start installing it on newer Windows machines. Then it seems to cause trouble.

Re: Creating a Directory [Re: Dooley] #476397
02/22/19 09:15
02/22/19 09:15
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
The point is that you need to ask to windows for the ProgramData folder path because it can change on different windows versions, especially if you want to give support for XP and Vista. It also happens that a user can install windows on any drive on his system, so it can easily not be C:. Hardcode a path out of your game installation folder is not a good practice and, as you experienced, ProgramFiles folder is locked for writting on newest systems.

Re: Creating a Directory [Re: txesmi] #476554
03/09/19 05:18
03/09/19 05:18
Joined: May 2005
Posts: 868
Chicago, IL
Dooley Offline OP
User
Dooley  Offline OP
User

Joined: May 2005
Posts: 868
Chicago, IL
Just thinking about the best way to deal with it. I think having a text file with the file directory would be a good way to do it. Then the user could edit it if their system is set up differently, or they want a custom location.

It would be nice to be able to handle that in-game, of course...

Re: Creating a Directory [Re: Dooley] #476556
03/09/19 18:57
03/09/19 18:57
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Just ask the OS where the paths are! SHGetKnownFolderPath is your friend, like txsemi has already said before!

Also, the last parameter to CreateDirectory is a pointer. Don't pass a float in there, just pass NULL.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1