// spDoc.cpp : implementation of the CSpDoc class // #include "stdafx.h" #include "sp.h" #include "spDoc.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define _CRTDBG_MAP_ALLOC #include #include ///////////////////////////////////////////////////////////////////////////// // CSpDoc IMPLEMENT_DYNCREATE(CSpDoc, CDocument) BEGIN_MESSAGE_MAP(CSpDoc, CDocument) //{{AFX_MSG_MAP(CSpDoc) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CSpDoc construction/destruction CSpDoc::CSpDoc() { // TODO: add one-time construction code here m_pApp= (CSpApp*)AfxGetApp(); } CSpDoc::~CSpDoc() { } BOOL CSpDoc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; // TODO: add reinitialization code here // (SDI documents will reuse this document) return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CSpDoc serialization void CSpDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // TODO: add storing code here } else { // TODO: add loading code here } } ///////////////////////////////////////////////////////////////////////////// // CSpDoc diagnostics #ifdef _DEBUG void CSpDoc::AssertValid() const { CDocument::AssertValid(); } void CSpDoc::Dump(CDumpContext& dc) const { CDocument::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CSpDoc commands bool CSpDoc::LocateData() { //and set connection string //FUTURE: USE INI FILE INSTEAD TO LOCATE DATA CString StartIn,temp; CFileStatus cfs; CFile::GetStatus("scdata.sc",cfs); StartIn.Format("%s",cfs.m_szFullName); if( StartIn.IsEmpty()) { AfxMessageBox("Cannot locate data file scdata.sc\r\nHave you set your StartIn Icon property correctly?"); return false; } else { StartIn=StartIn.Left(StartIn.GetLength()-10);//ADDRESS.GZ0 trim 11 characters leave path m_DBPath=StartIn; m_ConnectString.Format("%s%s%s;", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=", m_DBPath,"\\scdata.sc"); m_pApp->strConnectString=m_ConnectString; temp.Format("%s%s%s;","Provider=Microsoft.Jet.OLEDB.4.0;Data Source=", m_DBPath,"\\scdata.sc;Mode = Share Exclusive;"); m_pApp->strConnectStringExclusive=temp; //used by CSpApp::ReportDirectory() m_pApp->m_strDBPATH=m_DBPath+"\\"; } return true; } //**************************************************** // compact the database through a jro object //********************************************** bool CSpDoc::Compact(bool bKeepOld) { bool status=true; CString src,dest,tempfile; CFileStatus fstat; CWaitCursor wait; //delete old one if exists tempfile.Format("%s\\scdata.tmp",m_DBPath); if(CFile::GetStatus(tempfile,fstat)==TRUE)//file exists { TRY { CFile::Remove( tempfile ); } CATCH( CFileException, e ) { status=false; CString cstrErrMsg; cstrErrMsg.Format("Error in Compact: %s cannot be removed",tempfile); AfxMessageBox(cstrErrMsg); } END_CATCH } if(status==true) { src.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s\\scdata.sc;", m_DBPath); dest.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s\\scdata.tmp;", m_DBPath); _bstr_t bstsrc(src); _bstr_t bstdest(dest); try { IJetEnginePtr jet(__uuidof(JetEngine)); jet->CompactDatabase(bstsrc, bstdest); } catch(_com_error &e) { status=false; CString cstrErrMsg; //get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE( "*************************************************\n"); TRACE( "Exception thrown for classes generated by #import\n"); TRACE( "\tCode = %081x\n", e.Error); TRACE( "\tCode Meaning = %s\n",e.ErrorMessage()); TRACE( "\tSource = %s\n", (LPCTSTR) bstrSource); TRACE( "Description = %s\n", (LPCTSTR) bstrDescription); TRACE( "*************************************************\n"); cstrErrMsg.Format("Error in Compact: %s,\r\n%s",e.ErrorMessage(),(LPCTSTR) bstrDescription); AfxMessageBox(cstrErrMsg); } catch(...) { status=false; TRACE( "*** Unhandled exception ***" ); AfxMessageBox("Unhandled Error in Compact"); PostQuitMessage(-1);//exit now before anything worse happens } } //Added as indexing can leave a 100+mb old file //this way can delete it if(bKeepOld) { //copy mdb over old src.Format("%s\\scdata.sc",m_DBPath); dest.Format("%s\\scdata.old",m_DBPath); status=CopyFile(src.GetBuffer(100),dest.GetBuffer(100)); } if(status==true) { src.Format("%s\\scdata.tmp",m_DBPath); dest.Format("%s\\scdata.sc",m_DBPath); status=CopyFile(src.GetBuffer(100),dest.GetBuffer(100)); }//if status==true //delete gz1 tempfile.Format("%s\\scdata.tmp",m_DBPath); if(CFile::GetStatus(tempfile,fstat)==TRUE)//file exists { TRY { CFile::Remove( tempfile ); } CATCH( CFileException, e ) { status=false; CString cstrErrMsg; cstrErrMsg.Format("Error at end of Compact: %s cannot be removed\r\nOtherwise compact OK",tempfile); AfxMessageBox(cstrErrMsg); } END_CATCH } return status; } //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //******************************************* //copy a file, overwrite dest if exists bool CSpDoc::CopyFile(char *src, char *dest) { CFile sourceFile; CFile destFile; CFileException ex; CString tempfile; // open the source file for reading if (!sourceFile.Open(src, CFile::modeRead | CFile::shareDenyWrite, &ex)) { // complain if an error happened // no need to delete the ex object TCHAR szError[1024]; ex.GetErrorMessage(szError, 1024); CString errormsg; errormsg.Format("Error copying file %s to %s\r\n The error was: %s",src,dest,szError); AfxMessageBox(errormsg); return false; } else { if (!destFile.Open(dest, CFile::modeWrite | CFile::shareExclusive | CFile::modeCreate, &ex)) { TCHAR szError[1024]; ex.GetErrorMessage(szError, 1024); CString errormsg; errormsg.Format("Error copying file %s to %s\r\n The error was: %s",src,dest,szError); AfxMessageBox(errormsg); sourceFile.Close(); return false; } BYTE buffer[4096]; DWORD dwRead; // Read in 4096-byte blocks, // remember how many bytes were actually read, // and try to write that many out. This loop ends // when there are no more bytes to read. do { dwRead = sourceFile.Read(buffer, 4096); destFile.Write(buffer, dwRead); } while (dwRead > 0); // Close both files destFile.Close(); sourceFile.Close(); } return true; } void CSpDoc::Validate() { //registration key:companyhash,UINTfeatures,licensecount,EVALLIMIT CString key=m_pApp->m_strRegKey; CString comp=m_pApp->m_strRegCompany; CString kCompHash; CString temp; int firstcomma,secondcomma,thirdcomma; GZK cryp; cryp.GZHash(&comp); cryp.GZDecrypt(&key,false); firstcomma=key.Find(',',0); secondcomma=key.Find(',',firstcomma+1); thirdcomma=key.Find(',',secondcomma+1); if(firstcomma==-1 || secondcomma==-1 || thirdcomma==-1) { m_pApp->m_strRegKey.Empty(); m_pApp->m_strRegCompany.Empty(); return; } kCompHash=key.Left(firstcomma); if(kCompHash!=comp) { m_pApp->m_strRegKey.Empty(); m_pApp->m_strRegCompany.Empty(); return; } temp=key.Mid(firstcomma+1,(secondcomma-firstcomma)-1); m_pApp->m_uiFeatures=(UINT)_atoi64(temp); temp=key.Mid(secondcomma+1,(thirdcomma-secondcomma)-1); m_pApp->m_lRegLicCount=atol(temp); //expiry date? temp=key.Right(key.GetLength()-thirdcomma-1); if(temp==cryp.InLineDecrypt("Md2gXbFO5Vu4MqQpfyEWdw"/*15 eval key*/) || temp==cryp.InLineDecrypt("hm0s/6NFOzjXMUUd/HaGEA") /*69 licensed key*/ || temp==cryp.InLineDecrypt("o2jDhqik1/EKD7zT1MBbJQ") /*5 eval key*/) return;//All is ok, no need to check date //m_pApp->m_strRegEvalLimit=key.Right(key.GetLength()-thirdcomma-1); //If we are here, then this key has an expiry date, check if expired and announce time left? COleDateTime dtData; COleDateTime dtNow=COleDateTime::GetCurrentTime(); COleDateTimeSpan dtSpan; dtData.ParseDateTime(temp); CString m_strExpiryDays; CString strTemp; temp.Empty();//don't leave it floating around in memory if(dtData.GetStatus()!=0)//couldn't parse the date and time { m_pApp->m_strRegKey.Empty(); m_pApp->m_strRegCompany.Empty(); return; } else { //a valid expiry date was parsed, see if we've passed it //a better check would be to see the date of the last wo entry or something so that //setting the clock back wouldn't get around it dtSpan=dtData-dtNow; /*int nDays=dtSpan.GetTotalDays(); int nHours=dtSpan.GetTotalHours(); int nMinutes=dtSpan.GetTotalMinutes(); int nSeconds=dtSpan.GetTotalSeconds();*/ //note, checks total minutes, instead of DAYS because it would expire too soon otherwise. if(dtSpan.GetTotalMinutes()>atoi(cryp.InLineDecrypt("Z2OFaf5Y/3QAPzJuAxkGxw")))//"0" { //Not expired, build display string //set up an html text variable with days left m_strExpiryDays=cryp.InLineDecrypt( "xxr2uBTQMwSvJaQAPs5FpCJXhwHqYSsCX6VpQ3A8/0Z0mbTvyI7ekUGPbggnbGN+KYlf744E" "EkD0xn6BTtengPH2cGfWfpcnFlKvjHYsky05ZpqstyxpfuBo9kQ1SJloan6A6qp7VIfHaguT" "kTnt6PhzynEdggIgVMFE5IrAup1Pn//RCXhnzh1gcQxvR216KSvZa+AZMiSbMCmK0T+dexZk" "/4+Iy2JeRM9KNJJkKi/x2xwjD0jPbhyqa3JIr7FibUjzAGLCAMU3m1jICQeT8EG88IfkJo47" "2K+hZhXQQwvCMhtBuMctNZi+dcVS/M2B"/* Warning: As per the terms of purchase order acceptance, AyaNova is licensed temporarily until payment is received. This license key will expire in X1 days X2 hours X3 minutes. There will be no extensions or exceptions. */); strTemp.Format("%i",(int)dtSpan.GetDays()); m_strExpiryDays.Replace("X1",strTemp); strTemp.Format("%i",(int)dtSpan.GetHours()); m_strExpiryDays.Replace("X2",strTemp); strTemp.Format("%i",(int)dtSpan.GetMinutes()); m_strExpiryDays.Replace("X3",strTemp); AfxMessageBox(m_strExpiryDays,MB_SYSTEMMODAL|MB_ICONINFORMATION ); } else { //EXPIRED trash key and tell them. AfxMessageBox(cryp.InLineDecrypt("RCfDvTWdAiEnbCrfjtC0YKtRAiRHBSpo+ZvaToaFhEhwen69J2yE8Sr4pB8VRsm9GdLzz/T/" "ZzSq1tpfMi7QTPE8G++jFd/2vN9ivQU0TbPK36cR39u+//vyrvhdy5sWtpWLw0TawhwfIVfu" "Xkp5T73R4bNuvTZ7Hn30dDEX4oMe7QGLsaZEIx+PwjDfLjh25y5DUUSwqpnN9YUsdp+/FDLB" "D3V4UC2gu/zHrA0vaxabA42sa1j6uhk21aJwaLj4dW6SYf1B+IKWe+D4XQUPKNeBQRfDYI3o" "qsBBuJconLBBwIwY8MlYf47C9R5DdJySZyPWdaupnOErny4AEVkc8XakMydcH7wX8PovhiGE" "ibfLCD9kGwBVc7LDFh3Ryn4iYg3cGixpu0Csz/3rJexZcuWVLD5X1VmGfQxD2zhB1De/NFLu" "Dc8jweQ5Vpon64Tiq8BtG9dGIrWmCDqbgNi6BA==")); m_pApp->m_strRegKey.Empty(); m_pApp->m_strRegCompany.Empty(); return; } } }