<commit_before>"""
Utility dialogs for starcheat itself
"""

import os, sys
from PyQt5.QtWidgets import QDialog, QFileDialog, QMessageBox, QListWidgetItem
from PyQt5 import QtGui

from config import Config
from gui_common import preview_icon
import save_file, assets, logging
import qt_options, qt_openplayer, qt_about

def save_modified_dialog():
    """Display a prompt asking user what to do about a modified file. Return button clicked."""
    dialog = QMessageBox()
    dialog.setText("This player has been modified.")
    dialog.setInformativeText("Do you want to save your changes?")
    dialog.setStandardButtons(QMessageBox.Save | QMessageBox.Cancel | QMessageBox.Discard)
    dialog.setDefaultButton(QMessageBox.Save)
    dialog.setIcon(QMessageBox.Question)
    return dialog.exec()

def new_setup_dialog():
    """Run through an initial setup dialog for starcheat if it's required."""
    if os.path.isfile(Config().ini_file):
        return

    logging.info("First setup dialog")
    starbound_folder = Config().detect_starbound_folder()

    if starbound_folder == "":
        dialog = QMessageBox()
        dialog.setText("Unable to detect the main Starbound folder.")
        dialog.setInformativeText("Please select it in the next dialog.")
        dialog.setIcon(QMessageBox.Warning)
        dialog.exec()
        starbound_folder = QFileDialog.getExistingDirectory(caption="Select Starbound Folder")
    else:
        dialog = QMessageBox()
        dialog.setText("Detected the following folder as the location of Starbound. Is this correct?")
        dialog.setInformativeText(starbound_folder)
        dialog.setStandardButtons(QMessageBox.No | QMessageBox.Yes)
        dialog.setIcon(QMessageBox.Question)
        answer = dialog.exec()
        if answer == QMessageBox.No:
            starbound_folder = QFileDialog.getExistingDirectory(caption="Select Starbound Folder")
    if starbound_folder == "":
        dialog = QMessageBox()
        dialog.setIcon(QMessageBox.Critical)
        dialog.setText("starcheat needs Starbound installed to work properly.")
        dialog.exec()
        Config().remove_config()
        sys.exit()

    Config().create_config(starbound_folder)

    logging.info("Indexing assets")
    dialog = QMessageBox()
    dialog.setText("starcheat will now build a database of Starbound assets.")
    dialog.setInformativeText("This can take a little while, please be patient.")
    dialog.setIcon(QMessageBox.Information)
    dialog.exec()

    assets_db = Config().read("assets_db")
    try:
        if os.path.isfile(assets_db):
            assets.AssetsDb().rebuild_db()
        else:
            assets.AssetsDb().init_db()
    except FileNotFoundError:
        logging.exception("Asset folder not found")
        dialog = QMessageBox()
        dialog.setText("Unable to index assets.")
        dialog.setInformativeText("Try run starcheat again and check the Starbound folder is correct.")
        dialog.setIcon(QMessageBox.Critical)
        dialog.exec()
        Config().remove_config()
        sys.exit()

    total_assets = assets.AssetsDb().get_total_indexed()
    logging.debug(total_assets)

    if total_assets == 0:
        logging.error("No assets indexed")
        dialog = QMessageBox()
        dialog.setText("No assets were found. starcheat may not run correctly.")
        dialog.setInformativeText("Try run starcheat again and check the Starbound folder is correct.")
        dialog.setIcon(QMessageBox.Critical)
        dialog.exec()
        Config().remove_config()
        sys.exit()
<commit_msg>Clean config dir on failed setup<commit_after>"""
Utility dialogs for starcheat itself
"""

import os, sys
from PyQt5.QtWidgets import QDialog, QFileDialog, QMessageBox, QListWidgetItem
from PyQt5 import QtGui

from config import Config
from gui_common import preview_icon
import save_file, assets, logging
import qt_options, qt_openplayer, qt_about

def save_modified_dialog():
    """Display a prompt asking user what to do about a modified file. Return button clicked."""
    dialog = QMessageBox()
    dialog.setText("This player has been modified.")
    dialog.setInformativeText("Do you want to save your changes?")
    dialog.setStandardButtons(QMessageBox.Save | QMessageBox.Cancel | QMessageBox.Discard)
    dialog.setDefaultButton(QMessageBox.Save)
    dialog.setIcon(QMessageBox.Question)
    return dialog.exec()

def new_setup_dialog():
    """Run through an initial setup dialog for starcheat if it's required."""
    if os.path.isfile(Config().ini_file):
        return

    logging.info("First setup dialog")
    starbound_folder = Config().detect_starbound_folder()

    if starbound_folder == "":
        dialog = QMessageBox()
        dialog.setText("Unable to detect the main Starbound folder.")
        dialog.setInformativeText("Please select it in the next dialog.")
        dialog.setIcon(QMessageBox.Warning)
        dialog.exec()
        starbound_folder = QFileDialog.getExistingDirectory(caption="Select Starbound Folder")
    else:
        dialog = QMessageBox()
        dialog.setText("Detected the following folder as the location of Starbound. Is this correct?")
        dialog.setInformativeText(starbound_folder)
        dialog.setStandardButtons(QMessageBox.No | QMessageBox.Yes)
        dialog.setIcon(QMessageBox.Question)
        answer = dialog.exec()
        if answer == QMessageBox.No:
            starbound_folder = QFileDialog.getExistingDirectory(caption="Select Starbound Folder")
    if starbound_folder == "":
        dialog = QMessageBox()
        dialog.setIcon(QMessageBox.Critical)
        dialog.setText("starcheat needs Starbound installed to work properly.")
        dialog.exec()
        Config().remove_config()
        sys.exit()

    Config().create_config(starbound_folder)

    logging.info("Indexing assets")
    dialog = QMessageBox()
    dialog.setText("starcheat will now build a database of Starbound assets.")
    dialog.setInformativeText("This can take a little while, please be patient.")
    dialog.setIcon(QMessageBox.Information)
    dialog.exec()

    assets_db = Config().read("assets_db")
    try:
        if os.path.isfile(assets_db):
            os.remove(assets_db)
        assets.AssetsDb().init_db()
    except FileNotFoundError:
        logging.exception("Asset folder not found")
        dialog = QMessageBox()
        dialog.setText("Unable to index assets.")
        dialog.setInformativeText("Try run starcheat again and check the Starbound folder is correct.")
        dialog.setIcon(QMessageBox.Critical)
        dialog.exec()
        Config().remove_config()
        os.remove(assets_db)
        sys.exit()

    total_assets = assets.AssetsDb().get_total_indexed()
    logging.debug(total_assets)

    if total_assets == 0:
        logging.error("No assets indexed")
        dialog = QMessageBox()
        dialog.setText("No assets were found. starcheat may not run correctly.")
        dialog.setInformativeText("Try run starcheat again and check the Starbound folder is correct.")
        dialog.setIcon(QMessageBox.Critical)
        dialog.exec()
        Config().remove_config()
        os.remove(assets_db)
        sys.exit()

{'fraction_non_alphanumeric': 0.09484077318870811, 'fraction_numerical': 0.0008343763037129745, 'mean_word_length': 3.3014354066985647, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3270563', 'n_tokens_mistral': 1993, 'n_tokens_neox': 1950, 'n_words': 520}