Exemple #1
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(Properties.Resources.NO_ARGUMENTS);
                sb.AppendLine();
                sb.AppendLine();

                sb.AppendLine(Properties.Resources.HELP);
                MessageBox.Show(
                    sb.ToString(),
                    Application.ProductName,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Asterisk);
                return;
            }
            if (args.Length > 1)
            {
                StringBuilder sbNotFounds = new StringBuilder();
                for (int i = 0; i < args.Length; ++i)
                {
                    try
                    {
                        if (File.Exists(args[i]) || Directory.Exists(args[i]))
                        {
                            System.Diagnostics.Process.Start(Application.ExecutablePath, "\"" + args[i] + "\"");
                        }
                        else
                        {
                            sbNotFounds.AppendLine(args[i]);
                        }
                    }
                    catch (System.Exception e)
                    {
                        MessageBox.Show(e.Message,
                                        Application.ProductName,
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                }

                if (sbNotFounds.Length != 0)
                {
                    MessageBox.Show(Properties.Resources.FOLLOWING_DOESNOT_EXIST + "\r\n\r\n" + sbNotFounds.ToString(),
                                    Application.ProductName,
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Asterisk);
                }
                return;
            }

            string theFileName = args[0];

            // theFileName = @"C:\Documents and Settings\tt\My Documents\Productivity Distribution, Firm Heterogeneity, and Agglomeration.pdf";
            if (!File.Exists(theFileName) && !Directory.Exists(theFileName))
            {
                MessageBox.Show(string.Format(Properties.Resources.FILE_NOT_FOUND, theFileName),
                                Application.ProductName,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Asterisk);
                return;
            }

            System.IO.FileInfo fi = new System.IO.FileInfo(theFileName.Trim());

            string oldname = fi.Name;
            string oldext  = fi.Extension;
            string newName = fi.Name;

            if (!string.IsNullOrEmpty(oldext))
            {
                newName = newName.Replace(oldext, "");
            }
            do
            {
                try
                {
                    FormMain fm = new FormMain();
                    AmbLib.SetFontAll(fm);

                    fm.textName.Text = newName;
                    fm.textName.Tag  = theFileName;
                    if (DialogResult.OK != fm.ShowDialog())
                    {
                        return;
                    }

                    newName = fm.textName.Text;

                    if (!RenameIt(fi, newName, oldname, oldext))
                    {
                        continue;
                    }

                    break;
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message,
                                    Application.ProductName,
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Asterisk);
                }
            } while (true);
        }
