LibSettings Class Reference

The Gallery Resource Management class... More...

#include <sgrmfile.h>

Inheritance diagram for LibSettings:

CCObject SimpleCCObject List of all members.

Public Member Functions

 LibSettings ()
 The Gallery Resource Management code...
 ~LibSettings ()
 Destructor.

Static Public Member Functions

static BOOL Init (void)
 Value returning initialisation routine...
static BOOL GetEntry (String_256 *Section, INT32 Line, String_256 *Entry, FilePos *Pos=NULL, String_256 *pIniFileString=NULL)
 Returns a single line from the grm file.
static BOOL AddLine (String_256 *Line, String_256 *pIniFileString=NULL)
 Adds a single line to the end of the grm file.
static BOOL AddSection (String_256 *Section, String_256 *pIniFileString=NULL)
 Adds a new section to the end of the grm file.
static BOOL IsThisANewSection (String_256 *Line, String_256 *Section)
 Checks if a given line is a new section or not and returns the section name if it is...
static BOOL StartOutput (String_256 *Section, String_256 *pIniFileString=NULL)
 Checks if there's already a grm file on the disk. If so, create a new .bak file holding copies of all the sections (except the one specified), then copy this new file over the old .grm file.
static BOOL NukeSettings (String_256 *pIniFileString=NULL)
 Delete all the settings from the gallery resource file.
static BOOL GetPathName (PathName *PathName, String_256 *pIniFileString=NULL)
 Returns the path and filename for the gallery resource management file... Currently this file holds the groups in the gallery for use when it next starts up...
static BOOL GetEntryStart (CCDiskFile *DiskFile, String_256 *pIniFileString=NULL)
 Call with a pre-created, but not initialised CCDiskFile. After calling this, calls to GetEntryFromFile can be passed this diskfile. When finished, call GetEntryFinish with the DiskFile to De-do all the stuff we done here, like...
static BOOL GetEntryFromFile (CCLexFile *TheFile, String_256 *Section, INT32 Line, String_256 *Entry, FilePos *Pos=NULL)
 Returns a single line from the grm file.
static BOOL GetEntryFinish (CCDiskFile *DiskFile)
 Call after GetEntryStart, and after any GetEntryFromFile calls, but before killing the DiskFile off. This will close the file, and de-initialise the lexer, etc...
static BOOL BuildList (String_256 *Section, List *OutputList)
 Given a section, build a list of entries in the section. This should speed reading lots of things from a section up by quite a bit...
static BOOL GetNextLine (CCDiskFile *TheFile, String_256 *Line)
 Output the next line of the file passed in. Return FALSE if problems.
static BOOL SeekToSection (CCDiskFile *TheFile, String_256 *Section)
 Hunt down our section in the grm file.

Static Public Attributes

static CCDiskFileDiskFile

Detailed Description

The Gallery Resource Management class...

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/5/95
Notes: Currently this code uses the GRM file to remember which groups were in which libraries and in which order when quitting the program so than on loading next time we can reflect the old status in the library...

As this is fairly general read and write ini file code, then this has been expanded so that an option other ini file name can be specified. If this is specified then this will be used instead of the GRM file name. Added by Neville 14/1/97 for saving/loading paths for plug-ins as the main ini file code cannot cope with the concept of sections filled with an arbitrary number of items which need cleaning out when resaving to remove old items no longer required.

Definition at line 157 of file sgrmfile.h.


Constructor & Destructor Documentation

LibSettings::LibSettings  ) 
 

The Gallery Resource Management code...

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/5/95
Parameters:
[INPUTS] 
[OUTPUTS] 
Returns:
Notes: Currently this code uses the GRM file to remember which groups were in which libraries and in which order when quitting the program so than on loading next time we can reflect the old status in the library...

Definition at line 193 of file sgrmfile.cpp.

00194 {
00195 }

LibSettings::~LibSettings  ) 
 

Destructor.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/5/95
Parameters:
[INPUTS] 
[OUTPUTS] 
Returns:

