Skip to content

Commit a07a2eb

Browse files
committed
Deploy edited mimetype packages
1 parent f985c10 commit a07a2eb

File tree

11 files changed

+435
-53
lines changed

11 files changed

+435
-53
lines changed

src/libappimage/desktop_integration/integrator/Integrator.cpp

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -232,39 +232,11 @@ namespace appimage {
232232
// Generate deploy paths
233233
std::map<std::string, std::string> mimeTypeIconsTargetPaths;
234234
for (const auto& path: mimeTypeIconPaths)
235-
mimeTypeIconsTargetPaths[path] = generateMimeTypeIconDeployPath(path).string();
235+
mimeTypeIconsTargetPaths[path] = generateDeployPath(path).string();
236236

237237
resourcesExtractor.extractTo(mimeTypeIconsTargetPaths);
238238
}
239239

240-
/**
241-
* Append vendor prefix and appImage id to the file names to identify the appImage that owns
242-
* this file. Replace the default XDG_DATA_DIR by the one at <xdgDataHome>
243-
*
244-
* @param path resource path
245-
* @return path with a prefixed file name
246-
*/
247-
bf::path generateMimeTypeIconDeployPath(bf::path path) const {
248-
// add appImage resource identification prefix to the filename
249-
std::stringstream fileNameBuilder;
250-
fileNameBuilder << path.stem() << "-" << VENDOR_PREFIX << "-" << appImageId << path.extension();
251-
252-
// build the relative parent path ignoring the default XDG_DATA_DIR prefix ("usr/share")
253-
path.remove_filename();
254-
bf::path relativeParentPath;
255-
const bf::path defaultXdgDataDirPath = "usr/share";
256-
257-
for (const auto& itr : path) {
258-
relativeParentPath /= itr;
259-
260-
if (relativeParentPath == defaultXdgDataDirPath)
261-
relativeParentPath.clear();
262-
}
263-
264-
bf::path newPath = xdgDataHome / relativeParentPath / fileNameBuilder.str();
265-
return newPath;
266-
}
267-
268240
/**
269241
* Deploy <iconData> as the main application icon to
270242
* XDG_DATA_HOME/icons/hicolor/<size>/<iconGroup>/<vendorPrefix>_<appImageId>_<iconName>.<format extension>
@@ -311,18 +283,29 @@ namespace appimage {
311283
}
312284

313285
/**
314-
* Append vendor prefix and appImage id to the file names to identify the appImage that owns
286+
* Prepend vendor prefix and appImage id to the file names to identify the appImage that owns
315287
* this file. Replace the default XDG_DATA_DIR by the one at <xdgDataHome>
316288
*
317289
* @param path resource path
318-
* @return path with a prefixed file name
290+
* @return <xdg data home>/<relative path>/<vendor prefix>_<appImageId>_<file name>.<extension>
319291
*/
320292
bf::path generateDeployPath(bf::path path) const {
321293
// add appImage resource identification prefix to the filename
322294
std::stringstream fileNameBuilder;
323295
fileNameBuilder << VENDOR_PREFIX << "_" << appImageId << "_" << path.filename().string();
324296

325-
// build the relative parent path ignoring the default XDG_DATA_DIR prefix ("usr/share")
297+
boost::filesystem::path relativeParentPath = generateDeployParentPath(path);
298+
299+
bf::path newPath = xdgDataHome / relativeParentPath / fileNameBuilder.str();
300+
return newPath;
301+
}
302+
303+
/**
304+
* Build the relative parent path ignoring the default XDG_DATA_DIR prefix ("usr/share")
305+
* @param path
306+
* @return
307+
*/
308+
boost::filesystem::path generateDeployParentPath(boost::filesystem::path& path) const {
326309
path.remove_filename();
327310
bf::path relativeParentPath;
328311
const bf::path defaultXdgDataDirPath = "usr/share";
@@ -333,20 +316,20 @@ namespace appimage {
333316
if (relativeParentPath == defaultXdgDataDirPath)
334317
relativeParentPath.clear();
335318
}
336-
337-
bf::path newPath = xdgDataHome / relativeParentPath / fileNameBuilder.str();
338-
return newPath;
319+
return relativeParentPath;
339320
}
340321

