//ファイル保存を開始する //戻り値: // TRUE(成功)、FALSE(失敗) //引数: // fileName [IN]保存ファイルフルパス(必要に応じて拡張子変えたりなど行う) // overWriteFlag [IN]同一ファイル名存在時に上書きするかどうか(TRUE:する、FALSE:しない) // createSize [IN]入力予想容量(188バイトTSでの容量。即時録画時など総時間未定の場合は0。延長などの可能性もあるので目安程度) BOOL CWriteMain::_StartSave( LPCWSTR fileName, BOOL overWriteFlag, ULONGLONG createSize, HINSTANCE hInstance ) { if( fileName == NULL ){ return FALSE; } this->savePath = L""; this->savePath = fileName; WCHAR filePath[512] = L""; GetModuleFileName(hInstance, filePath, 512); wstring folder = L""; wstring fileTitle = L""; wstring iniPath = L""; GetFileFolder(filePath, folder); GetFileTitle(filePath, fileTitle); wstring grfPath = L""; Format(grfPath, L"%s\\%s.grf", folder.c_str(), fileTitle.c_str()); Format(iniPath, L"%s\\%s.ini", folder.c_str(), fileTitle.c_str()); WCHAR buff[256] = L""; GetPrivateProfileString(L"SET", L"ext", L"ts", buff, 256, iniPath.c_str()); wstring ext = buff; if( ext.find(L".") == string::npos ){ Format(ext, L".%s", buff); } HANDLE file = _CreateDirectoryAndFile( grfPath.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if( file == INVALID_HANDLE_VALUE ){ //設定ファイルないので新規作成 dshowCtrl.CreateNewGraph(); }else{ CloseHandle(file); //設定ファイルあるのでロード dshowCtrl.LoadGraph(grfPath.c_str()); } wstring saveFileName = L""; wstring saveFolder = L""; GetFileFolder(fileName, saveFolder); GetFileTitle(fileName, saveFileName); wstring savePath = L""; Format(savePath, L"%s\\%s%s", saveFolder.c_str(), saveFileName.c_str(), ext.c_str()); BOOL ret = dshowCtrl.CreateRunGraph(savePath.c_str()); if( ret == TRUE ){ this->savePath = savePath; //dshowCtrl.ConnectRunGraph(); } return ret; }
BOOL CWriteMain::Start( LPCWSTR fileName, BOOL overWriteFlag, ULONGLONG createSize ) { Stop(); this->savePath = fileName; _OutputDebugString(L"★CWriteMain::Start CreateFile:%s\r\n", this->savePath.c_str()); this->file = _CreateDirectoryAndFile(this->savePath.c_str(), GENERIC_WRITE, FILE_SHARE_READ, NULL, overWriteFlag ? CREATE_ALWAYS : CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); if( this->file == INVALID_HANDLE_VALUE ){ _OutputDebugString(L"★CWriteMain::Start Err:0x%08X\r\n", GetLastError()); WCHAR szPath[_MAX_PATH]; WCHAR szDrive[_MAX_DRIVE]; WCHAR szDir[_MAX_DIR]; WCHAR szFname[_MAX_FNAME]; WCHAR szExt[_MAX_EXT]; _wsplitpath_s(fileName, szDrive, szDir, szFname, szExt); _wmakepath_s(szPath, szDrive, szDir, szFname, NULL); for( int i = 1; ; i++ ){ Format(this->savePath, L"%s-(%d)%s", szPath, i, szExt); this->file = CreateFile(this->savePath.c_str(), GENERIC_WRITE, FILE_SHARE_READ, NULL, overWriteFlag ? CREATE_ALWAYS : CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); if( this->file != INVALID_HANDLE_VALUE || i >= 999 ){ DWORD err = GetLastError(); _OutputDebugString(L"★CWriteMain::Start CreateFile:%s\r\n", this->savePath.c_str()); if( this->file != INVALID_HANDLE_VALUE ){ break; } _OutputDebugString(L"★CWriteMain::Start Err:0x%08X\r\n", err); this->savePath = L""; return FALSE; } } } //ディスクに容量を確保 if( createSize > 0 ){ LARGE_INTEGER stPos; stPos.QuadPart = createSize; SetFilePointerEx( this->file, stPos, NULL, FILE_BEGIN ); SetEndOfFile( this->file ); SetFilePointer( this->file, 0, NULL, FILE_BEGIN ); } this->wrotePos = 0; //コマンドに分岐出力 if( this->teeCmd.empty() == false ){ this->teeFile = CreateFile(this->savePath.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); if( this->teeFile != INVALID_HANDLE_VALUE ){ this->teeThreadStopFlag = FALSE; this->teeThread = (HANDLE)_beginthreadex(NULL, 0, TeeThread, this, 0, NULL); } } return TRUE; }
void CTunerBankCtrl::SaveProgramInfo(LPCWSTR recPath, const EPGDB_EVENT_INFO& info, bool append) const { wstring iniCommonPath; GetCommonIniPath(iniCommonPath); wstring infoFolder = GetPrivateProfileToString(L"SET", L"RecInfoFolder", L"", iniCommonPath.c_str()); ChkFolderPath(infoFolder); wstring savePath; if( infoFolder.empty() ){ savePath = recPath; }else{ GetFileName(recPath, savePath); savePath = infoFolder + L"\\" + savePath; } savePath += L".program.txt"; wstring serviceName; for( size_t i = 0; i < this->chList.size(); i++ ){ if( this->chList[i].originalNetworkID == info.original_network_id && this->chList[i].transportStreamID == info.transport_stream_id && this->chList[i].serviceID == info.service_id ){ serviceName = this->chList[i].serviceName; break; } } wstring outTextW; _ConvertEpgInfoText2(&info, outTextW, serviceName); string outText; WtoA(outTextW, outText); HANDLE hFile = _CreateDirectoryAndFile(savePath.c_str(), GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, NULL, append ? OPEN_ALWAYS : CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if( hFile != INVALID_HANDLE_VALUE ){ if( append ){ SetFilePointer(hFile, 0, NULL, FILE_END); outText = "\r\n-----------------------\r\n" + outText; } DWORD dwWrite; WriteFile(hFile, outText.c_str(), (DWORD)outText.size(), &dwWrite, NULL); CloseHandle(hFile); } }