]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/iniconf.h
make wxFileName::{Mk,Rm}dir() const (closes #10868)
[wxWidgets.git] / include / wx / msw / iniconf.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/msw/iniconf.h
3 // Purpose: INI-file based wxConfigBase implementation
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 27.07.98
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_MSW_INICONF_H_
13 #define _WX_MSW_INICONF_H_
14
15 #include "wx/defs.h"
16
17 #if wxUSE_CONFIG && wxUSE_INICONF
18
19 // ----------------------------------------------------------------------------
20 // wxIniConfig is a wxConfig implementation which uses MS Windows INI files to
21 // store the data. Because INI files don't really support arbitrary nesting of
22 // groups, we do the following:
23 // (1) in win.ini file we store all entries in the [vendor] section and
24 // the value group1/group2/key is mapped to the value group1_group2_key
25 // in this section, i.e. all path separators are replaced with underscore
26 // (2) in appname.ini file we map group1/group2/group3/key to the entry
27 // group2_group3_key in [group1]
28 //
29 // Of course, it might lead to indesirable results if '_' is also used in key
30 // names (i.e. group/key is the same as group_key) and also GetPath() result
31 // may be not what you would expect it to be.
32 //
33 // Another limitation: the keys and section names are never case-sensitive
34 // which might differ from wxFileConfig it it was compiled with
35 // wxCONFIG_CASE_SENSITIVE option.
36 // ----------------------------------------------------------------------------
37
38 // for this class, "local" file is the file appname.ini and the global file
39 // is the [vendor] subsection of win.ini (default for "vendor" is to be the
40 // same as appname). The file name (strAppName parameter) may, in fact,
41 // contain the full path to the file. If it doesn't, the file is searched for
42 // in the Windows directory.
43 class WXDLLIMPEXP_CORE wxIniConfig : public wxConfigBase
44 {
45 public:
46 // ctor & dtor
47 // if strAppName doesn't contain the extension and is not an absolute path,
48 // ".ini" is appended to it. if strVendor is empty, it's taken to be the
49 // same as strAppName.
50 wxIniConfig(const wxString& strAppName = wxEmptyString, const wxString& strVendor = wxEmptyString,
51 const wxString& localFilename = wxEmptyString, const wxString& globalFilename = wxEmptyString, long style = wxCONFIG_USE_LOCAL_FILE);
52 virtual ~wxIniConfig();
53
54 // implement inherited pure virtual functions
55 virtual void SetPath(const wxString& strPath);
56 virtual const wxString& GetPath() const;
57
58 virtual bool GetFirstGroup(wxString& str, long& lIndex) const;
59 virtual bool GetNextGroup (wxString& str, long& lIndex) const;
60 virtual bool GetFirstEntry(wxString& str, long& lIndex) const;
61 virtual bool GetNextEntry (wxString& str, long& lIndex) const;
62
63 virtual size_t GetNumberOfEntries(bool bRecursive = false) const;
64 virtual size_t GetNumberOfGroups(bool bRecursive = false) const;
65
66 virtual bool HasGroup(const wxString& strName) const;
67 virtual bool HasEntry(const wxString& strName) const;
68
69 // return true if the current group is empty
70 bool IsEmpty() const;
71
72 virtual bool Flush(bool bCurrentOnly = false);
73
74 virtual bool RenameEntry(const wxString& oldName, const wxString& newName);
75 virtual bool RenameGroup(const wxString& oldName, const wxString& newName);
76
77 virtual bool DeleteEntry(const wxString& Key, bool bGroupIfEmptyAlso = true);
78 virtual bool DeleteGroup(const wxString& szKey);
79 virtual bool DeleteAll();
80
81 protected:
82 // read/write
83 bool DoReadString(const wxString& key, wxString *pStr) const;
84 bool DoReadLong(const wxString& key, long *plResult) const;
85 bool DoReadBinary(const wxString& key, wxMemoryBuffer *buf) const;
86
87 bool DoWriteString(const wxString& key, const wxString& szValue);
88 bool DoWriteLong(const wxString& key, long lValue);
89 bool DoWriteBinary(const wxString& key, const wxMemoryBuffer& buf);
90
91 private:
92 // helpers
93 wxString GetPrivateKeyName(const wxString& szKey) const;
94 wxString GetKeyName(const wxString& szKey) const;
95
96 wxString m_strLocalFilename; // name of the private INI file
97 wxString m_strGroup, // current group in appname.ini file
98 m_strPath; // the rest of the path (no trailing '_'!)
99
100 wxDECLARE_NO_COPY_CLASS(wxIniConfig);
101 DECLARE_ABSTRACT_CLASS(wxIniConfig)
102 };
103
104 #endif // wxUSE_CONFIG && wxUSE_INICONF
105
106 #endif // _WX_MSW_INICONF_H_