Squashed commit of the following:
commitb7dcadf359Author: Julian Freeman <freemanjulian372@gmail.com> Date: Fri Feb 2 17:55:23 2024 -0400 v1.0.0 commitd84b107177Author: Julian Freeman <freemanjulian372@gmail.com> Date: Fri Feb 2 09:35:56 2024 -0400 dev 02020935 commita69ba157a5Author: Julian Freeman <freemanjulian372@gmail.com> Date: Thu Feb 1 21:49:26 2024 -0400 dev 02012149 commit38d98dee94Author: Julian Freeman <freemanjulian372@gmail.com> Date: Thu Feb 1 18:12:45 2024 -0400 dev 02011812 commit3e17def627Author: Julian Freeman <freemanjulian372@gmail.com> Date: Thu Feb 1 11:27:24 2024 -0400 dev 02011127 commit06327f3bfcAuthor: Julian Freeman <freemanjulian372@gmail.com> Date: Thu Feb 1 00:44:45 2024 -0400 dev 24.01.31
This commit is contained in:
82
util_func.py
Normal file
82
util_func.py
Normal file
@@ -0,0 +1,82 @@
|
||||
# coding: utf8
|
||||
import os
|
||||
import wmi
|
||||
import json
|
||||
import win32gui
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from PySide6.QtCore import QDir, QSettings
|
||||
from PySide6.QtGui import QImage, QIcon, QPixmap
|
||||
from global_vars import request_content
|
||||
|
||||
|
||||
def get_isp_name() -> str:
|
||||
try:
|
||||
data = json.loads(request_content("https://ipinfo.io/"))
|
||||
return data.get("org", "[Not found]")
|
||||
except json.JSONDecodeError:
|
||||
return "[Decode Error]"
|
||||
|
||||
|
||||
def get_win_manufacturer() -> list[str]:
|
||||
w = wmi.WMI()
|
||||
cs_ls = w.Win32_ComputerSystem()
|
||||
if len(cs_ls) > 0:
|
||||
cs = cs_ls[0]
|
||||
return [cs.model, cs.Manufacturer]
|
||||
return []
|
||||
|
||||
|
||||
def get_win_license() -> str:
|
||||
temp_out = str(Path(QDir.tempPath(), "lic.txt"))
|
||||
return_code = subprocess.call(
|
||||
rf'cscript /Nologo /U "C:\Windows\System32\slmgr.vbs" /dlv >{temp_out}',
|
||||
shell=True,
|
||||
)
|
||||
if return_code == 0:
|
||||
with open(temp_out, "r", encoding="utf-16-le") as f:
|
||||
return f.read()
|
||||
return ""
|
||||
|
||||
|
||||
def get_win_installed_software() -> dict[str, str]:
|
||||
|
||||
def gather_software(path: str, software_dict: dict[str, str]):
|
||||
reg = QSettings(path, QSettings.Format.NativeFormat)
|
||||
soft = reg.childGroups()
|
||||
for s in soft:
|
||||
c = QSettings(path + "\\" + s.split("/")[0], QSettings.Format.NativeFormat)
|
||||
name = str(c.value("DisplayName"))
|
||||
if name == "None":
|
||||
continue
|
||||
icon = str(c.value("DisplayIcon"))
|
||||
software_dict[name] = icon
|
||||
|
||||
all_software = {}
|
||||
gather_software(r"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", all_software)
|
||||
gather_software(r"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall", all_software)
|
||||
gather_software(r"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall", all_software)
|
||||
|
||||
return all_software
|
||||
|
||||
|
||||
def extract_win_icon_from_file(icon: str, default: QIcon) -> QIcon:
|
||||
if icon == "None":
|
||||
return default
|
||||
if icon.endswith(",0"):
|
||||
icon = icon[:-2]
|
||||
icon = icon.replace('"', "")
|
||||
icon = icon.replace("'", "")
|
||||
if not os.path.exists(icon):
|
||||
return default
|
||||
if not icon.endswith(("exe", "EXE", "dll", "DLL")):
|
||||
return QIcon(icon)
|
||||
|
||||
large, small = win32gui.ExtractIconEx(icon, 0)
|
||||
if len(small) > 0:
|
||||
win32gui.DestroyIcon(small[0])
|
||||
if len(large) > 0:
|
||||
image = QImage.fromHICON(large[0])
|
||||
return QIcon(QPixmap(image))
|
||||
else:
|
||||
return default
|
||||
Reference in New Issue
Block a user