2323
2424namespace OCA \Theming ;
2525
26+ use OCP \App \AppPathNotFoundException ;
27+ use OCP \App \IAppManager ;
2628use OCP \IConfig ;
2729use OCP \Files \IRootFolder ;
2830
@@ -34,15 +36,20 @@ class Util {
3436 /** @var IRootFolder */
3537 private $ rootFolder ;
3638
39+ /** @var IAppManager */
40+ private $ appManager ;
41+
3742 /**
3843 * Util constructor.
3944 *
4045 * @param IConfig $config
4146 * @param IRootFolder $rootFolder
47+ * @param IAppManager $appManager
4248 */
43- public function __construct (IConfig $ config , IRootFolder $ rootFolder ) {
49+ public function __construct (IConfig $ config , IRootFolder $ rootFolder, IAppManager $ appManager ) {
4450 $ this ->config = $ config ;
4551 $ this ->rootFolder = $ rootFolder ;
52+ $ this ->appManager = $ appManager ;
4653 }
4754
4855 /**
@@ -108,8 +115,8 @@ public function generateRadioButton($color) {
108115 */
109116 public function getAppIcon ($ app ) {
110117 $ app = str_replace (array ('\0 ' , '/ ' , '\\' , '.. ' ), '' , $ app );
111- $ appPath = \OC_App:: getAppPath ( $ app );
112- if ( $ appPath !== false ) {
118+ try {
119+ $ appPath = $ this -> appManager -> getAppPath ( $ app );
113120 $ icon = $ appPath . '/img/ ' . $ app . '.svg ' ;
114121 if (file_exists ($ icon )) {
115122 return $ icon ;
@@ -118,7 +125,8 @@ public function getAppIcon($app) {
118125 if (file_exists ($ icon )) {
119126 return $ icon ;
120127 }
121- }
128+ } catch (AppPathNotFoundException $ e ) {}
129+
122130 if ($ this ->config ->getAppValue ('theming ' , 'logoMime ' , '' ) !== '' && $ this ->rootFolder ->nodeExists ('/themedinstancelogo ' )) {
123131 return $ this ->config ->getSystemValue ('datadirectory ' , \OC ::$ SERVERROOT . '/data/ ' ) . '/themedinstancelogo ' ;
124132 }
@@ -128,40 +136,45 @@ public function getAppIcon($app) {
128136 /**
129137 * @param $app string app name
130138 * @param $image string relative path to image in app folder
131- * @return string absolute path to image
139+ * @return string|false absolute path to image
132140 */
133141 public function getAppImage ($ app , $ image ) {
134142 $ app = str_replace (array ('\0 ' , '/ ' , '\\' , '.. ' ), '' , $ app );
135143 $ image = str_replace (array ('\0 ' , '\\' , '.. ' ), '' , $ image );
136- $ appPath = \OC_App::getAppPath ($ app );
137- if ($ app === "core " ) {
138- $ icon = \OC ::$ SERVERROOT . '/core/img/ ' . $ image ;
139- if (file_exists ($ icon )) {
140- return $ icon ;
141- }
142- }
143- if ($ appPath !== false ) {
144- $ icon = $ appPath . '/img/ ' . $ image ;
145- if (file_exists ($ icon )) {
146- return $ icon ;
147- }
148- $ icon = $ appPath . '/img/ ' . $ image . '.svg ' ;
149- if (file_exists ($ icon )) {
150- return $ icon ;
151- }
152- $ icon = $ appPath . '/img/ ' . $ image . '.png ' ;
153- if (file_exists ($ icon )) {
154- return $ icon ;
155- }
156- $ icon = $ appPath . '/img/ ' . $ image . '.gif ' ;
157- if (file_exists ($ icon )) {
158- return $ icon ;
159- }
160- $ icon = $ appPath . '/img/ ' . $ image . '.jpg ' ;
144+ if ($ app === "core " ) {
145+ $ icon = \OC ::$ SERVERROOT . '/core/img/ ' . $ image ;
161146 if (file_exists ($ icon )) {
162147 return $ icon ;
163148 }
164149 }
150+
151+ try {
152+ $ appPath = $ this ->appManager ->getAppPath ($ app );
153+ } catch (AppPathNotFoundException $ e ) {
154+ return false ;
155+ }
156+
157+ $ icon = $ appPath . '/img/ ' . $ image ;
158+ if (file_exists ($ icon )) {
159+ return $ icon ;
160+ }
161+ $ icon = $ appPath . '/img/ ' . $ image . '.svg ' ;
162+ if (file_exists ($ icon )) {
163+ return $ icon ;
164+ }
165+ $ icon = $ appPath . '/img/ ' . $ image . '.png ' ;
166+ if (file_exists ($ icon )) {
167+ return $ icon ;
168+ }
169+ $ icon = $ appPath . '/img/ ' . $ image . '.gif ' ;
170+ if (file_exists ($ icon )) {
171+ return $ icon ;
172+ }
173+ $ icon = $ appPath . '/img/ ' . $ image . '.jpg ' ;
174+ if (file_exists ($ icon )) {
175+ return $ icon ;
176+ }
177+
165178 return false ;
166179 }
167180
0 commit comments