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
Fix Ignore any third-party theme that uses "default" as ID (fix #4226) #4335
base: main
Are you sure you want to change the base?
Conversation
96b8ed0
to
7111683
Compare
clang-tidy review says "All clean, LGTM! 👍" |
Hello @martincapello. This solution hides any "aseprite-theme" themes from the |
src/app/commands/cmd_options.cpp
Outdated
@@ -1409,6 +1410,8 @@ class OptionsWindow : public app::gen::Options { | |||
extensionsList()->addChild(sep); | |||
for (auto e : App::instance()->extensions()) { | |||
if (e->category() == category) { | |||
if (isExtensionADuplicatedDefaultTheme(e)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we check that this if
is executed only for the Extension::Category::Themes
category?
I know that it a case that it is not likely to happen...but mentioning just in case.
src/app/commands/cmd_options.cpp
Outdated
@@ -1741,9 +1744,10 @@ class OptionsWindow : public app::gen::Options { | |||
return base::normalize_path(rf.defaultFilename()); | |||
} | |||
|
|||
static base::paths themeFolders() { | |||
static base::paths themeFolders(const std::vector<std::string> filenames) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would rename thefilenames
parameter by dirnames
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is base::paths
for this kind of type (list of paths).
ResourceFinder rf; | ||
rf.includeDataDir(skin::SkinTheme::kThemesFolderName); | ||
for (auto& fn : filenames) | ||
rf.includeUserDir(fn.c_str()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If feels like some logic was lost here. Because before this change rf.includeDataDir
was called, now we are calling rf.includeUserDir
, and as far as I see they include different paths. Although I couldn't find a case where this behaves incorrectly when testing...so not sure about this.
themeFolders({"extensions", skin::SkinTheme::kThemesFolderName}); | ||
for (auto& p : userThemePaths) { | ||
// Has the user path (p) the same path of the extension (e->path())? | ||
if (std::strncmp(e->path().c_str(), p.c_str(), p.size()) == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since e->path() and p are std::strings, this could be replaced by:
if (e->path() == p)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately that expression does not work, nor does the following one:
if (e->path().compare(p) == 0)
I'll return with
if (std::strncmp(e->path().c_str(), p.c_str(), p.size()) == 0)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, you are right, I didn't see that you where comparing up to p.size() characters and not the full strings.
In this case, the right one would be:
if ( e->path().compare(0, p.size(), p) == 0)
But I don't think it makes any difference...so I'm fine if you leave the std::strncmp() call as is.
…ite#4226) This fix hides user themes whose name is the same as the default, that is, "aseprite-theme" and are present in the user folders (i.e. 'extensions' and 'data/themes' folders).
7111683
to
5d49a03
Compare
clang-tidy review says "All clean, LGTM! 👍" |
src/app/commands/cmd_options.cpp
Outdated
@@ -1756,6 +1760,17 @@ class OptionsWindow : public app::gen::Options { | |||
return paths; | |||
} | |||
|
|||
static base::paths createUserDirPaths(const base::paths dirNames) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd change the name of this function to something like
static base::paths createUserDirPaths(const base::paths dirNames) { | |
static base::paths getUserDirPaths(const base::paths dirNames) { |
because when I saw it for first time I thought it was creating (mkdir) the directories.
I've just tested with a simple dacap-theme.aseprite-extension (with the same content of the default aseprite-theme) and it allows me to add the extension: After reopening the Preferences dialog the installed extensions is correctly not displayed anymore. But the extension keeps installed in the user directory ( I think we should show an error message and not install/uncompress the extension in the user directory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
src/app/commands/cmd_options.cpp
Outdated
base::string_to_lower(info.name)) | ||
return true; | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: method 'filenameMatchesDefaultTheme' can be made static [readability-convert-member-functions-to-static]
} | |
static bool filenameMatchesDefaultTheme(const std::string& filename) { |
src/app/commands/cmd_options.cpp
Outdated
catch (const std::exception& ex) { | ||
Console::showException(ex); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'info' of type 'ExtensionInfo' can be declared 'const' [misc-const-correctness]
} | |
ExtensionInfo const info = |
2adfd0b
to
af5b30a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
src/app/commands/cmd_options.cpp
Outdated
@@ -940,6 +940,18 @@ class OptionsWindow : public app::gen::Options { | |||
} | |||
} | |||
|
|||
// Get the extension information from the compressed | |||
// package.json file. | |||
ExtensionInfo info = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'info' of type 'ExtensionInfo' can be declared 'const' [misc-const-correctness]
ExtensionInfo info = | |
ExtensionInfo const info = |
…t aseprite-theme (fix aseprite#4226)
af5b30a
to
99de589
Compare
clang-tidy review says "All clean, LGTM! 👍" |
Ready for review. |
Pending alert artist when a theme with default ID is omitted.
fix #4226