Skip to content

Commit

Permalink
Added import command
Browse files Browse the repository at this point in the history
  • Loading branch information
AcidWeb committed Sep 23, 2019
1 parent 18bcab8 commit f185bc9
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
33 changes: 33 additions & 0 deletions CB/Core.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,36 @@ def bulk_check(self, addons):
headers=HEADERS).json()
for addon in payload:
self.wowiCache[str(addon['UID'])] = addon

def detect_addons(self, cfdata):
addon_dirs = os.listdir(self.path)
ignored = ['ElvUI_OptionsUI', 'Tukui_Config']
hit = []
partial_hit = []
partial_hit_tmp = []
partial_hit_raw = []
miss = []
for directory in addon_dirs:
if not os.path.isdir(self.path / directory / '.git'):
if directory in cfdata:
if len(cfdata[directory]) > 1:
partial_hit_raw.append(cfdata[directory])
elif not self.check_if_installed(f'https://www.curseforge.com/wow/addons/{cfdata[directory][0]}'):
hit.append(f'cf:{cfdata[directory][0]}')
else:
if directory == 'ElvUI' or directory == 'Tukui':
if not self.check_if_installed(directory):
hit.append(directory)
elif directory not in ignored:
miss.append(directory)
for partial in partial_hit_raw:
for slug in partial:
if f'cf:{slug}' in hit or self.check_if_installed(f'https://www.curseforge.com/wow/addons/{slug}'):
break
else:
partial = [f'cf:{s}' for s in partial]
partial_hit_tmp.append(sorted(partial))
for partial in partial_hit_tmp:
if partial not in partial_hit:
partial_hit.append(partial)
return sorted(list(set(hit))), partial_hit, sorted(list(set(miss)))
2 changes: 1 addition & 1 deletion CB/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import string
import random

__version__ = '2.4.0'
__version__ = '2.5.0'
__license__ = 'GPLv3'
__copyright__ = '2019, Paweł Jastrzębski <[email protected]>'
__docformat__ = 'restructuredtext en'
Expand Down
31 changes: 29 additions & 2 deletions CurseBreaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self):
self.tableData = None
self.table = None
self.cfSlugs = None
self.cfDirectories = None
self.wowiSlugs = None
self.completer = None
self.chandle = windll.kernel32.GetStdHandle(-11)
Expand All @@ -45,6 +46,7 @@ def start(self):
# Detect Classic client
if os.path.basename(os.path.dirname(sys.executable)) == '_classic_':
self.core.clientType = 'wow_classic'
os.system(f'title CurseBreaker v{__version__} - Classic')
# Check if client have write access
try:
with open('PermissionTest', 'w') as _:
Expand Down Expand Up @@ -123,6 +125,8 @@ def start(self):
printft(HTML('Use command <ansigreen>help</ansigreen> or press <ansigreen>TAB</ansigreen> to see a list of avai'
'lable commands.\nCommand <ansigreen>exit</ansigreen> or pressing <ansigreen>CTRL+D</ansigreen> wi'
'll close the application.\n'))
if len(self.core.config['Addons']) == 0:
printft(HTML('Command <ansigreen>import</ansigreen> might be used to detect already installed addons.\n'))
# Prompt session
while True:
try:
Expand Down Expand Up @@ -206,8 +210,8 @@ def setup_completer(self):
self.cfSlugs = []
self.wowiSlugs = []
commands = ['install', 'uninstall', 'update', 'force_update', 'wa_update', 'status', 'orphans', 'search',
'toggle_backup', 'toggle_dev', 'toggle_wa', 'set_wa_api', 'set_wa_wow_account', 'uri_integration',
'help', 'exit']
'import', 'toggle_backup', 'toggle_dev', 'toggle_wa', 'set_wa_api', 'set_wa_wow_account',
'uri_integration', 'help', 'exit']
addons = sorted(self.core.config['Addons'], key=lambda k: k['Name'].lower())
for addon in addons:
commands.extend([f'uninstall {addon["Name"]}', f'update {addon["Name"]}', f'force_update {addon["Name"]}',
Expand Down Expand Up @@ -441,6 +445,28 @@ def c_search(self, args):
else:
printft(HTML('<ansigreen>Usage:</ansigreen>\n\tThis command accepts a search query as an argument.'))

def c_import(self, args):
if not self.cfDirectories:
self.cfDirectories = pickle.load(gzip.open(io.BytesIO(
requests.get(f'https://storage.googleapis.com/cursebreaker/cfdir{self.core.clientType}.pickle.gz',
headers=HEADERS).content)))
hit, partial_hit, miss = self.core.detect_addons(self.cfDirectories)
if args == 'install' and len(hit) > 0:
self.c_install(','.join(hit))
else:
printft(HTML(f'<ansigreen>Addons found:</ansigreen>'))
for addon in hit:
printft(addon)
printft(HTML(f'\n<ansiyellow>Possible matches:</ansiyellow>'))
for addon in partial_hit:
printft(HTML(' <ansiwhite>or</ansiwhite> '.join(addon)))
printft(HTML(f'\n<ansired>Unknown directories:</ansired>'))
for addon in miss:
printft(f'{addon}')
printft(HTML(f'\nExecute <ansiwhite>import install</ansiwhite> command to install all detected addons.\n'
f'Possible matches need to be installed manually with the <ansiwhite>install</ansiwhite>'
f' command.'))

def c_help(self, _):
printft(HTML('<ansigreen>install [URL]</ansigreen>\n\tCommand accepts a comma-separated list of links.\n'
'<ansigreen>uninstall [URL/Name]</ansigreen>\n\tCommand accepts a comma-separated list of links or'
Expand All @@ -455,6 +481,7 @@ def c_help(self, _):
'<ansigreen>status</ansigreen>\n\tPrints the current state of all installed addons.\n'
'<ansigreen>orphans</ansigreen>\n\tPrints list of orphaned directories and files.\n'
'<ansigreen>search [Keyword]</ansigreen>\n\tExecutes addon search on CurseForge.\n'
'<ansigreen>import</ansigreen>\n\tCommand attempts to import already installed addons.\n'
'<ansigreen>toggle_backup</ansigreen>\n\tEnables/disables automatic daily backup of WTF directory.'
'\n<ansigreen>toggle_dev [Name]</ansigreen>\n\tCommand accepts an addon name as argument.\n\tPrior'
'itizes alpha/beta versions for the provided addon.\n'
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The latest release can be found [here](https://github.com/AcidWeb/CurseBreaker/r
## USAGE
Should be pretty self-explanatory. Place **CurseBreaker** EXE inside directory containing `Wow.exe` and start it up.\
Already installed addons will not be recognized by **CurseBreaker** and they need to be reinstalled.\
This process can be partially automated by using the `import` command.\
Both _Retail_ and _Classic_ clients are supported. The client version is detected automatically.\
By default **CurseBreaker** create backups of entire `WTF` directory.

Expand Down

0 comments on commit f185bc9

Please sign in to comment.