# Path: resources/lib/jsonrpc.py
# class JsonRpc(object):
# 
#     id_ = 1
#     jsonrpc = "2.0"
#     params = None
# 
#     def __init__(self, method, **kwargs):
#         
#         self.method = method
# 
#         for arg in kwargs:  # id_(int), jsonrpc(str)
#             self.arg = arg
# 
#     def _query(self):
# 
#         query = {
#             
#             'jsonrpc': self.jsonrpc,
#             'id': self.id_,
#             'method': self.method,
#         }
#         if self.params is not None:
#             query['params'] = self.params
# 
#         return json.dumps(query)
# 
#     def execute(self, params=None):
# 
#         self.params = params
#         return json.loads(xbmc.executeJSONRPC(self._query()))
# 
# def get_value(name):
#     result = JsonRpc('Settings.getSettingValue').execute({'setting': name})
#     return result['result']['value']
# 
# def set_value(name, value):
#     params = {
#         'setting': name,
#         'value': value
#     }
#     result = JsonRpc('Settings.setSettingValue').execute(params)
#     return result
# 
# Path: resources/lib/simple_logging.py
# class SimpleLogging:
#     name = ""
#     enable_logging = False
# 
#     def __init__(self, name):
#         settings = xbmcaddon.Addon()
#         prefix = settings.getAddonInfo('name')
#         self.name = prefix + '.' + name
#         self.enable_logging = settings.getSetting('log_debug') == "true"
# 
#         # params = {"setting": "debug.showloginfo"}
#         # setting_result = json_rpc('Settings.getSettingValue').execute(params)
#         # current_value = setting_result.get("result", None)
#         # if current_value is not None:
#         #     self.enable_logging = current_value.get("value", False)
#         # xbmc.log("LOGGING_ENABLED %s : %s" % (self.name, str(self.enable_logging)), level=xbmc.LOGDEBUG)
# 
#     def __str__(self):
#         return "LoggingEnabled: " + str(self.enable_logging)
# 
#     def info(self, fmt, *args, **kwargs):
#         log_line = self.name + "|INFO|" + self.log_line(fmt, *args)
#         xbmc.log(log_line, level=xbmc.LOGNOTICE)
# 
#     def error(self, fmt, *args, **kwargs):
#         log_line = self.name + "|ERROR|" + self.log_line(fmt, *args)
#         xbmc.log(log_line, level=xbmc.LOGERROR)
# 
#     def debug(self, fmt, *args, **kwargs):
#         if self.enable_logging:
#             log_line = self.name + "|DEBUG|" + self.log_line(fmt, *args)
#             xbmc.log(log_line, level=xbmc.LOGNOTICE)
# 
#     @staticmethod
#     def log_line(fmt, *args):
#         new_args = []
#         # convert any unicode to utf-8 strings
#         for arg in args:
#             if isinstance(arg, unicode):
#                 new_args.append(arg.encode("utf-8"))
#             else:
#                 new_args.append(arg)
#         log_line = fmt.format(*new_args)
#         return log_line


import os
import xbmc
import xbmcgui
import xbmcvfs
from .jsonrpc import JsonRpc, get_value, set_value
from .simple_logging import SimpleLogging

    installed = result.get("result") is not None
    version = 'na'
    if installed:
        version = result.get("result").get("addon").get("version")

    if not installed:
        clone_default_skin()


def clone_default_skin():
    xbmc.executebuiltin("Dialog.Close(all,true)")
    xbmc.executebuiltin("ActivateWindow(Home)")

    response = xbmcgui.Dialog().yesno("EmbyCon, Clone Estuary Skin?",
                                      "This will clone the default Estuary Kodi skin and add EmbyCon functionality to it.",
                                      "Once cloned you can switch between skins in the Kodi interface settings.",
                                      "Do you want to continue?")
    if not response:
        return

    clone_skin()
    set_skin_settings()
    update_kodi_settings()

    # xbmc.executebuiltin("ReloadSkin()")
    # xbmc.executebuiltin("ActivateWindow(Home)")


def walk_path(root_path, relative_path, all_files):

