446 lines
9.9 KiB
C++
446 lines
9.9 KiB
C++
#include "StdAfx.h"
|
|
#include "resource.h"
|
|
#include <afxdllx.h>
|
|
#include "KTMenuCtrlBar.h"
|
|
#include "CheckLock.h"
|
|
#include "Cmdpalette.h"
|
|
|
|
#include "uiiado.h"
|
|
#include<Iphlpapi.h>
|
|
#include "afxinet.h"
|
|
#include "CoreTools.h"
|
|
#include "CmdQueryDlg.h"
|
|
#include "initools.h"
|
|
#include "ShortcutKeyMappingDlg.h"
|
|
#pragma comment(lib, "IPHLPAPI.lib")
|
|
|
|
HINSTANCE _hdllInstance = NULL;
|
|
CCheckLock g_lockChk;
|
|
|
|
#define g_pszLicenseFileName _T("licenseTime.dat")
|
|
#define g_pszMacDbFileName _T("cityStandard.db")
|
|
|
|
|
|
#ifdef NEWUI
|
|
CmdPaletteSet g_wndMenuBar;
|
|
#else
|
|
KTMenuCtrlBar g_wndMenuBar;
|
|
#endif
|
|
|
|
void InitApplication();
|
|
void UnloadApplication();
|
|
|
|
AC_IMPLEMENT_EXTENSION_MODULE(KTMainDLL);
|
|
|
|
#define TIMER_CUIX 1
|
|
void CALLBACK TimerProc(HWND hWnd, UINT nMsg, UINT_PTR nTimerid, DWORD dwTime)
|
|
{
|
|
if (nTimerid == TIMER_CUIX)
|
|
{
|
|
void OnMenu();
|
|
OnMenu();
|
|
::KillTimer(hWnd, TIMER_CUIX);
|
|
}
|
|
}
|
|
|
|
extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
|
|
{
|
|
if (dwReason == DLL_PROCESS_ATTACH)
|
|
{
|
|
_hdllInstance = hInstance;
|
|
KTMainDLL.AttachInstance(hInstance);
|
|
InitAcUiDLL();
|
|
}
|
|
else if (dwReason == DLL_PROCESS_DETACH)
|
|
{
|
|
KTMainDLL.DetachInstance();
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
bool SpecialUserPermission()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
typedef struct LicenseTime
|
|
{
|
|
int nYear;
|
|
int nMonth;
|
|
int nDay;
|
|
int nHour;
|
|
int nMinute;
|
|
}LICENSETIME;
|
|
|
|
void ReadLicenseTime(CTime& tStop)
|
|
{
|
|
TCHAR szfileName[MAX_PATH],szFullPath[MAX_PATH];
|
|
GetModuleFileName(_hdllInstance,szfileName,MAX_PATH);
|
|
|
|
TCHAR drive[_MAX_DRIVE] = _T(""),
|
|
dir[_MAX_DIR] = _T(""),
|
|
fname[_MAX_FNAME] = _T(""),
|
|
ext[_MAX_EXT] = _T("");
|
|
|
|
//e:\,program files\autodesk\,myarx,exe
|
|
_tsplitpath(szfileName, drive, dir, fname, ext);
|
|
_tcscpy(szFullPath, drive);
|
|
_tcscat(szFullPath, dir);
|
|
|
|
CString sFullPath = szFullPath;
|
|
sFullPath.TrimRight(_T('\\'));
|
|
|
|
//上一级目录
|
|
int nPos = sFullPath.ReverseFind(_T('\\'));
|
|
CString sPath = sFullPath.Mid(0,nPos + 1);
|
|
|
|
sFullPath = sPath + _T("sys\\");
|
|
sFullPath += _T("licenseTime.dat");
|
|
|
|
CFileFind find;
|
|
if (find.FindFile(sFullPath))
|
|
{
|
|
CFile file;
|
|
if (file.Open(sFullPath,CFile::modeRead))
|
|
{
|
|
char szHead[37];
|
|
//strcpy(szHead,"kingtouch license file 1.0");
|
|
file.Read((void*)szHead,sizeof(szHead));
|
|
|
|
UINT nSize = 1 // 加密信息(4位随机数+4位加密方法)
|
|
+ sizeof(LicenseTime);
|
|
|
|
byte* pData = new byte[nSize];
|
|
ASSERT(NULL != pData);
|
|
|
|
file.Read((void*)pData, nSize);
|
|
byte* pBuffer = pData + 1;
|
|
|
|
LicenseTime lt;
|
|
Adesk::UInt32 n;
|
|
switch (pData[0] & 0x0F)
|
|
{
|
|
case 0x0a: // 加密方法0x0a解密:将每个字节高低4位颠倒,然后和加密信息异或
|
|
{
|
|
for (n = 1; n < nSize; n++)
|
|
{
|
|
byte chLow = (pData[n] & 0x0F);
|
|
byte chHigh = (pData[n] & 0xF0);
|
|
byte chNew = ((chLow << 4) | (chHigh >> 4));
|
|
pData[n] = (chNew ^ pData[0]);
|
|
}
|
|
|
|
memcpy(<, pBuffer, sizeof(LicenseTime));
|
|
CTime tTmp(lt.nYear,lt.nMonth,lt.nDay,lt.nHour,lt.nMinute,0);
|
|
tStop = tTmp;
|
|
|
|
//acutPrintf(_T("\n%d %d %d %d %d"),lt.nYear,lt.nMonth,lt.nDay,lt.nHour,lt.nMinute);
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
|
|
file.Close();
|
|
}
|
|
}
|
|
}
|
|
|
|
void GetMacAdr(CStringList& arMacs)
|
|
{
|
|
PIP_ADAPTER_INFO pAdapterInfo;
|
|
PIP_ADAPTER_INFO pAdapter = NULL;
|
|
DWORD dwRetVal = 0;
|
|
ULONG ulOutBufLen;
|
|
pAdapterInfo=(PIP_ADAPTER_INFO)malloc(sizeof(IP_ADAPTER_INFO));
|
|
ulOutBufLen = sizeof(IP_ADAPTER_INFO);
|
|
|
|
// 第一次调用GetAdapterInfo获取ulOutBufLen大小
|
|
if (::GetAdaptersInfo( pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW)
|
|
{
|
|
free(pAdapterInfo);
|
|
pAdapterInfo = (IP_ADAPTER_INFO *) malloc (ulOutBufLen);
|
|
}
|
|
|
|
CString sText;
|
|
if ((dwRetVal = ::GetAdaptersInfo( pAdapterInfo, &ulOutBufLen)) == NO_ERROR)
|
|
{
|
|
pAdapter = pAdapterInfo;
|
|
while (pAdapter)
|
|
{
|
|
sText = pAdapter->Description;
|
|
sText.MakeLower();
|
|
//acutPrintf(_T("\nName=%s"),sText);
|
|
if (sText.Find(_T("virtualbox")) == -1 &&
|
|
sText.Find(_T("vmware")) == -1)//不考虑虚拟机器
|
|
{
|
|
sText.Format(_T("%02x@%02x@%02x@%02x@%02x@%02x"),
|
|
pAdapter->Address[0],
|
|
pAdapter->Address[1],
|
|
pAdapter->Address[2],
|
|
pAdapter->Address[3],
|
|
pAdapter->Address[4],
|
|
pAdapter->Address[5]);
|
|
|
|
arMacs.AddTail(sText);
|
|
}
|
|
pAdapter = pAdapter->Next;
|
|
}
|
|
}
|
|
}
|
|
|
|
//禁止软件变为绿色版的!!!
|
|
int DbSetMacOrHasThis()
|
|
{
|
|
return 1395; //不限制
|
|
#ifdef BAL_REMOTE //集团版不检测绿色
|
|
return 1395;
|
|
#endif
|
|
|
|
#ifdef _DEBUG
|
|
return 1395;
|
|
#endif
|
|
|
|
TCHAR szfileName[MAX_PATH],szFullPath[MAX_PATH];
|
|
GetModuleFileName(_hdllInstance,szfileName,MAX_PATH);
|
|
|
|
TCHAR drive[_MAX_DRIVE] = _T(""),
|
|
dir[_MAX_DIR] = _T(""),
|
|
fname[_MAX_FNAME] = _T(""),
|
|
ext[_MAX_EXT] = _T("");
|
|
|
|
//e:\,program files\autodesk\,myarx,exe
|
|
_tsplitpath(szfileName, drive, dir, fname, ext);
|
|
_tcscpy(szFullPath, drive);
|
|
_tcscat(szFullPath, dir);
|
|
|
|
CString sFullPath = szFullPath;
|
|
sFullPath.TrimRight(_T('\\'));
|
|
|
|
//上一级目录
|
|
int nPos = sFullPath.ReverseFind(_T('\\'));
|
|
CString sPath = sFullPath.Mid(0,nPos + 1);
|
|
|
|
sFullPath = sPath + _T("sys\\");
|
|
sFullPath += g_pszMacDbFileName;
|
|
|
|
::CoInitialize(NULL);
|
|
CUIISQLiteServer sqldb;
|
|
if (!sqldb.InitADOServer(sFullPath))
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
CStringList listMac;
|
|
GetMacAdr(listMac);
|
|
|
|
CString sSQL,sMac,sText;
|
|
sSQL = _T("select cptpos from aec_position");
|
|
|
|
CStringArray arVals;
|
|
sqldb.GetSelData(sSQL,arVals);
|
|
|
|
if (arVals.IsEmpty())
|
|
{
|
|
for (POSITION ps = listMac.GetHeadPosition();ps != NULL;)
|
|
{
|
|
sMac = listMac.GetNext(ps);
|
|
sSQL.Format(_T("insert into aec_position (cptpos) values ('%s')"),sMac);
|
|
if ( !sqldb.ExecuteSQL(sSQL) )
|
|
{
|
|
return -19;
|
|
}
|
|
}
|
|
return 1395;
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0;i < arVals.GetSize();i++)
|
|
{
|
|
sText = arVals.GetAt(i);
|
|
if ( listMac.Find(sText) != NULL)
|
|
{
|
|
return 2396;
|
|
}
|
|
}
|
|
}
|
|
return 19;
|
|
}
|
|
|
|
static bool g_bHasDog = true;
|
|
extern "C" AcRx::AppRetCode
|
|
acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt)
|
|
{
|
|
switch (msg)
|
|
{
|
|
case AcRx::kLoadDwgMsg:
|
|
{
|
|
// 保证每次打开文档的时候,命令行会打开
|
|
if (::IsWindow(g_wndMenuBar.m_hWnd) && !g_wndMenuBar.IsVisible())
|
|
g_wndMenuBar.m_pDockSite->ShowControlBar(&g_wndMenuBar, TRUE, FALSE);
|
|
}
|
|
case AcRx::kInitAppMsg:
|
|
{
|
|
acrxDynamicLinker->unlockApplication(pkt);
|
|
acrxDynamicLinker->registerAppMDIAware(pkt);
|
|
|
|
int nDbSetMacOrHasThis = DbSetMacOrHasThis();
|
|
|
|
//if (!g_lockChk.CheckLock())
|
|
if (false)
|
|
{
|
|
CTime tStop(2020,5,1,2,2,2);
|
|
ReadLicenseTime(tStop);
|
|
|
|
CTime tCur = CTime::GetCurrentTime();
|
|
if (tCur < tStop)
|
|
{
|
|
if (nDbSetMacOrHasThis > 1394)
|
|
{
|
|
InitApplication();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
CString sTip;
|
|
sTip.LoadString(IDS_LOCK_CHKERROR);
|
|
acedAlert(sTip);
|
|
g_bHasDog = false;
|
|
return AcRx::kRetError;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (nDbSetMacOrHasThis > 1394)
|
|
{
|
|
InitApplication();
|
|
}
|
|
else
|
|
{
|
|
AfxMessageBox(_T("检查授权失败!"));
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
case AcRx::kUnloadAppMsg:
|
|
{
|
|
g_lockChk.SendLogoutMessage();
|
|
if (g_bHasDog)
|
|
UnloadApplication();
|
|
else
|
|
return AcRx::kRetError;
|
|
}
|
|
break;
|
|
}
|
|
return AcRx::kRetOK;
|
|
}
|
|
|
|
void OnMain()
|
|
{
|
|
|
|
// 在这里检查一下 "GP" 命令有没有注册,如果没有,退出
|
|
AcEdCommandStruc st;
|
|
Adesk::Boolean hasGP = acedCmdLookup(_T("GP"), Adesk::kFalse, &st);
|
|
if (!hasGP)
|
|
return;
|
|
|
|
if (::IsWindow(g_wndMenuBar.m_hWnd))
|
|
{
|
|
if (!g_wndMenuBar.IsVisible())
|
|
g_wndMenuBar.m_pDockSite->ShowControlBar(&g_wndMenuBar, TRUE, FALSE);
|
|
CString ss;
|
|
g_wndMenuBar.GetWindowText(ss);
|
|
}
|
|
else
|
|
{
|
|
std::map<CString, CString> mm;
|
|
IniTools::getSectionContent(FilePath::GetSysDir() + _T("\\product.ini")
|
|
, _T("Product")
|
|
, mm);
|
|
CString sNameOfPalette = _T("上华软件");
|
|
if (mm.find(_T("CName")) != mm.end() && mm.find(_T("Version")) != mm.end())
|
|
{
|
|
sNameOfPalette = mm[_T("CName")] + _T(" ") + mm[_T("Version")];
|
|
}
|
|
#ifdef NEWUI
|
|
g_wndMenuBar.CreatePaletteSet(sNameOfPalette);
|
|
#else
|
|
g_wndMenuBar.CreateMenuBar(sNameOfPalette);
|
|
g_wndMenuBar.SetName(sNameOfPalette);
|
|
#endif
|
|
|
|
if (::IsWindow(g_wndMenuBar.m_hWnd))
|
|
{
|
|
g_wndMenuBar.m_pDockSite->ShowControlBar(&g_wndMenuBar, TRUE, FALSE);
|
|
g_wndMenuBar.RestoreControlBar(AFX_IDW_DOCKBAR_RIGHT);
|
|
}
|
|
}
|
|
}
|
|
|
|
void OnMenu()
|
|
{
|
|
CString sys(FilePath::GetSysDir()), strIni(_T("")), strCuix(_T(""));
|
|
strIni = sys + _T("\\product.ini");
|
|
CString product(_T(""));
|
|
if (_taccess(strIni, 0x0) == 0x0)
|
|
{
|
|
TCHAR buf[MAX_PATH + 1] = { 0, };
|
|
::GetPrivateProfileString(_T("Product"), _T("ProfilesName"), _T(""), buf, MAX_PATH, strIni);
|
|
product = buf;
|
|
}
|
|
|
|
if (product.Find(_T("PP3D")) != -1 || product.Find(_T("ENVI")) != -1)
|
|
{
|
|
#ifndef ZWCAD
|
|
strCuix = sys + _T("\\shs-ew.cuix");
|
|
if (!acedIsMenuGroupLoaded(_T("shs-ew")))
|
|
SHads_command(RTSTR, _T(".MENULOAD"), RTSTR, strCuix, RTNONE);
|
|
else
|
|
SHads_command(RTSTR, _T(".MENUUNLOAD"), RTSTR, _T("shs-ew"), RTNONE);
|
|
#else
|
|
strCuix = sys + _T("\\shs-zw.cuix");
|
|
if (!acedIsMenuGroupLoaded(_T("shs-zw")))
|
|
SHads_command(RTSTR, _T(".MENULOAD"), RTSTR, strCuix, RTNONE);
|
|
else
|
|
SHads_command(RTSTR, _T(".MENUUNLOAD"), RTSTR, _T("shs-zw"), RTNONE);
|
|
#endif
|
|
}
|
|
}
|
|
|
|
void CMDSearch()
|
|
{
|
|
CAcModuleResourceOverride myResources;
|
|
if (!::IsWindow(g_CmdQueryDlg::instance().m_hWnd))
|
|
{
|
|
g_CmdQueryDlg::instance().Create(CmdQueryDlg::IDD, acedGetAcadFrame());
|
|
g_CmdQueryDlg::instance().CenterWindow();
|
|
}
|
|
|
|
if (!g_CmdQueryDlg::instance().IsWindowVisible())
|
|
g_CmdQueryDlg::instance().ShowWindow(SW_SHOW);
|
|
|
|
g_CmdQueryDlg::instance().initShow();
|
|
}
|
|
|
|
void KJJ()
|
|
{
|
|
CShortcutKeyMappingDlg::start();
|
|
}
|
|
|
|
// commands, reactors...
|
|
void InitApplication()
|
|
{
|
|
CoreTools::AddCommand(_T("DHMENU"), _T("GP"), _T("GP"), ACRX_CMD_TRANSPARENT | ACRX_CMD_USEPICKSET, OnMain);
|
|
CoreTools::AddCommand(_T("DHMENU"), _T("GPM"), _T("GPM"), ACRX_CMD_TRANSPARENT | ACRX_CMD_USEPICKSET, OnMenu);
|
|
CoreTools::AddCommand(_T("DHMENU"), _T("CMDS"), _T("CMDS"), ACRX_CMD_TRANSPARENT | ACRX_CMD_USEPICKSET, CMDSearch);
|
|
CoreTools::AddCommand(_T("DHMENU"), _T("CO_KJJ"), _T("CO_KJJ"), ACRX_CMD_TRANSPARENT | ACRX_CMD_USEPICKSET, KJJ);
|
|
OnMain();
|
|
::SetTimer(acedGetAcadFrame()->GetSafeHwnd(), TIMER_CUIX, 3000, TimerProc);
|
|
}
|
|
|
|
void UnloadApplication()
|
|
{
|
|
acedRegCmds->removeGroup(_T("DHMENU"));
|
|
}
|
|
|