Ejemplo n.º 1
0
        /// <summary>
        /// Thread safe find and add function for icon management
        /// </summary>
        private static int FindOrAddIcon(ref MOG_Properties properties, IconType iconType, string assetPropertiesName, string assetName)
        {
            // Make sure we are mutex safe
            mMutex.WaitOne();

            try
            {
                // Does this icon key exist already
                TstDictionaryEntry node = mAssetTypes.Find(assetName);
                if (node != null && node.IsKey)
                {
                    // Return the icon index then
                    return((int)node.Value);
                }
                else
                {
                    // Do we have a valid properties object?
                    if (properties == null)
                    {
                        // If we didn't get anything, we need to load this icon into our array
                        properties = new MOG_Properties(assetPropertiesName);
                    }
                    else if (properties != null && properties.AssetIcon.Length == 0 || properties.ClassIcon.Length == 0)
                    {
                        properties = new MOG_Properties(assetPropertiesName);
                    }

                    // Lets now populate our icon name to load
                    string iconName = "";

                    // What kind of icon is this?
                    switch (iconType)
                    {
                    case IconType.ASSET:
                        iconName = properties.AssetIcon;
                        break;

                    case IconType.CLASS:
                        iconName = properties.ClassIcon;
                        break;

                    default:
                        return(0);
                    }

                    // Load this icon into our list of icons and return its newly created index
                    return(LoadIcon(iconName, assetName));
                }
            }
            catch
            {
                return(0);
            }
            finally
            {
                // Realease our mutex
                mMutex.ReleaseMutex();
            }
        }
Ejemplo n.º 2
0
        /// <summary> SetAssetIcon
        /// Searches through mAssetTypes to find the matching key with
        /// that of the filename.  Then returns the index
        /// </summary>
        /// <param name="filename"></param>
        /// <returns>index of icon in the mAssetTypeImages list</returns>
        static public int GetClassIconIndex(string filename, MOG_Properties properties)
        {
            // Construct a filename
            MOG_Filename file = null;

            try
            {
                file = new MOG_Filename(filename);
            }
            catch (Exception e)
            {
                e.ToString();
                return(0);
            }

            string classification;

            switch (file.GetFilenameType())
            {
            case MOG_FILENAME_TYPE.MOG_FILENAME_Asset:
                classification = file.GetAssetClassification();
                break;

            case MOG_FILENAME_TYPE.MOG_FILENAME_Group:
                classification = "group";
                break;

            default:
                classification = filename;
                break;
            }

            try
            {
                TstDictionaryEntry node = mAssetTypes.Find(classification);
                if (node != null && node.IsKey)
                {
                    return((int)node.Value);
                }
                else
                {
                    if (properties == null)
                    {
                        // If we didn't get anything, we need to load this icon into our array
                        properties = new MOG_Properties(classification);
                    }
                    return(MogUtil_AssetIcons.LoadIcon(properties.ClassIcon, classification));
                }
            }
            catch
            {
                return(0);
            }
        }         // end ()
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the MOGAssetStatus for a given status name
        /// </summary>
        public StatusInfo GetStatusInfo(string status)
        {
            // Loops through statusInfos ArrayList in order
            // to find StatusInfo.Text that matches parameter
            // 'status'
            try
            {
                TstDictionaryEntry node = this.mStateTypes.Find(status.ToLower());
                if (node != null && node.IsKey)
                {
                    return((StatusInfo)node.Value);
                }
            }
            catch
            {
            }

            // If there was no match, return error
            return(new StatusInfo("Error", string.Empty, 0, 0));
        }
