Compare commits
6 Commits
feature/core
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| f9ae2fb2a0 | |||
| 95d031fef9 | |||
| 43701bbadc | |||
| 871d69de1c | |||
| b3d5291bb1 | |||
| 0ac5223086 |
Generated
+1
-1
@@ -4,7 +4,7 @@ version = 4
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "arena-core"
|
name = "arena-core"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proptest",
|
"proptest",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
+2
-2
@@ -3,7 +3,7 @@ resolver = "3"
|
|||||||
members = ["crates/*"]
|
members = ["crates/*"]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
license = "MPL-2.0"
|
license = "CPAL-1.0"
|
||||||
repository = "https://gitea.marek-novak.cz/mnovak/ArenaPublic"
|
repository = "https://gitea.marek-novak.cz/mnovak/ArenaPublic"
|
||||||
|
|||||||
@@ -1,373 +1,168 @@
|
|||||||
Mozilla Public License Version 2.0
|
Common Public Attribution License Version 1.0 (CPAL)
|
||||||
==================================
|
|
||||||
|
|
||||||
1. Definitions
|
1. “Definitions”
|
||||||
--------------
|
|
||||||
|
|
||||||
1.1. "Contributor"
|
1.0.1 “Commercial Use” means distribution or otherwise making the Covered Code available to a third party.
|
||||||
means each individual or legal entity that creates, contributes to
|
|
||||||
the creation of, or owns Covered Software.
|
|
||||||
|
|
||||||
1.2. "Contributor Version"
|
1.1 “Contributor” means each entity that creates or contributes to the creation of Modifications.
|
||||||
means the combination of the Contributions of others (if any) used
|
|
||||||
by a Contributor and that particular Contributor's Contribution.
|
|
||||||
|
|
||||||
1.3. "Contribution"
|
1.2 “Contributor Version” means the combination of the Original Code, prior Modifications used by a Contributor, and the Modifications made by that particular Contributor.
|
||||||
means Covered Software of a particular Contributor.
|
|
||||||
|
|
||||||
1.4. "Covered Software"
|
1.3 “Covered Code” means the Original Code or Modifications or the combination of the Original Code and Modifications, in each case including portions thereof.
|
||||||
means Source Code Form to which the initial Contributor has attached
|
|
||||||
the notice in Exhibit A, the Executable Form of such Source Code
|
|
||||||
Form, and Modifications of such Source Code Form, in each case
|
|
||||||
including portions thereof.
|
|
||||||
|
|
||||||
1.5. "Incompatible With Secondary Licenses"
|
1.4 “Electronic Distribution Mechanism” means a mechanism generally accepted in the software development community for the electronic transfer of data.
|
||||||
means
|
|
||||||
|
|
||||||
(a) that the initial Contributor has attached the notice described
|
1.5 “Executable” means Covered Code in any form other than Source Code.
|
||||||
in Exhibit B to the Covered Software; or
|
|
||||||
|
|
||||||
(b) that the Covered Software was made available under the terms of
|
1.6 “Initial Developer” means the individual or entity identified as the Initial Developer in the Source Code notice required by Exhibit A.
|
||||||
version 1.1 or earlier of the License, but not also under the
|
|
||||||
terms of a Secondary License.
|
|
||||||
|
|
||||||
1.6. "Executable Form"
|
1.7 “Larger Work” means a work which combines Covered Code or portions thereof with code not governed by the terms of this License.
|
||||||
means any form of the work other than Source Code Form.
|
|
||||||
|
|
||||||
1.7. "Larger Work"
|
1.8 “License” means this document.
|
||||||
means a work that combines Covered Software with other material, in
|
|
||||||
a separate file or files, that is not Covered Software.
|
|
||||||
|
|
||||||
1.8. "License"
|
1.8.1 “Licensable” means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently acquired, any and all of the rights conveyed herein.
|
||||||
means this document.
|
|
||||||
|
|
||||||
1.9. "Licensable"
|
1.9 “Modifications” means any addition to or deletion from the substance or structure of either the Original Code or any previous Modifications. When Covered Code is released as a series of files, a Modification is:
|
||||||
means having the right to grant, to the maximum extent possible,
|
|
||||||
whether at the time of the initial grant or subsequently, any and
|
|
||||||
all of the rights conveyed by this License.
|
|
||||||
|
|
||||||
1.10. "Modifications"
|
A. Any addition to or deletion from the contents of a file containing Original Code or previous Modifications.
|
||||||
means any of the following:
|
|
||||||
|
|
||||||
(a) any file in Source Code Form that results from an addition to,
|
B. Any new file that contains any part of the Original Code or previous Modifications.
|
||||||
deletion from, or modification of the contents of Covered
|
|
||||||
Software; or
|
|
||||||
|
|
||||||
(b) any new file in Source Code Form that contains any Covered
|
1.10 “Original Code” means Source Code of computer software code which is described in the Source Code notice required by Exhibit A as Original Code, and which, at the time of its release under this License is not already Covered Code governed by this License.
|
||||||
Software.
|
|
||||||
|
|
||||||
1.11. "Patent Claims" of a Contributor
|
1.10.1 “Patent Claims” means any patent claim(s), now owned or hereafter acquired, including without limitation, method, process, and apparatus claims, in any patent Licensable by grantor.
|
||||||
means any patent claim(s), including without limitation, method,
|
|
||||||
process, and apparatus claims, in any patent Licensable by such
|
|
||||||
Contributor that would be infringed, but for the grant of the
|
|
||||||
License, by the making, using, selling, offering for sale, having
|
|
||||||
made, import, or transfer of either its Contributions or its
|
|
||||||
Contributor Version.
|
|
||||||
|
|
||||||
1.12. "Secondary License"
|
1.11 “Source Code” means the preferred form of the Covered Code for making modifications to it, including all modules it contains, plus any associated interface definition files, scripts used to control compilation and installation of an Executable, or source code differential comparisons against either the Original Code or another well known, available Covered Code of the Contributor’s choice. The Source Code can be in a compressed or archival form, provided the appropriate decompression or de-archiving software is widely available for no charge.
|
||||||
means either the GNU General Public License, Version 2.0, the GNU
|
|
||||||
Lesser General Public License, Version 2.1, the GNU Affero General
|
|
||||||
Public License, Version 3.0, or any later versions of those
|
|
||||||
licenses.
|
|
||||||
|
|
||||||
1.13. "Source Code Form"
|
1.12 “You” (or “Your”) means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License or a future version of this License issued under Section 6.1. For legal entities, “You” includes any entity which controls, is controlled by, or is under common control with You. For purposes of this definition, “control” means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity.
|
||||||
means the form of the work preferred for making modifications.
|
|
||||||
|
|
||||||
1.14. "You" (or "Your")
|
2. Source Code License.
|
||||||
means an individual or a legal entity exercising rights under this
|
|
||||||
License. For legal entities, "You" includes any entity that
|
|
||||||
controls, is controlled by, or is under common control with You. For
|
|
||||||
purposes of this definition, "control" means (a) the power, direct
|
|
||||||
or indirect, to cause the direction or management of such entity,
|
|
||||||
whether by contract or otherwise, or (b) ownership of more than
|
|
||||||
fifty percent (50%) of the outstanding shares or beneficial
|
|
||||||
ownership of such entity.
|
|
||||||
|
|
||||||
2. License Grants and Conditions
|
2.1 The Initial Developer Grant.
|
||||||
--------------------------------
|
The Initial Developer hereby grants You a world-wide, royalty-free, non-exclusive license, subject to third party intellectual property claims:
|
||||||
|
|
||||||
2.1. Grants
|
(a) under intellectual property rights (other than patent or trademark) Licensable by Initial Developer to use, reproduce, modify, display, perform, sublicense and distribute the Original Code (or portions thereof) with or without Modifications, and/or as part of a Larger Work; and
|
||||||
|
|
||||||
Each Contributor hereby grants You a world-wide, royalty-free,
|
(b) under Patents Claims infringed by the making, using or selling of Original Code, to make, have made, use, practice, sell, and offer for sale, and/or otherwise dispose of the Original Code (or portions thereof).
|
||||||
non-exclusive license:
|
|
||||||
|
|
||||||
(a) under intellectual property rights (other than patent or trademark)
|
(c) the licenses granted in this Section 2.1(a) and (b) are effective on the date Initial Developer first distributes Original Code under the terms of this License.
|
||||||
Licensable by such Contributor to use, reproduce, make available,
|
|
||||||
modify, display, perform, distribute, and otherwise exploit its
|
|
||||||
Contributions, either on an unmodified basis, with Modifications, or
|
|
||||||
as part of a Larger Work; and
|
|
||||||
|
|
||||||
(b) under Patent Claims of such Contributor to make, use, sell, offer
|
(d) Notwithstanding Section 2.1(b) above, no patent license is granted: 1) for code that You delete from the Original Code; 2) separate from the Original Code; or 3) for infringements caused by: i) the modification of the Original Code or ii) the combination of the Original Code with other software or devices.
|
||||||
for sale, have made, import, and otherwise transfer either its
|
|
||||||
Contributions or its Contributor Version.
|
|
||||||
|
|
||||||
2.2. Effective Date
|
2.2 Contributor Grant.
|
||||||
|
Subject to third party intellectual property claims, each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license
|
||||||
|
|
||||||
The licenses granted in Section 2.1 with respect to any Contribution
|
(a) under intellectual property rights (other than patent or trademark) Licensable by Contributor, to use, reproduce, modify, display, perform, sublicense and distribute the Modifications created by such Contributor (or portions thereof) either on an unmodified basis, with other Modifications, as Covered Code and/or as part of a Larger Work; and
|
||||||
become effective for each Contribution on the date the Contributor first
|
|
||||||
distributes such Contribution.
|
|
||||||
|
|
||||||
2.3. Limitations on Grant Scope
|
(b) under Patent Claims infringed by the making, using, or selling of Modifications made by that Contributor either alone and/or in combination with its Contributor Version (or portions of such combination), to make, use, sell, offer for sale, have made, and/or otherwise dispose of: 1) Modifications made by that Contributor (or portions thereof); and 2) the combination of Modifications made by that Contributor with its Contributor Version (or portions of such combination).
|
||||||
|
|
||||||
The licenses granted in this Section 2 are the only rights granted under
|
(c) the licenses granted in Sections 2.2(a) and 2.2(b) are effective on the date Contributor first makes Commercial Use of the Covered Code.
|
||||||
this License. No additional rights or licenses will be implied from the
|
|
||||||
distribution or licensing of Covered Software under this License.
|
(d) Notwithstanding Section 2.2(b) above, no patent license is granted: 1) for any code that Contributor has deleted from the Contributor Version; 2) separate from the Contributor Version; 3) for infringements caused by: i) third party modifications of Contributor Version or ii) the combination of Modifications made by that Contributor with other software (except as part of the Contributor Version) or other devices; or 4) under Patent Claims infringed by Covered Code in the absence of Modifications made by that Contributor.
|
||||||
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
|
||||||
Contributor:
|
3. Distribution Obligations.
|
||||||
|
|
||||||
(a) for any code that a Contributor has removed from Covered Software;
|
3.1 Application of License.
|
||||||
or
|
The Modifications which You create or to which You contribute are governed by the terms of this License, including without limitation Section 2.2. The Source Code version of Covered Code may be distributed only under the terms of this License or a future version of this License released under Section 6.1, and You must include a copy of this License with every copy of the Source Code You distribute. You may not offer or impose any terms on any Source Code version that alters or restricts the applicable version of this License or the recipients’ rights hereunder. However, You may include an additional document offering the additional rights described in Section 3.5.
|
||||||
|
|
||||||
(b) for infringements caused by: (i) Your and any other third party's
|
3.2 Availability of Source Code.
|
||||||
modifications of Covered Software, or (ii) the combination of its
|
Any Modification which You create or to which You contribute must be made available in Source Code form under the terms of this License either on the same media as an Executable version or via an accepted Electronic Distribution Mechanism to anyone to whom you made an Executable version available; and if made available via Electronic Distribution Mechanism, must remain available for at least twelve (12) months after the date it initially became available, or at least six (6) months after a subsequent version of that particular Modification has been made available to such recipients. You are responsible for ensuring that the Source Code version remains available even if the Electronic Distribution Mechanism is maintained by a third party.
|
||||||
Contributions with other software (except as part of its Contributor
|
|
||||||
Version); or
|
3.3 Description of Modifications.
|
||||||
|
You must cause all Covered Code to which You contribute to contain a file documenting the changes You made to create that Covered Code and the date of any change. You must include a prominent statement that the Modification is derived, directly or indirectly, from Original Code provided by the Initial Developer and including the name of the Initial Developer in (a) the Source Code, and (b) in any notice in an Executable version or related documentation in which You describe the origin or ownership of the Covered Code.
|
||||||
(c) under Patent Claims infringed by Covered Software in the absence of
|
|
||||||
its Contributions.
|
3.4 Intellectual Property Matters
|
||||||
|
|
||||||
This License does not grant any rights in the trademarks, service marks,
|
(a) Third Party Claims. If Contributor has knowledge that a license under a third party’s intellectual property rights is required to exercise the rights granted by such Contributor under Sections 2.1 or 2.2, Contributor must include a text file with the Source Code distribution titled “LEGAL” which describes the claim and the party making the claim in sufficient detail that a recipient will know whom to contact. If Contributor obtains such knowledge after the Modification is made available as described in Section 3.2, Contributor shall promptly modify the LEGAL file in all copies Contributor makes available thereafter and shall take other steps (such as notifying appropriate mailing lists or newsgroups) reasonably calculated to inform those who received the Covered Code that new knowledge has been obtained.
|
||||||
or logos of any Contributor (except as may be necessary to comply with
|
|
||||||
the notice requirements in Section 3.4).
|
(b) Contributor APIs. If Contributor’s Modifications include an application programming interface and Contributor has knowledge of patent licenses which are reasonably necessary to implement that API, Contributor must also include this information in the LEGAL file.
|
||||||
|
|
||||||
2.4. Subsequent Licenses
|
(c) Representations. Contributor represents that, except as disclosed pursuant to Section 3.4(a) above, Contributor believes that Contributor’s Modifications are Contributor’s original creation(s) and/or Contributor has sufficient rights to grant the rights conveyed by this License.
|
||||||
|
|
||||||
No Contributor makes additional grants as a result of Your choice to
|
3.5 Required Notices.
|
||||||
distribute the Covered Software under a subsequent version of this
|
You must duplicate the notice in Exhibit A in each file of the Source Code. If it is not possible to put such notice in a particular Source Code file due to its structure, then You must include such notice in a location (such as a relevant directory) where a user would be likely to look for such a notice. If You created one or more Modification(s) You may add your name as a Contributor to the notice described in Exhibit A. You must also duplicate this License in any documentation for the Source Code where You describe recipients’ rights or ownership rights relating to Covered Code. You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Code. However, You may do so only on Your own behalf, and not on behalf of the Initial Developer or any Contributor. You must make it absolutely clear than any such warranty, support, indemnity or liability obligation is offered by You alone, and You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of warranty, support, indemnity or liability terms You offer.
|
||||||
License (see Section 10.2) or under the terms of a Secondary License (if
|
|
||||||
permitted under the terms of Section 3.3).
|
3.6 Distribution of Executable Versions.
|
||||||
|
You may distribute Covered Code in Executable form only if the requirements of Section 3.1-3.5 have been met for that Covered Code, and if You include a notice stating that the Source Code version of the Covered Code is available under the terms of this License, including a description of how and where You have fulfilled the obligations of Section 3.2. The notice must be conspicuously included in any notice in an Executable version, related documentation or collateral in which You describe recipients’ rights relating to the Covered Code. You may distribute the Executable version of Covered Code or ownership rights under a license of Your choice, which may contain terms different from this License, provided that You are in compliance with the terms of this License and that the license for the Executable version does not attempt to limit or alter the recipient’s rights in the Source Code version from the rights set forth in this License. If You distribute the Executable version under a different license You must make it absolutely clear that any terms which differ from this License are offered by You alone, not by the Initial Developer, Original Developer or any Contributor. You hereby agree to indemnify the Initial Developer, Original Developer and every Contributor for any liability incurred by the Initial Developer, Original Developer or such Contributor as a result of any such terms You offer.
|
||||||
2.5. Representation
|
|
||||||
|
3.7 Larger Works.
|
||||||
Each Contributor represents that the Contributor believes its
|
You may create a Larger Work by combining Covered Code with other code not governed by the terms of this License and distribute the Larger Work as a single product. In such a case, You must make sure the requirements of this License are fulfilled for the Covered Code.
|
||||||
Contributions are its original creation(s) or it has sufficient rights
|
|
||||||
to grant the rights to its Contributions conveyed by this License.
|
4. Inability to Comply Due to Statute or Regulation.
|
||||||
|
If it is impossible for You to comply with any of the terms of this License with respect to some or all of the Covered Code due to statute, judicial order, or regulation then You must: (a) comply with the terms of this License to the maximum extent possible; and (b) describe the limitations and the code they affect. Such description must be included in the LEGAL file described in Section 3.4 and must be included with all distributions of the Source Code. Except to the extent prohibited by statute or regulation, such description must be sufficiently detailed for a recipient of ordinary skill to be able to understand it.
|
||||||
2.6. Fair Use
|
|
||||||
|
5. Application of this License.
|
||||||
This License is not intended to limit any rights You have under
|
This License applies to code to which the Initial Developer has attached the notice in Exhibit A and to related Covered Code.
|
||||||
applicable copyright doctrines of fair use, fair dealing, or other
|
|
||||||
equivalents.
|
6. Versions of the License.
|
||||||
|
|
||||||
2.7. Conditions
|
6.1 New Versions.
|
||||||
|
Socialtext, Inc. (“Socialtext”) may publish revised and/or new versions of the License from time to time. Each version will be given a distinguishing version number.
|
||||||
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
|
|
||||||
in Section 2.1.
|
6.2 Effect of New Versions.
|
||||||
|
Once Covered Code has been published under a particular version of the License, You may always continue to use it under the terms of that version. You may also choose to use such Covered Code under the terms of any subsequent version of the License published by Socialtext. No one other than Socialtext has the right to modify the terms applicable to Covered Code created under this License.
|
||||||
3. Responsibilities
|
|
||||||
-------------------
|
6.3 Derivative Works.
|
||||||
|
If You create or use a modified version of this License (which you may only do in order to apply it to code which is not already Covered Code governed by this License), You must (a) rename Your license so that the phrases “Socialtext”, “CPAL” or any confusingly similar phrase do not appear in your license (except to note that your license differs from this License) and (b) otherwise make it clear that Your version of the license contains terms which differ from the CPAL. (Filling in the name of the Initial Developer, Original Developer, Original Code or Contributor in the notice described in Exhibit A shall not of themselves be deemed to be modifications of this License.)
|
||||||
3.1. Distribution of Source Form
|
|
||||||
|
7. DISCLAIMER OF WARRANTY.
|
||||||
All distribution of Covered Software in Source Code Form, including any
|
COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN “AS IS” BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER, ORIGINAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
|
||||||
Modifications that You create or to which You contribute, must be under
|
|
||||||
the terms of this License. You must inform recipients that the Source
|
8. TERMINATION.
|
||||||
Code Form of the Covered Software is governed by the terms of this
|
|
||||||
License, and how they can obtain a copy of this License. You may not
|
8.1 This License and the rights granted hereunder will terminate automatically if You fail to comply with terms herein and fail to cure such breach within 30 days of becoming aware of the breach. All sublicenses to the Covered Code which are properly granted shall survive any termination of this License. Provisions which, by their nature, must remain in effect beyond the termination of this License shall survive.
|
||||||
attempt to alter or restrict the recipients' rights in the Source Code
|
|
||||||
Form.
|
8.2 If You initiate litigation by asserting a patent infringement claim (excluding declatory judgment actions) against Initial Developer, Original Developer or a Contributor (the Initial Developer, Original Developer or Contributor against whom You file such action is referred to as “Participant”) alleging that:
|
||||||
|
|
||||||
3.2. Distribution of Executable Form
|
(a) such Participant’s Contributor Version directly or indirectly infringes any patent, then any and all rights granted by such Participant to You under Sections 2.1 and/or 2.2 of this License shall, upon 60 days notice from Participant terminate prospectively, unless if within 60 days after receipt of notice You either: (i) agree in writing to pay Participant a mutually agreeable reasonable royalty for Your past and future use of Modifications made by such Participant, or (ii) withdraw Your litigation claim with respect to the Contributor Version against such Participant. If within 60 days of notice, a reasonable royalty and payment arrangement are not mutually agreed upon in writing by the parties or the litigation claim is not withdrawn, the rights granted by Participant to You under Sections 2.1 and/or 2.2 automatically terminate at the expiration of the 60 day notice period specified above.
|
||||||
|
|
||||||
If You distribute Covered Software in Executable Form then:
|
(b) any software, hardware, or device, other than such Participant’s Contributor Version, directly or indirectly infringes any patent, then any rights granted to You by such Participant under Sections 2.1(b) and 2.2(b) are revoked effective as of the date You first made, used, sold, distributed, or had made, Modifications made by that Participant.
|
||||||
|
|
||||||
(a) such Covered Software must also be made available in Source Code
|
8.3 If You assert a patent infringement claim against Participant alleging that such Participant’s Contributor Version directly or indirectly infringes any patent where such claim is resolved (such as by license or settlement) prior to the initiation of patent infringement litigation, then the reasonable value of the licenses granted by such Participant under Sections 2.1 or 2.2 shall be taken into account in determining the amount or value of any payment or license.
|
||||||
Form, as described in Section 3.1, and You must inform recipients of
|
|
||||||
the Executable Form how they can obtain a copy of such Source Code
|
8.4 In the event of termination under Sections 8.1 or 8.2 above, all end user license agreements (excluding distributors and resellers) which have been validly granted by You or any distributor hereunder prior to termination shall survive termination.
|
||||||
Form by reasonable means in a timely manner, at a charge no more
|
|
||||||
than the cost of distribution to the recipient; and
|
9. LIMITATION OF LIABILITY.
|
||||||
|
UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL DEVELOPER, ORIGINAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY RESULTING FROM SUCH PARTY’S NEGLIGENCE TO THE EXTENT APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
|
||||||
(b) You may distribute such Executable Form under the terms of this
|
|
||||||
License, or sublicense it under different terms, provided that the
|
10. U.S. GOVERNMENT END USERS.
|
||||||
license for the Executable Form does not attempt to limit or alter
|
The Covered Code is a “commercial item,” as that term is defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of “commercial computer software” and “commercial computer software documentation,” as such terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), all U.S. Government End Users acquire Covered Code with only those rights set forth herein.
|
||||||
the recipients' rights in the Source Code Form under this License.
|
|
||||||
|
11. MISCELLANEOUS.
|
||||||
3.3. Distribution of a Larger Work
|
This License represents the complete agreement concerning subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. This License shall be governed by California law provisions (except to the extent applicable law, if any, provides otherwise), excluding its conflict-of-law provisions. With respect to disputes in which at least one party is a citizen of, or an entity chartered or registered to do business in the United States of America, any litigation relating to this License shall be subject to the jurisdiction of the Federal Courts of the Northern District of California, with venue lying in Santa Clara County, California, with the losing party responsible for costs, including without limitation, court costs and reasonable attorneys’ fees and expenses. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not apply to this License.
|
||||||
|
|
||||||
You may create and distribute a Larger Work under terms of Your choice,
|
12. RESPONSIBILITY FOR CLAIMS.
|
||||||
provided that You also comply with the requirements of this License for
|
As between Initial Developer, Original Developer and the Contributors, each party is responsible for claims and damages arising, directly or indirectly, out of its utilization of rights under this License and You agree to work with Initial Developer, Original Developer and Contributors to distribute such responsibility on an equitable basis. Nothing herein is intended or shall be deemed to constitute any admission of liability.
|
||||||
the Covered Software. If the Larger Work is a combination of Covered
|
|
||||||
Software with a work governed by one or more Secondary Licenses, and the
|
13. MULTIPLE-LICENSED CODE.
|
||||||
Covered Software is not Incompatible With Secondary Licenses, this
|
Initial Developer may designate portions of the Covered Code as Multiple-Licensed. Multiple-Licensed means that the Initial Developer permits you to utilize portions of the Covered Code under Your choice of the CPAL or the alternative licenses, if any, specified by the Initial Developer in the file described in Exhibit A.
|
||||||
License permits You to additionally distribute such Covered Software
|
|
||||||
under the terms of such Secondary License(s), so that the recipient of
|
14. ADDITIONAL TERM: ATTRIBUTION
|
||||||
the Larger Work may, at their option, further distribute the Covered
|
|
||||||
Software under the terms of either this License or such Secondary
|
(a) As a modest attribution to the organizer of the development of the Original Code (“Original Developer”), in the hope that its promotional value may help justify the time, money and effort invested in writing the Original Code, the Original Developer may include in Exhibit B (“Attribution Information”) a requirement that each time an Executable and Source Code or a Larger Work is launched or initially run (which includes initiating a session), a prominent display of the Original Developer’s Attribution Information (as defined below) must occur on the graphic user interface employed by the end user to access such Covered Code (which may include display on a splash screen), if any. The size of the graphic image should be consistent with the size of the other elements of the Attribution Information. If the access by the end user to the Executable and Source Code does not create a graphic user interface for access to the Covered Code, this obligation shall not apply. If the Original Code displays such Attribution Information in a particular form (such as in the form of a splash screen, notice at login, an “about” display, or dedicated attribution area on user interface screens), continued use of such form for that Attribution Information is one way of meeting this requirement for notice.
|
||||||
License(s).
|
|
||||||
|
(b) Attribution information may only include a copyright notice, a brief phrase, graphic image and a URL (“Attribution Information”) and is subject to the Attribution Limits as defined below. For these purposes, prominent shall mean display for sufficient duration to give reasonable notice to the user of the identity of the Original Developer and that if You include Attribution Information or similar information for other parties, You must ensure that the Attribution Information for the Original Developer shall be no less prominent than such Attribution Information or similar information for the other party. For greater certainty, the Original Developer may choose to specify in Exhibit B below that the above attribution requirement only applies to an Executable and Source Code resulting from the Original Code or any Modification, but not a Larger Work. The intent is to provide for reasonably modest attribution, therefore the Original Developer cannot require that You display, at any time, more than the following information as Attribution Information: (a) a copyright notice including the name of the Original Developer; (b) a word or one phrase (not exceeding 10 words); (c) one graphic image provided by the Original Developer; and (d) a URL (collectively, the “Attribution Limits”).
|
||||||
3.4. Notices
|
|
||||||
|
(c) If Exhibit B does not include any Attribution Information, then there are no requirements for You to display any Attribution Information of the Original Developer.
|
||||||
You may not remove or alter the substance of any license notices
|
|
||||||
(including copyright notices, patent notices, disclaimers of warranty,
|
(d) You acknowledge that all trademarks, service marks and/or trade names contained within the Attribution Information distributed with the Covered Code are the exclusive property of their owners and may only be used with the permission of their owners, or under circumstances otherwise permitted by law or as expressly set out in this License.
|
||||||
or limitations of liability) contained within the Source Code Form of
|
|
||||||
the Covered Software, except that You may alter any license notices to
|
15. ADDITIONAL TERM: NETWORK USE.
|
||||||
the extent required to remedy known factual inaccuracies.
|
The term “External Deployment” means the use, distribution, or communication of the Original Code or Modifications in any way such that the Original Code or Modifications may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Code or Modifications as a distribution under section 3.1 and make Source Code available under Section 3.2.
|
||||||
|
|
||||||
3.5. Application of Additional Terms
|
EXHIBIT A. Common Public Attribution License Version 1.0.
|
||||||
|
|
||||||
You may choose to offer, and to charge a fee for, warranty, support,
|
"The contents of this file are subject to the Common Public Attribution License Version 1.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://opensource.org/license/cpal_1-0. The License is based on the Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover use of software over a computer network and provide for limited attribution for the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B.
|
||||||
indemnity or liability obligations to one or more recipients of Covered
|
Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License.
|
||||||
Software. However, You may do so only on Your own behalf, and not on
|
The Original Code is ArenaPublic.
|
||||||
behalf of any Contributor. You must make it absolutely clear that any
|
The Original Developer is the Initial Developer.
|
||||||
such warranty, support, indemnity, or liability obligation is offered by
|
The Initial Developer of the Original Code is Marek Novák. All portions of the code written by Marek Novák are Copyright (c) 2026. All Rights Reserved.
|
||||||
You alone, and You hereby agree to indemnify every Contributor for any
|
Contributor: none."
|
||||||
liability incurred by such Contributor as a result of warranty, support,
|
|
||||||
indemnity or liability terms You offer. You may include additional
|
EXHIBIT B. Attribution Information
|
||||||
disclaimers of warranty and limitations of liability specific to any
|
|
||||||
jurisdiction.
|
Attribution Copyright Notice: Copyright (c) 2026 Marek Novák
|
||||||
|
Attribution Phrase (not exceeding 10 words): Built on Domi
|
||||||
4. Inability to Comply Due to Statute or Regulation
|
Attribution URL: https://aula.marek-novak.cz
|
||||||
---------------------------------------------------
|
Graphic Image as provided in the Covered Code, if any: none.
|
||||||
|
Display of Attribution Information is required in Larger Works which are defined in the CPAL as a work which combines Covered Code or portions thereof with code not governed by the terms of the CPAL.
|
||||||
If it is impossible for You to comply with any of the terms of this
|
|
||||||
License with respect to some or all of the Covered Software due to
|
|
||||||
statute, judicial order, or regulation then You must: (a) comply with
|
|
||||||
the terms of this License to the maximum extent possible; and (b)
|
|
||||||
describe the limitations and the code they affect. Such description must
|
|
||||||
be placed in a text file included with all distributions of the Covered
|
|
||||||
Software under this License. Except to the extent prohibited by statute
|
|
||||||
or regulation, such description must be sufficiently detailed for a
|
|
||||||
recipient of ordinary skill to be able to understand it.
|
|
||||||
|
|
||||||
5. Termination
|
|
||||||
--------------
|
|
||||||
|
|
||||||
5.1. The rights granted under this License will terminate automatically
|
|
||||||
if You fail to comply with any of its terms. However, if You become
|
|
||||||
compliant, then the rights granted under this License from a particular
|
|
||||||
Contributor are reinstated (a) provisionally, unless and until such
|
|
||||||
Contributor explicitly and finally terminates Your grants, and (b) on an
|
|
||||||
ongoing basis, if such Contributor fails to notify You of the
|
|
||||||
non-compliance by some reasonable means prior to 60 days after You have
|
|
||||||
come back into compliance. Moreover, Your grants from a particular
|
|
||||||
Contributor are reinstated on an ongoing basis if such Contributor
|
|
||||||
notifies You of the non-compliance by some reasonable means, this is the
|
|
||||||
first time You have received notice of non-compliance with this License
|
|
||||||
from such Contributor, and You become compliant prior to 30 days after
|
|
||||||
Your receipt of the notice.
|
|
||||||
|
|
||||||
5.2. If You initiate litigation against any entity by asserting a patent
|
|
||||||
infringement claim (excluding declaratory judgment actions,
|
|
||||||
counter-claims, and cross-claims) alleging that a Contributor Version
|
|
||||||
directly or indirectly infringes any patent, then the rights granted to
|
|
||||||
You by any and all Contributors for the Covered Software under Section
|
|
||||||
2.1 of this License shall terminate.
|
|
||||||
|
|
||||||
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
|
|
||||||
end user license agreements (excluding distributors and resellers) which
|
|
||||||
have been validly granted by You or Your distributors under this License
|
|
||||||
prior to termination shall survive termination.
|
|
||||||
|
|
||||||
************************************************************************
|
|
||||||
* *
|
|
||||||
* 6. Disclaimer of Warranty *
|
|
||||||
* ------------------------- *
|
|
||||||
* *
|
|
||||||
* Covered Software is provided under this License on an "as is" *
|
|
||||||
* basis, without warranty of any kind, either expressed, implied, or *
|
|
||||||
* statutory, including, without limitation, warranties that the *
|
|
||||||
* Covered Software is free of defects, merchantable, fit for a *
|
|
||||||
* particular purpose or non-infringing. The entire risk as to the *
|
|
||||||
* quality and performance of the Covered Software is with You. *
|
|
||||||
* Should any Covered Software prove defective in any respect, You *
|
|
||||||
* (not any Contributor) assume the cost of any necessary servicing, *
|
|
||||||
* repair, or correction. This disclaimer of warranty constitutes an *
|
|
||||||
* essential part of this License. No use of any Covered Software is *
|
|
||||||
* authorized under this License except under this disclaimer. *
|
|
||||||
* *
|
|
||||||
************************************************************************
|
|
||||||
|
|
||||||
************************************************************************
|
|
||||||
* *
|
|
||||||
* 7. Limitation of Liability *
|
|
||||||
* -------------------------- *
|
|
||||||
* *
|
|
||||||
* Under no circumstances and under no legal theory, whether tort *
|
|
||||||
* (including negligence), contract, or otherwise, shall any *
|
|
||||||
* Contributor, or anyone who distributes Covered Software as *
|
|
||||||
* permitted above, be liable to You for any direct, indirect, *
|
|
||||||
* special, incidental, or consequential damages of any character *
|
|
||||||
* including, without limitation, damages for lost profits, loss of *
|
|
||||||
* goodwill, work stoppage, computer failure or malfunction, or any *
|
|
||||||
* and all other commercial damages or losses, even if such party *
|
|
||||||
* shall have been informed of the possibility of such damages. This *
|
|
||||||
* limitation of liability shall not apply to liability for death or *
|
|
||||||
* personal injury resulting from such party's negligence to the *
|
|
||||||
* extent applicable law prohibits such limitation. Some *
|
|
||||||
* jurisdictions do not allow the exclusion or limitation of *
|
|
||||||
* incidental or consequential damages, so this exclusion and *
|
|
||||||
* limitation may not apply to You. *
|
|
||||||
* *
|
|
||||||
************************************************************************
|
|
||||||
|
|
||||||
8. Litigation
|
|
||||||
-------------
|
|
||||||
|
|
||||||
Any litigation relating to this License may be brought only in the
|
|
||||||
courts of a jurisdiction where the defendant maintains its principal
|
|
||||||
place of business and such litigation shall be governed by laws of that
|
|
||||||
jurisdiction, without reference to its conflict-of-law provisions.
|
|
||||||
Nothing in this Section shall prevent a party's ability to bring
|
|
||||||
cross-claims or counter-claims.
|
|
||||||
|
|
||||||
9. Miscellaneous
|
|
||||||
----------------
|
|
||||||
|
|
||||||
This License represents the complete agreement concerning the subject
|
|
||||||
matter hereof. If any provision of this License is held to be
|
|
||||||
unenforceable, such provision shall be reformed only to the extent
|
|
||||||
necessary to make it enforceable. Any law or regulation which provides
|
|
||||||
that the language of a contract shall be construed against the drafter
|
|
||||||
shall not be used to construe this License against a Contributor.
|
|
||||||
|
|
||||||
10. Versions of the License
|
|
||||||
---------------------------
|
|
||||||
|
|
||||||
10.1. New Versions
|
|
||||||
|
|
||||||
Mozilla Foundation is the license steward. Except as provided in Section
|
|
||||||
10.3, no one other than the license steward has the right to modify or
|
|
||||||
publish new versions of this License. Each version will be given a
|
|
||||||
distinguishing version number.
|
|
||||||
|
|
||||||
10.2. Effect of New Versions
|
|
||||||
|
|
||||||
You may distribute the Covered Software under the terms of the version
|
|
||||||
of the License under which You originally received the Covered Software,
|
|
||||||
or under the terms of any subsequent version published by the license
|
|
||||||
steward.
|
|
||||||
|
|
||||||
10.3. Modified Versions
|
|
||||||
|
|
||||||
If you create software not governed by this License, and you want to
|
|
||||||
create a new license for such software, you may create and use a
|
|
||||||
modified version of this License if you rename the license and remove
|
|
||||||
any references to the name of the license steward (except to note that
|
|
||||||
such modified license differs from this License).
|
|
||||||
|
|
||||||
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
|
||||||
Licenses
|
|
||||||
|
|
||||||
If You choose to distribute Source Code Form that is Incompatible With
|
|
||||||
Secondary Licenses under the terms of this version of the License, the
|
|
||||||
notice described in Exhibit B of this License must be attached.
|
|
||||||
|
|
||||||
Exhibit A - Source Code Form License Notice
|
|
||||||
-------------------------------------------
|
|
||||||
|
|
||||||
This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
|
|
||||||
If it is not possible or desirable to put the notice in a particular
|
|
||||||
file, then You may include the notice in a location (such as a LICENSE
|
|
||||||
file in a relevant directory) where a recipient would be likely to look
|
|
||||||
for such a notice.
|
|
||||||
|
|
||||||
You may add additional accurate notices of copyright ownership.
|
|
||||||
|
|
||||||
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
|
||||||
---------------------------------------------------------
|
|
||||||
|
|
||||||
This Source Code Form is "Incompatible With Secondary Licenses", as
|
|
||||||
defined by the Mozilla Public License, v. 2.0.
|
|
||||||
@@ -1,17 +1,32 @@
|
|||||||
# ArenaPublic
|
# ArenaPublic
|
||||||
|
|
||||||
The open core of Arena Domi, the Domi game library: pure Rust parsers for game launcher files (Steam
|
The open core of Arena Domi, the Domi game library: pure Rust parsers for game launcher files (Steam
|
||||||
`libraryfolders.vdf` and `appmanifest_<id>.acf`, Epic `.item`, GOG entries), the library model, and later the
|
`libraryfolders.vdf` and `appmanifest_<id>.acf`, Epic `.item`, GOG entries), the library model, and the
|
||||||
frametime statistics and replay-ring logic. No I/O: inputs are bytes or values, outputs are data. Builds for
|
overlay's pure logic (frametime statistics, game detection, the shortcut); later the replay-ring logic. No I/O:
|
||||||
Windows, Android and WebAssembly.
|
inputs are bytes or values, outputs are data. Builds for Windows, Android and WebAssembly.
|
||||||
|
|
||||||
Licence: MPL-2.0 (see LICENSE).
|
## Licence
|
||||||
|
|
||||||
|
ArenaPublic is licensed under the **Common Public Attribution License 1.0** (SPDX `CPAL-1.0`); see `LICENSE`.
|
||||||
|
|
||||||
|
Anyone who redistributes ArenaPublic, or a Larger Work built on it, must show the Exhibit B credit wherever
|
||||||
|
CPAL §14 asks for it (display in Larger Works is required):
|
||||||
|
|
||||||
|
| Field | Value |
|
||||||
|
| :-- | :-- |
|
||||||
|
| Attribution Copyright Notice | Copyright (c) 2026 Marek Novák |
|
||||||
|
| Attribution Phrase | Built on Domi |
|
||||||
|
| Attribution URL | https://aula.marek-novak.cz |
|
||||||
|
| Graphic Image | none |
|
||||||
|
|
||||||
|
Versions before this change (up to and including tag `core-v0.1.0`) stay available under MPL-2.0 to those who
|
||||||
|
received them; from this commit on, the code is under CPAL-1.0.
|
||||||
|
|
||||||
## Crates
|
## Crates
|
||||||
|
|
||||||
| Crate | Lib | What it holds |
|
| Crate | Lib | What it holds |
|
||||||
| :-- | :-- | :-- |
|
| :-- | :-- | :-- |
|
||||||
| `crates/arena-core` | `arena_core` | launcher parsers, `WinPath`, `GameId`, `Launch`, the `Game` / `Library` model, `merge` |
|
| `crates/arena-core` | `arena_core` | launcher parsers, `WinPath`, `GameId`, `Launch`, the `Game` / `Library` model, `merge`; for the overlay `frames`, `detect`, `hotkey` |
|
||||||
|
|
||||||
## `arena-core` in one screen
|
## `arena-core` in one screen
|
||||||
|
|
||||||
@@ -58,8 +73,29 @@ match &game.launch {
|
|||||||
| `Game` | `{ id, source, title, install_dir, launch, cover }`; serde round trip validates every field |
|
| `Game` | `{ id, source, title, install_dir, launch, cover }`; serde round trip validates every field |
|
||||||
| `ParseError` | typed, `Display`, never carries input text |
|
| `ParseError` | typed, `Display`, never carries input text |
|
||||||
|
|
||||||
|
For the overlay agent (0.2.0):
|
||||||
|
|
||||||
|
```rust
|
||||||
|
use arena_core::{frames, detect::{self, Detection, How, Marks}, hotkey::{self, Hotkey}};
|
||||||
|
|
||||||
|
// Frametimes in ms → avg FPS (frames / time), 1 % and 0.1 % lows (nearest-rank percentile, capped at the
|
||||||
|
// average), stutters (>= 2.5 x the median of the 60 frames before and >= 25 ms). None for empty or bad input.
|
||||||
|
let st: Option<frames::FrameStats> = frames::stats(&frametimes_ms);
|
||||||
|
|
||||||
|
// Launched by Arena > marked off ("not a game": None) > marked on > inside an install_dir (deepest wins).
|
||||||
|
// Outside every install_dir and not marked on: never a game. Whole path components, ignoring case.
|
||||||
|
marks.set(exe.clone(), true)?; // the "This is a game" toggle; false = off
|
||||||
|
let d: Option<Detection> = detect::detect(&exe, launched_by_arena, &library.games, &marks);
|
||||||
|
|
||||||
|
// "Ctrl+Shift+G" ⇄ Hotkey; refuses bare letters and Windows-reserved keys; Win32 values for RegisterHotKey.
|
||||||
|
let h: Hotkey = hotkey::parse("Ctrl+Shift+G")?;
|
||||||
|
let (fs_modifiers, vk) = (h.win32_modifiers(), h.virtual_key());
|
||||||
|
```
|
||||||
|
|
||||||
`Game`, `Library`, `GameId`, `WinPath` and `Launch` serialise with serde, and deserialising runs the same checks
|
`Game`, `Library`, `GameId`, `WinPath` and `Launch` serialise with serde, and deserialising runs the same checks
|
||||||
as the parsers, so a tampered `library.json` cannot smuggle in a bad path or launch string.
|
as the parsers, so a tampered `library.json` cannot smuggle in a bad path or launch string. The same holds for
|
||||||
|
`Marks` (`{"on": [...], "off": [...]}` exe paths in the agent's `overlay.json`) and `Hotkey` (its text form in
|
||||||
|
`settings.json`).
|
||||||
|
|
||||||
Docs: [`docs/FORMATS.md`](docs/FORMATS.md) (what each parser accepts and refuses, every cap) and
|
Docs: [`docs/FORMATS.md`](docs/FORMATS.md) (what each parser accepts and refuses, every cap) and
|
||||||
[`docs/PORTABILITY.md`](docs/PORTABILITY.md) (the target checks).
|
[`docs/PORTABILITY.md`](docs/PORTABILITY.md) (the target checks).
|
||||||
|
|||||||
@@ -0,0 +1,218 @@
|
|||||||
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
|
|
||||||
|
//! Which running exe is a game, for the overlay agent.
|
||||||
|
//!
|
||||||
|
//! The agent hands in the foreground process's exe path (already a [`WinPath`]: absolute, no `..`, no UNC or
|
||||||
|
//! `\\?\`, so it cannot climb out of a folder), whether Arena launched it, the library and the user's marks.
|
||||||
|
//! [`detect`] applies these rules, first match wins:
|
||||||
|
//!
|
||||||
|
//! 1. **Launched**: Arena started it. Always a game, whatever the marks; `game` is the library game that owns the
|
||||||
|
//! exe, if any (a launcher stub or a Domi app may live elsewhere: the window's `launched` message says which).
|
||||||
|
//! 2. **Marked off**: the user said "This is not a game" for exactly this exe: `None`, even inside an install folder.
|
||||||
|
//! 3. **Marked on**: the user said "This is a game" for exactly this exe: [`How::Marked`], with the library game
|
||||||
|
//! that owns the exe if there is one.
|
||||||
|
//! 4. **InstallDir**: the exe is a game's own launch exe, or lies inside a game's `install_dir`. The deepest
|
||||||
|
//! install folder wins (an expansion in a sub-folder beats the base game), then library order.
|
||||||
|
//!
|
||||||
|
//! **An exe outside every `install_dir` is never auto-detected**: without Arena launching it or an "on" mark, it is
|
||||||
|
//! not a game. Paths compare the way Windows does: ignoring case, `/` and `\` alike, on whole components, so
|
||||||
|
//! `C:\Games\Foo` never claims `C:\Games\FooBar\x.exe`. A drive root as an install folder (a manual game picked at
|
||||||
|
//! `D:\game.exe`) claims only that game's own exe, never the whole drive.
|
||||||
|
|
||||||
|
use crate::error::ParseError;
|
||||||
|
use crate::id::GameId;
|
||||||
|
use crate::launch::Launch;
|
||||||
|
use crate::limits::MAX_MARKS;
|
||||||
|
use crate::model::Game;
|
||||||
|
use crate::path::WinPath;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
|
/// A detected game.
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||||
|
pub struct Detection {
|
||||||
|
/// The library game, when one is known.
|
||||||
|
pub game: Option<GameId>,
|
||||||
|
/// Which rule matched.
|
||||||
|
pub how: How,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Which rule detected the game (in JSON: `launched`, `install_dir`, `marked`).
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
|
pub enum How {
|
||||||
|
/// Arena launched it.
|
||||||
|
Launched,
|
||||||
|
/// It is a game's launch exe or inside a game's install folder.
|
||||||
|
InstallDir,
|
||||||
|
/// The user marked this exe as a game.
|
||||||
|
Marked,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Detects whether `exe` is a game; see the [module docs](self) for the rules.
|
||||||
|
pub fn detect(exe: &WinPath, launched_by_arena: bool, library: &[Game], marked: &Marks) -> Option<Detection> {
|
||||||
|
let in_library = find_game(exe, library);
|
||||||
|
if launched_by_arena {
|
||||||
|
return Some(Detection { game: in_library, how: How::Launched });
|
||||||
|
}
|
||||||
|
match marked.get(exe) {
|
||||||
|
Some(false) => None,
|
||||||
|
Some(true) => Some(Detection { game: in_library, how: How::Marked }),
|
||||||
|
None => in_library.map(|game| Detection { game: Some(game), how: How::InstallDir }),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The library game that owns `exe`: its own launch exe, else the deepest install folder that strictly contains it.
|
||||||
|
fn find_game(exe: &WinPath, library: &[Game]) -> Option<GameId> {
|
||||||
|
let depth = exe.components().count();
|
||||||
|
let mut best: Option<(usize, &GameId)> = None;
|
||||||
|
for game in library {
|
||||||
|
let own_exe = matches!(&game.launch, Launch::Exe { exe: e, .. } if e.eq_ignore_case(exe));
|
||||||
|
let score = match &game.install_dir {
|
||||||
|
_ if own_exe => Some(usize::MAX),
|
||||||
|
Some(dir) => {
|
||||||
|
let d = dir.components().count();
|
||||||
|
(d > 0 && d < depth && exe.starts_with(dir)).then_some(d)
|
||||||
|
}
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
if let Some(s) = score
|
||||||
|
&& best.is_none_or(|(b, _)| s > b)
|
||||||
|
{
|
||||||
|
best = Some((s, &game.id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
best.map(|(_, id)| id.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The user's verdicts on single exes: `on` ("This is a game") and `off` ("This is not a game"), keyed by the
|
||||||
|
/// normalised path ignoring case. An exe is in at most one of the two; setting one clears the other.
|
||||||
|
///
|
||||||
|
/// Persisted in the agent's `overlay.json` as `{ "on": [paths], "off": [paths] }`, each sorted by the case-folded
|
||||||
|
/// path, first spelling kept. Loading also accepts a plain array of paths (the first 0.2.0 form), read as `on`.
|
||||||
|
/// Loading checks every path as a [`WinPath`], folds spellings of the same exe, refuses an exe in both lists
|
||||||
|
/// (`Duplicate("marks")`) and more than [`crate::limits::MAX_MARKS`] marks in all (`TooMany("marks")`).
|
||||||
|
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[serde(try_from = "MarksRepr", into = "MarksWire")]
|
||||||
|
pub struct Marks(BTreeMap<String, (WinPath, bool)>);
|
||||||
|
|
||||||
|
impl Marks {
|
||||||
|
/// No marks.
|
||||||
|
pub const fn new() -> Marks {
|
||||||
|
Marks(BTreeMap::new())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Marks `exe` as a game (`is_game`) or as not a game, replacing any earlier mark on it. `Ok(true)` when that
|
||||||
|
/// changed something, `Ok(false)` when the exe already had this mark (the first spelling stays),
|
||||||
|
/// `Err(TooMany("marks"))` for a new exe when [`crate::limits::MAX_MARKS`] exes are already marked.
|
||||||
|
pub fn set(&mut self, exe: WinPath, is_game: bool) -> Result<bool, ParseError> {
|
||||||
|
let key = exe.key();
|
||||||
|
if let Some(slot) = self.0.get_mut(&key) {
|
||||||
|
let changed = slot.1 != is_game;
|
||||||
|
slot.1 = is_game;
|
||||||
|
return Ok(changed);
|
||||||
|
}
|
||||||
|
if self.0.len() >= MAX_MARKS {
|
||||||
|
return Err(ParseError::TooMany("marks"));
|
||||||
|
}
|
||||||
|
self.0.insert(key, (exe, is_game));
|
||||||
|
Ok(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Removes any mark on `exe`, back to the automatic rules; true when there was one.
|
||||||
|
pub fn clear(&mut self, exe: &WinPath) -> bool {
|
||||||
|
self.0.remove(&exe.key()).is_some()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The mark on `exe`, in any spelling: `Some(true)` on, `Some(false)` off, `None` unmarked.
|
||||||
|
pub fn get(&self, exe: &WinPath) -> Option<bool> {
|
||||||
|
self.0.get(&exe.key()).map(|(_, on)| *on)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Shorthand for `set(exe, true)`: marks `exe` as a game.
|
||||||
|
pub fn insert(&mut self, exe: WinPath) -> Result<bool, ParseError> {
|
||||||
|
self.set(exe, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Removes an "on" mark from `exe`; true when it had one. An "off" mark stays.
|
||||||
|
pub fn remove(&mut self, exe: &WinPath) -> bool {
|
||||||
|
self.contains(exe) && self.clear(exe)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// True when `exe` is marked as a game.
|
||||||
|
pub fn contains(&self, exe: &WinPath) -> bool {
|
||||||
|
self.get(exe) == Some(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// True when `exe` is marked as not a game.
|
||||||
|
pub fn contains_off(&self, exe: &WinPath) -> bool {
|
||||||
|
self.get(exe) == Some(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The exes marked as games, sorted by the case-folded path.
|
||||||
|
pub fn on(&self) -> impl Iterator<Item = &WinPath> {
|
||||||
|
self.0.values().filter(|(_, on)| *on).map(|(p, _)| p)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The exes marked as not games, sorted by the case-folded path.
|
||||||
|
pub fn off(&self) -> impl Iterator<Item = &WinPath> {
|
||||||
|
self.0.values().filter(|(_, on)| !*on).map(|(p, _)| p)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Marks of both kinds.
|
||||||
|
pub fn len(&self) -> usize {
|
||||||
|
self.0.len()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
self.0.is_empty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// What `overlay.json` may hold: the current object, or a plain array (all `on`, the first 0.2.0 form).
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
enum MarksRepr {
|
||||||
|
Plain(Vec<WinPath>),
|
||||||
|
Split(MarksWire),
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The written form.
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
#[serde(deny_unknown_fields)]
|
||||||
|
struct MarksWire {
|
||||||
|
#[serde(default)]
|
||||||
|
on: Vec<WinPath>,
|
||||||
|
#[serde(default)]
|
||||||
|
off: Vec<WinPath>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<MarksRepr> for Marks {
|
||||||
|
type Error = ParseError;
|
||||||
|
|
||||||
|
fn try_from(repr: MarksRepr) -> Result<Self, Self::Error> {
|
||||||
|
let (on, off) = match repr {
|
||||||
|
MarksRepr::Plain(on) => (on, Vec::new()),
|
||||||
|
MarksRepr::Split(w) => (w.on, w.off),
|
||||||
|
};
|
||||||
|
let mut marks = Marks::new();
|
||||||
|
for p in on {
|
||||||
|
marks.set(p, true)?;
|
||||||
|
}
|
||||||
|
for p in off {
|
||||||
|
if marks.contains(&p) {
|
||||||
|
return Err(ParseError::Duplicate("marks"));
|
||||||
|
}
|
||||||
|
marks.set(p, false)?;
|
||||||
|
}
|
||||||
|
Ok(marks)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Marks> for MarksWire {
|
||||||
|
fn from(m: Marks) -> MarksWire {
|
||||||
|
let (on, off): (Vec<_>, Vec<_>) = m.0.into_values().partition(|(_, on)| *on);
|
||||||
|
MarksWire { on: on.into_iter().map(|(p, _)| p).collect(), off: off.into_iter().map(|(p, _)| p).collect() }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
|
|
||||||
//! Domi games: Atrium registry entries with `kind = "game"`, launched through their `domi-<app>://open` link, or
|
//! Domi games: Atrium registry entries with `kind = "game"`, launched through their `domi-<app>://open` link, or
|
||||||
//! web games (Rosea, Moin) opened by URL.
|
//! web games (Rosea, Moin) opened by URL.
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
|
|
||||||
//! Epic Games Launcher: one JSON `.item` manifest per installed app in
|
//! Epic Games Launcher: one JSON `.item` manifest per installed app in
|
||||||
//! `%ProgramData%\Epic\EpicGamesLauncher\Data\Manifests`. Launch is
|
//! `%ProgramData%\Epic\EpicGamesLauncher\Data\Manifests`. Launch is
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,119 @@
|
|||||||
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
|
|
||||||
|
//! Frametime statistics for the overlay's performance widget.
|
||||||
|
//!
|
||||||
|
//! Input: the frametimes of one window of play, in milliseconds, in the order the frames were presented (the
|
||||||
|
//! agent gets them from PresentMon). Output: [`FrameStats`]. Definitions:
|
||||||
|
//!
|
||||||
|
//! - **avg FPS** = frames / total time (`frames / seconds`), not the mean of per-frame FPS.
|
||||||
|
//! - **1 % low** and **0.1 % low** = the FPS of the frametime at the 99th and the 99.9th percentile
|
||||||
|
//! (`1000 / frametime_ms`). The percentile is nearest-rank: the frametimes sorted ascending, the value at rank
|
||||||
|
//! `ceil(p × frames)` (1-based). Each low is capped at avg FPS: when a few very long frames sit above the
|
||||||
|
//! percentile, the percentile frame can be faster than the average, and a "low" above the average would mislead.
|
||||||
|
//! So `low_0_1 <= low_1 <= avg_fps` always.
|
||||||
|
//! - **stutter** = a frametime ≥ 2.5 × the median of the 60 frames before it **and** ≥ 25 ms. Both bounds are
|
||||||
|
//! inclusive. The first 60 frames have no full history and are never stutters. The median of the 60 is the mean
|
||||||
|
//! of the 30th and 31st smallest.
|
||||||
|
//!
|
||||||
|
//! Refused (`None`): an empty series, more than [`crate::limits::MAX_FRAMES`] frametimes, any NaN, infinite or
|
||||||
|
//! negative frametime, and a series with no time in it (all zero). A zero frametime is allowed (`-0.0` counts as
|
||||||
|
//! zero); it only adds a frame.
|
||||||
|
|
||||||
|
use crate::limits::MAX_FRAMES;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
/// Frames of history the stutter rule looks back over.
|
||||||
|
const STUTTER_WINDOW: usize = 60;
|
||||||
|
/// A stutter is at least this many times the median of the window ...
|
||||||
|
const STUTTER_RATIO: f64 = 2.5;
|
||||||
|
/// ... and at least this long, in milliseconds.
|
||||||
|
const STUTTER_MIN_MS: f64 = 25.0;
|
||||||
|
|
||||||
|
/// Statistics over one series of frametimes; see the [module docs](self) for the definitions.
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
|
||||||
|
pub struct FrameStats {
|
||||||
|
/// Frames per second over the whole series: `frames / seconds`.
|
||||||
|
pub avg_fps: f64,
|
||||||
|
/// The 1 % low: the FPS of the 99th-percentile frametime, at most `avg_fps`.
|
||||||
|
pub low_1: f64,
|
||||||
|
/// The 0.1 % low: the FPS of the 99.9th-percentile frametime, at most `low_1`.
|
||||||
|
pub low_0_1: f64,
|
||||||
|
/// How many frames were stutters.
|
||||||
|
pub stutters: u32,
|
||||||
|
/// How many frametimes the series had.
|
||||||
|
pub frames: u32,
|
||||||
|
/// The sum of the frametimes, in seconds.
|
||||||
|
pub seconds: f64,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The statistics of `frametimes_ms`, or `None` when the series is refused (see the [module docs](self)).
|
||||||
|
pub fn stats(frametimes_ms: &[f32]) -> Option<FrameStats> {
|
||||||
|
let n = frametimes_ms.len();
|
||||||
|
if n == 0 || n > MAX_FRAMES {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
if frametimes_ms.iter().any(|f| !f.is_finite() || *f < 0.0) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let frames = u32::try_from(n).ok()?;
|
||||||
|
let total_ms: f64 = frametimes_ms.iter().map(|&f| f64::from(f)).sum();
|
||||||
|
if total_ms <= 0.0 || !total_ms.is_finite() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let seconds = total_ms / 1000.0;
|
||||||
|
let avg_fps = f64::from(frames) / seconds;
|
||||||
|
|
||||||
|
let mut sorted = frametimes_ms.to_vec();
|
||||||
|
sorted.sort_unstable_by(f32::total_cmp);
|
||||||
|
let low_1 = fps(percentile(&sorted, 99, 100)?).min(avg_fps);
|
||||||
|
let low_0_1 = fps(percentile(&sorted, 999, 1000)?).min(low_1);
|
||||||
|
|
||||||
|
let stats = FrameStats { avg_fps, low_1, low_0_1, stutters: stutters(frametimes_ms), frames, seconds };
|
||||||
|
[stats.avg_fps, stats.low_1, stats.low_0_1, stats.seconds].iter().all(|v| v.is_finite()).then_some(stats)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The FPS of one frametime; a zero frametime is infinitely fast (then capped by the caller).
|
||||||
|
fn fps(frametime_ms: f32) -> f64 {
|
||||||
|
let ms = f64::from(frametime_ms);
|
||||||
|
if ms > 0.0 { 1000.0 / ms } else { f64::INFINITY }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Nearest-rank percentile `num / den` of an ascending, non-empty slice: the value at rank `ceil(n × num / den)`.
|
||||||
|
/// Integer arithmetic, so 99 % of 100 frames is exactly rank 99.
|
||||||
|
fn percentile(sorted: &[f32], num: u64, den: u64) -> Option<f32> {
|
||||||
|
let n = u64::try_from(sorted.len()).ok()?;
|
||||||
|
let rank = (n * num).div_ceil(den).max(1);
|
||||||
|
sorted.get(usize::try_from(rank - 1).ok()?).copied()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Counts stutters with a sorted sliding window of the previous [`STUTTER_WINDOW`] frametimes.
|
||||||
|
fn stutters(frametimes_ms: &[f32]) -> u32 {
|
||||||
|
let mut window: Vec<f32> = Vec::with_capacity(STUTTER_WINDOW + 1);
|
||||||
|
let mut count: u32 = 0;
|
||||||
|
for (i, &ft) in frametimes_ms.iter().enumerate() {
|
||||||
|
if window.len() == STUTTER_WINDOW {
|
||||||
|
let ms = f64::from(ft);
|
||||||
|
if ms >= STUTTER_MIN_MS && median(&window).is_some_and(|m| ms >= STUTTER_RATIO * m) {
|
||||||
|
count = count.saturating_add(1);
|
||||||
|
}
|
||||||
|
// Slide: drop the frame that leaves the window.
|
||||||
|
if let Some(&old) = i.checked_sub(STUTTER_WINDOW).and_then(|j| frametimes_ms.get(j))
|
||||||
|
&& let Ok(at) = window.binary_search_by(|w| w.total_cmp(&old))
|
||||||
|
{
|
||||||
|
window.remove(at);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let at = window.partition_point(|w| w.total_cmp(&ft).is_lt());
|
||||||
|
window.insert(at, ft);
|
||||||
|
}
|
||||||
|
count
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The median of an ascending window of even length: the mean of the two middle values.
|
||||||
|
fn median(sorted: &[f32]) -> Option<f64> {
|
||||||
|
let half = sorted.len() / 2;
|
||||||
|
let lo = f64::from(*sorted.get(half.checked_sub(1)?)?);
|
||||||
|
let hi = f64::from(*sorted.get(half)?);
|
||||||
|
Some((lo + hi) / 2.0)
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
|
|
||||||
//! GOG: the app reads one registry key per installed game (assumption, verify on the PC:
|
//! GOG: the app reads one registry key per installed game (assumption, verify on the PC:
|
||||||
//! `HKLM\SOFTWARE\WOW6432Node\GOG.com\Games\<gameID>` with the values `gameID`, `gameName`, `path`, `exe`,
|
//! `HKLM\SOFTWARE\WOW6432Node\GOG.com\Games\<gameID>` with the values `gameID`, `gameName`, `path`, `exe`,
|
||||||
|
|||||||
@@ -0,0 +1,269 @@
|
|||||||
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
|
|
||||||
|
//! The overlay shortcut: `Ctrl+Shift+G` and friends, as text in `settings.json` and as Win32 values.
|
||||||
|
//!
|
||||||
|
//! Grammar: modifiers then one key, joined by `+`; spaces around each part are ignored; names ignore case.
|
||||||
|
//!
|
||||||
|
//! - Modifiers: `Ctrl`, `Alt`, `Shift`, `Win`, each at most once, in any order.
|
||||||
|
//! - Key (last): a letter `A`–`Z`, a digit `0`–`9`, or `F1`–`F24` (no leading zero).
|
||||||
|
//!
|
||||||
|
//! Refused:
|
||||||
|
//!
|
||||||
|
//! - A letter or digit with no modifier, or with Shift alone: that is typing, not a shortcut
|
||||||
|
//! ([`HotkeyError::NoModifier`]). A function key alone is allowed.
|
||||||
|
//! - Keys Windows reserves ([`HotkeyError::Reserved`]): `Ctrl+Alt+Del` (the secure attention sequence, with any
|
||||||
|
//! other modifiers too), `Ctrl+Shift+Esc` (Task Manager), `Win+L` (lock), `Alt+F4` (closes the active window) and
|
||||||
|
//! `F12` with any modifiers (Windows keeps it for the debugger, so `RegisterHotKey` must not take it).
|
||||||
|
//! `Del` and `Esc` are recognised only to name these; they are not keys a shortcut may use.
|
||||||
|
//!
|
||||||
|
//! [`Display`](std::fmt::Display) writes the canonical form: `Ctrl`, `Alt`, `Shift`, `Win` in that order, then the
|
||||||
|
//! key, uppercase, so `parse(&h.to_string()) == Ok(h)`. Whether Windows lets Arena register a valid shortcut (it
|
||||||
|
//! may be taken, as `Win+G` is by the Game Bar) is only known at `RegisterHotKey` time, in the agent.
|
||||||
|
|
||||||
|
use crate::limits::MAX_HOTKEY;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::fmt;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
/// The modifier keys of a shortcut.
|
||||||
|
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
|
pub struct Modifiers {
|
||||||
|
pub ctrl: bool,
|
||||||
|
pub alt: bool,
|
||||||
|
pub shift: bool,
|
||||||
|
pub win: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The non-modifier key of a shortcut. [`Hotkey::new`] checks the value: `Letter` holds `'A'..='Z'`, `Digit`
|
||||||
|
/// `0..=9`, `F` `1..=24`.
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
|
pub enum Key {
|
||||||
|
Letter(char),
|
||||||
|
Digit(u8),
|
||||||
|
F(u8),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Key {
|
||||||
|
fn is_valid(self) -> bool {
|
||||||
|
match self {
|
||||||
|
Key::Letter(c) => c.is_ascii_uppercase(),
|
||||||
|
Key::Digit(d) => d <= 9,
|
||||||
|
Key::F(n) => (1..=24).contains(&n),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The Win32 virtual-key code (`VK_*`): `0x41`–`0x5A` for letters, `0x30`–`0x39` for digits, `0x70`–`0x87`
|
||||||
|
/// for `F1`–`F24`.
|
||||||
|
fn virtual_key(self) -> u32 {
|
||||||
|
match self {
|
||||||
|
Key::Letter(c) => u32::from(c),
|
||||||
|
Key::Digit(d) => 0x30 + u32::from(d),
|
||||||
|
Key::F(n) => 0x6F + u32::from(n),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A checked overlay shortcut; see the [module docs](self). The default is `Ctrl+Shift+G`.
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
|
||||||
|
#[serde(try_from = "String", into = "String")]
|
||||||
|
pub struct Hotkey {
|
||||||
|
modifiers: Modifiers,
|
||||||
|
key: Key,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Why a shortcut was refused. Never carries input text.
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
|
pub enum HotkeyError {
|
||||||
|
/// Nothing but spaces.
|
||||||
|
Empty,
|
||||||
|
/// Longer than [`crate::limits::MAX_HOTKEY`] bytes.
|
||||||
|
TooLong,
|
||||||
|
/// An empty part: a leading, trailing or doubled `+`.
|
||||||
|
Malformed,
|
||||||
|
/// A part before the key is not `Ctrl`, `Alt`, `Shift` or `Win`.
|
||||||
|
UnknownModifier,
|
||||||
|
/// The same modifier twice.
|
||||||
|
DuplicateModifier,
|
||||||
|
/// Only modifiers, no key.
|
||||||
|
MissingKey,
|
||||||
|
/// The key is not a letter, a digit or `F1`–`F24`.
|
||||||
|
UnknownKey,
|
||||||
|
/// A letter or digit without Ctrl, Alt or Win.
|
||||||
|
NoModifier,
|
||||||
|
/// A combination Windows keeps for itself.
|
||||||
|
Reserved,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for HotkeyError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
f.write_str(match self {
|
||||||
|
HotkeyError::Empty => "the shortcut is empty",
|
||||||
|
HotkeyError::TooLong => "the shortcut is too long",
|
||||||
|
HotkeyError::Malformed => "the shortcut has an empty part",
|
||||||
|
HotkeyError::UnknownModifier => "modifiers are Ctrl, Alt, Shift and Win",
|
||||||
|
HotkeyError::DuplicateModifier => "a modifier appears twice",
|
||||||
|
HotkeyError::MissingKey => "the shortcut has no key",
|
||||||
|
HotkeyError::UnknownKey => "the key must be a letter, a digit or F1 to F24",
|
||||||
|
HotkeyError::NoModifier => "a letter or digit needs Ctrl, Alt or Win",
|
||||||
|
HotkeyError::Reserved => "Windows reserves this shortcut",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for HotkeyError {}
|
||||||
|
|
||||||
|
impl Hotkey {
|
||||||
|
/// Checks a shortcut built from parts, with the same rules as [`parse`].
|
||||||
|
pub fn new(modifiers: Modifiers, key: Key) -> Result<Hotkey, HotkeyError> {
|
||||||
|
if !key.is_valid() {
|
||||||
|
return Err(HotkeyError::UnknownKey);
|
||||||
|
}
|
||||||
|
let bare = matches!(key, Key::Letter(_) | Key::Digit(_));
|
||||||
|
if bare && !(modifiers.ctrl || modifiers.alt || modifiers.win) {
|
||||||
|
return Err(HotkeyError::NoModifier);
|
||||||
|
}
|
||||||
|
let only = |m: Modifiers| modifiers == m;
|
||||||
|
let none = Modifiers::default();
|
||||||
|
let reserved = key == Key::F(12)
|
||||||
|
|| (key == Key::Letter('L') && only(Modifiers { win: true, ..none }))
|
||||||
|
|| (key == Key::F(4) && only(Modifiers { alt: true, ..none }));
|
||||||
|
if reserved {
|
||||||
|
return Err(HotkeyError::Reserved);
|
||||||
|
}
|
||||||
|
Ok(Hotkey { modifiers, key })
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn modifiers(&self) -> Modifiers {
|
||||||
|
self.modifiers
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn key(&self) -> Key {
|
||||||
|
self.key
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The `fsModifiers` for `RegisterHotKey`: `MOD_ALT` 0x1, `MOD_CONTROL` 0x2, `MOD_SHIFT` 0x4, `MOD_WIN` 0x8.
|
||||||
|
/// (`MOD_NOREPEAT` is the caller's choice.)
|
||||||
|
pub fn win32_modifiers(&self) -> u32 {
|
||||||
|
let m = self.modifiers;
|
||||||
|
u32::from(m.alt) | (u32::from(m.ctrl) << 1) | (u32::from(m.shift) << 2) | (u32::from(m.win) << 3)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The `vk` for `RegisterHotKey`.
|
||||||
|
pub fn virtual_key(&self) -> u32 {
|
||||||
|
self.key.virtual_key()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Hotkey {
|
||||||
|
/// `Ctrl+Shift+G`.
|
||||||
|
fn default() -> Hotkey {
|
||||||
|
Hotkey { modifiers: Modifiers { ctrl: true, alt: false, shift: true, win: false }, key: Key::Letter('G') }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parses a shortcut such as `"Ctrl+Shift+G"`; see the [module docs](self) for the grammar and refusals.
|
||||||
|
pub fn parse(s: &str) -> Result<Hotkey, HotkeyError> {
|
||||||
|
if s.len() > MAX_HOTKEY {
|
||||||
|
return Err(HotkeyError::TooLong);
|
||||||
|
}
|
||||||
|
if s.trim_matches(' ').is_empty() {
|
||||||
|
return Err(HotkeyError::Empty);
|
||||||
|
}
|
||||||
|
let mut parts: Vec<&str> = s.split('+').map(|p| p.trim_matches(' ')).collect();
|
||||||
|
if parts.iter().any(|p| p.is_empty()) {
|
||||||
|
return Err(HotkeyError::Malformed);
|
||||||
|
}
|
||||||
|
let key = parts.pop().ok_or(HotkeyError::Empty)?;
|
||||||
|
let mut m = Modifiers::default();
|
||||||
|
for part in parts {
|
||||||
|
let slot = modifier(&mut m, part).ok_or(HotkeyError::UnknownModifier)?;
|
||||||
|
if *slot {
|
||||||
|
return Err(HotkeyError::DuplicateModifier);
|
||||||
|
}
|
||||||
|
*slot = true;
|
||||||
|
}
|
||||||
|
if modifier(&mut Modifiers::default(), key).is_some() {
|
||||||
|
return Err(HotkeyError::MissingKey);
|
||||||
|
}
|
||||||
|
// Named only to refuse them as reserved.
|
||||||
|
let ci = |name: &str| key.eq_ignore_ascii_case(name);
|
||||||
|
if ((ci("Del") || ci("Delete")) && m.ctrl && m.alt) || ((ci("Esc") || ci("Escape")) && m.ctrl && m.shift) {
|
||||||
|
return Err(HotkeyError::Reserved);
|
||||||
|
}
|
||||||
|
Hotkey::new(m, parse_key(key).ok_or(HotkeyError::UnknownKey)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The flag in `m` that `name` sets, if it names a modifier.
|
||||||
|
fn modifier<'a>(m: &'a mut Modifiers, name: &str) -> Option<&'a mut bool> {
|
||||||
|
let ci = |n: &str| name.eq_ignore_ascii_case(n);
|
||||||
|
if ci("Ctrl") {
|
||||||
|
Some(&mut m.ctrl)
|
||||||
|
} else if ci("Alt") {
|
||||||
|
Some(&mut m.alt)
|
||||||
|
} else if ci("Shift") {
|
||||||
|
Some(&mut m.shift)
|
||||||
|
} else if ci("Win") {
|
||||||
|
Some(&mut m.win)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_key(s: &str) -> Option<Key> {
|
||||||
|
let mut chars = s.chars();
|
||||||
|
let first = chars.next()?;
|
||||||
|
let rest = chars.as_str();
|
||||||
|
if rest.is_empty() {
|
||||||
|
return if first.is_ascii_alphabetic() {
|
||||||
|
Some(Key::Letter(first.to_ascii_uppercase()))
|
||||||
|
} else {
|
||||||
|
first.to_digit(10).and_then(|d| u8::try_from(d).ok()).map(Key::Digit)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
let canonical = !rest.starts_with('0') && rest.len() <= 2 && rest.bytes().all(|b| b.is_ascii_digit());
|
||||||
|
if !first.eq_ignore_ascii_case(&'F') || !canonical {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let n: u8 = rest.parse().ok()?;
|
||||||
|
(1..=24).contains(&n).then_some(Key::F(n))
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Hotkey {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
let m = self.modifiers;
|
||||||
|
for (on, name) in [(m.ctrl, "Ctrl"), (m.alt, "Alt"), (m.shift, "Shift"), (m.win, "Win")] {
|
||||||
|
if on {
|
||||||
|
write!(f, "{name}+")?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match self.key {
|
||||||
|
Key::Letter(c) => write!(f, "{c}"),
|
||||||
|
Key::Digit(d) => write!(f, "{d}"),
|
||||||
|
Key::F(n) => write!(f, "F{n}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for Hotkey {
|
||||||
|
type Err = HotkeyError;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
parse(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<String> for Hotkey {
|
||||||
|
type Error = HotkeyError;
|
||||||
|
|
||||||
|
fn try_from(s: String) -> Result<Self, Self::Error> {
|
||||||
|
parse(&s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Hotkey> for String {
|
||||||
|
fn from(h: Hotkey) -> String {
|
||||||
|
h.to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
|
|
||||||
use crate::error::ParseError;
|
use crate::error::ParseError;
|
||||||
use crate::limits::{MAX_GAME_ID, MAX_GOG_ID};
|
use crate::limits::{MAX_GAME_ID, MAX_GOG_ID};
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
|
|
||||||
use crate::error::ParseError;
|
use crate::error::ParseError;
|
||||||
use crate::limits::{MAX_ARG, MAX_ARGS, MAX_ARGS_LINE, MAX_HOST, MAX_URL};
|
use crate::limits::{MAX_ARG, MAX_ARGS, MAX_ARGS_LINE, MAX_HOST, MAX_URL};
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
|
|
||||||
//! The pure core of Arena Domi: strict parsers for game launcher files and the game library model.
|
//! The pure core of Arena Domi: strict parsers for game launcher files and the game library model.
|
||||||
//!
|
//!
|
||||||
@@ -14,6 +13,9 @@
|
|||||||
//! registry). [`merge`] dedupes the scans into one library.
|
//! registry). [`merge`] dedupes the scans into one library.
|
||||||
//!
|
//!
|
||||||
//! Launch strings are built by [`Launch::uri`] only from validated, parsed fields.
|
//! Launch strings are built by [`Launch::uri`] only from validated, parsed fields.
|
||||||
|
//!
|
||||||
|
//! For the overlay agent: [`frames`] (frametime statistics: average FPS, 1 % and 0.1 % lows, stutters), [`detect`]
|
||||||
|
//! (which running exe is a game, and the user's "This is a game" marks) and [`hotkey`] (the overlay shortcut).
|
||||||
|
|
||||||
#![forbid(unsafe_code)]
|
#![forbid(unsafe_code)]
|
||||||
#![deny(
|
#![deny(
|
||||||
@@ -36,6 +38,10 @@ mod path;
|
|||||||
mod text;
|
mod text;
|
||||||
pub mod vdf;
|
pub mod vdf;
|
||||||
|
|
||||||
|
pub mod detect;
|
||||||
|
pub mod frames;
|
||||||
|
pub mod hotkey;
|
||||||
|
|
||||||
pub mod domi;
|
pub mod domi;
|
||||||
pub mod epic;
|
pub mod epic;
|
||||||
pub mod gog;
|
pub mod gog;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
|
|
||||||
//! Every cap the parsers enforce. Anything over a cap is refused, never truncated. `docs/FORMATS.md` lists them
|
//! Every cap the parsers enforce. Anything over a cap is refused, never truncated. `docs/FORMATS.md` lists them
|
||||||
//! with the error each one gives.
|
//! with the error each one gives.
|
||||||
@@ -43,3 +42,9 @@ pub const MAX_URL: usize = 2048;
|
|||||||
pub const MAX_HOST: usize = 253;
|
pub const MAX_HOST: usize = 253;
|
||||||
/// Most games one [`crate::merge`] call accepts over all scans; the rest are dropped.
|
/// Most games one [`crate::merge`] call accepts over all scans; the rest are dropped.
|
||||||
pub const MAX_GAMES: usize = 100_000;
|
pub const MAX_GAMES: usize = 100_000;
|
||||||
|
/// Most frametimes one [`crate::frames::stats`] call accepts (about 73 minutes at 240 FPS); more is refused.
|
||||||
|
pub const MAX_FRAMES: usize = 1 << 20;
|
||||||
|
/// Most exes the user may mark as games ([`crate::detect::Marks`]).
|
||||||
|
pub const MAX_MARKS: usize = 4096;
|
||||||
|
/// Longest shortcut text [`crate::hotkey::parse`] accepts, in bytes (`Ctrl+Alt+Shift+Win+F24` is 22).
|
||||||
|
pub const MAX_HOTKEY: usize = 64;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
|
|
||||||
//! A game the user added by picking its `.exe`.
|
//! A game the user added by picking its `.exe`.
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
|
|
||||||
use crate::error::ParseError;
|
use crate::error::ParseError;
|
||||||
use crate::id::{GameId, Source};
|
use crate::id::{GameId, Source};
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
|
|
||||||
use crate::error::ParseError;
|
use crate::error::ParseError;
|
||||||
use crate::limits::MAX_PATH;
|
use crate::limits::MAX_PATH;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
|
|
||||||
//! Steam: `config/libraryfolders.vdf` lists the library folders; each installed app has
|
//! Steam: `config/libraryfolders.vdf` lists the library folders; each installed app has
|
||||||
//! `<library>/steamapps/appmanifest_<id>.acf`. Launch is `steam://rungameid/<id>`.
|
//! `<library>/steamapps/appmanifest_<id>.acf`. Launch is `steam://rungameid/<id>`.
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
|
|
||||||
//! Small shared checks: titles, ids, numbers, a stable hash, the lettered cover.
|
//! Small shared checks: titles, ids, numbers, a stable hash, the lettered cover.
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
|
|
||||||
//! A strict tokenizer, parser and writer for Valve's KeyValues text format (VDF), as used by Steam's
|
//! A strict tokenizer, parser and writer for Valve's KeyValues text format (VDF), as used by Steam's
|
||||||
//! `libraryfolders.vdf` and `appmanifest_<id>.acf`.
|
//! `libraryfolders.vdf` and `appmanifest_<id>.acf`.
|
||||||
|
|||||||
@@ -0,0 +1,405 @@
|
|||||||
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
|
|
||||||
|
//! Game detection for the overlay: the three rules, Windows path matching, and the persisted marks.
|
||||||
|
|
||||||
|
use arena_core::detect::{Detection, How, Marks, detect};
|
||||||
|
use arena_core::{Game, GameId, Launch, ParseError, Source, WinPath, limits, manual};
|
||||||
|
use proptest::prelude::*;
|
||||||
|
|
||||||
|
fn p(s: &str) -> WinPath {
|
||||||
|
WinPath::parse(s).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn steam(app: u32, title: &str, dir: &str) -> Game {
|
||||||
|
let id = GameId::new(Source::Steam, &app.to_string()).unwrap();
|
||||||
|
Game {
|
||||||
|
id,
|
||||||
|
source: Source::Steam,
|
||||||
|
title: title.into(),
|
||||||
|
install_dir: Some(p(dir)),
|
||||||
|
launch: Launch::steam(app).unwrap(),
|
||||||
|
cover: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn domi(app: &str) -> Game {
|
||||||
|
Game {
|
||||||
|
id: GameId::new(Source::Domi, app).unwrap(),
|
||||||
|
source: Source::Domi,
|
||||||
|
title: app.into(),
|
||||||
|
install_dir: None,
|
||||||
|
launch: Launch::domi_link(app).unwrap(),
|
||||||
|
cover: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn library() -> Vec<Game> {
|
||||||
|
vec![
|
||||||
|
steam(10, "Foo", r"C:\Games\Foo"),
|
||||||
|
steam(20, "FooBar", r"C:\Games\FooBar"),
|
||||||
|
steam(30, "Nested", r"C:\Games\Foo\Expansion"),
|
||||||
|
domi("lapilli"),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn id(s: &str) -> Option<GameId> {
|
||||||
|
Some(s.parse().unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn found(game: &str, how: How) -> Option<Detection> {
|
||||||
|
Some(Detection { game: id(game), how })
|
||||||
|
}
|
||||||
|
|
||||||
|
const NONE: &Marks = &Marks::new();
|
||||||
|
|
||||||
|
// --- an exe outside every install_dir is never auto-detected ---
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn outside_every_install_dir_is_not_detected() {
|
||||||
|
let lib = library();
|
||||||
|
for exe in [
|
||||||
|
r"C:\Windows\System32\notepad.exe",
|
||||||
|
r"C:\Games\foo.exe",
|
||||||
|
r"C:\Games\Fo\game.exe",
|
||||||
|
r"C:\Games\FooBarBaz\game.exe",
|
||||||
|
r"C:\Games\Foo Bar\game.exe",
|
||||||
|
r"D:\Games\Foo\game.exe",
|
||||||
|
r"C:\Program Files\Steam\steam.exe",
|
||||||
|
] {
|
||||||
|
assert_eq!(detect(&p(exe), false, &lib, NONE), None, "{exe}");
|
||||||
|
}
|
||||||
|
assert_eq!(detect(&p(r"C:\x.exe"), false, &[], NONE), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn inside_an_install_dir_is_detected() {
|
||||||
|
let lib = library();
|
||||||
|
assert_eq!(detect(&p(r"C:\Games\Foo\foo.exe"), false, &lib, NONE), found("steam:10", How::InstallDir));
|
||||||
|
assert_eq!(detect(&p(r"C:\Games\Foo\bin\x64\foo.exe"), false, &lib, NONE), found("steam:10", How::InstallDir));
|
||||||
|
assert_eq!(detect(&p(r"C:\Games\FooBar\fb.exe"), false, &lib, NONE), found("steam:20", How::InstallDir));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn prefix_of_a_segment_never_matches() {
|
||||||
|
// C:\Games\Foo must not claim C:\Games\FooBar's exes, in either direction, whatever the order.
|
||||||
|
let only_foo = vec![steam(10, "Foo", r"C:\Games\Foo")];
|
||||||
|
assert_eq!(detect(&p(r"C:\Games\FooBar\fb.exe"), false, &only_foo, NONE), None);
|
||||||
|
let only_foobar = vec![steam(20, "FooBar", r"C:\Games\FooBar")];
|
||||||
|
assert_eq!(detect(&p(r"C:\Games\Foo\foo.exe"), false, &only_foobar, NONE), None);
|
||||||
|
assert_eq!(detect(&p(r"C:\Games\Foo.exe"), false, &only_foo, NONE), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_deepest_install_dir_wins() {
|
||||||
|
let lib = library();
|
||||||
|
let exe = p(r"C:\Games\Foo\Expansion\exp.exe");
|
||||||
|
assert_eq!(detect(&exe, false, &lib, NONE), found("steam:30", How::InstallDir));
|
||||||
|
let mut rev = lib.clone();
|
||||||
|
rev.reverse();
|
||||||
|
assert_eq!(detect(&exe, false, &rev, NONE), found("steam:30", How::InstallDir));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_install_dir_itself_is_not_an_exe_inside_it() {
|
||||||
|
let lib = library();
|
||||||
|
assert_eq!(detect(&p(r"C:\Games\FooBar"), false, &lib, NONE), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_drive_root_install_dir_does_not_claim_the_whole_drive() {
|
||||||
|
// A manual game picked at D:\game.exe has the install folder D:\ — that must not make every exe on D: a game.
|
||||||
|
let g = manual::game(r"D:\game.exe", Some("Root game")).unwrap();
|
||||||
|
assert_eq!(g.install_dir, Some(p(r"D:\")));
|
||||||
|
let lib = vec![g.clone()];
|
||||||
|
assert_eq!(detect(&p(r"D:\Tools\editor.exe"), false, &lib, NONE), None);
|
||||||
|
assert_eq!(detect(&p(r"D:\other.exe"), false, &lib, NONE), None);
|
||||||
|
// Its own exe is still found, through the game's launch exe.
|
||||||
|
assert_eq!(
|
||||||
|
detect(&p(r"d:\GAME.EXE"), false, &lib, NONE),
|
||||||
|
Some(Detection { game: Some(g.id), how: How::InstallDir })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_game_s_own_launch_exe_is_detected() {
|
||||||
|
let g = manual::game(r"E:\Old\Thing\thing.exe", None).unwrap();
|
||||||
|
let lib = vec![g.clone()];
|
||||||
|
assert_eq!(detect(&p(r"E:\Old\Thing\thing.exe"), false, &lib, NONE).map(|d| d.how), Some(How::InstallDir));
|
||||||
|
assert_eq!(detect(&p(r"E:\Old\Thing\helper.exe"), false, &lib, NONE).and_then(|d| d.game), Some(g.id));
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Windows path rules ---
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn matching_ignores_case_and_separator_style() {
|
||||||
|
let lib = library();
|
||||||
|
for exe in [r"c:\games\foo\foo.exe", r"C:\GAMES\FOO\FOO.EXE", "C:/Games/foo/Bin/foo.exe", r"c:\\Games\\\Foo\\x.exe"]
|
||||||
|
{
|
||||||
|
assert_eq!(detect(&p(exe), false, &lib, NONE), found("steam:10", How::InstallDir), "{exe}");
|
||||||
|
}
|
||||||
|
let upper = vec![steam(10, "Foo", r"C:\GAMES\FOO")];
|
||||||
|
assert_eq!(detect(&p(r"c:\games\foo\a.exe"), false, &upper, NONE), found("steam:10", How::InstallDir));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn non_ascii_case_folds_too() {
|
||||||
|
let lib = vec![steam(40, "Hra", r"C:\Hry\Žluťoučký Kůň")];
|
||||||
|
assert_eq!(detect(&p(r"C:\HRY\ŽLUŤOUČKÝ KŮŇ\kun.exe"), false, &lib, NONE), found("steam:40", How::InstallDir));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn dot_dot_never_escapes() {
|
||||||
|
// A path with `..` cannot even be built, so `C:\Games\Foo\..\Other\x.exe` can never pass as inside Foo.
|
||||||
|
for s in [
|
||||||
|
r"C:\Games\Foo\..\Other\x.exe",
|
||||||
|
r"C:\Games\Foo\..\..\Windows\x.exe",
|
||||||
|
r"C:\Games\Foo\.\x.exe",
|
||||||
|
r"C:\Games\Foo.\x.exe",
|
||||||
|
r"C:\Games\Foo \x.exe",
|
||||||
|
r"\\?\C:\Games\Foo\x.exe",
|
||||||
|
r"\\server\share\Games\Foo\x.exe",
|
||||||
|
] {
|
||||||
|
assert!(WinPath::parse(s).is_err(), "{s}");
|
||||||
|
}
|
||||||
|
// Nor can a mark or a game folder carry one in through JSON.
|
||||||
|
assert!(serde_json::from_str::<Marks>(r#"["C:\\Games\\Foo\\..\\x.exe"]"#).is_err());
|
||||||
|
// An exe in a sibling folder is not inside, even if a join tried to climb.
|
||||||
|
assert!(p(r"C:\Games\Foo").join(r"..\FooBar\fb.exe").is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- launched by Arena ---
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn launched_by_arena_is_always_detected() {
|
||||||
|
let lib = library();
|
||||||
|
assert_eq!(detect(&p(r"C:\Games\Foo\foo.exe"), true, &lib, NONE), found("steam:10", How::Launched));
|
||||||
|
// Outside every install dir (a launcher stub, a Domi app): still a game, the window says which.
|
||||||
|
assert_eq!(
|
||||||
|
detect(&p(r"C:\Users\u\AppData\Local\Lapilli\lapilli.exe"), true, &lib, NONE),
|
||||||
|
Some(Detection { game: None, how: How::Launched })
|
||||||
|
);
|
||||||
|
assert_eq!(detect(&p(r"C:\x.exe"), true, &[], NONE), Some(Detection { game: None, how: How::Launched }));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn launched_beats_marked() {
|
||||||
|
let mut marks = Marks::new();
|
||||||
|
marks.insert(p(r"C:\Games\Foo\foo.exe")).unwrap();
|
||||||
|
assert_eq!(detect(&p(r"C:\Games\Foo\foo.exe"), true, &library(), &marks).map(|d| d.how), Some(How::Launched));
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- marked on ("This is a game") ---
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn marked_exe_outside_install_dirs_is_detected_without_a_game() {
|
||||||
|
let mut marks = Marks::new();
|
||||||
|
assert!(marks.insert(p(r"D:\Emulators\retro.exe")).unwrap());
|
||||||
|
let lib = library();
|
||||||
|
assert_eq!(
|
||||||
|
detect(&p(r"D:\Emulators\retro.exe"), false, &lib, &marks),
|
||||||
|
Some(Detection { game: None, how: How::Marked })
|
||||||
|
);
|
||||||
|
assert_eq!(detect(&p(r"d:\emulators\RETRO.exe"), false, &lib, &marks).map(|d| d.how), Some(How::Marked));
|
||||||
|
// Only that exe: not its folder, not its neighbours.
|
||||||
|
assert_eq!(detect(&p(r"D:\Emulators\other.exe"), false, &lib, &marks), None);
|
||||||
|
assert_eq!(detect(&p(r"D:\Emulators\retro.exe\x.exe"), false, &lib, &marks), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn marked_on_inside_an_install_dir_is_marked_and_names_the_game() {
|
||||||
|
let mut marks = Marks::new();
|
||||||
|
marks.insert(p(r"C:\Games\Foo\foo.exe")).unwrap();
|
||||||
|
assert_eq!(detect(&p(r"C:\Games\Foo\foo.exe"), false, &library(), &marks), found("steam:10", How::Marked));
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- marked off ("This is not a game") ---
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn marked_off_is_never_auto_detected() {
|
||||||
|
let lib = library();
|
||||||
|
let mut marks = Marks::new();
|
||||||
|
// A crash reporter inside a game's folder would be found by its install folder ...
|
||||||
|
let reporter = p(r"C:\Games\Foo\CrashReporter.exe");
|
||||||
|
assert_eq!(detect(&reporter, false, &lib, NONE), found("steam:10", How::InstallDir));
|
||||||
|
// ... until the user says it is not a game, in any spelling.
|
||||||
|
assert!(marks.set(p("c:/games/foo/crashreporter.EXE"), false).unwrap());
|
||||||
|
assert!(marks.contains_off(&reporter));
|
||||||
|
assert!(!marks.contains(&reporter));
|
||||||
|
assert_eq!(marks.get(&reporter), Some(false));
|
||||||
|
assert_eq!(detect(&reporter, false, &lib, &marks), None);
|
||||||
|
// Only that exe: the game next to it is still found.
|
||||||
|
assert_eq!(detect(&p(r"C:\Games\Foo\foo.exe"), false, &lib, &marks), found("steam:10", How::InstallDir));
|
||||||
|
// A game's own launch exe can be switched off too.
|
||||||
|
let g = manual::game(r"E:\Old\thing.exe", None).unwrap();
|
||||||
|
let mut m2 = Marks::new();
|
||||||
|
m2.set(p(r"E:\Old\thing.exe"), false).unwrap();
|
||||||
|
assert_eq!(detect(&p(r"E:\Old\thing.exe"), false, &[g], &m2), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn launched_by_arena_beats_marked_off() {
|
||||||
|
let mut marks = Marks::new();
|
||||||
|
marks.set(p(r"C:\Games\Foo\foo.exe"), false).unwrap();
|
||||||
|
marks.set(p(r"C:\Elsewhere\stub.exe"), false).unwrap();
|
||||||
|
assert_eq!(detect(&p(r"C:\Games\Foo\foo.exe"), true, &library(), &marks), found("steam:10", How::Launched));
|
||||||
|
assert_eq!(
|
||||||
|
detect(&p(r"C:\Elsewhere\stub.exe"), true, &library(), &marks),
|
||||||
|
Some(Detection { game: None, how: How::Launched })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn on_and_off_replace_each_other() {
|
||||||
|
let exe = p(r"D:\Emu\Retro.exe");
|
||||||
|
let mut marks = Marks::new();
|
||||||
|
assert_eq!(marks.get(&exe), None);
|
||||||
|
assert_eq!(marks.set(exe.clone(), true), Ok(true));
|
||||||
|
assert_eq!(marks.set(exe.clone(), true), Ok(false), "already on");
|
||||||
|
assert_eq!(marks.set(p(r"d:\emu\RETRO.EXE"), false), Ok(true), "on -> off");
|
||||||
|
assert_eq!(marks.len(), 1, "one exe, never in both sets");
|
||||||
|
assert_eq!(marks.on().count(), 0);
|
||||||
|
assert_eq!(marks.off().collect::<Vec<_>>(), vec![&exe], "first spelling kept");
|
||||||
|
assert_eq!(detect(&exe, false, &[], &marks), None);
|
||||||
|
// `remove` takes away only an "on" mark; `clear` takes away either.
|
||||||
|
assert!(!marks.remove(&exe));
|
||||||
|
assert!(marks.contains_off(&exe));
|
||||||
|
assert_eq!(marks.set(exe.clone(), true), Ok(true), "off -> on");
|
||||||
|
assert_eq!(detect(&exe, false, &[], &marks).map(|d| d.how), Some(How::Marked));
|
||||||
|
assert!(marks.clear(&exe));
|
||||||
|
assert!(!marks.clear(&exe));
|
||||||
|
assert!(marks.is_empty());
|
||||||
|
// Switching a mark at the cap does not count as a new exe.
|
||||||
|
let mut full = Marks::new();
|
||||||
|
for i in 0..limits::MAX_MARKS {
|
||||||
|
full.set(p(&format!(r"C:\G\{i}.exe")), i % 2 == 0).unwrap();
|
||||||
|
}
|
||||||
|
assert_eq!(full.set(p(r"C:\G\0.exe"), false), Ok(true));
|
||||||
|
assert_eq!(full.set(p(r"C:\G\new.exe"), false), Err(ParseError::TooMany("marks")));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn marks_are_keyed_by_the_normalised_path() {
|
||||||
|
let mut marks = Marks::new();
|
||||||
|
assert!(marks.insert(p(r"C:\Emu\Retro.exe")).unwrap());
|
||||||
|
assert!(!marks.insert(p("c:/emu//RETRO.EXE")).unwrap(), "same exe, another spelling");
|
||||||
|
assert_eq!(marks.len(), 1);
|
||||||
|
assert!(marks.contains(&p(r"c:\EMU\retro.exe")));
|
||||||
|
assert!(marks.remove(&p(r"C:\EMU\RETRO.EXE")));
|
||||||
|
assert!(marks.is_empty());
|
||||||
|
assert!(!marks.remove(&p(r"C:\Emu\Retro.exe")));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn marks_persist_through_json() {
|
||||||
|
let mut marks = Marks::new();
|
||||||
|
marks.insert(p(r"D:\Emu\Retro.exe")).unwrap();
|
||||||
|
marks.insert(p(r"C:\Tools\Game.exe")).unwrap();
|
||||||
|
marks.set(p(r"C:\Games\Foo\CrashReporter.exe"), false).unwrap();
|
||||||
|
marks.set(p(r"C:\Games\Foo\Launcher.exe"), false).unwrap();
|
||||||
|
let json = serde_json::to_string(&marks).unwrap();
|
||||||
|
// Two arrays of paths, each sorted by the case-folded key, the first spelling kept.
|
||||||
|
assert_eq!(
|
||||||
|
json,
|
||||||
|
concat!(
|
||||||
|
r#"{"on":["C:\\Tools\\Game.exe","D:\\Emu\\Retro.exe"],"#,
|
||||||
|
r#""off":["C:\\Games\\Foo\\CrashReporter.exe","C:\\Games\\Foo\\Launcher.exe"]}"#
|
||||||
|
)
|
||||||
|
);
|
||||||
|
let back: Marks = serde_json::from_str(&json).unwrap();
|
||||||
|
assert_eq!(back, marks);
|
||||||
|
assert_eq!(serde_json::to_string(&back).unwrap(), json);
|
||||||
|
assert_eq!(detect(&p(r"d:\emu\retro.exe"), false, &[], &back).map(|d| d.how), Some(How::Marked));
|
||||||
|
assert_eq!(detect(&p(r"c:\games\foo\launcher.exe"), false, &library(), &back), None);
|
||||||
|
// Empty marks write both keys.
|
||||||
|
assert_eq!(serde_json::to_string(&Marks::new()).unwrap(), r#"{"on":[],"off":[]}"#);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_plain_array_form_still_loads_as_on() {
|
||||||
|
let m: Marks = serde_json::from_str(r#"["C:\\Tools\\Game.exe","D:\\Emu\\Retro.exe"]"#).unwrap();
|
||||||
|
assert_eq!(m.len(), 2);
|
||||||
|
assert!(m.contains(&p(r"c:\tools\game.exe")) && m.contains(&p(r"D:\Emu\Retro.exe")));
|
||||||
|
assert_eq!(m.off().count(), 0);
|
||||||
|
// Written back in the new form.
|
||||||
|
assert_eq!(serde_json::to_string(&m).unwrap(), r#"{"on":["C:\\Tools\\Game.exe","D:\\Emu\\Retro.exe"],"off":[]}"#);
|
||||||
|
assert_eq!(serde_json::from_str::<Marks>("[]").unwrap(), Marks::new());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn marks_json_is_checked() {
|
||||||
|
// Spellings of one exe collapse on load; bad paths and non-strings are refused.
|
||||||
|
let m: Marks = serde_json::from_str(r#"["C:\\A\\x.exe","c:/a/X.EXE"]"#).unwrap();
|
||||||
|
assert_eq!(m.len(), 1);
|
||||||
|
let m: Marks = serde_json::from_str(r#"{"off":["C:\\A\\x.exe","c:/a/X.EXE"]}"#).unwrap();
|
||||||
|
assert_eq!((m.len(), m.on().count()), (1, 0), "a missing list is empty");
|
||||||
|
assert_eq!(serde_json::from_str::<Marks>("{}").unwrap(), Marks::new());
|
||||||
|
for bad in [
|
||||||
|
r#"["relative\\x.exe"]"#,
|
||||||
|
r#"["\\\\srv\\s\\x.exe"]"#,
|
||||||
|
r#"[1]"#,
|
||||||
|
r#"{"a":1}"#,
|
||||||
|
r#"{"on":[],"off":[],"extra":[]}"#,
|
||||||
|
r#"{"on":"C:\\x.exe"}"#,
|
||||||
|
r#"{"off":["C:\\G\\..\\x.exe"]}"#,
|
||||||
|
r#""C:\\x.exe""#,
|
||||||
|
"null",
|
||||||
|
// One exe in both lists, in two spellings: the verdict is unknown, so refuse.
|
||||||
|
r#"{"on":["C:\\A\\x.exe"],"off":["c:/a/X.EXE"]}"#,
|
||||||
|
] {
|
||||||
|
assert!(serde_json::from_str::<Marks>(bad).is_err(), "{bad}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn marks_are_capped() {
|
||||||
|
let mut marks = Marks::new();
|
||||||
|
for i in 0..limits::MAX_MARKS {
|
||||||
|
marks.insert(p(&format!(r"C:\G\{i}.exe"))).unwrap();
|
||||||
|
}
|
||||||
|
assert_eq!(marks.insert(p(r"C:\G\one-more.exe")), Err(ParseError::TooMany("marks")));
|
||||||
|
// Re-marking one already there is fine at the cap.
|
||||||
|
assert_eq!(marks.insert(p(r"C:\G\0.exe")), Ok(false));
|
||||||
|
let json = serde_json::to_string(&marks).unwrap();
|
||||||
|
assert!(serde_json::from_str::<Marks>(&json).is_ok());
|
||||||
|
let over: Vec<String> = (0..=limits::MAX_MARKS).map(|i| format!(r"C:\G\{i}.exe")).collect();
|
||||||
|
assert!(serde_json::from_str::<Marks>(&serde_json::to_string(&over).unwrap()).is_err());
|
||||||
|
// The cap counts both lists together.
|
||||||
|
let (on, off) = over.split_at(limits::MAX_MARKS / 2);
|
||||||
|
assert!(serde_json::from_value::<Marks>(serde_json::json!({ "on": on, "off": off })).is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn how_serialises_snake_case() {
|
||||||
|
let d = Detection { game: id("steam:10"), how: How::InstallDir };
|
||||||
|
assert_eq!(serde_json::to_string(&d).unwrap(), r#"{"game":"steam:10","how":"install_dir"}"#);
|
||||||
|
assert_eq!(serde_json::to_string(&How::Launched).unwrap(), r#""launched""#);
|
||||||
|
assert_eq!(serde_json::to_string(&How::Marked).unwrap(), r#""marked""#);
|
||||||
|
}
|
||||||
|
|
||||||
|
proptest! {
|
||||||
|
/// Whatever the folder names, auto-detection only ever claims exes inside an install dir, on whole segments.
|
||||||
|
#[test]
|
||||||
|
fn auto_detection_never_leaves_install_dirs(
|
||||||
|
dirs in proptest::collection::vec("[A-Za-z]{1,4}( [A-Za-z]{1,3})?", 1..4),
|
||||||
|
exe in r"[A-Za-z]{1,4}(\\[A-Za-z]{1,4}){0,3}\\[a-z]{1,4}\.exe",
|
||||||
|
) {
|
||||||
|
// Letters can spell device names (`con`, `nul`): those paths do not exist, so skip them.
|
||||||
|
prop_assume!(dirs.iter().all(|d| WinPath::parse(&format!(r"C:\Games\{d}")).is_ok()));
|
||||||
|
let exe = WinPath::parse(&format!(r"C:\Games\{exe}"));
|
||||||
|
prop_assume!(exe.is_ok());
|
||||||
|
let exe = exe.unwrap();
|
||||||
|
let lib: Vec<Game> = dirs.iter().enumerate()
|
||||||
|
.map(|(i, d)| steam(i as u32 + 1, d, &format!(r"C:\Games\{d}")))
|
||||||
|
.collect();
|
||||||
|
let first = exe.components().nth(1).unwrap().to_lowercase();
|
||||||
|
let expected = dirs.iter().any(|d| d.to_lowercase() == first);
|
||||||
|
let got = detect(&exe, false, &lib, NONE);
|
||||||
|
prop_assert_eq!(got.is_some(), expected);
|
||||||
|
if let Some(d) = got {
|
||||||
|
prop_assert_eq!(d.how, How::InstallDir);
|
||||||
|
let game = lib.iter().find(|g| Some(&g.id) == d.game.as_ref()).unwrap();
|
||||||
|
prop_assert!(exe.starts_with(game.install_dir.as_ref().unwrap()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
|
|
||||||
//! Epic `.item` manifests: valid fixtures and the hostile ones that are Epic-specific.
|
//! Epic `.item` manifests: valid fixtures and the hostile ones that are Epic-specific.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,262 @@
|
|||||||
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
|
|
||||||
|
//! Frametime statistics: known answers on generated series, refusals, and properties.
|
||||||
|
|
||||||
|
use arena_core::frames::{FrameStats, stats};
|
||||||
|
use arena_core::limits;
|
||||||
|
use proptest::prelude::*;
|
||||||
|
|
||||||
|
const EPS: f64 = 1e-6;
|
||||||
|
|
||||||
|
fn close(a: f64, b: f64) -> bool {
|
||||||
|
(a - b).abs() <= EPS * b.abs().max(1.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn s(ft: &[f32]) -> FrameStats {
|
||||||
|
stats(ft).expect("valid series")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A fixed pseudo-random permutation, so order-independence is tested without a dependency.
|
||||||
|
fn shuffled(mut v: Vec<f32>) -> Vec<f32> {
|
||||||
|
let mut x: u64 = 0x9e37_79b9_7f4a_7c15;
|
||||||
|
for i in (1..v.len()).rev() {
|
||||||
|
x ^= x << 13;
|
||||||
|
x ^= x >> 7;
|
||||||
|
x ^= x << 17;
|
||||||
|
v.swap(i, (x % (i as u64 + 1)) as usize);
|
||||||
|
}
|
||||||
|
v
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn constant_series() {
|
||||||
|
let st = s(&[16.0; 1000]);
|
||||||
|
assert_eq!(st.frames, 1000);
|
||||||
|
assert!(close(st.seconds, 16.0));
|
||||||
|
assert!(close(st.avg_fps, 62.5));
|
||||||
|
assert!(close(st.low_1, 62.5));
|
||||||
|
assert!(close(st.low_0_1, 62.5));
|
||||||
|
assert_eq!(st.stutters, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn single_frame() {
|
||||||
|
let st = s(&[25.0]);
|
||||||
|
assert_eq!(st.frames, 1);
|
||||||
|
assert!(close(st.seconds, 0.025));
|
||||||
|
assert!(close(st.avg_fps, 40.0));
|
||||||
|
assert!(close(st.low_1, 40.0));
|
||||||
|
assert!(close(st.low_0_1, 40.0));
|
||||||
|
assert_eq!(st.stutters, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn percentiles_are_nearest_rank() {
|
||||||
|
// 1..=100 ms in a scrambled order: the 99th percentile is 99 ms, the 99.9th is 100 ms.
|
||||||
|
let ft = shuffled((1..=100).map(|i| i as f32).collect());
|
||||||
|
let st = s(&ft);
|
||||||
|
assert!(close(st.seconds, 5.05));
|
||||||
|
assert!(close(st.avg_fps, 100.0 / 5.05));
|
||||||
|
assert!(close(st.low_1, 1000.0 / 99.0));
|
||||||
|
assert!(close(st.low_0_1, 10.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn one_percent_of_slow_frames_sets_both_lows() {
|
||||||
|
// 1000 frames: 980 at 10 ms, 20 at 20 ms. Rank 990 and rank 999 both fall in the 20 ms block.
|
||||||
|
let mut ft = vec![10.0f32; 980];
|
||||||
|
ft.extend([20.0f32; 20]);
|
||||||
|
let st = s(&shuffled(ft));
|
||||||
|
assert!(close(st.seconds, 10.2));
|
||||||
|
assert!(close(st.avg_fps, 1000.0 / 10.2));
|
||||||
|
assert!(close(st.low_1, 50.0));
|
||||||
|
assert!(close(st.low_0_1, 50.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn point_one_percent_low_sees_what_one_percent_low_does_not() {
|
||||||
|
// 1000 frames: 995 at 10 ms, 5 at 40 ms. Rank 990 is 10 ms, rank 999 is 40 ms.
|
||||||
|
let mut ft = vec![10.0f32; 995];
|
||||||
|
ft.extend([40.0f32; 5]);
|
||||||
|
let st = s(&shuffled(ft));
|
||||||
|
assert!(close(st.avg_fps, 1000.0 / 10.15));
|
||||||
|
// The percentile frame (10 ms = 100 FPS) is faster than the average: the low is capped at the average.
|
||||||
|
assert!(close(st.low_1, st.avg_fps));
|
||||||
|
assert!(close(st.low_0_1, 25.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_few_huge_frames_cap_the_one_percent_low_at_the_average() {
|
||||||
|
// 995 at 10 ms and 5 one-second hangs: the 99th-percentile frame is 10 ms (100 FPS), the average is ~66.9.
|
||||||
|
let mut ft = vec![10.0f32; 995];
|
||||||
|
ft.extend([1000.0f32; 5]);
|
||||||
|
let st = s(&ft);
|
||||||
|
assert!(close(st.avg_fps, 1000.0 / 14.95));
|
||||||
|
assert!(close(st.low_1, st.avg_fps));
|
||||||
|
assert!(close(st.low_0_1, 1.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn stutter_needs_both_conditions() {
|
||||||
|
// 100 Hz baseline; frames 100.. are spikes separated by 100 calm frames.
|
||||||
|
let mut ft = vec![10.0f32; 100];
|
||||||
|
ft.push(30.0); // 3x and >= 25 ms: a stutter
|
||||||
|
ft.extend([10.0f32; 100]);
|
||||||
|
ft.push(24.0); // 2.4x and < 25 ms: no
|
||||||
|
ft.extend([10.0f32; 100]);
|
||||||
|
ft.push(25.0); // exactly 2.5x and exactly 25 ms: a stutter (both bounds inclusive)
|
||||||
|
ft.extend([10.0f32; 100]);
|
||||||
|
assert_eq!(s(&ft).stutters, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn stutter_relative_to_a_slow_baseline() {
|
||||||
|
// At 60 FPS (16.67 ms) a 40 ms frame is 2.4x the median: not a stutter; 42 ms is 2.52x: a stutter.
|
||||||
|
let base = 1000.0f32 / 60.0;
|
||||||
|
let mut ft = vec![base; 60];
|
||||||
|
ft.push(40.0);
|
||||||
|
ft.extend(vec![base; 60]);
|
||||||
|
ft.push(42.0);
|
||||||
|
assert_eq!(s(&ft).stutters, 1);
|
||||||
|
// At 30 FPS a 50 ms frame is only 1.5x: never a stutter, though it is over 25 ms.
|
||||||
|
let mut slow = vec![33.3f32; 80];
|
||||||
|
slow.push(50.0);
|
||||||
|
assert_eq!(s(&slow).stutters, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn no_stutter_before_sixty_frames_of_history() {
|
||||||
|
let mut ft = vec![10.0f32; 59];
|
||||||
|
ft.push(100.0); // frame 59 has only 59 frames before it
|
||||||
|
assert_eq!(s(&ft).stutters, 0);
|
||||||
|
let mut ft = vec![10.0f32; 60];
|
||||||
|
ft.push(100.0); // frame 60 has a full window
|
||||||
|
assert_eq!(s(&ft).stutters, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn consecutive_spikes_each_count_and_the_window_slides() {
|
||||||
|
let mut ft = vec![10.0f32; 60];
|
||||||
|
ft.extend([50.0f32; 3]);
|
||||||
|
ft.extend([10.0f32; 10]);
|
||||||
|
assert_eq!(s(&ft).stutters, 3);
|
||||||
|
// After 30 slow frames the window's median is no longer 10 ms (it is the mean of 10 and 50 = 30 ms), so the
|
||||||
|
// 31st slow frame is not a stutter any more.
|
||||||
|
let mut ft = vec![10.0f32; 60];
|
||||||
|
ft.extend([50.0f32; 40]);
|
||||||
|
let st = s(&ft);
|
||||||
|
// Frames 60..=89 see a median of 10 ms (fewer than 30 slow frames before them) → 30 stutters; frame 90 sees
|
||||||
|
// 30 slow and 30 fast, median 30 ms, and 50 < 75 ms.
|
||||||
|
assert_eq!(st.stutters, 30);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn zero_frametimes_are_allowed_when_time_passes() {
|
||||||
|
let mut ft = vec![0.0f32; 10];
|
||||||
|
ft.push(10.0);
|
||||||
|
let st = s(&ft);
|
||||||
|
assert_eq!(st.frames, 11);
|
||||||
|
assert!(close(st.avg_fps, 1100.0));
|
||||||
|
assert!(st.low_1 <= st.avg_fps && st.low_0_1 <= st.low_1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn refusals() {
|
||||||
|
assert_eq!(stats(&[]), None);
|
||||||
|
assert_eq!(stats(&[0.0, 0.0]), None, "no time passed");
|
||||||
|
assert_eq!(stats(&[16.0, f32::NAN]), None);
|
||||||
|
assert_eq!(stats(&[16.0, f32::INFINITY]), None);
|
||||||
|
assert_eq!(stats(&[f32::NEG_INFINITY]), None);
|
||||||
|
assert_eq!(stats(&[16.0, -0.5]), None);
|
||||||
|
assert_eq!(stats(&[-0.0, 16.0]).map(|s| s.frames), Some(2), "-0.0 is zero, not negative");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn length_cap() {
|
||||||
|
let at_cap = vec![1.0f32; limits::MAX_FRAMES];
|
||||||
|
assert_eq!(stats(&at_cap).map(|s| s.frames as usize), Some(limits::MAX_FRAMES));
|
||||||
|
let over = vec![1.0f32; limits::MAX_FRAMES + 1];
|
||||||
|
assert_eq!(stats(&over), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn huge_frametimes_stay_finite() {
|
||||||
|
let st = s(&[f32::MAX, f32::MAX, 1.0]);
|
||||||
|
assert!(st.avg_fps.is_finite() && st.seconds.is_finite() && st.avg_fps > 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn serialises_for_the_overlay() {
|
||||||
|
let st = s(&[10.0; 100]);
|
||||||
|
let json = serde_json::to_value(st).unwrap();
|
||||||
|
for k in ["avg_fps", "low_1", "low_0_1", "stutters", "frames", "seconds"] {
|
||||||
|
assert!(json.get(k).is_some(), "missing {k}");
|
||||||
|
}
|
||||||
|
let back: FrameStats = serde_json::from_value(json).unwrap();
|
||||||
|
assert_eq!(back, st);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn frametime() -> impl Strategy<Value = f32> {
|
||||||
|
prop_oneof![
|
||||||
|
6 => 1.0f32..40.0,
|
||||||
|
2 => 0.0f32..1000.0,
|
||||||
|
1 => Just(0.0f32),
|
||||||
|
1 => 0.0f32..f32::MAX,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn any_f32() -> impl Strategy<Value = f32> {
|
||||||
|
prop_oneof![
|
||||||
|
4 => frametime(),
|
||||||
|
1 => Just(f32::NAN),
|
||||||
|
1 => Just(f32::INFINITY),
|
||||||
|
1 => Just(f32::NEG_INFINITY),
|
||||||
|
1 => -1000.0f32..0.0,
|
||||||
|
1 => any::<f32>(),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
proptest! {
|
||||||
|
#[test]
|
||||||
|
fn never_panics(ft in proptest::collection::vec(any_f32(), 0..400)) {
|
||||||
|
let _ = stats(&ft);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn bad_input_is_refused(mut ft in proptest::collection::vec(frametime(), 0..200), bad in prop_oneof![
|
||||||
|
Just(f32::NAN), Just(f32::INFINITY), Just(f32::NEG_INFINITY), -1e9f32..-1e-9
|
||||||
|
], at in any::<prop::sample::Index>()) {
|
||||||
|
let i = at.index(ft.len() + 1);
|
||||||
|
ft.insert(i, bad);
|
||||||
|
prop_assert_eq!(stats(&ft), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn invariants(ft in proptest::collection::vec(frametime(), 1..400)) {
|
||||||
|
if let Some(st) = stats(&ft) {
|
||||||
|
prop_assert_eq!(st.frames as usize, ft.len());
|
||||||
|
for v in [st.avg_fps, st.low_1, st.low_0_1, st.seconds] {
|
||||||
|
prop_assert!(v.is_finite() && v >= 0.0);
|
||||||
|
}
|
||||||
|
prop_assert!(st.avg_fps > 0.0);
|
||||||
|
prop_assert!(st.low_1 <= st.avg_fps);
|
||||||
|
prop_assert!(st.low_0_1 <= st.low_1);
|
||||||
|
prop_assert!((st.stutters as usize) < ft.len().saturating_sub(59).max(1));
|
||||||
|
} else {
|
||||||
|
// Only a series with no time in it is refused here.
|
||||||
|
prop_assert!(ft.iter().all(|&f| f == 0.0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn order_does_not_change_avg_or_lows(ft in proptest::collection::vec(1.0f32..100.0, 1..300)) {
|
||||||
|
let a = s(&ft);
|
||||||
|
let mut rev = ft.clone();
|
||||||
|
rev.reverse();
|
||||||
|
let b = s(&rev);
|
||||||
|
prop_assert!(close(a.avg_fps, b.avg_fps));
|
||||||
|
prop_assert_eq!(a.low_1, b.low_1);
|
||||||
|
prop_assert_eq!(a.low_0_1, b.low_0_1);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
|
|
||||||
//! GOG entries built from registry values the app passes in.
|
//! GOG entries built from registry values the app passes in.
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
|
|
||||||
//! Hostile input across every parser: refused with a typed error, never a panic.
|
//! Hostile input across every parser: refused with a typed error, never a panic.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,190 @@
|
|||||||
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
|
|
||||||
|
//! Overlay shortcuts: parsing, the canonical form, refusals, and the Win32 values.
|
||||||
|
|
||||||
|
use arena_core::hotkey::{Hotkey, HotkeyError, Key, Modifiers, parse};
|
||||||
|
use arena_core::limits;
|
||||||
|
use proptest::prelude::*;
|
||||||
|
|
||||||
|
const CTRL_SHIFT: Modifiers = Modifiers { ctrl: true, alt: false, shift: true, win: false };
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_default_shortcut() {
|
||||||
|
let h = parse("Ctrl+Shift+G").unwrap();
|
||||||
|
assert_eq!(h.modifiers(), CTRL_SHIFT);
|
||||||
|
assert_eq!(h.key(), Key::Letter('G'));
|
||||||
|
assert_eq!(h.to_string(), "Ctrl+Shift+G");
|
||||||
|
assert_eq!(Hotkey::default(), h);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn canonical_form() {
|
||||||
|
for (input, canonical) in [
|
||||||
|
("ctrl+shift+g", "Ctrl+Shift+G"),
|
||||||
|
("Shift+Ctrl+G", "Ctrl+Shift+G"),
|
||||||
|
(" Ctrl + Shift + g ", "Ctrl+Shift+G"),
|
||||||
|
("WIN+ALT+f5", "Alt+Win+F5"),
|
||||||
|
("win+g", "Win+G"),
|
||||||
|
("Alt+1", "Alt+1"),
|
||||||
|
("Ctrl+Alt+Shift+Win+Z", "Ctrl+Alt+Shift+Win+Z"),
|
||||||
|
("F1", "F1"),
|
||||||
|
("shift+f24", "Shift+F24"),
|
||||||
|
("Ctrl+0", "Ctrl+0"),
|
||||||
|
("Ctrl+F10", "Ctrl+F10"),
|
||||||
|
] {
|
||||||
|
assert_eq!(parse(input).map(|h| h.to_string()), Ok(canonical.to_string()), "{input}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn bare_letters_and_digits_are_refused() {
|
||||||
|
for s in ["G", "g", "7", "Shift+G", "Shift+5", "shift+a"] {
|
||||||
|
assert_eq!(parse(s), Err(HotkeyError::NoModifier), "{s}");
|
||||||
|
}
|
||||||
|
// A function key alone is fine (it types nothing).
|
||||||
|
assert!(parse("F9").is_ok());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn keys_windows_reserves_are_refused() {
|
||||||
|
for s in [
|
||||||
|
"Ctrl+Alt+Del",
|
||||||
|
"Ctrl+Alt+Delete",
|
||||||
|
"ctrl+alt+shift+del",
|
||||||
|
"Ctrl+Shift+Esc",
|
||||||
|
"Ctrl+Shift+Escape",
|
||||||
|
"Win+L",
|
||||||
|
"win+l",
|
||||||
|
"Alt+F4",
|
||||||
|
"F12",
|
||||||
|
"Ctrl+F12",
|
||||||
|
"Shift+Win+F12",
|
||||||
|
] {
|
||||||
|
assert_eq!(parse(s), Err(HotkeyError::Reserved), "{s}");
|
||||||
|
}
|
||||||
|
// Close neighbours are fine.
|
||||||
|
for s in ["Win+Shift+L", "Ctrl+L", "Ctrl+Alt+F4", "F11", "Win+G"] {
|
||||||
|
assert!(parse(s).is_ok(), "{s}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn malformed_input() {
|
||||||
|
assert_eq!(parse(""), Err(HotkeyError::Empty));
|
||||||
|
assert_eq!(parse(" "), Err(HotkeyError::Empty));
|
||||||
|
assert_eq!(parse("Ctrl+"), Err(HotkeyError::Malformed));
|
||||||
|
assert_eq!(parse("+G"), Err(HotkeyError::Malformed));
|
||||||
|
assert_eq!(parse("Ctrl++G"), Err(HotkeyError::Malformed));
|
||||||
|
assert_eq!(parse("Ctrl+Shift"), Err(HotkeyError::MissingKey));
|
||||||
|
assert_eq!(parse("Win"), Err(HotkeyError::MissingKey));
|
||||||
|
assert_eq!(parse("Ctrl+Ctrl+G"), Err(HotkeyError::DuplicateModifier));
|
||||||
|
assert_eq!(parse("ctrl+CTRL+G"), Err(HotkeyError::DuplicateModifier));
|
||||||
|
assert_eq!(parse("Hyper+G"), Err(HotkeyError::UnknownModifier));
|
||||||
|
assert_eq!(parse("G+Ctrl"), Err(HotkeyError::UnknownModifier), "the key comes last");
|
||||||
|
assert_eq!(parse("Ctrl+G+H"), Err(HotkeyError::UnknownModifier));
|
||||||
|
for k in ["Tab", "Space", "Esc", "Del", "F0", "F25", "F01", "GG", "10", "Ž", "Ctrl+é", "+", "F1 2"] {
|
||||||
|
let s = if k.contains('+') { k.to_string() } else { format!("Ctrl+{k}") };
|
||||||
|
assert!(matches!(parse(&s), Err(HotkeyError::UnknownKey | HotkeyError::Malformed)), "{s}");
|
||||||
|
}
|
||||||
|
assert_eq!(parse("Ctrl+Tab"), Err(HotkeyError::UnknownKey));
|
||||||
|
assert_eq!(parse(&format!("Ctrl+{}", "G".repeat(limits::MAX_HOTKEY))), Err(HotkeyError::TooLong));
|
||||||
|
assert_eq!(parse("Ctrl+\u{0}"), Err(HotkeyError::UnknownKey));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn new_checks_the_same_rules() {
|
||||||
|
let none = Modifiers::default();
|
||||||
|
let alt = Modifiers { alt: true, ..none };
|
||||||
|
assert_eq!(Hotkey::new(none, Key::Letter('G')), Err(HotkeyError::NoModifier));
|
||||||
|
assert_eq!(Hotkey::new(alt, Key::F(4)), Err(HotkeyError::Reserved));
|
||||||
|
assert_eq!(Hotkey::new(alt, Key::Letter('g')), Err(HotkeyError::UnknownKey), "letters are uppercase");
|
||||||
|
assert_eq!(Hotkey::new(alt, Key::Letter('1')), Err(HotkeyError::UnknownKey));
|
||||||
|
assert_eq!(Hotkey::new(alt, Key::Digit(10)), Err(HotkeyError::UnknownKey));
|
||||||
|
assert_eq!(Hotkey::new(alt, Key::F(0)), Err(HotkeyError::UnknownKey));
|
||||||
|
assert_eq!(Hotkey::new(alt, Key::F(25)), Err(HotkeyError::UnknownKey));
|
||||||
|
assert_eq!(Hotkey::new(CTRL_SHIFT, Key::Letter('G')), Ok(Hotkey::default()));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn win32_values() {
|
||||||
|
let h = parse("Ctrl+Shift+G").unwrap();
|
||||||
|
assert_eq!(h.win32_modifiers(), 0x0002 | 0x0004);
|
||||||
|
assert_eq!(h.virtual_key(), 0x47);
|
||||||
|
assert_eq!(parse("Win+G").unwrap().win32_modifiers(), 0x0008);
|
||||||
|
assert_eq!(parse("Alt+0").unwrap().win32_modifiers(), 0x0001);
|
||||||
|
assert_eq!(parse("Alt+0").unwrap().virtual_key(), 0x30);
|
||||||
|
assert_eq!(parse("Alt+9").unwrap().virtual_key(), 0x39);
|
||||||
|
assert_eq!(parse("Alt+A").unwrap().virtual_key(), 0x41);
|
||||||
|
assert_eq!(parse("Alt+Z").unwrap().virtual_key(), 0x5A);
|
||||||
|
assert_eq!(parse("F1").unwrap().virtual_key(), 0x70);
|
||||||
|
assert_eq!(parse("F24").unwrap().virtual_key(), 0x87);
|
||||||
|
assert_eq!(parse("F1").unwrap().win32_modifiers(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn serde_uses_the_text_form() {
|
||||||
|
let h = Hotkey::default();
|
||||||
|
assert_eq!(serde_json::to_string(&h).unwrap(), r#""Ctrl+Shift+G""#);
|
||||||
|
assert_eq!(serde_json::from_str::<Hotkey>(r#""shift+ctrl+g""#).unwrap(), h);
|
||||||
|
for bad in [r#""G""#, r#""Win+L""#, r#""""#, "7", r#"{"key":"G"}"#] {
|
||||||
|
assert!(serde_json::from_str::<Hotkey>(bad).is_err(), "{bad}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn errors_display_without_input() {
|
||||||
|
for e in [
|
||||||
|
HotkeyError::Empty,
|
||||||
|
HotkeyError::TooLong,
|
||||||
|
HotkeyError::Malformed,
|
||||||
|
HotkeyError::UnknownModifier,
|
||||||
|
HotkeyError::DuplicateModifier,
|
||||||
|
HotkeyError::MissingKey,
|
||||||
|
HotkeyError::UnknownKey,
|
||||||
|
HotkeyError::NoModifier,
|
||||||
|
HotkeyError::Reserved,
|
||||||
|
] {
|
||||||
|
assert!(!e.to_string().is_empty());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn modifiers() -> impl Strategy<Value = Modifiers> {
|
||||||
|
(any::<bool>(), any::<bool>(), any::<bool>(), any::<bool>()).prop_map(|(ctrl, alt, shift, win)| Modifiers {
|
||||||
|
ctrl,
|
||||||
|
alt,
|
||||||
|
shift,
|
||||||
|
win,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn key() -> impl Strategy<Value = Key> {
|
||||||
|
prop_oneof![
|
||||||
|
proptest::char::range('A', 'Z').prop_map(Key::Letter),
|
||||||
|
(0u8..=9).prop_map(Key::Digit),
|
||||||
|
(1u8..=24).prop_map(Key::F),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
proptest! {
|
||||||
|
#[test]
|
||||||
|
fn parse_display_round_trip(m in modifiers(), k in key()) {
|
||||||
|
match Hotkey::new(m, k) {
|
||||||
|
Ok(h) => {
|
||||||
|
prop_assert_eq!(parse(&h.to_string()), Ok(h));
|
||||||
|
prop_assert_eq!(parse(&h.to_string().to_lowercase()), Ok(h));
|
||||||
|
}
|
||||||
|
Err(e) => prop_assert!(matches!(e, HotkeyError::NoModifier | HotkeyError::Reserved)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_never_panics_and_is_canonical(s in r"((?i)(ctrl|alt|shift|win|control|meta| |\+)){0,6}[A-Za-z0-9 ]{0,4}|\PC{0,24}") {
|
||||||
|
if let Ok(h) = parse(&s) {
|
||||||
|
let text = h.to_string();
|
||||||
|
prop_assert_eq!(parse(&text), Ok(h));
|
||||||
|
prop_assert!(text.len() <= limits::MAX_HOTKEY);
|
||||||
|
prop_assert!(h.modifiers() != Modifiers::default() || matches!(h.key(), Key::F(_)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
|
|
||||||
//! Launch strings contain only parsed, validated fields: nothing raw from a file reaches a URI or an argument.
|
//! Launch strings contain only parsed, validated fields: nothing raw from a file reaches a URI or an argument.
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
|
|
||||||
//! Manual games (an `.exe` the user picked) and Domi games (Atrium registry entries).
|
//! Manual games (an `.exe` the user picked) and Domi games (Atrium registry entries).
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
|
|
||||||
//! Dedupe and ordering in `merge`.
|
//! Dedupe and ordering in `merge`.
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
|
|
||||||
//! `WinPath` and `GameId`: the two validated value types everything else is built from.
|
//! `WinPath` and `GameId`: the two validated value types everything else is built from.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
|
|
||||||
|
//! Static checks on the crate's own sources: no I/O or OS calls (decision 15, `docs/PORTABILITY.md`) and no
|
||||||
|
//! process access of any kind (DAY2 mandatory test: no handle with write or memory-read rights to another process).
|
||||||
|
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
const IO: [&str; 8] =
|
||||||
|
["std::fs", "std::process", "std::net", "std::env", "std::time", "SystemTime", "Instant", "Command"];
|
||||||
|
|
||||||
|
const PROCESS_ACCESS: [&str; 10] = [
|
||||||
|
"PROCESS_VM_READ",
|
||||||
|
"PROCESS_VM_WRITE",
|
||||||
|
"PROCESS_VM_OPERATION",
|
||||||
|
"PROCESS_ALL_ACCESS",
|
||||||
|
"ReadProcessMemory",
|
||||||
|
"WriteProcessMemory",
|
||||||
|
"CreateRemoteThread",
|
||||||
|
"SetWindowsHookEx",
|
||||||
|
"DuplicateHandle",
|
||||||
|
"OpenProcess",
|
||||||
|
];
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn sources_have_no_io_and_no_process_access() {
|
||||||
|
let src = Path::new(env!("CARGO_MANIFEST_DIR")).join("src");
|
||||||
|
let mut files = 0;
|
||||||
|
let mut hits = Vec::new();
|
||||||
|
for entry in std::fs::read_dir(&src).unwrap() {
|
||||||
|
let path = entry.unwrap().path();
|
||||||
|
if path.extension().is_some_and(|e| e == "rs") {
|
||||||
|
files += 1;
|
||||||
|
let text = std::fs::read_to_string(&path).unwrap();
|
||||||
|
for (n, line) in text.lines().enumerate() {
|
||||||
|
for word in IO.iter().chain(PROCESS_ACCESS.iter()) {
|
||||||
|
if line.contains(word) {
|
||||||
|
hits.push(format!("{}:{}: {word}", path.display(), n + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert!(files >= 10, "found only {files} source files under {}", src.display());
|
||||||
|
assert!(hits.is_empty(), "forbidden API names in arena-core sources:\n{}", hits.join("\n"));
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
|
|
||||||
//! Steam: valid fixtures and the hostile ones that are Steam-specific.
|
//! Steam: valid fixtures and the hostile ones that are Steam-specific.
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
|
|
||||||
//! The VDF tokenizer, parser and writer on hand-written input.
|
//! The VDF tokenizer, parser and writer on hand-written input.
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// SPDX-License-Identifier: CPAL-1.0
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
|
|
||||||
//! Property tests on the VDF tokenizer and parser: no panics on arbitrary bytes, and generated documents survive
|
//! Property tests on the VDF tokenizer and parser: no panics on arbitrary bytes, and generated documents survive
|
||||||
//! a write/parse round trip.
|
//! a write/parse round trip.
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ reads capped bytes and passes them in.
|
|||||||
| `MAX_URL` | 2048 bytes | a web-game URL | `TooLong("url")` |
|
| `MAX_URL` | 2048 bytes | a web-game URL | `TooLong("url")` |
|
||||||
| `MAX_HOST` | 253 bytes | the URL's host | `BadValue("url")` |
|
| `MAX_HOST` | 253 bytes | the URL's host | `BadValue("url")` |
|
||||||
| `MAX_GAMES` | 100 000 | games one `merge` call considers | the rest are dropped |
|
| `MAX_GAMES` | 100 000 | games one `merge` call considers | the rest are dropped |
|
||||||
|
| `MAX_FRAMES` | 1 048 576 | frametimes one `frames::stats` call takes | `None` |
|
||||||
|
| `MAX_MARKS` | 4096 | exes marked on or off, together (`detect::Marks`) | `TooMany("marks")` |
|
||||||
|
| `MAX_HOTKEY` | 64 bytes | shortcut text for `hotkey::parse` | `HotkeyError::TooLong` |
|
||||||
|
|
||||||
## Errors
|
## Errors
|
||||||
|
|
||||||
@@ -201,3 +204,31 @@ the allow-list, so launching a stored web game goes through `uri_checked`.
|
|||||||
Steam > Epic > GOG > Domi > Manual. Games of the same source are never dropped for sharing a folder; games
|
Steam > Epic > GOG > Domi > Manual. Games of the same source are never dropped for sharing a folder; games
|
||||||
without an install folder are never dropped here.
|
without an install folder are never dropped here.
|
||||||
3. The result is sorted by title (lowercased, by code point), then by id, so it does not depend on scan order.
|
3. The result is sorted by title (lowercased, by code point), then by id, so it does not depend on scan order.
|
||||||
|
|
||||||
|
## Overlay: frametimes, detection, shortcut
|
||||||
|
|
||||||
|
**`frames::stats(&[f32])`** (milliseconds, presentation order) → `FrameStats { avg_fps, low_1, low_0_1, stutters,
|
||||||
|
frames, seconds }`. `avg_fps = frames / seconds`; the lows are `1000 / frametime` at the nearest-rank 99th and
|
||||||
|
99.9th percentile (rank `ceil(p × n)`), each capped so `low_0_1 <= low_1 <= avg_fps`; a stutter is a frame
|
||||||
|
`>= 2.5 ×` the median of the 60 frames before it (mean of the 30th and 31st smallest) **and** `>= 25 ms`; the first
|
||||||
|
60 frames are never stutters. `None` for an empty series, over `MAX_FRAMES`, any NaN, infinite or negative value,
|
||||||
|
or no time at all (zeros alone).
|
||||||
|
|
||||||
|
**`detect::detect(exe, launched_by_arena, library, marks)`**, first match wins: `Launched` (Arena started it,
|
||||||
|
whatever the marks; the game if the library owns the exe); `None` when the exe is marked **off** ("This is not a
|
||||||
|
game"); `Marked` when it is marked **on** ("This is a game"; the game if the library owns the exe); `InstallDir`
|
||||||
|
(the game's own launch exe, else the deepest `install_dir` strictly containing the exe; drive roots never count as
|
||||||
|
a containing folder). Otherwise `None`: an exe outside every install folder is never auto-detected. Comparison is
|
||||||
|
component-wise and ignores case; `WinPath` already refuses `..`, `.`, UNC and `\\?\`. Marks are per exe, never
|
||||||
|
per folder, and an exe is in at most one set.
|
||||||
|
|
||||||
|
`Marks` serialises as `{"on": [paths], "off": [paths]}`, each sorted by the case-folded path. Loading also takes a
|
||||||
|
plain array of paths as `on` (the first 0.2.0 form), treats a missing list as empty, refuses unknown keys, re-checks
|
||||||
|
each path, folds spellings of one exe, and refuses an exe in both lists (`Duplicate("marks")`) or more than
|
||||||
|
`MAX_MARKS` in all (`TooMany("marks")`).
|
||||||
|
|
||||||
|
**`hotkey::parse(&str)`**: `Mod+...+Key`, spaces around parts ignored, names ignore case. Modifiers `Ctrl Alt Shift
|
||||||
|
Win` (each once); key `A`–`Z`, `0`–`9`, `F1`–`F24`, last. Errors: `Empty`, `TooLong`, `Malformed` (empty part),
|
||||||
|
`UnknownModifier`, `DuplicateModifier`, `MissingKey`, `UnknownKey`, `NoModifier` (a letter or digit without Ctrl,
|
||||||
|
Alt or Win), `Reserved` (`Ctrl+Alt+Del`, `Ctrl+Shift+Esc`, `Win+L`, `Alt+F4`, any `F12`). `Display` is canonical
|
||||||
|
(`Ctrl+Alt+Shift+Win+<KEY>`); serde uses that text.
|
||||||
|
|||||||
Reference in New Issue
Block a user