コード例 #1
1
ファイル: logviewer.c プロジェクト: Loremipsum1988/brickd
static void format_timestamp(uint64_t seconds, int microseconds, char *buffer, int length,
                             char *date_separator, char *date_time_separator, char *time_separator) {
	ULONGLONG timestamp = 0;
	ULONGLONG offset_to_1970 = 116444736000000000;
	SYSTEMTIME st;
	FILETIME ft, ft_local;

	timestamp = Int32x32To64(seconds, 10000000) + offset_to_1970;
	ft.dwHighDateTime = (DWORD)((timestamp >> 32) & 0xFFFFFFFF);
	ft.dwLowDateTime = (DWORD)(timestamp & 0xFFFFFFFF);

	FileTimeToLocalFileTime(&ft, &ft_local);
	FileTimeToSystemTime(&ft_local, &st);

	if (microseconds < 0) {
		_snprintf(buffer, length, "%d%s%02d%s%02d%s%02d%s%02d%s%02d",
		          st.wYear, date_separator, st.wMonth, date_separator, st.wDay, date_time_separator,
		          st.wHour, time_separator, st.wMinute, time_separator, st.wSecond);
	} else {
		_snprintf(buffer, length, "%d%s%02d%s%02d%s%02d%s%02d%s%02d.%06d",
		          st.wYear, date_separator, st.wMonth, date_separator, st.wDay, date_time_separator,
		          st.wHour, time_separator, st.wMinute, time_separator, st.wSecond, microseconds);
	}
}
コード例 #2
0
ファイル: mstime.cpp プロジェクト: juhuaguai/duilib
CMSTime::CMSTime(const FILETIME& fileTime, int nDST)
{
	// first convert file time (UTC time) to local time
	FILETIME localTime;
	if (!FileTimeToLocalFileTime(&fileTime, &localTime))
	{
		m_time = 0;
		//AtlThrow(E_INVALIDARG);
		return;
	}

	// then convert that time to system time
	SYSTEMTIME sysTime;
	if (!FileTimeToSystemTime(&localTime, &sysTime))
	{
		m_time = 0;
		//AtlThrow(E_INVALIDARG);		
		return;
	}

	// then convert the system time to a time_t (C-runtime local time)
	CMSTime timeT(sysTime, nDST);
	*this = timeT;
}
コード例 #3
0
ファイル: set_dump.cpp プロジェクト: bagdxk/openafs
void Filesets_Dump_OnInitDialog (HWND hDlg, LPSET_DUMP_PARAMS psdp)
{
   TCHAR szServer[ cchNAME ];
   TCHAR szAggregate[ cchNAME ];
   TCHAR szFileset[ cchNAME ];
   psdp->lpi->GetServerName (szServer);
   psdp->lpi->GetAggregateName (szAggregate);
   psdp->lpi->GetFilesetName (szFileset);

   TCHAR szText[ cchRESOURCE ];
   GetDlgItemText (hDlg, IDC_DUMP_FULL, szText, cchRESOURCE);

   LPTSTR pszText = FormatString (szText, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
   SetDlgItemText (hDlg, IDC_DUMP_FULL, pszText);
   FreeString (pszText);

   pszText = FormatString (IDS_SET_DUMP_NAME, TEXT("%s"), szFileset);
   SetDlgItemText (hDlg, IDC_DUMP_FILENAME, pszText);
   FreeString (pszText);

   // Get the local system time
   SYSTEMTIME st;
   GetSystemTime (&st);
   FILETIME ft;
   SystemTimeToFileTime (&st, &ft);
   FILETIME lft;
   FileTimeToLocalFileTime (&ft, &lft);
   FileTimeToSystemTime (&lft, &st);

   DA_SetDate (GetDlgItem (hDlg, IDC_DUMP_DATE), &st);
   TI_SetTime (GetDlgItem (hDlg, IDC_DUMP_TIME), &st);

   CheckDlgButton (hDlg, IDC_DUMP_FULL, TRUE);
   Filesets_Dump_OnSelect (hDlg);
   Filesets_Dump_EnableOK (hDlg);
}
コード例 #4
0
ファイル: Pmix.cpp プロジェクト: CyberShadow/FAR
void ConvertDate(const FILETIME& ft,wchar_t *DateText,wchar_t *TimeText)
{
	if (ft.dwHighDateTime==0 && ft.dwLowDateTime==0)
	{
		if (DateText!=NULL)
			*DateText=0;

		if (TimeText!=NULL)
			*TimeText=0;

		return;
	}

	SYSTEMTIME st;
	FILETIME ct;
	FileTimeToLocalFileTime(&ft,&ct);
	FileTimeToSystemTime(&ct,&st);

	if (TimeText!=NULL)
		GetTimeFormat(LOCALE_USER_DEFAULT, 0, &st, 0, TimeText, MAX_DATETIME);

	if (DateText!=NULL)
		GetDateFormat(LOCALE_USER_DEFAULT, 0, &st, 0, DateText, MAX_DATETIME);
}
コード例 #5
0
ファイル: StreamVideoSource.cpp プロジェクト: anyboo/SPlayer
BOOL CStreamVideoSource::GetRawImage(BYTE **pRawData, FILETIME *timestamp, DWORD *bEOF )
{

	// Lock the image here and don't unlock until we get the frame back
	EnterCriticalSection(&m_csBufLock);
	*bEOF = FALSE;

	if( m_bGotVideoFrame )
	{
		// Get the next frame
		*pRawData = m_pAlignedImg;

		// Need Time stamp
		GetSystemTimeAsFileTime(timestamp);
		FileTimeToLocalFileTime(timestamp, timestamp);

		m_bGotVideoFrame = FALSE;
		return TRUE;
	}
	else
	{
		// Nothing.. unlock
		LeaveCriticalSection(&m_csBufLock);

		// Check for process exit
		if( WAIT_OBJECT_0 == WaitForSingleObject( m_piStreamer.hProcess, 0 ) )
		{
			// Child process has disappeared (exited)
			*bEOF = TRUE;

			m_bRun = FALSE;
			CleanupChild();
		}
		return FALSE;
	}
}
コード例 #6
0
ファイル: POSIXEMU.C プロジェクト: lleoha/WinFellow
int posixemu_stat(const char *name, struct stat *statbuf)
{
	char buf[1024];
	DWORD attr;
	FILETIME ft, lft;

	fname_atow(name,buf,sizeof buf);

	if ((attr = getattr(buf,&ft,(size_t*)&statbuf->st_size)) == (DWORD)~0)
	{
		lasterror = GetLastError();
		return -1;
	}
	else
	{
        statbuf->st_mode = (attr & FILE_ATTRIBUTE_READONLY) ? FILEFLAG_READ: FILEFLAG_READ | FILEFLAG_WRITE;
		if (attr & FILE_ATTRIBUTE_ARCHIVE) statbuf->st_mode |= FILEFLAG_ARCHIVE;
		if (attr & FILE_ATTRIBUTE_DIRECTORY) statbuf->st_mode |= FILEFLAG_DIR;
		FileTimeToLocalFileTime(&ft,&lft);
		statbuf->st_mtime = (*(__int64 *)&lft-((__int64)(369*365+89)*(__int64)(24*60*60)*(__int64)10000000))/(__int64)10000000;
	}

	return 0;
}
コード例 #7
0
ファイル: hal.c プロジェクト: callcc/tekui
static TINT
hal_getsysdate(struct THALBase *hal, TDATE *datep, TINT *dsbiasp)
{
	union { LARGE_INTEGER li; FILETIME ft; } utime;
	union { LARGE_INTEGER li; FILETIME ft; } ltime;
	TUINT64 syst;
	TINT dsbias;

	GetSystemTimeAsFileTime(&utime.ft);
	syst = utime.li.QuadPart / 10; /* to microseconds since 1.1.1601 */

	FileTimeToLocalFileTime(&utime.ft, &ltime.ft);
	dsbias = (TINT) ((utime.li.QuadPart - ltime.li.QuadPart) / 10000000);

	if (dsbiasp)
		*dsbiasp = dsbias;
	else
		syst -= (TINT64) dsbias * 1000000;

	if (datep)
		datep->tdt_Int64 = syst;

	return 0;
}
コード例 #8
0
ファイル: minizip.c プロジェクト: BackupTheBerlios/kicad-svn
uLong filetime(
	const char *filename,	/* name of file to get info on */
	tm_zip *tmzip,			/* return value: access, modific. and creation times */
	uLong *dt)				/* dostime */
/*****************************/
#ifdef WIN32
{
  int ret = 0;
  {
	  FILETIME ftLocal;
	  HANDLE hFind;
	  WIN32_FIND_DATA  ff32;

	  hFind = FindFirstFile(filename,&ff32);
	  if (hFind != INVALID_HANDLE_VALUE)
	  {
		FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal);
		FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0);
		FindClose(hFind);
		ret = 1;
	  }
  }
  return ret;
}
コード例 #9
0
ファイル: OS_NS_time.cpp プロジェクト: 08keelr/TrinityCore
ACE_BEGIN_VERSIONED_NAMESPACE_DECL

