SGLibOil Class Reference

Initially, general OILy utilities for the library, but then the Add Library dialog code was added in... More...

#include <sgliboil.h>

Inheritance diagram for SGLibOil:

CCObject SimpleCCObject List of all members.

Public Member Functions

 SGLibOil ()
 ~SGLibOil ()

Static Public Member Functions

static BOOL FileCopy (PathName *Source, PathName *Destination)
 Copies a file from source to destination. Notes: This function was deemed necessary as actually doing this sort of thing in windows 3.1 is completely nasty, and completely incompatible with NT's way...
static BOOL FileExists (PathName *FileName)
 To find out whether a file actually exists. Notes:.
static INT32 FileSize (PathName *FileName)
 To find out whether a file actually exists. Notes:.
static BOOL FileDelete (PathName *FileName)
 Delete a file - scarry ! Notes:.
static UINT32 FileModified (PathName *FileName)
 Return numeric form of last modified time / date... for a file.
static BOOL DirExists (const PathName &FileName)
 To find out whether a dir actually exists. Notes:.
static BOOL IsRootDirectory (String_256 *Path)
 Checks if root directory or not... `.
static void AppendSlashIfNotPresent (String_256 *Str)
 Checks if the string has a slash on the end, and appends one if not.
static DWORD GetDriveSerialNumber (String_256 *PathStr)
 Obtains a serial number for the drive hosting the given pathname. Theoretically CD's all contain unique serial numbers, so we can use this to check for new CD's in the drive, etc...
static BOOL LocateCDROMDrive (LibraryGallery *LG, SGLibType LibType, String_256 *DriveName, BOOL *OnXaraNet, String_256 *XaraMount, BOOL AdjustPressed=FALSE)
 Looks for the Xara CD. At present we go through all their CDROM drives checking for the existance of certain directories on the CDs... We also check the various net points for the Xara CD test library...
static BOOL MakeSound (PathName *WaveFile)
 Processes messages from the Explorer version of the common File Open dialog. Used to kill the get path dbox when OK is clicked, handling 'Generate' clicks, and re-arranging the window's items...Plays a wave file through the computer's sound system (if it has one).
static BOOL PlayRandomSample (String_256 *SampleString, String_256 *SubPath)
 Plays a random wave file through the computer's sound system (if it has one).
static BOOL GetLibPath (LibraryGallery *LG, PathName *Path, BOOL CanGenerate, SGLibType Type, BOOL *Updated=NULL)
static BOOL GenerateClicked (LibraryGallery *LG, PathName *GenDirectory)
static BOOL CheckForIndex (String_256 *Path, LibraryGallery *ParentGallery)
static BOOL LoadSoundDefinition (CXaraFileRecordHandler *pXFileRecHandler, CXaraFile *pCXFile, INT32 Tag, UINT32 Size, UINT32 RecordNumber)
static BOOL ExportWav (BaseCamelotFilter *pFilter)
static BOOL TidyUp (void)
 Called by camelot de-init routines.

Static Public Attributes

static BOOL UseExplorerForAdd

Static Protected Member Functions

static UINT32 CALLBACK FileHook (wxWindow *hDlg, UINT32 Msg, UINT32 wParam, INT32 lParam)
 Processes messages from the common File Open dialog. Used to kill the get path dbox when OK is clicked. Used for handling 'Generate' clicks. Notes:.

Static Protected Attributes

static BOOL SearchButtonClicked
static String_256 SearchDirectory
static String_256 BrowsePath
static SGLibType LibType
static LibraryGalleryParentLibraryGallery
static BOOL GenerateButtonClicked
static TCHARTmpSndName = NULL

Detailed Description

Initially, general OILy utilities for the library, but then the Add Library dialog code was added in...

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/3/95

Definition at line 229 of file sgliboil.h.


Constructor & Destructor Documentation

SGLibOil::SGLibOil  )  [inline]
 

Definition at line 234 of file sgliboil.h.

00234 {}

SGLibOil::~SGLibOil  )  [inline]
 

Definition at line 235 of file sgliboil.h.

00235 {}


Member Function Documentation

void SGLibOil::AppendSlashIfNotPresent String_256 Str  )  [static]
 

Checks if the string has a slash on the end, and appends one if not.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/2/96
Parameters:
Str - String to append slash to [INPUTS]
Str - String with slash appended [OUTPUTS]

Definition at line 2874 of file sgliboil.cpp.

02875 {
02876     ERROR3IF(Str == NULL, "SGLibOil::AppendSlashIfNotPresent given a NULL string");
02877     if(Str == NULL)
02878         return;
02879 
02880     if(Str->Length() > 0)
02881         if( ((TCHAR *)*Str)[Str->Length()-1] != '/' )
02882             *Str += TEXT("/");
02883 }

static BOOL SGLibOil::CheckForIndex String_256 Path,
LibraryGallery ParentGallery
[static]
 

BOOL SGLibOil::DirExists const PathName FileName  )  [static]
 

To find out whether a dir actually exists. Notes:.

Author:
Luke Hart (Xara Group Ltd) <lukeh@xara.com>
Date:
21/05/06
Parameters:
File - Pointer to path and filename of dir [INPUTS]
Returns:
Returns true if the specified dir exists

Definition at line 1311 of file sgliboil.cpp.

01312 {
01313     return wxDir::Exists( PCTSTR(FileName.GetPath()) );
01314 
01315 #if 0
01316     CCDiskFile File;
01317     BOOL OldTEState = File.SetThrowExceptions(FALSE);
01318     BOOL OldREState = File.SetReportErrors(FALSE);
01319     BOOL Found = FALSE;
01320      
01321     // Open file - returns false if there was an error (file doesn't exist)
01322     Found = File.open(FileName->GetPath(), ios::in | ios::binary | ios::nocreate);
01323     if(Found) File.close();
01324         
01325     File.SetThrowExceptions(OldTEState);
01326     File.SetReportErrors(OldREState);
01327     Error::ClearError();
01328 
01329     return Found;
01330 #endif
01331 }

BOOL SGLibOil::ExportWav BaseCamelotFilter pFilter  )  [static]
 

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/2/96
Parameters:
pFilter - Filter point to which we want the data streaming [INPUTS]
Returns:
TRUE if the record was succesfully exported; FALSE if not

Definition at line 2806 of file sgliboil.cpp.

02807 {
02808 #if 0
02809     BOOL ok = TRUE;
02810     INT32 RecordNumber = pFilter->StartStreamedRecord(TAG_DEFINESOUND_WAV, CXF_UNKNOWN_SIZE);
02811 
02812     // If we had a problem starting the record up then exit now
02813     if (RecordNumber <= 0)
02814         return RecordNumber;
02815 
02816     PathName Source("C:\\sample.wav");  
02817     INT32 Size = SGLibOil::FileSize(&Source);
02818     void *Buffer = CCMalloc(Size + 4);
02819 
02820     if(Buffer != NULL)
02821     {
02822         CCDiskFile File(1024, FALSE, TRUE);
02823 
02824         // Open file and check if it exists at the same time
02825         TRY
02826         {
02827             // Read file into the buffer
02828             File.open(Source.GetPath(), ios::in | ios::binary | ios::nocreate);
02829             File.read(Buffer, Size);
02830             if(File.isOpen())
02831                 File.close();
02832 
02833             // Write file from buffer into output file
02834             //pOutput->write(Buffer, Size);
02835             for(INT32 i=0; i<Size; i++)
02836                 pFilter->Write(((BYTE *)Buffer)[i]);
02837         }       
02838 
02839         CATCH( CFileException, e)
02840         {
02841             // File not copied ok... Clear the errors and fall though to alternative low-
02842             // memory file copy... (this should be very rare !)
02843             Error::ClearError();
02844         }
02845         END_CATCH
02846 
02847         CCFree(Buffer);
02848     }
02849 
02850     // Ask for the record to be ended and hence items like the size in the record header
02851     // to be cleaned up and hence made correct
02852     if (ok) ok = pFilter->EndStreamedRecord();
02853 
02854     return ok;
02855 #else
02856     return FALSE;
02857 #endif
02858 }

BOOL SGLibOil::FileCopy PathName Source,
PathName Destination
[static]
 

Copies a file from source to destination. Notes: This function was deemed necessary as actually doing this sort of thing in windows 3.1 is completely nasty, and completely incompatible with NT's way...

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/3/95
Parameters:
Source - Source path to grab file from [INPUTS] Destination - Destination path to copy file to
Returns:
Returns true if all was hunky dorey

Definition at line 1146 of file sgliboil.cpp.

01147 {
01148     PORTNOTETRACE("dialog","SGLibOil::FileCopy - do nothing");
01149 #ifndef EXCLUDE_FROM_XARALX
01150     if(Source == NULL || Destination == NULL)
01151     {
01152         ERROR3("SGLibOil::FileCopy Source or Destination files should not be null");
01153         return FALSE;
01154     }
01155 
01156     if(!Destination->IsValid() || !Source->IsValid())
01157     {
01158         ERROR3("SGLibOil::FileCopy given invalid path");
01159         return FALSE;
01160     }
01161 
01162     if(FileExists(Destination))
01163     {
01164         ERROR3("SGLibOil::FileCopy destination file already exists");
01165         return FALSE;
01166     }
01167 
01168     if(!FileExists(Source))
01169     {
01170         ERROR3("SGLibOil::FileCopy source file doesn't exist");
01171         return FALSE;
01172     }
01173 
01174 // *************************
01175 
01176 //  return CopyFile((TCHAR *)Source->GetPath(), (TCHAR *)Destination->GetPath(), FALSE);
01177 
01178 // *************************
01179 
01180     INT32 Size = SGLibOil::FileSize(Source);
01181     void *Buffer = CCMalloc(Size + 4);
01182 
01183     if(Buffer != NULL)
01184     {
01185         CCDiskFile File(1024, FALSE, TRUE);
01186  
01187         // Open file and check if it exists at the same time
01188         try
01189         {
01190             // Read file into the buffer
01191             File.open( Source->GetPath(), ios::in | ios::binary );
01192             File.read( Buffer, Size );
01193             if(File.isOpen())
01194                 File.close();
01195 
01196             // Write file from buffer into output file
01197             File.open(Destination->GetPath(), ios::out | ios::binary);
01198             File.write(Buffer, Size);
01199             if(File.isOpen())
01200                 File.close();
01201 
01202             CCFree(Buffer);
01203 
01204             // File copied ok...
01205             return TRUE;
01206         }       
01207         catch( CFileException )
01208         {
01209             // File not copied ok... Clear the errors and fall though to alternative low-
01210             // memory file copy... (this should be very rare !)
01211             Error::ClearError();
01212         }
01213 
01214         CCFree(Buffer);
01215     }
01216 
01217 // *************************
01218 
01219     // Not enough memory available, do the copy the old, slow, byte by byte (ANSI) way...
01220 
01221     FILE               *FPin  = NULL;
01222     FILE               *FPout = NULL;
01223 
01224 #if defined(__WXMSW__)
01225     FPin  = _tfopen((const TCHAR *)Source->GetPath(), "rb");
01226     FPout = _tfopen((const TCHAR *)Destination->GetPath(), "wb");
01227 #else
01228     PSTR                pszSrc, pszDst;
01229     {
01230         size_t          cchTmp = camWcstombs( NULL, Source->GetPath(), 0 ) + 1;
01231         pszSrc = PSTR( alloca( cchTmp ) );
01232         camWcstombs( pszSrc, Source->GetPath(), cchTmp );
01233     }
01234     {
01235         size_t          cchTmp = camWcstombs( NULL, Destination->GetPath(), 0 ) + 1;
01236         pszDst = PSTR( alloca( cchTmp ) );
01237         camWcstombs( pszDst, Destination->GetPath(), cchTmp );
01238     }
01239 
01240     FPin  = fopen( pszSrc, "rb" );
01241     FPout = fopen( pszDst, "wb" );
01242 #endif
01243     
01244     if(FPin != NULL || FPout != NULL)
01245     {
01246         TCHAR C;
01247         while(!feof(FPin))
01248         {
01249             C = _fgettc(FPin);
01250             if(!feof(FPin)) _fputtc(C, FPout);
01251         }                       
01252         fclose(FPin);
01253         fclose(FPout);
01254         return TRUE;
01255     }
01256 
01257     if(FPin != NULL) fclose(FPin);
01258     if(FPout != NULL) fclose(FPout);
01259 #endif
01260     return FALSE;
01261 }

BOOL SGLibOil::FileDelete PathName FileName  )  [static]
 

Delete a file - scarry ! Notes:.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/3/95
Parameters:
File - Pointer to path and filename of file [INPUTS]
Returns:
Returns true if the specified file was deleted ok

Definition at line 1385 of file sgliboil.cpp.

01386 {
01387     PORTNOTETRACE("dialog","SGLibOil::FileDelete - do nothing");
01388 #ifndef EXCLUDE_FROM_XARALX
01389     ERROR3IF(FileName == NULL || !FileName->IsValid(), "SGLibOil::FileDelete given a dodgy FileName");
01390 
01391     // Check if it exists, if so, kill it...
01392     if( _taccess( (const TCHAR *)FileName->GetPath(), ios::in ) == 0 )
01393     {
01394 //      RemoveFile((TCHAR *)FileName->GetPath(), cmoVital | cmoForce);
01395         if(_tremove((const TCHAR *)FileName->GetPath()) == 0)
01396             return TRUE;
01397     }
01398 #endif
01399     return FALSE;
01400 }

BOOL SGLibOil::FileExists PathName FileName  )  [static]
 

To find out whether a file actually exists. Notes:.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/3/95
Parameters:
File - Pointer to path and filename of file [INPUTS]
Returns:
Returns true if the specified file exists

Definition at line 1276 of file sgliboil.cpp.

01277 {
01278     return wxFile::Exists( PCTSTR(FileName->GetPath()) );
01279 
01280 #if 0
01281     CCDiskFile File;
01282     BOOL OldTEState = File.SetThrowExceptions(FALSE);
01283     BOOL OldREState = File.SetReportErrors(FALSE);
01284     BOOL Found = FALSE;
01285      
01286     // Open file - returns false if there was an error (file doesn't exist)
01287     Found = File.open(FileName->GetPath(), ios::in | ios::binary | ios::nocreate);
01288     if(Found) File.close();
01289         
01290     File.SetThrowExceptions(OldTEState);
01291     File.SetReportErrors(OldREState);
01292     Error::ClearError();
01293 
01294     return Found;
01295 #endif
01296 }

UINT32 CALLBACK SGLibOil::FileHook wxWindow *  pDlg,
UINT32  Msg,
UINT32  wParam,
INT32  lParam
[static, protected]
 

Processes messages from the common File Open dialog. Used to kill the get path dbox when OK is clicked. Used for handling 'Generate' clicks. Notes:.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
2/4/95
Parameters:
hDlg - HWND of the dialog box. [INPUTS] iMsg - UINT32 message number. wParam - UINT32 parameter. lParam - INT32 parameter.
Returns:
Non-Zero or Zero, indicating if the common dialog should SKIP the message (non-zero) or not (zero). Don't confuse with typical dialog box return values.

Definition at line 1743 of file sgliboil.cpp.

01744 {
01745     PORTNOTETRACE("dialog","SGLibOil::FileHook - do nothing - window CB");
01746 #ifndef EXCLUDE_FROM_XARALX
01747     switch(Msg)
01748     {
01749         case WM_INITDIALOG:
01750             {           
01751 #ifdef STANDALONE
01752             // Remove the Help button on standalone builds...
01753             HWND hGadget = GetDlgItem((HWND)hDlg, (INT32)_R(IDC_LIBPATH_HELP_BUTTON));
01754             ShowWindow(hGadget, SW_HIDE);
01755 #endif
01756         
01757             // We need to apply the correct font if we are in DBCS land
01758             if (UnicodeManager::IsDBCSOS())
01759                 FontFactory::ApplyFontToWindow(hDlg, STOCKFONT_DIALOG);
01760             }
01761             return TRUE;
01762 
01763         case WM_COMMAND:
01764 
01765             switch(wParam)
01766             {
01767                 case _R(IDC_LIBPATH_HELP_BUTTON):
01768                     // Special check for the help button, and a bodgy way of invoking help for
01769                     // this dialog, which is a generic CFileDialog type with a custom template,
01770                     // and thus has no unique class-name.
01771                     _HelpUser(TEXT("SGalleryAddFolderDlg"));
01772                     return TRUE;
01773 
01774                 case IDOK:
01775                     // Close the dbox when Add pressed
01776                     PostMessage(GetParent(hDlg), WM_COMMAND, IDOK, (INT32)FALSE);
01777                     return FALSE;
01778 
01779                 case _R(IDC_LIBPATH_GENERATE):
01780                     // Since there's no way of getting the full pathname here, we simulate
01781                     // a click on 'OK' to close the dbox, and set a flag saying we've clicked
01782                     // 'Generate' instead, so the code after the DoModal can get the proper
01783                     // path, generate the index, and re-open the dbox. Talk about a bodge !         
01784                     SGLibOil::GenerateButtonClicked = TRUE;
01785                     PostMessage(hDlg, WM_COMMAND, IDOK, (INT32)FALSE);
01786                     return FALSE;
01787 
01788                 case _R(IDC_LIBPATH_SEARCH):
01789                     // Scan (Search) for some clipart
01790                     {
01791                         if(!SGLibOil::ParentLibraryGallery->ScanForLocation(SGLibOil::LibType,
01792                                                                             &SGLibOil::SearchDirectory))
01793                         {
01794                             // Keep the dialog open - don't change the path
01795                             INT32 ButtonPressed = InformWarning(_R(IDS_LIBRARY_BROWSING_CANT_FIND_LIBRARY), _R(IDS_OK));
01796                             Error::ClearError();
01797                             return FALSE;
01798                         }
01799 
01800                         DirPath Path(SGLibOil::SearchDirectory);
01801                         if(!Path.IsValid())
01802                         {
01803                             ERROR3("Scanned to path is invalid");
01804                             // Keep the dialog open - don't change the path
01805                             return FALSE;
01806                         }
01807 
01808                         // Remember the pathname and which button was clicked so we can update the dialog
01809                         SGLibOil::SearchButtonClicked = TRUE;
01810 
01811                         PostMessage(hDlg, WM_COMMAND, IDOK, (INT32)FALSE);
01812                         return FALSE;
01813                     }
01814 
01815                 default:
01816                     break;
01817             }
01818             break;
01819 
01820         default:
01821             return FALSE;
01822     }
01823 #endif
01824     return FALSE;
01825 }

UINT32 SGLibOil::FileModified PathName FileName  )  [static]
 

Return numeric form of last modified time / date... for a file.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/1/95
Parameters:
FileName - Pointer to path and filename of file [INPUTS]
Returns:
Returns a numeric value relating the last time the file was modified. Old files will always return a lesser number than new ones.

Definition at line 1414 of file sgliboil.cpp.

01415 {
01416     PORTNOTETRACE("dialog","SGLibOil::FileModified - do nothing");
01417 #ifndef EXCLUDE_FROM_XARALX
01418     ERROR3IF(FileName == NULL, "SGLibOil::FileModified given a NULL FileName");
01419     ERROR3IF(!FileName->IsValid(), "SGLibOil::FileModified given invalid path");
01420 
01421     struct _tstat buf;
01422 
01423     INT32 Result = _tstat((const TCHAR *)FileName->GetPath(), &buf);
01424 
01425     if(Result != 0)
01426         return 0;
01427 
01428     // some files seem to have dates of -1, which is a long time in the future, or basically
01429     // random... We assume they haven't been modified recently...
01430     if(buf.st_mtime == -1)
01431         return 0;
01432 
01433     return (UINT32)buf.st_mtime;
01434 #else   
01435     return 1;
01436 #endif
01437 }

INT32 SGLibOil::FileSize PathName FileName  )  [static]
 

To find out whether a file actually exists. Notes:.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/3/95
Parameters:
File - Pointer to path and filename of file [INPUTS]
Returns:
Returns true if the specified file exists

Definition at line 1346 of file sgliboil.cpp.

01347 {
01348     PORTNOTETRACE("dialog","SGLibOil::FileSize - do nothing");
01349 #ifndef EXCLUDE_FROM_XARALX
01350     ERROR3IF(FileName == NULL, "SGLibOil::FileSize Filename should not be null");
01351     ERROR3IF(!FileName->IsValid(), "SGLibOil::FileSize given invalid path");
01352 
01353     INT32 FileSize = 0;
01354 
01355     // Unfortunately MFC seems to have a nasty bug which is less than useful
01356     // WRT reading file sizes of old files... We resort to good old c.
01357     FILE *FP = NULL;
01358     FP = _tfopen((const TCHAR *)FileName->GetPath(), "rb");
01359     if(FP != NULL)
01360     {
01361         fseek(FP,0,SEEK_END);
01362         FileSize = ftell(FP);
01363         fclose(FP);
01364     }
01365 
01366     return FileSize;
01367 #else   
01368     return 1;
01369 #endif
01370 }

static BOOL SGLibOil::GenerateClicked LibraryGallery LG,
PathName GenDirectory
[static]
 

DWORD SGLibOil::GetDriveSerialNumber String_256 PathStr  )  [static]
 

Obtains a serial number for the drive hosting the given pathname. Theoretically CD's all contain unique serial numbers, so we can use this to check for new CD's in the drive, etc...

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/7/96
Parameters:
PathStr - Pathname string containing drive, etc [INPUTS]
Returns:
Serial number for given pathname's drive, or 0 if there were problems

Definition at line 2902 of file sgliboil.cpp.

02903 {
02904     TRACE( wxT("Warning - SGLibOil::GetDriveSerialNumber called\n") );
02905 #if defined(__WXMSW__)
02906     if(PathStr == NULL)
02907         return 0;
02908 
02909     TCHAR               Drive[MAX_PATH];
02910     BOOL                driveFound = FALSE;
02911 
02912     // Just for safety
02913     String_256 Path = *PathStr;
02914     const TCHAR *fn;
02915     fn = Path;
02916     BOOL BadCharacter = FALSE;
02917 
02918     // First check if there is a valid drive name or net drive name present
02919     // If the first character of the path is an alpha then assume drive and check if valid
02920     // and so of the form D:/
02921     // Otherwise, check for a UNC (Universal naming convention) form of drive of the form
02922     // //Deepthought 
02923     if (String::IsAlpha(*fn))           
02924         driveFound = getDrive(&fn, Drive);  // Parse the Drive 
02925     else 
02926         driveFound = getNetDrive(&fn, Drive, &BadCharacter);    //Parse as UNC or network drive
02927 
02928     if(driveFound && !BadCharacter)
02929     {
02930         String_256 FileSystemName;
02931         String_256 VolumeName;
02932         DWORD SerialNumber = 0;
02933         BOOL bRC = FALSE;
02934 
02935         bRC=GetVolumeInformation(Drive,
02936                 (TCHAR *)VolumeName,
02937                 255,
02938                 &SerialNumber,
02939                 NULL,
02940                 NULL,
02941                 (TCHAR *)FileSystemName,
02942                 255);
02943 
02944         if(bRC)
02945             return SerialNumber;
02946     }
02947 
02948     return 0;
02949 #else
02950     return 0x00BAD000;
02951 #endif
02952 }

static BOOL SGLibOil::GetLibPath LibraryGallery LG,
PathName Path,
BOOL  CanGenerate,
SGLibType  Type,
BOOL *  Updated = NULL
[static]
 

BOOL SGLibOil::IsRootDirectory String_256 Path  )  [static]
 

Checks if root directory or not... `.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/2/96
Parameters:
Path - Path string -> "A:\" or "C:\fred" [INPUTS]
Returns:
TRUE if the path describes a root directory -> "A:\" or "\\deepthought\materials", "\\fred\fred\", etc...

