Also fix settings not saving if reset was initiated.
This commit is contained in:
angelblue05 2015-07-22 08:16:08 -05:00
parent 85f8de7e68
commit 2bfe377378
7 changed files with 414 additions and 540 deletions

View file

@ -1,27 +1,27 @@
import xbmc
import xbmcaddon
import xbmcgui
# -*- coding: utf-8 -*-
import os
from uuid import uuid4 as uuid4
from Lock import Lock
import xbmc
import xbmcaddon
import xbmcgui
import Utils as utils
class ClientInformation():
def __init__(self):
addonId = self.getAddonId()
self.addon = xbmcaddon.Addon(id=addonId)
self.className = self.__class__.__name__
self.addon = xbmcaddon.Addon()
self.addonName = self.getAddonName()
def logMsg(self, msg, lvl=1):
utils.logMsg("%s %s" % (self.addonName, self.className), str(msg), int(lvl))
className = self.__class__.__name__
utils.logMsg("%s %s" % (self.addonName, className), msg, int(lvl))
def getAddonId(self):
# To use when declaring xbmcaddon.Addon(id=addonId)
@ -37,9 +37,15 @@ class ClientInformation():
def getDeviceName(self):
deviceName = self.addon.getSetting('deviceName')
deviceName = deviceName.replace("\"", "_")
deviceName = deviceName.replace("/", "_")
addon = self.addon
if addon.getSetting('deviceNameOpt') == "false":
# Use Kodi's deviceName
deviceName = xbmc.getInfoLabel('System.FriendlyName')
else:
deviceName = addon.getSetting('deviceName')
deviceName = deviceName.replace("\"", "_")
deviceName = deviceName.replace("/", "_")
return deviceName
@ -48,26 +54,26 @@ class ClientInformation():
WINDOW = xbmcgui.Window(10000)
clientId = WINDOW.getProperty("client_id")
if (clientId != None and clientId != ""):
if clientId:
return clientId
# we need to load and or generate a client machine id
__addon__ = self.addon
__addondir__ = xbmc.translatePath( __addon__.getAddonInfo('path'))
machine_guid_lock_path = os.path.join(__addondir__, "machine_guid.lock")
machine_guid_path = os.path.join(__addondir__, "machine_guid")
addon = self.addon
addondir = addon.getAddonInfo('path').decode('utf-8')
machine_guid_lock_path = xbmc.translatePath(os.path.join(addondir, "machine_guid.lock")).decode('utf-8')
machine_guid_path = xbmc.translatePath(os.path.join(addondir, "machine_guid")).decode('utf-8')
clientId = ""
try:
lock = Lock(machine_guid_lock_path)
locked = lock.acquire()
if (locked == True):
if locked:
fd = os.open(machine_guid_path, os.O_CREAT|os.O_RDWR)
clientId = os.read(fd, 256)
if (len(clientId) == 0):
if len(clientId) == 0:
uuid = uuid4()
clientId = str("%012X" % uuid)
self.logMsg("ClientId saved to FILE: %s" % clientId, 2)
@ -77,8 +83,7 @@ class ClientInformation():
os.close(fd)
self.logMsg("ClientId saved to WINDOW: %s" % clientId, 1)
WINDOW.setProperty("client_id", clientId)
WINDOW.setProperty("client_id", clientId)
finally:
lock.release()
@ -99,4 +104,4 @@ class ClientInformation():
elif xbmc.getCondVisibility('system.platform.android'):
return "Linux/Android"
return "Unknown"
return "Unknown"