// VistaEssentialsTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>
#include <rpcsal.h>
#include <gameux.h>
#include <strsafe.h>
#include <shlobj.h>

/*enum GAME_INSTALL_SCOPE
    {	GIS_NOT_INSTALLED	= 1,
	GIS_CURRENT_USER	= 2,
	GIS_ALL_USERS	= 3
    } 	GAME_INSTALL_SCOPE;*/

typedef HRESULT (__stdcall *InstallGamePtr)( bool use64BitBinaries,GAME_INSTALL_SCOPE InstallScope,WCHAR *strRegistryPath, WCHAR *langW );
typedef HRESULT (__stdcall *RemoveGamePtr)( GAME_INSTALL_SCOPE Scope, WCHAR* gameNameW);
typedef HRESULT (__stdcall *SetAllowLockdownMediaPtr)();
typedef HRESULT (__stdcall *RollbackAllowLockdownMediaPtr)();
typedef HRESULT (__stdcall *GetInstallPathPtr)(WCHAR* strRegistryPath, WCHAR* strInstallPathBuffer, DWORD bufferSize);

typedef HRESULT (__stdcall *CreateDefaultLanguageFilePtr)(WCHAR* strProductLanguage, WCHAR* strRegistryPath);
typedef HRESULT (__stdcall *DeleteUserDataPtr)(WCHAR* strRegistryPath);
typedef HRESULT (__stdcall *ShowReadmeFilePtr)(WCHAR* strRegistryPath, WCHAR* strFileName);

int _tmain(int argc, _TCHAR* argv[])
{
	WCHAR gameNameW[256] = L"Crysis";
	WCHAR langW[256] = L"";
	if (argc < 2)
		wcscpy_s(langW, sizeof(langW) / sizeof(langW[0]), L"English");
	else
		wcscpy_s(langW, sizeof(langW) / sizeof(langW[0]), argv[1]);
		//MultiByteToWideChar(CP_ACP, 0, argv[1], strlen(argv[1]), langW, sizeof(langW) / sizeof(langW[0]));

	HMODULE hDLL = LoadLibraryW( L"VistaEssentials.dll" );
	if (hDLL)
	{
		//SetAllowLockdownMediaPtr setFunc = (SetAllowLockdownMediaPtr)GetProcAddress(hDLL,"SetAllowLockdownMedia");
		//setFunc();
		//RollbackAllowLockdownMediaPtr rollbackFunc = (RollbackAllowLockdownMediaPtr)GetProcAddress(hDLL,"RollbackAllowLockdownMedia");
		//rollbackFunc();

		//WCHAR strInstallDir[2048];
		//GetInstallPathPtr installPathFunc = (GetInstallPathPtr)GetProcAddress(hDLL,"GetInstallPath");
		//installPathFunc(gameNameW, strInstallDir, sizeof(strInstallDir) / sizeof(strInstallDir[0]));

		//ShowReadmeFilePtr showReadmeFileFunc = (ShowReadmeFilePtr)GetProcAddress(hDLL,"ShowReadmeFile");
		//showReadmeFileFunc(L"Crysis", L"Readme (DE).txt");

		//CreateDefaultLanguageFilePtr createDefaultLanguageFileFunc = (CreateDefaultLanguageFilePtr)GetProcAddress(hDLL,"CreateDefaultLanguageFile");
		//createDefaultLanguageFileFunc(L"German", L"Crysis");

		//DeleteUserDataPtr deleteUserDataFunc = (DeleteUserDataPtr)GetProcAddress(hDLL,"DeleteUserData");
		//deleteUserDataFunc(L"Crysis");

		InstallGamePtr func = (InstallGamePtr)GetProcAddress(hDLL,"InstallGame");
		func( false,
			GIS_ALL_USERS,
			gameNameW,
			langW);

		/*RemoveGamePtr func2 = (RemoveGamePtr)GetProcAddress(hDLL,"RemoveGame");
		func2( GIS_ALL_USERS, gameNameW);
		FreeLibrary( hDLL );*/
	}
	else
	{
		MessageBoxW( NULL,L"VistaEssentials.dll Failed to Load",L"Error",MB_OK );
	}

	return 0;
}
