/****************************************************************************** * * Copyright (c) 2000 Microsoft Corporation * * Module Name: * testmap.cpp * * Abstract: * UI tool for enumerating the change log/restore map * * Revision History: * Brijesh Krishnaswami (brijeshk) 06/09/2000 * created * *****************************************************************************/ #include "stdafx.h" #include "resource.h" #include #include "srrpcapi.h" #include "stdio.h" #ifdef THIS_FILE #undef THIS_FILE #endif static char __szTraceSourceFile[] = __FILE__; #define THIS_FILE __szTraceSourceFile #include "dbgtrace.h" #include "restmap.h" #include "enumlogs.h" #include "shellapi.h" #include "srapi.h" // // Macros: // #define MAX_LOADSTRING 100 #define LocalRealloc(a, b) LocalReAlloc(a, b, LMEM_MOVEABLE) #define MSG(a) MessageBox(NULL, a, L"", MB_OK); #define CHGLOG_COLS 8 // // Global Variables: // HINSTANCE hInst; WCHAR szTitle[MAX_LOADSTRING]; WCHAR szWindowClass[MAX_LOADSTRING]; HWND g_hwndChgLog = 0, g_hwndRestMap = 0, g_hwndMain = 0; HANDLE g_hDevice = 0, g_hFile = 0; WCHAR g_szLogDir[ MAX_PATH ]; WCHAR g_szActiveLogFile[ MAX_PATH ]; BOOL g_fTraceStatus = FALSE; WCHAR g_bBuffer[4096*16]; WCHAR g_szCmdLine[MAX_PATH]; int g_nRPNum = 0; int g_nOption = 1; WCHAR g_szDrive[MAX_PATH]; WCHAR g_szRstrmap[MAX_PATH] = L"c:\\rstrmap.dat"; typedef struct _CHGLOG_ITEM { LPWSTR aCols[CHGLOG_COLS]; } CHGLOG_ITEM; LPWSTR CHGLOG_COLUMNS[CHGLOG_COLS] = { L"Seq", L"Size", L"Operation", L"Attributes", L"TmpFile", L"Src Path", L"Dest Path", L"Acl" }; INT CHGLOG_WIDTHS[CHGLOG_COLS] = { 50, 50, 80, 80, 150, 250, 100, 50 }; WCHAR g_szBuffer [4096]; WCHAR g_achLogTemp[256]; WCHAR g_achTemp [256]; BYTE mapEnt[ 4096 ]; WCHAR szBuffer[4096]; // // Foward declarations of functions included in this code module: // ATOM RegisterRestoreMapClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM); void Log(char *ctl, int len); struct _EVENT_STR_MAP { DWORD EventId; LPWSTR pEventStr; } EventMap[ 12 ] = { {SrEventInvalid , L"INVALID " }, {SrEventStreamChange, L"FILE-MODIFY" }, {SrEventAclChange, L"ACL-CHANGE " }, {SrEventAttribChange, L"ATTR-CHANGE" }, {SrEventStreamOverwrite,L"FILE-MODIFY" }, {SrEventFileDelete, L"FILE-DELETE" }, {SrEventFileCreate, L"FILE-CREATE" }, {SrEventFileRename, L"FILE-RENAME" }, {SrEventDirectoryCreate,L"DIR-CREATE " }, {SrEventDirectoryRename,L"DIR-RENAME " }, {SrEventDirectoryDelete,L"DIR-DELETE " }, {SrEventMaximum, L"INVALID-MAX" } }; LPWSTR GetEventString( DWORD EventId ) { LPWSTR pStr = L"NOT-FOUND"; for( int i=0; iaCols[0] = DupString(szSeqNo); pItem->aCols[1] = DupString(szSize); pItem->aCols[2] = DupString(szOperation); pItem->aCols[3] = DupString(szAttr); pItem->aCols[4] = DupString(szTmpFile); pItem->aCols[5] = DupString(szSrc); pItem->aCols[6] = DupString(szDest); pItem->aCols[7] = DupString(szAcl); // Initialize item-specific LVITEM members. lvi.iItem = iItem; lvi.iSubItem = 0; lvi.lParam = (LPARAM)pItem; // item data // Add the item. ListView_InsertItem(hwnd, &lvi); iItem++; return TRUE; } VOID WINAPI ChgLog_OnGetDispInfo(NMLVDISPINFO * pnmv) { // Provide the item or subitem's text, if requested. if (pnmv->item.mask & LVIF_TEXT) { CHGLOG_ITEM *pItem = (CHGLOG_ITEM *) (pnmv->item.lParam); lstrcpy(pnmv->item.pszText, pItem->aCols[pnmv->item.iSubItem]); } } BOOL WINAPI ChgLog_InitColumns(HWND hwnd) { LVCOLUMN lvc; int iCol; // Initialize the LVCOLUMN structure. lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; lvc.fmt = LVCFMT_LEFT; lvc.cx = 100; lvc.pszText = g_achTemp; // Add the columns. for (iCol = 0; iCol < CHGLOG_COLS; iCol++) { lvc.iSubItem = iCol; lvc.cx = CHGLOG_WIDTHS[iCol]; lstrcpy(g_achTemp, CHGLOG_COLUMNS[iCol]); if (ListView_InsertColumn(hwnd, iCol, &lvc) == -1) return FALSE; } return TRUE; } BOOL ChgLog_FillWindow() { WCHAR szSeqNo[50]; WCHAR szSize[50]; WCHAR szOperation[50]; WCHAR szAttr[50]; WCHAR szTmpFile[150]; WCHAR szSrc [MAX_PATH]; WCHAR szDest[MAX_PATH]; WCHAR szAcl[MAX_PATH]; if (g_nOption == 3) { if (ERROR_SUCCESS != SRSwitchLog()) goto done; } { CChangeLogEntryEnum ChangeLog(g_szDrive, (g_nOption == 3), g_nRPNum, (g_nOption == 3)); CChangeLogEntry cle; if (ERROR_SUCCESS != ChangeLog.FindFirstChangeLogEntry(cle)) goto done; do { wsprintf( szSeqNo , L"%ld", cle.GetSequenceNum()); wsprintf( szSize , L"%d" , 0); wsprintf( szOperation, L"%s" , GetEventString(cle.GetType()) ); wsprintf( szAttr , L"%08x" , cle.GetAttributes() ); wsprintf( szTmpFile , L"%s" , cle.GetTemp() ? cle.GetTemp() : L"" ); wsprintf( szSrc , L"%s" , cle.GetPath1() ? cle.GetPath1() : L""); wsprintf( szDest, L"%s", cle.GetPath2() ? cle.GetPath2() : L""); wsprintf( szAcl, L"%s", cle.GetAcl() ? (cle.GetAclInline() ? L"Inline" : (LPWSTR) cle.GetAcl()) : L""); ChgLog_Insert( g_hwndChgLog, szSeqNo, szSize, szOperation, szAttr, szTmpFile, szSrc, szDest, szAcl); } while (ChangeLog.FindNextChangeLogEntry(cle) == ERROR_SUCCESS); ChangeLog.FindClose(); } done: return TRUE; } BOOL RestMap_FillWindow() { WCHAR szSeqNo[50]; WCHAR szSize[50]; WCHAR szOperation[50]; WCHAR szAttr[50]; WCHAR szTmpFile[150]; WCHAR szSrc [MAX_PATH]; WCHAR szDest[MAX_PATH]; WCHAR szAcl[MAX_PATH]; LPWSTR pszSrc, pszDest, pszTemp; LPBYTE pbAcl = NULL; RestoreMapEntry *prme = NULL; HANDLE hFile; PVOID pOpt = NULL; hFile = CreateFile(g_szRstrmap, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) goto Err; while (ERROR_SUCCESS == ReadRestoreMapEntry(hFile, &prme)) { GetPaths(prme, &pszSrc, &pszTemp, &pszDest, &pbAcl); wsprintf( szSeqNo , L"%ld", 0); wsprintf( szSize , L"%d" , prme->m_dwSize); wsprintf( szOperation, L"%s" , GetEventString(prme->m_dwOperation)); wsprintf( szAttr , L"%08x" , prme->m_dwAttribute ); wsprintf( szTmpFile , L"%s" , pszTemp ? pszTemp : L""); wsprintf( szSrc , L"%s" , pszSrc ? pszSrc : L""); wsprintf( szDest, L"%s", pszDest ? pszDest : L""); wsprintf( szAcl, L"%s", prme->m_cbAcl ? (prme->m_fAclInline ? L"Inline" : (LPWSTR) pbAcl) : L""); ChgLog_Insert( g_hwndRestMap, szSeqNo, szSize, szOperation, szAttr, szTmpFile, szSrc, szDest, szAcl); } FreeRestoreMapEntry(prme); CloseHandle(hFile); Err: return TRUE; } void PrintUsage() { printf("Usage : testmap