Beispiel #1
0
        /// <summary>
        /// Creates a URLData based upon an IDataObject
        /// </summary>
        /// <param name="iDataObject">The IDataObject from which to create the URLData</param>
        /// <returns>The URLData, null if no URLData could be created</returns>
        public static URLData Create(IDataObject iDataObject)
        {
            // WinLive Bug 198371: Look at rolling the fix for WinLive 182698 into the OleDataObjectHelper.GetDataPresentSafe method
            // For now, we keep the changes targeted.
            bool canGetDataPresentDirectlyFromIDataObject = false;

            try
            {
                canGetDataPresentDirectlyFromIDataObject = iDataObject.GetDataPresent(DataFormatsEx.URLFormat) &&
                                                           iDataObject.GetDataPresent(DataFormatsEx.FileGroupDescriptorWFormat);
            }
            catch (Exception e)
            {
                Debug.Fail(e.ToString());
            }

            // Validate required format
            // WinLive Bug 182698: Assert when pasting a hyperlink from IE
            if (canGetDataPresentDirectlyFromIDataObject &&
                OleDataObjectHelper.GetDataPresentSafe(iDataObject, DataFormatsEx.URLFormat) &&
                OleDataObjectHelper.GetDataPresentSafe(iDataObject, DataFormatsEx.FileGroupDescriptorWFormat))
            {
                return(new URLData(iDataObject));
            }
            else
            {
                //check to see if the dataObject contains a single .url file,
                //if so, create the URLData from that.
                FileData fileData = FileData.Create(iDataObject);
                if (fileData != null && fileData.Files.Length == 1)
                {
                    string filePath = fileData.Files[0].ContentsPath;
                    if (PathHelper.IsPathUrlFile(filePath))
                    {
                        URLData urlData = new URLData(iDataObject, UrlHelper.GetUrlFromShortCutFile(filePath), Path.GetFileNameWithoutExtension(filePath));
                        urlData.DateCreated  = File.GetCreationTime(filePath);
                        urlData.DateModified = File.GetLastWriteTime(filePath);
                        return(urlData);
                    }
                }
            }
            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// Creates a URLData based upon an IDataObject
        /// </summary>
        /// <param name="iDataObject">The IDataObject from which to create the URLData</param>
        /// <returns>The URLData, null if no URLData could be created</returns>
        public static URLData Create(IDataObject iDataObject)
        {
            // WinLive Bug 198371: Look at rolling the fix for WinLive 182698 into the OleDataObjectHelper.GetDataPresentSafe method
            // For now, we keep the changes targeted.
            bool canGetDataPresentDirectlyFromIDataObject = false;

            try
            {
                canGetDataPresentDirectlyFromIDataObject = iDataObject.GetDataPresent(DataFormatsEx.URLFormat) &&
                                                           iDataObject.GetDataPresent(DataFormatsEx.FileGroupDescriptorWFormat);
            }
            catch (Exception e)
            {
                Debug.Fail(e.ToString());
            }

            // Validate required format
            // WinLive Bug 182698: Assert when pasting a hyperlink from IE
            if (canGetDataPresentDirectlyFromIDataObject &&
                OleDataObjectHelper.GetDataPresentSafe(iDataObject, DataFormatsEx.URLFormat) &&
                OleDataObjectHelper.GetDataPresentSafe(iDataObject, DataFormatsEx.FileGroupDescriptorWFormat))
                return new URLData(iDataObject);
            else
            {
                //check to see if the dataObject contains a single .url file,
                //if so, create the URLData from that.
                FileData fileData = FileData.Create(iDataObject);
                if (fileData != null && fileData.Files.Length == 1)
                {
                    string filePath = fileData.Files[0].ContentsPath;
                    if (PathHelper.IsPathUrlFile(filePath))
                    {
                        URLData urlData = new URLData(iDataObject, UrlHelper.GetUrlFromShortCutFile(filePath), Path.GetFileNameWithoutExtension(filePath));
                        urlData.DateCreated = File.GetCreationTime(filePath);
                        urlData.DateModified = File.GetLastWriteTime(filePath);
                        return urlData;
                    }
                }
            }
            return null;
        }