d2phap/ImageGlass · warning · ArgumentException

Cannot remove the default theme pack.

Error message

Cannot remove the default theme pack.

What it means

Thrown in igcmd Functions.UninstallThemePack when the supplied themeDirPath equals the default theme directory (App.ConfigDir(PathType.Dir, Dir.Themes, Const.DEFAULT_THEME), i.e. the built-in 'Kobe' theme), compared OrdinalIgnoreCase. It is an ArgumentException whose paramName is themeDirPath, used as an intentional guard so the shipped default theme cannot be deleted. The throw occurs inside Functions.Run, which catches it, sets IgExitCode.Error, and shows the message via Config.ShowError. Directory.Delete is never reached for the default path.

Source

Thrown at v9/igcmd/Functions.cs:220

        {
            _ = Config.ShowError(null,
                description: error.Message,
                title: Config.Language["FrmSettings._Theme._InstallTheme"]);
        });
    }


    /// <summary>
    /// Uninstall a theme pack.
    /// </summary>
    public static IgExitCode UninstallThemePack(string themeDirPath)
    {
        return Run(() =>
        {
            var defaultThemeDir = App.ConfigDir(PathType.Dir, Dir.Themes, Const.DEFAULT_THEME);
            if (themeDirPath.Equals(defaultThemeDir, StringComparison.OrdinalIgnoreCase))
            {
                throw new ArgumentException("Cannot remove the default theme pack.", themeDirPath);
            }

            Directory.Delete(themeDirPath, true);
        }, (error) =>
        {
            _ = Config.ShowError(null,
                description: error.Message,
                title: Config.Language["FrmSettings._Theme._UninstallTheme"]);
        });
    }



    /// <summary>
    /// Sets the Lock Screen background
    /// </summary>
    public static IgExitCode SetLockScreenBackground(string imgPath)
    {

View on GitHub (pinned to 4a3c4fecef)

Solutions

  1. Do not attempt to uninstall the default theme; remove only user-installed theme packs.
  2. At the caller, filter the default theme directory out of any candidate list before invoking UninstallThemePack.
  3. If a reset of the default theme is needed, restore it from the app installation instead of deleting the live folder.
  4. Show the default theme's uninstall action as disabled in the UI so the command is never issued.

Example fix

// before
var paths = CmdArgs.Where(cmd => Directory.Exists(cmd));
if (paths.Any())
{
    return (int)Functions.UninstallThemePack(paths.FirstOrDefault());
}

// after: exclude the default theme dir before delegating
var defaultThemeDir = App.ConfigDir(PathType.Dir, Dir.Themes, Const.DEFAULT_THEME);
var paths = CmdArgs
    .Where(cmd => Directory.Exists(cmd))
    .Where(cmd => !cmd.Equals(defaultThemeDir, StringComparison.OrdinalIgnoreCase));

if (!paths.Any())
{
    Console.Error.WriteLine("Nothing to uninstall (the default theme cannot be removed).");
    return (int)IgExitCode.Error;
}
return (int)Functions.UninstallThemePack(paths.First());
Defensive patterns

Strategy: validation

Validate before calling

// Exclude the default theme directory before calling UninstallThemePack
static bool IsDefaultTheme(string themeDirPath)
{
    var defaultThemeDir = App.ConfigDir(PathType.Dir, Dir.Themes, Const.DEFAULT_THEME);
    return themeDirPath.Equals(defaultThemeDir, StringComparison.OrdinalIgnoreCase);
}

Type guard

static bool IsRemovableTheme(string themeDirPath)
{
    if (string.IsNullOrEmpty(themeDirPath) || !Directory.Exists(themeDirPath)) return false;
    var defaultThemeDir = App.ConfigDir(PathType.Dir, Dir.Themes, Const.DEFAULT_THEME);
    return !themeDirPath.Equals(defaultThemeDir, StringComparison.OrdinalIgnoreCase);
}

Try / catch

// UninstallThemePack already wraps the action in Functions.Run and shows Config.ShowError.
// Guard at the caller so the command is never issued for the default theme:
try
{
    if (IsRemovableTheme(themeDirPath))
        Functions.UninstallThemePack(themeDirPath);
}
catch (ArgumentException ex) when (ex.Message.Contains("default theme pack"))
{
    logger.Info("Skipped default theme uninstall: {0}", themeDirPath);
}

Prevention

When it happens

Trigger: igcmd UNINSTALL_THEME is invoked and the first command-line argument that is an existing directory resolves to the default theme folder (the Themes/Kobe directory); e.g. the settings UI or a script passes the default theme's path for removal.

Common situations: A user selects the built-in 'Kobe' theme in the UI and clicks uninstall; a cleanup script enumerates all theme folders and tries to delete every one including the default; or a path comparison elsewhere normalizes away the guard.

Related errors


AI-assisted analysis of d2phap/ImageGlass@4a3c4fecef (2026-08-13). Data as JSON: /api/errors/25202d4198390ea2. Report an issue: GitHub.