MCPcopy Create free account
hub / github.com/SolarLune/masterplan / OpenProjectFrom

Function OpenProjectFrom

project.go:557–1055  ·  view source on GitHub ↗
(filename string)

Source from the content-addressed store, hash-verified

555}
556
557func OpenProjectFrom(filename string) {
558
559 i := 0
560 for {
561
562 if i >= len(globals.RecentFiles) {
563 break
564 }
565
566 file := globals.RecentFiles[i]
567
568 if !FileExists(file) {
569 globals.RecentFiles = append(globals.RecentFiles[:i], globals.RecentFiles[i+1:]...)
570 } else {
571 i++
572 }
573
574 }
575
576 jsonData, err := os.ReadFile(filename)
577 if err != nil {
578 globals.EventLog.Log("Error: %s", true, err.Error())
579 } else {
580
581 json := string(jsonData)
582
583 if !gjson.Get(json, "version").Exists() && !gjson.Get(json, "Version").Exists() {
584 // if !gjson.Get(json, "pages").Exists() && !gjson.Get(json, "Tasks").Exists() {
585 globals.EventLog.Log("Warning: Cannot open project as it doesn't appear to be a valid MasterPlan project file. Please double-check to ensure it is valid.", true)
586 return
587 }
588
589 // Destroy resources before we load new ones
590 globals.Resources.Destroy()
591
592 log.Println("Load started.")
593
594 AddFileToRecentFilesList(filename)
595
596 log.Println("Recent files list updated...")
597
598 globals.EventLog.On = false
599
600 newProject := NewProject()
601 newProject.Loading = true
602 newProject.UndoHistory.On = false
603 globals.NextProject = newProject
604
605 brokenProject := false
606
607 savedImageFileNames := map[string]string{}
608
609 if ver, err := semver.Parse(gjson.Get(json, "version").String()); err != nil || ver.Minor < 8 {
610
611 globals.EventLog.Log("WARNING: Not all features from MasterPlan v0.7.2 have been re-implemented.\nPlease double-check the project to ensure it has been imported correctly, and\ncheck the roadmap under Help to see what remains to be re-implemented.\nIt would probably be best not to save over the original plan.", true)
612
613 // IMPORT v0.7!
614

Callers 3

ReloadMethod · 0.85
mainFunction · 0.85
ConstructMenusFunction · 0.85

Calls 15

LinkMethod · 0.95
AddXYMethod · 0.95
WidthMethod · 0.95
PathToAbsoluteMethod · 0.95
AddPageMethod · 0.95
SendMessageMethod · 0.95
SetPageMethod · 0.95
FileExistsFunction · 0.85
AddFileToRecentFilesListFunction · 0.85
NewProjectFunction · 0.85
WriteImageToTempFunction · 0.85
NewMessageFunction · 0.85

Tested by

no test coverage detected