Definition at line 2672 of file sgliboil.cpp.

02673 {
02674     TRACE( wxT("Warning - SGLibOil::PlayRandomSample called\n") );
02675 #if defined(__WXMSW__)
02676     ERROR3IF(Path == NULL, "SGLibOil::IsRootDirectory given a NULL string");
02677     if(Path == NULL)
02678         return FALSE;
02679 //  ERROR3_PF(("IsRootDirectory -> %s", (TCHAR *)*Path));
02680     
02681     // Remove trailing '\'s
02682     String_256 TmpPath(*Path);
02683     if(TmpPath[TmpPath.Length()-1] == _T('\\'))
02684         Path->Left(&TmpPath, Path->Length()-1);
02685 
02686     // Check for 'a:'s...
02687     if( TmpPath.Length() == 2 && TmpPath[1] == _T(':') )
02688         return TRUE;
02689 
02690 //  ERROR3_PF(("For %s, Sub = %d, Count = %d", (TCHAR *)TmpPath, TmpPath.Sub(String_8("\\\\"), 0, TCHAR('*')), TmpPath.CountChar('\\')));
02691     
02692     // Check if unc root dir
02693     if( ( TmpPath.Sub( String_8( wxT("\\\\") ), 0, wxT('*') ) == 0 && TmpPath.CountChar( wxT('\\') ) <= 3 ) )
02694     {
02695 //      ERROR3("UNC root");
02696         return TRUE;
02697     }
02698 
02699 //  ERROR3_PF(("%s is not a root", (TCHAR *)*Path));
02700     return FALSE;
02701 #else
02702     return FALSE;
02703 #endif
02704 }

