public virtual int UpdateProperty(uint commandId, ref PropertyKey key, PropVariantRef currentValue, out PropVariant newValue)
        {
            Command command = ParentCommandManager.Get((CommandId)commandId);
            if (command == null)
            {
                return NullCommandUpdateProperty(commandId, ref key, currentValue, out newValue);
            }

            try
            {
                newValue = new PropVariant();
                command.GetPropVariant(key, currentValue, ref newValue);

                if (newValue.IsNull())
                {
                    Trace.Fail("Didn't property update property for " + PropertyKeys.GetName(key) + " on command " + ((CommandId)commandId).ToString());

                    newValue = PropVariant.FromObject(currentValue.PropVariant.Value);
                }
            }
            catch (Exception ex)
            {
                Trace.Fail("Exception in UpdateProperty for " + PropertyKeys.GetName(key) + " on command " + commandId + ": " + ex);
                newValue = PropVariant.FromObject(currentValue.PropVariant.Value);
            }

            return HRESULT.S_OK;
        }
 public static ManagedPropVariant FromPropVariant(PropVariant propVariant)
 {
     // Do a bitwise copy from the PropVariant that was passed in.
     ManagedPropVariant managedPropVariant = new ManagedPropVariant();
     UnsafeNativeMethods.CopyFromPropVariant(out managedPropVariant, ref propVariant);
     return managedPropVariant;
 }
        internal SearchCondition(ICondition nativeSearchCondition)
        {
            if (nativeSearchCondition == null)
            {
                throw new ArgumentNullException("nativeSearchCondition");
            }

            NativeSearchCondition = nativeSearchCondition;

            HResult hr = NativeSearchCondition.GetConditionType(out conditionType);

            if (!CoreErrorHelper.Succeeded(hr))
            {
                throw new ShellException(hr);
            }

            if (ConditionType == SearchConditionType.Leaf)
            {
                using (PropVariant propVar = new PropVariant())
                {
                    hr = NativeSearchCondition.GetComparisonInfo(out canonicalName, out conditionOperation, propVar);

                    if (!CoreErrorHelper.Succeeded(hr))
                    {
                        throw new ShellException(hr);
                    }

                    PropertyValue = propVar.Value.ToString();
                }
            }
        }
Exemplo n.º 4
0
        private void InstallShortcut(String shortcutPath)
        {
            // Find the path to the current executable
            String exePath = Process.GetCurrentProcess().MainModule.FileName;
            IShellLinkW newShortcut = (IShellLinkW)new CShellLink();

            // Create a shortcut to the exe
            ShellHelpers.ErrorHelper.VerifySucceeded(newShortcut.SetPath(exePath));
            ShellHelpers.ErrorHelper.VerifySucceeded(newShortcut.SetArguments(""));

            // Open the shortcut property store, set the AppUserModelId property
            IPropertyStore newShortcutProperties = (IPropertyStore)newShortcut;

            using (PropVariant appId = new PropVariant(APP_ID))
            {
                ShellHelpers.ErrorHelper.VerifySucceeded(
                    newShortcutProperties.SetValue(SystemProperties.System.AppUserModel.ID, appId));
                ShellHelpers.ErrorHelper.VerifySucceeded(newShortcutProperties.Commit());
            }

            // Commit the shortcut to disk
            IPersistFile newShortcutSave = (IPersistFile)newShortcut;

            ShellHelpers.ErrorHelper.VerifySucceeded(newShortcutSave.Save(shortcutPath, true));
        }
 /// <summary>
 /// Creates a leaf condition node that represents a comparison of property value and constant value. 
 /// Overload method takes a DateTime parameter for the comparison value.
 /// </summary>
 /// <param name="propertyName">The name of a property to be compared, or null for an unspecified property. 
 /// The locale name of the leaf node is LOCALE_NAME_USER_DEFAULT.</param>
 /// <param name="value">The DateTime value against which the property value should be compared.</param>
 /// <param name="operation">Specific condition to be used when comparing the actual value and the expected value of the given property</param>
 /// <returns>SearchCondition based on the given parameters</returns>
 /// <remarks>
 /// The search will only work for files that are indexed, as well as the specific properties are indexed. To find 
 /// the properties that are indexed, look for the specific property's property description and 
 /// <see cref="P:Microsoft.WindowsAPICodePack.Shell.PropertySystem.ShellPropertyDescription.TypeFlags"/> property for IsQueryable flag.
 /// </remarks>
 public static SearchCondition CreateLeafCondition(string propertyName, DateTime value, SearchConditionOperation operation)
 {
     using (PropVariant propVar = new PropVariant(value))
     {
         return CreateLeafCondition(propertyName, propVar, "System.StructuredQuery.CustomProperty.DateTime", operation);
     }
 }
 public static PropVariant ToPropVariant(ManagedPropVariant managedPropVariant)
 {
     // Do a bitwise copy from the ManagedPropVariant that was passed in.
     PropVariant propVariant = new PropVariant();
     UnsafeNativeMethods.CopyToPropVariant(out propVariant, ref managedPropVariant);
     return propVariant;
 }
 /// <summary>
 /// Creates a leaf condition node that represents a comparison of property value and constant value. 
 /// </summary>
 /// <param name="propertyName">The name of a property to be compared, or null for an unspecified property. 
 /// The locale name of the leaf node is LOCALE_NAME_USER_DEFAULT.</param>
 /// <param name="value">The constant value against which the property value should be compared.</param>
 /// <param name="operation">Specific condition to be used when comparing the actual value and the expected value of the given property</param>
 /// <returns>SearchCondition based on the given parameters</returns>
 /// <remarks>
 /// The search will only work for files that are indexed, as well as the specific properties are indexed. To find 
 /// the properties that are indexed, look for the specific property's property description and 
 /// <see cref="P:Microsoft.WindowsAPICodePack.Shell.PropertySystem.ShellPropertyDescription.TypeFlags"/> property for IsQueryable flag.
 /// </remarks>
 public static SearchCondition CreateLeafCondition(string propertyName, string value, SearchConditionOperation operation)
 {
     using (PropVariant propVar = new PropVariant(value))
     {
         return CreateLeafCondition(propertyName, propVar, null, operation);
     }
 }
        /// <summary>
        /// Creates a leaf condition node that represents a comparison of property value and constant value. 
        /// </summary>
        /// <param name="propertyName">The name of a property to be compared, or null for an unspecified property. 
        /// The locale name of the leaf node is LOCALE_NAME_USER_DEFAULT.</param>
        /// <param name="value">The constant value against which the property value should be compared.</param>
        /// <param name="operation">Specific condition to be used when comparing the actual value and the expected value of the given property</param>
        /// <returns>SearchCondition based on the given parameters</returns>
        /// <remarks>
        /// The search will only work for files that are indexed, as well as the specific properties are indexed. To find 
        /// the properties that are indexed, look for the specific property's property description and 
        /// <see cref="P:Microsoft.WindowsAPICodePack.Shell.PropertySystem.ShellPropertyDescription.TypeFlags"/> property for IsQueryable flag.
        /// </remarks>
        public static SearchCondition CreateLeafCondition(string propertyName, string value, SearchConditionOperation operation)
        {
            PropVariant propVar = new PropVariant();
            propVar.SetString(value);

            return CreateLeafCondition(propertyName, propVar, null, operation);
        }
        /// <summary>
        /// Creates a leaf condition node that represents a comparison of property value and Integer value. 
        /// </summary>
        /// <param name="propertyName">The name of a property to be compared, or null for an unspecified property. 
        /// The locale name of the leaf node is LOCALE_NAME_USER_DEFAULT.</param>
        /// <param name="value">The Integer value against which the property value should be compared.</param>
        /// <param name="operation">Specific condition to be used when comparing the actual value and the expected value of the given property</param>
        /// <returns>SearchCondition based on the given parameters</returns>
        /// <remarks>
        /// The search will only work for files that are indexed, as well as the specific properties are indexed. To find 
        /// the properties that are indexed, look for the specific property's property description and 
        /// <see cref="P:Microsoft.WindowsAPICodePack.Shell.PropertySystem.ShellPropertyDescription.TypeFlags"/> property for IsQueryable flag.
        /// </remarks>
        public static SearchCondition CreateLeafCondition(string propertyName, int value, SearchConditionOperation operation)
        {
            PropVariant propVar = new PropVariant();
            propVar.SetInt(value);

            return CreateLeafCondition(propertyName, propVar, "System.StructuredQuery.CustomProperty.Integer", operation);
        }
 public override void GetPropVariant(PropertyKey key, PropVariantRef currentValue, ref PropVariant value)
 {
     if (key == PropertyKeys.ContextAvailable)
     {
         value.SetUInt((uint)ContextAvailability);
     }
     else
         base.GetPropVariant(key, currentValue, ref value);
 }
