OpAddWebLibrary Class Reference

#include <inetop.h>

Inheritance diagram for OpAddWebLibrary:

Operation MessageHandler ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 OpAddWebLibrary ()
 ~OpAddWebLibrary ()
 OpAddWebLibrary 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 library's catalog (xaraclip.txt) file - in case of success a corresponding folder will be added to the clipart gallery
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 OpAddWebLibrary operation.
static OpState GetState (String_256 *, OpDescriptor *)
 Returns the OpState of the OpAddWebLibrary operation.

Public Attributes

AddWebFoldersParampParam

Static Protected Member Functions

static void Suspend ()
static void Resume ()

Protected Attributes

DOWNLOAD_HANDLE m_hDownload

Static Protected Attributes

static BOOL m_bIsSuspended = FALSE
static std::list< DOWNLOAD_HANDLE > m_lstPendingDownloads
static INT32 InstanceCount [8]
static INT32 FoldersAdded [8]
static INT32 ErrorCount [8]
static INT32 CachedFilesUsed [8]

Private Member Functions

 CC_DECLARE_DYNCREATE (OpAddWebLibrary)

Friends

class OpAddWebFolders

Detailed Description

Definition at line 505 of file inetop.h.


Constructor & Destructor Documentation

OpAddWebLibrary::OpAddWebLibrary  ) 
 

Definition at line 1239 of file inetop.cpp.

01240 {
01241     // The instance count is incremented in DoWithParam and not here, as at this point the type of the op is not known
01242     pParam = NULL;
01243     GetApplication()->RegisterIdleProcessor(IDLEPRIORITY_LOW, this);
01244     m_hDownload = 0;
01245     OpFlags.HasOwnTimeIndicator = TRUE;
01246 }       

OpAddWebLibrary::~OpAddWebLibrary  ) 
 

OpAddWebLibrary destructor.

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

Errors: -

See also:
-

Definition at line 1263 of file inetop.cpp.

01264 {
01265     GetApplication()->RemoveIdleProcessor(IDLEPRIORITY_LOW, this);
01266     if (pParam)
01267     {
01268         InstanceCount[pParam->type]--;
01269         delete pParam;
01270     }
01271 }


Member Function Documentation

OpAddWebLibrary::CC_DECLARE_DYNCREATE OpAddWebLibrary   )  [private]
 

void OpAddWebLibrary::Do OpDescriptor NotUsed  )  [virtual]
 

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

Errors: Always fails - should not be called

See also:
-

Reimplemented from Operation.

Definition at line 1333 of file inetop.cpp.

01334 {
01335     ERROR3("OpAddWebLibrary does not provide a Do() function - Use DoWithParam");
01336     End();
01337 }

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

attempts to download asynchronously the library's catalog (xaraclip.txt) file - in case of success a corresponding folder will be added to the clipart gallery

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 1354 of file inetop.cpp.

01355 {
01356     AddWebFoldersParam* pInfo = (AddWebFoldersParam*) pAddWebFoldersParam;
01357     if (pInfo == NULL || m_bIsSuspended) 
01358     {
01359         ERROR3IF(!pInfo, "OpAddWebLibrary called with NULL info pointer");
01360         goto FAIL;
01361     }
01362     else
01363     {
01364         if (!pInfo->localFile.IsValid() || pInfo->strURL.IsEmpty() || pInfo->strFolderName.IsEmpty() || !pInfo->pLibGal)
01365         {
01366             ERROR3("OpAddWebLibrary: invalid parameters");
01367             goto FAIL;
01368         }
01369         // Register the file for download
01370         String_256 strDescription(GetStringField((UINT32) pInfo->type, _R(IDS_GALLERY_DESCRIPTIONS)));
01371         strDescription += String_32(_R(IDS_CATALOGFILE));
01372         DOWNLOADINFO downloadInfo;
01373         downloadInfo.strURL = pInfo->strURL;
01374         downloadInfo.strLocalFile = (String_256) pInfo->localFile.GetPath();
01375         downloadInfo.nFileType = TYPE_CATALOG;
01376         downloadInfo.nPriority = AsynchDownload::PRIORITY_NORMAL;
01377         downloadInfo.strDescription = strDescription;
01378         downloadInfo.bHasProgressDlg = TRUE;
01379         downloadInfo.hwndNotifyWindow = 0;
01380         downloadInfo.lNotifyToken = 0;
01381         m_hDownload = InternetManager::RegisterDownload(&downloadInfo);
01382         if (!m_hDownload || m_hDownload == (DOWNLOAD_HANDLE) INVALID_HANDLE_VALUE)
01383         {
01384             String_256 strErrorMsg;
01385             strErrorMsg.MakeMsg(_R(IDS_CATALOGDOWNLOADFAILED), (TCHAR*) (String_256) GetStringField((UINT32) pInfo->type, _R(IDS_GALLERY_DESCRIPTIONS)),
01386                     (TCHAR*) (String_256) GetStringField((UINT32) pInfo->type, _R(IDS_GETX_CAPTIONS)));
01387             Error::SetError(0, strErrorMsg, 0);
01388             InformError();
01389         }
01390         else
01391             m_lstPendingDownloads.push_back(m_hDownload);
01392         pParam = pInfo;
01393         InstanceCount[pParam->type]++; // update instance count
01394         if (InstanceCount[pParam->type] == 1) // first instance, reset counters
01395         {
01396             ErrorCount[pParam->type] = 0; 
01397             FoldersAdded[pParam->type] = 0;
01398             CachedFilesUsed[pParam->type] = 0;
01399         }
01400     }
01401     return;
01402 FAIL:
01403         OpAddWebFolders::Success[pParam->type] = FALSE; 
01404         FailAndExecute(); 
01405         End();
01406 }

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

