< prev index next >

src/jdk.incubator.jpackage/share/native/libapplauncher/IniFile.cpp

Print this page




  92                         Append(sectionName, name, value);
  93                     }
  94                 }
  95             }
  96 
  97             result = true;
  98         }
  99     }
 100 
 101     return result;
 102 }
 103 
 104 bool IniFile::SaveToFile(const TString FileName, bool ownerOnly) {
 105     bool result = false;
 106 
 107     std::list<TString> contents;
 108     std::vector<TString> keys = FMap.GetKeys();
 109 
 110     for (unsigned int index = 0; index < keys.size(); index++) {
 111         TString name = keys[index];
 112         IniSectionData *section;
 113 
 114         if (FMap.GetValue(name, section) == true) {
 115             contents.push_back(_T("[") + name + _T("]"));
 116             std::list<TString> lines = section->GetLines();
 117             contents.insert(contents.end(), lines.begin(), lines.end());
 118             contents.push_back(_T(""));
 119         }
 120     }
 121 
 122     Platform& platform = Platform::GetInstance();
 123     platform.SaveToFile(FileName, contents, ownerOnly);
 124     result = true;
 125     return result;
 126 }
 127 
 128 void IniFile::Append(const TString SectionName,
 129         const TString Key, TString Value) {
 130     if (FMap.ContainsKey(SectionName) == true) {
 131         IniSectionData* section;
 132 
 133         if (FMap.GetValue(SectionName, section) == true && section != NULL) {
 134             section->SetValue(Key, Value);
 135         }
 136     }
 137     else {
 138         IniSectionData *section = new IniSectionData();
 139         section->SetValue(Key, Value);
 140         FMap.Append(SectionName, section);
 141     }
 142 }
 143 
 144 void IniFile::AppendSection(const TString SectionName,
 145         OrderedMap<TString, TString> Values) {
 146     if (FMap.ContainsKey(SectionName) == true) {
 147         IniSectionData* section;
 148 
 149         if (FMap.GetValue(SectionName, section) == true && section != NULL) {
 150             section->Append(Values);
 151         }
 152     }
 153     else {
 154         IniSectionData *section = new IniSectionData(Values);
 155         FMap.Append(SectionName, section);
 156     }
 157 }
 158 
 159 bool IniFile::GetValue(const TString SectionName,
 160         const TString Key, TString& Value) {
 161     bool result = false;
 162     IniSectionData* section;
 163 
 164     if (FMap.GetValue(SectionName, section) == true && section != NULL) {
 165         result = section->GetValue(Key, Value);
 166     }
 167 
 168     return result;
 169 }
 170 
 171 bool IniFile::SetValue(const TString SectionName,
 172         const TString Key, TString Value) {
 173     bool result = false;
 174     IniSectionData* section;
 175 
 176     if (FMap.GetValue(SectionName, section) && section != NULL) {
 177         result = section->SetValue(Key, Value);
 178     }
 179     else {
 180         Append(SectionName, Key, Value);
 181     }
 182 
 183 
 184     return result;
 185 }
 186 
 187 bool IniFile::GetSection(const TString SectionName,
 188         OrderedMap<TString, TString> &Data) {
 189     bool result = false;
 190 
 191     if (FMap.ContainsKey(SectionName) == true) {
 192         IniSectionData* section = NULL;
 193 
 194         if (FMap.GetValue(SectionName, section) == true && section != NULL) {




  92                         Append(sectionName, name, value);
  93                     }
  94                 }
  95             }
  96 
  97             result = true;
  98         }
  99     }
 100 
 101     return result;
 102 }
 103 
 104 bool IniFile::SaveToFile(const TString FileName, bool ownerOnly) {
 105     bool result = false;
 106 
 107     std::list<TString> contents;
 108     std::vector<TString> keys = FMap.GetKeys();
 109 
 110     for (unsigned int index = 0; index < keys.size(); index++) {
 111         TString name = keys[index];
 112         IniSectionData *section = NULL;
 113 
 114         if (FMap.GetValue(name, section) == true && section != NULL) {
 115             contents.push_back(_T("[") + name + _T("]"));
 116             std::list<TString> lines = section->GetLines();
 117             contents.insert(contents.end(), lines.begin(), lines.end());
 118             contents.push_back(_T(""));
 119         }
 120     }
 121 
 122     Platform& platform = Platform::GetInstance();
 123     platform.SaveToFile(FileName, contents, ownerOnly);
 124     result = true;
 125     return result;
 126 }
 127 
 128 void IniFile::Append(const TString SectionName,
 129         const TString Key, TString Value) {
 130     if (FMap.ContainsKey(SectionName) == true) {
 131         IniSectionData* section = NULL;
 132 
 133         if (FMap.GetValue(SectionName, section) == true && section != NULL) {
 134             section->SetValue(Key, Value);
 135         }
 136     }
 137     else {
 138         IniSectionData *section = new IniSectionData();
 139         section->SetValue(Key, Value);
 140         FMap.Append(SectionName, section);
 141     }
 142 }
 143 
 144 void IniFile::AppendSection(const TString SectionName,
 145         OrderedMap<TString, TString> Values) {
 146     if (FMap.ContainsKey(SectionName) == true) {
 147         IniSectionData* section = NULL;
 148 
 149         if (FMap.GetValue(SectionName, section) == true && section != NULL) {
 150             section->Append(Values);
 151         }
 152     }
 153     else {
 154         IniSectionData *section = new IniSectionData(Values);
 155         FMap.Append(SectionName, section);
 156     }
 157 }
 158 
 159 bool IniFile::GetValue(const TString SectionName,
 160         const TString Key, TString& Value) {
 161     bool result = false;
 162     IniSectionData* section = NULL;
 163 
 164     if (FMap.GetValue(SectionName, section) == true && section != NULL) {
 165         result = section->GetValue(Key, Value);
 166     }
 167 
 168     return result;
 169 }
 170 
 171 bool IniFile::SetValue(const TString SectionName,
 172         const TString Key, TString Value) {
 173     bool result = false;
 174     IniSectionData* section = NULL;
 175 
 176     if (FMap.GetValue(SectionName, section) && section != NULL) {
 177         result = section->SetValue(Key, Value);
 178     }
 179     else {
 180         Append(SectionName, Key, Value);
 181     }
 182 
 183 
 184     return result;
 185 }
 186 
 187 bool IniFile::GetSection(const TString SectionName,
 188         OrderedMap<TString, TString> &Data) {
 189     bool result = false;
 190 
 191     if (FMap.ContainsKey(SectionName) == true) {
 192         IniSectionData* section = NULL;
 193 
 194         if (FMap.GetValue(SectionName, section) == true && section != NULL) {


< prev index next >