Exemplo n.º 11
0
            public static PropVariant FromString(string str)
            {
                var pv = new PropVariant() {
                    variantType = 31,  // VT_LPWSTR
                    pointerValue = Marshal.StringToCoTaskMemUni(str),
                };

                return pv;
            }
Exemplo n.º 12
0
        public void FromObjectNullTest()
        {
            using (PropVariant pv = new PropVariant())
            {

                Assert.True(pv.IsNullOrEmpty);
                Assert.Equal(VarEnum.VT_EMPTY, pv.VarType);
                Assert.Null(pv.Value);
            }
        }
Exemplo n.º 13
0
        internal static void SetWindowProperty(IntPtr hwnd, PropertyKey propkey, string value)
        {
            // Get the IPropertyStore for the given window handle
            IPropertyStore propStore = GetWindowPropertyStore(hwnd);

            // Set the value
            PropVariant pv = new PropVariant();
            propStore.SetValue(ref propkey, ref pv);

            // Dispose the IPropertyStore and PropVariant
            Marshal.ReleaseComObject(propStore);
            pv.Clear();
        }
Exemplo n.º 14
0
        public HRESULT GetValue(ref PropertyKey key, out PropVariant value)
        {
            if (key == RibbonProperties.Label)
            {
                if ((style.Title == null) || (style.Title.Trim() == string.Empty))
                {
                    value = PropVariant.Empty;
                }
                else
                {
                    value = PropVariant.FromObject(style.Title);
                }
                return HRESULT.S_OK;
            }

            if (key == RibbonProperties.CategoryID)
            {
                if (categoryId.HasValue)
                {
                    value = PropVariant.FromObject(categoryId.Value);
                }
                else
                {
                    value = PropVariant.Empty;
                }
                return HRESULT.S_OK;
            }

            if (key == RibbonProperties.ItemImage)
            {
                if (itemImage != null)
                {
                    value = new PropVariant();
                    value.SetIUnknown(itemImage);
                }
                else
                {
                    value = PropVariant.Empty;
                }
                return HRESULT.S_OK;
            }

            Debug.WriteLine("Class {0} does not support property: {1}.", GetType().ToString(), RibbonProperties.GetPropertyKeyName(ref key));

            value = PropVariant.Empty;
            return HRESULT.E_NOTIMPL;
        }
        private static void ListOrExtract(string archiveName, uint level)
        {
            using (SevenZipFormat Format = new SevenZipFormat(SevenZipDllPath))
            {
            IInArchive Archive = Format.CreateInArchive(SevenZipFormat.GetClassIdFromKnownFormat(KnownSevenZipFormat.Zip));
            if (Archive == null)
                return;

            try
            {
                using (InStreamWrapper ArchiveStream = new InStreamWrapper(File.OpenRead(archiveName)))
                {
                    IArchiveOpenCallback OpenCallback = new ArchiveOpenCallback();

                    // 32k CheckPos is not enough for some 7z archive formats
                    ulong CheckPos = 128 * 1024;
                    if (Archive.Open(ArchiveStream, ref CheckPos, OpenCallback) != 0)
                        //ShowHelp();
                    if (!Directory.Exists(@"tmp_dir"))
                        Directory.CreateDirectory(@"tmp_dir");

                    //Console.WriteLine(archiveName);

                    uint Count = Archive.GetNumberOfItems();
                    for (uint I = 0; I < Count; I++)
                    {
                        PropVariant Name = new PropVariant();
                        Archive.GetProperty(I, ItemPropId.kpidPath, ref Name);
                        string FileName = (string)Name.GetObject();
                        Program.f1.label1.Text = FileName;
                        Application.DoEvents();
                        for(int i = 0; i < level; i++)
                            Console.Write("\t");
                        Console.Write(FileName + "\n");
                        FileName += level;
                        Archive.Extract(new uint[] { I }, 1, 0, new ArchiveExtractCallback(I, FileName));
                        Program.Determine_Parser(new System.IO.FileInfo("tmp_dir//" + FileName), level);
                    }
                }
            }
            finally
            {
                Marshal.ReleaseComObject(Archive);
                Directory.Delete(@"tmp_dir", true);
            }
            }
        }
        public HRESULT GetValue(ref PropertyKey key, out PropVariant value)
        {
            if (key == RibbonProperties.Label)
            {
                if ((_label == null) || (_label.Trim() == string.Empty))
                {
                    value = PropVariant.Empty;
                }
                else
                {
                    value = PropVariant.FromObject(_label);
                }
                return HRESULT.S_OK;
            }

            if (key == RibbonProperties.LabelDescription)
            {
                if ((_labelDescription == null) || (_labelDescription.Trim() == string.Empty))
                {
                    value = PropVariant.Empty;
                }
                else
                {
                    value = PropVariant.FromObject(_labelDescription);
                }
                return HRESULT.S_OK;
            }

            if (key == RibbonProperties.Pinned)
            {
                if (_pinned.HasValue)
                {
                    value = PropVariant.FromObject(_pinned.Value);
                }
                else
                {
                    value = PropVariant.Empty;
                }
                return HRESULT.S_OK;
            }

            Debug.WriteLine(string.Format("Class {0} does not support property: {1}.", GetType().ToString(), RibbonProperties.GetPropertyKeyName(ref key)));

            value = PropVariant.Empty;
            return HRESULT.E_NOTIMPL;
        }
        public HRESULT GetValue(ref PropertyKey key, out PropVariant value)
        {
            if (key == RibbonProperties.CommandID)
            {
                if (_commandID.HasValue)
                {
                    value = PropVariant.FromObject(_commandID.Value);
                }
                else
                {
                    value = PropVariant.Empty;
                }
                return HRESULT.S_OK;
            }

            if (key == RibbonProperties.CommandType)
            {
                if (_commandType.HasValue)
                {
                    value = PropVariant.FromObject((uint)_commandType.Value);
                }
                else
                {
                    value = PropVariant.Empty;
                }
                return HRESULT.S_OK;
            }

            if (key == RibbonProperties.CategoryID)
            {
                if (_categoryID.HasValue)
                {
                    value = PropVariant.FromObject(_categoryID.Value);
                }
                else
                {
                    value = PropVariant.Empty;
                }
                return HRESULT.S_OK;
            }

            Debug.WriteLine(string.Format("Class {0} does not support property: {1}.", GetType(), RibbonProperties.GetPropertyKeyName(ref key)));

            value = PropVariant.Empty;
            return HRESULT.E_NOTIMPL;
        }
