Audacity  3.0.3
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 
31 wxArrayString 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 
52 bool UpdateDataParser::HandleXMLTag(const wxChar* tag, const wxChar** attrs)
53 {
54  if (wxStrcmp(tag, mXmlTagNames[XmlParsedTags::kDescriptionTag]) == 0)
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  {
67  if (wxStrcmp(tag, mXmlTagNames[XmlParsedTags::kWin32Tag]) == 0)
68  {
69  if (info.GetOperatingSystemId() & wxOS_WINDOWS)
71  return true;
72  }
73  }
74 
75  if (is64Bit)
76  {
77  if (wxStrcmp(tag, mXmlTagNames[XmlParsedTags::kWin64Tag]) == 0)
78  {
79  if (info.GetOperatingSystemId() & wxOS_WINDOWS)
81  return true;
82  }
83  }
84 
85  if (wxStrcmp(tag, mXmlTagNames[XmlParsedTags::kMacosTag]) == 0)
86  {
87  if (info.GetOperatingSystemId() & wxOS_MAC)
89  return true;
90  }
91 
92  if (wxStrcmp(tag, mXmlTagNames[XmlParsedTags::kLinuxTag]) == 0)
93  {
94  if (info.GetOperatingSystemId() & wxOS_UNIX_LINUX)
96  return true;
97  }
98 
99  if (wxStrcmp(tag, mXmlTagNames[XmlParsedTags::kVersionTag]) == 0)
100  {
103  return true;
104  }
105 
106  if (wxStrcmp(tag, mXmlTagNames[XmlParsedTags::kLinkTag]) == 0)
107  {
110  return true;
111  }
112 
113  for (auto& xmlTag : mXmlTagNames)
114  {
115  if (wxStrcmp(tag, xmlTag.second) == 0)
116  return true;
117  }
118 
119  return false;
120 }
121 
122 void UpdateDataParser::HandleXMLEndTag(const wxChar* 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 
134 void UpdateDataParser::HandleXMLContent(const wxString& content)
135 {
136  if (mVersionPatch == nullptr)
137  return;
138 
139  wxString trimmedContent(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 (wxStrcmp(tag, xmlTag.second) == 0)
168  return this;
169  }
170 
171  return NULL;
172 }
UpdateDataParser::SplitChangelogSentences
wxArrayString SplitChangelogSentences(const wxString &changelogContent)
Definition: UpdateDataParser.cpp:31
VersionPatch::version
VersionId version
Definition: VersionPatch.h:20
UpdateDataParser::HandleXMLEndTag
void HandleXMLEndTag(const wxChar *tag) override
Definition: UpdateDataParser.cpp:122
UpdateDataParser::HandleXMLChild
XMLTagHandler * HandleXMLChild(const wxChar *tag) override
Definition: UpdateDataParser.cpp:163
VersionPatch::changelog
wxArrayString changelog
Definition: VersionPatch.h:21
UpdateDataParser::XmlParsedTags::kLinuxTag
@ kLinuxTag
UpdateDataParser::mVersionPatch
VersionPatch * mVersionPatch
Definition: UpdateDataParser.h:67
UpdateDataParser::XmlParsedTags::kWin32Tag
@ kWin32Tag
UpdateDataParser::Parse
bool Parse(const VersionPatch::UpdateDataFormat &updateData, VersionPatch *versionPatch)
Parsing from update data format to VersionPatch fields.
Definition: UpdateDataParser.cpp:22
UpdateDataParser::mXmlParsingState
XmlParsedTags mXmlParsingState
Definition: UpdateDataParser.h:46
VersionId::ParseFromString
static VersionId ParseFromString(wxString &versionString)
Parse and return version object from version string like "1.2.3".
Definition: VersionId.cpp:24
BasicUI::Get
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:26
XMLFileReader::ParseString
bool ParseString(XMLTagHandler *baseHandler, const wxString &xmldata)
Definition: XMLFileReader.cpp:136
UpdateDataParser::~UpdateDataParser
~UpdateDataParser()
Definition: UpdateDataParser.cpp:19
UpdateDataParser::XmlParsedTags::kNotUsedTag
@ kNotUsedTag
UpdateDataParser::XmlParsedTags::kDescriptionTag
@ kDescriptionTag
UpdateDataParser::XmlParsedTags::kVersionTag
@ kVersionTag
XMLFileReader.h
VersionPatch::download
wxString download
Definition: VersionPatch.h:22
XMLTagHandler
This class is an interface which should be implemented by classes which wish to be able to load and s...
Definition: XMLTagHandler.h:62
UpdateDataParser::UpdateDataParser
UpdateDataParser()
Definition: UpdateDataParser.cpp:16
UpdateDataParser::HandleXMLTag
bool HandleXMLTag(const wxChar *tag, const wxChar **attrs) override
Definition: UpdateDataParser.cpp:52
UpdateDataParser::XmlParsedTags::kMacosTag
@ kMacosTag
VersionPatch::UpdateDataFormat
std::string UpdateDataFormat
Definition: VersionPatch.h:16
XMLFileReader
Reads a file and passes the results through an XMLTagHandler.
Definition: XMLFileReader.h:18
VersionPatch
A structure that describes patch fields.
Definition: VersionPatch.h:15
UpdateDataParser::XmlParsedTags::kOsTag
@ kOsTag
MemoryX.h
UpdateDataParser.h
Declare a class that parses update server data format.
ValueRestorer
Set a variable temporarily in a scope.
Definition: MemoryX.h:332
UpdateDataParser::HandleXMLContent
void HandleXMLContent(const wxString &content) override
Definition: UpdateDataParser.cpp:134
UpdateDataParser::XmlParsedTags::kLinkTag
@ kLinkTag
UpdateDataParser::XmlParsedTags::kWin64Tag
@ kWin64Tag
UpdateDataParser::mXmlTagNames
std::map< XmlParsedTags, wxString > mXmlTagNames
Definition: UpdateDataParser.h:48