Exemple #2
0
        public FormMain(string[] args)
        {
            InitializeComponent();

            this.Text = Application.ProductName;

            // read ini
            HashIni ini = Profile.ReadAll(IniPath);

            AmbLib.LoadFormXYWH(this, SECTION_LOCATION, ini);

            int intval;

            if (Profile.GetInt(SECTION_OPTION, KEY_CHECKDURATION, 0, out intval, ini))
            {
                _checkDuration = intval;
            }
            float fval;

            if (Profile.GetFloat(SECTION_OPTION, KEY_MIN_CPUUSAGE, 0, out fval, ini))
            {
                _minCPUUsage = fval;
            }
            if (Profile.GetFloat(SECTION_OPTION, KEY_MAX_CPUUSAGE, 0, out fval, ini))
            {
                _maxCPUUsage = fval;
            }

            bool bval;

            if (Profile.GetBool(SECTION_OPTION, KEY_IS_AVERAGE, false, out bval, ini))
            {
                _isAverage = bval;
            }

            try
            {
                bool start = false;
                var  p     = new OptionSet();
                p.Add("v|version", "Show Version", dummy =>
                {
                    MessageBox.Show("ver");
                    Environment.Exit(0);
                });
                p.Add("max=", "Max cpu usage", max =>
                {
                    _maxCPUUsage = float.Parse(max);
                });
                p.Add("min=", "Min cpu usage", max =>
                {
                    _minCPUUsage = float.Parse(max);
                });
                p.Add("d=|duration=", "Duration of checking", duration =>
                {
                    _checkDuration = int.Parse(duration);
                });
                p.Add("a|average", "Use average", dummy =>
                {
                    _isAverage = true;
                });
                p.Add("h|H|help|?", "Show Help", dummy =>
                {
                    var stream = new MemoryStream();
                    var to     = new StreamWriter(stream);
                    p.WriteOptionDescriptions(to);
                    to.Flush();
                    stream.Position = 0;
                    var reader      = new StreamReader(stream);
                    string message  = reader.ReadToEnd();

                    MessageBox.Show(message,
                                    Application.ProductName + " v" + AmbLib.getAssemblyVersion(Assembly.GetExecutingAssembly(), 3),
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                    Environment.Exit(0);
                });
                p.Add("start", "Start without showing the dialog", dummy =>
                {
                    start = true;
                });

                List <string> mainArgs = p.Parse(args);
                _start = start;
                if (mainArgs.Count != 0)
                {
                    FatalExit("Uknown Option:" + string.Join(" ", mainArgs.ToArray()));
                }
            }
            catch (Exception ex)
            {
                FatalExit(ex.Message);
            }
        }
Exemple #3
0
 private void FormMain_SizeChanged(object sender, EventArgs e)
 {
     AmbLib.StretchToolItem(mainTool, cmbAddress);
 }
Exemple #4
0
 private void AboutToolStripMenuItem_Click(object sender, EventArgs e)
 {
     Ambiesoft.CppUtils.Info(string.Format("{0} ver{1}",
                                           Application.ProductName, AmbLib.getAssemblyVersion(System.Reflection.Assembly.GetExecutingAssembly(), 3)));
 }
Exemple #5
0
        static void Main(String[] args)
        {
            Ambiesoft.CppUtils.AmbSetProcessDPIAware();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            // Application.Run(new FormMain());
            if (args.Length < 1)
            {
                CppUtils.Alert(Properties.Resources.NO_ARGUMENTS);
                return;
            }

            //string theFileName = @"C:\Documents and Settings\tt\My Documents\Productivity Distribution, Firm Heterogeneity, and Agglomeration.pdf";
            string theFileName = args[0];

            if (!System.IO.File.Exists(theFileName)) //&& !System.IO.Directory.Exists(theFileName))
            {
                CppUtils.Alert(string.Format(Properties.Resources.FILE_NOT_EXIST, theFileName));
                return;
            }


            System.IO.FileInfo fi        = new System.IO.FileInfo(theFileName);
            DateTime           oldCRTime = fi.CreationTime;
            DateTime           oldLWTime = fi.LastWriteTime;
            DateTime           oldLATime = fi.LastAccessTime;

            try
            {
                FormMain fm = new FormMain();
                AmbLib.SetFontAll(fm);

                fm.Text             = Application.ProductName;
                fm.txtFileName.Text = theFileName;


                fm.dtpCRTime.Tag   = oldCRTime;
                fm.dtpCRTime.Value = oldCRTime;

                fm.dtpLWTime.Tag   = oldLWTime;
                fm.dtpLWTime.Value = oldLWTime;

                fm.dtpLATime.Tag   = oldLATime;
                fm.dtpLATime.Value = oldLATime;

                if (DialogResult.OK == fm.ShowDialog())
                {
                    if (fm.dtCRResult != null)
                    {
                        fi.CreationTime = fm.dtCRResult;
                    }
                    if (fm.dtLWResult != null)
                    {
                        fi.LastWriteTime = fm.dtLWResult;
                    }
                    if (fm.dtLAResult != null)
                    {
                        fi.LastAccessTime = fm.dtLAResult;
                    }
                }
            }
            catch (Exception e)
            {
                CppUtils.Alert(e);
            }
        }
Exemple #6
0
 private void toolStripMenuItem6_Click(object sender, EventArgs e)
 {
     AmbLib.setRegMaxIE(11000);
 }
Exemple #7
0
        static void Main(string[] args)
        {
            string theArguments;

            if (args.Length < 1)
            {
                MessageBox.Show(Properties.Resources.NO_ARGUMENTS,
                                Application.ProductName,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }



            if (args[0] == "/run")
            {
                if (args.Length < 2)
                {
                    MessageBox.Show(string.Format(Properties.Resources.NO_ARGUMENTS_AFTER_RUN),
                                    Application.ProductName,
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Asterisk);
                    return;
                }

                theArguments = AmbLib.getAllArgs(2);


                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.FileName        = AmbLib.getAllArgs(theArguments, 0, true);
                startInfo.Arguments       = AmbLib.getAllArgs(theArguments, 1);
                startInfo.UseShellExecute = true;
                startInfo.Verb            = "open";
                //startInfo.Arguments = "start \"\" \"" + theFileName + "\"";
                //startInfo.Arguments = theFileName;

                try
                {
                    Process proc = Process.Start(startInfo);
                    // proc.WaitForExit();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, Application.ProductName,
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                return;
            }
            else  // not with /run
            {
                theArguments = AmbLib.getAllArgs(1);

                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.FileName         = Application.ExecutablePath;
                startInfo.UseShellExecute  = true;
                startInfo.Verb             = IsAdmin() ? null : "runas";
                startInfo.Arguments        = "/run " + theArguments;
                startInfo.WorkingDirectory = System.IO.Directory.GetParent(AmbLib.unDoubleQuote(AmbLib.getAllArgs(theArguments, 0, true))).FullName;;


                try
                {
                    Process proc = Process.Start(startInfo);
                    // proc.WaitForExit();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, Application.ProductName,
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                return;
            }
        }
Exemple #8
0
        static void Main(string[] args)
        {
            string theArguments;

            if (args.Length < 1)
            {
                MessageBox.Show(Properties.Resources.NO_ARGUMENTS,
                                Application.ProductName,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter           = "Shortcut Files|*.lnk";
            ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.SendTo);
            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            theArguments = AmbLib.getAllArgs(1);
            if (string.IsNullOrEmpty(theArguments))
            {
                MessageBox.Show(Properties.Resources.NO_ARGUMENTS,
                                Application.ProductName,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }


            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.FileName         = ofd.FileName;
            startInfo.Arguments        = theArguments;
            startInfo.UseShellExecute  = true;
            startInfo.Verb             = "runas";
            startInfo.Arguments        = theArguments;
            startInfo.WorkingDirectory = System.IO.Directory.GetParent(AmbLib.unDoubleQuote(AmbLib.getAllArgs(theArguments, 0, true))).FullName;


            try
            {
                Process proc = Process.Start(startInfo);
                // proc.WaitForExit();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Application.ProductName,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }


            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new FormMain());
        }
Exemple #9
0
        static bool processArgs(string[] args, out string inputFile)
        {
            inputFile = string.Empty;

            // first get lang from command line and set culture
            {
                string lang             = string.Empty;
                var    optionSetForLang = new OptionSet()
                {
                    {
                        "lang=",
                        Properties.Resources.STR_COMMANDLINEHELP_LANG,
                        v =>
                        {
                            lang = v;
                        }
                    },
                };
                optionSetForLang.SafeParse(args);
                if (!string.IsNullOrEmpty(lang))
                {
                    try
                    {
                        CultureInfo ci = new CultureInfo(lang);
                        System.Threading.Thread.CurrentThread.CurrentCulture   = ci;
                        System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, Application.ProductName,
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }

            bool   showHelp    = false;
            bool   showVersion = false;
            string dummy;
            var    optionSet = new OptionSet()
            {
                {
                    "lang=",
                    Properties.Resources.STR_COMMANDLINEHELP_LANG,
                    v =>
                    {
                        dummy = v;
                    }
                },
                {
                    "h|help|?",
                    Properties.Resources.STR_SHOWHELP,
                    v =>
                    {
                        showHelp = true;
                    }
                },
                {
                    "v|version",
                    Properties.Resources.STR_SHOWHELP,
                    v =>
                    {
                        showVersion = true;
                    }
                }
            };
            List <string> extra = optionSet.SafeParse(args);

            if (showHelp)
            {
                StringBuilder sb = new StringBuilder();
                using (StringWriter sw = new StringWriter(sb))
                    optionSet.WriteOptionDescriptions(sw);
                MessageBox.Show(sb.ToString(), Application.ProductName,
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }
            if (showVersion)
            {
                MessageBox.Show(
                    string.Format("{0} v{1}",
                                  Application.ProductName, AmbLib.getAssemblyVersion(Assembly.GetExecutingAssembly(), 3)),
                    Application.ProductName,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
                return(false);
            }
            if (extra.Count > 1)
            {
                foreach (string arg in extra)
                {
                    if (!File.Exists(arg) && !Directory.Exists(arg))
                    {
                        CppUtils.Fatal(string.Format(Properties.Resources.INTPUFILE_NOT_FOUND, arg));
                        continue;
                    }

                    try
                    {
                        Process.Start(Application.ExecutablePath, AmbLib.doubleQuoteIfSpace(arg));
                    }
                    catch (Exception ex)
                    {
                        CppUtils.Alert(ex);
                        continue;
                    }
                }
                return(false);
            }
            else if (extra.Count == 1)
            {
                inputFile = extra[0];
            }
            return(true);
        }
Exemple #10
0
        static void Main(string[] argsOriginal)
        {
            Ambiesoft.CppUtils.AmbSetProcessDPIAware();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);


            if (argsOriginal.Length < 1)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(Properties.Resources.NO_ARGUMENTS);
                sb.AppendLine();
                sb.AppendLine();

                sb.AppendLine(Properties.Resources.HELP);
                CppUtils.Alert(sb.ToString());
                return;
            }

            List <string> args = new List <string>();

            foreach (string arg in argsOriginal)
            {
                if (arg == "-h" || arg == "/h" || arg == "--help")
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine(Properties.Resources.HELP);
                    CppUtils.Alert(sb.ToString());
                    return;
                }
                else if (arg == "/run")
                {
                    run_ = true;
                    continue;
                }
                args.Add(arg);
            }

            if (args.Count > 1)
            {
                StringBuilder sbNotFounds = new StringBuilder();
                for (int i = 0; i < args.Count; ++i)
                {
                    try
                    {
                        if (File.Exists(args[i]) || Directory.Exists(args[i]))
                        {
                            System.Diagnostics.Process.Start(
                                Application.ExecutablePath,
                                (run_ ? "/run ": "") + "\"" + args[i] + "\"");
                        }
                        else
                        {
                            sbNotFounds.AppendLine(args[i]);
                        }
                    }
                    catch (System.Exception e)
                    {
                        CppUtils.Fatal(e.Message);
                    }
                }

                if (sbNotFounds.Length != 0)
                {
                    CppUtils.Alert(Properties.Resources.FOLLOWING_DOESNOT_EXIST + "\r\n\r\n" + sbNotFounds.ToString());
                }
                return;
            }

            string theFileName = args[0].Trim();

            // theFileName = @"C:\Documents and Settings\tt\My Documents\Productivity Distribution, Firm Heterogeneity, and Agglomeration.pdf";
            if (!File.Exists(theFileName) && !Directory.Exists(theFileName))
            {
                CppUtils.Alert(string.Format(Properties.Resources.FILE_NOT_FOUND, theFileName));
                return;
            }

            //System.IO.FileInfo fi = new System.IO.FileInfo(theFileName.Trim());
            //string olddir = fi.Directory.FullName;
            //string oldname = fi.Name;
            //string oldext = fi.Extension;
            bool   bIsFolder = Directory.Exists(theFileName);
            string newName   = bIsFolder ? Path.GetFileName(theFileName) : Path.GetFileNameWithoutExtension(theFileName);

            //if (!string.IsNullOrEmpty(oldext))
            //{
            //    newName = newName.Replace(oldext, "");
            //}

            do
            {
                try
                {
                    FormMain fm = new FormMain();
                    AmbLib.SetFontAll(fm);

                    fm.txtName.Text = newName;
                    fm.txtName.Tag  = theFileName;
                    if (DialogResult.OK != fm.ShowDialog())
                    {
                        return;
                    }

                    //newName = fm.txtName.Text;

                    //if (!RenameIt(olddir, newName, oldname, oldext))
                    //    continue;

                    break;
                }
                catch (Exception e)
                {
                    CppUtils.Alert(e.Message);
                }
            } while (true);
        }
Exemple #11
0
        static void Main(string[] args)
        {
            Ambiesoft.CppUtils.AmbSetProcessDPIAware();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            bool          isFileClipboard = false;
            SaveImageType sit             = SaveImageType.PNG;

            for (int i = 0; i < args.Length; ++i)
            {
                string arg = args[i];
                if (arg == "/c")
                {
                    isFileClipboard = true;
                }
                else if (arg == "/v" || arg == "-v" ||
                         arg == "/h" || arg == "-h" || arg == "/?" || arg == "--help")
                {
                    StringBuilder sbMessage = new StringBuilder();

                    sbMessage.AppendFormat("{0} - {1}",
                                           Application.ProductName,
                                           "Save an image on the clipboard to a file");
                    sbMessage.AppendLine();
                    sbMessage.AppendLine();
                    sbMessage.AppendLine("Usage:");
                    sbMessage.AppendFormat("{0} {1}",
                                           Path.GetFileNameWithoutExtension(Application.ExecutablePath),
                                           "[/c] [/t [png|jpg]] [/h]");
                    sbMessage.AppendLine();
                    sbMessage.AppendLine();

                    string optionformat = "{0}\t{1}";

                    sbMessage.AppendFormat(optionformat,
                                           "-h", Properties.Resources.ID_SHOW_HELP);
                    sbMessage.AppendLine();

                    sbMessage.AppendFormat(optionformat,
                                           "/c", Properties.Resources.ID_C_HELP);
                    sbMessage.AppendLine();

                    sbMessage.AppendFormat(optionformat,
                                           "/t", Properties.Resources.ID_T_HELP);
                    sbMessage.AppendLine();

                    sbMessage.AppendLine();
                    sbMessage.AppendLine("Copyright 2019 Ambiesoft");
                    sbMessage.AppendLine("https://ambiesoft.github.io/webjumper/?target=ClipimageToFile");

                    JR.Utils.GUI.Forms.FlexibleMessageBox.Show(
                        sbMessage.ToString(),
                        string.Format("{0} version {1}",
                                      Application.ProductName,
                                      AmbLib.getAssemblyVersion(Assembly.GetExecutingAssembly(), 3)),
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information);
                    return;
                }
                else if (arg == "/t")
                {
                    if ((i + 1) != args.Length)
                    {
                        ++i;
                        arg = args[i];
                        arg = arg.ToLower();
                        if (arg == "bmp")
                        {
                            sit = SaveImageType.BMP;
                        }
                        else if (arg == "jpg" || arg == "jpeg")
                        {
                            sit = SaveImageType.JPG;
                        }
                        else if (arg == "png")
                        {
                            sit = SaveImageType.PNG;
                        }
                        else
                        {
                            MessageBox.Show(Properties.Resources.INVALID_IMAGE_TYPE + " \"" + arg + "\"",
                                            Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return;
                        }
                    }
                }
                else
                {
                    MessageBox.Show(
                        string.Format(Properties.Resources.ID_UNKNOW_OPTION, arg),
                        Application.ProductName,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    return;
                }
            }

            Object o = Clipboard.GetData(DataFormats.Bitmap);

            if (!(o is Bitmap))
            {
                MessageBox.Show(Properties.Resources.NO_IMAGE_ON_CLIPBOARD,
                                Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            try
            {
                Bitmap b = (Bitmap)o;

                if (isFileClipboard)
                {
                    string      clipfileext = null;
                    ImageFormat clipimagef  = null;
                    switch (sit)
                    {
                    case SaveImageType.BMP:
                        clipfileext = ".bmp";
                        clipimagef  = ImageFormat.Bmp;
                        break;

                    case SaveImageType.JPG:
                        clipfileext = ".jpg";
                        clipimagef  = ImageFormat.Jpeg;
                        break;

                    case SaveImageType.PNG:
                        clipfileext = ".png";
                        clipimagef  = ImageFormat.Png;
                        break;
                    }

                    string tempfile;
                    while (true)
                    {
                        DateTime now      = DateTime.Now;
                        string   datetime = "clipshot " + getDTString(now);
                        tempfile = System.IO.Path.GetTempPath() + datetime + clipfileext;
                        if (File.Exists(tempfile))
                        {
                            System.Threading.Thread.Sleep(1000);
                            continue;
                        }
                        break;
                    }

                    b.Save(tempfile, clipimagef);

                    // file to be cut on clipboard
                    string[] fileNames = { tempfile };
                    // DataObject will be holding data
                    DataObject data = new DataObject(DataFormats.FileDrop, fileNames);

                    // DragDropEffects.Move
                    byte[] bs = new byte[] { (byte)DragDropEffects.Move, 0, 0, 0 };
                    System.IO.MemoryStream ms = new System.IO.MemoryStream(bs);
                    data.SetData("Preferred DropEffect", ms);
                    data.SetText(tempfile);

                    // cut onto clipbard
                    Clipboard.Clear();
                    Clipboard.SetDataObject(data, true);

                    Application.DoEvents();

                    showBalloon(Properties.Resources.IMAGE_HAS_SET_ON_CLIPBOARD);
                }
                else
                {
                    CustomControls.FormSaveFileDialog ofd = new CustomControls.FormSaveFileDialog();
                    ofd.pbxPreview.Image    = (Bitmap)b.Clone();
                    ofd.lblColorsValue.Text = ofd.GetColorsCountFromImage(ofd.pbxPreview.Image);
                    ofd.lblFormatValue.Text = ofd.GetFormatFromImage(ofd.pbxPreview.Image);

                    ofd.OpenDialog.Title        = b.Width + "x" + b.Height + " - " + Application.ProductName;
                    ofd.OpenDialog.AddExtension = true;

                    System.Collections.ArrayList arFilers = new System.Collections.ArrayList();
                    string           filter = string.Empty;
                    ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
                    int filtin = 0;
                    int i      = 0;
                    foreach (ImageCodecInfo codec in codecs)
                    {
                        if ((codec.Flags & ImageCodecFlags.Encoder) != 0)
                        {
                            if (ImageFormat.Gif.Guid != codec.FormatID)
                            {
                                string ext = codec.FilenameExtension;
                                ext     = ext.Split(';')[0];
                                ext     = ext.ToLower();
                                filter += codec.FormatDescription + " (" + ext + ")|" + ext + "|";

                                if (isEqualCodec(codec.FormatDescription.ToLower(), sit))
                                {
                                    filtin = i;
                                }

                                arFilers.Add(codec);
                                ++i;
                            }
                        }
                    }
                    ofd.OpenDialog.Filter      = filter.TrimEnd('|');
                    ofd.OpenDialog.FilterIndex = filtin + 1;
                    if (DialogResult.OK != ofd.ShowDialog())
                    {
                        return;
                    }

                    ImageCodecInfo ici = (ImageCodecInfo)arFilers[ofd.OpenDialog.FilterIndex - 1];

                    EncoderParameters encoderParameters = new EncoderParameters(1);
                    encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L);
                    b.Save(ofd.OpenDialog.FileName, ici, encoderParameters);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,
                                Application.ProductName,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }