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

Method DetectNewMods

app.go:499–586  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

497}
498
499func (a *App) DetectNewMods() (*DetectResult, error) {
500 a.mu.Lock()
501 modsDir := a.ProjectData.ModsDir
502 snapshot := a.ProjectData.LatestSnapshot
503 savedNewMods := a.ProjectData.SavedNewMods
504 a.mu.Unlock()
505
506 if modsDir == "" {
507 return nil, fmt.Errorf("please select a mod folder first")
508 }
509 if snapshot == nil {
510 return nil, fmt.Errorf("no snapshot available. Create a snapshot first.")
511 }
512
513 entries, err := os.ReadDir(modsDir)
514 if err != nil {
515 return nil, fmt.Errorf("mod folder does not exist: %w", err)
516 }
517
518 currentMods := make(map[string]bool)
519 for _, e := range entries {
520 if !e.IsDir() && filepath.Ext(e.Name()) == ".jar" {
521 currentMods[e.Name()] = true
522 }
523 }
524
525 if savedNewMods != nil {
526 var filtered []string
527 for _, mod := range savedNewMods {
528 if currentMods[mod] {
529 filtered = append(filtered, mod)
530 }
531 }
532 if len(filtered) < len(savedNewMods) {
533 a.mu.Lock()
534 a.ProjectData.SavedNewMods = filtered
535 a.ProjectModified = true
536 a.mu.Unlock()
537 a.emitLog(fmt.Sprintf("Removed %d deleted mod(s) from 'saved new mods' list.", len(savedNewMods)-len(filtered)), LogInfo)
538 }
539 }
540
541 snapshotMods := make(map[string]bool)
542 for _, mod := range snapshot.Mods {
543 snapshotMods[mod] = true
544 }
545
546 var deletedMods []string
547 for mod := range snapshotMods {
548 if !currentMods[mod] {
549 deletedMods = append(deletedMods, mod)
550 }
551 }
552
553 if len(deletedMods) > 0 {
554 a.emitLog(fmt.Sprintf("Detected %d deleted mod(s). Updating snapshot...", len(deletedMods)), LogInfo)
555 var updatedMods []string
556 for _, mod := range snapshot.Mods {

Callers

nothing calls this directly

Calls 2

emitLogMethod · 0.95

Tested by

no test coverage detected