Definition at line 210 of file sgrmfile.cpp.

00211 {
00212 }


Member Function Documentation

BOOL LibSettings::AddLine String_256 Line,
String_256 pIniFileString = NULL
[static]
 

Adds a single line to the end of the grm file.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/5/95
Parameters:
Line - Line of text to add to file [INPUTS] pIniFileString set to NULL if using default gallery ini file (Default) or to the leafname of the ini file to use
[OUTPUTS] 
Returns:
TRUE if this was successful.
Notes: As this is fairly general read and write ini file code, then this has been expanded so that an option other ini file name can be specified. If this is specified then this will be used instead of the GRM file name. Added by Neville 14/1/97 for saving/loading paths for plug-ins as the main ini file code cannot cope with the concept of sections filled with an arbitrary number of items which need cleaning out when resaving to remove old items no longer required.

Definition at line 532 of file sgrmfile.cpp.

00533 {
00534     ERROR3IF(Line == NULL, "LibSettings::AddLine - not happy with null params");
00535 
00536     BOOL ok = TRUE;
00537 
00538     PathName GRMPath;
00539     if(!GetPathName(&GRMPath, pIniFileString))
00540     {
00541         ERROR3("LibSettings::AddLine - Problems getting pathname for grm file");
00542         return FALSE;
00543     }
00544 
00545     CCDiskFile GRMFile(1024, FALSE, TRUE);
00546 
00547     TRY
00548     {
00549         // Initialise the lexer memory for the token routines...
00550         if (!GRMFile.InitLexer(FALSE))
00551         {
00552             ERROR3("LibSettings::AddLine - Problems with InitLexer");
00553             ok = FALSE;
00554         }
00555 
00556         // Open file for appending to...
00557         if (ok && !GRMFile.open(GRMPath, ios::app))
00558         {
00559             ERROR3("LibSettings::AddLine - Failed to open the grm file for appending");
00560             ok = FALSE;
00561         }
00562 
00563         // Pop the token at the end of the file...
00564         if(ok) ok = GRMFile.PutToken(*Line, (String_8)"\r\n");
00565     }
00566 
00567     // See if there was a file io error
00568     CATCH(CFileException, e)
00569     {
00570         // Report the error if no one else did
00571         if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED))
00572             InformError();
00573         else
00574             Error::ClearError();    // otherwise remove the error so it won't get reported
00575 
00576         ok = FALSE;
00577     }
00578     END_CATCH
00579 
00580     // Make sure that the file is closed
00581     TRY
00582     {
00583         // Tidy up...
00584         GRMFile.DeinitLexer();
00585         if (GRMFile.isOpen()) GRMFile.close();
00586     }
00587     CATCH(CFileException, e)
00588     {
00589         // Failed to close the file - not much we can do about it really
00590         Error::ClearError();
00591     }
00592     END_CATCH
00593 
00594     if(!ok) ERROR3("LibSettings::AddLine - Something went wrong");
00595     return ok;
00596 }

BOOL LibSettings::AddSection String_256 Section,
String_256 pIniFileString = NULL
[static]
 

Adds a new section to the end of the grm file.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/5/95
Parameters:
Section - Section name to add to file [INPUTS] pIniFileString set to NULL if using default gallery ini file (Default) or to the leafname of the ini file to use
[OUTPUTS] 
Returns:
TRUE if this was successful.
Notes: This is essentially the same as AddLine but it gives us control of what sections look like.

Notes: As this is fairly general read and write ini file code, then this has been expanded so that an option other ini file name can be specified. If this is specified then this will be used instead of the GRM file name. Added by Neville 14/1/97 for saving/loading paths for plug-ins as the main ini file code cannot cope with the concept of sections filled with an arbitrary number of items which need cleaning out when resaving to remove old items no longer required.

Definition at line 626 of file sgrmfile.cpp.

