summaryrefslogtreecommitdiffstatshomepage
path: root/src-tauri/src/core/rules.rs
diff options
context:
space:
mode:
authorHsiangNianian <i@jyunko.cn>2026-01-13 16:14:49 +0800
committerHsiangNianian <i@jyunko.cn>2026-01-13 16:14:49 +0800
commit746a94952de6d506dee5f45c77c72ccb597bb516 (patch)
treeab3693dba733736a7670ed901aa4b9bf44d99d7b /src-tauri/src/core/rules.rs
parentd247a02cd9656b7ca15128e517c8e995af66903a (diff)
downloadDropOut-746a94952de6d506dee5f45c77c72ccb597bb516.tar.gz
DropOut-746a94952de6d506dee5f45c77c72ccb597bb516.zip
Implement library rules validation and zip extraction utility
- Added `is_library_allowed` function to evaluate library permissions based on defined rules. - Introduced `rule_matches` helper function to check OS compatibility for rules. - Created `extract_zip` function to handle zip file extraction, including directory creation and skipping of META-INF entries.
Diffstat (limited to 'src-tauri/src/core/rules.rs')
-rw-r--r--src-tauri/src/core/rules.rs67
1 files changed, 67 insertions, 0 deletions
diff --git a/src-tauri/src/core/rules.rs b/src-tauri/src/core/rules.rs
new file mode 100644
index 0000000..214d9bc
--- /dev/null
+++ b/src-tauri/src/core/rules.rs
@@ -0,0 +1,67 @@
+use crate::core::game_version::Rule;
+use std::env;
+
+pub fn is_library_allowed(rules: &Option<Vec<Rule>>) -> bool {
+ // If no rules, it's allowed by default
+ let Some(rules) = rules else {
+ return true;
+ };
+
+ if rules.is_empty() {
+ return true;
+ }
+
+ // Default depends on the first rule theoretically, but usually "allow" if no "disallow" matches?
+ // Actually MC logic: implicit disallow? No, implicit allow usually?
+ // Official launcher Rule logic:
+ // "Libraries are allowed unless restricted by a rule."
+ // Actually detailed logic:
+ // Check all rules. if action is "allow" and condition matches, allowed = true.
+ // if action is "disallow" and condition matches, allowed = false.
+ // Typically base state is false if rules exist? No.
+ // Let's check common pattern.
+ // Usually: [ {action: allow}, {action: disallow, os: "osx"} ]
+ // This implies base allowed, but OS X disallowed.
+ // Pattern 2: [ {action: allow, os: "osx"} ]
+ // This implies ONLY osx allowed?
+
+ // Correct logic:
+ // If rules are present, start with result = false (deny all).
+ // Loop through rules. If a rule applies (os matches), update result to (action == "allow").
+ // Wait, let's verify.
+ // If the list is [ {action: allow} ], result becomes true.
+ // If list is [ {action: allow}, {action: disallow, os: "osx"} ].
+ // On Linux: Rule 1 matches -> true. Rule 2 (osx) doesn't match -> ignore. Final: true.
+ // On OSX: Rule 1 matches -> true. Rule 2 matches -> false. Final: false.
+
+ // So: Start false. Apply rules in order.
+
+ let mut allowed = false;
+
+ for rule in rules {
+ if rule_matches(rule) {
+ allowed = (rule.action == "allow");
+ }
+ }
+ allowed
+}
+
+fn rule_matches(rule: &Rule) -> bool {
+ match &rule.os {
+ None => true, // No OS condition means it applies to all
+ Some(os_rule) => {
+ if let Some(os_name) = &os_rule.name {
+ match os_name.as_str() {
+ "osx" | "macos" => env::consts::OS == "macos",
+ "linux" => env::consts::OS == "linux",
+ "windows" => env::consts::OS == "windows",
+ _ => false, // Unknown OS name in rule
+ }
+ } else {
+ // OS rule exists but name is None? Maybe checking version/arch only.
+ // For simplicity, mostly name is used.
+ true
+ }
+ }
+ }
+}