Example #1
0
void OnInitNetDetailsDialog(HWND hwndDlg)
{
    PIP_ADAPTER_INFO    pAdapterInfo = NULL, pAdapterInfoHead = NULL;
    PFIXED_INFO         pNetworkParams = NULL;
    PIP_ADDR_STRING pDnsServer = NULL;
    ULONG               ulBufferSize = 0;
    DWORD               dwRetVal;
    HRESULT             hr = S_OK;
    DWORD               i;
    WCHAR               szIpAddr[MAX_IP_FIELD_WIDTH];
    WCHAR               szGateway[MAX_IP_FIELD_WIDTH];
    WCHAR               szSubnetMsk[MAX_IP_FIELD_WIDTH];
    WCHAR               szDHCPServer[MAX_IP_FIELD_WIDTH];
    WCHAR               szPhysicalAddr[MAX_WZCPHYSADDR_STR];
    WCHAR               szLeaseObtained[MAX_WZCIPCFGMISC_STR];
    WCHAR               szLeaseExpires[MAX_WZCIPCFGMISC_STR];
    WCHAR               szDNS1[MAX_IP_FIELD_WIDTH];
    WCHAR               szDNS2[MAX_IP_FIELD_WIDTH];
    WCHAR               szWINS1[MAX_IP_FIELD_WIDTH];
    WCHAR               szWINS2[MAX_IP_FIELD_WIDTH];
    WCHAR*				pTime;
    FILETIME            LeaseObtained, LeaseObtainedLocal;
    SYSTEMTIME          SysLeaseObtained;
    FILETIME            LeaseExpires, LeaseExpiresLocal;
    SYSTEMTIME          SysLeaseExpires;
    LV_COLUMN           lvCol = {0};
    RECT                rect;
    int                 iParamColWidth = 0; 
    TCHAR               szProperty[MAX_WZCIPCFGMISC_STR];
    int                 iIndex = 0;
    HWND                hList = GetDlgItem(hwndDlg, IDC_LIST_IPCFG);

    // Get IP adapter info
    hr = GetIPAdapterInfo(hwndDlg, &pAdapterInfoHead, &pAdapterInfo);
    if (FAILED(hr)) {
        DEBUGMSG(ZONE_ERROR, (TEXT("NETUIQC: Could not get the adapter info")));
        goto exit;
    }

    // Get IP data from iphelper

    wsprintf(szPhysicalAddr, TEXT("%02X"), pAdapterInfo->Address[0]);
    for (i=1;i<pAdapterInfo->AddressLength;i++) {
        wsprintf(szPhysicalAddr, TEXT("%s %02X"), szPhysicalAddr, pAdapterInfo->Address[i]);
    }

    mbstowcs(szIpAddr, pAdapterInfo->IpAddressList.IpAddress.String, strlen(pAdapterInfo->IpAddressList.IpAddress.String)+1);
    mbstowcs(szGateway, pAdapterInfo->GatewayList.IpAddress.String, strlen(pAdapterInfo->GatewayList.IpAddress.String)+1);
    mbstowcs(szSubnetMsk, pAdapterInfo->IpAddressList.IpMask.String, strlen(pAdapterInfo->IpAddressList.IpMask.String)+1);  
    mbstowcs(szDHCPServer, pAdapterInfo->DhcpServer.IpAddress.String, strlen(pAdapterInfo->DhcpServer.IpAddress.String)+1);
    mbstowcs(szWINS1, pAdapterInfo->PrimaryWinsServer.IpAddress.String, strlen(pAdapterInfo->PrimaryWinsServer.IpAddress.String)+1);
    mbstowcs(szWINS2, pAdapterInfo->SecondaryWinsServer.IpAddress.String, strlen(pAdapterInfo->SecondaryWinsServer.IpAddress.String)+1);

	// Get system time for lease obtained
    TimeToFileTime(pAdapterInfo->LeaseObtained, &LeaseObtained);
    FileTimeToLocalFileTime(&LeaseObtained, &LeaseObtainedLocal);    
    FileTimeToSystemTime(&LeaseObtainedLocal, &SysLeaseObtained);

	// Format string for lease obtained
    GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &SysLeaseObtained, NULL, szLeaseObtained, MAX_WZCIPCFGMISC_STR);
	wcscat(szLeaseObtained, TEXT(" "));
	pTime = szLeaseObtained + wcslen(szLeaseObtained); // Advance pointer to append time
	GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOTIMEMARKER, &SysLeaseObtained, NULL, pTime, (MAX_WZCIPCFGMISC_STR - wcslen(pTime)));

	// Get system time for lease expiry
    TimeToFileTime(pAdapterInfo->LeaseExpires, &LeaseExpires);
    FileTimeToLocalFileTime(&LeaseExpires, &LeaseExpiresLocal);    
    FileTimeToSystemTime(&LeaseExpiresLocal, &SysLeaseExpires);

	// Format string for lease expiry
    GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &SysLeaseExpires, NULL, szLeaseExpires, MAX_WZCIPCFGMISC_STR);
	wcscat(szLeaseExpires, TEXT(" "));
	pTime = szLeaseExpires + wcslen(szLeaseExpires); // Advance pointer to append time
	GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOTIMEMARKER, &SysLeaseExpires, NULL, pTime, (MAX_WZCIPCFGMISC_STR - wcslen(pTime)));

    // Get Network params struct for DNS servers
    dwRetVal = GetNetworkParams(pNetworkParams, &ulBufferSize);
    if (dwRetVal == ERROR_BUFFER_OVERFLOW) {
        pNetworkParams = (PFIXED_INFO)malloc(ulBufferSize);
        if (pNetworkParams == NULL) {
            DEBUGMSG(ZONE_ERROR, (TEXT("NETUIQC: Could not allocate memory for network params")));
            goto exit;
        }

        dwRetVal = GetNetworkParams(pNetworkParams, &ulBufferSize);
        if (dwRetVal != ERROR_SUCCESS) {
            DEBUGMSG(ZONE_ERROR, (TEXT("NETUIQC: Could not get network params")));
            goto exit;
        }
    } else if (dwRetVal != ERROR_SUCCESS) {
        DEBUGMSG(ZONE_ERROR, (TEXT("NETUIQC: Could not get network params")));
        goto exit;
    }

    if (pNetworkParams == NULL) {
        DEBUGMSG(ZONE_ERROR, (TEXT("NETUIQC: Could not get network params")));
        goto exit;
    }

    // Get DNS Servers
    pDnsServer = &(pNetworkParams->DnsServerList);
    mbstowcs(szDNS1, pDnsServer->IpAddress.String, strlen(pDnsServer->IpAddress.String)+1);
    pDnsServer = pDnsServer->Next;
    if (pDnsServer != NULL) {
        mbstowcs(szDNS2, pDnsServer->IpAddress.String, strlen(pDnsServer->IpAddress.String)+1); 
    } else {
        szDNS2[0] = 0;
    }

    // Update UI
    mbstowcs(szProperty,pAdapterInfo->AdapterName,strlen(pAdapterInfo->AdapterName)+1);
    SetWindowText(hwndDlg,szProperty);

    GetClientRect(hList, &rect);
    iParamColWidth = (rect.right/2);
    
    lvCol.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT ;
    lvCol.fmt = LVCFMT_LEFT;   // left-align column
    lvCol.cx = iParamColWidth;

    if (LoadString(v_hInst, IDS_IPCFG_PRAMETER,szProperty,sizeof(szProperty)/sizeof(szProperty[0]))) {
        lvCol.pszText = szProperty;
        iIndex = ListView_InsertColumn(hList, iIndex, &lvCol);
        iIndex++;
    }

    if (LoadString(v_hInst, IDS_IPCFG_VALUE,szProperty,sizeof(szProperty)/sizeof(szProperty[0]))) {
        lvCol.cx      = rect.right - iParamColWidth;
        lvCol.pszText = szProperty;
        iIndex = ListView_InsertColumn(hList, iIndex, &lvCol);
    }

    ListView_SetExtendedListViewStyle(hList, LVS_EX_FULLROWSELECT);

    iIndex=0;
    if (LoadString(v_hInst,IDS_IPCFG_PH_ADDR,szProperty,sizeof(szProperty)/sizeof(szProperty[0])))
        AddToListControl(hList, iIndex++, szProperty, szPhysicalAddr);
    if (LoadString(v_hInst,IDS_IPCFG_IPADDR,szProperty,sizeof(szProperty)/sizeof(szProperty[0])))
        AddToListControl(hList, iIndex++, szProperty, szIpAddr);
    if (LoadString(v_hInst,IDS_IPCFG_SUBNET,szProperty,sizeof(szProperty)/sizeof(szProperty[0])))
        AddToListControl(hList, iIndex++, szProperty, szSubnetMsk);
    if (LoadString(v_hInst,IDS_IPCFG_DEFGW,szProperty,sizeof(szProperty)/sizeof(szProperty[0])))
        AddToListControl(hList, iIndex++, szProperty, szGateway);
    if (LoadString(v_hInst,IDS_IPCFG_DHCP,szProperty,sizeof(szProperty)/sizeof(szProperty[0])))
        AddToListControl(hList, iIndex++, szProperty, szDHCPServer);
    if (LoadString(v_hInst,IDS_IPCFG_LEASE_OBT,szProperty,sizeof(szProperty)/sizeof(szProperty[0])))
        AddToListControl(hList, iIndex++, szProperty, szLeaseObtained);
    if (LoadString(v_hInst,IDS_IPCFG_LEASE_EXP,szProperty,sizeof(szProperty)/sizeof(szProperty[0])))
        AddToListControl(hList, iIndex++, szProperty, szLeaseExpires);
    if (LoadString(v_hInst,IDS_IPCFG_DNSSERVERS,szProperty,sizeof(szProperty)/sizeof(szProperty[0]))) {
        AddToListControl(hList, iIndex++, szProperty, szDNS1);
        AddToListControl(hList, iIndex++, L"", szDNS2);
    }
    if (LoadString(v_hInst,IDS_IPCFG_WINSSERVERS,szProperty,sizeof(szProperty)/sizeof(szProperty[0]))) {
        AddToListControl(hList, iIndex++, szProperty, szWINS1);
        AddToListControl(hList, iIndex++, L"", szWINS2);
    }

    exit:
    if (pAdapterInfoHead) {
        free(pAdapterInfoHead);
    }
    if (pNetworkParams) {
        free(pNetworkParams);
    }

    return; 

} // OnInitNetDetailsDialog
Example #2
0
bool FileSetTime(const char *filename, Time time)
{
	return SetFileTime(filename, TimeToFileTime(time));
}
Example #3
0
gbool GUrlCache::CopyFile(const CString &srcFilePath,const CString &destFilePath,gbool checkDir,time_t creationTime)
{
    DWORD err;
    CString dir;
    BOOL ret=FALSE;

    Lock();
    do {
        if (checkDir) {
            // get home path
            const char *path=destFilePath;
            const char *s;

            s=strrchr(path,'\\'); // for file:  URLĀ“s
            const char *s1=strrchr(path,'/');
            if (s1>s ) s = s1;
            if (s)
                dir =CString(path,s-path+1);
            else {
                dir = "";
                break;
            }
            if (!CreateDirectory(dir)) {
                err = GetLastError();
                TRACE("CreateDirectory failed with %d \n",err);
            }

        }

        if (::CopyFile(srcFilePath,destFilePath,FALSE))	{
            ret = TRUE;
            if (creationTime>0) { // set the creation & modifed date

                // CopyFile seems to take date of IE/NS Cache File

                CTime t(creationTime);
                FILETIME ft;
                FILETIME mft;
                if ( TimeToFileTime(t, &ft)) {

                    HANDLE f = CreateFile(destFilePath,GENERIC_READ|GENERIC_WRITE ,FILE_SHARE_READ,
                                          NULL,	 // address of security descriptor,
                                          OPEN_EXISTING,
                                          FILE_ATTRIBUTE_NORMAL,NULL);

                    if  (f == INVALID_HANDLE_VALUE) {
                        err = GetLastError();
                        ret = FALSE;
                    } else {

                        GetSystemTimeAsFileTime(&mft); // set to current time

                        if (!::SetFileTime(f,/* CreationTime */ &ft,&mft,&mft)) {
                            err = GetLastError();
                            TRACE("SetFileTime  failed with %d \n",err);
                            ASSERT(0);
                            ret = FALSE;
                        }
                        CloseHandle(f);

                    }
                }
            }

        }
        else {
            ret = FALSE;

        }
    } while (0);

    Unlock();

    if (!ret) {
        err = GetLastError();
        LPVOID lpMsgBuf=NULL;

        ::FormatMessage(
            FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
            NULL,
            GetLastError(),
            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
            (LPTSTR) &lpMsgBuf,
            0,
            NULL
        );




        TRACE("Copy file %s %s failed with %d (%s) \n",(const char *) srcFilePath,(const char *) destFilePath,err,(const char *) lpMsgBuf);
        // Free the buffer.
        if (lpMsgBuf) LocalFree( lpMsgBuf );

        // ERROR_FILE_NOT_FOUND

        //Local filename www.colonycity.com/cgi-bin/games/vrmltime.pl
        //Copy file C:\WINDOWS\Temporary Internet Files\Content.IE5\MLPJ2DHX\vrmltime[1].wrl G:\cc3d\0cache\www.colonycity.com/cgi-bin/games/vrmltime.pl failed with 2

        ASSERT(0);
    }
    return ret;

};