| 655 | } |
| 656 | |
| 657 | void DockLayout::load( |
| 658 | const std::string& path, |
| 659 | LoadResult& result, |
| 660 | DockLayout::Index& index_last_session) |
| 661 | { |
| 662 | pxAssert(!m_is_active); |
| 663 | |
| 664 | result = SUCCESS; |
| 665 | |
| 666 | std::optional<std::string> text = FileSystem::ReadFileToString(path.c_str()); |
| 667 | if (!text.has_value()) |
| 668 | { |
| 669 | Console.Error("Debugger: Failed to open layout file '%s'.", path.c_str()); |
| 670 | result = FILE_NOT_FOUND; |
| 671 | return; |
| 672 | } |
| 673 | |
| 674 | rapidjson::Document json; |
| 675 | if (json.Parse(text->c_str()).HasParseError() || !json.IsObject()) |
| 676 | { |
| 677 | Console.Error("Debugger: Failed to parse layout file '%s' as JSON.", path.c_str()); |
| 678 | result = INVALID_FORMAT; |
| 679 | return; |
| 680 | } |
| 681 | |
| 682 | auto format = json.FindMember("format"); |
| 683 | if (format == json.MemberEnd() || |
| 684 | !format->value.IsString() || |
| 685 | strcmp(format->value.GetString(), DEBUGGER_LAYOUT_FILE_FORMAT) != 0) |
| 686 | { |
| 687 | Console.Error("Debugger: Layout file '%s' has missing or invalid 'format' property.", path.c_str()); |
| 688 | result = INVALID_FORMAT; |
| 689 | return; |
| 690 | } |
| 691 | |
| 692 | auto version_major = json.FindMember("versionMajor"); |
| 693 | if (version_major == json.MemberEnd() || !version_major->value.IsInt()) |
| 694 | { |
| 695 | Console.Error("Debugger: Layout file '%s' has missing or invalid 'versionMajor' property.", path.c_str()); |
| 696 | result = MAJOR_VERSION_MISMATCH; |
| 697 | return; |
| 698 | } |
| 699 | |
| 700 | if (version_major->value.GetInt() != DEBUGGER_LAYOUT_FILE_VERSION_MAJOR) |
| 701 | { |
| 702 | result = MAJOR_VERSION_MISMATCH; |
| 703 | return; |
| 704 | } |
| 705 | |
| 706 | auto version_minor = json.FindMember("versionMinor"); |
| 707 | if (version_minor == json.MemberEnd() || !version_minor->value.IsInt()) |
| 708 | { |
| 709 | Console.Error("Debugger: Layout file '%s' has missing or invalid 'versionMinor' property.", path.c_str()); |
| 710 | result = MAJOR_VERSION_MISMATCH; |
| 711 | return; |
| 712 | } |
| 713 | |
| 714 | auto default_layout_hash = json.FindMember("defaultLayoutHash"); |
no test coverage detected