Skip to content

Commit

Permalink
Fix do not allow to install theme with the same content of the defaul…
Browse files Browse the repository at this point in the history
…t aseprite-theme (fix #4226)
  • Loading branch information
Gasparoken committed Apr 16, 2024
1 parent 5d49a03 commit af5b30a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions data/strings/en.ini
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ job_working = {0}<<Working...||&Cancel
nothing_to_report = Crash Report<<Nothing to report||&OK
install_extension = Warning\n<<Do you really want to install the given extension?\n<<"{0}"\n||&Install||&Cancel
uninstall_extension_warning = Warning\n<<Do you really want to uninstall "{0}" extension?\n||&Yes||&No
cannot_install_default_extension = Error\n<<This theme cannot be installed because its name matches the default aseprite theme\n||&OK
unknown_output_file_format_error = Aseprite\n<<Unknown file format "{0}" in output filename\n||&OK
update_screen_ui_scaling_with_theme_values = Update Screen/UI Scaling\n<<The new theme "{0}" wants to adjust some values for you:\n<< Screen Scaling: {1}% -> {2}%\n<< UI Scaling: {3}% -> {4}%\n<<Allow these changes?\n||&Adjust Scaling||&Don't Adjust Scaling
update_extension = Update Extension\n<<The extension "{0}" already exists.\n<<Do you want to {1} from v{2} to v{3}?\n||&Yes||&No
Expand Down
16 changes: 14 additions & 2 deletions src/app/commands/cmd_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,18 @@ class OptionsWindow : public app::gen::Options {
}
}

// Get the extension information from the compressed
// package.json file.
ExtensionInfo info =
App::instance()->extensions().getCompressedExtensionInfo(filename);
// Check if the filename corresponds to aseprite-default theme
if (base::string_to_lower(info.name) ==
kAsepriteDefaultThemeExtensionName) {
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)
Expand Down Expand Up @@ -1760,7 +1772,7 @@ class OptionsWindow : public app::gen::Options {
return paths;
}

static base::paths createUserDirPaths(const base::paths dirNames) {
static base::paths getUserDirPaths(const base::paths dirNames) {
ResourceFinder rf;
for (auto& fn : dirNames)
rf.includeUserDir(fn.c_str());
Expand Down Expand Up @@ -1791,7 +1803,7 @@ class OptionsWindow : public app::gen::Options {
if (!e->isDefaultTheme())
return false;
auto userThemePaths =
createUserDirPaths({"extensions", skin::SkinTheme::kThemesFolderName});
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)
Expand Down
3 changes: 1 addition & 2 deletions src/app/extensions.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2020-2023 Igara Studio S.A.
// Copyright (C) 2020-2024 Igara Studio S.A.
// Copyright (C) 2017-2018 David Capello
//
// This program is distributed under the terms of
Expand Down Expand Up @@ -56,7 +56,6 @@ namespace {
const char* kPackageJson = "package.json";
const char* kInfoJson = "__info.json";
const char* kPrefLua = "__pref.lua";
const char* kAsepriteDefaultThemeExtensionName = "aseprite-theme";

class ReadArchive {
public:
Expand Down
4 changes: 4 additions & 0 deletions src/app/extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ namespace ui {
class Widget;
}

namespace {
const char* kAsepriteDefaultThemeExtensionName = "aseprite-theme";
}

namespace app {

// Key=id
Expand Down

0 comments on commit af5b30a

Please sign in to comment.