Esempio n. 1
0
        private void btnAbout_Click(object sender, EventArgs e)
        {
            StringBuilder sbMessage = new StringBuilder();

            sbMessage.AppendLine(string.Format("{0} v{1}",
                                               Application.ProductName,
                                               AmbLib.getAssemblyVersion(Assembly.GetExecutingAssembly(), 3)));
            sbMessage.AppendLine();

            sbMessage.AppendLine(AmbLib.getAssemblyCopyright(Assembly.GetExecutingAssembly()));
            sbMessage.AppendLine();

            sbMessage.AppendLine(Program.Url);
            sbMessage.AppendLine(Properties.Resources.PRESS_CTRL_OK);

            CppUtils.CenteredMessageBox(this,
                                        sbMessage.ToString(),
                                        Application.ProductName,
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);

            if (CppUtils.IsCtrlPressed())
            {
                try
                {
                    Process.Start(Program.Url);
                }
                catch (Exception ex)
                {
                    CppUtils.Alert(ex);
                }
            }
        }
Esempio n. 2
0
        private void copyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            StringBuilder sb    = new StringBuilder();
            bool          first = true;

            foreach (ListViewItem item in listUrls.SelectedItems)
            {
                if (!first)
                {
                    sb.AppendLine();
                }
                else
                {
                    first = false;
                }

                sb.Append(item.Text);
            }

            try
            {
                Clipboard.SetText(sb.ToString());
            }
            catch (Exception ex)
            {
                CppUtils.Alert(ex);
            }
        }
Esempio n. 3
0
        private void FormMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            bool success = true;

            HashIni ini = Profile.ReadAll(IniPath);

            success &= Profile.WriteBool(SECTION_OPTION, KEY_CHECK_SINGLECLICK, chkShowSingleClick.Checked, ini);
            success &= Profile.WriteBool(SECTION_OPTION, KEY_CHECK_DOUBLECLICK, chkShowDoubleClick.Checked, ini);
            success &= Profile.WriteBool(SECTION_OPTION, KEY_CHECK_UP, chkShowUp.Checked, ini);
            success &= Profile.WriteBool(SECTION_OPTION, KEY_CHECK_DOWN, chkShowDown.Checked, ini);
            success &= Profile.WriteBool(SECTION_OPTION, KEY_CHECK_WHEEL, chkShowWheel.Checked, ini);
            success &= Profile.WriteBool(SECTION_OPTION, KEY_CHECK_MOVE, chkShowMove.Checked, ini);

            success &= AmbLib.SaveFormXYWH(this, SECTION_LOCATION, ini);

            success &= Profile.WriteInt(SECTION_OPTION, KEY_SPLITTER_DISTANCE, splitMain.SplitterDistance, ini);

            if (success)
            {
                try
                {
                    success &= Profile.WriteAll(ini, IniPath, true);
                }
                catch (Exception)
                {
                    success = false;
                }
            }

            if (!success)
            {
                CppUtils.Alert(Properties.Resources.SAVE_FAILED);
            }
        }
Esempio n. 4
0
 void FatalExit(string message, bool bExit)
 {
     CppUtils.Alert(message);
     if (bExit)
     {
         Environment.Exit(1);
     }
 }
Esempio n. 5
0
        static bool preRun()
        {
            if (!FolderConfigHelper.IsFolderAccessible(ConfigDir))
            {
                CppUtils.Alert(string.Format(Properties.Resources.ALERT_DIRECTORY_UNAVAILABLE, ConfigDir));
                return(false);
            }

            return(true);
        }
Esempio n. 6
0
 private void btnOK_Click(object sender, EventArgs e)
 {
     try
     {
         Serialize(true);
     }
     catch (Exception ex)
     {
         CppUtils.Alert(ex);
         DialogResult = DialogResult.None;
     }
 }