Returns the OpState of the OpAddWebLibrary operation.

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

Definition at line 1312 of file inetop.cpp.

01313 {
01314     OpState OpSt;
01315     return(OpSt);
01316 }

BOOL OpAddWebLibrary::Init void   )  [static]
 

Creates an OpDescriptor for an OpAddWebLibrary 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 1285 of file inetop.cpp.

01286 {  
01287 
01288     return RegisterOpDescriptor(
01289         0,                              // Tool ID
01290         _R(IDS_OPADDWEBLIBRARY),                // String resource ID
01291         CC_RUNTIME_CLASS(OpAddWebLibrary),  // Runtime class
01292         OPTOKEN_OPADDWEBLIBRARY,            // Token string
01293         OpAddWebLibrary::GetState,          // GetState function
01294         0,                              // Help ID
01295         0,                              // Bubble ID
01296         0,                              // Resource ID
01297         0                               // Control ID
01298     );
01299 }   

BOOL OpAddWebLibrary::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 1422 of file inetop.cpp.

01423 {
01424     InternetManager::UnregisterDownload(m_hDownload);
01425     End();
01426     return TRUE;
01427 }

BOOL OpAddWebLibrary::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 1448 of file inetop.cpp.

01449 {
01450     ERROR2IF(!pParam, FALSE, "Unexpected NULL pointer");
01451     if (m_bIsSuspended)
01452         return FALSE;
01453     UINT32 nModifiedFlag = FOLDER_UNMODIFIED; // flag indicating folder's status (FOLDER_UNMODIFIED/FOLDER_UPDATED/FOLDER_NEW)
01454     BOOL bHaveCatalogFile = FALSE; // flag indicating if we should add this folder to the gallery
01455     PathName localFile(pParam->localFile); // path to local (current) catalog file (may not exist if this is a new folder)
01456     localFile.SetType(String_32(_T("txt"))); // should be a .txt file
01457     PathName oldFile(pParam->localFile); // path to old catalog file (may not exist if this is a new folder)
01458     oldFile.SetType(String_32(_T("old")));
01459 
01460     LibraryGallery* pGallery = pParam->pLibGal;
01461     switch (InternetManager::GetDownloadState(m_hDownload))
01462     {
01463         case AsynchDownload::STATE_PENDING:
01464             // download pending, so we continue polling
01465             return TRUE;
01466         
01467         case AsynchDownload::STATE_SUCCEEDED:
01468         {
01469             // Check if the folder exists
01470             BOOL bFolderExists = (pGallery->FindLibrary((String_256) localFile.GetPath())) ? TRUE : FALSE;
01471             // File has transferred successfully, check if we have an older copy
01472             if (_taccess((String_256) localFile.GetPath(), 0) == -1) // not  found
01473             {
01474                 if (DownloadCache::RenameFile((String_256) pParam->localFile.GetPath(), (String_256) localFile.GetPath()))
01475                 {
01476                     InformError(_R(IDS_LOCALFILEERROR), _R(IDS_OK));
01477                     goto FAIL; // couldn't rename it for some reason
01478                 }
01479                 else
01480                 {
01481                     bHaveCatalogFile = TRUE;
01482                     nModifiedFlag = FOLDER_NEW;
01483                 }
01484             }
01485             else // we already have an older version of this file, so we compare the sizes to see if the web version is different
01486             {
01487                 CCDiskFile currentVersion, newVersion;
01488                 if (!currentVersion.open(localFile, ios::in) || !newVersion.open(pParam->localFile, ios::in))
01489                 {
01490                     // Cannot compare sizes due to some I/O error, so in case one of the files is good we'll just use that
01491                     BOOL bCurrentVersionBad = currentVersion.bad(); 
01492                     BOOL bNewVersionBad = newVersion.bad(); 
01493                     currentVersion.close();
01494                     newVersion.close();
01495                     if (!bNewVersionBad)
01496                     {
01497                         // move the new version over the old one
01498                         if (DownloadCache::RemoveFile((String_256) localFile.GetPath())) // failed - can't move
01499                         {
01500                                 InformError(_R(IDS_LOCALFILEERROR), _R(IDS_OK));
01501                                 DownloadCache::RemoveFile((String_256) pParam->localFile.GetPath());
01502                                 goto FAIL;
01503                         }
01504                         else // rename the new version 
01505                         {
01506                             if (DownloadCache::RenameFile((String_256) pParam->localFile.GetPath(), (String_256) localFile.GetPath()))
01507                             {
01508                                 InformError(_R(IDS_LOCALFILEERROR), _R(IDS_OK));
01509                                 goto FAIL; // couldn't rename it for some reason
01510                             }
01511                             else
01512                             {
01513                                 bHaveCatalogFile = TRUE;
01514                                 if (!bFolderExists)
01515                                     nModifiedFlag = FOLDER_NEW;
01516                             }
01517                         }
01518                     }
01519                     else if (!bCurrentVersionBad)
01520                     {
01521                         // the downloaded catalog file may be corrupted, so delete it and use the current one
01522                         DownloadCache::RemoveFile((String_256) pParam->localFile.GetPath());
01523                         bHaveCatalogFile = TRUE;
01524                         if (!bFolderExists)
01525                             nModifiedFlag = FOLDER_NEW;
01526                     }
01527                     else // none of the files can be opened - just clean up and inform the error
01528                     {
01529                         DownloadCache::RemoveFile((String_256) pParam->localFile.GetPath());
01530                         InformError(_R(IDS_LOCALFILEERROR), _R(IDS_OK));
01531                         goto FAIL; 
01532                     }
01533                 }
01534                 else
01535                 {
01536                     if (!bFolderExists)
01537                         nModifiedFlag = FOLDER_NEW;
01538                     else if (newVersion.Size() != currentVersion.Size())
01539                         nModifiedFlag = FOLDER_UPDATED;
01540                     currentVersion.close();
01541                     newVersion.close();
01542                     DownloadCache::RemoveFile((String_256) oldFile.GetPath());
01543                     if (DownloadCache::RenameFile((String_256) localFile.GetPath(), (String_256) oldFile.GetPath())) // failed - can't move
01544                     {
01545                             InformError(_R(IDS_LOCALFILEERROR), _R(IDS_OK));
01546                             DownloadCache::RemoveFile((String_256) pParam->localFile.GetPath());
01547                             goto FAIL;
01548                     }
01549                     else // rename the new version
01550                     {
01551                         if (DownloadCache::RenameFile((String_256) pParam->localFile.GetPath(), (String_256) localFile.GetPath()))
01552                         {
01553                             InformError(_R(IDS_LOCALFILEERROR), _R(IDS_OK));
01554                             goto FAIL; // couldn't rename it for some reason
01555                         }
01556                         else
01557                         {
01558                             bHaveCatalogFile = TRUE;
01559                         }
01560                     }
01561                 }
01562             }
01563         }
01564         break;
01565 
01566         case AsynchDownload::STATE_FAILED:
01567         {
01568             ErrorCount[pParam->type]++;
01569             OpAddWebFolders::Success[pParam->type] = FALSE; 
01570             // If we have on older catalog file we'll use that, otherwise we'll FAIL
01571             if (_taccess((String_256) localFile.GetPath(), 0) == -1) // not  found
01572             {
01573                 goto FAIL;
01574             }
01575             else 
01576             {
01577                 CachedFilesUsed[pParam->type]++;
01578                 bHaveCatalogFile = TRUE;
01579             }
01580         }
01581         break;
01582 
01583         case AsynchDownload::STATE_ABORTED:
01584         {
01585             // no errror message as this state is the result of a user cancel
01586             Suspend(); // ensure we are not reentered while we remove pending downloads
01587             std::list<DOWNLOAD_HANDLE>::iterator listIterator = m_lstPendingDownloads.begin();
01588             INT32 nListSize = m_lstPendingDownloads.size();
01589             for (INT32 i = 0; i < nListSize; i++)
01590                 InternetManager::UnregisterDownload(*listIterator++);
01591             Resume();
01592             goto FAIL;
01593         }
01594 
01595         default:
01596             ERROR3("Error or unrecognized state");
01597             goto FAIL;
01598     }
01599     // Add/update the folder if everything's fine
01600     if (bHaveCatalogFile && (nModifiedFlag == FOLDER_UPDATED || nModifiedFlag == FOLDER_NEW)) 
01601     {
01602         LibraryFile* LibFile = NULL;
01603         try
01604         {
01605             LibFile  = new LibraryFile;
01606         }
01607         catch (CMemoryException* pExc)
01608         {
01609             pExc->Delete();
01610             Error::SetError(_R(IDS_OUT_OF_MEMORY));
01611             InformError();
01612             goto FAIL;
01613         }
01614         String_256 strFileName(localFile.GetFileName());
01615         PathName FilesPath(localFile.GetLocation());
01616         pGallery->RemoveSimilarLibraryGroups(&FilesPath, &strFileName, TRUE, FALSE, NULL);
01617         if (!LibFile->AddSpecificIndex(pGallery, &localFile, pParam->type, &pParam->strFolderName, nModifiedFlag, TRUE))
01618         {
01619             delete LibFile;
01620             goto FAIL;
01621         }
01622         else
01623         {
01624             pGallery->OpenLibFiles.AddTail(LibFile);
01625             LibFile->DoScrollRedraw();
01626             FoldersAdded[pParam->type]++;
01627         }
01628         // If we got this far we can assume we succeeded
01629         SucceedAndDiscard();
01630         goto END;
01631     }
01632     else
01633     {
01634         goto END;
01635     }
01636 
01637 FAIL:
01638     OpAddWebFolders::Success[pParam->type] = FALSE; 
01639     FailAndDiscard();
01640 
01641 END:
01642     // inform errors, if any
01643     if (InstanceCount[pParam->type] == 1 && ErrorCount[pParam->type])
01644     {
01645         String_256 strErrorMsg;
01646         if (FoldersAdded[pParam->type]) // partial failure (we have added some of the folders)
01647         {
01648             if (CachedFilesUsed[pParam->type])
01649                 strErrorMsg.MakeMsg(_R(IDS_CATALOGPARTIALUSECACHE), (TCHAR*) (String_256) GetStringField((UINT32) pParam->type, _R(IDS_GALLERY_DESCRIPTIONS)),
01650                     (TCHAR*) (String_256) GetStringField((UINT32) pParam->type, _R(IDS_GETX_CAPTIONS)));
01651             else
01652                 strErrorMsg.MakeMsg(_R(IDS_CATALOGDOWNLOADPARTIALFAIL), (TCHAR*) (String_256) GetStringField((UINT32) pParam->type, _R(IDS_GALLERY_DESCRIPTIONS)),
01653                     (TCHAR*) (String_256) GetStringField((UINT32) pParam->type, _R(IDS_GETX_CAPTIONS)));
01654         }
01655         else
01656         {
01657             if (CachedFilesUsed[pParam->type])
01658                 strErrorMsg.MakeMsg(_R(IDS_CATALOGUSECACHE), (TCHAR*) (String_256) GetStringField((UINT32) pParam->type, _R(IDS_GALLERY_DESCRIPTIONS)),
01659                     (TCHAR*) (String_256) GetStringField((UINT32) pParam->type, _R(IDS_GETX_CAPTIONS)));
01660             else // failed completely...
01661                 strErrorMsg.MakeMsg(_R(IDS_CATALOGDOWNLOADFAILED), (TCHAR*) (String_256) GetStringField((UINT32) pParam->type, _R(IDS_GALLERY_DESCRIPTIONS)),
01662                     (TCHAR*) (String_256) GetStringField((UINT32) pParam->type, _R(IDS_GETX_CAPTIONS)));
01663         }
01664         Error::SetError(0, strErrorMsg, 0);
01665         InformError();
01666     }
01667     m_lstPendingDownloads.remove(m_hDownload);
01668     End();
01669     return FALSE;
01670 }