BOOL SGLibOil::LoadSoundDefinition CXaraFileRecordHandler pXFileRecHandler,
CXaraFile pCXFile,
INT32  Tag,
UINT32  Size,
UINT32  RecordNumber
[static]
 

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/2/96
Parameters:
pXFileRecHandler - The CXaraFileRecordHandler that is being used to provide read functions etc. [INPUTS] pCXFile - The CXaraFile that is being used to provide read functions etc. Tag - The tag of the record and hence the type of file being imported Size - The size of this record RecordNumber - The record number for this record
Returns:
TRUE if the record was succesfully imported; FALSE if not (e.g. out of memory)

Definition at line 2724 of file sgliboil.cpp.

02726 {
02727     TRACE( wxT("Warning - SGLibOil::LoadSoundDefinition called\n") );
02728 #if defined(__WXMSW__)
02729     if(TmpSndName != NULL)
02730     {
02731         PathName TheFile(TmpSndName);
02732         FileDelete(&TheFile);
02733         TmpSndName = NULL;
02734     }
02735 
02736     // Create a temporary filename to use
02737     if(( TmpSndName = _ttmpnam( NULL ) ) != NULL )
02738     {
02739         UINT32 Size = pCXFile->GetCurrentRecordSize();
02740         CCFile *pRecordFile = pCXFile->GetCCFile();
02741 
02742         void *Buffer = CCMalloc(Size + 4);
02743     
02744         BOOL ok = FALSE;
02745 
02746         if(Buffer != NULL)
02747         {
02748             CCDiskFile File(1024, FALSE, TRUE);
02749  
02750             // Open file and check if it exists at the same time
02751             try
02752             {
02753                 // Read file into the buffer
02754                 pRecordFile->read(Buffer, Size);
02755 
02756                 // Write file from buffer into output file
02757                 PathName OutputPath(TmpSndName);
02758                 File.open(OutputPath, ios::out | ios::binary);
02759                 File.write(Buffer, Size);
02760                 if(File.isOpen())
02761                     File.close();
02762 
02763                 // File copied ok...
02764                 ok = TRUE;
02765             }       
02766             catch( CFileException )
02767             {
02768                 // File not copied ok... Clear the errors and fall though to alternative low-
02769                 // memory file copy... (this should be very rare !)
02770                 Error::ClearError();
02771             }
02772 
02773             CCFree(Buffer);
02774         }
02775 
02776         if(ok)
02777         {
02778             ok = PlaySound((TCHAR *)TmpSndName, NULL, SND_ASYNC | SND_NODEFAULT | SND_NOWAIT | SND_FILENAME);
02779             if(!ok)
02780                 ok = sndPlaySound((TCHAR *)TmpSndName, SND_ASYNC | SND_NODEFAULT | SND_NOWAIT | SND_FILENAME);      
02781         }
02782 /*      PathName TheFile(TmpSndName);
02783         FileDelete(&TheFile);*/
02784     }
02785     
02786     return TRUE;
02787 #else
02788     return FALSE;
02789 #endif
02790 }