00627 {
00628     ERROR3IF(Section == NULL, "LibSettings::AddSection - not happy with null params");
00629 
00630     String_256 Line("[");
00631     Line += *Section;
00632     Line += "]";
00633     return AddLine(&Line, pIniFileString);
00634 }

BOOL LibSettings::BuildList String_256 Section,
List OutputList
[static]
 

Given a section, build a list of entries in the section. This should speed reading lots of things from a section up by quite a bit...

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/1/96
Parameters:
Section - Section title for who contents should be popped in the list [INPUTS]
OutputList - Appends each line it finds to this list [OUTPUTS]
Returns:
TRUE if this was successful.

Definition at line 934 of file sgrmfile.cpp.

00935 {
00936     ERROR3IF(Section == NULL || OutputList == NULL, "LibSettings::BuildList given NULL jobbies...");
00937 
00938     BOOL AddedItems = FALSE;
00939     String_256 Entry;
00940     INT32 Line = 1;
00941 
00942     CCDiskFile GetEntryFile(1024, FALSE, TRUE);
00943 
00944     if(GetEntryStart(&GetEntryFile))
00945     {
00946         if(SeekToSection(&GetEntryFile, Section))
00947         {
00948             while(GetNextLine(&GetEntryFile, &Entry))
00949             {
00950                 LibSettingsListItem *LibSettingsItem = new LibSettingsListItem(&Entry);
00951                 OutputList->AddTail((ListItem *)LibSettingsItem);
00952                 AddedItems = TRUE;
00953             }
00954         }
00955 
00956         GetEntryFinish(&GetEntryFile);
00957     }
00958 
00959     return AddedItems;
00960 }

BOOL LibSettings::GetEntry String_256 Section,
INT32  Line,
String_256 Entry,
FilePos Pos = NULL,
String_256 pIniFileString = NULL
[static]
 

Returns a single line from the grm file.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/5/95
Parameters:
Section - Text to match with the section names [INPUTS] Line - Line offset in the section to return pIniFileString set to NULL if using default gallery ini file (Default) or to the leafname of the ini file to use
Entry - The line associated with the two input params [OUTPUTS] Pos - The FilePos after the item was found
Returns:
TRUE if this was successful. FALSE if we hit the next section, or EOF or if the file doesn't exist...
Notes: As this is fairly general read and write ini file code, then this has been expanded so that an option other ini file name can be specified. If this is specified then this will be used instead of the GRM file name. Added by Neville 14/1/97 for saving/loading paths for plug-ins as the main ini file code cannot cope with the concept of sections filled with an arbitrary number of items which need cleaning out when resaving to remove old items no longer required.

Definition at line 262 of file sgrmfile.cpp.

00264 {
00265     ERROR3IF(Entry == NULL, "LibSettings::GetEntry - not happy with null params");
00266 
00267     BOOL ok = FALSE;
00268 
00269     CCDiskFile GetEntryFile(1024, FALSE, TRUE);
00270 
00271     if(GetEntryStart(&GetEntryFile))
00272     {
00273         ok = GetEntryFromFile(&GetEntryFile, Section, Line, Entry, Pos);
00274     }
00275 
00276     GetEntryFinish(&GetEntryFile);
00277     
00278     return ok;  
00279 }

BOOL LibSettings::GetEntryFinish CCDiskFile DiskFile  )  [static]
 

Call after GetEntryStart, and after any GetEntryFromFile calls, but before killing the DiskFile off. This will close the file, and de-initialise the lexer, etc...

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/1/96
Parameters:
DiskFile - The DiskFile to tidy up [INPUTS]
[OUTPUTS] 
Returns:
TRUE if this was successful

Definition at line 363 of file sgrmfile.cpp.

