コード例 #1
0
 /// <summary>
 /// Gets the specified property value.
 /// </summary>
 /// <param name="pKey">The key of the requested property.</param>
 public void GetValue(ref PropertyKey pKey, out PROPVARIANT pValue)
 {
     pValue = new PROPVARIANT();
     if (pKey.Equals(SensorPropertyKeys.SENSOR_DATA_TYPE_LATITUDE_DEGREES))
     {
         pValue.SetValue(_latitude);
     }
     else if (pKey.Equals(SensorPropertyKeys.SENSOR_DATA_TYPE_LONGITUDE_DEGREES))
     {
         pValue.SetValue(_longitude);
     }
     else if (pKey.Equals(SensorPropertyKeys.SENSOR_DATA_TYPE_ERROR_RADIUS_METERS))
     {
         pValue.SetValue(_errorRadius);
     }
     else if (pKey.Equals(SensorPropertyKeys.SENSOR_DATA_TYPE_ALTITUDE_ELLIPSOID_METERS))
     {
         pValue.SetValue(_altitude);
     }
     else if (pKey.Equals(SensorPropertyKeys.SENSOR_DATA_TYPE_ALTITUDE_ELLIPSOID_ERROR_METERS))
     {
         pValue.SetValue(_altitudeError);
     }
     else if (pKey.Equals(SensorPropertyKeys.SENSOR_DATA_TYPE_TIMESTAMP))
     {
         pValue.SetFileTime(_timeStamp);
     }
 }
コード例 #2
0
 /// <summary>
 /// Gets the specified property value.
 /// </summary>
 /// <param name="pKey">The key identifying requested property.</param>
 public void GetValue(ref PropertyKey pKey, out PROPVARIANT pValue)
 {
     pValue = new PROPVARIANT();
     if (pKey.Equals(SensorPropertyKeys.SENSOR_DATA_TYPE_ADDRESS1))
     {
         pValue.SetValue(_address1);
     }
     else if (pKey.Equals(SensorPropertyKeys.SENSOR_DATA_TYPE_ADDRESS2))
     {
         pValue.SetValue(_address2);
     }
     else if (pKey.Equals(SensorPropertyKeys.SENSOR_DATA_TYPE_CITY))
     {
         pValue.SetValue(_city);
     }
     else if (pKey.Equals(SensorPropertyKeys.SENSOR_DATA_TYPE_STATE_PROVINCE))
     {
         pValue.SetValue(_StateProvince);
     }
     else if (pKey.Equals(SensorPropertyKeys.SENSOR_DATA_TYPE_POSTALCODE))
     {
         pValue.SetValue(_PostalCode);
     }
     else if (pKey.Equals(SensorPropertyKeys.SENSOR_DATA_TYPE_TIMESTAMP))
     {
         pValue.SetFileTime(_timestamp);
     }
     else if (pKey.Equals(SensorPropertyKeys.SENSOR_DATA_TYPE_COUNTRY_REGION))
     {
         pValue.SetValue(_CountryRegion);
     }
 }
コード例 #3
0
ファイル: JumpList.cs プロジェクト: Yerongn/HandyControl
        private static IShellLinkW CreateLinkFromJumpTask(JumpTask jumpTask, bool allowSeparators)
        {
            if (string.IsNullOrEmpty(jumpTask.Title) && (!allowSeparators || !string.IsNullOrEmpty(jumpTask.CustomCategory)))
            {
                return(null);
            }
            IShellLinkW shellLinkW = (IShellLinkW)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("00021401-0000-0000-C000-000000000046")));
            IShellLinkW result;

            try
            {
                string path = JumpList._FullName;
                if (!string.IsNullOrEmpty(jumpTask.ApplicationPath))
                {
                    path = jumpTask.ApplicationPath;
                }
                shellLinkW.SetPath(path);
                if (!string.IsNullOrEmpty(jumpTask.WorkingDirectory))
                {
                    shellLinkW.SetWorkingDirectory(jumpTask.WorkingDirectory);
                }
                if (!string.IsNullOrEmpty(jumpTask.Arguments))
                {
                    shellLinkW.SetArguments(jumpTask.Arguments);
                }
                if (jumpTask.IconResourceIndex != -1)
                {
                    string pszIconPath = JumpList._FullName;
                    if (!string.IsNullOrEmpty(jumpTask.IconResourcePath))
                    {
                        if ((long)jumpTask.IconResourcePath.Length >= 260L)
                        {
                            return(null);
                        }
                        pszIconPath = jumpTask.IconResourcePath;
                    }
                    shellLinkW.SetIconLocation(pszIconPath, jumpTask.IconResourceIndex);
                }
                if (!string.IsNullOrEmpty(jumpTask.Description))
                {
                    shellLinkW.SetDescription(jumpTask.Description);
                }
                IPropertyStore propertyStore = (IPropertyStore)shellLinkW;
                using (PROPVARIANT propvariant = new PROPVARIANT())
                {
                    PKEY pkey = default(PKEY);
                    if (!string.IsNullOrEmpty(jumpTask.Title))
                    {
                        propvariant.SetValue(jumpTask.Title);
                        pkey = PKEY.Title;
                    }
                    else
                    {
                        propvariant.SetValue(true);
                        pkey = PKEY.AppUserModel_IsDestListSeparator;
                    }
                    propertyStore.SetValue(ref pkey, propvariant);
                }
                propertyStore.Commit();
                IShellLinkW shellLinkW2 = shellLinkW;
                shellLinkW = null;
                result     = shellLinkW2;
            }
            catch (Exception)
            {
                result = null;
            }
            finally
            {
                Utility.SafeRelease <IShellLinkW>(ref shellLinkW);
            }
            return(result);
        }
