1
0

inifile.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include <precomp.h>
  2. #include "inifile.h"
  3. #include <bfc/nsguid.h>
  4. #ifndef WIN32
  5. #include "profile.h"
  6. #endif
  7. IniFile::IniFile(const wchar_t *_filename) : filename(_filename) { }
  8. void IniFile::setString(const wchar_t *section, const wchar_t *tagname, const wchar_t *val) {
  9. WritePrivateProfileStringW(section, tagname, val, filename);
  10. }
  11. wchar_t *IniFile::getString(const wchar_t *section, const wchar_t *tagname, wchar_t *buf, int buflen, const wchar_t *default_val) {
  12. GetPrivateProfileStringW(section, tagname, default_val, buf, buflen, filename);
  13. return buf;
  14. }
  15. StringW IniFile::getString(const wchar_t *section, const wchar_t *tagname, const wchar_t *default_val) {
  16. wchar_t buf[WA_MAX_PATH]=L"";
  17. getString(section, tagname, buf, WA_MAX_PATH-1, default_val);
  18. return StringW(buf);
  19. }
  20. void IniFile::setInt(const wchar_t *section, const wchar_t *tagname, int val) {
  21. setString(section, tagname, StringPrintfW(val));
  22. }
  23. int IniFile::getInt(const wchar_t *section, const wchar_t *tagname, int default_val) {
  24. wchar_t buf[MAX_PATH] = {0};
  25. getString(section, tagname, buf, sizeof(buf), StringPrintfW(default_val));
  26. return WTOI(buf);
  27. }
  28. int IniFile::getBool(const wchar_t *section, const wchar_t *tagname, int default_val) {
  29. wchar_t buf[MAX_PATH] = {0};
  30. getString(section, tagname, buf, sizeof(buf), default_val ? L"true" : L"false");
  31. if (!_wcsicmp(buf, L"true")) return 1;
  32. return 0;
  33. }
  34. void IniFile::setBool(const wchar_t *section, const wchar_t *tagname, int val) {
  35. setString(section, tagname, val ? L"true" : L"false");
  36. }
  37. GUID IniFile::getGuid(const wchar_t *section, const wchar_t *tagname, GUID default_val) {
  38. wchar_t buf[MAX_PATH] = {0};
  39. getString(section, tagname, buf, sizeof(buf), StringPrintfW(default_val));
  40. return nsGUID::fromCharW(buf);
  41. }
  42. void IniFile::setGuid(const wchar_t *section, const wchar_t *tagname, const GUID &val) {
  43. setString(section, tagname, StringPrintfW(val));
  44. }