下载地址>> 戳我下载(电脑版)
戳我前往网页版
将您的小米/红米手机(平板)电量充到100%,充到100%后,请连续点击“设置>全部参数与信息>处理器(连续点击)”
稍等片刻后,将系统导出的“.zip”文件原封不动的传到计算机(电脑)(可以使用微信、小米互传等),并使用下载好的程序导入zip文件。
导入完成后,请根据您设备的"设置>我的设备>全部参数与信息>电池容量"在程序中输入您的数字。
此程序无任何上传代码,开源代码在下方。
声明:若对设备有任何问题,请前往线下小米售后,本程序仅进行对bug包进行分析计算得出的结果。
import zipfile
import tkinter as tk
from tkinter import filedialog, simpledialog
import re
print("请连续点击“设置>全部参数与信息>处理器(连续点击)”\n稍等片刻后,将系统导出的“.zip”文件原封不动的传到计算机,并打开刚刚导出的zip文件。")
def extract_battery_capacity(text):
match = re.search(r'Min learned battery capacity:\s*(\d+)\s*mAh', text)
if match:
return int(match.group(1))
return None
def find_min_battery_capacity(zip_path):
try:
with zipfile.ZipFile(zip_path, 'r') as outer_zip:
for outer_filename in outer_zip.namelist():
if outer_filename.endswith('.zip'):
with zipfile.ZipFile(outer_zip.open(outer_filename), 'r') as inner_zip:
for inner_filename in inner_zip.namelist():
if 'bugreport' in inner_filename and inner_filename.endswith('.txt'):
with inner_zip.open(inner_filename) as file:
content = file.read().decode('utf-8')
return extract_battery_capacity(content)
except zipfile.BadZipFile:
return None
except Exception as e:
print(f"An error occurred: {e}")
return None
def calculate_percentage(capacity, user_input):
if capacity is not None and user_input > 0:
return (capacity / user_input) * 100
return None
def main():
root = tk.Tk()
root.withdraw() # Hide the main window
zip_path = filedialog.askopenfilename(title="选择ZIP文件", filetypes=[("ZIP files", "*.zip")])
if not zip_path:
return
battery_capacity = find_min_battery_capacity(zip_path)
if battery_capacity is None:
tk.messagebox.showerror("错误", "无法从ZIP文件中找到或提取电池容量。")
return
user_input_str = simpledialog.askstring("请输入你的HyperOS/MIUI的初始电池容量", "请输入你的HyperOS/MIUI的初始电池容量", parent=root)
if user_input_str:
try:
user_input = float(user_input_str)
percentage = calculate_percentage(battery_capacity, user_input)
if percentage is not None:
tk.messagebox.showinfo("Get!", f"计算出的百分比为 {percentage:.2f}%.")
else:
tk.messagebox.showerror("错误", "无效输入或电池容量。")
except ValueError:
tk.messagebox.showerror("错误", "无效输入。请输入一个有效的数字")
else:
# User canceled the input dialog
pass
root.destroy() # Clean up the Tkinter main window
if __name__ == "__main__":
main()
# Copyright HikiMu