コード例 #4
0
        private static IShellLinkW CreateLinkFromJumpTask(JumpTask jumpTask, bool allowSeparators)
        {
            Debug.Assert(jumpTask != null);

            if (string.IsNullOrEmpty(jumpTask.Title))
            {
                if (!allowSeparators || !string.IsNullOrEmpty(jumpTask.CustomCategory))
                {
                    return(null);
                }
            }
            var link = (IShellLinkW)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(CLSID.ShellLink)));

            try
            {
                var appPath = _FullName;
                if (!string.IsNullOrEmpty(jumpTask.ApplicationPath))
                {
                    appPath = jumpTask.ApplicationPath;
                }
                link.SetPath(appPath);

                if (!string.IsNullOrEmpty(jumpTask.WorkingDirectory))
                {
                    link.SetWorkingDirectory(jumpTask.WorkingDirectory);
                }
                if (!string.IsNullOrEmpty(jumpTask.Arguments))
                {
                    link.SetArguments(jumpTask.Arguments);
                }

                if (jumpTask.IconResourceIndex != -1)
                {
                    var resourcePath = _FullName;
                    if (!string.IsNullOrEmpty(jumpTask.IconResourcePath))
                    {
                        if (jumpTask.IconResourcePath.Length >= Win32Value.MAX_PATH)
                        {
                            return(null);
                        }
                        resourcePath = jumpTask.IconResourcePath;
                    }
                    link.SetIconLocation(resourcePath, jumpTask.IconResourceIndex);
                }
                if (!string.IsNullOrEmpty(jumpTask.Description))
                {
                    link.SetDescription(jumpTask.Description);
                }
                var propStore = (IPropertyStore)link;
                using (var pv = new PROPVARIANT())
                {
                    var pkey = default(PKEY);
                    if (!string.IsNullOrEmpty(jumpTask.Title))
                    {
                        pv.SetValue(jumpTask.Title);
                        pkey = PKEY.Title;
                    }
                    else
                    {
                        pv.SetValue(true);
                        pkey = PKEY.AppUserModel_IsDestListSeparator;
                    }
                    propStore.SetValue(ref pkey, pv);
                }
                propStore.Commit();
                var retLink = link;
                link = null;
                return(retLink);
            }
            catch (Exception)
            {
                return(null);
            }
            finally
            {
                Utility.SafeRelease(ref link);
            }
        }