00364 {
00365     if(DiskFile == NULL)
00366     {
00367         ERROR3("LibSettings::GetEntryFinish given null diskfile");
00368         return FALSE;
00369     }
00370 
00371     if(DiskFile == NULL)
00372         return TRUE;
00373 
00374     BOOL ok = TRUE;
00375 
00376     // Make sure that the files are closed and the memory is reclaimed properly...
00377     TRY
00378     {
00379         // Tidy up...
00380         DiskFile->DeinitLexer();
00381         if (DiskFile->isOpen()) DiskFile->close();
00382     }
00383     CATCH(CFileException, e)
00384     {
00385         // Failed to close the files - not much we can do about it really
00386         Error::ClearError();
00387         ok = FALSE;
00388     }
00389     END_CATCH
00390 
00391     return ok;
00392 }

BOOL LibSettings::GetEntryFromFile CCLexFile TheFile,
String_256 Section,
INT32  Line,
String_256 Entry,
FilePos Pos = NULL
[static]
 

Returns a single line from the grm file.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/1/96
Parameters:
TheFile - An open and initialised LexFile which we should be using [INPUTS] Section - Text to match with the section names Line - Line offset in the section to return
Entry - The line associated with the two input params [OUTPUTS] Pos - The FilePos after the item was found
Returns:
TRUE if this was successful. FALSE if we hit the next section, or EOF or if the file doesn't exist...

Definition at line 415 of file sgrmfile.cpp.

00417 {
00418     BOOL FoundLine = FALSE;
00419     BOOL ok = TRUE;
00420 
00421     TRY
00422     {
00423         // When we're doing lines in the section specified this will be true
00424         BOOL InOurSection = FALSE;
00425 
00426         // This will count the number of the lines since the last section header
00427         INT32 LineCount = 0;
00428 
00429         String_256 TokenBuffer;
00430         LexTokenType TokType = TOKEN_LINE;
00431 
00432         // Loop through file checking for sections and incrementing the line count
00433         // Finish at EOF, if we find a token, or if there was a problem...
00434         while(TokType != TOKEN_EOF && ok && !FoundLine && TheFile->GetLineToken())
00435         {
00436             TokType = TheFile->GetTokenType();
00437 
00438             if(TokType == TOKEN_LINE)
00439             {
00440                 TokenBuffer = TheFile->GetTokenBuf();
00441                 LineCount ++;
00442 
00443                 // Check if we've hit a new section name, if so check it and stop the output...
00444                 String_256 PossibleSectionName;             
00445                 if(IsThisANewSection(&TokenBuffer, &PossibleSectionName))
00446                 {
00447                     LineCount = 0;
00448                     if(InOurSection)
00449                     {
00450                         // ERROR3("LibSettings::GetEntry - Line outside section");
00451                         ok = FALSE;
00452                     }
00453                     InOurSection = (PossibleSectionName == *Section);
00454                 }
00455 
00456                 // Check if it's the line we're interested in or not
00457                 if(InOurSection && Line == LineCount)
00458                 {
00459                     *Entry = TokenBuffer;
00460                     FoundLine = TRUE;
00461                 }
00462             }
00463         }
00464     }
00465 
00466     // See if there was a file io error
00467     CATCH(CFileException, e)
00468     {
00469         // Something rather unhelpful has taken place...
00470         ok = FALSE;
00471 
00472         // Report the error if no one else did
00473         if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED))
00474             InformError();
00475         else
00476             Error::ClearError();    // otherwise remove the error so it won't get reported
00477     }
00478     END_CATCH
00479 
00480     TRY
00481     {
00482         // Tidy up...
00483         if(Pos != NULL)
00484             *Pos = TheFile->tellIn();
00485     }
00486     CATCH(CFileException, e)
00487     {
00488         // Failed to close the files - not much we can do about it really
00489         Error::ClearError();
00490     }
00491     END_CATCH
00492 
00493 #ifdef _DEBUG
00494     // Something went wrong...
00495     if(!ok && FoundLine)
00496     {
00497         PathName GRMPath;
00498         if(GetPathName(&GRMPath))
00499             if(SGLibOil::FileExists(&GRMPath))
00500                 ERROR3("LibSettings::GetEntry - Something went wrong...");
00501     }
00502 #endif
00503 
00504     return (FoundLine && ok);
00505 }

