__s32 CloseConfigFile(__hdle hConfig) { if (OK != CloseConfig((HCONFIG)hConfig)) { return EPDK_FAIL; } return EPDK_OK; }
BOOL UpdateHighlightsFromConfig(HGRIDITEM hRoot, HWND hwndGridView, TCHAR *szBookPath, COLORREF col) { HCONFIG hConf, hBookmarks; HBOOKMARK bookmark; size_t i; TCHAR szFilePath[MAX_PATH]; GVITEM gvitem = { 0 }; hConf = OpenConfig(szBookPath); if(hConf) { if(GetConfigStr(hConf, TEXT("hexFileData\\filePath"), szFilePath, MAX_PATH, 0)) { hBookmarks = OpenConfigSection(hConf, TEXT("hexFileData\\bookmarks")); for(i = 0; bookmark = EnumConfigSection(hBookmarks, TEXT("bookmark"), (int)i); i++) { TCHAR name[100], desc[100]; BOOKMARK bm = { 0, 0, 0, 0, 0, name, 100, desc, 100 }; // do we need to add a root item? if(hRoot == 0) { GVITEM gvitem = { GVIF_TEXT }; gvitem.pszText = szFilePath; hRoot = GridView_FindChild(hwndGridView, GVI_ROOT, &gvitem); if (!hRoot) hRoot = CreateBookmarkFileRoot(GVI_ROOT, szFilePath, hwndGridView, FALSE); gvitem.mask = GVIF_PARAM|GVIF_FONT; gvitem.iFont = 0; // regular gvitem.param = 0; GridView_SetItem(hwndGridView, hRoot, &gvitem); GridView_DeleteChildren(hwndGridView, hRoot); MkRootGVITEM(&gvitem, szFilePath, FALSE, 0); GridView_SetItem(hwndGridView, hRoot, &gvitem); } GetConfigBookmark(bookmark, &bm); FillGridView2(hwndGridView, hRoot, NULL, &bm, col); //callback(&bm, param); } } CloseConfig(hConf); } return TRUE; }
BOOL UpdateHighlights2(HWND hwndHexView, HWND hwndGridView) { HGRIDITEM hGridItem; hGridItem = GVI_ROOT;//GridView_InsertChild(hwndGridView, GVI_ROOT, &gvitem); SendMessage(hwndGridView, WM_SETREDRAW, FALSE, 0); GridView_DeleteAll(hwndGridView); if(hwndHexView == 0) { // just add bookmarks for specified hexview FillHexViewHighlights(GVI_ROOT, hwndHexView, hwndGridView, 0); } else if(hwndHexView != (HWND)-1) { int i; // add bookmarks for all open files for(i = 0; (hwndHexView = EnumHexView(g_hwndMain, i)) != 0; i++) { AddHexViewHighlights(GVI_ROOT, hwndHexView, hwndGridView, 0); } } else { WIN32_FIND_DATA win32fd; HANDLE hFind; TCHAR szBookPath[MAX_PATH]; TCHAR szFilePath[MAX_PATH]; HCONFIG hConf ; GetProgramDataPath(szBookPath, MAX_PATH); lstrcat(szBookPath, TEXT("\\Bookmarks\\*")); // enumerate all files in the bookmarks directory if((hFind = FindFirstFile(szBookPath, &win32fd)) != 0) { do { if((win32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { HWND hwndHV; int i; HCONFIG hBookmarks, bookmark; HGRIDITEM hItem; GetProgramDataPath(szBookPath, MAX_PATH); wsprintf(szFilePath, TEXT("%s\\Bookmarks\\%s"), szBookPath, win32fd.cFileName); hConf = OpenConfig(szFilePath); GetConfigStr(hConf, TEXT("hexFileData\\filePath"), szFilePath, MAX_PATH, 0); if((hwndHV = HexIsOpen(g_hwndMain, szFilePath, 0)) != 0) { AddHexViewHighlights(GVI_ROOT, hwndHV, hwndGridView, 0); } else { hItem = CreateBookmarkFileRoot(GVI_ROOT, szFilePath, hwndGridView, FALSE); //EnumHighlights(szBookPath, addgv, hwndGridView); hBookmarks = OpenConfigSection(hConf, TEXT("hexFileData\\bookmarks")); for(i = 0; bookmark = EnumConfigSection(hBookmarks, TEXT("bookmark"), i); i++) { TCHAR name[100], desc[100]; BOOKMARK bm = { 0, 0, 0, 0, 0, name, 100, desc, 100 }; GetConfigBookmark(bookmark, &bm); FillGridView2(hwndGridView, hItem, NULL, &bm, 0); //callback(&bm, param); } } CloseConfig(hConf); } } while(FindNextFile(hFind, &win32fd)); FindClose(hFind); } } /* for(hbm = 0; (hbm = HexView_EnumBookmark(hwndHexView, hbm, &bm)) != 0; ) { TCHAR szOffset[32]; TCHAR szTitle[32]; _stprintf(szTitle, TEXT("%s"), bm.pszTitle); _stprintf(szOffset, TEXT("%08I64X (%d bytes)"), bm.offset, bm.length); FillGridView2(hwndGridView, hGridItem, hbm, szTitle, szOffset, bm.pszText); }*/ SendMessage(hwndGridView, WM_SETREDRAW, TRUE, 0); GridView_Update(hwndGridView); //ForceClientResize(hwndGridView); //InvalidateRect(hwndGridView, 0, 0); return TRUE; }
void DeleteBookmarkFromConfig(LPCTSTR szFilename, LPCTSTR szBookmarkName) { WIN32_FIND_DATA win32fd; HANDLE hFind; TCHAR szBookPath[MAX_PATH]; TCHAR szFilePath[MAX_PATH]; TCHAR szRefFilePath[MAX_PATH] = { 0 }; GetProgramDataPath(szBookPath, MAX_PATH); lstrcat(szBookPath, TEXT("\\Bookmarks\\*")); // enumerate all files in the bookmarks directory if ((hFind = FindFirstFile(szBookPath, &win32fd)) != 0) { do { if ((win32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { GetProgramDataPath(szBookPath, MAX_PATH); wsprintf(szFilePath, TEXT("%s\\Bookmarks\\%s"), szBookPath, win32fd.cFileName); HCONFIG configFile = OpenConfig(szFilePath); if (configFile) { if (GetConfigStr(configFile, TEXT("hexFileData\\filePath"), szRefFilePath, MAX_PATH, 0) && _tcscmp(szRefFilePath, szFilename) == 0) { HCONFIG bookmarksSection = OpenConfigSection(configFile, TEXT("hexFileData\\bookmarks")); DWORD idx = 0; HCONFIG bookmark = 0; DWORD countedBookmarks = 0; while (bookmark = EnumConfigSection(bookmarksSection, TEXT("bookmark"), idx++)) { TCHAR title[100]; BOOKMARK bm = { 0 }; bm.pszTitle = title; bm.nMaxTitle = ARRAYSIZE(title); if (GetConfigBookmark(bookmark, &bm) && _tcscmp(title, szBookmarkName) == 0) { DeleteConfigSection(bookmark); } else { countedBookmarks++; } } SaveConfig(szFilePath, configFile); CloseConfig(configFile); if (countedBookmarks == 0) { DeleteFile(szFilePath); } break; } CloseConfig(configFile); } } } while (FindNextFile(hFind, &win32fd)); FindClose(hFind); } }
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { if (msg == WM_TRAY) { if (lParam == WM_LBUTTONDOWN || lParam == WM_LBUTTONDBLCLK) { ToggleState(); if (lParam == WM_LBUTTONDBLCLK && !(GetAsyncKeyState(VK_SHIFT)&0x8000)) { SendMessage(hwnd, WM_OPENCONFIG, 0, 0); } } else if (lParam == WM_MBUTTONDOWN) { ShellExecute(NULL, L"open", inipath, NULL, NULL, SW_SHOWNORMAL); } else if (lParam == WM_RBUTTONDOWN) { ShowContextMenu(hwnd); } else if (lParam == NIN_BALLOONUSERCLICK) { hide = 0; SendMessage(hwnd, WM_COMMAND, SWM_UPDATE, 0); } else if (lParam == NIN_BALLOONTIMEOUT) { if (hide) { RemoveTray(); } } } else if (msg == WM_UPDATESETTINGS) { UpdateLanguage(); // Reload hooks if (ENABLED()) { UnhookSystem(); HookSystem(); } // Reload config language if (!wParam && IsWindow(g_cfgwnd)) { SendMessage(g_cfgwnd, WM_UPDATESETTINGS, 0, 0); } } else if (msg == WM_ADDTRAY) { hide = 0; UpdateTray(); } else if (msg == WM_HIDETRAY) { hide = 1; RemoveTray(); } else if (msg == WM_OPENCONFIG && (lParam || !hide)) { OpenConfig(wParam); } else if (msg == WM_CLOSECONFIG) { CloseConfig(); } else if (msg == WM_TASKBARCREATED) { tray_added = 0; UpdateTray(); } else if (msg == WM_COMMAND) { int wmId=LOWORD(wParam), wmEvent=HIWORD(wParam); if (wmId == SWM_TOGGLE) { ToggleState(); } else if (wmId == SWM_HIDE) { hide = 1; RemoveTray(); } else if (wmId == SWM_UPDATE) { if (MessageBox(NULL,l10n->update_dialog,APP_NAME,MB_ICONINFORMATION|MB_YESNO|MB_TOPMOST|MB_SETFOREGROUND) == IDYES) { OpenUrl(APP_URL); } } else if (wmId == SWM_CONFIG) { SendMessage(hwnd, WM_OPENCONFIG, 0, 0); } else if (wmId == SWM_ABOUT) { SendMessage(hwnd, WM_OPENCONFIG, 4, 0); } else if (wmId == SWM_EXIT) { DestroyWindow(hwnd); } } else if (msg == WM_QUERYENDSESSION && msghook) { showerror = 0; UnhookSystem(); } else if (msg == WM_DESTROY) { showerror = 0; UnhookSystem(); RemoveTray(); PostQuitMessage(0); } else if (msg == WM_LBUTTONDOWN || msg == WM_MBUTTONDOWN || msg == WM_RBUTTONDOWN) { // Hide cursorwnd if clicked on, this might happen if it wasn't hidden by hooks.c for some reason ShowWindow(hwnd, SW_HIDE); } return DefWindowProc(hwnd, msg, wParam, lParam); }