BOOL SGLibOil::LocateCDROMDrive LibraryGallery LG,
SGLibType  LibType,
String_256 DriveName,
BOOL *  OnXaraNet,
String_256 XaraMount,
BOOL  AdjustPressed = FALSE
[static]
 

Looks for the Xara CD. At present we go through all their CDROM drives checking for the existance of certain directories on the CDs... We also check the various net points for the Xara CD test library...

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/4/95
Parameters:
LG - parent library gallery for function [INPUTS] LibType - the type of library we're looking for AdjustPressed - Is 'adjust' held down ?
DriveName will return a string such as "D:\" for the last valid CD drive it [OUTPUTS] found with any of the magic directories present.
OnXaraNet will return TRUE if we found a camelot CD mount was point XaraMount will return the path of the dummy CD -> "g:\CD\"

Returns:
Returns true if a CD Drive or Xara mount was found
Notes: The internal network drive matching code uses the serial number of the drive itself. If we change the Xara CamelotCD mount point we'll need to change the serial number stuff below...

Definition at line 1466 of file sgliboil.cpp.

01468 {
01469 #if !defined(__WXMSW__)
01470     TRACE( _T("Warning - SGLibOil::FileModified called") );
01471     return FALSE;
01472 #else
01473     if(!LG || !DriveName || !OnXaraNet || !XaraMount)
01474     {
01475         ERROR3("SGLibOil::LocateCDROMDrive given null input stuff");
01476         return FALSE;
01477     }
01478 
01479     BOOL FoundCD = FALSE;
01480     BOOL FoundXara = FALSE;
01481     BOOL FoundProgramMount = FALSE;
01482 
01483     *OnXaraNet = FALSE;
01484 
01485     DWORD dwTemp;   
01486     const DWORD DriveStringBufferSize = 20480;
01487     TCHAR DriveStringBuffer[DriveStringBufferSize];
01488     TCHAR *lpszDriveStringBuffer = (TCHAR *)DriveStringBuffer;
01489     TCHAR RootPathName[] = { '?', ':', chPathSep, 0 };
01490 
01491     String_64 SlowJob(_R(IDS_LIBRARIES_FINDING_CD));
01492     BeginSlowJob(('z' - 'a'), FALSE, &SlowJob);
01493 
01494     DWORD dwDriveMask=GetLogicalDrives();
01495     DWORD dwRC=GetLogicalDriveStrings(DriveStringBufferSize, lpszDriveStringBuffer);
01496 
01497     //ERROR3IF(dwRC == 0, "SGLibOil::LocateCDROMDrive - RC == 0 (no worries, we can default to plan b !)");
01498     ERROR3IF(dwDriveMask == 0, "SGLibOil::LocateCDROMDrive - DriveMask == 0 - this means you haven't got any drives at all on your system !!!");
01499 
01500     if(dwRC == 0)
01501     {
01502         memset(DriveStringBuffer, 0, DriveStringBufferSize);
01503         INT32 i = 0;
01504         for(*RootPathName='a'; *RootPathName<='z'; (*RootPathName)++)
01505         {
01506             DriveStringBuffer[i] = *RootPathName;
01507             DriveStringBuffer[i + 1] = ':';
01508             DriveStringBuffer[i + 2] = chPathSep;
01509             DriveStringBuffer[i + 3] = 0;
01510             i += 4;             
01511         }
01512         
01513         dwRC = i;
01514         dwDriveMask = 0xffffffff;
01515     }
01516 
01517     if(dwRC != 0 && dwDriveMask != 0)
01518     {
01519         // Loop through all the drives
01520         for(*RootPathName='a'; *RootPathName<='z'; (*RootPathName)++)
01521         {
01522             if(!ContinueSlowJob(*RootPathName - 'a'))
01523             {
01524                 *RootPathName = 'z';
01525             }
01526             else
01527             {
01528                 dwTemp=dwDriveMask & 1;
01529                 dwDriveMask >>= 1;
01530                 if (dwTemp)
01531                 {
01532                     // finds out what sort of drive this is
01533                     dwRC=GetDriveType(RootPathName);
01534 
01535                     switch (dwRC)
01536                     {
01537                         case DRIVE_REMOTE:
01538 #ifdef SCANFORXARAMOUNT
01539                             {
01540                                 TRACEUSER( "Richard", wxT("The drive type for %s is remote\n"), lpszDriveStringBuffer);
01541 
01542                                 // See if we're on the Xara Net or not...
01543                                 String_256 FileSystemName;
01544                                 String_256 VolumeName;
01545                                 DWORD SerialNumber = 0;
01546                                 BOOL bRC;
01547                     
01548                                 bRC=GetVolumeInformation(RootPathName,
01549                                         (TCHAR *)VolumeName,
01550                                         255,
01551                                         &SerialNumber,
01552                                         NULL,
01553                                         NULL,
01554                                         (TCHAR *)FileSystemName,
01555                                         255);
01556                         
01557                                 if(bRC)
01558                                 {
01559                                     TRACEUSER( "Richard", wxT("%d - %s - %s\n"), SerialNumber, (TCHAR *)VolumeName, (TCHAR *)FileSystemName);                       
01560 
01561                                     BOOL FoundAPossibleMount = FALSE;
01562 
01563                                     // Programs mount
01564                                     if(    (SerialNumber    == (DWORD)0x589c1e6f)
01565                                         && (VolumeName      == (String_256)"")
01566                                         && (FileSystemName  == (String_256)"NTFS") )
01567                                     {
01568                                         FoundProgramMount = TRUE;
01569                                     }
01570 
01571                                     if(!AdjustPressed)
01572                                     {
01573                                         // \\jimpc\corelxra
01574                                         if(    (SerialNumber    == 0x6863b85e)
01575                                             && (VolumeName      == (String_256)"CORELXARA")
01576                                             && (FileSystemName  == (String_256)"CDFS") )
01577                                         {
01578                                             FoundAPossibleMount = TRUE;
01579                                         }
01580                                     }
01581 
01582                                     // \\earth\materials
01583                                     if(AdjustPressed)
01584                                     {
01585                                         if(    (SerialNumber    == 0xec29b7f6)
01586                                             && (VolumeName      == (String_256)"")
01587                                             && (FileSystemName  == (String_256)"NTFS") )
01588                                         {
01589                                             FoundAPossibleMount = TRUE;
01590                                         }
01591                                     }
01592 
01593                                     if(FoundAPossibleMount)
01594                                     {
01595                                         // OK, but are we the proper drive ?
01596                                         String_256 CDPath(lpszDriveStringBuffer);
01597                                         String_256 CheckPath(lpszDriveStringBuffer);
01598                                     
01599                                         if(AdjustPressed)
01600                                         {
01601                                             switch(LibType)
01602                                             {
01603                                                 case SGLib_ClipArt:
01604                                                 case SGLib_ClipArt_WebThemes:
01605                                                     CheckPath += TEXT("Graphics\\XaraSt~1");
01606                                                     break;
01607                                                 case SGLib_Font:
01608                                                     CheckPath += TEXT("Fonts");
01609                                                     break;
01610                                                 case SGLib_Texture:
01611                                                     CheckPath += TEXT("Graphics\\Fills");
01612                                                     break;
01613                                                 default:
01614                                                     CheckPath += TEXT("Fills\\Fabric");
01615                                                     break;
01616                                             }
01617                                         }
01618                                         else
01619                                             CheckPath += TEXT("Fills\\Fabric");
01620 
01621                                         if(_taccess((TCHAR *)CheckPath, ios::in ) == 0)
01622                                         {
01623                                             String_256 Drive(CDPath);
01624                                             SGLibOil::AppendSlashIfNotPresent(&Drive);
01625                                             *XaraMount = Drive;
01626                                             *OnXaraNet = TRUE;
01627                                             FoundXara = TRUE;
01628                                         }
01629                                     }
01630                                 }
01631                                 else
01632                                 {
01633                                     DWORD Problem = GetLastError();
01634                                     TRACEUSER( "Richard", wxT("GetVolumeInformation returned %d error"), Problem);
01635                                 }
01636                             }
01637 #endif
01638                             break;
01639 
01640                         case DRIVE_CDROM:
01641                             // Since autochangers seem to take a seemingly endless amount of time to swap through
01642                             // each disk, so I've added this check to see if we've already found the CD or not...
01643                             if(!FoundCD)
01644                             {
01645                                 String_256 CDPath(lpszDriveStringBuffer);
01646                                 String_256 LibDirName;                          
01647 PORTNOTE("dialog","Removed LibraryGallery usage")
01648 #ifndef EXCLUDE_FROM_XARALX
01649                                 LG->GetLibraryDirectoryName(&LibDirName);
01650 #endif
01651                                 CDPath += LibDirName;
01652 
01653                                 if( 0 == _taccess( (TCHAR *)CDPath, ios::in ) )
01654                                 {               
01655                                     FoundCD = TRUE;
01656                                     *DriveName = lpszDriveStringBuffer;
01657                                 }
01658 
01659                                 // Bodge for Viewer CD, which contains a hidden Fills directory
01660                                 // If this ever moves, the below code will need to be changed
01661                                 if(!FoundCD && LibType == SGLib_Texture)
01662                                 {
01663                                     CDPath = (String_256)lpszDriveStringBuffer;
01664                                     CDPath += TEXT("Clipart\\Clipart\\");
01665                                     CDPath += String_16(_R(IDS_LIBRARIES_XARAINFO_DIRNAME));
01666                                     CDPath += TEXT("\\");
01667                                     CDPath += String_16(_R(IDS_LIBRARIES_FILLS_DIRNAME));
01668                                     if(_taccess((TCHAR *)CDPath, ios::in ) == 0)
01669                                     {               
01670                                         FoundCD = TRUE;
01671                                         *DriveName = lpszDriveStringBuffer;
01672                                         *DriveName += TEXT("Clipart\\Clipart\\");
01673                                         *DriveName += String_16(_R(IDS_LIBRARIES_XARAINFO_DIRNAME));
01674                                         *DriveName += TEXT("\\");
01675                                     }                                   
01676                                 }
01677                             }
01678                             break;
01679 
01680                         case DRIVE_REMOVABLE:
01681                             TRACEUSER( "Richard", wxT("The drive type for %s is removable\n"), lpszDriveStringBuffer);
01682                             break;
01683     
01684                         case DRIVE_FIXED:
01685                             TRACEUSER( "Richard", wxT("The drive type for %s is fixed\n"), lpszDriveStringBuffer);
01686                             // Maybe we should be recursing through their hard drive looking for XaraInfo
01687                             // directories ? v2 probably...
01688                             break;
01689 
01690                         case DRIVE_RAMDISK:
01691                             TRACEUSER( "Richard", wxT("The drive type for %s is ramdisk\n"), lpszDriveStringBuffer);
01692                             break;
01693 
01694                         default:
01695                             break;
01696                     }
01697 
01698                     // Advance to next valid drive in system
01699                     lpszDriveStringBuffer = lpszDriveStringBuffer + camStrlen(lpszDriveStringBuffer) + 1;
01700                 }
01701             }
01702         }
01703     }
01704 
01705     EndSlowJob();
01706 
01707 #ifdef _DEBUG
01708     if(!FoundCD && !FoundXara && FoundProgramMount)
01709     {
01710         String_256 XaraMsg;
01711         XaraMsg = "You're connected to the Xara Net, but not the CamelotCD mount, so can't 'find' the library. ";
01712         ERROR3(XaraMsg);
01713     }
01714 #endif
01715 
01716     return (FoundCD || FoundXara);
01717 #endif
01718 }

