Example #1
0
 def save_current_file( self ):
     if not self.changed:
         # nothing to do
         xbmcgui.Dialog().ok( self.file.name, common.localize( 1007 ) )
         return
     try:
         writeable_file = open( self.file.name, 'wb' )
     except IOError:
         xbmcgui.Dialog().ok( 
             self.file.name, common.localize( 1008 ) # Access denied
         )
         return
     for i in range( self.window.getListSize() ):
         text = self.window.getListItem( i ).getLabel()
         if i:
             writeable_file.write( self.eol + text )
             writeable_file.flush()
         else:
             writeable_file.write( text )
             writeable_file.flush()
             try:
                 writeable_file = open( self.file.name, 'ab' )
             except IOError:
                 xbmcgui.Dialog().ok( self.file.name, 
                     os.linesep.join(
                         common.localize( 1008 ), # Access denied
                         common.localize( 1009 )
                     )
                 )
                 return
     writeable_file.close()
     xbmcgui.Dialog().ok( self.file.name, common.localize( 1010 ) )
     self.changed = False
     # update status area
     self.update_controls()
Example #2
0
 def insert():
     global new_id
     new_id = -1
     def before():
         global new_id
         if id < 0:
             # trying to insert to an empty file
             new_id = 0
         else:
             new_id = id
     def after():
         global new_id
         if id < 0:
             # trying to insert to an empty file
             new_id = 0
         else:
             new_id = id + 1
     # menu items
     items = dict()
     items[len(items.keys())+1] = {
         'label': common.localize( 504 ), # Insert before..
         'thumb': 'script-line-inserted-before.png',
         'onClick': before,
     }
     items[len(items.keys())+1] = {
         'label': common.localize( 505 ), # Insert after..
         'thumb': 'script-line-inserted-after.png',
         'onClick': after,
     }
     # show the menu
     menu = common.gui.dialog.popupmenu( items )
     if new_id < 0:
         return
     # insert the new item
     item = xbmcgui.ListItem( '', str( new_id + 1 ) )
     self.window.addItem( item, new_id )
     self.changed = True
     # reorganize line numbers
     renumber_lines( new_id )
     # select the new inserted line
     self.window.setCurrentListPosition( new_id )
     # make sure we've got the handle to the proper 
     #   ListItem still
     item = self.window.getListItem( new_id )
     new_text = None
     # show keyboard for user to change the text
     new_text = common.gui.dialog.getText( 
         common.localize( 1004 )
     )
     if len( new_text ):
         item.setLabel( new_text )
Example #3
0
    def __put_dep__(self, mod, importer):
        """
        Add a dependency to the dep file.

        **Positional Arguments:**

        mod:
            - is the file that is being imported/included
        importer:
            - the file that includes/imports `mod`
        """
        mod = localize(self.projecthome, mod)
        importer = localize(self.projecthome, importer)

        if self.__map__.has_key(mod):
            self.__map__[mod].append(importer)
        else:
            self.__map__[mod] = [importer]
Example #4
0
    def installHivemind(self,isFresh):
        message = ''
        if(isFresh):
            ret = dialog_yesno(localize(33000),localize(33001))
            log("Dialog YesNo -> {0}".format(ret))
            if(ret):
                waitDialog = WaitDialogHelper().create()
                try:
                    scriptPath = os.path.join(__addonpath__,'resources','lib','launchsetup.vbs')
                    log(('HiveMind setup launcher path = %s') % scriptPath)
                    si = subprocess.STARTUPINFO()
                    si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
                    exitCode = subprocess.call(["cscript.exe", scriptPath, self.setupPath], startupinfo=si)
                    log('HiveMind setup exit code = ' + str(tohex(exitCode, 32)))

                    if (exitCode == 0):
                        if(dialog_yesno(localize(33005),localize(33006))):
                            xbmc.executebuiltin('Skin.SetBool(IsCoreComponentInstalled)')

                            si = subprocess.STARTUPINFO()
                            si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
                            subprocess.call(["shutdown.exe", "/r", "/t", "0" ,"/f"], startupinfo=si)
                    else:
                        dialog_ok(localize(33003),localize(33004) + str(tohex(exitCode, 32)))
                except:
                    pass
                waitDialog.close()
        else:
            waitDialog = WaitDialogHelper().create()
            #try:
            import AlphaUIUtils
            setupPath = os.path.join(__addonpath__,'resources','lib')
            log(('HiveMind setup path = %s') % setupPath)

            retValue = AlphaUIUtils.LaunchHivemindSetup(setupPath)
            log('HiveMind setup return code = ' + str(retValue))

            if (retValue):
                if(dialog_yesno(localize(33005),localize(33006))):
                    si = subprocess.STARTUPINFO()
                    si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
                    subprocess.call(["shutdown.exe", "/r", "/t", "0" ,"/f"], startupinfo=si)
            else:
                dialog_ok(localize(33003))
            #except:
                # dialog_ok(localize(33003))
            waitDialog.close()        
Example #5
0
 def edit():
     new_text = None
     # show keyboard for user to change the text
     new_text = common.gui.dialog.getText( 
         common.localize( 1004 ),
         original_text, 
     )
     # perform the changes, assuming that the new text is not blank
     #   or the same as the old text
     if len( new_text ) and ( new_text != original_text ):
         item.setLabel( new_text )
         self.changed = True
Example #6
0
 def close( self ):
     # self.changed will be True if the last opened file was edited
     # TODO: ask to save changes to last opened file
     if self.changed:
         savefirst = xbmcgui.Dialog().yesno( 
             self.file.name, 
             common.localize( 1005 ) 
         )
         if savefirst:
             self.save_current_file()
     # close the file
     if self.file:
         self.file.close()
     # close the window
     common.gui.BaseScriptWindow.close( self )
Example #7
0
    def track_datafile(self, path):
        """
        Add a path stub to the `data_dep` `read` and `write` sections.

        **Positional Arguments:**

        path:
            - The path to a data file that will be written by blci.
        """

        path = localize(self.projecthome, path)
        self.__check_and_stub_dat_dep__()

        for ioattr in self.get(BL_DATA_DEP):
            if path not in self.get(BL_DATA_DEP)[ioattr].keys():
                # Add it to read or write
                print "Adding '{}' to {}: {} ...".format(
                    path, BL_DATA_DEP, ioattr)
                self._conf[BL_DATA_DEP][ioattr][path] = []
Example #8
0
 def update_controls( self ):
     try:
         if self.file:
             self.window.getControl( 50 ).setEnabled( True )
             self.window.getControl( 151 ).setLabel( os.path.split( self.file.name )[-1] )
             self.window.getControl( 152 ).setVisible( True ) # read access
             self.window.getControl( 153 ).setVisible( self.check_access( self.file.name ) ) # write access
             self.window.getControl( 154 ).setVisible( True ) # EOL type
             if self.eol == '\r\n':
                 eol_type = common.localize( 1541 )
             elif self.eol == '\n':
                 eol_type = common.localize( 1542 )
             elif self.eol == '\r':
                 eol_type = common.localize( 1543 )
             else:
                 eol_type = common.localize( 1544 )
             self.window.getControl( 154 ).setLabel( eol_type ) # EOL type
             self.window.getControl( 155 ).setVisible( True )
             self.window.getControl( 155 ).setLabel( ' '.join( (
                 str( len( range( self.window.getListSize() ) ) ),
                 common.localize( 155 )
             ) ) )
         else:
             self.window.getControl( 50 ).setEnabled( False )
             self.window.getControl( 151 ).setLabel( common.localize( 151 ) )
             self.window.getControl( 152 ).setVisible( False ) # read access
             self.window.getControl( 153 ).setVisible( False ) # write access
             self.window.getControl( 154 ).setVisible( False ) # EOL type
             self.window.getControl( 155 ).setVisible( False )
         if self.changed:
             self.window.getControl( 102 ).setEnabled( True )
         else:
             self.window.getControl( 102 ).setEnabled( False )
     except TypeError:
         # a control is not supported in the skin
         pass
     except:
         import traceback
         traceback.print_exc()
Example #9
0
    def findGames(self, orgGames, games):
        xbmc.executebuiltin("Dialog.Close(busydialog)")
        isCanceled = False
        try:
            steamPath = self.getSteamPath()
            if (steamPath):
                steamAppPath = os.path.join(os.path.abspath(steamPath),'steamapps')

                files = glob('{0}/*.acf'.format(steamAppPath))
                numFiles = len(files)
                if (numFiles > 0):
                    counter = 0

                    pDialog = xbmcgui.DialogProgress()
                    pDialog.create(__addonname__, localize(33003))
                    pDialog.update(0, localize(33003))

                    for filePath in glob('{0}/*.acf'.format(steamAppPath)):
                        log('findGames()::filepath -> %s' % filePath)
                        #try:
                        gameDict = parse_acf(filePath)

                        if (gameDict['appstate']['bytestodownload'] != '0' and gameDict['appstate']['bytestodownload'] == gameDict['appstate']['bytesdownloaded']):

                            orgGame = None
                            gameId = gameDict['appstate']['appid']
                            for game in orgGames:
                                if (game.gameId == gameId):
                                    orgGame = game
                                    break;

                            name = gameDict['appstate']['name']
                            path = ''
                            isNameChanged = 0
                            isPathChanged = 0
                            isIconChanged = 0
                            isFanartChanged = 0
                            thumbImage = ''
                            fanartImage = ''
                            type = 1

                            if ((not orgGame) or (orgGame is not None and orgGame.isFanartChanged == 0 and orgGame.isIconChanged == 0)):
                                gameFiles = self.downloadGameImage(gameId,gameDict['appstate']['name'])
                                thumbImage = gameFiles[0]
                                fanartImage = gameFiles[1]
                            elif (orgGame is not None and orgGame.isFanartChanged == 0):
                                gameFiles = self.downloadGameImage(gameId,gameDict['appstate']['name'])
                                thumbImage = orgGame.thumbImage
                                fanartImage = gameFiles[1]
                                isIconChanged = 1
                            elif (orgGame is not None and orgGame.isIconChanged == 0):
                                gameFiles = self.downloadGameImage(gameId,gameDict['appstate']['name'])
                                thumbImage = gameFiles[0]
                                fanartImage = orgGame.fanartImage
                                isFanartChanged = 1
                            else:
                                thumbImage = orgGame.thumbImage
                                fanartImage = orgGame.fanartImage
                                isIconChanged = 1
                                isFanartChanged = 1

                            if (orgGame is not None and orgGame.isNameChanged == 1):
                                name = orgGame.title
                                isNameChanged = 1

                            if (orgGame is not None and orgGame.isPathChanged == 1):
                                name = orgGame.path
                                isPathChanged = 1

                            games[gameId] = {}
                            games[gameId]['name'] = name
                            games[gameId]['path'] = path
                            games[gameId]['isNameChanged'] = isNameChanged
                            games[gameId]['isPathChanged'] = isPathChanged
                            games[gameId]['isIconChanged'] = isIconChanged
                            games[gameId]['isFanartChanged'] = isFanartChanged
                            games[gameId]['type'] = type
                            games[gameId]['thumbImage'] = thumbImage
                            games[gameId]['fanartImage'] = fanartImage

                            counter = counter + 1
                        #except:
                            #log('unable to parse the file %s' % filePath)

                        if (pDialog.iscanceled()):
                            isCanceled = True
                            break;

                        pDialog.update(int((float(counter)/float(numFiles))*100), localize(33003))

                    pDialog.close()
        except Exception,e:
            log(e.message)
            log(e.__class__.__name__)
            traceback.print_exc(e)
Example #10
0
    def findGames(self, orgGames, games):
        xbmc.executebuiltin("Dialog.Close(busydialog)")
        isCanceled = False
        try:
            battleGames = self.parseConfigurationFile()
            numFiles = len(battleGames)
            if (numFiles > 0):
                counter = 0

                pDialog = xbmcgui.DialogProgress()
                pDialog.create(__addonname__, localize(33003))
                pDialog.update(0, localize(33003))

                for battleGame in battleGames:
                    orgGame = None
                    gameId = battleGame.gameId
                    for game in orgGames:
                        if (game.gameId == gameId):
                            orgGame = game
                            break;

                    name = battleGame.name
                    path = battleGame.exePath
                    isNameChanged = 0
                    isPathChanged = 0
                    isIconChanged = 0
                    isFanartChanged = 0
                    thumbImage = ''
                    fanartImage = ''
                    type = 5

                    if ((not orgGame) or (orgGame is not None and orgGame.isFanartChanged == 0 and orgGame.isIconChanged == 0)):
                        gameFiles = self.downloadGameImage(gameId,name,path)
                        thumbImage = gameFiles[0]
                        fanartImage = gameFiles[1]
                    elif (orgGame is not None and orgGame.isFanartChanged == 0):
                        gameFiles = self.downloadGameImage(gameId,name,path)
                        thumbImage = orgGame.thumbImage
                        fanartImage = gameFiles[1]
                        isIconChanged = 1
                    elif (orgGame is not None and orgGame.isIconChanged == 0):
                        gameFiles = self.downloadGameImage(gameId,name,path)
                        thumbImage = gameFiles[0]
                        fanartImage = orgGame.fanartImage
                        isFanartChanged = 1
                    else:
                        thumbImage = orgGame.thumbImage
                        fanartImage = orgGame.fanartImage
                        isIconChanged = 1
                        isFanartChanged = 1

                    if (orgGame is not None and orgGame.isNameChanged == 1):
                        name = orgGame.title
                        isNameChanged = 1

                    if (orgGame is not None and orgGame.isPathChanged == 1):
                        name = orgGame.path
                        isPathChanged = 1

                    games[gameId] = {}
                    games[gameId]['name'] = name
                    games[gameId]['path'] = path
                    games[gameId]['isNameChanged'] = isNameChanged
                    games[gameId]['isPathChanged'] = isPathChanged
                    games[gameId]['isIconChanged'] = isIconChanged
                    games[gameId]['isFanartChanged'] = isFanartChanged
                    games[gameId]['type'] = type
                    games[gameId]['thumbImage'] = thumbImage
                    games[gameId]['fanartImage'] = fanartImage

                    counter = counter + 1

                    if (pDialog.iscanceled()):
                        isCanceled = True
                        break;

                    pDialog.update(int((float(counter)/float(numFiles))*100), localize(33003))

                pDialog.close()
        except Exception,e:
            #log(e.message)
            #log(e.__class__.__name__)
            traceback.print_exc(e)
Example #11
0
    def findGames(self, orgGames, games):
        xbmc.executebuiltin("Dialog.Close(busydialog)")
        isCanceled = False
        try:
            gameData = self.getMfstFiles()
            numFiles = len(gameData)
            if (numFiles > 0):
                counter = 0

                pDialog = xbmcgui.DialogProgress()
                pDialog.create(__addonname__, localize(33003))
                pDialog.update(0, localize(33003))

                for game in gameData:     
                    
                    try:           
                        installPath = self.getGameInstallPath(game)
                        #log("installPath = " + installPath)
                        fileName = self.extractDLL(installPath)                
                        xmlPath = os.path.join(TEMP_DIR,'Data_1.bin')
                        name, id, path = self.parseXML(xmlPath, installPath, fileName)

                        gameId = 'OR-%s' % id

                        orgGame = None

                        for game in orgGames:
                            if (game.gameId == gameId):
                                orgGame = game
                                break;

                        isNameChanged = 0
                        isPathChanged = 0
                        isIconChanged = 0
                        isFanartChanged = 0
                        thumbImage = ''
                        fanartImage = ''
                        type = 2

                        #log(path)
                        if ((not orgGame) or (orgGame is not None and orgGame.isFanartChanged == 0 and orgGame.isIconChanged == 0)):
                            gameFiles = self.downloadGameImage(gameId,name,path)
                            thumbImage = gameFiles[0]
                            fanartImage = gameFiles[1]
                        elif (orgGame is not None and orgGame.isFanartChanged == 0):
                            gameFiles = self.downloadGameImage(gameId,name,path)
                            thumbImage = orgGame.thumbImage
                            fanartImage = gameFiles[1]
                            isIconChanged = 1
                        elif (orgGame is not None and orgGame.isIconChanged == 0):
                            gameFiles = self.downloadGameImage(gameId,name,path)
                            thumbImage = gameFiles[0]
                            fanartImage = orgGame.fanartImage
                            isFanartChanged = 1
                        else:
                            thumbImage = orgGame.thumbImage
                            fanartImage = orgGame.fanartImage
                            isIconChanged = 1
                            isFanartChanged = 1

                        if (orgGame is not None and orgGame.isNameChanged == 1):
                            name = orgGame.title
                            isNameChanged = 1

                        if (orgGame is not None and orgGame.isPathChanged == 1):
                            name = orgGame.path
                            isPathChanged = 1

                        games[gameId] = {}
                        games[gameId]['name'] = name
                        games[gameId]['path'] = path
                        games[gameId]['isNameChanged'] = isNameChanged
                        games[gameId]['isPathChanged'] = isPathChanged
                        games[gameId]['isIconChanged'] = isIconChanged
                        games[gameId]['isFanartChanged'] = isFanartChanged
                        games[gameId]['type'] = type
                        games[gameId]['thumbImage'] = thumbImage
                        games[gameId]['fanartImage'] = fanartImage

                        counter = counter + 1

                        if (pDialog.iscanceled()):
                            isCanceled = True
                            break;

                        pDialog.update(int((float(counter)/float(numFiles))*100), localize(33003))


                    except:
                        log("error occured")

                pDialog.close()
        except Exception,e:
            #log(e.message)
            #log(e.__class__.__name__)
            traceback.print_exc(e)
Example #12
0
    def findGames(self, orgGames, games):
        xbmc.executebuiltin("Dialog.Close(busydialog)")
        isCanceled = False
        try:
            steamPath = self.getSteamPath()
            if (steamPath):
                steamAppPath = os.path.join(os.path.abspath(steamPath),'steamapps')

                files = glob('{0}/*.acf'.format(steamAppPath))
                numFiles = len(files)
                if (numFiles > 0):
                    counter = 0

                    pDialog = xbmcgui.DialogProgress()
                    pDialog.create(__addonname__, localize(33003))
                    pDialog.update(0, localize(33003))

                    for filePath in glob('{0}/*.acf'.format(steamAppPath)):
                        log('findGames()::filepath -> %s' % filePath)
                        #try:
                        gameDict = parse_acf(filePath)

                        if (gameDict['appstate']['bytestodownload'] != '0' and gameDict['appstate']['bytestodownload'] == gameDict['appstate']['bytesdownloaded']):

                            orgGame = None
                            gameId = gameDict['appstate']['appid']
                            for game in orgGames:
                                if (game.gameId == gameId):
                                    orgGame = game
                                    break;

                            name = gameDict['appstate']['name']
                            path = ''
                            isNameChanged = 0
                            isPathChanged = 0
                            isIconChanged = 0
                            isFanartChanged = 0
                            thumbImage = ''
                            fanartImage = ''
                            type = 1

                            if ((not orgGame) or (orgGame is not None and orgGame.isFanartChanged == 0 and orgGame.isIconChanged == 0)):
                                gameFiles = self.downloadGameImage(gameId,gameDict['appstate']['name'])
                                thumbImage = gameFiles[0]
                                fanartImage = gameFiles[1]
                            elif (orgGame is not None and orgGame.isFanartChanged == 0):
                                gameFiles = self.downloadGameImage(gameId,gameDict['appstate']['name'])
                                thumbImage = orgGame.thumbImage
                                fanartImage = gameFiles[1]
                                isIconChanged = 1
                            elif (orgGame is not None and orgGame.isIconChanged == 0):
                                gameFiles = self.downloadGameImage(gameId,gameDict['appstate']['name'])
                                thumbImage = gameFiles[0]
                                fanartImage = orgGame.fanartImage
                                isFanartChanged = 1
                            else:
                                thumbImage = orgGame.thumbImage
                                fanartImage = orgGame.fanartImage
                                isIconChanged = 1
                                isFanartChanged = 1

                            if (orgGame is not None and orgGame.isNameChanged == 1):
                                name = orgGame.title
                                isNameChanged = 1

                            if (orgGame is not None and orgGame.isPathChanged == 1):
                                name = orgGame.path
                                isPathChanged = 1

                            games[gameId] = {}
                            games[gameId]['name'] = name
                            games[gameId]['path'] = path
                            games[gameId]['isNameChanged'] = isNameChanged
                            games[gameId]['isPathChanged'] = isPathChanged
                            games[gameId]['isIconChanged'] = isIconChanged
                            games[gameId]['isFanartChanged'] = isFanartChanged
                            games[gameId]['type'] = type
                            games[gameId]['thumbImage'] = thumbImage
                            games[gameId]['fanartImage'] = fanartImage

                            counter = counter + 1
                        #except:
                            #log('unable to parse the file %s' % filePath)

                        if (pDialog.iscanceled()):
                            isCanceled = True
                            break;

                        pDialog.update(int((float(counter)/float(numFiles))*100), localize(33003))

                    pDialog.close()
        except Exception,e:
            log(e.message)
            log(e.__class__.__name__)
            traceback.print_exc(e)
Example #13
0
 def open_new_file( self ):
     # self.changed will be True if the last opened file was edited
     # TODO: ask to save changes to last opened file
     if self.changed:
         savefirst = xbmcgui.Dialog().yesno( 
             self.file.name, 
             common.localize( 1006 ) 
         )
         if savefirst:
             self.save_current_file()
         self.changed = False
     # close the old file
     if self.file:
         self.file.close()
         self.file = None
     # update status area
     self.update_controls()
     # get a path to the file 
     filepath = common.gui.dialog.browse( heading = common.localize( 1001 ) )
     if len( filepath ):
         try:
             # open the file in read only mode
             # TODO: check for write access here?
             self.file = open( filepath, 'rb' )
             def determine_eol():
                 # determine file EOL character string
                 end_of_line_chars = [ '\r', '\n' ]
                 # read single line out of file
                 line_one = self.file.readline()
                 # reset the seek position for later reads
                 self.file.seek(0)
                 # reset self.eol
                 self.eol = str()
                 # look at last two characters in the line
                 if len( line_one ) < 2:
                     eol = line_one
                 else:
                     eol = line_one[-2:]
                 for char in eol:
                     # we don't want any characters that aren't actually EOL to be
                     #   considered as such
                     if char in end_of_line_chars:
                         self.eol = self.eol + char
                 # readline() splits on '\n', so mac files won't split
                 #   note that the code above will not always result in self.eol
                 #   being an empty string, for example, if mac file ends in 
                 #   multiple empty lines, self.eol would be '\r\r' and valid to
                 #   the above code - need to check for that here too
                 file_len = int( os.stat( self.file.name ).st_size )
                 # if the file ended without a newline, see if this is mac file
                 if len( line_one ) == file_len:
                     # if a mac file ends in multiple newlines, set self.eol 
                     #   to only one EOL character
                     if len( self.eol ) > 1:
                         if self.eol[-1] == '\r':
                             self.eol = '\r'
                     # file had no EOL at the end of line_one, so check the
                     #   string to be sure that there aren't any mac EOL chars
                     if not len( self.eol ):
                         if line_one.find( '\r' ) > -1:
                             self.eol = '\r'
                 # still no eol encountered in this file, so set to default
                 if not len( self.eol ):
                     self.eol = os.linesep
             # clear the list before adding new items
             self.window.clearList()
             # add a new item to the list for each line of text in the file
             line_number = 0
             def line_cleanup( line ):
                 # strip all EOL characters out of the line for display
                 for char in self.eol:
                     line = line.replace( char, '' )
                 return line
             # figure out the EOL format
             determine_eol()
             if self.eol == '\r':
                 # mac line endings aren't recognized by readline()
                 #   but, don't do it this way unless it's required, 
                 #   because it is slower than using the for line in 
                 #   self.file method
                 lines = self.file.read( file_len ).split( self.eol )
             else:
                 lines = self.file
             # cleanup and add the lines as ListItems
             for line in lines:
                 line = line_cleanup( line )
                 line_number = line_number + 1
                 item = xbmcgui.ListItem( line, str( line_number ) )
                 self.window.addItem( item )
             # close the file
             if self.file:
                 self.file.close()
         except:
             import traceback
             traceback.print_exc()
     # update status area
     self.update_controls()
Example #14
0
 def change_line( self ):
     if not self.check_access( self.file.name ):
         # file is read-only, don't allow line changes
         dialog = xbmcgui.Dialog()
         dialog.ok(
             os.path.split( self.file.name )[-1],
             common.localize( 1002 ),
             common.localize( 1003 )
         )
     else:
         try:
             # find the current id and ListItem object
             id = self.window.getCurrentListPosition()
             item = None
             if id >= 0:
                 item = self.window.getListItem( id )
             original_text = str()
             if item:
                 try:
                     # get text from the ListItem
                     original_text = item.getLabel()
                 except:
                     pass
             def renumber_lines( line_number ):
                 # renumbers lines starting from line_number
                 for i in range( self.window.getListSize() ):
                     if i >= line_number:
                         # for pretty line numbers, increase by one for display
                         self.window.getListItem( i ).setLabel2( 
                             str( i + 1 )
                         )
             # set up functions to perform menu item selections
             def edit():
                 new_text = None
                 # show keyboard for user to change the text
                 new_text = common.gui.dialog.getText( 
                     common.localize( 1004 ),
                     original_text, 
                 )
                 # perform the changes, assuming that the new text is not blank
                 #   or the same as the old text
                 if len( new_text ) and ( new_text != original_text ):
                     item.setLabel( new_text )
                     self.changed = True
             def insert():
                 global new_id
                 new_id = -1
                 def before():
                     global new_id
                     if id < 0:
                         # trying to insert to an empty file
                         new_id = 0
                     else:
                         new_id = id
                 def after():
                     global new_id
                     if id < 0:
                         # trying to insert to an empty file
                         new_id = 0
                     else:
                         new_id = id + 1
                 # menu items
                 items = dict()
                 items[len(items.keys())+1] = {
                     'label': common.localize( 504 ), # Insert before..
                     'thumb': 'script-line-inserted-before.png',
                     'onClick': before,
                 }
                 items[len(items.keys())+1] = {
                     'label': common.localize( 505 ), # Insert after..
                     'thumb': 'script-line-inserted-after.png',
                     'onClick': after,
                 }
                 # show the menu
                 menu = common.gui.dialog.popupmenu( items )
                 if new_id < 0:
                     return
                 # insert the new item
                 item = xbmcgui.ListItem( '', str( new_id + 1 ) )
                 self.window.addItem( item, new_id )
                 self.changed = True
                 # reorganize line numbers
                 renumber_lines( new_id )
                 # select the new inserted line
                 self.window.setCurrentListPosition( new_id )
                 # make sure we've got the handle to the proper 
                 #   ListItem still
                 item = self.window.getListItem( new_id )
                 new_text = None
                 # show keyboard for user to change the text
                 new_text = common.gui.dialog.getText( 
                     common.localize( 1004 )
                 )
                 if len( new_text ):
                     item.setLabel( new_text )
             def delete():
                 self.window.removeItem( id )
                 # reorganize the line numbers
                 renumber_lines( id )
                 self.changed = True
             # menu items
             items = dict()
             if item:
                 items[len(items.keys())+1] = {
                     'label': common.localize( 501 ), # Edit
                     'thumb': 'script-line-changed.png',
                     'onClick': edit,
                 }
             items[len(items.keys())+1] = {
                 'label': common.localize( 503 ), # Insert
                 'thumb': 'script-line-inserted.png',
                 'onClick': insert,
             }
             if item:
                 items[len(items.keys())+1] = {
                     'label': common.localize( 502 ), # Delete
                     'thumb': 'script-line-deleted.png',
                     'onClick': delete,
                 }
             # show the menu
             menu = common.gui.dialog.popupmenu( items )
             # update status area
             self.update_controls()
         except:
             import traceback
             traceback.print_exc()
Example #15
0
    def findGames(self, orgGames, games):
        xbmc.executebuiltin("Dialog.Close(busydialog)")
        isCanceled = False
        try:
            gameData = self.getMfstFiles()
            numFiles = len(gameData)
            if (numFiles > 0):
                counter = 0

                pDialog = xbmcgui.DialogProgress()
                pDialog.create(__addonname__, localize(33003))
                pDialog.update(0, localize(33003))

                for game in gameData:

                    try:
                        installPath = self.getGameInstallPath(game)
                        #log("installPath = " + installPath)
                        fileName = self.extractDLL(installPath)
                        xmlPath = os.path.join(TEMP_DIR, 'Data_1.bin')
                        name, id, path = self.parseXML(xmlPath, installPath,
                                                       fileName)

                        gameId = 'OR-%s' % id

                        orgGame = None

                        for game in orgGames:
                            if (game.gameId == gameId):
                                orgGame = game
                                break

                        isNameChanged = 0
                        isPathChanged = 0
                        isIconChanged = 0
                        isFanartChanged = 0
                        thumbImage = ''
                        fanartImage = ''
                        type = 2

                        #log(path)
                        if ((not orgGame) or (orgGame is not None
                                              and orgGame.isFanartChanged == 0
                                              and orgGame.isIconChanged == 0)):
                            gameFiles = self.downloadGameImage(
                                gameId, name, path)
                            thumbImage = gameFiles[0]
                            fanartImage = gameFiles[1]
                        elif (orgGame is not None
                              and orgGame.isFanartChanged == 0):
                            gameFiles = self.downloadGameImage(
                                gameId, name, path)
                            thumbImage = orgGame.thumbImage
                            fanartImage = gameFiles[1]
                            isIconChanged = 1
                        elif (orgGame is not None
                              and orgGame.isIconChanged == 0):
                            gameFiles = self.downloadGameImage(
                                gameId, name, path)
                            thumbImage = gameFiles[0]
                            fanartImage = orgGame.fanartImage
                            isFanartChanged = 1
                        else:
                            thumbImage = orgGame.thumbImage
                            fanartImage = orgGame.fanartImage
                            isIconChanged = 1
                            isFanartChanged = 1

                        if (orgGame is not None
                                and orgGame.isNameChanged == 1):
                            name = orgGame.title
                            isNameChanged = 1

                        if (orgGame is not None
                                and orgGame.isPathChanged == 1):
                            name = orgGame.path
                            isPathChanged = 1

                        games[gameId] = {}
                        games[gameId]['name'] = name
                        games[gameId]['path'] = path
                        games[gameId]['isNameChanged'] = isNameChanged
                        games[gameId]['isPathChanged'] = isPathChanged
                        games[gameId]['isIconChanged'] = isIconChanged
                        games[gameId]['isFanartChanged'] = isFanartChanged
                        games[gameId]['type'] = type
                        games[gameId]['thumbImage'] = thumbImage
                        games[gameId]['fanartImage'] = fanartImage

                        counter = counter + 1

                        if (pDialog.iscanceled()):
                            isCanceled = True
                            break

                        pDialog.update(
                            int((float(counter) / float(numFiles)) * 100),
                            localize(33003))

                    except:
                        log("error occured")

                pDialog.close()
        except Exception, e:
            #log(e.message)
            #log(e.__class__.__name__)
            traceback.print_exc(e)
Example #16
0
    def findGames(self, orgGames, games):
        xbmc.executebuiltin("Dialog.Close(busydialog)")
        isCanceled = False
        try:
            numFiles = self.findGameCount()
            if (numFiles > 0):
                counter = 0

                pDialog = xbmcgui.DialogProgress()
                pDialog.create(__addonname__, localize(33003))
                pDialog.update(0, localize(33003))

                con = sqlite3.connect(DB_PATH)
                cur = con.cursor()
    
                command = "SELECT productId, localpath from main.Products"
                cur.execute(command)
                rows = cur.fetchall()
                
                command ="SELECT productId, name from main.AvailableGameIDNames"
                cur.execute(command)
                allRows = cur.fetchall()    

                for row in rows:
                    id = row[0]
                    installPath = row[1]
                    name = ''

                    for i in allRows:
                        if id == i[0]:
                            name = i[1]
                            break

                    dllFile = 'goggame-%s.dll' % id
                    self.extractDLL(installPath, dllFile)
                    xmlPath = os.path.join(TEMP_DIR,'Data_2.bin')
                    path = ''
                    arguments = ''
                    path, arguments = self.parseXML(xmlPath,installPath,dllFile)

                    if arguments != '':
                        path = path + ' ' + arguments

                    gameId = 'GO-%s' % id
        
                    #find the shortcut link
                    #os.chdir(installPath)
                    #for file in glob("Launch*"):
                        #path = os.path.join(installPath, file)


                    orgGame = None

                    for game in orgGames:
                        if (game.gameId == gameId):
                            orgGame = game
                            break;

                    isNameChanged = 0
                    isPathChanged = 0
                    isIconChanged = 0
                    isFanartChanged = 0
                    thumbImage = ''
                    fanartImage = ''
                    type = 3

                    if ((not orgGame) or (orgGame is not None and orgGame.isFanartChanged == 0 and orgGame.isIconChanged == 0)):
                        gameFiles = self.downloadGameImage(gameId,name,os.path.join(installPath,"dummy.exe"))
                        thumbImage = gameFiles[0]
                        fanartImage = gameFiles[1]
                    elif (orgGame is not None and orgGame.isFanartChanged == 0):
                        gameFiles = self.downloadGameImage(gameId,name,os.path.join(installPath,"dummy.exe"))
                        thumbImage = orgGame.thumbImage
                        fanartImage = gameFiles[1]
                        isIconChanged = 1
                    elif (orgGame is not None and orgGame.isIconChanged == 0):
                        gameFiles = self.downloadGameImage(gameId,name,os.path.join(installPath,"dummy.exe"))
                        thumbImage = gameFiles[0]
                        fanartImage = orgGame.fanartImage
                        isFanartChanged = 1
                    else:
                        thumbImage = orgGame.thumbImage
                        fanartImage = orgGame.fanartImage
                        isIconChanged = 1
                        isFanartChanged = 1

                    if (orgGame is not None and orgGame.isNameChanged == 1):
                        name = orgGame.title
                        isNameChanged = 1

                    if (orgGame is not None and orgGame.isPathChanged == 1):
                        name = orgGame.path
                        isPathChanged = 1

                    games[gameId] = {}
                    games[gameId]['name'] = name
                    games[gameId]['path'] = path
                    games[gameId]['isNameChanged'] = isNameChanged
                    games[gameId]['isPathChanged'] = isPathChanged
                    games[gameId]['isIconChanged'] = isIconChanged
                    games[gameId]['isFanartChanged'] = isFanartChanged
                    games[gameId]['type'] = type
                    games[gameId]['thumbImage'] = thumbImage
                    games[gameId]['fanartImage'] = fanartImage

                    counter = counter + 1

                    if (pDialog.iscanceled()):
                        isCanceled = True
                        break;

                    pDialog.update(int((float(counter)/float(numFiles))*100), localize(33003))




                pDialog.close()
                con.close()
        except Exception,e:
            #log(e.message)
            #log(e.__class__.__name__)
            traceback.print_exc(e)
Example #17
0
File: goggame.py Project: zmmr/Kodi
    def findGames(self, orgGames, games):
        xbmc.executebuiltin("Dialog.Close(busydialog)")
        isCanceled = False
        try:
            numFiles = self.findGameCount()
            if (numFiles > 0):
                counter = 0

                pDialog = xbmcgui.DialogProgress()
                pDialog.create(__addonname__, localize(33003))
                pDialog.update(0, localize(33003))

                con = sqlite3.connect(DB_PATH)
                cur = con.cursor()

                command = "SELECT productId, localpath from main.Products"
                cur.execute(command)
                rows = cur.fetchall()

                command = "SELECT productId, name from main.AvailableGameIDNames"
                cur.execute(command)
                allRows = cur.fetchall()

                for row in rows:
                    id = row[0]
                    installPath = row[1]
                    name = ''

                    for i in allRows:
                        if id == i[0]:
                            name = i[1]
                            break

                    dllFile = 'goggame-%s.dll' % id
                    self.extractDLL(installPath, dllFile)
                    xmlPath = os.path.join(TEMP_DIR, 'Data_2.bin')
                    path = ''
                    arguments = ''
                    path, arguments = self.parseXML(xmlPath, installPath,
                                                    dllFile)

                    if arguments != '':
                        path = path + ' ' + arguments

                    gameId = 'GO-%s' % id

                    #find the shortcut link
                    #os.chdir(installPath)
                    #for file in glob("Launch*"):
                    #path = os.path.join(installPath, file)

                    orgGame = None

                    for game in orgGames:
                        if (game.gameId == gameId):
                            orgGame = game
                            break

                    isNameChanged = 0
                    isPathChanged = 0
                    isIconChanged = 0
                    isFanartChanged = 0
                    thumbImage = ''
                    fanartImage = ''
                    type = 3

                    if ((not orgGame) or
                        (orgGame is not None and orgGame.isFanartChanged == 0
                         and orgGame.isIconChanged == 0)):
                        gameFiles = self.downloadGameImage(
                            gameId, name, os.path.join(installPath,
                                                       "dummy.exe"))
                        thumbImage = gameFiles[0]
                        fanartImage = gameFiles[1]
                    elif (orgGame is not None
                          and orgGame.isFanartChanged == 0):
                        gameFiles = self.downloadGameImage(
                            gameId, name, os.path.join(installPath,
                                                       "dummy.exe"))
                        thumbImage = orgGame.thumbImage
                        fanartImage = gameFiles[1]
                        isIconChanged = 1
                    elif (orgGame is not None and orgGame.isIconChanged == 0):
                        gameFiles = self.downloadGameImage(
                            gameId, name, os.path.join(installPath,
                                                       "dummy.exe"))
                        thumbImage = gameFiles[0]
                        fanartImage = orgGame.fanartImage
                        isFanartChanged = 1
                    else:
                        thumbImage = orgGame.thumbImage
                        fanartImage = orgGame.fanartImage
                        isIconChanged = 1
                        isFanartChanged = 1

                    if (orgGame is not None and orgGame.isNameChanged == 1):
                        name = orgGame.title
                        isNameChanged = 1

                    if (orgGame is not None and orgGame.isPathChanged == 1):
                        name = orgGame.path
                        isPathChanged = 1

                    games[gameId] = {}
                    games[gameId]['name'] = name
                    games[gameId]['path'] = path
                    games[gameId]['isNameChanged'] = isNameChanged
                    games[gameId]['isPathChanged'] = isPathChanged
                    games[gameId]['isIconChanged'] = isIconChanged
                    games[gameId]['isFanartChanged'] = isFanartChanged
                    games[gameId]['type'] = type
                    games[gameId]['thumbImage'] = thumbImage
                    games[gameId]['fanartImage'] = fanartImage

                    counter = counter + 1

                    if (pDialog.iscanceled()):
                        isCanceled = True
                        break

                    pDialog.update(
                        int((float(counter) / float(numFiles)) * 100),
                        localize(33003))

                pDialog.close()
                con.close()
        except Exception, e:
            #log(e.message)
            #log(e.__class__.__name__)
            traceback.print_exc(e)