Reads an image cache including images, cursors and colours. @param type if empty means read from an external binary file. otherwise the data is taken from a block of memory. @param bOkIfNotFound if true means do not report absent file. @return true iff we loaded the images.
| 840 | /// @param bOkIfNotFound if true means do not report absent file. |
| 841 | /// @return true iff we loaded the images. |
| 842 | bool ThemeBase::ReadImageCache( teThemeType type, bool bOkIfNotFound) |
| 843 | { |
| 844 | auto &resources = *mpSet; |
| 845 | EnsureInitialised(); |
| 846 | wxImage ImageCache; |
| 847 | |
| 848 | // Ensure we have an alpha channel... |
| 849 | // if( !ImageCache.HasAlpha() ) |
| 850 | // { |
| 851 | // ImageCache.InitAlpha(); |
| 852 | // } |
| 853 | |
| 854 | using namespace BasicUI; |
| 855 | |
| 856 | if( type.empty() || type == "custom" ) |
| 857 | { |
| 858 | mPreferredSystemAppearance = PreferredSystemAppearance::Light; |
| 859 | |
| 860 | // Take the image cache file for the theme chosen in preferences |
| 861 | auto dir = ThemeSubdir(GetFilePath(), GUITheme().Read()); |
| 862 | const auto &FileName = |
| 863 | wxFileName{ dir, ImageCacheFileName }.GetFullPath(); |
| 864 | if( !wxFileExists( FileName )) |
| 865 | { |
| 866 | if( bOkIfNotFound ) |
| 867 | return false; // did not load the images, so return false. |
| 868 | ShowMessageBox( |
| 869 | XO("Audacity could not find file:\n %s.\nTheme not loaded.") |
| 870 | .Format( FileName )); |
| 871 | return false; |
| 872 | } |
| 873 | if( !ImageCache.LoadFile( FileName, wxBITMAP_TYPE_PNG )) |
| 874 | { |
| 875 | ShowMessageBox( |
| 876 | /* i18n-hint: Do not translate png. It is the name of a file format.*/ |
| 877 | XO("Audacity could not load file:\n %s.\nBad png format perhaps?") |
| 878 | .Format( FileName )); |
| 879 | return false; |
| 880 | } |
| 881 | } |
| 882 | // ELSE we are reading from internal storage. |
| 883 | else |
| 884 | { |
| 885 | size_t ImageSize = 0; |
| 886 | const unsigned char * pImage = nullptr; |
| 887 | auto &lookup = GetThemeCacheLookup(); |
| 888 | auto iter = lookup.find({type, {}}); |
| 889 | if (const auto end = lookup.end(); iter == end) { |
| 890 | iter = lookup.find({"classic", {}}); |
| 891 | wxASSERT(iter != end); |
| 892 | } |
| 893 | |
| 894 | mPreferredSystemAppearance = iter->second.preferredSystemAppearance; |
| 895 | |
| 896 | ImageSize = iter->second.data.size(); |
| 897 | if (ImageSize == 0) |
| 898 | // This must be the image compiler |
| 899 | return true; |
nothing calls this directly
no test coverage detected