Exemplo n.º 18
0
        public static void CreateImagePropVariant(Image image, out PropVariant pv)
        {
            try
            {
                pv = new PropVariant();

                // Note that the missing image is a 32x32 png.
                if (image == null)
                    image = Images.Missing_LargeImage;

                pv.SetIUnknown(CreateImage(((Bitmap)image).GetHbitmap(), ImageCreationOptions.Transfer));
            }
            catch (Exception ex)
            {
                Trace.Fail("Failed to create image PropVariant: " + ex);
                pv = new PropVariant();
            }
        }
        public ManagedPropVariant GetSetting(ContentEditorSetting setting)
        {
            switch (setting)
            {
                case ContentEditorSetting.MshtmlOptionKeyPath:
                    return ManagedPropVariant.FromPropVariant(GetMshtmlOptionKeyPath());

                case ContentEditorSetting.ImageDefaultSize:
                    return ManagedPropVariant.FromPropVariant(GetImageDefaultSize());

                case ContentEditorSetting.Language:
                    return ManagedPropVariant.FromPropVariant(GetLanguage());

                default:
                    Debug.Fail("Unexpected ContentEditorSetting!");
                    PropVariant propVariant = new PropVariant();
                    propVariant.SetError();
                    return ManagedPropVariant.FromPropVariant(propVariant);
            }
        }
Exemplo n.º 20
0
        private static void InstallShortcut(string shortcutPath)
        {
            var exePath = Process.GetCurrentProcess().MainModule.FileName;
            var newShortcut = (IShellLinkW)new CShellLink();

            ErrorHelper.VerifySucceeded(newShortcut.SetPath(exePath));
            ErrorHelper.VerifySucceeded(newShortcut.SetArguments(""));

            var newShortcutProperties = (IPropertyStore)newShortcut;

            using (var appId = new PropVariant(Toast.AppId))
            {
                ErrorHelper.VerifySucceeded(newShortcutProperties.SetValue(SystemProperties.System.AppUserModel.ID, appId));
                ErrorHelper.VerifySucceeded(newShortcutProperties.Commit());
            }

            var newShortcutSave = (IPersistFile)newShortcut;

            ErrorHelper.VerifySucceeded(newShortcutSave.Save(shortcutPath, true));
        }
Exemplo n.º 21
0
        internal SearchCondition(ICondition nativeSearchCondition)
        {
            if (nativeSearchCondition == null) throw new ArgumentNullException("nativeSearchCondition");

            NativeSearchCondition = nativeSearchCondition;

            HResult hr = NativeSearchCondition.GetConditionType(out conditionType);

            if (hr != HResult.S_OK) return;

            if (ConditionType == SearchConditionType.Leaf)
            {
                using (var propVar = new PropVariant())
                {
                    hr = NativeSearchCondition.GetComparisonInfo(out canonicalName, out conditionOperation, propVar);

                    if (hr != HResult.S_OK) return;

                    PropertyValue = propVar.Value.ToString();
                }
            }
        }
Exemplo n.º 22
0
        private static void InstallShortcut(string exePath, string shortcutPath, string appId)
        {
            IShellLinkW newShortcut = (IShellLinkW)new CShellLink();

            // Create a shortcut to the exe
            ShellHelpers.ErrorHelper.VerifySucceeded(newShortcut.SetPath(exePath));
            ShellHelpers.ErrorHelper.VerifySucceeded(newShortcut.SetArguments(""));

            // Open the shortcut property store, set the AppUserModelId property
            IPropertyStore newShortcutProperties = (IPropertyStore)newShortcut;

            using (PropVariant appIdProperty = new PropVariant(appId))
            {
                ShellHelpers.ErrorHelper.VerifySucceeded(newShortcutProperties.SetValue(SystemProperties.System.AppUserModel.ID, appIdProperty));
                ShellHelpers.ErrorHelper.VerifySucceeded(newShortcutProperties.Commit());
            }

            // Commit the shortcut to disk
            IPersistFile newShortcutSave = (IPersistFile)newShortcut;

            ShellHelpers.ErrorHelper.VerifySucceeded(newShortcutSave.Save(shortcutPath, true));
        }
Exemplo n.º 23
0
        /// <summary>
        /// Handles IUICommandHandler.UpdateProperty function for the supported properties
        /// </summary>
        /// <param name="key">The Property Key to update</param>
        /// <param name="currentValue">A pointer to the current value for key. This parameter can be NULL</param>
        /// <param name="newValue">When this method returns, contains a pointer to the new value for key</param>
        /// <returns>Returns S_OK if successful, or an error value otherwise</returns>
        public override HRESULT UpdateProperty(ref PropertyKey key, PropVariantRef currentValue, ref PropVariant newValue)
        {
            if (key == RibbonProperties.AutomaticColorLabel)
            {
                if (_automaticColorLabel != null)
                {
                    newValue.SetString(_automaticColorLabel);
                }
            }
            else if (key == RibbonProperties.Color)
            {
                if (_color.HasValue)
                {
                    newValue.SetUInt((uint)ColorTranslator.ToWin32(_color.Value));
                }
            }
            else if (key == RibbonProperties.ColorType)
            {
                if (_colorType.HasValue)
                {
                    newValue.SetUInt((uint)_colorType.Value);
                }
            }
            else if (key == RibbonProperties.MoreColorsLabel)
            {
                if (_moreColorsLabel != null)
                {
                    newValue.SetString(_moreColorsLabel);
                }
            }
            else if (key == RibbonProperties.NoColorLabel)
            {
                if (_noColorLabel != null)
                {
                    newValue.SetString(_noColorLabel);
                }
            }
            else if (key == RibbonProperties.RecentColorsCategoryLabel)
            {
                if (_recentColorsCategoryLabel != null)
                {
                    newValue.SetString(_recentColorsCategoryLabel);
                }
            }
            else if (key == RibbonProperties.StandardColors)
            {
                if (_standardColors != null)
                {
                    int[] intStandardColors = Array.ConvertAll<Color, int>(_standardColors, new Converter<Color, int>(ColorTranslator.ToWin32));
                    uint[] uintStandardColors = Array.ConvertAll<int, uint>(intStandardColors, new Converter<int, uint>(Convert.ToUInt32));
                    newValue.SetUIntVector(uintStandardColors);
                }
            }
            else if (key == RibbonProperties.StandardColorsCategoryLabel)
            {
                if (_standardColorsCategoryLabel != null)
                {
                    newValue.SetString(_standardColorsCategoryLabel);
                }
            }
            else if (key == RibbonProperties.StandardColorsTooltips)
            {
                if (_standardColorsTooltips != null)
                {
                    newValue.SetStringVector(_standardColorsTooltips);
                }
            }
            else if (key == RibbonProperties.ThemeColors)
            {
                if (_themeColors != null)
                {
                    int[] intThemeColors = Array.ConvertAll<Color, int>(_themeColors, new Converter<Color, int>(ColorTranslator.ToWin32));
                    uint[] uintThemeColors = Array.ConvertAll<int, uint>(intThemeColors, new Converter<int, uint>(Convert.ToUInt32));
                    newValue.SetUIntVector(uintThemeColors);
                }
            }
            else if (key == RibbonProperties.ThemeColorsCategoryLabel)
            {
                if (_themeColorsCategoryLabel != null)
                {
                    newValue.SetString(_themeColorsCategoryLabel);
                }
            }
            else if (key == RibbonProperties.ThemeColorsTooltips)
            {
                if (_themeColorsTooltips != null)
                {
                    newValue.SetStringVector(_themeColorsTooltips);
                }
            }

            return HRESULT.S_OK;
        }