BOOL SGLibOil::MakeSound PathName WaveFile  )  [static]
 

Processes messages from the Explorer version of the common File Open dialog. Used to kill the get path dbox when OK is clicked, handling 'Generate' clicks, and re-arranging the window's items...Plays a wave file through the computer's sound system (if it has one).

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
2/1/96
Parameters:
WaveFile - Full filename of .wav file [INPUTS]
[OUTPUTS] 
Returns:
TRUE if played ok...

Definition at line 2558 of file sgliboil.cpp.

02559 {
02560 #if defined(__WXMSW__)
02561     // Actually play the sound      
02562     String_256 File(WaveFile->GetPath());
02563     BOOL ok = PlaySound((TCHAR *)File, NULL, SND_ASYNC | SND_NODEFAULT | SND_NOWAIT | SND_FILENAME);
02564     if(!ok)
02565         ok = sndPlaySound((TCHAR *)File, SND_ASYNC | SND_NODEFAULT | SND_NOWAIT | SND_FILENAME);
02566 
02567     return ok;
02568 #else
02569     TRACE( wxT("Warning - SGLibOil::MakeSound called\n") );
02570     return TRUE;
02571 #endif
02572 }

BOOL SGLibOil::PlayRandomSample String_256 SampleString,
String_256 SubPath
[static]
 

