/*
 * This code is released under the Microsoft Public License (MS-PL). See License.txt, below.
 */
#pragma once
#include "forwardDeclaration.h"
#include "enum.h"

#ifdef UNICODE
#define WFLAG "w, ccs=UTF-8"
#define AFLAG "a, ccs=UTF-8"
#else
#define WFLAG "w"
#define AFLAG "a"
#endif

#define OutputString(str, ...) \
{ \
	_tprintf(str, __VA_ARGS__); \
}
#ifdef _DEBUG
extern _TCHAR logBuffer[2048];
#define OutputErrorString(str, ...) \
{ \
	_stprintf(logBuffer, str, __VA_ARGS__); \
	OutputDebugString(logBuffer); \
}
#define OutputErrorLog(str, ...) \
{ \
	_stprintf(logBuffer, str, __VA_ARGS__); \
	OutputDebugString(logBuffer); \
}
#define OutputFileLog(str, ...) \
{ \
	_stprintf(logBuffer, str, __VA_ARGS__); \
	OutputDebugString(logBuffer); \
}
#else
#define OutputErrorString(str, ...) \
{ \
	_ftprintf(stderr, str, __VA_ARGS__); \
}
extern FILE* g_ErrorLog;
#define OutputErrorLog(str, ...) \
{ \
	_ftprintf(g_ErrorLog, str, __VA_ARGS__); \
}
#define OutputFileLog(str, ...) \
{ \
}
#endif

#define FcloseAndNull(fp) \
{ \
	if (fp) { \
		fclose(fp); \
		fp = NULL; \
	} \
}

#define FreeAndNull(buf) \
{ \
	if (buf) { \
		free(buf); \
		buf = NULL; \
	} \
}

FILE* CreateOrOpenFile(
	LPCTSTR pszSrcPath,
	LPTSTR pszSrcPathWithoutFileName,
	LPTSTR pszOutPath,
	LPTSTR pszFileNameWithoutPath,
	LPCTSTR pszExt,
	LPCTSTR pszMode,
	DWORD nFileCnt,
	DWORD nMaxFileNum
	);

BOOL CreateSeq(
	_TCHAR* path, 
	LPBYTE data, 
	DWORD dataSize,
	FILE* csvFp,
	PINTERNAL_MUSIC im
	);

BOOL CreateSSsq(
	_TCHAR* path, 
	LPBYTE data, 
	DWORD dataSize,
	FILE* csvFp,
	PINTERNAL_MUSIC im
	);

BOOL CreateKcet(
	_TCHAR* path, 
	LPBYTE data, 
	DWORD dataSize,
	FILE* csvFp,
	PINTERNAL_MUSIC im
	);

BOOL CreateSntp(
	_TCHAR* path, 
	LPBYTE data, 
	DWORD dataSize,
	FILE* csvFp,
	PINTERNAL_MUSIC im
	);

BOOL CreateSeqg(
	_TCHAR* path, 
	LPBYTE data, 
	FILE* csvFp,
	PINTERNAL_MUSIC im
	);

BOOL CreateSeqq(
	_TCHAR* path, 
	LPBYTE data, 
	FILE* csvFp,
	PINTERNAL_MUSIC im
	);

BOOL CreateSqv(
	_TCHAR* path, 
	LPBYTE data, 
	FILE* csvFp,
	PINTERNAL_MUSIC im
	);

BOOL CreateSseq(
	_TCHAR* path, 
	LPBYTE data, 
	FILE* csvFp,
	PINTERNAL_MUSIC im
	);

BOOL CreateVh(
	_TCHAR* path, 
	LPBYTE data, 
	DWORD dataSize,
	FILE* csvFp,
	PINTERNAL_MUSIC im,
	PVH vh,
	LPWORD vagSizeTbl
	);

BOOL CreateVhForBastard(
	_TCHAR* path,
	LPBYTE data,
	FILE* csvFp,
	PINTERNAL_MUSIC im,
	PVH vh,
	LPWORD vagSizeTbl
	);

BOOL CreateSShd(
	_TCHAR* path, 
	LPBYTE data, 
	DWORD dataSize, 
	LPDWORD vbSize,
	FILE* csvFp,
	PINTERNAL_MUSIC im
	);

BOOL CreateInst(
	_TCHAR* path, 
	LPBYTE data, 
	FILE* csvFp,
	PINTERNAL_MUSIC im
	);

BOOL CreateVbForVh(
	_TCHAR* path,
	LPBYTE data,
	DWORD dataSize,
	BOOL isVbHead0byte,
	SEARCH_TYPE searchType,
	FILE* csvFp,
	PINTERNAL_MUSIC im,
	PVH vh,
	LPWORD vagSizeTbl
	);

BOOL CreateVbForSShd(
	_TCHAR* path, 
	LPBYTE data, 
	DWORD dataSize, 
	LPDWORD vbSize, 
	BOOL isVbHead0byte,
	FILE* csvFp,
	PINTERNAL_MUSIC im
	);

BOOL CreateVbForInst(
	_TCHAR* path, 
	LPBYTE data, 
	FILE* csvFp,
	PINTERNAL_MUSIC im
	);

VOID OutputLastErrorNumAndString(
	LPCTSTR pszFuncName,
	LONG lLineNum
	);