Ejemplo n.º 4
0
        static public int GetLockedBinaryIcon(string filename)
        {
            try
            {
                // Check to see if we can find this loced icon in our cache
                TstDictionaryEntry assetLocked = mAssetTypes.Find(Path.GetFileName(filename) + "_locked");
                if (assetLocked != null && assetLocked.IsKey)
                {
                    // Yup, return the index
                    return((int)assetLocked.Value);
                }
                else
                {
                    // Nope, We are going to have to create it

                    // Setup some new containers
                    Bitmap newLockedIcon   = null;
                    Bitmap lockIconSource  = null;
                    Bitmap assetIconSource = null;


                    // Can we find the locked image
                    TstDictionaryEntry nodeLocked = mAssetTypes.Find("locked");
                    if (nodeLocked != null && nodeLocked.IsKey)
                    {
                        // Great, get a copy of that
                        lockIconSource = (Bitmap)mAssetTypeImages.Images[(int)nodeLocked.Value];

                        // Now try and get the icon of this asset
                        // Have we seen this type of asset by its extension?
                        if (mFileTypeManager.ExtensionListHasKey(filename))
                        {
                            // Great get a copy of that
                            assetIconSource = (Bitmap)mFileTypeManager.GetImage(filename);
                        }
                        else
                        {
                            // No, ok try and add it from the file its self
                            if (File.Exists(filename))
                            {
                                mFileTypeManager.AddFileIcon(filename);
                                assetIconSource = (Bitmap)mFileTypeManager.GetImage(filename);
                            }
                            else
                            {
                                // Use the default icon
                                assetIconSource = (Bitmap)mAssetTypeImages.Images[0];
                            }
                        }

                        // Ok, if we got a lockSource and a class source icon, lets attempt to overlay them
                        if (assetIconSource != null && lockIconSource != null)
                        {
                            newLockedIcon = BitmapManipulator.OverlayBitmap(assetIconSource, lockIconSource, 100, BitmapManipulator.ImageCornerEnum.BottomRight);
                        }

                        // Did the overlay work?
                        if (newLockedIcon != null)
                        {
                            lock (mAssetTypes)
                            {
                                // Add the image and the type to the arrayLists
                                mAssetTypeImages.Images.Add(newLockedIcon);
                                mAssetTypes.Add(Path.GetFileName(filename) + "_locked", mAssetTypeImages.Images.Count - 1);

                                return(mAssetTypeImages.Images.Count - 1);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MOG_Report.ReportMessage("Get Locked Binary Icon", e.Message, e.StackTrace, MOG_ALERT_LEVEL.CRITICAL);
            }

            return(0);
        }
Ejemplo n.º 5
0
        static public int GetLockedAssetIcon(MOG_Filename file)
        {
            try
            {
                // Check to see if we can find this loced icon in our cache
                TstDictionaryEntry assetLocked = mAssetTypes.Find(file.GetAssetClassification() + "ASSETICON_locked");
                if (assetLocked != null)
                {
                    // Yup, return the index
                    return((int)assetLocked.Value);
                }
                else
                {
                    // Nope, We are going to have to create it

                    // Setup some new containers
                    Bitmap myImage    = null;
                    Bitmap lockSource = null;
                    Bitmap source     = null;

                    // Can we find the locked image
                    TstDictionaryEntry nodeLocked = mAssetTypes.Find("locked");
                    if (nodeLocked != null && nodeLocked.IsKey)
                    {
                        // Great, get a copy of that
                        lockSource = (Bitmap)mAssetTypeImages.Images[(int)nodeLocked.Value];

                        // Can we find the class icon for this asset
                        TstDictionaryEntry nodeSource = mAssetTypes.Find(file.GetAssetClassification() + "_ASSETICON");
                        if (nodeSource != null && nodeSource.IsKey)
                        {
                            // Great get a copy of that
                            source = (Bitmap)mAssetTypeImages.Images[(int)nodeSource.Value];
                        }
                        else
                        {
                            // If we didn't get anything, we need to load this icon into our array
                            MOG_Properties properties = new MOG_Properties(file.GetAssetClassification());
                            source = (Bitmap)mAssetTypeImages.Images[MogUtil_AssetIcons.LoadIcon(properties.AssetIcon, file.GetAssetClassification() + "_ASSETICON")];
                        }

                        // Ok, if we got a lockSource and a class source icon, lets attempt to overlay them
                        if (source != null && lockSource != null)
                        {
                            myImage = BitmapManipulator.OverlayBitmap(source, lockSource, 100, BitmapManipulator.ImageCornerEnum.BottomRight);
                        }

                        // Did the overlay work?
                        if (myImage != null)
                        {
                            lock (mAssetTypes)
                            {
                                // Add the image and the type to the arrayLists
                                mAssetTypeImages.Images.Add(myImage);
                                mAssetTypes.Add(file.GetAssetClassification() + "ASSETICON_locked", mAssetTypeImages.Images.Count - 1);

                                return(mAssetTypeImages.Images.Count - 1);
                            }
                        }
                    }
                    else
                    {
                        // Try to just turn the source icon red or something
                        string message = "We could not locate the (FileLocked.png)lock icon! Make sure that it is located in one of your images directories within the MOG repository!";
                        MOG_Report.ReportMessage("Load Icon", message, "No StackTrace available", MOG_ALERT_LEVEL.ERROR);
                    }
                }
            }
            catch (Exception e)
            {
                MOG_Report.ReportMessage("Get Locked Icon", e.Message, e.StackTrace, MOG_ALERT_LEVEL.CRITICAL);
            }

            return(0);
        }
Ejemplo n.º 6
0
        }         // end ()

        static public int GetLockedIcon(string assetName, IconType iconType, MOG_Properties properties)
        {
            try
            {
                // Check to see if we can find this loced icon in our cache
                string             lockedIconKeyName = assetName + "_" + iconType.ToString() + "_locked";
                TstDictionaryEntry assetLocked       = mAssetTypes.Find(lockedIconKeyName);
                if (assetLocked != null)
                {
                    // Yup, return the index
                    return((int)assetLocked.Value);
                }
                else
                {
                    // *******************************************
                    // Nope, We are going to have to create it
                    // *******************************************
                    // We need 3 things:
                    // 1) Lock icon
                    // 2) Asset or class icon
                    // 3) New overlayed icon

                    // Setup some new containers
                    Bitmap myImage    = null;
                    Bitmap lockSource = null;
                    Bitmap source     = null;

                    // 1) Can we find the locked image
                    TstDictionaryEntry nodeLocked = mAssetTypes.Find("locked");
                    if (nodeLocked != null && nodeLocked.IsKey)
                    {
                        // Great, get a copy of that
                        lockSource = (Bitmap)mAssetTypeImages.Images[(int)nodeLocked.Value];

                        // Do we have a valid properties object?
                        if (properties == null)
                        {
                            // If we didn't get anything, we need to load this icon into our array
                            properties = new MOG_Properties(assetName);
                        }

                        // Lets now populate our icon name to load
                        string assetIconName = "";
                        string nodeIconName  = "";

                        // What kind of icon is this?
                        switch (iconType)
                        {
                        case IconType.ASSET:
                            assetIconName = properties.AssetIcon;
                            nodeIconName  = assetName + "_ASSET";
                            break;

                        case IconType.CLASS:
                            assetIconName = properties.ClassIcon;
                            nodeIconName  = assetName + "_CLASS";
                            break;

                        default:
                            return(0);
                        }

                        // 2) Can we find the class icon for this asset
                        TstDictionaryEntry nodeSource = mAssetTypes.Find(nodeIconName);
                        if (nodeSource != null && nodeSource.IsKey)
                        {
                            // Great get a copy of that
                            source = (Bitmap)mAssetTypeImages.Images[(int)nodeSource.Value];
                        }
                        else
                        {
                            // If we didn't get anything, we need to load this icon into our array
                            int newIconIndex = LoadIcon(assetIconName, nodeIconName);
                            source = (Bitmap)mAssetTypeImages.Images[newIconIndex];
                        }

                        // 3) Ok, if we got a lockSource and a class source icon, lets attempt to overlay them
                        if (source != null && lockSource != null)
                        {
                            myImage = BitmapManipulator.OverlayBitmap(source, lockSource, 100, BitmapManipulator.ImageCornerEnum.BottomRight);
                        }

                        // Did the overlay work?
                        if (myImage != null)
                        {
                            //Debug.WriteLine("Requesting icon - " + lockedIconKeyName);
                            return(InternalAddIconToLists(lockedIconKeyName, myImage));
                        }
                    }
                    else
                    {
                        // Try to just turn the source icon red or something
                        string message = "We could not locate the (FileLocked.png)lock icon! Make sure that it is located in one of your images directories within the MOG repository!";
                        MOG_Report.ReportSilent("Load Icon", message, Environment.StackTrace, MOG_ALERT_LEVEL.ERROR);
                    }
                }
            }
            catch (Exception e)
            {
                MOG_Report.ReportSilent("Get Locked Icon", e.Message, e.StackTrace, MOG_ALERT_LEVEL.CRITICAL);
            }

            return(0);
        }