Base working for damage
This commit is contained in:
+82
-15
@@ -1,5 +1,6 @@
|
||||
import logging
|
||||
import os
|
||||
import platform
|
||||
import subprocess
|
||||
import sys
|
||||
import requests
|
||||
|
||||
@@ -13,6 +14,7 @@ from PySide6.QtWidgets import QPushButton # type: ignore
|
||||
from ..engine import InitializationResult
|
||||
from ..engine import initialize
|
||||
from ..utils.config import config
|
||||
from ..environment import setup_logging
|
||||
|
||||
from .modules.main import MainWidget
|
||||
from .styling import style
|
||||
@@ -20,17 +22,40 @@ from ..utils.version import current_version as get_current_version
|
||||
from ..utils.version import latest_version as get_latest_version
|
||||
from ..utils.assets import path
|
||||
from ..utils.assets import scripts
|
||||
from ..utils import platform_utils
|
||||
from ..utils.platform_utils import capture_permissions_ok
|
||||
|
||||
sys.path.append(os.path.dirname(os.path.abspath('__file__')))
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def fix_network():
|
||||
script_name = platform_utils.repair_script()
|
||||
if not script_name:
|
||||
sys.exit(0)
|
||||
|
||||
script_path = scripts(script_name)
|
||||
|
||||
if platform_utils.is_windows():
|
||||
os.system(script_path)
|
||||
else:
|
||||
subprocess.call(['sh', script_path, sys.executable])
|
||||
|
||||
def fix_npcap():
|
||||
os.system(scripts('fixnpcap.bat'))
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
def run():
|
||||
setup_logging()
|
||||
|
||||
app_argv = [a for a in sys.argv if a not in ('--verbose', '-v')]
|
||||
|
||||
logger.info("Albion Online Stats v%s starting", get_current_version())
|
||||
logger.debug("python: %s (%s)", sys.executable, sys.version)
|
||||
logger.debug("platform: %s", platform_utils.system())
|
||||
|
||||
initialization_result = initialize()
|
||||
logger.debug("backend initialization result: %s", initialization_result)
|
||||
|
||||
conf = config()
|
||||
window_config = conf['window']
|
||||
@@ -38,7 +63,12 @@ def run():
|
||||
WIDTH = window_config['width']
|
||||
HEIGHT = window_config['height']
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
perms_ok = True
|
||||
if platform_utils.is_linux():
|
||||
perms_ok = capture_permissions_ok()
|
||||
logger.debug("capture permissions probe: %s", perms_ok)
|
||||
|
||||
app = QApplication(app_argv)
|
||||
|
||||
app.setStyleSheet(style)
|
||||
|
||||
@@ -73,21 +103,58 @@ def run():
|
||||
msg.setStandardButtons(QMessageBox.Ok)
|
||||
msg.show()
|
||||
|
||||
if initialization_result == InitializationResult.NetworkInterfaceListMissing:
|
||||
need_capture_fix = (
|
||||
initialization_result != InitializationResult.Ok
|
||||
or (platform_utils.is_linux() and not perms_ok)
|
||||
)
|
||||
|
||||
if need_capture_fix:
|
||||
msg = QMessageBox()
|
||||
msg.setIcon(QMessageBox.Critical)
|
||||
msg.setWindowTitle("Unable to track network traffic data!")
|
||||
msg.setText(
|
||||
"On windows make sure that WinPcap is installed in your system.")
|
||||
msg.setInformativeText("WinPcap can be installed from <a href='{}'>here</a> <br>\
|
||||
<b>Make sure to install with the \"Install Npcap in WinPcap API-compatible Mode\"<b> option<br><br>\
|
||||
In case where npcap is installed try to fix npcap and restart the app"
|
||||
.format('https://nmap.org/npcap/dist/npcap-0.9990.exe'))
|
||||
msg.setStandardButtons(QMessageBox.Ok)
|
||||
button = QPushButton("Fix npcap")
|
||||
|
||||
button.clicked.connect(fix_npcap)
|
||||
msg.addButton(button, QMessageBox.NoRole)
|
||||
if initialization_result == InitializationResult.BackendNotInstalled:
|
||||
msg.setText(
|
||||
"The packet capture backend (pyaoaddons) is not installed.")
|
||||
msg.setInformativeText(
|
||||
"pyaoaddons 0.2.8 ships prebuilt wheels only for CPython 3.6-3.10.<br>\
|
||||
Use one of those Python versions and reinstall the app \
|
||||
(<code>python -m pip install .</code>), or build pyaoaddons from source.<br><br>\
|
||||
See the README for details.")
|
||||
msg.setStandardButtons(QMessageBox.Ok)
|
||||
elif platform_utils.is_windows():
|
||||
msg.setText(
|
||||
"On Windows make sure that Npcap is installed in your system.")
|
||||
msg.setInformativeText("Npcap can be installed from <a href='{}'>here</a> <br>\
|
||||
<b>Make sure to install with the \"Install Npcap in WinPcap API-compatible Mode\"</b> option<br><br>\
|
||||
In case where npcap is installed try to fix npcap and restart the app"
|
||||
.format('https://nmap.org/npcap/dist/npcap-0.9990.exe'))
|
||||
msg.setStandardButtons(QMessageBox.Ok)
|
||||
button = QPushButton("Fix npcap")
|
||||
button.clicked.connect(fix_network)
|
||||
msg.addButton(button, QMessageBox.NoRole)
|
||||
else:
|
||||
permissions_missing = platform_utils.is_linux() and not perms_ok
|
||||
if permissions_missing:
|
||||
msg.setText(
|
||||
"The app does not have permission to capture network packets.")
|
||||
msg.setInformativeText(
|
||||
"Capturing packets requires elevated privileges. Use the button below \
|
||||
to grant the Python interpreter the needed capabilities \
|
||||
(or run the app with <code>sudo</code>).")
|
||||
else:
|
||||
msg.setText(
|
||||
"Make sure that libpcap is installed and network interfaces are available.")
|
||||
msg.setInformativeText(
|
||||
"Install libpcap:<br>\
|
||||
<b>Debian/Ubuntu:</b> <code>sudo apt install libpcap0.8</code><br>\
|
||||
<b>Fedora:</b> <code>sudo dnf install libpcap</code><br>\
|
||||
<b>Arch:</b> <code>sudo pacman -S libpcap</code>")
|
||||
msg.setStandardButtons(QMessageBox.Ok)
|
||||
if platform_utils.repair_script():
|
||||
button = QPushButton("Fix capture permissions")
|
||||
button.clicked.connect(fix_network)
|
||||
msg.addButton(button, QMessageBox.NoRole)
|
||||
msg.show()
|
||||
|
||||
sys.exit(app.exec_())
|
||||
|
||||
Reference in New Issue
Block a user