示例#1
0
bool KLUPD::IniFile::save()
{
    if(m_fileName.empty())
    {
        TRACE_MESSAGE("Failed to save ini file, because no file name is specified");
        return false;
    }

    FileStream file(pLog);
    if(!file.open(m_fileName, std::ios::out | std::ios::trunc))
    {
        TRACE_MESSAGE2("Unable to save ini configuration file, because unable to open file '%S'", m_fileName.toWideChar());
        return false;
    }

    for(std::vector<Section>::const_iterator sectionIter = m_sections.begin(); sectionIter != m_sections.end(); ++sectionIter)
    {
        bool wroteComment = false;
        if(!sectionIter->m_comment.empty())
        {
            wroteComment = true;
            file.writeLine(NoCaseString(L"\n") + commentStr(sectionIter->m_comment));
        }

        if(!sectionIter->m_name.empty())
        {
            NoCaseString buffer = wroteComment ? L"\n" : L"";
            buffer += NoCaseString(L"[") + sectionIter->m_name + L"]";
            file.writeLine(buffer);
        }

        for(std::vector<Key>::const_iterator keyIter = sectionIter->m_keys.begin(); keyIter != sectionIter->m_keys.end(); ++keyIter)
        {
            if(keyIter->m_key.empty())
                continue;

            NoCaseString buffer = keyIter->m_comment.empty() ? L"" : L"\n";
            buffer += commentStr(keyIter->m_comment);
            buffer += keyIter->m_comment.empty() ? L"" : L"\n";
            buffer += keyIter->m_key.toWideChar();
            buffer += s_equalIndicators[0];
            buffer += keyIter->m_value;

            file.writeLine(buffer);
        }
    }

    m_dirty = false;
    return true;
}
示例#2
0
bool ossimKeywordlist::write(const char* file, 
                             const char* comment) const
{
   std::ofstream filename(file);
   if (!filename)
   {
      ossimNotify(ossimNotifyLevel_WARN)
      <<"ossimKeywordlist::write, Error opening file:  "
      << file << std::endl;
      return false;
   }

   if ( comment != 0 )
   {
      ossimString commentStr("// ");
      commentStr += comment;

      // Write out the input comment to the first line.
      filename << commentStr.c_str() << std::endl;
   }

   writeToStream(filename);
   
   filename.close();
   
   return true;
}