Ejemplo n.º 1
0
    def unpack(self, archive_path):

        scripts_dir_0 = data_dir + '/scripts/' + self.lib
        scripts_dir_1 = nebula_dir + '/scripts/' + self.lib

        if not os.path.exists(scripts_dir_0):
            os.makedirs(scripts_dir_0)

        if self.lib == 'mylib':
            new_scripts_dir = tmp + '/games_nebula_' + self.lib + '_scripts-master/free/'
        else:
            new_scripts_dir = tmp + '/games_nebula_' + self.lib + '_scripts-master/'

        subprocess.call(['7z', 'x', '-aoa', '-o' + tmp, archive_path])
        os.remove(new_scripts_dir + 'LICENSE')

        git_sctipts = os.listdir(new_scripts_dir)
        existing_scripts_0 = os.listdir(scripts_dir_0)
        existing_scripts_1 = os.listdir(scripts_dir_1)
        existing_scripts = existing_scripts_0 + existing_scripts_1

        new_scripts = []
        for script in git_sctipts:
            if script not in existing_scripts:
                new_scripts.append(script)
                os.rename(new_scripts_dir + script, scripts_dir_0)

        if self.overwrite == True:
            os.system('cp -r "' + new_scripts_dir + '"* "' + scripts_dir_0 +
                      '"')

        shutil.rmtree(new_scripts_dir)
        os.remove(archive_path)

        new_scripts = sorted(new_scripts)
        n_new_scripts = len(new_scripts)

        if self.lib == 'goglib':

            goglib_data = goglib_get_data.games_info(data_dir)

            goglib_names = goglib_data[1]
            goglib_titles = goglib_data[2]

            name_to_title = {}

            for i in range(len(goglib_names)):
                name_to_title[goglib_names[i]] = goglib_titles[i]

            new_own_scripts = []
            for game in new_scripts:
                if game in goglib_names:
                    new_own_scripts.append(game)

        elif self.lib == 'mylib':

            mylib_data = mylib_get_data.games_info(data_dir)

            mylib_names = mylib_data[1]
            mylib_titles = mylib_data[2]

            name_to_title = {}

            for i in range(len(mylib_names)):
                name_to_title[mylib_names[i]] = mylib_titles[i]

            for game_name in new_scripts:
                image_url = images_url + game_name + '.jpg'
                banners_dir = data_dir + '/images/mylib/'
                get_banner.get_banner(game_name, image_url, banners_dir,
                                      self.lib)

        message_dialog = Gtk.MessageDialog(
            None,
            0,
            Gtk.MessageType.INFO,
            Gtk.ButtonsType.OK,
            _("Completed successfully"),
        )
        message_dialog.set_property('window_position',
                                    Gtk.WindowPosition.CENTER_ALWAYS)
        message_dialog.set_property('default-width', 480)

        if n_new_scripts != 0:
            message_dialog.format_secondary_text(_("New scripts downloaded"))
        else:
            message_dialog.format_secondary_text(
                _("No new scripts in repository"))

        content_area = message_dialog.get_content_area()
        content_area.set_property('margin-left', 10)
        content_area.set_property('margin-right', 10)
        content_area.set_property('margin-top', 10)
        content_area.set_property('margin-bottom', 10)
        action_area = message_dialog.get_action_area()
        action_area.set_property('spacing', 10)

        expander_new_all = Gtk.Expander(label=_("All new scripts (" +
                                                str(n_new_scripts) + "):"))

        if n_new_scripts == 0:
            expander_new_all.set_property('no-show-all', True)

        scrolled_window1 = Gtk.ScrolledWindow(height_request=240)

        textbuffer1 = Gtk.TextBuffer()

        for i in range(len(new_scripts)):
            iter1 = textbuffer1.get_end_iter()
            textbuffer1.insert(iter1, name_to_title[new_scripts[i]] + '\n')

        textview1 = Gtk.TextView(buffer=textbuffer1,
                                 editable=False,
                                 cursor_visible=False)

        scrolled_window1.add(textview1)
        expander_new_all.add(scrolled_window1)

        content_area.pack_start(expander_new_all, True, True, 0)

        if self.lib == 'goglib':

            expander_new_own = Gtk.Expander(
                label=_("Scripts for games you own (" +
                        str(len(new_own_scripts)) + "):"))

            if len(new_own_scripts) == 0:
                expander_new_own.set_property('no-show-all', True)

            scrolled_window_new_own = Gtk.ScrolledWindow(height_request=240)

            textbuffer_new_own = Gtk.TextBuffer()

            for i in range(len(new_own_scripts)):
                iter_new_own = textbuffer_new_own.get_end_iter()
                textbuffer_new_own.insert(
                    iter_new_own, name_to_title[new_own_scripts[i]] + '\n')

            textview_new_own = Gtk.TextView(buffer=textbuffer_new_own,
                                            editable=False,
                                            cursor_visible=False)

            scrolled_window_new_own.add(textview_new_own)
            expander_new_own.add(scrolled_window_new_own)

            content_area.pack_start(expander_new_own, True, True, 0)

        message_dialog.show_all()
        response = message_dialog.run()
        message_dialog.destroy()

        if (n_new_scripts != 0) and (self.lib == 'mylib'):
            return True
        else:
            return False
