Example #1
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            string title = string.Format("{0} - {1}",
                                         AmbLib.doubleQuoteIfSpace(Path.GetFileName(txtName.Tag.ToString())),
                                         ProductName);

            this.Text = title;

            if (chkAutoRun.Checked || Program.run_)
            {
                Program.SafeProcessStart(this.txtName.Tag.ToString(), true);
            }

            try
            {
                FileInfo      fi = new FileInfo(this.txtName.Tag.ToString());
                StringBuilder sb = new StringBuilder();
                sb.Append(Properties.Resources.Size);
                sb.Append(": ");
                sb.Append(SizeSuffix(fi.Length));
                lblFileInfo.Text  = sb.ToString();
                lblExtention.Text = Properties.Resources.Extention + ": " + fi.Extension;
            }
            catch (Exception) { }

            BeginInvoke(new EventHandler(this.afterLoad), sender, e);
        }
Example #2
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);
        }