Esempio n. 1
0
        private bool SetUrl()
        {
            bool   handled  = false;
            string iconFile = string.Empty;

            try
            {
                FileIni file = new FileIni(TargetFilePath);
                iconFile = file.Value("IconFile", string.Empty);
                if (string.IsNullOrEmpty(iconFile))
                {
                    string browserPath = FileUrl.GetDefaultBrowserPath();
                    if (string.IsNullOrEmpty(browserPath))
                    {
                        Log.Info($"Resolve *.URL '{TargetFilePath}'" +
                                 $"No default browser found!");
                    }
                    else
                    {
                        Icon       = IconReader.GetFileIconWithCache(browserPath, false);
                        diposeIcon = false;
                        handled    = true;
                    }
                }
                else if (System.IO.File.Exists(iconFile))
                {
                    Icon    = Icon.ExtractAssociatedIcon(iconFile);
                    handled = true;
                }
                else
                {
                    Log.Info($"Resolve *.URL '{TargetFilePath}' has no icon");
                }
            }
            catch (Exception ex)
            {
                if (ex is SecurityException ||
                    ex is ArgumentException ||
                    ex is UnauthorizedAccessException ||
                    ex is PathTooLongException ||
                    ex is NotSupportedException)
                {
                    Log.Warn($"path:'{TargetFilePath}', " +
                             $"iconFile:'{iconFile}'", ex);
                }
                else
                {
                    throw;
                }
            }

            SetText($"{FileInfo.Name.Substring(0, FileInfo.Name.Length - 4)}");

            return(handled);
        }