341322
void deployMimeTypePackages() {
342-
auto mimeTypePackagesPaths = resourcesExtractor.getMimeTypePackagesPaths();
343-
std::map<std::string, std::string> mimeTypePackagesTargetPaths;
344-
345-
// Generate deploy paths
346-
for (const auto& path: mimeTypePackagesPaths)
347-
mimeTypePackagesTargetPaths[path] = generateDeployPath(path).string();
348-
349-
resourcesExtractor.extractTo(mimeTypePackagesTargetPaths);
323+
for (auto& itr: mimeInfoFiles) {
324+
MimeInfoEditor& editor = itr.second;
325+
editor.setDeployId(VENDOR_PREFIX + '_' + appImageId);
326+
boost::filesystem::path deployPath = generateDeployPath(itr.first);
327+
328+
create_directories(deployPath.parent_path());
329+
std::ofstream out(deployPath.string());
330+
out << editor.edit();
331+
out.close();
332+
}
350333
}
351334

352335
void setExecutionPermission() {

src/libappimage/desktop_integration/integrator/MimeInfoEditor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace appimage {
4040
boost::replace_all(originalName, "/", "-");
4141
}
4242

43-
std::string newIconName = originalName + "-" + deployId;
43+
std::string newIconName = deployId + '_' + originalName;
4444

4545
subTree.put("icon.<xmlattr>.name", newIconName);
4646
}

src/libappimage/utils/resources_extractor/ResourcesExtractor.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,23 @@ namespace appimage {
2929

3030
PayloadEntriesCache entriesCache;
3131

32+
bool isFile(const std::string& fileName) const {
33+
return appimage::core::PayloadEntryType::REGULAR == entriesCache.getEntryType(fileName) ||
34+
appimage::core::PayloadEntryType::LINK == entriesCache.getEntryType(fileName);
35+
}
3236

3337
bool isIconFile(const std::string& fileName) const {
34-
return (fileName.find("usr/share/icons") != std::string::npos);
38+
return (fileName.find("usr/share/icons") != std::string::npos) && isFile(fileName);
3539
}
3640

3741
bool isMainDesktopFile(const std::string& fileName) const {
3842
return fileName.find(".desktop") != std::string::npos &&
39-
fileName.find('/') == std::string::npos;
43+
fileName.find('/') == std::string::npos && isFile(fileName);
4044
}
4145

4246
bool isMimeFile(const std::string& fileName) const {
4347
return fileName.find("usr/share/mime/packages") != std::string::npos &&
44-
fileName.find(".xml") == std::string::npos;
48+
fileName.find(".xml") != std::string::npos && isFile(fileName);
4549
}
4650

4751
std::vector<char> readDataFile(std::istream& istream) const {

tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ if(BUILD_TESTING)
66
# global definitions
77
add_definitions(
88
-DTEST_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data/"
9+
-DNEW_TEST_DATA_DIR="${CMAKE_CURRENT_BINARY_DIR}/data/"
910
-DGIT_COMMIT="AppImageKit unit tests"
1011
)
1112

1213

14+
add_subdirectory(data)
1315
add_subdirectory(libappimage)
1416

1517
if(ENABLE_COVERAGE)

tests/data/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
message(STATUS "Generating test data AppImage")
2+
3+
# Generate Echo AppImage with custom mime type package
4+
set(APPIMAGE_NAME "echo.with.mimetype")
5+
set(TARGET_APPDIR ${CMAKE_CURRENT_BINARY_DIR}/${APPIMAGE_NAME}.AppDir)
6+
7+
if(NOT EXISTS ${TARGET_APPDIR})
8+
message(STATUS "Generating ${APPIMAGE_NAME} AppDir")
9+
10+
file(MAKE_DIRECTORY ${TARGET_APPDIR})
11+
configure_file(squashfs-root/echo.desktop.in ${TARGET_APPDIR}/echo.desktop @ONLY)
12+
file(COPY squashfs-root/.DirIcon DESTINATION ${TARGET_APPDIR})
13+
file(COPY squashfs-root/AppRun DESTINATION ${TARGET_APPDIR})
14+
file(COPY squashfs-root/utilities-terminal.svg DESTINATION ${TARGET_APPDIR})
15+
file(COPY squashfs-root/usr DESTINATION ${TARGET_APPDIR})
16+
17+
message(STATUS "Creating ${APPIMAGE_NAME} AppImage")
18+
execute_process(
19+
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/appimagetool-x86_64.AppImage ${TARGET_APPDIR}
20+
${CMAKE_CURRENT_BINARY_DIR}/${APPIMAGE_NAME}.AppImage)
21+
endif()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[Desktop Entry]
2+
Version=1.0
3+
Type=Application
4+
Name=@APPIMAGE_NAME@
5+
Name[de]=Echo DE
6+
Comment=Just echo.
7+
Exec=echo %F
8+
Icon=utilities-terminal
9+
X-AppImage-Version=1234

0 commit comments

Comments
 (0)