public static void DownloadAvatar( SteamID steamId, byte[] avatarHash, Action<AvatarDownloadDetails> callBack ) { if(avatarMap.ContainsKey(steamId)) avatarMap[steamId] = avatarHash; else avatarMap.Add(steamId, avatarHash); string hashStr = BitConverter.ToString( avatarHash ).Replace( "-", "" ).ToLower(); string hashPrefix = hashStr.Substring( 0, 2 ); string localPath = Path.Combine( Application.StartupPath, "avatars" ); if ( !Directory.Exists( localPath ) ) { try { Directory.CreateDirectory( localPath ); // try making the cache directory DebugLog.WriteLine( "CDNCache", "Creating cache directory for avatars." ); } catch ( Exception ex ) { DebugLog.WriteLine( "CDNCache", "Unable to create cache directory.\n{0}", ex.ToString() ); callBack( new AvatarDownloadDetails() { Success = false, Exception = ex } ); return; } } string localFile = Path.Combine( localPath, hashStr + ".jpg" ); if ( File.Exists( localFile ) ) { callBack( new AvatarDownloadDetails() { Success = true, Filename = localFile } ); return; } AvatarData ad = new AvatarData { localFile = localFile, callback = callBack, hashstr = hashStr, }; AddJob( ad ); }
static void AddJob( AvatarData data ) { lock ( lockObj ) { jobQueue.Enqueue( data ); Monitor.Pulse( lockObj ); } }