Beispiel #1
0
static INT_PTR TimestampToString(WPARAM wParam,LPARAM lParam)
{
    DBTIMETOSTRING *tts=(DBTIMETOSTRING*)lParam;
    LARGE_INTEGER liFiletime;
    FILETIME filetime;
    SYSTEMTIME st;
    char dateTimeStr[64];
    char *pDest,*pFormat;
    size_t destCharsLeft, dateTimeStrLen;

    //this huge number is the difference between 1970 and 1601 in seconds
    liFiletime.QuadPart=((__int64)11644473600+(__int64)(DWORD)TimestampToLocal(wParam,0))*10000000;
    filetime.dwHighDateTime=liFiletime.HighPart;
    filetime.dwLowDateTime=liFiletime.LowPart;
    FileTimeToSystemTime(&filetime,&st);
    destCharsLeft=tts->cbDest;
    for(pFormat=tts->szFormat,pDest=tts->szDest; *pFormat; pFormat++) {
        switch(*pFormat) {
        case 't':
            GetTimeFormatA(LOCALE_USER_DEFAULT,TIME_NOSECONDS,&st,NULL,dateTimeStr,SIZEOF(dateTimeStr));
            break;
        case 's':
            GetTimeFormatA(LOCALE_USER_DEFAULT,0,&st,NULL,dateTimeStr,SIZEOF(dateTimeStr));
            break;
        case 'm':
            GetTimeFormatA(LOCALE_USER_DEFAULT,TIME_NOMINUTESORSECONDS,&st,NULL,dateTimeStr,SIZEOF(dateTimeStr));
            break;
        case 'd':
            GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&st,NULL,dateTimeStr,SIZEOF(dateTimeStr));
            break;
        case 'D':
            GetDateFormatA(LOCALE_USER_DEFAULT,DATE_LONGDATE,&st,NULL,dateTimeStr,SIZEOF(dateTimeStr));
            break;
        default:
            if(destCharsLeft) {
                *pDest++=*pFormat;
                destCharsLeft--;
            }
            continue;
        }
        dateTimeStrLen=strlen(dateTimeStr);
        if(destCharsLeft<dateTimeStrLen) dateTimeStrLen=destCharsLeft;
        CopyMemory(pDest,dateTimeStr,dateTimeStrLen);
        destCharsLeft-=dateTimeStrLen;
        pDest+=dateTimeStrLen;
    }
    if(destCharsLeft) *pDest=0;
    else tts->szDest[tts->cbDest-1]=0;
    return 0;
}
Beispiel #2
0
/*------------------------------------------------
  GetTimeFormat() for 95/NT
--------------------------------------------------*/
int MyGetTimeFormatW(int ilang, int codepage,
	DWORD dwFlags, CONST SYSTEMTIME *t,
	wchar_t* fmt, wchar_t* dst, int n)
{
	int r;
	LCID Locale;
	
	*dst = 0;
	Locale = MAKELCID((WORD)ilang, SORT_DEFAULT);
	if(GetVersion() & 0x80000000) // 95
	{
		char buf[80], afmt[40];
		if(fmt)
			WideCharToMultiByte(codepage, 0, fmt, -1,
				afmt, 39, NULL, NULL);
		r = GetTimeFormatA(Locale, dwFlags, t, fmt ? afmt : NULL, buf, 79);
		if(r)
			r = MultiByteToWideChar(codepage, 0, buf, -1, dst, n);
	}
	else  // NT
	{
		r = GetTimeFormatW(Locale, dwFlags, t, fmt, dst, n);
	}
	return r;
}
Beispiel #3
0
/*
 * @implemented
 */