Plays a random wave file through the computer's sound system (if it has one).

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
2/1/96
Parameters:
SampleString - String such as "Fish.wav|fred.wav|C:\tmp.wav" [INPUTS] SubPath - Path to append to file -> C:
Returns:
TRUE if item found and played ok...

Definition at line 2590 of file sgliboil.cpp.

02591 {
02592 #if defined(__WXMSW__)
02593     String_256 SoundToUse(*SampleString);
02594 
02595     if(SoundToUse.Length() > 2)
02596     {
02597         // Pick a random sound from a line such as "Frog.wav|fish.wav|water.wav"
02598         INT32 Fields = SampleString->CountChar('|');
02599 
02600         if(Fields > 0)
02601         {
02602             INT32 Count = (rand()%(Fields+1))+1;
02603             String_256 TmpSoundToUse(SoundToUse);
02604 
02605             if(Count > 0)
02606             {
02607                 TCHAR *Start = (TCHAR *)*SampleString;
02608                 TCHAR *Finish = Start + SampleString->Length();
02609 
02610                 // char to look for
02611                 const TCHAR BAR = '|';
02612 
02613                 TCHAR Ch = *Start;
02614                 INT32 FieldCount = 1;
02615 
02616                 // scan through fields until we hit our baby
02617                 while(Count > FieldCount && Start < Finish)
02618                 {
02619                     if(Ch == 0) break;
02620                     if(Ch == BAR) FieldCount ++;
02621                     Start += sizeof(TCHAR);
02622                     Ch = *Start;
02623                 }
02624 
02625                 // Pointer to sound to use
02626                 if(Count == FieldCount)
02627                     TmpSoundToUse = Start;
02628             }
02629 
02630             // Strip any trailing sounds
02631             if(TmpSoundToUse.Sub(String_8(_T("|"))) != -1)
02632                 TmpSoundToUse.Left(&SoundToUse, TmpSoundToUse.Sub(String_8(_T("|"))));
02633             else
02634                 SoundToUse = TmpSoundToUse;
02635         }
02636 
02637         // Path for normal files is with the pictures
02638         if(SoundToUse.Sub(String_8(_T("\\"))) == -1)
02639         {
02640             String_256 File = *SubPath;
02641             SGLibOil::AppendSlashIfNotPresent(&File);
02642             File += SoundToUse;
02643             SoundToUse = File;
02644         }
02645 
02646         PathName SoundPath(SoundToUse);
02647         return SGLibOil::MakeSound(&SoundPath);
02648     }
02649     return FALSE;
02650 #else
02651     TRACE( wxT("Warning - SGLibOil::PlayRandomSample called\n") );
02652     return TRUE;
02653 #endif
02654 }

