一段莫名其妙错误的代码
来源:互联网 发布:人工智能的评论 编辑:程序博客网 时间:2024/04/28 14:50
////////////////////////////////////////////////////////////////////////////////////
// ProFileInfo.cpp CProFileInfo类的实现文件
//模块: ProInnerVisitor
//功能:
// 定义CProFileInfo类,完成proe文件的创建时间以及创建人等信息
//=================================================================================
//History:
//=================================================================================
//
//=================================================================================
#include "stdafx.h"
#include "ProFileInfo.h"
#include <string>
#include <list>
#include <cmath>
#include <Windows.h>
#include <fstream>
#include <iostream>
#include <ProMenu.h>
#include <ProMdl.h>
#include <ProWindows.h>
#include <ProUtil.h>
#include <comutil.h>
using namespace std;
CProFileInfo::CProFileInfo(string fileName)
{
m_Creator.clear();
m_Time.clear();
m_FileName = fileName;
}
CProFileInfo::~CProFileInfo()
{
m_Creator.clear();
m_Time.clear();
}
//获得创建人信息
int CProFileInfo::GetFileCreator(string &strCreator)
{
int ret;
if (strCreator.c_str() == NULL)
{
return -1;
}
ret = ExcuteProCmd();
if (ret != 0)
{
m_Creator = "NoCreator";
}
strCreator = m_Creator;
return 0;
}
//获得上次修改时间
int CProFileInfo::GetLastModefyTime(string &strTime)
{
if (strTime.c_str() == NULL)
{
return -1;
}
strTime = m_Time;
return 0;
}
//执行"审计追踪"操作
int CProFileInfo::ExcuteProCmd()
{
ProError err;
int ret;
//宏命令为
//~ Activate `main_dlg_cur` `Info.psh_info_audit_trail`
wchar_t wszCmd[] = L"~ Activate `main_dlg_cur` `Info.psh_info_audit_trail`";
err = ProMacroLoad( wszCmd );
if (err != PRO_TK_NO_ERROR)
{
return -1;
}
err =ProMacroExecute();
if (err != PRO_TK_NO_ERROR)
{
return -1;
}
Sleep(1000*1);
//关闭浏览器窗口
int id;
double size;
err = ProWindowCurrentGet(&id);
if (err == PRO_TK_NO_ERROR)
{
ProWindowBrowserSizeSet(id,0);
}
//获取信息
FILE_MSG_LIST fileinfo;
ret = GetAuditInfo(&fileinfo);
if (ret != 0)
{
return -1;
}
return 0;
}
//返回文件信息,并将信息存入数据结构链表中
int CProFileInfo::GetAuditInfo(FILE_MSG_LIST *fileInfoList)
{
//获得启动目录
ProPath currPath;
ProDirectoryCurrentGet(currPath);
//解析全路径名,以此获得将要生成的文件名
ProPath fullName;
BSTR bsFullName;
bsFullName = _com_util::ConvertStringToBSTR( m_FileName.c_str() );
swprintf(fullName,L"%s",bsFullName);
ProPath path;
ProName name;
ProName extName;
int iVer;
ProFilenameParse(fullName,path,name,extName,&iVer);
//查找扩展名为.usr.*的文件,且文件名与刚才解析的文件名相同
HANDLE hFile = NULL;
int iFind = 1;
WIN32_FIND_DATA wfd;
wchar_t wszFindName[256];
ZeroMemory(wszFindName,256*2);
wchar_t wszTemp[256];
swprintf(wszTemp,L"%s.usr.*",name);
wcscat(wszFindName,currPath);
wcscat(wszFindName,wszTemp);
hFile = ::FindFirstFile(_com_util::ConvertBSTRToString(wszFindName) ,&wfd);
FILETIME ftNearest;
long lCmpRes;
WIN32_FIND_DATA FindDataTag;
if (hFile != INVALID_HANDLE_VALUE)
{
ftNearest = wfd.ftCreationTime;
FindDataTag = wfd;
while (iFind)
{
//现在查找时间最近的一个文件,如果不是,那么删除
FILETIME ftCur = wfd.ftCreationTime;
lCmpRes = CompareFileTime(&ftNearest,&ftCur);
if ( lCmpRes < 0 )
{
//将旧的文件删除
DeleteFile(FindDataTag.cFileName);
ftNearest = ftCur;
FindDataTag = wfd;
}
else if( lCmpRes > 0 )
{
DeleteFile(wfd.cFileName);
}
iFind = ::FindNextFile(hFile,&wfd);
}
}
else
{
return -1; //cannot find the generate file
}
//读取文件中的内容
ASSERT(FindDataTag.cFileName);
ifstream openfile(FindDataTag.cFileName);
if ( !openfile )
{
return -1; //can not open the file
}
char info[256];
for (int i = 0 ; i < 5 ; i++)
{
openfile.getline(info,256);
}
//将获取内容存入成员变量中
//获取修改时间
string handleInfo(info);
string::size_type index = handleInfo.find_first_of('|');
if (index != string::npos)
{
char *szTag = new char[index];
ZeroMemory(szTag,index);
handleInfo.copy(szTag,index);
m_Time = szTag;
delete [] szTag;
}
//获取修改人
string::size_type index1=0,index2=0;
index = 0;
for(int i=0; i < 4 ; ++i)
{
index = handleInfo.find('|',index+1);
if (index == string::npos)
{
return -1; //invalid message
}
if ( 2 == i)
{
index1 = index;
}
if ( 3 == i)
{
index2 = index;
}
}
int size = index2 - index1;
char *szTag1 = new char[size];
ZeroMemory(szTag1,size);
handleInfo.copy(szTag1,size-1,index1+1);
m_Creator = szTag1;
delete [] szTag1;
//删除生成的文件
DeleteFile(FindDataTag.cFileName);
return 0;
}
- 一段莫名其妙错误的代码
- 一段 莫名其妙的 JS 代码
- ASP 莫名其妙的错误
- 莫名其妙的错误窗口
- 一些莫名其妙的错误
- 【Android】莫名其妙的错误
- spark莫名其妙的错误
- 莫名其妙的错误
- 莫名其妙的代码
- 一个莫名其妙的配置错误
- 莫名其妙的http 405错误
- 程序莫名其妙的错误,怎么办?
- 由莫名其妙的错误开始
- 遇到一个莫名其妙的错误。
- net的一个莫名其妙的错误报警
- 定义的枚举莫名其妙的编译错误
- 一段让你晕上半天却找不出错误的JS代码
- 编译时一些莫名其妙的错误
- 操作EXCEL
- 很久没有更新咯,
- 在C#.NET中如何读写INI文件 from:http://www.linuxmine.com/48287.html
- xml的复杂解析取值和节点插入导出合并后的xml文件
- C#中 将DataTable内容显示到ListView当中
- 一段莫名其妙错误的代码
- VB打包工具--- setup factory 7 使用总结
- 不是网管,如何保护自己防止ARP欺骗
- 关于C 语言的文字(作者:梦幻尤里)
- 关于C语言的入门(作者:梦幻尤里)
- Python, Lisp, Ruby函数式编程的一个小对比
- 我看《中国造》
- 关于个性签名的修改说明(作者:梦幻尤里)
- 成就DBA职业生涯