Ejemplo n.º 1
0
        internal void SetData(RowData data, DataTable dataTable)
        {
            DataRow row = dataTable.Rows.Add();

            data.RowIndex = dataTable.Rows.IndexOf(row);

            if (icon == null)
            {
                icon = White50PercentageIcon;
            }

            if (HiddenEntry)
            {
                row[0] = IconReader.AddIconOverlay(
                    data.icon,
                    White50PercentageIcon);
            }
            else
            {
                row[0] = data.icon;
            }

            if (!ContainsMenu &&
                Config.IsHideFileExtension())
            {
                row[1] = Path.GetFileNameWithoutExtension(data.text);
            }
            else
            {
                row[1] = data.text;
            }

            row[2] = data;
        }
        //private SolutionItem(Package package, Project project) : this(package, project, true) {}

        private SolutionItem(Package package, Project project, bool recursive)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            IncrementSettings = new SolutionItemIncrementSettings(this);

            Package = package ?? throw new ArgumentNullException(nameof(package));
            _item   = project ?? throw new ArgumentNullException(nameof(project));
            Name    = project.Name;

            Filename   = project.FileName;
            UniqueName = project.UniqueName;

            if (!string.IsNullOrEmpty(Filename) && string.IsNullOrEmpty(Path.GetExtension(Filename)))
            {
                Filename += Path.GetExtension(project.UniqueName);
            }

            if (string.IsNullOrEmpty(project.FullName))
            {
                ItemType = SolutionItemType.Folder;
                Icon     = IconReader.AddFolderIcon(FolderType.Closed).ToImageSource();
                if (recursive)
                {
                    FillSolutionTree(package, this, project.ProjectItems);
                }
            }
            else
            {
                ItemType = SolutionItemType.Project;
                Icon     = IconReader.AddFileIcon(Filename).ToImageSource();

                GetGlobalVariables();
            }
        }
Ejemplo n.º 3
0
        public void ShowDataToLV(ExplorerNode parent)
        {
            lv_data.Clear();
            foreach (ExplorerNode item in parent.Child)
            {
                LV_data dt = new LV_data();
                dt.Node = item;

                if (item.Info.DateMod != time_default)
                {
                    dt.d_mod = item.Info.DateMod.ToString(timeformat);
                }
                if (item.Info.Size >= 0)
                {
                    dt.SizeString = UnitConventer.ConvertSize(item.Info.Size, 2, UnitConventer.unit_size);

                    string extension = item.GetExtension();
                    dt.ImgSource = Setting_UI.GetImage(
                        item.GetRoot.NodeType.Type == CloudType.LocalDisk ?
                        IconReader.GetFileIcon(item.GetFullPathString(), IconReader.IconSize.Small, false) :    //some large file make slow.
                        IconReader.GetFileIcon("." + extension, IconReader.IconSize.Small, false)
                        ).Source;
                }
                else
                {
                    dt.SizeString = "-1";
                    dt.ImgSource  = Setting_UI.GetImage(IconReader.GetFolderIcon(IconReader.IconSize.Small, IconReader.FolderType.Closed)).Source;
                }
                lv_data.Add(dt);
            }
        }
