Skip to content
This repository was archived by the owner on May 12, 2026. It is now read-only.

Commit 4e6ade4

Browse files
authored
Merge pull request #5 from jkfujr/main
Fix EU Localization Plugin
2 parents a957802 + 59133f7 commit 4e6ade4

1 file changed

Lines changed: 31 additions & 6 deletions

File tree

src/core/modifiers/plugins/eu_localization.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import shutil
1111
import tempfile
1212
import zipfile
13+
import subprocess
14+
import re
1315
from pathlib import Path
1416
from typing import Any, Dict, List, Union
1517

@@ -27,19 +29,39 @@ class EULocalizationPlugin(ModifierPlugin):
2729

2830
def check_prerequisites(self) -> bool:
2931
"""Check if EU localization can be applied."""
32+
# Check if we have an EU bundle (Explicit override)
33+
if getattr(self.ctx, "eu_bundle", None) is not None:
34+
return True
35+
3036
if not getattr(self.ctx, "is_port_eu_rom", False):
3137
return False
3238

3339
# Check if we have a CN stock to extract from
3440
if self._is_stock_cn():
3541
return True
3642

37-
# Check if we have an EU bundle
38-
if getattr(self.ctx, "eu_bundle", None) is not None:
39-
return True
40-
4143
return False
4244

45+
def _get_apk_version(self, apk_path: Path) -> str:
46+
"""Get APK version name/code using aapt2."""
47+
aapt2 = getattr(getattr(self.ctx, "tools", None), "aapt2", None)
48+
if not aapt2 or not apk_path.exists():
49+
return "unknown"
50+
51+
try:
52+
cmd = [str(aapt2), "dump", "badging", str(apk_path)]
53+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
54+
55+
match = re.search(r"versionName='([^']*)'", result.stdout)
56+
version_name = match.group(1) if match else "unknown"
57+
58+
match_code = re.search(r"versionCode='([^']*)'", result.stdout)
59+
version_code = match_code.group(1) if match_code else "unknown"
60+
61+
return f"{version_name} ({version_code})"
62+
except Exception:
63+
return "unknown"
64+
4365
def _is_stock_cn(self) -> bool:
4466
"""Detect if stock ROM is a CN (China) ROM.
4567
@@ -333,12 +355,15 @@ def _replace_eu_apps(self, bundle_path: Path):
333355
self.logger.info(f"Found {len(bundle_packages)} unique package(s) to process.")
334356

335357
# 2. For each unique package, find and remove original app in target ROM
336-
for pkg_name in bundle_packages:
358+
for pkg_name, bundle_apks in bundle_packages.items():
337359
target_apks = self.ctx.syncer.find_apks_by_package(pkg_name, self.ctx.target_dir)
338360

339361
if target_apks:
362+
# Log version comparison
363+
target_ver = self._get_apk_version(target_apks[0])
364+
bundle_ver = self._get_apk_version(bundle_apks[0])
340365
self.logger.info(
341-
f"Replacing EU App: {pkg_name} ({len(target_apks)} instance(s) found)"
366+
f"Replacing EU App: {pkg_name} [Target: {target_ver} -> Bundle: {bundle_ver}]"
342367
)
343368

344369
for target_apk in target_apks:

0 commit comments

Comments
 (0)