Skip to content

Commit

Permalink
Changed DosDevice Literal to Enum class
Browse files Browse the repository at this point in the history
  • Loading branch information
Root-Core committed Jan 9, 2025
1 parent 9404548 commit 30e1dc8
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import urllib.request
import functools

from enum import Enum
from pathlib import Path
from dataclasses import dataclass
from datetime import datetime, timezone
Expand All @@ -34,9 +35,27 @@

# TypeAliases
StrPath = Union[str, Path]
DosDeviceTypes = Literal['hd', 'network', 'floppy', 'cdrom']


# Enums
class DosDevice(Enum):
"""Enum for dos device types (mounted at 'prefix/dosdevices/')
Attributes:
NETWORK: A network device (UNC)
FLOPPY: A floppy drive
CD_ROM: A CD ROM drive
HD: A hard disk drive
"""

NETWORK = 'network'
FLOPPY = 'floppy'
CD_ROM = 'cdrom'
HD = 'hd'


# Helper classes
@dataclass
class ReplaceType:
"""Used for replacements"""
Expand All @@ -59,6 +78,7 @@ def __init__(self, version_string: str) -> None:
self.version_name: str = parts[1]


# Functions
@functools.lru_cache
def protondir() -> Path:
"""Returns the path to proton"""
Expand Down Expand Up @@ -951,12 +971,12 @@ def set_game_drive(enabled: bool) -> None:
protonmain.g_session.compat_config.discard("gamedrive")


def create_dos_device(letter: str = 'r', dev_type: DosDeviceTypes = 'cdrom') -> bool:
def create_dos_device(letter: str = 'r', dev_type: DosDevice = DosDevice.CD_ROM) -> bool:
"""Create a symlink to '/tmp' in the dosdevices folder of the prefix and register it
Args:
letter (str, optional): Letter that the device gets assigned to, must be len = 1
dev_type (DosDeviceTypes, optional): The device's type which will be registered to wine
dev_type (DosDevice, optional): The device's type which will be registered to wine
Returns:
bool: True, if device was created
Expand All @@ -972,7 +992,7 @@ def create_dos_device(letter: str = 'r', dev_type: DosDeviceTypes = 'cdrom') ->
dosdevice.symlink_to('/tmp', True)

# designate device as CD-ROM, requires 64-bit access
regedit_add('HKLM\\Software\\Wine\\Drives', f'{letter}:', 'REG_SZ', dev_type, True)
regedit_add('HKLM\\Software\\Wine\\Drives', f'{letter}:', 'REG_SZ', dev_type.value, True)
return True


Expand Down

0 comments on commit 30e1dc8

Please sign in to comment.