Example #1
0
//UDPで送信を行う
//戻り値:
// TRUE(成功)、FALSE(失敗)
//引数:
// enableFlag		[IN]TRUE(開始)、FALSE(停止)
BOOL CMediaPortal_BonMain::SendUDP(
	BOOL enableFlag
	)
{
	this->udpSendList.clear();
	if( enableFlag == TRUE ){
		wstring appIniPath = L"";
		GetModuleIniPath(appIniPath);

		int udpCount = GetPrivateProfileInt( L"SET_UDP", L"Count", 1, appIniPath.c_str() );
		for( int i = 0; i < udpCount; i++ ){
			NW_SEND_INFO item;

			CString key = L"";
			key.Format(L"IP%d",i);
			item.ip = GetPrivateProfileInt( L"SET_UDP", key.GetBuffer(0), 2130706433, appIniPath.c_str() );
			key.Format(L"Port%d",i);
			item.port = GetPrivateProfileInt( L"SET_UDP", key.GetBuffer(0), 3456, appIniPath.c_str() );
			Format(item.ipString, L"%d.%d.%d.%d",
				(item.ip&0xFF000000)>>24,
				(item.ip&0x00FF0000)>>16,
				(item.ip&0x0000FF00)>>8,
				(item.ip&0x000000FF) );
			key.Format(L"BroadCast%d",i);
			item.broadcastFlag = GetPrivateProfileInt( L"SET_UDP", key.GetBuffer(0), 0, appIniPath.c_str() );

			udpSendList.push_back(item);
		}
	}
Example #2
0
static void StartDebugLog()
{
	wstring iniPath;
	GetModuleIniPath(iniPath);
	if( GetPrivateProfileInt(L"SET", L"SaveDebugLog", 0, iniPath.c_str()) != 0 ){
		wstring logFolder;
		GetModuleFolderPath(logFolder);
		for( int i = 0; i < 100; i++ ){
			//パスに添え字をつけて書き込み可能な最初のものに記録する
			WCHAR logFileName[64];
			wsprintf(logFileName, L"\\EpgDataCap_Bon_DebugLog-%d.txt", i);
			g_hDebugLog = CreateFile((logFolder + logFileName).c_str(), FILE_APPEND_DATA, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
			if( g_hDebugLog != INVALID_HANDLE_VALUE ){
				if( GetLastError() == ERROR_SUCCESS ){
					DWORD dwWritten;
					WriteFile(g_hDebugLog, "\xFF\xFE", sizeof(char) * 2, &dwWritten, NULL);
				}else{
					LARGE_INTEGER liPos = {};
					SetFilePointerEx(g_hDebugLog, liPos, NULL, FILE_END);
				}
				InitializeCriticalSection(&g_debugLogLock);
				g_saveDebugLog = true;
				OutputDebugString(L"****** LOG START ******\r\n");
				break;
			}
		}
	}
}
Example #3
0
void CTunerBankCtrl::ReloadSetting()
{
	//モジュールini以外のパラメータは必要なときにその場で取得する
	wstring iniPath;
	GetModuleIniPath(iniPath);
	//録画開始のちょうどn分前だと起動と他チューナ録画開始が若干重なりやすくなるので僅かにずらす
	this->recWakeTime = ((__int64)GetPrivateProfileInt(L"SET", L"RecAppWakeTime", 2, iniPath.c_str()) * 60 - 3) * I64_1SEC;
	this->recWakeTime = max(this->recWakeTime, READY_MARGIN * I64_1SEC);
	this->recMinWake = GetPrivateProfileInt(L"SET", L"RecMinWake", 1, iniPath.c_str()) != 0;
	this->recView = GetPrivateProfileInt(L"SET", L"RecView", 1, iniPath.c_str()) != 0;
	this->recNW = GetPrivateProfileInt(L"SET", L"RecNW", 0, iniPath.c_str()) != 0;
	this->backPriority = GetPrivateProfileInt(L"SET", L"BackPriority", 1, iniPath.c_str()) != 0;
	this->saveProgramInfo = GetPrivateProfileInt(L"SET", L"PgInfoLog", 0, iniPath.c_str()) != 0;
	this->saveErrLog = GetPrivateProfileInt(L"SET", L"DropLog", 0, iniPath.c_str()) != 0;
	this->recOverWrite = GetPrivateProfileInt(L"SET", L"RecOverWrite", 0, iniPath.c_str()) != 0;
	int pr = GetPrivateProfileInt(L"SET", L"ProcessPriority", 3, iniPath.c_str());
	this->processPriority =
		pr == 0 ? REALTIME_PRIORITY_CLASS :
		pr == 1 ? HIGH_PRIORITY_CLASS :
		pr == 2 ? ABOVE_NORMAL_PRIORITY_CLASS :
		pr == 3 ? NORMAL_PRIORITY_CLASS :
		pr == 4 ? BELOW_NORMAL_PRIORITY_CLASS : IDLE_PRIORITY_CLASS;
	this->keepDisk = GetPrivateProfileInt(L"SET", L"KeepDisk", 1, iniPath.c_str()) != 0;
	this->recNameNoChkYen = GetPrivateProfileInt(L"SET", L"NoChkYen", 0, iniPath.c_str()) != 0;
	this->recNamePlugInFileName.clear();
	if( GetPrivateProfileInt(L"SET", L"RecNamePlugIn", 0, iniPath.c_str()) != 0 ){
		this->recNamePlugInFileName = GetPrivateProfileToString(L"SET", L"RecNamePlugInFile", L"RecName_Macro.dll", iniPath.c_str());
	}
}
Example #4
0
CEpgDataCap_BonDlg::CEpgDataCap_BonDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(CEpgDataCap_BonDlg::IDD, pParent)
	, log(_T(""))
	, statusLog(_T(""))
	, pgInfo(_T(""))
{
	m_hIcon = (HICON)LoadImage( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDI_ICON_BLUE ), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	m_hIcon2 = (HICON)LoadImage( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDI_ICON_BLUE ), IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR);
	iconRed = (HICON)LoadImage( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDI_ICON_RED ), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	iconBlue = (HICON)LoadImage( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDI_ICON_BLUE ), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	iconGreen = (HICON)LoadImage( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDI_ICON_GREEN ), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	iconGray = (HICON)LoadImage( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDI_ICON_GRAY ), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);

	wstring strPath = L"";
	GetModuleIniPath(strPath);
	this->moduleIniPath = strPath.c_str();
	GetCommonIniPath(strPath);
	this->commonIniPath = strPath.c_str();
	GetEpgTimerSrvIniPath(strPath);
	this->timerSrvIniPath = strPath.c_str();

	this->initONID = GetPrivateProfileInt( L"Set", L"LastONID", -1, this->moduleIniPath );
	this->initTSID = GetPrivateProfileInt( L"Set", L"LastTSID", -1, this->moduleIniPath );
	this->initSID = GetPrivateProfileInt( L"Set", L"LastSID", -1, this->moduleIniPath );
	WCHAR buff[512]=L"";
	GetPrivateProfileString( L"Set", L"LastBon", L"", buff, 512, this->moduleIniPath );
	this->iniBonDriver = buff;

	iniView = FALSE;
	iniNetwork = TRUE;
	iniMin = FALSE;
	this->iniUDP = FALSE;
	this->iniTCP = FALSE;
	
	this->minTask = GetPrivateProfileInt( L"Set", L"MinTask", 0, this->moduleIniPath );
	this->openLastCh = GetPrivateProfileInt( L"Set", L"OpenLast", 1, this->moduleIniPath );
	if( this->openLastCh == 0 ){
		if( GetPrivateProfileInt( L"Set", L"OpenFix", 0, this->moduleIniPath ) == 1){
			this->initONID = GetPrivateProfileInt( L"Set", L"FixONID", -1, this->moduleIniPath );
			this->initTSID = GetPrivateProfileInt( L"Set", L"FixTSID", -1, this->moduleIniPath );
			this->initSID = GetPrivateProfileInt( L"Set", L"FixSID", -1, this->moduleIniPath );
			GetPrivateProfileString( L"Set", L"FixBon", L"", buff, 512, this->moduleIniPath );
			this->iniBonDriver = buff;
		}else{
			this->initONID = -1;
			this->initTSID = -1;
			this->initSID = -1;
			this->iniBonDriver = L"";
		}
	}
	this->initOpenWait = 0;
	this->initChgWait = 0;
}
Example #5
0
CEpgDataCap_BonDlg::CEpgDataCap_BonDlg()
	: m_hWnd(NULL)
	, m_hKeyboardHook(NULL)
{
	m_hIcon = (HICON)LoadImage( GetModuleHandle(NULL), MAKEINTRESOURCE( IDI_ICON_BLUE ), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	m_hIcon2 = (HICON)LoadImage( GetModuleHandle(NULL), MAKEINTRESOURCE( IDI_ICON_BLUE ), IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR);
	iconRed = (HICON)LoadImage( GetModuleHandle(NULL), MAKEINTRESOURCE( IDI_ICON_RED ), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	iconBlue = (HICON)LoadImage( GetModuleHandle(NULL), MAKEINTRESOURCE( IDI_ICON_BLUE ), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	iconGreen = (HICON)LoadImage( GetModuleHandle(NULL), MAKEINTRESOURCE( IDI_ICON_GREEN ), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	iconGray = (HICON)LoadImage( GetModuleHandle(NULL), MAKEINTRESOURCE( IDI_ICON_GRAY ), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);

	taskbarCreated = RegisterWindowMessage(L"TaskbarCreated");

	wstring strPath = L"";
	GetModuleIniPath(strPath);
	this->moduleIniPath = strPath.c_str();
	GetCommonIniPath(strPath);
	this->commonIniPath = strPath.c_str();
	GetEpgTimerSrvIniPath(strPath);
	this->timerSrvIniPath = strPath.c_str();

	this->initONID = GetPrivateProfileInt( L"Set", L"LastONID", -1, this->moduleIniPath.c_str() );
	this->initTSID = GetPrivateProfileInt( L"Set", L"LastTSID", -1, this->moduleIniPath.c_str() );
	this->initSID = GetPrivateProfileInt( L"Set", L"LastSID", -1, this->moduleIniPath.c_str() );
	WCHAR buff[512]=L"";
	GetPrivateProfileString( L"Set", L"LastBon", L"", buff, 512, this->moduleIniPath.c_str() );
	this->iniBonDriver = buff;

	iniView = FALSE;
	iniNetwork = TRUE;
	iniMin = FALSE;
	this->iniUDP = FALSE;
	this->iniTCP = FALSE;
	
	this->minTask = GetPrivateProfileInt( L"Set", L"MinTask", 0, this->moduleIniPath.c_str() );
	this->openLastCh = GetPrivateProfileInt( L"Set", L"OpenLast", 1, this->moduleIniPath.c_str() );
	if( this->openLastCh == 0 ){
		if( GetPrivateProfileInt( L"Set", L"OpenFix", 0, this->moduleIniPath.c_str() ) == 1){
			this->initONID = GetPrivateProfileInt( L"Set", L"FixONID", -1, this->moduleIniPath.c_str() );
			this->initTSID = GetPrivateProfileInt( L"Set", L"FixTSID", -1, this->moduleIniPath.c_str() );
			this->initSID = GetPrivateProfileInt( L"Set", L"FixSID", -1, this->moduleIniPath.c_str() );
			GetPrivateProfileString( L"Set", L"FixBon", L"", buff, 512, this->moduleIniPath.c_str() );
			this->iniBonDriver = buff;
		}else{
			this->initONID = -1;
			this->initTSID = -1;
			this->initSID = -1;
			this->iniBonDriver = L"";
		}
	}
	this->initOpenWait = 0;
	this->initChgWait = 0;
}
Example #6
0
BOOL CParseChText4::SaveUdpMp()
{
	
	wstring appIniPath = L"";
	GetModuleIniPath(appIniPath);

	wstring ipString;
	DWORD ip;
	DWORD port;
	
	// MediaPortal TV Serverのデータベースへ登録
	if (this->dbCtrl.Connect(&this->mysql, MYSQL_HOST, MYSQL_USER, MYSQL_PASSWD, MYSQL_DB) != 0) {
		return FALSE;
	}

	this->results = NULL;
	CString sql = L"";
	wstring wsql = L"";

	this->dbCtrl.Begin(&this->mysql);

	map<CString, int> lockTable;
	lockTable[L"tuningdetail"] = 2;
	lockTable[L"groupmap"] = 2;
	if (this->dbCtrl.LockTable(&this->mysql, lockTable) != 0) goto ESC;

	ip = GetPrivateProfileInt(L"SET_UDP", L"IP0", 2130706433, appIniPath.c_str());
	Format(ipString, L"%d.%d.%d.%d", 
	(ip&0xFF000000)>>24, 
	(ip&0x00FF0000)>>16, 
	(ip&0x0000FF00)>>8, 
	(ip&0x000000FF) );
	port = GetPrivateProfileInt( L"SET_UDP", L"Port0", 3456, appIniPath.c_str() );

	sql.Format(_T("UPDATE tuningdetail LEFT JOIN groupmap ON tuningdetail.idChannel = groupmap.idChannel SET tuningdetail.url= 'udp://%s:%d' WHERE groupmap.idGroup IN(0,1);"), ipString.c_str(), port);
	if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;

	this->dbCtrl.Commit(&this->mysql);
	this->dbCtrl.UnlockTable(&this->mysql);
	this->dbCtrl.Close(&this->mysql);
	return TRUE;

	ESC: 
	wstring err = L"";
	Format(err, L"ERROR SQL:%s", sql);
	AfxMessageBox(err.c_str(), NULL, MB_OK);
	this->dbCtrl.Rollback(&this->mysql);
	this->dbCtrl.UnlockTable(&this->mysql);
	this->dbCtrl.Close(&this->mysql);
	return FALSE;

}
Example #7
0
static void StartDebugLog()
{
	wstring iniPath;
	GetModuleIniPath(iniPath);
	if( GetPrivateProfileInt(L"SET", L"SaveDebugLog", 0, iniPath.c_str()) != 0 ){
		wstring logPath;
		GetModuleFolderPath(logPath);
		logPath += L"\\EpgTimerSrvDebugLog.txt";
		g_hDebugLog = CreateFile(logPath.c_str(), FILE_APPEND_DATA, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
		if( g_hDebugLog != INVALID_HANDLE_VALUE ){
			if( GetLastError() == ERROR_SUCCESS ){
				DWORD dwWritten;
				WriteFile(g_hDebugLog, "\xFF\xFE", sizeof(char) * 2, &dwWritten, NULL);
			}else{
				LARGE_INTEGER liPos = {};
				SetFilePointerEx(g_hDebugLog, liPos, NULL, FILE_END);
			}
			InitializeCriticalSection(&g_debugLogLock);
			g_saveDebugLog = true;
			OutputDebugString(L"****** LOG START ******\r\n");
		}
	}
}
Example #8
0
void CRestApiManager::LoadRecSetData(WORD preset, REC_SETTING_DATA* recSetData)
{
	wstring iniPath = L"";
	GetModuleIniPath(iniPath);
	WCHAR iniBuff[512]=L"";

	wstring defName = L"";
	wstring defFolderName = L"";
	wstring defFolder1SegName = L"";
	if( preset == 0 ){
		defName = L"REC_DEF";
		defFolderName = L"REC_DEF_FOLDER";
		defFolder1SegName = L"REC_DEF_FOLDER_1SEG";
	}else{
		Format(defName, L"REC_DEF%d", preset);
		Format(defFolderName, L"REC_DEF_FOLDER%d", preset);
		Format(defFolder1SegName, L"REC_DEF_FOLDER_1SEG%d", preset);
	}

	recSetData->recMode = (BYTE)GetPrivateProfileInt(defName.c_str(), L"RecMode", 1, iniPath.c_str());
    recSetData->priority = (BYTE)GetPrivateProfileInt(defName.c_str(), L"Priority", 2, iniPath.c_str());
    recSetData->tuijyuuFlag = (BYTE)GetPrivateProfileInt(defName.c_str(), L"TuijyuuFlag", 1, iniPath.c_str());
    recSetData->serviceMode = (BYTE)GetPrivateProfileInt(defName.c_str(), L"ServiceMode", 0, iniPath.c_str());
    recSetData->pittariFlag = (BYTE)GetPrivateProfileInt(defName.c_str(), L"PittariFlag", 0, iniPath.c_str());

	ZeroMemory(iniBuff, sizeof(WCHAR)*512);
    GetPrivateProfileString(defName.c_str(), L"BatFilePath", L"", iniBuff, 512, iniPath.c_str());
    recSetData->batFilePath = iniBuff;

    int count = GetPrivateProfileInt(defFolderName.c_str(), L"Count", 0, iniPath.c_str());
    for (int i = 0; i < count; i++)
    {
		wstring fn;
		wstring wn;
		wstring rn;
		Format(fn, L"%d", i);
		Format(wn, L"WritePlugIn%d", i);
		Format(rn, L"RecNamePlugIn%d", i);
        REC_FILE_SET_INFO folderInfo;
        ZeroMemory(iniBuff, sizeof(WCHAR)*512);
		GetPrivateProfileString(defFolderName.c_str(), fn.c_str(), L"", iniBuff, 512, iniPath.c_str());
        folderInfo.recFolder = iniBuff;
        ZeroMemory(iniBuff, sizeof(WCHAR)*512);
		GetPrivateProfileString(defFolderName.c_str(), wn.c_str(), L"Write_Default.dll", iniBuff, 512, iniPath.c_str());
        folderInfo.writePlugIn = iniBuff;
        ZeroMemory(iniBuff, sizeof(WCHAR)*512);
		GetPrivateProfileString(defFolderName.c_str(), rn.c_str(), L"", iniBuff, 512, iniPath.c_str());
        folderInfo.recNamePlugIn = iniBuff;

        recSetData->recFolderList.push_back(folderInfo);
    }

    count = GetPrivateProfileInt(defFolder1SegName.c_str(), L"Count", 0, iniPath.c_str());
    for (int i = 0; i < count; i++)
    {
		wstring fn;
		wstring wn;
		wstring rn;
		Format(fn, L"%d", i);
		Format(wn, L"WritePlugIn%d", i);
		Format(rn, L"RecNamePlugIn%d", i);
        REC_FILE_SET_INFO folderInfo;
        ZeroMemory(iniBuff, sizeof(WCHAR)*512);
        GetPrivateProfileString(defFolder1SegName.c_str(), fn.c_str(), L"", iniBuff, 512, iniPath.c_str());
        folderInfo.recFolder = iniBuff;
        ZeroMemory(iniBuff, sizeof(WCHAR)*512);
        GetPrivateProfileString(defFolder1SegName.c_str(), wn.c_str(), L"Write_Default.dll", iniBuff, 512, iniPath.c_str());
        folderInfo.writePlugIn = iniBuff;
        ZeroMemory(iniBuff, sizeof(WCHAR)*512);
        GetPrivateProfileString(defFolder1SegName.c_str(), rn.c_str(), L"", iniBuff, 512, iniPath.c_str());
        folderInfo.recNamePlugIn = iniBuff;

        recSetData->partialRecFolder.push_back(folderInfo);
    }

    recSetData->suspendMode = (BYTE)GetPrivateProfileInt(defName.c_str(), L"SuspendMode", 0, iniPath.c_str());
    recSetData->rebootFlag = (BYTE)GetPrivateProfileInt(defName.c_str(), L"RebootFlag", 0, iniPath.c_str());
    recSetData->useMargineFlag = (BYTE)GetPrivateProfileInt(defName.c_str(), L"UseMargineFlag", 0, iniPath.c_str());
    recSetData->startMargine = GetPrivateProfileInt(defName.c_str(), L"StartMargine", 0, iniPath.c_str());
    recSetData->endMargine = GetPrivateProfileInt(defName.c_str(), L"EndMargine", 0, iniPath.c_str());
    recSetData->continueRecFlag = (BYTE)GetPrivateProfileInt(defName.c_str(), L"ContinueRec", 0, iniPath.c_str());
    recSetData->partialRecFlag = (BYTE)GetPrivateProfileInt(defName.c_str(), L"PartialRec", 0, iniPath.c_str());
    recSetData->tunerID = (DWORD)GetPrivateProfileInt(defName.c_str(), L"TunerID", 0, iniPath.c_str());

}
Example #9
0
DWORD CRestApiManager::GetEnumRecPresetInfo(string param, HTTP_STREAM* sendParam)
{
	DWORD ret = NO_ERR;

	wstring iniPath = L"";
	GetModuleIniPath(iniPath);
	WCHAR iniBuff[512]=L"";
	GetPrivateProfileString(L"SET", L"PresetID", L"", iniBuff, 512, iniPath.c_str());
	wstring parseBuff = iniBuff;
	vector<DWORD> idList;
	idList.push_back(0);
	do{
		wstring presetID =L"";
		Separate(parseBuff, L",", presetID, parseBuff);
		idList.push_back((DWORD)_wtoi(presetID.c_str()));
	}while(parseBuff.size()>0);


	wstring xml = L"";
	string utf8 = "";

	wstring buff = L"";
	xml += L"<?xml version=\"1.0\" encoding=\"UTF-8\" ?><entry>";
	Format(buff, L"<total>%d</total><index>0</index><count>%d</count>", idList.size(), idList.size());
	xml += buff;
	xml += L"<items>";
	wstring reserveinfo = L"";
	for( size_t i=0; i<idList.size(); i++ ){
		REC_SETTING_DATA recSetting;
		LoadRecSetData((WORD)idList[i], &recSetting);

		reserveinfo += L"<recpresetinfo>";

		if( idList[i] == 0 ){
			Format(buff, L"<id>%d</id>", idList[i]);
			reserveinfo += buff;
			reserveinfo += L"<name>デフォルト</name>";
		}else{
			wstring appName = L"";
			Format(appName, L"REC_DEF%d", idList[i]);
			ZeroMemory(iniBuff, sizeof(WCHAR)*512);
			GetPrivateProfileString(appName.c_str(), L"SetName", L"", iniBuff, 512, iniPath.c_str());

			Format(buff, L"<id>%d</id>", idList[i]);
			reserveinfo += buff;
			Format(buff, L"<name>%s</name>", iniBuff);
			reserveinfo += buff;
		}
		reserveinfo += L"<recsetting>";
		Format(buff, L"<recMode>%d</recMode>", recSetting.recMode);
		reserveinfo += buff;
		Format(buff, L"<priority>%d</priority>", recSetting.priority);
		reserveinfo += buff;
		Format(buff, L"<tuijyuuFlag>%d</tuijyuuFlag>", recSetting.tuijyuuFlag);
		reserveinfo += buff;
		Format(buff, L"<serviceMode>%d</serviceMode>", recSetting.serviceMode);
		reserveinfo += buff;
		Format(buff, L"<pittariFlag>%d</pittariFlag>", recSetting.pittariFlag);
		reserveinfo += buff;
		Format(buff, L"<batFilePath>%s</batFilePath>", recSetting.batFilePath.c_str());
		reserveinfo += buff;
		reserveinfo += L"<recFolderList>";
		for( size_t j=0; j<recSetting.recFolderList.size(); j++ ){
			reserveinfo += L"<recFolderInfo>";
			Format(buff, L"<recFolder>%s</recFolder>", recSetting.recFolderList[j].recFolder.c_str());
			reserveinfo += buff;
			Format(buff, L"<writePlugIn>%s</writePlugIn>", recSetting.recFolderList[j].writePlugIn.c_str());
			reserveinfo += buff;
			Format(buff, L"<recNamePlugIn>%s</recNamePlugIn>", recSetting.recFolderList[j].recNamePlugIn.c_str());
			reserveinfo += buff;
			reserveinfo += L"</recFolderInfo>";
		}
		reserveinfo += L"</recFolderList>";
		Format(buff, L"<suspendMode>%d</suspendMode>", recSetting.suspendMode);
		reserveinfo += buff;
		Format(buff, L"<rebootFlag>%d</rebootFlag>", recSetting.rebootFlag);
		reserveinfo += buff;
		Format(buff, L"<useMargineFlag>%d</useMargineFlag>", recSetting.useMargineFlag);
		reserveinfo += buff;
		Format(buff, L"<startMargine>%d</startMargine>", recSetting.startMargine);
		reserveinfo += buff;
		Format(buff, L"<endMargine>%d</endMargine>", recSetting.endMargine);
		reserveinfo += buff;
		Format(buff, L"<continueRecFlag>%d</continueRecFlag>", recSetting.continueRecFlag);
		reserveinfo += buff;
		Format(buff, L"<partialRecFlag>%d</partialRecFlag>", recSetting.partialRecFlag);
		reserveinfo += buff;
		Format(buff, L"<tunerID>%d</tunerID>", recSetting.tunerID);
		reserveinfo += buff;
		reserveinfo += L"<partialRecFolder>";
		for( size_t j=0; j<recSetting.partialRecFolder.size(); j++ ){
			reserveinfo += L"<recFolderInfo>";
			Format(buff, L"<recFolder>%s</recFolder>", recSetting.partialRecFolder[j].recFolder.c_str());
			reserveinfo += buff;
			Format(buff, L"<writePlugIn>%s</writePlugIn>", recSetting.partialRecFolder[j].writePlugIn.c_str());
			reserveinfo += buff;
			Format(buff, L"<recNamePlugIn>%s</recNamePlugIn>", recSetting.partialRecFolder[j].recNamePlugIn.c_str());
			reserveinfo += buff;
			reserveinfo += L"</recFolderInfo>";
		}
		reserveinfo += L"</partialRecFolder>";
		reserveinfo += L"</recsetting>";

		reserveinfo += L"</recpresetinfo>";
	}
	xml += reserveinfo;
	xml += L"</items>";
	xml += L"</entry>";

	WtoUTF8(xml, utf8);

	sendParam->dataSize = (DWORD)utf8.size();
	sendParam->data = new BYTE[sendParam->dataSize];
	memcpy(sendParam->data, utf8.c_str(), sendParam->dataSize);
	if( sendParam->dataSize > 0 ){
		Format(sendParam->httpHeader, "HTTP/1.0 200 OK\r\nContent-Type: text/xml\r\nContent-Length: %d\r\nConnection: close\r\n\r\n", sendParam->dataSize);
	}else{
		sendParam->httpHeader = "HTTP/1.0 400 Bad Request\r\nConnection: close\r\n\r\n";
	}

	return ret;
}
Example #10
0
//設定を行う
void CMediaPortal_BonMain::ReloadSetting()
{
	wstring commonIniPath = L"";
	GetCommonIniPath(commonIniPath);

	wstring appIniPath = L"";
	GetModuleIniPath(appIniPath);

	wstring settingPath = L"";
	GetSettingPath(settingPath);

	wstring bonDriverPath = L"";
	GetModuleFolderPath(bonDriverPath);
	bonDriverPath += BON_DLL_FOLDER;

	this->bonCtrl.SetSettingFolder( settingPath.c_str(), bonDriverPath.c_str() );

	this->recFolderList.clear();
	int iNum = GetPrivateProfileInt( L"SET", L"RecFolderNum", 0, commonIniPath.c_str() );
	if( iNum == 0 ){
		this->recFolderList.push_back( settingPath );
	}else{
		for( int i = 0; i < iNum; i++ ){
			CString key = L"";
			key.Format(L"RecFolderPath%d", i );
			WCHAR wBuff[512]=L"";
			GetPrivateProfileString( L"SET", key, L"", wBuff, 512, commonIniPath.c_str() );

			this->recFolderList.push_back(wBuff);
		}
	}

	this->enableScrambleFlag = GetPrivateProfileInt( L"SET", L"Scramble", 1, appIniPath.c_str() );
	this->enableEMMFlag = GetPrivateProfileInt( L"SET", L"EMM", 0, appIniPath.c_str() );
	this->allService = GetPrivateProfileInt( L"SET", L"AllService", 0, appIniPath.c_str() );
	this->needCaption = GetPrivateProfileInt( L"SET", L"Caption", 1, appIniPath.c_str() );
	this->needData = GetPrivateProfileInt( L"SET", L"Data", 0, appIniPath.c_str() );

	this->startMargine = GetPrivateProfileInt( L"SET", L"StartMargine", 5, appIniPath.c_str() );
	this->endMargine = GetPrivateProfileInt( L"SET", L"EndMargine", 5, appIniPath.c_str() );

	this->overWriteFlag = GetPrivateProfileInt( L"SET", L"OverWrite", 0, appIniPath.c_str() );

	this->BSBasic = GetPrivateProfileInt( L"SET", L"BSBasicOnly", 1, commonIniPath.c_str() );
	this->CS1Basic = GetPrivateProfileInt( L"SET", L"CS1BasicOnly", 1, commonIniPath.c_str() );
	this->CS2Basic = GetPrivateProfileInt( L"SET", L"CS2BasicOnly", 1, commonIniPath.c_str() );

	WCHAR buff[512]=L"";
	GetPrivateProfileString( L"SET", L"ViewPath", L"", buff, 512, appIniPath.c_str() );
	this->viewPath = buff;
	GetPrivateProfileString( L"SET", L"ViewOption", L"", buff, 512, appIniPath.c_str() );
	this->viewOpt = buff;

	this->udpCount = (DWORD)GetPrivateProfileInt( L"SET_UDP", L"Count", 0, appIniPath.c_str() );
	this->tcpCount = (DWORD)GetPrivateProfileInt( L"SET_TCP", L"Count", 0, appIniPath.c_str() );

	if( this->nwCtrlID != 0 ){
		if( this->allService == TRUE ){
			this->bonCtrl.SetServiceID(this->nwCtrlID, 0xFFFF);
		}else{
			this->bonCtrl.SetServiceID(this->nwCtrlID, this->lastSID);
		}
	}

	BOOL epgCapLive = (BOOL)GetPrivateProfileInt( L"SET", L"EpgCapLive", 1, appIniPath.c_str() );
	BOOL epgCapRec = (BOOL)GetPrivateProfileInt( L"SET", L"EpgCapRec", 1, appIniPath.c_str() );
	DWORD epgCapBackStartWaitSec = (DWORD)GetPrivateProfileInt( L"SET", L"EpgCapBackStartWaitSec", 30, appIniPath.c_str() );

	this->bonCtrl.SetBackGroundEpgCap(epgCapLive, epgCapRec, this->BSBasic, this->CS1Basic, this->CS2Basic, epgCapBackStartWaitSec);
	if( this->sendTcpFlag == FALSE && this->sendUdpFlag == FALSE ){
		this->bonCtrl.SetScramble(this->nwCtrlID, this->enableScrambleFlag);
	}
	this->bonCtrl.SetEMMMode(this->enableEMMFlag);

	DWORD tsBuffMaxCount = (DWORD)GetPrivateProfileInt( L"SET", L"TsBuffMaxCount", 5000, appIniPath.c_str() );
	int writeBuffMaxCount = GetPrivateProfileInt( L"SET", L"WriteBuffMaxCount", -1, appIniPath.c_str() );
	this->bonCtrl.SetTsBuffMaxCount(tsBuffMaxCount, writeBuffMaxCount);

	this->openWait = (DWORD)GetPrivateProfileInt( L"SET", L"OpenWait", 200, appIniPath.c_str() );
}
Example #11
0
BOOL CSyoboiCalUtil::SendReserve(vector<RESERVE_DATA>* reserveList, vector<TUNER_RESERVE_INFO>* tunerList)
{
	if( reserveList == NULL || tunerList == NULL ){
		return FALSE;
	}
	if( reserveList->size() == 0 ){
		return FALSE;
	}

	wstring iniAppPath = L"";
	GetModuleIniPath(iniAppPath);
	if( GetPrivateProfileInt(L"SYOBOI", L"use", 0, iniAppPath.c_str()) == 0 ){
		return FALSE;
	}
	_OutputDebugString(L"★SyoboiCalUtil:SendReserve");

	wstring textPath;
	GetModuleFolderPath(textPath);
	textPath += L"\\SyoboiCh.txt";
	CParseServiceChgText srvChg;
	srvChg.ParseText(textPath.c_str());

	SAFE_DELETE(this->proxyInfo);
	WCHAR buff[512] = L"";
	int length = 0;
	BOOL useProxy = (BOOL)GetPrivateProfileInt(L"SYOBOI", L"useProxy", 0, iniAppPath.c_str());
	if( useProxy == TRUE ){
		this->proxyInfo = new USE_PROXY_INFO;

		GetPrivateProfileString(L"SYOBOI", L"ProxyServer", L"", buff, 512, iniAppPath.c_str());
		this->proxyInfo->serverName = new WCHAR[wcslen(buff)+1];
		wcscpy_s(this->proxyInfo->serverName, wcslen(buff)+1, buff);

		ZeroMemory(buff, (sizeof(WCHAR)*512));
		GetPrivateProfileString(L"SYOBOI", L"ProxyID", L"", buff, 512, iniAppPath.c_str());
		length = (int)wcslen(buff);
		if( length > 0 ){
			this->proxyInfo->userName = new WCHAR[length+1];
			wcscpy_s(this->proxyInfo->userName, length+1, buff);
		}else{
			this->proxyInfo->userName = NULL;
		}

		ZeroMemory(buff, (sizeof(WCHAR)*512));
		GetPrivateProfileString(L"SYOBOI", L"ProxyPWD", L"", buff, 512, iniAppPath.c_str());
		length = (int)wcslen(buff);
		if( length > 0 ){
			this->proxyInfo->password = new WCHAR[length+1];
			wcscpy_s(this->proxyInfo->password, length+1, buff);
		}else{
			this->proxyInfo->password = NULL;
		}

	}

	ZeroMemory(buff, (sizeof(WCHAR)*512));
	GetPrivateProfileString(L"SYOBOI", L"userID", L"", buff, 512, iniAppPath.c_str());
	this->id=buff;

	ZeroMemory(buff, (sizeof(WCHAR)*512));
	GetPrivateProfileString(L"SYOBOI", L"PWD", L"", buff, 512, iniAppPath.c_str());
	this->pass=buff;

	int slot = GetPrivateProfileInt(L"SYOBOI", L"slot", 0, iniAppPath.c_str());

	ZeroMemory(buff, (sizeof(WCHAR)*512));
	GetPrivateProfileString(L"SYOBOI", L"devcolors", L"", buff, 512, iniAppPath.c_str());
	wstring devcolors=buff;
	
	ZeroMemory(buff, (sizeof(WCHAR)*512));
	GetPrivateProfileString(L"SYOBOI", L"epgurl", L"", buff, 512, iniAppPath.c_str());
	wstring epgurl=buff;

	if( this->id.size() == 0 ){
		_OutputDebugString(L"★SyoboiCalUtil:NoUserID");
		return FALSE;
	}

	//Authorization
	wstring auth = L"";
	auth = this->id;
	auth += L":";
	auth += this->pass;
	string authA;
	WtoA(auth, authA);

	DWORD destSize = 0;
	Base64Enc(authA.c_str(), (DWORD)authA.size(), NULL, &destSize);
	WCHAR* base64 = new WCHAR[destSize];
	ZeroMemory(base64, destSize*sizeof(WCHAR));
	Base64Enc(authA.c_str(), (DWORD)authA.size(), base64, &destSize);

	wstring authHead = L"";
	Format(authHead, L"Authorization: Basic %s\r\nContent-type: application/x-www-form-urlencoded\r\n", base64);

	//data
	wstring dataParam;
	wstring param;
	map<DWORD, wstring> tunerMap;
	for( size_t i=0; i<tunerList->size(); i++ ){
		for( size_t j=0; j<(*tunerList)[i].reserveList.size(); j++ ){
			tunerMap.insert(pair<DWORD, wstring>((*tunerList)[i].reserveList[j], (*tunerList)[i].tunerName));
		}
	}
	map<DWORD, wstring>::iterator itrTuner;
	DWORD dataCount = 0;
	for(size_t i=0; i<reserveList->size(); i++ ){
		if( dataCount>=200 ){
			break;
		}
		RESERVE_DATA* info = &(*reserveList)[i];
		if( info->recSetting.recMode == RECMODE_NO || info->recSetting.recMode == RECMODE_VIEW ){
			continue;
		}
		wstring device=L"";
		itrTuner = tunerMap.find(info->reserveID);
		if( itrTuner != tunerMap.end() ){
			device = itrTuner->second;
		}

		wstring stationName = info->stationName;
		srvChg.ChgText(stationName);

		__int64 startTime = GetTimeStamp(info->startTime);
		Format(param, L"%I64d\t%I64d\t%s\t%s\t%s\t\t0\t%d\n", startTime, startTime+info->durationSecond, device.c_str(), info->title.c_str(), stationName.c_str(), info->reserveID );
		dataParam+=param;
	}

	if(dataParam.size() == 0 ){
		_OutputDebugString(L"★SyoboiCalUtil:NoReserve");
		return FALSE;
	}

	string utf8;
	UrlEncodeUTF8(dataParam.c_str(), (DWORD)dataParam.size(), utf8);
	string data;
	Format(data, "slot=%d&data=%s",slot, utf8.c_str());

	if( devcolors.size() > 0){
		utf8 = "";
		UrlEncodeUTF8(devcolors.c_str(), (DWORD)devcolors.size(), utf8);
		data += "&devcolors=";
		data += utf8;
	}
	if( epgurl.size() > 0){
		utf8 = "";
		UrlEncodeUTF8(epgurl.c_str(), (DWORD)epgurl.size(), utf8);
		data += "&epgurl=";
		data += utf8;
	}

	UPLOAD_DATA_LIST upList;
	upList.listCount = 1;
	upList.list = new UPLOAD_DATA[1];
	upList.list->filePathFlag = 0;
	upList.list->buffSize = (DWORD)data.size();
	upList.list->buff = new BYTE[data.size()+1];
	ZeroMemory(upList.list->buff, data.size()+1);
	memcpy(upList.list->buff, data.c_str(), data.size());

	wstring url;
	Format(url,L"%s",SYOBOI_UP_URL);

	CWinHTTPUtil http;
	DWORD result = NO_ERR;
	result = http.OpenSession(L"EpgTimerSrv", FALSE, useProxy, this->proxyInfo);
	if( result != NO_ERR ){
		return FALSE;
	}
	result = http.SendRequest(url.c_str(), NW_VERB_POST, authHead.c_str(), NULL, &upList);


	DWORD dlSize = 0;
	http.GetDLBuff(NULL, &dlSize);
	if( dlSize > 0 ){
		BYTE* dlBuff = new BYTE[dlSize+1];
		ZeroMemory(dlBuff, dlSize+1);
		http.GetDLBuff(dlBuff, &dlSize);

		string response = (char*)dlBuff;
		SAFE_DELETE_ARRAY(dlBuff);
	}

	http.CloseRequest();

	_OutputDebugString(L"★SyoboiCalUtil:SendRequest res:%d", result);

	if( result != NO_ERR ){
		return FALSE;
	}
	return TRUE;
}
Example #12
0
BOOL CSyoboiCalUtil::SendReserve(const vector<RESERVE_DATA>* reserveList, const vector<TUNER_RESERVE_INFO>* tunerList)
{
	if( reserveList == NULL || tunerList == NULL ){
		return FALSE;
	}
	if( reserveList->size() == 0 ){
		return FALSE;
	}

	wstring iniAppPath = L"";
	GetModuleIniPath(iniAppPath);
	if( GetPrivateProfileInt(L"SYOBOI", L"use", 0, iniAppPath.c_str()) == 0 ){
		return FALSE;
	}
	_OutputDebugString(L"★SyoboiCalUtil:SendReserve");

	wstring textPath;
	GetModuleFolderPath(textPath);
	textPath += L"\\SyoboiCh.txt";
	CParseServiceChgText srvChg;
	srvChg.ParseText(textPath.c_str());

	wstring proxyServerName;
	wstring proxyUserName;
	wstring proxyPassword;
	if( GetPrivateProfileInt(L"SYOBOI", L"useProxy", 0, iniAppPath.c_str()) != 0 ){
		proxyServerName = GetPrivateProfileToString(L"SYOBOI", L"ProxyServer", L"", iniAppPath.c_str());
		proxyUserName = GetPrivateProfileToString(L"SYOBOI", L"ProxyID", L"", iniAppPath.c_str());
		proxyPassword = GetPrivateProfileToString(L"SYOBOI", L"ProxyPWD", L"", iniAppPath.c_str());
	}

	wstring id=GetPrivateProfileToString(L"SYOBOI", L"userID", L"", iniAppPath.c_str());

	wstring pass=GetPrivateProfileToString(L"SYOBOI", L"PWD", L"", iniAppPath.c_str());

	int slot = GetPrivateProfileInt(L"SYOBOI", L"slot", 0, iniAppPath.c_str());

	wstring devcolors=GetPrivateProfileToString(L"SYOBOI", L"devcolors", L"", iniAppPath.c_str());
	
	wstring epgurl=GetPrivateProfileToString(L"SYOBOI", L"epgurl", L"", iniAppPath.c_str());

	if( id.size() == 0 ){
		_OutputDebugString(L"★SyoboiCalUtil:NoUserID");
		return FALSE;
	}

	//Authorization
	wstring auth = L"";
	auth = id;
	auth += L":";
	auth += pass;
	string authA;
	WtoA(auth, authA);

	DWORD destSize = 0;
	Base64Enc(authA.c_str(), (DWORD)authA.size(), NULL, &destSize);
	vector<WCHAR> base64(destSize + 1, L'\0');
	Base64Enc(authA.c_str(), (DWORD)authA.size(), &base64.front(), &destSize);
	//無駄なCRLFが混じることがあるため
	std::replace(base64.begin(), base64.end(), L'\r', L'\0');
	std::replace(base64.begin(), base64.end(), L'\n', L'\0');

	wstring authHead = L"";
	Format(authHead, L"Authorization: Basic %s\r\nContent-type: application/x-www-form-urlencoded\r\n", &base64.front());

	//data
	wstring dataParam;
	wstring param;
	map<DWORD, wstring> tunerMap;
	for( size_t i=0; i<tunerList->size(); i++ ){
		for( size_t j=0; j<(*tunerList)[i].reserveList.size(); j++ ){
			tunerMap.insert(pair<DWORD, wstring>((*tunerList)[i].reserveList[j], (*tunerList)[i].tunerName));
		}
	}
	map<DWORD, wstring>::iterator itrTuner;
	DWORD dataCount = 0;
	for(size_t i=0; i<reserveList->size(); i++ ){
		if( dataCount>=200 ){
			break;
		}
		const RESERVE_DATA* info = &(*reserveList)[i];
		if( info->recSetting.recMode == RECMODE_NO || info->recSetting.recMode == RECMODE_VIEW ){
			continue;
		}
		wstring device=L"";
		itrTuner = tunerMap.find(info->reserveID);
		if( itrTuner != tunerMap.end() ){
			device = itrTuner->second;
		}

		wstring stationName = info->stationName;
		srvChg.ChgText(stationName);

		__int64 startTime = GetTimeStamp(info->startTime);
		Format(param, L"%I64d\t%I64d\t%s\t%s\t%s\t\t0\t%d\n", startTime, startTime+info->durationSecond, device.c_str(), info->title.c_str(), stationName.c_str(), info->reserveID );
		dataParam+=param;
	}

	if(dataParam.size() == 0 ){
		_OutputDebugString(L"★SyoboiCalUtil:NoReserve");
		return FALSE;
	}

	string utf8;
	UrlEncodeUTF8(dataParam.c_str(), (DWORD)dataParam.size(), utf8);
	string data;
	Format(data, "slot=%d&data=%s",slot, utf8.c_str());

	if( devcolors.size() > 0){
		utf8 = "";
		UrlEncodeUTF8(devcolors.c_str(), (DWORD)devcolors.size(), utf8);
		data += "&devcolors=";
		data += utf8;
	}
	if( epgurl.size() > 0){
		utf8 = "";
		UrlEncodeUTF8(epgurl.c_str(), (DWORD)epgurl.size(), utf8);
		data += "&epgurl=";
		data += utf8;
	}
	vector<char> dataBuff(data.begin(), data.end());

	//URLの分解
	URL_COMPONENTS stURL = {};
	stURL.dwStructSize = sizeof(stURL);
	stURL.dwSchemeLength = (DWORD)-1;
	stURL.dwHostNameLength = (DWORD)-1;
	stURL.dwUrlPathLength = (DWORD)-1;
	stURL.dwExtraInfoLength = (DWORD)-1;
	if( WinHttpCrackUrl(SYOBOI_UP_URL, 0, 0, &stURL) == FALSE || stURL.dwHostNameLength == 0 ){
		return FALSE;
	}
	wstring host(stURL.lpszHostName, stURL.dwHostNameLength);
	wstring sendUrl(stURL.lpszUrlPath, stURL.dwUrlPathLength + stURL.dwExtraInfoLength);

	HINTERNET session;
	if( proxyServerName.empty() ){
		session = WinHttpOpen(L"EpgTimerSrv", WINHTTP_ACCESS_TYPE_NO_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
	}else{
		session = WinHttpOpen(L"EpgTimerSrv", WINHTTP_ACCESS_TYPE_NAMED_PROXY, proxyServerName.c_str(), WINHTTP_NO_PROXY_BYPASS, 0);
	}
	if( session == NULL ){
		return FALSE;
	}

	LPCWSTR result = L"1";
	HINTERNET connect = NULL;
	HINTERNET request = NULL;

	if( WinHttpSetTimeouts(session, 15000, 15000, 15000, 15000) == FALSE ){
		result = L"0 SetTimeouts";
		goto EXIT;
	}
	//コネクションオープン
	connect = WinHttpConnect(session, host.c_str(), stURL.nPort, 0);
	if( connect == NULL ){
		result = L"0 Connect";
		goto EXIT;
	}
	//リクエストオープン
	request = WinHttpOpenRequest(connect, L"POST", sendUrl.c_str(), NULL, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES,
	                             stURL.nPort == INTERNET_DEFAULT_HTTPS_PORT ? WINHTTP_FLAG_SECURE : 0);
	if( request == NULL ){
		result = L"0 OpenRequest";
		goto EXIT;
	}
	if( proxyServerName.empty() == false ){
		//ProxyのIDかパスワードがあったらセット
		if( proxyUserName.empty() == false || proxyPassword.empty() == false ){
			if( WinHttpSetCredentials(request, WINHTTP_AUTH_TARGET_PROXY, WINHTTP_AUTH_SCHEME_BASIC,
			                          proxyUserName.c_str(), proxyPassword.c_str(), NULL) == FALSE ){
				result = L"0 SetCredentials";
				goto EXIT;
			}
		}
	}
	if( WinHttpSendRequest(request, authHead.c_str(), (DWORD)-1, &dataBuff.front(), (DWORD)dataBuff.size(), (DWORD)dataBuff.size(), 0) == FALSE ){
		result = L"0 SendRequest";
		goto EXIT;
	}
	if( WinHttpReceiveResponse(request, NULL) == FALSE ){
		result = L"0 ReceiveResponse";
		goto EXIT;
	}
	//HTTPのステータスコード確認
	DWORD statusCode;
	DWORD statusCodeSize = sizeof(statusCode);
	if( WinHttpQueryHeaders(request, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, WINHTTP_HEADER_NAME_BY_INDEX,
	                        &statusCode, &statusCodeSize, WINHTTP_NO_HEADER_INDEX) == FALSE ){
		statusCode = 0;
	}
	if( statusCode != 200 && statusCode != 201 ){
		result = L"0 StatusNotOK";
		goto EXIT;
	}

EXIT:
	if( request != NULL ){
		WinHttpCloseHandle(request);
	}
	if( connect != NULL ){
		WinHttpCloseHandle(connect);
	}
	if( session != NULL ){
		WinHttpCloseHandle(session);
	}

	_OutputDebugString(L"★SyoboiCalUtil:SendRequest res:%s", result);

	if( result[0] != L'1' ){
		return FALSE;
	}
	return TRUE;
}
Example #13
0
//チューナー一覧の読み込みを行う
//戻り値:
// TRUE(成功)、FALSE(失敗)
BOOL CTunerManager::ReloadTuner()
{
	this->tunerMap.clear();

	wstring path = L"";
	GetSettingPath(path);

	wstring srvIniPath = L"";
	GetModuleIniPath(srvIniPath);

	wstring searchKey = path;
	searchKey += L"\\*.ChSet4.txt";

	WIN32_FIND_DATA findData;
	HANDLE find;

	//指定フォルダのファイル一覧取得
	find = FindFirstFile( searchKey.c_str(), &findData);
	if ( find == INVALID_HANDLE_VALUE ) {
		return FALSE;
	}
	do{
		if( (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0 ){
			wstring bonFileName;
			if( FindBonFileName(findData.cFileName, bonFileName) != FALSE ){
				wstring chSetPath = L"";
				Format(chSetPath, L"%s\\%s", path.c_str(), findData.cFileName);

				bonFileName += L".dll";

				WORD count = (WORD)GetPrivateProfileInt(bonFileName.c_str(), L"Count", 0, srvIniPath.c_str());
				if( count != 0 ){
					//カウント0以上のものだけ利用
					WORD priority = (WORD)GetPrivateProfileInt(bonFileName.c_str(), L"Priority", 0, srvIniPath.c_str());
					BOOL epgCapFlag = (BOOL)GetPrivateProfileInt(bonFileName.c_str(), L"GetEpg", 1, srvIniPath.c_str());
					WORD EPGcount = (WORD)GetPrivateProfileInt(bonFileName.c_str(), L"EPGCount", count, srvIniPath.c_str());
					if(EPGcount==0)	EPGcount = count;

					if( this->tunerMap.find((DWORD)priority<<16 | 1) != this->tunerMap.end() ){
						OutputDebugString(L"CTunerManager::ReloadTuner(): Duplicate bonID\r\n");
						count = 0;
					}
					for( WORD i=1; i<=count; i++ ){
						TUNER_INFO item;
						item.epgCapMaxOfThisBon = min(epgCapFlag == FALSE ? 0 : EPGcount, count);
						item.bonFileName = bonFileName;
						item.chSet4FilePath = chSetPath;
						CParseChText4 chUtil;
						chUtil.ParseText(chSetPath.c_str());
						map<DWORD, CH_DATA4>::const_iterator itr;
						for( itr = chUtil.GetMap().begin(); itr != chUtil.GetMap().end(); itr++ ){
							item.chList.push_back(itr->second);
						}
						this->tunerMap.insert(pair<DWORD, TUNER_INFO>((DWORD)priority<<16 | i, item));
					}
				}
			}
		}
	}while(FindNextFile(find, &findData));

	FindClose(find);

	return TRUE;
}
Example #14
0
BOOL CParseChText4::SaveChText(LPCWSTR filePath)
{
	wstring loadFilePath = L"";
	wstring loadTunerName = L"";
	if( filePath == NULL ){
		loadFilePath = this->filePath;
		loadTunerName = this->tunerName;
	}else{
		loadFilePath = filePath;
		wregex re(L".+\\\\(.+)\\(.+\\)\\.ChSet4\\.txt$");
		wstring text(filePath);
		wsmatch m;
		if( regex_search(text, m, re) ){ 
			loadTunerName = m[1];
			loadTunerName += L".dll";
		}
	}

	if( loadFilePath.size() == 0 ){
		return FALSE;
	}

	if( loadTunerName.size() == 0 ){
		return FALSE;
	}

	multimap<LONGLONG, CH_DATA4> sortList;
	multimap<LONGLONG, CH_DATA4>::iterator itr;
	for( itr = this->chList.begin(); itr != this->chList.end(); itr++ ){
		LONGLONG Key = ((LONGLONG)itr->second.space)<<32 | ((LONGLONG)itr->second.ch)<<16 | (LONGLONG)itr->second.serviceID;
		sortList.insert(pair<LONGLONG, CH_DATA4>(Key, itr->second));
	}


	// ファイル出力
	HANDLE hFile = _CreateFile2( loadFilePath.c_str(), GENERIC_WRITE, FILE_SHARE_READ, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
	if( hFile == INVALID_HANDLE_VALUE ){
		return FALSE;
	}

	for( itr = sortList.begin(); itr != sortList.end(); itr++ ){
		string chName="";
		WtoA(itr->second.chName, chName);
		string serviceName="";
		WtoA(itr->second.serviceName, serviceName);
		string networkName="";
		WtoA(itr->second.networkName, networkName);

		string strBuff;
		Format(strBuff, "%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\r\n",
			chName.c_str(),
			serviceName.c_str(),
			networkName.c_str(),
			itr->second.space,
			itr->second.ch,
			itr->second.originalNetworkID,
			itr->second.transportStreamID,
			itr->second.serviceID,
			itr->second.serviceType,
			itr->second.partialFlag,
			itr->second.useViewFlag,
			itr->second.remoconID
			);
		DWORD dwWrite = 0;
		WriteFile(hFile, strBuff.c_str(), (DWORD)strBuff.length(), &dwWrite, NULL);
	}

	CloseHandle(hFile);

	wstring appIniPath = L"";
	GetModuleIniPath(appIniPath);

	wstring ipString;
	DWORD ip;
	DWORD port;

	ip = GetPrivateProfileInt(L"SET_UDP", L"IP0", 2130706433, appIniPath.c_str());
	Format(ipString, L"%d.%d.%d.%d", 
	(ip&0xFF000000)>>24, 
	(ip&0x00FF0000)>>16, 
	(ip&0x0000FF00)>>8, 
	(ip&0x000000FF) );
	port = GetPrivateProfileInt( L"SET_UDP", L"Port0", 3456, appIniPath.c_str() );

	// MediaPortal TV Serverのデータベースへ登録
	if (this->dbCtrl.Connect(&this->mysql, MYSQL_HOST, MYSQL_USER, MYSQL_PASSWD, MYSQL_DB) != 0) {
		return FALSE;
	}

	this->results = NULL;
	CString sql = L"";
	wstring wsql = L"";
	int chkNum = 0;

	this->dbCtrl.Begin(&this->mysql);

	map<CString, int> lockTable;
	lockTable[L"channelgroup"] = 2;
	lockTable[L"tuningdetail"] = 2;
	lockTable[L"groupmap"    ] = 2;
	lockTable[L"channel"     ] = 2;
	lockTable[L"channelmap"  ] = 2;
	if (this->dbCtrl.LockTable(&this->mysql, lockTable) != 0) goto ESC;


	// channelgroupの登録が何個あるか調べる
	sql  = L"SELECT idGroup FROM channelgroup WHERE idGroup < 2;";
	if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;
	this->dbCtrl.StoreResult(&this->mysql, &this->results);
	chkNum = this->dbCtrl.NumRows(&this->results);
	this->dbCtrl.FreeResult(&this->results);

	int maxNum;
	sql  = L"SELECT MAX(idGroup) FROM channelgroup;";
	if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;
	this->dbCtrl.StoreResult(&this->mysql, &this->results);
	this->record = this->dbCtrl.FetchRow(&this->results);
	maxNum = atoi(this->record[0]);
	this->dbCtrl.FreeResult(&this->results);

	switch(chkNum){
		case 0: // 登録が0個ならidGroupの0(地上波・BS)と1(CS)を登録する
			// idGroupに0はオートナンバーのためINSERTの段階では登録できないのでINSERTしてから変更する
			sql.Format(_T("INSERT INTO channelgroup VALUES(%d,'地上波・BS',0);"), maxNum + 1);
			if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;

			sql.Format(_T("UPDATE channelgroup SET idGroup = 0 WHERE idGroup = %d;"), maxNum + 1);
			if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;

			sql  = L"INSERT INTO channelgroup VALUES(1,'CS',1);";
			if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;
			break;
		case 1: // 登録が1個ならidGroupの1を末番に変更して、idGroupの0(地上波・BS)と1(CS)を登録する
			// 1個ということはMediaPortal_Bonより前にMediaPortal TV Serverのチャンネル設定で初期値が入った。
			sql.Format(_T("UPDATE channelgroup SET idGroup = %d WHERE idGroup = 1;"), maxNum + 1);
			if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;

			sql.Format(_T("UPDATE groupmap SET idGroup = %d WHERE idGroup = 1;"), maxNum + 1);
			if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;

			sql  = L"SELECT MAX(idGroup) FROM channelgroup;";
			if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;
			this->dbCtrl.StoreResult(&this->mysql, &this->results);
			this->record = this->dbCtrl.FetchRow(&this->results);
			maxNum = atoi(this->record[0]);
			this->dbCtrl.FreeResult(&this->results);

			sql.Format(_T("INSERT INTO channelgroup VALUES(%d,'地上波・BS',0);"), maxNum + 1);
			if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;

			sql.Format(_T("UPDATE channelgroup SET idGroup = 0 WHERE idGroup = %d;"), maxNum + 1);
			if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;

			sql  = L"INSERT INTO channelgroup VALUES(1,'CS',1);";
			if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;
			break;
	}

	// 同じチューナーの既存の登録に対してチューナー名を変更する。
	sql.Format(_T("UPDATE tuningdetail SET provider = '@_%s' WHERE provider = '%s';"), loadTunerName.c_str(), loadTunerName.c_str());
	if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;

	//sql.Format(_T("iterator = '%d' '%d';"), sortList.begin(), sortList.end());
	//AfxMessageBox(sql, NULL, MB_OK);

	int tmpCh;  // 登録用チャンネル
	for( itr = sortList.begin(); itr != sortList.end(); itr++ ){
		if(itr->second.useViewFlag){
			wsql  = L"";
			wsql += L"SELECT idChannel FROM tuningdetail WHERE ";
			wsql += L"provider = '@_%s' AND ";
			wsql += L"channelNumber = %d AND ";
			wsql += L"networkId     = %d AND ";
			wsql += L"transportId   = %d AND ";
			wsql += L"serviceId     = %d;";
			sql.Format(wsql.c_str(),
				loadTunerName.c_str(),
				itr->second.ch,
				itr->second.originalNetworkID,
				itr->second.transportStreamID,
				itr->second.serviceID
				);
			if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;
			this->dbCtrl.StoreResult(&this->mysql, &this->results);

			//AfxMessageBox(loadTunerName.c_str(), NULL, MB_OK);

			if(this->dbCtrl.NumRows(&this->results)){ // 既存のチャンネルは退避する
				this->record = this->dbCtrl.FetchRow(&this->results);
				tmpCh = atoi(this->record[0]);
				this->dbCtrl.FreeResult(&this->results);

				wsql  = L"";
				wsql += L"UPDATE tuningdetail SET provider = '%s' WHERE ";
				wsql += L"provider = '@_%s' AND ";
				wsql += L"channelNumber = %d AND ";
				wsql += L"networkId     = %d AND ";
				wsql += L"transportId   = %d AND ";
				wsql += L"serviceId     = %d;";
				sql.Format(wsql.c_str(),
					loadTunerName.c_str(),
					loadTunerName.c_str(),
					itr->second.ch,
					itr->second.originalNetworkID,
					itr->second.transportStreamID,
					itr->second.serviceID
					);
				if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;

				// 既存のチャンネル登録があってもgroupmap.idGroupが適切な値(0:地上波・BS, 1:CS)になっているかを調べる。
				sql.Format(_T("SELECT idMap FROM groupmap WHERE idChannel = %d AND idGroup = %d;"), tmpCh, itr->second.space);
				if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;
				this->dbCtrl.StoreResult(&this->mysql, &this->results);
				if(!this->dbCtrl.NumRows(&this->results)){
					this->dbCtrl.FreeResult(&this->results);
					sql  = L"SELECT SortOrder FROM groupmap;";
					if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;
					this->dbCtrl.StoreResult(&this->mysql, &this->results);
					maxNum = this->dbCtrl.NumRows(&this->results);

					// groupmap.idGroupに適切な値(0:地上波・BS, 1:CS)の登録を行う。
					sql.Format(_T("INSERT INTO groupmap VALUES(0, %d, %d, %d);"), itr->second.space, tmpCh, maxNum);
					if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;
				}
				this->dbCtrl.FreeResult(&this->results);

				// チャンネル概要があるか
				sql.Format(_T("SELECT displayName FROM channel WHERE idChannel = %d;"), tmpCh);
				if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;
				this->dbCtrl.StoreResult(&this->mysql, &this->results);
				if(!this->dbCtrl.NumRows(&this->results)){
					// チャンネルの登録を行う。
					sql.Format(_T("INSERT INTO channel VALUES(%d,0,1,0,'2000-01-01 00:00:00',0,'2000-01-01 00:00:00',%d,1,'','%s',0,%d);"), 
						tmpCh, 
						(tmpCh + itr->second.space * 1000), 
						itr->second.serviceName.c_str(),
						itr->second.ch
					);
					if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;
				}
				this->dbCtrl.FreeResult(&this->results);

				// チャンネルマップがあるか
				sql.Format(_T("SELECT idChannelMap FROM channelmap WHERE idChannel = %d AND idCard = 1;"), tmpCh);
				if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;
				this->dbCtrl.StoreResult(&this->mysql, &this->results);
				if(!this->dbCtrl.NumRows(&this->results)){
					// チャンネルマップの登録を行う。
					sql.Format(_T("INSERT INTO channelmap VALUES(0,%d,1,0);"), tmpCh);
					if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;
				}
				this->dbCtrl.FreeResult(&this->results);

			} else { // チャンネルを新規登録
				this->dbCtrl.FreeResult(&this->results);

				// BONドライバーが違っても同じチャンネルがあるかどうか
				wsql  = L"";
				wsql += L"SELECT idChannel FROM tuningdetail WHERE ";
				wsql += L"provider <> '@_%s' AND ";
				wsql += L"channelNumber = %d AND ";
				wsql += L"networkId     = %d AND ";
				wsql += L"transportId   = %d AND ";
				wsql += L"serviceId     = %d;";
				sql.Format(wsql.c_str(),
					loadTunerName.c_str(),
					itr->second.ch,
					itr->second.originalNetworkID,
					itr->second.transportStreamID,
					itr->second.serviceID
					);
				if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;
				this->dbCtrl.StoreResult(&this->mysql, &this->results);
				
				// 同じチャンネルがある場合はそのチャンネルを使う
				// ない場合はチャンネル概要の次番号を得る。
				if(!this->dbCtrl.NumRows(&this->results)){
					sql  = L"SELECT MAX(idChannel) FROM channel;";
					if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;
					this->dbCtrl.StoreResult(&this->mysql, &this->results);
				}
				this->record = this->dbCtrl.FetchRow(&this->results);
				//if(CA2T(this->record[0], CP_UTF8) == L"") maxNum = 0;
				if(this->record[0] == 0x00000000) maxNum = 0;
				else maxNum = atoi(this->record[0]);
				tmpCh  = maxNum + 1;
				this->dbCtrl.FreeResult(&this->results);

				// チャンネル概要があるか
				sql.Format(_T("SELECT displayName FROM channel WHERE idChannel = %d;"), tmpCh);
				if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;
				this->dbCtrl.StoreResult(&this->mysql, &this->results);
				if(!this->dbCtrl.NumRows(&this->results)){
					// チャンネルの登録を行う。
					sql.Format(_T("INSERT INTO channel VALUES(%d,0,1,0,'2000-01-01 00:00:00',0,'2000-01-01 00:00:00',%d,1,'','%s',0,%d);"), 
						tmpCh, 
						(tmpCh + itr->second.space * 1000), 
						itr->second.serviceName.c_str(),
						itr->second.ch
					);
					if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;
				}
				this->dbCtrl.FreeResult(&this->results);

				// チャンネル詳細の次番号を得る。
				int maxTuNum;
				sql  = L"SELECT MAX(idTuning) FROM tuningdetail;";
				if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;
				this->dbCtrl.StoreResult(&this->mysql, &this->results);
				this->record = this->dbCtrl.FetchRow(&this->results);
				if(this->record[0] == 0x00000000) maxTuNum = 0;
				else maxTuNum = atoi(this->record[0]);
				this->dbCtrl.FreeResult(&this->results);

				// チャンネル詳細登録
				sql.Format(L"INSERT INTO tuningdetail VALUES(%d,%d,'%s','%s',7,%d,0,31,0,1,%d,%d,%d,496,0,0,0,0,1,0,8,-1,-1,0,0,0,-1,-1,-1,-1,'udp://%s:%d',0,0,0);",
					maxTuNum + 1,
					tmpCh,
					itr->second.serviceName.c_str(),
					loadTunerName.c_str(),
					itr->second.ch,
					itr->second.originalNetworkID,
					itr->second.transportStreamID,
					itr->second.serviceID,
					ipString.c_str(),
					port
				);
				if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;

				//AfxMessageBox(sql, NULL, MB_OK);

				// グループがあるか
				sql.Format(_T("SELECT idChannel FROM groupmap WHERE idGroup = %d AND idChannel = %d;"), itr->second.space, tmpCh);
				if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;
				this->dbCtrl.StoreResult(&this->mysql, &this->results);
				if(!this->dbCtrl.NumRows(&this->results)){
					this->dbCtrl.FreeResult(&this->results);
					sql  = L"SELECT SortOrder FROM groupmap;";
					if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;
					this->dbCtrl.StoreResult(&this->mysql, &this->results);
					maxNum = this->dbCtrl.NumRows(&this->results);

					// グループの登録を行う。
					sql.Format(_T("INSERT INTO groupmap VALUES(0, %d, %d, %d);"), itr->second.space, tmpCh, maxNum);
					if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;
				}
				this->dbCtrl.FreeResult(&this->results);
				
				// チャンネルマップがあるか
				sql.Format(_T("SELECT idChannelMap FROM channelmap WHERE idChannel = %d AND idCard = 2;"), tmpCh);
				if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;
				this->dbCtrl.StoreResult(&this->mysql, &this->results);
				if(!this->dbCtrl.NumRows(&this->results)){
					// チャンネルマップの登録を行う。
					sql.Format(_T("INSERT INTO channelmap VALUES(0,%d,2,0);"), tmpCh);
					if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;
				}
				this->dbCtrl.FreeResult(&this->results);
			}
		}
	}

	// 残ったチャンネルを削除する
	sql.Format(_T("DELETE FROM tuningdetail WHERE provider = '@_%s';"), loadTunerName.c_str());
	if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;

	// ついでにチューナーのないチャンネルを削除する
	sql  = L"DELETE channel FROM channel LEFT JOIN tuningdetail ON channel.idChannel = tuningdetail.idChannel WHERE tuningdetail.idChannel IS NULL;";
	if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;

	// ついでにチャンネルのないグループを削除する。
	sql  = L"DELETE groupmap FROM groupmap LEFT JOIN channel ON groupmap.idChannel = channel.idChannel WHERE channel.idChannel IS NULL;";
	if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;

	// ついでにチャンネルのないチャンネルマップも削除する
	sql  = L"DELETE channelmap FROM channelmap LEFT JOIN channel ON channelmap.idChannel = channel.idChannel WHERE channel.idChannel IS NULL;";
	if (this->dbCtrl.Query(&this->mysql, sql) != 0) goto ESC;

	this->dbCtrl.Commit(&this->mysql);
	this->dbCtrl.UnlockTable(&this->mysql);
	this->dbCtrl.Close(&this->mysql);
	return TRUE;

	ESC: 
	wstring err = L"";
	Format(err, L"ERROR SQL:%s", sql);
	AfxMessageBox(err.c_str(), NULL, MB_OK);
	this->dbCtrl.Rollback(&this->mysql);
	this->dbCtrl.UnlockTable(&this->mysql);
	this->dbCtrl.Close(&this->mysql);
	return FALSE;
}