z_mirror/fmm
git clone https://git.raiguard.me/z_mirror/fmm
269870f
predep-parsing
1package main 2 3import ( 4"bufio" 5"fmt" 6"os" 7"strings" 8) 9 10func expandDependencies (mods []ModIdent ) []ModIdent { 11visited := make (map [string ]bool ) 12 13dir ,err := newDir (modsDir ) 14if err != nil { 15abort (err ) 16 } 17 18for i := 0 ;i < len (mods );i += 1 { 19mod := mods [i ] 20visited [mod .Name ]= true 21file ,_ ,err := dir .Find (Dependency {mod ,DependencyRequired ,VersionAny }) 22var deps []Dependency 23if file != nil { 24realDeps ,err := file .Dependencies () 25if err != nil { 26errorln (err ) 27continue 28 } 29deps = * realDeps 30 }else { 31deps ,err = portalGetDependencies (mod ) 32if err != nil { 33errorln (err ) 34continue 35 } 36 } 37for _ ,dep := range deps { 38// FIXME: Dependency kind or version might be different / incompatible 39if dep .Ident .Name == "base" || visited [dep .Ident .Name ] { 40continue 41 } 42if dep .Kind == DependencyRequired || dep .Kind == DependencyNoLoadOrder { 43visited [dep .Ident .Name ]= true 44mods = append (mods ,dep .Ident ) 45 } 46 } 47 } 48 49return mods 50} 51 52func parseLogFile (filepath string ) []ModIdent { 53var output []ModIdent 54file ,err := os .Open (filepath ) 55if err != nil { 56fmt .Fprintf (os .Stderr ,"Error reading %s: %s" ,filepath ,err ) 57return output 58 } 59defer file .Close () 60 61fileScanner := bufio .NewScanner (file ) 62fileScanner .Split (bufio .ScanLines ) 63 64inChecksums := false 65for fileScanner .Scan () { 66line := fileScanner .Text () 67if ! strings .Contains (line ,"Checksum of" ) { 68if inChecksums { 69break 70 }else { 71continue 72 } 73 } 74inChecksums = true 75modName ,_ := strings .CutSuffix (strings .Split (strings .TrimSpace (line )," " )[3 ],":" ) 76if modName == "base" { 77continue 78 } 79output = append (output ,ModIdent {modName ,nil }) 80 } 81 82return output 83} 84 85func parseMods (input []string ,parseDependencies bool ) []ModIdent { 86var output []ModIdent 87 88for _ ,input := range input { 89if strings .HasSuffix (input ,".zip" ) { 90// TODO: Read from save 91 }else if strings .HasSuffix (input ,".log" ) { 92output = append (output ,parseLogFile (input )... ) 93 }else if strings .HasSuffix (input ,".json" ) { 94// TODO: info.json 95 }else if strings .HasPrefix (input ,"!" ) { 96// TODO: Mod set 97 }else { 98output = append (output ,newModIdent (input )) 99 } 100 } 101 102if parseDependencies { 103output = expandDependencies (output ) 104 } 105 106return output 107}