# if defined (ACE_HAS_WINCE)
ACE_TCHAR *
ACE_OS::ctime_r (const time_t *clock, ACE_TCHAR *buf, int buflen)
{
  // buflen must be at least 26 wchar_t long.
  if (buflen < 26)              // Again, 26 is a magic number.
    {
      errno = ERANGE;
      return 0;
    }
  // This is really stupid, converting FILETIME to timeval back and
  // forth.  It assumes FILETIME and DWORDLONG are the same structure
  // internally.
  ULARGE_INTEGER _100ns;
  _100ns.QuadPart = (DWORDLONG) *clock * 10000 * 1000
                     + ACE_Time_Value::FILETIME_to_timval_skew;
  FILETIME file_time;
  file_time.dwLowDateTime = _100ns.LowPart;
  file_time.dwHighDateTime = _100ns.HighPart;

  FILETIME localtime;
  SYSTEMTIME systime;
  FileTimeToLocalFileTime (&file_time, &localtime);
  FileTimeToSystemTime (&localtime, &systime);
  ACE_OS::sprintf (buf, ACE_OS_CTIME_R_FMTSTR,
                   ACE_OS_day_of_week_name[systime.wDayOfWeek],
                   ACE_OS_month_name[systime.wMonth - 1],
                   systime.wDay,
                   systime.wHour,
                   systime.wMinute,
                   systime.wSecond,
                   systime.wYear);
  return buf;
}
コード例 #10
0
void CFileEncryptDlg::OnDropFiles(HDROP hDropInfo)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	int DropCount = DragQueryFile(hDropInfo, -1, NULL, 0);
	CString FileInfo;
	TCHAR *pName;
	WIN32_FIND_DATA FindFileData;
	SYSTEMTIME mysystime;
	FILETIME loctime;
	if (DropCount <= 1)
	{
		HANDLE hFile;
		int NameSize = DragQueryFile(hDropInfo, 0, NULL, 0);
		pName = new TCHAR[NameSize + 1];
		DragQueryFile(hDropInfo, 0, pName, NameSize+1);
		hFile = FindFirstFile(pName, &FindFileData);
		FindClose(hFile);
		if (hFile == INVALID_HANDLE_VALUE)
		{
			FileInfo = _T("是不是把硬盘\\U盘\\CD驱动器拖拽进来啦,这样是不行滴!");
			SetButtonFalse();
		}		
		else if ((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0x10)
		{
			FileInfo = _T("不能对文件夹进行操作!");
			SetButtonFalse();
		}
		else if (FindFileData.nFileSizeLow == 0 && FindFileData.nFileSizeHigh == 0)
		{
			FileInfo = _T("文件大小为0字节,无需操作!");
			SetButtonFalse();
		}
		else
		{
			// 文件名称
			str_FileName = pName;
			FileInfo += str_FileName;
			FileInfo += _T("\r\n");
			CString str_data;
			// 文件大小
			// llFileSize = (FindFileData.nFileSizeHigh << 32) + FindFileData.nFileSizeLow; // 行为未定义,但是运行正常,会首先转换为LONGLONG,然后左移
			llFileSize = FindFileData.nFileSizeHigh;
			llFileSize <<= 32;
			llFileSize += FindFileData.nFileSizeLow;
			str_data.Format(_T("文件大小:%I64d字节\r\n"), llFileSize);
			FileInfo += str_data;
			// 文件创建时间
			// 转化为本地时间,否则会有8小时误差
			FileTimeToLocalFileTime(&FindFileData.ftLastWriteTime, &loctime);
			FileTimeToSystemTime(&loctime, &mysystime);
			str_data.Format(_T("最后修改时间:%d年%d月%d日 %d:%02d:%02d"), mysystime.wYear, mysystime.wMonth, 
				mysystime.wDay, mysystime.wHour, mysystime.wMinute, mysystime.wSecond);
			FileInfo += str_data;
			GetDlgItem(IDC_ENCRYPT)->EnableWindow(TRUE);
			GetDlgItem(IDC_DECRYPT)->EnableWindow(TRUE);
		}
 		delete[] pName;
		pName = NULL;
		DragFinish(hDropInfo);
	}
	else
	{
		FileInfo = _T("本程序只支持单个文件拖拽加密!");
	}	
	SetDlgItemText(IDC_FILE_INFORMATION, FileInfo);
	
	CDialogEx::OnDropFiles(hDropInfo);
}
コード例 #11
0
ファイル: propBasic.c プロジェクト: songbei6/WinObjEx64
/*
* propBasicQueryKey
*
* Purpose:
*
* Set information values for Key object type
*
* If ExtendedInfoAvailable is FALSE then it calls propSetDefaultInfo to set Basic page properties
*
*/
VOID propBasicQueryKey(
    _In_ PROP_OBJECT_INFO *Context,
    _In_ HWND hwndDlg,
    _In_ BOOL ExtendedInfoAvailable
)
{
    NTSTATUS    status;
    ULONG       bytesNeeded;
    HANDLE      hObject;
    TIME_FIELDS	SystemTime;
    WCHAR       szBuffer[MAX_PATH];

    KEY_FULL_INFORMATION  kfi;

    SetDlgItemText(hwndDlg, ID_KEYSUBKEYS, T_CannotQuery);
    SetDlgItemText(hwndDlg, ID_KEYVALUES, T_CannotQuery);
    SetDlgItemText(hwndDlg, ID_KEYLASTWRITE, T_CannotQuery);

    if (Context == NULL) {
        return;
    }

    //
    // Open Key object.
    //
    hObject = NULL;
    if (!propOpenCurrentObject(Context, &hObject, KEY_QUERY_VALUE)) {
        return;
    }

    RtlSecureZeroMemory(&kfi, sizeof(KEY_FULL_INFORMATION));
    status = NtQueryKey(hObject, KeyFullInformation, &kfi,
        sizeof(KEY_FULL_INFORMATION), &bytesNeeded);

    if (NT_SUCCESS(status)) {

        //Subkeys count
        RtlSecureZeroMemory(szBuffer, sizeof(szBuffer));
        ultostr(kfi.SubKeys, _strend(szBuffer));
        SetDlgItemText(hwndDlg, ID_KEYSUBKEYS, szBuffer);

        //Values count
        RtlSecureZeroMemory(szBuffer, sizeof(szBuffer));
        ultostr(kfi.Values, _strend(szBuffer));
        SetDlgItemText(hwndDlg, ID_KEYVALUES, szBuffer);

        //LastWrite time
        RtlSecureZeroMemory(&SystemTime, sizeof(SystemTime));
        FileTimeToLocalFileTime((PFILETIME)&kfi.LastWriteTime,
            (PFILETIME)&kfi.LastWriteTime);
        RtlTimeToTimeFields((PLARGE_INTEGER)&kfi.LastWriteTime,
            (PTIME_FIELDS)&SystemTime);

        //Month starts from 0 index
        if (SystemTime.Month - 1 < 0) SystemTime.Month = 1;
        if (SystemTime.Month > 12) SystemTime.Month = 12;

        RtlSecureZeroMemory(&szBuffer, sizeof(szBuffer));
        wsprintf(szBuffer, FORMATTED_TIME_DATE_VALUE,
            SystemTime.Hour,
            SystemTime.Minute,
            SystemTime.Second,
            SystemTime.Day,
            Months[SystemTime.Month - 1],
            SystemTime.Year);

        SetDlgItemText(hwndDlg, ID_KEYLASTWRITE, szBuffer);
    }

    //
    // Query object basic and type info if needed.
    //
    if (ExtendedInfoAvailable == FALSE) {
        propSetDefaultInfo(Context, hwndDlg, hObject);
    }
    NtClose(hObject);
}
コード例 #12
0
ファイル: propBasic.c プロジェクト: songbei6/WinObjEx64
/*
* propBasicQuerySymlink
*
* Purpose:
*
* Set information values for SymbolicLink object type
*
* If ExtendedInfoAvailable is FALSE then it calls propSetDefaultInfo to set Basic page properties
*
*/
VOID propBasicQuerySymlink(
    _In_ PROP_OBJECT_INFO *Context,
    _In_ HWND hwndDlg,
    _In_ BOOL ExtendedInfoAvailable
)
{
    NTSTATUS    status;
    ULONG       bytesNeeded;
    HANDLE      hObject;
    LPWSTR      lpLinkTarget;
    TIME_FIELDS	SystemTime;
    WCHAR       szBuffer[MAX_PATH];

    OBJECT_BASIC_INFORMATION obi;

    SetDlgItemText(hwndDlg, ID_OBJECT_SYMLINK_TARGET, T_CannotQuery);
    SetDlgItemText(hwndDlg, ID_OBJECT_SYMLINK_CREATION, T_CannotQuery);

    if (Context == NULL) {
        return;
    }

    //
    // Open SymbolicLink object.
    //
    hObject = NULL;
    if (!propOpenCurrentObject(Context, &hObject, SYMBOLIC_LINK_QUERY)) {
        return;
    }

    //
    // Copy link target from main object list for performance reasons.
    // So we don't need to query same data again.
    //
    lpLinkTarget = Context->lpDescription;
    if (lpLinkTarget) {
        SetDlgItemText(hwndDlg, ID_OBJECT_SYMLINK_TARGET, lpLinkTarget);
    }

    //Query Link Creation Time
    RtlSecureZeroMemory(&obi, sizeof(OBJECT_BASIC_INFORMATION));

    status = NtQueryObject(hObject, ObjectBasicInformation, &obi,
        sizeof(OBJECT_BASIC_INFORMATION), &bytesNeeded);

    if (NT_SUCCESS(status)) {
        FileTimeToLocalFileTime((PFILETIME)&obi.CreationTime, (PFILETIME)&obi.CreationTime);
        RtlSecureZeroMemory(&SystemTime, sizeof(SystemTime));
        RtlTimeToTimeFields((PLARGE_INTEGER)&obi.CreationTime, (PTIME_FIELDS)&SystemTime);

        //Month starts from 0 index
        if (SystemTime.Month - 1 < 0) SystemTime.Month = 1;
        if (SystemTime.Month > 12) SystemTime.Month = 12;

        RtlSecureZeroMemory(&szBuffer, sizeof(szBuffer));
        wsprintf(szBuffer, FORMATTED_TIME_DATE_VALUE,
            SystemTime.Hour,
            SystemTime.Minute,
            SystemTime.Second,
            SystemTime.Day,
            Months[SystemTime.Month - 1],
            SystemTime.Year);

        SetDlgItemText(hwndDlg, ID_OBJECT_SYMLINK_CREATION, szBuffer);
    }

    //
    // Query object basic and type info if needed.
    //
    if (ExtendedInfoAvailable == FALSE) {
        propSetDefaultInfo(Context, hwndDlg, hObject);
    }
    NtClose(hObject);
}
コード例 #13
0
ファイル: Files.c プロジェクト: garfieldchien/omnia-projetcs
//----------------------------------------------------------------
void CheckRecursivFilesFromSizeAndEM(DWORD iitem, char *remote_name, long long int size, char *MD5, char *SHA256, BOOL recursif, char*source)
{
  #ifdef DEBUG_MODE_FILES
  AddMsg(h_main,"DEBUG","files:CheckRecursivFilesFromSizeAndEM START",remote_name);
  #endif
  WIN32_FIND_DATA data;
  char tmp_path[LINE_SIZE]="", tmp_remote_name[LINE_SIZE]="", date[MAX_PATH]="\0\0\0";

  //search
  BOOL exist;
  HANDLE hfile, hfind;
  LARGE_INTEGER filesize;
  char s_sha[SHA256_SIZE]="",s_md5[MAX_PATH];
  FILETIME LocalFileTime;
  SYSTEMTIME SysTimeModification;

  snprintf(tmp_path,LINE_SIZE,"%s\\*.*",remote_name);
  hfind = FindFirstFile(tmp_path, &data);
  if (hfind != INVALID_HANDLE_VALUE && scan_start)
  {
    do
    {
      if (data.cFileName[0] == '.' && (data.cFileName[1] == 0 || (data.cFileName[2] == 0 && data.cFileName[1] == '.')))continue;

      #ifdef DEBUG_MODE_FILES
      AddMsg(h_main,(char*)"DEBUG S(CheckRecursivFilesFromSizeAndEM)",remote_name,(char*)data.cFileName);
      #endif

      if ((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && recursif)
      {
        snprintf(tmp_remote_name,LINE_SIZE,"%s\\%s",remote_name,data.cFileName);

        #ifdef DEBUG_MODE_FILES
        AddMsg(h_main,(char*)"DEBUG D(CheckRecursivFilesFromSizeAndEM)",tmp_remote_name,(char*)"");
        #endif

        CheckRecursivFilesFromSizeAndEM(iitem, tmp_remote_name, size, MD5, SHA256, recursif, source);
        continue;
      }

      exist = FALSE;
      filesize.HighPart = data.nFileSizeHigh;
      filesize.LowPart  = data.nFileSizeLow;

      if (filesize.QuadPart == size || size == -1)
      {
        snprintf(tmp_remote_name,LINE_SIZE,"%s\\%s",remote_name,data.cFileName);

        s_md5[0] = 0;
        s_sha[0] = 0;

        if (MD5[0] != 0 || SHA256[0] != 0 || (SHA256[0] == 0 && MD5[0] == 0))
        {
          //make MD5 and SHA256 hashes
          //MD5
          hfile = CreateFile(tmp_remote_name,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,0);
          if (hfile != INVALID_HANDLE_VALUE)
          {
            FileToMd5(hfile, s_md5);
            CloseHandle(hfile);

            //SHA256
            hfile = CreateFile(tmp_remote_name,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,0);
            if (hfile != INVALID_HANDLE_VALUE)
            {
              FileToSHA256(hfile, s_sha);
              CloseHandle(hfile);
            }
          }

          if (MD5[0] == 0 && SHA256[0] == 0)exist = TRUE;
          else
          {
            if(MD5[0] != 0 && compare_nocas(MD5,s_md5))exist = TRUE;
            else if(SHA256[0] != 0 && compare_nocas(SHA256,s_sha))exist = TRUE;
          }

          if (exist && (filesize.QuadPart!=0 || (data.ftLastWriteTime.dwHighDateTime != 0 && data.ftLastWriteTime.dwLowDateTime != 0)))
          {
            date[0] = 0;
            FileTimeToLocalFileTime(&(data.ftLastWriteTime), &LocalFileTime);
            FileTimeToSystemTime(&LocalFileTime, &SysTimeModification);
            snprintf(date,MAX_PATH,"[Last_modification:%02d/%02d/%02d-%02d:%02d:%02d,Size:%lo]"
                         ,SysTimeModification.wYear,SysTimeModification.wMonth,SysTimeModification.wDay
                         ,SysTimeModification.wHour,SysTimeModification.wMinute,SysTimeModification.wSecond,filesize.QuadPart);

            if (s_sha[0] != 0)
            {
              snprintf(tmp_remote_name,LINE_SIZE,"%s %s;MD5;%s;%s;%s",tmp_remote_name,date,s_md5[0]==0?"":s_md5,SHA1_enable?"SHA1":"SHA256",s_sha[0]==0?"":s_sha);
            }else if (s_md5[0] != 0)
            {
              snprintf(tmp_remote_name,LINE_SIZE,"%s %s;MD5;%s;;",tmp_remote_name,date,s_md5);
            }else snprintf(tmp_remote_name,LINE_SIZE,"%s %s;;;;",tmp_remote_name,date);

            AddMsg(h_main,(char*)"FOUND (File2)",tmp_remote_name,(char*)"");
            AddLSTVUpdateItem(tmp_remote_name, COL_FILES, iitem);
          }
        }
      }
    }while(FindNextFile(hfind, &data) != 0 && scan_start);
    FindClose(hfind);
  }
  #ifdef DEBUG_MODE_FILES
  AddMsg(h_main,"DEBUG","files:CheckRecursivFilesFromSizeAndEM END",remote_name);
  #endif
}
コード例 #14
0
ファイル: wce_stat.c プロジェクト: RangelReale/sandbox
/*******************************************************************************
* wceex_stat - Get file attributes for file and store them in buffer.
*
* Description:
*
*   File times on Windows CE: Windows CE object store keeps track of only
*   one time, the time the file was last written to.
*
* Return value:
*
*   Upon successful completion, 0 shall be returned.
*   Otherwise, -1 shall be returned and errno set to indicate the error.
*
*   XXX - mloskot - errno is not yet implemented
*
* Reference:
*   IEEE Std 1003.1, 2004 Edition
*
*******************************************************************************/
int wceex_stat(const char* filename, struct stat *buffer)
{
    HANDLE findhandle;
    WIN32_FIND_DATA findbuf;
    wchar_t pathWCE[MAX_PATH];

    //Don't allow wildcards to be interpreted by system
    if(strpbrk(filename, "?*"))
        //if(wcspbrk(path, L"?*"))
    {
        //errno = ENOENT;
        return(-1);
    }

    //search file/dir
    mbstowcs(pathWCE, filename, strlen(filename) + 1);
    findhandle = FindFirstFile(pathWCE, &findbuf);
    if(findhandle == INVALID_HANDLE_VALUE)
    {
        //is root
        if(_stricmp(filename, ".\\")==0)
        {
            findbuf.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;

            //dummy values
            findbuf.nFileSizeHigh = 0;
            findbuf.nFileSizeLow = 0;
            findbuf.cFileName[0] = '\0';

            buffer->st_mtime = wceex_local_to_time_r(1980 - TM_YEAR_BASE, 0, 1, 0, 0, 0);
            buffer->st_atime = buffer->st_mtime;
            buffer->st_ctime = buffer->st_mtime;
        }

        //treat as an error
        else
        {
            //errno = ENOENT;
            return(-1);
        }
    }
    else
    {
        /* File is found*/

        SYSTEMTIME SystemTime;
        FILETIME LocalFTime;

        //Time of last modification
        if(!FileTimeToLocalFileTime( &findbuf.ftLastWriteTime, &LocalFTime) ||
            !FileTimeToSystemTime(&LocalFTime, &SystemTime))
        {
            //errno = ::GetLastError();
            FindClose( findhandle );
            return( -1 );
        }

        buffer->st_mtime = wceex_local_to_time(&SystemTime);

        //Time od last access of file
        if(findbuf.ftLastAccessTime.dwLowDateTime || findbuf.ftLastAccessTime.dwHighDateTime)
        {
            if(!FileTimeToLocalFileTime(&findbuf.ftLastAccessTime, &LocalFTime) ||
                !FileTimeToSystemTime(&LocalFTime, &SystemTime))
            {
                //errno = ::GetLastError();
                FindClose( findhandle );
                return( -1 );
            }
            buffer->st_atime = wceex_local_to_time(&SystemTime);
        }
        else
        {
            buffer->st_atime = buffer->st_mtime;
        }


        //Time of creation of file
        if(findbuf.ftCreationTime.dwLowDateTime || findbuf.ftCreationTime.dwHighDateTime)
        {
            if(!FileTimeToLocalFileTime(&findbuf.ftCreationTime, &LocalFTime) ||
                !FileTimeToSystemTime(&LocalFTime, &SystemTime))
            {
                //errno = ::GetLastError();
                FindClose( findhandle );
                return( -1 );
            }
            buffer->st_ctime = wceex_local_to_time(&SystemTime);
        }
        else
        {
            buffer->st_ctime = buffer->st_mtime;
        }

        //close handle
        FindClose(findhandle);
    }

    //file mode
    buffer->st_mode = __wceex_get_file_mode(filename, findbuf.dwFileAttributes);

    //file size
    buffer->st_size = findbuf.nFileSizeLow;

    //drive letter 0
    buffer->st_rdev = buffer->st_dev = 0;

    //set the common fields
    buffer->st_gid = 0;
    buffer->st_ino = 0;
    buffer->st_uid = 0;

    //1 dla nlink
    buffer->st_nlink = 1;


    return 0;
}
コード例 #15
0
ファイル: s_direct.cpp プロジェクト: AaronDP/efte_adbshell
int FileFind::FindNext(FileInfo **fi) {
#if defined(USE_DIRENT)
    struct dirent *dent;
    char fullpath[MAXPATH];
    char *name;

    *fi = 0;
again:
    if ((dent = readdir(dir)) == NULL)
        return -1;
    name = dent->d_name;

    if (name[0] == '.')
        if (!(Flags & ffHIDDEN))
            goto again;

    if (Pattern && fnmatch(Pattern, dent->d_name, 0) != 0)
        goto again;

    if (Flags & ffFULLPATH) {
        JoinDirFile(fullpath, Directory, dent->d_name);
        name = fullpath;
    }

    if (Flags & ffFAST) {
        *fi = new FileInfo(name, fiUNKNOWN, 0, 0);
    } else {
        struct stat st = { 0 };
        char linktarget[MAXPATH] = "";

        if (!(Flags & ffFULLPATH)) // need it now
            JoinDirFile(fullpath, Directory, dent->d_name);

#if defined(UNIX)
        if (readlink(fullpath, linktarget, sizeof(linktarget)) == -1)
            strcpy(linktarget, "");
#endif

        if (Flags & ffLINK) {
            // if we are handling location of symbolic links, lstat cannot be used
            // instead use normal stat
            if (stat(fullpath, &st) != 0)
                // possibly a broken link, let's try to get
                // the correct mtime for it at least
#if defined(UNIX) // must use lstat if available
                lstat(fullpath, &st)
#endif
                    ;
        } else {
            if (
#if defined(UNIX) // must use lstat if available
                lstat
#else
                stat
#endif
                (fullpath, &st) != 0 && 0)
                goto again;
        }

        if (!(Flags & ffDIRECTORY) && S_ISDIR(st.st_mode))
            goto again;

        *fi = new FileInfo(name,
                           S_ISDIR(st.st_mode) ? fiDIRECTORY : fiFILE,
                           st.st_size,
                           st.st_mtime,
                           strlen(linktarget) > 0 ? linktarget : 0
                          );
    }
    //printf("ok\n");
    return 0;
#elif defined(OS2) && !defined(USE_DIRENT)
    ULONG count = 1;
    FILEFINDBUF3 find; // need to improve to fetch multiple entries at once
    char fullpath[MAXPATH];
    char *name;
    struct tm t;
    int rc;

    if ((rc = DosFindNext(dir,
                          &find, sizeof(find),
                          &count)) != 0) {
        //fprintf(stderr, "%d\n\n", rc);
        return -1;
    }
    if (count != 1)
        return -1;
    name = find.achName;
    if (Flags & ffFULLPATH) {
        JoinDirFile(fullpath, Directory, name);
        name = fullpath;
    }
    memset((void *)&t, 0, sizeof(t));
    t.tm_year = find.fdateLastWrite.year + 80;
    t.tm_mon = find.fdateLastWrite.month - 1;
    t.tm_mday = find.fdateLastWrite.day;
    t.tm_hour = find.ftimeLastWrite.hours;
    t.tm_min = find.ftimeLastWrite.minutes;
    t.tm_sec = find.ftimeLastWrite.twosecs * 2; // ugh!
    t.tm_isdst = -1;
    *fi = new FileInfo(name,
                       (find.attrFile & FILE_DIRECTORY) ? fiDIRECTORY : fiFILE,
                       find.cbFile,
                       mktime(&t));

    return 0;
#elif defined(NT) && !defined(USE_DIRENT)
#if defined(USE_VCFIND)
    _finddata_t find;
    char fullpath[MAXPATH];
    char *name;
    struct tm t;
    int rc;

    if ((rc = _findnext(dir,
                        &find)) != 0) {
        // fprintf(stderr, "%d\n\n", rc);
        return -1;
    }

    name = find.name;
    if (Flags & ffFULLPATH) {
        JoinDirFile(fullpath, Directory, name);
        name = fullpath;
    }

    *fi = new FileInfo(name,
                       (find.attrib & _A_SUBDIR) ? fiDIRECTORY : fiFILE,
                       find.size,
                       find.time_create);
    return 0;
#else
    WIN32_FIND_DATA find;
    char fullpath[MAXPATH];
    char *name;
    struct tm t;
    SYSTEMTIME st;
    FILETIME localft;                   // needed for time conversion
    int rc;

    if ((rc = FindNextFile((HANDLE)dir,
                           &find)) != TRUE) {
        //fprintf(stderr, "%d\n\n", rc);
        return -1;
    }

    name = find.cFileName;
    if (Flags & ffFULLPATH) {
        JoinDirFile(fullpath, Directory, name);
        name = fullpath;
    }

    /*
    * since filetime is in UTC format we need to convert it first to
    * localtime and when we have "correct" time we can use it.
    */

    FileTimeToLocalFileTime(&find.ftLastWriteTime, &localft);
    FileTimeToSystemTime(&localft, &st);

    t.tm_year = st.wYear - 1900;
    t.tm_mon = st.wMonth - 1;           // in system time january is 1...
    t.tm_mday = st.wDay;
    t.tm_hour = st.wHour;
    t.tm_min = st.wMinute;
    t.tm_sec = st.wSecond;
    t.tm_isdst = -1;

    *fi = new FileInfo(name,
                       (find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? fiDIRECTORY : fiFILE,
                       find.nFileSizeLow,
                       mktime(&t));
    return 0;
#endif
    //    put code here
#endif
}
コード例 #16
0
HRESULT FindAttributesOrClasses(IDirectorySearch *pSchemaNC, //IDirectorySearch pointer to schema naming context.
		 LPOLESTR szFilter, //Filter for finding specific attributes.
                            //NULL returns all attributeSchema objects.
         LPOLESTR *pszPropertiesToReturn, //Properties to return for attributeSchema objects found
					                    //NULL returns all set properties unless bIsVerbose is FALSE.
		 BOOL bIsAttributeQuery, //TRUE queries for attributes;FALSE for classes
		 BOOL bIsVerbose //TRUE means all properties for the found objects are displayed.
		                 //FALSE means only the ldapDisplayName with cn in parentheses:
						 //example: l (Locality-Name)
							)
{
	if (!pSchemaNC)
		return E_POINTER;
    //Create search filter
	int allocFilter = MAX_PATH*2;
	LPOLESTR pszSearchFilter = new OLECHAR[allocFilter];
	
    if ( !pszSearchFilter )
    {
        delete [] pszSearchFilter;
        return E_OUTOFMEMORY;
    }
        
	LPOLESTR szCategory = NULL;
	if (bIsAttributeQuery)
		szCategory = L"attributeSchema";
	else
		szCategory = L"classSchema";


	wcscpy_s(pszSearchFilter, allocFilter, L"(&(objectCategory=attributeSchema)%s)");
	BOOL bBufferOK=false;
	// Check for buffer overrun...
	if (szFilter)
	{
		if ( IS_BUFFER_ENOUGH(allocFilter,pszSearchFilter, szCategory) > 0 )
		{
	       swprintf_s(pszSearchFilter, allocFilter, L"(&(objectCategory=%s)%s)",szCategory,szFilter);
		   bBufferOK=true;
		}
	}
	else
	{
		if ( IS_BUFFER_ENOUGH(allocFilter,pszSearchFilter, szCategory) > 0 )
		{
 	       swprintf_s(pszSearchFilter, allocFilter,L"(objectCategory=%s)",szCategory);
		   bBufferOK=true;
		}
	}

	
	if( !bBufferOK)
	{
            delete [] pszSearchFilter;
			wprintf(L"Filter is too large - aborting");
			return E_FAIL;
	}

    //Attributes are one-level deep in the Schema container so only need to search one level.
	ADS_SEARCHPREF_INFO SearchPrefs;
	SearchPrefs.dwSearchPref = ADS_SEARCHPREF_SEARCH_SCOPE;
	SearchPrefs.vValue.dwType = ADSTYPE_INTEGER;
	SearchPrefs.vValue.Integer = ADS_SCOPE_ONELEVEL;
    DWORD dwNumPrefs = 1;

	// COL for iterations
	LPOLESTR pszColumn = NULL;    
	ADS_SEARCH_COLUMN col;
    HRESULT hr;
    
    // Interface Pointers
    IADs    *pObj = NULL;
    IADs	* pIADs = NULL;

    // Handle used for searching
    ADS_SEARCH_HANDLE hSearch = NULL;
	
	// Set the search preference
    hr = pSchemaNC->SetSearchPreference( &SearchPrefs, dwNumPrefs);
    if (FAILED(hr))
        return hr;

	LPOLESTR pszBool = NULL;
	DWORD dwBool;
	PSID pObjectSID = NULL;
	LPOLESTR szSID = NULL;
	LPGUID pObjectGUID = NULL;
	FILETIME filetime;
	SYSTEMTIME systemtime;
	DATE date;
	VARIANT varDate;
	LARGE_INTEGER liValue;
	LPOLESTR *pszPropertyList = NULL;
	LPOLESTR pszNonVerboseList[] = {L"lDAPDisplayName",L"cn"};

	LPOLESTR szCNValue = new OLECHAR[MAX_PATH];
	LPOLESTR szLDAPDispleyNameValue = new OLECHAR[MAX_PATH];
	LPOLESTR szDSGUID = new WCHAR [39];
	
	if ( !szCNValue || 	!szLDAPDispleyNameValue || !szDSGUID )
	{
        if ( szDSGUID )
            delete [] szDSGUID;
        if ( szCNValue )
            delete [] szCNValue;
        if ( szLDAPDispleyNameValue )
            delete [] szLDAPDispleyNameValue;
        if ( pszSearchFilter )
            delete [] pszSearchFilter;	
        return E_OUTOFMEMORY;
    }

	int iCount = 0;
	DWORD x = 0L;



	if (!bIsVerbose)
	{
		 //Return non-verbose list properties only
         hr = pSchemaNC->ExecuteSearch(pszSearchFilter,
		                          pszNonVerboseList,
								  sizeof(pszNonVerboseList)/sizeof(LPOLESTR),
								  &hSearch
								  );
	}
	else
	{
		if (!pszPropertiesToReturn)
		{
			//Return all properties.
			hr = pSchemaNC->ExecuteSearch(pszSearchFilter,
		                          NULL,
								  0L,
								  &hSearch
								  );
		}
		else
		{
			//specified subset.
		    pszPropertyList = pszPropertiesToReturn;
		   //Return specified properties
		   hr = pSchemaNC->ExecuteSearch(pszSearchFilter,
		                          pszPropertyList,
								  sizeof(pszPropertyList)/sizeof(LPOLESTR),
								  &hSearch
								  );
		}
	}
 	if ( SUCCEEDED(hr) )
	{    
    // Call IDirectorySearch::GetNextRow() to retrieve the next row 
    //of data
	  hr = pSchemaNC->GetFirstRow( hSearch);
	  if (SUCCEEDED(hr))
	  {
        while( hr != S_ADS_NOMORE_ROWS )
		{
			//Keep track of count.
			iCount++;
			if (bIsVerbose)
			  wprintf(L"----------------------------------\n");
            // loop through the array of passed column names,
            // print the data for each column

			while( pSchemaNC->GetNextColumnName( hSearch, &pszColumn ) != S_ADS_NOMORE_COLUMNS )
            {
                hr = pSchemaNC->GetColumn( hSearch, pszColumn, &col );
			    if ( SUCCEEDED(hr) )
			    {
		            // Print the data for the column and free the column
				  if(bIsVerbose)
				  {
			        // Get the data for this column
				    wprintf(L"%s\n",col.pszAttrName);
					switch (col.dwADsType)
					{
						case ADSTYPE_DN_STRING:
                          for (x = 0; x< col.dwNumValues; x++)
						  {
							  wprintf(L"  %s\r\n",col.pADsValues[x].DNString);
						  }
						  break;
						case ADSTYPE_CASE_EXACT_STRING:	    
						case ADSTYPE_CASE_IGNORE_STRING:	    
						case ADSTYPE_PRINTABLE_STRING:	    
						case ADSTYPE_NUMERIC_STRING:	        
						case ADSTYPE_TYPEDNAME:	            
						case ADSTYPE_FAXNUMBER:	            
						case ADSTYPE_PATH:	                
						case ADSTYPE_OBJECT_CLASS:
						  for (x = 0; x< col.dwNumValues; x++)
						  {
							  wprintf(L"  %s\r\n",col.pADsValues[x].CaseIgnoreString);
						  }
						  break;
						case ADSTYPE_BOOLEAN:
						  for (x = 0; x< col.dwNumValues; x++)
						  {
							  dwBool = col.pADsValues[x].Boolean;
							  pszBool = dwBool ? L"TRUE" : L"FALSE";
							  wprintf(L"  %s\r\n",pszBool);
						  }
						  break;
						case ADSTYPE_INTEGER:
					      for (x = 0; x< col.dwNumValues; x++)
						  {
							  wprintf(L"  %d\r\n",col.pADsValues[x].Integer);
						  }
						  break;
						case ADSTYPE_OCTET_STRING:
						    if ( _wcsicmp(col.pszAttrName,L"objectSID") == 0 )
							{
						      for (x = 0; x< col.dwNumValues; x++)
							  {
								  pObjectSID = (PSID)(col.pADsValues[x].OctetString.lpValue);
								  //Convert SID to string.
								  ConvertSidToStringSid(pObjectSID, &szSID);
								  wprintf(L"  %s\r\n",szSID);
								  LocalFree(szSID);
							  }
							}
						    else if ( (_wcsicmp(col.pszAttrName,L"objectGUID") == 0)
								|| (_wcsicmp(col.pszAttrName,L"schemaIDGUID") == 0) 
								|| (_wcsicmp(col.pszAttrName,L"attributeSecurityGUID") == 0) )
							{
						      for (x = 0; x< col.dwNumValues; x++)
							  {
								//Cast to LPGUID
								pObjectGUID = (LPGUID)(col.pADsValues[x].OctetString.lpValue);
								//Convert GUID to string.
								::StringFromGUID2(*pObjectGUID, szDSGUID, 39); 
								//Print the GUID
								wprintf(L"  %s\r\n",szDSGUID);
							  }
							}
						    else if ( _wcsicmp(col.pszAttrName,L"oMObjectClass") == 0 )
							{
							  //TODO: 
							  wprintf(L"  TODO:No conversion for this.");
							}
							else
							  wprintf(L"  Value of type Octet String. No Conversion.");
						    break;
						case ADSTYPE_UTC_TIME:
						  for (x = 0; x< col.dwNumValues; x++)
						  {
							systemtime = col.pADsValues[x].UTCTime;
							if (SystemTimeToVariantTime(&systemtime,
														&date) != 0) 
							{
								//Pack in variant.vt
								varDate.vt = VT_DATE;
								varDate.date = date;
								VariantChangeType(&varDate,&varDate,VARIANT_NOVALUEPROP,VT_BSTR);
							    wprintf(L"  %s\r\n",varDate.bstrVal);
								VariantClear(&varDate);
							}
							else
								wprintf(L"  Could not convert UTC-Time.\n");
						  }
						  break;
						case ADSTYPE_LARGE_INTEGER:
						  for (x = 0; x< col.dwNumValues; x++)
						  {
						    liValue = col.pADsValues[x].LargeInteger;
							filetime.dwLowDateTime = liValue.LowPart;
							filetime.dwHighDateTime = liValue.HighPart;
							if((filetime.dwHighDateTime==0) && (filetime.dwLowDateTime==0))
							{
								wprintf(L"  No value set.\n");
							}
							else
							{
								//Check for properties of type LargeInteger that represent time
								//if TRUE, then convert to variant time.
								if ((0==wcscmp(L"accountExpires", col.pszAttrName))|
									(0==wcscmp(L"badPasswordTime", col.pszAttrName))||
									(0==wcscmp(L"lastLogon", col.pszAttrName))||
									(0==wcscmp(L"lastLogoff", col.pszAttrName))||
									(0==wcscmp(L"lockoutTime", col.pszAttrName))||
									(0==wcscmp(L"pwdLastSet", col.pszAttrName))
								   )
								{
									//Handle special case for Never Expires where low part is -1
									if (filetime.dwLowDateTime==-1)
									{
										wprintf(L"  Never Expires.\n");
									}
									else
									{
										if (FileTimeToLocalFileTime(&filetime, &filetime) != 0) 
										{
											if (FileTimeToSystemTime(&filetime,
																 &systemtime) != 0)
											{
												if (SystemTimeToVariantTime(&systemtime,
																			&date) != 0) 
												{
													//Pack in variant.vt
													varDate.vt = VT_DATE;
													varDate.date = date;
													VariantChangeType(&varDate,&varDate,VARIANT_NOVALUEPROP,VT_BSTR);
													wprintf(L"  %s\r\n",varDate.bstrVal);
													VariantClear(&varDate);
												}
												else
												{
													wprintf(L"  FileTimeToVariantTime failed\n");
												}
											}
											else
											{
												wprintf(L"  FileTimeToSystemTime failed\n");
											}

										}
										else
										{
											wprintf(L"  FileTimeToLocalFileTime failed\n");
										}
									}
								}
								else
								{
									//Print the LargeInteger.
									wprintf(L"  high: %d low: %d\r\n",filetime.dwHighDateTime, filetime.dwLowDateTime);
								}
							}
						  }
						  break;
						case ADSTYPE_NT_SECURITY_DESCRIPTOR:
						  for (x = 0; x< col.dwNumValues; x++)
						  {
							  wprintf(L"  Security descriptor.\n");
						  }
						  break;
						default:
				          wprintf(L"Unknown type %d.\n",col.dwADsType);
					}
				  }
			      else
				  {
					//Verbose handles only the two single-valued attributes: cn and ldapdisplayname
					//so this is a special case.
					if (0==wcscmp(L"cn", pszColumn))
					{
					  wcscpy_s(szCNValue,MAX_PATH,col.pADsValues->CaseIgnoreString);
					}
					if (0==wcscmp(L"lDAPDisplayName", pszColumn))
					{
					  wcscpy_s(szLDAPDispleyNameValue,MAX_PATH,col.pADsValues->CaseIgnoreString);
					}
				  }
			      pSchemaNC->FreeColumn( &col );
			    }
				FreeADsMem( pszColumn );
            }
		   if (!bIsVerbose)
			   wprintf(L"%s (%s)\n",szLDAPDispleyNameValue,szCNValue);
 		   //Get the next row
		   hr = pSchemaNC->GetNextRow( hSearch);
		}

	  }
	  // Close the search handle to clean up
      pSchemaNC->CloseSearchHandle(hSearch);
	} 
	if (SUCCEEDED(hr) && 0==iCount)
		hr = S_FALSE;

    delete [] szDSGUID;
    delete [] szCNValue;
    delete [] szLDAPDispleyNameValue;
    delete [] pszSearchFilter;
        
    return hr;
}
コード例 #17
0
ファイル: datetime.cpp プロジェクト: alexlav/conemu
void ConvertDate(const FILETIME &ft,string &strDateText, string &strTimeText,int TimeLength,
                 int Brief,int TextMonth,int FullYear,int DynInit)
{
	static int WDateFormat;
	static wchar_t WDateSeparator,WTimeSeparator,WDecimalSeparator;
	static bool Init=false;
	static SYSTEMTIME lt;
	int DateFormat;
	wchar_t DateSeparator,TimeSeparator,DecimalSeparator;

	if (!Init)
	{
		WDateFormat=GetDateFormat();
		WDateSeparator=GetDateSeparator();
		WTimeSeparator=GetTimeSeparator();
		WDecimalSeparator=GetDecimalSeparator();
		GetLocalTime(&lt);
		Init=true;
	}

	DateFormat=DynInit?GetDateFormat():WDateFormat;
	DateSeparator=DynInit?GetDateSeparator():WDateSeparator;
	TimeSeparator=DynInit?GetTimeSeparator():WTimeSeparator;
	DecimalSeparator=DynInit?GetDecimalSeparator():WDecimalSeparator;
	int CurDateFormat=DateFormat;

	if (Brief && CurDateFormat==2)
		CurDateFormat=0;

	SYSTEMTIME st;
	FILETIME ct;

	if (!ft.dwHighDateTime)
	{
		strDateText.Clear();
		strTimeText.Clear();
		return;
	}

	FileTimeToLocalFileTime(&ft,&ct);
	FileTimeToSystemTime(&ct,&st);
	//if ( !strTimeText.IsEmpty() )
	{
		const wchar_t *Letter=L"";

		if (TimeLength==6)
		{
			Letter=(st.wHour<12) ? L"a":L"p";

			if (st.wHour>12)
				st.wHour-=12;

			if (!st.wHour)
				st.wHour=12;
		}

		if (TimeLength<7)
			strTimeText.Format(L"%02d%c%02d%s",st.wHour,TimeSeparator,st.wMinute,Letter);
		else
		{
			string strFullTime;
			strFullTime.Format(L"%02d%c%02d%c%02d%c%03d",st.wHour,TimeSeparator,
			                   st.wMinute,TimeSeparator,st.wSecond,DecimalSeparator,st.wMilliseconds);
			strTimeText.Format(L"%.*s",TimeLength, strFullTime.CPtr());
		}
	}
	//if ( !strDateText.IsEmpty() )
	{
		int Year=st.wYear;

		if (!FullYear)
			Year%=100;

		if (TextMonth)
		{
			const wchar_t *Month=MSG(MMonthJan+st.wMonth-1);

			switch (CurDateFormat)
			{
				case 0:
					strDateText.Format(L"%3.3s %2d %02d",Month,st.wDay,Year);
					break;
				case 1:
					strDateText.Format(L"%2d %3.3s %02d",st.wDay,Month,Year);
					break;
				default:
					strDateText.Format(L"%02d %3.3s %2d",Year,Month,st.wDay);
					break;
			}
		}
		else
		{
			int p1,p2,p3=Year;
			int w1=2, w2=2, w3=2;
			wchar_t f1=L'0', f2=L'0', f3=FullYear==2?L' ':L'0';
			switch (CurDateFormat)
			{
				case 0:
					p1=st.wMonth;
					p2=st.wDay;
					break;
				case 1:
					p1=st.wDay;
					p2=st.wMonth;
					break;
				default:
					p1=Year;
					w1=FullYear==2?5:2;
					f3=f1;
					f1=L' ';
					p2=st.wMonth;
					p3=st.wDay;
					break;
			}
			FormatString Fmt;
			Fmt<<fmt::FillChar(f1)<<fmt::Width(w1)<<p1<<DateSeparator<<fmt::FillChar(f2)<<fmt::Width(w2)<<p2<<DateSeparator<<fmt::FillChar(f3)<<fmt::Width(w3)<<p3;
			strDateText=Fmt;
		}
	}

	if (Brief)
	{
		strDateText.SetLength(TextMonth ? 6 : 5);

		if (lt.wYear!=st.wYear)
			strTimeText.Format(L"%5d",st.wYear);
	}
}
コード例 #18
0
ファイル: llwindebug.cpp プロジェクト: VirtualReality/Viewer
//*************************************************************
LLSD WINAPI Get_Exception_Info(PEXCEPTION_POINTERS pException)
//*************************************************************
// Allocate Str[DUMP_SIZE_MAX] and return Str with dump, if !pException - just return call stack in Str.
{
	LLSD info;
	LPWSTR		Str;
	int			Str_Len;
//	int			i;
	LPWSTR		Module_Name = new WCHAR[MAX_PATH];
	PBYTE		Module_Addr;
	HANDLE		hFile;
	FILETIME	Last_Write_Time;
	FILETIME	Local_File_Time;
	SYSTEMTIME	T;

	Str = new WCHAR[DUMP_SIZE_MAX];
	Str_Len = 0;
	if (!Str)
		return NULL;
	
	Get_Version_Str(info);
	
	GetModuleFileName(NULL, Str, MAX_PATH);
	info["Process"] = ll_convert_wide_to_string(Str);
	info["ThreadID"] = (S32)GetCurrentThreadId();

	// If exception occurred.
	if (pException)
	{
		EXCEPTION_RECORD &	E = *pException->ExceptionRecord;
		CONTEXT &			C = *pException->ContextRecord;

		// If module with E.ExceptionAddress found - save its path and date.
		if (Get_Module_By_Ret_Addr((PBYTE)E.ExceptionAddress, Module_Name, Module_Addr))
		{
			info["Module"] = ll_convert_wide_to_string(Module_Name);

			if ((hFile = CreateFile(Module_Name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
				FILE_ATTRIBUTE_NORMAL, NULL)) != INVALID_HANDLE_VALUE)
			{
				if (GetFileTime(hFile, NULL, NULL, &Last_Write_Time))
				{
					FileTimeToLocalFileTime(&Last_Write_Time, &Local_File_Time);
					FileTimeToSystemTime(&Local_File_Time, &T);

					info["DateModified"] = llformat("%02d/%02d/%d", T.wMonth, T.wDay, T.wYear);
				}
				CloseHandle(hFile);
			}
		}
		else
		{
			info["ExceptionAddr"] = (int)E.ExceptionAddress;
		}
		
		info["ExceptionCode"] = (int)E.ExceptionCode;
		
		/*
		//TODO: Fix this
		if (E.ExceptionCode == EXCEPTION_ACCESS_VIOLATION)
		{
			// Access violation type - Write/Read.
			LLSD exception_info;
			exception_info["Type"] = E.ExceptionInformation[0] ? "Write" : "Read";
			exception_info["Address"] = llformat("%08x", E.ExceptionInformation[1]);
			info["Exception Information"] = exception_info;
		}
		*/

		
		// Save instruction that caused exception.
		/*
		std::string str;
		for (i = 0; i < 16; i++)
			str += llformat(" %02X", PBYTE(E.ExceptionAddress)[i]);
		info["Instruction"] = str;
		*/
		LLSD registers;
		registers["EAX"] = (int)C.Eax;
		registers["EBX"] = (int)C.Ebx;
		registers["ECX"] = (int)C.Ecx;
		registers["EDX"] = (int)C.Edx;
		registers["ESI"] = (int)C.Esi;
		registers["EDI"] = (int)C.Edi;
		registers["ESP"] = (int)C.Esp;
		registers["EBP"] = (int)C.Ebp;
		registers["EIP"] = (int)C.Eip;
		registers["EFlags"] = (int)C.EFlags;
		info["Registers"] = registers;
	} //if (pException)
	
	// Save call stack info.
	Get_Call_Stack(pException->ExceptionRecord, pException->ContextRecord, info);

	return info;
} //Get_Exception_Info
コード例 #19
0
ファイル: time.c プロジェクト: ohmann/checkapi
APR_DECLARE(apr_status_t) apr_time_exp_lt(apr_time_exp_t *result,
                                          apr_time_t input)
{
    SYSTEMTIME st;
    FILETIME ft, localft;

    AprTimeToFileTime(&ft, input);

#if APR_HAS_UNICODE_FS && !defined(_WIN32_WCE)
    IF_WIN_OS_IS_UNICODE
    {
        TIME_ZONE_INFORMATION *tz;
        SYSTEMTIME localst;
        apr_time_t localtime;

        get_local_timezone(&tz);

        FileTimeToSystemTime(&ft, &st);

        /* The Platform SDK documents that SYSTEMTIME/FILETIME are
         * generally UTC.  We use SystemTimeToTzSpecificLocalTime
         * because FileTimeToLocalFileFime is documented that the
         * resulting time local file time would have DST relative
         * to the *present* date, not the date converted.
         */
        SystemTimeToTzSpecificLocalTime(tz, &st, &localst);
        SystemTimeToAprExpTime(result, &localst);
        result->tm_usec = (apr_int32_t) (input % APR_USEC_PER_SEC);


        /* Recover the resulting time as an apr time and use the
         * delta for gmtoff in seconds (and ignore msec rounding)
         */
        SystemTimeToFileTime(&localst, &localft);
        FileTimeToAprTime(&localtime, &localft);
        result->tm_gmtoff = (int)apr_time_sec(localtime)
                          - (int)apr_time_sec(input);

        /* To compute the dst flag, we compare the expected
         * local (standard) timezone bias to the delta.
         * [Note, in war time or double daylight time the
         * resulting tm_isdst is, desireably, 2 hours]
         */
        result->tm_isdst = (result->tm_gmtoff / 3600)
                         - (-(tz->Bias + tz->StandardBias) / 60);
    }
#endif
#if APR_HAS_ANSI_FS || defined(_WIN32_WCE)
    ELSE_WIN_OS_IS_ANSI
    {
        TIME_ZONE_INFORMATION tz;
	/* XXX: This code is simply *wrong*.  The time converted will always
         * map to the *now current* status of daylight savings time.
         */

        FileTimeToLocalFileTime(&ft, &localft);
        FileTimeToSystemTime(&localft, &st);
        SystemTimeToAprExpTime(result, &st);
        result->tm_usec = (apr_int32_t) (input % APR_USEC_PER_SEC);

        switch (GetTimeZoneInformation(&tz)) {
            case TIME_ZONE_ID_UNKNOWN:
                result->tm_isdst = 0;
                /* Bias = UTC - local time in minutes
                 * tm_gmtoff is seconds east of UTC
                 */
                result->tm_gmtoff = tz.Bias * -60;
                break;
            case TIME_ZONE_ID_STANDARD:
                result->tm_isdst = 0;
                result->tm_gmtoff = (tz.Bias + tz.StandardBias) * -60;
                break;
            case TIME_ZONE_ID_DAYLIGHT:
                result->tm_isdst = 1;
                result->tm_gmtoff = (tz.Bias + tz.DaylightBias) * -60;
                break;
            default:
                /* noop */;
        }
    }
#endif

    return APR_SUCCESS;
}
コード例 #20
0
ファイル: dir_sys_win.cpp プロジェクト: Klaim/falcon
bool fal_stats( const String &filename, FileStat &sts )
{
   String fname = filename;
   Path::uriToWin( fname );

	AutoWString wBuffer( fname );
   // First, determine if the file exists
   if( filename.size() > 0 && filename.getCharAt(filename.length()-1) != '.' )
   {
      WIN32_FIND_DATAW wFindData;

      HANDLE hFound = FindFirstFileW( wBuffer.w_str(), &wFindData );
      if( hFound == INVALID_HANDLE_VALUE )
      {
         if( GetLastError() == ERROR_CALL_NOT_IMPLEMENTED )
         {
            WIN32_FIND_DATAA aFindData;
            AutoCString cBuffer( fname );
            
            hFound = FindFirstFileA( cBuffer.c_str(), &aFindData );
            
            if ( hFound == INVALID_HANDLE_VALUE )
               return false;

            FindClose( hFound );

            // check case sensitive
            String ffound(aFindData.cFileName);
            if( fname.subString( fname.length() - ffound.length() ) != ffound )
               return false;
         }
         else
            return false;
      }
      
      FindClose( hFound );
      
      // Then, see if the case matches.
      String ffound(wFindData.cFileName);
      if( fname.subString( fname.length() - ffound.length() ) != ffound )
         return false;
   }

   // ok, file exists and with matching case

   HANDLE temp = CreateFileW( wBuffer.w_str(),
      GENERIC_READ,
      FILE_SHARE_READ,
      NULL,
      OPEN_EXISTING,
      FILE_FLAG_BACKUP_SEMANTICS,
      NULL );

	if( (temp == INVALID_HANDLE_VALUE || temp == 0) && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED )
	{
      AutoCString cBuffer( fname );
      temp = CreateFile( cBuffer.c_str(),
	   		GENERIC_READ,
				FILE_SHARE_READ,
				NULL,
				OPEN_EXISTING,
				FILE_FLAG_BACKUP_SEMANTICS,
				NULL );
	}

   if( temp == INVALID_HANDLE_VALUE ) 
   {
      // on win 95/98, we can't normally access directory data.
		
      DWORD attribs = GetFileAttributesW( wBuffer.w_str() );
		if(  attribs == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED )
		{
         AutoCString cBuffer( fname );
			attribs = GetFileAttributes( cBuffer.c_str() );
		}

      if( attribs == INVALID_FILE_ATTRIBUTES ) {
         return false;
      }

      if( (attribs & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY ) {
         sts.m_type = FileStat::t_dir;
         sts.m_attribs = attribs;
         sts.m_size = 0;
         sts.m_mtime = new TimeStamp();
         sts.m_atime = new TimeStamp();
         sts.m_ctime = new TimeStamp();
         sts.m_owner = 0;      /* user ID of owner */
         sts.m_group = 0;      /* group ID of owner */
         return true;
      }
      return false;
   }

   BY_HANDLE_FILE_INFORMATION info;
   memset( &info, 0, sizeof( info ) );

   GetFileInformationByHandle( temp, &info );

   if( info.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY )
      sts.m_type = FileStat::t_dir;
   else
      sts.m_type = FileStat::t_normal;

   FILETIME local_timing;
   SYSTEMTIME timing;

   FileTimeToLocalFileTime( &info.ftCreationTime, &local_timing );
   FileTimeToSystemTime( &local_timing, &timing );
   WinSystemTime mtime( timing );
   if ( sts.m_ctime == 0 )
      sts.m_ctime = new TimeStamp();
   sts.m_ctime->fromSystemTime( mtime );

   FileTimeToLocalFileTime( &info.ftLastAccessTime, &local_timing );
   FileTimeToSystemTime( &local_timing, &mtime.m_time );
   if ( sts.m_atime == 0 )
      sts.m_atime = new TimeStamp();
   sts.m_atime->fromSystemTime( mtime );

   FileTimeToLocalFileTime( &info.ftLastWriteTime, &local_timing );
   FileTimeToSystemTime( &local_timing, &mtime.m_time );
   if ( sts.m_mtime == 0 )
      sts.m_mtime = new TimeStamp();
   sts.m_mtime->fromSystemTime( mtime );

   sts.m_size = info.nFileSizeHigh;
   sts.m_size = sts.m_size << 32 | info.nFileSizeLow;
   sts.m_attribs = info.dwFileAttributes;
   sts.m_owner = 0;      /* user ID of owner */
   sts.m_group = 0;      /* group ID of owner */

   CloseHandle( temp );

   return true;
}
コード例 #21
0
ファイル: s_direct.cpp プロジェクト: AaronDP/efte_adbshell
int FileFind::FindFirst(FileInfo **fi) {
#if defined(USE_DIRENT)
    if (dir)
        closedir(dir);
    if ((dir = opendir(Directory)) == 0)
        return -1;
    return FindNext(fi);
#elif defined(OS2) && !defined(USE_DIRENT)
    char fullpattern[MAXPATH];
    HDIR hdir = HDIR_CREATE;
    ULONG attr = FILE_ARCHIVED | FILE_READONLY;
    ULONG count = 1;
    FILEFINDBUF3 find; // need to improve to fetch multiple entries at once
    char fullpath[MAXPATH];
    char *name;
    struct tm t;
    int rc;

    if (dir)
        DosFindClose(dir);

    if (Flags & ffDIRECTORY)
        attr |= FILE_DIRECTORY;

    if (Flags & ffHIDDEN)
        attr |= FILE_HIDDEN | FILE_SYSTEM; // separate ?

    if (Pattern)
        JoinDirFile(fullpattern, Directory, Pattern);
    else
        JoinDirFile(fullpattern, Directory, "*");

    if ((rc = DosFindFirst(fullpattern,
                           &hdir,
                           attr,
                           &find, sizeof(find),
                           &count,
                           FIL_STANDARD)) != 0) {
        //fprintf(stderr, "%s: %d\n\n", fullpattern, rc);
        return -1;
    }
    dir = hdir;
    if (count != 1)
        return -1;
    name = find.achName;
    if (Flags & ffFULLPATH) {
        JoinDirFile(fullpath, Directory, name);
        name = fullpath;
    }
    memset((void *)&t, 0, sizeof(t));
    t.tm_year = find.fdateLastWrite.year + 80; // ugh!
    t.tm_mon = find.fdateLastWrite.month - 1;
    t.tm_mday = find.fdateLastWrite.day;
    t.tm_hour = find.ftimeLastWrite.hours;
    t.tm_min = find.ftimeLastWrite.minutes;
    t.tm_sec = find.ftimeLastWrite.twosecs * 2; // ugh!
    t.tm_isdst = -1;
    *fi = new FileInfo(name,
                       (find.attrFile & FILE_DIRECTORY) ? fiDIRECTORY : fiFILE,
                       find.cbFile,
                       mktime(&t));
    return 0;
#elif defined(NT) && !defined(USE_DIRENT)
#if defined(USE_VCFIND)
    char fullpattern[MAXPATH];

    _finddata_t find; // need to improve to fetch multiple entries at once
    char fullpath[MAXPATH];
    char *name;
    struct tm t;
    int rc;

    if (dir)
        _findclose(dir);

    /*if (Flags & ffDIRECTORY)
    attr |= FILE_DIRECTORY;

    if (Flags & ffHIDDEN)
    attr |= FILE_HIDDEN | FILE_SYSTEM; // separate ?
    */
    if (Pattern)
        JoinDirFile(fullpattern, Directory, Pattern);
    else
        JoinDirFile(fullpattern, Directory, "*");

    if ((rc = _findfirst(fullpattern, &find)) == -1) {
        //        fprintf(stderr, "%s: %d\n\n", fullpattern, rc);
        return -1;
    }
    dir = rc;

    name = find.name;
    if (Flags & ffFULLPATH) {
        JoinDirFile(fullpath, Directory, name);
        name = fullpath;
    }

    *fi = new FileInfo(name,
                       (find.attrib & _A_SUBDIR) ? fiDIRECTORY : fiFILE,
                       find.size,
                       find.time_create);
    return 0;
#else
    char fullpattern[MAXPATH];

    WIN32_FIND_DATA find; // need to improve to fetch multiple entries at once
    char fullpath[MAXPATH];
    char *name;
    struct tm t;
    SYSTEMTIME st;
    FILETIME localft;                   // needed for time conversion
    int rc;

    if (dir)
        _findclose(dir);

    /*if (Flags & ffDIRECTORY)
    attr |= FILE_DIRECTORY;

    if (Flags & ffHIDDEN)
    attr |= FILE_HIDDEN | FILE_SYSTEM; // separate ?
    */
    if (Pattern)
        JoinDirFile(fullpattern, Directory, Pattern);
    else
        JoinDirFile(fullpattern, Directory, "*");

    if ((rc = (int) FindFirstFile(fullpattern, &find)) < 0) {
        //fprintf(stderr, "%s: %d\n\n", fullpattern, rc);
        return -1;
    }
    dir = rc;

    name = find.cFileName;
    if (Flags & ffFULLPATH) {
        JoinDirFile(fullpath, Directory, name);
        name = fullpath;
    }

    /*
    * since filetime is in UTC format we need to convert it first to
    * localtime and when we have "correct" time we can use it.
    */

    FileTimeToLocalFileTime(&find.ftLastWriteTime, &localft);
    FileTimeToSystemTime(&localft, &st);

    t.tm_year = st.wYear - 1900;
    t.tm_mon = st.wMonth - 1;           // in system time january is 1...
    t.tm_mday = st.wDay;
    t.tm_hour = st.wHour;
    t.tm_min = st.wMinute;
    t.tm_sec = st.wSecond;
    t.tm_isdst = -1;


    *fi = new FileInfo(name,
                       (find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? fiDIRECTORY : fiFILE,
                       find.nFileSizeLow, // !!!
                       mktime(&t));
    return 0;
#endif
#endif
}
コード例 #22
0
ファイル: OS_NS_time.cpp プロジェクト: 08keelr/TrinityCore
struct tm *
ACE_OS::localtime_r (const time_t *t, struct tm *res)
{
  ACE_OS_TRACE ("ACE_OS::localtime_r");
#if defined (ACE_HAS_REENTRANT_FUNCTIONS)
  ACE_OSCALL_RETURN (::localtime_r (t, res), struct tm *, 0);
#elif defined (ACE_HAS_TR24731_2005_CRT)
  ACE_SECURECRTCALL (localtime_s (res, t), struct tm *, 0, res);
  return res;
#elif !defined (ACE_HAS_WINCE)
  ACE_OS_GUARD

  ACE_UNUSED_ARG (res);
  struct tm * res_ptr = 0;
  ACE_OSCALL (::localtime (t), struct tm *, 0, res_ptr);
  if (res_ptr == 0)
    return 0;
  else
    {
      *res = *res_ptr;
      return res;
    }
#elif defined (ACE_HAS_WINCE)
  // This is really stupid, converting FILETIME to timeval back and
  // forth.  It assumes FILETIME and DWORDLONG are the same structure
  // internally.

  TIME_ZONE_INFORMATION pTz;

  const unsigned short int __mon_yday[2][13] =
  {
    /* Normal years.  */
    { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
    /* Leap years.  */
    { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
  };

  ULARGE_INTEGER _100ns;
  ::GetTimeZoneInformation (&pTz);

  _100ns.QuadPart = (DWORDLONG) *t * 10000 * 1000 + ACE_Time_Value::FILETIME_to_timval_skew;
  FILETIME file_time;
  file_time.dwLowDateTime = _100ns.LowPart;
  file_time.dwHighDateTime = _100ns.HighPart;

  FILETIME localtime;
  SYSTEMTIME systime;
  FileTimeToLocalFileTime (&file_time, &localtime);
  FileTimeToSystemTime (&localtime, &systime);

  res->tm_hour = systime.wHour;

  if(pTz.DaylightBias!=0)
    res->tm_isdst = 1;
  else
    res->tm_isdst = 1;

   int iLeap;
   iLeap = (res->tm_year % 4 == 0 && (res->tm_year% 100 != 0 || res->tm_year % 400 == 0));
   // based on leap select which group to use

   res->tm_mday = systime.wDay;
   res->tm_min = systime.wMinute;
   res->tm_mon = systime.wMonth - 1;
   res->tm_sec = systime.wSecond;
   res->tm_wday = systime.wDayOfWeek;
   res->tm_yday = __mon_yday[iLeap][systime.wMonth] + systime.wDay;
   res->tm_year = systime.wYear;// this the correct year but bias the value to start at the 1900
   res->tm_year = res->tm_year - 1900;

   return res;
#else
  // @@ Same as ACE_OS::localtime (), you need to implement it
  //    yourself.
  ACE_UNUSED_ARG (t);
  ACE_UNUSED_ARG (res);
  ACE_NOTSUP_RETURN (0);
#endif /* ACE_HAS_REENTRANT_FUNCTIONS */
}
コード例 #23
0
ファイル: timedate.cpp プロジェクト: TsNeko/vbslib
/***********************************************************************
  <<< [main] >>> 
************************************************************************/
int  main( int argc, char* argv[] )
{
  int   r = 0;
  int   e;
  char  str[256];
  char  left[128];
  char  right[128];
  char* l_SetSentence;
  char* l_Path;
  char* p;
  time_t     t;
  struct tm  t2;
  size_t     len;
  BOOL  b;

  e = 1;

  // Get main parameters
  l_SetSentence = ( argc > 1 ? argv[1] : "now=now" );
  l_Path = ( argc > 2 ? argv[2] : "" );


  // Get left and right from l_SetSentence
  p = strchr( l_SetSentence, '=' );  if ( p == NULL )  strchr( l_SetSentence, '\0' );
  strncpy_r( left, sizeof(left), l_SetSentence, (int)(p - l_SetSentence) );
  #pragma warning(push)
  #pragma warning(disable: 4996)
    if ( *p == '\0' )  strcpy( right, "now" );  else  strcpy_r( right, sizeof(right), p + 1 );
  #pragma warning(pop)


  // if ( right == "now" )  str = now time
  if ( _stricmp( right, "now" ) == 0 ) {
    time( &t );
    localtime_s( &t2, &t );
  #pragma warning(push)
  #pragma warning(disable: 4996)
    strcpy( str, "Set " );
  #pragma warning(pop)
    strcpy_r( str+4, sizeof(str)-4, left );
    len = strlen( str );
    strftime( str + len, sizeof(str) - len, "=%Y%m%d_%H%M", &t2 );
    e = 0;
  }

  // if ( right == "update" )  str = update time stamp of l_Path
  else if ( _stricmp( right, "update" ) == 0 ) {
    HANDLE  f;
    FILETIME    ft;
    SYSTEMTIME  st;

    e = 0;
    f = CreateFile( l_Path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
         FILE_ATTRIBUTE_NORMAL , 0 );
    if ( f == NULL || f == INVALID_HANDLE_VALUE )  { e = 1;  f = NULL; }

    if(!e){  b= GetFileTime( f, NULL, NULL, &ft ); if(!b)e=1; }
    if(!e){  b= FileTimeToLocalFileTime( &ft, &ft ); if(!b)e=1; }
    if(!e){  b= FileTimeToSystemTime( &ft, &st ); if(!b)e=1; }
    if ( f != NULL )  CloseHandle( f );
    if(!e)  stprintf_r( str, sizeof(str), _T("Set %s=%04d%02d%02d_%02d%02d"),
              left, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute );
  }

  // error output
  if(e) {
    stprintf_r( str, sizeof(str), _T("Set %s="), left );
  }

  printf( "%s", str );

  return  r;
}
コード例 #24
0
ファイル: timefn.cpp プロジェクト: Hakansv/OpenCPN
void RarTime::GetLocal(RarLocalTime *lt)
{
#ifdef _WIN_ALL
  FILETIME ft;
  GetWin32(&ft);
  FILETIME lft;

  if (WinNT() < WNT_VISTA)
  {
    // SystemTimeToTzSpecificLocalTime based code produces 1 hour error on XP.
    FileTimeToLocalFileTime(&ft,&lft);
  }
  else
  {
    // We use these functions instead of FileTimeToLocalFileTime according to
    // MSDN recommendation: "To account for daylight saving time
    // when converting a file time to a local time ..."
    SYSTEMTIME st1,st2;
    FileTimeToSystemTime(&ft,&st1);
    SystemTimeToTzSpecificLocalTime(NULL,&st1,&st2);
    SystemTimeToFileTime(&st2,&lft);

    // Correct precision loss (low 4 decimal digits) in FileTimeToSystemTime.
    FILETIME rft;
    SystemTimeToFileTime(&st1,&rft);
    int64 Corrected=INT32TO64(ft.dwHighDateTime,ft.dwLowDateTime)-
                    INT32TO64(rft.dwHighDateTime,rft.dwLowDateTime)+
                    INT32TO64(lft.dwHighDateTime,lft.dwLowDateTime);
    lft.dwLowDateTime=(DWORD)Corrected;
    lft.dwHighDateTime=(DWORD)(Corrected>>32);
  }

  SYSTEMTIME st;
  FileTimeToSystemTime(&lft,&st);
  lt->Year=st.wYear;
  lt->Month=st.wMonth;
  lt->Day=st.wDay;
  lt->Hour=st.wHour;
  lt->Minute=st.wMinute;
  lt->Second=st.wSecond;
  lt->wDay=st.wDayOfWeek;
  lt->yDay=lt->Day-1;

  static int mdays[12]={31,28,31,30,31,30,31,31,30,31,30,31};
  for (uint I=1;I<lt->Month && I<=ASIZE(mdays);I++)
    lt->yDay+=mdays[I-1];

  if (lt->Month>2 && IsLeapYear(lt->Year))
    lt->yDay++;

  st.wMilliseconds=0;
  FILETIME zft;
  SystemTimeToFileTime(&st,&zft);

  // Calculate the time reminder, which is the part of time smaller
  // than 1 second, represented in 100-nanosecond intervals.
  lt->Reminder=INT32TO64(lft.dwHighDateTime,lft.dwLowDateTime)-
               INT32TO64(zft.dwHighDateTime,zft.dwLowDateTime);
#else
  time_t ut=GetUnix();
  struct tm *t;
  t=localtime(&ut);

  lt->Year=t->tm_year+1900;
  lt->Month=t->tm_mon+1;
  lt->Day=t->tm_mday;
  lt->Hour=t->tm_hour;
  lt->Minute=t->tm_min;
  lt->Second=t->tm_sec;
  lt->Reminder=itime % 10000000;
  lt->wDay=t->tm_wday;
  lt->yDay=t->tm_yday;
#endif
}
コード例 #25
0
ファイル: ImpSfx.cpp プロジェクト: wkoiking/xyzzy
void extract_archive(void *hWnd)
{
    uint i;
    char arcname[MAX_PATH * 2];
    char outdir[MAX_PATH * 2];
    char outfilename[MAX_PATH * 2];
    CUnImp Imp;
    IMP_ARCHIVE_INFO iai;
    DWORD dwAttribute;
    FILETIME ctime;
    FILETIME ctime_local;
    FILETIME mtime;
    FILETIME mtime_local;
    GetModuleFileName(GetModuleHandle(NULL),arcname,MAX_PATH * 2);
    if (Imp.open_archive(arcname,&iai) == false)
    {
        MessageBox((HWND)hWnd,"自己展開書庫ではありません。","IMP Self Extract Archiver",MB_OK);
        extract_flag = false;
        _endthread();
    }
    GetDlgItemText((HWND)hWnd,IDC_OUTDIR,outdir,MAX_PATH * 2);
    if (outdir[lstrlen(outdir) - 1] != '\\')
    {
        lstrcat(outdir,"\\");
    }
    for (i = 0;i < iai.file_count;i++)
    {
        sprintf(outfilename,"%s%s",outdir,iai.ifh[i].filename);
        SetDlgItemText((HWND)hWnd,IDC_FILENAME,iai.ifh[i].filename);
        if (Imp.extract_file(iai.ifh[i].dirent,outfilename) == false)
        {
            MessageBox((HWND)hWnd,"展開に失敗しました。","IMP Self Extract Archiver",MB_OK);
            Imp.close_archive();
            free(iai.ifh);
            extract_flag = false;
            _endthread();
        }
        dwAttribute = 0;
        if (iai.ifh[i].dirent.attrib & _A_ARCH)
        {
            dwAttribute |= FILE_ATTRIBUTE_ARCHIVE;
        }
        if (iai.ifh[i].dirent.attrib & _A_HIDDEN)
        {
            dwAttribute |= FILE_ATTRIBUTE_HIDDEN;
        }
        if (iai.ifh[i].dirent.attrib & _A_RDONLY)
        {
            dwAttribute |= FILE_ATTRIBUTE_READONLY;
        }
        if (iai.ifh[i].dirent.attrib & _A_SUBDIR)
        {
            dwAttribute |= FILE_ATTRIBUTE_DIRECTORY;
        }
        if (iai.ifh[i].dirent.attrib & _A_SYSTEM)
        {
            dwAttribute |= FILE_ATTRIBUTE_SYSTEM;
        }
        SetFileAttributes(outfilename,dwAttribute);
        DosDateTimeToFileTime(iai.ifh[i].dirent.cdate,iai.ifh[i].dirent.ctime,&ctime);
        FileTimeToLocalFileTime(&ctime,&ctime_local);
        DosDateTimeToFileTime(iai.ifh[i].dirent.cdate,iai.ifh[i].dirent.ctime,&mtime);
        FileTimeToLocalFileTime(&mtime,&mtime_local);
        SetFileTimeEx(outfilename,ctime_local,mtime_local,mtime_local);
    }
    Imp.close_archive();
    free(iai.ifh);
    MessageBox((HWND)hWnd,"展開に成功しました。","IMP Self Extract Archiver",MB_OK);
    extract_flag = false;
    _endthread();
}
コード例 #26
0
void ONScripterLabel::searchSaveFile( SaveFileInfo &save_file_info, int no )
{
    char file_name[256];

    bool use_fullwidth = (script_h.system_menu_script == ScriptHandler::JAPANESE_SCRIPT);
    script_h.getStringFromInteger( save_file_info.sjis_no, no,
                                  (num_save_file >= 10)?2:1,
                                  false, use_fullwidth );
#if defined(LINUX) || defined(MACOSX)
    if (script_h.savedir)
        sprintf( file_name, "%ssave%d.dat", script_h.savedir, no );
    else
        sprintf( file_name, "%ssave%d.dat", script_h.save_path, no );
    struct stat buf;
    struct tm *tm;
    if ( stat( file_name, &buf ) != 0 ){
        save_file_info.valid = false;
        return;
    }
    time_t mtime = buf.st_mtime;
    tm = localtime( &mtime );

    save_file_info.month  = tm->tm_mon + 1;
    save_file_info.day    = tm->tm_mday;
    save_file_info.hour   = tm->tm_hour;
    save_file_info.minute = tm->tm_min;
#elif defined(WIN32)
    if (script_h.savedir)
        sprintf( file_name, "%ssave%d.dat", script_h.savedir, no );
    else
        sprintf( file_name, "%ssave%d.dat", script_h.save_path, no );
    HANDLE  handle;
    FILETIME    tm, ltm;
    SYSTEMTIME  stm;

    handle = CreateFile( file_name, GENERIC_READ, 0, NULL,
                         OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
    if ( handle == INVALID_HANDLE_VALUE ){
        save_file_info.valid = false;
        return;
    }

    GetFileTime( handle, NULL, NULL, &tm );
    FileTimeToLocalFileTime( &tm, &ltm );
    FileTimeToSystemTime( &ltm, &stm );
    CloseHandle( handle );

    save_file_info.month  = stm.wMonth;
    save_file_info.day    = stm.wDay;
    save_file_info.hour   = stm.wHour;
    save_file_info.minute = stm.wMinute;
#elif defined(MACOS9)
    if (script_h.savedir)
        sprintf( file_name, "%ssave%d.dat", script_h.savedir, no );
    else
        sprintf( file_name, "%ssave%d.dat", script_h.save_path, no );
	CInfoPBRec  pb;
	Str255      p_file_name;
	FSSpec      file_spec;
	DateTimeRec tm;
	c2pstrcpy( p_file_name, file_name );
	if ( FSMakeFSSpec(0, 0, p_file_name, &file_spec) != noErr ){
		save_file_info.valid = false;
		return;
	}
	pb.hFileInfo.ioNamePtr = file_spec.name;
	pb.hFileInfo.ioVRefNum = file_spec.vRefNum;
	pb.hFileInfo.ioFDirIndex = 0;
	pb.hFileInfo.ioDirID = file_spec.parID;
	if (PBGetCatInfoSync(&pb) != noErr) {
		save_file_info.valid = false;
		return;
	}
	SecondsToDate( pb.hFileInfo.ioFlMdDat, &tm );
	save_file_info.month  = tm.month;
	save_file_info.day    = tm.day;
	save_file_info.hour   = tm.hour;
	save_file_info.minute = tm.minute;
#elif defined(PSP)
    if (script_h.savedir)
        sprintf( file_name, "%ssave%d.dat", script_h.savedir, no );
    else
        sprintf( file_name, "%ssave%d.dat", script_h.save_path, no );
    SceIoStat buf;
    if ( sceIoGetstat(file_name, &buf)<0 ){
        save_file_info.valid = false;
        return;
    }

    save_file_info.month  = buf.st_mtime.month;
    save_file_info.day    = buf.st_mtime.day;
    save_file_info.hour   = buf.st_mtime.hour;
    save_file_info.minute = buf.st_mtime.minute;
#else
    sprintf( file_name, "save%d.dat", no );
    FILE *fp;
    if ( (fp = fopen( file_name, "rb" )) == NULL ){
        save_file_info.valid = false;
        return;
    }
    fclose( fp );

    save_file_info.month  = 1;
    save_file_info.day    = 1;
    save_file_info.hour   = 0;
    save_file_info.minute = 0;
#endif
    save_file_info.valid = true;
    script_h.getStringFromInteger( save_file_info.sjis_month,
                                   save_file_info.month, 2,
                                   false, use_fullwidth );
    script_h.getStringFromInteger( save_file_info.sjis_day,
                                   save_file_info.day, 2,
                                   false, use_fullwidth );
    script_h.getStringFromInteger( save_file_info.sjis_hour,
                                   save_file_info.hour, 2,
                                   false, use_fullwidth );
    script_h.getStringFromInteger( save_file_info.sjis_minute,
                                   save_file_info.minute, 2,
                                   true, use_fullwidth );
}
コード例 #27
0
ファイル: Files.c プロジェクト: garfieldchien/omnia-projetcs
//----------------------------------------------------------------
void CheckFile(DWORD iitem, char *file, WIN32_FIND_DATA *data, char *source)
{
  #ifdef DEBUG_MODE_FILES
  AddMsg(h_main,"DEBUG","files:CheckFile START",file);
  #endif
  char s_sha[SHA256_SIZE]="",s_md5[MAX_PATH], date[MAX_PATH]="\0\0\0";
  HANDLE hfile;
  LARGE_INTEGER filesize;
  FILETIME LocalFileTime;
  SYSTEMTIME SysTimeModification;

  BOOL error = FALSE;

  //last modify
  if (data == NULL)
  {
    WIN32_FIND_DATA d0;
    HANDLE hfind = FindFirstFile(file, &d0);
    if (hfind != INVALID_HANDLE_VALUE)
    {
      filesize.HighPart = d0.nFileSizeHigh;
      filesize.LowPart  = d0.nFileSizeLow;

      if (filesize.QuadPart == 0 && d0.ftLastWriteTime.dwHighDateTime == 0 && d0.ftLastWriteTime.dwLowDateTime == 0) error = TRUE;
      else
      {
        FileTimeToLocalFileTime(&(d0.ftLastWriteTime), &LocalFileTime);
        FileTimeToSystemTime(&LocalFileTime, &SysTimeModification);
        snprintf(date,MAX_PATH,"[Last_modification:%02d/%02d/%02d-%02d:%02d:%02d,Size:%do]"
                     ,SysTimeModification.wYear,SysTimeModification.wMonth,SysTimeModification.wDay
                     ,SysTimeModification.wHour,SysTimeModification.wMinute,SysTimeModification.wSecond,filesize.QuadPart);
        FindClose(hfind);
      }
    }
  }else if (data->ftLastWriteTime.dwHighDateTime != 0 || data->ftLastWriteTime.dwLowDateTime != 0)
  {
    filesize.HighPart = data->nFileSizeHigh;
    filesize.LowPart  = data->nFileSizeLow;

    if (filesize.QuadPart == 0) error = TRUE;
    else
    {
      FileTimeToLocalFileTime(&(data->ftLastWriteTime), &LocalFileTime);
      FileTimeToSystemTime(&LocalFileTime, &SysTimeModification);
      snprintf(date,MAX_PATH,"[Last_modification:%02d/%02d/%02d-%02d:%02d:%02d,Size:%do]"
                   ,SysTimeModification.wYear,SysTimeModification.wMonth,SysTimeModification.wDay
                   ,SysTimeModification.wHour,SysTimeModification.wMinute,SysTimeModification.wSecond,filesize.QuadPart);
    }
  }else error = TRUE;

  if (!error)
  {
    //MD5
    hfile = CreateFile(file,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,0);
    if (hfile != INVALID_HANDLE_VALUE)
    {
      FileToMd5(hfile, s_md5);
      CloseHandle(hfile);

      //SHA256
      hfile = CreateFile(file,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,0);
      if (hfile != INVALID_HANDLE_VALUE)
      {
        FileToSHA256(hfile, s_sha);
        CloseHandle(hfile);
      }
    }

    if (s_sha[0] != 0)
    {
      snprintf(file,LINE_SIZE,"%s %s;MD5;%s;%s;%s",file,date,s_md5[0]==0?"":s_md5,SHA1_enable?"SHA1":"SHA256",s_sha[0]==0?"":s_sha);
    }else if (s_md5[0] != 0)
    {
      snprintf(file,LINE_SIZE,"%s %s;MD5;%s;;",file,date,s_md5);
    }else snprintf(file,LINE_SIZE,"%s %s;;;;",file,date);

    AddMsg(h_main,(char*)"FOUND (File1)",source,(char*)file);
    AddLSTVUpdateItem(file, COL_FILES, iitem);
  }

  #ifdef DEBUG_MODE_FILES
  AddMsg(h_main,"DEBUG","files:CheckFile END",file);
  #endif
}
コード例 #28
0
/* Format Timestamp from EventLog */
char *WinEvtTimeToString(ULONGLONG ulongTime)
{
    SYSTEMTIME sysTime;
    FILETIME fTime, lfTime;
    ULARGE_INTEGER ulargeTime;
    struct tm tm_struct;
    char *timestamp = NULL;
    int size = 80;

    if ((timestamp = malloc(size)) == NULL) {
        log2file(
            "%s: ERROR: Could not malloc() memory to convert timestamp which returned [(%d)-(%s)]",
            ARGV0,
            errno,
            strerror(errno));
        goto cleanup;
    }

    /* Zero out structure */
    memset(&tm_struct, 0, sizeof(tm_struct));

    /* Convert from ULONGLONG to usable FILETIME value */
    ulargeTime.QuadPart = ulongTime;

    fTime.dwLowDateTime = ulargeTime.LowPart;
    fTime.dwHighDateTime = ulargeTime.HighPart;

    /* Adjust time value to reflect current timezone then convert to a
     * SYSTEMTIME
     */
    if (FileTimeToLocalFileTime(&fTime, &lfTime) == 0) {
        log2file(
            "%s: ERROR: Could not FileTimeToLocalFileTime() to convert timestamp which returned (%lu)",
            ARGV0,
            GetLastError());
        goto cleanup;
    }

    if (FileTimeToSystemTime(&lfTime, &sysTime) == 0) {
        log2file(
            "%s: ERROR: Could not FileTimeToSystemTime() to convert timestamp which returned (%lu)",
            ARGV0,
            GetLastError());
        goto cleanup;
    }

    /* Convert SYSTEMTIME to tm */
    tm_struct.tm_year = sysTime.wYear - 1900;
    tm_struct.tm_mon  = sysTime.wMonth - 1;
    tm_struct.tm_mday = sysTime.wDay;
    tm_struct.tm_hour = sysTime.wHour;
    tm_struct.tm_wday = sysTime.wDayOfWeek;
    tm_struct.tm_min  = sysTime.wMinute;
    tm_struct.tm_sec  = sysTime.wSecond;

    /* Format timestamp string */
    strftime(timestamp, size, "%Y %b %d %H:%M:%S", &tm_struct);

    return (timestamp);

cleanup:
    free(timestamp);

    return (NULL);
}
コード例 #29
0
ファイル: Files.c プロジェクト: garfieldchien/omnia-projetcs
//----------------------------------------------------------------
void CheckListFile(DWORD iitem, char *file_path, char*filename, long long int filesize, WIN32_FIND_DATA *data, DWORD cb_id)
{
  DWORD j, _nb_i = SendDlgItemMessage(h_main,cb_id,LB_GETCOUNT,(WPARAM)NULL,(LPARAM)NULL);
  char file[LINE_SIZE], tmp[LINE_SIZE], date[MAX_PATH];

  HANDLE hfile;
  char s_sha[SHA256_SIZE]="",s_md5[MAX_PATH];
  FILETIME LocalFileTime;
  SYSTEMTIME SysTimeModification;
  BOOL exist = FALSE;

  char ss_sha[SHA256_SIZE]="",ss_md5[MAX_PATH]="", s_size[MAX_PATH]="";
  long long int d_size = -1;

  BOOL hash_already_done = FALSE;

  for (j=0;j<_nb_i && scan_start;j++)
  {
    if (SendDlgItemMessage(h_main,cb_id,LB_GETTEXTLEN,(WPARAM)j,(LPARAM)NULL) > LINE_SIZE)continue;
    if (SendDlgItemMessage(h_main,cb_id,LB_GETTEXT,(WPARAM)j,(LPARAM)file))
    {
      exist = FALSE;
      //check if the file exist
      if (file[0] == ':') // hash type
      {
        ss_sha[0] = 0;
        ss_md5[0] = 0;
        s_size[0] = 0;
        d_size    = -1;

        //format= :size on octets:MD5 hash: SHA256 hash:
        char *c = file+1; //pass ':'******':')continue;
        while (*c && *c != ':')
        {
          *d++ = *c++;
        }
        *d = 0;
        d_size = atol(s_size);
        if (d_size < 1 ) d_size = -1;

        //MD5
        d = ss_md5;
        c++;//pass ':'******':')
        {
          while (*c && *c != ':')
          {
            *d++ = *c++;
          }
          *d = 0;
        }

        //SHA
        d = ss_sha;
        c++;//pass ':'******':')
        {
          *d++ = *c++;
        }
        *d = 0;

        //check
        if (d_size == filesize || d_size == -1)
        {
          if (hash_already_done)
          {
            if (ss_md5[0] != 0)
              if (compare_nocas(s_md5,ss_md5))
                exist = TRUE;

            if ((!exist && ss_md5[0] == 0) && (ss_sha[0] != 0))
              if (compare_nocas(s_sha,ss_sha))
                exist = TRUE;
          }else
          {
            hash_already_done = TRUE;

            //check all other datas
            s_md5[0] = 0;
            s_sha[0] = 0;

            hfile = CreateFile(file_path,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,0);
            if (hfile != INVALID_HANDLE_VALUE)
            {
              FileToMd5(hfile, s_md5);
              CloseHandle(hfile);

              hfile = CreateFile(file_path,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,0);
              if (hfile != INVALID_HANDLE_VALUE)
              {
                FileToSHA256(hfile, s_sha);
                CloseHandle(hfile);
              }
            }

            if (ss_md5[0] != 0)
              if (compare_nocas(s_md5,ss_md5))
                exist = TRUE;

            if (!exist && ss_sha[0] != 0)
              if (compare_nocas(s_sha,ss_sha))
                exist = TRUE;
          }

          if (!exist && ss_md5[0] == 0 && ss_sha[0] == 0)exist = TRUE;
        }
      }else if (file[0] == '*')//contient
      {
        if (Contient_nocas(filename,&file[1]))
        {
          exist = TRUE;

          s_md5[0] = 0;
          s_sha[0] = 0;

          hfile = CreateFile(file_path,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,0);
          if (hfile != INVALID_HANDLE_VALUE)
          {
            FileToMd5(hfile, s_md5);
            CloseHandle(hfile);

            hfile = CreateFile(file_path,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,0);
            if (hfile != INVALID_HANDLE_VALUE)
            {
              FileToSHA256(hfile, s_sha);
              CloseHandle(hfile);
            }
          }
        }
      }else //file type
      {
        if (compare_nocas(filename,file))
        {
          exist = TRUE;

          s_md5[0] = 0;
          s_sha[0] = 0;

          hfile = CreateFile(file_path,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,0);
          if (hfile != INVALID_HANDLE_VALUE)
          {
            FileToMd5(hfile, s_md5);
            CloseHandle(hfile);

            hfile = CreateFile(file_path,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,0);
            if (hfile != INVALID_HANDLE_VALUE)
            {
              FileToSHA256(hfile, s_sha);
              CloseHandle(hfile);
            }
          }
        }
      }

      if (exist && (filesize != 0 || (data->ftLastWriteTime.dwHighDateTime != 0 && data->ftLastWriteTime.dwLowDateTime != 0)))
      {
        date[0] = 0;
        FileTimeToLocalFileTime(&(data->ftLastWriteTime), &LocalFileTime);
        FileTimeToSystemTime(&LocalFileTime, &SysTimeModification);
        snprintf(date,MAX_PATH,"[Last_modification:%02d/%02d/%02d-%02d:%02d:%02d,Size:%lo]"
                     ,SysTimeModification.wYear,SysTimeModification.wMonth,SysTimeModification.wDay
                     ,SysTimeModification.wHour,SysTimeModification.wMinute,SysTimeModification.wSecond,filesize);


        if (s_sha[0] != 0)
        {
          snprintf(tmp,LINE_SIZE,"%s %s;MD5;%s;%s;%s",file_path,date,s_md5[0]==0?"":s_md5,SHA1_enable?"SHA1":"SHA256",s_sha[0]==0?"":s_sha);
        }else if (s_md5[0] != 0)
        {
          snprintf(tmp,LINE_SIZE,"%s %s;MD5;%s;;",file_path,date,s_md5[0]==0?"":s_md5);
        }else snprintf(tmp,LINE_SIZE,"%s %s;;;;",file_path,date);

        AddMsg(h_main,(char*)"FOUND (File3)",tmp,(char*)"");
        AddLSTVUpdateItem(tmp, COL_FILES, iitem);
      }
    }
  }
}
コード例 #30
0
ファイル: Crash.cpp プロジェクト: qiqisteve/wxsj2
//*************************************************************
void Get_Exception_Info(PEXCEPTION_POINTERS pException, FILE* fp, DWORD dwLastError)
//*************************************************************
// Allocate Str[DUMP_SIZE_MAX] and return Str with dump, if !pException - just return call stack in Str.
{
	int			i;
	TCHAR		Module_Name[MAX_PATH];
	PBYTE		Module_Addr;
	HANDLE		hFile;
	FILETIME	Last_Write_Time;
	FILETIME	Local_File_Time;
	SYSTEMTIME	T;
	
	Get_Version_Str(fp);

	_ftprintf(fp, _T("------------------------------------------------------------------------------")NL);
	_ftprintf(fp, _T("Process:  ") );

	GetModuleFileName(NULL, Module_Name, MAX_PATH);
	_ftprintf(fp, _T("%s") NL, Module_Name);

	// If exception occurred.
	if (pException)
	{
		EXCEPTION_RECORD &	E = *pException->ExceptionRecord;
		CONTEXT &			C = *pException->ContextRecord;

		// If module with E.ExceptionAddress found - save its path and date.
		if (Get_Module_By_Ret_Addr((PBYTE)E.ExceptionAddress, Module_Name, Module_Addr))
		{
			_ftprintf(fp, _T("Module:   %s") NL, Module_Name);

			if ((hFile = CreateFile(Module_Name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
				FILE_ATTRIBUTE_NORMAL, NULL)) != INVALID_HANDLE_VALUE)
			{
				if (GetFileTime(hFile, NULL, NULL, &Last_Write_Time))
				{
					FileTimeToLocalFileTime(&Last_Write_Time, &Local_File_Time);
					FileTimeToSystemTime(&Local_File_Time, &T);

					_ftprintf(fp, _T("Date Modified:  %02d/%02d/%d") NL, 
						T.wMonth, T.wDay, T.wYear);
				}
				CloseHandle(hFile);
			}
		}
		else
		{
			_ftprintf(fp, _T("Exception Addr:  %08X") NL , (LONG_PTR)(E.ExceptionAddress));
		}
		
		_ftprintf(fp, _T("------------------------------------------------------------------------------")NL);

		//加入具体异常解释信息
		CreateExceptionDesc(pException, fp, dwLastError);
		
		_ftprintf(fp, _T("------------------------------------------------------------------------------")NL);

		// Save instruction that caused exception.
		if(E.ExceptionAddress)
		{
			_ftprintf(fp, _T("Instruction: ")NL);
			for (i = 0; i < 16; i++)
				_ftprintf(fp, _T(" %02X"), PBYTE(E.ExceptionAddress)[i]);
		}
		// Save registers at exception.
		_ftprintf(fp, NL _T("Registers:") NL);
		_ftprintf(fp, _T("EAX: %08X  EBX: %08X  ECX: %08X  EDX: %08X") NL, C.Eax, C.Ebx, C.Ecx, C.Edx);
		_ftprintf(fp, _T("ESI: %08X  EDI: %08X  ESP: %08X  EBP: %08X")NL, C.Esi, C.Edi, C.Esp, C.Ebp);
		_ftprintf(fp, _T("EIP: %08X  EFlags: %08X")NL, C.Eip, C.EFlags);
	} //if (pException)
	
	_ftprintf(fp, _T("------------------------------------------------------------------------------")NL);

	// Save call stack info.
	_ftprintf(fp, _T("Call Stack:")NL);
	Get_Call_Stack(pException, fp);
} //Get_Exception_Info