/// <summary> /// Called publicly to add a file's icon to the ImageList. /// </summary> /// <param name="filePath">Full path to the file.</param> /// <returns>Integer of the icon's position in the ImageList</returns> public int AddFileOverlayIcon(string filePath, string overlayTagName, string overlayFilename) { // Check if the file exists, otherwise, throw exception. if (!System.IO.File.Exists(filePath)) { throw new System.IO.FileNotFoundException("File does not exist"); } // Split it down so we can get the extension string[] splitPath = filePath.Split(new Char[] { '.' }); string extension = (string)splitPath.GetValue(splitPath.GetUpperBound(0)); // Add in the special overlay tag name to the extension name extension = "{" + overlayTagName + "}" + extension; //Check that we haven't already got the extension, if we have, then //return back its index if (_extensionList.ContainsKey(extension.ToUpper())) { return((int)_extensionList[extension.ToUpper()]); //return existing index } else { // It's not already been added, so add it and record its position. int pos = ((ImageList)_imageLists[0]).Images.Count; //store current count -- new item's index if (ManageBothSizes == true) { //managing two lists, so add it to small first, then large ((ImageList)_imageLists[0]).Images.Add(IconReader.GetFileIcon(filePath, IconReader.IconSize.Small, false)); ((ImageList)_imageLists[1]).Images.Add(IconReader.GetFileIcon(filePath, IconReader.IconSize.Large, false)); } else { Bitmap myImage = null; // Great, get a copy of that Bitmap lockSource = new Bitmap(overlayFilename); // Great get a copy of that Bitmap source = IconReader.GetFileIcon(filePath, _iconSize, false).ToBitmap(); // 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); } //only doing one size, so use IconSize as specified in _iconSize. ((ImageList)_imageLists[0]).Images.Add(myImage); //add to image list } AddExtension(extension.ToUpper(), pos); // add to hash table return(pos); } }
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); }
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); }
} // 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); }