예제 #1
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);
        }