OpAddWebFolders Class Reference

#include <inetop.h>

Inheritance diagram for OpAddWebFolders:

Operation MessageHandler ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 OpAddWebFolders ()
 ~OpAddWebFolders ()
 OpAddWebFolders destructor.
virtual void Do (OpDescriptor *)
virtual BOOL OnIdleEvent ()
 
  • idle time polling loop; continues until either the download completes or the operation is terminated on receiving a death message. Different actions are taken according to the state of the download on completion (succeeded/aborted/failed)

virtual void DoWithParam (OpDescriptor *pOp, OpParam *pAddWebFoldersParam)
 attempts to download asynchronously the main web clipart index file, and if this succeeds it goes on to parse it and launch separate downloads for each of the catalog files referenced by the index
virtual BOOL OnDeathMsg ()
 
  • aborts the download (so that we won't leak resources) and ends the op on Webster exit


Static Public Member Functions

static BOOL Init ()
 Creates an OpDescriptor for an OpAddWebFolders operation.
static OpState GetState (String_256 *, OpDescriptor *)
 Returns the OpState of the OpAddWebFolders operation.

Public Attributes

AddWebFoldersParampParam

Static Public Attributes

static BOOL Success [8]

Protected Attributes

DOWNLOAD_HANDLE m_hDownload

Detailed Description

Definition at line 475 of file inetop.h.


Constructor & Destructor Documentation

OpAddWebFolders::OpAddWebFolders  ) 
 

Definition at line 864 of file inetop.cpp.

00865 {
00866     pParam = NULL;
00867     GetApplication()->RegisterIdleProcessor(IDLEPRIORITY_LOW, this);
00868     OpFlags.HasOwnTimeIndicator = TRUE;
00869     m_hDownload = 0;
00870 }       

OpAddWebFolders::~OpAddWebFolders  ) 
 

OpAddWebFolders destructor.

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/12/96
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 887 of file inetop.cpp.

00888 {
00889     GetApplication()->RemoveIdleProcessor(IDLEPRIORITY_LOW, this);
00890     if (pParam)
00891         delete pParam;
00892 }


Member Function Documentation

void OpAddWebFolders::Do OpDescriptor NotUsed  )  [virtual]
 

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/3/95
Parameters:
OpAddWebFolders (unused) [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: Always fails - should not be called

See also:
-

Reimplemented from Operation.

Definition at line 953 of file inetop.cpp.

00954 {
00955     ERROR3("OpAddWebFolders does not provide a Do() function - Use DoWithParam");
00956     End();
00957 }

void OpAddWebFolders::DoWithParam OpDescriptor pOp,
OpParam pAddWebFoldersParam
[virtual]
 

attempts to download asynchronously the main web clipart index file, and if this succeeds it goes on to parse it and launch separate downloads for each of the catalog files referenced by the index

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/01/97
Parameters:
pOp - OpDescriptor as for all Do() functions [INPUTS] pAddWebFoldersParam - pointer to AddWebFoldersParam structure
- none [OUTPUTS]
Returns:
-

Reimplemented from Operation.

Definition at line 975 of file inetop.cpp.

00976 {
00977     AddWebFoldersParam *pInfo = (AddWebFoldersParam*) pAddWebFoldersParam;
00978     if (pInfo == NULL)
00979     {
00980         ERROR3("OpAddWebFolders called with NULL info pointer");
00981         goto FAIL;
00982     }
00983     else
00984     {
00985         if (!pInfo->localFile.IsValid() || pInfo->strURL.IsEmpty() || !pInfo->pLibGal)
00986         {
00987             ERROR3("OpAddWebFolders: invalid parameters");
00988             goto FAIL;
00989         }
00990         // Register the file for download
00991         DOWNLOADINFO downloadInfo;
00992         downloadInfo.strURL = pInfo->strURL;
00993         downloadInfo.strLocalFile = (String_256) pInfo->localFile.GetPath();
00994         downloadInfo.nFileType = TYPE_CATALOG;
00995         downloadInfo.nPriority = AsynchDownload::PRIORITY_NORMAL;
00996         downloadInfo.bHasProgressDlg = TRUE;
00997         downloadInfo.hwndNotifyWindow = 0;
00998         downloadInfo.lNotifyToken = 0;
00999         m_hDownload = InternetManager::RegisterDownload(&downloadInfo);
01000         if (!m_hDownload || m_hDownload == (DOWNLOAD_HANDLE) INVALID_HANDLE_VALUE)
01001         {
01002             InformError(_R(IDS_CATALOGDOWNLOADFAILED), _R(IDS_OK));
01003             goto FAIL;
01004         }
01005         pParam = pInfo;
01006     }
01007     // Make some optimistic assumptions...
01008     Success[pParam->type] = TRUE; 
01009     return;
01010 
01011 FAIL:
01012     Success[pParam->type] = FALSE; 
01013     FailAndExecute(); 
01014     End();
01015 }

OpState OpAddWebFolders::GetState String_256 pString,
OpDescriptor pOpDesc
[static]
 

Returns the OpState of the OpAddWebFolders operation.

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/12/96
See also:

Definition at line 932 of file inetop.cpp.

00933 {
00934     OpState OpSt;
00935     return(OpSt);
00936 }

BOOL OpAddWebFolders::Init void   )  [static]
 