BOOL LibSettings::GetEntryStart CCDiskFile DiskFile,
String_256 pIniFileString = NULL
[static]
 

Call with a pre-created, but not initialised CCDiskFile. After calling this, calls to GetEntryFromFile can be passed this diskfile. When finished, call GetEntryFinish with the DiskFile to De-do all the stuff we done here, like...

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/1/96
Parameters:
DiskFile - The DiskFile to use in following GetEntryFromFile calls [INPUTS] pIniFileString set to NULL if using default gallery ini file (Default) or to the leafname of the ini file to use
DiskFile - This will be initialised and opened withe the correct grm file [OUTPUTS]
Returns:
TRUE if this was successful
Notes: As this is fairly general read and write ini file code, then this has been expanded so that an option other ini file name can be specified. If this is specified then this will be used instead of the GRM file name. Added by Neville 14/1/97 for saving/loading paths for plug-ins as the main ini file code cannot cope with the concept of sections filled with an arbitrary number of items which need cleaning out when resaving to remove old items no longer required.

Definition at line 308 of file sgrmfile.cpp.

00309 {
00310     if(DiskFile == NULL)
00311     {
00312         ERROR3("LibSettings::GetEntryStart given null diskfile");
00313         return FALSE;
00314     }
00315     
00316     // Get the pathname of the grm file
00317     PathName GRMPath;
00318     if(!GetPathName(&GRMPath, pIniFileString))
00319     {
00320         ERROR3("LibSettings::GetEntryStart couldn't even get the pathname without going wrong...");
00321         return FALSE;
00322     }
00323 
00324     if(!DiskFile->InitLexer(TRUE))
00325     {
00326         ERROR3("LibSettings::GetEntryStart - Problems with InitLexer");
00327         return FALSE;
00328     }
00329 
00330     TRY
00331     {
00332         // Open the GRM file
00333         if(!DiskFile->open(GRMPath, ios::in | ios::nocreate))
00334             return FALSE;
00335     }   
00336     CATCH(CFileException, e)
00337     {
00338         // Something bad happened with the GRM file. It possibly doesn't exist...
00339         Error::ClearError();
00340         return FALSE;
00341     }
00342     END_CATCH
00343 
00344     return TRUE;
00345 }

BOOL LibSettings::GetNextLine CCDiskFile TheFile,
String_256 Line
[static]
 

Output the next line of the file passed in. Return FALSE if problems.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/1/96
Parameters:
TheFile - Open and seeked lex/disk file [INPUTS]
Line - Will contain the next line (if we return TRUE) [OUTPUTS]
Returns:
TRUE if this was successful and a line was found and placed in Line.
Notes: If we hit a section title, we also return FALSE

Definition at line 979 of file sgrmfile.cpp.

00980 {
00981     BOOL FoundLine = FALSE;
00982     BOOL ok = TRUE;
00983 
00984     TRY
00985     {
00986         String_256 TokenBuffer;
00987         LexTokenType TokType = TOKEN_LINE;
00988 
00989         while(TokType != TOKEN_EOF && !FoundLine && TheFile->GetLineToken())
00990         {
00991             TokType = TheFile->GetTokenType();
00992             if(TokType == TOKEN_LINE)
00993             {
00994                 TokenBuffer = TheFile->GetTokenBuf();
00995 
00996                 // Check if we've hit a new section name, if so check it and stop the output...
00997                 String_256 PossibleSectionName;             
00998                 if(IsThisANewSection(&TokenBuffer, &PossibleSectionName))
00999                     return FALSE;
01000 
01001                 *Line = TokenBuffer;
01002                 FoundLine = TRUE;
01003             }
01004         }
01005     }
01006 
01007     // See if there was a file io error
01008     CATCH(CFileException, e)
01009     {
01010         // Something rather unhelpful has taken place...
01011         ok = FALSE;
01012 
01013         // Report the error if no one else did
01014         if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED))
01015             InformError();
01016         else
01017             Error::ClearError();    // otherwise remove the error so it won't get reported
01018     }
01019     END_CATCH
01020 
01021     return (FoundLine && ok);
01022 }

