void main(int argc,char **argv) { int fd; char *path; if(argc != 2){ printf("invalid argument!\n"); exit(1); } path = argv[1]; fd = _CreateFile(path,0770,O_RDONLY); printf("Creat file -- %s fd -- %d\n",path,fd); _CloseFile(fd); exit(0); }
FilePtr CFileManager::LoadFile(const SFileCreateDesc& Desc) { FilePtr pFile = _CreateFile( Desc ); if( VKE_SUCCEEDED( _LoadFromFile( &pFile ) ) ) { } else { pFile->Release(); pFile = nullptr; } return pFile; }
void DICOMFile::OpenFile(char *filename, int applicationId) { _elements.clear(); _CreateFile(filename); MC_STATUS status = MC_Open_File(applicationId, _fileId, this, MediaToFile); if(status != MC_NORMAL_COMPLETION) throw std::invalid_argument("ERROR: Failed to open file.\n"); memset(buffer, 0, WORK_BUFFER_SIZE); fclose(fp); _FetchElements(_fileId, _elements); MC_Free_File(&_fileId); }
DWORD CSettingDlg::CreateSettingDialog(HINSTANCE hInstance) { DWORD dwRet = 0; WCHAR filePath[512] = L""; GetModuleFileName(hInstance, filePath, 512); wstring folder = L""; wstring fileTitle = L""; wstring iniPath = L""; GetFileFolder(filePath, folder); GetFileTitle(filePath, fileTitle); 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()); ext = buff; HANDLE file = _CreateFile( grfPath.c_str(), GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if( file == INVALID_HANDLE_VALUE ) { //設定ファイルないので新規作成 ctrl.CreateNewGraph(); } else { CloseHandle(file); //設定ファイルあるのでロード ctrl.LoadGraph(grfPath.c_str()); } dwRet = (DWORD)DialogBox(hInstance,MAKEINTRESOURCE(IDD_DIALOG_SET), NULL, (DLGPROC)DlgProc ); if( dwRet == IDOK ) { WritePrivateProfileString( L"SET", L"ext", ext.c_str(), iniPath.c_str() ); } return dwRet; }
// When this is running, no member variable should be accessed // from other threads status_t MovieEncoder::_EncoderThread() { int32 framesLeft = fFileList->CountItems(); int32 framesWritten = 0; if (framesLeft <= 0) { DisposeData(); BMessage message(kEncodingFinished); message.AddInt32("status", (int32)B_ERROR); fMessenger.SendMessage(&message); return B_ERROR; } // Create movie entry_ref movieRef; get_ref_for_path(fOutputFile.Path(), &movieRef); BitmapEntry* entry = fFileList->ItemAt(0); BBitmap* bitmap = entry->Bitmap(); BRect sourceFrame = bitmap->Bounds(); delete bitmap; if (!fDestFrame.IsValid()) fDestFrame = sourceFrame.OffsetToCopy(B_ORIGIN); // Calc the average time difference between the first 100 frames, // and use it to calculate the framerate. // TODO: Actually we could just calculate the number of frames and // the time difference between the first and the last one. /*int32 maxTimeStampNum = std::min((int32)100, fFileList->CountItems()); bigtime_t previousFrameTime = entry->TimeStamp(); bigtime_t diffSum = 0; for (int32 i = 0; i < maxTimeStampNum; i++) { BitmapEntry* entry = fFileList->ItemAt(i); bigtime_t currentFrameTime = entry->TimeStamp(); diffSum += currentFrameTime - previousFrameTime; previousFrameTime = currentFrameTime; } float medianDiffTime = diffSum / maxTimeStampNum; */ int32 numFrames = fFileList->CountItems(); BitmapEntry* firstEntry = fFileList->ItemAt(0); BitmapEntry* lastEntry = fFileList->ItemAt(numFrames - 1); int frameSeconds = (1000000 * numFrames) / (lastEntry->TimeStamp() - firstEntry->TimeStamp()); media_format inputFormat = fFormat; inputFormat.u.raw_video.field_rate = frameSeconds; status_t status = _CreateFile(movieRef, fFileFormat, inputFormat, fCodecInfo); if (status < B_OK) { DisposeData(); BMessage message(kEncodingFinished); message.AddInt32("status", (int32)status); fMessenger.SendMessage(&message); return status; } // Bitmap and view used to convert the source bitmap // to the correct size and depth BBitmap* destBitmap = new BBitmap(fDestFrame, fColorSpace, true); BView* destDrawer = new BView(fDestFrame, "drawing view", B_FOLLOW_NONE, 0); if (destBitmap->Lock()) { destBitmap->AddChild(destDrawer); destBitmap->Unlock(); } const uint32 keyFrameFrequency = 10; // TODO: Make this tunable BMessage progressMessage(B_UPDATE_STATUS_BAR); progressMessage.AddFloat("delta", 1.0); destBitmap->Bounds().PrintToStream(); PrintMediaFormat(inputFormat); status = B_OK; while (BitmapEntry* entry = const_cast<FileList*>(fFileList)->Pop()) { if (fKillThread) break; bool keyFrame = (framesWritten % keyFrameFrequency == 0); BBitmap* frame = entry->Bitmap(); if (frame == NULL) { // TODO: What to do here ? Exit with an error ? std::cerr << "Error while loading bitmap entry" << std::endl; delete entry; continue; } // Draw scaled if (status == B_OK) { destBitmap->Lock(); destDrawer->DrawBitmap(frame, frame->Bounds(), destDrawer->Bounds()); destDrawer->Sync(); destBitmap->Unlock(); } delete frame; delete entry; if (status == B_OK) status = _WriteFrame(destBitmap, keyFrame); if (status != B_OK) break; framesWritten++; if (fMessenger.IsValid()) fMessenger.SendMessage(new BMessage(progressMessage)); else { // BMessenger is no longer valid. This means that the application // has been closed or it has crashed. break; } } delete destBitmap; DisposeData(); if (fMessenger.IsValid()) { BMessage message(kEncodingFinished); message.AddInt32("status", (int32)status); message.AddInt32("frames", (int32)framesWritten); fMessenger.SendMessage(&message); } return status; }
UINT WINAPI CEpgDBManager::LoadThread(LPVOID param) { CEpgDBManager* sys = (CEpgDBManager*)param; OutputDebugString(L"Start Load EpgData\r\n"); DWORD time = GetTickCount(); CEpgDataCap3Util epgUtil; if( epgUtil.Initialize(FALSE) == FALSE ){ OutputDebugString(L"★EpgDataCap3.dllの初期化に失敗しました。\r\n"); return 0; } //EPGファイルの検索 vector<wstring> epgFileList; wstring epgDataPath = L""; GetSettingPath(epgDataPath); epgDataPath += EPG_SAVE_FOLDER; wstring searchKey = epgDataPath; searchKey += L"\\*_epg.dat"; WIN32_FIND_DATA findData; HANDLE find; //指定フォルダのファイル一覧取得 find = FindFirstFile( searchKey.c_str(), &findData); if ( find == INVALID_HANDLE_VALUE ) { //1つも存在しない epgUtil.UnInitialize(); return 0; } do{ if( (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0 ){ //本当に拡張子DLL? if( IsExt(findData.cFileName, L".dat" ) == TRUE ){ //見つかったファイルを一覧に追加 wstring epgFilePath = L""; Format(epgFilePath, L"%s\\%s", epgDataPath.c_str(), findData.cFileName); epgFileList.push_back(epgFilePath); } } }while(FindNextFile(find, &findData)); FindClose(find); //EPGファイルの解析 for( size_t i=0; i<epgFileList.size(); i++ ){ HANDLE file = _CreateFile( epgFileList[i].c_str(), GENERIC_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if( file != INVALID_HANDLE_VALUE ){ FILETIME CreationTime; FILETIME LastAccessTime; FILETIME LastWriteTime; GetFileTime(file, &CreationTime, &LastAccessTime, &LastWriteTime); LONGLONG fileTime = ((LONGLONG)LastWriteTime.dwHighDateTime)<<32 | (LONGLONG)LastWriteTime.dwLowDateTime; if( fileTime + 7*24*60*60*I64_1SEC < GetNowI64Time() ){ //1週間以上前のファイルなので削除 CloseHandle(file); DeleteFile( epgFileList[i].c_str() ); _OutputDebugString(L"★delete %s", epgFileList[i].c_str()); }else{ DWORD fileSize = GetFileSize( file, NULL ); BYTE readBuff[188*1024]; DWORD readSize = 0; while( readSize < fileSize ){ if( ::WaitForSingleObject(sys->loadStopEvent, 0) != WAIT_TIMEOUT ){ //キャンセルされた CloseHandle(file); epgUtil.UnInitialize(); return 0; } DWORD read=0; ReadFile( file, &readBuff, 188*1024, &read, NULL ); for( DWORD i=0; i<read; i+=188 ){ epgUtil.AddTSPacket(readBuff+i, 188); } readSize+=read; Sleep(0); } CloseHandle(file); } } Sleep(0); } //EPGデータを取得 DWORD serviceListSize = 0; SERVICE_INFO* serviceList = NULL; if( epgUtil.GetServiceListEpgDB(&serviceListSize, &serviceList) == FALSE ){ epgUtil.UnInitialize(); return 0; } for( DWORD i=0; i<serviceListSize; i++ ){ LONGLONG key = _Create64Key(serviceList[i].original_network_id, serviceList[i].transport_stream_id, serviceList[i].service_id); EPGDB_SERVICE_DATA* item = new EPGDB_SERVICE_DATA; item->serviceInfo.ONID = serviceList[i].original_network_id; item->serviceInfo.TSID = serviceList[i].transport_stream_id; item->serviceInfo.SID = serviceList[i].service_id; if( serviceList[i].extInfo != NULL ){ item->serviceInfo.service_type = serviceList[i].extInfo->service_type; item->serviceInfo.partialReceptionFlag = serviceList[i].extInfo->partialReceptionFlag; if( serviceList[i].extInfo->service_provider_name != NULL ){ item->serviceInfo.service_provider_name = serviceList[i].extInfo->service_provider_name; } if( serviceList[i].extInfo->service_name != NULL ){ item->serviceInfo.service_name = serviceList[i].extInfo->service_name; } if( serviceList[i].extInfo->network_name != NULL ){ item->serviceInfo.network_name = serviceList[i].extInfo->network_name; } if( serviceList[i].extInfo->ts_name != NULL ){ item->serviceInfo.ts_name = serviceList[i].extInfo->ts_name; } item->serviceInfo.remote_control_key_id = serviceList[i].extInfo->remote_control_key_id; } sys->epgMap.insert(pair<LONGLONG, EPGDB_SERVICE_DATA*>(key, item)); DWORD epgInfoListSize = 0; EPG_EVENT_INFO* epgInfoList = NULL; if( epgUtil.GetEpgInfoList(item->serviceInfo.ONID, item->serviceInfo.TSID, item->serviceInfo.SID, &epgInfoListSize, &epgInfoList) == TRUE ){ for( DWORD j=0; j<epgInfoListSize; j++ ){ EPGDB_EVENT_INFO* itemEvent = new EPGDB_EVENT_INFO; sys->ConvertEpgInfo(item->serviceInfo.ONID, item->serviceInfo.TSID, item->serviceInfo.SID, epgInfoList+j, itemEvent); item->eventMap.insert(pair<WORD, EPGDB_EVENT_INFO*>(itemEvent->event_id, itemEvent)); } } Sleep(0); } _OutputDebugString(L"End Load EpgData %dmsec\r\n", GetTickCount()-time); epgUtil.UnInitialize(); return 0; }