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

Fix Ignore any third-party theme that uses "default" as ID (fix #4226) #4335

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Gasparoken
Copy link
Member

Pending alert artist when a theme with default ID is omitted.

fix #4226

@aseprite-bot
Copy link
Collaborator

clang-tidy review says "All clean, LGTM! 👍"

@Gasparoken
Copy link
Member Author

Hello @martincapello. This solution hides any "aseprite-theme" themes from the Extensions and Theme lists.

@@ -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))
Copy link
Member

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.

@@ -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) {
Copy link
Member

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

Copy link
Member

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());

Copy link
Member

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)
Copy link
Member

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)

Copy link
Member Author

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)

Copy link
Member

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).
@aseprite-bot
Copy link
Collaborator

clang-tidy review says "All clean, LGTM! 👍"

@Gasparoken Gasparoken assigned dacap and unassigned Gasparoken Apr 12, 2024
@@ -1756,6 +1760,17 @@ class OptionsWindow : public app::gen::Options {
return paths;
}

static base::paths createUserDirPaths(const base::paths dirNames) {
Copy link
Member

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

Suggested change
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.

@dacap
Copy link
Member

dacap commented Apr 15, 2024

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:

bug2

After reopening the Preferences dialog the installed extensions is correctly not displayed anymore. But the extension keeps installed in the user directory (c:/Users/David/AppData/Roaming/Aseprite/extensions/aseprite-theme).

I think we should show an error message and not install/uncompress the extension in the user directory.

@dacap dacap assigned Gasparoken and unassigned dacap Apr 15, 2024
Copy link
Collaborator

@aseprite-bot aseprite-bot left a 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

base::string_to_lower(info.name))
return true;
return false;
}
Copy link
Collaborator

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]

Suggested change
}
static bool filenameMatchesDefaultTheme(const std::string& filename) {

catch (const std::exception& ex) {
Console::showException(ex);
}
}
Copy link
Collaborator

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]

Suggested change
}
ExtensionInfo const info =

Copy link
Collaborator

@aseprite-bot aseprite-bot left a 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

@@ -940,6 +940,18 @@ class OptionsWindow : public app::gen::Options {
}
}

// Get the extension information from the compressed
// package.json file.
ExtensionInfo info =
Copy link
Collaborator

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]

Suggested change
ExtensionInfo info =
ExtensionInfo const info =

@aseprite-bot
Copy link
Collaborator

clang-tidy review says "All clean, LGTM! 👍"

@Gasparoken Gasparoken assigned dacap and unassigned Gasparoken Apr 16, 2024
@Gasparoken
Copy link
Member Author

Ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ignore any third-party theme that uses "default" as ID
4 participants