<commit_before>// in_tta.cpp : Defines the initialization routines for the DLL.
//
/* Description:	 TTA input plug-in for upper Winamp 2.91
 *               with MediaLibrary Extension version
 * Developed by: <NAME> <<EMAIL>>
 *               <NAME> <<EMAIL>>
 *               (MediaLibrary Extension Yamagata Fumihiro <<EMAIL>> )
 *
 * Copyright (c) 2005 <NAME>. All rights reserved.
 *
 */

 /*
 The ttaplugin-winamp project.
 Copyright (C) 2005-2016 <NAME>

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or any later version.

 This library 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
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "in_tta.h"

#include <Shlwapi.h>
#include <stdlib.h>
#include <type_traits>

#include <Winamp/in2.h>
#include <Agave/Language/api_language.h>

#include <taglib/tag.h>
#include <taglib/trueaudiofile.h>
#include <taglib/tstring.h>

#include "AlbumArt.h"
#include "DecodeFile.h"
#include "MediaLibrary.h"

#include "..\common\VersionNo.h"
#include "resource.h"

 // for playing static variables
static __declspec(align(16)) CDecodeFile playing_ttafile;

static HANDLE decoder_handle = INVALID_HANDLE_VALUE;
static DWORD WINAPI __stdcall DecoderThread(void *p);
static volatile int killDecoderThread = 0;

// for transcoding static variable
static __declspec(align(16)) CDecodeFile transcode_ttafile;

// for MetaData static variables
CMediaLibrary m_ReadTag;
CMediaLibrary m_WriteTag;

void config(HWND hwndParent);
void about(HWND hwndParent);
void init();
void quit();
void getfileinfo(const wchar_t *file, wchar_t *title, int *length_in_ms);
int  infodlg(const wchar_t *file, HWND hwndParent);
int  isourfile(const wchar_t *fn);
int  play(const wchar_t *fn);
void pause();
void unpause();
int  ispaused();
void stop();
int  getlength();
int  getoutputtime();
void setoutputtime(int time_in_ms);
void setvolume(int volume);
void setpan(int pan);
void eq_set(int on, char data[10], int preamp);

In_Module mod = {
	IN_VER,
	"TTA Audio Decoder " PLUGIN_VERSION,
	NULL,		// hMainWindow
	NULL,		// hDllInstance
	"TTA\0TTA Audio File (*.TTA)\0",
	1,			// is_seekable
	1,			// uses output
	config,
	about,
	init,
	quit,
	getfileinfo,
	infodlg,
	isourfile,
	play,
	pause,
	unpause,
	ispaused,
	stop,
	getlength,
	getoutputtime,
	setoutputtime,
	setvolume,
	setpan,
	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, // vis stuff
	NULL, NULL,	// dsp
	eq_set,
	NULL,		// setinfo
	NULL		// out_mod
};

static void tta_error_message(int error, const wchar_t *filename)
{
	wchar_t message[1024];

	std::wstring name(filename);

	switch (error)
	{
	case TTA_OPEN_ERROR:
		wsprintf(message, L"Can't open file:\n%ls", name.c_str());
		break;
	case TTA_FORMAT_ERROR:
		wsprintf(message, L"Unknown TTA format version:\n%ls", name.c_str());
		break;
	case TTA_NOT_SUPPORTED:
		wsprintf(message, L"Not supported file format:\n%ls", name.c_str());
		break;
	case TTA_FILE_ERROR:
		wsprintf(message, L"File is corrupted:\n%ls", name.c_str());
		break;
	case TTA_READ_ERROR:
		wsprintf(message, L"Can't read from file:\n%ls", name.c_str());
		break;
	case TTA_WRITE_ERROR:
		wsprintf(message, L"Can't write to file:\n%ls", name.c_str());
		break;
	case TTA_MEMORY_ERROR:
		wsprintf(message, L"Insufficient memory available");
		break;
	case TTA_SEEK_ERROR:
		wsprintf(message, L"file seek error");
		break;
	case TTA_PASSWORD_ERROR:
		wsprintf(message, L"password protected file");
		break;
	default:
		wsprintf(message, L"Unknown TTA decoder error");
		break;
	}

	MessageBox(mod.hMainWindow, message, L"TTA Decoder Error",
		MB_OK | MB_ICONERROR | MB_SYSTEMMODAL);

}

static BOOL CALLBACK about_dialog(HWND dialog, UINT message, WPARAM wparam, LPARAM lparam)
{
	switch (message)
	{
	case WM_INITDIALOG:
		SetDlgItemText(dialog, IDC_PLUGIN_VERSION,
			L"Winamp plug-in version " PLUGIN_VERSION "\nbased on "
			LIBTTA_VERSION "\n" PROJECT_URL);
		SetDlgItemText(dialog, IDC_PLUGIN_CREADIT,
			ORIGINAL_CREADIT01 ORIGINAL_CREADIT02 ORIGINAL_CREADIT03
			CREADIT01 CREADIT02);
		return TRUE;
	case WM_COMMAND:
		switch (LOWORD(wparam))
		{
		case IDOK:
		case IDCANCEL:
			EndDialog(dialog, wparam);
			return TRUE;
		}
		break;
	}
	return FALSE;
}

void config(HWND hwndParent)
{
	DialogBox(mod.hDllInstance, MAKEINTRESOURCE(IDD_ABOUT),
		hwndParent, about_dialog);
}

void about(HWND hwndParent)
{
	DialogBox(mod.hDllInstance, MAKEINTRESOURCE(IDD_ABOUT),
		hwndParent, about_dialog);<commit_msg>Change static string from char type to wchar_t type and use StringCbPrintf function to make error message<commit_after>// in_tta.cpp : Defines the initialization routines for the DLL.
//
/* Description:	 TTA input plug-in for upper Winamp 2.91
 *               with MediaLibrary Extension version
 * Developed by: <NAME> <<EMAIL>>
 *               <NAME> <<EMAIL>>
 *               (MediaLibrary Extension Yamagata Fumihiro <<EMAIL>> )
 *
 * Copyright (c) 2005 <NAME>. All rights reserved.
 *
 */

 /*
 The ttaplugin-winamp project.
 Copyright (C) 2005-2016 <NAME>

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or any later version.

 This library 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
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "in_tta.h"

#include <Shlwapi.h>
#include <stdlib.h>
#include <type_traits>
#include <strsafe.h>

#include <Winamp/in2.h>
#include <Agave/Language/api_language.h>

#include <taglib/tag.h>
#include <taglib/trueaudiofile.h>
#include <taglib/tstring.h>

#include "AlbumArt.h"
#include "DecodeFile.h"
#include "MediaLibrary.h"

#include "..\common\VersionNo.h"
#include "resource.h"

const static int MAX_MESSAGE_LENGTH = 1024;

// for playing static variables
static __declspec(align(16)) CDecodeFile playing_ttafile;

static HANDLE decoder_handle = INVALID_HANDLE_VALUE;
static DWORD WINAPI __stdcall DecoderThread(void *p);
static volatile int killDecoderThread = 0;

// for transcoding static variable
static __declspec(align(16)) CDecodeFile transcode_ttafile;

// for MetaData static variables
CMediaLibrary m_ReadTag;
CMediaLibrary m_WriteTag;

void config(HWND hwndParent);
void about(HWND hwndParent);
void init();
void quit();
void getfileinfo(const wchar_t *file, wchar_t *title, int *length_in_ms);
int  infodlg(const wchar_t *file, HWND hwndParent);
int  isourfile(const wchar_t *fn);
int  play(const wchar_t *fn);
void pause();
void unpause();
int  ispaused();
void stop();
int  getlength();
int  getoutputtime();
void setoutputtime(int time_in_ms);
void setvolume(int volume);
void setpan(int pan);
void eq_set(int on, char data[10], int preamp);

In_Module mod = {
	IN_VER,
	"TTA Audio Decoder " PLUGIN_VERSION_CHAR,
	NULL,		// hMainWindow
	NULL,		// hDllInstance
	"TTA\0TTA Audio File (*.TTA)\0",
	1,			// is_seekable
	1,			// uses output
	config,
	about,
	init,
	quit,
	getfileinfo,
	infodlg,
	isourfile,
	play,
	pause,
	unpause,
	ispaused,
	stop,
	getlength,
	getoutputtime,
	setoutputtime,
	setvolume,
	setpan,
	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, // vis stuff
	NULL, NULL,	// dsp
	eq_set,
	NULL,		// setinfo
	NULL		// out_mod
};

static void tta_error_message(int error, const wchar_t *filename)
{
	wchar_t message[MAX_MESSAGE_LENGTH];

	std::wstring name(filename);

	switch (error)
	{
	case TTA_OPEN_ERROR:
		StringCbPrintf(message, MAX_MESSAGE_LENGTH, L"Can't open file:\n%ls", name.c_str());
		break;
	case TTA_FORMAT_ERROR:
		StringCbPrintf(message, MAX_MESSAGE_LENGTH, L"Unknown TTA format version:\n%ls", name.c_str());
		break;
	case TTA_NOT_SUPPORTED:
		StringCbPrintf(message, MAX_MESSAGE_LENGTH, L"Not supported file format:\n%ls", name.c_str());
		break;
	case TTA_FILE_ERROR:
		StringCbPrintf(message, MAX_MESSAGE_LENGTH, L"File is corrupted:\n%ls", name.c_str());
		break;
	case TTA_READ_ERROR:
		StringCbPrintf(message, MAX_MESSAGE_LENGTH, L"Can't read from file:\n%ls", name.c_str());
		break;
	case TTA_WRITE_ERROR:
		StringCbPrintf(message, MAX_MESSAGE_LENGTH, L"Can't write to file:\n%ls", name.c_str());
		break;
	case TTA_MEMORY_ERROR:
		StringCbPrintf(message, MAX_MESSAGE_LENGTH, L"Insufficient memory available");
		break;
	case TTA_SEEK_ERROR:
		StringCbPrintf(message, MAX_MESSAGE_LENGTH, L"file seek error");
		break;
	case TTA_PASSWORD_ERROR:
		StringCbPrintf(message, MAX_MESSAGE_LENGTH, L"password protected file");
		break;
	default:
		StringCbPrintf(message, MAX_MESSAGE_LENGTH, L"Unknown TTA decoder error");
		break;
	}

	MessageBox(mod.hMainWindow, message, L"TTA Decoder Error",
		MB_OK | MB_ICONERROR | MB_SYSTEMMODAL);

}

static BOOL CALLBACK about_dialog(HWND dialog, UINT message, WPARAM wparam, LPARAM lparam)
{
	switch (message)
	{
	case WM_INITDIALOG:
		SetDlgItemText(dialog, IDC_PLUGIN_VERSION, 
			IN_TTA_PLUGIN_VERSION_CREADIT);
		SetDlgItemText(dialog, IDC_PLUGIN_CREADIT,
			ORIGINAL_CREADIT01 ORIGINAL_CREADIT02 ORIGINAL_CREADIT03
			CREADIT01 CREADIT02);
		return TRUE;
	case WM_COMMAND:
		switch (LOWORD(wparam))
		{
		case IDOK:
		case IDCANCEL:
			EndDialog(dialog, wparam);
			return TRUE;
		}
		break;
	}
	return FALSE;
}

void config(HWND hwndParent)
{
	DialogBox(mod.hDllInstance, MAKEINTRESOURCE(IDD_ABOUT),
		hwndParent, about_dialog);
}

void about(HWND hwndParent)
{
	DialogBox(mod.hDllInstance, MAKEINTRESOURCE(IDD_ABOUT),
		hwndParent, about_dialog);
{'fraction_non_alphanumeric': 0.10398832684824903, 'fraction_numerical': 0.010505836575875487, 'mean_word_length': 4.727576601671309, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1811371', 'n_tokens_mistral': 3822, 'n_tokens_neox': 3646, 'n_words': 1038}