Exemplo n.º 24
0
        public override bool RunBody(State state)
        {
            RequirePropertyHandlerRegistered();
            RequireExtHasHandler();

            string       propertyName1 = "System.Comment";
            const string cval1         = "comment";
            const string cval1a        = "commenta";
            Guid         format1       = new Guid("F29F85E0-4FF9-1068-AB91-08002B27B3D9");
            int          id1           = 6;

            string       propertyName2 = "System.Title";
            const string cval2         = "title";
            const string cval2a        = "titlea";
            Guid         format2       = new Guid("F29F85E0-4FF9-1068-AB91-08002B27B3D9");
            int          id2           = 2;

            //Create a temp file to put metadata on
            string fileName = CreateFreshFile(1);

            // Use API Code Pack to set the values
            IShellProperty prop1 = ShellObject.FromParsingName(fileName).Properties.GetProperty(propertyName1);

            (prop1 as ShellProperty <string>).Value = cval1;
            IShellProperty prop2 = ShellObject.FromParsingName(fileName).Properties.GetProperty(propertyName2);

            (prop2 as ShellProperty <string>).Value = cval2;

            var handler = new CPropertyHandler();

            handler.Initialize(fileName, 0);

            // Read the values with the Property Handler
            PropVariant getvalue1 = new PropVariant();
            PropVariant getvalue2 = new PropVariant();

            handler.GetValue(new TestDriverCodePack.PropertyKey(format1, id1), getvalue1);
            handler.GetValue(new TestDriverCodePack.PropertyKey(format2, id2), getvalue2);
            string result1 = (string)getvalue1.Value;
            string result2 = (string)getvalue2.Value;

            if (result1 != cval1 || result2 != cval2)
            {
                return(false);
            }

            // Set the values with the Property Handler
            PropVariant value1 = new PropVariant(cval1a);
            PropVariant value2 = new PropVariant(cval2a);

            // System.Comment
            handler.SetValue(new TestDriverCodePack.PropertyKey(format1, id1), value1);
            // System.Category
            handler.SetValue(new TestDriverCodePack.PropertyKey(format2, id2), value2);
            handler.Commit();

            // Read the updated values with the Property Handler
            getvalue1 = new PropVariant();
            getvalue2 = new PropVariant();
            handler.GetValue(new TestDriverCodePack.PropertyKey(format1, id1), getvalue1);
            handler.GetValue(new TestDriverCodePack.PropertyKey(format2, id2), getvalue2);
            result1 = (string)getvalue1.Value;
            result2 = (string)getvalue2.Value;

            Marshal.ReleaseComObject(handler); // preempt GC for CCW

            File.Delete(fileName);             // only works if all have let go of the file

            return(result1 == cval1a && result2 == cval2a);
        }
Exemplo n.º 25
0
        /// <summary>
        /// Handles IUICommandHandler.UpdateProperty function for the supported properties
        /// </summary>
        /// <param name="key">The Property Key to update</param>
        /// <param name="currentValue">A pointer to the current value for key. This parameter can be NULL</param>
        /// <param name="newValue">When this method returns, contains a pointer to the new value for key</param>
        /// <returns>Returns S_OK if successful, or an error value otherwise</returns>
        public override HRESULT UpdateProperty(ref PropertyKey key, PropVariantRef currentValue, ref PropVariant newValue)
        {
            if (key == RibbonProperties.TooltipTitle)
            {
                if (_tooltipTitle != null)
                {
                    newValue.SetString(_tooltipTitle);
                }
            }
            else if (key == RibbonProperties.TooltipDescription)
            {
                if (_tooltipDescription != null)
                {
                    newValue.SetString(_tooltipDescription);
                }
            }

            return HRESULT.S_OK;
        }
Exemplo n.º 26
0
        public int UpdateProperty(uint commandId, ref PropertyKey key, PropVariantRef currentValue, out PropVariant newValue)
        {
            try
            {
                Command command = Get((CommandId)commandId);
                if (command == null)
                {
                    return(genericCommandHandler.NullCommandUpdateProperty(commandId, ref key, currentValue, out newValue));
                }

                return(command.UpdateProperty(ref key, currentValue, out newValue));
            }
            catch (Exception ex)
            {
                Debug.Fail("Exception throw in CommandManager.UpdateProperty: " + ex + "\r\n\r\nCommand: " + commandId + " Key: " + PropertyKeys.GetName(key));
                throw;
            }
        }
Exemplo n.º 27
0
 public int GetUICommandProperty(uint commandId, ref PropertyKey key, out PropVariant value)
 {
     value = PropVariant.Empty;
     return(0);
 }
Exemplo n.º 28
0
 internal PropertyStoreProperty(PropertyKey key, PropVariant value)
 {
     _PropertyKey = key;
     propValue    = value;
 }
Exemplo n.º 29
0
 internal static extern uint InitPropVariantFromFileTime([In] ref System.Runtime.InteropServices.ComTypes.FILETIME pftIn, out PropVariant ppropvar);
Exemplo n.º 30
0
 internal static extern void PropVariantGetUInt64Elem([In] ref PropVariant propVar, [In] uint iElem, [Out] out UInt64 pnVal);
Exemplo n.º 31
0
 internal static extern void PropVariantGetDoubleElem([In] ref PropVariant propVar, [In] uint iElem, [Out] out double pnVal);
Exemplo n.º 32
0
 internal static extern void PropVariantGetInt32Elem([In] ref PropVariant propVar, [In] uint iElem, [Out] out int pnVal);
Exemplo n.º 33
0
 internal static extern void PropVariantGetBooleanElem([In] ref PropVariant propVar, [In] uint iElem, [Out, MarshalAs(UnmanagedType.Bool)] out bool pfVal);
Exemplo n.º 34
0
 internal static extern int PropVariantGetElementCount([In] ref PropVariant propVar);
Exemplo n.º 35
0
 internal static extern void InitPropVariantFromDoubleVector([In, Out] double[] prgn, uint cElems, [Out] PropVariant propvar);