Ejemplo n.º 2
0
def autosetup(lib, install_dir, game_name):

    parser = ConfigParser()

    if lib == 'goglib':
        banners_dir = os.getenv('HOME') + '/.games_nebula/images/goglib/'
        path_0 = os.getenv('HOME') + '/.games_nebula/scripts/goglib/autosetup.ini'
        path_1 = nebula_dir + '/scripts/goglib/autosetup.ini'
    elif lib == 'mylib':
        banners_dir = os.getenv('HOME') + '/.games_nebula/images/mylib/'
        path_0 = os.getenv('HOME') + '/.games_nebula/scripts/mylib/autosetup.ini'
        path_1 = nebula_dir + '/scripts/mylib/autosetup.ini'

    if os.path.exists(path_0):
        parser.read(path_0)
    else:
        parser.read(path_1)

    if parser.has_section(game_name):

        if parser.has_option(game_name, 'image'):
            image = parser.get(game_name, 'image')
            if image != '':
                print("Downloading image")
                get_banner.get_banner(game_name, image, banners_dir, lib)

        if parser.has_option(game_name, 'native_exe'):
            native_exe = parser.get(game_name, 'native_exe')
            if native_exe != '':
                print("Writing start.sh")

                start_file_path = install_dir + '/' + game_name + '/start.sh'
                start_gog_path = install_dir + '/' + game_name + '/start_gog.sh'

                if os.path.exists(start_file_path):
                    os.system('mv ' + start_file_path + ' ' + start_gog_path)

                start_lines = ['#!/bin/bash\n',
                'python "$NEBULA_DIR/launcher_native.py" ' + game_name]

                start_file = open(start_file_path, 'w')
                for line in start_lines:
                    start_file.write(line)
                start_file.close()
                os.system('chmod +x ' + start_file_path)

                if '/' in native_exe:
                    native_exe_dir = native_exe.split('/')[0]
                    native_exe = native_exe.split('/')[1]
                    start_gn_lines = ['#!/bin/bash\n',
                    'cd "$INSTALL_DIR/' + game_name + '/game/' + native_exe_dir + '"\n',
                    './' + native_exe]
                else:
                    start_gn_lines = ['#!/bin/bash\n',
                    'cd "$INSTALL_DIR/' + game_name + '/game"\n',
                    './' + native_exe]

                start_gn_file_path = install_dir + '/' + game_name + '/start_gn.sh'
                start_gn_file = open(start_gn_file_path, 'w')
                for line in start_gn_lines:
                    start_gn_file.write(line)
                start_gn_file.close()
                os.system('chmod +x ' + start_gn_file_path)

        if parser.has_option(game_name, 'native_settings_exe'):
            native_settings_exe = parser.get(game_name, 'native_settings_exe')
            if native_settings_exe != '':
                print("Writing settings.sh")

                if '/' in native_settings_exe:
                    native_settings_exe_dir = native_settings_exe.split('/')[0]
                    native_settings_exe = native_settings_exe.split('/')[1]
                    start_gn_lines = ['#!/bin/bash\n',
                    'cd "$INSTALL_DIR/' + game_name + '/game/' + native_settings_exe_dir + '"\n',
                    './' + native_settings_exe]
                else:
                    start_gn_lines = ['#!/bin/bash\n',
                    'cd "$INSTALL_DIR/' + game_name + '/game"\n',
                    './' + native_settings_exe]

                start_gn_file_path = install_dir + '/' + game_name + '/settings.sh'
                start_gn_file = open(start_gn_file_path, 'w')
                for line in start_gn_lines:
                    start_gn_file.write(line)
                start_gn_file.close()
                os.system('chmod +x ' + start_gn_file_path)

        if parser.has_option(game_name, 'win_exe'):
            win_exe = parser.get(game_name, 'win_exe')
            if win_exe != '':
                print("Writing start.sh")

                if parser.has_option(game_name, 'winedlloverrides'):
                    overrides = parser.get(game_name, 'winedlloverrides')
                    start_lines = ['#!/bin/bash\n',
                    'export WINEDLLOVERRIDES="' + overrides + '"\n',
                    'python "$NEBULA_DIR/launcher_wine.py" ' + game_name + ' "' + win_exe + '"']
                else:
                    start_lines = ['#!/bin/bash\n',
                    'python "$NEBULA_DIR/launcher_wine.py" ' + game_name + ' "' + win_exe + '"']

                start_file_path = install_dir + '/' + game_name + '/start.sh'
                start_file = open(start_file_path, 'w')
                for line in start_lines:
                    start_file.write(line)
                start_file.close()
                os.system('chmod +x ' + start_file_path)

        if parser.has_option(game_name, 'win_settings_exe'):
            win_settings_exe = parser.get(game_name, 'win_settings_exe')
            if win_settings_exe != '':
                print("Writing settings.sh")

                settings_lines = ['#!/bin/bash\n',
                'cd "$INSTALL_DIR/' + game_name + '/game"\n',
                '"$WINELOADER" "' + win_settings_exe + '"']

                settings_file_path = install_dir + '/' + game_name + '/settings.sh'
                settings_file = open(settings_file_path, 'w')
                for line in settings_lines:
                    settings_file.write(line)
                settings_file.close()
                os.system('chmod +x ' + settings_file_path)

        if parser.has_option(game_name, 'winetricks'):
            winetricks = parser.get(game_name, 'winetricks')
            if winetricks != '':
                print("Writing additions.sh")

                additions_lines = ['#!/bin/bash\n',
                'python "$NEBULA_DIR/dialogs.py" "progress" "' + 'winetricks --gui ' + winetricks + '"\n']

                additions_file_path = install_dir + '/' + game_name + '/additions.sh'
                additions_file = open(additions_file_path, 'w')
                for line in additions_lines:
                    additions_file.write(line)
                additions_file.close()
                os.system('chmod +x ' + additions_file_path)

        if parser.has_option(game_name, 'dos_iso'):
            dos_iso = parser.get(game_name, 'dos_iso')
        else:
            dos_iso = ''

        if parser.has_option(game_name, 'dos_exe'):
            dos_exe = parser.get(game_name, 'dos_exe')
            if dos_exe != '':
                print("Writing start.sh")

                start_lines = ['#!/bin/bash\n',
                'python "$NEBULA_DIR/launcher_dosbox.py" ' + game_name]

                exe_dir = ''
                if '\\' in dos_exe:
                    exe = dos_exe.split('\\')[-1]
                    exe_dir = '\\'.join(dos_exe.split('\\')[:-1])
                    dos_exe = exe

                start_file_path = install_dir + '/' + game_name + '/start.sh'
                start_file = open(start_file_path, 'w')
                for line in start_lines:
                    start_file.write(line)
                start_file.close()
                os.system('chmod +x ' + start_file_path)

                game_conf_lines = ['[autoexec]\n',
                '@echo off\n',
                'mount c ' + os.getenv('HOME') + '/.games_nebula/games/.dosbox/' + game_name + '\n',
                'c:\n',
                'imgmount d ' + os.getenv('HOME') + '/.games_nebula/games/.dosbox/' + game_name + '/' + dos_iso + ' -fs iso\n',
                'cls\n',
                'cd ' + exe_dir + '\n',
                dos_exe + '\n',
                'exit\n']

                if dos_iso == '':
                    del game_conf_lines[4]
                    if exe_dir == '':
                        del game_conf_lines[5]
                elif exe_dir == '':
                    del game_conf_lines[6]

                dosbox_game_conf_path = install_dir + '/' + game_name + '/dosbox_game.conf'
                dosbox_game_conf = open(dosbox_game_conf_path, 'w')
                for line in game_conf_lines:
                    dosbox_game_conf.write(line)
                dosbox_game_conf.close()

        if parser.has_option(game_name, 'dos_settings_exe'):
            dos_settings_exe = parser.get(game_name, 'dos_settings_exe')
            if dos_settings_exe != '':
                print("Writing dosbox_settings.conf")

                exe_dir = ''
                if '\\' in dos_settings_exe:
                    exe = dos_settings_exe.split('\\')[-1]
                    exe_dir = '\\'.join(dos_settings_exe.split('\\')[:-1])
                    dos_settings_exe = exe

                settings_conf_lines = ['[autoexec]\n',
                '@echo off\n',
                'mount c ' + os.getenv('HOME') + '/.games_nebula/games/.dosbox/' + game_name + '\n',
                'c:\n',
                'imgmount d ' + os.getenv('HOME') + '/.games_nebula/games/.dosbox/' + game_name + '/' + dos_iso + ' -fs iso\n',
                'cls\n',
                'cd ' + exe_dir + '\n',
                dos_settings_exe + '\n',
                'exit\n']

                if dos_iso == '':
                    del settings_conf_lines[4]
                    if exe_dir == '':
                        del settings_conf_lines[5]
                if exe_dir == '':
                    del settings_conf_lines[6]

                dosbox_settings_conf_path = install_dir + '/' + game_name + '/dosbox_settings.conf'
                dosbox_settings_conf = open(dosbox_settings_conf_path, 'w')
                for line in settings_conf_lines:
                    dosbox_settings_conf.write(line)
                dosbox_settings_conf.close()

        if parser.has_option(game_name, 'scummvm_name') and \
                parser.has_option(game_name, 'scummvm_id'):

            scummvm_name = parser.get(game_name, 'scummvm_name')
            scummvm_id = parser.get(game_name, 'scummvm_id')

            if scummvm_id != '':
                print("Writing start.sh")

                start_lines = ['#!/bin/bash\n',
                'python "$NEBULA_DIR/launcher_scummvm.py" ' + game_name + ' ' + scummvm_name]

                start_file_path = install_dir + '/' + game_name + '/start.sh'
                start_file = open(start_file_path, 'w')
                for line in start_lines:
                    start_file.write(line)
                start_file.close()
                os.system('chmod +x ' + start_file_path)

                scummvmrc_lines = ['[' + scummvm_name + ']\n',
                'gameid=' + scummvm_id + '\n']

                scummvmrc_path = install_dir + '/' + game_name + '/scummvmrc'
                scummvmrc = open(scummvmrc_path, 'w')
                for line in scummvmrc_lines:
                    scummvmrc.write(line)
                scummvmrc.close()

        if parser.has_option(game_name, 'special'):
            commands_list = parser.get(game_name, 'special').split('; ')
            for command in commands_list:
                os.system(command)

        if parser.has_option(game_name, 'win_reg1'):
            win_reg1 = parser.get(game_name, 'win_reg1')
            if win_reg1 != '':
                print("Writing additions.sh, reg keys")

                options_list = parser.options(game_name)

                for i in range(len(options_list)):
                    if options_list[i] == 'win_reg1':
                        win_reg1_index = i

                reg_list = parser.options(game_name)[win_reg1_index:]

                additions_file_path = install_dir + '/' + game_name + '/additions.sh'

                if (parser.has_option(game_name, 'winetricks')) and (winetricks != ''):
                    additions_file = open(additions_file_path, 'a')
                else:
                    additions_file = open(additions_file_path, 'w')
                    additions_file.write('#!/bin/bash\n')

                for item in reg_list:

                    key = parser.get(game_name, item).split('; ')[0]
                    value = parser.get(game_name, item).split('; ')[1]
                    dtype = parser.get(game_name, item).split('; ')[2]
                    data = parser.get(game_name, item).split('; ')[3]

                    line = '"$WINELOADER" reg add "' + key + '" /v "' + value + '" /t ' + dtype + ' /d "' + data + '" /f\n'

                    additions_file.write(line)

                additions_file.close()
                os.system('chmod +x ' + additions_file_path)