#!/bin/bash -efu
### This file is covered by the GNU General Public License,
### which should be included as the file LICENSE.

. alterator-entry-sh-functions

OLD_CATEGORIES_DIR="/usr/share/alterator/desktop-directories"
NEW_CATEGORIES_DIR="/usr/share/alterator/categories"

if [ -d "$OLD_CATEGORIES_DIR" ]; then
	while IFS= read -r -d '' file; do
		ini_config_get "$file" "Desktop Entry" "X-Alterator-Category"
	done < <(find "$OLD_CATEGORIES_DIR" -type f -print0)
fi

if [ -d "$NEW_CATEGORIES_DIR" ]; then
	while IFS= read -r -d '' file; do
		validate_alterator_entry "$file" ||
			continue

		file_type=$(get_alterator_entry_type "$file")
		[ "$file_type" = "Category" ] ||
			continue

		get_alterator_entry_name "$file"
	done < <(find "$NEW_CATEGORIES_DIR" -type f -print0)
fi