Esempio n. 7
0
        private void FormMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            HashIni ini = Profile.ReadAll(IniPath);

            AmbLib.SaveFormXYWH(this, SECTION_LOCATION, ini);
            AmbLib.SaveListViewColumnWidth(listMain, SECTION_OPTION, KEY_COLUMN_WIDTH, ini);
            AmbLib.SaveComboBox(cmbApplication, SECTION_APP_COMBO, MAX_COMBO_SAVE, ini);
            AmbLib.SaveComboBox(cmbArguments, SECTION_ARG_COMBO, MAX_COMBO_SAVE, ini);
            if (!Profile.WriteAll(ini, IniPath))
            {
                CppUtils.Alert("Failed to save ini");
            }
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            Ambiesoft.CppUtils.AmbSetProcessDPIAware();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (args.Length < 1)
            {
                CppUtils.Alert(Properties.Resources.NO_ARG);
                return;
            }

            try
            {
                string[] lines = System.IO.File.ReadAllLines(args[0]);
                if (lines.Length == 0)
                {
                    CppUtils.Alert(Properties.Resources.NO_FILE_CONTENT);
                    return;
                }

                if (lines[0].Length == 0)
                {
                    CppUtils.Alert(Properties.Resources.EMPTY_FIRST_LINE);
                    return;
                }


                Clipboard.SetText(lines[0]);

                // https://www.flickr.com/photos/thotmeglynn/5161731232/sizes/q/

                NotifyIcon ni = new NotifyIcon();
                ni.BalloonTipTitle = Application.ProductName;
                ni.BalloonTipText  = Properties.Resources.FIRST_LINE_IS_SET_ON_CLIPBOARD;
                ni.Icon            = Properties.Resources.icon;

                ni.Text    = Application.ProductName;
                ni.Visible = true;
                ni.ShowBalloonTip(5 * 1000);

                System.Threading.Thread.Sleep(5 * 1000);
                ni.Dispose();
            }
            catch (Exception ex)
            {
                CppUtils.Fatal(ex);
            }
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            Ambiesoft.CppUtils.AmbSetProcessDPIAware();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try
            {
                doit(args);
            }
            catch (Exception ex)
            {
                CppUtils.Alert(ex);
            }
        }
Esempio n. 10
0
        private void btnCrop_Click(object sender, EventArgs e)
        {
            if (listUrls.SelectedItems.Count == 0)
            {
                CppUtils.Alert(this, Properties.Resources.NO_ITEM_SELECTED);
                return;
            }

            foreach (ListViewItem item in listUrls.Items)
            {
                if (!item.Selected)
                {
                    item.Remove();
                }
            }
        }
Esempio n. 11
0
        private void btnEditNotification_Click(object sender, EventArgs e)
        {
            HashIni ini = Profile.ReadAll(IniPath);

            afterFinishDialog_.LoadValues("AfterFinish", ini);
            if (DialogResult.OK != afterFinishDialog_.ShowDialog())
            {
                return;
            }
            txtNotification.Text = afterFinishDialog_.ToDescription();
            afterFinishDialog_.SaveValues("AfterFinish", ini);
            if (!Profile.WriteAll(ini, IniPath))
            {
                CppUtils.Alert("Failed to save ini");
            }
        }
Esempio n. 12
0
        private void FormMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            HashIni ini = Profile.ReadAll(IniFile);

            Profile.WriteInt(SECTION_SETTING, "X", Location.X, ini);
            Profile.WriteInt(SECTION_SETTING, "Y", Location.Y, ini);
            Profile.WriteInt(SECTION_SETTING, "Width", Size.Width, ini);
            Profile.WriteInt(SECTION_SETTING, "Height", Size.Height, ini);

            Profile.WriteBool(SECTION_SETTING, KEY_SMARTDOUBLECLICKSELECTION,
                              tsmiSmartDoubleClickSelection.Checked, ini);

            if (!Profile.WriteAll(ini, IniFile))
            {
                CppUtils.Alert("failed saving ini.");
            }
        }
Esempio n. 13
0
 private void addModifyToolToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         if (DialogResult.OK !=
             _mTools.Edit(Miszou.ToolManager.Tools.EditFlags.AllowLockedUIEdit, this)
             )
         {
             return;
         }
     }
     catch (Exception ex)
     {
         CppUtils.Alert(ex.Message);
         return;
     }
 }
Esempio n. 14
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

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

            foreach (string arg in args)
            {
                if (!File.Exists(arg))
                {
                    CppUtils.Alert(string.Format(Properties.Resources.S_FILE_NOT_EXISTS, arg));
                    return;
                }
                inputVideos.Add(Path.GetFullPath(arg));
            }
            Application.Run(new FormMain(inputVideos));
        }
Esempio n. 15
0
        internal static bool RenameIt(IWin32Window win, string oldfull, string newName)
        {
            //if (oldname == (newName + oldext))
            //{
            //    return true;
            //}

            //if (string.IsNullOrEmpty(oldext))
            //{
            //    newName = newName.TrimEnd(' ');
            //}

            if (!File.Exists(oldfull) && !Directory.Exists(oldfull))
            {
                CppUtils.Alert(string.Format(Properties.Resources.SOURCEFILE_NOT_FOUND, oldfull));
                return(false);
            }

            if (string.IsNullOrEmpty(newName))
            {
                CppUtils.Alert(Properties.Resources.ENTER_FILENAME);
                return(false);
            }

            if (-1 != newName.IndexOfAny(damemoji.ToCharArray()))
            {
                CppUtils.Alert(Properties.Resources.FOLLOWING_UNABLE_FILENAME + Environment.NewLine + Environment.NewLine + damemoji);
                return(false);
            }

            string olddir  = Path.GetDirectoryName(oldfull);
            string oldext  = Directory.Exists(oldfull) ? string.Empty : Path.GetExtension(oldfull);
            string newfull = Path.Combine(olddir, newName + oldext);

            if (String.Compare(oldfull, newfull, true) == 0)
            {
                return(true);
            }

            int ret = Ambiesoft.CppUtils.MoveFile(win, oldfull, newfull);

            return(ret == 0);
        }
