コード例 #1
0
ファイル: Category.cs プロジェクト: pseymour/taskbar-groups
        private static void createMultiIcon(Image iconImage, string filePath)
        {
            var diffList = from number in iconSizes
                           select new
            {
                number,
                difference = Math.Abs(number - iconImage.Height)
            };
            var nearestSize = (from diffItem in diffList
                               orderby diffItem.difference
                               select diffItem).First().number;

            List <Bitmap> iconList = new List <Bitmap>();

            while (nearestSize != 16)
            {
                iconList.Add(ImageFunctions.ResizeImage(iconImage, nearestSize, nearestSize));
                nearestSize = (int)Math.Round((decimal)nearestSize / 2);
            }

            using (var stream = new FileStream(filePath, FileMode.Create))
            {
                IconFactory.SavePngsAsIcon(iconList.ToArray(), stream);
            }
        }
コード例 #2
0
        public void CreateConfig(Image groupImage)
        {
            string path = @"config\" + this.Name;

            //string filePath = path + @"\" + this.Name + "Group.exe";
            //
            // Directory and .exe
            //
            System.IO.Directory.CreateDirectory(@path);

            //System.IO.File.Copy(@"config\config.exe", @filePath);
            //
            // XML config
            //
            System.Xml.Serialization.XmlSerializer writer =
                new System.Xml.Serialization.XmlSerializer(typeof(Category));

            using (FileStream file = System.IO.File.Create(@path + @"\ObjectData.xml"))
                writer.Serialize(file, this);
            //
            // Create .ico
            //

            Image img = ImageFunctions.ResizeImage(groupImage, 1024, 1024); // Resize img if too big

            img.Save(path + @"\GroupImage.png");

            using (FileStream fs = new FileStream(path + @"\GroupIcon.ico", FileMode.Create))
                ImageFunctions.IconFromImage(img).Save(fs);  // saving as icon
                                                             //
                                                             // Create .lnk shortcut
                                                             //


            // Through shellLink.cs class, pass through into the function information on how to construct the icon
            // Needed due to needing to set a unique AppUserModelID so the shortcut applications don't stack on the taskbar with the main application
            // Tricks Windows to think they are from different applications even though they are from the same .exe
            ShellLink.InstallShortcut(
                Path.GetFullPath(@System.AppDomain.CurrentDomain.FriendlyName),
                "tjackenpacken.taskbarGroup.menu." + this.Name,
                path + " shortcut",
                Path.GetFullPath(@path),
                Path.GetFullPath(path + @"\GroupIcon.ico"),
                path + "\\" + this.Name + ".lnk",
                this.Name
                );


            // Build the icon cache
            cacheIcons();

            System.IO.File.Move(@path + "\\" + this.Name + ".lnk",
                                Path.GetFullPath(@"Shortcuts\" + Regex.Replace(this.Name, @"(_)+", " ") + ".lnk")); // Move .lnk to correct directory
        }
コード例 #3
0
 private static Bitmap getLogo(String logoPath, String defaultFile)
 {
     if (File.Exists(logoPath))
     {
         using (MemoryStream ms = new MemoryStream(System.IO.File.ReadAllBytes(logoPath)))
             return(ImageFunctions.ResizeImage(Bitmap.FromStream(ms), 64, 64));
     }
     else
     {
         return(Icon.ExtractAssociatedIcon(defaultFile).ToBitmap());
     }
 }
コード例 #4
0
        public void CreateConfig(Image groupImage)
        {
            string path     = @"config\" + this.Name;
            string filePath = path + @"\" + this.Name + "Group.exe";

            //
            // Directory and .exe
            //
            System.IO.Directory.CreateDirectory(@"Shortcuts\");
            System.IO.Directory.CreateDirectory(@path);
            System.IO.File.Copy(@"config\config.exe", @filePath);
            //
            // XML config
            //
            System.Xml.Serialization.XmlSerializer writer =
                new System.Xml.Serialization.XmlSerializer(typeof(Category));

            using (FileStream file = System.IO.File.Create(@path + @"\ObjectData.xml"))
                writer.Serialize(file, this);
            //
            // Create .ico
            //

            Image img = ImageFunctions.ResizeImage(groupImage, 1024, 1024); // Resize img if too big

            img.Save(path + @"\GroupImage.png");

            using (FileStream fs = new FileStream(path + @"\GroupIcon.ico", FileMode.Create))
                ImageFunctions.IconFromImage(img).Save(fs);  // saving as icon
                                                             //
                                                             // Create .lnk shortcut
                                                             //
            var wsh = new IWshShell_Class();

            IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(
                path + "\\" + this.Name + ".lnk") as IWshRuntimeLibrary.IWshShortcut;
            shortcut.Arguments        = "";
            shortcut.TargetPath       = Path.GetFullPath(@filePath);
            shortcut.WindowStyle      = 1;
            shortcut.Description      = path + " shortcut";
            shortcut.WorkingDirectory = Path.GetFullPath(@path);
            shortcut.IconLocation     = Path.GetFullPath(path + @"\GroupIcon.ico");
            shortcut.Save();
            System.IO.File.Move(@path + "\\" + this.Name + ".lnk",
                                Path.GetFullPath(@"Shortcuts\" + this.Name + ".lnk")); // moving .lnk to correct directory
        }
コード例 #5
0
ファイル: Category.cs プロジェクト: pseymour/taskbar-groups
        public void CreateConfig(Image groupImage)
        {
            string path = Path.Combine(Paths.ConfigPath, this.Name);

            //
            // Directory and .exe
            //
            System.IO.Directory.CreateDirectory(@path);

            //System.IO.File.Copy(@"config\config.exe", @filePath);
            //
            // XML config
            //
            System.Xml.Serialization.XmlSerializer writer =
                new System.Xml.Serialization.XmlSerializer(typeof(Category));

            using (FileStream file = System.IO.File.Create(Path.Combine(@path, "ObjectData.xml")))
            {
                writer.Serialize(file, this);
                file.Close();
            }
            //
            // Create .ico
            //

            Image img = ImageFunctions.ResizeImage(groupImage, 256, 256); // Resize img if too big

            img.Save(Path.Combine(path, "GroupImage.png"));

            if (GetMimeType(groupImage).ToString() == "*.PNG")
            {
                createMultiIcon(groupImage, Path.Combine(path, "GroupIcon.ico"));
            }
            else
            {
                using (FileStream fs = new FileStream(Path.Combine(path, "GroupIcon.ico"), FileMode.Create))
                {
                    ImageFunctions.IconFromImage(img).Save(fs);
                    fs.Close();
                }
            }


            // Through shellLink.cs class, pass through into the function information on how to construct the icon
            // Needed due to needing to set a unique AppUserModelID so the shortcut applications don't stack on the taskbar with the main application
            // Tricks Windows to think they are from different applications even though they are from the same .exe
            ShellLink.InstallShortcut(
                Paths.exeString,
                "tjackenpacken.taskbarGroup.menu." + this.Name,
                path + " shortcut",
                path,
                Path.Combine(path, "GroupIcon.ico"),
                Path.Combine(path, this.Name + ".lnk"),
                this.Name
                );


            // Build the icon cache
            cacheIcons();

            System.IO.File.Move(Path.Combine(path, this.Name + ".lnk"),
                                Path.Combine(Paths.ShortcutsPath, Regex.Replace(this.Name, @"(_)+", " ") + ".lnk")); // Move .lnk to correct directory
        }
コード例 #6
0
        public void CreateConfig(Image groupImage)
        {
            try
            {
                //string filePath = path + @"\" + this.Name + "Group.exe";
                //
                // Directory and .exe
                //
                path = Path.Combine(Paths.ConfigPath, this.Name);
                System.IO.Directory.CreateDirectory(@path);

                //System.IO.File.Copy(@"config\config.exe", @filePath);


                writeXML();

                //
                // Create .ico
                //

                Image img = ImageFunctions.ResizeImage(groupImage, 256, 256); // Resize img if too big
                img.Save(Path.Combine(path, "GroupImage.png"));

                if (GetMimeType(groupImage).ToString() == "*.PNG")
                {
                    createMultiIcon(groupImage, Path.Combine(path, "GroupIcon.ico"));
                }
                else
                {
                    using (FileStream fs = new FileStream(Path.Combine(path, "GroupIcon.ico"), FileMode.Create))
                    {
                        ImageFunctions.IconFromImage(img).Save(fs);
                        fs.Close();
                    }
                }


                // Through shellLink.cs class, pass through into the function information on how to construct the icon
                // Needed due to needing to set a unique AppUserModelID so the shortcut applications don't stack on the taskbar with the main application
                // Tricks Windows to think they are from different applications even though they are from the same .exe
                ShellLink.InstallShortcut(
                    Paths.BackgroundApplication,
                    "tjackenpacken.taskbarGroup.menu." + this.Name,
                    path + " shortcut",
                    path,
                    Path.Combine(path, "GroupIcon.ico"),
                    Path.Combine(path, this.Name + ".lnk"),
                    this.Name
                    );


                // Build the icon cache
                cacheIcons();

                System.IO.File.Move(Path.Combine(path, this.Name + ".lnk"),
                                    Path.Combine(Paths.ShortcutsPath, Regex.Replace(this.Name, @"(_)+", " ") + ".lnk")); // Move .lnk to correct directory
            }
            catch { }
            finally
            {
                Process[] pname = Process.GetProcessesByName(Path.GetFileNameWithoutExtension("Taskbar Groups Background"));
                if (pname.Length != 0)
                {
                    pname[0].Kill();
                }


                Process backgroundProcess = new Process();
                backgroundProcess.StartInfo.FileName = Paths.BackgroundApplication;
                backgroundProcess.Start();


                Process p = new Process();
                p.StartInfo.FileName  = Paths.BackgroundApplication;
                p.StartInfo.Arguments = this.Name + " setGroupContextMenu";
                p.Start();
            }
        }