Exemplo n.º 1
0
        void OnServiceMethod( SteamUnifiedMessages.ServiceMethodResponse callback )
        {
            UGCJob ugcJob;
            bool foundJob = ugcJobs.TryGetValue( callback.JobID, out ugcJob );
            ugcJobs.Remove( callback.JobID );

            if ( !foundJob )
            {
                // didn't find a waiting UGC job for this response
                return;
            }

            if ( callback.Result != EResult.OK )
            {
                ugcJob.Callback( new UGCJobResult( callback.JobID, callback.Result ) );
                return;
            }

            var response = callback.GetDeserializedResponse<CPublishedFile_GetDetails_Response>();
            var details = response.publishedfiledetails.FirstOrDefault(); // we only ever request one pubfile at a time

            EResult pubResult = (EResult)details.result;

            if ( pubResult != EResult.OK )
            {
                ugcJob.Callback( new UGCJobResult ( callback.JobID, pubResult ) );
                return;
            }

            // cache out this ugc to file and memory

            ugcCache[details.publishedfileid] = new UGCCacheEntry
            {
                PubFileID = details.publishedfileid,
                AppID = details.consumer_appid,

                Name = details.title,
                Tags = details.tags
            };

            using ( var ms = new MemoryStream() )
            {
                Serializer.Serialize( ms, details );

                try
                {
                    File.WriteAllBytes( GetCachePath( details.publishedfileid ), ms.ToArray() );
                }
                catch ( IOException ex )
                {
                    Log.WriteError( "UGCHandler", "Unable to cache ugc for pubfile {0}: {1}", details.publishedfileid, ex.Message );
                    return;
                }
            }

            var result = new UGCJobResult
            {
                ID = callback.JobID,
                Details = details,
            };

            ugcJob.Callback( result );
        }
Exemplo n.º 2
0
        void OnServiceMethod(SteamUnifiedMessages.ServiceMethodResponse callback)
        {
            UGCJob ugcJob;
            bool   foundJob = ugcJobs.TryGetValue(callback.JobID, out ugcJob);

            ugcJobs.Remove(callback.JobID);

            if (!foundJob)
            {
                // didn't find a waiting UGC job for this response
                return;
            }

            if (callback.Result != EResult.OK)
            {
                ugcJob.Callback(new UGCJobResult(callback.JobID, callback.Result));
                return;
            }

            var response = callback.GetDeserializedResponse <CPublishedFile_GetDetails_Response>();
            var details  = response.publishedfiledetails.FirstOrDefault(); // we only ever request one pubfile at a time

            EResult pubResult = (EResult)details.result;

            if (pubResult != EResult.OK)
            {
                ugcJob.Callback(new UGCJobResult(callback.JobID, pubResult));
                return;
            }

            // cache out this ugc to file and memory

            ugcCache[details.publishedfileid] = new UGCCacheEntry
            {
                PubFileID = details.publishedfileid,
                AppID     = details.consumer_appid,

                Name = details.title,
                Tags = details.tags
            };

            using (var ms = new MemoryStream())
            {
                Serializer.Serialize(ms, details);

                try
                {
                    File.WriteAllBytes(GetCachePath(details.publishedfileid), ms.ToArray());
                }
                catch (IOException ex)
                {
                    Log.WriteError("UGCHandler", "Unable to cache ugc for pubfile {0}: {1}", details.publishedfileid, ex.Message);
                    return;
                }
            }

            var result = new UGCJobResult
            {
                ID      = callback.JobID,
                Details = details,
            };

            ugcJob.Callback(result);
        }