#!/usr/bin/python3.12

# 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 = "2.9.3"

if os.name == "nt":
    PKGDATADIR = os.path.join(os.path.dirname(__file__), "..", "share", "cartridges")
else:
    PKGDATADIR = "/usr/share/cartridges"
    LOCALEDIR = "/usr/share/locale"

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)
else:
    gettext.install("cartridges")

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))
