MCPcopy Index your code
hub / github.com/WendellCraft/ModpackDebuggerKit / modrinthSync

Method modrinthSync

app.go:675–832  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

673}
674
675func (a *App) modrinthSync() {
676 a.mu.Lock()
677 modsDir := a.ProjectData.ModsDir
678 a.mu.Unlock()
679
680 if modsDir == "" {
681 a.emitLog("Error: Please select a mod folder first", LogError)
682 wailsRuntime.EventsEmit(a.ctx, "sync-complete", nil)
683 return
684 }
685
686 entries, err := os.ReadDir(modsDir)
687 if err != nil {
688 a.emitLog("Error: Mod folder does not exist", LogError)
689 wailsRuntime.EventsEmit(a.ctx, "sync-complete", nil)
690 return
691 }
692
693 var jarFiles []string
694 for _, e := range entries {
695 if !e.IsDir() && filepath.Ext(e.Name()) == ".jar" {
696 jarFiles = append(jarFiles, e.Name())
697 }
698 }
699
700 if len(jarFiles) == 0 {
701 a.emitLog("No .jar files found in the mods folder.", LogWarning)
702 wailsRuntime.EventsEmit(a.ctx, "sync-complete", nil)
703 return
704 }
705
706 a.emitLog(fmt.Sprintf("Starting Modrinth dependency sync for %d mods...", len(jarFiles)), LogInfo)
707
708 modHashes := make(map[string]string)
709 for i, jf := range jarFiles {
710 if a.getSyncCancelled() {
711 wailsRuntime.EventsEmit(a.ctx, "sync-complete", nil)
712 return
713 }
714 filePath := filepath.Join(modsDir, jf)
715 hash, err := getSHA1Hash(filePath)
716 if err == nil && hash != "" {
717 modHashes[jf] = hash
718 }
719 a.emitLog(fmt.Sprintf("Hashing mods... (%d/%d)", i+1, len(jarFiles)), LogProgress)
720 wailsRuntime.EventsEmit(a.ctx, "sync-progress", map[string]int{"current": i + 1, "total": len(jarFiles)})
721 }
722
723 hashToFilename := make(map[string]string)
724 for k, v := range modHashes {
725 hashToFilename[v] = k
726 }
727
728 newDepsCount := 0
729 i := 0
730 for jarFile, fileHash := range modHashes {
731 if a.getSyncCancelled() {
732 wailsRuntime.EventsEmit(a.ctx, "sync-complete", nil)

Callers 1

StartModrinthSyncMethod · 0.95

Calls 7

emitLogMethod · 0.95
getSyncCancelledMethod · 0.95
getSHA1HashFunction · 0.85
getModInfoFunction · 0.85
getProjectVersionsFunction · 0.85
joinStringsFunction · 0.85

Tested by

no test coverage detected