Ejemplo n.º 4
0
        private BitmapSource GetIcon(IconReader.IconSize size)
        {
            var path = Path;

            if (Path.ToLower().EndsWith(".lnk"))
            {
                var shell = new WshShell();
                var link  = (IWshShortcut)shell.CreateShortcut(Path);
                if (link.TargetPath != string.Empty)
                {
                    var info = new FileInfo(link.TargetPath);
                    if (info.Exists)
                    {
                        path = link.TargetPath;
                    }
                }
            }

            var ic   = IconReader.GetFileIcon(path, size, false);
            var icon = Imaging.CreateBitmapSourceFromHBitmap((ic.ToBitmap()).GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

            icon.Freeze();
            ic.Dispose();
            return(icon);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Get an icon for a given filename
        /// </summary>
        /// <param name="fileName">any filename</param>
        /// <param name="large">16x16 or 32x32 icon</param>
        /// <returns>null if path is null, otherwise - an icon</returns>
        public static ImageSource FindIconForFilename(string fileName, bool large, bool isfolder = false)
        {
            var extension = Path.GetExtension(fileName);

            if (extension == null)
            {
                return(null);
            }
            //var cache = large ? _largeIconCache : _smallIconCache;
            ImageSource icon;

            //if (cache.TryGetValue(extension, out icon))
            //    icon = IconReader.GetFileIcon(fileName, large ? IconReader.IconSize.Large : IconReader.IconSize.Small, false, true).ToImageSource();
            //else
            //    icon = IconReader.GetFileIcon(fileName, large ? IconReader.IconSize.Large : IconReader.IconSize.Small, false).ToImageSource();

            if (isfolder)
            {
                icon = IconReader.GetFileIcon(fileName, large ? IconReader.IconSize.Large : IconReader.IconSize.Small, false, true).ToImageSource();
            }
            else
            {
                icon = IconReader.GetFileIcon(fileName, large ? IconReader.IconSize.Large : IconReader.IconSize.Small, false).ToImageSource();
            }

            //cache.Add(extension, icon);
            return(icon);
        }
Ejemplo n.º 6
0
        private void paintIcon()
        {
            Dictionary <string, string> programlist = pm.returnProgramlist();
            Bitmap myBitmap;
            int    positionX = 30;
            int    positionY = 220;
            int    i         = 0;

            pictureBox = new PictureBox[programlist.Count];


            nCount = programlist.Count;
            if (nCount > 10)
            {
                pindex = 5;
            }
            else
            {
                pindex = nCount / 2;
            }

            foreach (KeyValuePair <string, string> kvp in programlist)
            {
                Icon icn = IconReader.GetFileIcon(kvp.Value, IconReader.IconSize.Large, false);


                myBitmap = icn.ToBitmap();
                myBitmap = ResizeBitmap(myBitmap, 50, 50);
                //  CenterPictureBox(pictureBox[i], myBitmap);
                pictureBox[i]      = new PictureBox();
                pictureBox[i].Name = kvp.Value;
                pictureBox[i].Tag  = kvp.Key;

                pictureBox[i].Size = new Size(100, 100);
                //first index = total /2, if total > 10 then index 5
                if (pindex == i)
                {
                    selectindex();
                    pictureBox[i].Location = new Point(positionX, positionY - indexPositionY);
                }
                else
                {
                    pictureBox[i].Location = new Point(positionX, positionY);
                }
                pictureBox[i].TabIndex    = 10;
                pictureBox[i].TabStop     = false;
                pictureBox[i].Visible     = true;
                pictureBox[i].Parent      = this;
                pictureBox[i].BorderStyle = BorderStyle.None;
                pictureBox[i].Image       = myBitmap;
                pictureBox[i].Paint      += new PaintEventHandler(Form1_Paint);
                pictureBox[i].Padding     = new Padding(4, 0, 4, 0);
                pictureBox[i].BackColor   = Color.Aqua;
                pictureBox[i].SizeMode    = PictureBoxSizeMode.CenterImage;

                positionX += 100;

                i++;
            }
        }
Ejemplo n.º 7
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            ItemType type;

            if (!Enum.TryParse <ItemType>(value.GetType().Name, out type))
            {
                return(null);
            }

            IconSize size;

            if (!Enum.TryParse <IconSize>((string)parameter, out size))
            {
                size = IconSize.Small;
            }

            if (type == ItemType.File)
            {
                Icon icon = IconReader.GetFileIcon(((File)value).Extension.ToLower(), size, false);
                return(icon.ToImageSource());
            }
            else
            {
                if ((type == ItemType.DriveModel) && !Enum.TryParse <ItemType>(((DriveModel)value).DriveType.ToString(), out type))
                {
                    return(null);
                }
                string key = type.ToString() + size.ToString();
                if (!_folderIconCache.ContainsKey(key))
                {
                    _folderIconCache.Add(key, IconReader.GetIcon(type, size).ToImageSource());
                }
                return(_folderIconCache[key]);
            }
        }
Ejemplo n.º 8
0
 public ImageSource GetFileIconImage(string filePath, bool small)
 {
     return(LoadBitmap(IconReader.GetFileIcon(
                           filePath,
                           (small) ? IconReader.IconSize.Small : IconReader.IconSize.Large,
                           false)));
 }
Ejemplo n.º 9
0
        public override System.Drawing.Icon GetIcon()
        {
            System.Drawing.Icon icon = null;

            if (String.IsNullOrEmpty(FileName))
            {
            }
            else
            {
                if (FileName.StartsWith("http://"))
                {
                    return(BrowserIcon);
                }
                else if (LPath.IsValid(FileName))
                {
                    var p = new LPath(FileName);
                    if (p.IsDirectory)
                    {
                        icon = IconReader.GetFolderIcon(IconReader.IconSize.Large, IconReader.FolderType.Closed);
                    }
                    else if (p.IsFile)
                    {
                        icon = IconReader.GetFileIcon(p, IconReader.IconSize.Large, false);
                    }
                }
            }
            return(icon);
        }
Ejemplo n.º 10
0
 public ImageSource GetFolderIconImage(string folderPath, bool closed, bool small)
 {
     return(LoadBitmap(IconReader.GetFolderIcon(
                           folderPath,
                           (small) ? IconReader.IconSize.Small : IconReader.IconSize.Large,
                           (closed) ? IconReader.FolderType.Closed : IconReader.FolderType.Opened)));
 }
Ejemplo n.º 11
0
        internal void SetData(RowData data, DataTable dataTable)
        {
            DataRow row = dataTable.Rows.Add();

            data.RowIndex = dataTable.Rows.IndexOf(row);

            if (icon == null)
            {
                icon = Properties.Resources.WhiteTransparency;
            }

            if (HiddenEntry)
            {
                row[0] = IconReader.AddIconOverlay(
                    data.icon,
                    Properties.Resources.WhiteTransparency);
            }
            else
            {
                row[0] = data.icon;
            }

            row[1] = data.text;
            row[2] = data;
        }
Ejemplo n.º 12
0
        private bool SetLnk(
            ref bool isLnkDirectory,
            ref string resolvedLnkPath)
        {
            bool handled = false;

            resolvedLnkPath = FileLnk.GetResolvedFileName(TargetFilePath);
            if (FileLnk.IsDirectory(resolvedLnkPath))
            {
                icon           = IconReader.GetFolderIconSTA(TargetFilePath, IconReader.FolderType.Open, true);
                handled        = true;
                isLnkDirectory = true;
            }
            else if (FileLnk.IsNetworkRoot(resolvedLnkPath))
            {
                isLnkDirectory = true;
            }
            else if (string.IsNullOrEmpty(resolvedLnkPath))
            {
                Log.Info($"Resolve *.LNK '{TargetFilePath}' has no icon");
            }
            else
            {
                IWshShell    shell = new WshShell();
                IWshShortcut lnk   = shell.CreateShortcut(TargetFilePath)
                                     as IWshShortcut;
                arguments        = lnk.Arguments;
                workingDirectory = lnk.WorkingDirectory;
                string iconLocation = lnk.IconLocation;
                if (iconLocation.Length > 2)
                {
                    iconLocation = iconLocation[0..^ 2];
        public FileListViewItem(JsonObject file, ImageList img, int index, JsonArray wanted, JsonArray priorities)
            : base()
        {
            for (int i = 0; i < 6; i++)
            {
                base.SubItems.Add("");
            }
            string name = (string)file[ProtocolConstants.FIELD_NAME];

            this.FileName        = Toolbox.TrimPath(name);
            base.SubItems[0].Tag = name;
            this.FileIndex       = index;
            string[] split = this.Name.Split('.');
            if (split.Length > 1)
            {
                this.Extension = split[split.Length - 1].ToLower();
                if (Program.Form.fileIconImageList.Images.ContainsKey(this.Extension) || IconReader.AddToImgList(this.Extension, Program.Form.fileIconImageList))
                {
                    this.TypeName = IconReader.GetTypeName(this.Extension);
                    base.ImageKey = this.Extension;
                }
                else
                {
                    this.TypeName = this.Extension;
                }
            }
            this.FileSize = Toolbox.ToLong(file[ProtocolConstants.FIELD_LENGTH]);
            this.Update(file, wanted, priorities);
        }
        public SolutionItem(Package package, Solution solution, bool recursive)
        {
            if (package == null)
            {
                throw (new ArgumentNullException(nameof(package)));
            }

            if (solution == null)
            {
                throw (new ArgumentNullException(nameof(solution)));
            }

            IncrementSettings = new SolutionItemIncrementSettings(this);

            Package    = package;
            _item      = solution;
            ItemType   = SolutionItemType.Solution;
            Icon       = IconReader.AddFileIcon(solution.FileName).ToImageSource();
            Name       = Path.GetFileNameWithoutExtension(solution.FileName);
            Filename   = solution.FileName;
            UniqueName = Name;

            GetGlobalVariables();

            if (recursive)
            {
                FillSolutionTree(package, this, solution.Projects);
            }
        }
Ejemplo n.º 15
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog pFileDlg = new OpenFileDialog();

            pFileDlg.Filter = "All Files(*.*)|*.*";
            pFileDlg.Title  = "편집할 파일을 선택하여 주세요.";

            if (pFileDlg.ShowDialog() == DialogResult.OK)
            {
                string strFullPathFile = pFileDlg.FileName;
                string Filename        = pFileDlg.SafeFileName;

                if (pm.containProgram(Filename))
                {
                    MessageBox.Show("이미 저장한 프로그램입니다.");
                }
                else
                {
                    //MessageBox.Show(strFullPathFile);
                    Icon icn = IconReader.GetFileIcon(strFullPathFile, IconReader.IconSize.Large, false);
                    iconView.Images.Add(icn);
                    iconList.Items.Add(Filename, iconList.Items.Count);

                    pm.saveProgram(Filename, strFullPathFile);
                }
            }
        }
Ejemplo n.º 16
0
        public FSA(TCPGecko UGecko, TreeView UTreeView, ToolStripMenuItem UExtractToolStripMenuItem, TextBox UFileSwapCode, ExceptionHandler UExceptionHandling)
        {
            exceptionHandling = UExceptionHandling;
            imgList           = new ImageList();
#if !MONO
            System.Drawing.Icon ni = IconReader.GetFolderIcon(IconReader.IconSize.Small,
                                                              IconReader.FolderType.Closed);
            imgList.Images.Add(ni);
            ni = IconReader.GetFolderIcon(IconReader.IconSize.Small,
                                          IconReader.FolderType.Open);
            imgList.Images.Add(ni);
            ni = IconReader.GetFileIcon("?.?", IconReader.IconSize.Small, false);
            imgList.Images.Add(ni);
#endif
            treeView                           = UTreeView;
            treeView.ImageList                 = imgList;
            treeView.NodeMouseClick           += TreeView_NodeMouseClick;
            treeView.AfterSelect              += treeView_AfterSelect;
            treeView.ContextMenuStrip.Opening += ContextMenuStrip_Opening;

            extractToolStripMenuItem        = UExtractToolStripMenuItem;
            extractToolStripMenuItem.Click += extractToolStripMenuItem_Click;

            gecko = UGecko;

            fileSwapCode = UFileSwapCode;

            selectedFile = -1;
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Real method to get the file icon after parsing the parameter.
 /// </summary>
 /// <param name="value">The databound value.</param>
 /// <param name="large">if set to <c>true</c> return large icon.</param>
 /// <returns></returns>
 protected virtual ImageSource GetFileIconCore(object value, bool large)
 {
     if (value == null)
     {
         return(null);
     }
     return(IconReader.GetFileIconWpf(value.ToString(), large ? IconReader.IconSize.Large : IconReader.IconSize.Small, false));
 }
Ejemplo n.º 18
0
 public static void ChangeIcon(string exeFilePath, string iconFilePath)
 {
     using (FileStream fs = new FileStream(iconFilePath, FileMode.Open, FileAccess.Read))
     {
         var reader = IconReader.Read(fs);
         ChangeIcon(exeFilePath, reader);
     }
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Update Files OLV
        /// </summary>
        private void UpdateOLV()
        {
            fileName.ImageGetter = delegate(object x)
            {
                try
                {
                    Icon   ico;
                    string path = ((FInfo)x).Path;
                    if (File.Exists(path))
                    {
                        ico = IconReader.GetFileIcon(path, IconReader.IconSize.Small, false);   //ico = Icon.ExtractAssociatedIcon(path);
                    }
                    else if (Directory.Exists(path))
                    {
                        ico = IconReader.GetFolderIcon(path, IconReader.IconSize.Small, IconReader.FolderType.Open);
                    }
                    else
                    {
                        ico = IconReader.GetFileIcon(RelativePath + Path.DirectorySeparatorChar + path, IconReader.IconSize.Small, false);
                    }
                    //ico = Icon.ExtractAssociatedIcon(RelativePath + Path.DirectorySeparatorChar + path);

                    //Icon ico = Icon.ExtractAssociatedIcon(((FInfo)x).Path);
                    //ico = IconReader.GetFileIcon(((FInfo)x).Path, IconReader.IconSize.Small, false);

                    return(ico.ToBitmap());
                }
                catch
                {
                    return(null);
                }
            };
            fileName.AspectGetter = delegate(object x) {
                return(((FInfo)x).Name);
            };
            filePath.AspectGetter = delegate(object x) {
                return(((FInfo)x).Path);
            };
            fileVersion.AspectGetter = delegate(object x) {
                return(((FInfo)x).Version);
            };
            fileGroup.AspectGetter = delegate(object x) {
                return(((FInfo)x).Group);
            };
            fileDescription.AspectGetter = delegate(object x) {
                return(((FInfo)x).Description);
            };

            this.fileName.GroupKeyGetter        = delegate(object x) { return(((FInfo)x).Group); };
            this.filePath.GroupKeyGetter        = delegate(object x) { return(((FInfo)x).Group); };
            this.fileVersion.GroupKeyGetter     = delegate(object x) { return(((FInfo)x).Group); };
            this.fileGroup.GroupKeyGetter       = delegate(object x) { return(((FInfo)x).Group); };
            this.fileDescription.GroupKeyGetter = delegate(object x) { return(((FInfo)x).Group); };

            olvFiles.ShowGroups = true;

            olvFiles.SetObjects(FileList);
        }
Ejemplo n.º 20
0
        private BitmapSource GetIcon(IconReader.IconSize size)
        {
            var ic   = IconReader.GetFolderIcon(Path, size, IconReader.FolderType.Open);
            var icon = Imaging.CreateBitmapSourceFromHBitmap((ic.ToBitmap()).GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

            icon.Freeze();
            ic.Dispose();
            return(icon);
        }
 public ICResult ChangeIcon(string exeFilePath, string iconFilePath)
 {
     using (FileStream fs = new FileStream(iconFilePath, FileMode.Open, FileAccess.Read))
     {
         var reader      = new IconReader(fs);
         var iconChanger = new IconChanger();
         return(iconChanger.ChangeIcon(exeFilePath, reader.Icons));
     }
 }
Ejemplo n.º 22
0
 public void Dispose()
 {
     worker.Dispose();
     keyboardInput.Dispose();
     timerStillActiveCheck.Dispose();
     waitLeave.Dispose();
     IconReader.Dispose();
     DisposeMenu(menus[0]);
 }
Ejemplo n.º 23
0
 private void IconHelperInit()
 {
     _smallImageList.ColorDepth = ColorDepth.Depth32Bit;
     _smallImageList.ImageSize  = new System.Drawing.Size(16, 16);
     _iconListManager           = new IconListManager(_smallImageList, IconReader.IconSize.Small);
     treeView1.ImageList        = _smallImageList;
     treeView1.ImageList.Images.Add(IconReader.GetFolderIcon(IconReader.IconSize.Small, IconReader.FolderType.Open));
     treeView1.ImageList.Images.Add(IconReader.GetFolderIcon(IconReader.IconSize.Small, IconReader.FolderType.Closed));
 }
Ejemplo n.º 24
0
        static AppIconImage()
        {
            StretchProperty.OverrideMetadata(typeof(AppIconImage), new FrameworkPropertyMetadata(Stretch.Uniform));
            SourceProperty.OverrideMetadata(typeof(AppIconImage), new FrameworkPropertyMetadata(null, new PropertyChangedCallback(SourceChanged), new CoerceValueCallback(SourceCoerceCallback)));

            string exePath = GetExePath();

            __appSmallIcon = IconReader.GetFileIcon(exePath, IconReader.IconSize.Small, false);
            //__appLargeIcon = IconReader.GetFileIcon(exePath, IconReader.IconSize.Large, false);
        }
Ejemplo n.º 25
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);
        }
Ejemplo n.º 26
0
 public Bitmap GetFolderIconBitmap(string path)
 {
     try
     {
         return(IconReader.GetFolderIcon(IconReader.IconSize.Large, IconReader.FolderType.Open).ToBitmap());
     }
     catch (Exception)
     {
         return(SystemIcons.WinLogo.ToBitmap());
     }
 }
Ejemplo n.º 27
0
        /// <returns>null if path is null, otherwise - an icon</returns>
        public static ImageSource FindIconForFolder(bool large, bool is_open)
        {
            var         cache = large ? _largeIconCache : _smallIconCache;
            ImageSource icon;

            if (cache.TryGetValue("", out icon))
            {
                return(icon);
            }
            icon = IconReader.GetFolderIcon(large ? IconReader.IconSize.Large : IconReader.IconSize.Small, is_open ? IconReader.FolderType.Open : IconReader.FolderType.Closed).ToImageSource();
            cache.Add("", icon);
            return(icon);
        }
Ejemplo n.º 28
0
        /// <summary>
        ///     Grabs the associated icon with a path.
        /// </summary>
        /// <param name="path">The path to grab.</param>
        /// <returns>Bitmap icon object.</returns>
        public Bitmap GetFileIconBitmap(string path)
        {
            try
            {
                return(IconReader.GetFileIcon(path, IconReader.IconSize.Large, false).ToBitmap());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

                return(SystemIcons.WinLogo.ToBitmap());
            }
        }
Ejemplo n.º 29
0
        private bool SetLnk(ref bool isLnkDirectory,
                            ref string resolvedLnkPath)
        {
            bool handled = false;

            resolvedLnkPath = LnkHelper.GetResolvedFileName(TargetFilePath);
            if (LnkHelper.IsDirectory(resolvedLnkPath))
            {
                Icon = IconReader.GetFolderIcon(TargetFilePath,
                                                IconReader.FolderType.Open, true);
                handled        = true;
                isLnkDirectory = true;
            }
            else if (string.IsNullOrEmpty(resolvedLnkPath))
            {
                Log.Info($"Resolve *.LNK '{TargetFilePath}' has no icon");
#warning [Feature] Resolve network root #48, start here
            }
            else
            {
                IWshShell    shell = new WshShell();
                IWshShortcut lnk   = shell.CreateShortcut(TargetFilePath)
                                     as IWshShortcut;
                Arguments        = lnk.Arguments;
                WorkingDirectory = lnk.WorkingDirectory;
                string iconLocation = lnk.IconLocation;
                if (iconLocation.Length > 2)
                {
                    iconLocation = iconLocation.Substring(0,
                                                          iconLocation.Length - 2);
                    if (System.IO.File.Exists(iconLocation))
                    {
                        try
                        {
                            Icon    = Icon.ExtractAssociatedIcon(iconLocation);
                            handled = true;
                        }
                        catch (ArgumentException ex)
                        {
                            Log.Warn($"iconLocation:'{iconLocation}'", ex);
                        }
                    }
                }

                TargetFilePath = resolvedLnkPath;
            }

            SetText(Path.GetFileNameWithoutExtension(TargetFilePathOrig));

            return(handled);
        }
Ejemplo n.º 30
0
        public AppNotifyIcon()
        {
            indexLoad          = bitmapsLoading.Count;
            notifyIcon.Icon    = bitmapsLoading.First();
            load.Tick         += Load_Tick;
            load.Interval      = Interval60FPS;
            notifyIcon.Text    = Translator.GetText("SystemTrayMenu");
            notifyIcon.Visible = true;

            if (Properties.Settings.Default.UseIconFromRootFolder)
            {
                SystemTrayMenu = IconReader.GetFolderIconSTA(
                    Config.Path,
                    IconReader.FolderType.Closed,
                    false);
            }

            notifyIcon.Icon = SystemTrayMenu;
            AppContextMenu contextMenus = new AppContextMenu();

            contextMenus.ClickedOpenLog += ClickedOpenLog;
            void ClickedOpenLog()
            {
                OpenLog?.Invoke();
            }

            contextMenus.ClickedRestart += ClickedRestart;
            void ClickedRestart()
            {
                Restart?.Invoke();
            }

            contextMenus.ClickedExit += ClickedExit;
            void ClickedExit()
            {
                Exit?.Invoke();
            }

            notifyIcon.ContextMenuStrip = contextMenus.Create();
            notifyIcon.MouseClick      += NotifyIcon_MouseClick;
            void NotifyIcon_MouseClick(object sender, MouseEventArgs e)
            {
                VerifyClick(e);
            }

            notifyIcon.MouseDoubleClick += NotifyIcon_MouseDoubleClick;
            void NotifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
            {
                VerifyClick(e);
            }
        }