예제 #1
0
    def check_for_changes(self):
        changefile = UserCacheFile('last_change_number')
        change_number = 0

        if changefile.exists():
            try:
                change_number = int(changefile.read_full())
            except:
                changefile.remove()

        self._LOG.debug("Checking PICS for app changes")
        resp = self.steam.get_changes_since(change_number, True, False)

        if resp.force_full_app_update:
            change_number = 0

        if resp.current_change_number != change_number:
            with changefile.open('w') as fp:
                fp.write(str(resp.current_change_number))

            changed_apps = set((entry.appid for entry in resp.app_changes))

            if change_number == 0 or changed_apps:
                self._LOG.debug("Checking for outdated cached appinfo files")

                for appinfo_file in UserCacheDirectory('appinfo').iter_files(
                        '*.json'):
                    app_id = int(appinfo_file.filename[:-5])

                    if change_number == 0 or app_id in changed_apps:
                        appinfo_file.remove()
예제 #2
0
 def has_cached_app_depot_info(self, app_id):
     if app_id in self.app_depots:
         return True
     cached_appinfo = UserCacheFile("appinfo/{}.json".format(app_id))
     if cached_appinfo.exists():
         return True
     return False
예제 #3
0
    def get_cached_manifest(self, app_id, depot_id, manifest_gid):
        key = (app_id, depot_id, manifest_gid)

        if key in self.manifests:
            return self.manifests[key]

        # if we don't have the manifest loaded, check cache
        cached_manifest = UserCacheFile("manifests/{}_{}_{}".format(app_id, depot_id, manifest_gid))

        # we have a cached manifest file, load it
        if cached_manifest.exists():
            with cached_manifest.open('r+b') as fp:
                try:
                    manifest = self.DepotManifestClass(self, app_id, fp.read())
                except Exception as exp:
                    self._LOG.debug("Error parsing cached manifest: %s", exp)
                else:
                    # if its not empty, load it
                    if manifest.gid > 0:
                        self.manifests[key] = manifest

                        # update cached file if we have depot key for it
                        if manifest.filenames_encrypted and manifest.depot_id in self.depot_keys:
                            manifest.decrypt_filenames(self.depot_keys[manifest.depot_id])
                            fp.seek(0)
                            fp.write(manifest.serialize(compress=False))
                            fp.truncate()

                        return manifest

            # empty manifest files shouldn't exist, handle it gracefully by removing the file
            if key not in self.manifests:
                self._LOG.debug("Found cached manifest, but encountered error or file is empty")
                cached_manifest.remove()
예제 #4
0
    def get_app_depot_info(self, app_id):
        if app_id not in self.app_depots:
            cached_appinfo = UserCacheFile("appinfo/{}.json".format(app_id))
            appinfo = None

            if cached_appinfo.exists():
                appinfo = cached_appinfo.read_json()

            if not appinfo:
                app_req = {'appid': app_id}
                token = self.get_app_access_token(app_id)

                if token:
                    app_req['access_token'] = token

                try:
                    appinfo = self.steam.get_product_info([app_req])['apps'][app_id]
                except KeyError:
                    raise SteamError("Invalid app id")

                if appinfo['_missing_token']:
                    raise SteamError("No access token available")

                cached_appinfo.write_json(appinfo)

            self.app_depots[app_id] = appinfo.get('depots', {})

        return self.app_depots[app_id]
예제 #5
0
    def get_app_depot_info(self, app_id):
        if app_id not in self.app_depots:
            cached_appinfo = UserCacheFile("appinfo/{}.json".format(app_id))
            appinfo = None

            if cached_appinfo.exists():
                appinfo = cached_appinfo.read_json()

            if not appinfo:
                appinfo = self.steam.get_product_info([app_id])['apps'][app_id]
                cached_appinfo.write_json(appinfo)

            self.app_depots[app_id] = appinfo['depots']

        return self.app_depots[app_id]
예제 #6
0
    def get_cached_appinfo(self, app_id):
        cache_file = UserCacheFile("appinfo/{}.json".format(app_id))

        if cache_file.exists():
            return cache_file.read_json()