int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { WNDCLASSEX winClass; HWND hwnd; MSG msg; // Process command line LPWSTR *argv = NULL; int argc; int i; unsigned short tilingMode = DEFAULT_TILING_MODE; argv = CommandLineToArgvW(GetCommandLineW(), &argc); for (i = 0; i < argc; i++) { char arg[128]; wsprintfA(arg, "%S", argv[i]); if (i < (argc - 1)) { char nextarg[128]; wsprintfA(nextarg, "%S", argv[i + 1]); if (!strcmp(arg, "-o")) { alpha = atoi(nextarg); } else if (!strcmp(arg, "-i")) { if (ignoreCount < MAX_IGNORE) { sprintf(ignoreClasses[ignoreCount++], "%s", nextarg); } } else if (!strcmp(arg, "-a")) { include_mode = 1; // Include mode instead of exclude if (includeCount < MAX_IGNORE) { sprintf(includeClasses[includeCount++], "%s", nextarg); } } else if (!strcmp(arg, "-m")) { int y; modkeys = 0; for (y = 0; y < strlen(nextarg); y++) { switch (nextarg[y]) { case 'c': modkeys |= MOD_CONTROL; break; case 'a': modkeys |= MOD_ALT; break; case 's': modkeys |= MOD_SHIFT; break; case 'w': modkeys |= MOD_WIN; break; } } } else if (!strcmp(arg, "-t")) { tilingMode = atoi(nextarg); } else if (!strcmp(arg, "-left")) { screen_x = atoi(nextarg); } else if (!strcmp(arg, "-top")) { screen_y = atoi(nextarg); } else if (!strcmp(arg, "-width")) { screen_width = atoi(nextarg); } else if (!strcmp(arg, "-height")) { screen_height = atoi(nextarg); } } if (!strcmp(arg, "-v")) { MessageBox(NULL, VERSION, "Version", MB_OK); LocalFree(argv); return 1; } else if (!strcmp(arg, "-l")) { lockMouse = 1; } else if (!strcmp(arg, "-x")) { experimental_mouse = 1; } else if (!strcmp(arg, "--one-tag")) { one_tag_per_window = 1; } } // Initialize tags for (i = 0; i < TAGS; i++) { tags[i].nodes = NULL; tags[i].last_node = NULL; tags[i].current_window = NULL; tags[i].tilingMode = tilingMode; tags[i].masterarea_count = 1; } LocalFree(argv); winClass.cbSize = sizeof(WNDCLASSEX); winClass.style = 0; winClass.lpfnWndProc = WndProc; winClass.cbClsExtra = 0; winClass.cbWndExtra = 0; winClass.hInstance = hInstance; winClass.hIcon = NULL; winClass.hIconSm = NULL; winClass.hCursor = NULL; winClass.hbrBackground = NULL; winClass.lpszMenuName = NULL; winClass.lpszClassName = NAME; if (!RegisterClassEx(&winClass)) { MessageBox(NULL, "Error Registering Window Class", "Error", MB_OK | MB_ICONERROR); return 0; // Bail } hwnd = CreateWindowEx(0, NAME, NAME, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, hInstance, NULL); if (!hwnd) { MessageBox(NULL, "Error Creating Window", "Error", MB_OK | MB_ICONERROR); return 0; // Bail } if (!screen_x && !screen_y && !screen_width && !screen_height) { // Screen options aren't being specified from the command line so set some defaults RECT workarea; SystemParametersInfo(SPI_GETWORKAREA, 0, &workarea, 0); screen_x = workarea.left; screen_y = workarea.top; screen_width = workarea.right - workarea.left; screen_height = workarea.bottom - workarea.top; } RegisterHotkeys(hwnd); UpdateMousePos(hwnd); EnumWindows(EnumWindowsRestore, 0); // Restore windows on startup so they get tiled EnumWindows(EnumWindowsProc, 0); ArrangeWindows(); // Get function pointer for RegisterShellHookWindow if ( RegisterShellHookWindow_ == NULL ) { RegisterShellHookWindow_ = (BOOL (__stdcall *)(HWND))GetProcAddress(GetModuleHandle("USER32.DLL"), "RegisterShellHookWindow"); if (RegisterShellHookWindow_ == NULL) { MessageBox(NULL, "Could not find RegisterShellHookWindow", "Error", MB_OK | MB_ICONERROR); return 0; } } RegisterShellHookWindow_(hwnd); shellhookid = RegisterWindowMessage("SHELLHOOK"); // Grab a dynamic id for the SHELLHOOK message to be used later while (GetMessage(&msg, NULL, 0, 0) > 0) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; }
Tcl_Channel TclWinOpenConsoleChannel( HANDLE handle, char *channelName, int permissions) { char encoding[4 + TCL_INTEGER_SPACE]; ConsoleInfo *infoPtr; DWORD modes; ConsoleInit(); /* * See if a channel with this handle already exists. */ infoPtr = ckalloc(sizeof(ConsoleInfo)); memset(infoPtr, 0, sizeof(ConsoleInfo)); infoPtr->validMask = permissions; infoPtr->handle = handle; infoPtr->channel = (Tcl_Channel) NULL; wsprintfA(encoding, "cp%d", GetConsoleCP()); infoPtr->threadId = Tcl_GetCurrentThread(); /* * Use the pointer for the name of the result channel. This keeps the * channel names unique, since some may share handles (stdin/stdout/stderr * for instance). */ sprintf(channelName, "file%" TCL_I_MODIFIER "x", (size_t) infoPtr); infoPtr->channel = Tcl_CreateChannel(&consoleChannelType, channelName, infoPtr, permissions); if (permissions & TCL_READABLE) { /* * Make sure the console input buffer is ready for only character * input notifications and the buffer is set for line buffering. IOW, * we only want to catch when complete lines are ready for reading. */ GetConsoleMode(infoPtr->handle, &modes); modes &= ~(ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT); modes |= ENABLE_LINE_INPUT; SetConsoleMode(infoPtr->handle, modes); StartChannelThread(infoPtr, &infoPtr->reader, ConsoleReaderThread); } if (permissions & TCL_WRITABLE) { StartChannelThread(infoPtr, &infoPtr->writer, ConsoleWriterThread); } /* * Files have default translation of AUTO and ^Z eof char, which means * that a ^Z will be accepted as EOF when reading. */ Tcl_SetChannelOption(NULL, infoPtr->channel, "-translation", "auto"); Tcl_SetChannelOption(NULL, infoPtr->channel, "-eofchar", "\032 {}"); #ifdef UNICODE Tcl_SetChannelOption(NULL, infoPtr->channel, "-encoding", "unicode"); #else Tcl_SetChannelOption(NULL, infoPtr->channel, "-encoding", encoding); #endif return infoPtr->channel; }
void DataManager::ParseDeviceInfo(std::wstring deviceName) { std::wstring key = deviceName; wchar_t deviceFile[MAX_PATH] = {0}; wsprintfW(deviceFile, L"%s\\%s\\DeviceInfo", m_dirPath.c_str(), key.c_str()); HANDLE hDevice = CreateFileW( deviceFile, FILE_GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if ( INVALID_HANDLE_VALUE == hDevice ) { Utils::__TRACE(L"[DataManager] Create File Failed.[%s] [%d]\r\n", deviceFile, GetLastError()); wsprintfW(deviceFile, L"%s\\%s\\Device_Info.xml", m_dirPath.c_str(), key.c_str()); QFile xml(Utils::wtoq(deviceFile)); if ( !xml.open(QIODevice::ReadOnly | QIODevice::Text) ) return ; QDomDocument doc; if ( !doc.setContent(&xml, false) ) return; QString type = doc.documentElement().firstChildElement("type").text(); QString brand = doc.documentElement().firstChildElement("brand").text(); QString model = doc.documentElement().firstChildElement("model").text(); QString version = doc.documentElement().firstChildElement("version").text(); QString cpu = doc.documentElement().firstChildElement("cpu_abi").text(); QString imei = doc.documentElement().firstChildElement("imei").text(); bool root = doc.documentElement().firstChildElement("root").text() == "yes"; DEV_INFO devItem; memset(&devItem, 0, sizeof(DEV_INFO)); devItem.baseDevInfo.devType = DEV_TYPE_ANDROID; wsprintfA(devItem.baseDevInfo.szDevName, "%s", Utils::qtou(brand).c_str()); wsprintfA(devItem.baseDevInfo.szDevModel, "%s", Utils::qtou(model).c_str()); wsprintfA(devItem.baseDevInfo.szOSVersion, "%s", Utils::qtou(version).c_str()); wsprintfA(devItem.baseDevInfo.szCpuArc, "%s", Utils::qtou(cpu).c_str()); wsprintfA(devItem.baseDevInfo.szSerialNum, "%s", Utils::qtou(imei).c_str()); devItem.baseDevInfo.bJailBroken = root; m_deviceMap[key] = devItem; return; } SetFilePointer(hDevice, sizeof(LAST_STATUS), NULL, FILE_BEGIN); DEV_INFO devItem; DWORD readed = 0; ReadFile(hDevice, &devItem, sizeof(DEV_INFO), &readed, NULL); if ( !readed ) return; Utils::CastChar(devItem.baseDevInfo.szCpuArc, '\n'); Utils::CastChar(devItem.baseDevInfo.szOSVersion, '\n'); m_deviceMap[key] = devItem; CloseHandle(hDevice); }
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, char *CmdLine, int CmdShow) { bool uninstall_mode = false; char exe_name[MAX_PATH]; char exe_dir[MAX_PATH]; UINT os_ver = GetWindowsVersion(); CoInitialize(NULL); DisableWow64FsRedirection(); if (SeStartWith(CmdLine, "/uninstall")) { uninstall_mode = true; } GetModuleFileNameA(hInst, exe_name, sizeof(exe_name)); SeGetDirNameFromFilePath(exe_dir, sizeof(exe_dir), exe_name); if (uninstall_mode == false) { char driver_inf_filename[MAX_PATH] = {0}; bool install_driver = false; // Check the Windows version if (os_ver == OS_UNKNOWN) { MessageBoxA(NULL, "This operating system is not supported by Win10Pcap.\r\n\r\n" "Win10Pcap requires Windows 7, Server 2008 R2, Windows 8, Windows 8.1, Windows Server 2012, Windows Server 2012 R2 or Windows 10.", INSTALLER_TITLE, MB_ICONSTOP | MB_SYSTEMMODAL); return -1; } SeStrCpy(driver_inf_filename, sizeof(driver_inf_filename), exe_dir); if (os_ver == OS_WIN10) { SeStrCat(driver_inf_filename, sizeof(driver_inf_filename), "\\drivers\\win10"); } else { SeStrCat(driver_inf_filename, sizeof(driver_inf_filename), "\\drivers\\win78"); } SeStrCat(driver_inf_filename, sizeof(driver_inf_filename), "\\Win10Pcap.inf"); // Install the device driver if (Is64BitCode()) { // x64 install_driver = true; } else if (IsWow64() == false) { // x86 install_driver = true; } else { // Do nothing. } if (install_driver) { LABEL_RETRY_INSTALL_DRIVER: if (InstallNdisProtocolDriver(driver_inf_filename, L"Win10Pcap", 60 * 1000) == false) { if (MessageBoxA(NULL, "The install process of the Win10Pcap NDIS device driver failed.", INSTALLER_TITLE, MB_ICONEXCLAMATION | MB_SYSTEMMODAL | MB_RETRYCANCEL) == IDRETRY) { goto LABEL_RETRY_INSTALL_DRIVER; } else { return -1; } } MsStartService("Win10Pcap"); } if (InstallDllToSystem32(exe_dir, "Packet.dll", "Packet.dll") == false || InstallDllToSystem32(exe_dir, "wpcap.dll", "wpcap.dll") == false) { return -1; } if (Is64BitCode() == false && Is64BitWindows()) { // Run x64 char x64_exe[MAX_PATH]; wsprintfA(x64_exe, "%s\\..\\x64\\Installer.exe", exe_dir); Win32RunAndWaitProcess(x64_exe, CmdLine, false, false, INFINITE); } } else { bool uninstall_driver = false; UninstallDllFromSystem32("Packet.dll"); UninstallDllFromSystem32("wpcap.dll"); // Install the device driver if (Is64BitCode()) { // x64 uninstall_driver = true; } else if (IsWow64() == false) { // x86 uninstall_driver = true; } else { // Do nothing. } if (uninstall_driver) { LABEL_RETRY_UNINSTALL_DRIVER: if (UninstallNdisProtocolDriver(L"Win10Pcap", 60 * 1000) == false) { if (MessageBoxA(NULL, "The uninstall process of the Win10Pcap NDIS device driver failed.", INSTALLER_TITLE, MB_ICONEXCLAMATION | MB_SYSTEMMODAL | MB_RETRYCANCEL) == IDRETRY) { goto LABEL_RETRY_UNINSTALL_DRIVER; } } } if (Is64BitCode() == false && Is64BitWindows()) { // Run x64 char x64_exe[MAX_PATH]; wsprintfA(x64_exe, "%s\\..\\x64\\Installer.exe", exe_dir); Win32RunAndWaitProcess(x64_exe, CmdLine, false, false, INFINITE); } } CoUninitialize(); return 0; }
inline int ADbg::_OutPut(const char * format,va_list params) const { int result; char tst[1000]; char myformat[256]; #ifdef WIN32 if (my_time_included) { SYSTEMTIME time; GetSystemTime(&time); if (prefix[0] == '\0') wsprintfA(myformat,"%04d/%02d/%02d %02d:%02d:%02d.%03d UTC : %s\r\n", time.wYear, time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond, time.wMilliseconds, format); else wsprintfA(myformat,"%04d/%02d/%02d %02d:%02d:%02d.%03d UTC : %s - %s\r\n", time.wYear, time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond, time.wMilliseconds, prefix, format); } else { if (prefix[0] == '\0') wsprintfA( myformat, "%s\r\n", format); else wsprintfA( myformat, "%s - %s\r\n", prefix, format); } result = vsprintf(tst,myformat,params); if (my_debug_output) OutputDebugStringA(tst); if (my_use_file && (hFile != NULL)) { SetFilePointer( hFile, 0, 0, FILE_END ); DWORD written; WriteFile( hFile, tst, lstrlenA(tst), &written, NULL ); } #else if (my_time_included) { time_t nowSecs; struct tm *now; struct timeval tv; nowSecs = time(NULL); gettimeofday(&tv, NULL); now = gmtime(&nowSecs); if (prefix[0] == '\0') sprintf(myformat,"%04d/%02d/%02d %02d:%02d:%02ld.%03ld UTC : %s\r\n", now->tm_year, now->tm_mon, now->tm_mday, now->tm_hour, now->tm_min, tv.tv_sec, (long)tv.tv_usec / 1000, format); else sprintf(myformat,"%04d/%02d/%02d %02d:%02d:%02ld.%03ld UTC : %s - %s\r\n", now->tm_year, now->tm_mon, now->tm_mday, now->tm_hour, now->tm_min, tv.tv_sec, (long)tv.tv_usec / 1000, prefix, format); } else { if (prefix[0] == '\0') sprintf( myformat, "%s\r\n", format); else sprintf( myformat, "%s - %s\r\n", prefix, format); } result = vsprintf(tst,myformat,params); if (my_debug_output) fputs(tst, stderr); if (my_use_file && (hFile != NULL)) fputs(tst, hFile); #endif return result; }
BOOL CEpgDBUtil::AddEIT(WORD PID, const CEITTable* eit, __int64 streamTime) { if( eit == NULL ){ return FALSE; } CBlockLock lock(&this->dbLock); ULONGLONG key = _Create64Key(eit->original_network_id, eit->transport_stream_id, eit->service_id); //サービスのmapを取得 map<ULONGLONG, SERVICE_EVENT_INFO>::iterator itr; SERVICE_EVENT_INFO* serviceInfo = NULL; itr = serviceEventMap.find(key); if( itr == serviceEventMap.end() ){ serviceInfo = &serviceEventMap.insert(std::make_pair(key, SERVICE_EVENT_INFO())).first->second; }else{ serviceInfo = &itr->second; } SI_TAG siTag; siTag.tableID = eit->table_id; siTag.version = eit->version_number; siTag.time = (DWORD)(streamTime / (10 * I64_1SEC)); if( eit->table_id <= 0x4F && eit->section_number <= 1 ){ //[p/f] if( siTag.time == 0 ){ //チャンネル変更時の応答性のため、タイムスタンプ不明の[p/f]が来たらDB上の不明でない[p/f]をクリアする //EPGファイルを入力するときは古い[p/f]による上書きが発生するので、利用側で時系列にするかタイムスタンプを確定させる工夫が必要 if( serviceInfo->nowEvent && serviceInfo->nowEvent->time != 0 || serviceInfo->nextEvent && serviceInfo->nextEvent->time != 0 ){ serviceInfo->nowEvent.reset(); serviceInfo->nextEvent.reset(); } } if( eit->eventInfoList.empty() ){ //空セクション if( eit->section_number == 0 ){ if( serviceInfo->nowEvent && siTag.time >= serviceInfo->nowEvent->time ){ serviceInfo->nowEvent.reset(); } }else{ if( serviceInfo->nextEvent && siTag.time >= serviceInfo->nextEvent->time ){ serviceInfo->nextEvent.reset(); } } } } //イベントごとに更新必要が判定 for( size_t i=0; i<eit->eventInfoList.size(); i++ ){ const CEITTable::EVENT_INFO_DATA* eitEventInfo = &eit->eventInfoList[i]; map<WORD, std::unique_ptr<EVENT_INFO>>::iterator itrEvent; EVENT_INFO* eventInfo = NULL; if( eitEventInfo->running_status == 1 || eitEventInfo->running_status == 3 ){ //非実行中または停止中 _OutputDebugString(L"★非実行中または停止中イベント ONID:0x%04x TSID:0x%04x SID:0x%04x EventID:0x%04x %04d/%02d/%02d %02d:%02d", eit->original_network_id, eit->transport_stream_id, eit->service_id, eitEventInfo->event_id, eitEventInfo->start_time.wYear, eitEventInfo->start_time.wMonth, eitEventInfo->start_time.wDay, eitEventInfo->start_time.wHour, eitEventInfo->start_time.wMinute ); continue; } #ifdef DEBUG_EIT wsprintfA(g_szDebugEIT, "%c%04x.%02x%02x.%02d.%d\r\n", eit->table_id <= 0x4F ? 'P' : 'S', eitEventInfo->event_id, eit->table_id, eit->section_number, eit->version_number, siTag.time % 1000000); #endif //[actual]と[other]は等価に扱う //[p/f]と[schedule]は各々完全に独立してデータベースを作成する if( eit->table_id <= 0x4F && eit->section_number <= 1 ){ //[p/f] if( eit->section_number == 0 ){ if( eitEventInfo->StartTimeFlag == FALSE ){ OutputDebugString(L"Invalid EIT[p/f]\r\n"); }else if( serviceInfo->nowEvent == NULL || siTag.time >= serviceInfo->nowEvent->time ){ if( serviceInfo->nowEvent == NULL || serviceInfo->nowEvent->event_id != eitEventInfo->event_id ){ //イベント入れ替わり serviceInfo->nowEvent.reset(); if( serviceInfo->nextEvent && serviceInfo->nextEvent->event_id == eitEventInfo->event_id ){ serviceInfo->nowEvent.swap(serviceInfo->nextEvent); serviceInfo->nowEvent->time = 0; } } if( serviceInfo->nowEvent == NULL ){ eventInfo = new EVENT_INFO; serviceInfo->nowEvent.reset(eventInfo); eventInfo->event_id = eitEventInfo->event_id; eventInfo->time = 0; eventInfo->tagBasic.version = 0xFF; eventInfo->tagBasic.time = 0; eventInfo->tagExt.version = 0xFF; eventInfo->tagExt.time = 0; }else{ eventInfo = serviceInfo->nowEvent.get(); } } }else{ if( serviceInfo->nextEvent == NULL || siTag.time >= serviceInfo->nextEvent->time ){ if( serviceInfo->nextEvent == NULL || serviceInfo->nextEvent->event_id != eitEventInfo->event_id ){ serviceInfo->nextEvent.reset(); if( serviceInfo->nowEvent && serviceInfo->nowEvent->event_id == eitEventInfo->event_id ){ serviceInfo->nextEvent.swap(serviceInfo->nowEvent); serviceInfo->nextEvent->time = 0; } } if( serviceInfo->nextEvent == NULL ){ eventInfo = new EVENT_INFO; serviceInfo->nextEvent.reset(eventInfo); eventInfo->event_id = eitEventInfo->event_id; eventInfo->time = 0; eventInfo->tagBasic.version = 0xFF; eventInfo->tagBasic.time = 0; eventInfo->tagExt.version = 0xFF; eventInfo->tagExt.time = 0; }else{ eventInfo = serviceInfo->nextEvent.get(); } } } }else if( PID != 0x0012 || eit->table_id > 0x4F ){ //[schedule]もしくは(H-EITでないとき)[p/f after] //TODO: イベント消滅には対応していない(クラス設計的に対応は厳しい)。EDCB的には実用上のデメリットはあまり無い if( eitEventInfo->StartTimeFlag == FALSE || eitEventInfo->DurationFlag == FALSE ){ OutputDebugString(L"Invalid EIT[schedule]\r\n"); }else{ itrEvent = serviceInfo->eventMap.find(eitEventInfo->event_id); if( itrEvent == serviceInfo->eventMap.end() ){ eventInfo = new EVENT_INFO; eventInfo->event_id = eitEventInfo->event_id; serviceInfo->eventMap[eventInfo->event_id].reset(eventInfo); eventInfo->time = 0; eventInfo->tagBasic.version = 0xFF; eventInfo->tagBasic.time = 0; eventInfo->tagExt.version = 0xFF; eventInfo->tagExt.time = 0; }else{ eventInfo = itrEvent->second.get(); } } } if( eventInfo ){ //開始時間等はタイムスタンプのみを基準に更新 if( siTag.time >= eventInfo->time ){ eventInfo->StartTimeFlag = eitEventInfo->StartTimeFlag; eventInfo->start_time = eitEventInfo->start_time; eventInfo->DurationFlag = eitEventInfo->DurationFlag; eventInfo->durationSec = (eitEventInfo->durationHH * 60 + eitEventInfo->durationMM) * 60 + eitEventInfo->durationSS; eventInfo->freeCAFlag = eitEventInfo->free_CA_mode; eventInfo->time = siTag.time; } //記述子はテーブルバージョンも加味して更新(単に効率のため) if( siTag.time >= eventInfo->tagExt.time ){ if( eit->version_number != eventInfo->tagExt.version || eit->table_id != eventInfo->tagExt.tableID || siTag.time > eventInfo->tagExt.time + 180 ){ if( AddExtEvent(eventInfo, &eitEventInfo->descriptorList) != FALSE ){ eventInfo->tagExt = siTag; } }else{ eventInfo->tagExt.time = siTag.time; } } //[schedule extended]以外 if( (eit->table_id < 0x58 || 0x5F < eit->table_id) && (eit->table_id < 0x68 || 0x6F < eit->table_id) ){ if( eit->table_id > 0x4F && eventInfo->tagBasic.version != 0xFF && eventInfo->tagBasic.tableID <= 0x4F ){ //[schedule][p/f after]とも運用するサービスがあれば[p/f after]を優先する(今のところサービス階層が分離しているのであり得ないはず) _OutputDebugString(L"Conflicts EIT[schedule][p/f after] SID:0x%04x EventID:0x%04x\r\n", eit->service_id, eventInfo->event_id); }else if( siTag.time >= eventInfo->tagBasic.time ){ if( eit->version_number != eventInfo->tagBasic.version || eit->table_id != eventInfo->tagBasic.tableID || siTag.time > eventInfo->tagBasic.time + 180 ){ AddBasicInfo(eventInfo, &eitEventInfo->descriptorList, eit->original_network_id, eit->transport_stream_id); } eventInfo->tagBasic = siTag; } } } } if( eit->original_network_id == 0x0003 ){ return TRUE; } //セクションステータス if( PID != 0x0012 ){ //L-EIT if( eit->table_id <= 0x4F ){ if( serviceInfo->lastTableID != eit->table_id || serviceInfo->sectionList[0].version != eit->version_number + 1 ){ serviceInfo->lastTableID = 0; } if( serviceInfo->lastTableID == 0 ){ //リセット memset(&serviceInfo->sectionList.front(), 0, sizeof(SECTION_FLAG_INFO) * 8); for( int i = 1; i < 8; i++ ){ //第0テーブル以外のセクションを無視 memset(serviceInfo->sectionList[i].ignoreFlags, 0xFF, sizeof(serviceInfo->sectionList[0].ignoreFlags)); } serviceInfo->lastTableID = eit->table_id; } //第0セグメント以外のセクションを無視 memset(serviceInfo->sectionList[0].ignoreFlags + 1, 0xFF, sizeof(serviceInfo->sectionList[0].ignoreFlags) - 1); //第0セグメントの送られないセクションを無視 for( int i = eit->segment_last_section_number % 8 + 1; i < 8; i++ ){ serviceInfo->sectionList[0].ignoreFlags[0] |= 1 << i; } serviceInfo->sectionList[0].version = eit->version_number + 1; serviceInfo->sectionList[0].flags[0] |= 1 << (eit->section_number % 8); } }else{ //H-EIT if( eit->table_id > 0x4F ){ BYTE& lastTableID = eit->table_id % 16 >= 8 ? serviceInfo->lastTableIDExt : serviceInfo->lastTableID; vector<SECTION_FLAG_INFO>& sectionList = eit->table_id % 16 >= 8 ? serviceInfo->sectionExtList : serviceInfo->sectionList; if( sectionList.empty() ){ //拡張情報はないことも多いので遅延割り当て sectionList.resize(8); } if( lastTableID != eit->last_table_id ){ lastTableID = 0; }else if( sectionList[eit->table_id % 8].version != 0 && sectionList[eit->table_id % 8].version != eit->version_number + 1 ){ OutputDebugString(L"EIT[schedule] updated\r\n"); lastTableID = 0; } if( lastTableID == 0 ){ //リセット memset(§ionList.front(), 0, sizeof(SECTION_FLAG_INFO) * 8); for( int i = eit->last_table_id % 8 + 1; i < 8; i++ ){ //送られないテーブルのセクションを無視 memset(sectionList[i].ignoreFlags, 0xFF, sizeof(sectionList[0].ignoreFlags)); } lastTableID = eit->last_table_id; } //送られないセグメントのセクションを無視 memset(sectionList[eit->table_id % 8].ignoreFlags + eit->last_section_number / 8 + 1, 0xFF, sizeof(sectionList[0].ignoreFlags) - eit->last_section_number / 8 - 1); if( eit->table_id % 8 == 0 && streamTime > 0 ){ //放送済みセグメントのセクションを無視 memset(sectionList[0].ignoreFlags, 0xFF, streamTime / (3 * 60 * 60 * I64_1SEC) % 8); } //このセグメントの送られないセクションを無視 for( int i = eit->segment_last_section_number % 8 + 1; i < 8; i++ ){ sectionList[eit->table_id % 8].ignoreFlags[eit->section_number / 8] |= 1 << i; } sectionList[eit->table_id % 8].version = eit->version_number + 1; sectionList[eit->table_id % 8].flags[eit->section_number / 8] |= 1 << (eit->section_number % 8); } } return TRUE; }
/** Modifies the wininit.ini file to rename / delete a file. * * @param prevName The previous / current name of the file. * @param newName The new name to move the file to. If NULL, the current file * will be deleted. */ void RenameViaWininit(TCHAR* prevName, TCHAR* newName) { static char szRenameLine[1024]; static TCHAR wininit[1024]; static TCHAR tmpbuf[1024]; #ifdef _UNICODE static char shortExisting[1024]; static char shortNew[1024]; #endif int cchRenameLine; static const char szRenameSec[] = "[Rename]\r\n"; // rename section marker HANDLE hfile; DWORD dwFileSize; DWORD dwBytes; DWORD dwRenameLinePos; char *pszWinInit; // Contains the file contents of wininit.ini int spn; // length of the short path name in TCHARs. lstrcpy(tmpbuf, _T("NUL")); if (newName) { // create the file if it's not already there to prevent GetShortPathName from failing CloseHandle(myOpenFile(newName,0,CREATE_NEW)); spn = GetShortPathName(newName,tmpbuf,1024); if (!spn || spn > 1024) return; } // wininit is used as a temporary here spn = GetShortPathName(prevName,wininit,1024); if (!spn || spn > 1024) return; // Because wininit.ini is an ASCII text file, we need to be careful what we // convert here to TCHARs. #ifdef _UNICODE // The short name produced by GetShortPathName is always in the ASCII range // of characters. // Convert short name of new name to ANSI if (WideCharToMultiByte(CP_ACP, 0, tmpbuf, -1, shortNew, sizeof(shortNew), NULL, NULL) == 0) { // We have a failure in conversion to ANSI return; } // Convert short name of old name to ANSI if (WideCharToMultiByte(CP_ACP, 0, wininit, -1, shortExisting, sizeof(shortExisting), NULL, NULL) == 0) { // We have a failure in conversion to ANSI return; } cchRenameLine = wsprintfA(szRenameLine, "%s=%s\r\n", shortNew, shortExisting); #else cchRenameLine = wsprintfA(szRenameLine, "%s=%s\r\n", tmpbuf, wininit); #endif // Get the path to the wininit.ini file. GetWindowsDirectory(wininit, 1024-16); lstrcat(wininit, _T("\\wininit.ini")); hfile = myOpenFile(wininit, GENERIC_READ | GENERIC_WRITE, OPEN_ALWAYS); if (hfile != INVALID_HANDLE_VALUE) { // We are now working on the Windows wininit file dwFileSize = GetFileSize(hfile, NULL); pszWinInit = (char*) GlobalAlloc(GPTR, dwFileSize + cchRenameLine + 10); if (pszWinInit != NULL) { if (ReadFile(hfile, pszWinInit, dwFileSize, &dwBytes, NULL) && dwFileSize == dwBytes) { // Look for the rename section in the current file. LPSTR pszRenameSecInFile = mystrstriA(pszWinInit, szRenameSec); if (pszRenameSecInFile == NULL) { // No rename section. So we add it to the end of file. lstrcpyA(pszWinInit+dwFileSize, szRenameSec); dwFileSize += 10; dwRenameLinePos = dwFileSize; } else { // There is a rename section, but is there another section after it? char *pszFirstRenameLine = pszRenameSecInFile+10; char *pszNextSec = mystrstriA(pszFirstRenameLine,"\n["); if (pszNextSec) { char *p = pszWinInit + dwFileSize; char *pEnd = pszWinInit + dwFileSize + cchRenameLine; while (p > pszNextSec) { *pEnd-- = *p--; } dwRenameLinePos = pszNextSec - pszWinInit + 1; // +1 for the \n } // rename section is last, stick item at end of file else dwRenameLinePos = dwFileSize; } mini_memcpy(&pszWinInit[dwRenameLinePos], szRenameLine, cchRenameLine); dwFileSize += cchRenameLine; SetFilePointer(hfile, 0, NULL, FILE_BEGIN); WriteFile(hfile, pszWinInit, dwFileSize, &dwBytes, NULL); GlobalFree(pszWinInit); } } CloseHandle(hfile); } }