BOOL LibSettings::GetPathName PathName PathName,
String_256 pIniFileString = NULL
[static]
 

Returns the path and filename for the gallery resource management file... Currently this file holds the groups in the gallery for use when it next starts up...

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/5/95
Parameters:
pIniFileString set to NULL if using default gallery ini file (Default) [INPUTS] or to the leafname of the ini file to use
PathName - returns the pathname of the settings file in c:, or wherever [OUTPUTS]
Returns:
TRUE if successful
Notes: As this is fairly general read and write ini file code, then this has been expanded so that an option other ini file name can be specified. If this is specified then this will be used instead of the GRM file name. Added by Neville 14/1/97 for saving/loading paths for plug-ins as the main ini file code cannot cope with the concept of sections filled with an arbitrary number of items which need cleaning out when resaving to remove old items no longer required.

Definition at line 879 of file sgrmfile.cpp.

00880 {
00881     ERROR3IF(PathName == NULL, "LibSettings::GetPathName - not happy with null params");
00882 
00883     String_256 GRMFile;
00884 
00885     // Have a look in the windows directory for our GRM file...
00886     UINT32 Len = GetWindowsDirectory((TCHAR *)GRMFile, 255);
00887     if ((Len > 0) && (Len < _MAX_PATH))
00888     {
00889         GRMFile += "\\";
00890         // File was called XStudio.grm or XViewer.grm
00891         // We will now call them all CorelX##.ini where ## in this case is GM
00892         String_256 File(PRODUCT_GALLERY_INIFILE);
00893         // If somebody has asked us to use a different ini file name then use this instead
00894         if (pIniFileString != NULL)
00895             File = *pIniFileString;
00896 
00897         GRMFile += File;
00898 
00899         //TRACEUSER( "Richard", _T("Path Gallery Resource Management file - %s\n"), (TCHAR *)GRMFile);
00900 
00901         PathName->SetPathName(GRMFile);
00902         if(!PathName->IsValid())
00903         {
00904             Error::ClearError();
00905             ERROR3("LibSettings::GetPathName - invalid pathname");
00906             return FALSE;
00907         }
00908         
00909         return TRUE;
00910     }
00911 
00912     ERROR3("LibSettings::GetPathName - Problems getting the windows directory name for the Gallery Resource Management file");
00913 
00914     // oops .. Problems getting the windows directory name
00915     return FALSE;
00916 }

BOOL LibSettings::Init void   )  [static]
 

Value returning initialisation routine...

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/5/95
Parameters:
[INPUTS] 
[OUTPUTS] 
Returns:

Reimplemented from SimpleCCObject.

Definition at line 228 of file sgrmfile.cpp.

00229 {
00230     return TRUE;
00231 }

BOOL LibSettings::IsThisANewSection String_256 Line,
String_256 Section
[static]
 

Checks if a given line is a new section or not and returns the section name if it is...

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/5/95
Parameters:
Line - Line of text to check [INPUTS]
Section - The actual section name itself [OUTPUTS]
Returns:
TRUE if this line is a new section name

Definition at line 652 of file sgrmfile.cpp.

00653 {
00654     ERROR3IF(Section == NULL, "LibSettings::IsThisANewSection - not happy with null params");
00655     ERROR3IF(Line == NULL, "LibSettings::IsThisANewSection - not happy with null params");
00656 
00657     if((Line->Sub((String_8)"[") != -1) && (Line->Sub((String_8)"]") != -1))
00658     {
00659         INT32 first = Line->Sub((String_8)"[");
00660         INT32 second = Line->Sub((String_8)"]");
00661 
00662         if(first < second-1)
00663         {
00664             Line->Mid(Section, first+1, (second - first)-1);
00665             return TRUE;
00666         }
00667     }
00668     return FALSE;
00669 }

BOOL LibSettings::NukeSettings String_256 pIniFileString = NULL  )  [static]
 