Creates an OpDescriptor for an OpAddWebFolders operation.

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/12/96
Returns:
FALSE if it fails (due to lack of memory)
See also:

Reimplemented from SimpleCCObject.

Definition at line 906 of file inetop.cpp.

00907 {  
00908     return RegisterOpDescriptor(
00909         0,                              // Tool ID
00910         _R(IDS_OPADDWEBFOLDERS),                // String resource ID
00911         CC_RUNTIME_CLASS(OpAddWebFolders),  // Runtime class
00912         OPTOKEN_OPADDWEBFOLDERS,            // Token string
00913         OpAddWebFolders::GetState,          // GetState function
00914         0,                              // Help ID
00915         0,                              // Bubble ID
00916         0,                              // Resource ID
00917         0                               // Control ID
00918     );
00919 }   

BOOL OpAddWebFolders::OnDeathMsg void   )  [virtual]
 

  • aborts the download (so that we won't leak resources) and ends the op on Webster exit

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/01/97
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
- always TRUE

Reimplemented from MessageHandler.

Definition at line 1030 of file inetop.cpp.

01031 {
01032     InternetManager::UnregisterDownload(m_hDownload);
01033     End();
01034     return TRUE;
01035 }

BOOL OpAddWebFolders::OnIdleEvent void   )  [virtual]
 

  • idle time polling loop; continues until either the download completes or the operation is terminated on receiving a death message. Different actions are taken according to the state of the download on completion (succeeded/aborted/failed)

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/01/97
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
- TRUE if we want to continue polling, FALSE otherwise

Reimplemented from Operation.

Definition at line 1055 of file inetop.cpp.