Esempio n. 16
0
        static int Main(string[] args)
        {
            Ambiesoft.CppUtils.AmbSetProcessDPIAware();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            if (args.Length == 0)
            {
                CppUtils.Alert("No Args");
                return(-1);
            }

            FormMain f = new FormMain();

            f.txtExe.Text = args[0];
            f.ShowDialog();
            f.Dispose();

            return(0);
        }
Esempio n. 17
0
 private void btnReopenAsAdmin_Click(object sender, EventArgs e)
 {
     btnReopenAsAdmin.Enabled = false;
     try
     {
         if (AmbLib.StartAsAdmin())
         {
             this.Close();
         }
         return;
     }
     catch (Exception ex)
     {
         CppUtils.Alert(this, ex);
     }
     finally
     {
         btnReopenAsAdmin.Enabled = true;
     }
 }
Esempio n. 18
0
        static void Main(string[] args)
        {
            Ambiesoft.CppUtils.AmbSetProcessDPIAware();

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

            if (args.Length < 1)
            {
                CppUtils.Alert("No Arguments");
                return;
            }

            try
            {
                dowork(args[0]);
            }
            catch (Exception ex)
            {
                CppUtils.Fatal(ex);
            }
        }
Esempio n. 19
0
        private void FormPrint_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult.Yes != CppUtils.CenteredMessageBox(this,
                                                                Properties.Resources.AreYouSureToQuit,
                                                                Application.ProductName,
                                                                MessageBoxButtons.YesNo,
                                                                MessageBoxIcon.Question,
                                                                MessageBoxDefaultButton.Button2))
            {
                e.Cancel = true;
                return;
            }

            HashIni ini = Profile.ReadAll(IniFile);

            Profile.WriteInt(SECTION_OPTION, KEY_WAIT_COUNT, decimal.ToInt32(udWait.Value), ini);
            if (!Profile.WriteAll(ini, IniFile))
            {
                CppUtils.Alert(Properties.Resources.FAILED_TO_SAVE_INI);
            }
            Environment.Exit(0);
        }
Esempio n. 20
0
        public FormMain()
        {
            InitializeComponent();

            this.panelClick.MouseWheel += panelClick_MouseWheel;
            // Load from ini file
            bool bval;

            try
            {
                ini_ = Profile.ReadAll(IniPath, true);

                Profile.GetBool(SECTION_OPTION, KEY_CHECK_SINGLECLICK, true, out bval, ini_);
                chkShowSingleClick.Checked = bval;
                Profile.GetBool(SECTION_OPTION, KEY_CHECK_DOUBLECLICK, false, out bval, ini_);
                chkShowDoubleClick.Checked = bval;
                Profile.GetBool(SECTION_OPTION, KEY_CHECK_UP, false, out bval, ini_);
                chkShowUp.Checked = bval;
                Profile.GetBool(SECTION_OPTION, KEY_CHECK_DOWN, true, out bval, ini_);
                chkShowDown.Checked = bval;
                Profile.GetBool(SECTION_OPTION, KEY_CHECK_WHEEL, true, out bval, ini_);
                chkShowWheel.Checked = bval;
                Profile.GetBool(SECTION_OPTION, KEY_CHECK_MOVE, true, out bval, ini_);
                chkShowMove.Checked = bval;

                AmbLib.LoadFormXYWH(this, SECTION_LOCATION, ini_);
            }
            catch (FileNotFoundException)
            {
            }
            catch (Exception ex)
            {
                CppUtils.Alert(ex);
                Environment.Exit(1);
            }

            // Set Title
            this.Text = Application.ProductName;
        }
Esempio n. 21
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);
        }