Delete all the settings from the gallery resource file.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/6/95
Parameters:
[INPUTS] 
[OUTPUTS] 
Returns:
TRUE if this was successful.
This will be called when the user hits 'default' at startup, so the galleries will have to find some other way of working out where their groups are - the ini file for instance, but since this will also have been destroyed, there only remains 1 place - the default static setting - eek !

Notes: As this is fairly general read and write ini file code, then this has been expanded so that an option other ini file name can be specified. If this is specified then this will be used instead of the GRM file name. Added by Neville 14/1/97 for saving/loading paths for plug-ins as the main ini file code cannot cope with the concept of sections filled with an arbitrary number of items which need cleaning out when resaving to remove old items no longer required.

Definition at line 844 of file sgrmfile.cpp.

00845 {
00846     PathName GRMFile;
00847     if(LibSettings::GetPathName(&GRMFile, pIniFileString))
00848     {
00849         SGLibOil::FileDelete(&GRMFile);
00850         return TRUE;
00851     }
00852     return FALSE;
00853 }

BOOL LibSettings::SeekToSection CCDiskFile TheFile,
String_256 Section
[static]
 

Hunt down our section in the grm file.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/1/96
Parameters:
TheFile - Open lex/disk file (preferably not seeked half way through) [INPUTS] Section - The section we're a'looking for
Returns:
TRUE if this was successful and we're now seeked to the EOL after the section name

Definition at line 1038 of file sgrmfile.cpp.

01039 {
01040     TRY
01041     {
01042         String_256 TokenBuffer;
01043         LexTokenType TokType = TOKEN_LINE;
01044 
01045         while(TokType != TOKEN_EOF && TheFile->GetLineToken())
01046         {
01047             TokType = TheFile->GetTokenType();
01048             if(TokType == TOKEN_LINE)
01049             {
01050                 TokenBuffer = TheFile->GetTokenBuf();
01051 
01052                 // Check if we've hit a new section name, if so check it and stop the output...
01053                 String_256 PossibleSectionName;             
01054                 if(IsThisANewSection(&TokenBuffer, &PossibleSectionName))
01055                 {
01056                     if(PossibleSectionName == *Section)
01057                         return TRUE;
01058                 }
01059             }
01060         }
01061     }
01062 
01063     // See if there was a file io error
01064     CATCH(CFileException, e)
01065     {
01066         // Report the error if no one else did
01067         if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED))
01068             InformError();
01069         else
01070             Error::ClearError();    // otherwise remove the error so it won't get reported
01071     }
01072     END_CATCH
01073 
01074     return FALSE;
01075 }

BOOL LibSettings::StartOutput String_256 Section,
String_256 pIniFileString = NULL
[static]
 

Checks if there's already a grm file on the disk. If so, create a new .bak file holding copies of all the sections (except the one specified), then copy this new file over the old .grm file.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/5/95
Parameters:
Section - The section we're about to add [INPUTS] pIniFileString set to NULL if using default gallery ini file (Default) or to the leafname of the ini file to use
[OUTPUTS] 
Returns:
TRUE if this was successful.
Doing this means that future calls to AddLine will append the information to the end of the grm file, and there won't be any duplication.

Notes: This avoids the old system of sending a message around all the galleries, and also means that unopened galleries don't need to store a list of their groups.

Also, if there's a crisis, the old grm file is still on the disk...

Notes: As this is fairly general read and write ini file code, then this has been expanded so that an option other ini file name can be specified. If this is specified then this will be used instead of the GRM file name. Added by Neville 14/1/97 for saving/loading paths for plug-ins as the main ini file code cannot cope with the concept of sections filled with an arbitrary number of items which need cleaning out when resaving to remove old items no longer required.

Definition at line 706 of file sgrmfile.cpp.

