Ejemplo n.º 1
0
        private void IconGenerator_DoWork(object sender, DoWorkEventArgs e)
        {
            var results = new Dictionary <string, string>();

            e.Result = results;

            var targetDir = SharedRoutines.GetIconDirectoryPath();

            EnsureDirectoryCreate(targetDir, false);

            foreach (var eachKey in ImageList.Images.Keys)
            {
                var targetPath = Path.Combine(targetDir, eachKey + ".ico");
                var fileInfo   = new FileInfo(targetPath);

                if (fileInfo.Exists && fileInfo.Length > 0L)
                {
                    continue;
                }

                var creationResult = ImagingHelper.ConvertToIcon(ImageList.Images[eachKey], fileInfo.FullName);

                if (!creationResult)
                {
                    results.Add(eachKey, targetPath);
                }
            }
        }
Ejemplo n.º 2
0
        void button2_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                //Generar Icono
                Bitmap pngIcon = new Bitmap(pictureBox1.Image);

                using (FileStream stream = File.OpenWrite("temp.ico"))
                {
                    ImagingHelper.ConvertToIcon(pngIcon, stream);
                }

                Console.WriteLine("Generated icon");

                // Generar ejecutable
                CodeDomProvider codeProvider = CodeDomProvider.CreateProvider("CSharp");

                                #if DEBUG
                File.WriteAllText("generatedApp.cs", generatedApp.GenerateApp());
                                #endif

                CompilerParameters parameters = new CompilerParameters();
                parameters.GenerateExecutable = true;
                parameters.OutputAssembly     = folderBrowserDialog1.SelectedPath + "\\" + (txtName.Text.Length > 0 ? txtName.Text : "Untitled Folder") + ".exe";
                parameters.CompilerOptions    = "/win32icon:temp.ico /target:winexe /optimize";
                parameters.ReferencedAssemblies.Add("System.dll");
                parameters.ReferencedAssemblies.Add("System.Drawing.dll");
                parameters.ReferencedAssemblies.Add("System.Collections.dll");
                parameters.ReferencedAssemblies.Add("System.Windows.Forms.dll");
                parameters.ReferencedAssemblies.Add("System.IO.dll");
                parameters.ReferencedAssemblies.Add("System.Reflection.dll");
                parameters.ReferencedAssemblies.Add("System.Runtime.InteropServices.dll");
                CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, generatedApp.GenerateApp());

                if (results.Errors.Count > 0)
                {
                    string error = "";
                    foreach (CompilerError CompErr in results.Errors)
                    {
                        error += "Line number " + CompErr.Line +
                                 ", Error Number: " + CompErr.ErrorNumber +
                                 ", '" + CompErr.ErrorText + ";" +
                                 Environment.NewLine;
                    }
                    MessageBox.Show(error);
                }
                else
                {
                    pngIcon.Dispose();
                    File.Delete("temp.ico");                     //Elimina icono temporal.
                    MessageBox.Show("Folder generated successfully!", "Success", MessageBoxButtons.OK);
                }
            }
        }
Ejemplo n.º 3
0
        private string SaveDistroIconImage(Stream readableStream, string distroName)
        {
            var targetDirectoryPath = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                "WslManager", "Icons");

            if (!Directory.Exists(targetDirectoryPath))
            {
                Directory.CreateDirectory(targetDirectoryPath);
            }

            var targetImageFilePath = Path.Combine(targetDirectoryPath, $"{distroName}.png");

            using (var fileStream = File.OpenWrite(targetImageFilePath))
            {
                readableStream.Seek(0L, SeekOrigin.Begin);
                readableStream.CopyTo(fileStream);
            }

            var targetIconFilePath = Path.Combine(targetDirectoryPath, $"{distroName}.ico");

            ImagingHelper.ConvertToIcon(targetImageFilePath, targetIconFilePath);
            return(targetIconFilePath);
        }