Exemplo n.º 36
0
 private extern static void PropVariantClear([In, Out] PropVariant pvar); // Or ref
Exemplo n.º 37
0
 internal PropertyStoreProperty(PropertyKey key, PropVariant value)
 {
     propertyKey = key;
     propertyValue = value;
 }
Exemplo n.º 38
0
 internal static extern void InitPropVariantFromInt32Vector([In, Out] Int32[] prgn, uint cElems, [Out] PropVariant propVar);
Exemplo n.º 39
0
        public override void GetPropVariant(PropertyKey key, PropVariantRef currentValue, ref PropVariant value)
        {
            if (key == PropertyKeys.LabelDescription)
            {
                // In order to vertically align the label title, we need to return an error for the label description.
                value.SetError();
                return;
            }

            base.GetPropVariant(key, currentValue, ref value);
        }
Exemplo n.º 40
0
 internal static extern void InitPropVariantFromUInt16Vector([In, Out] UInt16[] prgn, uint cElems, out PropVariant ppropvar);
Exemplo n.º 41
0
 public int SetUICommandProperty(uint commandId, ref PropertyKey key, ref PropVariant value)
 {
     return(0);
 }
Exemplo n.º 42
0
        /// <summary>
        /// Implementation of IUICommandHandler.UpdateProperty
        /// Responds to property update requests from the Windows Ribbon (Ribbon) framework.
        /// </summary>
        /// <param name="commandID">The ID for the Command, which is specified in the Markup resource file</param>
        /// <param name="key">The Property Key to update</param>
        /// <param name="currentValue">A pointer to the current value for key. This parameter can be NULL</param>
        /// <param name="newValue">When this method returns, contains a pointer to the new value for key</param>
        /// <returns>Returns S_OK if successful, or an error value otherwise</returns>
        /// <remarks>This method is used internally by the Ribbon class and should not be called by the user.</remarks>
        public virtual HRESULT UpdateProperty(uint commandID, ref PropertyKey key, PropVariantRef currentValue, ref PropVariant newValue)
        {
#if DEBUG
            //Debug.WriteLine(string.Format("UpdateProperty key: {0} for command {1}", RibbonProperties.GetPropertyKeyName(ref key), commandID));
#endif

            if (_mapRibbonControls.ContainsKey(commandID))
            {
                return(_mapRibbonControls[commandID].UpdateProperty(ref key, currentValue, ref newValue));
            }

            return(HRESULT.S_OK);
        }
        /// <summary>
        /// Handles IUICommandHandler.UpdateProperty function for the supported properties
        /// </summary>
        /// <param name="key">The Property Key to update</param>
        /// <param name="currentValue">A pointer to the current value for key. This parameter can be NULL</param>
        /// <param name="newValue">When this method returns, contains a pointer to the new value for key</param>
        /// <returns>Returns S_OK if successful, or an error value otherwise</returns>
        public override HRESULT UpdateProperty(ref PropertyKey key, PropVariantRef currentValue, ref PropVariant newValue)
        {
            if (key == RibbonProperties.Categories)
            {
                if (CategoriesReady != null)
                {
                    CategoriesReady(_sender, EventArgs.Empty);
                }
            }
            else if (key == RibbonProperties.ItemsSource)
            {
                if (ItemsSourceReady != null)
                {
                    ItemsSourceReady(_sender, EventArgs.Empty);
                }
            }
            else if (key == RibbonProperties.SelectedItem)
            {
                if (_selectedItem.HasValue)
                {
                    newValue.SetUInt(_selectedItem.Value);
                }
            }

            return(HRESULT.S_OK);
        }
        /// <summary>
        /// Handles IUICommandHandler.UpdateProperty function for the supported properties
        /// </summary>
        /// <param name="key">The Property Key to update</param>
        /// <param name="currentValue">A pointer to the current value for key. This parameter can be NULL</param>
        /// <param name="newValue">When this method returns, contains a pointer to the new value for key</param>
        /// <returns>Returns S_OK if successful, or an error value otherwise</returns>
        public override HRESULT UpdateProperty(ref PropertyKey key, PropVariantRef currentValue, ref PropVariant newValue)
        {
            if (key == RibbonProperties.RecentItems)
            {
                if (_recentItems != null)
                {
                    newValue.SetSafeArray(_recentItems.ToArray());
                }
            }

            return(HRESULT.S_OK);
        }
Exemplo n.º 45
0
 internal static extern void InitPropVariantFromFileTimeVector([In, Out] System.Runtime.InteropServices.ComTypes.FILETIME[] prgft, uint cElems, [Out] PropVariant ppropvar);
        /// <summary>
        /// Handles IUICommandHandler.UpdateProperty function for the supported properties
        /// </summary>
        /// <param name="key">The Property Key to update</param>
        /// <param name="currentValue">A pointer to the current value for key. This parameter can be NULL</param>
        /// <param name="newValue">When this method returns, contains a pointer to the new value for key</param>
        /// <returns>Returns S_OK if successful, or an error value otherwise</returns>
        public override HRESULT UpdateProperty(ref PropertyKey key, PropVariantRef currentValue, ref PropVariant newValue)
        {
            if (key == RibbonProperties.FontProperties)
            {
                if (currentValue != null)
                {
                    // get current font properties
                    IPropertyStore fontProperties = (IPropertyStore)currentValue.PropVariant.Value;

                    // set family
                    if ((_family == null) || (_family.Trim() == string.Empty))
                    {
                        PropVariant propFamily = PropVariant.Empty;
                        fontProperties.SetValue(ref RibbonProperties.FontProperties_Family, ref propFamily);
                    }
                    else
                    {
                        PropVariant propFamily = PropVariant.FromObject(_family);
                        fontProperties.SetValue(ref RibbonProperties.FontProperties_Family, ref propFamily);
                    }

                    // set size
                    if (_size.HasValue)
                    {
                        PropVariant propSize = PropVariant.FromObject(_size.Value);
                        fontProperties.SetValue(ref RibbonProperties.FontProperties_Size, ref propSize);
                    }

                    // set bold
                    if (_bold.HasValue)
                    {
                        PropVariant propBold = PropVariant.FromObject((uint)_bold.Value);
                        fontProperties.SetValue(ref RibbonProperties.FontProperties_Bold, ref propBold);
                    }

                    // set italic
                    if (_italic.HasValue)
                    {
                        PropVariant propItalic = PropVariant.FromObject((uint)_italic.Value);
                        fontProperties.SetValue(ref RibbonProperties.FontProperties_Italic, ref propItalic);
                    }

                    // set underline
                    if (_underline.HasValue)
                    {
                        PropVariant propUnderline = PropVariant.FromObject((uint)_underline.Value);
                        fontProperties.SetValue(ref RibbonProperties.FontProperties_Underline, ref propUnderline);
                    }

                    // set strikethrough
                    if (_strikethrough.HasValue)
                    {
                        PropVariant propStrikethrough = PropVariant.FromObject((uint)_strikethrough.Value);
                        fontProperties.SetValue(ref RibbonProperties.FontProperties_Strikethrough, ref propStrikethrough);
                    }

                    // set foregroundColor
                    if (_foregroundColor.HasValue)
                    {
                        PropVariant propForegroundColor = PropVariant.FromObject((uint)ColorTranslator.ToWin32(_foregroundColor.Value));
                        fontProperties.SetValue(ref RibbonProperties.FontProperties_ForegroundColor, ref propForegroundColor);
                    }

                    // set foregroundColorType
                    if (_foregroundColorType.HasValue)
                    {
                        PropVariant propForegroundColorType = PropVariant.FromObject((uint)_foregroundColorType.Value);
                        fontProperties.SetValue(ref RibbonProperties.FontProperties_ForegroundColorType, ref propForegroundColorType);
                    }

                    // set backgroundColor
                    if (_backgroundColor.HasValue)
                    {
                        PropVariant propBackgroundColor = PropVariant.FromObject((uint)ColorTranslator.ToWin32(_backgroundColor.Value));
                        fontProperties.SetValue(ref RibbonProperties.FontProperties_BackgroundColor, ref propBackgroundColor);
                    }

                    // set backgroundColorType
                    if (_backgroundColorType.HasValue)
                    {
                        PropVariant propBackgroundColorType = PropVariant.FromObject((uint)_backgroundColorType.Value);
                        fontProperties.SetValue(ref RibbonProperties.FontProperties_BackgroundColorType, ref propBackgroundColorType);
                    }

                    // set verticalPositioning
                    if (_verticalPositioning.HasValue)
                    {
                        PropVariant propVerticalPositioning = PropVariant.FromObject((uint)_verticalPositioning.Value);
                        fontProperties.SetValue(ref RibbonProperties.FontProperties_VerticalPositioning, ref propVerticalPositioning);
                    }

                    // set new font properties
                    newValue.SetIUnknown(fontProperties);
                }
            }

            return(HRESULT.S_OK);
        }
