MCPcopy Create free account
hub / github.com/XorTroll/uLaunch / TryCacheLoadThemeIcon

Function TryCacheLoadThemeIcon

libs/uCommon/source/ul/cfg/cfg_Config.cpp:68–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66 }
67
68 Result TryCacheLoadThemeIcon(const Theme &theme, std::string &out_icon_path) {
69 const auto theme_path = fs::JoinPath(ThemesPath, theme.name);
70 auto theme_zip = zip_open(theme_path.c_str(), 0, 'r');
71 if(!theme_zip) {
72 return ResultInvalidThemeZipFile;
73 }
74 UL_ON_SCOPE_EXIT(
75 zip_close(theme_zip);
76 );
77
78 std::string icon_fmt;
79 for(const auto &fmt: ImageFormatList) {
80 const auto icon_path = fs::JoinPath("theme", "Icon." + std::string(fmt));
81 if(zip_entry_open(theme_zip, icon_path.c_str()) == 0) {
82 icon_fmt = fmt;
83 break;
84 }
85 }
86 if(icon_fmt.empty()) {
87 return ResultThemeIconNotFound;
88 }
89 UL_ON_SCOPE_EXIT(
90 zip_entry_close(theme_zip);
91 );
92
93 void *icon_ptr;
94 size_t icon_ptr_size;
95 if(zip_entry_read(theme_zip, &icon_ptr, &icon_ptr_size) <= 0) {
96 return ResultInvalidThemeZipFileRead;
97 }
98 UL_ON_SCOPE_EXIT(
99 free(icon_ptr);
100 );
101
102 u8 hash[SHA256_HASH_SIZE] = {};
103 sha256CalculateHash(hash, icon_ptr, icon_ptr_size);
104 const auto icon_cache_path = fs::JoinPath(ThemePreviewCachePath, util::FormatSha256Hash(hash, true) + "." + icon_fmt);
105
106 fs::CreateDirectory(ThemePreviewCachePath);
107 if(!fs::WriteFile(icon_cache_path, icon_ptr, icon_ptr_size, true)) {
108 return ResultThemeIconCacheFail;
109 }
110
111 out_icon_path = icon_cache_path;
112 return ResultSuccess;
113 }
114
115 std::vector<Theme> FindThemes() {
116 std::vector<Theme> themes;

Callers 1

ReloadMethod · 0.85

Calls 4

JoinPathFunction · 0.85
FormatSha256HashFunction · 0.85
CreateDirectoryFunction · 0.85
WriteFileFunction · 0.85

Tested by

no test coverage detected