├── .gitignore
├── .gitmodules
├── LICENSE
├── README.md
├── Schticker-Book-Rewritten.pro
├── downloadworker.cpp
├── downloadworker.h
├── extractionworker.cpp
├── extractionworker.h
├── filelocationchooser.cpp
├── filelocationchooser.h
├── filelocationchooser.ui
├── globaldefines.h
├── jsonworker.cpp
├── jsonworker.h
├── launcherwindow.cpp
├── launcherwindow.h
├── launcherwindow.ui
├── loginworker.cpp
├── loginworker.h
├── main.cpp
├── patchworker.cpp
├── patchworker.h
├── pictures
├── about-tab.png
├── fishing-tab.png
├── groups-tab.png
├── invasions-tab.png
└── launcher-tab.png
├── resources.qrc
├── resources
├── 128x128
│ └── shticker-book-rewritten.png
├── 256x256
│ └── shticker-book-rewritten.png
├── 32x32
│ └── shticker-book-rewritten.png
├── 64x64
│ └── shticker-book-rewritten.png
├── TTR_Logo.png
├── icon.icns
└── icon.ico
├── shticker-book-rewritten.desktop
├── twofactorwindow.cpp
├── twofactorwindow.h
├── twofactorwindow.ui
├── updateworker.cpp
├── updateworker.h
├── utilities.cpp
├── utilities.h
└── windows
├── fake_unistd.h
├── getopt.c
├── getopt.h
└── shticker-book-rewritten.rc
/.gitignore:
--------------------------------------------------------------------------------
1 | # C++ objects and libs
2 |
3 | *.slo
4 | *.lo
5 | *.o
6 | *.a
7 | *.la
8 | *.lai
9 | *.so
10 | *.dll
11 | *.dylib
12 |
13 | # Qt-es
14 |
15 | /.qmake.cache
16 | /.qmake.stash
17 | *.pro.user
18 | *.pro.user.*
19 | *.qbs.user
20 | *.qbs.user.*
21 | *.moc
22 | moc_*.cpp
23 | qrc_*.cpp
24 | ui_*.h
25 | Makefile*
26 | *-build-*
27 |
28 | # QtCreator
29 |
30 | *.autosave
31 |
32 | #QtCtreator Qml
33 | *.qmlproject.user
34 | *.qmlproject.user.*
35 |
36 |
37 | #misc
38 |
39 | .directory
40 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madsciencecoder/shticker-book-rewritten/a40f4fffcf3d518c3032530f34b5b1f66145aa5d/.gitmodules
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
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 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) {year} {name of author}
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 | {project} Copyright (C) {year} {fullname}
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 |
676 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Shticker Book Rewritten
2 |
3 | Custom launcher for the MMORPG Toontown Rewritten. Named after the in game shticker book which provides access to various settings and data. It tries to provide an all in one tool to provide useful tools to make playing easier.
4 |
5 | It supports all platforms that Toontown Rewritten does. MacOS users need to manually allow the app to run by opening the Applications folder in Finder and opening it by pressing the command key while opening the app. This is because Apple forces apps to be signed but charges for the ability to sign them.
6 |
7 | ### Screenshots
8 |
9 | Colors and theme may be different depending on the user's platform and Qt theme.
10 |
11 | 
12 | 
13 | 
14 | 
15 | 
16 |
17 | ### Windows Installer
18 |
19 | There is now an official installer for Windows. Please check the releases page to download the most recent version. Please note that it does not check for updates for itself yet so be sure to either keep an eye out or you can follow the repository for email updates.
20 |
21 | ### Linux Packages
22 |
23 | I have created packages through OpenSuse's OBS for the most popular distributions. There are currently packages for OpenSuse, Fedora, Debian, and Ubuntu. If there is a version without a repository please open an issue as I may have forgot to update them.
24 |
25 | You can get the packages at https://software.opensuse.org/download.html?project=home%3Amadsciencecoder%3Ashticker-book-rewritten&package=shticker-book-rewritten. Just click your distribution and follow the instructions for your version.
26 |
27 | Note: The packages available have been patched to replace webengine with webkit in the distros that do not provide webengine packages (Debian, Ubuntu, and Fedora).
28 |
29 | ### Features
30 |
31 | * Automatic downloading and patching of game files
32 | * Linux version stores the game files in the user's home under the folder ToontownRewritten. This is to allow Schticker Book Rewritten to be installed like a normal package in root but still allow it write access to update the game files.
33 | * Built in group tracker via www.toonhq.org
34 | * Built in invasion tracker via www.toonhq.org
35 | * Built in fishing guide via http://siggen.toontown-click.de/fishadvisor/en/ponds.html
36 | * Unlimited number of toons may be launched from the same launcher, no need to open one per toon
37 | * Warns if you close the launcher while a game instance is running as it will cause the game to close if the launcher is closed
38 | * Option to save login details for an unlimited number of accounts
39 | * Option to turn off automatic game file updates on startup to allow you to login faster
40 | * Option to update the game files manually
41 |
42 | #### Planned Features
43 |
44 | * Standalone invasion tracker. More features can be added to the tracker and there is no need to rely on ToonHQ like it is necessary for the groups due to lack of an API. The notifications also don't work 100% with QWebKit.
45 | * Content pack installer. Currently you must manually place the content pack inside a folder called `resources` in the game's folder. For Linux this is ToontownRewritten inside the user's home folder.
46 | * Self updating to new versions of the launcher (Windows only since Linux has good package management already)
47 |
48 | ### How to Compile
49 |
50 | This program relies on 2 external libraries: Qt 5 and libbzip2. Bsdiff is also used but are embedded into the project.
51 |
52 | #### Linux based distros
53 |
54 | ##### Ubuntu / Debian
55 |
56 | Required dependency packages: `qt5-qmake build-essential libbz2-dev`. Qt's webengine is necessary but they do not provide packages.
57 |
58 | To build and install:
59 | ```
60 | export QT_SELECT=qt5
61 | qmake
62 | make
63 | sudo make install
64 | ```
65 |
66 | ##### OpenSuse
67 |
68 | Required dependency packages: `libbz2-devel libqt5-qtwebengine-devel`
69 |
70 | To build and install:
71 | ```
72 | qmake-qt5
73 | make
74 | sudo make install
75 | ````
76 |
77 | ##### Fedora
78 |
79 | Required dependency packages: `qt5-qtbase-devel qt5-qtwebengine-devel gcc-c++ bzip2-devel`. Qt's webengine is necessary but they do not provide packages until Fedora 24 is released.
80 |
81 | To build and install:
82 | ```
83 | qmake-qt5
84 | make
85 | sudo make install
86 | ````
87 |
88 | ##### Arch
89 |
90 | Required dependency packages: `bzip2 qt5-base qt5-webengine`.
91 |
92 | AUR package for the latest git version: https://aur.archlinux.org/packages/shticker-book-rewritten-git/.
93 |
94 | #### Windows
95 |
96 | The easiest way to compile this on Windows is to download Qt from their website (https://www.qt.io/download-open-source/) and install with at least Qt 5.5 and MinGW. You will need to manually supply a built bzip2 library for Qt to use which you can download a pre-compiled one from http://sourceforge.net/projects/mingw/files/MinGW/Extension/bzip2/bzip2-1.0.6-4/. You will need both the dev and dll-2 downloads. Then copy the files to the Qt folders containing the build libraries. You will also need openssl DLLs which can be downloaded from http://slproweb.com/products/Win32OpenSSL.html. To make handling DLLs easier you may wish to add the Qt bin directory to your Windows PATH environment variable.
97 |
98 | #### Mac OS X
99 |
100 | Please check the releases page to download the most recent version. You may need to manually allow the app to run by opening the Applications folder in Finder and opening it by pressing the command key while opening the app. This is because Apple forces apps to be signed but charges for the ability to sign them. This only needs to be done once, after that you can launch the app like normal.
101 |
--------------------------------------------------------------------------------
/Schticker-Book-Rewritten.pro:
--------------------------------------------------------------------------------
1 | #-------------------------------------------------
2 | #
3 | # Project created by QtCreator 2015-12-29T13:25:12
4 | #
5 | #-------------------------------------------------
6 | # Copyright (c) 2015-2016 Joshua Snyder
7 | # Distributed under the GNU GPL v3. For full terms see the file LICENSE
8 | #
9 | # This file is part of Shticker Book Rewritten.
10 | #
11 | # Shticker Book Rewritten is free software: you can redistribute it and/or modify
12 | # it under the terms of the GNU General Public License as published by
13 | # the Free Software Foundation, either version 3 of the License, or
14 | # (at your option) any later version.
15 | #
16 | # Shticker Book Rewritten is distributed in the hope that it will be useful,
17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | # GNU General Public License for more details.
20 | #
21 | # You should have received a copy of the GNU General Public License
22 | # along with Shticker Book Rewritten. If not, see .
23 |
24 | QT += core gui webenginewidgets network widgets
25 |
26 | lessThan(QT_MAJOR_VERSION, 5): error("This program requires Qt 5 or higher")
27 |
28 | TARGET = shticker-book-rewritten
29 | TEMPLATE = app
30 |
31 |
32 | SOURCES += main.cpp\
33 | launcherwindow.cpp \
34 | updateworker.cpp \
35 | jsonworker.cpp \
36 | extractionworker.cpp \
37 | downloadworker.cpp \
38 | loginworker.cpp \
39 | twofactorwindow.cpp \
40 | patchworker.cpp \
41 | filelocationchooser.cpp \
42 | utilities.cpp
43 |
44 | HEADERS += launcherwindow.h \
45 | globaldefines.h \
46 | updateworker.h \
47 | jsonworker.h \
48 | extractionworker.h \
49 | downloadworker.h \
50 | loginworker.h \
51 | twofactorwindow.h \
52 | patchworker.h \
53 | filelocationchooser.h \
54 | utilities.h
55 |
56 | FORMS += launcherwindow.ui \
57 | twofactorwindow.ui \
58 | filelocationchooser.ui
59 |
60 | RESOURCES += \
61 | resources.qrc
62 |
63 | LIBS += -lbz2
64 |
65 | DISTFILES += LICENSE
66 | unix:!mac {
67 | isEmpty(PREFIX):PREFIX = /usr
68 | BINDIR = $$PREFIX/bin
69 | INSTALLS += target
70 | target.path = $$BINDIR
71 | DATADIR = $$PREFIX/share
72 | PKGDATADIR = $$DATADIR/shticker-book-rewritten
73 | DEFINES += DATADIR=\\\"$$DATADIR\\\" \
74 | PKGDATADIR=\\\"$$PKGDATADIR\\\"
75 | INSTALLS += desktop \
76 | icon32 \
77 | icon64 \
78 | icon128 \
79 | icon256
80 | desktop.path = $$DATADIR/applications
81 | desktop.files += shticker-book-rewritten.desktop
82 | icon32.path = $$DATADIR/icons/hicolor/32x32/apps
83 | icon32.files += resources/32x32/shticker-book-rewritten.png
84 | icon64.path = $$DATADIR/icons/hicolor/64x64/apps
85 | icon64.files += resources/64x64/shticker-book-rewritten.png
86 | icon128.path = $$DATADIR/icons/hicolor/128x128/apps
87 | icon128.files += resources/128x128/shticker-book-rewritten.png
88 | icon256.path = $$DATADIR/icons/hicolor/256x256/apps
89 | icon256.files += resources/256x256/shticker-book-rewritten.png
90 | }
91 |
92 | RC_FILE = windows/shticker-book-rewritten.rc
93 |
--------------------------------------------------------------------------------
/downloadworker.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015-2016 Joshua Snyder
3 | * Distributed under the GNU GPL v3. For full terms see the file LICENSE
4 | *
5 | * This file is part of Shticker Book Rewritten.
6 | *
7 | * Shticker Book Rewritten is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Shticker Book Rewritten is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Shticker Book Rewritten. If not, see .
19 | */
20 |
21 | #include "downloadworker.h"
22 | #include "globaldefines.h"
23 |
24 | #include
25 | #include
26 | #include
27 | #include
28 |
29 | DownloadWorker::DownloadWorker(QObject *parent) : QObject(parent)
30 | {
31 |
32 | }
33 |
34 | //returns true if successful and false if there was an error
35 | bool DownloadWorker::getFile(QUrl url, QString fileName)
36 | {
37 | //Create a temporary file to download into to save RAM
38 | file = new QFile(fileName);
39 |
40 | //open the file to write into
41 | if(file->open(QIODevice::WriteOnly))
42 | {
43 | qDebug() << "Getting the bz2 file" << file->fileName();
44 | }
45 | else
46 | {
47 | qDebug() << "Unable to open or write to" << file->fileName();
48 | delete file;
49 | file = 0;
50 | return false;
51 | }
52 |
53 | //show the progress bar
54 | emit showProgressBar();
55 |
56 | networkManager = new QNetworkAccessManager(this);
57 | QEventLoop waitForFinished;
58 |
59 | //start downloading the file
60 | reply = networkManager->get(QNetworkRequest(url));
61 |
62 | //connect the reply to our event loop to wait for the download to finish
63 | connect(reply, SIGNAL(finished()), &waitForFinished, SLOT(quit()));
64 | //send the data information to our progress bar
65 | connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(relayDownloadProgress(qint64, qint64)));
66 | connect(reply, SIGNAL(readyRead()), this, SLOT(httpReadyRead()));
67 |
68 | //start the event loop to wait for the download to finish
69 | waitForFinished.exec();
70 |
71 | //hide the progress bar again now that we are done
72 | emit hideProgressBar();
73 |
74 | //close the file and flush it from memory
75 | file->flush();
76 | file->close();
77 | delete file;
78 |
79 | if(reply->error())
80 | {
81 | qDebug() << "There was an error downloading" << url << "Error:" << reply->errorString() << endl;
82 |
83 | reply->deleteLater();
84 |
85 | return false;
86 | }
87 | else
88 | {
89 | reply->deleteLater();
90 |
91 | return true;
92 | }
93 | }
94 |
95 | void DownloadWorker::relayDownloadProgress(qint64 receivedBytes, qint64 totalBytes)
96 | {
97 | emit sendDownloadProgress(receivedBytes, totalBytes);
98 | }
99 |
100 | void DownloadWorker::httpReadyRead()
101 | {
102 | //whenever there is new data from the reply we write it to the file to prevent using too much RAM
103 | if(file)
104 | {
105 | file->write(reply->readAll());
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/downloadworker.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015-2016 Joshua Snyder
3 | * Distributed under the GNU GPL v3. For full terms see the file LICENSE
4 | *
5 | * This file is part of Shticker Book Rewritten.
6 | *
7 | * Shticker Book Rewritten is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Shticker Book Rewritten is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Shticker Book Rewritten. If not, see .
19 | */
20 |
21 | #ifndef DOWNLOADWORKER_H
22 | #define DOWNLOADWORKER_H
23 |
24 | #include
25 | #include
26 | #include
27 | #include
28 |
29 | class DownloadWorker : public QObject
30 | {
31 | Q_OBJECT
32 | public:
33 | explicit DownloadWorker(QObject *parent = 0);
34 | bool getFile(QUrl, QString);
35 |
36 | signals:
37 | void sendDownloadProgress(qint64, qint64);
38 | void showProgressBar();
39 | void hideProgressBar();
40 |
41 | public slots:
42 |
43 | private slots:
44 | void relayDownloadProgress(qint64, qint64);
45 | void httpReadyRead();
46 |
47 | private:
48 | QNetworkAccessManager *networkManager;
49 | QNetworkReply *reply;
50 | QFile *file;
51 | };
52 |
53 | #endif // DOWNLOADWORKER_H
54 |
--------------------------------------------------------------------------------
/extractionworker.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015-2016 Joshua Snyder
3 | * Distributed under the GNU GPL v3. For full terms see the file LICENSE
4 | *
5 | * This file is part of Shticker Book Rewritten.
6 | *
7 | * Shticker Book Rewritten is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Shticker Book Rewritten is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Shticker Book Rewritten. If not, see .
19 | */
20 |
21 | #include "extractionworker.h"
22 |
23 | #include
24 | #include
25 | #include
26 |
27 | ExtractionWorker::ExtractionWorker(QObject *parent) : QObject(parent)
28 | {
29 |
30 | }
31 |
32 | bool ExtractionWorker::extractBz2(QString compressedFileName, QString extractedFileName)
33 | {
34 | qDebug() << "Extracting" << compressedFileName << "to" << extractedFileName;
35 |
36 | FILE *compressedFile;
37 | BZFILE *bzFile;
38 | int bzError;
39 | int bufferBytesRead;
40 | char buffer[1024];
41 | QByteArray decompressedData;
42 | QFile extractedFile(extractedFileName);
43 |
44 | //open the destination file
45 | if(!extractedFile.open(QFile::WriteOnly))
46 | {
47 | qDebug() << "Unable to open" << extractedFile.fileName();
48 | return false;
49 | }
50 |
51 | //open the compressed file
52 | compressedFile = fopen(compressedFileName.toStdString().c_str(), "rb");
53 | if(!compressedFile)
54 | {
55 | qDebug() << "Error opening file: " << compressedFileName << endl;
56 |
57 | return false;
58 | }
59 |
60 | bzFile = BZ2_bzReadOpen(&bzError, compressedFile, 0, 0, NULL, 0);
61 | if(bzError != BZ_OK)
62 | {
63 | qDebug() << "Error opening file to extract:" << compressedFileName;
64 | return false;
65 | }
66 |
67 | //decompress the file in segments to save RAM
68 | while(bzError == BZ_OK)
69 | {
70 | //decompress the file in increments of 1024 bytes
71 | bufferBytesRead = BZ2_bzRead(&bzError, bzFile, buffer, 1024);
72 | if(bzError == BZ_OK || bzError == BZ_STREAM_END)
73 | {
74 | for(int i=0; i.
19 | */
20 |
21 | #ifndef EXTRACTIONWORKER_H
22 | #define EXTRACTIONWORKER_H
23 |
24 | #include
25 |
26 | class ExtractionWorker : public QObject
27 | {
28 | Q_OBJECT
29 | public:
30 | explicit ExtractionWorker(QObject *parent = 0);
31 | bool extractBz2(QString, QString);
32 |
33 | signals:
34 |
35 | public slots:
36 | };
37 |
38 | #endif // EXTRACTIONWORKER_H
39 |
--------------------------------------------------------------------------------
/filelocationchooser.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015-2016 Joshua Snyder
3 | * Distributed under the GNU GPL v3. For full terms see the file LICENSE
4 | *
5 | * This file is part of Shticker Book Rewritten.
6 | *
7 | * Shticker Book Rewritten is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Shticker Book Rewritten is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Shticker Book Rewritten. If not, see .
19 | */
20 |
21 | #include "filelocationchooser.h"
22 | #include "globaldefines.h"
23 | #include "ui_filelocationchooser.h"
24 |
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 |
31 | FileLocationChooser::FileLocationChooser() : QDialog(), ui(new Ui::FileLocationChooser)
32 | {
33 | ui->setupUi(this);
34 |
35 |
36 | ui->filePathEdit->setText(DEFAULT_PATH);
37 |
38 | connect(ui->browseButton, SIGNAL(clicked()), this, SLOT(chooseFile()));
39 | connect(ui->saveButton, SIGNAL(clicked()), this, SLOT(pathChosen()));
40 | }
41 |
42 | FileLocationChooser::~FileLocationChooser()
43 | {
44 | delete ui;
45 | }
46 |
47 | void FileLocationChooser::pathChosen()
48 | {
49 | QDir dir;
50 | //check to see if it already exists
51 | if(!dir.exists(ui->filePathEdit->text()))
52 | {
53 | dir.mkpath(ui->filePathEdit->text());
54 | }
55 |
56 | //make sure the user has write permissions
57 | QFileInfo info(ui->filePathEdit->text());
58 |
59 | if(info.isWritable() && info.isReadable() && info.isExecutable())
60 | {
61 | QSettings settings("Shticker-Book-Rewritten", "Shticker-Book-Rewritten");
62 |
63 | settings.beginGroup("FilesPath");
64 | settings.setValue("path", ui->filePathEdit->text());
65 | settings.endGroup();
66 |
67 | emit finished();
68 | }
69 |
70 | else
71 | {
72 | QMessageBox::warning(this,
73 | "Invalid Folder",
74 | "The folder you have chosen is invalid. Please make sure your user has read, write, and execute permissions.",
75 | QMessageBox::Ok);
76 | }
77 | }
78 |
79 | void FileLocationChooser::chooseFile()
80 | {
81 | QString path = QFileDialog::getExistingDirectory(0, "Game file location", QDir::homePath());
82 |
83 | ui->filePathEdit->setText(path);
84 | }
85 |
--------------------------------------------------------------------------------
/filelocationchooser.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015-2016 Joshua Snyder
3 | * Distributed under the GNU GPL v3. For full terms see the file LICENSE
4 | *
5 | * This file is part of Shticker Book Rewritten.
6 | *
7 | * Shticker Book Rewritten is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Shticker Book Rewritten is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Shticker Book Rewritten. If not, see .
19 | */
20 |
21 | #ifndef FILELOCATIONCHOOSER_H
22 | #define FILELOCATIONCHOOSER_H
23 |
24 | #include
25 | #include
26 |
27 | namespace Ui {
28 | class FileLocationChooser;
29 | }
30 |
31 | class FileLocationChooser : public QDialog
32 | {
33 | Q_OBJECT
34 |
35 | public:
36 | explicit FileLocationChooser();
37 | ~FileLocationChooser();
38 |
39 | signals:
40 | void finished();
41 |
42 | public slots:
43 |
44 | private slots:
45 | void pathChosen();
46 | void chooseFile();
47 |
48 | private:
49 | Ui::FileLocationChooser *ui;
50 | };
51 |
52 | #endif // FILELOCATIONCHOOSER_H
53 |
--------------------------------------------------------------------------------
/filelocationchooser.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | FileLocationChooser
4 |
5 |
6 |
7 | 0
8 | 0
9 | 464
10 | 223
11 |
12 |
13 |
14 |
15 | 0
16 | 0
17 |
18 |
19 |
20 | Choose location
21 |
22 |
23 |
24 | :/resources/icon.ico:/resources/icon.ico
25 |
26 |
27 | -
28 |
29 |
30 | -
31 |
32 |
33 | Browse
34 |
35 |
36 |
37 | -
38 |
39 |
40 | Save
41 |
42 |
43 |
44 | ..
45 |
46 |
47 |
48 | -
49 |
50 |
51 | <html><head/><body><p>Please choose where Shticker Book Rewritten should save the Toontown Rewritten game files. Be sure to pick a location where your user has read, write, and execute permissions.</p><p>This dialog will only appear once and will save the chosen location. The location may be changed later in the settings tab of the launcher.</p></body></html>
52 |
53 |
54 | true
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/globaldefines.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015-2016 Joshua Snyder
3 | * Distributed under the GNU GPL v3. For full terms see the file LICENSE
4 | *
5 | * This file is part of Shticker Book Rewritten.
6 | *
7 | * Shticker Book Rewritten is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Shticker Book Rewritten is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Shticker Book Rewritten. If not, see .
19 | */
20 |
21 | #ifndef GLOBALDEFINES_H
22 | #define GLOBALDEFINES_H
23 |
24 | #endif // GLOBALDEFINES_H
25 |
26 | //Platform Specific Configurations
27 | #ifdef Q_OS_LINUX
28 | #define DEFAULT_PATH QDir::homePath() + QString("/ToontownRewritten")
29 | #define PLATFORM "linux2"
30 | #define ENGINE_FILENAME QString("./TTREngine")
31 |
32 | //for windows support (64bit)
33 | #elif defined(Q_OS_WIN64)
34 | #define DEFAULT_PATH QString(QDir::currentPath()) + QString("/Game-Files")
35 | #define ENGINE_FILENAME QString("TTREngine64.exe")
36 | #define PLATFORM "win64"
37 |
38 | //for windows support (32bit)
39 | #elif defined(Q_OS_WIN)
40 | #define DEFAULT_PATH QString(QDir::currentPath()) + QString("/Game-Files")
41 | #define ENGINE_FILENAME QString("TTREngine.exe")
42 | #define PLATFORM "win32"
43 |
44 | //For OS X support (not used because no mac to compile and test on)
45 | #elif defined(Q_OS_MAC)
46 | #define DEFAULT_PATH QDir::homePath() + QString("/Library/Application Support/Toontown Rewritten")
47 | #define LIBRARY_PATH QString("./Libraries.bundle")
48 | #define ENGINE_FILENAME QString("\"./Toontown Rewritten\"")
49 | #define PLATFORM "darwin"
50 |
51 | #else
52 | #error "Unsupported platform."
53 | #endif
54 |
55 | //patch manifest URL
56 | #define PATCH_MANIFEST_URL "https://cdn.toontownrewritten.com/content/patchmanifest.txt"
57 |
58 | //content distribution URL
59 | #define CDN_URL "https://download.toontownrewritten.com/patches/"
60 |
--------------------------------------------------------------------------------
/jsonworker.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015-2016 Joshua Snyder
3 | * Distributed under the GNU GPL v3. For full terms see the file LICENSE
4 | *
5 | * This file is part of Shticker Book Rewritten.
6 | *
7 | * Shticker Book Rewritten is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Shticker Book Rewritten is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Shticker Book Rewritten. If not, see .
19 | */
20 |
21 | #include "jsonworker.h"
22 |
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | JsonWorker::JsonWorker(QObject *parent) : QObject(parent)
29 | {
30 |
31 | }
32 |
33 | //Retrieves the passed url and creates a JSON document to work with various APIs
34 | void JsonWorker::startRequest(QUrl url)
35 | {
36 | qDebug() << "Downloading file:" << url.url();
37 |
38 | networkManager = new QNetworkAccessManager(this); //Network manager to handle downloading the JSON document
39 |
40 | reply = networkManager->get(QNetworkRequest(url));
41 | connect(reply, SIGNAL(finished()), this, SLOT(requestFinished()));
42 | }
43 |
44 | //Gets called when the request finishes and creates the JSON document then emits it
45 | void JsonWorker::requestFinished()
46 | {
47 | QByteArray rawData;
48 | QJsonDocument jsonDocument;
49 | QJsonParseError *parseError = new QJsonParseError();
50 |
51 | //Check for any errors getting the file
52 | if(reply->error())
53 | {
54 | qDebug() << "Error downloading file:" << reply->errorString();
55 | }
56 | else
57 | {
58 | rawData = reply->readAll();
59 |
60 | qDebug() << "Successfully retreived file";
61 | }
62 |
63 | reply->deleteLater(); //delete file to prevent using too much ram
64 |
65 | jsonDocument = QJsonDocument::fromJson(rawData, parseError); //parse the downloaded file into a JSON array
66 |
67 | //Check for errors during parsing
68 | if(parseError->error != QJsonParseError::NoError)
69 | {
70 | qDebug() << "Error parsing JSON file:" << parseError->errorString() << endl;
71 | }
72 | else
73 | {
74 | qDebug() << "Successfully parsed JSON document\n";
75 | }
76 |
77 | emit documentReady(jsonDocument);
78 | }
79 |
--------------------------------------------------------------------------------
/jsonworker.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015-2016 Joshua Snyder
3 | * Distributed under the GNU GPL v3. For full terms see the file LICENSE
4 | *
5 | * This file is part of Shticker Book Rewritten.
6 | *
7 | * Shticker Book Rewritten is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Shticker Book Rewritten is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Shticker Book Rewritten. If not, see .
19 | */
20 |
21 | #ifndef JSONWORKER_H
22 | #define JSONWORKER_H
23 |
24 | #include
25 | #include
26 | #include
27 | #include
28 |
29 | class JsonWorker : public QObject
30 | {
31 | Q_OBJECT
32 | public:
33 | explicit JsonWorker(QObject *parent = 0);
34 | void startRequest(QUrl);
35 |
36 | signals:
37 | void documentReady(QJsonDocument);
38 |
39 | public slots:
40 |
41 | private slots:
42 | void requestFinished();
43 |
44 | private:
45 | QNetworkAccessManager *networkManager;
46 | QNetworkReply *reply;
47 | };
48 |
49 | #endif // JSONWORKER_H
50 |
--------------------------------------------------------------------------------
/launcherwindow.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015-2016 Joshua Snyder
3 | * Distributed under the GNU GPL v3. For full terms see the file LICENSE
4 | *
5 | * This file is part of Shticker Book Rewritten.
6 | *
7 | * Shticker Book Rewritten is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Shticker Book Rewritten is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Shticker Book Rewritten. If not, see .
19 | */
20 |
21 | #include "launcherwindow.h"
22 | #include "ui_launcherwindow.h"
23 | #include "globaldefines.h"
24 | #include "updateworker.h"
25 | #include "filelocationchooser.h"
26 |
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 |
35 | LauncherWindow::LauncherWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::LauncherWindow)
36 | {
37 | gameInstances = 0;
38 |
39 | ui->setupUi(this);
40 | connect(this, SIGNAL(enableUpdate(bool)), ui->updateButton, SLOT(setEnabled(bool)));
41 | connect(ui->updatesCheckBox, SIGNAL(toggled(bool)), this, SLOT(toggleAutoUpdates()));
42 | connect(ui->updateButton, SIGNAL(clicked(bool)), this, SLOT(updateFiles()));
43 |
44 | //read the previous settings
45 | readSettings();
46 |
47 | //check if the user has already chosen a file location for the game files
48 | while(filePath == "/")
49 | {
50 | setFilePath();
51 | }
52 |
53 | //setup saved toons
54 | ui->savedToonsBox->addItem("Saved logins");
55 | ui->savedToonsBox->addItems(savedUsers);
56 |
57 | connect(ui->savedToonsBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(fillCredentials(QString)));
58 |
59 | //setup the webviews
60 | ui->newsWebview->setUrl(QUrl("https://www.toontownrewritten.com/news/launcher"));
61 | ui->fishWebview->setUrl(QUrl("http://siggen.toontown-click.de/fishadvisor/en/fishes.html"));
62 | ui->invasionsWebview->setUrl(QUrl("http://toonhq.org/invasions/"));
63 | ui->groupsWebview->setUrl(QUrl("http://toonhq.org/groups/"));
64 |
65 | //change news view to a dark background since text is white
66 | connect(ui->newsWebview->page(), SIGNAL(loadFinished(bool)), this, SLOT(newsViewLoaded()));
67 |
68 | //disable login until files are updated
69 | emit enableLogin(false);
70 | loginIsReady = false;
71 |
72 | if(autoUpdate)
73 | {
74 | updateFiles();
75 | }
76 | else
77 | {
78 | loginReady();
79 | ui->progressBar->hide();
80 | }
81 | }
82 |
83 | LauncherWindow::~LauncherWindow()
84 | {
85 | delete ui;
86 | }
87 |
88 | void LauncherWindow::relayMessage(QString message)
89 | {
90 | emit sendMessage(message);
91 | }
92 |
93 | void LauncherWindow::relayProgressBarReceived(int receivedBytes)
94 | {
95 | emit sendProgressBarReceived(receivedBytes);
96 | }
97 |
98 | void LauncherWindow::relayShowProgressBar()
99 | {
100 | emit showProgressBar();
101 | }
102 |
103 | void LauncherWindow::relayHideProgressBar()
104 | {
105 | emit hideProgressBar();
106 | }
107 |
108 | void LauncherWindow::updatesReady()
109 | {
110 | if(gameInstances == 0)
111 | {
112 | emit enableUpdate(true);
113 | }
114 | }
115 |
116 | void LauncherWindow::loginReady()
117 | {
118 | emit enableLogin(true);
119 | loginIsReady = true;
120 |
121 | emit sendMessage("Logins are ready!");
122 | }
123 |
124 | void LauncherWindow::initiateLogin()
125 | {
126 | if(loginIsReady)
127 | {
128 | qDebug() << "Initiating login sequence\n";
129 |
130 | //disable login again to prevent duplicate logins
131 | emit enableLogin(false);
132 | loginIsReady = false;
133 |
134 | loginWorker = new LoginWorker(this);
135 |
136 | connect(loginWorker, SIGNAL(sendMessage(QString)), this, SLOT(relayMessage(QString)));
137 | connect(loginWorker, SIGNAL(gameStarted()), this, SLOT(gameHasStarted()));
138 | connect(loginWorker, SIGNAL(gameFinished(int, QByteArray)), this, SLOT(gameHasFinished(int, QByteArray)));
139 | connect(loginWorker, SIGNAL(authenticationFailed()), this, SLOT(authenticationFailed()));
140 |
141 | //start login and then the game
142 | loginWorker->initiateLogin(ui->usernameBox->text(), ui->passwordBox->text());
143 | }
144 | else
145 | {
146 | qDebug() << "Login isn't ready, ignoring login event\n";
147 | }
148 | }
149 |
150 | void LauncherWindow::gameHasStarted()
151 | {
152 | //disable updates while an instance is running
153 | emit enableUpdate(false);
154 |
155 | //check whether to save the credentials or not
156 | if(ui->saveCredentialsBox->isChecked())
157 | {
158 | //check to see if it already exists
159 | if(savedUsers.contains(ui->usernameBox->text()))
160 | {
161 | int i;
162 | i = savedUsers.indexOf(ui->usernameBox->text());
163 |
164 | //replace the password for this username
165 | savedPasses.replace(i, ui->passwordBox->text());
166 | }
167 | else
168 | {
169 | savedUsers.append(ui->usernameBox->text());
170 | savedPasses.append(ui->passwordBox->text());
171 |
172 | ui->savedToonsBox->addItem(ui->usernameBox->text());
173 | }
174 |
175 | //uncheck the box now
176 | ui->saveCredentialsBox->setChecked(false);
177 | writeSettings();
178 | }
179 |
180 | //clear the username and password boxes to prevent accidental relaunching of the game and to be ready to launch another
181 | ui->usernameBox->clear();
182 | ui->passwordBox->clear();
183 | ui->savedToonsBox->setCurrentIndex(0);
184 |
185 | //increment to show how many instances are running
186 | gameInstances++;
187 |
188 | qDebug() << "New game instance, there are now" << gameInstances;
189 |
190 | //enable login again now that the game has finished starting
191 | loginReady();
192 | }
193 |
194 | void LauncherWindow::gameHasFinished(int exitCode, QByteArray gameOutput)
195 | {
196 | //increment to show how many instances are running
197 | gameInstances--;
198 |
199 | qDebug() << "Game instance has closed, there are now" << gameInstances << "Exit code is:" << exitCode;
200 |
201 | if(exitCode != 0)
202 | {
203 | qDebug() << "TTR has crashed. Output from the engine is:" << gameOutput;
204 | emit sendMessage("Looks like Toontown Rewritten has crashed.");
205 |
206 | QMessageBox::warning(this, "Toontown Rewritten has crashed.",
207 | "Looks like Toontown Rewritten has crashed. The engine's error message is:\n" + gameOutput,
208 | QMessageBox::Ok);
209 | }
210 |
211 | //re-enable updates (checks to see if no other instances are running as well)
212 | updatesReady();
213 | }
214 |
215 | void LauncherWindow::authenticationFailed()
216 | {
217 | emit enableLogin(true);
218 | loginIsReady = true;
219 | }
220 |
221 | //confirm closing of the launcher to alert of closing all running games
222 | void LauncherWindow::closeEvent(QCloseEvent *event)
223 | {
224 | //check if any game instances are running
225 | if(gameInstances!=0)
226 | {
227 | //create a dialog box to confirm exit and warn about running instances
228 | QMessageBox::StandardButton dialog;
229 | dialog = QMessageBox::warning(this,
230 | "Please confirm closing.",
231 | "Are you sure you would like to close? Closing the launcher when any game instance is running will cause it to close. There are currently "
232 | + QString::number(gameInstances) + " instances running.",
233 | QMessageBox::Yes | QMessageBox::No);
234 |
235 | if( dialog == QMessageBox::Yes)
236 | {
237 | //save the current settings before quitting
238 | writeSettings();
239 | exit(0);
240 | }
241 | else
242 | {
243 | event->ignore();
244 | }
245 | }
246 |
247 | //no running instances so we can just close
248 | else
249 | {
250 | //save the current settings before quitting
251 | writeSettings();
252 |
253 | exit(0);
254 | }
255 | }
256 |
257 | void LauncherWindow::newsViewLoaded()
258 | {
259 | ui->newsWebview->page()->runJavaScript(QString("document.body.style.backgroundColor = \"#141618\";"));
260 | }
261 |
262 | void LauncherWindow::toggleAutoUpdates()
263 | {
264 | if(ui->updatesCheckBox->isChecked())
265 | {
266 | autoUpdate = true;
267 | }
268 | else
269 | {
270 | autoUpdate = false;
271 | }
272 |
273 | writeSettings();
274 | }
275 |
276 | void LauncherWindow::writeSettings()
277 | {
278 | QSettings settings("Shticker-Book-Rewritten", "Shticker-Book-Rewritten");
279 |
280 | settings.beginGroup("LauncherWindow");
281 | settings.setValue("size", size());
282 | settings.setValue("pos", pos());
283 | settings.setValue("update", autoUpdate);
284 | settings.endGroup();
285 |
286 | settings.beginGroup("Logins");
287 | settings.setValue("username", savedUsers);
288 | settings.setValue("pass", savedPasses);
289 | settings.endGroup();
290 | }
291 |
292 | void LauncherWindow::readSettings()
293 | {
294 | QSettings settings("Shticker-Book-Rewritten", "Shticker-Book-Rewritten");
295 |
296 | settings.beginGroup("LauncherWindow");
297 | resize(settings.value("size", QSize(400, 400)).toSize());
298 | move(settings.value("pos", QPoint(200, 200)).toPoint());
299 | autoUpdate = settings.value("update", true).toBool();
300 | settings.endGroup();
301 |
302 | settings.beginGroup("Logins");
303 | savedUsers = settings.value("username").toStringList();
304 | savedPasses = settings.value("pass").toStringList();
305 | settings.endGroup();
306 |
307 | if(autoUpdate)
308 | {
309 | ui->updatesCheckBox->setChecked(true);
310 | }
311 |
312 | readSettingsPath();
313 | }
314 |
315 | void LauncherWindow::readSettingsPath()
316 | {
317 | QSettings settings("Shticker-Book-Rewritten", "Shticker-Book-Rewritten");
318 |
319 | settings.beginGroup("FilesPath");
320 | filePath = settings.value("path").toString();
321 | settings.endGroup();
322 |
323 | filePath = filePath + QString("/");
324 | cachePath = filePath + QString(".cache/");
325 | }
326 |
327 | void LauncherWindow::fillCredentials(QString username)
328 | {
329 | if(username == "Saved logins")
330 | {
331 | ui->usernameBox->clear();
332 | ui->passwordBox->clear();
333 | return;
334 | }
335 |
336 | else
337 | {
338 | int i;
339 | i = savedUsers.indexOf(username);
340 |
341 | ui->usernameBox->setText(username);
342 | ui->passwordBox->setText(savedPasses.at(i));
343 | }
344 |
345 | }
346 |
347 | void LauncherWindow::updateFiles()
348 | {
349 | ui->progressBar->show();
350 |
351 | emit enableUpdate(false);
352 |
353 | //check to make sure the cache directory exists and make it if it doesn't
354 | if(!QDir(filePath).exists())
355 | {
356 | QDir().mkdir(filePath);
357 | }
358 | if(!QDir(cachePath).exists())
359 | {
360 | QDir().mkdir(cachePath);
361 | }
362 |
363 | //Begin updating the game files
364 | updateThread = new QThread(this);
365 | UpdateWorker *updateWorker = new UpdateWorker();
366 | //make a new thread for the updating process since it can bog down the main thread and make the window unresponsive
367 | updateWorker->moveToThread(updateThread);
368 |
369 | connect(updateThread, SIGNAL(started()), updateWorker, SLOT(startUpdating()));
370 | connect(updateWorker, SIGNAL(updateComplete()), updateThread, SLOT(quit()));
371 |
372 | //allow the update worker to communicate with the main window
373 | connect(updateWorker, SIGNAL(sendMessage(QString)), this, SLOT(relayMessage(QString)));
374 | connect(updateWorker, SIGNAL(sendProgressBarReceived(int)), this, SLOT(relayProgressBarReceived(int)));
375 | connect(updateWorker, SIGNAL(showProgressBar()), this, SLOT(relayShowProgressBar()));
376 | connect(updateWorker, SIGNAL(hideProgressBar()), this, SLOT(relayHideProgressBar()));
377 | connect(updateWorker, SIGNAL(updateComplete()), this, SLOT(loginReady()));
378 | connect(updateWorker, SIGNAL(updateComplete()), this, SLOT(updatesReady()));
379 |
380 | updateThread->start();
381 | }
382 |
383 | void LauncherWindow::changeFilePath()
384 | {
385 | //disable login until files are updated
386 | emit enableLogin(false);
387 | loginIsReady = false;
388 |
389 | setFilePath();
390 | updateFiles();
391 | }
392 |
393 | void LauncherWindow::setFilePath()
394 | {
395 | FileLocationChooser *chooser = new FileLocationChooser;
396 | chooser->show();
397 | chooser->activateWindow();
398 |
399 | //wait until a path is chosen
400 | QEventLoop waitForPath;
401 | connect(chooser, SIGNAL(finished()), &waitForPath, SLOT(quit()));
402 | connect(chooser, SIGNAL(rejected()), &waitForPath, SLOT(quit()));
403 | waitForPath.exec();
404 |
405 | chooser->deleteLater();
406 |
407 | readSettingsPath();
408 | }
409 |
--------------------------------------------------------------------------------
/launcherwindow.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015-2016 Joshua Snyder
3 | * Distributed under the GNU GPL v3. For full terms see the file LICENSE
4 | *
5 | * This file is part of Shticker Book Rewritten.
6 | *
7 | * Shticker Book Rewritten is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Shticker Book Rewritten is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Shticker Book Rewritten. If not, see .
19 | */
20 |
21 | #ifndef LAUNCHERWINDOW_H
22 | #define LAUNCHERWINDOW_H
23 |
24 | #include "loginworker.h"
25 |
26 | #include
27 | #include
28 | #include
29 |
30 | namespace Ui {
31 | class LauncherWindow;
32 | }
33 |
34 | class LauncherWindow : public QMainWindow
35 | {
36 | Q_OBJECT
37 |
38 | public:
39 | explicit LauncherWindow(QWidget *parent = 0);
40 | ~LauncherWindow();
41 |
42 | private slots:
43 | void relayMessage(QString);
44 | void relayProgressBarReceived(int);
45 | void relayShowProgressBar();
46 | void relayHideProgressBar();
47 | void loginReady();
48 | void initiateLogin();
49 | void gameHasStarted();
50 | void gameHasFinished(int, QByteArray);
51 | void authenticationFailed();
52 | void newsViewLoaded();
53 | void fillCredentials(QString);
54 | void changeFilePath();
55 | void updateFiles();
56 | void updatesReady();
57 | void toggleAutoUpdates();
58 |
59 | signals:
60 | void sendMessage(QString);
61 | void sendProgressBarReceived(int);
62 | void showProgressBar();
63 | void hideProgressBar();
64 | void enableLogin(bool);
65 | void enableUpdate(bool);
66 |
67 | private:
68 | Ui::LauncherWindow *ui;
69 | bool loginIsReady;
70 | LoginWorker *loginWorker;
71 | int gameInstances;
72 | QThread *updateThread;
73 | QStringList savedUsers;
74 | QStringList savedPasses;
75 | QString filePath;
76 | QString cachePath;
77 | bool autoUpdate;
78 |
79 | void readSettings();
80 | void readSettingsPath();
81 | void writeSettings();
82 | void setFilePath();
83 |
84 | protected:
85 | void closeEvent(QCloseEvent *event);
86 | };
87 |
88 | #endif // LAUNCHERWINDOW_H
89 |
--------------------------------------------------------------------------------
/launcherwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | LauncherWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 796
10 | 409
11 |
12 |
13 |
14 |
15 | 500
16 | 0
17 |
18 |
19 |
20 |
21 | 0
22 | 0
23 |
24 |
25 |
26 | Shticker Book Rewritten
27 |
28 |
29 |
30 | :/resources/icon.ico:/resources/icon.ico
31 |
32 |
33 |
34 |
35 | 0
36 |
37 |
38 | 5
39 |
40 |
41 | 0
42 |
43 |
44 | 0
45 |
46 |
47 | 0
48 |
49 | -
50 |
51 |
52 | QTabWidget::Rounded
53 |
54 |
55 | 0
56 |
57 |
58 |
59 | Launcher
60 |
61 |
62 |
63 | 0
64 |
65 |
66 | 0
67 |
68 |
69 | 0
70 |
71 |
72 | 0
73 |
74 |
-
75 |
76 |
77 | -
78 |
79 |
80 | QLayout::SetMinimumSize
81 |
82 |
83 | 0
84 |
85 |
86 | 6
87 |
88 |
-
89 |
90 |
91 | Save username and password
92 |
93 |
94 |
95 | -
96 |
97 |
98 |
99 | 0
100 | 0
101 |
102 |
103 |
104 |
105 | 300
106 | 16777215
107 |
108 |
109 |
110 | Checking for updates.
111 |
112 |
113 | true
114 |
115 |
116 |
117 | -
118 |
119 |
120 |
121 | 0
122 | 0
123 |
124 |
125 |
126 |
127 | 300
128 | 150
129 |
130 |
131 |
132 | false
133 |
134 |
135 | background-image:url(:/resources/TTR_Logo.png);background-repeat:no-repeat;
136 |
137 |
138 |
139 | -
140 |
141 |
142 | 0
143 |
144 |
145 | true
146 |
147 |
148 |
149 | -
150 |
151 |
152 | QLineEdit::Password
153 |
154 |
155 | Password
156 |
157 |
158 | true
159 |
160 |
161 |
162 | -
163 |
164 |
165 | Launch!
166 |
167 |
168 |
169 | -
170 |
171 |
172 | Username
173 |
174 |
175 | true
176 |
177 |
178 |
179 | -
180 |
181 |
182 | Qt::Vertical
183 |
184 |
185 |
186 | 20
187 | 40
188 |
189 |
190 |
191 |
192 | -
193 |
194 |
195 |
196 |
197 |
198 |
199 | -
200 |
201 |
202 | Update Game Files
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 | Group Tracker
213 |
214 |
215 |
216 | 0
217 |
218 |
219 | 0
220 |
221 |
222 | 0
223 |
224 |
225 | 0
226 |
227 |
228 | 0
229 |
230 | -
231 |
232 |
233 |
234 |
235 |
236 |
237 | Invasion Tracker
238 |
239 |
240 |
241 | 0
242 |
243 |
244 | 0
245 |
246 |
247 | 0
248 |
249 |
250 | 0
251 |
252 |
253 | 0
254 |
255 | -
256 |
257 |
258 |
259 |
260 |
261 |
262 | Fishing Guide
263 |
264 |
265 |
266 | 0
267 |
268 |
269 | 0
270 |
271 |
272 | 0
273 |
274 |
275 | 0
276 |
277 |
278 | 0
279 |
280 | -
281 |
282 |
283 |
284 |
285 |
286 |
287 | Settings
288 |
289 |
290 | -
291 |
292 |
293 | Change Game File Location
294 |
295 |
296 |
297 | -
298 |
299 |
300 | Enable Automatic Game File Updates
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 | About
309 |
310 |
311 |
312 | 0
313 |
314 |
315 | 0
316 |
317 |
318 | 0
319 |
320 |
321 | 0
322 |
323 |
324 | 0
325 |
326 | -
327 |
328 |
-
329 |
330 |
331 | false
332 |
333 |
334 | QFrame::NoFrame
335 |
336 |
337 | QFrame::Plain
338 |
339 |
340 | false
341 |
342 |
343 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
344 | <html><head><meta name="qrichtext" content="1" /><style type="text/css">
345 | p, li { white-space: pre-wrap; }
346 | </style></head><body style=" font-family:'.SF NS Text'; font-size:13pt; font-weight:400; font-style:normal;">
347 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Roboto'; font-size:9pt; font-weight:600;">About:</span></p>
348 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Roboto'; font-size:9pt;">Shticker Book Rewritten is not affiliated in any way with Toontown Rewritten. It is provided by a third party to extend functionality and provide an open base for launching their game. This program is written in the C++ programming language and makes use of the following libraries: Qt, bsdiff, and libbzip2.</span></p>
349 | <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Roboto'; font-size:9pt;"><br /></p>
350 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Roboto'; font-size:9pt; font-weight:600;">License:</span></p>
351 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Roboto'; font-size:9pt;">Copyright 2015-2016 Joshua Snyder</span></p>
352 | <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Roboto'; font-size:9pt;"><br /></p>
353 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Roboto'; font-size:9pt;">This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.</span></p>
354 | <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Roboto'; font-size:9pt;"><br /></p>
355 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Roboto'; font-size:9pt;">This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. </span></p>
356 | <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Roboto'; font-size:9pt;"><br /></p>
357 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Roboto'; font-size:9pt;">You should have received a copy of the GNU General Public License along with this program. If not, see </span><a href="http://www.gnu.org/licenses/"><span style=" font-family:'Roboto'; font-size:9pt; text-decoration: underline; color:#3daee9;">http://www.gnu.org/licenses/</span></a><span style=" font-family:'Roboto'; font-size:9pt;">.</span></p>
358 | <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Roboto'; font-size:9pt;"><br /></p>
359 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Roboto'; font-size:9pt; font-weight:600;">Source:</span></p>
360 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Roboto'; font-size:9pt;">If you have not received a copy of the source you may obtain it at: </span><a href="https://github.com/madsciencecoder/Shticker-Book-Rewritten"><span style=" font-family:'Roboto'; font-size:10pt; text-decoration: underline; color:#3daee9;">https://github.com/madsciencecoder/Shticker-Book-Rewritten</span></a><span style=" font-family:'Roboto'; font-size:9pt;">.</span></p>
361 | <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Roboto'; font-size:9pt;"><br /></p>
362 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Roboto'; font-size:9pt; font-weight:600;">Web Views:</span></p>
363 | <ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" font-family:'Roboto'; font-size:10pt;" style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Groups and Invasion tracker provided by: <a href="http://toonhq.org/"><span style=" text-decoration: underline; color:#3daee9;">http://toonhq.org/</span></a></li>
364 | <li style=" font-family:'Roboto'; font-size:10pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Fishing Guide provided by: <a href="http://siggen.toontown-click.de/fishadvisor/en/ponds.html"><span style=" text-decoration: underline; color:#3daee9;">http://siggen.toontown-click.de/fishadvisor/en/ponds.html</span></a></li></ul></body></html>
365 |
366 |
367 | Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 | QWebEngineView
384 | QWidget
385 |
386 | 1
387 |
388 |
389 |
390 | savedToonsBox
391 | usernameBox
392 | passwordBox
393 | saveCredentialsBox
394 | webviewTabWidget
395 | textEdit
396 |
397 |
398 |
399 |
400 |
401 |
402 | usernameBox
403 | returnPressed()
404 | passwordBox
405 | setFocus()
406 |
407 |
408 | 757
409 | 305
410 |
411 |
412 | 757
413 | 340
414 |
415 |
416 |
417 |
418 | LauncherWindow
419 | sendMessage(QString)
420 | statusLabel
421 | setText(QString)
422 |
423 |
424 | 388
425 | 198
426 |
427 |
428 | 622
429 | 248
430 |
431 |
432 |
433 |
434 | LauncherWindow
435 | sendProgressBarReceived(int)
436 | progressBar
437 | setValue(int)
438 |
439 |
440 | 388
441 | 198
442 |
443 |
444 | 622
445 | 273
446 |
447 |
448 |
449 |
450 | LauncherWindow
451 | hideProgressBar()
452 | progressBar
453 | hide()
454 |
455 |
456 | 388
457 | 198
458 |
459 |
460 | 622
461 | 273
462 |
463 |
464 |
465 |
466 | LauncherWindow
467 | showProgressBar()
468 | progressBar
469 | show()
470 |
471 |
472 | 388
473 | 198
474 |
475 |
476 | 622
477 | 273
478 |
479 |
480 |
481 |
482 | passwordBox
483 | returnPressed()
484 | LauncherWindow
485 | initiateLogin()
486 |
487 |
488 | 622
489 | 340
490 |
491 |
492 | 388
493 | 198
494 |
495 |
496 |
497 |
498 | filePathButton
499 | clicked()
500 | LauncherWindow
501 | changeFilePath()
502 |
503 |
504 | 397
505 | 217
506 |
507 |
508 | 397
509 | 204
510 |
511 |
512 |
513 |
514 | goButton
515 | clicked()
516 | LauncherWindow
517 | initiateLogin()
518 |
519 |
520 | 531
521 | 355
522 |
523 |
524 | 397
525 | 204
526 |
527 |
528 |
529 |
530 | LauncherWindow
531 | enableLogin(bool)
532 | goButton
533 | setEnabled(bool)
534 |
535 |
536 | 397
537 | 204
538 |
539 |
540 | 531
541 | 355
542 |
543 |
544 |
545 |
546 |
547 | sendMessage(QString)
548 | sendProgressBarReceived(int)
549 | hideProgressBar()
550 | showProgressBar()
551 | enableLogin(bool)
552 | initiateLogin()
553 | changeFilePath()
554 |
555 |
556 |
--------------------------------------------------------------------------------
/loginworker.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015-2016 Joshua Snyder
3 | * Distributed under the GNU GPL v3. For full terms see the file LICENSE
4 | *
5 | * This file is part of Shticker Book Rewritten.
6 | *
7 | * Shticker Book Rewritten is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Shticker Book Rewritten is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Shticker Book Rewritten. If not, see .
19 | */
20 |
21 | #include "loginworker.h"
22 | #include "twofactorwindow.h"
23 | #include "globaldefines.h"
24 |
25 | #include
26 | #include
27 | #include
28 | #include
29 |
30 |
31 | LoginWorker::LoginWorker(QObject *parent) : QObject(parent)
32 | {
33 | timer = new QTimer(this);
34 | timer->setSingleShot(true);
35 | connect(timer, SIGNAL(timeout()), this, SLOT(timerFinished()));
36 |
37 | QSettings settings("Shticker-Book-Rewritten", "Shticker-Book-Rewritten");
38 |
39 | settings.beginGroup("FilesPath");
40 | filePath = settings.value("path").toString();
41 | settings.endGroup();
42 | }
43 |
44 | QByteArray LoginWorker::loginApiWorker(QByteArray postData)
45 | {
46 | networkManager = new QNetworkAccessManager(this);
47 | //setup the headers for our API request
48 | QNetworkRequest request(QUrl("https://www.toontownrewritten.com/api/login?format=json"));
49 | request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
50 | request.setRawHeader("Accept", "text/plain");
51 |
52 | reply = networkManager->post(request, postData); //initiate the file download
53 | connect(reply, SIGNAL(finished()), &waitForFinished, SLOT(quit())); //when the file is finished stop the event loop
54 | waitForFinished.exec(); //start the event loop
55 |
56 | QByteArray apiReply;
57 | apiReply = reply->readAll();
58 |
59 | //schedule to erase the reply
60 | reply->deleteLater();
61 | networkManager->deleteLater();
62 |
63 | return apiReply;
64 | }
65 |
66 | void LoginWorker::initiateLogin(QString username, QString password)
67 | {
68 | //let the user know we are starting the login
69 | emit sendMessage("Sending credentials to the TTR Servers");
70 |
71 | //setup the initial POST parameters for the login API
72 | QByteArray postData;
73 | QUrlQuery postParameters;
74 | postParameters.addQueryItem("username", username);
75 | postParameters.addQueryItem("password", password);
76 | postData.append(postParameters.toString());
77 |
78 | QByteArray replyData;
79 |
80 | //send the initial login request
81 | replyData = loginApiWorker(postData);
82 |
83 | //reset the querry parameters
84 | postData.clear();
85 | postParameters.clear();
86 |
87 | parseError = new QJsonParseError(); //container to hold any errors when parsing the json document
88 |
89 | jsonDocument = QJsonDocument::fromJson(replyData, parseError); //parse the downloaded file into a JSON array
90 | jsonObject = jsonDocument.object();
91 |
92 | authenticationLoop();
93 | }
94 |
95 | void LoginWorker::authenticationLoop()
96 | {
97 | //if the login gets rejected for whatever reason
98 | if(jsonObject["success"].toString() == "false")
99 | {
100 | //display the login fail message
101 | emit sendMessage(jsonObject["banner"].toString());
102 | qDebug() << "Login failed:" << jsonObject["banner"].toString();
103 |
104 | //let the main window know it failed to enable login again
105 | emit authenticationFailed();
106 |
107 | return;
108 | }
109 | //if the login required 2 factor authentication
110 | else if(jsonObject["success"].toString() == "partial")
111 | {
112 | authToken = jsonObject["responseToken"].toString();
113 |
114 | startTwoFactorAuthentication();
115 | }
116 | else if(jsonObject["success"].toString() == "delayed")
117 | {
118 | //when it isn't quite ready to login yet check again every 0.5 seconds
119 | qDebug() << "Waiting in queue. ETA:" << jsonObject["eta"].toString() << ", Position in line:" << jsonObject["position"].toString();
120 | sendMessage(QString("Waiting in queue. ETA: ") + jsonObject["eta"].toString() + QString(", Position in line: ") + jsonObject["position"].toString());
121 |
122 | lineToken = jsonObject["queueToken"].toString();
123 |
124 | timer->start(500);
125 | }
126 | else if(jsonObject["success"].toString() == "true")
127 | {
128 | QString playCookie = jsonObject["cookie"].toString();
129 | QString gameServer = jsonObject["gameserver"].toString();
130 |
131 | qDebug() << "Authenticated fully and starting game!";
132 | qDebug() << "Play cookie:" << playCookie << "Game server:" << gameServer;
133 | emit sendMessage("Authentication complete. Starting game now.");
134 |
135 | //start the game now that we have the play cookie and server info
136 | startGame(playCookie, gameServer);
137 | }
138 | else
139 | {
140 | qDebug() << "Unable to authenticate. Error:" << jsonObject["banner"].toString();
141 | emit sendMessage(jsonObject["banner"].toString());
142 |
143 | //let the main window know it failed to enable login again
144 | emit authenticationFailed();
145 | }
146 | }
147 |
148 | void LoginWorker::receiveToken(QString token)
149 | {
150 | receivedToken = token;
151 | //stop the loop now that we have the token and allow the login worker to continue
152 | waitForFinished.exit();
153 | }
154 |
155 | void LoginWorker::startTwoFactorAuthentication()
156 | {
157 | QByteArray replyData;
158 | QByteArray postData;
159 | QUrlQuery postParameters;
160 |
161 | //run as a loop to keep requesting a valid token until one is provided or the user gives up or the API decides to kick us
162 | while(jsonObject["success"].toString() == "partial")
163 | {
164 | emit sendMessage(jsonObject["banner"].toString());
165 |
166 | qDebug() << "Partial authentication: starting 2 factor authentication.";
167 |
168 |
169 | TwoFactorWindow *twoFactorWindow = new TwoFactorWindow(jsonObject["banner"].toString());
170 | twoFactorWindow->show();
171 |
172 | connect(twoFactorWindow, SIGNAL(sendToken(QString)), this, SLOT(receiveToken(QString)));
173 |
174 | waitForFinished.exec(); //wait for the user to provide a token
175 |
176 | //if the user decides to cancel the login
177 | if(receivedToken == "cancel")
178 | {
179 | emit sendMessage("Cancelling login.");
180 | emit authenticationFailed();
181 | qDebug() << "Cancelling two factor authentication\n";
182 | return;
183 | }
184 |
185 | //send a new API request with the provided token
186 | postParameters.addQueryItem("appToken", receivedToken);
187 | postParameters.addQueryItem("authToken", authToken);
188 | postData.append(postParameters.toString());
189 |
190 | replyData = loginApiWorker(postData);
191 |
192 | //reset the querry parameters
193 | postData.clear();
194 | postParameters.clear();
195 |
196 | jsonDocument = QJsonDocument::fromJson(replyData, parseError); //parse the downloaded file into a JSON array
197 | jsonObject = jsonDocument.object();
198 | }
199 | if(jsonObject["success"].toString() != "false")
200 | {
201 | qDebug() << "Two Factor authentication complete";
202 | }
203 |
204 | //go back to the main loop now that we are authenticated
205 | authenticationLoop();
206 | }
207 |
208 | void LoginWorker::timerFinished()
209 | {
210 | qDebug() << "Queued authentication: checking where we stand in line again.";
211 |
212 | //check the login API again to see if we are ready yet
213 | QByteArray replyData;
214 | QByteArray postData;
215 | QUrlQuery postParameters;
216 |
217 | //send a new API request with our line token
218 | postParameters.addQueryItem("queueToken", lineToken);
219 | postData.append(postParameters.toString());
220 |
221 | replyData = loginApiWorker(postData);
222 |
223 | postData.clear();
224 | postParameters.clear();
225 |
226 | jsonDocument = QJsonDocument::fromJson(replyData, parseError); //parse the downloaded file into a JSON array
227 | jsonObject = jsonDocument.object();
228 |
229 | //go back to the main login loop to check where we stand in line
230 | authenticationLoop();
231 | }
232 |
233 | void LoginWorker::startGame(QString cookie, QString gameServer)
234 | {
235 | qDebug() << "Starting game!\n";
236 |
237 | gameProcess = new QProcess();
238 |
239 | gameProcess->setWorkingDirectory(filePath);
240 | QDir::setCurrent(filePath);
241 |
242 | //set the environment variables for the engine
243 | QProcessEnvironment gameEnvironment = QProcessEnvironment::systemEnvironment();
244 | gameEnvironment.insert("TTR_PLAYCOOKIE", cookie);
245 | gameEnvironment.insert("TTR_GAMESERVER", gameServer);
246 |
247 | #ifdef Q_OS_MAC
248 | gameEnvironment.insert("DYLD_LIBRARY_PATH", LIBRARY_PATH);
249 | #endif
250 |
251 | gameProcess->setProcessEnvironment(gameEnvironment);
252 |
253 | connect(gameProcess, SIGNAL(started()), this, SLOT(gameHasStarted()));
254 | connect(gameProcess, SIGNAL(finished(int)), this, SLOT(gameHasFinished(int)));
255 |
256 | //start the game
257 | gameProcess->start(ENGINE_FILENAME);
258 | gameProcess->waitForStarted(30000);
259 | }
260 |
261 | void LoginWorker::gameHasStarted()
262 | {
263 | emit gameStarted();
264 | }
265 |
266 | void LoginWorker::gameHasFinished(int exitCode)
267 | {
268 | emit gameFinished(exitCode, gameProcess->readAllStandardError());
269 | }
270 |
--------------------------------------------------------------------------------
/loginworker.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015-2016 Joshua Snyder
3 | * Distributed under the GNU GPL v3. For full terms see the file LICENSE
4 | *
5 | * This file is part of Shticker Book Rewritten.
6 | *
7 | * Shticker Book Rewritten is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Shticker Book Rewritten is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Shticker Book Rewritten. If not, see .
19 | */
20 |
21 | #ifndef LOGINWORKER_H
22 | #define LOGINWORKER_H
23 |
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 |
35 | class LoginWorker : public QObject
36 | {
37 | Q_OBJECT
38 | public:
39 | explicit LoginWorker(QObject *parent = 0);
40 |
41 | signals:
42 | void sendMessage(QString);
43 | void gameStarted();
44 | void gameFinished(int, QByteArray);
45 | void authenticationFailed();
46 |
47 | public slots:
48 | void initiateLogin(QString, QString);
49 | void receiveToken(QString);
50 | void timerFinished();
51 | void gameHasStarted();
52 | void gameHasFinished(int);
53 |
54 | private:
55 | QNetworkAccessManager *networkManager;
56 | QNetworkReply *reply;
57 | QEventLoop waitForFinished;
58 | QString receivedToken;
59 | QString authToken;
60 | QJsonDocument jsonDocument;
61 | QJsonObject jsonObject;
62 | QJsonParseError *parseError;
63 | QTimer *timer;
64 | QString lineToken;
65 | QProcess *gameProcess;
66 | QString filePath;
67 |
68 | QByteArray loginApiWorker(QByteArray);
69 | void startTwoFactorAuthentication();
70 | void authenticationLoop();
71 | void startGame(QString, QString);
72 | };
73 |
74 | #endif // LOGINWORKER_H
75 |
--------------------------------------------------------------------------------
/main.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015-2016 Joshua Snyder
3 | * Distributed under the GNU GPL v3. For full terms see the file LICENSE
4 | *
5 | * This file is part of Shticker Book Rewritten.
6 | *
7 | * Shticker Book Rewritten is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Shticker Book Rewritten is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Shticker Book Rewritten. If not, see .
19 | */
20 |
21 | #include "launcherwindow.h"
22 |
23 | #include
24 | #include
25 |
26 | int main(int argc, char *argv[])
27 | {
28 | QApplication a(argc, argv);
29 |
30 | LauncherWindow w;
31 | w.show();
32 |
33 | return a.exec();
34 | }
35 |
--------------------------------------------------------------------------------
/patchworker.cpp:
--------------------------------------------------------------------------------
1 | /*-
2 | * The following code is a derivative work of the code from bsdiff.
3 | * The original author's copyright and license is stated below.
4 | *
5 | * Copyright 2003-2005 Colin Percival
6 | * All rights reserved
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted providing that the following conditions
10 | * are met:
11 | * 1. Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * 2. Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in the
15 | * documentation and/or other materials provided with the distribution.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
21 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | * POSSIBILITY OF SUCH DAMAGE.
28 | *
29 | *__________________________________________________________________________________
30 | *
31 | * Copyright (c) 2015-2016 Joshua Snyder
32 | * Distributed under the GNU GPL v3. For full terms see the file LICENSE
33 | *
34 | * This file is part of Shticker Book Rewritten.
35 | *
36 | * Shticker Book Rewritten is free software: you can redistribute it and/or modify
37 | * it under the terms of the GNU General Public License as published by
38 | * the Free Software Foundation, either version 3 of the License, or
39 | * (at your option) any later version.
40 | *
41 | * Shticker Book Rewritten is distributed in the hope that it will be useful,
42 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
43 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 | * GNU General Public License for more details.
45 | *
46 | * You should have received a copy of the GNU General Public License
47 | * along with Shticker Book Rewritten. If not, see .
48 | */
49 |
50 | #include "patchworker.h"
51 |
52 | #include
53 |
54 | #include
55 | #include
56 | #include
57 |
58 | #ifdef Q_OS_WIN32
59 | #include "windows/fake_unistd.h"
60 | #define fseeko fseek
61 | #else
62 | #include
63 | #endif
64 |
65 |
66 | PatchWorker::PatchWorker(QObject *parent) : QObject(parent)
67 | {
68 |
69 | }
70 |
71 | int PatchWorker::patchFile(QString patchFile, QString targetFile)
72 | {
73 | //apply a temporary .tmp extension for the final patched file, will remove when finished
74 | QString newFileTemp = targetFile + ".tmp";
75 |
76 | bsdiff_patch((char *) patchFile.toStdString().c_str(), (char *) targetFile.toStdString().c_str(), (char *) newFileTemp.toStdString().c_str());
77 |
78 | //replace the old file with the patched one
79 | QFile::remove(targetFile);
80 | QFile file(newFileTemp);
81 | file.rename(targetFile);
82 |
83 | return 0;
84 | }
85 |
86 | int PatchWorker::bsdiff_patch(char *patchFile, char *oldFile, char *newFile)
87 | {
88 | FILE * f, * cpf, * dpf, * epf;
89 | BZFILE * cpfbz2, * dpfbz2, * epfbz2;
90 | int cbz2err, dbz2err, ebz2err;
91 | int fd;
92 | ssize_t oldsize,newsize;
93 | ssize_t bzctrllen,bzdatalen;
94 | u_char header[32],buf[8];
95 | u_char *old, *new_;
96 | off_t oldpos,newpos;
97 | off_t ctrl[3];
98 | off_t lenread;
99 | off_t i;
100 |
101 | /* Open patch file */
102 | if ((f = fopen(patchFile, "rb")) == NULL)
103 | {
104 | qDebug() << "Unable to open patch file.";
105 |
106 | return 1;
107 | }
108 |
109 | /*
110 | File format:
111 | 0 8 "BSDIFF40"
112 | 8 8 X
113 | 16 8 Y
114 | 24 8 sizeof(newfile)
115 | 32 X bzip2(control block)
116 | 32+X Y bzip2(diff block)
117 | 32+X+Y ??? bzip2(extra block)
118 | with control block a set of triples (x,y,z) meaning "add x bytes
119 | from oldfile to x bytes from the diff block; copy y bytes from the
120 | extra block; seek forwards in oldfile by z bytes".
121 | */
122 |
123 | /* Read header */
124 | if (fread(header, 1, 32, f) < 32)
125 | {
126 | qDebug() << "Unable to read patch file's header.";
127 |
128 | return 1;
129 | }
130 |
131 | /* Check for appropriate magic */
132 | if (memcmp(header, "BSDIFF40", 8) != 0)
133 | {
134 | qDebug() << "Unable to determine patch's version / invalid patch";
135 |
136 | return 1;
137 | }
138 |
139 | /* Read lengths from header */
140 | bzctrllen=offtin(header+8);
141 | bzdatalen=offtin(header+16);
142 | newsize=offtin(header+24);
143 | if((bzctrllen<0) || (bzdatalen<0) || (newsize<0))
144 | {
145 | qDebug() << "Unable to determine patch's size / invalid patch";
146 |
147 | return 1;
148 | }
149 |
150 | /* Close patch file and re-open it via libbzip2 at the right places */
151 | if (fclose(f))
152 | {
153 | qDebug() << "Unable to close patch file";
154 |
155 | return 1;
156 | }
157 | if ((cpf = fopen(patchFile, "rb")) == NULL)
158 | {
159 | qDebug() << "Unable to open patch file with bzip2";
160 |
161 | return 1;
162 | }
163 | if (fseeko(cpf, 32, SEEK_SET))
164 | {
165 | qDebug() << "Unable to seek to the patch data";
166 |
167 | return 1;
168 | }
169 | if ((cpfbz2 = BZ2_bzReadOpen(&cbz2err, cpf, 0, 0, NULL, 0)) == NULL)
170 | {
171 | qDebug() << "Unable to read with bzip2, bzerror =" << cbz2err;
172 |
173 | return 1;
174 | }
175 | if ((dpf = fopen(patchFile, "rb")) == NULL)
176 | {
177 | qDebug() << "Unable to open patch file with bzip2 /2";
178 |
179 | return 1;
180 | }
181 | if (fseeko(dpf, 32 + bzctrllen, SEEK_SET))
182 | {
183 | qDebug() << "Unable to seek to the patch data /2";
184 |
185 | return 1;
186 | }
187 | if ((dpfbz2 = BZ2_bzReadOpen(&dbz2err, dpf, 0, 0, NULL, 0)) == NULL)
188 | {
189 | qDebug() << "Unable to read with bzip2 /2, bzerror =" << dbz2err;
190 |
191 | return 1;
192 | }
193 | if ((epf = fopen(patchFile, "rb")) == NULL)
194 | {
195 | qDebug() << "Unable to open patch file with bzip2 /3";
196 |
197 | return 1;
198 | }
199 | if (fseeko(epf, 32 + bzctrllen + bzdatalen, SEEK_SET))
200 | {
201 | qDebug() << "Unable to seek to the patch data /3";
202 |
203 | return 1;
204 | }
205 | if ((epfbz2 = BZ2_bzReadOpen(&ebz2err, epf, 0, 0, NULL, 0)) == NULL)
206 | {
207 | qDebug() << "Unable to read with bzip2 /3, bzerror =" << ebz2err;
208 |
209 | return 1;
210 | }
211 |
212 | if(((fd=open(oldFile,OPEN_ARGS,0))<0) || ((oldsize=lseek(fd,0,SEEK_END))==-1) || ((old=(u_char*)malloc(oldsize+1))==NULL) ||
213 | (lseek(fd,0,SEEK_SET)!=0) || (read(fd,old,oldsize)!=oldsize) || (close(fd)==-1))
214 | {
215 | qDebug() << "Unable to open the old file";
216 |
217 | return 1;
218 | }
219 |
220 | if((new_=(u_char*)malloc(newsize+1))==NULL)
221 | {
222 | qDebug() << "Unable to allocate the new space";
223 |
224 | return 1;
225 | }
226 |
227 | //start the actual patching
228 | oldpos=0;newpos=0;
229 | while(newposnewsize)
245 | {
246 | qDebug() << "Corrupt patch, failed during sanity check 1";
247 |
248 | return 1;
249 | }
250 |
251 | /* Read diff string */
252 | lenread = BZ2_bzRead(&dbz2err, dpfbz2, new_ + newpos, ctrl[0]);
253 | if ((lenread < ctrl[0]) || ((dbz2err != BZ_OK) && (dbz2err != BZ_STREAM_END)))
254 | {
255 | qDebug() << "Corrupt patch, unable to read diff string";
256 |
257 | return 1;
258 | }
259 |
260 | /* Add old data to diff string */
261 | for(i=0;i=0) && (oldpos+inewsize)
275 | {
276 | qDebug() << "Corrupt patch, failed during sanity check 2";
277 |
278 | return 1;
279 | }
280 |
281 | /* Read extra string */
282 | lenread = BZ2_bzRead(&ebz2err, epfbz2, new_ + newpos, ctrl[1]);
283 | if ((lenread < ctrl[1]) || ((ebz2err != BZ_OK) && (ebz2err != BZ_STREAM_END)))
284 | {
285 | qDebug() << "Corrupt patch, unable to read extra string";
286 |
287 | return 1;
288 | }
289 |
290 | /* Adjust pointers */
291 | newpos+=ctrl[1];
292 | oldpos+=ctrl[2];
293 | };
294 |
295 | /* Clean up the bzip2 reads */
296 | BZ2_bzReadClose(&cbz2err, cpfbz2);
297 | BZ2_bzReadClose(&dbz2err, dpfbz2);
298 | BZ2_bzReadClose(&ebz2err, epfbz2);
299 |
300 | if (fclose(cpf) || fclose(dpf) || fclose(epf))
301 | {
302 | qDebug() << "Error closing patch files";
303 |
304 | return 1;
305 | }
306 |
307 | /* Write the new file */
308 | if(((fd=open(newFile,WRITE_ARGS,0666))<0) || (write(fd,new_,newsize)!=newsize) || (close(fd)==-1))
309 | {
310 | qDebug() << "Error writing patched file";
311 |
312 | return 1;
313 | }
314 |
315 | free(new_);
316 | free(old);
317 |
318 |
319 | return 0;
320 | }
321 |
322 |
323 | off_t PatchWorker::offtin(u_char *buf)
324 | {
325 | off_t y;
326 |
327 | y=buf[7]&0x7F;
328 | y=y*256;y+=buf[6];
329 | y=y*256;y+=buf[5];
330 | y=y*256;y+=buf[4];
331 | y=y*256;y+=buf[3];
332 | y=y*256;y+=buf[2];
333 | y=y*256;y+=buf[1];
334 | y=y*256;y+=buf[0];
335 |
336 | if(buf[7]&0x80) y=-y;
337 |
338 | return y;
339 | }
340 |
--------------------------------------------------------------------------------
/patchworker.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015-2016 Joshua Snyder
3 | * Distributed under the GNU GPL v3. For full terms see the file LICENSE
4 | *
5 | * This file is part of Shticker Book Rewritten.
6 | *
7 | * Shticker Book Rewritten is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Shticker Book Rewritten is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Shticker Book Rewritten. If not, see .
19 | */
20 |
21 | #ifndef PATCHWORKER_H
22 | #define PATCHWORKER_H
23 |
24 | #include
25 |
26 | //*********************************************************
27 | //need to include winsock.h to define u_char for Windows
28 | //O_BINARY must be added to the open() functions for Windows but not for Linux
29 | #include
30 | #ifdef Q_OS_WIN
31 | #include
32 | #define OPEN_ARGS O_RDONLY|O_BINARY
33 | #define WRITE_ARGS O_CREAT|O_TRUNC|O_WRONLY|O_BINARY
34 | #else
35 | #define OPEN_ARGS O_RDONLY
36 | #define WRITE_ARGS O_CREAT|O_TRUNC|O_WRONLY
37 | #endif
38 | //*********************************************************
39 |
40 | #ifdef Q_OS_MAC
41 | #include
42 | #endif
43 |
44 | class PatchWorker : public QObject
45 | {
46 | Q_OBJECT
47 | public:
48 | explicit PatchWorker(QObject *parent = 0);
49 | int patchFile(QString, QString);
50 |
51 | signals:
52 |
53 | public slots:
54 |
55 | private:
56 | off_t offtin(u_char *);
57 | int bsdiff_patch(char *, char *, char *);
58 | };
59 |
60 | #endif // PATCHWORKER_H
61 |
--------------------------------------------------------------------------------
/pictures/about-tab.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madsciencecoder/shticker-book-rewritten/a40f4fffcf3d518c3032530f34b5b1f66145aa5d/pictures/about-tab.png
--------------------------------------------------------------------------------
/pictures/fishing-tab.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madsciencecoder/shticker-book-rewritten/a40f4fffcf3d518c3032530f34b5b1f66145aa5d/pictures/fishing-tab.png
--------------------------------------------------------------------------------
/pictures/groups-tab.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madsciencecoder/shticker-book-rewritten/a40f4fffcf3d518c3032530f34b5b1f66145aa5d/pictures/groups-tab.png
--------------------------------------------------------------------------------
/pictures/invasions-tab.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madsciencecoder/shticker-book-rewritten/a40f4fffcf3d518c3032530f34b5b1f66145aa5d/pictures/invasions-tab.png
--------------------------------------------------------------------------------
/pictures/launcher-tab.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madsciencecoder/shticker-book-rewritten/a40f4fffcf3d518c3032530f34b5b1f66145aa5d/pictures/launcher-tab.png
--------------------------------------------------------------------------------
/resources.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | resources/icon.ico
4 | resources/TTR_Logo.png
5 |
6 |
7 |
--------------------------------------------------------------------------------
/resources/128x128/shticker-book-rewritten.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madsciencecoder/shticker-book-rewritten/a40f4fffcf3d518c3032530f34b5b1f66145aa5d/resources/128x128/shticker-book-rewritten.png
--------------------------------------------------------------------------------
/resources/256x256/shticker-book-rewritten.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madsciencecoder/shticker-book-rewritten/a40f4fffcf3d518c3032530f34b5b1f66145aa5d/resources/256x256/shticker-book-rewritten.png
--------------------------------------------------------------------------------
/resources/32x32/shticker-book-rewritten.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madsciencecoder/shticker-book-rewritten/a40f4fffcf3d518c3032530f34b5b1f66145aa5d/resources/32x32/shticker-book-rewritten.png
--------------------------------------------------------------------------------
/resources/64x64/shticker-book-rewritten.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madsciencecoder/shticker-book-rewritten/a40f4fffcf3d518c3032530f34b5b1f66145aa5d/resources/64x64/shticker-book-rewritten.png
--------------------------------------------------------------------------------
/resources/TTR_Logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madsciencecoder/shticker-book-rewritten/a40f4fffcf3d518c3032530f34b5b1f66145aa5d/resources/TTR_Logo.png
--------------------------------------------------------------------------------
/resources/icon.icns:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madsciencecoder/shticker-book-rewritten/a40f4fffcf3d518c3032530f34b5b1f66145aa5d/resources/icon.icns
--------------------------------------------------------------------------------
/resources/icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madsciencecoder/shticker-book-rewritten/a40f4fffcf3d518c3032530f34b5b1f66145aa5d/resources/icon.ico
--------------------------------------------------------------------------------
/shticker-book-rewritten.desktop:
--------------------------------------------------------------------------------
1 | [Desktop Entry]
2 | Type=Application
3 | Name=Shticker Book Rewritten
4 | Icon=shticker-book-rewritten
5 | Exec=shticker-book-rewritten
6 | Terminal=false
7 | Categories=Game;RolePlaying;
8 |
--------------------------------------------------------------------------------
/twofactorwindow.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015-2016 Joshua Snyder
3 | * Distributed under the GNU GPL v3. For full terms see the file LICENSE
4 | *
5 | * This file is part of Shticker Book Rewritten.
6 | *
7 | * Shticker Book Rewritten is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Shticker Book Rewritten is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Shticker Book Rewritten. If not, see .
19 | */
20 |
21 | #include "twofactorwindow.h"
22 | #include "ui_twofactorwindow.h"
23 |
24 | TwoFactorWindow::TwoFactorWindow(QString message) : QDialog(), ui(new Ui::TwoFactorWindow)
25 | {
26 | ui->setupUi(this);
27 |
28 | ui->messageLabel->setText(message);
29 | }
30 |
31 | TwoFactorWindow::~TwoFactorWindow()
32 | {
33 | delete ui;
34 | }
35 |
36 | void TwoFactorWindow::tokenReceived()
37 | {
38 | emit sendToken(ui->codeBox->text());
39 | }
40 |
41 | void TwoFactorWindow::cancel()
42 | {
43 | emit sendToken("cancel");
44 | }
45 |
--------------------------------------------------------------------------------
/twofactorwindow.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015-2016 Joshua Snyder
3 | * Distributed under the GNU GPL v3. For full terms see the file LICENSE
4 | *
5 | * This file is part of Shticker Book Rewritten.
6 | *
7 | * Shticker Book Rewritten is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Shticker Book Rewritten is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Shticker Book Rewritten. If not, see .
19 | */
20 |
21 | #ifndef TWOFACTORWINDOW_H
22 | #define TWOFACTORWINDOW_H
23 |
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 |
30 | namespace Ui {
31 | class TwoFactorWindow;
32 | }
33 |
34 | class TwoFactorWindow : public QDialog
35 | {
36 | Q_OBJECT
37 |
38 | public:
39 | explicit TwoFactorWindow(QString);
40 | ~TwoFactorWindow();
41 |
42 | signals:
43 | void sendToken(QString);
44 |
45 | protected slots:
46 | void cancel();
47 | void tokenReceived();
48 |
49 | private:
50 | QLineEdit *codeBox;
51 | QPushButton *cancelButton;
52 | QPushButton *okButton;
53 | QLabel *twoFactorMessage;
54 |
55 | Ui::TwoFactorWindow *ui;
56 | };
57 |
58 | #endif // TWOFACTORWINDOW_H
59 |
--------------------------------------------------------------------------------
/twofactorwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | TwoFactorWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 346
10 | 129
11 |
12 |
13 |
14 | Dialog
15 |
16 |
17 | -
18 |
19 |
-
20 |
21 |
22 | Qt::Vertical
23 |
24 |
25 |
26 | 20
27 | 40
28 |
29 |
30 |
31 |
32 | -
33 |
34 |
35 |
36 |
37 |
38 |
39 | -
40 |
41 |
42 |
43 |
44 | -
45 |
46 |
-
47 |
48 |
49 | OK
50 |
51 |
52 |
53 | -
54 |
55 |
56 | Cancel
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 | cancelButton
68 | clicked()
69 | TwoFactorWindow
70 | cancel()
71 |
72 |
73 | 257
74 | 106
75 |
76 |
77 | 172
78 | 64
79 |
80 |
81 |
82 |
83 | okButton
84 | clicked()
85 | TwoFactorWindow
86 | tokenReceived()
87 |
88 |
89 | 88
90 | 106
91 |
92 |
93 | 172
94 | 64
95 |
96 |
97 |
98 |
99 | codeBox
100 | returnPressed()
101 | TwoFactorWindow
102 | tokenReceived()
103 |
104 |
105 | 172
106 | 68
107 |
108 |
109 | 172
110 | 64
111 |
112 |
113 |
114 |
115 | cancelButton
116 | clicked()
117 | TwoFactorWindow
118 | close()
119 |
120 |
121 | 257
122 | 106
123 |
124 |
125 | 172
126 | 64
127 |
128 |
129 |
130 |
131 | codeBox
132 | returnPressed()
133 | TwoFactorWindow
134 | close()
135 |
136 |
137 | 172
138 | 68
139 |
140 |
141 | 172
142 | 64
143 |
144 |
145 |
146 |
147 | okButton
148 | clicked()
149 | TwoFactorWindow
150 | close()
151 |
152 |
153 | 88
154 | 106
155 |
156 |
157 | 172
158 | 64
159 |
160 |
161 |
162 |
163 |
164 | cancel()
165 | tokenReceived()
166 |
167 |
168 |
--------------------------------------------------------------------------------
/updateworker.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015-2016 Joshua Snyder
3 | * Distributed under the GNU GPL v3. For full terms see the file LICENSE
4 | *
5 | * This file is part of Shticker Book Rewritten.
6 | *
7 | * Shticker Book Rewritten is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Shticker Book Rewritten is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Shticker Book Rewritten. If not, see .
19 | */
20 |
21 | #include "updateworker.h"
22 | #include "globaldefines.h"
23 | #include "extractionworker.h"
24 | #include "downloadworker.h"
25 | #include "patchworker.h"
26 | #include "utilities.h"
27 |
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include
36 |
37 | UpdateWorker::UpdateWorker(QObject *parent) : QObject(parent)
38 | {
39 | QSettings settings("Shticker-Book-Rewritten", "Shticker-Book-Rewritten");
40 |
41 | settings.beginGroup("FilesPath");
42 | filePath = settings.value("path").toString();
43 | settings.endGroup();
44 |
45 | filePath = filePath + QString("/");
46 | cachePath = QString(filePath + ".cache/");
47 | }
48 |
49 | void UpdateWorker::startUpdating()
50 | {
51 | emit sendMessage(QString("Checking for outdated game files."));
52 |
53 | jsonWorker = new JsonWorker(this);
54 |
55 | //download the patch manifest
56 | connect(jsonWorker, SIGNAL(documentReady(QJsonDocument)), this, SLOT(patchManifestReady(QJsonDocument)));
57 | jsonWorker->startRequest(QUrl(PATCH_MANIFEST_URL));
58 | }
59 |
60 | void UpdateWorker::patchManifestReady(QJsonDocument patchManifest)
61 | {
62 | qDebug() << "Received patch manifest";
63 |
64 | //begin parsing the patch manifest
65 | QJsonObject manifestObject = patchManifest.object();
66 | QStringList fileNamesList = manifestObject.keys(); //get a list of all the filenames in the JSON file
67 | QString fileName; //used to store the filename we are working on in the following foreach loop
68 | QByteArray fileHash;
69 |
70 | //stores the file number we are working on in the foreach loop
71 | int currentFileNum = 1;
72 |
73 | //run through each filename and determine if we need to update that file
74 | foreach(fileName, fileNamesList)
75 | {
76 | QJsonObject fileObject = manifestObject[fileName].toObject(); //create an object for each file in the JSON document
77 | QJsonArray platforms = fileObject["only"].toArray(); //look for the platform the file is for
78 |
79 | emit sendMessage(QString("Updating file ") + QString::number(currentFileNum) + QString (" of ") + QString::number(fileNamesList.size()) + QString(" (") + fileName + QString(")"));
80 | qDebug() << "Checking" << fileName << "for updates";
81 |
82 | if(platforms.contains(PLATFORM))
83 | {
84 | QString localBz2FileName = cachePath + fileObject["dl"].toString();
85 | QString localFileName = filePath + fileName;
86 | QFile file(localFileName);
87 | bool fileIsOld = true;
88 | int i = 0;
89 |
90 | //loop to run until the file is fully updated or maximum of 5 times to prevent infinite loops
91 | while(fileIsOld && i<5)
92 | {
93 | i++;
94 | //check to see if the file already exists or not
95 | if(file.exists())
96 | {
97 | //generate the SHA1 hash of the file to compare with the patch manifest
98 | fileHash = getHash(localFileName);
99 | qDebug() << "Local file's hash is:" << fileHash;
100 |
101 | //Check if the hash matches the patch manifest
102 | if(fileHash == fileObject["hash"].toString())
103 | {
104 | qDebug() << "Hash matches patch manifest, skipping update\n";
105 | fileIsOld = false;
106 | }
107 | else
108 | {
109 | qDebug() << "Hash does not match patch manifest, checking for a patch";
110 |
111 | QJsonObject patchListObject = fileObject["patches"].toObject();
112 | QStringList patchList = patchListObject.keys();
113 | QString manifestHash;
114 | bool hasBeenPatched = false;
115 |
116 | foreach(manifestHash, patchList)
117 | {
118 | //check if the patch applies to our hash
119 | if(fileHash == manifestHash)
120 | {
121 | QJsonObject patchObject = patchListObject[manifestHash].toObject();
122 | PatchWorker *patchWorker = new PatchWorker(this);
123 |
124 | QString patchFileName = cachePath + patchObject["filename"].toString();
125 | QString extractedFileName = patchFileName + ".decomp";
126 |
127 | //get the patch file
128 | getNewFile(patchObject["filename"].toString(), patchFileName, extractedFileName, patchObject["compPatchHash"].toString());
129 |
130 | //verify the downloaded patch is good
131 | if(getHash(extractedFileName) == patchObject["patchHash"].toString())
132 | {
133 | qDebug() << "Downloaded patch matches manifest";
134 | }
135 | else
136 | {
137 | qDebug() << "Downloaded patch does not match manifet";
138 | }
139 |
140 | //patch the file
141 | qDebug() << "extracted name:" << extractedFileName << "old name:" << localFileName;
142 | patchWorker->patchFile(extractedFileName,localFileName);
143 | hasBeenPatched = true;
144 |
145 | //check if the patch updated the file fully
146 | if(getHash(localFileName) == fileObject["hash"].toString())
147 | {
148 | qDebug() << "File has been patched fully\n";
149 | fileIsOld = false;
150 | }
151 | else
152 | {
153 | qDebug() << "Downloaded file fails integrity check, looping again to check for patches. This is try" << i << "of 5";
154 | }
155 |
156 | //delete the patch files
157 | QFile::remove(patchFileName);
158 | QFile::remove(extractedFileName);
159 | }
160 | }
161 | //check if it was patched and if not no patch is available but still out of date so try to get a new copy
162 | if(hasBeenPatched == false)
163 | {
164 | qDebug() << "No patch found, downloading a fresh copy";
165 |
166 | getNewFile(fileObject["dl"].toString(), localBz2FileName, localFileName, fileObject["compHash"].toString());
167 |
168 | //check to make sure it is up to date
169 | fileHash = getHash(localFileName);
170 | if(fileHash == fileObject["hash"].toString())
171 | {
172 | qDebug() << "Downloaded file's integrity has been verified\n";
173 | fileIsOld = false;
174 | }
175 | else
176 | {
177 | qDebug() << "Downloaded file fails integrity check, looping again to check for patches. This is try" << i << "of 5";
178 | }
179 | }
180 | //delete the zipped file
181 | QFile::remove(localBz2FileName);
182 | }
183 | }
184 | else
185 | {
186 | //file doesn't exist, download new one
187 | getNewFile(fileObject["dl"].toString(), localBz2FileName, localFileName, fileObject["compHash"].toString());
188 |
189 | //check to make sure it is up to date
190 | fileHash = getHash(localFileName);
191 | if(fileHash == fileObject["hash"].toString())
192 | {
193 | qDebug() << "Downloaded file's integrity has been verified\n";
194 | fileIsOld = false;
195 | }
196 | else
197 | {
198 | qDebug() << "Downloaded file fails integrity check, looping again to check for patches. This is try" << i << "of 5";
199 | }
200 |
201 | //delete the zipped file
202 | QFile::remove(localBz2FileName);
203 | }
204 | }
205 | }
206 | else
207 | {
208 | qDebug() << "Skipping, it is not for our platform\n";
209 | }
210 |
211 | currentFileNum++;
212 | }
213 |
214 | emit sendMessage(QString("All files are up to date!"));
215 | emit hideProgressBar();
216 | emit updateComplete();
217 |
218 | //on Linux platforms we need to check if TTREngine is executable since it isn't by default
219 | #ifdef Q_OS_LINUX
220 | #include
221 |
222 | QFileInfo engine(QString(filePath + "TTREngine"));
223 |
224 | if(engine.isExecutable())
225 | {
226 | qDebug() << "TTREngine is already executable\n";
227 | }
228 | else
229 | {
230 | qDebug() << "TTREngine is not executable, setting it\n";
231 | QFile engineFile(QString(filePath + "TTREngine"));
232 | engineFile.setPermissions(QFile::ExeOwner | QFile::ReadUser | QFile::WriteOwner);
233 |
234 | engineFile.flush();
235 | engineFile.close();
236 | engineFile.deleteLater();
237 | }
238 | #endif
239 | }
240 |
241 | void UpdateWorker::startDownload(QString fileToDownload)
242 | {
243 | DownloadWorker *downloadWorker = new DownloadWorker(this);
244 | QString downloadFileName = cachePath + fileToDownload;
245 |
246 | qDebug() << "Downloading" << fileToDownload;
247 |
248 | connect(downloadWorker, SIGNAL(hideProgressBar()), this, SLOT(relayHideProgressBar()));
249 | connect(downloadWorker, SIGNAL(showProgressBar()), this, SLOT(relayShowProgressBar()));
250 | connect(downloadWorker, SIGNAL(sendDownloadProgress(qint64,qint64)), this, SLOT(relayDownloadProgress(qint64,qint64)));
251 |
252 | //retreive the file
253 | bool sucessfulDownload = downloadWorker->getFile(CDN_URL + fileToDownload, downloadFileName);
254 |
255 | if (sucessfulDownload)
256 | {
257 | qDebug() << "Successfully downloaded file" << downloadFileName;
258 | }
259 | else
260 | {
261 | qDebug() << "Error downloding file" << downloadFileName << endl;
262 | }
263 | }
264 |
265 | void UpdateWorker::getNewFile(QString dlFile, QString localBz2FileName, QString localFileName, QString compHash)
266 | {
267 | //get the file
268 | startDownload(dlFile);
269 |
270 | //make sure download succeeded, logging for debugging purposes but still extracting because TTR has been known to not update hashes
271 | QByteArray fileHash = getHash(localBz2FileName);
272 |
273 | if(fileHash == compHash)
274 | {
275 | qDebug() << "Integrity of" << dlFile << "is valid.";
276 | }
277 | else
278 | {
279 | qDebug() << "Failure verifying the integrity of" << dlFile;
280 | }
281 |
282 | //extract the file
283 | emit sendMessage(QString("Extracting " + dlFile));
284 | ExtractionWorker *extractionWorker = new ExtractionWorker(this);
285 |
286 | extractionWorker->extractBz2(localBz2FileName, localFileName);
287 |
288 | //delete the worker now that we are done with it
289 | extractionWorker->deleteLater();
290 | }
291 |
292 | void UpdateWorker::relayDownloadProgress(qint64 bytesReceived, qint64 totalBytes)
293 | {
294 | //convert the progress into a percentage since QProgressBar only uses an int
295 | emit sendProgressBarReceived((bytesReceived * 100) / totalBytes);
296 | }
297 |
298 | void UpdateWorker::relayHideProgressBar()
299 | {
300 | emit hideProgressBar();
301 | }
302 |
303 | void UpdateWorker::relayShowProgressBar()
304 | {
305 | emit showProgressBar();
306 | }
307 |
--------------------------------------------------------------------------------
/updateworker.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015-2016 Joshua Snyder
3 | * Distributed under the GNU GPL v3. For full terms see the file LICENSE
4 | *
5 | * This file is part of Shticker Book Rewritten.
6 | *
7 | * Shticker Book Rewritten is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Shticker Book Rewritten is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Shticker Book Rewritten. If not, see .
19 | */
20 |
21 | #ifndef UPDATEWORKER_H
22 | #define UPDATEWORKER_H
23 |
24 | #include "jsonworker.h"
25 |
26 | #include
27 | #include
28 |
29 |
30 | class UpdateWorker : public QObject
31 | {
32 | Q_OBJECT
33 | public:
34 | explicit UpdateWorker(QObject *parent = 0);
35 |
36 | signals:
37 | void sendMessage(QString);
38 | void sendProgressBarReceived(int);
39 | void hideProgressBar();
40 | void showProgressBar();
41 | void updateComplete();
42 |
43 | public slots:
44 | void startUpdating();
45 |
46 | private slots:
47 | void relayDownloadProgress(qint64, qint64);
48 | void patchManifestReady(QJsonDocument);
49 | void relayShowProgressBar();
50 | void relayHideProgressBar();
51 |
52 | private:
53 | JsonWorker *jsonWorker;
54 | QString filePath;
55 | QString cachePath;
56 |
57 | void startDownload(QString);
58 | void getNewFile(QString, QString, QString, QString);
59 | };
60 |
61 | #endif // UPDATEWORKER_H
62 |
--------------------------------------------------------------------------------
/utilities.cpp:
--------------------------------------------------------------------------------
1 | #include "utilities.h"
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | QByteArray getHash(QString fileName)
9 | {
10 | QString hashString;
11 | QFile file(fileName);
12 | QByteArray hashArray;
13 | QCryptographicHash *sha1Hash;
14 |
15 | //Attempt to open the file
16 | if(!file.open(QFile::ReadOnly))
17 | {
18 | qDebug() << "Unable to read file:" << fileName << ". Error:" << file.errorString() << "\n";
19 | }
20 | else
21 | {
22 | //Load the file's data to process
23 | QByteArray fileContents = file.readAll();
24 |
25 | hashArray = sha1Hash->hash(fileContents, QCryptographicHash::Sha1);
26 | }
27 |
28 | //clean up the file since we are done with it
29 | file.flush();
30 | file.close();
31 | file.deleteLater();
32 |
33 | //return the checksum in hexidecimal format since that is what the manifest requires
34 | return hashArray.toHex();
35 | }
36 |
--------------------------------------------------------------------------------
/utilities.h:
--------------------------------------------------------------------------------
1 | #ifndef UTILITIES_H
2 | #define UTILITIES_H
3 |
4 | #include
5 |
6 | QByteArray getHash(QString);
7 |
8 | #endif // UTILITIES_H
9 |
--------------------------------------------------------------------------------
/windows/fake_unistd.h:
--------------------------------------------------------------------------------
1 | #ifndef _UNISTD_H
2 | #define _UNISTD_H 1
3 |
4 | /* This file intended to serve as a drop-in replacement for
5 | * unistd.h on Windows
6 | * Please add functionality as neeeded
7 | */
8 |
9 | #include
10 | #include
11 | #include "getopt.h" /* getopt at: https://gist.github.com/ashelly/7776712 */
12 | #include /* for getpid() and the exec..() family */
13 | #include /* for _getcwd() and _chdir() */
14 |
15 | #define srandom srand
16 | #define random rand
17 |
18 | /* Values for the second argument to access.
19 | These may be OR'd together. */
20 | #define R_OK 4 /* Test for read permission. */
21 | #define W_OK 2 /* Test for write permission. */
22 | //#define X_OK 1 /* execute permission - unsupported in windows*/
23 | #define F_OK 0 /* Test for existence. */
24 |
25 | #define access _access
26 | #define dup2 _dup2
27 | #define execve _execve
28 | #define ftruncate _chsize
29 | #define unlink _unlink
30 | #define fileno _fileno
31 | #define getcwd _getcwd
32 | #define chdir _chdir
33 | #define isatty _isatty
34 | #define lseek _lseek
35 | /* read, write, and close are NOT being #defined here, because while there are file handle specific versions for Windows, they probably don't work for sockets. You need to look at your app and consider whether to call e.g. closesocket(). */
36 |
37 | #define ssize_t int
38 |
39 | #define STDIN_FILENO 0
40 | #define STDOUT_FILENO 1
41 | #define STDERR_FILENO 2
42 |
43 | #endif /* unistd.h */
44 |
--------------------------------------------------------------------------------
/windows/getopt.c:
--------------------------------------------------------------------------------
1 | /* Getopt for GNU.
2 | NOTE: getopt is now part of the C library, so if you don't know what
3 | "Keep this file name-space clean" means, talk to drepper@gnu.org
4 | before changing it!
5 | Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001
6 | Free Software Foundation, Inc.
7 | This file is part of the GNU C Library.
8 |
9 | The GNU C Library is free software; you can redistribute it and/or
10 | modify it under the terms of the GNU Lesser General Public
11 | License as published by the Free Software Foundation; either
12 | version 2.1 of the License, or (at your option) any later version.
13 |
14 | The GNU C Library is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 | Lesser General Public License for more details.
18 |
19 | You should have received a copy of the GNU Lesser General Public
20 | License along with the GNU C Library; if not, write to the Free
21 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 | 02111-1307 USA. */
23 |
24 | /* This tells Alpha OSF/1 not to define a getopt prototype in .
25 | Ditto for AIX 3.2 and . */
26 | #ifndef _NO_PROTO
27 | # define _NO_PROTO
28 | #endif
29 |
30 | #ifdef HAVE_CONFIG_H
31 | # include
32 | #endif
33 |
34 | #if !defined __STDC__ || !__STDC__
35 | /* This is a separate conditional since some stdc systems
36 | reject `defined (const)'. */
37 | # ifndef const
38 | # define const
39 | # endif
40 | #endif
41 |
42 | #include
43 |
44 | /* Comment out all this code if we are using the GNU C Library, and are not
45 | actually compiling the library itself. This code is part of the GNU C
46 | Library, but also included in many other GNU distributions. Compiling
47 | and linking in this code is a waste when using the GNU C library
48 | (especially if it is a shared library). Rather than having every GNU
49 | program understand `configure --with-gnu-libc' and omit the object files,
50 | it is simpler to just do this in the source for each such file. */
51 |
52 | #define GETOPT_INTERFACE_VERSION 2
53 | #if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
54 | # include
55 | # if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
56 | # define ELIDE_CODE
57 | # endif
58 | #endif
59 |
60 | #ifndef ELIDE_CODE
61 |
62 |
63 | /* This needs to come after some library #include
64 | to get __GNU_LIBRARY__ defined. */
65 | #ifdef __GNU_LIBRARY__
66 | /* Don't include stdlib.h for non-GNU C libraries because some of them
67 | contain conflicting prototypes for getopt. */
68 | # include
69 | # include
70 | #endif /* GNU C library. */
71 |
72 | #ifdef VMS
73 | # include
74 | # if HAVE_STRING_H - 0
75 | # include
76 | # endif
77 | #endif
78 |
79 | #ifndef _
80 | /* This is for other GNU distributions with internationalized messages. */
81 | # if (HAVE_LIBINTL_H && ENABLE_NLS) || defined _LIBC
82 | # include
83 | # ifndef _
84 | # define _(msgid) gettext (msgid)
85 | # endif
86 | # else
87 | # define _(msgid) (msgid)
88 | # endif
89 | # if defined _LIBC && defined USE_IN_LIBIO
90 | # include
91 | # endif
92 | #endif
93 |
94 | /* This version of `getopt' appears to the caller like standard Unix `getopt'
95 | but it behaves differently for the user, since it allows the user
96 | to intersperse the options with the other arguments.
97 |
98 | As `getopt' works, it permutes the elements of ARGV so that,
99 | when it is done, all the options precede everything else. Thus
100 | all application programs are extended to handle flexible argument order.
101 |
102 | Setting the environment variable POSIXLY_CORRECT disables permutation.
103 | Then the behavior is completely standard.
104 |
105 | GNU application programs can use a third alternative mode in which
106 | they can distinguish the relative order of options and other arguments. */
107 |
108 | #include "getopt.h"
109 |
110 | /* For communication from `getopt' to the caller.
111 | When `getopt' finds an option that takes an argument,
112 | the argument value is returned here.
113 | Also, when `ordering' is RETURN_IN_ORDER,
114 | each non-option ARGV-element is returned here. */
115 |
116 | char *optarg;
117 |
118 | /* Index in ARGV of the next element to be scanned.
119 | This is used for communication to and from the caller
120 | and for communication between successive calls to `getopt'.
121 |
122 | On entry to `getopt', zero means this is the first call; initialize.
123 |
124 | When `getopt' returns -1, this is the index of the first of the
125 | non-option elements that the caller should itself scan.
126 |
127 | Otherwise, `optind' communicates from one call to the next
128 | how much of ARGV has been scanned so far. */
129 |
130 | /* 1003.2 says this must be 1 before any call. */
131 | int optind = 1;
132 |
133 | /* Formerly, initialization of getopt depended on optind==0, which
134 | causes problems with re-calling getopt as programs generally don't
135 | know that. */
136 |
137 | int __getopt_initialized;
138 |
139 | /* The next char to be scanned in the option-element
140 | in which the last option character we returned was found.
141 | This allows us to pick up the scan where we left off.
142 |
143 | If this is zero, or a null string, it means resume the scan
144 | by advancing to the next ARGV-element. */
145 |
146 | static char *nextchar;
147 |
148 | /* Callers store zero here to inhibit the error message
149 | for unrecognized options. */
150 |
151 | int opterr = 1;
152 |
153 | /* Set to an option character which was unrecognized.
154 | This must be initialized on some systems to avoid linking in the
155 | system's own getopt implementation. */
156 |
157 | int optopt = '?';
158 |
159 | /* Describe how to deal with options that follow non-option ARGV-elements.
160 |
161 | If the caller did not specify anything,
162 | the default is REQUIRE_ORDER if the environment variable
163 | POSIXLY_CORRECT is defined, PERMUTE otherwise.
164 |
165 | REQUIRE_ORDER means don't recognize them as options;
166 | stop option processing when the first non-option is seen.
167 | This is what Unix does.
168 | This mode of operation is selected by either setting the environment
169 | variable POSIXLY_CORRECT, or using `+' as the first character
170 | of the list of option characters.
171 |
172 | PERMUTE is the default. We permute the contents of ARGV as we scan,
173 | so that eventually all the non-options are at the end. This allows options
174 | to be given in any order, even with programs that were not written to
175 | expect this.
176 |
177 | RETURN_IN_ORDER is an option available to programs that were written
178 | to expect options and other ARGV-elements in any order and that care about
179 | the ordering of the two. We describe each non-option ARGV-element
180 | as if it were the argument of an option with character code 1.
181 | Using `-' as the first character of the list of option characters
182 | selects this mode of operation.
183 |
184 | The special argument `--' forces an end of option-scanning regardless
185 | of the value of `ordering'. In the case of RETURN_IN_ORDER, only
186 | `--' can cause `getopt' to return -1 with `optind' != ARGC. */
187 |
188 | static enum
189 | {
190 | REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
191 | } ordering;
192 |
193 | /* Value of POSIXLY_CORRECT environment variable. */
194 | static char *posixly_correct;
195 |
196 | #ifdef __GNU_LIBRARY__
197 | /* We want to avoid inclusion of string.h with non-GNU libraries
198 | because there are many ways it can cause trouble.
199 | On some systems, it contains special magic macros that don't work
200 | in GCC. */
201 | # include
202 | # define my_index strchr
203 | #else
204 |
205 | # if HAVE_STRING_H || WIN32 /* Pete Wilson mod 7/28/02 */
206 | # include
207 | # else
208 | # include
209 | # endif
210 |
211 | /* Avoid depending on library functions or files
212 | whose names are inconsistent. */
213 |
214 | #ifndef getenv
215 | extern char *getenv ();
216 | #endif
217 |
218 | static char *
219 | my_index (str, chr)
220 | const char *str;
221 | int chr;
222 | {
223 | while (*str)
224 | {
225 | if (*str == chr)
226 | return (char *) str;
227 | str++;
228 | }
229 | return 0;
230 | }
231 |
232 | /* If using GCC, we can safely declare strlen this way.
233 | If not using GCC, it is ok not to declare it. */
234 | #ifdef __GNUC__
235 | /* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h.
236 | That was relevant to code that was here before. */
237 | # if (!defined __STDC__ || !__STDC__) && !defined strlen
238 | /* gcc with -traditional declares the built-in strlen to return int,
239 | and has done so at least since version 2.4.5. -- rms. */
240 | extern int strlen (const char *);
241 | # endif /* not __STDC__ */
242 | #endif /* __GNUC__ */
243 |
244 | #endif /* not __GNU_LIBRARY__ */
245 |
246 | /* Handle permutation of arguments. */
247 |
248 | /* Describe the part of ARGV that contains non-options that have
249 | been skipped. `first_nonopt' is the index in ARGV of the first of them;
250 | `last_nonopt' is the index after the last of them. */
251 |
252 | static int first_nonopt;
253 | static int last_nonopt;
254 |
255 | #ifdef _LIBC
256 | /* Stored original parameters.
257 | XXX This is no good solution. We should rather copy the args so
258 | that we can compare them later. But we must not use malloc(3). */
259 | extern int __libc_argc;
260 | extern char **__libc_argv;
261 |
262 | /* Bash 2.0 gives us an environment variable containing flags
263 | indicating ARGV elements that should not be considered arguments. */
264 |
265 | # ifdef USE_NONOPTION_FLAGS
266 | /* Defined in getopt_init.c */
267 | extern char *__getopt_nonoption_flags;
268 |
269 | static int nonoption_flags_max_len;
270 | static int nonoption_flags_len;
271 | # endif
272 |
273 | # ifdef USE_NONOPTION_FLAGS
274 | # define SWAP_FLAGS(ch1, ch2) \
275 | if (nonoption_flags_len > 0) \
276 | { \
277 | char __tmp = __getopt_nonoption_flags[ch1]; \
278 | __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \
279 | __getopt_nonoption_flags[ch2] = __tmp; \
280 | }
281 | # else
282 | # define SWAP_FLAGS(ch1, ch2)
283 | # endif
284 | #else /* !_LIBC */
285 | # define SWAP_FLAGS(ch1, ch2)
286 | #endif /* _LIBC */
287 |
288 | /* Exchange two adjacent subsequences of ARGV.
289 | One subsequence is elements [first_nonopt,last_nonopt)
290 | which contains all the non-options that have been skipped so far.
291 | The other is elements [last_nonopt,optind), which contains all
292 | the options processed since those non-options were skipped.
293 |
294 | `first_nonopt' and `last_nonopt' are relocated so that they describe
295 | the new indices of the non-options in ARGV after they are moved. */
296 |
297 | #if defined __STDC__ && __STDC__
298 | static void exchange (char **);
299 | #endif
300 |
301 | static void
302 | exchange (argv)
303 | char **argv;
304 | {
305 | int bottom = first_nonopt;
306 | int middle = last_nonopt;
307 | int top = optind;
308 | char *tem;
309 |
310 | /* Exchange the shorter segment with the far end of the longer segment.
311 | That puts the shorter segment into the right place.
312 | It leaves the longer segment in the right place overall,
313 | but it consists of two parts that need to be swapped next. */
314 |
315 | #if defined _LIBC && defined USE_NONOPTION_FLAGS
316 | /* First make sure the handling of the `__getopt_nonoption_flags'
317 | string can work normally. Our top argument must be in the range
318 | of the string. */
319 | if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len)
320 | {
321 | /* We must extend the array. The user plays games with us and
322 | presents new arguments. */
323 | char *new_str = malloc (top + 1);
324 | if (new_str == NULL)
325 | nonoption_flags_len = nonoption_flags_max_len = 0;
326 | else
327 | {
328 | memset (__mempcpy (new_str, __getopt_nonoption_flags,
329 | nonoption_flags_max_len),
330 | '\0', top + 1 - nonoption_flags_max_len);
331 | nonoption_flags_max_len = top + 1;
332 | __getopt_nonoption_flags = new_str;
333 | }
334 | }
335 | #endif
336 |
337 | while (top > middle && middle > bottom)
338 | {
339 | if (top - middle > middle - bottom)
340 | {
341 | /* Bottom segment is the short one. */
342 | int len = middle - bottom;
343 | register int i;
344 |
345 | /* Swap it with the top part of the top segment. */
346 | for (i = 0; i < len; i++)
347 | {
348 | tem = argv[bottom + i];
349 | argv[bottom + i] = argv[top - (middle - bottom) + i];
350 | argv[top - (middle - bottom) + i] = tem;
351 | SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
352 | }
353 | /* Exclude the moved bottom segment from further swapping. */
354 | top -= len;
355 | }
356 | else
357 | {
358 | /* Top segment is the short one. */
359 | int len = top - middle;
360 | register int i;
361 |
362 | /* Swap it with the bottom part of the bottom segment. */
363 | for (i = 0; i < len; i++)
364 | {
365 | tem = argv[bottom + i];
366 | argv[bottom + i] = argv[middle + i];
367 | argv[middle + i] = tem;
368 | SWAP_FLAGS (bottom + i, middle + i);
369 | }
370 | /* Exclude the moved top segment from further swapping. */
371 | bottom += len;
372 | }
373 | }
374 |
375 | /* Update records for the slots the non-options now occupy. */
376 |
377 | first_nonopt += (optind - last_nonopt);
378 | last_nonopt = optind;
379 | }
380 |
381 | /* Initialize the internal data when the first call is made. */
382 |
383 | #if defined __STDC__ && __STDC__
384 | static const char *_getopt_initialize (int, char *const *, const char *);
385 | #endif
386 | static const char *
387 | _getopt_initialize (argc, argv, optstring)
388 | int argc;
389 | char *const *argv;
390 | const char *optstring;
391 | {
392 | /* Start processing options with ARGV-element 1 (since ARGV-element 0
393 | is the program name); the sequence of previously skipped
394 | non-option ARGV-elements is empty. */
395 |
396 | first_nonopt = last_nonopt = optind;
397 |
398 | nextchar = NULL;
399 |
400 | posixly_correct = getenv ("POSIXLY_CORRECT");
401 |
402 | /* Determine how to handle the ordering of options and nonoptions. */
403 |
404 | if (optstring[0] == '-')
405 | {
406 | ordering = RETURN_IN_ORDER;
407 | ++optstring;
408 | }
409 | else if (optstring[0] == '+')
410 | {
411 | ordering = REQUIRE_ORDER;
412 | ++optstring;
413 | }
414 | else if (posixly_correct != NULL)
415 | ordering = REQUIRE_ORDER;
416 | else
417 | ordering = PERMUTE;
418 |
419 | #if defined _LIBC && defined USE_NONOPTION_FLAGS
420 | if (posixly_correct == NULL
421 | && argc == __libc_argc && argv == __libc_argv)
422 | {
423 | if (nonoption_flags_max_len == 0)
424 | {
425 | if (__getopt_nonoption_flags == NULL
426 | || __getopt_nonoption_flags[0] == '\0')
427 | nonoption_flags_max_len = -1;
428 | else
429 | {
430 | const char *orig_str = __getopt_nonoption_flags;
431 | int len = nonoption_flags_max_len = strlen (orig_str);
432 | if (nonoption_flags_max_len < argc)
433 | nonoption_flags_max_len = argc;
434 | __getopt_nonoption_flags =
435 | (char *) malloc (nonoption_flags_max_len);
436 | if (__getopt_nonoption_flags == NULL)
437 | nonoption_flags_max_len = -1;
438 | else
439 | memset (__mempcpy (__getopt_nonoption_flags, orig_str, len),
440 | '\0', nonoption_flags_max_len - len);
441 | }
442 | }
443 | nonoption_flags_len = nonoption_flags_max_len;
444 | }
445 | else
446 | nonoption_flags_len = 0;
447 | #endif
448 |
449 | return optstring;
450 | }
451 |
452 | /* Scan elements of ARGV (whose length is ARGC) for option characters
453 | given in OPTSTRING.
454 |
455 | If an element of ARGV starts with '-', and is not exactly "-" or "--",
456 | then it is an option element. The characters of this element
457 | (aside from the initial '-') are option characters. If `getopt'
458 | is called repeatedly, it returns successively each of the option characters
459 | from each of the option elements.
460 |
461 | If `getopt' finds another option character, it returns that character,
462 | updating `optind' and `nextchar' so that the next call to `getopt' can
463 | resume the scan with the following option character or ARGV-element.
464 |
465 | If there are no more option characters, `getopt' returns -1.
466 | Then `optind' is the index in ARGV of the first ARGV-element
467 | that is not an option. (The ARGV-elements have been permuted
468 | so that those that are not options now come last.)
469 |
470 | OPTSTRING is a string containing the legitimate option characters.
471 | If an option character is seen that is not listed in OPTSTRING,
472 | return '?' after printing an error message. If you set `opterr' to
473 | zero, the error message is suppressed but we still return '?'.
474 |
475 | If a char in OPTSTRING is followed by a colon, that means it wants an arg,
476 | so the following text in the same ARGV-element, or the text of the following
477 | ARGV-element, is returned in `optarg'. Two colons mean an option that
478 | wants an optional arg; if there is text in the current ARGV-element,
479 | it is returned in `optarg', otherwise `optarg' is set to zero.
480 |
481 | If OPTSTRING starts with `-' or `+', it requests different methods of
482 | handling the non-option ARGV-elements.
483 | See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
484 |
485 | Long-named options begin with `--' instead of `-'.
486 | Their names may be abbreviated as long as the abbreviation is unique
487 | or is an exact match for some defined option. If they have an
488 | argument, it follows the option name in the same ARGV-element, separated
489 | from the option name by a `=', or else the in next ARGV-element.
490 | When `getopt' finds a long-named option, it returns 0 if that option's
491 | `flag' field is nonzero, the value of the option's `val' field
492 | if the `flag' field is zero.
493 |
494 | The elements of ARGV aren't really const, because we permute them.
495 | But we pretend they're const in the prototype to be compatible
496 | with other systems.
497 |
498 | LONGOPTS is a vector of `struct option' terminated by an
499 | element containing a name which is zero.
500 |
501 | LONGIND returns the index in LONGOPT of the long-named option found.
502 | It is only valid when a long-named option has been found by the most
503 | recent call.
504 |
505 | If LONG_ONLY is nonzero, '-' as well as '--' can introduce
506 | long-named options. */
507 |
508 | int
509 | _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
510 | int argc;
511 | char *const *argv;
512 | const char *optstring;
513 | const struct option *longopts;
514 | int *longind;
515 | int long_only;
516 | {
517 | int print_errors = opterr;
518 | if (optstring[0] == ':')
519 | print_errors = 0;
520 |
521 | if (argc < 1)
522 | return -1;
523 |
524 | optarg = NULL;
525 |
526 | if (optind == 0 || !__getopt_initialized)
527 | {
528 | if (optind == 0)
529 | optind = 1; /* Don't scan ARGV[0], the program name. */
530 | optstring = _getopt_initialize (argc, argv, optstring);
531 | __getopt_initialized = 1;
532 | }
533 |
534 | /* Test whether ARGV[optind] points to a non-option argument.
535 | Either it does not have option syntax, or there is an environment flag
536 | from the shell indicating it is not an option. The later information
537 | is only used when the used in the GNU libc. */
538 | #if defined _LIBC && defined USE_NONOPTION_FLAGS
539 | # define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \
540 | || (optind < nonoption_flags_len \
541 | && __getopt_nonoption_flags[optind] == '1'))
542 | #else
543 | # define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0')
544 | #endif
545 |
546 | if (nextchar == NULL || *nextchar == '\0')
547 | {
548 | /* Advance to the next ARGV-element. */
549 |
550 | /* Give FIRST_NONOPT and LAST_NONOPT rational values if OPTIND has been
551 | moved back by the user (who may also have changed the arguments). */
552 | if (last_nonopt > optind)
553 | last_nonopt = optind;
554 | if (first_nonopt > optind)
555 | first_nonopt = optind;
556 |
557 | if (ordering == PERMUTE)
558 | {
559 | /* If we have just processed some options following some non-options,
560 | exchange them so that the options come first. */
561 |
562 | if (first_nonopt != last_nonopt && last_nonopt != optind)
563 | exchange ((char **) argv);
564 | else if (last_nonopt != optind)
565 | first_nonopt = optind;
566 |
567 | /* Skip any additional non-options
568 | and extend the range of non-options previously skipped. */
569 |
570 | while (optind < argc && NONOPTION_P)
571 | optind++;
572 | last_nonopt = optind;
573 | }
574 |
575 | /* The special ARGV-element `--' means premature end of options.
576 | Skip it like a null option,
577 | then exchange with previous non-options as if it were an option,
578 | then skip everything else like a non-option. */
579 |
580 | if (optind != argc && !strcmp (argv[optind], "--"))
581 | {
582 | optind++;
583 |
584 | if (first_nonopt != last_nonopt && last_nonopt != optind)
585 | exchange ((char **) argv);
586 | else if (first_nonopt == last_nonopt)
587 | first_nonopt = optind;
588 | last_nonopt = argc;
589 |
590 | optind = argc;
591 | }
592 |
593 | /* If we have done all the ARGV-elements, stop the scan
594 | and back over any non-options that we skipped and permuted. */
595 |
596 | if (optind == argc)
597 | {
598 | /* Set the next-arg-index to point at the non-options
599 | that we previously skipped, so the caller will digest them. */
600 | if (first_nonopt != last_nonopt)
601 | optind = first_nonopt;
602 | return -1;
603 | }
604 |
605 | /* If we have come to a non-option and did not permute it,
606 | either stop the scan or describe it to the caller and pass it by. */
607 |
608 | if (NONOPTION_P)
609 | {
610 | if (ordering == REQUIRE_ORDER)
611 | return -1;
612 | optarg = argv[optind++];
613 | return 1;
614 | }
615 |
616 | /* We have found another option-ARGV-element.
617 | Skip the initial punctuation. */
618 |
619 | nextchar = (argv[optind] + 1
620 | + (longopts != NULL && argv[optind][1] == '-'));
621 | }
622 |
623 | /* Decode the current option-ARGV-element. */
624 |
625 | /* Check whether the ARGV-element is a long option.
626 |
627 | If long_only and the ARGV-element has the form "-f", where f is
628 | a valid short option, don't consider it an abbreviated form of
629 | a long option that starts with f. Otherwise there would be no
630 | way to give the -f short option.
631 |
632 | On the other hand, if there's a long option "fubar" and
633 | the ARGV-element is "-fu", do consider that an abbreviation of
634 | the long option, just like "--fu", and not "-f" with arg "u".
635 |
636 | This distinction seems to be the most useful approach. */
637 |
638 | if (longopts != NULL
639 | && (argv[optind][1] == '-'
640 | || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1])))))
641 | {
642 | char *nameend;
643 | const struct option *p;
644 | const struct option *pfound = NULL;
645 | int exact = 0;
646 | int ambig = 0;
647 | int indfound = -1;
648 | int option_index;
649 |
650 | for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
651 | /* Do nothing. */ ;
652 |
653 | /* Test all long options for either exact match
654 | or abbreviated matches. */
655 | for (p = longopts, option_index = 0; p->name; p++, option_index++)
656 | if (!strncmp (p->name, nextchar, nameend - nextchar))
657 | {
658 | if ((unsigned int) (nameend - nextchar)
659 | == (unsigned int) strlen (p->name))
660 | {
661 | /* Exact match found. */
662 | pfound = p;
663 | indfound = option_index;
664 | exact = 1;
665 | break;
666 | }
667 | else if (pfound == NULL)
668 | {
669 | /* First nonexact match found. */
670 | pfound = p;
671 | indfound = option_index;
672 | }
673 | else if (long_only
674 | || pfound->has_arg != p->has_arg
675 | || pfound->flag != p->flag
676 | || pfound->val != p->val)
677 | /* Second or later nonexact match found. */
678 | ambig = 1;
679 | }
680 |
681 | if (ambig && !exact)
682 | {
683 | if (print_errors)
684 | {
685 | #if defined _LIBC && defined USE_IN_LIBIO
686 | char *buf;
687 |
688 | __asprintf (&buf, _("%s: option `%s' is ambiguous\n"),
689 | argv[0], argv[optind]);
690 |
691 | if (_IO_fwide (stderr, 0) > 0)
692 | __fwprintf (stderr, L"%s", buf);
693 | else
694 | fputs (buf, stderr);
695 |
696 | free (buf);
697 | #else
698 | fprintf (stderr, _("%s: option `%s' is ambiguous\n"),
699 | argv[0], argv[optind]);
700 | #endif
701 | }
702 | nextchar += strlen (nextchar);
703 | optind++;
704 | optopt = 0;
705 | return '?';
706 | }
707 |
708 | if (pfound != NULL)
709 | {
710 | option_index = indfound;
711 | optind++;
712 | if (*nameend)
713 | {
714 | /* Don't test has_arg with >, because some C compilers don't
715 | allow it to be used on enums. */
716 | if (pfound->has_arg)
717 | optarg = nameend + 1;
718 | else
719 | {
720 | if (print_errors)
721 | {
722 | #if defined _LIBC && defined USE_IN_LIBIO
723 | char *buf;
724 | #endif
725 |
726 | if (argv[optind - 1][1] == '-')
727 | {
728 | /* --option */
729 | #if defined _LIBC && defined USE_IN_LIBIO
730 | __asprintf (&buf, _("\
731 | %s: option `--%s' doesn't allow an argument\n"),
732 | argv[0], pfound->name);
733 | #else
734 | fprintf (stderr, _("\
735 | %s: option `--%s' doesn't allow an argument\n"),
736 | argv[0], pfound->name);
737 | #endif
738 | }
739 | else
740 | {
741 | /* +option or -option */
742 | #if defined _LIBC && defined USE_IN_LIBIO
743 | __asprintf (&buf, _("\
744 | %s: option `%c%s' doesn't allow an argument\n"),
745 | argv[0], argv[optind - 1][0],
746 | pfound->name);
747 | #else
748 | fprintf (stderr, _("\
749 | %s: option `%c%s' doesn't allow an argument\n"),
750 | argv[0], argv[optind - 1][0], pfound->name);
751 | #endif
752 | }
753 |
754 | #if defined _LIBC && defined USE_IN_LIBIO
755 | if (_IO_fwide (stderr, 0) > 0)
756 | __fwprintf (stderr, L"%s", buf);
757 | else
758 | fputs (buf, stderr);
759 |
760 | free (buf);
761 | #endif
762 | }
763 |
764 | nextchar += strlen (nextchar);
765 |
766 | optopt = pfound->val;
767 | return '?';
768 | }
769 | }
770 | else if (pfound->has_arg == 1)
771 | {
772 | if (optind < argc)
773 | optarg = argv[optind++];
774 | else
775 | {
776 | if (print_errors)
777 | {
778 | #if defined _LIBC && defined USE_IN_LIBIO
779 | char *buf;
780 |
781 | __asprintf (&buf,
782 | _("%s: option `%s' requires an argument\n"),
783 | argv[0], argv[optind - 1]);
784 |
785 | if (_IO_fwide (stderr, 0) > 0)
786 | __fwprintf (stderr, L"%s", buf);
787 | else
788 | fputs (buf, stderr);
789 |
790 | free (buf);
791 | #else
792 | fprintf (stderr,
793 | _("%s: option `%s' requires an argument\n"),
794 | argv[0], argv[optind - 1]);
795 | #endif
796 | }
797 | nextchar += strlen (nextchar);
798 | optopt = pfound->val;
799 | return optstring[0] == ':' ? ':' : '?';
800 | }
801 | }
802 | nextchar += strlen (nextchar);
803 | if (longind != NULL)
804 | *longind = option_index;
805 | if (pfound->flag)
806 | {
807 | *(pfound->flag) = pfound->val;
808 | return 0;
809 | }
810 | return pfound->val;
811 | }
812 |
813 | /* Can't find it as a long option. If this is not getopt_long_only,
814 | or the option starts with '--' or is not a valid short
815 | option, then it's an error.
816 | Otherwise interpret it as a short option. */
817 | if (!long_only || argv[optind][1] == '-'
818 | || my_index (optstring, *nextchar) == NULL)
819 | {
820 | if (print_errors)
821 | {
822 | #if defined _LIBC && defined USE_IN_LIBIO
823 | char *buf;
824 | #endif
825 |
826 | if (argv[optind][1] == '-')
827 | {
828 | /* --option */
829 | #if defined _LIBC && defined USE_IN_LIBIO
830 | __asprintf (&buf, _("%s: unrecognized option `--%s'\n"),
831 | argv[0], nextchar);
832 | #else
833 | fprintf (stderr, _("%s: unrecognized option `--%s'\n"),
834 | argv[0], nextchar);
835 | #endif
836 | }
837 | else
838 | {
839 | /* +option or -option */
840 | #if defined _LIBC && defined USE_IN_LIBIO
841 | __asprintf (&buf, _("%s: unrecognized option `%c%s'\n"),
842 | argv[0], argv[optind][0], nextchar);
843 | #else
844 | fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),
845 | argv[0], argv[optind][0], nextchar);
846 | #endif
847 | }
848 |
849 | #if defined _LIBC && defined USE_IN_LIBIO
850 | if (_IO_fwide (stderr, 0) > 0)
851 | __fwprintf (stderr, L"%s", buf);
852 | else
853 | fputs (buf, stderr);
854 |
855 | free (buf);
856 | #endif
857 | }
858 | nextchar = (char *) "";
859 | optind++;
860 | optopt = 0;
861 | return '?';
862 | }
863 | }
864 |
865 | /* Look at and handle the next short option-character. */
866 |
867 | {
868 | char c = *nextchar++;
869 | char *temp = my_index (optstring, c);
870 |
871 | /* Increment `optind' when we start to process its last character. */
872 | if (*nextchar == '\0')
873 | ++optind;
874 |
875 | if (temp == NULL || c == ':')
876 | {
877 | if (print_errors)
878 | {
879 | #if defined _LIBC && defined USE_IN_LIBIO
880 | char *buf;
881 | #endif
882 |
883 | if (posixly_correct)
884 | {
885 | /* 1003.2 specifies the format of this message. */
886 | #if defined _LIBC && defined USE_IN_LIBIO
887 | __asprintf (&buf, _("%s: illegal option -- %c\n"),
888 | argv[0], c);
889 | #else
890 | fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c);
891 | #endif
892 | }
893 | else
894 | {
895 | #if defined _LIBC && defined USE_IN_LIBIO
896 | __asprintf (&buf, _("%s: invalid option -- %c\n"),
897 | argv[0], c);
898 | #else
899 | fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c);
900 | #endif
901 | }
902 |
903 | #if defined _LIBC && defined USE_IN_LIBIO
904 | if (_IO_fwide (stderr, 0) > 0)
905 | __fwprintf (stderr, L"%s", buf);
906 | else
907 | fputs (buf, stderr);
908 |
909 | free (buf);
910 | #endif
911 | }
912 | optopt = c;
913 | return '?';
914 | }
915 | /* Convenience. Treat POSIX -W foo same as long option --foo */
916 | if (temp[0] == 'W' && temp[1] == ';')
917 | {
918 | char *nameend;
919 | const struct option *p;
920 | const struct option *pfound = NULL;
921 | int exact = 0;
922 | int ambig = 0;
923 | int indfound = 0;
924 | int option_index;
925 |
926 | /* This is an option that requires an argument. */
927 | if (*nextchar != '\0')
928 | {
929 | optarg = nextchar;
930 | /* If we end this ARGV-element by taking the rest as an arg,
931 | we must advance to the next element now. */
932 | optind++;
933 | }
934 | else if (optind == argc)
935 | {
936 | if (print_errors)
937 | {
938 | /* 1003.2 specifies the format of this message. */
939 | #if defined _LIBC && defined USE_IN_LIBIO
940 | char *buf;
941 |
942 | __asprintf (&buf, _("%s: option requires an argument -- %c\n"),
943 | argv[0], c);
944 |
945 | if (_IO_fwide (stderr, 0) > 0)
946 | __fwprintf (stderr, L"%s", buf);
947 | else
948 | fputs (buf, stderr);
949 |
950 | free (buf);
951 | #else
952 | fprintf (stderr, _("%s: option requires an argument -- %c\n"),
953 | argv[0], c);
954 | #endif
955 | }
956 | optopt = c;
957 | if (optstring[0] == ':')
958 | c = ':';
959 | else
960 | c = '?';
961 | return c;
962 | }
963 | else
964 | /* We already incremented `optind' once;
965 | increment it again when taking next ARGV-elt as argument. */
966 | optarg = argv[optind++];
967 |
968 | /* optarg is now the argument, see if it's in the
969 | table of longopts. */
970 |
971 | for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++)
972 | /* Do nothing. */ ;
973 |
974 | /* Test all long options for either exact match
975 | or abbreviated matches. */
976 | for (p = longopts, option_index = 0; p->name; p++, option_index++)
977 | if (!strncmp (p->name, nextchar, nameend - nextchar))
978 | {
979 | if ((unsigned int) (nameend - nextchar) == strlen (p->name))
980 | {
981 | /* Exact match found. */
982 | pfound = p;
983 | indfound = option_index;
984 | exact = 1;
985 | break;
986 | }
987 | else if (pfound == NULL)
988 | {
989 | /* First nonexact match found. */
990 | pfound = p;
991 | indfound = option_index;
992 | }
993 | else
994 | /* Second or later nonexact match found. */
995 | ambig = 1;
996 | }
997 | if (ambig && !exact)
998 | {
999 | if (print_errors)
1000 | {
1001 | #if defined _LIBC && defined USE_IN_LIBIO
1002 | char *buf;
1003 |
1004 | __asprintf (&buf, _("%s: option `-W %s' is ambiguous\n"),
1005 | argv[0], argv[optind]);
1006 |
1007 | if (_IO_fwide (stderr, 0) > 0)
1008 | __fwprintf (stderr, L"%s", buf);
1009 | else
1010 | fputs (buf, stderr);
1011 |
1012 | free (buf);
1013 | #else
1014 | fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),
1015 | argv[0], argv[optind]);
1016 | #endif
1017 | }
1018 | nextchar += strlen (nextchar);
1019 | optind++;
1020 | return '?';
1021 | }
1022 | if (pfound != NULL)
1023 | {
1024 | option_index = indfound;
1025 | if (*nameend)
1026 | {
1027 | /* Don't test has_arg with >, because some C compilers don't
1028 | allow it to be used on enums. */
1029 | if (pfound->has_arg)
1030 | optarg = nameend + 1;
1031 | else
1032 | {
1033 | if (print_errors)
1034 | {
1035 | #if defined _LIBC && defined USE_IN_LIBIO
1036 | char *buf;
1037 |
1038 | __asprintf (&buf, _("\
1039 | %s: option `-W %s' doesn't allow an argument\n"),
1040 | argv[0], pfound->name);
1041 |
1042 | if (_IO_fwide (stderr, 0) > 0)
1043 | __fwprintf (stderr, L"%s", buf);
1044 | else
1045 | fputs (buf, stderr);
1046 |
1047 | free (buf);
1048 | #else
1049 | fprintf (stderr, _("\
1050 | %s: option `-W %s' doesn't allow an argument\n"),
1051 | argv[0], pfound->name);
1052 | #endif
1053 | }
1054 |
1055 | nextchar += strlen (nextchar);
1056 | return '?';
1057 | }
1058 | }
1059 | else if (pfound->has_arg == 1)
1060 | {
1061 | if (optind < argc)
1062 | optarg = argv[optind++];
1063 | else
1064 | {
1065 | if (print_errors)
1066 | {
1067 | #if defined _LIBC && defined USE_IN_LIBIO
1068 | char *buf;
1069 |
1070 | __asprintf (&buf, _("\
1071 | %s: option `%s' requires an argument\n"),
1072 | argv[0], argv[optind - 1]);
1073 |
1074 | if (_IO_fwide (stderr, 0) > 0)
1075 | __fwprintf (stderr, L"%s", buf);
1076 | else
1077 | fputs (buf, stderr);
1078 |
1079 | free (buf);
1080 | #else
1081 | fprintf (stderr,
1082 | _("%s: option `%s' requires an argument\n"),
1083 | argv[0], argv[optind - 1]);
1084 | #endif
1085 | }
1086 | nextchar += strlen (nextchar);
1087 | return optstring[0] == ':' ? ':' : '?';
1088 | }
1089 | }
1090 | nextchar += strlen (nextchar);
1091 | if (longind != NULL)
1092 | *longind = option_index;
1093 | if (pfound->flag)
1094 | {
1095 | *(pfound->flag) = pfound->val;
1096 | return 0;
1097 | }
1098 | return pfound->val;
1099 | }
1100 | nextchar = NULL;
1101 | return 'W'; /* Let the application handle it. */
1102 | }
1103 | if (temp[1] == ':')
1104 | {
1105 | if (temp[2] == ':')
1106 | {
1107 | /* This is an option that accepts an argument optionally. */
1108 | if (*nextchar != '\0')
1109 | {
1110 | optarg = nextchar;
1111 | optind++;
1112 | }
1113 | else
1114 | optarg = NULL;
1115 | nextchar = NULL;
1116 | }
1117 | else
1118 | {
1119 | /* This is an option that requires an argument. */
1120 | if (*nextchar != '\0')
1121 | {
1122 | optarg = nextchar;
1123 | /* If we end this ARGV-element by taking the rest as an arg,
1124 | we must advance to the next element now. */
1125 | optind++;
1126 | }
1127 | else if (optind == argc)
1128 | {
1129 | if (print_errors)
1130 | {
1131 | /* 1003.2 specifies the format of this message. */
1132 | #if defined _LIBC && defined USE_IN_LIBIO
1133 | char *buf;
1134 |
1135 | __asprintf (&buf,
1136 | _("%s: option requires an argument -- %c\n"),
1137 | argv[0], c);
1138 |
1139 | if (_IO_fwide (stderr, 0) > 0)
1140 | __fwprintf (stderr, L"%s", buf);
1141 | else
1142 | fputs (buf, stderr);
1143 |
1144 | free (buf);
1145 | #else
1146 | fprintf (stderr,
1147 | _("%s: option requires an argument -- %c\n"),
1148 | argv[0], c);
1149 | #endif
1150 | }
1151 | optopt = c;
1152 | if (optstring[0] == ':')
1153 | c = ':';
1154 | else
1155 | c = '?';
1156 | }
1157 | else
1158 | /* We already incremented `optind' once;
1159 | increment it again when taking next ARGV-elt as argument. */
1160 | optarg = argv[optind++];
1161 | nextchar = NULL;
1162 | }
1163 | }
1164 | return c;
1165 | }
1166 | }
1167 |
1168 | int
1169 | getopt (argc, argv, optstring)
1170 | int argc;
1171 | char *const *argv;
1172 | const char *optstring;
1173 | {
1174 | return _getopt_internal (argc, argv, optstring,
1175 | (const struct option *) 0,
1176 | (int *) 0,
1177 | 0);
1178 | }
1179 |
1180 | #endif /* Not ELIDE_CODE. */
1181 |
1182 |
1183 | /* Compile with -DTEST to make an executable for use in testing
1184 | the above definition of `getopt'. */
1185 |
1186 | /* #define TEST */ /* Pete Wilson mod 7/28/02 */
1187 | #ifdef TEST
1188 |
1189 | #ifndef exit /* Pete Wilson mod 7/28/02 */
1190 | int exit(int); /* Pete Wilson mod 7/28/02 */
1191 | #endif /* Pete Wilson mod 7/28/02 */
1192 |
1193 | int
1194 | main (argc, argv)
1195 | int argc;
1196 | char **argv;
1197 | {
1198 | int c;
1199 | int digit_optind = 0;
1200 |
1201 | while (1)
1202 | {
1203 | int this_option_optind = optind ? optind : 1;
1204 |
1205 | c = getopt (argc, argv, "abc:d:0123456789");
1206 | if (c == -1)
1207 | break;
1208 |
1209 | switch (c)
1210 | {
1211 | case '0':
1212 | case '1':
1213 | case '2':
1214 | case '3':
1215 | case '4':
1216 | case '5':
1217 | case '6':
1218 | case '7':
1219 | case '8':
1220 | case '9':
1221 | if (digit_optind != 0 && digit_optind != this_option_optind)
1222 | printf ("digits occur in two different argv-elements.\n");
1223 | digit_optind = this_option_optind;
1224 | printf ("option %c\n", c);
1225 | break;
1226 |
1227 | case 'a':
1228 | printf ("option a\n");
1229 | break;
1230 |
1231 | case 'b':
1232 | printf ("option b\n");
1233 | break;
1234 |
1235 | case 'c':
1236 | printf ("option c with value `%s'\n", optarg);
1237 | break;
1238 |
1239 | case '?':
1240 | break;
1241 |
1242 | default:
1243 | printf ("?? getopt returned character code 0%o ??\n", c);
1244 | }
1245 | }
1246 |
1247 | if (optind < argc)
1248 | {
1249 | printf ("non-option ARGV-elements: ");
1250 | while (optind < argc)
1251 | printf ("%s ", argv[optind++]);
1252 | printf ("\n");
1253 | }
1254 |
1255 | exit (0);
1256 | }
1257 |
1258 | #endif /* TEST */
1259 |
--------------------------------------------------------------------------------
/windows/getopt.h:
--------------------------------------------------------------------------------
1 |
2 | /* getopt.h */
3 | /* Declarations for getopt.
4 | Copyright (C) 1989-1994, 1996-1999, 2001 Free Software
5 | Foundation, Inc. This file is part of the GNU C Library.
6 |
7 | The GNU C Library is free software; you can redistribute
8 | it and/or modify it under the terms of the GNU Lesser
9 | General Public License as published by the Free Software
10 | Foundation; either version 2.1 of the License, or
11 | (at your option) any later version.
12 |
13 | The GNU C Library is distributed in the hope that it will
14 | be useful, but WITHOUT ANY WARRANTY; without even the
15 | implied warranty of MERCHANTABILITY or FITNESS FOR A
16 | PARTICULAR PURPOSE. See the GNU Lesser General Public
17 | License for more details.
18 |
19 | You should have received a copy of the GNU Lesser General
20 | Public License along with the GNU C Library; if not, write
21 | to the Free Software Foundation, Inc., 59 Temple Place,
22 | Suite 330, Boston, MA 02111-1307 USA. */
23 |
24 |
25 |
26 |
27 | #ifndef _GETOPT_H
28 |
29 | #ifndef __need_getopt
30 | # define _GETOPT_H 1
31 | #endif
32 |
33 | /* If __GNU_LIBRARY__ is not already defined, either we are being used
34 | standalone, or this is the first header included in the source file.
35 | If we are being used with glibc, we need to include , but
36 | that does not exist if we are standalone. So: if __GNU_LIBRARY__ is
37 | not defined, include , which will pull in for us
38 | if it's from glibc. (Why ctype.h? It's guaranteed to exist and it
39 | doesn't flood the namespace with stuff the way some other headers do.) */
40 | #if !defined __GNU_LIBRARY__
41 | # include
42 | #endif
43 |
44 | #ifdef __cplusplus
45 | extern "C" {
46 | #endif
47 |
48 | /* For communication from `getopt' to the caller.
49 | When `getopt' finds an option that takes an argument,
50 | the argument value is returned here.
51 | Also, when `ordering' is RETURN_IN_ORDER,
52 | each non-option ARGV-element is returned here. */
53 |
54 | extern char *optarg;
55 |
56 | /* Index in ARGV of the next element to be scanned.
57 | This is used for communication to and from the caller
58 | and for communication between successive calls to `getopt'.
59 |
60 | On entry to `getopt', zero means this is the first call; initialize.
61 |
62 | When `getopt' returns -1, this is the index of the first of the
63 | non-option elements that the caller should itself scan.
64 |
65 | Otherwise, `optind' communicates from one call to the next
66 | how much of ARGV has been scanned so far. */
67 |
68 | extern int optind;
69 |
70 | /* Callers store zero here to inhibit the error message `getopt' prints
71 | for unrecognized options. */
72 |
73 | extern int opterr;
74 |
75 | /* Set to an option character which was unrecognized. */
76 |
77 | extern int optopt;
78 |
79 | #ifndef __need_getopt
80 | /* Describe the long-named options requested by the application.
81 | The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
82 | of `struct option' terminated by an element containing a name which is
83 | zero.
84 |
85 | The field `has_arg' is:
86 | no_argument (or 0) if the option does not take an argument,
87 | required_argument (or 1) if the option requires an argument,
88 | optional_argument (or 2) if the option takes an optional argument.
89 |
90 | If the field `flag' is not NULL, it points to a variable that is set
91 | to the value given in the field `val' when the option is found, but
92 | left unchanged if the option is not found.
93 |
94 | To have a long-named option do something other than set an `int' to
95 | a compiled-in constant, such as set a value from `optarg', set the
96 | option's `flag' field to zero and its `val' field to a nonzero
97 | value (the equivalent single-letter option character, if there is
98 | one). For long options that have a zero `flag' field, `getopt'
99 | returns the contents of the `val' field. */
100 |
101 | struct option
102 | {
103 | # if (defined __STDC__ && __STDC__) || defined __cplusplus
104 | const char *name;
105 | # else
106 | char *name;
107 | # endif
108 | /* has_arg can't be an enum because some compilers complain about
109 | type mismatches in all the code that assumes it is an int. */
110 | int has_arg;
111 | int *flag;
112 | int val;
113 | };
114 |
115 | /* Names for the values of the `has_arg' field of `struct option'. */
116 |
117 | # define no_argument 0
118 | # define required_argument 1
119 | # define optional_argument 2
120 | #endif /* need getopt */
121 |
122 |
123 | /* Get definitions and prototypes for functions to process the
124 | arguments in ARGV (ARGC of them, minus the program name) for
125 | options given in OPTS.
126 |
127 | Return the option character from OPTS just read. Return -1 when
128 | there are no more options. For unrecognized options, or options
129 | missing arguments, `optopt' is set to the option letter, and '?' is
130 | returned.
131 |
132 | The OPTS string is a list of characters which are recognized option
133 | letters, optionally followed by colons, specifying that that letter
134 | takes an argument, to be placed in `optarg'.
135 |
136 | If a letter in OPTS is followed by two colons, its argument is
137 | optional. This behavior is specific to the GNU `getopt'.
138 |
139 | The argument `--' causes premature termination of argument
140 | scanning, explicitly telling `getopt' that there are no more
141 | options.
142 |
143 | If OPTS begins with `--', then non-option arguments are treated as
144 | arguments to the option '\0'. This behavior is specific to the GNU
145 | `getopt'. */
146 |
147 | #if (defined __STDC__ && __STDC__) || defined __cplusplus
148 | # ifdef __GNU_LIBRARY__
149 | /* Many other libraries have conflicting prototypes for getopt, with
150 | differences in the consts, in stdlib.h. To avoid compilation
151 | errors, only prototype getopt for the GNU C library. */
152 | extern int getopt (int ___argc, char *const *___argv, const char *__shortopts);
153 | # else /* not __GNU_LIBRARY__ */
154 | extern int getopt ();
155 | # endif /* __GNU_LIBRARY__ */
156 |
157 | # ifndef __need_getopt
158 | extern int getopt_long (int ___argc, char *const *___argv,
159 | const char *__shortopts,
160 | const struct option *__longopts, int *__longind);
161 | extern int getopt_long_only (int ___argc, char *const *___argv,
162 | const char *__shortopts,
163 | const struct option *__longopts, int *__longind);
164 |
165 | /* Internal only. Users should not call this directly. */
166 | extern int _getopt_internal (int ___argc, char *const *___argv,
167 | const char *__shortopts,
168 | const struct option *__longopts, int *__longind,
169 | int __long_only);
170 | # endif
171 | #else /* not __STDC__ */
172 | extern int getopt ();
173 | # ifndef __need_getopt
174 | extern int getopt_long ();
175 | extern int getopt_long_only ();
176 |
177 | extern int _getopt_internal ();
178 | # endif
179 | #endif /* __STDC__ */
180 |
181 | #ifdef __cplusplus
182 | }
183 | #endif
184 |
185 | /* Make sure we later can get all the definitions and declarations. */
186 | #undef __need_getopt
187 |
188 | #endif /* getopt.h */
189 |
--------------------------------------------------------------------------------
/windows/shticker-book-rewritten.rc:
--------------------------------------------------------------------------------
1 | IDI_ICON1 ICON DISCARDABLE "../resources/icon.ico"
2 |
--------------------------------------------------------------------------------