Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve mime type deployment #135

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve MimeInfoEditor members naming
  • Loading branch information
azubieta committed Jul 3, 2019
commit 7ef3c6198c484f2435ff0576e73a9fdc4df7a11e
6 changes: 4 additions & 2 deletions src/libappimage/desktop_integration/integrator/Integrator.cpp
Original file line number Diff line number Diff line change
@@ -84,6 +84,7 @@ namespace appimage {
*/
void extractMimeInfoFiles() {
std::vector<std::string> mimeInfoPaths = resourcesExtractor.getMimeTypePackagesPaths();

for (const std::string& path: mimeInfoPaths) {
azubieta marked this conversation as resolved.
Show resolved Hide resolved
std::string mimeInfoFileData = resourcesExtractor.extractText(path);
mimeInfoFiles.insert(std::make_pair(path, MimeInfoEditor(mimeInfoFileData)));
@@ -316,18 +317,19 @@ namespace appimage {
if (relativeParentPath == defaultXdgDataDirPath)
relativeParentPath.clear();
}

return relativeParentPath;
azubieta marked this conversation as resolved.
Show resolved Hide resolved
}

void deployMimeTypePackages() {
for (auto& itr: mimeInfoFiles) {
MimeInfoEditor& editor = itr.second;
editor.setDeployId(VENDOR_PREFIX + '_' + appImageId);
editor.prependDeployIdToIcons(VENDOR_PREFIX + '_' + appImageId);
bf::path deployPath = generateDeployPath(itr.first);

create_directories(deployPath.parent_path());
std::ofstream out(deployPath.string());
out << editor.edit();
out << editor.getResult();
out.close();
}
}
25 changes: 15 additions & 10 deletions src/libappimage/desktop_integration/integrator/MimeInfoEditor.cpp
Original file line number Diff line number Diff line change
@@ -23,7 +23,21 @@ namespace appimage {
}
}

std::string MimeInfoEditor::edit() {
std::string MimeInfoEditor::getResult() {
try {
using boost::property_tree::ptree;
std::stringstream out;

write_xml(out, pt);

return out.str();
} catch (const std::runtime_error& error) {
appimage::utils::Logger::warning(std::string("Unable to edit MimeInfo: ") + error.what());
return std::string{};
}
}

void MimeInfoEditor::prependDeployIdToIcons(const std::string& deployId) {
try {
using boost::property_tree::ptree;

@@ -45,20 +59,11 @@ namespace appimage {
subTree.put("icon.<xmlattr>.name", newIconName);
}
}

std::stringstream out;
write_xml(out, pt);
return out.str();
} catch (const std::runtime_error& error) {
appimage::utils::Logger::warning(std::string("Unable to edit MimeInfo: ") + error.what());
return std::string{};
}
}

void MimeInfoEditor::setDeployId(const std::string& deployId) {
MimeInfoEditor::deployId = deployId;
}

std::list<std::string> MimeInfoEditor::getMimeTypeIconNames() const {
std::list<std::string> icons;

10 changes: 5 additions & 5 deletions src/libappimage/desktop_integration/integrator/MimeInfoEditor.h
Original file line number Diff line number Diff line change
@@ -23,16 +23,17 @@ namespace appimage {
MimeInfoEditor(std::string data);

/**
* Set the deploy id to be prepended to the icon file name
* @brief Prepends <deployId> to the icon file name
*
*
* @param deployId
*/
void setDeployId(const std::string& deployId);
void prependDeployIdToIcons(const std::string& deployId);

/**
* Apply modification to the MimeInfo file
* @return modified MimeInfo
*/
std::string edit();
std::string getResult();

/**
* Extract the icon names from from the icon entry or the mime type name
@@ -42,7 +43,6 @@ namespace appimage {

private:
boost::property_tree::ptree pt;
std::string deployId;
};
}
}
Original file line number Diff line number Diff line change
@@ -58,8 +58,8 @@ class MimeInfoEditorTests : public ::testing::Test {

TEST_F(MimeInfoEditorTests, setIcon) {
MimeInfoEditor editor(mimeInfo.str());
editor.setDeployId("appimaged_d41d8cd98f00b204e9800998ecf8427e");
std::string result = editor.edit();
editor.prependDeployIdToIcons("appimaged_d41d8cd98f00b204e9800998ecf8427e");
std::string result = editor.getResult();


using boost::property_tree::ptree;
@@ -77,8 +77,8 @@ TEST_F(MimeInfoEditorTests, setIcon) {

TEST_F(MimeInfoEditorTests, updateIcon) {
MimeInfoEditor editor(mimeInfoWithIconEntry.str());
editor.setDeployId("appimaged_d41d8cd98f00b204e9800998ecf8427e");
std::string result = editor.edit();
editor.prependDeployIdToIcons("appimaged_d41d8cd98f00b204e9800998ecf8427e");
std::string result = editor.getResult();


using boost::property_tree::ptree;