Beispiel #1
0
        private void itemExistingFolder_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem item = sender as ToolStripMenuItem;

            if (item == null)
            {
                return;
            }
            string dir = item.Tag as string;

            if (dir == null)
            {
                // LANG
                CppUtils.Fatal(dir + " is not a directory");
                return;
            }
            else if (!System.IO.Directory.Exists(dir))
            {
                if (DialogResult.Yes != CppUtils.YesOrNo(string.Format(Properties.Resources.DIR_NOT_EXIST_DO_YOU_WANT_TO_REMOVE, dir),
                                                         MessageBoxDefaultButton.Button2))
                {
                    return;
                }
                removeFromDiskDirs(dir);
                return;
            }
            moveToAndClose(dir);
        }
Beispiel #2
0
 private void itemClearFolder_Click(object sender, EventArgs e)
 {
     if (DialogResult.Yes != CppUtils.YesOrNo(Properties.Resources.ARE_YOU_SURE_CLEAR_ALL_ITEMS,
                                              MessageBoxDefaultButton.Button2))
     {
         return;
     }
     DiskDirs = new string[0];
 }
Beispiel #3
0
        private void tsmiRemoveAll_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes != CppUtils.YesOrNo(string.Format("sure all items?"),
                                                     MessageBoxDefaultButton.Button2))
            {
                return;
            }

            listMain.Items.Clear();
        }
Beispiel #4
0
        private void btnClear_Click(object sender, EventArgs e)
        {
            if (Running)
            {
                return;
            }
            if (DialogResult.Yes != CppUtils.YesOrNo("Clear?", MessageBoxDefaultButton.Button2))
            {
                return;
            }

            ClearAllListIndicator();
        }
Beispiel #5
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            if (Running)
            {
                Cancelling = true;
                return;
            }
            Cancelling = false;
            if (IsListAllDone())
            {
                if (DialogResult.Yes != CppUtils.YesOrNo(
                        Properties.Resources.DO_IT_AGAIN,
                        MessageBoxDefaultButton.Button2))
                {
                    return;
                }
                ClearAllListIndicator();
            }
            UpdateCombo();

            List <KeyValuePair <string, string> > willExecute = new List <KeyValuePair <string, string> >();

            RunAsync(RunAsyncType.RunAsync_DryRun, willExecute);
            StringBuilder sbFilesAndArgs = new StringBuilder();

            for (int i = 0; i < willExecute.Count; ++i)
            {
                sbFilesAndArgs.AppendLine(string.Format("File{0}={1}", i, willExecute[i].Key));
                sbFilesAndArgs.AppendLine(string.Format("Args{0}={1}", i, willExecute[i].Value));
                sbFilesAndArgs.AppendLine();
            }

            StringBuilder sbMessage = new StringBuilder();

            sbMessage.AppendLine(Properties.Resources.BEFORE_RUN_MESSAGE);
            sbMessage.AppendLine();
            sbMessage.Append(sbFilesAndArgs);
            if (DialogResult.Yes != CppUtils.CenteredMessageBox(this,
                                                                sbMessage.ToString(),
                                                                Application.ProductName,
                                                                MessageBoxButtons.YesNo,
                                                                MessageBoxIcon.Question))
            {
                return;
            }

            RunAsync(RunAsyncType.RunAsync_Normal, null);
        }
Beispiel #6
0
        private void tsmiRemove_Click(object sender, EventArgs e)
        {
            int countSelected = GetSelectedItemCount();

            if (countSelected == 0)
            {
                return;
            }

            if (DialogResult.Yes != CppUtils.YesOrNo(string.Format("sure {0} items?", countSelected),
                                                     MessageBoxDefaultButton.Button2))
            {
                return;
            }

            ClearSelectedListItems();
        }
Beispiel #7
0
        private void btnTrash_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes != CppUtils.YesOrNo(string.Format(Properties.Resources.ARE_YOU_SURE_TO_TRASH, txtName.Tag.ToString()),
                                                     MessageBoxDefaultButton.Button2))
            {
                return;
            }

            List <Control> cs = disableAll();

            try
            {
                //FileSystem.DeleteFile(
                //  this.txtName.Tag.ToString(),
                //  UIOption.OnlyErrorDialogs,
                //  RecycleOption.SendToRecycleBin);

                if (0 == CppUtils.DeleteFile(this, this.txtName.Tag.ToString()))
                {
                    Close();
                }
            }
            catch (Exception)
            {
                //using (new Ambiesoft.CenteringDialog(this))
                //{
                //    MessageBox.Show(ex.Message,
                //    Application.ProductName,
                //    MessageBoxButtons.OK,
                //    MessageBoxIcon.Exclamation);
                //}
            }
            finally
            {
                enableAll(cs);
            }
        }
Beispiel #8
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);
        }
Beispiel #9
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);
                }
            }
        }