12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907 |
- #include "stdafx.h"
- #include "UpgradeRunFSM.h"
- #include "mod_UpgradeRun.h"
- #include "iniutil.h"
- #include "memutil.h"
- #include "fileutil.h"
- #include <vector>
- #include "EventCode.h"
- #include<algorithm>
- #ifdef RVC_OS_WIN
- #include <shellapi.h>
- #include <io.h>
- #include "XUnzip.h"
- #else
- #include <errno.h>
- #include <sys/utsname.h>
- #include "XUnZipZilb.h"
- #endif // RVC_OS_WIN
- CUpgradeRunFSM::CUpgradeRunFSM(void)
- {
- //解决sonar扫描问题
- }
- CUpgradeRunFSM::~CUpgradeRunFSM(void)
- {
- //解决sonar扫描问题
- }
- ErrorCodeEnum CUpgradeRunFSM::OnInit()
- {
- AddStateHooker(this);
- //m_nIntallPackType = 1;
- //m_strInstallPack = "update-1.0.0.zip";
- m_chInstallState = 'N';
- return Error_Succeed;
- }
- ErrorCodeEnum CUpgradeRunFSM::OnExit()
- {
- RemoveStateHooker(this);
- return Error_Succeed;
- }
- ErrorCodeEnum CUpgradeRunFSM::GetRunState(CSimpleStringA &strPackName, char &cState)
- {
- if (!m_strInstallPack.IsNullOrEmpty())
- {
- strPackName = m_strInstallPack;
- if (m_iState == s1)
- cState = 'P';
- else
- cState = 'I';
- }
- return Error_Succeed;
- }
- void CUpgradeRunFSM::OnStateTrans(int iSrcState, int iDstState)
- {
- Dbg("CUpgradeRunFSM state change from %s to %s", GetStateName(iSrcState), GetStateName(iDstState));
- }
- void CUpgradeRunFSM::s1_on_entry()
- {
- //解决sonar扫描问题
- }
- void CUpgradeRunFSM::s1_on_exit()
- {
- //解决sonar扫描问题
- }
- unsigned int CUpgradeRunFSM::s1_on_event(FSMEvent* event)
- {
- if (event->iEvt == Event_EnableUpgrade)
- {
- if (!m_strInstallPack.IsNullOrEmpty())
- {
- LOG_TRACE("continue upgrade pack: [%s]", (const char*)m_strInstallPack);
- return 1;
- }
- }
- else if (event->iEvt == Event_StartUpgrade)
- {
- StartUpgradeEvent *pEvent = (StartUpgradeEvent*)event;
-
- if (!m_strInstallPack.IsNullOrEmpty())
- {
- LogError(Severity_Low, Error_Unexpect, 0, CSimpleStringA::Format("pack [%s] is installing now, refuse upgrade pack [%s]",
- (const char*)m_strInstallPack, (const char*)pEvent->strPackName));
- }
- else
- {
- LOG_TRACE("upgrade disable now, install pack [%s] later", (const char*)pEvent->strPackName);
- m_strInstallPack = pEvent->strPackName;
- m_nIntallPackType = pEvent->nPackType;
- m_chInstallState = 'N';
- }
- }
- return 0;
- }
- void CUpgradeRunFSM::s2_on_entry()
- {
- m_strInstallPack.Clear();
- m_nIntallPackType = 1;
- m_chInstallState = 'N';
- }
- void CUpgradeRunFSM::s2_on_exit()
- {
- //解决sonar扫描问题
- }
- unsigned int CUpgradeRunFSM::s2_on_event(FSMEvent* event)
- {
- if (event->iEvt == Event_DisableUpgrade)
- {
- LOG_TRACE("pause upgrade now");
- }
- else if (event->iEvt == Event_StartUpgrade)
- {
- StartUpgradeEvent *pEvent = (StartUpgradeEvent*)event;
- assert(m_strInstallPack.IsNullOrEmpty());
- m_strInstallPack = pEvent->strPackName;
- m_nIntallPackType = pEvent->nPackType;
- m_chInstallState = 'N';
- LOG_TRACE("start upgrade pack: [%s], type[%d]", (const char*)pEvent->strPackName, pEvent->nPackType);
- }
- return 0;
- }
- namespace Task
- {
- struct UnzipTask : public ITaskSp
- {
- CUpgradeRunFSM* fsm;
- explicit UnzipTask(CUpgradeRunFSM* f) : fsm(f) {}
- void Process()
- {
- auto pEntity = fsm->GetEntityBase();
- //兼容zip和cab格式安装包
- if (fsm->m_strInstallPack.IsEndWith(".cab"))
- {
- //校验安装包签名
- auto rc = fsm->CheckInstallPackSign();
- if (rc == Error_Succeed)
- {
- LOG_TRACE("check pack [%s] sign succeed", (const char*)fsm->m_strInstallPack);
- }
- else
- {
- UpgradeRun::UpgradeDoneEvent e = {};
- e.strPackName = fsm->m_strInstallPack;
- e.error = rc;
- e.strComment = "升级包签名校验失败";
- ((CUpgradeRunEntity*)pEntity)->BroadcastUpgradeDoneEvent(e);
- LogError(Severity_Low, rc, ERROR_UPGRADERUN_CABSIGN_FAIL, CSimpleStringA::Format("升级包[%s]签名校验失败", (const char*)fsm->m_strInstallPack));
- fsm->PostEventFIFO(new FSMEvent(CUpgradeRunFSM::Event_EndUpgrade));
- return;
- }
- rc = fsm->UncabPack();
- if (rc == Error_Succeed)
- {
- fsm->m_chInstallState = 'Z';
- LOG_TRACE("unzip pack [%s] succeed", (const char*)fsm->m_strInstallPack);
- if (fsm->IsManual() && (1 == fsm->m_nIntallPackType))
- {
- UpgradeRun::UpgradeDoneEvent e = {};
- e.strPackName = fsm->m_strInstallPack;
- e.error = rc;
- e.bSysInstall = true;
- e.strComment = "手动升级";
- ((CUpgradeRunEntity*)pEntity)->BroadcastUpgradeDoneEvent(e);
- fsm->PostEventFIFO(new FSMEvent(CUpgradeRunFSM::Event_EndUpgrade));
- return;
- }
- }
- else
- {
- fsm->DeleteInstallingPack();//删除解压失败的安装包,下次升级重新下载
- UpgradeRun::UpgradeDoneEvent e = {};
- e.strPackName = fsm->m_strInstallPack;
- e.error = rc;
- e.strComment = "解压失败";
- ((CUpgradeRunEntity*)pEntity)->BroadcastUpgradeDoneEvent(e);
- LogError(Severity_Low, rc, ERROR_UPGRADERUN_CAB_UNZIP_FAIL, CSimpleStringA::Format("uncab pack [%s] fail", (const char*)fsm->m_strInstallPack));
- fsm->PostEventFIFO(new FSMEvent(CUpgradeRunFSM::Event_EndUpgrade));
- return;
- }
- }
- else if (fsm->m_strInstallPack.IsEndWith(".zip"))
- {
- auto rc = fsm->UnzipPack();
- //auto rc = fsm->NewUnzipPack();
- if (rc == Error_Succeed)
- {
- fsm->m_chInstallState = 'Z';
- LOG_TRACE("unzip pack [%s] succeed", (const char*)fsm->m_strInstallPack);
- //若果是手动升级,且是第一次执行,直接返回
- if (fsm->IsManual() && (1==fsm->m_nIntallPackType))
- {
- UpgradeRun::UpgradeDoneEvent e = {};
- e.strPackName = fsm->m_strInstallPack;
- e.error = rc;
- e.bSysInstall = true;
- e.strComment = "手动升级";
- ((CUpgradeRunEntity*)pEntity)->BroadcastUpgradeDoneEvent(e);
- fsm->PostEventFIFO(new FSMEvent(CUpgradeRunFSM::Event_EndUpgrade));
- return;
- }
- }
- else
- {
- fsm->DeleteInstallingPack();//删除解压失败的安装包,下次升级重新下载
- UpgradeRun::UpgradeDoneEvent e = {};
- e.strPackName = fsm->m_strInstallPack;
- e.error = rc;
- e.strComment = "解压失败";
- ((CUpgradeRunEntity*)pEntity)->BroadcastUpgradeDoneEvent(e);
- LogError(Severity_Low, rc, ERROR_UPGRADERUN_ZIP_UNZIP_FAIL, CSimpleStringA::Format("unzip pack [%s] fail", (const char*)fsm->m_strInstallPack));
- fsm->PostEventFIFO(new FSMEvent(CUpgradeRunFSM::Event_EndUpgrade));
- return;
- }
- }
- else
- {
- LogError(Severity_Low, Error_Unexpect, 0, CSimpleStringA::Format("unkown pack format, [%s]", (const char*)fsm->m_strInstallPack));
- fsm->PostEventFIFO(new FSMEvent(CUpgradeRunFSM::Event_EndUpgrade));
- return;
- }
- fsm->ScheduleTimer(1, 3000);
- }
- };
- struct InstallPackTask : ITaskSp
- {
- explicit InstallPackTask(CUpgradeRunFSM *pFSM)
- : m_pFSM(pFSM) {}
- CUpgradeRunFSM *m_pFSM;
- virtual void Process()
- {
- auto pEntity = m_pFSM->GetEntityBase();
- bool bSysInstall = false;
- bool bLightPack = false;
- CSimpleStringA strNewVer;
- CSimpleStringA strErrMsg = "安装成功";
- auto rc = m_pFSM->InstallPack(bSysInstall, bLightPack, strNewVer, strErrMsg);
- // 系统外升级单独线程异步执行,返回成功不表示升级完成
- if (!bSysInstall || rc != Error_Succeed)
- {
- UpgradeRun::UpgradeDoneEvent e = {};
- e.strPackName = m_pFSM->m_strInstallPack;
- e.error = rc;
- e.bLightPack = bLightPack;
- e.bSysInstall = bSysInstall;
- e.strNewVersion = strNewVer;
- e.strComment = strErrMsg;
- if (rc == Error_Succeed)
- {
- Dbg("install pack [%s] succeed", (const char*)m_pFSM->m_strInstallPack);
- }
- else
- {
- LogError(Severity_Low, rc, ERROR_UPGRADERUN_INSTALL_PACK_FAIL, CSimpleStringA::Format("install pack [%s] fail", (const char*)m_pFSM->m_strInstallPack));
- if (!bLightPack && !bSysInstall)
- {
- Dbg("delete temp new version dir");
- CSimpleStringA strRootVerPath;
- pEntity->GetFunction()->GetPath("RootVer", strRootVerPath);
- CSimpleStringA strNewVerPath = CSimpleStringA::Format("%s\\%s", (const char*)strRootVerPath, (const char*)strNewVer);
- if (ExistsDirA(strNewVerPath))
- {
- RemoveDirRecursiveA(strNewVerPath);
- }
- }
- }
- // 删除临时解压目录
- m_pFSM->DeleteUnzipDir();
- m_pFSM->PostEventFIFO(new FSMEvent(CUpgradeRunFSM::Event_EndUpgrade));
- ((CUpgradeRunEntity*)pEntity)->BroadcastUpgradeDoneEvent(e);//modify by zl 20190905,全部处理完再发事件,否则会导致UpgradeRun和UpgradeMgr两个状态机不同步
- }
- }
- };
- }
- // 每次暂停之后当前步骤要重做一次
- void CUpgradeRunFSM::s3_on_entry()
- {
- // 检查安装包状态
- assert(!m_strInstallPack.IsNullOrEmpty());
- assert(m_chInstallState != 'I');
- if (m_chInstallState == 'N') // 新安装包
- {
- //另起线程解压,防止解压超时
- Task::UnzipTask* task = new Task::UnzipTask(this);
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- }
- void CUpgradeRunFSM::s3_on_exit()
- {
- //解决sonar扫描问题
- }
- unsigned int CUpgradeRunFSM::s3_on_event(FSMEvent* event)
- {
- if (event->iEvt == Event_DisableUpgrade)
- {
- LOG_TRACE("pause upgrade pack: [%s]", (const char*)m_strInstallPack);
- }
- else if (event->iEvt == Event_StartUpgrade)
- {
- StartUpgradeEvent *pEvent = (StartUpgradeEvent*)event;
- LogError(Severity_Low, Error_Unexpect, 0, CSimpleStringA::Format("pack [%s] is installing now, refuse upgrade pack [%s]",
- (const char*)m_strInstallPack, (const char*)pEvent->strPackName));
- return 1;
- }
- else if (event->iEvt == Event_EndUpgrade)
- {
- m_strInstallPack.Clear();
- m_chInstallState = 'N';
- }
- else if (event->iEvt == EVT_TIMER)
- {
- if (m_chInstallState == 'Z') // 已解压
- {
- // 检查安装配置文件
- CAutoArray<CSimpleStringA> coverlist;
- CSimpleStringA strErrMsg = "检查通过";
- auto rc = CheckInstallConfig(coverlist, strErrMsg);
- // 广播检查结果
- UpgradeCheckEvent e = {};
- e.error = rc;
- e.coverList = coverlist;
- e.strPackName = m_strInstallPack;
- e.strComment = strErrMsg;
- ((CUpgradeRunEntity*)m_pEntity)->BroadcastUpgradeCheckEvent(e);
- if (rc == Error_Succeed)
- {
- LOG_TRACE("pack [%s] install check passed", (const char*)m_strInstallPack);
- m_chInstallState = 'C';
- }
- else
- {
- LogError(Severity_Low, rc, ERROR_UPGRADERUN_INSTALL_CHECK_FAIL, CSimpleStringA::Format("pack [%s] install check not pass", (const char*)m_strInstallPack));
- // 删除临时解压目录
- DeleteUnzipDir();
- PostEventFIFO(new FSMEvent(Event_EndUpgrade));
- return 1;
- }
- }
- if (m_chInstallState == 'C') // 已检查
- {
- //另起线程安装,防止安装超时
- Task::InstallPackTask* task = new Task::InstallPackTask(this);
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- m_chInstallState = 'I';
- //bool bSysInstall = false;
- //bool bLightPack = false;
- //CSimpleStringA strNewVer;
- //CSimpleStringA strErrMsg = "安装成功";
- //auto rc = InstallPack(bSysInstall, bLightPack, strNewVer, strErrMsg);
- //// 系统外升级单独线程异步执行,返回成功不表示升级完成
- //if (!bSysInstall || rc != Error_Succeed)
- //{
- // UpgradeRun::UpgradeDoneEvent e = {};
- // e.strPackName = m_strInstallPack;
- // e.error = rc;
- // e.bLightPack = bLightPack;
- // e.bSysInstall = bSysInstall;
- // e.strNewVersion = strNewVer;
- // e.strComment = strErrMsg;
- // ((CUpgradeRunEntity*)m_pEntity)->BroadcastUpgradeDoneEvent(e);
- // if (rc == Error_Succeed)
- // {
- // Dbg("install pack [%s] succeed", (const char*)m_strInstallPack);
- // }
- // else
- // {
- // LogError(Severity_Low, rc, 0, CSimpleStringA::Format("install pack [%s] fail", (const char*)m_strInstallPack));
- // if (!bLightPack && !bSysInstall)
- // {
- // Dbg("delete temp new version dir");
- // CSimpleStringA strRootVerPath;
- // m_pEntity->GetFunction()->GetPath("RootVer", strRootVerPath);
- // CSimpleStringA strNewVerPath = CSimpleStringA::Format("%s\\%s", (const char*)strRootVerPath, (const char*)strNewVer);
- // if (ExistsDirA(strNewVerPath))
- // {
- // RemoveDirRecursiveA(strNewVerPath);
- // }
- // }
- // }
- // // 删除临时解压目录
- // DeleteUnzipDir();
- // PostEventFIFO(new FSMEvent(Event_EndUpgrade));
- // return 1;
- //}
- }
- ScheduleTimer(1, 1000);
- }
- return 0;
- }
- ErrorCodeEnum CUpgradeRunFSM::DeleteUnzipDir()
- {
- assert(!m_strInstallPack.IsNullOrEmpty());
- CSimpleStringA strUnzipPath;
- auto rc = GetUnzipTempDir(strUnzipPath);
-
- // 如目标目录存在,则先删除
- if (rc == Error_Succeed && ExistsDirA(strUnzipPath))
- {
- RemoveDirRecursiveA(strUnzipPath);
- Dbg("remove unzip temp dir: [%s]", (const char*)strUnzipPath);
- }
- return rc;
- }
- ErrorCodeEnum CUpgradeRunFSM::CheckInstallPackSign()
- {
- assert(!m_strInstallPack.IsNullOrEmpty());
- int nVerifyCodeSign = 0;
- CSmartPointer<IEntityFunction> spFunction = m_pEntity->GetFunction();
- CSmartPointer<IConfigInfo> spConfig;
- ErrorCodeEnum Error = spFunction->OpenConfig(Config_CenterSetting, spConfig);
- if (Error_Succeed == Error)
- {
- Error = spConfig->ReadConfigValueInt("SpBase", "VerifyCodeSign", nVerifyCodeSign);
- if (Error_Succeed == Error)
- {
- Dbg("get VerifyCodeSign[%d] from CenterSetting.ini", nVerifyCodeSign);
- }
- else
- {
- Dbg("get VerifyCodeSign from CenterSetting.ini failed");
- }
- }
- if (nVerifyCodeSign == 0)
- {
- Dbg("VerifyCodeSign flag is 0 or not exsit,ignore code signature");
- return Error_Succeed;
- }
- CSimpleStringA strDownloadsPath;
- auto rc = m_pEntity->GetFunction()->GetPath("Downloads", strDownloadsPath);
- assert(rc == Error_Succeed);
- CSimpleStringA strCabFile = CSimpleStringA::Format("%s\\%s", (const char*)strDownloadsPath, (const char*)m_strInstallPack);
- //验证签名
- CSimpleStringA strErrMsg;
- rc = m_pEntity->GetFunction()->VerifySignature(strCabFile, strErrMsg);
- if (rc != Error_Succeed)
- {
- LogError(Severity_Low, Error_Unexpect, 0, CSimpleStringA::Format("[%s]签名校验失败", (const char*)strCabFile));
- return Error_Unexpect;
- }
- return Error_Succeed;
- }
- bool CUpgradeRunFSM::IsManual()
- {
- CSimpleStringA strConfigPath;
- auto rc = GetInstallConfigPath(strConfigPath);
- assert(rc == Error_Succeed);
- // 检查文件是否存在
- #ifdef RVC_OS_WIN
- DWORD attr = GetFileAttributesA(strConfigPath);
- Dbg("check install config: %s, attr[0x%08X]", (const char*)strConfigPath, attr);
- if (attr == INVALID_FILE_ATTRIBUTES || (attr & FILE_ATTRIBUTE_DIRECTORY))
- {
- LogError(Severity_Low, Error_Unexpect, 0, CSimpleStringA::Format("install config [%s] not exists",
- (const char*)strConfigPath));
- return false;
- }
- #else
- if (!ExistsFileA(strConfigPath))
- {
- LogError(Severity_Low, Error_Unexpect, 0, CSimpleStringA::Format("install config [%s] not exists",
- (const char*)strConfigPath));
- return false;
- }
- #endif // RVC_OS_WIN
-
- // InstallType=manual
- char *p = inifile_read_str(strConfigPath, "Precondition", "InstallType", "");
- CSimpleStringA strInstallType = p;
- toolkit_free(p);
- if (!strInstallType.IsNullOrEmpty())
- {
- return (strInstallType.Compare("manual",true)==0)?true:false;
- }
- return false;
- }
- ErrorCodeEnum CUpgradeRunFSM::NewUnzipPack()
- {
- //assert(!m_strInstallPack.IsNullOrEmpty());
- //// 设定解压临时目录
- //char szOldPath[MAX_PATH] = {};
- //GetCurrentDirectoryA(MAX_PATH, szOldPath);
- //CSimpleStringA strDownloadsPath;
- //auto rc = m_pEntity->GetFunction()->GetPath("Downloads", strDownloadsPath);
- //assert(rc == Error_Succeed);
- //CSimpleStringA strUnzipPath;
- //rc = GetUnzipTempDir(strUnzipPath);
- //assert(rc == Error_Succeed);
- //// 如目标目录存在,则先删除
- //if (ExistsDirA(strUnzipPath))
- //{
- // RemoveDirRecursiveA(strUnzipPath);
- //}
- //// 创建临时解压目录
- //CreateDirectoryA(strUnzipPath, NULL);
- //SetCurrentDirectoryA(strUnzipPath);
- //CSimpleStringA strZipFile = CSimpleStringA::Format("%s\\%s", (const char*)strDownloadsPath, (const char*)m_strInstallPack);
- ////将路径转为TCHAR类型
- //int iUnicode = MultiByteToWideChar(CP_ACP, 0, strZipFile.GetData(), strZipFile.GetLength(), NULL, 0);
- //WCHAR* pwUnicode = new WCHAR[iUnicode + 2];
- //if (pwUnicode)
- //{
- // ZeroMemory(pwUnicode, iUnicode + 2);
- //}
- //MultiByteToWideChar(CP_ACP, 0, strZipFile.GetData(), strZipFile.GetLength(), pwUnicode, iUnicode);
- //pwUnicode[iUnicode] = '\0';
- //pwUnicode[iUnicode+1] = '\0';
- ////解压文件
- ////SetCurrentDirectoryA(strdec.c_str());//将进程的工作目录移动到该参数所指的目录下,该目录为winrar.exe的默认文件路径
- ////解压文件会直接在项目的.vcproj目录下进行
- ////HZIP hz = OpenZip(pwUnicode,0);
- //HZIP hz = OpenZip("C:\\rvc\\Downloads\\a845816b53f24aff_test2019030601.zip",0);
- //ZIPENTRY ze;
- //auto zrc = GetZipItem(hz,-1,&ze);
- //assert(zrc == ZR_OK);
- //int numitems = ze.index;
- //for (int zi = 0; zi < numitems; zi++)
- //{
- // ZIPENTRY ze;
- // zrc = GetZipItem(hz, zi, &ze);
- // assert(zrc == ZR_OK);
- // zrc = UnzipItem(hz, zi,ze.name);
- // assert(zrc == ZR_OK);
- // Dbg("unzip [%s] item succeed", ze.name);
- //}
- //CloseZip(hz);
- //// 恢复当前目录
- //SetCurrentDirectoryA(szOldPath);
- return Error_Succeed;
- }
- ErrorCodeEnum CUpgradeRunFSM::UnzipPack()
- {
- #ifdef RVC_OS_WIN
- assert(!m_strInstallPack.IsNullOrEmpty());
- // 设定解压临时目录
- char szOldPath[MAX_PATH] = {};
- GetCurrentDirectoryA(MAX_PATH, szOldPath);
-
- CSimpleStringA strDownloadsPath;
- auto rc = m_pEntity->GetFunction()->GetPath("Downloads", strDownloadsPath);
- assert(rc == Error_Succeed);
- CSimpleStringA strUnzipPath;
- rc = GetUnzipTempDir(strUnzipPath);
- assert(rc == Error_Succeed);
-
- // 如目标目录存在,则先删除
- if (ExistsDirA(strUnzipPath))
- {
- RemoveDirRecursiveA(strUnzipPath);
- }
-
- // 创建临时解压目录
- CreateDirectoryA(strUnzipPath, NULL);
- SetCurrentDirectoryA(strUnzipPath);
- // 解压
- CSimpleStringA strZipFile = CSimpleStringA::Format("%s\\%s", (const char*)strDownloadsPath, (const char*)m_strInstallPack);
-
- DWORD attr = GetFileAttributesA(strZipFile);
- if (attr == INVALID_FILE_ATTRIBUTES)
- {
- LogError(Severity_Low, Error_NotExist, 0, CSimpleStringA::Format("pack [%s] not exists", (const char*)m_strInstallPack));
- return Error_NotExist;
- }
- HZIP hz = OpenZip((void*)(const char*)strZipFile,0,ZIP_FILENAME);
- if (hz == 0)
- {
- SetCurrentDirectoryA(szOldPath);
- LogError(Severity_Low, Error_Unexpect, 0, CSimpleStringA::Format("open zip file [%s] fail", (const char*)m_strInstallPack));
- return Error_Unexpect;
- }
- ZIPENTRY ze;
- auto zrc = GetZipItemA(hz,-1,&ze);
- assert(zrc == ZR_OK);
- int numitems=ze.index;
- for (int i=0; i<numitems; i++)
- {
- zrc = GetZipItemA(hz,i,&ze);
- assert(zrc == ZR_OK);
- UnzipItem(hz,i,ze.name,0,ZIP_FILENAME);
- assert(zrc == ZR_OK);
- Dbg("unzip [%s] item succeed", ze.name);
- }
- CloseZip(hz);
- // 恢复当前目录
- SetCurrentDirectoryA(szOldPath);
- return Error_Succeed;
- #else
- assert(!m_strInstallPack.IsNullOrEmpty());
- CSimpleStringA strDownloadsPath;
- auto rc = m_pEntity->GetFunction()->GetPath("Downloads", strDownloadsPath);
- assert(rc == Error_Succeed);
- CSimpleStringA strUnzipPath;
- rc = GetUnzipTempDir(strUnzipPath);
- assert(rc == Error_Succeed);
- // 如目标目录存在,则先删除
- if (ExistsDirA(strUnzipPath))
- {
- if (!RemoveDirRecursiveA(strUnzipPath)) {
- LogError(Severity_Low, Error_NotExist, 0, CSimpleStringA::Format("remove old unzip dir [%s] fail", strUnzipPath.GetData()));
- return Error_NotExist;
- }
- }
- // 创建临时解压目录
- CreateDirA(strUnzipPath.GetData(), false);
- // 解压
- CSimpleStringA strZipFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strDownloadsPath, (const char*)m_strInstallPack);
- string zipFileStr = strZipFile.GetData();
- string zipTempDir = strUnzipPath.GetData();
- if (!ExistsFileA(strZipFile.GetData()))
- {
- LogError(Severity_Low, Error_NotExist, 0, CSimpleStringA::Format("pack [%s] not exists", (const char*)m_strInstallPack));
- return Error_NotExist;
- }
- if (UnZipToDir(zipFileStr, zipTempDir)!=0)
- {
- LogError(Severity_Low, Error_Unexpect, 0, CSimpleStringA::Format("unzip pack [%s] fail", (const char*)m_strInstallPack));
- return Error_NotExist;
- }
- return Error_Succeed;
- #endif
-
- }
- ErrorCodeEnum CUpgradeRunFSM::UncabPack()
- {
- #ifdef RVC_OS_WIN
- assert(!m_strInstallPack.IsNullOrEmpty());
- // 设定解压临时目录
- char szOldPath[MAX_PATH] = {};
- GetCurrentDirectoryA(MAX_PATH, szOldPath);
- CSimpleStringA strDownloadsPath;
- auto rc = m_pEntity->GetFunction()->GetPath("Downloads", strDownloadsPath);
- assert(rc == Error_Succeed);
- CSimpleStringA strUnzipPath;
- rc = GetUnzipTempDir(strUnzipPath);
- assert(rc == Error_Succeed);
- // 如目标目录存在,则先删除
- if (ExistsDirA(strUnzipPath))
- {
- RemoveDirRecursiveA(strUnzipPath);
- }
- // 创建临时解压目录
- CreateDirectoryA(strUnzipPath, NULL);
- SetCurrentDirectoryA(strUnzipPath);
- // 解压
- CSimpleStringA strZipFile = CSimpleStringA::Format("%s\\%s", (const char*)strDownloadsPath, (const char*)m_strInstallPack);
- DWORD attr = GetFileAttributesA(strZipFile);
- if (attr == INVALID_FILE_ATTRIBUTES)
- {
- LogError(Severity_Low, Error_NotExist, 0, CSimpleStringA::Format("pack [%s] not exists", (const char*)m_strInstallPack));
- return Error_NotExist;
- }
- CSimpleStringA strCmd;
- CSimpleStringA strBinFath;
- rc = m_pEntity->GetFunction()->GetPath("Bin", strBinFath);
- assert(rc == Error_Succeed);
- //先进入目标目录"D:\cabarc.exe -p -r X a\ D:\a.cab *.* D:\a\"
- strCmd = CSimpleStringA::Format(("%s\\cabarc.exe -p -r X %s *.* %s\\"), (const char*)strBinFath, (const char*)strZipFile, (const char*)strUnzipPath);
- Dbg("解压cab命令:%s", strCmd);
- DWORD dwRet = SYSTEM_ON(strCmd, TRUE);
- if (0 != dwRet)
- {
- Dbg("%s解压cab失败", strZipFile);
- rc = Error_Unexpect;
- }
- else
- {
- Dbg("%s解压cab成功", strZipFile);
- }
- SetCurrentDirectoryA(szOldPath);
- return rc;
- #endif // RVC_OS_WIN
- return Error_Exception;
- }
- ErrorCodeEnum CUpgradeRunFSM::DeleteInstallingPack()
- {
- assert(!m_strInstallPack.IsNullOrEmpty());
- CSimpleStringA strDownloadsPath;
- auto rc = m_pEntity->GetFunction()->GetPath("Downloads", strDownloadsPath);
- assert(rc == Error_Succeed);
- CSimpleStringA strZipFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strDownloadsPath, (const char*)m_strInstallPack);
- #ifdef RVC_OS_WIN
- DWORD attr = GetFileAttributesA(strZipFile);
- if (attr == INVALID_FILE_ATTRIBUTES)
- {
- Dbg("pack [%s] not exists", strZipFile);
- return Error_Succeed;
- }
- if (DeleteFileA(strZipFile))
- {
- Dbg("delete %s success", strZipFile);
- }
- else
- {
- Dbg("delete %s failed", strZipFile);
- }
- #else
- if (!ExistsFileA(strZipFile.GetData()))
- {
- Dbg("pack [%s] not exists", strZipFile);
- return Error_Succeed;
- }
- if (RemoveFileA(strZipFile.GetData()))
- {
- Dbg("delete %s success", strZipFile.GetData());
- }
- else
- {
- Dbg("delete %s failed", strZipFile.GetData());
- }
-
- #endif // RVC_OS_WIN
- // 删除临时解压目录
- DeleteUnzipDir();
- return Error_Succeed;
- }
- DWORD CUpgradeRunFSM::waitSystem(const CSimpleStringA cmd, const CSimpleStringA par, BOOL nShow)
- {
- #ifdef RVC_OS_WIN
- SHELLEXECUTEINFOA ShExecInfo = { 0 };
- ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
- ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
- ShExecInfo.hwnd = NULL;
- ShExecInfo.lpVerb = NULL;
- ShExecInfo.lpFile = cmd; //调用的程序名
- ShExecInfo.lpParameters = par; //调用程序的命令行参数
- ShExecInfo.lpDirectory = NULL;
- ShExecInfo.nShow = nShow ? SW_SHOW : SW_HIDE; //窗口状态为隐藏
- ShExecInfo.hInstApp = NULL;
- if (!ShellExecuteEx(&ShExecInfo))
- {
- Dbg("ShellExecuteEx failed %d", GetLastError());
- return GetLastError();
- }
- //等到该进程结束,如果120s没解压结束,强行杀死进程
- if (WaitForSingleObject(ShExecInfo.hProcess, 120000) == WAIT_TIMEOUT)
- {
- if (!TerminateProcess(ShExecInfo.hProcess, 0))
- {
- return GetLastError();
- }
- return -1;
- }
- DWORD exitCode = 0;
- if (!GetExitCodeProcess(ShExecInfo.hProcess, &exitCode))
- {
- return GetLastError();
- }
- //Sleep(100);
- return exitCode;
- #endif // RVC_OS_WIN
- return -1;
- }
- DWORD CUpgradeRunFSM::SYSTEM_ON(CSimpleStringA cmdLine, BOOL isWait)
- {
- UINT result = 0;
- CSimpleStringA strCmd, strPar;
- strPar = CSimpleStringA::Format(("/c %s >cmd.log 2>&1"), cmdLine);
- strCmd = CSimpleStringA::Format(("cmd %s >cmd.log 2>&1"), strPar);
- //result = WinExec(strCmd.GetData(), SW_HIDE);
- return waitSystem("cmd.exe", strPar, FALSE);
- //return result > 31 ? ERROR_SUCCESS : result + 31;
- //return result > 31 ? TRUE : FALSE;
- // //char tempCmd[2048];
- // //CStringToMultiByte(strCmd, tempCmd, strCmd.GetLength() + 1);
- //#ifdef DEBUG
- // //result = system(cmdLine);
- // //return result;
- // return waitSystem(_T("cmd.exe"), strPar, FALSE);
- //#else
- // if (isWait)
- // {
- // return waitSystem(("cmd.exe"), strPar, FALSE);
- // }
- // else
- // {
- // result = WinExec(strCmd.GetData(), SW_HIDE);
- // //return result > 31 ? ERROR_SUCCESS : result + 31;
- // return result > 31 ? ERROR_SUCCESS : result;
- // }
- //#endif
- }
- ErrorCodeEnum CUpgradeRunFSM::GetUnzipTempDir(CSimpleStringA &strUnzipDir)
- {
- CSimpleStringA strDownloadsPath;
- auto rc = m_pEntity->GetFunction()->GetPath("Downloads", strDownloadsPath);
- assert(rc == Error_Succeed);
- strUnzipDir = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strDownloadsPath, (const char*)m_strInstallPack);
- if (strUnzipDir.IsEndWith(".zip") || strUnzipDir.IsEndWith(".cab"))
- strUnzipDir = strUnzipDir.SubString(0, strUnzipDir.GetLength()-4);
- return Error_Succeed;
- }
- ErrorCodeEnum CUpgradeRunFSM::GetInstallConfigPath(CSimpleStringA &strConfigPath)
- {
- CSimpleStringA strUnzipPath;
- auto rc = GetUnzipTempDir(strUnzipPath);
- assert(rc == Error_Succeed);
- strConfigPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "Run.ini", (const char*)strUnzipPath);
- return Error_Succeed;
- }
- ErrorCodeEnum CUpgradeRunFSM::CheckInstallConfig(CAutoArray<CSimpleStringA> &coverlist, CSimpleStringA &strErrMsg)
- {
- CSimpleStringA strConfigPath;
- auto rc = GetInstallConfigPath(strConfigPath);
- assert(rc == Error_Succeed);
- // 检查文件是否存在
- #ifdef RVC_OS_WIN
- DWORD attr = GetFileAttributesA(strConfigPath);
- Dbg("check install config: %s", (const char*)strConfigPath);
- //assert((attr != INVALID_FILE_ATTRIBUTES) && !(attr & FILE_ATTRIBUTE_DIRECTORY));
- if (attr == INVALID_FILE_ATTRIBUTES || (attr & FILE_ATTRIBUTE_DIRECTORY))
- {
- LogError(Severity_Low, Error_Unexpect, 0, CSimpleStringA::Format("install config [%s] not exists",
- (const char*)strConfigPath));
- strErrMsg = "run.ini不存在";
- return Error_Unexpect;
- }
- #else
- Dbg("check install config: %s", (const char*)strConfigPath);
- if (!ExistsFileA(strConfigPath.GetData()))
- {
- LogError(Severity_Low, Error_Unexpect, 0, CSimpleStringA::Format("install config [%s] not exists",
- (const char*)strConfigPath));
- strErrMsg = "run.ini不存在";
- return Error_Unexpect;
- }
- #endif // RVC_OS_WIN
- CSystemStaticInfo sysInfo;
- ZeroMemory(&sysInfo, sizeof(sysInfo));
- rc = m_pEntity->GetFunction()->GetSystemStaticInfo(sysInfo);
- assert(rc == Error_Succeed);
- // MachineType=RVC.Standard,RVC.Wall
- char *p = inifile_read_str(strConfigPath, "Precondition", "MachineType", "");
- CSimpleStringA strMachineType = p;
- toolkit_free(p);
- if (!strMachineType.IsNullOrEmpty())
- {
- bool bMatch = strMachineType.IndexOf(sysInfo.strMachineType) >=0;
- if (!bMatch)
- {
- LogError(Severity_Low, Error_NotMeetCondition, 0, CSimpleStringA::Format("machine type mismatch, config: [%s], current: [%s]",
- (const char*)strMachineType, (const char*)sysInfo.strMachineType));
- strErrMsg = CSimpleStringA::Format("机型不匹配(配置:%s, 当前:%s)", (const char*)strMachineType, (const char*)sysInfo.strMachineType);
- return Error_NotMeetCondition;
- }
- }
- // MachineVersion=1.0-
- p = inifile_read_str(strConfigPath, "Precondition", "MachineVersion", "");
- CSimpleStringA strMachineVersion = p;
- toolkit_free(p);
- if (!strMachineVersion.IsNullOrEmpty())
- {
- CVersion CurMachineVersion(sysInfo.MachineVersion.GetMajor(), sysInfo.MachineVersion.GetMinor());
- bool bMatch = false;
-
- DWORD dwMajor1(0), dwMinor1(0);
- int n = sscanf(strMachineVersion, "%d.%d", &dwMajor1, &dwMinor1);
- CVersion beginVersion(dwMajor1, dwMinor1);
-
- auto list = strMachineVersion.Split('-');
- if (list.GetCount() >= 2)
- {
- DWORD dwMajor2(0), dwMinor2(0);
- n = sscanf(list[1], "%d.%d", &dwMajor2, &dwMinor2);
- CVersion endVersion(dwMajor2, dwMinor2);
-
- bMatch = CurMachineVersion >= beginVersion && CurMachineVersion <= endVersion;
- }
- else
- {
- if (strMachineVersion.IsEndWith("-"))
- bMatch = CurMachineVersion >= beginVersion;
- else
- bMatch = CurMachineVersion == beginVersion;
- }
-
- if (!bMatch)
- {
- LogError(Severity_Low, Error_NotMeetCondition, 0, CSimpleStringA::Format("machine version mismatch, config: [%s], current: [%s]",
- (const char*)strMachineVersion, (const char*)sysInfo.MachineVersion.ToString()));
- strErrMsg = CSimpleStringA::Format("硬件版本不匹配(配置:%s, 当前:%s)", (const char*)strMachineVersion, (const char*)sysInfo.MachineVersion.ToString());
- return Error_NotMeetCondition;
- }
- }
-
- // SoftwareVersion=1.1.1-1.2.1
- p = inifile_read_str(strConfigPath, "Precondition", "SoftwareVersion", "");
- CSimpleStringA strSoftwareVersion = p;
- toolkit_free(p);
- if (!strSoftwareVersion.IsNullOrEmpty())
- {
- CVersion CurSoftwareVersion(sysInfo.InstallVersion.GetMajor(), sysInfo.InstallVersion.GetMinor(), sysInfo.InstallVersion.GetRevision(), 0);
- bool bMatch = false;
-
- DWORD dwMajor1(0), dwMinor1(0), dwRevision1(0);
- int n = sscanf(strSoftwareVersion, "%d.%d.%d", &dwMajor1, &dwMinor1, &dwRevision1);
- CVersion beginVersion(dwMajor1, dwMinor1, dwRevision1, 0);
- auto list = strSoftwareVersion.Split('-');
- if (list.GetCount() >= 2)
- {
- DWORD dwMajor2(0), dwMinor2(0), dwRevision2(0);
- n = sscanf(list[1], "%d.%d.%d", &dwMajor2, &dwMinor2, &dwRevision2);
- CVersion endVersion(dwMajor2, dwMinor2, dwRevision2, 0);
- bMatch = CurSoftwareVersion >= beginVersion && CurSoftwareVersion <= endVersion;
- }
- else
- {
- if (strSoftwareVersion.IsEndWith("-"))
- bMatch = CurSoftwareVersion >= beginVersion;
- else
- bMatch = CurSoftwareVersion == beginVersion;
- }
-
- if (!bMatch)
- {
- LogError(Severity_Low, Error_NotMeetCondition, 0, (const char*)CSimpleStringA::Format("software version mismatch, config: [%s], current: [%s]",
- (const char*)strSoftwareVersion, (const char*)sysInfo.InstallVersion.ToString()));
- strErrMsg = CSimpleStringA::Format("终端版本不匹配(配置:%s, 当前:%s)", (const char*)strSoftwareVersion, (const char*)sysInfo.InstallVersion.ToString());
- return Error_NotMeetCondition;
- }
- }
- // OSVersion=6.1
- p = inifile_read_str(strConfigPath, "Precondition", "OSVersion", "");
- CSimpleStringA strOSVersion = p;
- toolkit_free(p);
- //if (!strOSVersion.IsNullOrEmpty())
- //{
- // OSVERSIONINFO osvi;
- // ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
- // osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- // GetVersionEx(&osvi);
- // CVersion osVersion(osvi.dwMajorVersion, osvi.dwMinorVersion);
- // DWORD dwMajor1(0), dwMinor1(0);
- // int n = sscanf(strOSVersion, "%d.%d", &dwMajor1, &dwMinor1);
- // CVersion beginVersion(dwMajor1, dwMinor1);
- // bool bMatch = false;
- // auto list = strOSVersion.Split('-');
- // if (list.GetCount() >= 2)
- // {
- // DWORD dwMajor2(0), dwMinor2(0);
- // n = sscanf(list[1], "%d.%d", &dwMajor2, &dwMinor2);
- // CVersion endVersion(dwMajor2, dwMinor2);
- // bMatch = osVersion >= beginVersion && osVersion <= endVersion;
- // }
- // else
- // {
- // if (strOSVersion.IsEndWith("-"))
- // bMatch = osVersion >= beginVersion;
- // else
- // bMatch = osVersion == beginVersion;
- // }
- // if (!bMatch)
- // {
- // LogError(Severity_Low, Error_NotMeetCondition, 0, CSimpleStringA::Format("OS version mismatch, config: [%s], current: [%s]",
- // (const char*)strOSVersion, (const char*)osVersion.ToString()));
- // strErrMsg = CSimpleStringA::Format("操作系统版本不匹配(配置:%s, 当前:%s)", (const char*)strOSVersion, (const char*)osVersion.ToString());
- // return Error_NotMeetCondition;
- // }
- //}
- if (!strOSVersion.IsNullOrEmpty())
- {
- DWORD dwMajorVersion(0), dwMinorVersion(0);
- if (getOSVersion(dwMajorVersion,dwMinorVersion)) {
- CVersion osVersion(dwMajorVersion, dwMinorVersion);
- DWORD dwMajor1(0), dwMinor1(0);
- int n = sscanf(strOSVersion, "%d.%d", &dwMajor1, &dwMinor1);
- CVersion beginVersion(dwMajor1, dwMinor1);
- bool bMatch = false;
- auto list = strOSVersion.Split('-');
- if (list.GetCount() >= 2)
- {
- DWORD dwMajor2(0), dwMinor2(0);
- n = sscanf(list[1], "%d.%d", &dwMajor2, &dwMinor2);
- CVersion endVersion(dwMajor2, dwMinor2);
- bMatch = osVersion >= beginVersion && osVersion <= endVersion;
- }
- else
- {
- if (strOSVersion.IsEndWith("-"))
- bMatch = osVersion >= beginVersion;
- else
- bMatch = osVersion == beginVersion;
- }
- if (!bMatch)
- {
- LogError(Severity_Low, Error_NotMeetCondition, 0, CSimpleStringA::Format("OS version mismatch, config: [%s], current: [%s]",
- (const char*)strOSVersion, (const char*)osVersion.ToString()));
- strErrMsg = CSimpleStringA::Format("操作系统版本不匹配(配置:%s, 当前:%s)", (const char*)strOSVersion, (const char*)osVersion.ToString());
- return Error_NotMeetCondition;
- }
- }
- else{
- LogError(Severity_Low, Error_NotMeetCondition, 0, CSimpleStringA::Format("OS version get fail, config: [%s], current: [0.0.0.0]",
- (const char*)strOSVersion));
- strErrMsg = CSimpleStringA::Format("操作系统版本获取失败(配置:%s, 当前:0.0.0.0)", (const char*)strOSVersion);
- return Error_NotMeetCondition;
- }
- }
- // Device=(HPxx,1.0-),(IBMxx,2.0-3.0)
- p = inifile_read_str(strConfigPath, "Precondition", "Device", "");
- CSimpleStringA strDevice = p;
- toolkit_free(p);
- // Depend=upgrade1.zip, upgrade2.zip
- p = inifile_read_str(strConfigPath, "Precondition", "Depend", "");
- CSimpleStringA strDepend = p;
- toolkit_free(p);
- if (!strDepend.IsNullOrEmpty())
- {
- auto list = strDepend.Split(',');
- for(int i=0; i<list.GetCount(); i++)
- {
- auto& strPack = list[i];
- //TODO:此处判断需要调用真正的是否安装接口(修改前)
- if (!m_pEntity->GetFunction()->IsPackInstalled(strPack))
- {
- strErrMsg = CSimpleStringA::Format("依赖包[%s]未安装", (const char*)strPack);
- LogError(Severity_Low, Error_NotMeetCondition, 0, CSimpleStringA::Format("depend pack [%s] not installed", (const char*)strPack));
- return Error_NotMeetCondition;
- }
- }
- }
- // Cover=upgrade3.zip, upgrade4.zip
- p = inifile_read_str(strConfigPath, "Precondition", "Cover", "");
- CSimpleStringA strCover = p;
- toolkit_free(p);
- if (!strCover.IsNullOrEmpty())
- {
- coverlist = strCover.Split(',');
- }
- if (!CheckNewRunFilesSign())
- {
- strErrMsg = CSimpleStringA::Format("升级包中dll或exe签名验证失败");
- LogError(Severity_Low, Error_NotMeetCondition, 0, CSimpleStringA::Format("升级包中dll或exe签名验证失败"));
- return Error_NotMeetCondition;
- }
- return Error_Succeed;
- }
- CSimpleStringA CUpgradeRunFSM::GetSysPatchNameFromPackName(const char *pszPackName)
- {
- //操作系统补丁升级包名格式:ServerPack_日期_补丁名
- CSimpleStringA str = pszPackName;
- CSimpleStringA strSysPatchName = "";
- if (!str.IsNullOrEmpty())
- {
- auto arr = str.Split('_');
- if (arr.GetCount() == 3)
- {
- strSysPatchName = arr[2];
- }
- else
- {
- Dbg("升级包名[%s]不符合规范, 必须是:ServerPack_日期_补丁名格式", str);
- }
- }
- return strSysPatchName;
- }
- struct SysPackInstallTask : ITaskSp
- {
- SysPackInstallTask(CUpgradeRunFSM *pFSM, const char *pszPackName, const char *pszSysCustomVer)
- : m_pFSM(pFSM), m_strSysPackName(pszPackName), m_strSysCustomVer(pszSysCustomVer) {}
- CUpgradeRunFSM *m_pFSM;
- CSimpleStringA m_strSysPackName;
- CSimpleStringA m_strSysCustomVer;
- virtual void Process()
- {
- auto pEntity = m_pFSM->GetEntityBase();
- CSimpleStringA strErrMsg;
- CSimpleStringA strVersion;
- Dbg("begin install sys pack: [%s]", (const char*)m_strSysPackName);
- auto rc = pEntity->GetFunction()->GetPrivilegeFunction()->BeginSysPackInstall(m_strSysPackName, strErrMsg);
- Dbg("end install sys pack: [%s], result: %s(%d)", (const char*)m_strSysPackName, (const char*)strErrMsg, rc);
- //获取升级结果
- UpgradeRun::UpgradeDoneEvent e = {};
- if (m_strSysPackName.IsStartWith("SP"))
- {
- //系统补丁
- if (!((CUpgradeRunEntity*)pEntity)->GetServerPackUpgradeResult(m_strSysPackName, strVersion, strErrMsg))
- {
- Dbg("get [%s] ServerPack upgrade result fail, %s", (const char*)m_strSysPackName, (const char*)strErrMsg);
- strErrMsg = "";
- }
- e.strSysPatchName = strVersion;
- }
- else if (m_strSysPackName.IsStartWith("FP"))
- {
- //固件
- if (!((CUpgradeRunEntity*)pEntity)->GetFirmwarePackUpgradeResult(m_strSysPackName, strVersion, strErrMsg))
- {
- Dbg("get [%s] FirmwarePack upgrade result fail, %s", (const char*)m_strSysPackName, (const char*)strErrMsg);
- strErrMsg = "";
- }
- e.strFWID = strVersion;
- }
- else if (m_strSysPackName.IsStartWith("SCP"))
- {
- //系统定制
- e.strNewVersion = m_strSysCustomVer;
- }
- else
- {
- Dbg("unknow pack name[%s]", (const char*)m_strSysPackName);
- }
- e.strPackName = m_strSysPackName;
- e.error = rc;
- e.bLightPack = false;
- e.bSysInstall = true;
- e.strComment = strErrMsg;
- Dbg("end install sys pack: [%s], result: %s(%d)", (const char*)m_strSysPackName, (const char*)strErrMsg, rc);
-
-
- // 删除临时解压目录
- m_pFSM->DeleteUnzipDir();//先删除临时目录,再发送Event_EndUpgrade,否则m_strInstallPack被清空后assert(!m_strInstallPack.IsNullOrEmpty())会报异常
- m_pFSM->PostEventFIFO(new FSMEvent(CUpgradeRunFSM::Event_EndUpgrade));
- Sleep(2000);
- ((CUpgradeRunEntity*)pEntity)->BroadcastUpgradeDoneEvent(e); //modify by lwt 20210207,全部处理完再发事件,否则会导致UpgradeRun和UpgradeMgr两个状态机不同步
- }
- };
- ErrorCodeEnum CUpgradeRunFSM::InstallPack(bool &bSysInstall, bool &bLightPack, CSimpleStringA &strNewVersion, CSimpleStringA &strErrMsg)
- {
- CSimpleStringA strConfigPath;
- auto rc = GetInstallConfigPath(strConfigPath);
- assert(rc == Error_Succeed);
- auto pEntityFunc = m_pEntity->GetFunction();
- assert(pEntityFunc != NULL);
- auto pPrivFunc = pEntityFunc->GetPrivilegeFunction();
- assert(pPrivFunc != NULL);
- CSystemStaticInfo sysInfo;
- ZeroMemory(&sysInfo, sizeof(sysInfo));
- rc = pEntityFunc->GetSystemStaticInfo(sysInfo);
- assert(rc == Error_Succeed);
- // 检查文件是否存在
- #ifdef RVC_OS_WIN
- DWORD attr = GetFileAttributesA(strConfigPath);
- assert((attr != INVALID_FILE_ATTRIBUTES) && !(attr & FILE_ATTRIBUTE_DIRECTORY));
- #else
- if(!ExistsFileA(strConfigPath.GetData()))
- {
- strErrMsg = "run.ini不存在";
- return Error_NotExist;
- }
- #endif // RVC_OS_WIN
- // UpgradeVersion=1.1.2|A
- char *p = inifile_read_str(strConfigPath, "Action", "UpgradeVersion", "");
- CSimpleStringA strUpgradeVersion = p;
- toolkit_free(p);
- // ToRun= autorun.bat
- p = inifile_read_str(strConfigPath, "Action", "ToRun", "");
- CSimpleStringA strToRun = p;
- toolkit_free(p);
- // SysCustomVer=1.4
- p = inifile_read_str(strConfigPath, "Action", "SysCustomVer", "");
- CSimpleStringA strSysCustomVer = p;
- toolkit_free(p);
- // InstallType=auto或manual
- p = inifile_read_str(strConfigPath, "Precondition", "InstallType", "");
- CSimpleStringA strInstallType = p;
- toolkit_free(p);
- bSysInstall = !strToRun.IsNullOrEmpty();
- CVersion latterVersion;
- if (!bSysInstall && strUpgradeVersion.IsNullOrEmpty())
- {
- bLightPack = true;
- }
- else
- {
- bLightPack = false;
- CVersion &curVer = sysInfo.InstallVersion;
-
- if (strUpgradeVersion == "A")
- {
- latterVersion = CVersion(curVer.GetMajor(), curVer.GetMinor(), curVer.GetRevision(), curVer.GetBuild()+1);
- }
- else
- {
- // 指定版本
- DWORD dwMajor(0), dwMinor(0), dwRevision(0);
- int n = sscanf(strUpgradeVersion, "%d.%d.%d", &dwMajor, &dwMinor, &dwRevision);
- //assert(n == 3);
- if (n < 3)
- {
- strErrMsg = CSimpleStringA::Format("指定升级版本无效(%s)", (const char*)strUpgradeVersion);
- LogError(Severity_Low, Error_Unexpect, 0, CSimpleStringA::Format("specified software version is invalid: [%s]", (const char*)strUpgradeVersion));
- return Error_NotMeetCondition;
- }
-
- if (dwMajor < curVer.GetMajor()
- || (dwMajor == curVer.GetMajor() && dwMinor < curVer.GetMinor())
- || (dwMajor == curVer.GetMajor() && dwMinor == curVer.GetMinor() && dwRevision <curVer.GetRevision()))
- {
- LogError(Severity_Low, Error_NotMeetCondition, 0,
- CSimpleStringA::Format("specified software version is invalid, config: [%s], current: [%d.%d.%d]",
- (const char*)strUpgradeVersion, curVer.GetMajor(), curVer.GetMinor(), curVer.GetRevision()));
- strErrMsg = CSimpleStringA::Format("指定升级版本无效(配置:%s, 当前:%d.%d.%d)", (const char*)strUpgradeVersion, curVer.GetMajor(), curVer.GetMinor(), curVer.GetRevision());
- return Error_NotMeetCondition;
- }
- if (dwMajor == curVer.GetMajor() && dwMinor == curVer.GetMinor() && dwRevision ==curVer.GetRevision())
- latterVersion = CVersion(dwMajor, dwMinor, dwRevision, curVer.GetBuild()+1);
- else
- latterVersion = CVersion(dwMajor, dwMinor, dwRevision, 1);
- }
- LOG_TRACE("upgraded install version is: [%s]", (const char*)latterVersion.ToString());
- strNewVersion = latterVersion.ToString();
- }
- if (bLightPack)
- {
- rc = pPrivFunc->BeginLightInstall(m_strInstallPack);
- if (rc != Error_Succeed)
- {
- strErrMsg = "轻量升级失败";
- LogError(Severity_Low, Error_Unexpect, ERROR_UPGRADERUN_INSTALL_LIGHTPACK_FAIL, "轻量升级失败");
- return Error_Unexpect;
- }
- //尝试对轻量包文件整体赋权
- return rc;
- }
- else if (bSysInstall)
- {
- // xkm@20161208: 系统外执行改为异步线程池执行
- //strNewVersion = strSysCustomVer; // 存放系统定制版本
- //return pPrivFunc->BeginSysPackInstall(m_strInstallPack);
- ////modify by zl 20170813,通过升级类型判断是否自动升级。如果是手工升级类型
- //bool bManual = (strInstallType.Compare("manual",true)==0)?true:false;
- //if (!bManual)
- //{
- // pEntityFunc->PostThreadPoolTask(new SysPackInstallTask(this, m_strInstallPack, strSysCustomVer));
- //}
- //else
- //{
- // //手工升级直接返回
- // return Error_Succeed;
- //}
- pEntityFunc->PostThreadPoolTask(new SysPackInstallTask(this, m_strInstallPack, strSysCustomVer));
- }
- else
- {
- // 框架升级,建立新目录
- CSimpleStringA strErrInfo = "";
- Dbg("准备开始安装目录,版本[%s],安装包[%s]",(const char*)latterVersion.ToString(),m_strInstallPack.GetData());
- rc = pPrivFunc->CreateInstallNewVersion(latterVersion, m_strInstallPack,strErrInfo);
- if (rc != Error_Succeed)
- {
- Dbg("创建新版本目录失败:%s",strErrInfo.GetData());
- strErrMsg = CSimpleStringA::Format("创建新版本目录失败:%s",strErrInfo.GetData());
- LogError(Severity_Low, Error_Unexpect, ERROR_UPGRADERUN_CREATE_VERSION_FAIL, "create new version directory fail");
- return Error_Unexpect;
- }
- //ToDelete=Run\bin\abc.dll,Data\*.tmp
- p = inifile_read_str(strConfigPath, "Action", "ToDelete", "");
- CSimpleStringA strToDelete = p;
- toolkit_free(p);
- if (!strToDelete.IsNullOrEmpty())
- {
- #ifdef RVC_OS_WIN
- #else
- /*适配linux终端: 转换路径中的‘\’字符成‘/’*/
- Dbg("ToDelete tranfer begin=%s", strToDelete.GetData());
- string tmp = strToDelete.GetData();
- replace(tmp.begin(), tmp.end(), '\\', SPLIT_SLASH);
- strToDelete = tmp.c_str();
- Dbg("ToDelete tranfer end=%s", strToDelete.GetData());
- #endif
- auto list = strToDelete.Split(',');
- for(int i=0; i<list.GetCount(); i++)
- {
- Dbg("delete file [%s] in new version", (const char*)list[i]);
- rc = pPrivFunc->DeleteFileInNewVersion(list[i]);
- }
- }
- //ToCopy= Run\bin\SpShell.exe, Run\dep\*.dll
- p = inifile_read_str(strConfigPath, "Action", "ToCopy", "");
- CSimpleStringA strToCopy = p;
- toolkit_free(p);
-
- if (!strToCopy.IsNullOrEmpty())
- {
- #ifdef RVC_OS_WIN
- #else
- /*转换路径中的‘\’字符成‘/’*/
- Dbg("ToCopy tranfer begin=%s", strToCopy.GetData());
- string tmp = strToCopy.GetData();
- replace(tmp.begin(), tmp.end(), '\\', SPLIT_SLASH);
- strToCopy = tmp.c_str();
- Dbg("ToCopy tranfer end=%s", strToCopy.GetData());
- #endif
- auto copyList = strToCopy.Split(',');
- for(int i=0; i<copyList.GetCount(); i++)
- {
- auto &file = copyList[i];
- // 通配符检测
- if (file.IndexOf("*") >0)
- {
- CSimpleStringA strUnzipPath;
- GetUnzipTempDir(strUnzipPath);
- auto strFileDir = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strUnzipPath, (const char*)GetFileDirectory(file));
- list<CSimpleStringA> fileList;
- RecursiveGetSubFiles(strFileDir, strFileDir, fileList);//得到文件夹下面所有文件
- CSimpleStringA strFileFilter = _GetFileName(file);//得到过滤条件
- for(auto it = fileList.begin(); it != fileList.end(); it++)
- {
- if (IsFileMatch(strFileFilter, _GetFileName((const char*)(*it))))
- {
- CSimpleStringA strActFileName = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)GetFileDirectory(file), (const char*)(*it));
- Dbg("copy file [%s] matched wildchar name [%s]", (const char*)strActFileName, (const char*)strFileFilter);
- rc = pPrivFunc->CopyFileToNewVersion(strActFileName, 3);
- Dbg("copy file [%s] to new version %s", (const char*)strActFileName, rc == Error_Succeed ? "succeed" : "fail");
-
- if (rc != Error_Succeed)
- {
- strErrMsg = CSimpleStringA::Format("拷贝文件[%s]失败", (const char*)strActFileName);
- return rc;
- }
- }
- }
- }
- else
- {
- //判断绝对文件名是否存在,因存在智能对比,故此文件不一定存在
- //Dbg("install file is %s",file.GetData());
- CSimpleStringA strDownloadsPath;
- ErrorCodeEnum ece = m_pEntity->GetFunction()->GetPath("Downloads", strDownloadsPath);
- if(ece != Error_Succeed){
- Dbg("InstallPack fail ,get Downloads path is fail ,copy file [%s] fail",file.GetData());
- strErrMsg = CSimpleStringA::Format("拷贝文件[%s]失败", file.GetData());
- return ece;
- }
- CSimpleStringA strUnzipPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", strDownloadsPath.GetData(), m_strInstallPack.GetData());
- //Dbg("strUnzipPath is %s",strUnzipPath.GetData());
- if (strUnzipPath.IsEndWith(".zip") || strUnzipPath.IsEndWith(".cab")){
- strUnzipPath = strUnzipPath.SubString(0, strUnzipPath.GetLength()-4);
- }
- CSimpleStringA strSourceFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", strUnzipPath.GetData(), file.GetData());
- //Dbg("strSourceFile is %s",strSourceFile.GetData());
- if(ExistsFileA(strSourceFile.GetData())){
- //int nCopyMode = inifile_read_int(strConfigPath, GetFileName(file), "CopyMode", 3);
- rc = pPrivFunc->CopyFileToNewVersion(file.GetData(), 3);
- Dbg("copy file [%s] to new version %s", file.GetData(), rc == Error_Succeed ? "succeed" : "fail");
- if (rc != Error_Succeed)
- {
- strErrMsg = CSimpleStringA::Format("拷贝文件[%s]失败", file.GetData());
- return rc;
- }
- }else{
- Dbg("file [%s] is not exist ,ignore copy to new version ",file.GetData());
- }
- }
- }
- //Dbg("total copy %d files", list.GetCount());
- }
- //尝试对新系统版本文件整体赋权
- }
- return rc;
- }
- CSimpleStringA CUpgradeRunFSM::GetFileDirectory(const char *pszFullPath)
- {
- int i=strlen(pszFullPath)-1;
- for( ; i>0 && pszFullPath[i]!=SPLIT_SLASH; i--)NULL;
- return CSimpleStringA(pszFullPath, i);
- }
- CSimpleStringA CUpgradeRunFSM::GetFileName(const char *pszFullPath)
- {
- const char *p = strrchr(pszFullPath, SPLIT_SLASH);
- if (p != NULL)
- {
- return p+1;
- }
- else
- {
- return pszFullPath;
- }
- }
- void CUpgradeRunFSM::RecursiveGetSubFiles(const char *pszDir, const char *pszTrimStart, list<CSimpleStringA>& retList)
- {
- if (!ExistsDirA(pszDir))
- return;
- auto arr = fileutil_get_sub_files(pszDir);
- if (arr != NULL)
- {
- for (int i = 0; i < arr->nelts; ++i)
- {
- char *file = ARRAY_IDX(arr, i, char*);
- if (pszTrimStart != NULL && strnicmp(file, pszTrimStart, strlen(pszTrimStart))==0) {
- file += strlen(pszTrimStart);
- if (*file == SPLIT_SLASH)
- file++;
- }
- retList.push_back(file);
- }
- toolkit_array_free2(arr);
- }
- arr = fileutil_get_sub_dirs(pszDir);
- if (arr != NULL)
- {
- for (int i = 0; i < arr->nelts; ++i)
- {
- char *dir = ARRAY_IDX(arr, i, char*);
- RecursiveGetSubFiles(dir, pszTrimStart, retList);
- }
- toolkit_array_free2(arr);
- }
- }
- bool CUpgradeRunFSM::IsFileMatch(const char *pszFilter, const char *pszFileName)
- {
- const char *p1 = pszFilter;
- const char *p2 = pszFileName;
- if (p1 == NULL)
- return true;
- if (p2 == NULL)
- return false;
- if (*p1 ==NULL && *p2 ==NULL)
- return true;
- else if (*p1 == NULL)
- return false;
- else if (*p2 == NULL)
- {
- // 查找*p1是否全是*
- while(*p1 == '*')
- p1++;
- if (*p1 == NULL)
- return true;
- else
- return false;
- }
- if (*p1 != '*')
- {
- if (tolower(*p1) != tolower(*p2))
- return false;
- else
- return IsFileMatch(p1+1, p2+1);
- }
- else
- {
- while(*++p1 == '*');
- if (*p1 == NULL)
- return true;
- while (*p2)
- {
- while(tolower(*p1) != tolower(*p2) && *++p2);
- if (*p2 == NULL)
- return false;
- if(IsFileMatch(p1+1, p2+1))
- return true;
- p2++;
- }
- return false;
- }
- }
- void getFiles(string path, vector<string>& files)
- {
- #ifdef RVC_OS_WIN
- //查询文件
- //文件句柄
- long hFile = 0;
- //文件信息
- struct _finddata_t fileinfo;
- string p;
- if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1)
- {
- do
- {
- //如果是目录,迭代之
- //如果不是,加入列表
- if ((fileinfo.attrib & _A_SUBDIR))
- {
- if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
- getFiles(p.assign(path).append("\\").append(fileinfo.name), files);
- }
- else
- {
- files.push_back(p.assign(path).append("\\").append(fileinfo.name));
- }
- } while (_findnext(hFile, &fileinfo) == 0);
- _findclose(hFile);
- }
- #else
- array_header_t* arr_files = fileutil_get_sub_files2_a(path.c_str(),1000);
- if (arr_files)
- {
- int i;
- for (i = 0; i < arr_files->nelts; ++i)
- {
- char* file_path = ARRAY_IDX(arr_files, i, char*);
- string strfilePath = file_path;
- files.push_back(strfilePath);
- }
- toolkit_array_free2(arr_files);
- }
- array_header_t* arr_dir = fileutil_get_sub_dirs_a(path.c_str());
- if (arr_dir) {
- int i;
- for (i = 0; i < arr_dir->nelts; ++i) {
- char* dir_path = ARRAY_IDX(arr_dir, i, char*);
- getFiles(dir_path, files);
- }
- }
- #endif
-
- }
- bool CUpgradeRunFSM::CheckNewRunFilesSign()
- {
- CSimpleStringA strErrMsg;
- int nVerifyflg = 0;
- CSmartPointer<IEntityFunction> spFunction = m_pEntity->GetFunction();
- CSmartPointer<IConfigInfo> spConfig;
- ErrorCodeEnum Error = spFunction->OpenConfig(Config_CenterSetting, spConfig);
- if (Error_Succeed == Error)
- {
- Error = spConfig->ReadConfigValueInt("SpBase", "VerifyCodeSign", nVerifyflg);
- if (Error_Succeed == Error)
- {
- Dbg("get VerifyCodeSign[%d] from CenterSetting.ini", nVerifyflg);
- }
- else
- {
- Dbg("get VerifyCodeSign from CenterSetting.ini failed");
- }
- }
- if (0 == nVerifyflg)
- {
- Dbg("VerifyCodeSign flag is 0 or not exsit,ignore code signature");
- return true;
- }
- //TODO:校验升级包中mod和bin目录下所有签名,防止升级后,出现失败无法启动框架或升级实体导致无法自动回滚
- CSimpleStringA strDownloadsPath;
- auto rc = m_pEntity->GetFunction()->GetPath("Downloads", strDownloadsPath);
- assert(rc == Error_Succeed);
- CSimpleStringA strUnzipPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strDownloadsPath, (const char*)m_strInstallPack);
- if (strUnzipPath.IsEndWith(".zip") || strUnzipPath.IsEndWith(".cab"))
- strUnzipPath = strUnzipPath.SubString(0, strUnzipPath.GetLength() - 4);
- CSimpleStringA strDownloadRunPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "Run", (const char*)strUnzipPath);
- string runPath = strDownloadRunPath.GetData();
- vector<string> files;
- getFiles(runPath, files);
- int size = files.size();
- for (int i = 0;i < size;i++)
- {
- CSimpleStringA strFileName = files[i].c_str();
- if (strFileName.IsEndWith(".exe", true) || strFileName.IsEndWith(".dll", true))
- {
- rc = m_pEntity->GetFunction()->VerifySignature(strFileName.GetData(), strErrMsg);
- if (rc != Error_Succeed)
- {
- LogError(Severity_Low, Error_Unexpect, 0, CSimpleStringA::Format("[%s]签名校验失败", strFileName));
- return false;
- }
- Dbg("%s in pack %s, verify sign success", (const char*)strFileName, (const char*)m_strInstallPack);
- }
- }
- //CSimpleStringA strDownloadsPath;
- //auto rc = m_pEntity->GetFunction()->GetPath("Downloads", strDownloadsPath);
- //assert(rc == Error_Succeed);
- //CSimpleStringA strUnzipPath = CSimpleStringA::Format("%s\\%s", (const char*)strDownloadsPath, (const char*)m_strInstallPack);
- //if (strUnzipPath.IsEndWith(".zip") || strUnzipPath.IsEndWith(".cab"))
- // strUnzipPath = strUnzipPath.SubString(0, strUnzipPath.GetLength() - 4);
- //CSimpleStringA strSpShellPath = CSimpleStringA::Format("%s\\Run\\bin\\SpShell.exe", (const char*)strUnzipPath);
- //CSimpleStringA strSpHostPath = CSimpleStringA::Format("%s\\Run\\bin\\SpHost.exe", (const char*)strUnzipPath);
- //CSimpleStringA strSpbasePath = CSimpleStringA::Format("%s\\Run\\bin\\SpBase.dll", (const char*)strUnzipPath);
- //CSimpleStringA strUpgradeManagerPath = CSimpleStringA::Format("%s\\Run\\mod\\mod_UpgradeMgr.dll", (const char*)strUnzipPath);
- //// 检查文件是否存在,存在则校验其签名
- //DWORD attr = GetFileAttributesA(strSpShellPath);
- //if (attr == INVALID_FILE_ATTRIBUTES || (attr & FILE_ATTRIBUTE_DIRECTORY))
- //{
- // Dbg("not find %s in pack %s, no need to verify sign", strSpShellPath, m_strInstallPack);
- //}
- //else
- //{
- // rc = m_pEntity->GetFunction()->VerifySignature(strSpShellPath, strErrMsg);
- // if (rc != Error_Succeed)
- // {
- // LogError(Severity_Low, Error_Unexpect, 0, CSimpleStringA::Format("[%s]签名校验失败", (const char*)strSpShellPath));
- // return false;
- // }
- //}
- //attr = GetFileAttributesA(strSpHostPath);
- //if (attr == INVALID_FILE_ATTRIBUTES || (attr & FILE_ATTRIBUTE_DIRECTORY))
- //{
- // Dbg("not find %s in pack %s, no need to verify sign", strSpHostPath, m_strInstallPack);
- //}
- //else
- //{
- // rc = m_pEntity->GetFunction()->VerifySignature(strSpHostPath, strErrMsg);
- // if (rc != Error_Succeed)
- // {
- // LogError(Severity_Low, Error_Unexpect, 0, CSimpleStringA::Format("[%s]签名校验失败", (const char*)strSpHostPath));
- // return false;
- // }
- //}
- //attr = GetFileAttributesA(strSpbasePath);
- //if (attr == INVALID_FILE_ATTRIBUTES || (attr & FILE_ATTRIBUTE_DIRECTORY))
- //{
- // Dbg("not find %s in pack %s, no need to verify sign", strSpbasePath, m_strInstallPack);
- //}
- //else
- //{
- // rc = m_pEntity->GetFunction()->VerifySignature(strSpbasePath, strErrMsg);
- // if (rc != Error_Succeed)
- // {
- // LogError(Severity_Low, Error_Unexpect, 0, CSimpleStringA::Format("[%s]签名校验失败", (const char*)strSpbasePath));
- // return false;
- // }
- //}
- //
- //attr = GetFileAttributesA(strUpgradeManagerPath);
- //if (attr == INVALID_FILE_ATTRIBUTES || (attr & FILE_ATTRIBUTE_DIRECTORY))
- //{
- // Dbg("not find %s in pack %s, no need to verify sign", strUpgradeManagerPath, m_strInstallPack);
- //}
- //else
- //{
- // rc = m_pEntity->GetFunction()->VerifySignature(strUpgradeManagerPath, strErrMsg);
- // if (rc != Error_Succeed)
- // {
- // LogError(Severity_Low, Error_Unexpect, 0, CSimpleStringA::Format("[%s]签名校验失败", (const char*)strUpgradeManagerPath));
- // return false;
- // }
- //}
- return true;
- }
- bool CUpgradeRunFSM::getOSVersion(DWORD &dwMajorVersion, DWORD &dwMinorVersion)
- {
- #ifdef RVC_OS_WIN
- OSVERSIONINFO osvi;
- ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- GetVersionEx(&osvi);
- dwMajorVersion = osvi.dwMajorVersion;
- dwMinorVersion = osvi.dwMinorVersion;
- return true;
- #else
- struct utsname kernel_info;
- int ret = uname(&kernel_info);
- if (ret == 0) {
- Dbg("get linux kernel version success: %s", kernel_info.release);
- int n = sscanf((const char*)kernel_info.release, "%d.%d", &dwMajorVersion, &dwMinorVersion);
- return true;
- }
- else {
- Dbg("get linux kernel version fail: %s", strerror(errno));
- return false;
- }
- #endif // RVC_OS_WIN
-
- }
|