Skip to content

Commit

Permalink
feat[close #3515]: Win11 support
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkobrombin committed Oct 15, 2024
1 parent bcbcf8f commit d656e2b
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 14 deletions.
2 changes: 1 addition & 1 deletion bottles/backend/managers/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ def __step_replace_font(config: BottleConfig, step: dict):
def __step_set_windows(config: BottleConfig, step: dict):
"""Set the Windows version."""
rk = RegKeys(config)
rk.set_windows(step.get("version"))
rk.lg_set_windows(step.get("version"))
return True

@staticmethod
Expand Down
13 changes: 7 additions & 6 deletions bottles/backend/managers/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ def check_bottles(self, silent: bool = False):

def process_bottle(bottle):
_name = bottle
_bottle = os.path.join(Paths.bottles, bottle)
_bottle = str(os.path.join(Paths.bottles, bottle))
_placeholder = os.path.join(_bottle, "placeholder.yml")
_config = os.path.join(_bottle, "bottle.yml")

Expand Down Expand Up @@ -852,7 +852,7 @@ def process_bottle(bottle):

# Check if the path in the bottle config corresponds to the folder name
# if not, change the config to reflect the folder name
# if the folder name is "illegal" accross all platforms, rename the folder
# if the folder name is "illegal" across all platforms, rename the folder

# "universal" platform works for all filesystem/OSes
sane_name = pathvalidate.sanitize_filepath(_name, platform="universal")
Expand All @@ -864,7 +864,9 @@ def process_bottle(bottle):
if sane_name != _name:
# This hopefully doesn't happen, but it's managed
logging.warning(f"Broken path in bottle {_name}, fixing...")
shutil.move(_bottle, os.path.join(Paths.bottles, sane_name))
shutil.move(
_bottle, str(os.path.join(Paths.bottles, sane_name))
)
# Restart the process bottle function. Normally, can't be recursive!
process_bottle(sane_name)
return
Expand Down Expand Up @@ -1112,8 +1114,7 @@ def create_bottle_from_config(self, config: BottleConfig) -> bool:
res = self.dependency_manager.install(config, dep)
if not res.ok:
logging.error(
_("Failed to install dependency: %s")
% dep.get("Description", "n/a"),
_("Failed to install dependency: %s") % dependency,
jn=True,
)
return False
Expand Down Expand Up @@ -1364,7 +1365,7 @@ def components_check():
if (
"soda" not in runner_name.lower() and "caffe" not in runner_name.lower()
): # Caffe/Soda came with win10 by default
rk.set_windows(config.Windows)
rk.lg_set_windows(config.Windows)
wineboot.update()

FileUtils.wait_for_files(reg_files)
Expand Down
8 changes: 4 additions & 4 deletions bottles/backend/wine/catalogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"CSDVersionHex": "0",
"CurrentBuild": "22000",
"CurrentBuildNumber": "22000",
"CurrentVersion": "10.0",
"CurrentVersion": "6.3",
"CurrentMinorVersionNumber": "0",
"CurrentMajorVersionNumber": "a", # 10
"ProductType": "WinNT",
Expand All @@ -13,9 +13,9 @@
"win10": {
"CSDVersion": "",
"CSDVersionHex": "0",
"CurrentBuild": "17763",
"CurrentBuildNumber": "17763",
"CurrentVersion": "10.0",
"CurrentBuild": "19043",
"CurrentBuildNumber": "19043",
"CurrentVersion": "6.3",
"CurrentMinorVersionNumber": "0",
"CurrentMajorVersionNumber": "a", # 10
"ProductType": "WinNT",
Expand Down
11 changes: 11 additions & 0 deletions bottles/backend/wine/regkeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from bottles.backend.wine.catalogs import win_versions
from bottles.backend.wine.reg import Reg
from bottles.backend.wine.wineboot import WineBoot
from bottles.backend.wine.winecfg import WineCfg

logging = Logger()

Expand All @@ -14,6 +15,16 @@ def __init__(self, config: BottleConfig):
self.config = config
self.reg = Reg(self.config)

def lg_set_windows(self, version: str):
"""
Legacy method to change Windows version in a bottle using
the Wine Configuration tool.
"""
winecfg = WineCfg(self.config)
res = winecfg.set_windows_version(version)
if not res.ok:
raise ValueError(f"Failed to set Windows version to {version}")

def set_windows(self, version: str):
"""
Change Windows version in a bottle from the given
Expand Down
28 changes: 28 additions & 0 deletions bottles/backend/wine/winecfg.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,37 @@
import os
import time

from bottles.backend.logger import Logger
from bottles.backend.wine.wineprogram import WineProgram
from bottles.backend.wine.winedbg import WineDbg
from bottles.backend.wine.wineboot import WineBoot

logging = Logger()


class WineCfg(WineProgram):
program = "Wine Configuration"
command = "winecfg"

def set_windows_version(self, version):
logging.info(f"Setting Windows version to {version}")

winedbg = WineDbg(self.config)
wineboot = WineBoot(self.config)

wineboot.kill()

res = self.launch(
args=f"-v {version}",
communicate=True,
environment={
"DISPLAY": os.environ.get("DISPLAY", ":0"),
"WAYLAND_DISPLAY": os.environ.get("WAYLAND_DISPLAY", ""),
},
action_name="set_windows_version",
)

winedbg.wait_for_process("winecfg")
wineboot.restart()

return res
5 changes: 4 additions & 1 deletion bottles/backend/wine/wineprogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ def launch(
post_script=post_script,
cwd=cwd,
arguments=program_args,
).run()
)

# logging.info("Executing command:", res.command)
res = res.run()
return res

def launch_terminal(self, args: Optional[str] = None):
Expand Down
2 changes: 1 addition & 1 deletion bottles/frontend/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ def edit_bottle(self):
mng.update_config(bottle, k, v, scope="Environment_Variables")

if _win is not None:
RegKeys(bottle).set_windows(_win)
RegKeys(bottle).lg_set_windows(_win)

if _runner is not None:
Runner.runner_update(bottle, mng, _runner)
Expand Down
2 changes: 1 addition & 1 deletion bottles/frontend/views/bottle_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ def update(result, error=False):
config=self.config, key="Windows", value=windows_version
).data["config"]

RunAsync(rk.set_windows, callback=update, version=windows_version)
RunAsync(rk.lg_set_windows, callback=update, version=windows_version)
break

def __set_language(self, *_args):
Expand Down

0 comments on commit d656e2b

Please sign in to comment.