2 * Copyright 2017, Andrew Lindesay <apl@lindesay.co.nz>.
3 * All rights reserved. Distributed under the terms of the MIT License.
6 #include "LocalIconStore.h"
10 #include <Directory.h>
11 #include <FindDirectory.h>
14 #include "ServerIconExportUpdateProcess.h"
15 #include "StorageUtils.h"
18 LocalIconStore::LocalIconStore(const BPath
& path
)
20 fIconStoragePath
= path
;
24 LocalIconStore::~LocalIconStore()
30 LocalIconStore::_HasIconStoragePath() const
32 return fIconStoragePath
.InitCheck() == B_OK
;
36 /* This method will try to find an icon for the package name supplied. If an
37 * icon was able to be found then the method will return B_OK and will update
38 * the supplied path object with the path to the icon file.
42 LocalIconStore::TryFindIconPath(const BString
& pkgName
, BPath
& path
) const
45 BPath
iconPkgPath(fIconStoragePath
);
49 if ( (iconPkgPath
.Append("hicn") == B_OK
)
50 && (iconPkgPath
.Append(pkgName
) == B_OK
)
51 && (StorageUtils::ExistsObject(iconPkgPath
, &exists
, &isDir
, NULL
)
55 && (_IdentifyBestIconFileAtDirectory(iconPkgPath
, bestIconPath
)
63 return B_FILE_NOT_FOUND
;
68 LocalIconStore::_IdentifyBestIconFileAtDirectory(const BPath
& directory
,
69 BPath
& bestIconPath
) const
71 StringList iconLeafnames
;
73 iconLeafnames
.Add("icon.hvif");
74 iconLeafnames
.Add("64.png");
75 iconLeafnames
.Add("32.png");
76 iconLeafnames
.Add("16.png");
80 for (int32 i
= 0; i
< iconLeafnames
.CountItems(); i
++) {
81 BString iconLeafname
= iconLeafnames
.ItemAt(i
);
82 BPath
workingPath(directory
);
86 if ( (workingPath
.Append(iconLeafname
) == B_OK
87 && StorageUtils::ExistsObject(
88 workingPath
, &exists
, &isDir
, NULL
) == B_OK
)
91 bestIconPath
.SetTo(workingPath
.Path());
96 return B_FILE_NOT_FOUND
;