コード例 #5
0
        private static IShellLinkW CreateLinkFromJumpTask(JumpTask jumpTask, bool allowSeparators)
        {
            Debug.Assert(jumpTask != null);

            // Title is generally required.  If it's missing we need to treat this like a separator.
            // Everything else can still appear on separator elements,
            // but separators can only exist in the Tasks category.
            if (string.IsNullOrEmpty(jumpTask.Title))
            {
                if (!allowSeparators || !string.IsNullOrEmpty(jumpTask.CustomCategory))
                {
                    // Just treat this situation as an InvalidItem.
                    return(null);
                }
            }

            var link = (IShellLinkW)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(CLSID.ShellLink)));

            try
            {
                string appPath = _FullName;
                if (!string.IsNullOrEmpty(jumpTask.ApplicationPath))
                {
                    appPath = jumpTask.ApplicationPath;
                }

                link.SetPath(appPath);

                // This is optional.  Don't set it if the app hasn't explicitly requested it.
                if (!string.IsNullOrEmpty(jumpTask.WorkingDirectory))
                {
                    // Don't verify this.  It's possible that the directory doesn't exist now, but it will later.
                    // Shell handles this fine when we try to set an improperly formatted path.
                    link.SetWorkingDirectory(jumpTask.WorkingDirectory);
                }

                if (!string.IsNullOrEmpty(jumpTask.Arguments))
                {
                    link.SetArguments(jumpTask.Arguments);
                }

                // -1 is a sentinel value indicating not to use the icon.
                if (jumpTask.IconResourceIndex != -1)
                {
                    string resourcePath = _FullName;
                    if (!string.IsNullOrEmpty(jumpTask.IconResourcePath))
                    {
                        // Shell bug (Windows 7 595770): IShellLink doesn't correctly limit icon location path to MAX_PATH.
                        // It's really too bad we have to enforce this here.  When the shortcut gets
                        // serialized it streams the full string.  On deserialization it only retrieves
                        // MAX_PATH for this field leaving junk behind for subsequent gets, leading to data corruption.
                        // Because we don't want to allow the app to do create something that we know may
                        // be corrupt we have to enforce this ourselves.  If Shell fixes this later then
                        // we need to remove this check to let them handle this as they see fit.
                        // If they fix it by supporting longer paths, then we're artificially constraining this value...
                        if (jumpTask.IconResourcePath.Length >= Win32Constant.MAX_PATH)
                        {
                            // we could throw the exception here, but we're already globally catching everything.
                            return(null);
                        }
                        resourcePath = jumpTask.IconResourcePath;
                    }
                    link.SetIconLocation(resourcePath, jumpTask.IconResourceIndex);
                }

                if (!string.IsNullOrEmpty(jumpTask.Description))
                {
                    link.SetDescription(jumpTask.Description);
                }

                IPropertyStore propStore = (IPropertyStore)link;
                var            pv        = new PROPVARIANT();
                try
                {
                    PKEY pkey = default(PKEY);

                    if (!string.IsNullOrEmpty(jumpTask.Title))
                    {
                        pv.SetValue(jumpTask.Title);
                        pkey = PKEY.Title;
                    }
                    else
                    {
                        pv.SetValue(true);
                        pkey = PKEY.AppUserModel_IsDestListSeparator;
                    }

                    propStore.SetValue(ref pkey, pv);
                }
                finally
                {
                    Utilities.SafeDispose(ref pv);
                }

                propStore.Commit();

                IShellLinkW retLink = link;
                link = null;
                return(retLink);
            }
            catch (Exception)
            {
                // IShellLinkW::Set* methods tend to return E_FAIL when trying to set invalid data.
                // The create methods don't explicitly check for these kinds of errors.

                // If we aren't able to create the item for any reason just return null to indicate an invalid item.
                return(null);
            }
            finally
            {
                Utilities.SafeRelease(ref link);
            }
        }
コード例 #6
0
ファイル: JumpList.cs プロジェクト: uzbekdev1/HandyControls
 private static Standard.IShellLinkW CreateLinkFromJumpTask(JumpTask jumpTask, bool allowSeparators)
 {
     Standard.IShellLinkW kw3;
     if (string.IsNullOrEmpty(jumpTask.Title) && (!allowSeparators || !string.IsNullOrEmpty(jumpTask.CustomCategory)))
     {
         return(null);
     }
     Standard.IShellLinkW comObject = (Standard.IShellLinkW)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("00021401-0000-0000-C000-000000000046")));
     try
     {
         string pszFile = _FullName;
         if (!string.IsNullOrEmpty(jumpTask.ApplicationPath))
         {
             pszFile = jumpTask.ApplicationPath;
         }
         comObject.SetPath(pszFile);
         if (!string.IsNullOrEmpty(jumpTask.WorkingDirectory))
         {
             comObject.SetWorkingDirectory(jumpTask.WorkingDirectory);
         }
         if (!string.IsNullOrEmpty(jumpTask.Arguments))
         {
             comObject.SetArguments(jumpTask.Arguments);
         }
         if (jumpTask.IconResourceIndex != -1)
         {
             string pszIconPath = _FullName;
             if (!string.IsNullOrEmpty(jumpTask.IconResourcePath))
             {
                 if (jumpTask.IconResourcePath.Length >= 260L)
                 {
                     return(null);
                 }
                 pszIconPath = jumpTask.IconResourcePath;
             }
             comObject.SetIconLocation(pszIconPath, jumpTask.IconResourceIndex);
         }
         if (!string.IsNullOrEmpty(jumpTask.Description))
         {
             comObject.SetDescription(jumpTask.Description);
         }
         Standard.IPropertyStore store = (Standard.IPropertyStore)comObject;
         using (PROPVARIANT propvariant = new PROPVARIANT())
         {
             Standard.PKEY title = new Standard.PKEY();
             if (!string.IsNullOrEmpty(jumpTask.Title))
             {
                 propvariant.SetValue(jumpTask.Title);
                 title = Standard.PKEY.Title;
             }
             else
             {
                 propvariant.SetValue(true);
                 title = Standard.PKEY.AppUserModel_IsDestListSeparator;
             }
             store.SetValue(ref title, propvariant);
         }
         store.Commit();
         Standard.IShellLinkW kw2 = comObject;
         comObject = null;
         kw3       = kw2;
     }
     catch (Exception)
     {
         kw3 = null;
     }
     finally
     {
         Standard.Utility.SafeRelease <Standard.IShellLinkW>(ref comObject);
     }
     return(kw3);
 }