char* _strtime(char* time)
{
   static const char format[] = "HH':'mm':'ss";

   GetTimeFormatA(LOCALE_NEUTRAL, 0, NULL, format, time, 9); 

   return time;
}
Beispiel #4
0
BOOL My_GetTimeFormatA()
{
	LCID Locale=NULL;
	DWORD dwFlags=NULL;
	CONST SYSTEMTIME * lpTime=NULL;
	LPCSTR lpFormat=NULL;
	LPSTR lpTimeStr=NULL;
	int cchTime=NULL;
	int returnVal_Real = NULL;
	int returnVal_Intercepted = NULL;

	DWORD error_Real = 0;
	DWORD error_Intercepted = 0;
	disableInterception();
	returnVal_Real = GetTimeFormatA (Locale,dwFlags,lpTime,lpFormat,lpTimeStr,cchTime);
	error_Real = GetLastError();
	enableInterception();
	returnVal_Intercepted = GetTimeFormatA (Locale,dwFlags,lpTime,lpFormat,lpTimeStr,cchTime);
	error_Intercepted = GetLastError();
	return ((returnVal_Real == returnVal_Intercepted) && (error_Real == error_Intercepted));
}
Beispiel #5
0
inline std::string NowTime()
{
   const int MAX_LEN = 200;
   char buffer[MAX_LEN];
   if (GetTimeFormatA(LOCALE_USER_DEFAULT, 0, 0, "HH':'mm':'ss", buffer, MAX_LEN) == 0) {
      return "Error in NowTime()";
   }

   char result[100];
   static DWORD first = GetTickCount();
   sprintf(result, "%s.%03ld", buffer, (long)(GetTickCount() - first) % 1000); 
   return result;
}
Beispiel #6
0
// Превратить время/дату файла в строку в соответствии с настройками 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));
}
Beispiel #7
0
static UINT WINAPI ExtCabCallback(PVOID Context, UINT Notification, UINT_PTR Param1, UINT_PTR Param2)
{
    FILE_IN_CABINET_INFO_W *pInfo;
    FILEPATHS_W *pFilePaths;

    switch(Notification)
    {
        case SPFILENOTIFY_FILEINCABINET:
            pInfo = (FILE_IN_CABINET_INFO_W*)Param1;
            if(show_content)
            {
                FILETIME ft;
                SYSTEMTIME st;
                CHAR date[12], time[12], buf[2 * MAX_PATH];
                int count;
                DWORD dummy;

                /* DosDate and DosTime already represented at local time */
                DosDateTimeToFileTime(pInfo->DosDate, pInfo->DosTime, &ft);
                FileTimeToSystemTime(&ft, &st);
                GetDateFormatA(0, 0, &st, "MM'-'dd'-'yyyy", date, sizeof date);
                GetTimeFormatA(0, 0, &st, "HH':'mm':'ss", time, sizeof time);
                count = wsprintfA(buf, "%s %s %c%c%c%c %15u %S\n", date, time,
                        pInfo->DosAttribs & FILE_ATTRIBUTE_ARCHIVE  ? 'A' : '-',
                        pInfo->DosAttribs & FILE_ATTRIBUTE_HIDDEN   ? 'H' : '-',
                        pInfo->DosAttribs & FILE_ATTRIBUTE_READONLY ? 'R' : '-',
                        pInfo->DosAttribs & FILE_ATTRIBUTE_SYSTEM   ? 'S' : '-',
                        pInfo->FileSize, pInfo->NameInCabinet);
                WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), buf, count, &dummy, NULL);
                return FILEOP_SKIP;
            }
            else
            {
                lstrcpyW(pInfo->FullTargetName, (LPCWSTR)Context);
                lstrcatW(pInfo->FullTargetName, pInfo->NameInCabinet);
                /* SetupIterateCabinet() doesn't create full path to target by itself,
                   so we should do it manually */
                create_target_directory(pInfo->FullTargetName);
                return FILEOP_DOIT;
            }
        case SPFILENOTIFY_FILEEXTRACTED:
            pFilePaths = (FILEPATHS_W*)Param1;
            WINE_TRACE("Extracted %s\n", wine_dbgstr_w(pFilePaths->Target));
            return NO_ERROR;
    }
    return NO_ERROR;
}
void kull_m_string_displayFileTime(IN PFILETIME pFileTime)
{
	SYSTEMTIME st;
	char buffer[0xff];
	if(pFileTime)
	{
		if(FileTimeToSystemTime(pFileTime, &st ))
		{
			if(GetDateFormatA(LOCALE_USER_DEFAULT, 0, &st, NULL, buffer, sizeof(buffer)))
			{
				dprintf("%s ", buffer);
				if(GetTimeFormatA(LOCALE_USER_DEFAULT, 0, &st, NULL, buffer, sizeof(buffer)))
					dprintf("%s", buffer);
			}
		}
	}
}
Beispiel #9
0
/**
 * Generates a timestamp of the current time.
 * @return String in D-M-Y_H-M-S format.
 */
