debian: fix build-deps for focal
[amule.git] / src / libs / ec / cpp / ECFileConfig.h
blob367a1398ea72ed9de34a64201f692630baff182d
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2004-2011 aMule Team ( admin@amule.org / http://www.amule.org )
5 //
6 // Any parts of this program derived from the xMule, lMule or eMule project,
7 // or contributed by third-party developers are copyrighted by their
8 // respective authors.
9 //
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #ifndef ECFILECONFIG_H
26 #define ECFILECONFIG_H
28 #include <wx/fileconf.h>
29 #include <wx/filename.h>
30 #include <wx/utils.h>
32 #include "MD4Hash.h" // Needed for CMD4Hash
33 #include "OtherFunctions.h" // Needed for GetConfigDir()
36 /**
37 * Prepends ConfigDir to filename, if it has no PathSeparator chars in it
39 inline wxString FinalizeFilename(const wxString filename)
41 if (wxStrchr(filename, wxFileName::GetPathSeparator()) == NULL) {
42 return GetConfigDir(filename) + filename;
44 if ((filename.GetChar(0) == '~') && (filename.GetChar(1) == wxFileName::GetPathSeparator())) {
45 return wxGetHomeDir() + filename.Mid(1);
47 return filename;
51 /**
52 * Extension to wxFileConfig for reading/writing CMD4Hash values.
54 * This class converts between the text and binary representation of an MD4 hash,
55 * and also maps empty strings to the empty hash and vica versa.
57 class CECFileConfig : public wxFileConfig {
58 public:
60 CECFileConfig(const wxString& localFilename = wxEmptyString)
61 : wxFileConfig(wxEmptyString, wxEmptyString, FinalizeFilename(localFilename),
62 wxEmptyString, wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_RELATIVE_PATH)
65 /**
66 * Reads a hash from the config file
68 * @param key the key to be read
69 * @param hash the CMD4Hash object to write the hash to
71 * @return true on success, false otherwise.
73 bool ReadHash(const wxString& key, CMD4Hash *hash)
75 wxString sHash;
76 bool retval = wxFileConfig::Read(key, &sHash, wxEmptyString);
77 if (sHash.IsEmpty()) {
78 hash->Clear();
79 } else {
80 hash->Decode(sHash);
82 return retval;
85 /**
86 * Writes a CMD4Hash object to the config file
88 * @param key the key to write to
89 * @param hash the hash to be written
91 * @return true on success, false otherwise.
93 bool WriteHash(const wxString& key, const CMD4Hash& hash)
95 return wxFileConfig::Write(key, hash.IsEmpty() ? wxString(wxEmptyString) : hash.Encode());
99 #endif /* ECFILECONFIG_H */
100 // File_checked_for_headers