/*
	N-Rage`s Dinput8 Plugin
    (C) 2002, 2006  Norbert Wladyka

	Author`s Email: norbert.wladyka@chello.at
	Website: http://go.to/nrage


    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#ifndef _FILEACCESS_H_
#define _FILEACCESS_H_

#include "NRagePluginV2.h"
#include "Version.h"
#include <string>
using std::string;

bool GetDirectory( LPTSTR pszDirectory, WORD wDirID );
bool CheckFileExists( LPCTSTR FileName );
void GetAbsoluteFileName( LPTSTR szAbsolute, LPCTSTR szFileName, const WORD wDirID );

BOOL SendFilestoList( HWND hDlgItem, WORD wType );
bool StoreConfigToINI();
bool LoadConfigFromINI();
LANGID GetLanguageFromINI();

bool LoadProfileFile( LPCTSTR pszFileName, int iController, LPTSTR pszGameDevice, LPBYTE bGameDeviceNr );
bool LoadShortcutsFile( LPCTSTR pszFileName );
void FormatProfileBlock( FILE * fFile, const int iController );
void FormatShortcutsBlock( FILE * fFile, bool bIsINI );
bool BrowseFolders( HWND hwndParent, LPTSTR pszHeader, LPTSTR pszDirectory );
bool BrowseFile( HWND hDlg, LPTSTR pszFileName, DWORD dwType, bool fSave );
bool ReadMemPakFile( LPTSTR pszMemPakFile, BYTE *aMemPak, bool fCreate );
bool WriteMemPakFile( LPTSTR pszMemPakFile, BYTE *aMemPak, bool fCreate );
bool LoadProfileFromResource( int indexController, bool bIsInterface );
bool LoadShortcutsFromResource( bool bIsInterface );
inline void GUIDtoStringA( char * szGUIDbuf, const GUID guid );
inline bool StringtoGUIDA( LPGUID guid, const char * szGUIDbuf );
unsigned long djbHash(const char *str);

#ifdef _UNICODE
#define TCHAR_TO_CHAR(x,y,z)	wcstombs(x,y,z)
#define CHAR_TO_TCHAR(x,y,z)	mbstowcs(x,y,z)
#else
#define TCHAR_TO_CHAR(x,y,z)	strncpy(x,y,z)
#define CHAR_TO_TCHAR(x,y,z)	strncpy(x,y,z)
#endif

#define STRING_DEF_MEMPAKFILE	_T("MemPaks")
#define STRING_DEF_GBROMFILE	_T("GBxRoms")
#define STRING_DEF_GBROMSAVE	_T("GBxSaves")

#define STRING_INI_HEADER		"# Generated by NRage input plugin V2 version " VER_FILE_VERSION_STR "\n"
// We use these names for loading from INI files and NRage config files
#define STRING_INI_GENERAL		"General"
#define STRING_INI_CONTROLLER	"Controller"
#define STRING_INI_FOLDERS		"Folders"
#define STRING_INI_BROWSER		"lastBrowserDir"
#define STRING_INI_CONTROLS		"Controls"
#define STRING_INI_SHORTCUTS	"Shortcuts"
#define STRING_INI_MODIFIERS	"Modifiers"

#define STRING_INI_LANGUAGE		"Language"
#define STRING_INI_SHOWMESSAGES	"ShowMessages"

#define STRING_INI_BRPROFILE	"Profile"
#define STRING_INI_BRNOTE		"Note"
#define STRING_INI_BRMEMPAK		"Mempak"
#define STRING_INI_BRGBROM		"GBxRom"
#define STRING_INI_BRGBSAVE		"GBxSave"
// #define STRING_INI_BRSHORTCUTS	STRING_INI_SHORTCUTS

#define STRING_INI_PLUGGED		"Plugged"
#define STRING_INI_XINPUT		"xInput"
#define STRING_INI_RAWDATA		"RawData"
#define STRING_INI_PAKTYPE		"PakType"
#define STRING_INI_REALN64RANGE	"RealN64Range"
#define STRING_INI_RAPIDFIREENABLED	"RapidFireEnabled"
#define STRING_INI_RAPIDFIRERATE	"RapidFireRate"
#define STRING_INI_STICKRANGE	"StickRange"
#define STRING_INI_MOUSEMOVEX	"MouseMoveX"
#define STRING_INI_MOUSEMOVEY	"MouseMoveY"
#define STRING_INI_AXISSET		"AxisSet"
#define STRING_INI_KEYABSOLUTEX	"KeyAbsoluteX"
#define STRING_INI_KEYABSOLUTEY	"KeyAbsoluteY"
#define STRING_INI_PADDEADZONE	"PadDeadZone"
#define STRING_INI_MOUSESENSX	"MouseSensitivityX"
#define STRING_INI_MOUSESENSY	"MouseSensitivityY"
#define STRING_INI_RUMBLETYPE	"RumbleType"
#define STRING_INI_RUMBLESTRENGTH	"RumbleStrength"
#define STRING_INI_VISUALRUMBLE	"VisualRumble"
#define STRING_INI_FFDEVICEGUID	"FFDeviceGUID"
#define STRING_INI_MEMPAKFILE	"MemPakFile"
#define STRING_INI_GBROMFILE	"GBRomFile"
#define STRING_INI_GBROMSAVE	"GBRomSave"

#define STRING_INI_DINPUTGUID	"DInputGUID"
#define STRING_INI_BUTTON		"Button"
#define STRING_INI_MODIFIER		"Modifier"

// The following are not found in INI files; only profile and shortcuts files
#define STRING_PROFILEVERSION22 "Controller Profile 2.2"
#define STRING_PROFILEVERSION	STRING_PROFILEVERSION22

#define STRING_INI_FFDEVICENAME	"FFDeviceName"
#define STRING_INI_FFDEVICENR	"FFDeviceNr"
#define STRING_INI_DINPUTNAME	"DInputName"
#define STRING_INI_DINPUTNR		"DInputNr"


// the following are hashes for the string values above

// version strings, including the @ in front
#define CHK_PROFILEVERSION20 2278962538
#define CHK_PROFILEVERSION21 2278962539
#define CHK_PROFILEVERSION22 2278962540

// categories
#define CHK_GENERAL			63249731
#define CHK_FOLDERS			3455681620
#define CHK_LASTBROWSERDIR	2659654652
#define CHK_CONTROLLER_1	3910856026
#define CHK_CONTROLLER_2	3910856027
#define CHK_CONTROLLER_3	3910856028
#define CHK_CONTROLLER_4	3910856029
#define CHK_CONTROLS		3459743001
#define CHK_SHORTCUTS		2945387732
#define CHK_MODIFIERS		95935975

// assignments (to the left of the '=' sign)
#define CHK_LANGUAGE		3857633481
#define CHK_SHOWMESSAGES	638097246

#define CHK_MEMPAK			3230166560
#define CHK_GBXROM			2992194388
#define CHK_GBXSAVE			4253155349

#define CHK_PROFILE			3606499382
#define CHK_NOTE			2089365563

#define CHK_PLUGGED			3378836077
#define CHK_XINPUT			3665436173
#define CHK_RAWDATA			1238573385
#define CHK_PAKTYPE			2936974691
#define CHK_REALN64RANGE	1279831790
#define CHK_RAPIDFIREENABLED	1491009894
#define CHK_RAPIDFIRERATE	1576165031
#define CHK_STICKRANGE		4145501776
#define CHK_MOUSEMOVEX		1825694205
#define CHK_MOUSEMOVEY		1825694206
#define CHK_AXISSET			1642523718
#define CHK_KEYABSOLUTEX	958566277
#define CHK_KEYABSOLUTEY	958566278
#define CHK_PADDEADZONE		2913910084
#define CHK_MOUSESENSITIVITYX	1513071697
#define CHK_MOUSESENSITIVITYY	1513071698
#define CHK_RUMBLETYPE		3440038446
#define CHK_RUMBLESTRENGTH	3038086267
#define CHK_VISUALRUMBLE	1795686016
#define CHK_FFDEVICEGUID	2645316746
#define CHK_MEMPAKFILE		2373591360
#define CHK_GBROMFILE		2409678172
#define CHK_GBROMSAVE		2410136971

#define CHK_DINPUTGUID		1452894242
#define CHK_BUTTON			2818908353
#define CHK_MODIFIER		4037573396


// The following are not found in INI files; only profile and shortcuts files
#define CHK_FFDEVICENAME	2645546658
#define CHK_FFDEVICENR		2037510273
#define CHK_DINPUTNAME		1453124154
#define CHK_DINPUTNR		3965009433


// If any of the following values conflict with djbHash return values (such as a blank string), there will be problems!

// nothing
#define PL_NOHIT				0
	// [Category]
#define PL_CATEGORY				1
	// @STRING_PROFILEVERSION
#define PL_VERSIONSTRING		10

		// resets the static vars in ProcessKey
#define PL_RESET			200


#define DIRECTORY_MEMPAK		0
#define DIRECTORY_GBROMS		1
#define DIRECTORY_GBSAVES		2
#define DIRECTORY_CONFIG		252
#define DIRECTORY_LOG			253
#define DIRECTORY_DLL			254
#define DIRECTORY_APPLICATION	255
#define DIRECTORY_INVALID		256


#define FILIST_MEM			1
#define FILIST_TRANSFER		2

#define BF_LOAD				false
#define BF_SAVE				true

#define	BF_MEMPAK			0
#define	BF_GBROM			1
#define	BF_GBSAVE			2
#define	BF_PROFILE			3
#define BF_NOTE				4
#define BF_SHORTCUTS		5

	// 32 hex characters, 4 hyphens, 2 end braces
#define GUID_STRINGLENGTH	32+4+2

#endif // #ifndef _FILEACCESS_H_
