;title='Mod Alchemist'
;creator=ppkantorski
;version=0.5.3
;about='This package was designed for managing, converting, and installing mods.'
;credits='Special thanks to Fl4sh9174, KeatonTheBot, StevensND, cucholix and theboy181.'
;color=#8e43f7

[@Enhance]

[gap]
;mode=table
;background=false
;gap=20

[Title ID]
;mode=table
'Program ID'='{title_id}'

[Manage Mods]

[*exeFS Patches]
;mode=forwarder
package_source ./exefs_patches.ini


[*Contents Mods?1]

[*Active?2]
;mode=toggle
;grouping=split5
on:
    file_source './contents/.loaded/*/{title_id}/'
    delete {file_source}
    delete './contents/.loaded/{folder_name}/duplicates.txt'
    compare './contents/.loaded/{split({folder_name}," - ",0)}*/location_on.txt' './contents/.loaded/{folder_name}/location_on.txt' './contents/.loaded/{folder_name}/duplicates.txt'
    move -src './contents/.loaded/{folder_name}/location_on.txt' -dest './contents/.loaded/{folder_name}/location_off.txt' -copy_filter './contents/.loaded/{folder_name}/duplicates.txt'
    delete './contents/.loaded/{folder_name}/'
off:
    file_source './contents/*/{title_id}/'
    filter './contents/.loaded/*/'
    move './contents/{folder_name}/' '/atmosphere/contents/' -log_src './contents/.loaded/{folder_name}/location_off.txt' -log_dest './contents/.loaded/{folder_name}/location_on.txt'
    mkdir ./contents/.loaded/{folder_name}/{file_name}/

[gap]
;mode=table
;background=false
;gap=20

[*Toggle?2]
;mode=toggle
;grouping=split5
on:
    file_source './contents/.loaded/*/*/'
    delete {file_source}
    delete './contents/.loaded/{folder_name}/duplicates.txt'
    compare './contents/.loaded/{split({folder_name}," - ",0)}*/location_on.txt' './contents/.loaded/{folder_name}/location_on.txt' './contents/.loaded/{folder_name}/duplicates.txt'
    move -src './contents/.loaded/{folder_name}/location_on.txt' -dest './contents/.loaded/{folder_name}/location_off.txt' -copy_filter './contents/.loaded/{folder_name}/duplicates.txt'
    delete './contents/.loaded/{folder_name}/'
off:
    file_source './contents/*/*/'
    filter './contents/.loaded/*/'
    move './contents/{folder_name}/' '/atmosphere/contents/' -log_src './contents/.loaded/{folder_name}/location_off.txt' -log_dest './contents/.loaded/{folder_name}/location_on.txt'
    mkdir ./contents/.loaded/{folder_name}/{file_name}/



[*Delete?2]
;grouping=split3
file_source './contents/.loaded/*/'
file_source './contents/*/'
compare './contents/.loaded/{split({file_name}," - ",0)}*/location_on.txt' '{file_source}location_on.txt' '{file_source}duplicates.txt'
delete -src '{file_source}location_on.txt' -filter '{file_source}duplicates.txt'
delete {file_source}

[gap]
;mode=table
;background=false
;gap=20

[contents info]
;mode=table
;background=false
;alignment=left
;offset=6
;spacing=10

'For managing content mods installed in'=''
''='"/switch/.packages/Mod Alchemist/contents/"'



[Convert Mods]

[*pchtxt  ips]
;grouping=split2
file_source './pchtxts/*/*.pchtxt'
mkdir "/atmosphere/exefs_patches/{folder_name}/"
pchtxt2ips "{file_source}" "/atmosphere/exefs_patches/{folder_name}/"

[*pchtxt  cheat]
;grouping=split2
file_source './pchtxts/*/*.pchtxt'
pchtxt2cheat "{file_source}"




#[gap]
#;mode=table
#;background=false
#;gap=16


[*Delete pchtxt]
;grouping=split2
file_source './pchtxts/*/*.pchtxt'
delete "{file_source}"



#[gap]
#;mode=table
#;background=false
#;gap=20
#
#[pchtxt info]
#;mode=table
#;background=false
#;alignment=left
#;offset=9
#;spacing=10
#
#'"/{GAME} - {MOD}/{VERSION}.pchtxt" go in'=''
#''='"/switch/.packages/Mod Alchemist/pchtxts/"'


[@Integrate]

[Mod Repos]

[*Install pchtxt]
[*Search Pattern?pchtxt_repo]
;mode=option
list_file_source './search_patterns.txt'
set-footer '{list_file_source(*)}'

[*Search Results?pchtxt_repo]
;grouping=split2
ini_file './config.ini'
file_source './repos/pchtxts/*/*{ini_file("*Search Pattern?pchtxt_repo",footer)}*/*.pchtxt'
cp "{file_source}" './pchtxts/{folder_name}/'

