Changeset 1546 for trunk/gsinstaller


Ignore:
Timestamp:
2000-09-14T03:19:34+12:00 (24 years ago)
Author:
cs025
Message:

Fixed a problem with VC++ - it didn't create the install.log file when the stream
was opened to it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsinstaller/unInstall.cpp

    r1543 r1546  
    66
    77bool installManager::openLog(string filename, bool write)
    8 {
    9   string command;
    10   stringArray params;
    11 
    12   if (this->logfile.rdbuf()->is_open())
    13     {
    14       this->closeLog();
    15     }
    16   this->logfileName = filename;
    17   this->logfile.open(filename.c_str(), ios::out | ios::in);
    18   if (write == false)
    19     {
    20       while ((command = this->readCommand(params)) != "")
    21     {
    22       if (command[0] == '[' && command[command.length()-1] == ']')
    23         {
    24           this->setModule(command.substr(1, command.length() - 2));
    25         }
    26       else
    27         {
    28           unInstallCommand action(command, params);
    29           this->storeCommand(action);
    30         }
     8{ string command;
     9    stringArray params;
     10
     11  // close the log if already open
     12    if (this->logfile.rdbuf()->is_open())
     13    {   this->closeLog();
    3114    }
    32     }
     15
     16  // note the new file details and do an open
     17    this->logfileName = filename;
     18    this->logfile.open(filename.c_str(), ios::out | ios::in);
     19
     20  // if the file didn't open, then this is almost certainly being compiled
     21  // with Microsoft Visual C++ which has a library which fails to open the
     22  // file if it doesn't already exist.  Do a createfile and hope for success.
     23  // TODO: add proper error handling here
     24    if (!this->logfile.rdbuf()->is_open() && write == true)
     25    { HANDLE fHandle;
     26
     27    fHandle = CreateFile(filename.c_str(), GENERIC_READ | GENERIC_WRITE,
     28                         FILE_SHARE_WRITE, NULL, CREATE_NEW,
     29                             FILE_ATTRIBUTE_NORMAL, NULL);
     30    if (fHandle)
     31    { CloseHandle(fHandle);
     32    }
     33        this->logfile.open(filename.c_str(), ios::out | ios::in);
     34    }
     35
     36  // if we aren't seeking write access, then get the commands into this
     37  // object
     38    if (write == false)
     39    {   while ((command = this->readCommand(params)) != "")
     40        {   if (command[0] == '[' && command[command.length()-1] == ']')
     41            { this->setModule(command.substr(1, command.length() - 2));
     42        }
     43        else
     44        {   unInstallCommand action(command, params);
     45            this->storeCommand(action);
     46        }
     47    }
     48  }
     49
     50  // set to the default module
    3351  this->setModule("default");
    3452  return true;
     
    3654
    3755bool installManager::reopenLog()
    38 {
    39   if (this->logfile.rdbuf()->is_open())
    40     {
    41       this->logfile.close();
    42     }
     56{ if (this->logfile.rdbuf()->is_open())
     57  { this->logfile.close();
     58  }
    4359  else
    44     {
    45       this->logfile.close();
    46     }
     60  { this->logfile.close();
     61    }
    4762 
    4863  this->logfile.open(this->logfileName.c_str(), ios::out | ios::in);
     
    5166
    5267void installManager::setModule(string moduleName)
    53 {
    54   this->currentModule = moduleName;
     68{   this->currentModule = moduleName;
    5569}
    5670
    5771bool installManager::storeCommand(unInstallCommand &command)
    58 {
    59   this->modules[this->currentModule].push_back(command);
    60   return true;
     72{ this->modules[this->currentModule].push_back(command);
     73    return true;
    6174}
    6275
    6376bool installManager::writeCommand(unInstallCommand &command)
    64 {
    65   if (!this->writeString(command.command))
    66     {
    67       return false;
    68     }
    69   for (unsigned int p = 0; p < command.parameters.size(); p ++)
    70     {
    71       if (!this->writeSeparator())
    72     {
    73       return false;
    74     }
    75       if (!this->writeString(command.parameters[p]))
    76     {
    77       return false;
    78     }
    79     }
     77{ if (!this->writeString(command.command))
     78    { return false;
     79  }
     80    for (unsigned int p = 0; p < command.parameters.size(); p ++)
     81  { if (!this->writeSeparator())
     82    { return false;
     83    }
     84    if (!this->writeString(command.parameters[p]))
     85    { return false;
     86    }
     87  }
    8088  if (!this->writeString("\n"))
    81     {
    82       return false;
    83     }
     89  { return false;
     90  }
    8491  return true;
    8592}
    8693
    8794bool installManager::writeString(char *buffer)
    88 {
    89   string s(buffer);
    90   return this->writeString(s);
     95{ string s(buffer);
     96    return this->writeString(s);
    9197}
    9298
    9399bool installManager::writeString(string str)
    94 {
    95   bool quote;
    96  
    97   // TODO: check for space characters in str and quote if necessary
     100{ bool quote;
     101
     102    // TODO: check for space characters in str and quote if necessary
    98103  quote = str.find_first_of(' ') < str.length();
    99104
     105    if (quote)
     106  { this->logfile << "\"";
     107  }
     108    this->logfile << str;
    100109  if (quote)
    101     {
    102       this->logfile << "\"";
    103     }
    104   this->logfile << str;
    105   if (quote)
    106     {
    107       this->logfile << "\"";
    108     }
     110  { this->logfile << "\"";
     111  }
    109112  return true;
    110113}
    111114
    112115bool installManager::writeSeparator()
    113 {
    114   this->logfile << " ";
    115   return true;
     116{   this->logfile << " ";
     117    return true;
    116118}
    117119
    118120string installManager::readString()
    119 {
    120   string reply = "";
    121   char c;
     121{   string reply = "";
     122    char c;
    122123
    123124  if (this->logfile.eof())
    124     {
    125       return reply;
    126     }
     125    {   return reply;
     126  }
    127127
    128128  this->logfile >> c;
    129129  while (c <= ' ' && !this->logfile.eof())
    130     {   
    131       this->logfile.get();
    132     }
     130  { this->logfile.get();
     131  }
    133132
    134133  if (this->logfile.eof())
    135     {
    136       return reply;
    137     }
     134  { return reply;
     135  }
    138136
    139137  if (c == '\"')
    140     {
    141       do
    142     {
    143       c = this->logfile.get();
    144       if (c != '\"')
    145         {
    146           reply += c;
    147         }
    148     }
    149       while (c != '\"' && !this->logfile.eof());
    150     }
     138  { do
     139    {   c = this->logfile.get();
     140        if (c != '\"')
     141      { reply += c;
     142      }
     143    }
     144    while (c != '\"' && !this->logfile.eof());
     145  }
    151146  else
    152     {
    153       while (c > ' ')
    154     {
    155       reply += c;
    156       if (this->logfile.eof())
    157         {
    158           break;
    159         }
    160       c = this->logfile.get();
    161     }
    162       if (!this->logfile.eof())
    163     {
    164       this->logfile.putback(c);
    165     }
    166       //this->logfile >> reply;
    167     }
     147  { while (c > ' ')
     148    { reply += c;
     149        if (this->logfile.eof())
     150      { break;
     151      }
     152        c = this->logfile.get();
     153    }
     154    if (!this->logfile.eof())
     155    {   this->logfile.putback(c);
     156    }
     157    //this->logfile >> reply;
     158  }
    168159  return reply;
    169160}
    170161
    171162string installManager::readCommand(stringArray &array)
    172 {
    173   string reply = "";
     163{   string reply = "";
    174164  char c;
    175165
     
    177167
    178168  if (this->logfile.eof())
    179     {
    180       return reply;
    181     }
    182 
    183   reply = this->readString();
     169  { return reply;
     170  }
     171
     172    reply = this->readString();
    184173  if (reply == "")
    185     {
    186       return reply;
    187     }
     174  { return reply;
     175  }
    188176
    189177  while(!this->logfile.eof() &&
    190     (c = this->logfile.get()) != '\n')
    191     {
    192       this->logfile.putback(c);
    193       array.add(this->readString());
    194     }
     178            (c = this->logfile.get()) != '\n')
     179  { this->logfile.putback(c);
     180    array.add(this->readString());
     181  }
    195182  if (!this->logfile.eof())
    196     {
    197       this->logfile.putback(c);
    198     }
     183  { this->logfile.putback(c);
     184  }
    199185
    200186  return reply;
     
    202188
    203189string installManager::popCommand(stringArray &array)
    204 {
    205   string command;
     190{ string command;
    206191
    207192  if (this->modules[this->currentModule].size() == 0)
    208     {
    209       command = "";
    210     }
     193  { command = "";
     194  }
    211195  else
    212     {
    213       unsigned int last;
    214 
    215       last = this->modules[this->currentModule].size() - 1;
    216       command = this->modules[this->currentModule][last].commandName();
    217       array = this->modules[this->currentModule][last].parameterList();
    218       this->modules[this->currentModule].erase(this->modules[this->currentModule].begin() + last);
    219     }
     196  { unsigned int last;
     197
     198      last = this->modules[this->currentModule].size() - 1;
     199    command = this->modules[this->currentModule][last].commandName();
     200    array       = this->modules[this->currentModule][last].parameterList();
     201    this->modules[this->currentModule].erase(this->modules[this->currentModule].begin() + last);
     202  }
    220203  return command;
    221204}
    222205
    223206bool installManager::closeLog()
    224 {
    225   if (this->logfile.rdbuf()->is_open() == false)
    226     {
    227       return false;
    228     }
    229 
    230   unInstallCommandMap::iterator here = this->modules.begin();
    231   unInstallCommandMap::iterator end = this->modules.end();
    232  
     207{ if (this->logfile.rdbuf()->is_open() == false)
     208  { return false;
     209  }
     210
     211    unInstallCommandMap::iterator here = this->modules.begin();
     212    unInstallCommandMap::iterator end  = this->modules.end();
     213
    233214  while (here != end)
    234     {
    235       this->writeString("[" + (*here).first + "]\n");
    236 
    237       unInstallCommandList::iterator ahere = (*here).second.begin();
    238       unInstallCommandList::iterator aend  = (*here).second.end();
    239       while (ahere != aend)
    240     {
    241       this->writeCommand(*ahere);
    242       ahere ++;
    243     }
    244       here ++;
    245     }
    246   this->logfile.close();
     215  { this->writeString("[" + (*here).first + "]\n");
     216
     217    unInstallCommandList::iterator  ahere = (*here).second.begin();
     218    unInstallCommandList::iterator  aend  = (*here).second.end();
     219    while (ahere != aend)
     220        { this->writeCommand(*ahere);
     221        ahere ++;
     222    }
     223    here ++;
     224  }
     225    this->logfile.close();
    247226  return true;
    248227}
    249228
    250229bool installManager::isEmpty()
    251 {
    252   unInstallCommandMap::iterator here = this->modules.begin();
    253   unInstallCommandMap::iterator end = this->modules.end();
     230{ unInstallCommandMap::iterator here = this->modules.begin();
     231    unInstallCommandMap::iterator end  = this->modules.end();
    254232
    255233  while (here != end)
    256     {
    257       this->writeString("[" + (*here).first + "]\n");
    258 
    259       unInstallCommandList::iterator    ahere = (*here).second.begin();
    260       unInstallCommandList::iterator  aend  = (*here).second.end();
    261       if (ahere != aend)
    262     {
    263       return false;
    264     }
    265       here ++;
    266     }
     234  { this->writeString("[" + (*here).first + "]\n");
     235
     236    unInstallCommandList::iterator  ahere = (*here).second.begin();
     237    unInstallCommandList::iterator  aend  = (*here).second.end();
     238    if (ahere != aend)
     239    {   return false;
     240    }
     241    here ++;
     242  }
    267243  return true;
    268244}
    269245
    270246installManager::~installManager()
    271 {
    272   if (this->logfile.rdbuf()->is_open())
    273     {
    274       this->closeLog();
    275     }
    276 }
     247{   if (this->logfile.rdbuf()->is_open())
     248    {   this->closeLog();
     249  }
     250}
     251
     252
Note: See TracChangeset for help on using the changeset viewer.