-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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?
Changes from all commits
ab75d06
d59be8e
6bc037f
6d47605
1b1e879
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -940,6 +940,18 @@ class OptionsWindow : public app::gen::Options { | |
} | ||
} | ||
|
||
// Get the extension information from the compressed | ||
// package.json file. | ||
const ExtensionInfo info = | ||
App::instance()->extensions().getCompressedExtensionInfo(filename); | ||
// Check if the filename corresponds to aseprite-default theme | ||
if (base::string_to_lower(info.name) == | ||
Extensions::kAsepriteDefaultThemeName) { | ||
ui::Alert::show( | ||
fmt::format(Strings::alerts_cannot_install_default_extension())); | ||
return false; | ||
} | ||
|
||
// Install? | ||
if (ui::Alert::show( | ||
fmt::format(Strings::alerts_install_extension(), filename)) != 1) | ||
|
@@ -1393,7 +1405,8 @@ class OptionsWindow : public app::gen::Options { | |
if (!ext->isEnabled()) | ||
continue; | ||
|
||
if (ext->themes().empty()) | ||
if (ext->themes().empty() || | ||
isExtensionADuplicatedDefaultTheme(ext)) | ||
continue; | ||
|
||
if (first) { | ||
|
@@ -1425,6 +1438,9 @@ class OptionsWindow : public app::gen::Options { | |
extensionsList()->addChild(sep); | ||
for (auto e : App::instance()->extensions()) { | ||
if (e->category() == category) { | ||
if (category == Extension::Category::Themes && | ||
isExtensionADuplicatedDefaultTheme(e)) | ||
continue; | ||
ExtensionItem* item = new ExtensionItem(e); | ||
extensionsList()->addChild(item); | ||
hasItems = true; | ||
|
@@ -1587,6 +1603,11 @@ class OptionsWindow : public app::gen::Options { | |
// package.json file. | ||
ExtensionInfo info = exts.getCompressedExtensionInfo(filename); | ||
|
||
if (info.themeId == "default") { | ||
ui::Alert::show( | ||
fmt::format(Strings::alerts_cannot_open_theme())); | ||
return; | ||
} | ||
// Check if the extension already exist | ||
for (auto ext : exts) { | ||
if (base::string_to_lower(ext->name()) != | ||
|
@@ -1767,6 +1788,17 @@ class OptionsWindow : public app::gen::Options { | |
return paths; | ||
} | ||
|
||
static base::paths getUserDirPaths(const base::paths& dirNames) { | ||
ResourceFinder rf; | ||
for (auto& fn : dirNames) | ||
rf.includeUserDir(fn.c_str()); | ||
|
||
base::paths paths; | ||
while (rf.next()) | ||
paths.push_back(base::normalize_path(rf.filename())); | ||
return paths; | ||
} | ||
|
||
void updateCategoryVisibility() { | ||
bool visibleCategories[int(Extension::Category::Max)]; | ||
for (auto& v : visibleCategories) | ||
|
@@ -1782,6 +1814,20 @@ class OptionsWindow : public app::gen::Options { | |
} | ||
} | ||
|
||
// Function to determine if the input extension is the default theme | ||
static bool isExtensionADuplicatedDefaultTheme(const Extension* e) { | ||
if (!e->isDefaultTheme()) | ||
return false; | ||
auto userThemePaths = | ||
getUserDirPaths({"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 commentThe 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 commentThe 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 commentThe 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. |
||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
#ifdef _WIN32 | ||
void onTabletAPIChange() { | ||
if (tabletApiWindowsPointer()->isSelected()) { | ||
|
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 callingrf.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.