std::string now()
{
	const int MAX_LEN = 25, MAX_RESULT = 80;
	char result[MAX_RESULT] = { 0 };
#ifdef _WIN32
	char date[MAX_LEN], time[MAX_LEN];
	if (GetDateFormatA(LOCALE_INVARIANT, 0, 0, "dd'-'MM'-'yyyy", date, MAX_LEN) == 0)
		return "00-00-0000";
	if (GetTimeFormatA(LOCALE_INVARIANT, TIME_FORCE24HOURFORMAT, 0, "HH'-'mm'-'ss", time, MAX_LEN) == 0)
		return "00-00-00";
	sprintf(result, "%s_%s", date, time);
#else
	char buffer[MAX_LEN];
	time_t rawtime;
	struct tm *timeinfo;
	time(&rawtime);
	timeinfo = localtime(&rawtime);
	strftime(buffer, MAX_LEN, "%d-%m-%Y_%H-%M-%S", timeinfo);
	sprintf(result, "%s", buffer);
#endif
	return result;
}
static void JabberSendPresenceTo(TlenProtocol *proto, int status, char *to)
{
	char *showBody, *statusMsg, *presenceType;
	char *ptr = NULL;

	if (!proto->isOnline) return;

	// Send <presence/> update for status (we won't handle ID_STATUS_OFFLINE here)
	// Note: jabberModeMsg is already encoded using JabberTextEncode()
	EnterCriticalSection(&proto->modeMsgMutex);

	showBody = NULL;
	statusMsg = NULL;
	presenceType = NULL;
	switch (status) {
	case ID_STATUS_ONLINE:
		showBody = "available";
		statusMsg = proto->modeMsgs.szOnline;
		break;
	case ID_STATUS_AWAY:
	case ID_STATUS_ONTHEPHONE:
	case ID_STATUS_OUTTOLUNCH:
		showBody = "away";
		statusMsg = proto->modeMsgs.szAway;
		break;
	case ID_STATUS_NA:
		showBody = "xa";
		statusMsg = proto->modeMsgs.szNa;
		break;
	case ID_STATUS_DND:
	case ID_STATUS_OCCUPIED:
		showBody = "dnd";
		statusMsg = proto->modeMsgs.szDnd;
		break;
	case ID_STATUS_FREECHAT:
		showBody = "chat";
		statusMsg = proto->modeMsgs.szFreechat;
		break;
	case ID_STATUS_INVISIBLE:
		presenceType = "invisible";
		statusMsg = proto->modeMsgs.szInvisible;
		break;
	case ID_STATUS_OFFLINE:
		presenceType = "unavailable";
		if (DBGetContactSettingByte(NULL, proto->iface.m_szModuleName, "LeaveOfflineMessage", FALSE)) {
			int offlineMessageOption = DBGetContactSettingWord(NULL, proto->iface.m_szModuleName, "OfflineMessageOption", 0);
			if (offlineMessageOption == 0) {
				switch (proto->iface.m_iStatus) {
					case ID_STATUS_ONLINE:
						ptr = mir_strdup(proto->modeMsgs.szOnline);
						break;
					case ID_STATUS_AWAY:
					case ID_STATUS_ONTHEPHONE:
					case ID_STATUS_OUTTOLUNCH:
						ptr = mir_strdup(proto->modeMsgs.szAway);
						break;
					case ID_STATUS_NA:
						ptr = mir_strdup(proto->modeMsgs.szNa);
						break;
					case ID_STATUS_DND:
					case ID_STATUS_OCCUPIED:
						ptr = mir_strdup(proto->modeMsgs.szDnd);
						break;
					case ID_STATUS_FREECHAT:
						ptr = mir_strdup(proto->modeMsgs.szFreechat);
						break;
					case ID_STATUS_INVISIBLE:
						ptr = mir_strdup(proto->modeMsgs.szInvisible);
						break;
				}
			} else if (offlineMessageOption == 99) {

			} else if (offlineMessageOption < 7) {
				DBVARIANT dbv;
				const char *statusNames[] = {"OnDefault", "AwayDefault", "NaDefault", "DndDefault", "FreeChatDefault", "InvDefault"};
				if (!DBGetContactSetting(NULL, "SRAway", statusNames[offlineMessageOption-1], &dbv)) {
					int i;
					char substituteStr[128];
					ptr = mir_strdup(dbv.pszVal);
					DBFreeVariant(&dbv);
					for(i=0;ptr[i];i++) {
						if(ptr[i]!='%') continue;
						if(!_strnicmp(ptr+i,"%time%",6))
							GetTimeFormatA(LOCALE_USER_DEFAULT,TIME_NOSECONDS,NULL,NULL,substituteStr,sizeof(substituteStr));
						else if(!_strnicmp(ptr+i,"%date%",6))
							GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,NULL,NULL,substituteStr,sizeof(substituteStr));
						else continue;
						if(strlen(substituteStr)>6) ptr=(char*)mir_realloc(ptr,strlen(ptr)+1+strlen(substituteStr)-6);
						MoveMemory(ptr+i+strlen(substituteStr),ptr+i+6,strlen(ptr)-i-5);
						CopyMemory(ptr+i,substituteStr,strlen(substituteStr));
					}
				}
			}
		}
		statusMsg = ptr;
		break;
	default:
		// Should not reach here
		break;
	}
	proto->iface.m_iStatus = status;
	if (presenceType) {
		if (statusMsg)
			JabberSend(proto, "<presence type='%s'><status>%s</status></presence>", presenceType, statusMsg);
		else
			JabberSend(proto, "<presence type='%s'></presence>", presenceType);
	} else {
		if (statusMsg)
			JabberSend(proto, "<presence><show>%s</show><status>%s</status></presence>", showBody, statusMsg);
		else
			JabberSend(proto, "<presence><show>%s</show></presence>", showBody);
	}
	if (ptr) {
		mir_free(ptr);
	}
	LeaveCriticalSection(&proto->modeMsgMutex);
}