#include <Windows.h>
#include <Shlobj.h>
#include <Userenv.h>

#include "winapi_utils.h"
#include "../common/allocators.h"



LPSTR GetLocalAppData()
{
	
	LPSTR szAppData = (LPSTR)salloc(MAX_PATH);

	if (szAppData)
		SHGetSpecialFolderPathA(NULL, szAppData, CSIDL_LOCAL_APPDATA, TRUE);

	return szAppData;
}

LPSTR GetUserHomeDirectory()
{
	LPSTR szHomeDirBuf = (LPSTR)malloc(MAX_PATH * sizeof(CHAR));

	HANDLE hToken = 0;
	OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken);

	DWORD BufSize = MAX_PATH;
	GetUserProfileDirectory(hToken, szHomeDirBuf, &BufSize);

	CloseHandle(hToken);
	return szHomeDirBuf;
}