Esempio n. 22
0
        static int Main(string[] args)
        {
            Ambiesoft.CppUtils.AmbSetProcessDPIAware();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            SimpleCommandLineParserWritable parser = new SimpleCommandLineParserWritable(args);

            parser.addOption("rf", ARGUMENT_TYPE.MUST);
            parser.addOption("rfu", ARGUMENT_TYPE.MUST);
            parser.addOption("rt", ARGUMENT_TYPE.MUST);
            parser.addOption("rtu", ARGUMENT_TYPE.MUST);

            parser.addOption("ie", ARGUMENT_TYPE.MUSTNOT);
            parser.addOption("ic", ARGUMENT_TYPE.MUSTNOT);
            parser.addOption("cf", ARGUMENT_TYPE.MUSTNOT);
            parser.addOption("ncf", ARGUMENT_TYPE.MUSTNOT);
            parser.addOption("ca", ARGUMENT_TYPE.MUSTNOT);
            parser.addOption("glob", ARGUMENT_TYPE.MUSTNOT);
            parser.addOption("h", ARGUMENT_TYPE.MUSTNOT);
            parser.addOption("?", ARGUMENT_TYPE.MUSTNOT);

            parser.Parse();

            if (parser.getInvalidOptions().Length != 0)
            {
                StringBuilder sbMessage = new StringBuilder();
                sbMessage.AppendLine(Properties.Resources.INVALID_OPTION);
                foreach (string s in parser.getInvalidOptions())
                {
                    sbMessage.AppendLine(s);
                }

                sbMessage.AppendLine();
                sbMessage.AppendLine(Properties.Resources.HYPHEN_EXPLANATION);

                ShowAlert(sbMessage.ToString());
                return(1);
            }
            if (parser["h"] != null || parser["?"] != null)
            {
                ShowHelp();
                return(0);
            }


            StringBuilder sbCheckArguments = new StringBuilder();

            using (var prepareForm = new FormPrepare(parser))
            {
                if (parser["rf"] != null)
                {
                    sbCheckArguments.Append("rf:");
                    sbCheckArguments.AppendLine(parser["rf"].ToString());
                }
                if (parser["rfu"] != null)
                {
                    sbCheckArguments.Append("rfu:");
                    sbCheckArguments.AppendLine(parser["rfu"].ToString());
                }

                if (parser["rt"] != null)
                {
                    sbCheckArguments.Append("rt:");
                    sbCheckArguments.AppendLine(parser["rt"].ToString());
                }
                if (parser["rtu"] != null)
                {
                    sbCheckArguments.Append("rtu:");
                    sbCheckArguments.AppendLine(parser["rtu"].ToString());
                }

                if (parser["ie"] != null)
                {
                    sbCheckArguments.AppendLine("ie");
                }
                if (parser["ic"] != null)
                {
                    sbCheckArguments.AppendLine("ic");
                }
                if (parser["ca"] != null)
                {
                    sbCheckArguments.AppendLine("ca");
                }

                if (parser["cf"] != null)
                {
                    sbCheckArguments.AppendLine("cf");
                }
                if (parser["ncf"] != null)
                {
                    sbCheckArguments.AppendLine("ncf");
                }
                if (parser["glob"] != null)
                {
                    sbCheckArguments.AppendLine("glob");
                }

                if (parser["h"] != null)
                {
                    sbCheckArguments.AppendLine("h");
                }
                if (parser["?"] != null)
                {
                    sbCheckArguments.AppendLine("?");
                }

                sbCheckArguments.AppendLine();
                sbCheckArguments.AppendLine(Properties.Resources.DO_YOU_WANT_TO_CONTINUE);

                if (GetKeyState(VirtualKeyStates.VK_SHIFT) < 0 ||
                    GetKeyState(VirtualKeyStates.VK_CONTROL) < 0)
                {
                    if (DialogResult.OK != prepareForm.ShowDialog())
                    {
                        return(0);
                    }
                }
            }

            if (parser["ca"] != null)
            {
                // check argument
                if (DialogResult.Yes != CppUtils.CenteredMessageBox(sbCheckArguments.ToString(),
                                                                    Application.ProductName + " " + "check arg",
                                                                    MessageBoxButtons.YesNo,
                                                                    MessageBoxIcon.Question,
                                                                    MessageBoxDefaultButton.Button2))
                {
                    return(0);
                }
            }

            if (parser["rf"] != null && parser["rfu"] != null)
            {
                ShowAlert("TODO");
                return(1);
            }
            if (parser["rt"] != null && parser["rtu"] != null)
            {
                ShowAlert("TODO");
                return(1);
            }

            if (parser["rf"] == null && parser["rfu"] == null)
            {
                ShowAlert(Properties.Resources.MUST_SPECIFY_RF_RT);
                return(1);
            }
            if (parser["rt"] == null && parser["rtu"] == null)
            {
                ShowAlert(Properties.Resources.MUST_SPECIFY_RF_RT);
                return(1);
            }

            string strRegFind = string.Empty;

            if (parser["rf"] != null)
            {
                strRegFind = parser["rf"].ToString();
            }
            else if (parser["rfu"] != null)
            {
                strRegFind = System.Web.HttpUtility.UrlDecode(parser["rfu"].ToString());
            }
            else
            {
                throw new Exception(Properties.Resources.UNEXPECTED_ERROR);
            }

            string strTarget = string.Empty;

            if (parser["rt"] != null)
            {
                strTarget = parser["rt"].ToString();
            }
            else if (parser["rtu"] != null)
            {
                strTarget = System.Web.HttpUtility.UrlDecode(parser["rtu"].ToString());
            }
            else
            {
                throw new Exception(Properties.Resources.UNEXPECTED_ERROR);
            }


            if (parser.MainargLength == 0)
            {
                ShowAlert(Properties.Resources.NO_FILE);
                return(1);
            }

            Regex regf = null;

            try
            {
                if (parser["ic"] != null)
                {
                    regf = new Regex(strRegFind, RegexOptions.IgnoreCase);
                }
                else
                {
                    regf = new Regex(strRegFind);
                }
            }
            catch (Exception ex)
            {
                CppUtils.CenteredMessageBox(ex.Message);
                return(1);
            }
            bool isAlsoExt = null != parser["ie"];

            if (parser["cf"] != null && parser["ncf"] != null)
            {
                ShowAlert(Properties.Resources.BOTH_CF_NCF_SPECIFIED);
                return(1);
            }
            bool dryrun = parser["ncf"] == null;
            Dictionary <string, string> targets = new Dictionary <string, string>();

            string[] mainArgs = ConstructMainArgs(parser);
            try
            {
                foreach (string orgFullorRelativeFileName in mainArgs)
                {
                    FileInfo fiorig      = new FileInfo(orgFullorRelativeFileName);
                    string   orgFileName = getProperName(fiorig, isAlsoExt);
                    string   orgFolder   = fiorig.DirectoryName;

                    string newFileName = regf.Replace(orgFileName, strTarget);
                    if (!isAlsoExt)
                    {
                        newFileName += fiorig.Extension;
                    }

                    targets.Add(fiorig.FullName, orgFolder + @"\" + newFileName);
                }

                if (dryrun)
                {
                    StringBuilder sbDryAll      = new StringBuilder();
                    StringBuilder sbDryChanging = new StringBuilder();
                    bool          bRenameExists = false;
                    foreach (string org in targets.Keys)
                    {
                        if (org != targets[org])
                        {
                            bRenameExists = true;
                            string tmp = string.Format("\"{0}\" ->\r\n\"{1}\"",
                                                       Path.GetFileName(org),
                                                       Path.GetFileName(targets[org]));

                            sbDryAll.Append(tmp);

                            sbDryChanging.Append(tmp);
                            sbDryChanging.AppendLine();
                            sbDryChanging.AppendLine();
                        }
                        else
                        {
                            sbDryAll.AppendFormat("\"{0}\" -> " + Properties.Resources.NO_CHANGE,
                                                  Path.GetFileName(org),
                                                  Path.GetFileName(targets[org]));
                        }
                        sbDryAll.AppendLine();
                        sbDryAll.AppendLine();
                    }

                    using (FormConfirm form = new FormConfirm())
                    {
                        form.Text            = Application.ProductName + " " + Properties.Resources.CONFIRM;
                        form.lblMessage.Text = !bRenameExists ?
                                               Properties.Resources.NO_FILES_TO_RENAME:
                                               Properties.Resources.DO_YOU_WANT_TO_PERFORM;
                        form.initialTextAll_      = sbDryAll.ToString();
                        form.initialTextChanging_ = sbDryChanging.ToString();
                        form.btnYes.Enabled       = bRenameExists;
                        if (DialogResult.Yes != form.ShowDialog())
                        {
                            return(0);
                        }
                    }
                }

                foreach (string org in targets.Keys)
                {
                    if (org != targets[org])
                    {
                        if (Directory.Exists(org))
                        {
                            if (!tryMoveFile(org, targets[org], Directory.Move))
                            {
                                return(1);
                            }
                        }
                        else if (File.Exists(org))
                        {
                            if (!tryMoveFile(org, targets[org], File.Move))
                            {
                                return(1);
                            }
                        }
                        else
                        {
                            CppUtils.Alert(string.Format(Properties.Resources.FILE_NOT_EXIST, org));
                        }
                    }
                }
                return(0);
            }
            catch (Exception e)
            {
                CppUtils.Fatal(e.Message);
                return(-1);
            }
        }
Esempio n. 23
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);
        }
