コード例 #1
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
                                                             //
            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
        }