| 753 | |
| 754 | |
| 755 | bool VarTable::Read_JSON( const std::string& file) |
| 756 | { |
| 757 | rapidjson::Document doc; |
| 758 | /* |
| 759 | FILE* fp = fopen(file.c_str(), "r"); |
| 760 | if (!fp) return false; |
| 761 | char readBuffer[65536]; |
| 762 | rapidjson::FileReadStream is(fp, readBuffer, sizeof(readBuffer)); |
| 763 | */ |
| 764 | |
| 765 | wxString sfn = file; |
| 766 | wxFileName fn(sfn); |
| 767 | // sfn.Replace(".json", ".zip"); |
| 768 | |
| 769 | |
| 770 | wxFileInputStream fis(sfn); |
| 771 | |
| 772 | if (!fis.IsOk()) { |
| 773 | wxLogError(wxS("Couldn't open the file '%s'."), sfn); |
| 774 | return false; |
| 775 | } |
| 776 | |
| 777 | /* compressed file |
| 778 | wxZipInputStream zis(fis); |
| 779 | std::unique_ptr<wxZipEntry> upZe; |
| 780 | |
| 781 | if ((upZe.reset(zis.GetNextEntry()), upZe) == nullptr) { |
| 782 | wxLogError(wxS("Zip file '%s' is empty"), sfn); |
| 783 | return false; |
| 784 | } |
| 785 | |
| 786 | // Read 'zis' to access the 'upZe's' data. |
| 787 | if (!zis.CanRead()) { |
| 788 | wxLogError(wxS("Could not read the zip entry '%s'."), upZe->GetName()); |
| 789 | return false; |
| 790 | } |
| 791 | */ |
| 792 | wxStringOutputStream os; |
| 793 | |
| 794 | //zis.Read(os); |
| 795 | fis.Read(os); |
| 796 | |
| 797 | rapidjson::StringStream is(os.GetString().c_str()); |
| 798 | |
| 799 | // doc.ParseStream(is); |
| 800 | // SAM issue 1856 handle parsing Inf values for max tier usage values. |
| 801 | doc.ParseStream< rapidjson::kParseNanAndInfFlag>( is); |
| 802 | if (doc.HasParseError()) { |
| 803 | // throw? |
| 804 | // fclose(fp); |
| 805 | // wxLogError(wxS("Could not read the zip file string conversion '%s'."), upZe->GetName()); |
| 806 | wxLogError(wxS("Could not read the json file string conversion '%s'."), sfn); |
| 807 | return false; |
| 808 | } |
| 809 | else { |
| 810 | Read_JSON(doc); |
| 811 | // fclose(fp); |
| 812 | return true; |
nothing calls this directly
no test coverage detected