#!@PYTHON@

# cartridges.in
#
# Copyright 2022-2024 kramo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later

import gettext
import locale
import os
import signal
import sys
from pathlib import Path
from platform import system

VERSION = "@VERSION@"

if os.name == "nt":
    PKGDATADIR = os.path.join(os.path.dirname(__file__), "..", "share", "cartridges")
else:
    PKGDATADIR = "@pkgdatadir@"
    LOCALEDIR = "@localedir@"

sys.path.insert(1, PKGDATADIR)
signal.signal(signal.SIGINT, signal.SIG_DFL)

if system() == "Linux":
    locale.bindtextdomain("cartridges", LOCALEDIR)
    locale.textdomain("cartridges")
    gettext.install("cartridges", LOCALEDIR, names=['ngettext'])
else:
    gettext.install("cartridges", names=['ngettext'])

if __name__ == "__main__":
    from gi.repository import Gio, GLib

    try:
        # For a macOS application bundle
        resource = Gio.Resource.load(
            str(Path(__file__).parent / "Resources" / "cartridges.gresource")
        )
    except GLib.GError:
        resource = Gio.Resource.load(os.path.join(PKGDATADIR, "cartridges.gresource"))
    resource._register()  # pylint: disable=protected-access

    from cartridges import main

    sys.exit(main.main(VERSION))
