Skip to content

Commit

Permalink
Fix several issues with sessions and moving files during updates (#40)
Browse files Browse the repository at this point in the history
* Get rid of 'default_session' special case

* Look for `id` instead of `ident`

* Fix moving launcher and save folder

* Rename Session to User Data

* rename Directory to Game Directory for clarity
  • Loading branch information
Fris0uman authored Dec 18, 2022
1 parent f2576e0 commit f983fc2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
7 changes: 4 additions & 3 deletions cddagl/ui/views/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ def game_dir_changed(self, new_dir):
def get_save_dir(self):
save_dir = os.path.join(self.game_dir, 'save')
session = get_config_value('session_directory')
if session != 'default_session' and session is not None:
if session != self.game_dir and session is not None:
save_dir = os.path.join(session, 'save')
if not os.path.isdir(save_dir) and os.path.isdir(session):
try:
Expand Down Expand Up @@ -1146,7 +1146,7 @@ def app_locale(self):
def get_backup_dir(self):
backup_dir = os.path.join(self.game_dir, 'save_backups')
session = get_config_value('session_directory')
if session != 'default_session' and session is not None:
if session != self.game_dir and session is not None:
backup_dir = os.path.join(session, 'save_backups')
if not os.path.isdir(backup_dir) and os.path.isdir(session):
try:
Expand Down Expand Up @@ -1197,6 +1197,7 @@ def update_backups_table(self):

self.backups_scan = scandir(backup_dir)
save_dir_name = get_config_value('session_directory')
# Check default_session for compatibility with 1.6.3
if save_dir_name == 'default_session' or save_dir_name is None:
save_dir_name = 'save/'
else:
Expand All @@ -1218,7 +1219,7 @@ def timeout():
uncompressed_size += info.file_size

path_items = info.filename.split('/')
target_length = 3 if get_config_value('session_directory') =='default_session' else 4
target_length = 3 if get_config_value('session_directory') == self.game_dir else 4
if len(path_items) == target_length:
save_file = path_items[-1]
if save_file.endswith('.sav'):
Expand Down
36 changes: 16 additions & 20 deletions cddagl/ui/views/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ def __init__(self):
self.set_text()

def set_text(self):
self.dir_label.setText(_('Directory:'))
self.session_label.setText(_('Session:'))
self.dir_label.setText(_('Game Directory:'))
self.session_label.setText(_('User Data:'))
self.version_label.setText(_('Version:'))
self.build_label.setText(_('Build:'))
self.saves_label.setText(_('Saves:'))
Expand Down Expand Up @@ -293,8 +293,9 @@ def showEvent(self, event):
self.game_directory_changed()

sess_directory = get_config_value('session_directory')
if sess_directory is None or sess_directory == game_directory:
sess_directory = 'default_session'
# Check for default_session for compatibility with 1.6.3
if sess_directory == 'default_session' or sess_directory is None:
sess_directory = game_directory
self.set_sess_combo_value(sess_directory)
self.sess_directory_changed()

Expand Down Expand Up @@ -465,7 +466,7 @@ def launch_game_process(self):
params = ' ' + params

current_session = get_config_value('session_directory')
if current_session != 'default_session' and current_session is not None:
if current_session != self.game_dir and current_session is not None:
self.get_main_window().statusBar().showMessage(current_session)
params = params + ' ' + '--userdir' + ' ' + '\"' + current_session + '/\"'

Expand Down Expand Up @@ -652,11 +653,6 @@ def sess_index_changed(self, index):

def sess_directory_changed(self):
directory = self.sess_combo.currentText()
game_dir = self.dir_combo.currentText()
if directory == game_dir:
directory = 'default_session'
self.sess_combo.setCurrentText(directory)
self.sess_directory_changed()

set_config_value('session_directory', directory)
self.add_session_dir()
Expand Down Expand Up @@ -694,8 +690,8 @@ def dc_index_changed(self, index):
def game_directory_changed(self):
directory = self.dir_combo.currentText()
sess_dir = self.sess_combo.currentText()
if directory == sess_dir:
self.sess_combo.setCurrentText('default_session')
if not os.path.isdir(sess_dir):
self.sess_combo.setCurrentText(directory)
self.sess_directory_changed()

main_window = self.get_main_window()
Expand Down Expand Up @@ -1038,7 +1034,7 @@ def update_saves(self):
self.saves_value_edit.setText(_('Unknown'))

save_dir = os.path.join(self.game_dir, 'save')
if session != 'default_session' and session is not None:
if session != self.game_dir and session is not None:
save_dir = os.path.join(session, 'save')

if not os.path.isdir(save_dir):
Expand Down Expand Up @@ -2302,11 +2298,7 @@ def backup_current_game(self):
excluded_dirs = []
for session in sessions:
if os.path.dirname(session) == game_dir:
excluded_dirs.append( os.path.basename(os.path.normpath(session)))

for entry in dir_list:
if entry not in excluded_dirs:
self.backup_dir_list.append(entry)
excluded_dirs.append(os.path.basename(os.path.normpath(session)))

if (config_true(get_config_value('prevent_save_move', 'False'))
and 'save' in dir_list):
Expand All @@ -2319,6 +2311,10 @@ def backup_current_game(self):
if launcher_name in dir_list:
dir_list.remove(launcher_name)

for entry in dir_list:
if entry not in excluded_dirs:
self.backup_dir_list.append(entry)

if len(dir_list) > 0:
status_bar.showMessage(_('Backing up current game'))

Expand Down Expand Up @@ -2531,12 +2527,12 @@ def mod_ident(self, path):
values = json.load(f)
if isinstance(values, dict):
if values.get('type', '') == 'MOD_INFO':
return values.get('ident', None)
return values.get('id', None)
elif isinstance(values, list):
for item in values:
if (isinstance(item, dict)
and item.get('type', '') == 'MOD_INFO'):
return item.get('ident', None)
return item.get('id', None)
except ValueError:
pass
except FileNotFoundError:
Expand Down
2 changes: 1 addition & 1 deletion cddagl/ui/views/soundpacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ def game_dir_changed(self, new_dir):

session = get_config_value('session_directory')
soundpacks_dir = os.path.join(new_dir, 'data', 'sound')
if session != 'default_session' and session is not None:
if session != self.game_dir and session is not None:
soundpacks_dir = os.path.join(session, 'sound')
if not os.path.isdir(soundpacks_dir) and os.path.isdir(session):
try:
Expand Down

0 comments on commit f983fc2

Please sign in to comment.