|
Creating a Directory
#476342
02/19/19 19:11
02/19/19 19:11
|
Joined: May 2005
Posts: 868 Chicago, IL
Dooley
OP
User
|
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: 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
OP
User
|
OP
User
Joined: May 2005
Posts: 868
Chicago, IL
|
Ah ... got it!
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: txesmi]
#476386
02/21/19 22:04
02/21/19 22:04
|
Joined: Jul 2007
Posts: 619 Turkey, Izmir
Emre
User
|
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:
#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
///////////////////////////////
#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
OP
User
|
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...
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]
#476556
03/09/19 18:57
03/09/19 18:57
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
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
|
|
|
|