Exemplo n.º 47
0
        public int UpdateProperty(uint commandId, ref PropertyKey key, PropVariantRef currentValue, out PropVariant newValue)
        {
            try
            {
                Command command = Get((CommandId)commandId);
                if (command == null)
                {
                    return genericCommandHandler.NullCommandUpdateProperty(commandId, ref key, currentValue, out newValue);
                }

                return command.UpdateProperty(ref key, currentValue, out newValue);
            }
            catch (Exception ex)
            {
                Debug.Fail("Exception throw in CommandManager.UpdateProperty: " + ex + "\r\n\r\nCommand: " + commandId + " Key: " + PropertyKeys.GetName(key));
                throw;
            }
        }
Exemplo n.º 48
0
        private void SetPropertyValue(string fileName, TestDriverCodePack.ShellPropertyDescription propDesc, IShellProperty prop)
        {
            Type   t = propDesc.ValueType;
            string s;

            try
            {
                if (t == typeof(string))
                {
                    object obj = GetEnumValueForProperty(propDesc);

                    if (obj != null)
                    {
                        s = (string)obj;
                    }
                    else
                    {
                        s = RandomString();
                    }

                    savedProps.Add(new SavedProp {
                        Name = prop.CanonicalName, Value = s
                    });
                    //(prop as ShellProperty<string>).Value = s;

                    // Workaround Code Pack bug with 1 char strings by using PropertyHandler
                    // Have to open and release each time to avoid lock problems - still, it ups the pounding
                    var handler = new CPropertyHandler();
                    handler.Initialize(fileName, 0);

                    PropVariant value = new PropVariant(s);
                    handler.SetValue(new TestDriverCodePack.PropertyKey(prop.PropertyKey.FormatId, prop.PropertyKey.PropertyId), value);
                    handler.Commit();

                    Marshal.ReleaseComObject(handler);  // preempt GC for CCW
                }
                else if (t == typeof(string[]))
                {
                    string[] ss = GetStringArrayValueForProperty(propDesc);

                    savedProps.Add(new SavedProp {
                        Name = prop.CanonicalName, Value = ss
                    });
                    //(prop as ShellProperty<string[]>).Value = ss;

                    // Workaround Code Pack bug with 1 char strings by using PropertyHandler
                    // Have to open and release each time to avoid lock problems - still, it ups the pounding
                    var handler = new CPropertyHandler();
                    handler.Initialize(fileName, 0);

                    PropVariant value = new PropVariant(ss);
                    handler.SetValue(new TestDriverCodePack.PropertyKey(prop.PropertyKey.FormatId, prop.PropertyKey.PropertyId), value);
                    handler.Commit();

                    Marshal.ReleaseComObject(handler);  // preempt GC for CCW
                }
                else if (t == typeof(Int16?) || t == typeof(Int32?) || t == typeof(UInt16?) || t == typeof(UInt32?))
                {
                    object obj = GetEnumValueForProperty(propDesc);

                    if (t == typeof(Int16?))
                    {
                        Int16?val = obj != null ? (Int16?)obj : (Int16?)NullableRandomNumber(-max16, max16);
                        savedProps.Add(new SavedProp {
                            Name = prop.CanonicalName, Value = val
                        });
                        (prop as ShellProperty <Int16?>).Value = val;
                    }
                    else if (t == typeof(Int32?))
                    {
                        Int32?val = obj != null ? (Int32?)obj : (Int32?)NullableRandomNumber(-max32, max32);
                        savedProps.Add(new SavedProp {
                            Name = prop.CanonicalName, Value = val
                        });
                        (prop as ShellProperty <Int32?>).Value = val;
                    }
                    else if (t == typeof(UInt16?))
                    {
                        UInt16?val = obj != null ? (UInt16?)obj : (UInt16?)NullableRandomNumber(max16);
                        savedProps.Add(new SavedProp {
                            Name = prop.CanonicalName, Value = val
                        });
                        (prop as ShellProperty <UInt16?>).Value = val;
                    }
                    else // UInt32?
                    {
                        UInt32?val = obj != null ? (UInt32?)obj : (UInt32?)NullableRandomNumber(max16);
                        savedProps.Add(new SavedProp {
                            Name = prop.CanonicalName, Value = val
                        });
                        (prop as ShellProperty <UInt32?>).Value = val;
                    }
                }
                else if (t == typeof(Int32[]))
                {
                    Int32[] vals = new Int32[4];
                    for (int i = 0; i < 4; i++)
                    {
                        vals[i] = RandomNumber(-max32, max32);
                    }
                    savedProps.Add(new SavedProp {
                        Name = prop.CanonicalName, Value = vals
                    });
                    (prop as ShellProperty <Int32[]>).Value = vals;
                }
                else if (t == typeof(UInt32[]))
                {
                    UInt32[] vals = new UInt32[4];
                    for (int i = 0; i < 4; i++)
                    {
                        vals[i] = (UInt32)RandomNumber(max32);
                    }
                    savedProps.Add(new SavedProp {
                        Name = prop.CanonicalName, Value = vals
                    });
                    (prop as ShellProperty <UInt32[]>).Value = vals;
                }
                else if (t == typeof(bool?))
                {
                    int? r     = NullableRandomNumber();
                    bool?value = (r == null) ? (bool?)null : (r % 2 == 0);
                    savedProps.Add(new SavedProp {
                        Name = prop.CanonicalName, Value = value
                    });
                    (prop as ShellProperty <bool?>).Value = value;
                }
                else if (t == typeof(DateTime?))
                {
                    DateTime dt = new DateTime((long)(random.NextDouble() * (maxTocks - minTicks) + minTicks));
                    savedProps.Add(new SavedProp {
                        Name = prop.CanonicalName, Value = dt
                    });
                    (prop as ShellProperty <DateTime?>).Value = dt;
                }
                else if (t == typeof(double?))
                {
                    // fails in Code Pack, so skip
                    //(prop as ShellProperty<double>).Value = (double)RandomNumber(max64);
                }
                else if (t == typeof(Int64?))
                {
                    // fails in Code Pack, so skip
                    //(prop as ShellProperty<Int64>).Value = RandomNumber(max64);
                }
                else if (t == typeof(UInt64?))
                {
                    // fails in Code Pack, so skip
                    // (prop as ShellProperty<UInt64>).Value = (UInt64) RandomNumber(max64);
                }
                else if (t == typeof(byte?))
                {
                    // The Code Pack does not support setting these, so skip for now
                    //(prop as ShellProperty<byte>).Value = (byte)RandomNumber(max8);
                }
                else if (t == typeof(byte[]))
                {
                    // The Code Pack does not support setting these, so skip for now
                    // Mostly 128 byte arrays e.g. System.Photo.MakerNote
                    //byte[] bs = new byte[128];
                    //random.NextBytes(bs);
                    //(prop as ShellProperty<byte[]>).Value = bs;
                }
                else if (t == typeof(object) || t == typeof(IntPtr?) || t == typeof(System.Runtime.InteropServices.ComTypes.IStream))
                {
                    // ignore these, they are system artefacts like group header props, and don't appear in settable lists
                }
                else
                {
                    throw new System.Exception("Need " + t.ToString() + " for " + propDesc.CanonicalName);
                }
            }
            catch (System.Exception e)
            {
                throw new System.Exception(String.Format("Error setting property {0} to '{1}'",
                                                         savedProps.Last().Name, ToDisplayString(savedProps.Last().Value)), e);
            }
        }