BOOL SGLibOil::TidyUp void   )  [static]
 

Called by camelot de-init routines.

Definition at line 1119 of file sgliboil.cpp.

01120 {
01121     if(TmpSndName != NULL)
01122     {
01123         PathName TheFile(TmpSndName);
01124         FileDelete(&TheFile);
01125         TmpSndName = NULL;
01126     }
01127     return TRUE;
01128 }


Member Data Documentation

String_256 SGLibOil::BrowsePath [static, protected]
 

Definition at line 265 of file sgliboil.h.

BOOL SGLibOil::GenerateButtonClicked [static, protected]
 

Definition at line 268 of file sgliboil.h.

SGLibType SGLibOil::LibType [static, protected]
 

Definition at line 266 of file sgliboil.h.

LibraryGallery* SGLibOil::ParentLibraryGallery [static, protected]
 

Definition at line 267 of file sgliboil.h.

BOOL SGLibOil::SearchButtonClicked [static, protected]
 

Definition at line 263 of file sgliboil.h.

String_256 SGLibOil::SearchDirectory [static, protected]
 

Definition at line 264 of file sgliboil.h.

TCHAR * SGLibOil::TmpSndName = NULL [static, protected]
 

Definition at line 269 of file sgliboil.h.

BOOL SGLibOil::UseExplorerForAdd [static]
 

Definition at line 272 of file sgliboil.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 04:01:09 2007 for Camelot by  doxygen 1.4.4