# Path: resources/lib/jsonrpc.py
# class JsonRpc(object):
# 
#     id_ = 1
#     jsonrpc = "2.0"
#     params = None
# 
#     def __init__(self, method, **kwargs):
#         
#         self.method = method
# 
#         for arg in kwargs:  # id_(int), jsonrpc(str)
#             self.arg = arg
# 
#     def _query(self):
# 
#         query = {
#             
#             'jsonrpc': self.jsonrpc,
#             'id': self.id_,
#             'method': self.method,
#         }
#         if self.params is not None:
#             query['params'] = self.params
# 
#         return json.dumps(query)
# 
#     def execute(self, params=None):
# 
#         self.params = params
#         return json.loads(xbmc.executeJSONRPC(self._query()))
# 
# def get_value(name):
#     result = JsonRpc('Settings.getSettingValue').execute({'setting': name})
#     return result['result']['value']
# 
# def set_value(name, value):
#     params = {
#         'setting': name,
#         'value': value
#     }
#     result = JsonRpc('Settings.setSettingValue').execute(params)
#     return result
# 
# Path: resources/lib/simple_logging.py
# class SimpleLogging:
#     name = ""
#     enable_logging = False
# 
#     def __init__(self, name):
#         settings = xbmcaddon.Addon()
#         prefix = settings.getAddonInfo('name')
#         self.name = prefix + '.' + name
#         self.enable_logging = settings.getSetting('log_debug') == "true"
# 
#         # params = {"setting": "debug.showloginfo"}
#         # setting_result = json_rpc('Settings.getSettingValue').execute(params)
#         # current_value = setting_result.get("result", None)
#         # if current_value is not None:
#         #     self.enable_logging = current_value.get("value", False)
#         # xbmc.log("LOGGING_ENABLED %s : %s" % (self.name, str(self.enable_logging)), level=xbmc.LOGDEBUG)
# 
#     def __str__(self):
#         return "LoggingEnabled: " + str(self.enable_logging)
# 
#     def info(self, fmt, *args, **kwargs):
#         log_line = self.name + "|INFO|" + self.log_line(fmt, *args)
#         xbmc.log(log_line, level=xbmc.LOGNOTICE)
# 
#     def error(self, fmt, *args, **kwargs):
#         log_line = self.name + "|ERROR|" + self.log_line(fmt, *args)
#         xbmc.log(log_line, level=xbmc.LOGERROR)
# 
#     def debug(self, fmt, *args, **kwargs):
#         if self.enable_logging:
#             log_line = self.name + "|DEBUG|" + self.log_line(fmt, *args)
#             xbmc.log(log_line, level=xbmc.LOGNOTICE)
# 
#     @staticmethod
#     def log_line(fmt, *args):
#         new_args = []
#         # convert any unicode to utf-8 strings
#         for arg in args:
#             if isinstance(arg, unicode):
#                 new_args.append(arg.encode("utf-8"))
#             else:
#                 new_args.append(arg)
#         log_line = fmt.format(*new_args)
#         return log_line


# Path: resources/lib/skin_cloner.py
import os
import xbmc
import xbmcgui
import xbmcvfs
from .jsonrpc import JsonRpc, get_value, set_value
from .simple_logging import SimpleLogging


    installed = result.get("result") is not None
    version = 'na'
    if installed:
        version = result.get("result").get("addon").get("version")

    if not installed:
        clone_default_skin()


def clone_default_skin():
    xbmc.executebuiltin("Dialog.Close(all,true)")
    xbmc.executebuiltin("ActivateWindow(Home)")

    response = xbmcgui.Dialog().yesno("EmbyCon, Clone Estuary Skin?",
                                      "This will clone the default Estuary Kodi skin and add EmbyCon functionality to it.",
                                      "Once cloned you can switch between skins in the Kodi interface settings.",
                                      "Do you want to continue?")
    if not response:
        return

    clone_skin()
    set_skin_settings()
    update_kodi_settings()

    # xbmc.executebuiltin("ReloadSkin()")
    # xbmc.executebuiltin("ActivateWindow(Home)")


def walk_path(root_path, relative_path, all_files):

    files = xbmcvfs.listdir(root_path)