Files
Launcher/core_lib/__init__.py
T
wei ad38cf726e Update to 0.1.7-alpha
Add custom game directory and launch log controls

CoreLib update to 0.1.9
2026-11-14 17:10:33 +08:00

674 lines
17 KiB
Python

__version__ = '0.1.9'
__description__ = """
A library for Python-based block game launcher.
Some reference implementation are from bk_core.
"""
from .common.common import (
DEFAULT_HASH_CHUNK_SIZE,
DEFAULT_DOWNLOAD_CHUNK_SIZE,
THREADED_DOWNLOAD_MAX_WORKERS,
SUPPORTED_HASH_ALGORITHMS,
FileObject,
generate_random_suffix,
download_file,
download_multiple_files,
unzip,
get_platform_info,
is_valid_zipfile,
bytes_to_data_url,
attempt,
)
from .common.exception import (
LauncherException,
LauncherHTTPException,
HashMismatchException,
UnsupportedHashAlgorithmException,
UnsupportedPlatformException,
VersionNotSelectedException,
VersionManifestFetchException,
VersionManifestSaveException,
NoVersionFoundException,
NoSpecifiedVersionKeyException,
VersionDataKeyNotFoundException,
VersionManifestException,
DependencyException,
NativeResolveException,
DownloadException,
ExtractException,
AssetManifestFetchException,
AssetManifestSaveException,
AssetManifestException,
AssetDataKeyNotFoundException,
JavaRuntimeException,
JavaRuntimeParseException,
RuntimeManifestFetchException,
RuntimeManifestDataException,
ProfileException,
ProfileSaveException,
ProfileLoadException,
ProfileKeyNotFoundException,
AccountException,
AccountSaveException,
AccountLoadException,
AccountKeyNotFoundException,
AuthenticationException,
AuthenticationConnectException,
AuthenticationSessionException,
ThirdPartyAPIException,
SettingsError,
ModelRegistrationError,
ConfigValidationError,
ArgumentError,
ArgumentValueError,
)
from .common.python import (
is_function_in_file,
)
from .game.account import (
get_account_sample,
get_accounts_sample,
Account,
create_account_data_from_object,
SUPPORT_DATA_URL_IMAGE_TYPE,
is_valid_account_avatar,
is_account_valid,
is_accounts_valid,
list_accounts,
is_account_exists,
get_account,
get_current_account_id,
get_active_account_id,
get_current_account,
get_active_account,
set_current_account_id,
set_active_account_id,
add_account,
create_account,
update_account,
remove_account,
convert_account_data_to_object,
read_account_file,
read_accounts_file,
create_or_save_account_file,
get_account_avatar,
save_account_avatar,
create_or_save_accounts_file,
)
from .game.argument import (
FeatureSpec,
validate_resolution,
FEATURE_SPECS,
compare_versions,
is_argument_allowed,
PLACEHOLDER_PATTERN,
replace_placeholders,
ArgumentMappings,
convert_argument_to_multiple_string,
find_game_and_jvm_args,
parse_and_generate_arguments,
append_missing_necessary_jvm_arguments,
find_match_feature_argument,
generate_enabled_feature_arguments,
generate_feature_placeholders,
generate_launch_command,
is_a_argument,
generate_argument_details,
is_same_argument,
)
from .game.asset import (
MOJANG_RESOURCE_ENDPOINT,
ASSET_DOWNLOAD_MAX_WORKERS,
ASSET_CHECK_MAX_WORKERS,
fetch_asset_manifest,
fetch_and_save_asset_manifest,
collect_assets_from_manifest,
download_assets_and_copy,
correct_assets_name_and_copy,
download_assets,
check_assets_exist,
read_exist_assets_indexes,
find_correct_assets_dir,
)
from .game.authentication import (
MICROSOFT_DEVICE_CODE_URL,
MICROSOFT_TOKEN_URL,
XBOX_AUTH_URL,
XSTS_AUTH_URL,
MINECRAFT_LOGIN_URL,
MINECRAFT_ENTITLEMENTS_URL,
MINECRAFT_PROFILE_URL,
auth_exception_handler,
get_device_code,
get_microsoft_token,
get_xbox_token_and_user_hash,
get_xsts_token,
extract_xuid,
get_xbox_xuid,
get_minecraft_access_token,
get_account_entitlements,
get_minecraft_profile,
has_minecraft_license,
refresh_microsoft_token,
is_access_token_valid,
)
from .game.library import (
parse_maven_coordinate,
convert_maven_version,
generate_filename_from_maven_coordinate,
generate_repo_path,
is_complete_maven_url,
generate_repo_url,
is_library_allowed,
filter_platform_libraries,
get_natives_platform_info,
is_native_allowed,
is_legacy_native_allowed,
generate_relative_path_by_maven_coordinate,
remove_duplicate_artifacts,
generate_formatted_artifact_with_name,
)
from .game.library_core import (
collect_library_artifacts,
locate_natives_extract_dir,
locate_natives_extract_dir_by_manifest,
collect_native_artifacts,
download_libraries,
unzip_natives,
check_libraries_exists_and_verify,
check_natives_exists,
check_full_libraries_exists,
generate_classpath,
download_full_libraries,
)
from .game.libraryx import (
convert_maven_version_with_extra,
generate_unique_library_key,
normalize_library_to_common_struct,
LibraryPreference,
PREFER_BY_HIGHER_VERSION,
PREFER_BY_LOWER_VERSION,
PREFER_MOD_LIBRARY,
PREFER_INHERITS_LIBRARY,
LIBRARY_PREFER_OPTIONS,
compare_library_versions,
deduplicate_libraries,
)
from .game.mod.fabric import (
FABRIC_META_VERSION_ENDPOINT_V2,
FABRIC_META_LOADER_VERSION_ENDPOINT_V2,
FABRIC_META_LOADER_MANIFEST_ENDPOINT_V2,
FABRIC_MAVEN_URL,
get_full_version_string,
fetch_fabric_versions,
is_version_supported_and_stable,
get_version_support_loader_list,
get_loader_manifest_from_loader_data,
)
from .game.mod.forge_like import (
FORGE_MAVEN_URL,
FORGE_METADATA_URL,
fetch_forge_versions,
)
from .game.mod.mod_core import (
LOADER_LIBRARY_MARKERS,
detect_loader_name,
find_useful_part_in_mod_version_manifest,
merge_necessary_dependencies,
merge_arguments,
merge_game_and_jvm_args,
merge_manifest,
)
from .game.mod.rules import (
MOD_LOADER_RULES,
)
from .game.profile import (
get_profile_sample,
Profile,
create_profile_data_from_object,
create_profile,
create_or_save_profile_file,
read_profile_file,
is_profiles_valid,
is_profile_valid,
is_profile_exists,
list_profiles,
get_profile,
set_current_profile_id,
get_current_profile_id,
get_last_played_profile_id,
add_profile,
remove_profile,
duplicate_profile,
convert_profile_data_to_object,
update_profile,
set_last_used_time,
set_last_used_time_to_current,
)
from .game.third_party import (
MC_HEADS_HEAD_ENDPOINT,
get_minecraft_head_url,
get_minecraft_head,
)
from .game.version_info import (
MOJANG_VERSION_MANIFEST_V2,
MOJANG_VERSION_MANIFEST,
MOJANG_LIBRARIES_ENDPOINT,
NATIVE_OS_KEY_MAP,
NATIVE_OS_RULE_MAP,
NATIVE_ARCH_KEY_MAP,
NATIVE_OLD_TO_NEW_ARCH,
NATIVE_NEW_TO_OLD_ARCH,
RUNTIME_PLATFORM_MAP,
RUNTIME_ARCH_EMPTY,
RUNTIME_ARCH_MAP,
get_version_manifest,
get_latest_version,
get_all_versions,
get_available_version_types,
get_specific_version_manifest_url,
get_specific_version_manifest_url_and_hash,
fetch_specific_version_manifest,
get_specific_version_manifest,
default_java_version,
find_useful_part_in_specific_version_manifest,
get_core_file_download_url_and_hash,
validate_version_manifest,
save_version_manifest,
fetch_and_save_version_manifest,
download_core_file,
check_core_file_exists_and_verify,
LATEST_VERSION_ALIASES,
)
from .i18n import (
SUPPORTED_LANGUAGES,
TranslationManager,
)
from .launcher.object import (
Launcher,
)
from .log.default import (
DEFAULT_FORMAT,
DEFAULT_DATE_FORMAT,
get_colorful_handler,
LogEmitter,
LogCaptureHandler,
)
from .qt.hack import (
move_window_to_center,
is_main_thread,
recolor_standard_icon,
recolor_pixmap,
recolor_icon,
is_light_theme,
add_icon_padding,
data_url_to_qt_image,
)
from .qt.item_button import (
ItemButton,
)
from .qt.messagebox import (
create_messagebox,
error,
info,
warning,
error_with_plain_text,
ask_yes_no_with_plain_text,
)
from .qt.progress_dialog import (
ProgressRow,
ProgressDialog,
)
from .runtime.java import (
get_java_version,
find_java_installations,
)
from .runtime.mojang import (
MOJANG_RUNTIME_MANIFEST,
RUNTIME_CHECK_MAX_WORKERS,
RUNTIME_DOWNLOAD_MAX_WORKERS,
get_current_platform_runtime_key,
fetch_runtime_manifest,
find_support_runtime_manifests_info,
get_support_runtime_manifest,
RuntimeCheckResult,
collect_runtime_files,
post_process_runtime_dir,
download_java_runtimes,
)
__all__ = [
# common.common
"DEFAULT_HASH_CHUNK_SIZE",
"DEFAULT_DOWNLOAD_CHUNK_SIZE",
"THREADED_DOWNLOAD_MAX_WORKERS",
"SUPPORTED_HASH_ALGORITHMS",
"FileObject",
"generate_random_suffix",
"download_file",
"download_multiple_files",
"unzip",
"get_platform_info",
"is_valid_zipfile",
"bytes_to_data_url",
"attempt",
# common.exception
"LauncherException",
"LauncherHTTPException",
"HashMismatchException",
"UnsupportedHashAlgorithmException",
"UnsupportedPlatformException",
"VersionNotSelectedException",
"VersionManifestFetchException",
"VersionManifestSaveException",
"NoVersionFoundException",
"NoSpecifiedVersionKeyException",
"VersionDataKeyNotFoundException",
"VersionManifestException",
"DependencyException",
"NativeResolveException",
"DownloadException",
"ExtractException",
"AssetManifestFetchException",
"AssetManifestSaveException",
"AssetManifestException",
"AssetDataKeyNotFoundException",
"JavaRuntimeException",
"JavaRuntimeParseException",
"RuntimeManifestFetchException",
"RuntimeManifestDataException",
"ProfileException",
"ProfileSaveException",
"ProfileLoadException",
"ProfileKeyNotFoundException",
"AccountException",
"AccountSaveException",
"AccountLoadException",
"AccountKeyNotFoundException",
"AuthenticationException",
"AuthenticationConnectException",
"AuthenticationSessionException",
"ThirdPartyAPIException",
"SettingsError",
"ModelRegistrationError",
"ConfigValidationError",
"ArgumentError",
"ArgumentValueError",
# common.python
"is_function_in_file",
# game.account
"get_account_sample",
"get_accounts_sample",
"Account",
"create_account_data_from_object",
"SUPPORT_DATA_URL_IMAGE_TYPE",
"is_valid_account_avatar",
"is_account_valid",
"is_accounts_valid",
"list_accounts",
"is_account_exists",
"get_account",
"get_current_account_id",
"get_active_account_id",
"get_current_account",
"get_active_account",
"set_current_account_id",
"set_active_account_id",
"add_account",
"create_account",
"update_account",
"remove_account",
"convert_account_data_to_object",
"read_account_file",
"read_accounts_file",
"create_or_save_account_file",
"get_account_avatar",
"save_account_avatar",
"create_or_save_accounts_file",
# game.argument
"FeatureSpec",
"validate_resolution",
"FEATURE_SPECS",
"compare_versions",
"is_argument_allowed",
"PLACEHOLDER_PATTERN",
"replace_placeholders",
"ArgumentMappings",
"convert_argument_to_multiple_string",
"find_game_and_jvm_args",
"parse_and_generate_arguments",
"append_missing_necessary_jvm_arguments",
"find_match_feature_argument",
"generate_enabled_feature_arguments",
"generate_feature_placeholders",
"generate_launch_command",
"is_a_argument",
"generate_argument_details",
"is_same_argument",
# game.asset
"MOJANG_RESOURCE_ENDPOINT",
"ASSET_DOWNLOAD_MAX_WORKERS",
"ASSET_CHECK_MAX_WORKERS",
"fetch_asset_manifest",
"fetch_and_save_asset_manifest",
"collect_assets_from_manifest",
"download_assets_and_copy",
"correct_assets_name_and_copy",
"download_assets",
"check_assets_exist",
"read_exist_assets_indexes",
"find_correct_assets_dir",
# game.authentication
"MICROSOFT_DEVICE_CODE_URL",
"MICROSOFT_TOKEN_URL",
"XBOX_AUTH_URL",
"XSTS_AUTH_URL",
"MINECRAFT_LOGIN_URL",
"MINECRAFT_ENTITLEMENTS_URL",
"MINECRAFT_PROFILE_URL",
"auth_exception_handler",
"get_device_code",
"get_microsoft_token",
"get_xbox_token_and_user_hash",
"get_xsts_token",
"extract_xuid",
"get_xbox_xuid",
"get_minecraft_access_token",
"get_account_entitlements",
"get_minecraft_profile",
"has_minecraft_license",
"refresh_microsoft_token",
"is_access_token_valid",
# game.library
"parse_maven_coordinate",
"convert_maven_version",
"generate_filename_from_maven_coordinate",
"generate_repo_path",
"is_complete_maven_url",
"generate_repo_url",
"is_library_allowed",
"filter_platform_libraries",
"get_natives_platform_info",
"is_native_allowed",
"is_legacy_native_allowed",
"generate_relative_path_by_maven_coordinate",
"remove_duplicate_artifacts",
"generate_formatted_artifact_with_name",
# game.library_core
"collect_library_artifacts",
"locate_natives_extract_dir",
"locate_natives_extract_dir_by_manifest",
"collect_native_artifacts",
"download_libraries",
"unzip_natives",
"check_libraries_exists_and_verify",
"check_natives_exists",
"check_full_libraries_exists",
"generate_classpath",
"download_full_libraries",
# game.libraryx
"convert_maven_version_with_extra",
"generate_unique_library_key",
"normalize_library_to_common_struct",
"LibraryPreference",
"PREFER_BY_HIGHER_VERSION",
"PREFER_BY_LOWER_VERSION",
"PREFER_MOD_LIBRARY",
"PREFER_INHERITS_LIBRARY",
"LIBRARY_PREFER_OPTIONS",
"compare_library_versions",
"deduplicate_libraries",
# game.mod.fabric
"FABRIC_META_VERSION_ENDPOINT_V2",
"FABRIC_META_LOADER_VERSION_ENDPOINT_V2",
"FABRIC_META_LOADER_MANIFEST_ENDPOINT_V2",
"FABRIC_MAVEN_URL",
"get_full_version_string",
"fetch_fabric_versions",
"is_version_supported_and_stable",
"get_version_support_loader_list",
"get_loader_manifest_from_loader_data",
# game.mod.forge
"FORGE_MAVEN_URL",
"FORGE_METADATA_URL",
"fetch_forge_versions",
# game.mod.mod_core
"LOADER_LIBRARY_MARKERS",
"detect_loader_name",
"find_useful_part_in_mod_version_manifest",
"merge_necessary_dependencies",
"merge_arguments",
"merge_game_and_jvm_args",
"merge_manifest",
# game.mod.rules
"MOD_LOADER_RULES",
# game.profile
"get_profile_sample",
"Profile",
"create_profile_data_from_object",
"create_profile",
"create_or_save_profile_file",
"read_profile_file",
"is_profiles_valid",
"is_profile_valid",
"is_profile_exists",
"list_profiles",
"get_profile",
"set_current_profile_id",
"get_current_profile_id",
"get_last_played_profile_id",
"add_profile",
"remove_profile",
"duplicate_profile",
"convert_profile_data_to_object",
"update_profile",
"set_last_used_time",
"set_last_used_time_to_current",
# game.third_party
"MC_HEADS_HEAD_ENDPOINT",
"get_minecraft_head_url",
"get_minecraft_head",
# game.version_info
"MOJANG_VERSION_MANIFEST_V2",
"MOJANG_VERSION_MANIFEST",
"MOJANG_LIBRARIES_ENDPOINT",
"NATIVE_OS_KEY_MAP",
"NATIVE_OS_RULE_MAP",
"NATIVE_ARCH_KEY_MAP",
"NATIVE_OLD_TO_NEW_ARCH",
"NATIVE_NEW_TO_OLD_ARCH",
"RUNTIME_PLATFORM_MAP",
"RUNTIME_ARCH_EMPTY",
"RUNTIME_ARCH_MAP",
"get_version_manifest",
"get_latest_version",
"get_all_versions",
"get_available_version_types",
"get_specific_version_manifest_url",
"get_specific_version_manifest_url_and_hash",
"fetch_specific_version_manifest",
"get_specific_version_manifest",
"default_java_version",
"find_useful_part_in_specific_version_manifest",
"get_core_file_download_url_and_hash",
"validate_version_manifest",
"save_version_manifest",
"fetch_and_save_version_manifest",
"download_core_file",
"check_core_file_exists_and_verify",
"LATEST_VERSION_ALIASES",
# i18n
"SUPPORTED_LANGUAGES",
"TranslationManager",
# launcher.object
"Launcher",
# log.default
"DEFAULT_FORMAT",
"DEFAULT_DATE_FORMAT",
"get_colorful_handler",
"LogEmitter",
"LogCaptureHandler",
# qt.hack
"move_window_to_center",
"is_main_thread",
"recolor_standard_icon",
"recolor_pixmap",
"recolor_icon",
"is_light_theme",
"add_icon_padding",
"data_url_to_qt_image",
# qt.item_button
"ItemButton",
# qt.messagebox
"create_messagebox",
"error",
"info",
"warning",
"error_with_plain_text",
"ask_yes_no_with_plain_text",
# qt.progress_dialog
"ProgressRow",
"ProgressDialog",
# runtime.java
"get_java_version",
"find_java_installations",
# runtime.mojang
"MOJANG_RUNTIME_MANIFEST",
"RUNTIME_CHECK_MAX_WORKERS",
"RUNTIME_DOWNLOAD_MAX_WORKERS",
"get_current_platform_runtime_key",
"fetch_runtime_manifest",
"find_support_runtime_manifests_info",
"get_support_runtime_manifest",
"RuntimeCheckResult",
"collect_runtime_files",
"post_process_runtime_dir",
"download_java_runtimes",
]