From 778d0788a4895609dddc238594ef8f955eec303f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?= <pawelj@iosphe.re>
Date: Wed, 25 Sep 2019 10:22:25 +0200
Subject: [PATCH] Fixed issues with Tukui GitLab support (close #17)

---
 CB/Core.py     | 4 +++-
 CB/GitLab.py   | 3 +++
 CB/WeakAura.py | 2 +-
 CB/__init__.py | 2 +-
 4 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/CB/Core.py b/CB/Core.py
index 2f6fd25..282952c 100644
--- a/CB/Core.py
+++ b/CB/Core.py
@@ -127,8 +127,10 @@ def parse_url(self, url):
                 raise RuntimeError('Incorrect client version.')
             return TukuiAddon(url, False)
         elif url.startswith('https://www.tukui.org/classic-addons.php?id='):
-            if self.clientType == 'wow_retail' or url.endswith('1') or url.endswith('2'):
+            if self.clientType == 'wow_retail':
                 raise RuntimeError('Incorrect client version.')
+            elif url.endswith('1') or url.endswith('2'):
+                raise RuntimeError('ElvUI and Tukui cannot be installed this way.')
             return TukuiAddon(url, True)
         elif url.lower() == 'elvui':
             if self.clientType == 'wow_retail':
diff --git a/CB/GitLab.py b/CB/GitLab.py
index 3ebb5dd..3701b7c 100644
--- a/CB/GitLab.py
+++ b/CB/GitLab.py
@@ -27,11 +27,14 @@ def get_addon(self):
             file_info = self.archive.getinfo(file)
             if file_info.is_dir() and file_info.filename.count('/') == 2 and '.gitlab' not in file_info.filename:
                 self.directories.append(file_info.filename.split('/')[1])
+        if len(self.directories) == 0 or self.directories == ['']:
+            raise RuntimeError
 
     def install(self, path):
         self.get_addon()
         self.archive.extractall(path)
         for directory in self.directories:
+            shutil.rmtree(path / directory, ignore_errors=True)
             # FIXME - Python bug #32689
             shutil.move(str(path / f'{self.shorthPath}-{self.branch}' / directory), str(path))
         shutil.rmtree(path / f'{self.shorthPath}-{self.branch}')
diff --git a/CB/WeakAura.py b/CB/WeakAura.py
index d0a2764..4e70a42 100644
--- a/CB/WeakAura.py
+++ b/CB/WeakAura.py
@@ -109,7 +109,7 @@ def install_companion(self, client_type, force):
         if not os.path.isdir(Path('Interface\AddOns\WeakAurasCompanion')) or force:
             Path('Interface\AddOns\WeakAurasCompanion').mkdir(exist_ok=True)
             with open(Path('Interface\AddOns\WeakAurasCompanion\WeakAurasCompanion.toc'), 'w', newline='\n') as out:
-                out.write(f'## Interface: {"11302" if client_type == "wow_classic" else "80200"}\n## Title: WeakAu'
+                out.write(f'## Interface: {"11302" if client_type == "wow_classic" else "80205"}\n## Title: WeakAu'
                           f'ras Companion\n## Author: The WeakAuras Team\n## Version: 1.0.0\n## Notes: Keep your WeakAu'
                           f'ras updated!\n## X-Category: Interface Enhancements\n## DefaultState: Enabled\n## LoadOnDem'
                           f'and: 0\n## Dependencies: WeakAuras\n\ndata.lua\ninit.lua')
diff --git a/CB/__init__.py b/CB/__init__.py
index cedf798..3c9cda3 100644
--- a/CB/__init__.py
+++ b/CB/__init__.py
@@ -1,7 +1,7 @@
 import string
 import random
 
-__version__ = '2.6.0'
+__version__ = '2.6.1'
 __license__ = 'GPLv3'
 __copyright__ = '2019, Paweł Jastrzębski <pawelj@iosphe.re>'
 __docformat__ = 'restructuredtext en'