Exemplo n.º 49
0
 private extern static int PropVariantClear(ref PropVariant pvar);
Exemplo n.º 50
0
        private int GetAndCheckValues(string fileName, State state, bool useCodePack = false)
        {
            int errors = 0;
            CPropertyHandler handler = null;

            if (!useCodePack)
            {
                handler = new CPropertyHandler();
                handler.Initialize(fileName, 0);
            }

            foreach (var saved in savedProps)
            {
                IShellProperty prop = ShellObject.FromParsingName(fileName).Properties.GetProperty(saved.Name);

                object objVal;
                if (useCodePack)
                {
                    objVal = prop.ValueAsObject;
                }
                else
                {
                    var value = new PropVariant();
                    handler.GetValue(new TestDriverCodePack.PropertyKey(prop.PropertyKey.FormatId, prop.PropertyKey.PropertyId), value);
                    objVal = value.Value;
                }

                bool bSame = false;
                Type t     = objVal != null?objVal.GetType() : null;

                if (t == typeof(Int16) || t == typeof(Int32) || t == typeof(UInt16) || t == typeof(UInt32) || t == typeof(bool))
                {
                    bSame = objVal.Equals(saved.Value);
                }
                else if (t == typeof(string))
                {
                    bSame = (string)objVal == (string)saved.Value;
                }
                else if (t == typeof(string[]))
                {
                    string[] oss = (string[])objVal;
                    string[] sss = (string[])saved.Value;
                    bSame = true;
                    if (oss.Length == sss.Length)
                    {
                        for (int i = 0; i < oss.Length; i++)
                        {
                            if (oss[i] != sss[i])
                            {
                                bSame = false;
                                break;
                            }
                        }
                    }
                    else
                    {
                        bSame = false;
                    }
                }
                else if (t == typeof(Int32[]) || t == typeof(UInt32[]))
                {
                    int[] os = (int[])objVal;
                    int[] ss = (int[])saved.Value;
                    bSame = true;
                    if (os.Length == ss.Length)
                    {
                        for (int i = 0; i < os.Length; i++)
                        {
                            if (!os[i].Equals(ss[i]))
                            {
                                bSame = false;
                                break;
                            }
                        }
                    }
                    else
                    {
                        bSame = false;
                    }
                }
                else if (t == typeof(DateTime))
                {
                    DateTime save = (DateTime)(saved.Value);
                    DateTime read = (DateTime)objVal;

                    // Compare this way because exact ticks don't survive a round trip to text, and legibility
                    // is more useful than serializing just a number of ticks
                    bSame = save.Year == read.Year && save.Month == read.Month && save.Day == read.Day &&
                            save.Hour == read.Hour && save.Minute == read.Minute && save.Second == read.Second &&
                            save.Millisecond == read.Millisecond;
                }
                else
                {
                    bSame = (saved.Value == null && objVal == null);
                }

                if (!bSame)
                {
                    state.RecordEntry(String.Format("Mismatch for property {0}: expected {1}, got {2}", saved.Name,
                                                    saved.Value != null ? ToDisplayString(saved.Value) : "Null", objVal != null ? ToDisplayString(objVal) : "Null"));
                    errors++;
                }
            }

            if (!useCodePack)
            {
                Marshal.ReleaseComObject(handler);  // preempt GC for CCW
            }
            return(errors);
        }
        internal static void SetWindowProperty(IntPtr hwnd, PropertyKey propkey, string value)
        {
            // Get the IPropertyStore for the given window handle
            IPropertyStore propStore = GetWindowPropertyStore(hwnd);

            // Set the value
            using (PropVariant pv = new PropVariant(value))
            {
                HResult result = propStore.SetValue(ref propkey, pv);
                if (!CoreErrorHelper.Succeeded(result))
                {
                    throw new ShellException(result);
                }
            }


            // Dispose the IPropertyStore and PropVariant
            Marshal.ReleaseComObject(propStore);
        }
Exemplo n.º 52
0
        /// <summary>
        /// Handles IUICommandHandler.UpdateProperty function for the supported properties
        /// </summary>
        /// <param name="key">The Property Key to update</param>
        /// <param name="currentValue">A pointer to the current value for key. This parameter can be NULL</param>
        /// <param name="newValue">When this method returns, contains a pointer to the new value for key</param>
        /// <returns>Returns S_OK if successful, or an error value otherwise</returns>
        public override HRESULT UpdateProperty(ref PropertyKey key, PropVariantRef currentValue, ref PropVariant newValue)
        {
            if (key == RibbonProperties.Label)
            {
                if (_label != null)
                {
                    newValue.SetString(_label);
                }
            }

            return(HRESULT.S_OK);
        }
Exemplo n.º 53
0
 internal static extern void InitPropVariantFromUInt64Vector([In, Out] UInt64[] prgn, uint cElems, [Out] PropVariant ppropvar);
