private static void ProcessResource(ContentPreload resource, ContentResource item)
        {
            var id = resource.ID;

            try
            {
                switch (resource.Type)
                {
                case ContentPreloadType.UITexture:
                    /** Apply alpha channel masking & load into GD **/
                    UIElement.StoreTexture(id, item, true, true);
                    break;

                case ContentPreloadType.UITexture_NoMask:
                    UIElement.StoreTexture(id, item, false, true);
                    break;

                case ContentPreloadType.Other:
                    ContentManager.TryToStoreResource(id, item);
                    break;
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Failed to load file: " + id + ", " + e.Message);
            }
        }
        public void Process(ContentPreload resource, ContentResource item)
        {
            m_Lock.WaitOne();

            lock (m_Work)
            {
                resource.Item = item;
                m_Work.Add(resource);
            }
        }
        public static ContentResource GetResourceInfo(ulong ID)
        {
            /** Busy wait until we are ready **/
            while (!initComplete)
            {
                ;
            }

            ContentResource result = null;

            if (!m_LoadedResources.TryGetValue(ID, out result))
            {
                result = new ContentResource
                {
                    ID = ID
                };

                string path = m_Resources[ID];
                result.FilePath      = path;
                result.FileExtension = Path.GetExtension(path).ToLower();

                if (!path.EndsWith(".dat"))
                {
                    /** Isnt an archive **/
                    result.Data = File.ReadAllBytes(path);
                    return(result);
                }

                if (!m_Archives.ContainsKey(path))
                {
                    FAR3Archive Archive = new FAR3Archive(path);
                    m_Archives.Add(path, Archive);
                }

                result.Data = m_Archives[path].GetItemByID(ID);

                return(result);
            }
            else
            {
                return(result);
            }
        }
        /// <summary>
        /// Tries to store a resource in the internal cache.
        /// </summary>
        /// <param name="ID">The ID of the resource to store.</param>
        /// <param name="Resource">The resource to store.</param>
        public static void TryToStoreResource(ulong ID, ContentResource Resource)
        {
            lock (m_LoadedResources)
            {
                if (m_CurrentCacheSize < m_CACHESIZE)
                {
                    if (!m_LoadedResources.ContainsKey(ID))
                    {
                        m_LoadedResources.Add(ID, Resource);
                        m_CurrentCacheSize += Resource.Data.Length;
                    }
                }
                else
                {
                    ulong LastKey = m_LoadedResources.Keys.Last();

                    m_CurrentCacheSize -= m_LoadedResources[LastKey].Data.Length;
                    m_LoadedResources.Remove(LastKey);

                    m_LoadedResources.Add(ID, Resource);
                    m_CurrentCacheSize += Resource.Data.Length;
                }
            }
        }
        /// <summary>
        /// Threading function that takes care of loading.
        /// </summary>
        private static void LoadContent(object ThreadObject)
        {
            var loadingList = new List <ContentPreload>();

            /** UI Textures **/
            loadingList.AddRange(
                CollectionUtils.Select <FileIDs.UIFileIDs, ContentPreload>(
                    Enum.GetValues(typeof(FileIDs.UIFileIDs)),
                    x => new ContentPreload
            {
                ID   = (ulong)((long)x),
                Type = ContentPreloadType.Other
            }
                    )
                );



            var startTime = DateTime.Now;

            var totalItems = (float)loadingList.Count;

            loadingList.Shuffle();

            var loadingListLength = loadingList.Count;

            for (var i = 0; i < loadingListLength; i++)
            {
                var item = loadingList[i];
                try
                {
                    ContentResource contentItem = null;
                    contentItem = ContentManager.GetResourceInfo(item.ID);

                    switch (item.Type)
                    {
                    case ContentPreloadType.UITexture:
                        /** Apply alpha channel masking & load into GD **/
                        UIElement.StoreTexture(item.ID, contentItem, true, true);
                        break;

                    case ContentPreloadType.UITexture_NoMask:
                        UIElement.StoreTexture(item.ID, contentItem, false, true);
                        break;

                    case ContentPreloadType.Other:
                        ContentManager.TryToStoreResource(item.ID, contentItem);
                        break;
                    }
                }
                catch (Exception)
                {
                }

                PreloadProgress = i / totalItems;
            }

            var endTime = DateTime.Now;

            System.Diagnostics.Debug.WriteLine("Content took " + new TimeSpan(endTime.Ticks - startTime.Ticks).ToString() + " to load");

            PreloadProgress = 1.0f;
        }