TSRM_API int win32_utime(const char *filename, struct utimbuf *buf) /* {{{ */ { FILETIME mtime, atime; HANDLE hFile; hFile = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_WRITE|FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_FLAG_BACKUP_SEMANTICS, NULL); /* OPEN_ALWAYS mode sets the last error to ERROR_ALREADY_EXISTS but the CreateFile operation succeeds */ if (GetLastError() == ERROR_ALREADY_EXISTS) { SetLastError(0); } if ( hFile == INVALID_HANDLE_VALUE ) { return -1; } if (!buf) { SYSTEMTIME st; GetSystemTime(&st); SystemTimeToFileTime(&st, &mtime); atime = mtime; } else { UnixTimeToFileTime(buf->modtime, &mtime); UnixTimeToFileTime(buf->actime, &atime); } if (!SetFileTime(hFile, NULL, &atime, &mtime)) { CloseHandle(hFile); return -1; } CloseHandle(hFile); return 1; }
MIR_CORE_DLL(int) TimeZone_PrintTimeStamp(HANDLE hTZ, mir_time ts, LPCTSTR szFormat, LPTSTR szDest, size_t cbDest, DWORD dwFlags) { MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ; if (tz == NULL && (dwFlags & (TZF_DIFONLY | TZF_KNOWNONLY))) return 1; if (tz == NULL) tz = &myInfo.myTZ; FILETIME ft; if (tz == UTC_TIME_HANDLE) UnixTimeToFileTime(ts, &ft); else { if (tz->offset == INT_MIN) CalcTsOffset(tz); UnixTimeToFileTime(ts + tz->offset, &ft); } SYSTEMTIME st; FileTimeToSystemTime(&ft, &st); FormatTime(&st, szFormat, szDest, cbDest); return 0; }
static int timeapiPrintTimeStamp(HANDLE hTZ, time_t ts, LPCTSTR szFormat, LPTSTR szDest, int cbDest, DWORD dwFlags) { MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ; if (tz == NULL && (dwFlags & (TZF_DIFONLY | TZF_KNOWNONLY))) return 1; FILETIME ft; if (tz == NULL) tz = &myInfo.myTZ; if (tz == NULL) { FILETIME lft; UnixTimeToFileTime(ts, &lft); FileTimeToLocalFileTime(&lft, &ft); } else if (tz == UTC_TIME_HANDLE) UnixTimeToFileTime(ts, &ft); else { if (tz->offset == INT_MIN) CalcTsOffset(tz); UnixTimeToFileTime(ts + tz->offset, &ft); } SYSTEMTIME st; FileTimeToSystemTime(&ft, &st); FormatTime(&st, szFormat, szDest, cbDest); return 0; }
/* * @implemented */ int _futime (int nHandle, struct _utimbuf *pTimes) { FILETIME LastAccessTime; FILETIME LastWriteTime; // check for stdin / stdout handles ?? if (nHandle == -1) { __set_errno(EBADF); return -1; } if (pTimes == NULL) { pTimes = alloca(sizeof(struct _utimbuf)); time(&pTimes->actime); time(&pTimes->modtime); } if (pTimes->actime < pTimes->modtime) { __set_errno(EINVAL); return -1; } UnixTimeToFileTime(pTimes->actime,&LastAccessTime,0); UnixTimeToFileTime(pTimes->modtime,&LastWriteTime,0); if (!SetFileTime(_get_osfhandle(nHandle),NULL, &LastAccessTime, &LastWriteTime)) { __set_errno(EBADF); return -1; } return 0; }
void UnixTimeToSystemTime(const time_t t, LPSYSTEMTIME pst) { FILETIME ft; UnixTimeToFileTime(t, &ft); FileTimeToSystemTime(&ft, pst); }
int SetFileTimes (const char* Path, time_t T) /* Set the time of last modification and the time of last access of a file to ** the given time T. This calls utime() for system where it works, and applies ** workarounds for all others (which in fact means "WINDOWS"). */ { HANDLE H; FILETIME FileTime; int Error = EACCES; /* Assume an error */ /* Open the file */ H = CreateFile (Path, GENERIC_WRITE, FILE_SHARE_READ, 0, /* Security attributes */ OPEN_EXISTING, 0, /* File flags */ 0); /* Template file */ if (H != INVALID_HANDLE_VALUE) { /* Set access and modification time */ UnixTimeToFileTime (T, &FileTime); if (SetFileTime (H, 0, &FileTime, &FileTime)) { /* Done */ Error = 0; } /* Close the handle */ (void) CloseHandle (H); } /* Return the error code */ return Error; }
BOOL CTBBMailbox::GetMsgInfo( TBBMsgHeader * pHdr, PMsgInfo lpInfo ) { if ( lpInfo == NULL ) return FALSE; lpInfo->StructSize = sizeof( TMsgInfo ); if ( pHdr->Priority > 0 ) lpInfo->Priority = EMP_HIGH; else if ( pHdr->Priority < 0 ) lpInfo->Priority = EMP_LOW; else lpInfo->Priority = EMP_NORMAL; lpInfo->Flags = 0; if ( pHdr->Flags & TBF_DELETED ) lpInfo->Flags |= EMF_DELETED; if ( pHdr->Flags & TBF_READED ) lpInfo->Flags |= EMF_READED; if ( pHdr->Flags & TBF_FLAGGED ) lpInfo->Flags |= EMF_FLAGGED; if ( pHdr->Flags & TBF_REPLIED ) lpInfo->Flags |= EMF_REPLIED; if ( pHdr->Flags & TBF_FORWARDED ) lpInfo->Flags |= EMF_FORWDED; UnixTimeToFileTime( pHdr->Received, &lpInfo->Received ); return TRUE; }
/** * Generates a new UID in outlook format. Format is described in VConverter::HrMakeBinaryUID * * @param[out] lpStrData returned generated UID string * @return MAPI error code */ HRESULT HrGenerateUid(std::string *lpStrData) { HRESULT hr = hrSuccess; std::string strByteArrayID = "040000008200E00074C5B7101A82E008"; std::string strBinUid; GUID sGuid; FILETIME ftNow; ULONG ulSize = 1; hr = CoCreateGuid(&sGuid); if (hr != hrSuccess) goto exit; hr = UnixTimeToFileTime(time(NULL), &ftNow); if (hr != hrSuccess) goto exit; strBinUid = strByteArrayID; // Outlook Guid strBinUid += "00000000"; // InstanceDate strBinUid += bin2hex(sizeof(FILETIME), (LPBYTE)&ftNow); strBinUid += "0000000000000000"; // Padding strBinUid += bin2hex(sizeof(ULONG), (LPBYTE)&ulSize); // always 1 strBinUid += bin2hex(sizeof(GUID), (LPBYTE)&sGuid); // new guid lpStrData->swap(strBinUid); exit: return hr; }
bool touchmind::util::TimeUtil::UnixTimeToSystemTime(time_t t, SYSTEMTIME* systemTime) { FILETIME fileTime; UnixTimeToFileTime(t, &fileTime); return FileTimeToSystemTime(&fileTime, systemTime) != 0; }
int WINAPI _export GetArcItem(struct PluginPanelItem *Item,struct ArcItemInfo *Info) { if (setjmp(jumper) != 0) {cleanup(); return GETARC_BROKEN;} // Сюда мы попадём при возникновении ошибки в одной из вызываемых процедур // Считаем следующий блок каталога архива, если все файлы из текущего уже перечислены if( current_block < 0 || ++current_file_in_block >= dirblock->total_files) { FreeAndNil (dirblock); for(;;) { if( ++current_block == arcinfo->control_blocks_descriptors.size ) { return GETARC_EOF; } // Если это блок каталога - прочитаем его и выйдем из цикла BLOCK& descriptor = arcinfo->control_blocks_descriptors [current_block]; if (descriptor.type == DIR_BLOCK) { dirblock = new DIRECTORY_BLOCK (*arcinfo, descriptor); current_file_in_block = current_data_block = 0; if (dirblock->total_files>0) break; FreeAndNil (dirblock); } } //printf("%d files\n", dirblock->total_files); } // Заполним описание файла int i = current_file_in_block; Item->FindData.dwFileAttributes = dirblock->isdir[i]? FILE_ATTRIBUTE_DIRECTORY : 0; UnixTimeToFileTime (dirblock->time[i], &Item->FindData.ftLastWriteTime); Item->FindData.nFileSizeHigh = ((uint64) dirblock->size[i]) >> 32; Item->FindData.nFileSizeLow = dirblock->size[i]; char utf8name[MY_FILENAME_MAX*4]; WCHAR utf16name[MY_FILENAME_MAX*2]; dirblock->fullname (i, utf8name); utf8_to_utf16 (utf8name, utf16name); CharToOemW (utf16name, Item->FindData.cFileName); Item->CRC32 = dirblock->crc[i]; Info->UnpVer = UnpVer; // Теперь извлечём информацию из описания солид-блока int &b = current_data_block; // Увеличим номер солид-блока если мы вышли за последний принадлежащий ему файл if (current_file_in_block >= dirblock->block_end(b)) b++; // Если это первый файл в солид-блоке - соберём block-related информацию if (current_file_in_block == dirblock->block_start(b)) { // Запишем на первый файл в блоке весь его упакованный размер uint64 packed = dirblock->data_block[b].compsize; Item->PackSizeHigh = packed >> 32; Item->PackSize = packed; // Запомним информацию о солид-блоке для использования её со всеми файлами из этого солид-блока char *c = dirblock->data_block[b].compressor; Solid = dirblock->block_start(b)+1 != dirblock->block_end(b); Encrypted = strstr (c, "+aes-")!=NULL || strstr (c, "+serpent-")!=NULL || strstr (c, "+blowfish-")!=NULL || strstr (c, "+twofish-")!=NULL; DictSize = compressorGetDecompressionMem (dirblock->data_block[b].compressor); }
void UnixTimeToSystemTime(time_t t, LPSYSTEMTIME pst) { FILETIME ft; SYSTEMTIME st; UnixTimeToFileTime(t, &ft); FileTimeToSystemTime(&ft, &st); SystemTimeToTzSpecificLocalTime(NULL, &st, pst); }
int setFileAccessed(const std::string& filename, time_t accessed){ FILETIME accesstime; UnixTimeToFileTime(accessed,&accesstime); HANDLE fhnd = CreateFileA(filename.c_str(), FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); int ret = SetFileTime(fhnd,NULL,&accesstime,NULL); CloseHandle(fhnd); return ret; }
int setFileTimes(const std::string& filename, unsigned long modified, unsigned long created, unsigned long accessed){ // Create a FILETIME struct and convert our new SYSTEMTIME // over to the FILETIME struct for use in SetFileTime below FILETIME modtime,createtime,accesstime; UnixTimeToFileTime(created,&createtime); UnixTimeToFileTime(accessed,&accesstime); // Get a handle to our file and with file_write_attributes access HANDLE fhnd = CreateFileA(filename.c_str(), FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); // Set the file time on the file int ret = SetFileTime(fhnd,&createtime,&accesstime,&modtime); // Close our handle. CloseHandle(fhnd); return ret; }
void MakeExtractingInfo(CTar32* pTarfile,const char *fname,EXTRACTINGINFOEX &extractinfo,EXTRACTINGINFOEX64 &exinfo64) { CTar32FileStatus &stat = pTarfile->m_currentfile_status; //EXTRACTINGINFOEX extractinfo; { memset(&extractinfo,0,sizeof(extractinfo)); extractinfo.exinfo.dwFileSize = (DWORD)stat.original_size; extractinfo.exinfo.dwWriteSize = 0; strncpy(extractinfo.exinfo.szSourceFileName, pTarfile->get_arc_filename().c_str(),FNAME_MAX32+1); strncpy(extractinfo.exinfo.szDestFileName, fname, FNAME_MAX32+1); extractinfo.dwCompressedSize = (DWORD)stat.compress_size; extractinfo.dwCRC = stat.chksum; extractinfo.uOSType = 0; extractinfo.wRatio = (WORD)(extractinfo.exinfo.dwFileSize ? (1000 * extractinfo.dwCompressedSize / extractinfo.exinfo.dwFileSize) : 0); extractinfo.wDate = GetARCDate(stat.mtime); extractinfo.wTime = GetARCTime(stat.mtime); GetARCAttribute(stat.mode, extractinfo.szAttribute,sizeof(extractinfo.szAttribute)); GetARCMethod(pTarfile->m_archive_type, extractinfo.szMode, sizeof(extractinfo.szMode)); } //EXTRACTINGINFOEX64 exinfo64; { memset(&exinfo64,0,sizeof(exinfo64)); exinfo64.dwStructSize=sizeof(exinfo64); exinfo64.exinfo=extractinfo.exinfo; exinfo64.llFileSize =stat.original_size; exinfo64.llCompressedSize =stat.compress_size; exinfo64.llWriteSize =0; exinfo64.dwAttributes =GetARCAttribute(stat.mode); exinfo64.dwCRC =extractinfo.dwCRC; exinfo64.uOSType =extractinfo.uOSType; exinfo64.wRatio =extractinfo.wRatio; UnixTimeToFileTime(stat.ctime,exinfo64.ftCreateTime); UnixTimeToFileTime(stat.atime,exinfo64.ftAccessTime); UnixTimeToFileTime(stat.mtime,exinfo64.ftWriteTime); strncpy(exinfo64.szMode,extractinfo.szMode,sizeof(exinfo64.szMode)); strncpy(exinfo64.szSourceFileName, extractinfo.exinfo.szSourceFileName,FNAME_MAX32+1); strncpy(exinfo64.szDestFileName, extractinfo.exinfo.szDestFileName, FNAME_MAX32+1); } }
// Превратить время/дату файла в строку в соответствии с настройками locale или заданными форматами времени и даты void GuiFormatDateTime (time_t t, char *buf, int bufsize, char *date_format, char *time_format) { if (t<0) t=INT_MAX; // Иначе получаем вылет :( FILETIME ft1, ft2; UnixTimeToFileTime (t, &ft1); FileTimeToLocalFileTime (&ft1, &ft2); SYSTEMTIME datetime; FileTimeToSystemTime (&ft2, &datetime); GetDateFormatA(LOCALE_USER_DEFAULT, 0, &datetime, date_format, buf, bufsize); char *p = str_end(buf); *p++ = ' '; GetTimeFormatA(LOCALE_USER_DEFAULT, 0, &datetime, time_format, p, bufsize - (p-buf)); }
static HANDLE fillLfWithFile(WIN32_FIND_DATA * FindData, LastFindStructType * lf, size_t n) { //Copy that info to TotalCommander's structure my_fxp_names * currentDir = lf->mCurrentDir; fxp_name * name = currentDir->names[n]; if (lf->hideDotNames) { // skip dot names for(;;) { if (name->filename[0] != '.' || name->filename[1] == 0) break; ++n; if (n >= lf->mSumIndex) return INVALID_HANDLE_VALUE; name = currentDir->names[n]; } } lf->mCurrentIndex = n; char FileTyp = name->longname[0]; FindData->dwReserved0 = octal_permissions_2_tc_integral(name->attrs.permissions); if (FileTyp == 'd') { FindData->dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY | 0x80000000; } else if (FileTyp == 'l') { FindData->dwFileAttributes = FILE_ATTRIBUTE_REPARSE_POINT | FILE_ATTRIBUTE_DIRECTORY |0x80000000; FindData->dwReserved0 |= S_IFLNK; // Wincmd uses only this one! } else { FindData->dwFileAttributes = FILE_ATTRIBUTE_NORMAL | 0x80000000; } if (!UnixTimeToFileTime (name->attrs.mtime, &FindData->ftLastWriteTime)) { FindData->ftLastWriteTime.dwHighDateTime = 0xFFFFFFFF; FindData->ftLastWriteTime.dwLowDateTime = 0xFFFFFFFE; } FindData->nFileSizeHigh = (DWORD) name->attrs.size.hi; FindData->nFileSizeLow = (FindData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? 0 : (DWORD) name->attrs.size.lo; bstrcpy(FindData->cFileName, name->filename); return (HANDLE) lf; }
//--------------------------------------------------------------------- // get a remote file -> local bool Server::cmdGet(bstring const & remotePath, bstring const & localName, bool exists) { DBGPRINT(("get '%s' '%s' %b\r\n", remotePath.c_str(), localName.c_str(), exists)); bstring cmd = bstring(exists ? TEXT("reget \"") : TEXT("get \"")) + remotePath + TEXT("\" \"") + localName + TEXT("\""); if (!doCommand(cmd)) return false; FILETIME ft; fxp_attrs * attr = currentMapper->getLastAttr(); if (UnixTimeToFileTime(attr->mtime, &ft)) { HANDLE hf = CreateFile(localName.c_str(), GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0); SetFileTime(hf, &ft, &ft, &ft); CloseHandle(hf); } return true; }
//--------------------------------------------------------------------- // move a remote file to a remote file bool Server::cmdMove(bstring const & oldRemotePath, bstring const & newRemotePath) { bstring cmd = bstring(TEXT("mv \"")) + oldRemotePath + TEXT("\" \"") + newRemotePath + TEXT("\""); if (!doCommand(cmd)) return false; fxp_name * fn = removeFile(oldRemotePath); if (fn) { FILETIME ft; UnixTimeToFileTime(fn->attrs.mtime, &ft); insertFile(newRemotePath, &ft, fn->attrs.size.lo, fn->attrs.size.hi, fn->longname[0]); freeFn(fn); } else { bstring path; splitPath(path, newRemotePath); invalidateDirContent(path); } return true; }
static time_t timeapiTimeStampToTimeZoneTimeStamp(HANDLE hTZ, time_t ts) { MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ; if (tz == NULL) tz = &myInfo.myTZ; if (tz == NULL) { FILETIME ft, lft; UnixTimeToFileTime(ts, &ft); FileTimeToLocalFileTime(&ft, &lft); return FileTimeToUnixTime(&lft); } else if (tz == UTC_TIME_HANDLE) return ts; if (tz->offset == INT_MIN) CalcTsOffset(tz); return ts + tz->offset; }
/* * Get the DST offset for the time passed in. */ static double calculateDSTOffset(time_t localTime, double utcOffset) { #if OS(WINDOWS) FILETIME utcFileTime; UnixTimeToFileTime(localTime, &utcFileTime); SYSTEMTIME utcSystemTime, localSystemTime; if (!::FileTimeToSystemTime(&utcFileTime, &utcSystemTime)) return 0; if (!::SystemTimeToTzSpecificLocalTime(nullptr, &utcSystemTime, &localSystemTime)) return 0; double offsetTime = (localTime * msPerSecond) + utcOffset; // Offset from UTC but doesn't include DST obviously int offsetHour = msToHours(offsetTime); int offsetMinute = msToMinutes(offsetTime); double diff = ((localSystemTime.wHour - offsetHour) * secondsPerHour) + ((localSystemTime.wMinute - offsetMinute) * 60); return diff * msPerSecond; #else //input is UTC so we have to shift back to local time to determine DST thus the + getUTCOffset() double offsetTime = (localTime * msPerSecond) + utcOffset; // Offset from UTC but doesn't include DST obviously int offsetHour = msToHours(offsetTime); int offsetMinute = msToMinutes(offsetTime); tm localTM; getLocalTime(&localTime, &localTM); double diff = ((localTM.tm_hour - offsetHour) * secondsPerHour) + ((localTM.tm_min - offsetMinute) * 60); if (diff < 0) diff += secondsPerDay; return (diff * msPerSecond); #endif }
DWORD FmtData(TCHAR *buf, BYTE *HexData, TYPE baseType, bool displaySigned, bool displayHex, bool bigEndian) { double f; DWORD typeLenLookup[] = { 0, 1, 2, 1, 2, 4, 8, 4, 8, 4, 2, 2, 4, 8 }; // TCHAR *typeFmtLookupHex2[] = { 0, TEXT("%#02x \'%c\'"), TEXT("%#04x '%lc\'"), TEXT("%#02x"), TEXT("%#04x"), TEXT("%#08x"), TEXT("%#0I64x"), TEXT("%#g"), TEXT("%#g") }; TCHAR *typeFmtLookupHex[] = { 0, TEXT("%02x \'%c\'"), TEXT("%04x '%lc\'"), TEXT("%02x"), TEXT("%04x"), TEXT("%08x"), TEXT("%0I64x"), TEXT("%#g"), TEXT("%#g") }; TCHAR *typeFmtLookupSigned[] = { 0, TEXT("%d \'%c\'"), TEXT("%d \'%lc\'"), TEXT("%d"), TEXT("%hd"), TEXT("%d"), TEXT("%I64d"), TEXT("%#g"), TEXT("%#g") }; TCHAR *typeFmtLookupUnsigned[] = { 0, TEXT("%u \'%c\'"), TEXT("%u \'%lc\'"), TEXT("%u"), TEXT("%hu"), TEXT("%u"), TEXT("%I64u"), TEXT("%#g"), TEXT("%#g") }; TCHAR *fmt; if(displayHex) fmt = typeFmtLookupHex[baseType]; else if(displaySigned) fmt = typeFmtLookupSigned[baseType]; else fmt = typeFmtLookupUnsigned[baseType]; DWORD dwLength = typeLenLookup[baseType]; if(bigEndian || g_fDisplayBigEndian) reverse(HexData, dwLength); struct DOSDATE { WORD day : 5; WORD month : 4; WORD year : 7; } *dosdate = (DOSDATE *)HexData; struct DOSTIME { WORD sec : 5; WORD min : 6; WORD hour : 5; } *dostime = (DOSTIME *)HexData; FILETIME ft; SYSTEMTIME st; switch(baseType) { case typeDOSTIME: _stprintf(buf, TEXT("%02d:%02d:%02d"), dostime->hour, dostime->min, dostime->sec); break; case typeDOSDATE: _stprintf(buf, TEXT("%02d/%02d/%04d"), dosdate->day, dosdate->month, dosdate->year); break; case typeTIMET: UnixTimeToFileTime(*(time_t *)HexData, &ft); FileTimeToSystemTime((FILETIME *)HexData, &st); _stprintf(buf, TEXT("%02d/%02d/%04d %02d:%02d:%02d"), st.wDay, st.wMonth, st.wYear, st.wHour, st.wMinute, st.wSecond); break; case typeFILETIME: FileTimeToSystemTime((FILETIME *)HexData, &st); _stprintf(buf, TEXT("%02d/%02d/%04d %02d:%02d:%02d"), st.wDay, st.wMonth, st.wYear, st.wHour, st.wMinute, st.wSecond); break; case typeCHAR: _stprintf(buf, fmt, HexData[0], HexData[0] < ' ' ? '.' : HexData[0]); break; case typeWCHAR: _stprintf(buf, fmt, *(WCHAR *)(&HexData[0])); break; case typeBYTE: _stprintf(buf, fmt, HexData[0]); break; case typeWORD: _stprintf(buf, fmt, *(UINT16 *)(&HexData[0])); break; case typeDWORD: _stprintf(buf, fmt, *(UINT32 *)(&HexData[0])); break; case typeQWORD: _stprintf(buf, fmt, *(UINT64 *)(&HexData[0])); break; case typeFLOAT: f = *(float *)(&HexData[0]); _stprintf(buf, fmt, f); break; case typeDOUBLE: f = *(double*)(&HexData[0]); _stprintf(buf, fmt, f); break; } return 0; }
int PaintListFileWindow(HWND hwnd, LISTWINDOW_INFO *lpListWindowInfo) { DIRECTORY_INFO *lpDirectoryInfo; DIRECTORY_LIST *llist; RECT clientRect; RECT textRect; TEXTMETRIC textMetric; HFONT hLargeFont; HFONT hSmallFont; SIZE sizeTextExtent; int heightLargeFont; int heightSmallFont; int heightLine; HDC hdc; PAINTSTRUCT psPaint; char textoutbuffer[255]; char filesizeString[255]; char durationString[255]; FILETIME filetime; SYSTEMTIME systemtime; int smallcolumnwidth=80; int dividerlinewidth=2; int y=0; lpDirectoryInfo=&lpListWindowInfo->directoryInfo; hdc = BeginPaint(hwnd, &psPaint); GetClientRect(hwnd, &clientRect); //Load the fonts hLargeFont = CreateFont( MulDiv(13, GetDeviceCaps(hdc, LOGPIXELSY), 72), 0,0,0,FW_BOLD, FALSE,FALSE,FALSE, DEFAULT_CHARSET,OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY, VARIABLE_PITCH|FF_SWISS,"Arial"); hSmallFont = CreateFont( MulDiv(8, GetDeviceCaps(hdc, LOGPIXELSY), 72), 0,0,0,FW_BOLD, FALSE,FALSE,FALSE, DEFAULT_CHARSET,OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS,NONANTIALIASED_QUALITY, VARIABLE_PITCH|FF_SWISS,"Arial"); SelectObject(hdc,hLargeFont); GetTextMetrics(hdc, &textMetric); heightLargeFont= textMetric.tmHeight; SelectObject(hdc,hSmallFont); GetTextMetrics(hdc, &textMetric); heightSmallFont= textMetric.tmHeight; if ((heightLargeFont)>(2*heightSmallFont)) //if the large font is much larger, then it controls line height heightLine=heightLargeFont/2; else heightLine=heightSmallFont; GetTextExtentPoint32(hdc, "WW/WW/WW", 8, &sizeTextExtent); smallcolumnwidth = sizeTextExtent.cx; //Start going through linked list, and display all the files llist=lpDirectoryInfo->first; //Skip up until the first thing to display while ((llist) && (llist->index<lpListWindowInfo->firstLine) ) { if ((llist->index < lpListWindowInfo->firstLine)) llist->boundingRect.top=-1;llist->boundingRect.bottom=-1; llist->boundingRect.left=-1;llist->boundingRect.right=-1; llist=llist->next; } while ((llist)&&(y<clientRect.bottom)) { if (llist->index==lpListWindowInfo->selectedLine) { SetTextColor(hdc, RGB_ZINNY_WHITE); SetBkColor(hdc, RGB_ZINNY_BRIGHTBLUE); } else { SetTextColor(hdc, RGB_ZINNY_DARKBLUE); SetBkColor(hdc, RGB_ZINNY_MIDPURPLE); } //Draw the Recording Name, then the filename (on the left) SetTextAlign(hdc, TA_LEFT); SelectObject(hdc,hLargeFont); textRect.left=clientRect.left; textRect.right=clientRect.right-smallcolumnwidth; textRect.top=y+0;textRect.bottom=y+heightLargeFont; ExtTextOut(hdc, 5,textRect.top, ETO_OPAQUE, &textRect, llist->recordingname, strlen(llist->recordingname), NULL); SelectObject(hdc,hSmallFont); //textRect.top=y+2*heightLine;textRect.bottom=y+3*heightLine; textRect.top=y+heightLargeFont;textRect.bottom=y+3*heightLine; ExtTextOut(hdc, 5,textRect.top, ETO_OPAQUE, &textRect, llist->shortfilename, strlen(llist->shortfilename), NULL); SetTextAlign(hdc, TA_RIGHT); //This helps to get a pretty date UnixTimeToFileTime(llist->unixtime, &filetime); FileTimeToSystemTime(&filetime, &systemtime); textRect.top=y+0;textRect.bottom=y+1*heightLine; textRect.left=clientRect.right-smallcolumnwidth; textRect.right=clientRect.right; sprintf(textoutbuffer, "%02d/%02d/%04d",systemtime.wDay,systemtime.wMonth,systemtime.wYear); ExtTextOut(hdc, textRect.right-5,textRect.top, ETO_OPAQUE, &textRect, textoutbuffer, strlen(textoutbuffer), NULL); textRect.top=y+1*heightLine;textRect.bottom=y+2*heightLine; //24 hour time sprintf(textoutbuffer, "%02d:%02d",systemtime.wHour,systemtime.wMinute); //12 hour time sprintf(textoutbuffer, "%d:%02d%s",systemtime.wHour==0?12:(systemtime.wHour>12?systemtime.wHour-12:systemtime.wHour),systemtime.wMinute, systemtime.wHour>=12?"p":"a"); ExtTextOut(hdc, textRect.right-5,textRect.top, ETO_OPAQUE, &textRect, textoutbuffer, strlen(textoutbuffer), NULL); DurationShortFormatDHMS(llist->duration, durationString); sprintf(textoutbuffer, "%s", durationString); textRect.top=y+2*heightLine;textRect.bottom=y+3*heightLine; ExtTextOut(hdc, textRect.right-5,textRect.top, ETO_OPAQUE, &textRect, textoutbuffer, strlen(textoutbuffer), NULL); //We won't display the size, as if often not done correctly //BytesDisplayNice(llist->filesize, "%.2f %s", 1, filesizeString); SetBkColor(hdc, RGB_ZINNY_HIGHPURPLE); textRect.left=clientRect.left; textRect.right=clientRect.right; textRect.top=y+3*heightLine;textRect.bottom=y+3*heightLine+dividerlinewidth; ExtTextOut(hdc, 0,0, ETO_OPAQUE, &textRect, "", 0, NULL); //this is the separator llist->boundingRect.left=clientRect.left; llist->boundingRect.right=clientRect.right; llist->boundingRect.top=y; llist->boundingRect.bottom=y+3*heightLine+dividerlinewidth; if (llist->index==lpListWindowInfo->selectedLine) { //if this is selected, remember its bounding box lpListWindowInfo->oldBoundingRect.left=llist->boundingRect.left; lpListWindowInfo->oldBoundingRect.right=llist->boundingRect.right; lpListWindowInfo->oldBoundingRect.top=llist->boundingRect.top; lpListWindowInfo->oldBoundingRect.bottom=llist->boundingRect.bottom; } y+=3*heightLine+dividerlinewidth; if (y<=clientRect.bottom) //if this is true, then we have displayed a full line lpListWindowInfo->fullyDisplayedLines=llist->index - lpListWindowInfo->firstLine; llist=llist->next; } //Because we don't display these, we need to ensure their bounding rects are gone while (llist) { llist->boundingRect.left=-1; llist->boundingRect.right=-1; llist->boundingRect.top=-1; llist->boundingRect.bottom=-1; llist=llist->next; } // if (y<clientRect.bottom) //if we don't get to the end, work it out by dividing lpListWindowInfo->fullyDisplayedLines=(clientRect.bottom-clientRect.top) / (3*heightLine+dividerlinewidth); SetBkColor(hdc, RGB_ZINNY_MIDPURPLE); textRect.left=clientRect.left; textRect.right=clientRect.right; textRect.top=y; textRect.bottom=clientRect.bottom; ExtTextOut(hdc, 0,0, ETO_OPAQUE, &textRect, "", 0, NULL); //this is the separator //SHBrowseForFolder DeleteObject(hSmallFont); DeleteObject(hLargeFont); EndPaint (hwnd, &psPaint); ListScrollUpdate(hwnd, lpListWindowInfo); return 0; }
ECRESULT ECUserStoreTable::QueryRowData(ECGenericObjectTable *lpThis, struct soap *soap, ECSession *lpSession, ECObjectTableList* lpRowList, struct propTagArray *lpsPropTagArray, void* lpObjectData, struct rowSet **lppRowSet, bool bCacheTableData, bool bTableLimit) { ECRESULT er = erSuccess; ECUserStoreTable *pThis = dynamic_cast<ECUserStoreTable*>(lpThis); struct rowSet *lpsRowSet = NULL; ECObjectTableList::iterator iterRowList; int i, k; GUID sZeroGuid = {0}; if (!lpThis) { er = ZARAFA_E_INVALID_PARAMETER; goto exit; } lpsRowSet = s_alloc<rowSet>(soap); lpsRowSet->__size = 0; lpsRowSet->__ptr = NULL; if(lpRowList->empty()) { *lppRowSet = lpsRowSet; goto exit; // success } // We return a square array with all the values lpsRowSet->__size = lpRowList->size(); lpsRowSet->__ptr = s_alloc<propValArray>(soap, lpsRowSet->__size); memset(lpsRowSet->__ptr, 0, sizeof(propValArray) * lpsRowSet->__size); // Allocate memory for all rows for (i = 0; i < lpsRowSet->__size; i++) { lpsRowSet->__ptr[i].__size = lpsPropTagArray->__size; lpsRowSet->__ptr[i].__ptr = s_alloc<propVal>(soap, lpsPropTagArray->__size); memset(lpsRowSet->__ptr[i].__ptr, 0, sizeof(propVal) * lpsPropTagArray->__size); } for (i = 0, iterRowList = lpRowList->begin(); iterRowList != lpRowList->end(); iterRowList++, i++) { for (k = 0; k < lpsPropTagArray->__size; k++) { lpsRowSet->__ptr[i].__ptr[k].ulPropTag = PROP_TAG(PT_ERROR, lpsPropTagArray->__ptr[k]); lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_ul; lpsRowSet->__ptr[i].__ptr[k].Value.ul = ZARAFA_E_NOT_FOUND; switch (PROP_ID(lpsPropTagArray->__ptr[k])) { case PROP_ID(PR_INSTANCE_KEY): // generate key lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_bin; lpsRowSet->__ptr[i].__ptr[k].ulPropTag = PR_INSTANCE_KEY; lpsRowSet->__ptr[i].__ptr[k].Value.bin = s_alloc<xsd__base64Binary>(soap); lpsRowSet->__ptr[i].__ptr[k].Value.bin->__size = sizeof(sObjectTableKey); lpsRowSet->__ptr[i].__ptr[k].Value.bin->__ptr = s_alloc<unsigned char>(soap, sizeof(sObjectTableKey)); memcpy(lpsRowSet->__ptr[i].__ptr[k].Value.bin->__ptr, (void*)&(*iterRowList), sizeof(sObjectTableKey)); break; case PROP_ID(PR_EC_USERNAME): if (!pThis->m_mapUserStoreData[iterRowList->ulObjId].strUsername.empty()) { lpsRowSet->__ptr[i].__ptr[k].ulPropTag = lpsPropTagArray->__ptr[k]; lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_lpszA; lpsRowSet->__ptr[i].__ptr[k].Value.lpszA = s_strcpy(soap, (char*)pThis->m_mapUserStoreData[iterRowList->ulObjId].strUsername.c_str()); } break; case PROP_ID(PR_DISPLAY_NAME): if (!pThis->m_mapUserStoreData[iterRowList->ulObjId].strGuessname.empty()) { lpsRowSet->__ptr[i].__ptr[k].ulPropTag = lpsPropTagArray->__ptr[k]; lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_lpszA; lpsRowSet->__ptr[i].__ptr[k].Value.lpszA = s_strcpy(soap, (char*)pThis->m_mapUserStoreData[iterRowList->ulObjId].strGuessname.c_str()); } break; case PROP_ID(PR_EC_STOREGUID): if (pThis->m_mapUserStoreData[iterRowList->ulObjId].sGuid != sZeroGuid) { lpsRowSet->__ptr[i].__ptr[k].ulPropTag = lpsPropTagArray->__ptr[k]; lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_bin; lpsRowSet->__ptr[i].__ptr[k].Value.bin = s_alloc<xsd__base64Binary>(soap); lpsRowSet->__ptr[i].__ptr[k].Value.bin->__size = sizeof(GUID); lpsRowSet->__ptr[i].__ptr[k].Value.bin->__ptr = s_alloc<unsigned char>(soap, sizeof(GUID)); memcpy(lpsRowSet->__ptr[i].__ptr[k].Value.bin->__ptr, (unsigned char*)&pThis->m_mapUserStoreData[iterRowList->ulObjId].sGuid, sizeof(GUID)); } break; case PROP_ID(PR_EC_STORETYPE): lpsRowSet->__ptr[i].__ptr[k].ulPropTag = lpsPropTagArray->__ptr[k]; lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_ul; lpsRowSet->__ptr[i].__ptr[k].Value.ul = pThis->m_mapUserStoreData[iterRowList->ulObjId].ulStoreType; break; case PROP_ID(PR_EC_COMPANYID): if (pThis->m_mapUserStoreData[iterRowList->ulObjId].ulCompanyId != 0) { lpsRowSet->__ptr[i].__ptr[k].ulPropTag = lpsPropTagArray->__ptr[k]; lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_ul; lpsRowSet->__ptr[i].__ptr[k].Value.ul = pThis->m_mapUserStoreData[iterRowList->ulObjId].ulCompanyId; } break; case PROP_ID(PR_EC_COMPANY_NAME): if (!pThis->m_mapUserStoreData[iterRowList->ulObjId].strCompanyName.empty()) { lpsRowSet->__ptr[i].__ptr[k].ulPropTag = lpsPropTagArray->__ptr[k]; lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_lpszA; lpsRowSet->__ptr[i].__ptr[k].Value.lpszA = s_strcpy(soap, (char*)pThis->m_mapUserStoreData[iterRowList->ulObjId].strCompanyName.c_str()); } break; case PROP_ID(PR_STORE_ENTRYID): // ignore errors ECGenProps::GetPropComputedUncached(soap, NULL ,lpSession, PR_STORE_ENTRYID, pThis->m_mapUserStoreData[iterRowList->ulObjId].ulObjId, 0, pThis->m_mapUserStoreData[iterRowList->ulObjId].ulObjId, 0, MAPI_STORE, &lpsRowSet->__ptr[i].__ptr[k]); break; case PROP_ID(PR_LAST_MODIFICATION_TIME): if (pThis->m_mapUserStoreData[iterRowList->ulObjId].tModTime != 0) { FILETIME ftTmp; UnixTimeToFileTime(pThis->m_mapUserStoreData[iterRowList->ulObjId].tModTime, &ftTmp); lpsRowSet->__ptr[i].__ptr[k].ulPropTag = lpsPropTagArray->__ptr[k]; lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_hilo; lpsRowSet->__ptr[i].__ptr[k].Value.hilo = s_alloc<struct hiloLong>(soap); lpsRowSet->__ptr[i].__ptr[k].Value.hilo->hi = ftTmp.dwHighDateTime; lpsRowSet->__ptr[i].__ptr[k].Value.hilo->lo = ftTmp.dwLowDateTime; } break; case PROP_ID(PR_MESSAGE_SIZE_EXTENDED): lpsRowSet->__ptr[i].__ptr[k].ulPropTag = lpsPropTagArray->__ptr[k]; lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_li; lpsRowSet->__ptr[i].__ptr[k].Value.li = pThis->m_mapUserStoreData[iterRowList->ulObjId].ullStoreSize; break; default: lpsRowSet->__ptr[i].__ptr[k].ulPropTag = PROP_TAG(PT_ERROR, lpsPropTagArray->__ptr[k]); lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_ul; lpsRowSet->__ptr[i].__ptr[k].Value.ul = ZARAFA_E_NOT_FOUND; break; }; } } *lppRowSet = lpsRowSet; exit: return er; }
// // offset - offset to read data from for this item // size_w FmtData(HWND hwndGV, HGRIDITEM hRoot, Type *type, size_w dwOffset, TypeDecl *typeDecl) { GVITEM gvitem = { 0 }; Enum *eptr; TCHAR buf[200]; double f; size_t i; DWORD typeLenLookup[] = { 0, 1, 2, 1, 2, 4, 8, 4, 8, 4, 2, 2, 4, 8 }; // TCHAR *typeFmtLookupHex2[] = { 0, TEXT("%#02x \'%c\'"), TEXT("%#04x '%lc\'"), TEXT("%#02x"), TEXT("%#04x"), TEXT("%#08x"), TEXT("%#0I64x"), TEXT("%#g"), TEXT("%#g") }; TCHAR *typeFmtLookupHex[] = { 0, TEXT("%02x \'%c\'"), TEXT("%04x '%lc\'"), TEXT("%02x"), TEXT("%04x"), TEXT("%08x"), TEXT("%0I64x"), TEXT("%#g"), TEXT("%#g") }; TCHAR *typeFmtLookupSigned[] = { 0, TEXT("%d \'%c\'"), TEXT("%d \'%lc\'"), TEXT("%d"), TEXT("%hd"), TEXT("%d"), TEXT("%I64d"), TEXT("%#g"), TEXT("%#g") }; TCHAR *typeFmtLookupUnsigned[] = { 0, TEXT("%u \'%c\'"), TEXT("%u \'%lc\'"), TEXT("%u"), TEXT("%hu"), TEXT("%u"), TEXT("%I64u"), TEXT("%#g"), TEXT("%#g") }; TCHAR *fmt; bool displaySigned = false; BOOL displayHex = g_fDisplayHex; bool bigEndian = false; TYPE baseType = BaseType(type); bool displayEnum = false; Enum *baseEnum = 0; displaySigned = FindType(type, typeSIGNED) ? true : false; if(typeDecl) { ExprNode *expr; if(FindTag(typeDecl->tagList, TOK_ENDIAN, &expr)) { if(strcmp(expr->str, "big") == 0) bigEndian = true; } if(FindTag(typeDecl->tagList, TOK_ENUM, &expr)) { baseEnum = FindEnum(expr->str); displayEnum = true; } } if(displayHex) fmt = typeFmtLookupHex[baseType]; else if(displaySigned) fmt = typeFmtLookupSigned[baseType]; else fmt = typeFmtLookupUnsigned[baseType]; BYTE HexData[8]; HWND hwndHV = GetActiveHexView(g_hwndMain); DWORD numread; numread = HexView_GetData(hwndHV, dwOffset, (BYTE *)&HexData, sizeof(HexData)); DWORD dwLength = typeLenLookup[type->ty]; if(numread < dwLength) { gvitem.pszText = TEXT(""); gvitem.iSubItem = COLIDX_DATA; gvitem.state = 0; gvitem.mask = GVIF_TEXT | GVIF_STATE; GridView2_SetItem(hwndGV, hRoot, &gvitem); return typeLenLookup[type->ty]; } if(bigEndian || g_fDisplayBigEndian) reverse(HexData, dwLength); if(FindType(type, typeDOSDATE)) baseType = type->ty; if(FindType(type, typeDOSTIME)) baseType = type->ty; if(FindType(type, typeFILETIME))baseType = type->ty; if(FindType(type, typeTIMET)) baseType = type->ty; if(displayEnum) { if(BaseType(type) == typeENUM) eptr = BaseNode(type)->eptr; else eptr = baseEnum; WORD *wptr = (WORD *)(&HexData[0]); _stprintf(buf, TEXT("%04x"), *wptr); for(i = 0; i < eptr->fieldList.size(); i++) { if(Evaluate(eptr->fieldList[i]->expr) == *wptr) { _stprintf(buf, TEXT("%hs"), eptr->fieldList[i]->name->name); break; } } gvitem.pszText = buf; gvitem.iSubItem = COLIDX_DATA; gvitem.state = GVIS_DROPDOWN; gvitem.mask = GVIF_TEXT | GVIF_STATE; GridView2_SetItem(hwndGV, hRoot, &gvitem); return SizeOf(type, 0, 0); } else { struct DOSDATE { WORD day : 5; WORD month : 4; WORD year : 7; } *dosdate = (DOSDATE *)HexData; struct DOSTIME { WORD sec : 5; WORD min : 6; WORD hour : 5; } *dostime = (DOSTIME *)HexData; FILETIME ft; SYSTEMTIME st; switch(baseType) { case typeDOSTIME: _stprintf(buf, TEXT("%02d:%02d:%02d"), dostime->hour, dostime->min, dostime->sec); break; case typeDOSDATE: _stprintf(buf, TEXT("%02d/%02d/%04d"), dosdate->day, dosdate->month, dosdate->year); break; case typeTIMET: UnixTimeToFileTime(*(time_t *)HexData, &ft); FileTimeToSystemTime((FILETIME *)HexData, &st); _stprintf(buf, TEXT("%02d/%02d/%04d %02d:%02d:%02d"), st.wDay, st.wMonth, st.wYear, st.wHour, st.wMinute, st.wSecond); break; case typeFILETIME: FileTimeToSystemTime((FILETIME *)HexData, &st); _stprintf(buf, TEXT("%02d/%02d/%04d %02d:%02d:%02d"), st.wDay, st.wMonth, st.wYear, st.wHour, st.wMinute, st.wSecond); break; case typeCHAR: _stprintf(buf, fmt, HexData[0], HexData[0] < ' ' ? '.' : HexData[0]); break; case typeWCHAR: _stprintf(buf, fmt, *(WCHAR *)(&HexData[0])); break; case typeBYTE: _stprintf(buf, fmt, HexData[0]); break; case typeWORD: _stprintf(buf, fmt, *(UINT16 *)(&HexData[0])); break; case typeDWORD: _stprintf(buf, fmt, *(UINT32 *)(&HexData[0])); break; case typeQWORD: _stprintf(buf, fmt, *(UINT64 *)(&HexData[0])); break; case typeFLOAT: f = *(float *)(&HexData[0]); _stprintf(buf, fmt, f); break; case typeDOUBLE: f = *(double*)(&HexData[0]); _stprintf(buf, fmt, f); break; case typeENUM: eptr = BaseNode(type)->eptr; { WORD *wptr = (WORD *)(&HexData[0]); _stprintf(buf, TEXT("%04x"), *wptr); for(i = 0; i < eptr->fieldList.size(); i++) { if(Evaluate(eptr->fieldList[i]->expr) == *wptr) { _stprintf(buf, TEXT("%hs"), eptr->fieldList[i]->name->name); break; } } } gvitem.pszText = buf; gvitem.iSubItem = COLIDX_DATA; gvitem.state = GVIS_DROPDOWN; gvitem.mask = GVIF_TEXT | GVIF_STATE; GridView2_SetItem(hwndGV, hRoot, &gvitem); return 4; } } gvitem.pszText = buf; gvitem.iSubItem = COLIDX_DATA; gvitem.state = 0; gvitem.mask = GVIF_TEXT | GVIF_STATE | GVIF_COLOR; gvitem.color = numread ? RGB(0,0,0) : RGB(128,128,128); GridView2_SetItem(hwndGV, hRoot, &gvitem); return typeLenLookup[type->ty]; }