Skip to content

Commit

Permalink
Added support for new curseforge URI (close #230)
Browse files Browse the repository at this point in the history
  • Loading branch information
AcidWeb committed Nov 12, 2020
1 parent 4fb3caf commit 4b481bf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
20 changes: 15 additions & 5 deletions CB/Core.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ def add_addon(self, url, ignore):
raise NotImplementedError('Provided URL is not supported.')
elif 'twitch://' in url:
url = url.split('/download-client')[0].replace('twitch://', 'https://').strip()
elif 'curseforge://' in url:
url = self.parse_cf_payload(url.strip(), False)
elif url.startswith('cf:'):
url = f'https://www.curseforge.com/wow/addons/{url[3:]}'
elif url.startswith('wowi:'):
Expand Down Expand Up @@ -469,7 +471,12 @@ def create_reg(self):
'KEY_CURRENT_USER\Software\Classes\\twitch\DefaultIcon]\n@="\\"CurseBreaker.exe,1\\""\n[HKEY_'
'CURRENT_USER\Software\Classes\\twitch\shell]\n[HKEY_CURRENT_USER\Software\Classes\\twitch\sh'
'ell\open]\n[HKEY_CURRENT_USER\Software\Classes\\twitch\shell\open\command]\n@="\\"'
+ os.path.abspath(sys.executable).replace('\\', '\\\\') + '\\" \\"%1\\""')
+ os.path.abspath(sys.executable).replace('\\', '\\\\') + '\\" \\"%1\\""\n[HKEY_CURRENT_USER'
'\Software\Classes\\curseforge]\n"URL Protocol"="\\"\\""\n@="\\"URL:CurseBreaker Protocol\\"'
'"\n[HKEY_CURRENT_USER\Software\Classes\\curseforge\DefaultIcon]\n@="\\"CurseBreaker.exe,1\\'
'""\n[HKEY_CURRENT_USER\Software\Classes\\curseforge\shell]\n[HKEY_CURRENT_USER\Software\Cla'
'sses\\curseforge\shell\open]\n[HKEY_CURRENT_USER\Software\Classes\\curseforge\shell\open\co'
'mmand]\n@="\\"' + os.path.abspath(sys.executable).replace('\\', '\\\\') + '\\" \\"%1\\""')

@retry()
def parse_cf_id(self, url, bulk=False, reverse=False):
Expand Down Expand Up @@ -516,10 +523,13 @@ def parse_cf_id(self, url, bulk=False, reverse=False):
self.save_config()
return project

@retry(custom_error='Failed to parse the XML file.')
def parse_cf_xml(self, path):
xml = parse(path)
project = xml.childNodes[0].getElementsByTagName('project')[0].getAttribute('id')
@retry(custom_error='Failed to parse the URI.')
def parse_cf_payload(self, path, xml=True):
if xml:
xml = parse(path)
project = xml.childNodes[0].getElementsByTagName('project')[0].getAttribute('id')
else:
project = re.search(r'\d+', path).group()
payload = requests.get(f'https://addons-ecs.forgesvc.net/api/v2/addon/{project}', headers=HEADERS,
timeout=5).json()
url = payload['websiteUrl'].strip()
Expand Down
2 changes: 1 addition & 1 deletion CB/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import random
from rich.terminal_theme import TerminalTheme

__version__ = '3.14.2'
__version__ = '3.15.0'
__license__ = 'GPLv3'
__copyright__ = '2019-2020, Paweł Jastrzębski <[email protected]>'
__docformat__ = 'restructuredtext en'
Expand Down
6 changes: 3 additions & 3 deletions CurseBreaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def start(self):
pause(self.headless)
sys.exit(1)
self.setup_table()
# Curse URI Support
if len(sys.argv) == 2 and 'twitch://' in sys.argv[1]:
# CurseForge URI Support
if len(sys.argv) == 2 and any(x in sys.argv[1] for x in ['twitch://', 'curseforge://']):
try:
self.c_install(sys.argv[1].strip())
except Exception as e:
Expand All @@ -105,7 +105,7 @@ def start(self):
if len(sys.argv) == 2 and '.ccip' in sys.argv[1]:
try:
path = sys.argv[1].strip()
self.c_install(self.core.parse_cf_xml(path))
self.c_install(self.core.parse_cf_payload(path))
if os.path.exists(path):
os.remove(path)
except Exception as e:
Expand Down

0 comments on commit 4b481bf

Please sign in to comment.