Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change save data folder to my games #313

Merged
merged 2 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/games/fallout4.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class fallout4(gameable):
# f4_wav_file2 = f'MutantellaOutput2.wav'

def __init__(self, config: ConfigLoader):
super().__init__('data/Fallout4/fallout4_characters.csv', "Fallout4")
super().__init__(config, 'data/Fallout4/fallout4_characters.csv', "Fallout4")
if config.game == "Fallout4VR":
self.__compatibility = file_communication_compatibility(config.game_path, int(config.port))# <- creating an object of this starts the listen thread
self.__config: ConfigLoader = config
Expand Down
8 changes: 2 additions & 6 deletions src/games/gameable.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,14 @@ class gameable(ABC):
Args:
ABC (_type_): _description_
"""
def __init__(self, path_to_character_df: str, mantella_game_folder_path: str):
def __init__(self, config: ConfigLoader, path_to_character_df: str, mantella_game_folder_path: str):
try:
self.__character_df: pd.DataFrame = self.__get_character_df(path_to_character_df)
except:
logging.error(f'Unable to read / open {path_to_character_df}. If you have recently edited this file, please try reverting to a previous version. This error is normally due to using special characters, or saving the CSV in an incompatible format.')
input("Press Enter to exit.")

# if the exe is being run by another process, store conversation data in MantellaData rather than the local data folder
if "--integrated" in sys.argv:
self.__conversation_folder_path = str(Path(utils.resolve_path()).parent.parent.parent.parent)+f'/MantellaData/{mantella_game_folder_path}/conversations'
else:
self.__conversation_folder_path = f"data/{mantella_game_folder_path}/conversations"
self.__conversation_folder_path = config.save_folder+f"data/{mantella_game_folder_path}/conversations"

conversation_log.game_path = self.__conversation_folder_path

Expand Down
2 changes: 1 addition & 1 deletion src/games/skyrim.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class skyrim(gameable):
LIP_FILE = f'MantellaDi_MantellaDialogu_00001D8B_1.lip'

def __init__(self, config: ConfigLoader):
super().__init__('data/Skyrim/skyrim_characters.csv', "Skyrim")
super().__init__(config, 'data/Skyrim/skyrim_characters.csv', "Skyrim")
self.__create_all_voice_folders(config)

def __create_all_voice_folders(self, config: ConfigLoader):
Expand Down
19 changes: 13 additions & 6 deletions src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ def set_cwd_to_exe_dir():
if getattr(sys, 'frozen', False): # if exe and not Python script
# change the current working directory to the executable's directory
os.chdir(os.path.dirname(sys.executable))

def get_my_games_directory():
home = Path.home()
save_dir = home / "Documents" / "My Games" / "Mantella"
save_dir.mkdir(parents=True, exist_ok=True)
return str(save_dir)+'\\'

def setup_logging(file_name):
logging.basicConfig(level=logging.DEBUG, format='%(levelname)s: %(message)s', handlers=[])
Expand Down Expand Up @@ -81,17 +87,18 @@ def get_language_info(file_name) -> dict[Hashable, str]:
return {}

set_cwd_to_exe_dir()
setup_logging(logging_file)
if "--integrated" in sys.argv:
config_file = str(Path(utils.resolve_path()).parent.parent.parent.parent)+'/MantellaData/'+config_file
config = config_loader.ConfigLoader(config_file)
logging.log(24, f'Mantella.exe running in {os.getcwd()}. config.ini available in {os.path.abspath(config_file)}.')
logging.log(24, f'Mantella currently running for {config.game}. Mantella mod files located in {config.mod_path}.')
save_folder = get_my_games_directory()
setup_logging(save_folder+logging_file)
config = config_loader.ConfigLoader(save_folder+config_file)
config.save_folder = save_folder
logging.log(23, f'Mantella.exe running in {os.getcwd()}. config.ini, logging.log, and conversation histories available in {save_folder}.')
logging.log(23, f'Mantella currently running for {config.game}. Mantella mod files located in {config.mod_path}.')
if not config.have_all_config_values_loaded_correctly:
logging.error("Cannot start Mantella. Not all settings that are required are set to correct values. Please check the above error messages and correct the corresponding settings!")

# clean up old instances of exe runtime files
utils.cleanup_mei(config.remove_mei_folders)
utils.cleanup_tmp(config.save_folder+'data\\tmp')

language_info = get_language_info(language_file)

Expand Down
3 changes: 2 additions & 1 deletion src/tts/ttsable.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ def __init__(self, config: ConfigLoader) -> None:
self._facefx_path = config.facefx_path
self._times_checked = 0
self._tts_print = config.tts_print # to print output to console
self._output_path = utils.resolve_path()+'/data'
self._output_path = config.save_folder+'data\\tmp'
self._voiceline_folder = f"{self._output_path}/voicelines"
os.makedirs(self._voiceline_folder, exist_ok=True)
self._language = config.language
self._last_voice = '' # last active voice model
# determines whether the voiceline should play internally
Expand Down
2 changes: 1 addition & 1 deletion src/tts/xtts.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def filter_and_log_speakers(voice_model_list, log_file_name, available_speakers,
log_data.append(row)

# Write log data to CSV file
with open(f"data/{log_file_name}_xtts.csv", 'w', newline='', encoding='utf-8') as csvfile:
with open(f"{self.config.save_folder}data/{log_file_name}_xtts.csv", 'w', newline='', encoding='utf-8') as csvfile:
writer = csv.writer(csvfile)
writer.writerows(log_data)

Expand Down
2 changes: 1 addition & 1 deletion src/tts/xvasynth.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def tts_synthesize(self, voiceline, final_voiceline_file, aggro):
phrases = self._split_voiceline(voiceline)
voiceline_files = []
for phrase in phrases:
voiceline_file = f"{self._output_path}/voicelines/{utils.clean_text(phrase)[:150]}.wav"
voiceline_file = f"{self._voiceline_folder}/{utils.clean_text(phrase)[:150]}.wav"
voiceline_files.append(voiceline_file)

if len(phrases) == 1:
Expand Down
15 changes: 15 additions & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ def get_file_encoding(file_path) -> str | None:
return None


def cleanup_tmp(tmp_folder: str):
if os.path.exists(tmp_folder):
mei_bundle = getattr(sys, "_MEIPASS", False)

for filename in os.listdir(tmp_folder):
file_path = os.path.join(tmp_folder, filename)
try:
if os.path.isfile(file_path):
os.remove(file_path)
elif (os.path.isdir(file_path)) and (file_path != mei_bundle):
rmtree(file_path)
except Exception as e:
logging.error(f"Failed to delete tmp folder: {e}")


def cleanup_mei(remove_mei_folders: bool):
"""
Rudimentary workaround for https://github.com/pyinstaller/pyinstaller/issues/2379
Expand Down