Esempio n. 24
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);
            }
        }
Esempio n. 25
0
        private void doJoinCommon(bool bReEncode, bool bH265)
        {
            if (lvMain.Items.Count < 1)
            {
                CppUtils.Alert(Properties.Resources.S_NO_ITEMS);
                return;
            }

            if (lvMain.Items.Count < 2)
            {
                if (DialogResult.Yes != CppUtils.YesOrNo(Properties.Resources.S_CONFIRM_JOIN_ONEITEM))
                {
                    return;
                }
            }

            // check file exists
            foreach (ListViewItem item in lvMain.Items)
            {
                if (!File.Exists(item.Text))
                {
                    CppUtils.Alert(this,
                                   string.Format(Properties.Resources.S_FILE_NOT_EXISTS, item.Text));
                    return;
                }
            }

            string ext        = null;
            string extwithout = null;

            foreach (ListViewItem item in lvMain.Items)
            {
                string   file = item.Text;
                FileInfo fi   = new FileInfo(file);
                if (ext == null)
                {
                    ext = fi.Extension;
                }
                else
                {
                    // check if extention is same.
                    if (!bReEncode)
                    {
                        if (string.Compare(ext, fi.Extension, true) != 0)
                        {
                            CppUtils.CenteredMessageBox(
                                this,
                                Properties.Resources.S_DIFFERENT_EXTENSION);
                            return;
                        }
                    }
                }
            }
            extwithout = ext.TrimStart('.');

            string outfilename = null;

            foreach (ListViewItem item in lvMain.Items)
            {
                string   file = item.Text;
                FileInfo fi   = new FileInfo(file);
                if (outfilename == null)
                {
                    outfilename = fi.Name;
                }
                else
                {
                    int isame = 0;
                    try
                    {
                        for (int i = 0; i < fi.Name.Length; ++i)
                        {
                            if (fi.Name[i] == outfilename[i])
                            {
                                isame = i + 1;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    catch (Exception) { }

                    outfilename = outfilename.Substring(0, isame);
                }
            }

            // find initdir for savedialog
            string initDir = null;

            foreach (ListViewItem item in lvMain.Items)
            {
                string d = Path.GetDirectoryName(item.Text);
                if (initDir == null)
                {
                    initDir = d;
                    continue;
                }

                if (d != initDir)
                {
                    initDir = null;
                    return;
                }
            }



            HashSet <string> exts = new HashSet <string>();

            if (!bReEncode)
            {
                exts.Add(extwithout);
            }
            else
            {
                exts.Add(extwithout);
                exts.Add("mp4");
                exts.Add("avi");
            }
            //string extwithout = ext.TrimStart('.');
            //string[] availableext = { "mp4", "avi" };
            string outfile = null;

            using (SaveFileDialog sfd = new SaveFileDialog())
            {
                sfd.FileName = outfilename;
                //string filter = extwithout + "File ";
                //filter += "(*.";
                //filter += extwithout;
                //filter += ")|*.";
                //filter += extwithout;
                //filter += "|All File(*.*)|*.*";
                //sfd.Filter=filter;

                StringBuilder sbFilter = new StringBuilder();
                foreach (string ae in exts)
                {
                    sbFilter.Append(ae);
                    sbFilter.Append("File ");
                    sbFilter.Append("(*.");


                    sbFilter.Append(ae);
                    sbFilter.Append(")|*.");
                    sbFilter.Append(ae);
                    sbFilter.Append("|");
                }
                sbFilter.Append("All File(*.*)|*.*");
                sfd.Filter = sbFilter.ToString();

                sfd.InitialDirectory = initDir;
                if (DialogResult.OK != sfd.ShowDialog(this))
                {
                    return;
                }

                outfile = sfd.FileName;

                // if extention is empty
                //string outfileext = Path.GetExtension(outfile).TrimStart('.').ToLower();
                //if (outfileext != extwithout)
                //{
                //    outfile += "." + extwithout;
                //}
            }


            // Create tmp file for ffmpeg argument
            string tempfile = string.Empty;

            if (!bReEncode)
            {
                tempfile = Path.GetTempFileName();
                using (TextWriter writer = File.CreateText(tempfile))
                {
                    foreach (ListViewItem item in lvMain.Items)
                    {
                        writer.Write(@"file '");
                        writer.Write(item.Text);
                        writer.Write(@"'");
                        writer.WriteLine();
                    }
                }
            }

            try
            {
                string ffmpeg = getffmpeg();

                string argument = string.Empty;
                if (!bReEncode)
                {
                    argument += "-safe 0 -f concat -i \"";

                    argument += tempfile;
                    argument += "\"";
                    argument += " -c copy \"";
                    argument += outfile;
                    argument += "\"";

                    // argument =
                    // -safe 0 -f concat -i "C:\Users\bjdTfeRf\AppData\Local\Temp\tmpEE1.tmp" -c copy "C:\Users\bjdTfeRf\Desktop\yyy\111.mp4"
                }
                else
                {
                    foreach (ListViewItem item in lvMain.Items)
                    {
                        argument += "-i \"" + item.Text + "\" ";
                    }

                    argument += "-filter_complex \"";
                    string tmp = "";
                    for (int i = 0; i < lvMain.Items.Count; ++i)
                    {
                        tmp += string.Format("[{0}:v:0] [{1}:a:0] ", i, i);
                    }
                    argument += tmp;

                    argument += string.Format("concat=n={0}:v=1:a=1 [v] [a]\" ", lvMain.Items.Count);
                    argument += "-map \"[v]\" -map \"[a]\" ";
                    if (bH265)
                    {
                        argument += "-vcodec libx265 ";
                    }
                    argument += "\"" + outfile + "\"";
                }

                //int retval;
                //string output, err;
                //AmbLib.OpenCommandGetResult(ffmpeg, argument, Encoding.UTF8, out retval, out output, out err);
                ProcessStartInfo psi = new ProcessStartInfo();
                psi.FileName  = ffmpeg;
                psi.Arguments = argument;
                psi.RedirectStandardOutput = false;
                psi.RedirectStandardError  = false;
                psi.UseShellExecute        = false;
                psi.CreateNoWindow         = false;

                Process p = Process.Start(psi);

                p.WaitForExit();
                if (p.ExitCode != 0)
                {
                    CppUtils.Alert(this,
                                   string.Format(Properties.Resources.S_JOIN_FAILED, p.ExitCode));
                    return;
                }

                CppUtils.OpenFolder(this, outfile);

                string prevsum   = getSum().ToString().TrimEnd('0');
                string resultsum = getVideoLength(outfile);

                StringBuilder sbMessage = new StringBuilder();

                sbMessage.AppendLine(string.Format(
                                         "{0}:\t\t{1}",
                                         Properties.Resources.S_DURATION_OF_INPUTFILES,
                                         prevsum));
                sbMessage.AppendLine(string.Format(
                                         "{0}:\t\t{1}",
                                         Properties.Resources.S_DURATION_OUTPUT,
                                         resultsum));

                sbMessage.AppendLine();
                sbMessage.AppendLine(Properties.Resources.S_DO_YOU_WANT_TO_OPEN_CREATED_VIDEO);
                if (DialogResult.Yes == CppUtils.CenteredMessageBox(this,
                                                                    sbMessage.ToString(),
                                                                    Application.ProductName,
                                                                    MessageBoxButtons.YesNo,
                                                                    MessageBoxIcon.Question))
                {
                    Process.Start(outfile);
                }

                //
                // deleting original files
                //
                List <string> filesToDel = new List <string>();
                foreach (ListViewItem item in lvMain.Items)
                {
                    filesToDel.Add(item.Text);
                }

                StringBuilder sbDeleteMessage = new StringBuilder();
                sbDeleteMessage.AppendLine(string.Format(Properties.Resources.S_DO_YOU_WANT_TO_TRASH_FOLLOWING_N_ORIGINAL_FILES, filesToDel.Count));
                sbDeleteMessage.AppendLine();
                foreach (string file in filesToDel)
                {
                    sbDeleteMessage.AppendLine(file);
                }
                if (DialogResult.Yes == CppUtils.CenteredMessageBox(this,
                                                                    sbDeleteMessage.ToString(),
                                                                    Application.ProductName,
                                                                    MessageBoxButtons.YesNo,
                                                                    MessageBoxIcon.Question,
                                                                    MessageBoxDefaultButton.Button2))
                {
                    CppUtils.DeleteFiles(this, filesToDel.ToArray());
                }
            }
            finally
            {
                if (!string.IsNullOrEmpty(tempfile))
                {
                    File.Delete(tempfile);
                }
            }
        }
Esempio n. 26
0
        private void btnJoinDifferent_Click_obsolete(object sender, EventArgs e)
        {
            if (lvMain.Items.Count < 2)
            {
                CppUtils.Alert(Properties.Resources.S_CONFIRM_JOIN_ONEITEM);
                return;
            }
            string outfilename = null;

            foreach (ListViewItem item in lvMain.Items)
            {
                string   file = item.Text;
                FileInfo fi   = new FileInfo(file);
                if (outfilename == null)
                {
                    outfilename = fi.Name;
                }
                else
                {
                    int isame = 0;
                    try
                    {
                        for (int i = 0; i < fi.Name.Length; ++i)
                        {
                            if (fi.Name[i] == outfilename[i])
                            {
                                isame = i + 1;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    catch (Exception) { }

                    outfilename = outfilename.Substring(0, isame);
                }
            }

            string outfile = null;

            string[] availableext = { "mp4", "avi" };
            using (SaveFileDialog sfd = new SaveFileDialog())
            {
                sfd.FileName = outfilename;
                StringBuilder sbFilter = new StringBuilder();
                foreach (string ae in availableext)
                {
                    sbFilter.Append(ae);
                    sbFilter.Append("File ");
                    sbFilter.Append("(*.");


                    sbFilter.Append(ae);
                    sbFilter.Append(")|*.");
                    sbFilter.Append(ae);
                    sbFilter.Append("|");
                }
                sbFilter.Append("All File(*.*)|*.*");

                sfd.Filter = sbFilter.ToString();
                if (DialogResult.OK != sfd.ShowDialog(this))
                {
                    return;
                }

                outfile = sfd.FileName;
            }


            string ffmpeg = getffmpeg();


            // c:\work>c:\LegacyPrograms\ffmpeg\bin\ffmpeg.exe -i stream_0.mp4 -i stream_1.mp4
            // -filter_complex "[0:v:0] [0:a:0] [1:v:0] [1:a:0] concat=n=2:v=1:a=1 [v] [a]" -ma
            // p "[v]" -map "[a]" aaa.mp4

            // -i "C:\work\stream_0.mp4" -i "C:\work\stream_1.mp4"
            // -filter_complex "[0:v:0] [0:a:0] [1:v:1] [1:a:1] concat=n=2:v=1:a=1 [v] [a]" -ma
            // p "[v]" -map "[a]" "C:\Users\1dollar\Desktop\4.mp4"

            string argument = "";

            foreach (ListViewItem item in lvMain.Items)
            {
                argument += "-i \"" + item.Text + "\" ";
            }

            argument += "-filter_complex \"";
            string tmp = "";

            for (int i = 0; i < lvMain.Items.Count; ++i)
            {
                tmp += string.Format("[{0}:v:0] [{1}:a:0] ", i, i);
            }
            argument += tmp;

            argument += string.Format("concat=n={0}:v=1:a=1 [v] [a]\" ", lvMain.Items.Count);

            argument += "-map \"[v]\" -map \"[a]\" ";

            argument += "\"" + outfile + "\"";


            //
            // -i "C:\Users\bjdTfeRf\Desktop\yyy\1.mp4" -i "C:\Users\bjdTfeRf\Desktop\yyy\2.mp4" -i "C:\Users\bjdTfeRf\Desktop\yyy\3.mp4" -filter_complex "[0:v:0] [0:a:0] [1:v:0] [1:a:0] [2:v:0] [2:a:0] concat=n=3:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" "C:\Users\bjdTfeRf\Desktop\yyy\111.mp4"
            ProcessStartInfo psi = new ProcessStartInfo();

            psi.FileName  = ffmpeg;
            psi.Arguments = argument;
            psi.RedirectStandardOutput = false;
            psi.RedirectStandardError  = false;
            psi.UseShellExecute        = false;
            psi.CreateNoWindow         = false;

            Process p = Process.Start(psi);

            p.WaitForExit();

            string prevsum   = getSum().ToString().TrimEnd('0');
            string resultsum = getVideoLength(outfile);

            CppUtils.CenteredMessageBox(this,
                                        "prev sum duration =\t" + prevsum + "\r\n" + "result duration =\t\t" + resultsum,
                                        Application.ProductName,
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
            //File.Delete(tempfile);
        }
Esempio n. 27
0
        static void doit(string[] args)
        {
            bool recursive   = false;
            int  depth       = -1;
            bool touchfolder = false;
            bool followlink  = false;
            var  p           = new OptionSet()
            {
                {
                    "r|recursive",
                    "Touch recursively",
                    v => { recursive = v != null; }
                },
                {
                    "d|depth=",
                    "Directory depth of recursive operation, 0 for specifying only arg itself, -1 for inifinite depth.",
                    v => { depth = int.Parse(v); }
                },
                {
                    "f|folder",
                    "Touch folders as well as files",
                    v => { touchfolder = v != null; }
                },
                {
                    "l|followlink",
                    "Follow links",
                    v => { followlink = v != null; }
                }
            };

            List <string> extra = p.Parse(args);

            if (extra.Count < 1)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(Properties.Resources.STR_NO_ARGUMENTS);
                sb.AppendLine();
                sb.AppendLine();
                StringWriter sw = new StringWriter(sb);
                p.WriteOptionDescriptions(sw);

                throw new Exception(sb.ToString());
            }


            if (((GetKeyState(0x10) & 0x8000) != 0) ||     // VK_SHIFT
                ((GetKeyState(0x11) & 0x8000) != 0) ||     // VK_CONTROL
                ((GetKeyState(0x02) & 0x8000) != 0))       // VK_RBUTTION
            {
                // check input has any folders.
                bool hasFolder = false;
                foreach (string filename in extra)
                {
                    if (Directory.Exists(filename))
                    {
                        hasFolder = true;
                        break;
                    }
                }

                if (hasFolder)
                {
                    if (DialogResult.Yes != CppUtils.YesOrNo(Properties.Resources.STR_CONFIRM_ALL_SUB,
                                                             MessageBoxDefaultButton.Button2))
                    {
                        return;
                    }
                    recursive = true;
                    depth     = -1;
                }
            }
            DateTime now          = DateTime.Now;
            int      touchedCount = 0;
            var      untouchabled = new Dictionary <string, Exception>();

            foreach (string filename in extra)
            {
                dotouch(now, filename, touchfolder, recursive, followlink, 0, depth, ref touchedCount, untouchabled);
            }
            if (untouchabled.Count != 0)
            {
                var sb = new StringBuilder();
                sb.AppendLine(Properties.Resources.STR_TOUCH_FAILED);
                sb.AppendLine();

                foreach (string key in untouchabled.Keys)
                {
                    sb.Append(key);
                    sb.Append(" (");
                    sb.Append(untouchabled[key].Message);
                    sb.Append(")");
                    sb.AppendLine();
                }
                CppUtils.Alert(sb.ToString());
            }
            showtip(5000, Application.ProductName,
                    string.Format(Properties.Resources.STR_TOUCHED, touchedCount), Properties.Resources.icon);
        }