| 152 | } |
| 153 | |
| 154 | bool ProjectInfo::LoadProject(const String& projectPath) |
| 155 | { |
| 156 | // Load Json file |
| 157 | StringAnsi fileData; |
| 158 | if (File::ReadAllText(projectPath, fileData)) |
| 159 | { |
| 160 | ShowProjectLoadError(TEXT("Failed to read file contents."), projectPath); |
| 161 | return true; |
| 162 | } |
| 163 | |
| 164 | // Parse Json data |
| 165 | rapidjson_flax::Document document; |
| 166 | document.Parse(fileData.Get(), fileData.Length()); |
| 167 | if (document.HasParseError()) |
| 168 | { |
| 169 | ShowProjectLoadError(TEXT("Failed to parse project contents. Ensure to have valid Json format."), projectPath); |
| 170 | return true; |
| 171 | } |
| 172 | |
| 173 | // Parse properties |
| 174 | Name = JsonTools::GetString(document, "Name", String::Empty); |
| 175 | ProjectPath = projectPath; |
| 176 | ProjectFolderPath = StringUtils::GetDirectoryName(projectPath); |
| 177 | const auto versionMember = document.FindMember("Version"); |
| 178 | if (versionMember != document.MemberEnd()) |
| 179 | { |
| 180 | auto& version = versionMember->value; |
| 181 | if (version.IsString()) |
| 182 | { |
| 183 | Version::Parse(version.GetText(), &Version); |
| 184 | } |
| 185 | else if (version.IsObject()) |
| 186 | { |
| 187 | Version = ::Version( |
| 188 | JsonTools::GetInt(version, "Major", 0), |
| 189 | JsonTools::GetInt(version, "Minor", 0), |
| 190 | JsonTools::GetInt(version, "Build", -1), |
| 191 | JsonTools::GetInt(version, "Revision", -1)); |
| 192 | } |
| 193 | } |
| 194 | if (Version.Revision() == 0) |
| 195 | Version = ::Version(Version.Major(), Version.Minor(), Version.Build()); |
| 196 | if (Version.Build() == 0 && Version.Revision() == -1) |
| 197 | Version = ::Version(Version.Major(), Version.Minor()); |
| 198 | Company = JsonTools::GetString(document, "Company", String::Empty); |
| 199 | Copyright = JsonTools::GetString(document, "Copyright", String::Empty); |
| 200 | GameTarget = JsonTools::GetString(document, "GameTarget", String::Empty); |
| 201 | EditorTarget = JsonTools::GetString(document, "EditorTarget", String::Empty); |
| 202 | EngineNickname = JsonTools::GetString(document, "EngineNickname", String::Empty); |
| 203 | const auto referencesMember = document.FindMember("References"); |
| 204 | if (referencesMember != document.MemberEnd()) |
| 205 | { |
| 206 | const auto& references = referencesMember->value.GetArray(); |
| 207 | References.Resize(references.Size()); |
| 208 | for (int32 i = 0; i < References.Count(); i++) |
| 209 | { |
| 210 | auto& reference = References[i]; |
| 211 | auto& value = references[i]; |
no test coverage detected