Audacity 3.2.0
UpdateDataParser.cpp
Go to the documentation of this file.
1/*!********************************************************************
2 Audacity: A Digital Audio Editor
3
4 @file UpdateDataParser.cpp
5 @brief Declare a class that parses update server data format.
6
7 Anton Gerasimov
8 **********************************************************************/
9
10#include "UpdateDataParser.h"
11
12#include "XMLFileReader.h"
13#include "MemoryX.h"
14#include <wx/platinfo.h>
15
17{}
18
20{}
21
23{
24 XMLFileReader xmlReader;
25
26 ValueRestorer<VersionPatch*> setter{ mVersionPatch, versionPatch };
27
28 return xmlReader.ParseString(this, updateData);
29}
30
31wxArrayString UpdateDataParser::SplitChangelogSentences(const wxString& changelogContent)
32{
33 wxArrayString changelogSentenceList;
34
35 size_t pos = 0;
36 std::string s(changelogContent.ToStdString());
37 std::string token;
38 const std::string delimiter(". ");
39
40 while ((pos = s.find(delimiter)) != std::string::npos)
41 {
42 token = s.substr(0, pos + 1);
43 changelogSentenceList.Add(wxString(token).Trim());
44
45 s.erase(0, pos + delimiter.length());
46 }
47 changelogSentenceList.Add(wxString(s).Trim());
48
49 return changelogSentenceList;
50}
51
52bool UpdateDataParser::HandleXMLTag(const std::string_view& tag, const AttributesList& attrs)
53{
55 {
57 return true;
58 }
59
60 const wxPlatformInfo& info = wxPlatformInfo::Get();
61
62 constexpr bool is32Bit = sizeof(void*) == 4;
63 constexpr bool is64Bit = sizeof(void*) == 8;
64
65 if (is32Bit)
66 {
68 {
69 if (info.GetOperatingSystemId() & wxOS_WINDOWS)
71 return true;
72 }
73 }
74
75 if (is64Bit)
76 {
78 {
79 if (info.GetOperatingSystemId() & wxOS_WINDOWS)
81 return true;
82 }
83 }
84
86 {
87 if (info.GetOperatingSystemId() & wxOS_MAC)
89 return true;
90 }
91
93 {
94 if (info.GetOperatingSystemId() & wxOS_UNIX_LINUX)
96 return true;
97 }
98
100 {
103 return true;
104 }
105
107 {
110 return true;
111 }
112
113 for (auto& xmlTag : mXmlTagNames)
114 {
115 if (tag == xmlTag.second)
116 return true;
117 }
118
119 return false;
120}
121
122void UpdateDataParser::HandleXMLEndTag(const std::string_view& tag)
123{
127
128 // If it is our working OS, using "kOsTag" for keeping ready for parse state for both tags:
129 // <Version> and <Link>, that ordered one after another.
132}
133
134void UpdateDataParser::HandleXMLContent(const std::string_view& content)
135{
136 if (mVersionPatch == nullptr)
137 return;
138
139 wxString trimmedContent = std::string(content);
140
141 switch (mXmlParsingState)
142 {
144 trimmedContent.Trim(true).Trim(false);
146 break;
147
149 trimmedContent.Trim(true).Trim(false);
151 break;
152
154 trimmedContent.Trim(true).Trim(false);
155 mVersionPatch->download = trimmedContent;
156 break;
157
158 default:
159 break;
160 }
161}
162
164{
165 for (auto& xmlTag : mXmlTagNames)
166 {
167 if (tag == xmlTag.second)
168 return this;
169 }
170
171 return NULL;
172}
Declare a class that parses update server data format.
std::vector< Attribute > AttributesList
Definition: XMLTagHandler.h:40
bool Parse(const VersionPatch::UpdateDataFormat &updateData, VersionPatch *versionPatch)
Parsing from update data format to VersionPatch fields.
std::map< XmlParsedTags, const char * > mXmlTagNames
bool HandleXMLTag(const std::string_view &tag, const AttributesList &attrs) override
void HandleXMLEndTag(const std::string_view &tag) override
XMLTagHandler * HandleXMLChild(const std::string_view &tag) override
VersionPatch * mVersionPatch
XmlParsedTags mXmlParsingState
void HandleXMLContent(const std::string_view &content) override
wxArrayString SplitChangelogSentences(const wxString &changelogContent)
Set a variable temporarily in a scope.
Definition: MemoryX.h:211
static VersionId ParseFromString(wxString &versionString)
Parse and return version object from version string like "1.2.3".
Definition: VersionId.cpp:24
Reads a file and passes the results through an XMLTagHandler.
Definition: XMLFileReader.h:19
bool ParseString(XMLTagHandler *baseHandler, const wxString &xmldata)
This class is an interface which should be implemented by classes which wish to be able to load and s...
Definition: XMLTagHandler.h:42
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:196
constexpr size_t npos(-1)
A structure that describes patch fields.
Definition: VersionPatch.h:15
VersionId version
Definition: VersionPatch.h:20
wxArrayString changelog
Definition: VersionPatch.h:21
std::string UpdateDataFormat
Definition: VersionPatch.h:16
wxString download
Definition: VersionPatch.h:22