| 986 | } |
| 987 | |
| 988 | String getState(const char* const key) const override |
| 989 | { |
| 990 | #if CARDINAL_VARIANT_MINI || !defined(HEADLESS) |
| 991 | if (std::strcmp(key, "windowSize") == 0) |
| 992 | return fState.windowSize; |
| 993 | #endif |
| 994 | |
| 995 | if (std::strcmp(key, "comment") == 0) |
| 996 | return fState.comment; |
| 997 | if (std::strcmp(key, "screenshot") == 0) |
| 998 | return fState.screenshot; |
| 999 | |
| 1000 | if (std::strcmp(key, "patch") != 0) |
| 1001 | return String(); |
| 1002 | if (fAutosavePath.empty()) |
| 1003 | return String(); |
| 1004 | |
| 1005 | std::vector<uint8_t> data; |
| 1006 | |
| 1007 | { |
| 1008 | const ScopedContext sc(this); |
| 1009 | |
| 1010 | context->engine->prepareSave(); |
| 1011 | context->patch->saveAutosave(); |
| 1012 | context->patch->cleanAutosave(); |
| 1013 | // context->history->setSaved(); |
| 1014 | |
| 1015 | #if CARDINAL_VARIANT_MINI && ! DISTRHO_PLUGIN_WANT_DIRECT_ACCESS |
| 1016 | FILE* const f = std::fopen(rack::system::join(context->patch->autosavePath, "patch.json").c_str(), "r"); |
| 1017 | DISTRHO_SAFE_ASSERT_RETURN(f != nullptr, String()); |
| 1018 | |
| 1019 | DEFER({ |
| 1020 | std::fclose(f); |
| 1021 | }); |
| 1022 | |
| 1023 | std::fseek(f, 0, SEEK_END); |
| 1024 | const long fileSize = std::ftell(f); |
| 1025 | DISTRHO_SAFE_ASSERT_RETURN(fileSize > 0, String()); |
| 1026 | |
| 1027 | std::fseek(f, 0, SEEK_SET); |
| 1028 | char* const fileContent = static_cast<char*>(std::malloc(fileSize+1)); |
| 1029 | |
| 1030 | DISTRHO_SAFE_ASSERT_RETURN(std::fread(fileContent, fileSize, 1, f) == 1, String()); |
| 1031 | fileContent[fileSize] = '\0'; |
| 1032 | |
| 1033 | return String(fileContent, false); |
| 1034 | #else |
| 1035 | try { |
| 1036 | data = rack::system::archiveDirectory(fAutosavePath, 1); |
| 1037 | } DISTRHO_SAFE_EXCEPTION_RETURN("getState archiveDirectory", String()); |
| 1038 | #endif |
| 1039 | } |
| 1040 | |
| 1041 | return String::asBase64(data.data(), data.size()); |
| 1042 | } |
| 1043 | |
| 1044 | void setState(const char* const key, const char* const value) override |
| 1045 | { |
nothing calls this directly
no test coverage detected