#!/usr/bin/python3

# bottles.in
#
# Copyright 2020 brombinmirko <send@mirko.pm>
#
# 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/>.

import os
import sys
import signal
import gettext

if "APPDIR" in os.environ:
	APPDIR = os.environ["APPDIR"]
	VERSION = "2022.1.14"
	pkgdatadir = "/usr/local/share/bottles"
	localedir = "/usr/local/share/locale"
	gresource_path = f"{APPDIR}/{pkgdatadir}/bottles.gresource"
	sys.path.insert(1, f"{APPDIR}/{pkgdatadir}")
elif "SNAP" in os.environ:
	SNAP = os.environ["SNAP"]
	VERSION = "2022.1.14"
	pkgdatadir = "usr/share/bottles"
	localedir = "usr/share/locale"
	gresource_path = f"{SNAP}/{pkgdatadir}/bottles.gresource"
	sys.path.insert(1, f"{SNAP}/{pkgdatadir}")
else:
	VERSION = "2022.1.14"
	pkgdatadir = "/usr/share/bottles"
	localedir = "/usr/share/locale"
	gresource_path = f"{pkgdatadir}/bottles.gresource"
	sys.path.insert(1, pkgdatadir)

signal.signal(signal.SIGINT, signal.SIG_DFL)
gettext.install('bottles', localedir)

if __name__ == '__main__':
    import gi

    from gi.repository import Gio
    resource = Gio.Resource.load(gresource_path)
    resource._register()

    from bottles import main
    sys.exit(main.main(VERSION))
