Skip to content

Commit

Permalink
Update 032821 6
Browse files Browse the repository at this point in the history
Add advanced setting to convert old IAGL favorites files, fixes #206
  • Loading branch information
zach-morris committed Mar 9, 2021
1 parent cb4522e commit c7166f6
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 1 deletion.
40 changes: 40 additions & 0 deletions convert_old_favorites.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import xbmc, xbmcgui, xbmcvfs, os
from pathlib import Path
from resources.lib.utils import loc_str, get_mem_cache, set_mem_cache, clear_mem_cache, check_if_file_exists, get_xml_games, get_xml_header_path_et_fromstring, write_text_to_file
from resources.lib import xmltodict
from resources.lib.main import iagl_addon
iagl_addon_handle = iagl_addon()
if not get_mem_cache('iagl_script_started'):
set_mem_cache('iagl_script_started','true')
xbmc.log(msg='IAGL: Convert old favorites format script started', level=xbmc.LOGDEBUG)
success = False
current_dialog = xbmcgui.Dialog()
old_file = current_dialog.browse(1,loc_str(30618),'')
if old_file:
old_file_path = Path(old_file)
games = None
if check_if_file_exists(old_file_path):
games = get_xml_games(old_file_path)
games_header = get_xml_header_path_et_fromstring(old_file_path)
for gg in games:
if gg.get('rom') and gg.get('rom').get('@name'):
gg['route'] = gg.get('rom').get('@name').replace('plugin://plugin.program.iagl/game/','').split('/')[0]
gg.pop('rom', None)
new_file_path = iagl_addon_handle.directory.get('userdata').get('dat_files').get('path').joinpath(old_file_path.name)
if not check_if_file_exists(new_file_path):
xml_out = xmltodict.unparse({'datafile':{'header':games_header}}, pretty=True).replace('</datafile>',''.join([xmltodict.unparse({'game':x},pretty=True).replace('<?xml version="1.0" encoding="utf-8"?>','') for x in games if x and x.get('route')]))+'\n</datafile>'
success = write_text_to_file(xml_out.replace('\n\n','\n'),new_file_path)
else:
xbmc.log(msg='IAGL: A favorites file with the same name already exists. Please rename the old file or delete the existing file.', level=xbmc.LOGERROR)
else:
xbmc.log(msg='IAGL: Unable to stat old file, please ensure it is on the local filesystem', level=xbmc.LOGERROR)
if success:
ok_ret = current_dialog.ok(loc_str(30202),loc_str(30620))
clear_mem_cache('iagl_directory')
else:
ok_ret = current_dialog.ok(loc_str(30203),loc_str(30621))
clear_mem_cache('iagl_script_started')
xbmc.log(msg='IAGL: Convert old favorites format script completed', level=xbmc.LOGDEBUG)
else:
xbmc.log(msg='IAGL: Script already running', level=xbmc.LOGDEBUG)
del iagl_addon_handle, loc_str, get_mem_cache, set_mem_cache, clear_mem_cache, check_if_file_exists, get_xml_games, get_xml_header_path_et_fromstring, write_text_to_file
14 changes: 14 additions & 0 deletions resources/language/English/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,21 @@ msgctxt "#30617"
msgid "Do you want to enable Netplay features?"
msgstr "Do you want to enable Netplay features?"

msgctxt "#30618"
msgid "Convert old IAGL Favorites File"
msgstr "Convert old IAGL Favorites File"

msgctxt "#30619"
msgid "Convert an IAGL v2.x Favorites File to use with IAGL 3.x"
msgstr "Convert an IAGL v2.x Favorites File to use with IAGL 3.x"

msgctxt "#30620"
msgid "File converted and saved to game lists"
msgstr "File converted and saved to game lists"

msgctxt "#30621"
msgid "Error converting file, see Kodi log"
msgstr "Error converting file, see Kodi log"

#
#General
Expand Down
13 changes: 13 additions & 0 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,19 @@
</dependencies>
<control format="action" type="button"/>
</setting>
<setting help="30619" id="iagl_convert_old_favorites" label="30618" type="action">
<level>2</level>
<data>RunScript(special://home/addons/plugin.program.iagl/convert_old_favorites.py)</data>
<constraints>
<allowempty>true</allowempty>
</constraints>
<dependencies>
<dependency type="visible">
<condition name="InfoBool" on="property">true</condition>
</dependency>
</dependencies>
<control format="action" type="button"/>
</setting>
</group>
<group id="11">
<setting help="30578" id="iagl_run_script_clear_cache" label="30056" type="action">
Expand Down
1 change: 0 additions & 1 deletion unhide_all_archives.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from resources.lib.utils import loc_str, get_mem_cache, set_mem_cache, clear_mem_cache
from resources.lib.main import iagl_addon
iagl_addon_handle = iagl_addon()
clear_mem_cache('iagl_script_started')
if not get_mem_cache('iagl_script_started'):
set_mem_cache('iagl_script_started','true')
xbmc.log(msg='IAGL: Set game lists to visible script started', level=xbmc.LOGDEBUG)
Expand Down

0 comments on commit c7166f6

Please sign in to comment.