FileHandle * FileHandlePlain(int *fd_p) { FileHandle *fh; fh = FileHandleCreate(PlainCloseFunc, PlainReadFunc, sizeof(int)); if (fh != NULL) { int *new_fd_p = fh->fh_InstData; *new_fd_p = *fd_p; *fd_p = -1; } return fh; }
BOOL SaveChart (HWND hWndGraph, HANDLE hInputFile, BOOL bGetFileName) { PGRAPHSTRUCT pGraph ; PLINE pLine ; HANDLE hFile ; DISKCHART DiskChart ; PERFFILEHEADER FileHeader ; TCHAR szFileName [256] ; BOOL newFileName = FALSE ; if (hInputFile) { // use the input file handle if it is available // this is the case for saving workspace data hFile = hInputFile ; } else { if (pChartFullFileName) { lstrcpy (szFileName, pChartFullFileName) ; } if (bGetFileName || pChartFullFileName == NULL) { // if (!pChartFullFileName) // { // StringLoad (IDS_GRAPH_FNAME, szFileName) ; // } if (!FileGetName (hWndGraph, IDS_CHARTFILE, szFileName)) { return (FALSE) ; } newFileName = TRUE ; } hFile = FileHandleCreate (szFileName) ; if (hFile && newFileName) { ChangeSaveFileName (szFileName, IDM_VIEWCHART) ; } else if (!hFile) { DlgErrorBox (hWndGraph, ERR_CANT_OPEN, szFileName) ; } } if (!hFile) return (FALSE) ; pGraph = pGraphs ; if (!pGraph) { if (!hInputFile) { CloseHandle (hFile) ; } return (FALSE) ; } if (!hInputFile) { // only need to write file header if not workspace memset (&FileHeader, 0, sizeof (FileHeader)) ; lstrcpy (FileHeader.szSignature, szPerfChartSignature) ; FileHeader.dwMajorVersion = ChartMajorVersion ; FileHeader.dwMinorVersion = ChartMinorVersion ; if (!FileWrite (hFile, &FileHeader, sizeof (PERFFILEHEADER))) { goto Exit0 ; } } DiskChart.Visual = pGraph->Visual ; DiskChart.gOptions = pGraph->gOptions ; DiskChart.gMaxValues = pGraph->gMaxValues ; DiskChart.dwNumLines = NumLines (pGraph->pLineFirst) ; DiskChart.bManualRefresh = pGraph->bManualRefresh ; DiskChart.perfmonOptions = Options ; if (!FileWrite (hFile, &DiskChart, sizeof (DISKCHART))) { goto Exit0 ; } for (pLine = pGraph->pLineFirst ; pLine ; pLine = pLine->pLineNext) { // for if (!WriteLine (pLine, hFile)) { goto Exit0 ; } } // for if (!hInputFile) { CloseHandle (hFile) ; } return (TRUE) ; Exit0: if (!hInputFile) { CloseHandle (hFile) ; // only need to report error if not workspace DlgErrorBox (hWndGraph, ERR_SETTING_FILE, szFileName) ; } return (FALSE) ; } // SaveChart
// This routine opens the export file and put in the header info. // It is used by ExportChart, ExportAlert, & ExportReport. INT ExportFileOpen (HWND hWnd, HANDLE *phFile, int IntervalMSecs, LPTSTR *ppFileName) { CHAR TempBuff [LongTextLen] ; TCHAR UnicodeBuff [LongTextLen] ; TCHAR UnicodeBuff1 [MiscTextLen] ; SYSTEMTIME SystemTime ; int StringLen ; INT ErrCode = 0 ; FLOAT eIntervalSecs ; // defined and setup in status.c extern TCHAR szCurrentActivity [] ; extern TCHAR szStatusFormat [] ; *phFile = 0 ; if (!FileGetName (hWnd, IDS_EXPORTFILE, UnicodeBuff)) { // user cancel goto Exit0 ; } *ppFileName = StringAllocate (UnicodeBuff) ; // open the file.. if (!(*phFile = FileHandleCreate (UnicodeBuff))) { // can't open the file ErrCode = ERR_CANT_OPEN ; goto Exit0 ; } // export header StringLoad (IDS_REPORT_HEADER, UnicodeBuff) ; ConvertUnicodeStr (TempBuff, UnicodeBuff) ; StringLen = strlen (TempBuff) ; ConvertUnicodeStr (&TempBuff[StringLen], LocalComputerName) ; strcat (TempBuff, LineEndStr) ; if (!FileWrite (*phFile, TempBuff, strlen(TempBuff))) { ErrCode = ERR_EXPORT_FILE ; goto Exit0 ; } // export today's date time GetLocalTime (&SystemTime) ; StringLoad (IDS_EXPORT_DATE, UnicodeBuff) ; StringLen = lstrlen (UnicodeBuff) ; UnicodeBuff[StringLen] = TEXT(':') ; UnicodeBuff[StringLen+1] = TEXT(' ') ; SystemTimeDateString (&SystemTime, &UnicodeBuff[StringLen+2]) ; ConvertUnicodeStr (TempBuff, UnicodeBuff) ; strcat (TempBuff, LineEndStr) ; if (!FileWrite (*phFile, TempBuff, strlen(TempBuff))) { ErrCode = ERR_EXPORT_FILE ; goto Exit0 ; } StringLoad (IDS_EXPORT_TIME, UnicodeBuff) ; StringLen = lstrlen (UnicodeBuff) ; UnicodeBuff[StringLen] = TEXT(':') ; UnicodeBuff[StringLen+1] = TEXT(' ') ; SystemTimeTimeString (&SystemTime, &UnicodeBuff[StringLen+2], FALSE) ; ConvertUnicodeStr (TempBuff, UnicodeBuff) ; strcat (TempBuff, LineEndStr) ; if (!FileWrite (*phFile, TempBuff, strlen(TempBuff))) { ErrCode = ERR_EXPORT_FILE ; goto Exit0 ; } // export data source TSPRINTF (UnicodeBuff, szStatusFormat, PlayingBackLog () ? PlaybackLog.szFileTitle : szCurrentActivity) ; ConvertUnicodeStr (TempBuff, UnicodeBuff) ; strcat (TempBuff, LineEndStr) ; if (!FileWrite (*phFile, TempBuff, strlen(TempBuff))) { ErrCode = ERR_EXPORT_FILE ; goto Exit0 ; } if (!PlayingBackLog()) { eIntervalSecs = (FLOAT)IntervalMSecs / (FLOAT) 1000.0 ; StringLoad (IDS_CHARTINT_FORMAT, UnicodeBuff1) ; TSPRINTF (UnicodeBuff, UnicodeBuff1, eIntervalSecs) ; ConvertDecimalPoint (UnicodeBuff) ; ConvertUnicodeStr (TempBuff, UnicodeBuff) ; strcat (TempBuff, LineEndStr) ; if (!FileWrite (*phFile, TempBuff, strlen(TempBuff))) { ErrCode = ERR_EXPORT_FILE ; goto Exit0 ; } } else { // export the log start and stop date/time StringLoad (IDS_START_TEXT, UnicodeBuff) ; StringLen = lstrlen (UnicodeBuff) ; LogPositionSystemTime (&(PlaybackLog.StartIndexPos), &SystemTime) ; SystemTimeDateString (&SystemTime, &UnicodeBuff[StringLen]) ; StringLen = lstrlen (UnicodeBuff) ; UnicodeBuff[StringLen] = TEXT(' ') ; StringLen++ ; SystemTimeTimeString (&SystemTime, &UnicodeBuff[StringLen], FALSE) ; ConvertUnicodeStr (TempBuff, UnicodeBuff) ; strcat (TempBuff, LineEndStr) ; if (!FileWrite (*phFile, TempBuff, strlen(TempBuff))) { ErrCode = ERR_EXPORT_FILE ; goto Exit0 ; } StringLoad (IDS_STOP_TEXT, UnicodeBuff) ; StringLen = lstrlen (UnicodeBuff) ; LogPositionSystemTime (&(PlaybackLog.StopIndexPos), &SystemTime) ; SystemTimeDateString (&SystemTime, &UnicodeBuff[StringLen]) ; StringLen = lstrlen (UnicodeBuff) ; UnicodeBuff[StringLen] = TEXT(' ') ; StringLen++ ; SystemTimeTimeString (&SystemTime, &UnicodeBuff[StringLen], FALSE) ; ConvertUnicodeStr (TempBuff, UnicodeBuff) ; strcat (TempBuff, LineEndStr) ; if (!FileWrite (*phFile, TempBuff, strlen(TempBuff))) { ErrCode = ERR_EXPORT_FILE ; goto Exit0 ; } if (hWnd == hWndAlert) { eIntervalSecs = (FLOAT)IntervalMSecs / (FLOAT) 1000.0 ; StringLoad (IDS_CHARTINT_FORMAT, UnicodeBuff1) ; TSPRINTF (UnicodeBuff, UnicodeBuff1, eIntervalSecs) ; ConvertDecimalPoint (UnicodeBuff) ; ConvertUnicodeStr (TempBuff, UnicodeBuff) ; strcat (TempBuff, LineEndStr) ; if (!FileWrite (*phFile, TempBuff, strlen(TempBuff))) { ErrCode = ERR_EXPORT_FILE ; goto Exit0 ; } } } return (0) ; Exit0: return (ErrCode) ; } // ExportFileOpen