LPMITEMINFO CWinMenu::AddMenuItem( LPCTSTR pName, DWORD dwCmd, HICON hIcon, HCURSOR hCursor, LPBOOL pBool, LPCTSTR pRText, HICON *pRIcons, DWORD dwRIcons ) { // LPMITEMINFO node = new MITEMINFO; // if ( node == NULL ) return NULL; LPMITEMINFO node = (LPMITEMINFO)m_mitems.New( NULL, 0, pName ); if ( node == NULL ) return NULL; // Save item information if ( pName != NULL ) { strcpy_sz( node->name, pName ); } else *node->name = 0x0; node->cmd = dwCmd; node->icon = hIcon; node->bmp = NULL; node->cursor = hCursor; node->b = pBool; if ( pRText != NULL ) { strcpy_sz( node->rtext, pRText ); } else *node->rtext = 0x0; if ( pRIcons != NULL && dwRIcons > 0 ) for ( DWORD i = 0; i < dwRIcons && i < 16; i++ ) node->ricon[ i ] = pRIcons[ i ]; // Is this a sub menu? if ( dwCmd == MAXDWORD ) node->submenu = new CWinMenu(); else node->submenu = NULL; return node; }
HTPAGE CDlgTreeFrame::AddPage(HTPAGE hParent, HICON hIcon, CDialog * pg, DWORD idd, LPCTSTR name, LPCTSTR help, LPCTSTR hlink) { // Sanity checks if ( name == NULL ) return FALSE; // Use top of list if none specified if ( hParent == NULL ) hParent = &m_pg; // Allocate memory LPTREEPAGEINFO node = new TREEPAGEINFO; if ( node == NULL ) return FALSE; ZeroMemory( node, sizeof( TREEPAGEINFO ) ); // Save page information node->index = m_dwIndex++; node->icon = hIcon; node->pg = pg; node->idd = idd; if ( name != NULL ) strcpy_sz( node->name, name ); if ( help != NULL ) strcpy_sz( node->help, help ); if ( hlink != NULL ) strcpy_sz( node->hlink, hlink ); // Add this node to the list node->pParent = hParent; node->pNext = NULL; node->pPrev = hParent->pTail; if ( hParent->pTail == NULL ) hParent->pHead = node; else hParent->pTail->pNext = node; hParent->pTail = node; hParent->dwSize++; m_dwSize++; if ( hIcon != NULL ) { // Add icon to image list if ( m_images.GetSafeHandle() == NULL ) m_images.Create( 16, 16, ILC_MASK | ILC_COLOR24, 32, 32 ); // Add this icon m_images.Add( hIcon ); // Count one icon node->iindex = m_dwIcon++; } // end if // No icon else node->iindex = MAXDWORD; return node; }
HGROUP CCfgFile::AddGroup(LPCTSTR pGroup) {_STTEX(); // Does this group already exist? LPCFGGROUPINFO node = FindGroup( pGroup ); if ( node != NULL ) return node; // Create new group node node = new CFGGROUPINFO; if ( node == NULL ) return NULL; ZeroMemory( node, sizeof( CFGGROUPINFO ) ); // Copy group name if ( pGroup != NULL ) { strcpy_sz( node->name, pGroup ); } else *node->name = 0; // Add this node to the list node->pNext = NULL; node->pPrev = m_pTail; if ( m_pTail == NULL ) m_pHead = node; else m_pTail->pNext = node; m_pTail = node; m_dwSize++; return node; }
HTREEITEM CDlgTreeFrame::MakeTreeEntry(LPCTSTR pText, HTREEITEM hParent, DWORD dwImage) { HTREEITEM hItem; TV_INSERTSTRUCT tv; char pszTemp[256]; strcpy_sz( pszTemp, pText ); tv.item.pszText = pszTemp; tv.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE; tv.item.state = 0; tv.item.iImage = dwImage; tv.item.iSelectedImage = dwImage; tv.hInsertAfter = TVI_LAST; if ( hParent != NULL ) tv.hParent = hParent; else tv.hParent = TVI_ROOT; hItem = m_tree.InsertItem( &tv ); // Start expanded if ( hParent != NULL ) m_tree.Expand( hParent, TVE_EXPAND ); return hItem; }
LPVAR CVar::AddVar(LPCTSTR pVar, DWORD dwType, LPVOID pVal, DWORD dwSize) {_STTEX(); // Sanity checks if ( pVar == NULL ) return NULL; // Does the variable already exist? BOOL add = FALSE; LPVAR node = FindVar( pVar ); if ( node != NULL ) { // Delete variable if needed if ( node->size != 0 && node->val != NULL ) { delete [] node->val; node->val = NULL; } // end if } // end if else { // Allocate memory node = (LPVAR)New(); if ( node == NULL ) return NULL; } // end if // Save variable type node->type = dwType; // Copy variable name strcpy_sz( node->name, pVar ); // Copy variable size node->size = dwSize; // Copy the data if ( dwSize == 0 ) node->val = pVal; else { // Allocate variable value memory plus one for NULL char node->val = new LPBYTE[ dwSize + 1 ]; if ( node->val == NULL ) { Delete( node ); return NULL; } // Check for init data if ( pVal == NULL ) ZeroMemory( node->val, dwSize ); // Copy the value else memcpy( node->val, pVal, dwSize ); // NULL terminate for good measure ( (LPBYTE)node->val )[ dwSize ] = 0; } // end else return node; }
LPMIMEBLOCK CMime::AddFile( LPCTSTR pFile, LPBYTE buf, DWORD size, DWORD flags ) {_STT(); // Allocate memory LPMIMEBLOCK node = new MIMEBLOCK; if ( node == NULL ) return NULL; ZeroMimeBlock( node ); // Get the file name if ( pFile != NULL ) { strcpy_sz( node->fname, pFile ); } // Get MIME type GetContentType( node->fname, node->ctype ); // Create Content-Type string char typestr[ MIME_STRSIZE ]; wsprintf( typestr, "%s;\r\n\tname=\"%s\"", node->ctype, node->fname ); // Save header information node->var.AddVar( "Content-Type", typestr ); node->var.AddVar( "Content-Transfer-Encoding", "base64" ); if ( ( flags & MBF1_ATTACHMENT ) != 0 ) { char disp[ MIME_STRSIZE ]; wsprintf( disp, "attachment;\r\n\tfilename=\"%s\"", node->fname ); node->var.AddVar( "Content-Disposition", disp ); } // end if // Save flags node->f1 = flags; node->f1 |= MBF1_DECODED; // Use base64 encoding node->encode = MBEN_BASE64; // Any data? if ( size > 0 ) { // Allocate memory node->pdata = new char[ size + 1 ]; if ( node->pdata == NULL ) { delete node; return FALSE; } // Copy the data memcpy( node->pdata, buf, size ); node->dsize = size; // NULL terminate (just in case) ( (LPBYTE)node->pdata )[ size ] = 0; } // end if return AddBlock( node ); }
void CDlgPublishHtml::OnChooseDir() { char dir[ CWF_STRSIZE ] = { 0 }; strcpy_sz( dir, m_sDir ); // Get folder name if ( !CWinFile::GetBrowseDir( GetSafeHwnd(), "Choose Publish Folder", dir, dir ) ) return; // Save publish folder m_sDir = dir; CFG().SetValue( "Settings", "HtmlPubDir", (LPCTSTR)m_sDir ); UpdateData( FALSE ); }
HRESULT CWinDropTarget::DragEnter(IDataObject *pdto, DWORD grfKeyState, POINTL ptl, DWORD *pdwEffect) {_STT(); // Save drag object m_spdtoDragging = pdto; // Clear previous data *m_szData = 0; if ( m_bPlainTextMode ) { // Check for plain text format STGMEDIUM stgMedium; FORMATETC fmt = { CF_TEXT, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; if ( pdto->GetData( &fmt, &stgMedium ) == S_OK ) { RULIB_TRY { switch ( stgMedium.tymed ) { case TYMED_FILE: // Copy the filename wcstombs( m_szData, stgMedium.lpszFileName, sizeof( m_szData ) ); break; case TYMED_MFPICT: case TYMED_HGLOBAL: { LPCTSTR pStr = (LPCTSTR)GlobalLock( stgMedium.hGlobal ); if ( pStr != NULL ) { strcpy_sz( m_szData, pStr ); GlobalUnlock( stgMedium.hGlobal ); } // end if } break; } // end switch // Release memory ::ReleaseStgMedium( &stgMedium ); } // end try // Catch all RULIB_CATCH_ALL { ASSERT( 0 ); } } // end if } // end if
CNetFile::CNetFile( LPCTSTR pUserAgent ) {_STT(); *m_szUrl = NULL; *m_szLocal = NULL; m_hFile = NULL; m_hInternet = NULL; m_hConnect = NULL; m_pMem = NULL; m_bMem = FALSE; m_dwTransferStatus = 0; m_dwTransferError = 0; m_bCloseFileAfterDownload = FALSE; m_dwDataRead = 0; m_dwBlockSize = 4096; m_dwInetFlags = 0; m_dwOpenFlags = INTERNET_FLAG_RESYNCHRONIZE; m_dwAccessFlags = INTERNET_OPEN_TYPE_PRECONFIG; if ( pUserAgent != NULL ) { strcpy_sz( m_szUserAgent, pUserAgent ); } else strcpy( m_szUserAgent, "WheresJames Software (www_wheresjames_com)" ); m_hWndParent = NULL; m_bUpload = FALSE; m_dwDataWritten = 0; *m_szUsername = 0; *m_szPassword = 0; m_hWndCallback = NULL; m_uMsgCallback = 0; m_pCallback = NULL; m_bPassive = TRUE; m_bGetTotalLength = FALSE; m_dwTotalLength = 0; }
BOOL CDlgProductUpdate::DoUpdateCheck(CWnd *pParent, LPCTSTR pLink, double dVer, BOOL bSilent) { // Lose any current window m_nf.Destroy(); if ( ::IsWindow( GetSafeHwnd() ) ) DestroyWindow(); // Copy data strcpy_sz( m_szLink, pLink ); m_dVer = dVer; m_bSilent = bSilent; // Create the dialog box if ( !Create( CDlgProductUpdate::IDD, pParent ) ) return FALSE; // Show or hide if ( !bSilent ) ShowWindow( SW_SHOWNORMAL ); else ShowWindow( SW_HIDE ); return TRUE; }
LPMIMEBLOCK CMime::AddFile(LPCTSTR pFile, LPCTSTR pName, DWORD flags ) {_STT(); // Sanity checks if ( pFile == NULL ) return FALSE; if ( !CWinFile::DoesExist( pFile ) ) return FALSE; // Open the file CWinFile f; if ( !f.OpenExisting( pFile, GENERIC_READ ) ) return FALSE; DWORD size = f.Size(); // Allocate memory LPMIMEBLOCK node = new MIMEBLOCK; if ( node == NULL ) return NULL; ZeroMimeBlock( node ); // Get the file name if ( pName != NULL ) { strcpy_sz( node->fname, pName ); } else CWinFile::GetFileNameFromPath( pFile, node->fname ); // Get MIME type GetContentType( node->fname, node->ctype ); // Create Content-Type string char typestr[ MIME_STRSIZE ]; wsprintf( typestr, "%s;\r\n\tname=\"%s\"", node->ctype, node->fname ); // Save header information node->var.AddVar( "Content-Type", typestr ); node->var.AddVar( "Content-Transfer-Encoding", "base64" ); if ( ( flags & MBF1_ATTACHMENT ) != 0 ) { char disp[ MIME_STRSIZE ]; wsprintf( disp, "attachment;\r\n\tfilename=\"%s\"", node->fname ); node->var.AddVar( "Content-Disposition", disp ); } // end if // Save flags node->f1 = flags; node->f1 |= MBF1_DECODED; // Use base64 encoding node->encode = MBEN_BASE64; if ( size > 0 ) { // Allocate memory node->pdata = new char[ size + 1 ]; if ( node->pdata == NULL ) { delete node; return FALSE; } // Read in file data if ( !f.Read( node->pdata, size, &node->dsize ) ) { delete [] node->pdata; delete node; return FALSE; } // NULL terminate (just in case) ( (LPBYTE)node->pdata )[ size ] = 0; } // end if return AddBlock( node ); }
LPMIMEBLOCK CMime::Create( LPCTSTR pTo, LPCTSTR pFrom, LPCTSTR pSubject ) {_STT(); // Lose old mime message Destroy(); // Allocate memory for header LPMIMEBLOCK node = new MIMEBLOCK; if ( node == NULL ) return NULL; ZeroMimeBlock( node ); // Header is always first in the list m_header = node; // Fill in header information strcpy_sz( m_header->ctype, "multipart/mixed" ); // Get boundry type GenBoundry( m_header->boundry ); // Add user information // Copy from email list if ( pFrom != NULL && *pFrom != 0 ) { TMem< char > buf; if ( buf.allocate( ( strlen( pFrom ) * 2 ) + 1 ) ) { VerifyEmailList( buf, pFrom, ",\r\n\t" ); m_header->var.AddVar( "From", buf ); } // end if } // end if // Copy to email list if ( pTo != NULL && *pTo != 0 ) { TMem< char > buf; if ( buf.allocate( ( strlen( pTo ) * 2 ) + 1 ) ) { VerifyEmailList( buf, pTo, ",\r\n\t" ); m_header->var.AddVar( "To", buf ); } // end if } // end if // Copy subject if ( pSubject != NULL ) m_header->var.AddVar( "Subject", pSubject ); // add time/date SYSTEMTIME st; GetLocalTime( &st ); // Get time-zone information TIME_ZONE_INFORMATION tzi; ZeroMemory( &tzi, sizeof( tzi ) ); GetTimeZoneInformation( &tzi ); // Change to correct format long hour = tzi.Bias / 60; if ( tzi.Bias < 0 ) tzi.Bias = -tzi.Bias; long min = tzi.Bias % 60; if ( hour <= 12 ) hour = -hour; else if ( hour > 12 ) hour = 24 - hour; char tzone[ MIME_STRSIZE ] = { 0 }; if ( hour < 0 ) wsprintf( tzone, "%03li%02lu", hour, min ); else wsprintf( tzone, "+%02li%02lu", hour, min ); char date[ MIME_STRSIZE ] = { 0 }; wsprintf( date, "%s, %lu %s %lu %02lu:%02lu:%02lu %s", s_days[ st.wDayOfWeek ], st.wDay, s_months[ st.wMonth ], st.wYear, st.wHour, st.wMinute, st.wSecond, tzone ); char tzname[ MIME_STRSIZE ]; wcstombs( tzname, tzi.StandardName, sizeof( tzname ) - 1 ); m_header->var.AddVar( "Date", date ); // end add time/date // Mime version m_header->var.AddVar( "MIME-Version", "1.0" ); char type[ MIME_STRSIZE ]; wsprintf( type, "multipart/mixed;\r\n\tboundary=\"%s\"", m_header->boundry ); m_header->var.AddVar( "Content-Type", type ); // Add X- MIME Data m_header->var.AddVar( "X-Time-Zone", tzname ); char pri[ MIME_STRSIZE ]; wsprintf( pri, "%lu", m_dwPriority ); m_header->var.AddVar( "X-Priority", pri ); m_header->var.AddVar( "X-MIME-Encoder", "WheresJames MIME Encoder (www.wheresjames.com) " MIMEENCODERVERSTR ); // Default message char *msg = "This message is in MIME format. Since your mail\r\n" "reader does not understand this format, some or\r\n" "all of this message may not be legible."; // Add message to header m_header->dsize = strlen( msg ); m_header->pdata = new char[ m_header->dsize + 1 ]; if ( m_header->pdata != NULL ) { memcpy( m_header->pdata, msg, m_header->dsize ); ( (LPBYTE)m_header->pdata )[ m_header->dsize ] = 0; } // end if else m_header->dsize = 0; // Add the node to the list return AddBlock( node ); }
BOOL CNetFile::Download(LPCTSTR pUrl, LPCTSTR pLocal, BOOL bCloseFileAfterDownload, HWND hWndParent) {_STT(); // Lose previous file Destroy(); // Downloading m_bUpload = FALSE; // Save parent window m_hWndParent = hWndParent; // Save close file status m_bCloseFileAfterDownload = bCloseFileAfterDownload; // Sanity check if ( pUrl == NULL || *pUrl == NULL ) return FALSE; // Are we downloading to file or ram? m_bMem = ( pLocal == NULL ); { // Copy the url char buf[ sizeof( m_szUrl ) ]; DWORD size = sizeof( m_szUrl ) - 1; // Is it a local file? if ( GetFileAttributes( pUrl ) == MAXDWORD ) { // Fix the url if ( InternetCanonicalizeUrl( pUrl, buf, &size, 0 ) ) { strcpy_sz( m_szUrl, buf ); } // Copy the url name else strcpy_sz( m_szUrl, pUrl ); } // end if // Copy the local file name else strcpy_sz( m_szUrl, pUrl ); } // end copy url // Is it a local file? if ( GetFileAttributes( m_szUrl ) != MAXDWORD ) { CWinFile file; if ( file.OpenExisting( m_szUrl, GENERIC_READ ) ) { DWORD size = file.Size(); if ( m_bMem ) { // Allocate memory m_pMem = new BYTE[ size + 1 ]; if ( m_pMem == NULL ) { m_dwTransferStatus = NETFILE_DS_ERROR; return FALSE; } // end if // Read in the file if ( !file.Read( m_pMem, size, &m_dwDataRead ) ) { m_dwTransferStatus = NETFILE_DS_ERROR; return FALSE; } // end if // NULL terminate for good measure m_pMem[ size ] = 0; } // end if else { // Where to download the file if ( pLocal != DOWNLOADTEMP ) { strcpy_sz( m_szLocal, pLocal ); } else CWinFile::CreateTemp( m_szLocal ); // Copy the file CopyFile( m_szUrl, m_szLocal, FALSE ); // Open the file if ( !m_local.OpenExisting( m_szLocal, GENERIC_READ | GENERIC_WRITE ) ) { m_dwTransferStatus = NETFILE_DS_ERROR; return FALSE; } // end if // Get the file size m_dwDataRead = m_local.Size(); } // end else // Memory read complete m_dwTransferStatus = NETFILE_DS_DONE; return TRUE; } // end if } // end if if ( !m_bMem ) { // Where to download the file if ( pLocal != DOWNLOADTEMP ) { strcpy_sz( m_szLocal, pLocal ); } else CWinFile::CreateTemp( m_szLocal ); // Create a file to load data if ( !m_local.OpenNew( m_szLocal, GENERIC_READ | GENERIC_WRITE ) ) return FALSE; } // end else // Set status m_dwTransferStatus = NETFILE_DS_INITIALIZING; // Create a thread to download the file if ( !StartThread() ) { Destroy(); m_dwTransferStatus = NETFILE_DS_ERROR; return FALSE; } // end if return TRUE; }
BOOL CCfgFile::AddElement( HGROUP hGroup, LPCTSTR name, DWORD type, DWORD size, LPVOID value ) {_STTEX(); BOOL bNew = FALSE; LPCFGELEMENTINFO node = FindElement( hGroup, name ); // Find the NULL group if ( hGroup == NULL ) { hGroup = VerifyGroup( NULL ); if ( hGroup == NULL ) hGroup = AddGroup( NULL ); if ( hGroup == NULL ) return FALSE; } // end if // Does it already exist if ( node == NULL ) { bNew = TRUE; node = new CFGELEMENTINFO; if ( node == NULL ) return FALSE; } // end if // Lose previous memory else if ( node->size != 0 && node->value != NULL ) delete[] node->value; // Save element name if ( name != NULL ) { strcpy_sz( node->name, name ); } else *node->name = NULL; // Save type and size information node->type = type; node->size = size; // Just store value if size is zero if ( size == 0 ) node->value = value; // Allocate memory if needed else { // Allocate memory for user information node->value = new BYTE[ size + 1 ]; // Punt if no memory if ( node->value == NULL ) { delete node; return FALSE; } // Copy user data if ( value != NULL ) memcpy( node->value, value, size ); else { ZeroMemory( node->value, size ); } // NULL terminate data ( (LPBYTE)node->value )[ size ] = 0; } // end else // Don't add if not new if ( !bNew ) return TRUE; // Add this node to the list node->pNext = NULL; node->pPrev = hGroup->tail; if ( hGroup->tail == NULL ) hGroup->head = node; else hGroup->tail->pNext = node; hGroup->tail = node; hGroup->size++; return TRUE; }
HPARAM CParams::Add(DWORD function, LPCTSTR pParams) {_STT(); // Allocate memory LPPARAMINFO node = (LPPARAMINFO)New(); if ( node == NULL ) return NULL; // Copy the function id node->function = function; // Copy description if any if ( pParams != NULL ) { strcpy_sz( node->pdesc, pParams ); } else return node; char type[ 512 ]; char size[ 512 ]; char name[ 512 ]; char min[ 512 ]; char max[ 512 ]; char def[ 512 ]; char step[ 512 ]; DWORD i = 0; node->n = 0; // Calculate total size needed DWORD sz = 0; while( ( sz = GetParam( &node->pdesc[ i ], type, size, NULL, NULL, NULL, NULL, NULL ) ) != 0 ) { node->n++; node->size += GetParamSize( GetParamType( type ), strtoul( size, NULL, 10 ) ); i += sz; } // end while // Anything to allocate? if ( node->size == 0 || node->n == 0 ) { node->n = 0; node->size = 0; return node; } // end if // Allocate memory for param data node->pdata = new BYTE[ node->size + 1 ]; if ( node->pdata == NULL ) { DeleteObject( node ); return NULL; } // end if ZeroMemory( node->pdata, node->size + 1 ); // Allocate memory for param index node->param = new PARAM[ node->n ]; if ( node->param == NULL ) { DeleteObject( node ); return NULL; } // end if ZeroMemory( node->param, sizeof( PARAM ) * node->n ); // Save param info so it's easy to index i = 0; DWORD p = 0, o = 0; while( ( sz = GetParam( &node->pdesc[ i ], type, size, name, min, max, def, step ) ) != 0 ) { node->param[ p ].type = GetParamType( type ); node->param[ p ].data = &node->pdata[ o ]; node->param[ p ].size = GetParamSize( node->param[ p ].type, strtoul( size, NULL, 10 ) ); o += node->param[ p ].size; strcpy_sz( node->param[ p ].name, name ); if ( *min ) { node->param[ p ].flags |= PFLAG_MIN; node->param[ p ].min = strtod( min, NULL ); } else node->param[ p ].min = 0; strcpy_sz( node->param[ p ].pmin, min ); if ( *max ) { node->param[ p ].flags |= PFLAG_MAX; node->param[ p ].max = strtod( max, NULL ); } else node->param[ p ].max = 0; strcpy_sz( node->param[ p ].pmax, max ); if ( *def ) { node->param[ p ].flags |= PFLAG_DEF; node->param[ p ].def = strtod( def, NULL ); } else node->param[ p ].def = 0; strcpy_sz( node->param[ p ].pdef, def ); if ( *step ) { node->param[ p ].flags |= PFLAG_STEP; node->param[ p ].step = strtod( step, NULL ); } else node->param[ p ].step = 0; strcpy_sz( node->param[ p ].pstep, step ); // Set default value SetValue( node, p, GetDef( node, p ) ); p++; i += sz; } // end while // We're ready return node; }
BOOL CNetFile::Upload(LPCTSTR pUrl, LPCTSTR pLocal, BOOL bPassive) {_STT(); // Stop whatever else we were doing if ( pLocal != NULL ) Destroy(); // Uploading file m_bUpload = TRUE; m_dwDataWritten = 0; m_bPassive = bPassive; // Save parent window m_hWndParent = NULL; // Sanity check if ( pUrl == NULL || *pUrl == NULL ) return FALSE; // Are we downloading to file or ram? m_bMem = ( pLocal == NULL ); { // Copy the url char buf[ sizeof( m_szUrl ) ]; DWORD size = sizeof( m_szUrl ) - 1; // Is it a local file? if ( GetFileAttributes( pUrl ) == MAXDWORD ) { // Fix the url if ( InternetCanonicalizeUrl( pUrl, buf, &size, 0 ) ) { strcpy_sz( m_szUrl, buf ); } // Copy the url name else strcpy_sz( m_szUrl, pUrl ); } // end if // Copy the local file name else strcpy_sz( m_szUrl, pUrl ); } // end copy url if ( !m_bMem ) { // Where to download the file if ( pLocal != DOWNLOADTEMP ) { strcpy_sz( m_szLocal, pLocal ); } else CWinFile::CreateTemp( m_szLocal ); // Create a file to load data if ( !m_local.OpenExisting( m_szLocal, GENERIC_READ | GENERIC_WRITE ) ) return FALSE; } // end else // Set status m_dwTransferStatus = NETFILE_DS_INITIALIZING; // Create a thread to download the file if ( !StartThread() ) { Destroy(); m_dwTransferStatus = NETFILE_DS_INITIALIZING; return FALSE; } // end if return TRUE; }
DWORD CReg::ProcessLine(LPBYTE buf, DWORD size) {_STTEX(); DWORD i = 0; // Check for key name if ( buf[ i ] == '[' ) { i++; // Skip '[' // Allocate memory LPBYTE name = new BYTE[ size + 1 ]; if ( name == NULL ) return 0; // Read key name DWORD x = 0; while ( i < size && buf[ i ] != 0 && buf[ i ] != ']' && buf[ i ] >= ' ' && buf[ i ] <= '~' ) name[ x++ ] = buf[ i++ ]; name[ x ] = 0; // Add this key m_pCurKey = AddKey( (char*)name ); delete [] name; // Skip line i = NextLine( buf, size, i ); return i; } // end if // Allocate scratch memory LPBYTE data = new BYTE[ size + 1 ]; if ( data == NULL ) return 0; // Old file type if ( m_pCurKey == NULL ) { // Get name i += GetToken( data, size, &buf[ i ], size, '=' ); // skip '=' i++; char value[ 1024 ]; CWinFile::GetFileNameFromPath( (char*)data, value ); CWinFile::GetPathFromFileName( (char*)data, (char*)data ); // Create key LPREGKEY prf = AddKey( (char*)data ); // Check for NULL value if ( buf[ i ] != '=' ) prf->key->Set( value, "" ); else { // Get the data i += GetToken( data, size, &buf[ i ], size - i, 0 ); // Check for default value if ( *value == '@' ) prf->key->Set( "", (char*)data ); // Add string prf->key->Set( value, (char*)data ); } // end else } // end if else { BOOL bDefault = ( buf[ i ] == '@' ); // Get name i += GetToken( data, size, &buf[ i ], size - i, '=' ); // Check for NULL value if ( buf[ i ] != '=' ) m_pCurKey->key->Add( REG_SZ, (LPCTSTR)data, "", 0 ); else { // skip '=' i++; char value[ 1024 ]; if ( bDefault ) *value = 0; else strcpy_sz( value, (char*)data ); DWORD dsize = size, type = 0; DWORD c = ConvertData( &type, data, &dsize, &buf[ i ], size - i ); i += c; // Add reg value m_pCurKey->key->Add( type, value, data, dsize ); } // end else } // end else // Release memory delete [] data; // Next line i = NextLine( buf, size, i ); return i; }
BOOL CNetFile::HttpRequest(LPCTSTR pUrl, CRKey *pHeaders, CRKey *pData, LPCTSTR pMethod, LPCTSTR pLocal, BOOL bCloseFileAfterDownload, HWND hWndParent, DWORD dwUrlEncoding) {_STT(); // Lose previous file Destroy(); // Downloading m_bUpload = FALSE; // Save parent window m_hWndParent = hWndParent; // Save close file status m_bCloseFileAfterDownload = bCloseFileAfterDownload; // Sanity check if ( pUrl == NULL || *pUrl == NULL ) return FALSE; // Are we downloading to file or ram? m_bMem = ( pLocal == NULL ); { // Copy the url char buf[ sizeof( m_szUrl ) ] = { 0 }; DWORD size = sizeof( m_szUrl ) - 1; // Is it a local file? if ( GetFileAttributes( pUrl ) == MAXDWORD ) { // Fix the url if ( InternetCanonicalizeUrl( pUrl, buf, &size, 0 ) ) { strcpy_sz( m_szUrl, buf ); } // Copy the url name else strcpy_sz( m_szUrl, pUrl ); } // end if // Copy the local file name else strcpy_sz( m_szUrl, pUrl ); } // end copy url if ( !m_bMem ) { // Where to download the file if ( pLocal != DOWNLOADTEMP ) { strcpy_sz( m_szLocal, pLocal ); } else CWinFile::CreateTemp( m_szLocal ); // Create a file to load data if ( !m_local.OpenNew( m_szLocal, GENERIC_READ | GENERIC_WRITE ) ) return FALSE; } // end else // Set status m_dwTransferStatus = NETFILE_DS_INITIALIZING; // Save request method if ( pMethod == NULL || *pMethod == 0 ) m_sMethod = "POST"; else m_sMethod = pMethod; // Set data DWORD dwContentLength = 0; if ( pData != NULL ) { CPipe pipe; pData->EncodeUrl( &pipe, dwUrlEncoding ); m_sData.copy( (LPCTSTR)pipe.GetBuffer(), pipe.GetBufferSize() ); dwContentLength = pipe.GetBufferSize(); } // end if // Set headers if ( strcmpi( m_sMethod, "GET" ) ) { CRKey rkHeaders; if ( pHeaders != NULL ) rkHeaders.Copy( pHeaders ); rkHeaders.Set( "Content-Type", "application/x-www-form-urlencoded" ); rkHeaders.Set( "Content-Length", dwContentLength ); CPipe pipe; rkHeaders.EncodeHttpHeaders( &pipe ); m_sHeaders.copy( (LPCTSTR)pipe.GetBuffer(), pipe.GetBufferSize() ); } // end if // Create a thread to download the file if ( !StartThread() ) { Destroy(); m_dwTransferStatus = NETFILE_DS_ERROR; return FALSE; } // end if return TRUE; }