Skip to content

Commit

Permalink
misc: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkobrombin committed Feb 10, 2024
1 parent 158fac5 commit 540f6fc
Show file tree
Hide file tree
Showing 140 changed files with 3,135 additions and 2,538 deletions.
29 changes: 18 additions & 11 deletions bottles/backend/cabextract.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class CabExtract:
extracts the file in a new directory with the input name under the Bottles'
temp directory.
"""

requirements: bool = False
path: str
name: str
Expand All @@ -42,7 +43,13 @@ class CabExtract:
def __init__(self):
self.cabextract_bin = shutil.which("cabextract")

def run(self, path: str, name: str = "", files: Optional[list] = None, destination: str = ""):
def run(
self,
path: str,
name: str = "",
files: Optional[list] = None,
destination: str = "",
):
if files is None:
files = []

Expand Down Expand Up @@ -70,10 +77,10 @@ def __extract(self) -> bool:
try:
if len(self.files) > 0:
for file in self.files:
'''
"""
if file already exists as a symlink, remove it
preventing broken symlinks
'''
"""
if os.path.exists(os.path.join(self.destination, file)):
if os.path.islink(os.path.join(self.destination, file)):
os.unlink(os.path.join(self.destination, file))
Expand All @@ -82,27 +89,27 @@ def __extract(self) -> bool:
self.cabextract_bin,
f"-F '*{file}*'",
f"-d {self.destination}",
f"-q {self.path}"
f"-q {self.path}",
]
command = " ".join(command)
subprocess.Popen(
command,
shell=True
).communicate()
subprocess.Popen(command, shell=True).communicate()

if len(file.split("/")) > 1:
_file = file.split("/")[-1]
_dir = file.replace(_file, "")
if not os.path.exists(f"{self.destination}/{_file}"):
shutil.move(f"{self.destination}/{_dir}/{_file}", f"{self.destination}/{_file}")
shutil.move(
f"{self.destination}/{_dir}/{_file}",
f"{self.destination}/{_file}",
)
else:
command_list = [
self.cabextract_bin,
f"-d {self.destination}",
f"-q {self.path}"
f"-q {self.path}",
]
command = " ".join(command_list)
subprocess.Popen(command, shell=True).communicate()
subprocess.Popen(command, shell=True).communicate()

logging.info(f"Cabinet {self.name} extracted successfully")
return True
Expand Down
18 changes: 5 additions & 13 deletions bottles/backend/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ class Diff:
This class is no more used by the application, it's just a
reference for future implementations.
"""
__ignored = [
"dosdevices",
"users",
"bottle.yml",
"storage"
]

__ignored = ["dosdevices", "users", "bottle.yml", "storage"]

@staticmethod
def hashify(path: str) -> dict:
Expand All @@ -26,10 +22,10 @@ def hashify(path: str) -> dict:
_files = {}

if path[-1] != os.sep:
'''
"""
Be sure to add a trailing slash at the end of the path to
prevent the correct path name in the result.
'''
"""
path += os.sep

for root, dirs, files in os.walk(path):
Expand Down Expand Up @@ -71,8 +67,4 @@ def compare(parent: dict, child: dict) -> dict:
elif parent[f] != child[f]:
changed.append(f)

return {
"added": added,
"removed": removed,
"changed": changed
}
return {"added": added, "removed": removed, "changed": changed}
52 changes: 31 additions & 21 deletions bottles/backend/dlls/dll.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def check(self) -> bool:
found = deepcopy(self.dlls)

if None in self.dlls:
logging.error(f"DLL(s) \"{self.dlls[None]}\" path haven't been found, ignoring...")
logging.error(
f'DLL(s) "{self.dlls[None]}" path haven\'t been found, ignoring...'
)
return

