Hey guys,

for a number of reasons I want to put my game's savegame data into the user-specific %APPDATA% folder. I would like to use file_open_... commands for my savegames, rather than using game_save. Now I have several problems with that:

1. Unicode User Names
As Emre kindly explained here, it is possible to retrieve the complete %APPDATA% path using a shell32-function. However, as this example uses "SHGetFolderPathA", it only works as long as the Windows username does not contain any unicode characters. Using non-unicode usernames is rather common for territories like east-asia, russia and so on. There is a function "SHGetFolderPathW", which is supposed to return a unicode string, but I never managed to retrieve more than a single letter "C" from it.

Have a look at that here:
Code:
HRESULT WINAPI SHGetFolderPath(HWND hwndOwner, int nFolder,HANDLE hToken,DWORD dwFlags,char* pszPath);
#define PRAGMA_API SHGetFolderPath;Shell32.dll!SHGetFolderPathW
char temp_getfolder[260];
STRING* str_sv_dir="";

const int APPDATA = 0x001A;

function get_appdata_folder_startup()
{
	SHGetFolderPath(NULL,APPDATA,0,NULL,temp_getfolder);
	str_sv_dir=str_createw(temp_getfolder);
	error(str_sv_dir); // opens a dialog box containing the letter "C"
}



BTW, I also tried using "SHGetSpecialFolderPath" from windows.h with similar results.
My question is: How can I retrieve the correct appdata path as a unicode string? And once I have this - do Lite-C's "file_open..." commands actually work with such a string?

2. Creating a possibly non-existing folder
Now, at every start of my game, I want to make sure that the actual savegame folder and file exist to prevent Invalid Pointer errors. Therefore I refer to the manual, which states:

  • file_open_append (STRING* name);
    Opens a file for appending additional content at the end. If the file does not exist, it is created.
    The functions return a file handle - that is a unique number to identify the opened file. The file handle is used by other functions to access that file.

I expected that calling this function on a non-existent file in an also non-existent folder path would simply create both the file and the folder. But instead, the engine can't find the given file, throws
an "Invalid Pointer" error message, and the script execution stops.

I then tried "game_save". This command actually creates the required folder, which is good - except that I don't want to use Acknex' .SAV files at all, so this is no option for me.

I also tried using "CreateDirectory(char* lpPathName,long lpSecurityAttributes);" from windows.h with the String I got from "SHGetFolderPath" (see above), combined with "mygametitle". It did not work at all.

Is there any other method to create a folder from inside the engine?