mindstorm38 / portablemc

A fast, reliable and cross-platform command-line Minecraft launcher and API for developers. Including fast and easy installation of common mod loaders such as Fabric, Forge, NeoForge and Quilt.
https://pypi.org/project/portablemc/
GNU General Public License v3.0
372 stars 20 forks source link

I don't understand how to properly install #144

Closed ZeralldMC closed 1 year ago

ZeralldMC commented 1 year ago

I have this code in my python app:

import os 
import eel
import jinja2
import requests
import json
import subprocess
from portablemc import StartOptions
from portablemc import Start
from portablemc import Context
from portablemc import VersionManifest
from portablemc import Version, VersionError, JvmLoadingError

@eel.expose
def startGame():
    main_dir = "app/user/data"
    work_dir = "app/user/minecraft"

    manifest = VersionManifest()
    ctx = Context(main_dir, work_dir)

    start_opts = StartOptions()
    start_opts.disable_multiplayer = False
    start_opts.username = "niceworld"
    start_opts.resolution = (700, 500)

    version_id = manifest.filter_latest("1.18.1")
    version = Version(ctx, version_id)

    try:
        version.install(jvm=True)
    except VersionError as e:
        print(f"Version '{e.version}' not found.")
    except JvmLoadingError as e:
        print(f"No JVM found for you system.")

    start = Start(version)
    start.prepare(start_opts)
    start.start()

I am using the EEL library to run functions through an HTML shell. Here is the console log on startup:

User path is exists, continue...
'app/' -> file: config.json founded
Traceback (most recent call last):
  File "C:\Users\Zerlald\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\eel\__init__.py", line 281, in _process_message
    return_val = _exposed_functions[message['name']](*message['args'])
  File "c:\Users\Zerlald\Desktop\ac launcher\app.py", line 200, in startGame
    version.install(jvm=True)
  File "C:\Users\Zerlald\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\portablemc\__init__.py", line 583, in install
    self.prepare_meta()
  File "C:\Users\Zerlald\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\portablemc\__init__.py", line 182, in prepare_meta
    version_meta, version_dir = self._prepare_meta_internal(self.id)
  File "C:\Users\Zerlald\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\portablemc\__init__.py", line 206, in _prepare_meta_internal
    version_dir = self.context.get_version_dir(version_id)
  File "C:\Users\Zerlald\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\portablemc\__init__.py", line 107, in get_version_dir
    return path.join(self.versions_dir, version_id)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2800.0_x64__qbz5n2kfra8p0\lib\ntpath.py", line 143, in join
    genericpath._check_arg_types('join', path, *paths)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2800.0_x64__qbz5n2kfra8p0\lib\genericpath.py", line 152, in _check_arg_types
    raise TypeError(f'{funcname}() argument must be str, bytes, or '
TypeError: join() argument must be str, bytes, or os.PathLike object, not 'tuple'

I really don't understand what the problem is. Excuse me if this seems silly to you, but I'm not very good at it.

mindstorm38 commented 1 year ago

The problem here is that your version_id variable is being set to a tuple. This is because the manifest.filter_latest("1.18.1") function returns a tuple (version, alias). So you should use version_id, alias = manifest.filter_latest("1.18.1") instead. The alias variable is a boolean that indicates if the given identifier is an alias or not. By the way for your exemple, it's not that useful to use filter_latest because 1.18.1, unlike snapshot or release, is not an alias.