[gap]
;mode=table
;background=false
;gap=10

[*Repos?1]
;mode=forwarder
package_source ./pchtxt_repos.ini



[*Install Contents]
[*Search Pattern?contents_repo]
;mode=option
list_file_source './search_patterns.txt'
set-footer '{list_file_source(*)}'

[*Search Results?contents_repo]
;grouping=split2
ini_file './config.ini'
file_source './repos/contents/*/*{ini_file("*Search Pattern?contents_repo",footer)}*/'
cp "{file_source}" './contents/{folder_name}/'

[gap]
;mode=table
;background=false
;gap=10


[*Repos?2]
;mode=forwarder
package_source ./contents_repos.ini




[*Extract Repos]

[Extract All]
unzip './repos/pchtxts/Fl4sh9174.zip' './repos/pchtxts/Fl4sh9174/'
unzip './repos/pchtxts/KeatonTheBot.zip' './repos/pchtxts/KeatonTheBot/'
unzip './repos/pchtxts/StevensND.zip' './repos/pchtxts/StevensND/'
unzip './repos/pchtxts/cucholix.zip' './repos/pchtxts/cucholix/'
unzip './repos/pchtxts/theboy181.zip' './repos/pchtxts/theboy181/'

unzip './repos/contents/cucholix.zip' './repos/contents/cucholix/'

[gap]
;mode=table
;background=false
;gap=10


[Fl4sh9174's Mods]
unzip './repos/pchtxts/Fl4sh9174.zip' './repos/pchtxts/Fl4sh9174/'

[KeatonTheBot's Mods]
unzip './repos/pchtxts/KeatonTheBot.zip' './repos/pchtxts/KeatonTheBot/'

[StevensND's Mods]
unzip './repos/pchtxts/StevensND.zip' './repos/pchtxts/StevensND/'

[cucholix's Mods]
unzip './repos/pchtxts/cucholix.zip' './repos/pchtxts/cucholix/'
unzip './repos/contents/cucholix.zip' './repos/contents/cucholix/'

[theboy181's Mods]
unzip './repos/pchtxts/theboy181.zip' './repos/pchtxts/theboy181/'



[Tools]
[*Software Update]

[Update Mod Alchemist]
try:
delete /config/ultrahand/downloads/Mod.Alchemist.zip
download http://github.com/ppkantorski/Mod-Alchemist/releases/latest/download/Mod.Alchemist.zip /config/ultrahand/downloads/
unzip /config/ultrahand/downloads/Mod.Alchemist.zip /
delete /config/ultrahand/downloads/Mod.Alchemist.zip

[Update Repos + Extract]
delete './repos/pchtxts/Fl4sh9174.zip'
delete './repos/pchtxts/KeatonTheBot.zip'
delete './repos/pchtxts/StevensND.zip'
delete './repos/pchtxts/cucholix.zip'
delete './repos/pchtxts/theboy181.zip'
delete './repos/contents/cucholix.zip'

download https://github.com/ppkantorski/Mod-Alchemist/raw/refs/heads/main/Mod%20Alchemist/repos/pchtxts/Fl4sh9174.zip  ./repos/pchtxts/
download https://github.com/ppkantorski/Mod-Alchemist/raw/refs/heads/main/Mod%20Alchemist/repos/pchtxts/KeatonTheBot.zip ./repos/pchtxts/
download https://github.com/ppkantorski/Mod-Alchemist/raw/refs/heads/main/Mod%20Alchemist/repos/pchtxts/StevensND.zip ./repos/pchtxts/
download https://github.com/ppkantorski/Mod-Alchemist/raw/refs/heads/main/Mod%20Alchemist/repos/pchtxts/cucholix.zip ./repos/pchtxts/
download https://github.com/ppkantorski/Mod-Alchemist/raw/refs/heads/main/Mod%20Alchemist/repos/pchtxts/theboy181.zip ./repos/pchtxts/
download https://github.com/ppkantorski/Mod-Alchemist/raw/refs/heads/main/Mod%20Alchemist/repos/contents/cucholix.zip ./repos/contents/

unzip './repos/pchtxts/Fl4sh9174.zip' './repos/pchtxts/Fl4sh9174/'
unzip './repos/pchtxts/KeatonTheBot.zip' './repos/pchtxts/KeatonTheBot/'
unzip './repos/pchtxts/StevensND.zip' './repos/pchtxts/StevensND/'
unzip './repos/pchtxts/cucholix.zip' './repos/pchtxts/cucholix/'
unzip './repos/pchtxts/theboy181.zip' './repos/pchtxts/theboy181/'

unzip './repos/contents/cucholix.zip' './repos/contents/cucholix/'

[Package Info]
