├── .clang-format
├── .github
└── FUNDING.yml
├── .gitignore
├── COPYING
├── README.md
├── marketplace.json
├── src
├── impl
│ ├── appcastparser.cpp
│ ├── appcastparser.h
│ ├── checker.cpp
│ ├── checker.h
│ ├── defaultupdater.cpp
│ ├── defaultupdater.h
│ ├── dialog.cpp
│ ├── dialog.h
│ ├── downloader.cpp
│ ├── downloader.h
│ ├── installer.h
│ ├── openinstaller.cpp
│ ├── openinstaller.h
│ ├── parser.h
│ ├── runinstaller.cpp
│ ├── runinstaller.h
│ ├── simplexmlparser.cpp
│ └── simplexmlparser.h
├── sparkle
│ ├── sparkleupdater.h
│ └── sparkleupdater.mm
├── updater.cpp
└── updater.h
├── updater.pri
└── updater.pro
/.clang-format:
--------------------------------------------------------------------------------
1 | BasedOnStyle: LLVM
2 | IndentWidth: 4
3 | AccessModifierOffset: -4
4 | ColumnLimit: 100
5 | AllowShortIfStatementsOnASingleLine: true
6 | AllowShortFunctionsOnASingleLine: Inline
7 | KeepEmptyLinesAtTheStartOfBlocks: false
8 | ContinuationIndentWidth: 8
9 | AlignAfterOpenBracket: true
10 | BinPackParameters: false
11 | AllowAllParametersOfDeclarationOnNextLine: false
12 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: flaviotordini
2 | custom: https://flavio.tordini.org/donate
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | .DS_Store
3 | .vscode
4 |
--------------------------------------------------------------------------------
/COPYING:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # An updater for Qt apps
2 |
3 | This is an extensible updater for Qt apps. It can wrap [Sparkle](https://sparkle-project.org/) on macOS and use its own implementation on Windows and Linux. I use it in my apps at https://flavio.tordini.org .
4 |
5 | ## Design
6 |
7 | The main interface is [Updater](https://github.com/flaviotordini/updater/blob/master/src/updater.h). A shared Updater subclass instance should be set on startup using `Updater::setInstance()`. Available implementations are:
8 |
9 | - [`updater::DefaultUpdater`](https://github.com/flaviotordini/updater/blob/master/src/impl/defaultupdater.h), the default Qt-based implementation.
10 |
11 | - [`updater::SparkleUpdater`](https://github.com/flaviotordini/updater/blob/master/src/sparkle/sparkleupdater.h), a Sparkle-based implementation for macOS
12 |
13 | ## User Interface
14 |
15 | ### Built-in Widgets
16 |
17 | Updater provides ready-to-use widgets:
18 |
19 | - `Updater::getAction()` returns a QAction suitable to be inserted in a QMenu.
20 | - `Updater::getLabel()` returns a QLabel that automatically changes its message. Typically used in the about box.
21 | - `Updater::getButton()` returns a QPushButton that autohides or automatically changes its function depending on the Updater status.
22 |
23 | When the user triggers the action or pushes the button a dialog will show which is dependent on the Updater implementation.
24 |
25 | ## Entension Points
26 |
27 | [updater::DefaultUpdater](https://github.com/flaviotordini/updater/blob/master/src/impl/defaultupdater.h) has a number of extension points so it can be adapted to different release manifest formats and update mechanisms.
28 |
29 | ### Parser
30 |
31 | Implement [updater::Parser](https://github.com/flaviotordini/updater/blob/master/src/impl/parser.h) to parse your own manifest format. There are two ready-to-use parsers:
32 |
33 | - [updater::AppcastParser](https://github.com/flaviotordini/updater/blob/master/src/impl/appcastparser.h). This the appcast format also used by Sparkle. It's a RSS feed with Sparkle extensions.
34 | - [updater::SimpleXmlParser](https://github.com/flaviotordini/updater/blob/master/src/impl/simplexmlparser.h). This is a very simple XML format
35 |
36 | Set the desired Parser implementation using `updater::DefaultUpdater::setParser`. The default is [updater::AppcastParser].
37 |
38 | ### Installer
39 |
40 | [updater::Installer](https://github.com/flaviotordini/updater/blob/master/src/impl/installer.h) is the abstraction responsible for preparing and running the update process. Currently the only available Installer implementation is [updater::RunInstaller](https://github.com/flaviotordini/updater/blob/master/src/impl/runinstaller.h). It just runs an executable update payload, optionally with arguments.
41 |
42 | Installer can be implemented in other ways, for example an Installer that unzips a payload and moves files. Or one that invokes an update helper. Another idea is signature validation.
43 |
44 | Set the desired Installer implementation using `updater::DefaultUpdater::setInstaller`. The default is [updater::RunInstaller].
45 |
46 | ## Build Instructions
47 |
48 | ### qmake
49 | ```
50 | mkdir build
51 | cd build
52 | qmake ..
53 | make
54 | ```
55 |
56 | ## Integration
57 |
58 | You can use this library as a git submodule. For example, add it to your project inside a lib subdirectory:
59 |
60 | ```
61 | git submodule add -b master https://github.com/flaviotordini/updater lib/updater
62 | ```
63 |
64 | Then you can update your git submodules like this:
65 |
66 | ```
67 | git submodule update --init --recursive --remote
68 | ```
69 |
70 | To integrate the library in your qmake based project just add this to your .pro file:
71 |
72 | ```
73 | include(lib/updater/updater.pri)
74 | ```
75 |
76 | qmake builds all object files in the same directory. In order to avoid filename clashes use:
77 |
78 | ```
79 | CONFIG += object_parallel_to_source
80 | ```
81 |
82 | ## Examples
83 |
84 | Example setup of the shared Updater instance:
85 |
86 | ```
87 | #include "updater.h"
88 | #ifdef UPDATER_SPARKLE
89 | #include "sparkleupdater.h"
90 | #else
91 | #include "defaultupdater.h"
92 | #endif
93 |
94 | void setupUpdater() {
95 | #ifdef UPDATER_SPARKLE
96 | Updater::setInstance(new updater::SparkleUpdater());
97 | #else
98 | auto updater = new updater::DefaultUpdater();
99 | updater->setManifestUrl(myAppcastUrl);
100 | Updater::setInstance(updater);
101 | #endif
102 | }
103 | ```
104 |
105 | Updater provides a QAction instance ready to be used in a menu.
106 |
107 | ```
108 | myMenu->addAction(Updater::instance().getAction());
109 | ```
110 |
111 | In the About box you can use the standard widgets provided by Updater. A QLabel and a QPushButton.
112 |
113 | ```
114 | myLayout->addWidget(Updater::instance().getLabel());
115 | myLayout->addWidget(Updater::instance().getButton());
116 | ```
117 |
118 | ## Security
119 |
120 | Always serve your manifest files and binary updates via HTTPS.
121 |
122 | ## Support
123 |
124 | If you need more features or integration with your product, I'm available for hire.
125 |
126 | ## License
127 |
128 | You can use this library under the GPLv3 license terms. If you do, you're welcome contributing your changes and fixes. Donations are welcome at https://flavio.tordini.org/donate
129 |
130 | For commercial projects I ask for a one-time license fee, contact me at flavio.tordini@gmail.com
131 |
--------------------------------------------------------------------------------
/marketplace.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://qt.io/schema/extension-schema-v1#",
3 | "title": "Updater",
4 | "extensionType": [
5 | "library"
6 | ],
7 | "version": "1",
8 | "vendor": {
9 | "name": "Flavio Tordini",
10 | "url": "https://flavio.tordini.org"
11 | },
12 | "contact": "Flavio Tordini ",
13 | "copyright": [
14 | "Flavio Tordini"
15 | ],
16 | "author": "Flavio Tordini",
17 | "icon": "https://flavio.tordini.org/favicon-196x196.png",
18 | "licenses": [
19 | {
20 | "licenseType": "GPLv3",
21 | "licenseUrl": "https://opensource.org/licenses/GPL-3.0"
22 | }
23 | ],
24 | "created": "2020-07-03",
25 | "platforms": [
26 | "Windows",
27 | "Linux",
28 | "macOS"
29 | ],
30 | "qtVersions": [
31 | "5.10.0-or-later"
32 | ],
33 | "tags": [
34 | "updater,update,deploy,release,tools,utility"
35 | ],
36 | "price": {
37 | "listprice": 0
38 | },
39 | "support": "flavio.tordini@gmail.com",
40 | "bugUrl": "https://github.com/flaviotordini/updater/issues",
41 | "sourceRepoUrl": "https://github.com/flaviotordini/updater",
42 | "userManuals": [
43 | "https://github.com/flaviotordini/updater/blob/master/README.md"
44 | ],
45 | "dependencies": [
46 | "Network"
47 | ]
48 | }
49 |
--------------------------------------------------------------------------------
/src/impl/appcastparser.cpp:
--------------------------------------------------------------------------------
1 | #include "appcastparser.h"
2 |
3 | #include "defaultupdater.h"
4 |
5 | namespace updater {
6 |
7 | AppcastParser::AppcastParser() {}
8 |
9 | void AppcastParser::parse(const QByteArray &bytes) {
10 | error = false;
11 | errorMessage.clear();
12 |
13 | const QLatin1String sparkleNS("http://www.andymatuschak.org/xml-namespaces/sparkle");
14 |
15 | QXmlStreamReader reader(bytes);
16 | while (!reader.atEnd()) {
17 | reader.readNext();
18 | if (reader.name() == QLatin1String("item")) {
19 | while (reader.readNextStartElement()) {
20 | if (reader.name() == QLatin1String("enclosure")) {
21 | auto attrs = reader.attributes();
22 | QString url = attrs.value(QLatin1String("url")).toString();
23 | updater->setDownloadUrl(url);
24 |
25 | QString version = attrs.value(sparkleNS, QLatin1String("version")).toString();
26 | updater->setVersion(version);
27 |
28 | QString shortVersionString =
29 | attrs.value(sparkleNS, QLatin1String("shortVersionString")).toString();
30 | updater->setDisplayVersion(shortVersionString);
31 | }
32 | reader.skipCurrentElement();
33 | }
34 | }
35 | }
36 |
37 | if (reader.hasError()) {
38 | error = true;
39 | errorMessage = reader.errorString();
40 | }
41 | }
42 |
43 | } // namespace updater
44 |
--------------------------------------------------------------------------------
/src/impl/appcastparser.h:
--------------------------------------------------------------------------------
1 | #ifndef APPCASTPARSER_H
2 | #define APPCASTPARSER_H
3 |
4 | #include
5 |
6 | #include "parser.h"
7 |
8 | namespace updater {
9 |
10 | class DefaultUpdater;
11 |
12 | class AppcastParser : public Parser {
13 | public:
14 | AppcastParser();
15 | void parse(const QByteArray &bytes);
16 | };
17 |
18 | } // namespace updater
19 |
20 | #endif // APPCASTPARSER_H
21 |
--------------------------------------------------------------------------------
/src/impl/checker.cpp:
--------------------------------------------------------------------------------
1 | #include "checker.h"
2 |
3 | #include "appcastparser.h"
4 | #include "defaultupdater.h"
5 | #include "parser.h"
6 |
7 | #ifdef HTTP
8 | #include "http.h"
9 | #endif
10 |
11 | namespace {
12 | const QString updateCheckKey = "updateCheck";
13 | }
14 |
15 | namespace updater {
16 |
17 | Checker::Checker(DefaultUpdater *updater, QObject *parent) : QObject(parent), updater(updater) {}
18 |
19 | void Checker::check() {
20 | qDebug() << "Checking for update" << updater->getManifestUrl();
21 | error = false;
22 | errorMessage.clear();
23 |
24 | #ifdef HTTP
25 | HttpReply *reply = Http::instance().get(updater->getManifestUrl());
26 | connect(reply, &HttpReply::finished, this, [this](const HttpReply &reply) {
27 | if (reply.isSuccessful()) {
28 | invokeParser(reply.body());
29 | } else {
30 | qWarning() << "Update check failed" << reply.statusCode() << reply.reasonPhrase();
31 | error = true;
32 | errorMessage = reply.reasonPhrase();
33 | updater->setStatus(Updater::Status::UpToDate);
34 | emit done();
35 | }
36 | });
37 | #else
38 | QNetworkAccessManager *manager = new QNetworkAccessManager(this);
39 | QNetworkRequest request;
40 | request.setUrl(updater->getManifestUrl());
41 | request.setRawHeader("User-Agent",
42 | (updater->getAppName() + ' ' + updater->getLocalVersion()).toUtf8());
43 | connect(manager, &QNetworkAccessManager::finished, this, [this](QNetworkReply *reply) {
44 | int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
45 | if (status >= 200 && status < 300) {
46 | invokeParser(reply->readAll());
47 | } else {
48 | QString msg = reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
49 | qWarning() << "Update check failed" << status << msg;
50 | error = true;
51 | errorMessage = msg;
52 | updater->setStatus(Updater::Status::UpToDate);
53 | emit done();
54 | }
55 | reply->deleteLater();
56 | });
57 | manager->get(request);
58 | #endif
59 | } // namespace updater
60 |
61 | qint64 Checker::getLastCheck() {
62 | QSettings settings;
63 | return settings.value(updateCheckKey).toInt();
64 | }
65 |
66 | void Checker::invokeParser(const QByteArray &bytes) {
67 | auto parser = updater->getParser();
68 | if (!parser) {
69 | AppcastParser defaultParser;
70 | defaultParser.setUpdater(updater);
71 | defaultParser.parse(bytes);
72 | } else {
73 | parser->parse(bytes);
74 | }
75 |
76 | auto compareVersions = [](QString localVersion, QString remoteVersion) {
77 | qDebug() << "Comparing versions" << localVersion << remoteVersion;
78 | auto local = QVersionNumber::fromString(localVersion);
79 | auto remote = QVersionNumber::fromString(remoteVersion);
80 | return QVersionNumber::compare(local, remote) < 0;
81 | };
82 |
83 | bool remoteVersionIsNewer = compareVersions(updater->getLocalVersion(), updater->getVersion());
84 | if (remoteVersionIsNewer && updater->getStatus() != Updater::Status::UpdateDownloaded) {
85 | if (updater->getAutomaticDownload()) {
86 | updater->downloadUpdate();
87 | } else {
88 | updater->setStatus(Updater::Status::UpdateAvailable);
89 | }
90 | } else {
91 | updater->setStatus(Updater::Status::UpToDate);
92 | }
93 |
94 | QSettings settings;
95 | settings.setValue(updateCheckKey, QDateTime::currentSecsSinceEpoch());
96 | emit done();
97 | }
98 |
99 | } // namespace updater
100 |
--------------------------------------------------------------------------------
/src/impl/checker.h:
--------------------------------------------------------------------------------
1 | #ifndef UPDATER_IMPL_CHECKER_H
2 | #define UPDATER_IMPL_CHECKER_H
3 |
4 | #include
5 |
6 | namespace updater {
7 |
8 | class DefaultUpdater;
9 |
10 | class Checker : public QObject {
11 | Q_OBJECT
12 |
13 | public:
14 | explicit Checker(DefaultUpdater *updater, QObject *parent = nullptr);
15 |
16 | void check();
17 | bool hasError() const { return error; };
18 | QString getErrorMessage() const { return errorMessage; };
19 |
20 | static qint64 getLastCheck();
21 |
22 | signals:
23 | void done();
24 |
25 | private:
26 | void invokeParser(const QByteArray &bytes);
27 |
28 | DefaultUpdater *updater;
29 |
30 | bool error = false;
31 | QString errorMessage;
32 | };
33 |
34 | } // namespace updater
35 |
36 | #endif // UPDATER_IMPL_CHECKER_H
37 |
--------------------------------------------------------------------------------
/src/impl/defaultupdater.cpp:
--------------------------------------------------------------------------------
1 | #include "defaultupdater.h"
2 |
3 | #include "checker.h"
4 | #include "dialog.h"
5 | #include "downloader.h"
6 | #include "installer.h"
7 | #include "openinstaller.h"
8 | #include "parser.h"
9 |
10 | namespace updater {
11 |
12 | DefaultUpdater::DefaultUpdater() {
13 | checkTimer = new QTimer(this);
14 | checkTimer->setInterval(checkInterval);
15 | checkTimer->setTimerType(Qt::VeryCoarseTimer);
16 | auto autoCheck = [this] {
17 | // auto check after interval
18 | qint64 lastCheck = Checker::getLastCheck();
19 | int secondsSinceLastCheck = QDateTime::currentSecsSinceEpoch() - lastCheck;
20 | if (secondsSinceLastCheck >= checkInterval) {
21 | auto checker = new Checker(this);
22 | connect(checker, &Checker::done, this, [this, checker] {
23 | if (!getAutomaticDownload() && getStatus() != Updater::Status::UpToDate) {
24 | showDialog();
25 | }
26 | checker->deleteLater();
27 | });
28 | checker->check();
29 | }
30 | };
31 | connect(checkTimer, &QTimer::timeout, this, autoCheck);
32 | QTimer::singleShot(5000, autoCheck);
33 | checkTimer->start();
34 | }
35 |
36 | void DefaultUpdater::setCheckInterval(const qint64 &value) {
37 | checkInterval = value;
38 | checkTimer->setInterval(checkInterval);
39 | }
40 |
41 | void DefaultUpdater::setInstaller(Installer *value) {
42 | installer = value;
43 | installer->setUpdater(this);
44 | }
45 |
46 | void DefaultUpdater::setParser(Parser *value) {
47 | parser = value;
48 | parser->setUpdater(this);
49 | }
50 |
51 | void DefaultUpdater::checkAndShowUI() {
52 | auto checker = new Checker(this);
53 | connect(checker, &Checker::done, this, [this, checker] {
54 | if (getStatus() == Updater::Status::UpToDate) {
55 | QMessageBox msgBox(qApp->activeWindow());
56 | msgBox.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
57 | msgBox.setWindowModality(Qt::WindowModal);
58 | msgBox.setIconPixmap(getIcon().pixmap(64, 64));
59 | msgBox.setText(tr("There are currently no updates available."));
60 | msgBox.exec();
61 | } else {
62 | if (getStatus() != Updater::Status::UpdateAvailable) {
63 | downloadUpdate();
64 | }
65 | showDialog();
66 | }
67 |
68 | checker->deleteLater();
69 | });
70 | checker->check();
71 | }
72 |
73 | void DefaultUpdater::checkAndMaybeShowUI() {
74 | auto checker = new Checker(this);
75 | connect(checker, &Checker::done, this, [this, checker] {
76 | if (getStatus() != Updater::Status::UpToDate) {
77 | showDialog();
78 | }
79 | checker->deleteLater();
80 | });
81 | checker->check();
82 | }
83 |
84 | void DefaultUpdater::checkWithoutUI() {
85 | auto checker = new Checker(this);
86 | connect(checker, &Checker::done, this, [checker] { checker->deleteLater(); });
87 | checker->check();
88 | }
89 |
90 | void DefaultUpdater::update() {
91 | if (!installer) {
92 | installer = new OpenInstaller();
93 | installer->setUpdater(this);
94 | }
95 | connect(installer, &Installer::error, this, [](auto message) { qWarning() << message; });
96 | connect(installer, &Installer::finished, this,
97 | [this]() { setStatus(Updater::Status::UpToDate); });
98 | installer->start(downloadedFilename);
99 | }
100 |
101 | Downloader *DefaultUpdater::downloadUpdate() {
102 | if (downloader) return downloader;
103 | if (!downloadedFilename.isEmpty()) {
104 | qDebug() << "Update already downloded";
105 | }
106 |
107 | setStatus(Updater::Status::DownloadingUpdate);
108 |
109 | downloader = new Downloader();
110 | connect(downloader, &Downloader::fileReady, [this](auto filename) {
111 | downloader->deleteLater();
112 | downloader = nullptr;
113 | downloadedFilename = filename;
114 | setStatus(Updater::Status::UpdateDownloaded);
115 |
116 | if (getImmediateInstallWithoutRelaunch()) {
117 | update();
118 | } else if (getImmediateInstallAndRelaunch()) {
119 | update();
120 | qApp->quit();
121 | } else {
122 | connect(qApp, &QCoreApplication::aboutToQuit, this, [this] { update(); });
123 | }
124 | });
125 |
126 | connect(downloader, &Downloader::error, [this](auto message) {
127 | qWarning() << message;
128 | downloader->deleteLater();
129 | downloader = nullptr;
130 | downloadedFilename.clear();
131 | setStatus(Updater::Status::UpdateDownloadFailed);
132 | });
133 |
134 | connect(downloader, &Downloader::progress,
135 | [](int percent) { qDebug() << QString("Downloading update %1%").arg(percent); });
136 |
137 | downloader->download(downloadUrl);
138 |
139 | return downloader;
140 | }
141 |
142 | void DefaultUpdater::showDialog() {
143 | if (!dialog) {
144 | dialog = new Dialog(this, qApp->activeWindow());
145 | connect(dialog, &QWidget::destroyed, this, [this] { dialog = nullptr; });
146 | }
147 | dialog->show();
148 | }
149 |
150 | } // namespace updater
151 |
--------------------------------------------------------------------------------
/src/impl/defaultupdater.h:
--------------------------------------------------------------------------------
1 | #ifndef UPDATER_IMPL_UPDATER_H
2 | #define UPDATER_IMPL_UPDATER_H
3 |
4 | #include "updater.h"
5 |
6 | namespace updater {
7 |
8 | class Downloader;
9 | class Dialog;
10 | class Installer;
11 | class Parser;
12 |
13 | class DefaultUpdater : public ::Updater {
14 | Q_OBJECT
15 |
16 | public:
17 | DefaultUpdater();
18 |
19 | QString getAppName() const { return appName; }
20 | void setAppName(const QString &value) { appName = value; }
21 |
22 | QIcon getIcon() const { return icon; }
23 | void setIcon(const QIcon &value) { icon = value; }
24 |
25 | QString getLocalVersion() const { return localVersion; }
26 | void setLocalVersion(const QString &value) { localVersion = value; }
27 |
28 | QUrl getManifestUrl() const { return manifestUrl; }
29 | void setManifestUrl(const QUrl &value) { manifestUrl = value; }
30 |
31 | void setCheckInterval(const qint64 &value);
32 |
33 | /// A fixed download url. In alternative, the Parser impl can set the download url from the
34 | /// manifest
35 | void setDownloadUrl(const QUrl &value) { downloadUrl = value; }
36 |
37 | void setInstaller(Installer *value);
38 |
39 | Parser *getParser() const { return parser; }
40 | void setParser(Parser *value);
41 |
42 | Downloader *downloadUpdate();
43 | Downloader *getDownloader() const { return downloader; }
44 |
45 | void checkAndShowUI();
46 | void checkAndMaybeShowUI();
47 | void checkWithoutUI();
48 |
49 | protected slots:
50 | void update();
51 |
52 | private:
53 | void showDialog();
54 |
55 | QString appName = QGuiApplication::applicationDisplayName();
56 | QIcon icon = QGuiApplication::windowIcon();
57 | QString localVersion = QCoreApplication::applicationVersion();
58 |
59 | QUrl manifestUrl;
60 | qint64 checkInterval = 86400;
61 |
62 | Downloader *downloader = nullptr;
63 | QUrl downloadUrl;
64 | QString downloadedFilename;
65 |
66 | Installer *installer = nullptr;
67 | Parser *parser = nullptr;
68 |
69 | Dialog *dialog = nullptr;
70 |
71 | QTimer *checkTimer;
72 | };
73 |
74 | } // namespace updater
75 |
76 | #endif // UPDATER_IMPL_UPDATER_H
77 |
--------------------------------------------------------------------------------
/src/impl/dialog.cpp:
--------------------------------------------------------------------------------
1 | #include "dialog.h"
2 |
3 | #include "downloader.h"
4 |
5 | namespace {
6 | static const int padding = 15;
7 | } // namespace
8 |
9 | namespace updater {
10 |
11 | DownloadWidget::DownloadWidget(const QString &message, QDialog *parent)
12 | : QWidget(parent) {
13 | QBoxLayout *layout = new QVBoxLayout(this);
14 | layout->setContentsMargins(0, 0, 0, 0);
15 | layout->setSpacing(padding);
16 |
17 | QLabel *msgLabel = new QLabel(message);
18 | QFont boldFont = msgLabel->font();
19 | boldFont.setBold(true);
20 | msgLabel->setFont(boldFont);
21 | layout->addWidget(msgLabel);
22 |
23 | progressBar = new QProgressBar();
24 | layout->addWidget(progressBar);
25 |
26 | QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
27 |
28 | QPushButton *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
29 | connect(cancelButton, &QPushButton::clicked, this, [parent] { parent->reject(); });
30 | connect(progressBar, &QProgressBar::valueChanged, this, [cancelButton](int percent) {
31 | if (percent == 100) cancelButton->hide();
32 | });
33 |
34 | QPushButton *closeButton = buttonBox->addButton(QDialogButtonBox::Ok);
35 | closeButton->setDefault(true);
36 | closeButton->setFocus();
37 | closeButton->connect(closeButton, &QPushButton::clicked, this, [parent] { parent->accept(); });
38 |
39 | layout->addWidget(buttonBox);
40 |
41 | errorLabel = new QLabel();
42 | errorLabel->hide();
43 | layout->addWidget(errorLabel);
44 | }
45 |
46 | void DownloadWidget::setProgress(int percent) {
47 | progressBar->setValue(percent);
48 | }
49 |
50 | void DownloadWidget::setErrorMessage(const QString &message) {
51 | errorLabel->setText(message);
52 | errorLabel->show();
53 | }
54 |
55 | Dialog::Dialog(DefaultUpdater *updater, QWidget *parent)
56 | : QDialog(parent), updater(updater), downloadWidget(nullptr) {
57 | setWindowModality(Qt::WindowModal);
58 | setAttribute(Qt::WA_DeleteOnClose);
59 | setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
60 |
61 | QBoxLayout *hLayout = new QHBoxLayout(this);
62 | hLayout->setSizeConstraint(QLayout::SetFixedSize);
63 | hLayout->setContentsMargins(padding * 2, padding * 2, padding * 2, padding * 2);
64 | hLayout->setSpacing(padding);
65 |
66 | if (!updater->getIcon().isNull()) {
67 | QLabel *logo = new QLabel();
68 | logo->setPixmap(updater->getIcon().pixmap(64, 64));
69 | hLayout->addWidget(logo, 0, Qt::AlignTop);
70 | }
71 |
72 | stackedLayout = new QStackedLayout();
73 | hLayout->addLayout(stackedLayout, 1);
74 |
75 | auto onStatusChange = [this](Updater::Status status) {
76 | QWidget *w = nullptr;
77 | switch (status) {
78 | case Updater::Status::UpToDate:
79 | w = new QLabel(tr("You already have the latest version"));
80 | break;
81 | case Updater::Status::UpdateAvailable:
82 | w = messageWidget();
83 | break;
84 |
85 | case Updater::Status::DownloadingUpdate:
86 | case Updater::Status::UpdateDownloaded:
87 | case Updater::Status::UpdateDownloadFailed:
88 | w = setupDownloadWidget();
89 | break;
90 | }
91 | if (w) showWidget(w);
92 | };
93 | connect(updater, &Updater::statusChanged, this, onStatusChange);
94 | onStatusChange(updater->getStatus());
95 | }
96 |
97 | QWidget *Dialog::setupDownloadWidget() {
98 | if (!downloadWidget) {
99 | QString message =
100 | tr("Downloading %1 %2...").arg(updater->getAppName(), updater->getVersion());
101 | downloadWidget = new DownloadWidget(message, this);
102 | }
103 |
104 | Downloader *downloader = updater->getDownloader();
105 | if (downloader) {
106 | connect(downloader, &Downloader::progress, downloadWidget, &DownloadWidget::setProgress);
107 | connect(downloader, &Downloader::error, downloadWidget, &DownloadWidget::setErrorMessage);
108 | connect(this, &QDialog::rejected, downloader, &Downloader::stop);
109 | }
110 |
111 | return downloadWidget;
112 | }
113 |
114 | void Dialog::showWidget(QWidget *widget) {
115 | QWidget *currentWidget = stackedLayout->currentWidget();
116 | if (currentWidget == widget) return;
117 | if (currentWidget) {
118 | stackedLayout->removeWidget(currentWidget);
119 | currentWidget->deleteLater();
120 | }
121 | stackedLayout->addWidget(widget);
122 | }
123 |
124 | QWidget *Dialog::messageWidget() {
125 | QWidget *w = new QWidget();
126 |
127 | QFormLayout *layout = new QFormLayout(w);
128 | layout->setContentsMargins(0, 0, 0, 0);
129 | layout->setSpacing(padding);
130 |
131 | QLabel *titleLabel =
132 | new QLabel(tr("A new version of %1 is available!").arg(updater->getAppName()));
133 | QFont boldFont = titleLabel->font();
134 | boldFont.setBold(true);
135 | titleLabel->setFont(boldFont);
136 | layout->addWidget(titleLabel);
137 |
138 | QLabel *label = new QLabel(
139 | tr("%1 %2 is now available. You have %3.")
140 | .arg(updater->getAppName(), updater->getVersion(), updater->getLocalVersion()));
141 | layout->addWidget(label);
142 |
143 | label = new QLabel(tr("Would you like to download it now?"));
144 | layout->addWidget(label);
145 |
146 | QDialogButtonBox *buttonBox = new QDialogButtonBox();
147 |
148 | QPushButton *laterButton =
149 | buttonBox->addButton(tr("Remind Me Later"), QDialogButtonBox::RejectRole);
150 | connect(laterButton, &QPushButton::clicked, this, &QDialog::close);
151 |
152 | QPushButton *updateButton =
153 | buttonBox->addButton(tr("Download Update"), QDialogButtonBox::AcceptRole);
154 | connect(updateButton, &QPushButton::clicked, updater, &DefaultUpdater::downloadUpdate);
155 |
156 | layout->addWidget(buttonBox);
157 |
158 | return w;
159 | }
160 |
161 | } // namespace updater
162 |
--------------------------------------------------------------------------------
/src/impl/dialog.h:
--------------------------------------------------------------------------------
1 | #ifndef UPDATER_IMPL_DIALOG_H
2 | #define UPDATER_IMPL_DIALOG_H
3 |
4 | #include
5 | #include
6 |
7 | #include "defaultupdater.h"
8 |
9 | namespace updater {
10 |
11 | class DownloadWidget : public QWidget {
12 | Q_OBJECT
13 |
14 | public:
15 | DownloadWidget(const QString &message, QDialog *parent = 0);
16 |
17 | public slots:
18 | void setProgress(int percent);
19 | void setErrorMessage(const QString &message);
20 |
21 | private:
22 | QProgressBar *progressBar;
23 | QLabel *errorLabel;
24 | };
25 |
26 | class Dialog : public QDialog {
27 | Q_OBJECT
28 |
29 | public:
30 | Dialog(DefaultUpdater *updater, QWidget *parent);
31 |
32 | private:
33 | void showWidget(QWidget *widget);
34 | QWidget *setupDownloadWidget();
35 | QWidget *messageWidget();
36 |
37 | DefaultUpdater *updater;
38 | QStackedLayout *stackedLayout;
39 | DownloadWidget *downloadWidget;
40 | };
41 |
42 | } // namespace updater
43 |
44 | #endif // UPDATER_IMPL_DIALOG_H
45 |
--------------------------------------------------------------------------------
/src/impl/downloader.cpp:
--------------------------------------------------------------------------------
1 | #include "downloader.h"
2 |
3 | #include
4 |
5 | namespace updater {
6 |
7 | void Downloader::download(const QUrl &url) {
8 | const QString tempDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
9 | QString filename = tempDir + "/" +
10 | QByteArray::number(QRandomGenerator::global()->generate()).toHex() +
11 | url.fileName();
12 | file.setFileName(filename);
13 |
14 | qDebug() << "Downloading" << url << "to" << filename;
15 |
16 | #ifdef HTTP
17 | HttpRequest req;
18 | req.url = url;
19 | reply = Http::instance().networkReply(req);
20 | #else
21 | QNetworkAccessManager *manager = new QNetworkAccessManager(this);
22 | QNetworkRequest request;
23 | request.setUrl(url);
24 | reply = manager->get(request);
25 | #endif
26 |
27 | connect(reply, &QNetworkReply::readyRead, this, [this] {
28 | if (!reply) return;
29 |
30 | if (!file.isOpen()) {
31 | if (!file.open(QIODevice::ReadWrite)) {
32 | emit error(QString("Error opening file: %1").arg(file.errorString()));
33 | reply->disconnect();
34 | reply->abort();
35 | reply->deleteLater();
36 | reply = nullptr;
37 | return;
38 | }
39 | }
40 | if (-1 == file.write(reply->readAll())) {
41 | emit error(file.errorString());
42 | reply->disconnect();
43 | reply->abort();
44 | reply->deleteLater();
45 | reply = nullptr;
46 | }
47 | });
48 |
49 | connect(reply,
50 | &QNetworkReply::errorOccurred,
51 | this, [this] {
52 | emit error(reply->errorString());
53 | reply->disconnect();
54 | reply->abort();
55 | reply->deleteLater();
56 | reply = nullptr;
57 | });
58 |
59 | connect(reply, &QNetworkReply::downloadProgress, this,
60 | [this](qint64 bytesReceived, qint64 bytesTotal) {
61 | if (bytesTotal <= 0) return;
62 | int percent = bytesReceived * 100 / bytesTotal;
63 | emit progress(percent);
64 | });
65 |
66 | connect(reply, &QNetworkReply::finished, this, [this] {
67 | if (!reply) return;
68 | int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
69 | if (status != 200) {
70 | QString message =
71 | reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
72 | if (message.isEmpty()) message = reply->errorString();
73 | emit error(message);
74 | return;
75 | }
76 |
77 | file.close();
78 |
79 | reply->deleteLater();
80 | reply = nullptr;
81 |
82 | emit fileReady(file.fileName());
83 | });
84 | }
85 |
86 | void Downloader::stop() {
87 | if (!reply) return;
88 | reply->disconnect();
89 | reply->abort();
90 | reply->deleteLater();
91 | reply = nullptr;
92 | emit error("Canceled");
93 | }
94 |
95 | } // namespace updater
96 |
--------------------------------------------------------------------------------
/src/impl/downloader.h:
--------------------------------------------------------------------------------
1 | #ifndef UPDATER_IMPL_DOWNLOADER_H
2 | #define UPDATER_IMPL_DOWNLOADER_H
3 |
4 | #include
5 |
6 | #ifdef HTTP
7 | #include "http.h"
8 | #endif
9 |
10 | namespace updater {
11 |
12 | class Downloader : public QObject {
13 | Q_OBJECT
14 |
15 | public:
16 | void download(const QUrl &url);
17 | void stop();
18 |
19 | signals:
20 | void progress(int percent);
21 | void error(const QString &message);
22 | void fileReady(const QString &filename);
23 |
24 | private:
25 | QNetworkReply *reply = nullptr;
26 | QFile file;
27 | };
28 |
29 | } // namespace updater
30 |
31 | #endif // UPDATER_IMPL_DOWNLOADER_H
32 |
--------------------------------------------------------------------------------
/src/impl/installer.h:
--------------------------------------------------------------------------------
1 | #ifndef UPDATER_IMPL_INSTALLER_H
2 | #define UPDATER_IMPL_INSTALLER_H
3 |
4 | #include
5 |
6 | namespace updater {
7 |
8 | class DefaultUpdater;
9 |
10 | /**
11 | * Implement this interface to create your own installer mechanism
12 | * E.g. Unzip and copy files, payload integrity checking, validation, etc.
13 | */
14 | class Installer : public QObject {
15 | Q_OBJECT
16 |
17 | public:
18 | Installer(){};
19 | void setUpdater(DefaultUpdater *value) { updater = value; }
20 |
21 | virtual void start(const QString &filename) = 0;
22 |
23 | signals:
24 | void error(const QString &message);
25 | void finished();
26 |
27 | protected:
28 | DefaultUpdater *updater = nullptr;
29 | };
30 |
31 | } // namespace updater
32 |
33 | #endif // UPDATER_IMPL_INSTALLER_H
34 |
--------------------------------------------------------------------------------
/src/impl/openinstaller.cpp:
--------------------------------------------------------------------------------
1 | #include "openinstaller.h"
2 |
3 | #include
4 |
5 | namespace updater {
6 |
7 | OpenInstaller::OpenInstaller() {}
8 |
9 | void updater::OpenInstaller::start(const QString &filename) {
10 | if (!QDesktopServices::openUrl(QUrl("file:///" + filename))) emit error("Cannot start update");
11 | emit finished();
12 | }
13 |
14 | } // namespace updater
15 |
--------------------------------------------------------------------------------
/src/impl/openinstaller.h:
--------------------------------------------------------------------------------
1 | #ifndef OPENINSTALLER_H
2 | #define OPENINSTALLER_H
3 |
4 | #include
5 |
6 | #include "installer.h"
7 |
8 | namespace updater {
9 |
10 | /// Installer implementation that opens the downloaded update
11 | class OpenInstaller : public Installer {
12 | Q_OBJECT
13 |
14 | public:
15 | OpenInstaller();
16 | void start(const QString &filename);
17 | };
18 |
19 | } // namespace updater
20 | #endif // OPENINSTALLER_H
21 |
--------------------------------------------------------------------------------
/src/impl/parser.h:
--------------------------------------------------------------------------------
1 | #ifndef UPDATER_IMPL_PARSER_H
2 | #define UPDATER_IMPL_PARSER_H
3 |
4 | #include
5 |
6 | namespace updater {
7 |
8 | class DefaultUpdater;
9 |
10 | /**
11 | * Implement this interface to parse your custom manifest format
12 | */
13 | class Parser {
14 | public:
15 | /// Parse your manifest and set relevant Updater properties
16 | virtual void parse(const QByteArray &bytes) = 0;
17 |
18 | void setUpdater(DefaultUpdater *value) { updater = value; }
19 | bool hasError() const { return error; };
20 | QString getErrorMessage() const { return errorMessage; };
21 |
22 | protected:
23 | Parser(){};
24 | DefaultUpdater *updater = nullptr;
25 | bool error = false;
26 | QString errorMessage;
27 | };
28 |
29 | } // namespace updater
30 |
31 | #endif // UPDATER_IMPL_PARSER_H
32 |
--------------------------------------------------------------------------------
/src/impl/runinstaller.cpp:
--------------------------------------------------------------------------------
1 | #include "runinstaller.h"
2 |
3 | #include
4 |
5 | #include "defaultupdater.h"
6 |
7 | namespace updater {
8 |
9 | RunInstaller::RunInstaller() : Installer() {}
10 |
11 | void RunInstaller::start(const QString &filename) {
12 | auto processedArguments = arguments;
13 |
14 | if (command.isEmpty()) {
15 | command = filename;
16 | } else {
17 | // replace markers
18 | for (auto &arg : processedArguments)
19 | arg.replace("%filename%", filename);
20 | #ifdef Q_OS_LINUX
21 | if (runAsAdmin) {
22 | processedArguments.prepend(command);
23 | command = "pkexec";
24 | }
25 | #endif
26 | }
27 |
28 | QProcess *process = new QProcess();
29 | QObject::connect(process, &QProcess::errorOccurred, this, [this](auto error) {
30 | this->emit error("Update error: " + QVariant::fromValue(error).toString());
31 | });
32 |
33 | if (!fork) {
34 | auto thread = new QThread;
35 | process->moveToThread(thread);
36 | connect(process, QOverload::of(&QProcess::finished), this,
37 | [this](int exitCode, QProcess::ExitStatus exitStatus) {
38 | qDebug() << "finished" << exitCode << exitStatus;
39 | if (autoRestart && exitStatus == QProcess::NormalExit && exitCode == 0) {
40 | qDebug() << "Restarting" << qApp->applicationFilePath();
41 | QProcess *restartProcess = new QProcess(this);
42 | restartProcess->startDetached(qApp->applicationFilePath(), {});
43 | }
44 | emit finished();
45 | });
46 | qDebug() << "Executing" << command << processedArguments;
47 | process->start(command, processedArguments);
48 | process->waitForFinished(60000);
49 | } else {
50 | qDebug() << "Forking" << command << processedArguments;
51 | if (!process->startDetached(command, processedArguments)) {
52 | qWarning() << "Cannot execute" << command << processedArguments
53 | << process->errorString();
54 | // Fallback to opening the downloaded payload
55 | QDesktopServices::openUrl(QUrl("file:///" + filename));
56 | }
57 | emit finished();
58 | }
59 | }
60 |
61 | } // namespace updater
62 |
--------------------------------------------------------------------------------
/src/impl/runinstaller.h:
--------------------------------------------------------------------------------
1 | #ifndef UPDATER_IMPL_RUNINSTALLER_H
2 | #define UPDATER_IMPL_RUNINSTALLER_H
3 |
4 | #include
5 |
6 | #include "installer.h"
7 |
8 | namespace updater {
9 |
10 | /**
11 | * Installer implementation that executes a command with arguments
12 | */
13 | class RunInstaller : public Installer {
14 | Q_OBJECT
15 |
16 | public:
17 | RunInstaller();
18 | void setCommand(const QString &value) { command = value; }
19 | void setArguments(const QStringList &value) { arguments = value; };
20 |
21 | /**
22 | * Currently supported on Linux only using pkexec. Does not work together with fork.
23 | */
24 | void setRunAsAdmin(bool value) { runAsAdmin = value; }
25 |
26 | /**
27 | * This will cause the update process to run while the app is still running. Then the app will
28 | * self-restart. Does not work together with fork.
29 | */
30 | void setAutoRestart(bool value) { autoRestart = value; }
31 |
32 | /**
33 | * When true the update process will be detached from the app process (i.e. the app can quit
34 | * without killing it). Does not work together with autoRestart.
35 | */
36 | void setFork(bool value) { fork = value; }
37 |
38 | void start(const QString &filename);
39 |
40 | private:
41 | QString command;
42 | QStringList arguments;
43 | bool runAsAdmin = false;
44 | bool autoRestart = false;
45 | bool fork = false;
46 | };
47 |
48 | } // namespace updater
49 |
50 | #endif // UPDATER_IMPL_RUNINSTALLER_H
51 |
--------------------------------------------------------------------------------
/src/impl/simplexmlparser.cpp:
--------------------------------------------------------------------------------
1 | #include "simplexmlparser.h"
2 |
3 | #include "defaultupdater.h"
4 |
5 | namespace updater {
6 |
7 | SimpleXmlParser::SimpleXmlParser() {}
8 |
9 | void SimpleXmlParser::parse(const QByteArray &bytes) {
10 | error = false;
11 | errorMessage.clear();
12 |
13 | QXmlStreamReader reader;
14 | reader.addData(bytes);
15 | while (!reader.atEnd()) {
16 | reader.readNext();
17 | if (reader.isStartElement()) {
18 | if (reader.name() == rootElementName) {
19 | while (!reader.atEnd()) {
20 | reader.readNext();
21 | if (reader.isStartElement() && reader.name() == versionElementName) {
22 | updater->setVersion(reader.readElementText());
23 | } else if (reader.isStartElement() && reader.name() == urlElementName) {
24 | QString url = reader.readElementText();
25 | for (const auto &arg : qAsConst(urlArguments)) {
26 | url = url.arg(arg);
27 | }
28 | updater->setDownloadUrl(url);
29 | }
30 | }
31 | }
32 | }
33 | }
34 | if (reader.hasError()) {
35 | error = true;
36 | errorMessage = reader.errorString();
37 | }
38 | }
39 |
40 | } // namespace updater
41 |
--------------------------------------------------------------------------------
/src/impl/simplexmlparser.h:
--------------------------------------------------------------------------------
1 | #ifndef SIMPLEXMLPARSER_H
2 | #define SIMPLEXMLPARSER_H
3 |
4 | #include
5 |
6 | #include "parser.h"
7 |
8 | namespace updater {
9 |
10 | class DefaultUpdater;
11 |
12 | /**
13 | * Format example:
14 | *
15 | * 3.4.2
16 | *
17 | * Or
18 | *
19 | *
20 | * 3.4.2
21 | * https://mydomain/mypayload.%1
22 | *
23 | */
24 | class SimpleXmlParser : public Parser {
25 |
26 | public:
27 | explicit SimpleXmlParser();
28 | void parse(const QByteArray &bytes);
29 |
30 | void setRootElementName(const QString &value) { rootElementName = value; }
31 | void setVersionElementName(const QString &value) { versionElementName = value; }
32 | void setUrlElementName(const QString &value) { urlElementName = value; }
33 | void setUrlArguments(const QStringList &value) { urlArguments = value; }
34 |
35 | private:
36 | QString rootElementName = "release";
37 | QString versionElementName = "version";
38 | QString urlElementName = "url";
39 | QStringList urlArguments;
40 | };
41 |
42 | } // namespace updater
43 |
44 | #endif // SIMPLEXMLPARSER_H
45 |
--------------------------------------------------------------------------------
/src/sparkle/sparkleupdater.h:
--------------------------------------------------------------------------------
1 | #ifndef SPARKLE_UPDATER_H
2 | #define SPARKLE_UPDATER_H
3 |
4 | #include "updater.h"
5 |
6 | Q_FORWARD_DECLARE_OBJC_CLASS(SPUUpdater);
7 |
8 | namespace updater {
9 |
10 | class SparkleUpdater : public ::Updater {
11 | Q_OBJECT
12 |
13 | public:
14 | SparkleUpdater();
15 |
16 | bool getAutomaticDownload() const;
17 | void setAutomaticDownload(bool value);
18 |
19 | void checkAndShowUI();
20 | void checkAndMaybeShowUI();
21 | void checkWithoutUI();
22 |
23 | protected slots:
24 | void update();
25 |
26 | private:
27 | SPUUpdater *updater = NULL;
28 | };
29 |
30 | } // namespace updater
31 |
32 | #endif // SPARKLE_UPDATER_H
33 |
--------------------------------------------------------------------------------
/src/sparkle/sparkleupdater.mm:
--------------------------------------------------------------------------------
1 | #include "sparkleupdater.h"
2 |
3 | #import
4 | #import
5 | #import
6 | #import
7 |
8 | // https://sparkle-project.org/documentation/programmatic-setup/
9 |
10 | @interface SparkleDelegate : NSObject {
11 | }
12 | @end
13 |
14 | @implementation SparkleDelegate {
15 | Updater *u;
16 | }
17 |
18 | - (void)setUpdater:(Updater *)v {
19 | u = v;
20 | }
21 |
22 | - (void)updater:(SPUUpdater *)updater didFindValidUpdate:(SUAppcastItem *)item {
23 | qDebug() << item.versionString;
24 | Q_UNUSED(updater)
25 | u->setVersion(QString::fromNSString(item.displayVersionString));
26 | u->setStatus(Updater::Status::UpdateAvailable);
27 | // [updater installUpdatesIfAvailable];
28 | }
29 |
30 | - (void)updaterDidNotFindUpdate:(SPUUpdater *)updater {
31 | Q_UNUSED(updater)
32 | u->setStatus(Updater::Status::UpToDate);
33 | }
34 |
35 | - (void)updater:(SPUUpdater *)updater
36 | willDownloadUpdate:(SUAppcastItem *)item
37 | withRequest:(NSMutableURLRequest *)request {
38 | qDebug() << item.versionString << request;
39 | Q_UNUSED(updater)
40 | u->setStatus(Updater::Status::DownloadingUpdate);
41 | }
42 |
43 | - (void)updater:(SPUUpdater *)updater didDownloadUpdate:(SUAppcastItem *)item {
44 | qDebug() << item.versionString;
45 | Q_UNUSED(updater)
46 | u->setStatus(Updater::Status::UpdateDownloaded);
47 | }
48 |
49 | - (void)userDidCancelDownload:(SPUUpdater *)updater {
50 | Q_UNUSED(updater)
51 | u->setStatus(Updater::Status::UpdateAvailable);
52 | }
53 |
54 | - (void)updater:(SPUUpdater *)updater
55 | failedToDownloadUpdate:(SUAppcastItem *)item
56 | error:(NSError *)error {
57 | qDebug() << error;
58 | u->setStatus(Updater::Status::UpdateDownloadFailed);
59 | }
60 |
61 | - (void)updater:(SPUUpdater *)updater
62 | willInstallUpdateOnQuit:(SUAppcastItem *)item
63 | immediateInstallationInvocation:(NSInvocation *)invocation {
64 | Q_UNUSED(updater)
65 | qDebug() << u->getImmediateInstallAndRelaunch();
66 | if (u->getImmediateInstallAndRelaunch()) [invocation invoke];
67 | }
68 |
69 | - (void)updater:(SPUUpdater *)updater willInstallUpdate:(SUAppcastItem *)item {
70 | qDebug() << item.versionString;
71 | }
72 |
73 | - (void)updaterWillRelaunchApplication:(SPUUpdater *)updater {
74 | qDebug() << updater;
75 | }
76 |
77 | - (void)updater:(SPUUpdater *)updater didAbortWithError:(NSError *)error {
78 | qDebug() << error;
79 | }
80 |
81 | @end
82 |
83 | namespace updater {
84 |
85 | SparkleUpdater::SparkleUpdater() {
86 | SparkleDelegate *delegate = [[SparkleDelegate alloc] init];
87 | [delegate setUpdater:this];
88 |
89 | SPUStandardUpdaterController *updaterController = [SPUStandardUpdaterController alloc];
90 | [updaterController initWithStartingUpdater:YES updaterDelegate:delegate userDriverDelegate:Nil];
91 |
92 | updater = updaterController.updater;
93 | updater.automaticallyChecksForUpdates = YES;
94 | updater.automaticallyDownloadsUpdates = YES;
95 | }
96 |
97 | bool SparkleUpdater::getAutomaticDownload() const {
98 | return updater.automaticallyDownloadsUpdates;
99 | }
100 |
101 | void SparkleUpdater::setAutomaticDownload(bool value) {
102 | updater.automaticallyDownloadsUpdates = value;
103 | }
104 |
105 | void SparkleUpdater::checkAndShowUI() {
106 | [updater checkForUpdates];
107 | }
108 |
109 | void SparkleUpdater::checkAndMaybeShowUI() {
110 | [updater checkForUpdatesInBackground];
111 | }
112 |
113 | void SparkleUpdater::checkWithoutUI() {
114 | [updater checkForUpdateInformation];
115 | }
116 |
117 | void SparkleUpdater::update() {
118 | qDebug() << "Not implemented";
119 | }
120 |
121 | } // namespace updater
122 |
--------------------------------------------------------------------------------
/src/updater.cpp:
--------------------------------------------------------------------------------
1 | #include "updater.h"
2 |
3 | namespace {
4 | Updater *sharedInstance = nullptr;
5 | }
6 |
7 | void Updater::setInstance(Updater *value) {
8 | sharedInstance = value;
9 | }
10 |
11 | Updater &Updater::instance() {
12 | return *sharedInstance;
13 | }
14 |
15 | Updater::Updater(QObject *parent) : QObject(parent) {}
16 |
17 | QAction *Updater::getAction() {
18 | if (!action) {
19 | action = new QAction(this);
20 | connect(action, &QWidget::destroyed, this, [this] { action = nullptr; });
21 | action->setMenuRole(QAction::ApplicationSpecificRole);
22 | connect(action, &QAction::triggered, this, &Updater::onUserAction);
23 | auto onStatusChange = [this](Updater::Status status) {
24 | QString v = displayVersion.isEmpty() ? version : displayVersion;
25 | QString t;
26 | switch (status) {
27 | case Updater::Status::Unknown:
28 | case Updater::Status::UpToDate:
29 | t = tr("Check for Updates...");
30 | break;
31 | case Updater::Status::UpdateAvailable:
32 | t = tr("Version %1 is available...").arg(v);
33 | break;
34 | case Updater::Status::DownloadingUpdate:
35 | t = tr("Downloading version %1...").arg(v);
36 | break;
37 | case Updater::Status::UpdateDownloaded:
38 | t = tr("Restart to Update");
39 | break;
40 | case Updater::Status::UpdateDownloadFailed:
41 | t = tr("Version %1 download failed").arg(v);
42 | break;
43 | }
44 | action->setText(t);
45 | };
46 | connect(this, &Updater::statusChanged, this, onStatusChange);
47 | onStatusChange(status);
48 | }
49 | return action;
50 | }
51 |
52 | QPushButton *Updater::getButton() {
53 | if (!button) {
54 | button = new QPushButton();
55 | connect(button, &QWidget::destroyed, this, [this] { button = nullptr; });
56 | connect(button, &QPushButton::clicked, this, &Updater::onUserAction);
57 | auto onStatusChange = [this](Updater::Status status) {
58 | QString t;
59 | bool visible = true;
60 | switch (status) {
61 | case Updater::Status::Unknown:
62 | case Updater::Status::UpToDate:
63 | t = tr("Check for Updates");
64 | break;
65 | case Updater::Status::UpdateAvailable:
66 | t = tr("Download Update");
67 | break;
68 | case Updater::Status::DownloadingUpdate:
69 | t = tr("Downloading update...");
70 | visible = false;
71 | break;
72 | case Updater::Status::UpdateDownloaded:
73 | t = tr("Restart to Update");
74 | break;
75 | case Updater::Status::UpdateDownloadFailed:
76 | t = tr("Retry Update Download");
77 | break;
78 | }
79 | button->setText(t);
80 | button->setVisible(visible);
81 | };
82 | connect(this, &Updater::statusChanged, button, onStatusChange);
83 | onStatusChange(status);
84 | }
85 | return button;
86 | }
87 |
88 | QLabel *Updater::getLabel() {
89 | if (!label) {
90 | label = new QLabel();
91 | connect(label, &QWidget::destroyed, this, [this] { label = nullptr; });
92 | auto onStatusChange = [this](Updater::Status status) {
93 | QString v = displayVersion.isEmpty() ? version : displayVersion;
94 | QString t;
95 | switch (status) {
96 | case Updater::Status::Unknown:
97 | t = tr("Didn't check for updates.");
98 | break;
99 | case Updater::Status::UpToDate:
100 | t = tr("You have the latest version.");
101 | break;
102 | case Updater::Status::UpdateAvailable:
103 | t = tr("Version %1 is available.").arg(v);
104 | break;
105 | case Updater::Status::DownloadingUpdate:
106 | t = tr("Downloading update...");
107 | break;
108 | case Updater::Status::UpdateDownloaded:
109 | t = tr("An update has been downloaded and is ready to be installed.");
110 | break;
111 | case Updater::Status::UpdateDownloadFailed:
112 | t = tr("Version %1 download failed.").arg(v);
113 | break;
114 | }
115 | label->setText(t);
116 | };
117 | connect(this, &Updater::statusChanged, label, onStatusChange);
118 | onStatusChange(status);
119 | }
120 | return label;
121 | }
122 |
123 | void Updater::setStatus(Status v) {
124 | if (status != v) {
125 | status = v;
126 | emit statusChanged(status);
127 | }
128 | }
129 |
130 | void Updater::onUserAction() {
131 | if (status == Updater::Status::UpdateDownloaded) {
132 | // update will be installed on quit
133 | qApp->quit();
134 | return;
135 | } else {
136 | checkAndShowUI();
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/src/updater.h:
--------------------------------------------------------------------------------
1 | #ifndef UPDATER_H
2 | #define UPDATER_H
3 |
4 | #include
5 |
6 |
7 | class Updater : public QObject {
8 | Q_OBJECT
9 |
10 | public:
11 | /// Set a shared Updater instance
12 | static void setInstance(Updater *value);
13 |
14 | /// Get a shared updater instance, null by default
15 | static Updater &instance();
16 |
17 | Updater(QObject *parent = nullptr);
18 |
19 | QAction *getAction();
20 | QPushButton *getButton();
21 | QLabel *getLabel();
22 |
23 | enum class Status {
24 | Unknown,
25 | UpToDate,
26 | UpdateAvailable,
27 | DownloadingUpdate,
28 | UpdateDownloaded,
29 | UpdateDownloadFailed
30 | };
31 | Q_ENUM(Status)
32 | Status getStatus() const { return status; }
33 | // This should be protected
34 | void setStatus(Status v);
35 |
36 | QString getVersion() const { return version; }
37 | // This should be protected
38 | void setVersion(const QString &value) { version = value; }
39 |
40 | QString getDisplayVersion() const { return displayVersion; }
41 | // This should be protected
42 | void setDisplayVersion(const QString &value) { displayVersion = value; }
43 |
44 | /// true if the app can be updated immediately while running (default: false)
45 | virtual bool getImmediateInstallWithoutRelaunch() const {
46 | return immediateInstallWithoutRelaunch;
47 | }
48 | virtual void setImmediateInstallWithoutRelaunch(bool value) {
49 | immediateInstallWithoutRelaunch = value;
50 | }
51 |
52 | /// true if the app can be stopped and relaunched immediately (default: false)
53 | virtual bool getImmediateInstallAndRelaunch() const { return immediateInstallAndRelaunch; }
54 | virtual void setImmediateInstallAndRelaunch(bool value) { immediateInstallAndRelaunch = value; }
55 |
56 | /// when true an available update will be downloaded without user interaction (default: true)
57 | virtual bool getAutomaticDownload() const { return automaticDownload; }
58 | virtual void setAutomaticDownload(bool value) { automaticDownload = value; }
59 |
60 | virtual void checkAndShowUI() = 0;
61 | virtual void checkAndMaybeShowUI() = 0;
62 | virtual void checkWithoutUI() = 0;
63 |
64 | protected slots:
65 | virtual void update() = 0;
66 | virtual void onUserAction();
67 |
68 | signals:
69 | void statusChanged(Status status);
70 | void actionTextChanged(const QString &actionText);
71 |
72 | private:
73 | QAction *action = nullptr;
74 | QPushButton *button = nullptr;
75 | QLabel *label = nullptr;
76 |
77 | bool automaticDownload = true;
78 | bool immediateInstallAndRelaunch = false;
79 | bool immediateInstallWithoutRelaunch = false;
80 | Status status = Status::Unknown;
81 | QString version;
82 | QString displayVersion;
83 | };
84 |
85 | #endif // UPDATER_H
86 |
--------------------------------------------------------------------------------
/updater.pri:
--------------------------------------------------------------------------------
1 | DEFINES *= UPDATER
2 |
3 | INCLUDEPATH += $$PWD/src
4 |
5 | HEADERS += $$PWD/src/updater.h
6 | SOURCES += $$PWD/src/updater.cpp
7 |
8 | macx:!contains(DEFINES, UPDATER_NO_SPARKLE) {
9 | DEFINES += UPDATER_SPARKLE
10 | INCLUDEPATH += $$PWD/src/sparkle
11 | LIBS += -F/Library/Frameworks -framework Sparkle
12 | INCLUDEPATH += /Library/Frameworks/Sparkle.framework/Headers
13 |
14 | # Hack to get the inclusion of headers working
15 | # Sparkle includes stuff using
16 | # We need to create a Sparkle subdir inside Sparkle-headers
17 | INCLUDEPATH += /Library/Frameworks/Sparkle-headers
18 |
19 | HEADERS += $$PWD/src/sparkle/sparkleupdater.h
20 | OBJECTIVE_SOURCES += $$PWD/src/sparkle/sparkleupdater.mm
21 | } else {
22 | DEFINES += UPDATER_DEFAULT
23 | QT *= network widgets
24 | INCLUDEPATH += $$PWD/src/impl
25 |
26 | HEADERS += \
27 | $$PWD/src/impl/checker.h \
28 | $$PWD/src/impl/defaultupdater.h \
29 | $$PWD/src/impl/dialog.h \
30 | $$PWD/src/impl/downloader.h \
31 | $$PWD/src/impl/installer.h \
32 | $$PWD/src/impl/parser.h \
33 | $$PWD/src/impl/runinstaller.h \
34 | $$PWD/src/impl/simplexmlparser.h \
35 | $$PWD/src/impl/appcastparser.h \
36 | $$PWD/src/impl/openinstaller.h
37 |
38 | SOURCES += \
39 | $$PWD/src/impl/checker.cpp \
40 | $$PWD/src/impl/defaultupdater.cpp \
41 | $$PWD/src/impl/dialog.cpp \
42 | $$PWD/src/impl/downloader.cpp \
43 | $$PWD/src/impl/runinstaller.cpp \
44 | $$PWD/src/impl/simplexmlparser.cpp \
45 | $$PWD/src/impl/appcastparser.cpp \
46 | $$PWD/src/impl/openinstaller.cpp
47 | }
48 |
--------------------------------------------------------------------------------
/updater.pro:
--------------------------------------------------------------------------------
1 | TEMPLATE = lib
2 | include(updater.pri)
3 |
--------------------------------------------------------------------------------