for path in self.dlls:
Expand Down Expand Up @@ -82,24 +84,25 @@ def install(self, config: BottleConfig, overrides_only: bool = False, exclude=No
exclude = []

if None in self.checked_dlls:
logging.error(f"DLL(s) \"{self.checked_dlls[None]}\" path haven't been found, ignoring...")
logging.error(
f'DLL(s) "{self.checked_dlls[None]}" path haven\'t been found, ignoring...'
)
return

for path in self.checked_dlls:
for dll in self.checked_dlls[path]:
if dll not in exclude:
dll_name = dll.split('/')[-1].split('.')[0]
dll_name = dll.split("/")[-1].split(".")[0]
if overrides_only:
dll_in.append(dll_name)
else:
if self.__install_dll(config, path, dll, False):
dll_in.append(dll_name)

for dll in dll_in:
bundle["HKEY_CURRENT_USER\\Software\\Wine\\DllOverrides"].append({
"value": dll,
"data": "native,builtin"
})
bundle["HKEY_CURRENT_USER\\Software\\Wine\\DllOverrides"].append(
{"value": dll, "data": "native,builtin"}
)

reg.import_bundle(bundle)

Expand All @@ -112,21 +115,22 @@ def uninstall(self, config: BottleConfig, exclude=None):
exclude = []

if None in self.dlls:
logging.error(f"DLL(s) \"{self.dlls[None]}\" path haven't been found, ignoring...")
logging.error(
f'DLL(s) "{self.dlls[None]}" path haven\'t been found, ignoring...'
)
return

for path in self.dlls:
for dll in self.dlls[path]:
if dll not in exclude:
dll_name = dll.split('/')[-1].split('.')[0]
dll_name = dll.split("/")[-1].split(".")[0]
if self.__uninstall_dll(config, path, dll):
dll_in.append(dll_name)

for dll in dll_in:
bundle["HKEY_CURRENT_USER\\Software\\Wine\\DllOverrides"].append({
"value": dll,
"data": "-"
})
bundle["HKEY_CURRENT_USER\\Software\\Wine\\DllOverrides"].append(
{"value": dll, "data": "-"}
)

reg.import_bundle(bundle)

Expand All @@ -136,14 +140,18 @@ def __get_sys_path(config: BottleConfig, path: str):
if path in ["x32", "x86"]:
return "system32"
if config.Arch == Arch.WIN64:
if path in ["x64"] or any(arch in path for arch in ("x86_64", "lib64", "lib/")):
if path in ["x64"] or any(
arch in path for arch in ("x86_64", "lib64", "lib/")
):
return "system32"
if path in ["x32", "x86"]:
return "syswow64"
return None

def __install_dll(self, config: BottleConfig, path: str, dll: str, remove: bool = False):
dll_name = dll.split('/')[-1]
def __install_dll(
self, config: BottleConfig, path: str, dll: str, remove: bool = False
):
dll_name = dll.split("/")[-1]
bottle = ManagerUtils.get_bottle_path(config)
bottle = os.path.join(bottle, "drive_c", "windows")
source = os.path.join(self.base_path, path, dll)
Expand All @@ -163,27 +171,29 @@ def __install_dll(self, config: BottleConfig, path: str, dll: str, remove: bool
try:
shutil.copyfile(source, target)
except FileNotFoundError:
logging.warning(f"{source} not found") # TODO: should not be ok but just ignore it for now
logging.warning(
f"{source} not found"
) # TODO: should not be ok but just ignore it for now
return False
'''
"""
reg.add(
key="HKEY_CURRENT_USER\\Software\\Wine\\DllOverrides",
value=dll_name.split('.')[0],
data="native,builtin"
)
'''
"""
return True

if os.path.exists(f"{target}.bck"):
shutil.move(f"{target}.bck", target)
elif os.path.exists(target):
os.remove(target)
'''
"""
reg.remove(
key="HKEY_CURRENT_USER\\Software\\Wine\\DllOverrides",
value=dll_name.split('.')[0]
)
'''
"""
return True

def __uninstall_dll(self, config, path: str, dll: str):
Expand Down
14 changes: 2 additions & 12 deletions bottles/backend/dlls/dxvk.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,8 @@

class DXVKComponent(DLLComponent):
dlls = {
"x32": [
"d3d9.dll",
"d3d10core.dll",
"d3d11.dll",
"dxgi.dll"
],
"x64": [
"d3d9.dll",
"d3d10core.dll",
"d3d11.dll",
"dxgi.dll"
]
"x32": ["d3d9.dll", "d3d10core.dll", "d3d11.dll", "dxgi.dll"],
"x64": ["d3d9.dll", "d3d10core.dll", "d3d11.dll", "dxgi.dll"],
}

@staticmethod
Expand Down
28 changes: 14 additions & 14 deletions bottles/backend/dlls/nvapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,9 @@

class NVAPIComponent(DLLComponent):
dlls = {
"x32": [
"nvapi.dll"
],
"x64": [
"nvapi64.dll"
],
get_nvidia_dll_path(): [
"nvngx.dll",
"_nvngx.dll"
]
"x32": ["nvapi.dll"],
"x64": ["nvapi64.dll"],
get_nvidia_dll_path(): ["nvngx.dll", "_nvngx.dll"],
}

@staticmethod
Expand All @@ -54,6 +47,7 @@ def get_base_path(version: str) -> str:
@staticmethod
def check_bottle_nvngx(bottle_path: str, bottle_config: BottleConfig):
"""Checks for the presence of the DLLs provided by the Nvidia driver, and if they're up to date."""

def md5sum(file):
hash_md5 = hashlib.md5()
with open(file, "rb") as f:
Expand All @@ -65,7 +59,9 @@ def md5sum(file):
nvngx_path_system = get_nvidia_dll_path()

if nvngx_path_system is None:
logging.error("Nvidia driver libraries haven't been found. DLSS might not work!")
logging.error(
"Nvidia driver libraries haven't been found. DLSS might not work!"
)
return

# Reinstall nvngx if not present (acts as migration for this new patch)
Expand All @@ -79,10 +75,14 @@ def md5sum(file):

# If the system dll is different than the one in the bottle, reinstall them
# Nvidia driver updates can change this DLL, so this should be checked at each startup
if md5sum(os.path.join(nvngx_path_bottle, "nvngx.dll")) != md5sum(os.path.join(get_nvidia_dll_path(), "nvngx.dll")):
if md5sum(os.path.join(nvngx_path_bottle, "nvngx.dll")) != md5sum(
os.path.join(get_nvidia_dll_path(), "nvngx.dll")
):
NVAPIComponent(bottle_config.NVAPI).install(bottle_config)
return

if md5sum(os.path.join(nvngx_path_bottle, "_nvngx.dll")) != md5sum(os.path.join(get_nvidia_dll_path(), "_nvngx.dll")):

if md5sum(os.path.join(nvngx_path_bottle, "_nvngx.dll")) != md5sum(
os.path.join(get_nvidia_dll_path(), "_nvngx.dll")
):
NVAPIComponent(bottle_config.NVAPI).install(bottle_config)
return
10 changes: 2 additions & 8 deletions bottles/backend/dlls/vkd3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@

class VKD3DComponent(DLLComponent):
dlls = {
"x86": [
"d3d12.dll",
"d3d12core.dll"
],
"x64": [
"d3d12.dll",
"d3d12core.dll"
]
"x86": ["d3d12.dll", "d3d12core.dll"],
"x64": ["d3d12.dll", "d3d12core.dll"],
}

@staticmethod
Expand Down
Loading

0 comments on commit 540f6fc

Please sign in to comment.