Exemple #1
0
//ファイル保存を開始する
//戻り値:
// TRUE(成功)、FALSE(失敗)
//引数:
// fileName				[IN]保存ファイルフルパス(必要に応じて拡張子変えたりなど行う)
// overWriteFlag		[IN]同一ファイル名存在時に上書きするかどうか(TRUE:する、FALSE:しない)
// createSize			[IN]入力予想容量(188バイトTSでの容量。即時録画時など総時間未定の場合は0。延長などの可能性もあるので目安程度)
BOOL CWriteMain::_StartSave(
	LPCWSTR fileName,
	BOOL overWriteFlag,
	ULONGLONG createSize
	)
{
	this->savePath = L"";

	wstring errMsg = L"";
	DWORD err = 0;

	wstring recFilePath = fileName;
	if( overWriteFlag == TRUE ){
		_OutputDebugString(L"★_StartSave CreateFile:%s", recFilePath.c_str());
		this->file = _CreateFile2( recFilePath.c_str(), GENERIC_WRITE, FILE_SHARE_READ, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
		if( this->file == INVALID_HANDLE_VALUE ){
			err = GetLastError();
			GetLastErrMsg(err, errMsg);
			_OutputDebugString(L"★_StartSave Err:0x%08X %s", err, errMsg.c_str());
			if( GetNextFileName(fileName, recFilePath) == TRUE ){
				_OutputDebugString(L"★_StartSave CreateFile:%s", recFilePath.c_str());
				this->file = _CreateFile2( recFilePath.c_str(), GENERIC_WRITE, FILE_SHARE_READ, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
			}
		}
	}else{
		_OutputDebugString(L"★_StartSave CreateFile:%s", recFilePath.c_str());
		this->file = _CreateFile2( recFilePath.c_str(), GENERIC_WRITE, FILE_SHARE_READ, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL );
		if( this->file == INVALID_HANDLE_VALUE ){
			err = GetLastError();
			GetLastErrMsg(err, errMsg);
			_OutputDebugString(L"★_StartSave Err:0x%08X %s", err, errMsg.c_str());
			if( GetNextFileName(fileName, recFilePath) == TRUE ){
				_OutputDebugString(L"★_StartSave CreateFile:%s", recFilePath.c_str());
				this->file = _CreateFile2( recFilePath.c_str(), GENERIC_WRITE, FILE_SHARE_READ, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL );
			}
		}
	}
	if( this->file == INVALID_HANDLE_VALUE ){
		err = GetLastError();
		GetLastErrMsg(err, errMsg);
		_OutputDebugString(L"★_StartSave Err:0x%08X %s", err, errMsg.c_str());
		this->file = NULL;
		return FALSE;
	}

	//ディスクに容量を確保
	if( createSize > 0 ){
		LARGE_INTEGER stPos;
		stPos.QuadPart = createSize;
		SetFilePointerEx( this->file, stPos, NULL, FILE_BEGIN );
		SetEndOfFile( this->file );
		CloseHandle( this->file );
		this->file = _CreateFile2( recFilePath.c_str(), GENERIC_WRITE, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
		SetFilePointer( this->file, 0, NULL, FILE_BEGIN );
	}

	this->savePath = recFilePath;

	return TRUE;
}
Exemple #2
0
BOOL CParseSearchChgText::ParseReserveText(LPCWSTR filePath)
{
	if( filePath == NULL ){
		return FALSE;
	}

	this->chgKey.clear();

	HANDLE hFile = _CreateFile2( filePath, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
	if( hFile == INVALID_HANDLE_VALUE ){
		return FALSE;
	}
	DWORD dwFileSize = GetFileSize( hFile, NULL );
	if( dwFileSize == 0 ){
		CloseHandle(hFile);
		return TRUE;
	}
	char* pszBuff = new char[dwFileSize+1];
	if( pszBuff == NULL ){
		CloseHandle(hFile);
		return FALSE;
	}
	ZeroMemory(pszBuff,dwFileSize+1);
	DWORD dwRead=0;
	ReadFile( hFile, pszBuff, dwFileSize, &dwRead, NULL );

	string strRead = pszBuff;

	CloseHandle(hFile);
	SAFE_DELETE_ARRAY(pszBuff)

	string parseLine="";
	int iIndex = 0;
	DWORD dwCount = 1;
	while( iIndex != (int)string::npos ){
		iIndex = (int)strRead.find("\r\n");
		if( iIndex == (int)string::npos ){
			parseLine = strRead;
			strRead.clear();
		}else{
			parseLine = strRead.substr(0,iIndex);
			strRead.erase( 0, iIndex+2 );
		}
		//先頭;はコメント行
		if( parseLine.find(";") != 0 ){
			//空行?
			if( parseLine.find("\t") != string::npos ){
				CHG_INFO Item;
				BOOL bRet = Parse1Line(parseLine, Item.oldText, Item.newText);
				if( bRet == TRUE ){
					this->chgKey.push_back(Item);
				}
			}
		}
	}

	return TRUE;
}
Exemple #3
0
BOOL DLNAParsePublicFolder::ParseText(LPCWSTR filePath)
{
	if( filePath == NULL ){
		return FALSE;
	}

	this->folderList.clear();

	HANDLE hFile = _CreateFile2( filePath, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
	if( hFile == INVALID_HANDLE_VALUE ){
		return FALSE;
	}
	DWORD dwFileSize = GetFileSize( hFile, NULL );
	if( dwFileSize == 0 ){
		CloseHandle(hFile);
		return TRUE;
	}
	char* pszBuff = new char[dwFileSize+1];
	if( pszBuff == NULL ){
		CloseHandle(hFile);
		return FALSE;
	}
	ZeroMemory(pszBuff,dwFileSize+1);
	DWORD dwRead=0;
	ReadFile( hFile, pszBuff, dwFileSize, &dwRead, NULL );

	string strRead = pszBuff;

	CloseHandle(hFile);
	SAFE_DELETE_ARRAY(pszBuff)

	string parseLine="";
	size_t iIndex = 0;
	size_t iFind = 0;
	while( iFind != string::npos ){
		iFind = strRead.find("\r\n", iIndex);
		if( iFind == (int)string::npos ){
			parseLine = strRead.substr(iIndex);
			//strRead.clear();
		}else{
			parseLine = strRead.substr(iIndex,iFind-iIndex);
			//strRead.erase( 0, iIndex+2 );
			iIndex = iFind + 2;
		}
		if( parseLine.find(";") != 0 ){
			DLNA_PUBLIC_FOLDER_INFO Item;
			if( Parse1Line(parseLine, &Item) == TRUE ){
				this->folderList.insert( pair<wstring, DLNA_PUBLIC_FOLDER_INFO>(Item.virtualPath,Item) );
			}
		}
	}

	return TRUE;
}
Exemple #4
0
BOOL CParseChText4::ParseText(LPCWSTR filePath)
{
	if( filePath == NULL ){
		return FALSE;
	}

	this->chList.clear();
	this->filePath = filePath;

	HANDLE hFile = _CreateFile2( filePath, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
	if( hFile == INVALID_HANDLE_VALUE ){
		return FALSE;
	}
	DWORD dwFileSize = GetFileSize( hFile, NULL );
	if( dwFileSize == 0 ){
		CloseHandle(hFile);
		return TRUE;
	}
	char* pszBuff = new char[dwFileSize+1];
	if( pszBuff == NULL ){
		CloseHandle(hFile);
		return FALSE;
	}
	ZeroMemory(pszBuff,dwFileSize+1);
	DWORD dwRead=0;
	ReadFile( hFile, pszBuff, dwFileSize, &dwRead, NULL );

	string strRead = pszBuff;

	CloseHandle(hFile);
	SAFE_DELETE_ARRAY(pszBuff)

	string parseLine="";
	size_t iIndex = 0;
	size_t iFind = 0;
	while( iFind != string::npos ){
		iFind = strRead.find("\r\n", iIndex);
		if( iFind == (int)string::npos ){
			parseLine = strRead.substr(iIndex);
			//strRead.clear();
		}else{
			parseLine = strRead.substr(iIndex,iFind-iIndex);
			//strRead.erase( 0, iIndex+2 );
			iIndex = iFind + 2;
		}
		CH_DATA4 Item;
		if( Parse1Line(parseLine, &Item) == TRUE ){
			LONGLONG iKey = _Create64Key(Item.originalNetworkID, Item.transportStreamID, Item.serviceID );
			this->chList.insert( pair<LONGLONG, CH_DATA4>(iKey,Item) );
		}
	}

	return TRUE;
}
Exemple #5
0
__int64 CHttpFileSend::GetContentLength(wstring filePath)
{
	HANDLE hFile = _CreateFile2( filePath.c_str(), GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
	if( hFile == INVALID_HANDLE_VALUE ){
		return 0;
	}
	DWORD sizeH = 0;
	DWORD sizeL = GetFileSize( hFile, &sizeH );

	__int64 fileSize = 0;

	fileSize = ((__int64)sizeH)<<32 | sizeL;

	CloseHandle(hFile);

	return fileSize;
}
Exemple #6
0
BOOL CParseRecInfoText::ParseRecInfoText(LPCWSTR filePath)
{
	if( filePath == NULL ){
		return FALSE;
	}

	multimap<wstring, REC_FILE_INFO*>::iterator itr;
	for( itr = this->recInfoMap.begin(); itr != this->recInfoMap.end(); itr++ ){
		SAFE_DELETE(itr->second)
	}
	this->recInfoMap.clear();
	this->recIDMap.clear();
	this->nextID = 1;

	this->loadFilePath = filePath;

	HANDLE hFile = _CreateFile2( filePath, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
	if( hFile == INVALID_HANDLE_VALUE ){
		return FALSE;
	}
	DWORD dwFileSize = GetFileSize( hFile, NULL );
	if( dwFileSize == 0 ){
		CloseHandle(hFile);
		return TRUE;
	}
	char* pszBuff = new char[dwFileSize+1];
	if( pszBuff == NULL ){
		CloseHandle(hFile);
		return FALSE;
	}
	ZeroMemory(pszBuff,dwFileSize+1);
	DWORD dwRead=0;
	ReadFile( hFile, pszBuff, dwFileSize, &dwRead, NULL );

	string strRead = pszBuff;

	CloseHandle(hFile);
	SAFE_DELETE_ARRAY(pszBuff);

	string parseLine="";
	size_t iIndex = 0;
	size_t iFind = 0;
	while( iFind != string::npos ){
		iFind = strRead.find("\r\n", iIndex);
		if( iFind == (int)string::npos ){
			parseLine = strRead.substr(iIndex);
			//strRead.clear();
		}else{
			parseLine = strRead.substr(iIndex,iFind-iIndex);
			//strRead.erase( 0, iIndex+2 );
			iIndex = iFind + 2;
		}
		//先頭;はコメント行
		if( parseLine.find(";") != 0 ){
			//空行?
			if( parseLine.find("\t") != string::npos ){
				REC_FILE_INFO* item = new REC_FILE_INFO;
				BOOL bRet = Parse1Line(parseLine, item);
				if( bRet == FALSE ){
					SAFE_DELETE(item)
				}else{
					wstring strKey;
					Format(strKey, L"%04d%02d%02d%02d%02d%02d%04X%04X",
							item->startTime.wYear,
							item->startTime.wMonth,
							item->startTime.wDay,
							item->startTime.wHour,
							item->startTime.wMinute,
							item->startTime.wSecond,
							item->originalNetworkID,
							item->transportStreamID);

					item->id = GetNextReserveID();
					this->recInfoMap.insert( pair<wstring, REC_FILE_INFO*>(strKey,item) );
					this->recIDMap.insert( pair<DWORD, REC_FILE_INFO*>(item->id,item) );
				}
			}
		}
	}
BOOL CParseEpgAutoAddText::ParseText(LPCWSTR filePath)
{
	if( filePath == NULL ){
		return FALSE;
	}

	map<DWORD, EPG_AUTO_ADD_DATA*>::iterator itr;
	for( itr = this->dataIDMap.begin(); itr != this->dataIDMap.end(); itr++ ){
		SAFE_DELETE(itr->second)
	}
	this->dataIDMap.clear();
	this->nextID = 1;

	this->loadFilePath = filePath;

	HANDLE hFile = _CreateFile2( filePath, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
	if( hFile == INVALID_HANDLE_VALUE ){
		return FALSE;
	}
	DWORD dwFileSize = GetFileSize( hFile, NULL );
	if( dwFileSize == 0 ){
		CloseHandle(hFile);
		return TRUE;
	}
	char* pszBuff = new char[dwFileSize+1];
	if( pszBuff == NULL ){
		CloseHandle(hFile);
		return FALSE;
	}
	ZeroMemory(pszBuff,dwFileSize+1);
	DWORD dwRead=0;
	ReadFile( hFile, pszBuff, dwFileSize, &dwRead, NULL );

	string strRead = pszBuff;

	CloseHandle(hFile);
	SAFE_DELETE_ARRAY(pszBuff)

	string parseLine="";
	size_t iIndex = 0;
	size_t iFind = 0;
	while( iFind != string::npos ){
		iFind = strRead.find("\r\n", iIndex);
		if( iFind == (int)string::npos ){
			parseLine = strRead.substr(iIndex);
			//strRead.clear();
		}else{
			parseLine = strRead.substr(iIndex,iFind-iIndex);
			//strRead.erase( 0, iIndex+2 );
			iIndex = iFind + 2;
		}
		//先頭;はコメント行
		if( parseLine.find(";") != 0 ){
			//空行?
			if( parseLine.find("\t") != string::npos ){
				EPG_AUTO_ADD_DATA* item = new EPG_AUTO_ADD_DATA;
				BOOL bRet = Parse1Line(parseLine, item);
				if( bRet == FALSE ){
					SAFE_DELETE(item)
				}else{
					item->dataID = GetNextID();
					this->dataIDMap.insert( pair<DWORD, EPG_AUTO_ADD_DATA*>(item->dataID,item) );
				}
			}
		}
	}
Exemple #8
0
int CHttpFileSend::SendFile(wstring filePath, __int64 offset, __int64 endPos, SOCKET clientSock, HANDLE stopEvent)
{
	int ret = NO_ERR;

	HANDLE hFile = _CreateFile2( filePath.c_str(), GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
	if( hFile == INVALID_HANDLE_VALUE ){
		return ERR_FALSE;
	}
	DWORD sizeH = 0;
	DWORD sizeL = GetFileSize( hFile, &sizeH );

	__int64 fileSize = 0;

	fileSize = ((__int64)sizeH)<<32 | sizeL;

	if( endPos >= 0 ){
		fileSize = endPos;
	}

	DWORD buffSize = 256*1024;
	DWORD readSize = 0;
	__int64 totalReadSize = 0;
	BYTE* readBuff = NULL;

	DWORD read;
	DWORD totalSendSize = 0;

	readBuff = new BYTE[buffSize];
	totalReadSize = offset;

	LONG setH = (LONG)(offset>>32);
	LONG setL = (LONG)(offset & 0x00000000FFFFFFFF);
	SetFilePointer(hFile, setL, &setH, FILE_BEGIN);

	fd_set ready;
	struct timeval to;
	int result;

	u_long val=1;
	int sock_buf_size = 1024*1024;

	ioctlsocket(clientSock, FIONBIO, &val);
	setsockopt( clientSock, SOL_SOCKET, SO_SNDBUF, (char *)&sock_buf_size, sizeof(sock_buf_size) );




	while(totalReadSize < fileSize){
		if( WaitForSingleObject( stopEvent, 0 ) != WAIT_TIMEOUT ){
			//中止
			break;
		}

		if(totalReadSize+buffSize < fileSize){
			readSize = buffSize;
		}else{
			readSize = (DWORD)(fileSize-totalReadSize);
		}
		ReadFile(hFile, readBuff, readSize, &read, NULL );

		totalSendSize = 0;

		while(totalSendSize<readSize){
			if( WaitForSingleObject( stopEvent, 0 ) != WAIT_TIMEOUT ){
				//中止
				ret = ERR_FALSE;
				goto Err_End;
			}

			to.tv_sec = 0;
			to.tv_usec = 500*1000;
			FD_ZERO(&ready);
			FD_SET(clientSock, &ready);

			result = select(0, NULL, &ready, NULL, &to );
			if( result == SOCKET_ERROR ){
				int a = WSAGetLastError();
				ret = ERR_FALSE;
				goto Err_End;
			}
			if ( FD_ISSET(clientSock, &ready) ){
				result = send(clientSock, (char*)readBuff+totalSendSize, readSize-totalSendSize, 0);
				if( result == SOCKET_ERROR || result == 0){
					if (WSAGetLastError() == WSAEWOULDBLOCK) {
						continue;
					}

				int a = WSAGetLastError();
					ret = ERR_FALSE;
					goto Err_End;
				}
				totalSendSize+=result;
			}
		}
		totalReadSize+=readSize;
	}

Err_End:
	CloseHandle(hFile);
	SAFE_DELETE_ARRAY(readBuff);

	return ret;
}
Exemple #9
0
BOOL CBatManager::CreateBatFile(BAT_WORK_INFO* info, wstring batSrcFilePath, wstring& batFilePath )
{
	if( info == NULL ){
		return FALSE;
	}
	GetModuleFolderPath(batFilePath);
	batFilePath+=L"\\EpgTimer_Bon_RecEnd.bat";

	//バッチの作成
	HANDLE hRead = CreateFileW( batSrcFilePath.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
	if( hRead == INVALID_HANDLE_VALUE ){
		return FALSE;
	}
	HANDLE hWrite = _CreateFile2( batFilePath.c_str(), GENERIC_WRITE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
	if( hWrite == INVALID_HANDLE_VALUE ){
		CloseHandle(hRead);
		return FALSE;
	}

	DWORD dwRead=0;
	DWORD dwL = GetFileSize(hRead, NULL);
	char* pBuff = new char[dwL+1];
	ZeroMemory(pBuff, dwL+1);
	ReadFile(hRead, pBuff, dwL, &dwRead, NULL );
	CloseHandle(hRead);

	string strRead = "";
	strRead = pBuff;
	SAFE_DELETE_ARRAY(pBuff);

	string strRecFilePath="";
	string strFolderPath="";
	string strFileName="";
	string strTitle="";
	string strSDYYYY="";
	string strSDYY="";
	string strSDMM="";
	string strSDM="";
	string strSDDD="";
	string strSDD="";
	string strSDW="";
	string strSTHH="";
	string strSTH="";
	string strSTMM="";
	string strSTM="";
	string strSTSS="";
	string strSTS="";
	string strEDYYYY="";
	string strEDYY="";
	string strEDMM="";
	string strEDM="";
	string strEDDD="";
	string strEDD="";
	string strEDW="";
	string strETHH="";
	string strETH="";
	string strETMM="";
	string strETM="";
	string strETSS="";
	string strETS="";
	string strONID10="";
	string strTSID10="";
	string strSID10="";
	string strEID10="";
	string strONID16="";
	string strTSID16="";
	string strSID16="";
	string strEID16="";
	string strServiceName="";
	string strSDYYYY28="";
	string strSDYY28="";
	string strSDMM28="";
	string strSDM28="";
	string strSDDD28="";
	string strSDD28="";
	string strSDW28="";
	string strSTHH28="";
	string strSTH28="";
	string strEDYYYY28="";
	string strEDYY28="";
	string strEDMM28="";
	string strEDM28="";
	string strEDDD28="";
	string strEDD28="";
	string strEDW28="";
	string strETHH28="";
	string strETH28="";
	string strDUH="";
	string strDUHH="";
	string strDUM="";
	string strDUMM="";
	string strDUS="";
	string strDUSS="";
	string strTitle2="";
	string strDrops="";
	string strScrambles="";
	string strResult="";
	string strTitleF="";
	string strTitle2F="";
	string strAddKey="";

	WtoA(info->recFileInfo.recFilePath, strRecFilePath);

	WCHAR szDrive[_MAX_DRIVE];
	WCHAR szDir[_MAX_DIR];
	WCHAR szFname[_MAX_FNAME];
	WCHAR szExt[_MAX_EXT];
	WCHAR szPath[_MAX_PATH] = L"";
	_tsplitpath_s( info->recFileInfo.recFilePath.c_str(), szDrive, _MAX_DRIVE, szDir, _MAX_DIR, szFname, _MAX_FNAME, szExt, _MAX_EXT );
	_tmakepath_s( szPath, _MAX_PATH, szDrive, szDir, NULL, NULL );
	wstring strFolder;
	strFolder = szPath;
	ChkFolderPath(strFolder);

	WtoA(szFname, strFileName);
	WtoA(strFolder, strFolderPath);
	WtoA(info->recFileInfo.title, strTitle);

	Format(strSDYYYY, "%04d", info->recFileInfo.startTime.wYear);
	Format(strSDYY, "%02d", info->recFileInfo.startTime.wYear%100);
	Format(strSDMM, "%02d", info->recFileInfo.startTime.wMonth);
	Format(strSDM, "%d", info->recFileInfo.startTime.wMonth);
	Format(strSDDD, "%02d", info->recFileInfo.startTime.wDay);
	Format(strSDD, "%d", info->recFileInfo.startTime.wDay);
	GetDayOfWeekString2(info->recFileInfo.startTime, strSDW);
	Format(strSTHH, "%02d", info->recFileInfo.startTime.wHour);
	Format(strSTH, "%d", info->recFileInfo.startTime.wHour);
	Format(strSTMM, "%02d", info->recFileInfo.startTime.wMinute);
	Format(strSTM, "%d", info->recFileInfo.startTime.wMinute);
	Format(strSTSS, "%02d", info->recFileInfo.startTime.wSecond);
	Format(strSTS, "%d", info->recFileInfo.startTime.wSecond);

	SYSTEMTIME t28TimeS;
	if( 0 <= info->recFileInfo.startTime.wHour && info->recFileInfo.startTime.wHour < 4 ){
		GetSumTime(info->recFileInfo.startTime, -24*60*60, &t28TimeS);
		GetDayOfWeekString2(t28TimeS, strSDW28);
		t28TimeS.wHour+=24;
	}else{
		t28TimeS = info->recFileInfo.startTime;
		GetDayOfWeekString2(t28TimeS, strSDW28);
	}

	Format(strSDYYYY28, "%04d", t28TimeS.wYear);
	Format(strSDYY28, "%02d", t28TimeS.wYear%100);
	Format(strSDMM28, "%02d", t28TimeS.wMonth);
	Format(strSDM28, "%d", t28TimeS.wMonth);
	Format(strSDDD28, "%02d", t28TimeS.wDay);
	Format(strSDD28, "%d", t28TimeS.wDay);
	Format(strSTHH28, "%02d", t28TimeS.wHour);
	Format(strSTH28, "%d", t28TimeS.wHour);

	SYSTEMTIME tEnd;
	GetI64Time(info->recFileInfo.startTime, info->recFileInfo.durationSecond, NULL, NULL, &tEnd);

	Format(strEDYYYY, "%04d", tEnd.wYear);
	Format(strEDYY, "%02d", tEnd.wYear%100);
	Format(strEDMM, "%02d", tEnd.wMonth);
	Format(strEDM, "%d", tEnd.wMonth);
	Format(strEDDD, "%02d", tEnd.wDay);
	Format(strEDD, "%d", tEnd.wDay);
	GetDayOfWeekString2(tEnd, strEDW);
	Format(strETHH, "%02d", tEnd.wHour);
	Format(strETH, "%d", tEnd.wHour);
	Format(strETMM, "%02d", tEnd.wMinute);
	Format(strETM, "%d", tEnd.wMinute);
	Format(strETSS, "%02d", tEnd.wSecond);
	Format(strETS, "%d", tEnd.wSecond);

	SYSTEMTIME t28TimeE;
	if( 0 <= tEnd.wHour && tEnd.wHour < 4 ){
		GetSumTime(tEnd, -24*60*60, &t28TimeE);
		GetDayOfWeekString2(t28TimeE, strEDW28);
		t28TimeE.wHour+=24;
	}else{
		t28TimeE = tEnd;
		GetDayOfWeekString2(tEnd, strEDW28);
	}

	Format(strEDYYYY28, "%04d", t28TimeE.wYear);
	Format(strEDYY28, "%02d", t28TimeE.wYear%100);
	Format(strEDMM28, "%02d", t28TimeE.wMonth);
	Format(strEDM28, "%d", t28TimeE.wMonth);
	Format(strEDDD28, "%02d", t28TimeE.wDay);
	Format(strEDD28, "%d", t28TimeE.wDay);
	Format(strETHH28, "%02d", t28TimeE.wHour);
	Format(strETH28, "%d", t28TimeE.wHour);

	Format(strONID10, "%d", info->recFileInfo.originalNetworkID);
	Format(strTSID10, "%d", info->recFileInfo.transportStreamID);
	Format(strSID10, "%d", info->recFileInfo.serviceID);
	Format(strEID10, "%d", info->recFileInfo.eventID);
	Format(strONID16, "%04X", info->recFileInfo.originalNetworkID);
	Format(strTSID16, "%04X", info->recFileInfo.transportStreamID);
	Format(strSID16, "%04X", info->recFileInfo.serviceID);
	Format(strEID16, "%04X", info->recFileInfo.eventID);

	WtoA(info->recFileInfo.serviceName, strServiceName);

	Format(strDUHH, "%02d", info->recFileInfo.durationSecond/(60*60));
	Format(strDUH, "%d", info->recFileInfo.durationSecond/(60*60));
	Format(strDUMM, "%02d", (info->recFileInfo.durationSecond%(60*60))/60);
	Format(strDUM, "%d", (info->recFileInfo.durationSecond%(60*60))/60);
	Format(strDUSS, "%02d", info->recFileInfo.durationSecond%60);
	Format(strDUS, "%d", info->recFileInfo.durationSecond%60);

	wstring strTemp = info->recFileInfo.title;
	while( (strTemp.find(L"[") != string::npos) && (strTemp.find(L"]") != string::npos) ){
		wstring strSep1=L"";
		wstring strSep2=L"";
		Separate(strTemp, L"[", strSep1, strTemp);
		Separate(strTemp, L"]", strSep2, strTemp);
		strSep1 += strTemp;
		strTemp = strSep1;
	}
	WtoA(strTemp, strTitle2);

	Format(strDrops, "%I64d", info->recFileInfo.drops);
	Format(strScrambles, "%I64d", info->recFileInfo.scrambles);
	WtoA(info->recFileInfo.comment, strResult);

	CheckFileName(strTitleF);
	CheckFileName(strTemp);
	WtoA(strTemp, strTitle2F);
	strTemp = info->recFileInfo.title;
	CheckFileName(strTemp);
	WtoA(strTemp, strTitleF);

	if( info->reserveInfo.comment.find(L"EPG自動予約(") != string::npos ){
		WtoA(info->reserveInfo.comment, strAddKey);
		Replace(strAddKey, "EPG自動予約(", "");
		strAddKey.erase(strAddKey.length()-1, 1);
	}

	Replace(strRead, "$FilePath$", strRecFilePath);
	Replace(strRead, "$FolderPath$", strFolderPath);
	Replace(strRead, "$FileName$", strFileName);
	Replace(strRead, "$Title$", strTitle);
	Replace(strRead, "$SDYYYY$", strSDYYYY);
	Replace(strRead, "$SDYY$", strSDYY);
	Replace(strRead, "$SDMM$", strSDMM);
	Replace(strRead, "$SDM$", strSDM);
	Replace(strRead, "$SDDD$", strSDDD);
	Replace(strRead, "$SDD$", strSDD);
	Replace(strRead, "$SDW$", strSDW);
	Replace(strRead, "$STHH$", strSTHH);
	Replace(strRead, "$STH$", strSTH);
	Replace(strRead, "$STMM$", strSTMM);
	Replace(strRead, "$STM$", strSTM);
	Replace(strRead, "$STSS$", strSTSS);
	Replace(strRead, "$STS$", strSTS);
	Replace(strRead, "$EDYYYY$", strEDYYYY);
	Replace(strRead, "$EDYY$", strEDYY);
	Replace(strRead, "$EDMM$", strEDMM);
	Replace(strRead, "$EDM$", strEDM);
	Replace(strRead, "$EDDD$", strEDDD);
	Replace(strRead, "$EDD$", strEDD);
	Replace(strRead, "$EDW$", strEDW);
	Replace(strRead, "$ETHH$", strETHH);
	Replace(strRead, "$ETH$", strETH);
	Replace(strRead, "$ETMM$", strETMM);
	Replace(strRead, "$ETM$", strETM);
	Replace(strRead, "$ETSS$", strETSS);
	Replace(strRead, "$ETS$", strETS);
	Replace(strRead, "$ONID10$", strONID10);
	Replace(strRead, "$TSID10$", strTSID10);
	Replace(strRead, "$SID10$", strSID10);
	Replace(strRead, "$EID10$", strEID10);
	Replace(strRead, "$ONID16$", strONID16);
	Replace(strRead, "$TSID16$", strTSID16);
	Replace(strRead, "$SID16$", strSID16);
	Replace(strRead, "$EID16$", strEID16);
	Replace(strRead, "$ServiceName$", strServiceName);
	Replace(strRead, "$SDYYYY28$", strSDYYYY28);
	Replace(strRead, "$SDYY28$", strSDYY28);
	Replace(strRead, "$SDMM28$", strSDMM28);
	Replace(strRead, "$SDM28$", strSDM28);
	Replace(strRead, "$SDDD28$", strSDDD28);
	Replace(strRead, "$SDD28$", strSDD28);
	Replace(strRead, "$SDW28$", strSDW28);
	Replace(strRead, "$STHH28$", strSTHH28);
	Replace(strRead, "$STH28$", strSTH28);
	Replace(strRead, "$EDYYYY28$", strEDYYYY28);
	Replace(strRead, "$EDYY28$", strEDYY28);
	Replace(strRead, "$EDMM28$", strEDMM28);
	Replace(strRead, "$EDM28$", strEDM28);
	Replace(strRead, "$EDDD28$", strEDDD28);
	Replace(strRead, "$EDD28$", strEDD28);
	Replace(strRead, "$EDW28$", strEDW28);
	Replace(strRead, "$ETHH28$", strETHH28);
	Replace(strRead, "$ETH28$", strETH28);
	Replace(strRead, "$DUHH$", strDUHH);
	Replace(strRead, "$DUH$", strDUH);
	Replace(strRead, "$DUMM$", strDUMM);
	Replace(strRead, "$DUM$", strDUM);
	Replace(strRead, "$DUSS$", strDUSS);
	Replace(strRead, "$DUS$", strDUS);
	Replace(strRead, "$Title2$", strTitle2);
	Replace(strRead, "$Drops$", strDrops);
	Replace(strRead, "$Scrambles$", strScrambles);
	Replace(strRead, "$Result$", strResult);
	Replace(strRead, "$TitleF$", strTitleF);
	Replace(strRead, "$Title2F$", strTitle2F);
	Replace(strRead, "$AddKey$", strAddKey);

	DWORD dwWrite=0;
	WriteFile(hWrite, strRead.c_str(), (DWORD)strRead.length(), &dwWrite, NULL );
	CloseHandle(hWrite);

	return TRUE;
}
Exemple #10
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;
}
Exemple #11
0
BOOL CParseChText5::SaveChText(LPCWSTR filePath)
{
	wstring loadFilePath = L"";
	if( filePath == NULL ){
		loadFilePath = this->filePath;
	}else{
		loadFilePath = filePath;
	}

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

	if( this->chList.size() == 0 ){
		return FALSE;
	}

	HANDLE hFile = _CreateFile2( loadFilePath.c_str(), GENERIC_WRITE, FILE_SHARE_READ, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
	if( hFile == INVALID_HANDLE_VALUE ){
		return FALSE;
	}

	multimap<LONGLONG, CH_DATA5> sortList;
	map<LONGLONG, CH_DATA5>::iterator itrCh;
	for( itrCh = this->chList.begin(); itrCh != this->chList.end(); itrCh++ ){
		int network;
		if( 0x7880 <= itrCh->second.originalNetworkID && itrCh->second.originalNetworkID <= 0x7FE8 ){
			if( itrCh->second.partialFlag == 0 ){
				network = 0; //地デジ
			}else{
				network = 1; //ワンセグ
			}
		}else if( itrCh->second.originalNetworkID == 0x04 ){
			network = 2; //BS
		}else if( itrCh->second.originalNetworkID == 0x06 || itrCh->second.originalNetworkID == 0x07 ){
			network = 3; //CS
		}else{
			network = 4; //その他
		}

		LONGLONG Key = ((LONGLONG)network)<<16 | (LONGLONG)itrCh->second.serviceID;
		sortList.insert(pair<LONGLONG, CH_DATA5>(Key, itrCh->second));
	}

	multimap<LONGLONG, CH_DATA5>::iterator itr;
	for( itr = sortList.begin(); itr != sortList.end(); itr++ ){
		string serviceName="";
		WtoA(itr->second.serviceName, serviceName);
		string networkName="";
		WtoA(itr->second.networkName, networkName);

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

	CloseHandle(hFile);
	return TRUE;
}
Exemple #12
0
BOOL CParseChText4::SaveChText(LPCWSTR filePath)
{
	wstring loadFilePath = L"";
	if( filePath == NULL ){
		loadFilePath = this->filePath;
	}else{
		loadFilePath = filePath;
	}

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

/*
	std::wregex re(L".+\\(.+)\(.+\)\.ChSet4\.txt$");
	
	
	std::wstring text(str);
	std::wsmatch m;

	if( std::regex_search(text, m, re) ) this->mpStartTimeShifting = m[1];
*/



	HANDLE hFile = _CreateFile2( loadFilePath.c_str(), GENERIC_WRITE, FILE_SHARE_READ, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
	if( hFile == INVALID_HANDLE_VALUE ){
		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));
	}

	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);
	return TRUE;
}