Various changes, block telemetry feature.
-Sp/--patch is now required to do block telemetry before patching. Still preparing for hdiffpatch (will be coming at 1.10) Ay yo hosty support coming soon xD
This commit is contained in:
@ -6,6 +6,7 @@ from pathlib import Path
|
||||
import shutil
|
||||
import aiohttp
|
||||
import asyncio
|
||||
from worthless import linux
|
||||
from worthless import constants
|
||||
from worthless.launcher import Launcher
|
||||
from worthless.installer import Installer
|
||||
@ -31,8 +32,11 @@ class Patcher:
|
||||
self._patch_path = data_dir.joinpath("Patch")
|
||||
self._temp_path = data_dir.joinpath("Temp/Patcher")
|
||||
self._overseas = overseas
|
||||
self._installer = Installer(self._gamedir, overseas=overseas, data_dir=self._temp_path)
|
||||
self._installer = Installer(self._gamedir, overseas=overseas, data_dir=data_dir)
|
||||
self._launcher = Launcher(self._gamedir, overseas=overseas)
|
||||
match platform.system():
|
||||
case "Linux":
|
||||
self._linuxutils = linux.LinuxUtils()
|
||||
|
||||
@staticmethod
|
||||
async def _get(url, **kwargs) -> aiohttp.ClientResponse:
|
||||
@ -100,6 +104,40 @@ class Patcher:
|
||||
"""
|
||||
await self._download_repo()
|
||||
|
||||
async def is_telemetry_blocked(self):
|
||||
"""
|
||||
Check if the telemetry is blocked.
|
||||
|
||||
"""
|
||||
if self._overseas:
|
||||
telemetry_url = constants.TELEMETRY_URL_LIST
|
||||
else:
|
||||
telemetry_url = constants.TELEMETRY_URL_CN_LIST
|
||||
unblocked_list = []
|
||||
async with aiohttp.ClientSession() as session:
|
||||
for url in telemetry_url:
|
||||
try:
|
||||
await session.get("https://" + url)
|
||||
except (aiohttp.ClientResponseError, aiohttp.ClientConnectorError):
|
||||
continue
|
||||
else:
|
||||
unblocked_list.append(url)
|
||||
return None if unblocked_list == [] else unblocked_list
|
||||
|
||||
async def block_telemetry(self):
|
||||
telemetry = await self.is_telemetry_blocked()
|
||||
if not telemetry:
|
||||
raise ValueError("All telemetry are blocked")
|
||||
telemetry_hosts = ""
|
||||
for url in telemetry:
|
||||
telemetry_hosts += "0.0.0.0 " + url + "\n"
|
||||
match platform.system():
|
||||
case "Linux":
|
||||
await self._linuxutils.append_text_to_file(telemetry_hosts)
|
||||
return
|
||||
# TODO: Windows and macOS
|
||||
raise NotImplementedError("Platform not implemented.")
|
||||
|
||||
async def _patch_unityplayer_fallback(self):
|
||||
# xdelta3-python doesn't work becuase it's outdated.
|
||||
if self._overseas:
|
||||
@ -115,7 +153,10 @@ class Patcher:
|
||||
|
||||
async def _patch_xlua_fallback(self):
|
||||
# xdelta3-python doesn't work becuase it's outdated.
|
||||
patch = "xlua_patch.vcdiff"
|
||||
if self._overseas:
|
||||
patch = "unityplayer_patch_os.vcdiff"
|
||||
else:
|
||||
patch = "unityplayer_patch_cn.vcdiff"
|
||||
gamever = "".join(self._installer.get_game_version().split("."))
|
||||
data_name = self._installer.get_game_data_name()
|
||||
xlua_path = self._gamedir.joinpath("{}/Plugins/xlua.dll".format(data_name))
|
||||
|
||||
Reference in New Issue
Block a user