📄 embocheck2.cpp
字号:
if( hMsgQ == NULL )
{
ERRORMSG(1,(_T("CreateMsgQueue failed: (0x%X)\r\n"),GetLastError()));
return 0;
}
hNotifications = RequestDeviceNotifications( &guid, hMsgQ, TRUE );
if( hNotifications == NULL )
{
ERRORMSG(1,(_T("RequestDeviceNotifications failed: (0x%X)\r\n"),GetLastError()));
return 0;
}
// wait for messages and StopEvent...
HANDLE waitHandles[] = { hMsgQ, hDetectLocalPathThreadStopEvent };
for(DWORD i=0;i<dwNetworkMappingRetry;i++)
{
DWORD dwWaitResult=WaitForMultipleObjects(2, waitHandles, FALSE, dwNetworkMappingRetryGap);
if(WAIT_OBJECT_0==dwWaitResult) //if get notification
{
if( !ReadMsgQueue( hMsgQ, buf, sizeof(buf), &numRead, 0, &flags ) )
{
ERRORMSG(1,(_T("Failed to read from queue: (0x%X)\r\n"),GetLastError()));
continue; //goto WAIT_LOOP_START;
}
OnMountStorage( *((const DEVDETAIL*)buf), flags);
continue; //goto WAIT_LOOP_START;
}
else if(WAIT_TIMEOUT==dwWaitResult) //if timeout
{
TCHAR szFind[MAX_PATH]={0};
_tcscpy(szFind, g_szEmboRoot);
_tcscat(szFind, Embo_Wcopy_ToFind); //szFind=\harddisk\EmboBSP\Wcopy\*.*
WIN32_FIND_DATA WinFindDataSrc1={0};
HANDLE hFindSrc1;
hFindSrc1=FindFirstFile(szFind, &WinFindDataSrc1); //开始从源根目录进行查找
if(hFindSrc1!=INVALID_HANDLE_VALUE)
{
//find
fPathOK=TRUE;
SetEvent( hDetectLocalPathThreadStopEvent );
//SetPathOKEvent();
FindClose(hFindSrc1); //关闭查找文件
//goto WAIT_LOOP_END;
}
continue; //goto WAIT_LOOP_START;
}
else if((WAIT_OBJECT_0+1) == dwWaitResult)//if hDetectLocalPathThreadStopEvent
{
//goto WAIT_LOOP_END;
StopDeviceNotifications(hNotifications);
CloseMsgQueue( hMsgQ );
CloseHandle( hDetectLocalPathThreadStopEvent );
SetPathOKEvent();
break;
}
continue; //goto WAIT_LOOP_START;
}
//WAIT_LOOP_END:
return 1;
}
BOOL IfEmboRootIsNetwork(PTCHAR szEmboRoot2)
{
#define NetworkName1 _T("network")
#define NetworkName2 _T("网络")
#define NetworkName3 _T("網路")
BOOL fCheck=FALSE;
PTCHAR pcsPath=NULL;
TCHAR szEmboRoot[MAX_PATH]={0};
_tcscpy(szEmboRoot, szEmboRoot2);
pcsPath=_tcsstr(szEmboRoot, NetworkName1);
if((DWORD)((DWORD)szEmboRoot+2)==(DWORD)pcsPath)
{
fCheck=TRUE;
goto FOUND_NETWORK;
}
pcsPath=_tcsstr(szEmboRoot, NetworkName2);
if((DWORD)((DWORD)szEmboRoot+2)==(DWORD)pcsPath)
{
fCheck=TRUE;
goto FOUND_NETWORK;
}
pcsPath=_tcsstr(szEmboRoot, NetworkName3);
if((DWORD)((DWORD)szEmboRoot+2)==(DWORD)pcsPath)
{
fCheck=TRUE;
goto FOUND_NETWORK;
}
FOUND_NETWORK:
return fCheck;
}
BOOL IfEmboRootIsLocal(PTCHAR szEmboRoot2)
{
#define LocalName1 _T("harddisk")
#define LocalName2 _T("diskonchip")
#define LocalName3 _T("hard disk")
//#define LocalName4 _T("硬盘")
//#define LocalName5 _T("硬碟")
BOOL fCheck=FALSE;
PTCHAR pcsPath=NULL; //to find LocalName
PTCHAR pcsPath2=NULL; //to find "\\" after LocalName
TCHAR szEmboRoot[MAX_PATH]={0}; //it maybe \harddisk\machine1_path\user1_path\...
_tcscpy(szEmboRoot, szEmboRoot2);
pcsPath=_tcsstr(szEmboRoot, LocalName1);
if((DWORD)((DWORD)szEmboRoot+2)==(DWORD)pcsPath)
{
fCheck=TRUE;
goto GET_EmboRootVolume;
}
pcsPath=_tcsstr(szEmboRoot, LocalName2);
if((DWORD)((DWORD)szEmboRoot+2)==(DWORD)pcsPath)
{
fCheck=TRUE;
goto GET_EmboRootVolume;
}
pcsPath=_tcsstr(szEmboRoot, LocalName3);
if((DWORD)((DWORD)szEmboRoot+2)==(DWORD)pcsPath)
{
fCheck=TRUE;
goto GET_EmboRootVolume;
}
return fCheck;
GET_EmboRootVolume:
if(fCheck==TRUE) //to get szEmboRootVolume, it should be as \harddisk
{
pcsPath2=_tcsstr(pcsPath, _T("\\"));
if(NULL!=pcsPath2)
{
*pcsPath2=NULL;
}
_stprintf(g_szEmboRootVolume, _T("\\%s"), pcsPath);
}
return fCheck;
}
BOOL GetBaseinfoFromLoader(PBOOT_ARGS pbootArg, PEmboBaseInfo pbaseInfo)
{
DWORD dwStatus=TRUE;
if(dwStatus && !GetBootArg(pbootArg))
{
dwStatus = FALSE;
}
if(dwStatus && !GetBaseInfo(pbaseInfo,pbootArg))
{
dwStatus = FALSE;
}
return dwStatus;
}
//#define REG_KEY_EMBO_CHECK _T("Software\\Embedded-Tech\\EmboCheck")
//[HKEY_LOCAL_MACHINE\Software\Embedded-Tech\EmboCheck]
//"WaitForLocalPathTime"=dword:90000 ;micro seconds, about 2 minutes
//"NetworkMappingRetry"=dword:128 ;Network mapping retry 128 times, about 2 minutes
//"NetworkMappingRetryGap"=dword:1000 ;Network mapping retry Gap 1000 ms, about 1 seconds
//"WaitForPathOKTime"=dword:120000 ;micro seconds, about 2 minutes
//"DUpdatesRoot"="Harddisk"; //
//"DUpdatesServerName"="\\\\embo-notebookxp"; //
//"DUpdatesServerUser"=""; //
//"DUpdatesServerPass"=""; //
//"DUpdatesServerDir="\\test2"; //
//"DUpdatesLocalDir"="\\test"; //
//"IsNetwork"=dword:0; //()
//"IsPureOS"=dword:0; //
void GetRegistrySettings(void)
{
HKEY hKey=NULL;
DWORD dwRegValueType=REG_DWORD;
DWORD dwRegValueLength=0;
LONG dwRegResult=ERROR_SUCCESS;
// Get dwWaitForPathOKTime default = 180,000 3 minutes ///////////////////////////////////
dwWaitForPathOKTime=g_baseInfo.dwDUpdatesWaitingTime;
dwRegResult=RegOpenKeyEx(HKEY_LOCAL_MACHINE,REG_KEY_EMBO_DUPDATES,0,0,&hKey);
if(ERROR_SUCCESS==dwRegResult)
{
dwRegValueLength=MAX_PATH;
dwRegResult=RegQueryValueEx(hKey,TEXT("WaitForPathOKTime"),0,&dwRegValueType,NULL,&dwRegValueLength);
if(ERROR_SUCCESS ==dwRegResult)
{
dwRegResult=RegQueryValueEx(hKey,TEXT("WaitForPathOKTime"),0,&dwRegValueType,(LPBYTE)&dwWaitForPathOKTime,&dwRegValueLength);
}
RegCloseKey(hKey);
}
// Get dwNetworkMappingRetry ///////////////////////////////////
dwRegResult=RegOpenKeyEx(HKEY_LOCAL_MACHINE,REG_KEY_EMBO_DUPDATES,0,0,&hKey);
if(ERROR_SUCCESS==dwRegResult)
{
dwRegValueLength=MAX_PATH;
dwRegResult=RegQueryValueEx(hKey,TEXT("NetworkMappingRetry"),0,&dwRegValueType,NULL,&dwRegValueLength);
if(ERROR_SUCCESS==dwRegResult)
{
dwRegResult=RegQueryValueEx(hKey,TEXT("NetworkMappingRetry"),0,&dwRegValueType,(LPBYTE)&dwNetworkMappingRetry,&dwRegValueLength);
}
RegCloseKey(hKey);
}
// Get dwNetworkMappingRetryGap ///////////////////////////////////
dwRegResult=RegOpenKeyEx(HKEY_LOCAL_MACHINE,REG_KEY_EMBO_DUPDATES,0,0,&hKey);
if(ERROR_SUCCESS==dwRegResult)
{
dwRegValueLength=MAX_PATH;
dwRegResult=RegQueryValueEx(hKey,TEXT("NetworkMappingRetryGap"),0,&dwRegValueType,NULL,&dwRegValueLength);
if(ERROR_SUCCESS==dwRegResult)
{
dwRegResult=RegQueryValueEx(hKey,TEXT("NetworkMappingRetryGap"),0,&dwRegValueType,(LPBYTE)&dwNetworkMappingRetryGap,&dwRegValueLength);
}
RegCloseKey(hKey);
}
}
BOOL FindFolders()
{
//#define Embo_Wcopy_Folder _T("\\EmboBSP\\Wcopy\\")
//#define Embo_Wcopy_ToFind _T("\\EmboBSP\\Wcopy\\*.*")
//#define Embo_Wcopy_Exclude _T("backup")
////////////////////////////Make sure g_szEmboRoot of format \harddisk
DWORD dwTempPtr=_tcslen(g_szEmboRoot)-1;
if((g_szEmboRoot[dwTempPtr])==_T('\\'))
{
g_szEmboRoot[dwTempPtr]=NULL;
}
////////////////////////////
TCHAR szFind[MAX_PATH]={0};
_tcscpy(szFind, g_szEmboRoot);
_tcscat(szFind, Embo_Wcopy_ToFind); //szFind=\harddisk\EmboBSP\Wcopy\*.*
TCHAR szToCopy[MAX_PATH]={0};
_tcscpy(szToCopy, g_szEmboRoot);
_tcscat(szToCopy, Embo_Wcopy_Folder); //szToCopy=\harddisk\EmboBSP\Wcopy\
BOOL fResult=TRUE;
WIN32_FIND_DATA WinFindDataSrc1={0};
HANDLE hFindSrc1;
hFindSrc1=FindFirstFile(szFind, &WinFindDataSrc1); //开始从源根目录进行查找
if(hFindSrc1!=INVALID_HANDLE_VALUE)
{
do
{
if((WinFindDataSrc1.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
int FolderFind=1; //是目录,不是文件
DWORD dwLength=_tcslen(WinFindDataSrc1.cFileName);
if( (!(_tcsicmp(WinFindDataSrc1.cFileName, Embo_Wcopy_Exclude)))//是Embo_Wcopy_Exclude
)
{
continue;
}
else
{
TCHAR szToCopySrc[MAX_PATH]={0};
_tcscpy(szToCopySrc, szToCopy);
_tcscat(szToCopySrc, WinFindDataSrc1.cFileName);
CopyAllFiles(szToCopySrc, _T("\\")); //拷贝其下到根'\'
int baa=0;
}
}
/*
else //是文件,不是目录
{
int FileFind=1; //是目录,不是文件
DWORD dwLength=_tcslen(WinFindDataSrc1.cFileName);
if((!(_tcsicmp(&WinFindDataSrc1.cFileName[dwLength-4], _T(".reg"))))//是*.reg file?
)
{
TCHAR szRegfile[MAX_PATH]={0};
_tcscpy(szRegfile, szToCopy);
_tcscat(szRegfile, WinFindDataSrc1.cFileName);
GetRegFile(szRegfile); //do getregfile
}
}
*/
}while(FindNextFile(hFindSrc1,&WinFindDataSrc1));
if(hFindSrc1!=INVALID_HANDLE_VALUE)FindClose(hFindSrc1); //关闭查找文件
return TRUE;
}
else
{
return FALSE;
}
}
void SetNetworkPara(CNetEnvSetting* pnetwork, PEmboBaseInfo pEmboBaseInfo_In)
{
/*
(LPSTR)g_baseInfo.szNCServerName,
(LPSTR)g_baseInfo.szNCServerDir,
(LPSTR)g_baseInfo.szNCLocalDir,
(LPSTR)g_baseInfo.szNCServerUser,
(LPSTR)g_baseInfo.szNCServerPass))
unsigned char szDUpdatesServerName[MAX_LEN_16]; // DUpdates目标服务器名
unsigned char szDUpdatesServerDir[MAX_LEN_16]; // DUpdates目标服务器上的共享目录名
unsigned char szDUpdatesLocalDir[MAX_LEN_16]; // DUpdates本地计算机的映射目录名
unsigned char szDUpdatesServerUser[MAX_LEN_16]; // DUpdates目标服务器的登陆名
unsigned char szDUpdatesServerPass[MAX_LEN_16]; // DUpdates目标服务器的登陆密码
TCHAR ServerName[NAME_LENGTH];
TCHAR RemoteShared[NAME_LENGTH];
TCHAR NetworkSubFolder[NAME_LENGTH];
TCHAR UserName[NAME_LENGTH];
TCHAR Password[NAME_LENGTH];
*/
////////////////////////////////First get from loader
TCHAR buffer[MAX_PATH];
// Get szDUpdatesServerName ///////////////////////////////////
memset(buffer, 0, sizeof buffer);
mbstowcs((LPTSTR)buffer,(LPSTR)pEmboBaseInfo_In->szDUpdatesServerName, MAX_LEN_16);
if(buffer[0]==NULL)
{
memset(buffer, 0, sizeof buffer);
mbstowcs((LPTSTR)buffer,(LPSTR)pEmboBaseInfo_In->szNCServerName, MAX_LEN_16);
}
wcscpy(pnetwork->ServerName, buffer);
dwRegResult=RegOpenKeyEx(HKEY_LOCAL_MACHINE,REG_KEY_EMBO_DUPDATES,0,0,&hKey);
if(ERROR_SUCCESS==dwRegResult)
{
dwRegValueLength=MAX_PATH;
dwRegResult=RegQueryValueEx(hKey,TEXT("DUpdatesServerName"),0,&dwRegValueType,NULL,&dwRegValueLength);
if(ERROR_SUCCESS==dwRegResult)
{
dwRegResult=RegQueryValueEx(hKey,TEXT("DUpdatesServerName"),0,&dwRegValueType,(LPBYTE)pnetwork->ServerName,&dwRegValueLength);
}
RegCloseKey(hKey);
}
// Get szDUpdatesServerDir ///////////////////////////////////
memset(buffer, 0, sizeof buffer);
mbstowcs((LPTSTR)buffer,(LPSTR)pEmboBaseInfo_In->szDUpdatesServerDir, MAX_LEN_16);
if(buffer[0]==NULL)
{
memset(buffer, 0, sizeof buffer);
mbstowcs((LPTSTR)buffer,(LPSTR)pEmboBaseInfo_In->szNCServerDir, MAX_LEN_16);
}
wcscpy(pnetwork->RemoteShared, buffer);
dwRegResult=RegOpenKeyEx(HKEY_LOCAL_MACHINE,REG_KEY_EMBO_DUPDATES,0,0,&hKey);
if(ERROR_SUCCESS==dwRegResult)
{
dwRegValueLength=MAX_PATH;
dwRegResult=RegQueryValueEx(hKey,TEXT("DUpdatesServerDir"),0,&dwRegValueType,NULL,&dwRegValueLength);
if(ERROR_SUCCESS==dwRegResult)
{
dwRegResult=RegQueryValueEx(hKey,TEXT("DUpdatesServerDir"),0,&dwRegValueType,(LPBYTE)pnetwork->RemoteShared,&dwRegValueLength);
}
RegCloseKey(hKey);
}
// Get szDUpdatesLocalDir ///////////////////////////////////
memset(buffer, 0, sizeof buffer);
mbstowcs((LPTSTR)buffer,(LPSTR)pEmboBaseInfo_In->szDUpdatesLocalDir, MAX_LEN_16);
if(buffer[0]==NULL)
{
memset(buffer, 0, sizeof buffer);
mbstowcs((LPTSTR)buffer,(LPSTR)pEmboBaseInfo_In->szNCLocalDir, MAX_LEN_16);
}
wcscpy(pnetwork->NetworkSubFolder, buffer);
dwRegResult=RegOpenKeyEx(HKEY_LOCAL_MACHINE,REG_KEY_EMBO_DUPDATES,0,0,&hKey);
if(ERROR_SUCCESS==dwRegResult)
{
dwRegValueLength=MAX_PATH;
dwRegResult=RegQueryValueEx(hKey,TEXT("DUpdatesLocalDir"),0,&dwRegValueType,NULL,&dwRegValueLength);
if(ERROR_SUCCESS==dwRegResult)
{
dwRegResult=RegQueryValueEx(hKey,TEXT("DUpdatesLocalDir"),0,&dwRegValueType,(LPBYTE)pnetwork->NetworkSubFolder,&dwRegValueLength);
}
RegCloseKey(hKey);
}
// Get szDUpdatesServerUser ///////////////////////////////////
memset(buffer, 0, sizeof buffer);
mbstowcs((LPTSTR)buffer,(LPSTR)pEmboBaseInfo_In->szDUpdatesServerUser, MAX_LEN_16);
if(buffer[0]==NULL)
{
memset(buffer, 0, sizeof buffer);
mbstowcs((LPTSTR)buffer,(LPSTR)pEmboBaseInfo_In->szNCServerUser, MAX_LEN_16);
}
wcscpy(pnetwork->UserName, buffer);
dwRegResult=RegOpenKeyEx(HKEY_LOCAL_MACHINE,REG_KEY_EMBO_DUPDATES,0,0,&hKey);
if(ERROR_SUCCESS==dwRegResult)
{
dwRegValueLength=MAX_PATH;
dwRegResult=RegQueryValueEx(hKey,TEXT("DUpdatesServerUser"),0,&dwRegValueType,NULL,&dwRegValueLength);
if(ERROR_SUCCESS==dwRegResult)
{
dwRegResult=RegQueryValueEx(hKey,TEXT("DUpdatesServerUser"),0,&dwRegValueType,(LPBYTE)pnetwork->UserName,&dwRegValueLength);
}
RegCloseKey(hKey);
}
// Get szDUpdatesServerPassword ///////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -