# Path: scctool/settings/client_config.py
# class ClientConfig(object):
#     """Define PyUpdater data."""
# 
#     PUBLIC_KEY = 'AV48jKZoJOOiSR3sXdgDih6FECQOHJi5eDsWcs9psio'
#     APP_NAME = 'StarCraft-Casting-Tool'
#     COMPANY_NAME = 'team pheeniX'
#     HTTP_TIMEOUT = 30
#     MAX_DOWNLOAD_RETRIES = 3
#     UPDATE_URLS = ['https://github.com/teampheenix/SCCT-archive/raw/master/']
# 
# Path: scctool/tasks/tasksthread.py
# class TasksThread(QThread):
#     """Define generic thread for various tasks."""
# 
#     def __init__(self):
#         """Init thread."""
#         QThread.__init__(self)
# 
#         self.__tasks = {}
#         self.__run = {}
#         self.__methods = {}
#         self.__timeout = 1
#         self.__idx = 0
#         self.__wait_first = False
# 
#     def setWaitFirst(self, wait_first):
#         """Set the thread to wait first."""
#         self.__wait_first = bool(wait_first)
# 
#     def setTimeout(self, timeout):
#         """Set the timeout between tasks."""
#         self.__timeout = float(timeout)
# 
#     def addTask(self, task, method):
#         """Add a task."""
#         if(len(self.__tasks) > 5):
#             raise UserWarning("Only {} tasks allowed per thread.".format(6))
#         self.__tasks[task] = False
#         self.__methods[task] = method
# 
#     def hasActiveTask(self):
#         """Check if any task is active."""
#         return any(self.__tasks.values())
# 
#     def isActive(self, task):
#         """Check if a sepcific task is active."""
#         try:
#             return self.__tasks[task]
#         except Exception:
#             return False
# 
#     def activateTask(self, task):
#         """Activate a task."""
#         if not (task in self.__tasks):
#             raise UserWarning(
#                 "Task {} of {} is not valid.".format(
#                     task,
#                     self.__class__.__name__))
# 
#         self.__tasks[task] = True
# 
#         if not self.isRunning():
#             self.start()
# 
#     def terminate(self):
#         """Deactivate all tasks and terminate thread."""
#         for task in self.__tasks:
#             self.__tasks[task] = False
# 
#     def deactivateTask(self, task):
#         """Deactivate a Task."""
#         if not (task in self.__tasks):
#             raise UserWarning(
#                 "Task {} of {} is not valid.".format(
#                     task,
#                     self.__class__.__name__))
#         self.__tasks[task] = False
# 
#     def execTask(self, task):
#         """Execute task."""
#         self.__methods[task]()
# 
#     def execActiveTasks(self):
#         """Exectute all active tasks."""
#         executedTasks = []
#         continue_loop = True
# 
#         while continue_loop and self.hasActiveTask():
#             continue_loop = False
#             for task, active in self.__tasks.items():
#                 if active and task not in executedTasks:
#                     self.execTask(task)
#                     executedTasks.append(task)
#                     continue_loop = True
# 
#     def __wait(self):
#         if(not self.hasActiveTask()):
#             return
# 
#         cycletime = 0.1
#         cycles = int(self.__timeout / cycletime)
#         rest = max(self.__timeout - cycles * cycletime, 0.0)
# 
#         for __ in range(cycles):
#             time.sleep(cycletime)
#             if(not self.hasActiveTask()):
#                 return
#         time.sleep(rest)
# 
#     def run(self):
#         """Run the thread."""
#         module_logger.info(
#             "A {} is starting.".format(self.__class__.__name__))
# 
#         if self.__wait_first:
#             self.__wait()
# 
#         while self.hasActiveTask():
#             self.execActiveTasks()
#             self.__wait()
# 
#         module_logger.info("A {} is done.".format(self.__class__.__name__))


import json
import logging
import os
import sys
import tarfile
import zipfile
import scctool
import scctool.settings.translation
from PyQt5.QtCore import pyqtSignal
from pyupdater.client import Client
from scctool.settings.client_config import ClientConfig
from scctool.tasks.tasksthread import TasksThread
    """Extract data."""
    handler(10)
    if asset_update.is_downloaded():
        file = os.path.join(asset_update.update_folder,
                            asset_update.filename)
        targetdir = scctool.settings.profileManager.profiledir()
        with zipfile.ZipFile(file, "r") as myzip:
            myzip.extractall(targetdir)
        handler(50)
        file = os.path.join(targetdir,
                            'SCCT-data')
        with tarfile.open(file, "r:gz") as tar:
            tar.extractall(targetdir)
        handler(90)
        os.remove(file)
        handler(95)
        setDataVersion(asset_update.latest)
        handler(100)


class VersionHandler(TasksThread):
    """Check for new version and update or notify."""

    newVersion = pyqtSignal(str)
    newData = pyqtSignal(str)
    noNewVersion = pyqtSignal()
    progress = pyqtSignal(dict)
    updated_data = pyqtSignal(str)

    # Constants

# Path: scctool/settings/client_config.py
# class ClientConfig(object):
#     """Define PyUpdater data."""
# 
#     PUBLIC_KEY = 'AV48jKZoJOOiSR3sXdgDih6FECQOHJi5eDsWcs9psio'
#     APP_NAME = 'StarCraft-Casting-Tool'
#     COMPANY_NAME = 'team pheeniX'
#     HTTP_TIMEOUT = 30
#     MAX_DOWNLOAD_RETRIES = 3
#     UPDATE_URLS = ['https://github.com/teampheenix/SCCT-archive/raw/master/']
# 
# Path: scctool/tasks/tasksthread.py
# class TasksThread(QThread):
#     """Define generic thread for various tasks."""
# 
#     def __init__(self):
#         """Init thread."""
#         QThread.__init__(self)
# 
#         self.__tasks = {}
#         self.__run = {}
#         self.__methods = {}
#         self.__timeout = 1
#         self.__idx = 0
#         self.__wait_first = False
# 
#     def setWaitFirst(self, wait_first):
#         """Set the thread to wait first."""
#         self.__wait_first = bool(wait_first)
# 
#     def setTimeout(self, timeout):
#         """Set the timeout between tasks."""
#         self.__timeout = float(timeout)
# 
#     def addTask(self, task, method):
#         """Add a task."""
#         if(len(self.__tasks) > 5):
#             raise UserWarning("Only {} tasks allowed per thread.".format(6))
#         self.__tasks[task] = False
#         self.__methods[task] = method
# 
#     def hasActiveTask(self):
#         """Check if any task is active."""
#         return any(self.__tasks.values())
# 
#     def isActive(self, task):
#         """Check if a sepcific task is active."""
#         try:
#             return self.__tasks[task]
#         except Exception:
#             return False
# 
#     def activateTask(self, task):
#         """Activate a task."""
#         if not (task in self.__tasks):
#             raise UserWarning(
#                 "Task {} of {} is not valid.".format(
#                     task,
#                     self.__class__.__name__))
# 
#         self.__tasks[task] = True
# 
#         if not self.isRunning():
#             self.start()
# 
#     def terminate(self):
#         """Deactivate all tasks and terminate thread."""
#         for task in self.__tasks:
#             self.__tasks[task] = False
# 
#     def deactivateTask(self, task):
#         """Deactivate a Task."""
#         if not (task in self.__tasks):
#             raise UserWarning(
#                 "Task {} of {} is not valid.".format(
#                     task,
#                     self.__class__.__name__))
#         self.__tasks[task] = False
# 
#     def execTask(self, task):
#         """Execute task."""
#         self.__methods[task]()
# 
#     def execActiveTasks(self):
#         """Exectute all active tasks."""
#         executedTasks = []
#         continue_loop = True
# 
#         while continue_loop and self.hasActiveTask():
#             continue_loop = False
#             for task, active in self.__tasks.items():
#                 if active and task not in executedTasks:
#                     self.execTask(task)
#                     executedTasks.append(task)
#                     continue_loop = True
# 
#     def __wait(self):
#         if(not self.hasActiveTask()):
#             return
# 
#         cycletime = 0.1
#         cycles = int(self.__timeout / cycletime)
#         rest = max(self.__timeout - cycles * cycletime, 0.0)
# 
#         for __ in range(cycles):
#             time.sleep(cycletime)
#             if(not self.hasActiveTask()):
#                 return
#         time.sleep(rest)
# 
#     def run(self):
#         """Run the thread."""
#         module_logger.info(
#             "A {} is starting.".format(self.__class__.__name__))
# 
#         if self.__wait_first:
#             self.__wait()
# 
#         while self.hasActiveTask():
#             self.execActiveTasks()
#             self.__wait()
# 
#         module_logger.info("A {} is done.".format(self.__class__.__name__))


# Path: scctool/tasks/updater.py
import json
import logging
import os
import sys
import tarfile
import zipfile
import scctool
import scctool.settings.translation
from PyQt5.QtCore import pyqtSignal
from pyupdater.client import Client
from scctool.settings.client_config import ClientConfig
from scctool.tasks.tasksthread import TasksThread

    """Extract data."""
    handler(10)
    if asset_update.is_downloaded():
        file = os.path.join(asset_update.update_folder,
                            asset_update.filename)
        targetdir = scctool.settings.profileManager.profiledir()
        with zipfile.ZipFile(file, "r") as myzip:
            myzip.extractall(targetdir)
        handler(50)
        file = os.path.join(targetdir,
                            'SCCT-data')
        with tarfile.open(file, "r:gz") as tar:
            tar.extractall(targetdir)
        handler(90)
        os.remove(file)
        handler(95)
        setDataVersion(asset_update.latest)
        handler(100)


class VersionHandler(TasksThread):
    """Check for new version and update or notify."""

    newVersion = pyqtSignal(str)
    newData = pyqtSignal(str)
    noNewVersion = pyqtSignal()
    progress = pyqtSignal(dict)
    updated_data = pyqtSignal(str)

    # Constants

    APP_NAME = ClientConfig.APP_NAME