예제 #1
0
        bool Displace(string message)
        {
            do
            {
                List <string> toRemoves     = new List <string>();
                DirectoryInfo di            = new DirectoryInfo(SendToFolder);
                FileInfo[]    filesOnSendto = di.GetFiles("*.lnk", SearchOption.TopDirectoryOnly);
                foreach (FileInfo fi in filesOnSendto)
                {
                    string data;
                    if (Helper.ReadAlternateStream(fi.FullName, out data))
                    {
                        if (data == "1")
                        {
                            toRemoves.Add(fi.FullName);
                        }
                    }
                }

                StringBuilder sb = new StringBuilder();
                sb.AppendLine(message);
                sb.AppendLine();

                foreach (string f in toRemoves)
                {
                    sb.AppendLine("\"" + f + "\"");
                }

                if (toRemoves.Count > 0)
                {
                    if (DialogResult.Yes != YesOrNo(sb.ToString()))
                    {
                        break;
                    }

                    if (0 != CppUtils.DeleteFiles(toRemoves.ToArray()))
                    {
                        Alert(Properties.Resources.FAILED_TO_REMOVE_FILES);
                        return(false);
                    }
                }
            } while (false);
            return(true);
        }
예제 #2
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);
                }
            }
        }