}// MenuCommand private CNode CheckForDuplicateApp(AppFiles af) { // Run through this node's children to see if a node with this app file exists int iNumChildren = NumChildren; for (int i = 0; i < iNumChildren; i++) { CNode node = CNodeManager.GetNode(Child[i]); if (node is CApplication) { AppFiles afNode = ((CApplication)node).MyAppInfo; // Check the App file's name if ((af.sAppFile == null && afNode.sAppFile == null) || af.sAppFile.Equals(afNode.sAppFile)) { // Check the App File's config file if ((af.sAppConfigFile == null && afNode.sAppConfigFile == null) || af.sAppConfigFile.Equals(afNode.sAppConfigFile)) { return(node); } } } } // We couldn't find a node with that app info return(null); }// CheckForDuplicateApp
//------------------------------------------------- // CApplication - Constructor // // Initializes some variables, and determines the icon // we'll be displaying for this application. //------------------------------------------------- internal CApplication(AppFiles appInfo) { // Standard stuff we need to set for all nodes m_sGuid = "C338CBF6-2F60-4e1b-8FB5-12FEAE2DD937"; m_sHelpSection = ""; m_appInfo = appInfo; // Let's pull the path and extension off of the application filename // so we can display just the application name to the user // We're guarenteed to have at least the config file, but not necessarily the // application file... let's get our best name String sName = (m_appInfo.sAppFile.Length > 0) ? m_appInfo.sAppFile : m_appInfo.sAppConfigFile; // Get the file description FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(sName); if (fvi.FileDescription != null && fvi.FileDescription.Length > 0 && !fvi.FileDescription.Equals(" ")) { m_sDisplayName = fvi.FileDescription; } else { String[] sWords = sName.Split(new char[] { '\\' }); m_sDisplayName = sWords[sWords.Length - 1]; } // Can't set this up until we know what our display name is m_oResults = new CApplicationTaskPad(this); // Let's try and get the icon that explorer would use to display this file m_hIcon = (IntPtr)(-1); SHFILEINFO finfo = new SHFILEINFO(); uint iRetVal = 0; // Grab an icon for this application iRetVal = SHGetFileInfo(sName, 0, out finfo, 20, SHGFI.ICON | SHGFI.SMALLICON); // If this function returned a zero, then we know it was a failure... // We'll just grab a default icon if (iRetVal == 0) { m_hIcon = CResourceStore.GetHIcon("application_ico"); m_bBigPic = new Bitmap(Bitmap.FromHicon(m_hIcon), new Size(32, 32)); } // We could get a valid icon from the shell else { m_hIcon = finfo.hIcon; // Obtain a cookie for this icon int iIconCookie = CResourceStore.StoreHIcon(m_hIcon); // Put this icon in MMC's image list CNodeManager.ConsoleImageListSetIcon(m_hIcon, iIconCookie); // We can also get the 'big' icon to use in the property page iRetVal = SHGetFileInfo(sName, 0, out finfo, 20, SHGFI.ICON); m_bBigPic = new Bitmap(Bitmap.FromHicon(finfo.hIcon)); } }// CApplication
}// CreateChildren private void MergeFusionAndMyApps(ArrayList alApps, StringCollection sc) { int nLen = sc.Count; for (int i = 0; i < nLen; i++) { if (!SearchForAppName(alApps, sc[i])) { AppFiles af = new AppFiles(); af.sAppFile = sc[i]; af.sAppConfigFile = sc[i] + ".config"; alApps.Add(af); } } }// MergeFusionAndMyApps
internal CApplicationTaskPad(CApplication n) : base(n) { m_AppFiles = n.MyAppInfo; m_sDisplayName = n.DisplayName; }// CSinglePermSetTaskPad
//------------------------------------------------- // CAppProps - Constructor // // Sets up some member variables //------------------------------------------------- internal CAppProps(AppFiles appFiles, Bitmap bBigPic) { m_appFiles = appFiles; m_sTitle = CResourceStore.GetString("CAppProps:PageTitle"); m_bBigPic = bBigPic; }// CAppProps
}// AddMenuItems internal override void MenuCommand(int iCommandID) { if (iCommandID == COMMANDS.ADD_APPLICATION) { // Pop up a dialog so the user can find an assembly CChooseAppDialog cad = new CChooseAppDialog(); System.Windows.Forms.DialogResult dr = cad.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.OK) { String sConfigFile = cad.Filename; String sAppFilename = ""; // If this is an executable or Dll, or if it is managed int iLen = sConfigFile.Length; if (iLen > 3) { String sExtension = sConfigFile.Substring(sConfigFile.Length - 3).ToUpper(CultureInfo.InvariantCulture); if (sExtension.ToUpper(CultureInfo.InvariantCulture).Equals("EXE") || sExtension.ToUpper(CultureInfo.InvariantCulture).Equals("DLL") || Fusion.isManaged(sConfigFile)) { sAppFilename = sConfigFile; // Let's add a config extension sConfigFile = sConfigFile + ".config"; } else if (iLen > 6) { // Check to see if they selected a config file sExtension = sConfigFile.Substring(sConfigFile.Length - 6).ToUpper(CultureInfo.InvariantCulture); if (sExtension.ToUpper(CultureInfo.InvariantCulture).Equals("CONFIG")) { // They've selected a config file. Let's see if there is an assembly around there as well. String sAssemName = sConfigFile.Substring(0, sConfigFile.Length - 7); if (File.Exists(sAssemName)) { sAppFilename = sAssemName; } } } } AppFiles appFile = new AppFiles(); appFile.sAppFile = sAppFilename; appFile.sAppConfigFile = sConfigFile; // Check to see if we already have this app file shown CNode node = CheckForDuplicateApp(appFile); if (node == null) { CConfigStore.SetSetting("AppConfigFiles", appFile); node = new CApplication(appFile); int iCookie = CNodeManager.AddNode(ref node); AddChild(iCookie); InsertSpecificChild(iCookie); } CNodeManager.Console.SelectScopeItem(node.HScopeItem); } } else if (iCommandID == COMMANDS.FIX_APPLICATION) { PolicyManager(CNodeManager.MMChWnd, null, null, null); } }// MenuCommand
}// CheckForDuplicateApp //------------------------------------------------- // CreateChildren // // This function creates the node's children, registers // the nodes with the node manager, and places the node's // cookies in it's child array //------------------------------------------------- internal override void CreateChildren() { // Don't bother doing any of this if we're not using MMC if (!(CNodeManager.Console is INonMMCHost)) { // Grab all the applications we know about and display the names to the // user ArrayList alApps = (ArrayList)CConfigStore.GetSetting("AppConfigFiles"); int iLen = alApps.Count; for (int i = 0; i < iLen; i++) { // Check to see if this App still exists AppFiles af = (AppFiles)alApps[i]; // We need either an exe or a config file to do this bool fHaveSomething = false; // Verify the exe still exists.... if (af.sAppFile != null && af.sAppFile.Length > 0) { if (File.Exists(af.sAppFile)) { fHaveSomething = true; } else { // The exe doesn't exist anymore. Let's update the record CConfigStore.SetSetting("RemoveAppConfigFile", af); af.sAppFile = ""; CConfigStore.SetSetting("AppConfigFiles", af); } } // Verify the config file exists if (af.sAppConfigFile != null && af.sAppConfigFile.Length > 0) { // If we don't have an exe, let's see if we can find it if ((af.sAppFile == null || af.sAppFile.Length == 0) && af.sAppConfigFile.Length > 6) { String sExtension = af.sAppConfigFile.Substring(af.sAppConfigFile.Length - 6).ToUpper(CultureInfo.InvariantCulture); if (sExtension.ToUpper(CultureInfo.InvariantCulture).Equals("CONFIG")) { // This is an appropriately named config file. Let's see if there is an assembly around there as well. String sAssemName = af.sAppConfigFile.Substring(0, af.sAppConfigFile.Length - 7); if (File.Exists(sAssemName)) { // Cool. When the user first added the application, they only had a config // file. Now they have an exe too. We'll take note of that CConfigStore.SetSetting("RemoveAppConfigFile", af); af.sAppFile = sAssemName; CConfigStore.SetSetting("AppConfigFiles", af); fHaveSomething = true; } } } // Check to see if the config file is still valid if (File.Exists(af.sAppConfigFile)) { fHaveSomething = true; } // If it doesn't exist... not a big deal. Config files could get // deleted. No worries. } // See if we snagged something to go off of if (fHaveSomething) { CNode node = new CApplication(af); int iCookie = CNodeManager.AddNode(ref node); AddChild(iCookie); } // This entry is now bogus. Get rid of it else { CConfigStore.SetSetting("RemoveAppConfigFile", af); } } } }// CreateChildren