static void OpAddWebLibrary::Resume  )  [inline, static, protected]
 

Definition at line 534 of file inetop.h.

static void OpAddWebLibrary::Suspend  )  [inline, static, protected]
 

Definition at line 533 of file inetop.h.


Friends And Related Function Documentation

friend class OpAddWebFolders [friend]
 

Definition at line 535 of file inetop.h.


Member Data Documentation

INT32 OpAddWebLibrary::CachedFilesUsed [static, protected]
 

Definition at line 532 of file inetop.h.

INT32 OpAddWebLibrary::ErrorCount [static, protected]
 

Definition at line 531 of file inetop.h.

INT32 OpAddWebLibrary::FoldersAdded [static, protected]
 

Definition at line 530 of file inetop.h.

INT32 OpAddWebLibrary::InstanceCount [static, protected]
 

Definition at line 529 of file inetop.h.

BOOL OpAddWebLibrary::m_bIsSuspended = FALSE [static, protected]
 

Definition at line 525 of file inetop.h.

DOWNLOAD_HANDLE OpAddWebLibrary::m_hDownload [protected]
 

Definition at line 524 of file inetop.h.

std::list< DOWNLOAD_HANDLE > OpAddWebLibrary::m_lstPendingDownloads [static, protected]
 

Definition at line 527 of file inetop.h.

AddWebFoldersParam* OpAddWebLibrary::pParam
 

Definition at line 510 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