Exemplo n.º 54
0
        /// <summary>
        /// Retrieves some information about a window, like the title, the icon, and return it.
        /// </summary>
        /// <param name="windowHandle">The handle of the window</param>
        /// <returns>A <see cref="Window"/> that represents the information about the window</returns>
        private Window GetWindowInformation(IntPtr windowHandle)
        {
            var stringBuilder = new StringBuilder(256);

            NativeMethods.GetWindowText(windowHandle, stringBuilder, stringBuilder.Capacity);

            // We retrieve the process id
            int processId;

            NativeMethods.GetWindowThreadProcessId(windowHandle, out processId);

            BitmapImage icon                  = null;
            var         process               = Process.GetProcessById(processId);
            var         isWindowsStoreApp     = false;
            var         applicationIdentifier = string.Empty;

            Requires.NotNull(process, nameof(process));

            // If the process corresponds to a Windows Store app (process ApplicationFrameHost
            if (string.Equals(process.ProcessName, Consts.WindowsStoreProcessName, StringComparison.OrdinalIgnoreCase))
            {
                // We retrieve the Win Store App package linked to this window.
                isWindowsStoreApp = true;

                IPropertyStore propStore;
                var            iidIPropertyStore = new Guid("{" + Consts.PropertyStore + "}");
                Requires.VerifySucceeded(NativeMethods.SHGetPropertyStoreForWindow(windowHandle, ref iidIPropertyStore, out propStore));

                using (var prop = new PropVariant())
                {
                    Requires.VerifySucceeded(propStore.GetValue(_appUserModelIdKey, prop));

                    var familyName = prop.Value.Split('!').First();
                    var package    = _windowsStoreApps.FirstOrDefault(app => string.Equals(app.FamilyName, familyName, StringComparison.Ordinal));
                    if (package != null)
                    {
                        applicationIdentifier = package.FamilyName;
                        // Avoid some Thread problem with the hooking. TODO : Investigate for a better solution
                        var thread = new Thread(() =>
                        {
                            // Then we retrieve the application's icon.
                            var iconTask = GetWindowsStoreIconAsync(package);
                            iconTask.Wait();
                            icon = iconTask.Result;
                        });
                        thread.Start();
                        thread.Join();
                    }
                }
            }
            else
            {
                applicationIdentifier = SystemInfoHelper.GetExecutablePath(process.Id);
                icon = GetWin32WindowIcon(windowHandle, applicationIdentifier);
            }

            if (string.IsNullOrEmpty(applicationIdentifier))
            {
                return(null);
            }

            if (icon == null)
            {
                icon = new BitmapImage();
                if (applicationIdentifier.ToLower() == (Environment.GetFolderPath(Environment.SpecialFolder.Windows) + "\\explorer.exe").ToLower() && stringBuilder.ToString() == "") // Desktop
                {
                    Bitmap bitIcon = Icon.ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.Windows) + "\\explorer.exe").ToBitmap();
                    using (var memory = new MemoryStream())
                    {
                        bitIcon.Save(memory, System.Drawing.Imaging.ImageFormat.Png);
                        memory.Position = 0;
                        icon.BeginInit();
                        icon.StreamSource = memory;
                        icon.CacheOption  = BitmapCacheOption.OnLoad;
                        icon.EndInit();
                        icon.Freeze();
                    }
                }
                else // Other app without icon
                {
                    icon.BeginInit();
                    icon.UriSource   = new Uri("pack://application:,,,/Clipboard;component/Assets/NoIcon.png", UriKind.RelativeOrAbsolute);
                    icon.CacheOption = BitmapCacheOption.OnLoad;
                    icon.EndInit();
                    icon.Freeze();
                }
            }

            return(new Window(windowHandle, stringBuilder.ToString(), process, applicationIdentifier, icon, isWindowsStoreApp));
        }
Exemplo n.º 55
0
 internal static extern void PropVariantGetFileTimeElem([In] ref PropVariant propVar, [In] uint iElem, [Out, MarshalAs(UnmanagedType.Struct)] out System.Runtime.InteropServices.ComTypes.FILETIME pftVal);
Exemplo n.º 56
0
 internal static extern int InitPropVariantFromPropVariantVectorElem([In] ref PropVariant propvarIn, uint iElem, [Out] out PropVariant ppropvar);
Exemplo n.º 57
0
        public HRESULT UpdateProperty(ref PropertyKey key, PropVariantRef currentValue, ref PropVariant newValue)
        {
            if (key == RibbonProperties.ItemsSource)
            {
                if (_itemsSource != null)
                {
                    IUICollection itemsSource = (IUICollection)currentValue.PropVariant.Value;

                    itemsSource.Clear();
                    uint count;
                    _itemsSource.GetCount(out count);
                    for (uint i = 0; i < count; ++i)
                    {
                        object item;
                        _itemsSource.GetItem(i, out item);
                        itemsSource.Add(item);
                    }
                }
            }
            return HRESULT.S_OK;
        }
Exemplo n.º 58
0
 internal static extern void PropVariantGetStringElem([In] ref PropVariant propVar, [In]  uint iElem, [Out, MarshalAs(UnmanagedType.LPWStr)] out string ppszVal);
Exemplo n.º 59
0
        static void Main(string[] args)
        {
            if (args.Length < 2)
              {
            ShowHelp();
            return;
              }

              try
              {
            string ArchiveName;
            uint FileNumber = 0xFFFFFFFF;
            bool Extract;

            switch (args[0])
            {
              case "l":
            ArchiveName = args[1];
            Extract = false;
            break;
              case "e":
            ArchiveName = args[1];
            Extract = true;
            if ((args.Length < 3) || !uint.TryParse(args[2], out FileNumber))
            {
              ShowHelp();
              return;
            }
            break;
              default:
            ShowHelp();
            return;
            }

            using (SevenZipFormat Format = new SevenZipFormat(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "7z.dll")))
            {
              IInArchive Archive = Format.CreateInArchive(SevenZipFormat.GetClassIdFromKnownFormat(KnownSevenZipFormat.Zip));
              if (Archive == null)
              {
            ShowHelp();
            return;
              }

              try
              {
            using (InStreamWrapper ArchiveStream = new InStreamWrapper(File.OpenRead(ArchiveName)))
            {
              ulong CheckPos = 32 * 1024;
              if (Archive.Open(ArchiveStream, ref CheckPos, null) != 0)
                ShowHelp();

              Console.Write("Archive: ");
              Console.WriteLine(ArchiveName);

              if (Extract)
              {
                PropVariant Name = new PropVariant();
                Archive.GetProperty(FileNumber, ItemPropId.kpidPath, ref Name);
                string FileName = (string)Name.GetObject();

                Console.Write("Extracting: ");
                Console.Write(FileName);
                Console.Write(' ');

                Archive.Extract(new uint[] { FileNumber }, 1, 0, new ArchiveCallback(FileNumber, FileName));
              }
              else
              {
                Console.WriteLine("List:");
                uint Count = Archive.GetNumberOfItems();
                for (uint I = 0; I < Count; I++)
                {
                  PropVariant Name = new PropVariant();
                  Archive.GetProperty(I, ItemPropId.kpidPath, ref Name);
                  Console.Write(I);
                  Console.Write(' ');
                  Console.WriteLine(Name.GetObject());
                }
              }
            }
              }
              finally
              {
            Marshal.ReleaseComObject(Archive);
              }
            }
              }
              catch (Exception e)
              {
            Console.Write("Error: ");
            Console.WriteLine(e.Message);
              }
        }
Exemplo n.º 60
0
 internal static extern void InitPropVariantFromBooleanVector([In, Out] bool[] prgf, uint cElems, out PropVariant ppropvar);