| 7 |
using System.Drawing; |
using System.Drawing; |
| 8 |
using System.IO; |
using System.IO; |
| 9 |
using System.Threading; |
using System.Threading; |
| 10 |
|
using OpenMetaverse.Imaging; |
| 11 |
|
|
| 12 |
namespace Xenki.DefaultTexture |
namespace Xenki.DefaultTexture |
| 13 |
{ |
{ |
| 19 |
|
|
| 20 |
string cachefolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "textures"); |
string cachefolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "textures"); |
| 21 |
|
|
| 22 |
|
string bmpFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "texture"); |
| 23 |
|
|
| 24 |
//the textures have load in memory. |
//the textures have load in memory. |
| 25 |
private readonly Dictionary<UUID, byte[]> CurruntTextures = new Dictionary<UUID, byte[]>(); |
private readonly Dictionary<UUID, byte[]> CurruntTextures = new Dictionary<UUID, byte[]>(); |
| 36 |
|
|
| 37 |
|
|
| 38 |
// maximum allowed concurrent requests at once |
// maximum allowed concurrent requests at once |
| 39 |
const int MAX_TEXTURE_REQUESTS = 3; |
const int MAX_TEXTURE_REQUESTS = 5; |
| 40 |
|
|
| 41 |
private GridClient gridClient; |
private GridClient gridClient; |
| 42 |
|
|
| 162 |
GridClient.Assets.RequestImage(ti.RequestID, ImageType.Normal); |
GridClient.Assets.RequestImage(ti.RequestID, ImageType.Normal); |
| 163 |
|
|
| 164 |
// don't release this worker slot until texture is downloaded or timeout occurs |
// don't release this worker slot until texture is downloaded or timeout occurs |
| 165 |
if (!resetEvents[ti.RequestNbr].WaitOne(300 * 1000, false)) |
if (!resetEvents[ti.RequestNbr].WaitOne(30 * 1000, false)) |
| 166 |
{ |
{ |
| 167 |
// Timed out |
// Timed out |
| 168 |
Logger.Log("Worker " + ti.RequestNbr + " Timeout waiting for Texture " + ti.RequestID + " to Download", Helpers.LogLevel.Warning); |
Logger.Log("Worker " + ti.RequestNbr + " Timeout waiting for Texture " + ti.RequestID + " to Download", Helpers.LogLevel.Warning); |
| 174 |
// free up this download slot |
// free up this download slot |
| 175 |
threadpoolSlots[ti.RequestNbr] = -1; |
threadpoolSlots[ti.RequestNbr] = -1; |
| 176 |
} |
} |
| 177 |
|
object mmm = new object(); |
| 178 |
private void Assets_OnImageReceived(ImageDownload image, AssetTexture asset) |
private void Assets_OnImageReceived(ImageDownload image, AssetTexture asset) |
| 179 |
{ |
{ |
| 180 |
if (image.Success) |
if (image.Success) |
| 181 |
{ |
{ |
|
if (GridClient.Assets.Cache.HasImage(image.ID) == true) |
|
|
{ |
|
|
string succeeeeeee = GridClient.Assets.Cache.ImageFileName(image.ID); |
|
|
} |
|
| 182 |
lock (CurruntTextures) |
lock (CurruntTextures) |
| 183 |
{ |
{ |
| 184 |
if (!CurruntTextures.ContainsKey(image.ID)) |
if (!CurruntTextures.ContainsKey(image.ID)) |
| 191 |
CurruntTextures.Add(image.ID, image.AssetData); |
CurruntTextures.Add(image.ID, image.AssetData); |
| 192 |
} |
} |
| 193 |
} |
} |
| 194 |
|
|
| 195 |
|
if (File.Exists(Path.Combine(bmpFilePath, image.ID.ToString() + ".bmp")) == false) |
| 196 |
|
{ |
| 197 |
|
ManagedImage managedimg; |
| 198 |
|
Image img; |
| 199 |
|
//byte[] bytes = GetTextureDataByTextureID(downLoadedTextureID); |
| 200 |
|
|
| 201 |
|
if (OpenJPEG.DecodeToImage(image.AssetData, out managedimg, out img)) |
| 202 |
|
{ |
| 203 |
|
Bitmap bitmap = new Bitmap(img); |
| 204 |
|
bitmap.Save(Path.Combine(bmpFilePath, image.ID.ToString() + ".bmp")); |
| 205 |
|
|
| 206 |
|
// bitmap.Dispose(); |
| 207 |
|
bitmap = null; |
| 208 |
|
} |
| 209 |
|
|
| 210 |
|
} |
| 211 |
|
|
| 212 |
} |
} |
| 213 |
|
|
| 214 |
if (onDownloadFinished != null) |
if (onDownloadFinished != null) |