01056 {
01057     ERROR2IF(!pParam, FALSE, "Unexpected NULL pointer");
01058     CCDiskFile mainIndex;
01059     switch (InternetManager::GetDownloadState(m_hDownload))
01060     {
01061         case AsynchDownload::STATE_PENDING:
01062             // download pending, so we continue polling
01063             return TRUE;
01064 
01065         case AsynchDownload::STATE_SUCCEEDED:
01066         {
01067             // file has transferred successfully, so we can go on and parse it
01068             if (!mainIndex.open(pParam->localFile,ios::in))
01069             {
01070                 // I/O error - no need to inform the user as CCDiskFile is error reporting by default
01071                 goto FAIL;
01072             }
01073             if (!mainIndex.InitLexer())
01074             {
01075                 String_256 strErrorMsg;
01076                 if (pParam->type == SGLib_ClipArt || pParam->type == SGLib_ClipArt_WebThemes)
01077                     strErrorMsg = _T("Failed to parse web clipart index file - web folders cannot be updated");
01078                 else if (pParam->type == SGLib_Font)
01079                     strErrorMsg = _T("Failed to parse web fonts index file - web folders cannot be updated");
01080                 ERROR2(FALSE,strErrorMsg); 
01081                 goto FAIL;
01082             }
01083             LexTokenType tokType = TOKEN_EOL;   
01084             // Initialise lexing routines, and aspects of the lexer
01085             mainIndex.SetDelimiters("\r\n");            // Set token delimiting characters
01086             mainIndex.SetCommentMarker('#');            // Set comment marker char
01087             mainIndex.SetWhitespace("\t");          // Set whitespace chars
01088             const TCHAR* TokenBuf = mainIndex.GetTokenBuf();    // Token buffer remains constant until lexer deinitialisation
01089             String_256 strFolderName("");
01090             String_256 strRelativePath("");
01091             String_256 strRootURL("");
01092             INT32 nFieldOffset = 0;
01093             INT32 nRecords = 0;
01094             while (tokType != TOKEN_EOF)
01095             {   
01096                 mainIndex.GetToken();
01097                 tokType = mainIndex.GetTokenType();
01098                 if (tokType == TOKEN_NORMAL)
01099                 {
01100                     switch (nFieldOffset)
01101                     {
01102                         case 0: // first field
01103                             strFolderName = TokenBuf;
01104                             break;
01105                         case 1: // second field
01106                             strRelativePath = TokenBuf;
01107                             break;
01108                         case 2: // third field
01109                             strRootURL = TokenBuf;
01110                             break;
01111                         default:
01112                             InformError(_R(IDS_CORRUPTEDINDEXFILE), _R(IDS_OK));
01113                             mainIndex.DeinitLexer();
01114                             goto FAIL;
01115                     }
01116                     if (nFieldOffset == 2) // finished reading a line, so try adding the corresponding library
01117                     {
01118                         // append a slash to the root URL if necessary
01119                         if (camStrstr((TCHAR*) strRootURL, _T("file://")))
01120                         {
01121                             if (strRootURL[strRootURL.Length() - 1] != _T('\\'))
01122                                 strRootURL += _T('\\');
01123                         }
01124                         else if (strRootURL[strRootURL.Length() - 1] != _T('/'))
01125                             strRootURL += _T('/');
01126                         Library::URLBase = strRootURL; // set the base URL (this is a static variable at present)
01127                         OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(OpAddWebLibrary));
01128                         if (pOpDesc != NULL)
01129                         {
01130                             AddWebFoldersParam* Param = NULL;
01131                             try
01132                             {
01133                                 Param = new AddWebFoldersParam;
01134                             }
01135                             catch (CMemoryException* pExc)
01136                             {
01137                                 pExc->Delete();
01138                                 Error::SetError(_R(IDS_OUT_OF_MEMORY));
01139                                 InformError();
01140                                 mainIndex.DeinitLexer();
01141                                 goto FAIL;
01142                             }
01143                             // Set up the web library's param
01144                             Param->localFile.SetPathName((TCHAR *) MakeLocalPath(strRelativePath)); // local path of catalog file
01145                             // We change the file extention from .txt to .tmp to avoid overwriting the old one - if any - so that we can compare
01146                             // their sizes and figure out if the web catalog has been modified since the last download
01147                             ERROR3IF(Param->localFile.GetType() != _T("txt") && Param->localFile.GetType() != _T("TXT"),
01148                                 "Catalog files are expected to have the .txt extention");
01149                             Param->localFile.SetType(String_32(_T("tmp")));
01150                             Param->strURL = MakeURL(strRelativePath, strRootURL); // URL of catalog file on our web server
01151                             Param->pLibGal = pParam->pLibGal; // pass on the pointer to the gallery
01152                             Param->strFolderName = strFolderName;
01153                             Param->type = pParam->type; // pass on the gallery type
01154                             // Invoke the operation
01155                             // This will initiate a download of the catalog file - if it succeeds, the folder will be added to the gallery
01156                             pOpDesc->Invoke((OpParam*) Param);
01157                         }                   
01158                         nRecords++; // we've gone through another record
01159                         nFieldOffset = 0; // reset field pointer
01160                     }
01161                     else
01162                     {
01163                         nFieldOffset++;
01164                     }
01165                 }
01166                 else if (tokType == TOKEN_EOL)
01167                 {
01168                     // if the field pointer is not 0, the previous line must have had either less or more than 3 fields - the
01169                     // file might have been corrupted or contains an error, so we skip the rest
01170                     if (nFieldOffset)
01171                     {
01172                         InformError(_R(IDS_CORRUPTEDINDEXFILE), _R(IDS_OK));
01173                         mainIndex.DeinitLexer();
01174                         goto FAIL;
01175                     }
01176                 }
01177             }
01178             // We are now finished with the lexer
01179             mainIndex.DeinitLexer();
01180             mainIndex.close();
01181             // remove the file as we don't need it anymore. Using remove() is OK in this case as the file is not in the cache
01182             _tremove((TCHAR*) String_256(pParam->localFile.GetPath()));
01183             if  (!nRecords) // eof reached without coming across any records - a bit fishy
01184             {
01185                 InformError(_R(IDS_CORRUPTEDINDEXFILE), _R(IDS_OK));
01186                 goto FAIL;
01187             }
01188             // if we got this far we can assume we succeeded
01189             SucceedAndDiscard();
01190             End();
01191             return FALSE;
01192         }
01193 
01194         case AsynchDownload::STATE_FAILED:
01195         {
01196             String_256 strErrorMsg;
01197             strErrorMsg.MakeMsg(_R(IDS_CATALOGDOWNLOADFAILED), (TCHAR*) (String_256) GetStringField((UINT32) pParam->type, _R(IDS_GALLERY_DESCRIPTIONS)),
01198                     (TCHAR*) (String_256) GetStringField((UINT32) pParam->type, _R(IDS_GETX_CAPTIONS)));
01199             Error::SetError(0, strErrorMsg, 0);
01200             InformError();
01201             goto FAIL;
01202         }
01203 
01204         case AsynchDownload::STATE_ABORTED:
01205         {
01206             // no errror message as this state is the result of a user cancel
01207             goto FAIL;
01208         }
01209 
01210         default:
01211             ERROR3("Error or unrecognized state");
01212             goto FAIL;
01213     }
01214 
01215 FAIL:
01216     // Make sure the file is closed so we can delete it
01217     if (mainIndex.isOpen())
01218         mainIndex.close();
01219     _tremove((TCHAR*) String_256(pParam->localFile.GetPath()));
01220     Success[pParam->type] = FALSE; 
01221     FailAndDiscard();
01222     End();
01223     return FALSE;
01224 }


Member Data Documentation

DOWNLOAD_HANDLE OpAddWebFolders::m_hDownload [protected]
 

Definition at line 496 of file inetop.h.

AddWebFoldersParam* OpAddWebFolders::pParam
 

Definition at line 480 of file inetop.h.

BOOL OpAddWebFolders::Success [static]
 

Definition at line 482 of file inetop.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:57:24 2007 for Camelot by  doxygen 1.4.4