00707 {
00708     ERROR3IF(Section == NULL, "LibSettings::StartOutput - not happy with null params");
00709 
00710     // Get the pathname of the grm file
00711     PathName GRMPath;
00712     BOOL ok = GetPathName(&GRMPath, pIniFileString);
00713     if(!ok)
00714     {
00715         ERROR3("LibSettings::StartOutput couldn't even get the pathname without going wrong...");
00716         return FALSE;
00717     }
00718 
00719     if(!SGLibOil::FileExists(&GRMPath))
00720     {
00721         // No existing GRM file, don't bother keeping its contents...
00722         return TRUE;
00723     }
00724 
00725     PathName BAKPath(GRMPath);
00726     BAKPath.SetType("bak");
00727 
00728     CCDiskFile GRMFile(1024, FALSE, TRUE);
00729     CCDiskFile BAKFile(1024, FALSE, TRUE);
00730 
00731     TRY
00732     {
00733         if (!GRMFile.InitLexer(FALSE) || !BAKFile.InitLexer(FALSE))
00734         {
00735             ERROR3("LibSettings::StartOutput - Problems with InitLexer");
00736             ok = FALSE;
00737         }
00738 
00739         if(ok) ok = GRMFile.open(GRMPath, ios::in | ios::nocreate);
00740         if(ok) ok = BAKFile.open(BAKPath, ios::out);
00741         
00742         if(ok)
00743         {
00744             // When we're doing lines in the section specified this will be true
00745             BOOL InOurSection = FALSE;
00746             BOOL Finished = FALSE;
00747 
00748             String_256 TokenBuffer;
00749             LexTokenType TokType = TOKEN_LINE;
00750 
00751             // Read and write the lines...
00752             while(TokType != TOKEN_EOF && ok && GRMFile.GetLineToken())
00753             {
00754                 TokType = GRMFile.GetTokenType();
00755 
00756                 if(TokType == TOKEN_LINE)
00757                 {
00758                     TokenBuffer = GRMFile.GetTokenBuf();
00759 
00760                     // Check if we've hit a new section name, if so check it and stop the output...
00761                     String_256 PossibleSectionName;             
00762                     if(IsThisANewSection(&TokenBuffer, &PossibleSectionName))
00763                         InOurSection = (PossibleSectionName == *Section);
00764 
00765                     // If it's not the specified section, write the line straight out to the bak file
00766                     if(!InOurSection)
00767                     {
00768                         if(ok) ok = BAKFile.PutToken(TokenBuffer, (String_8)"\r\n");
00769                     }
00770                 }
00771             }
00772         }
00773     }
00774 
00775     // See if there was a file io error
00776     CATCH(CFileException, e)
00777     {
00778         // Something rather unhelpful has taken place...
00779         ok = FALSE;
00780 
00781         // Report the error if no one else did
00782         if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED))
00783             InformError();
00784         else
00785             Error::ClearError();    // otherwise remove the error so it won't get reported
00786     }
00787     END_CATCH
00788 
00789     // Make sure that the files are closed and the memory is reclaimed properly...
00790     TRY
00791     {
00792         // Tidy up...
00793         GRMFile.DeinitLexer();
00794         BAKFile.DeinitLexer();
00795         if (GRMFile.isOpen()) GRMFile.close();
00796         if (BAKFile.isOpen()) BAKFile.close();
00797     }
00798     CATCH(CFileException, e)
00799     {
00800         // Failed to close the files - not much we can do about it really
00801         Error::ClearError();
00802     }
00803     END_CATCH
00804 
00805     // Copy the BAK file over the GRM file
00806     if(ok) SGLibOil::FileDelete(&GRMPath);
00807     if(ok) ok = SGLibOil::FileCopy(&BAKPath, &GRMPath);
00808     
00809     // Always delete the bak file, whatever happened
00810     SGLibOil::FileDelete(&BAKPath);
00811 
00812     // Something went wrong...
00813     if(!ok) ERROR3("LibSettings::StartOutput - Something went wrong...");
00814     return ok;
00815 }


Member Data Documentation

CCDiskFile* LibSettings::DiskFile [static]
 

Definition at line 183 of file sgrmfile.h.


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