@@ -4,18 +4,29 @@ import {
44 type Artifact ,
55 type Asset ,
66 type AssetIndex ,
7+ type Classifiers ,
8+ type Library ,
79 type LoggingConfig ,
810 type Manifest ,
911 type VersionMetaModern ,
1012} from "@/lib/schemas/minecrafts-schemas" ;
1113import { download } from "@tauri-apps/plugin-upload" ;
1214import Value from "typebox/value" ;
13- import { TreeAssetIndexes , TreeAssetObjects , TreeLogging } from "@/constants/application" ;
15+ import {
16+ TreeAssetIndexes ,
17+ TreeAssetObjects ,
18+ TreeLibraries ,
19+ TreeLogging ,
20+ TreeNatives ,
21+ } from "@/constants/application" ;
1422import { readTextFile } from "@tauri-apps/plugin-fs" ;
1523import { extractError } from "@/lib/helpers/extract-error" ;
1624import { log } from "@/lib/handlers/log" ;
1725import { validateFileSize } from "@/lib/helpers/validate-file-size" ;
1826import { checksum } from "@/lib/helpers/checksum" ;
27+ import { evaluateRules } from "@/lib/helpers/parse-rules" ;
28+ import { transformPlatform } from "@/lib/helpers/transform-platform" ;
29+ import { unzipFile } from "@/lib/helpers/unzip-file" ;
1930
2031
2132async function fetchVersionManifest ( ) : Promise < Manifest > {
@@ -101,3 +112,40 @@ async function downloadAssets(path: string) {
101112 log . error ( `Downloading asset (${ path } ) failed: ${ error . reason } ` ) ;
102113 }
103114}
115+
116+ async function downloadClassifiers ( classifiers : Classifiers , version : string , extract : boolean ) {
117+ const platform = transformPlatform ( ) ;
118+ const key = `natives-${ platform } ` as keyof typeof classifiers ;
119+ const native = classifiers [ key ] ;
120+
121+ if ( ! native ) {
122+ throw new Error ( `Expected native (${ key } ) not found` ) ;
123+ }
124+
125+ await downloadArtifact ( native , `${ TreeLibraries } ` ) ;
126+
127+ if ( extract ) {
128+ const path = `${ TreeLibraries } /${ native . path } ` ;
129+
130+ await unzipFile ( path , `${ TreeNatives } /${ version } ` ) ;
131+ }
132+ }
133+
134+ async function downloadLibraries ( libraries : Library [ ] , version : string ) {
135+ for ( const library of libraries ) {
136+ const rules = library . rules ;
137+
138+ if ( rules && ! await evaluateRules ( rules ) ) {
139+ continue ;
140+ }
141+ await downloadArtifact ( library . downloads . artifact , TreeLibraries ) ;
142+
143+ if ( library . downloads . classifiers ) {
144+ await downloadClassifiers (
145+ library . downloads . classifiers ,
146+ version ,
147+ library . extract != undefined ,
148+ ) ;
149+ }
150+ }
151+ }
0 commit comments