Created
August 6, 2023 20:18
-
-
Save Hammer2900/760938086a5146010f0c707c0cf877eb to your computer and use it in GitHub Desktop.
Bottle fast game install
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import uuid | |
from pathlib import Path | |
import sh | |
import fire | |
import yaml | |
DEFAULT_GAME_PATH = '/home/izot/Downloads/torrents/The-Last-Starship-Alpha-5a_setup.exe' | |
DEFAULT_BOTTLE_LIB_PATH = '/home/izot/Downloads/_bottle_area' | |
EXCLUDED_DIRS = ['Program Files', 'users', 'ProgramData', 'Program Files (x86)', 'windows'] | |
def create_list(items: list): | |
form_fields = [] | |
for item in items: | |
form_fields.extend(['FALSE', f'{item}']) | |
response = sh.yad( | |
'--list', | |
f'--title=Choice exe files', | |
f'--width=1100', | |
f'--height=400', | |
'--checklist', | |
'--column=Select', | |
'--column=Name', | |
*form_fields, | |
) | |
return [Path(line.split('|')[1]) for line in response.split('\n') if line.strip()] | |
def show_exes(base_dir): | |
base_dir = Path(base_dir) | |
exe_files = list(base_dir.glob('**/*.exe')) | |
for dir in EXCLUDED_DIRS: | |
exe_files = [f for f in exe_files if dir not in f.parts] | |
return create_list(exe_files) | |
def make_windows_path(path): | |
dirs = path.parts | |
return 'C:\\' + '\\'.join(dirs[dirs.index('drive_c') + 1 :]) | |
def main( | |
path: str = DEFAULT_GAME_PATH, | |
root_dir: str = DEFAULT_BOTTLE_LIB_PATH, | |
): | |
setup_file = Path(path) | |
root_path = Path(root_dir) | |
game_path = root_path / setup_file.stem.lower() | |
sh.flatpak.run( | |
'--command=bottles-cli', | |
'com.usebottles.bottles', | |
'new', | |
'--bottle-name', | |
setup_file.stem.lower(), | |
'--environment', | |
'gaming', | |
) | |
print('[create] bottle') | |
sh.flatpak.run( | |
'--command=bottles-cli', | |
'com.usebottles.bottles', | |
'run', | |
'-b', | |
setup_file.stem.lower(), | |
'-e', | |
setup_file, | |
) | |
print('[install] game') | |
with open(game_path / 'bottle.yml', 'r') as f: | |
data = yaml.safe_load(f) | |
for path in show_exes(game_path): | |
shortcut_info = { | |
'executable': path.name, | |
'id': str(uuid.uuid4()), | |
'name': path.stem, | |
'path': make_windows_path(path), | |
} | |
data['External_Programs'][shortcut_info['id']] = shortcut_info | |
with open(game_path / 'bottle.yml', 'w') as f: | |
yaml.safe_dump(data, f) | |
if __name__ == '__main__': | |
fire.Fire(main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment