Exemple #1
0
    def backup(self,backup_location=None):
        # If they just called backup(), then use the path specified in the config
        if not backup_location:
            backup_location = settings.config()["Storage"]["backup directory"]
        # If backup_location is still undefined, then we have no idea where to do the backup, so
        # we just return after printing a message
        if not backup_location:
            ice_logger.log("No backup location specified. Not creating backup file.")
            return None

        # If the shortcuts file is undefined, print an error and return
        if not self.shortcuts_file:
            print "SteamShortcutManager Backup Error: No file specified"
            return None

        # Get the user id using the location of the shortcuts file and create a directory
        # in the backup location using the same directory structure Steam uses
        user_id = os.path.split(os.path.dirname(os.path.dirname(self.shortcuts_file)))[1]
        new_dir = os.path.expanduser(os.path.join(os.path.join(backup_location,user_id),"config"))
        try:  # Handle possible race condition
            os.makedirs(new_dir)
        except OSError:
            if not os.path.isdir(new_dir):
                raise

        backup_file_name = "shortcuts." + datetime.now().strftime('%Y%m%d%H%M%S') + ".vdf"
        open(os.path.join(new_dir,backup_file_name),"w").write(open(self.shortcuts_file,"r").read())
Exemple #2
0
def create_directory_if_needed(dir, log=None):
    """
    Checks to see if a directory exists and, if not, creates it
    """
    if not os.path.exists(dir):
        if log is not None:
            ice_logger.log(log)
        os.makedirs(dir)
Exemple #3
0
def create_directory_if_needed(dir, log=None):
    """
    Checks to see if a directory exists and, if not, creates it
    """
    if not os.path.exists(dir):
        if log is not None:
            ice_logger.log(log)
        os.makedirs(dir)
Exemple #4
0
 def add_rom(self, rom):
     # Don't add a ROM if we don't have a supported emulator for it
     if rom.console.emulator is None:
         return
     if not self.rom_already_in_steam(rom):
         ice_logger.log("Adding %s" % rom.name())
         generated_shortcut = rom.to_shortcut()
         self.managed_shortcuts.add(generated_shortcut)
         self.shortcut_manager.add(generated_shortcut)
Exemple #5
0
 def add_rom(self,rom):
     # Don't add a ROM if we don't have a supported emulator for it
     if rom.console.emulator is None:
         return
     if not self.rom_already_in_steam(rom):
         ice_logger.log("Adding %s" % rom.name())
         generated_shortcut = rom.to_shortcut()
         self.managed_shortcuts.add(generated_shortcut)
         self.shortcut_manager.add(generated_shortcut)
Exemple #6
0
 def is_enabled(self,verbose=False):
     if self.emulator is None:
         if verbose:
             ice_logger.log("Skipping %s (no emulator provided)" % self)
         return False
     if self.custom_roms_directory and not filesystem_helper.available_to_use(self.custom_roms_directory, create_if_needed=True):
         if verbose:
             ice_logger.log("Skipping %s (ROMs directory provided either doesn't exist or is not writable)" % self)
         return False
     return True
Exemple #7
0
 def remove_deleted_roms_from_steam(self, roms):
     # We define 'has been deleted' by checking whether we have a shortcut
     # that was managed by Ice in Steam that is no longer in our ROM folders
     rom_shortcuts = set()
     for rom in roms:
         rom_shortcuts.add(rom.to_shortcut())
     deleted_rom_shortcuts = self.managed_shortcuts - rom_shortcuts
     for shortcut in deleted_rom_shortcuts:
         ice_logger.log("Deleting: %s" % shortcut.appname)
         self.shortcut_manager.shortcuts.remove(shortcut)
Exemple #8
0
 def remove_deleted_roms_from_steam(self,roms):
     # We define 'has been deleted' by checking whether we have a shortcut
     # that was managed by Ice in Steam that is no longer in our ROM folders
     rom_shortcuts = set()
     for rom in roms:
         rom_shortcuts.add(rom.to_shortcut())
     deleted_rom_shortcuts = self.managed_shortcuts - rom_shortcuts
     for shortcut in deleted_rom_shortcuts:
         ice_logger.log("Deleting: %s" % shortcut.appname)
         self.shortcut_manager.shortcuts.remove(shortcut)
Exemple #9
0
 def is_enabled(self,verbose=False):
     if self.emulator is None:
         if verbose:
             ice_logger.log("Skipping %s (no emulator provided)" % self)
         return False
     if self.custom_roms_directory and not filesystem_helper.available_to_use(self.custom_roms_directory, create_if_needed=True):
         if verbose:
             ice_logger.log("Skipping %s (ROMs directory provided either doesn't exist or is not writable)" % self)
         return False
     return True
Exemple #10
0
 def is_enabled(self, verbose=False):
     """
     Checks to see whether enough information has been entered by the user
     to make the emulator useable
     """
     # Right now the only thing we care about is whether a file exists where
     # the user says the emulator is.
     if not os.path.isfile(self.location):
         if verbose:
             ice_logger.log("(Emulator) File does not exist at '%s'. Ignoring %s" % (self.location, self.name))
         return False
     return True
Exemple #11
0
def supported_consoles():
    consoles = settings_consoles()
    # Remove any consoles from supported_consoles if there does not exist an
    # emulator for them
    for console in list(consoles):
        if not console.is_enabled(verbose=True):
            consoles.remove(console)
    # Print out all of the detected consoles so the user knows what is going
    # on.
    for console in consoles:
        ice_logger.log("Detected Console: %s => %s" % (console.fullname, console.emulator.name))
    return consoles
Exemple #12
0
def supported_consoles():
    consoles = settings_consoles()
    # Remove any consoles from supported_consoles if there does not exist an
    # emulator for them
    for console in list(consoles):
        if not console.is_enabled(verbose=True):
            consoles.remove(console)
    # Print out all of the detected consoles so the user knows what is going
    # on.
    for console in consoles:
        ice_logger.log("Detected Console: %s => %s" % (console.fullname, console.emulator.name))
    return consoles
Exemple #13
0
def settings_emulators():
    emulators = []
    emulators_dict = settings.emulators()
    for name in emulators_dict.keys():
        emulator_data = emulators_dict[name]
        location = utils.idx(emulator_data, 'location', "")
        current_emulator = Emulator(name, location, emulator_data)
        if current_emulator.is_enabled(verbose=True):
            emulators.append(current_emulator)
    # After all of the invalid emulators have been removed, let the user know
    # which emulators have initialized successfully
    for emulator in emulators:
        ice_logger.log("Detected Emulator: %s" % emulator.name)
    return emulators
Exemple #14
0
def settings_emulators():
    emulators = []
    emulators_dict = settings.emulators()
    for name in emulators_dict.keys():
        emulator_data = emulators_dict[name]
        location = utils.idx(emulator_data, 'location', "")
        current_emulator = Emulator(name, location, emulator_data)
        if current_emulator.is_enabled(verbose=True):
            emulators.append(current_emulator)
    # After all of the invalid emulators have been removed, let the user know
    # which emulators have initialized successfully
    for emulator in emulators:
        ice_logger.log("Detected Emulator: %s" % emulator.name)
    return emulators
Exemple #15
0
 def is_enabled(self, verbose=False):
     """
     Checks to see whether enough information has been entered by the user
     to make the emulator useable
     """
     # Right now the only thing we care about is whether a file exists where
     # the user says the emulator is.
     if not os.path.isfile(self.location):
         if verbose:
             ice_logger.log(
                 "(Emulator) File does not exist at '%s'. Ignoring %s" %
                 (self.location, self.name))
         return False
     return True
Exemple #16
0
 def update_user_images(self, user_id, roms):
     """
     Sets a suitable grid image for every rom in 'roms' for the user
     defined by 'user_id'
     """
     grid = steam_grid.SteamGrid(steam_user_manager.userdata_directory_for_user_id(user_id))
     for rom in roms:
         shortcut = rom.to_shortcut()
         if not grid.existing_image_for_filename(grid.filename_for_shortcut(shortcut.appname, shortcut.exe)):
             path = self.image_for_rom(rom)
             if path is None:
                 # TODO: Tell the user what went wrong
                 pass
             else:
                 # TODO: Tell the user that an image was found
                 ice_logger.log("Found grid image for %s" % shortcut.appname)
                 grid.set_image_for_shortcut(path, shortcut.appname, shortcut.exe)
Exemple #17
0
 def find_roms(self):
     """
     Reads a list of all the ROMs from the appropriate directory for the
     console
     """
     roms = []
     if not os.path.exists(self.roms_directory()):
         ice_logger.log("Creating %s directory at %s" % (self.shortname,self.roms_directory()))
         os.makedirs(self.roms_directory())
     for filename in os.listdir(self.roms_directory()):
         file_path = os.path.join(self.roms_directory(),filename)
         if not os.path.isdir(file_path):
             # On Linux/OSX, we want to make sure hidden files don't get
             # accidently added as well
             if not pf.is_windows() and filename.startswith('.'):
                 continue
             if self.emulator is not None and not self.is_valid_rom(file_path):
                 ice_logger.log_warning("Ignoring Non-ROM file: %s" % file_path)
                 continue
             roms.append(ROM(file_path,self))
     return roms
Exemple #18
0
 def find_roms(self):
     """
     Reads a list of all the ROMs from the appropriate directory for the
     console
     """
     roms = []
     if not os.path.exists(self.roms_directory()):
         ice_logger.log("Creating %s directory at %s" % (self.shortname, self.roms_directory()))
         os.makedirs(self.roms_directory())
     for filename in os.listdir(self.roms_directory()):
         file_path = os.path.join(self.roms_directory(), filename)
         if not os.path.isdir(file_path):
             # On Linux/OSX, we want to make sure hidden files don't get
             # accidently added as well
             if not pf.is_windows() and filename.startswith("."):
                 continue
             if self.emulator is not None and not self.is_valid_rom(file_path):
                 ice_logger.log_warning("Ignoring Non-ROM file: %s" % file_path)
                 continue
             roms.append(ROM(file_path, self))
     return roms
Exemple #19
0
 def update_user_images(self, user_id, roms):
     """
     Sets a suitable grid image for every rom in 'roms' for the user
     defined by 'user_id'
     """
     grid = steam_grid.SteamGrid(
         steam_user_manager.userdata_directory_for_user_id(user_id))
     for rom in roms:
         shortcut = rom.to_shortcut()
         if not grid.existing_image_for_filename(
                 grid.filename_for_shortcut(shortcut.appname,
                                            shortcut.exe)):
             path = self.image_for_rom(rom)
             if path is None:
                 # TODO: Tell the user what went wrong
                 pass
             else:
                 # TODO: Tell the user that an image was found
                 ice_logger.log("Found grid image for %s" %
                                shortcut.appname)
                 grid.set_image_for_shortcut(path, shortcut.appname,
                                             shortcut.exe)
Exemple #20
0
 def startIce(self):
     # very similar to the one in ice.py
     try:
         if steam_is_running():
             ice_logger.log_error("Ice cannot be run while Steam is open. Please close Steam and try again")
             return
         ice_logger.log("Starting Ice")
         fs.create_directory_if_needed(fs.roms_directory(), log="Creating ROMs directory at %s" % fs.roms_directory())
         # Find all of the ROMs that are currently in the designated folders
         roms = console.find_all_roms()
         # Find the Steam Account that the user would like to add ROMs for
         user_ids = steam_user_manager.user_ids_on_this_machine()
         grid_manager = IceGridImageManager()
         for user_id in user_ids:
             ice_logger.log("Running for user %s" % str(user_id))
             # Load their shortcuts into a SteamShortcutManager object
             shortcuts_path = steam_user_manager.shortcuts_file_for_user_id(user_id)
             shortcuts_manager = SteamShortcutManager(shortcuts_path)
             rom_manager = IceROMManager(shortcuts_manager)
             # Add the new ROMs in each folder to our Shortcut Manager
             rom_manager.sync_roms(roms)
             # Generate a new shortcuts.vdf file with all of the new additions
             shortcuts_manager.save()
             if IceGridImageManager.should_download_images():
                 ice_logger.log("Downloading grid images")
                 grid_manager.update_user_images(user_id,roms)
             else:
                 ice_logger.log("Skipping 'Download Image' step")
         ice_logger.log("Finished")
     except ConfigError as error:
         ice_logger.log_error('Stopping')
         ice_logger.log_config_error(error)
         ice_logger.log_exception()
     except StandardError as error:
         ice_logger.log_error("An Error has occurred:")
         ice_logger.log_exception()
Exemple #21
0
 def update_user_images(self,user_id,roms):
     """
     Sets a suitable grid image for every rom in 'roms' for the user defined
     by 'user_id'
     """
     grid = steam_grid.SteamGrid(steam_user_manager.userdata_directory_for_user_id(user_id))
     for rom in roms:
         shortcut = rom.to_shortcut()
         if not grid.existing_image_for_filename(grid.filename_for_shortcut(shortcut.appname,shortcut.exe)):
             image = self.find_image_for_rom(rom)
             # Game not found
             if image is None:
                 ice_logger.log_warning("No game found for %s on %s" % (rom.name(),rom.console.fullname))
                 ice_logger.log("The image provider has no game called %s for %s. Try going to %s and submittng the game yourself" % (rom.name(),rom.console.fullname, self.host_for_image_source()))
             # Game found, but there is no picture
             elif image == "":
                 ice_logger.log_warning("No image found for %s. The URL checked was '%s'" % (rom.name(),self.url_for_rom(rom)))
                 ice_logger.log("We couldn't find an image for %s. If you find one you like, upload it to %s, and next time Ice runs it will use it" % (rom.name(),self.host_for_image_source()))
             # Game found, AND there is a picture there
             else:
                 ice_logger.log("Setting custom image for %s" % rom.name())
                 ice_logger.log('Found grid-image for "' + rom.name() +'"')
                 image_path = self.download_image(image)
                 grid.set_image_for_shortcut(image_path,shortcut.appname,shortcut.exe)