diff --git a/FFBatch/Form1_prev.cs b/FFBatch/Form1_prev.cs deleted file mode 100644 index 4b0834fa..00000000 --- a/FFBatch/Form1_prev.cs +++ /dev/null @@ -1,52830 +0,0 @@ -using FFBatch.Properties; -using Microsoft.VisualBasic.FileIO; -using Microsoft.Win32; -using Shell32; -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Diagnostics; -using System.Drawing; -using System.Globalization; -using System.IO; -using System.Linq; -using System.Management.Instrumentation; -using System.Net; -using System.Reflection; -using System.Runtime.ExceptionServices; -using System.Runtime.InteropServices; -using System.Security.Cryptography; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace FFBatch -{ - public partial class Form1 : Form - { - - internal const int CTRL_C_EVENT = 0; - - [DllImport("kernel32.dll")] - internal static extern bool GenerateConsoleCtrlEvent(uint dwCtrlEvent, uint dwProcessGroupId); - - [DllImport("kernel32.dll", SetLastError = true)] - internal static extern bool AttachConsole(uint dwProcessId); - - [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)] - internal static extern bool FreeConsole(); - - [DllImport("kernel32.dll")] - private static extern bool SetConsoleCtrlHandler(ConsoleCtrlDelegate HandlerRoutine, bool Add); - - // Delegate type to be used as the Handler Routine for SCCH - private delegate Boolean ConsoleCtrlDelegate(uint CtrlType); - - private String prev_map = String.Empty; - public List sel_filter = new List(); - public List ff_ena = new List(); - Boolean ss_to = false; - private Double total_prog = 0; - private List list_chaps = new List(); - private List list_chaps_m = new List(); - private Boolean watched_tick = false; - private String chapters_m = String.Empty; - private String err_chaps = "[splitchapters] chapter information is unavailable"; - private int paused_bats = 0; - private Boolean paused_battery = false; - private Boolean target_one_pass = false; - private String target_aud_cod = String.Empty; - private int target_aud_bit = 64; - private String target_codec = String.Empty; - private String target_profile = String.Empty; - private Boolean target_size = false; - private int target_mb = 0; - private Boolean keep_dates = false; - private List custom_m_params = new List(); - private int cust_p_col = 0; - private String atempo = ""; - private Double atemp = 1; - private Boolean reloaded_q = false; - private Boolean ignore_encoded = false; - private Boolean no_output_pop = false; - private List already_scan = new List(); - private String current_out = ""; - private List selecs = new List(); - private ProgressBarWithText Pg1 = new ProgressBarWithText(); - private Boolean show_est = false; - private int current_fr = 4000; - private Boolean warn_space = false; - private Decimal check_space = 1; - private String img_dur_wiz = "0"; - private Boolean images_from_wiz = false; - private String split_by_size = ""; - private String img_aud_from_wiz = ""; - private Boolean start_seq = false; - private Boolean start_multi = false; - public string language = Settings.Default.app_lang; - private Boolean has_lives_multi = false; - private Boolean t_out_yt = false; - private int thumbs_count = 0; - private Boolean display_eta = false; - private String current_channel = ""; - private String bestv_a = ""; - private ListViewColumnSorter lvwColumnSorter3; - private ListViewColumnSorter lvwColumnSorter_Full; - private ColumnHeader SortingColumn = null; - private Boolean batch_concat = false; - public String concat_intro = ""; - public String concat_end = ""; - public String concat_intro_dur = ""; - public String concat_end_dur = ""; - private const int _minimumColumnWidth = 64; - private List list_successful_m = new List(); - private List list_failed_m = new List(); - public String latest_ff = String.Empty; - public Boolean show_wiz_start = true; - public Boolean from_wizard = false; - private Boolean prevent_sleep = false; - private Boolean show_wiz = false; - private String port_path = Path.Combine(Application.StartupPath, "settings") + "\\"; - public Boolean res_col = false; - private int col_width = 0; - private String selected_add_col = ""; - private System.Media.SoundPlayer soundPlayer = new System.Media.SoundPlayer(); - private Boolean fix_pre = false; - private Boolean play_on_end = false; - private String play_file_path = String.Empty; - private Boolean writable_yl = false; - private String saved_pres_two = ""; - private String saved_ext_two = ""; - private Boolean stopped_recording = false; - private String vc_download = ""; - private ToolTip toolT002 = new ToolTip(); - private ToolTip toolTipMon = new ToolTip(); - private String run_command = String.Empty; - private String run_command_args = String.Empty; - private Boolean m3u_params_checked, output_server_checked = false; - private String down_speed_m = ""; - private String embed_subs_m = ""; - private String embed_meta_m = ""; - private String write_subs_m = ""; - private String convert_subs_m = ""; - private String format_out_m = ""; - private Boolean show_total_prog_m = false; - private String m3u_output_ext_m = String.Empty; - private String output_server_m = String.Empty; - private String m3u_params_m = String.Empty; - private String auto_subs_m = String.Empty; - private DataGridView dg1_temp = new DataGridView(); - private Boolean opened_m = false; - private String multi_dest = ""; - private Boolean fatal_parallel = false; - private String fatal_parallel_msg = ""; - private Boolean one_ok = false; - private Boolean yt_chk = false; - public Boolean abort_validate_url = false; - private float font_size = Settings.Default.font_size; - private Boolean adding_youtube = false; - private ListView lv_size = new ListView(); - private Boolean pop_invalids = false; - private Boolean cancel_cache = false; - private WebClient wc = new WebClient(); - private WebClient wc2 = new WebClient(); - private WebClient wc_dl = new WebClient(); - private WebClient wc_dl2 = new WebClient(); - private Boolean cached = false; - public long file_size_prog = 0; - private Boolean cancelados_paralelos = false; - private Boolean cancel_queue = false; - private Boolean working = false; - private int tiempo_apaga = 120; - private Double durat_n = 0; - private String validate_duration; - private Boolean valid_prog = false; - private String def_mux_video_enc = "copy"; - private String def_mux_audio_enc = "copy"; - private String def_mux_subs_enc = "copy"; - private String def_lang_und_tracks = "und"; - //private Boolean Extract_img = false; - private Boolean select_mp4 = false; - private int time_n_tasks = 0; - private Boolean total_time = false; - private Boolean recording_scr = false; - private Boolean hard_sub = false; - private String add_suffix = ""; - //private int capture_handle; - private Boolean Enable_txt_hard_Subs = false; - private long tot_size = 0; - private Boolean add_subfs = false; - - private String n_th_suffix = String.Empty; - - private String n_th_source_ext = String.Empty; - private int pending_dur = 0; - private Boolean canceled_add = false; - private Boolean dur_ok = false; - private Boolean canceled_file_adding = false; - private ListView list_pending_dur = new ListView(); - private ListView list_adding = new ListView(); - private ListView list_global_proc = new ListView(); - private List files_to_add = new List(); - private Image[] dg_thumbs = new Image[2000]; - private Boolean change_tab_1 = false; - private Boolean change_tab_2 = false; - private Boolean list_not_empty = false; - private Process process_rec = new Process(); - private Process probe_urls = new Process(); - - private Label was_started = new Label(); - - private Boolean avoid_overwriting = false; - private Boolean stop_validating_url = false; - private Boolean skip_current_url = false; - private Boolean m3u_running = false; - private Boolean multi_running = false; - private Dictionary procs = new Dictionary(); - private Dictionary points = new Dictionary(); - private Dictionary sizes = new Dictionary(); - private Dictionary m_images = new Dictionary(); - private Dictionary multi_logs = new Dictionary(); - private Dictionary multi_params = new Dictionary(); - private Dictionary to_rem = new Dictionary(); - private Dictionary matched = new Dictionary(); - private Dictionary> media_list = new Dictionary>(); - public List multi_speeds = new List(); - public List multi_fps = new List(); - private Boolean aborted_url = false; - private int capture_count = 0; - private Boolean tried_ok = false; - private String textbox_params = String.Empty; - private Boolean aborted = false; - private Double total_duration = 0; - private Double total_multi_duration = 0; - private Double start_total_time = 0; - private Boolean tracks_empty = true; - private int time_est_size = 0; - private Form frm_log = new Form(); - private RichTextBox Rtxt = new RichTextBox(); - private Boolean skipped = false; - private List tried_params = new List(); - private Boolean m3u_single_running = false; - private Boolean paused = false; - private ComboBox CB1_o = new ComboBox(); - private String audio_capture_device = String.Empty; - private String prev_dev_audio = String.Empty; - private Boolean abort_capture = false; - private Boolean hw_decoders = false; - private String hw_decode_glob = String.Empty; - private Boolean warn_mux_webm = false; - private Boolean warn_mux_mov = false; - private String shut_type = "Power off"; - private Boolean fade_ok = true; - private String silence_params = String.Empty; - private String multi_pr1 = String.Empty; - private String multi_pr2 = String.Empty; - private String multi_pr3 = String.Empty; - private String multi_pr1_ext = String.Empty; - private String multi_pr2_ext = String.Empty; - private String multi_pr3_ext = String.Empty; - private int n_multi_presets = 0; - private String multi_two_pr1 = String.Empty; - private String multi_two_ext = String.Empty; - private String multi_1st_pass = String.Empty; - private Boolean ren_multi = false; - private Boolean runnin_n_presets = false; - private TextBox path_txt = new TextBox(); - private ListBox LB1_o_try = new ListBox(); - public Boolean is_portable = false; - private ToolTip toolTip01 = new ToolTip(); - private ToolTip toolTip_settings = new ToolTip(); - private Boolean back_ff = true; - private Boolean just_started = true; - private Boolean just_started5 = true; - private int current_prio; - private Boolean save_path_state = false; - private Boolean save_preset_state = false; - private List decoders = new List(); - private Boolean big_res = false; - private int ff_ver_proc = 0; - private Form frm_output2 = new Form(); - private Boolean tip_sort_dur = false; - private Boolean sort_multi_dur = false; - private Boolean is_ff_ok = false; - private Boolean first_concat = true; - private ListView LB1_kf = new ListView(); - - private Form3 form3 = new Form3(); - private Form4 form4 = new Form4(); - private Form22 frm22 = new Form22(); - private Form33 frm33 = new Form33(); - private Form16 frm_mux_jobs = new Form16(); - - private Boolean delete_def = false; - private Boolean delete_one = false; - private OpenFileDialog file_dialog_ffq = new OpenFileDialog(); - private SaveFileDialog save_ffq = new SaveFileDialog(); - private Boolean send_par_consol = true; - private Boolean warn_success_items = true; - private Boolean no_warn_0_dur = true; - private Boolean no_save_logs = false; - private Boolean verbose_logs = false; - private Boolean full_report = false; - private Boolean no_save_cache = false; - private Boolean os_save_cache = false; - private Boolean remember_last_tab = false; - private Boolean remember_w = false; - private ListView unfilter_lv1 = new ListView(); - private ListView filtered_lv1 = new ListView(); - private ToolTip tool_undo_filter = new ToolTip(); - private Boolean size_sorted = false; - private int initial_tab = 0; - private PictureBox pic_pause = new PictureBox(); - private Boolean two_try_fail = false; - public Boolean cancel_two = false; - private int invalids = 0; - private String file_to_copy = String.Empty; - private Boolean ask_cache_net = false; - private Boolean first_run = false; - private Boolean current_save_prio = false; - public TextBox pr_default = new TextBox(); - private Boolean mixed_urls = false; - private Boolean opening_youtubes = false; - private Boolean internet_up = true; - private String pl_url = ""; - private String Clear_cache = ""; - private Double Total_dur_urls = 0; - private Boolean checking_url_m3u = false; - private String[] lines_txt_m3u = new String[] { "" }; - private int playlists_int = 0; - private int errors_enc = 0; - private int warn_enc = 0; - private string down_ver = "https://raw.githubusercontent.com/eibol/ffmpeg_batch/gh-pages/current_ffb.txt"; - private string down_ver2 = "https://ffmpeg-batch.sourceforge.io/current_ffb.txt"; - private String yl_latest = "https://github.com/yt-dlp/yt-dlp/releases/latest"; - private String yl_latest_exe = "https://github.com/yt-dlp/yt-dlp/releases/"; - private String down_ff_g = "https://ffmpeg-batch.sourceforge.io/ffmpeg-release-full.7z"; - private String down_ff_v = "https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-full.7z"; - private String down_ff_vh = "https://files.videohelp.com/u/273695/ffmpeg-release-full.7z"; - private string proj_web = "https://ffmpeg-batch.sourceforge.io"; - private String man_en_url = "https://raw.githubusercontent.com/eibol/ffmpeg_batch/gh-pages/FFmpeg_Batch_User_Guide_en.pdf"; - private String man_es_url = "https://raw.githubusercontent.com/eibol/ffmpeg_batch/gh-pages/FFmpeg_Batch_User_Guide_es.pdf"; - private Boolean images_v = false; - private String images_time = "5"; - - //Tecla global de parada ha sido pulsada - - [DllImport("user32.dll")] - private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk); - - [DllImport("user32.dll")] - private static extern bool UnregisterHotKey(IntPtr hWnd, int id); - - private enum KeyModifier - { - None = 0, - Alt = 1, - Control = 2, - Shift = 4, - WinKey = 8 - } - - [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] - private static extern IntPtr GetForegroundWindow(); - - [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] - private static extern int GetWindowThreadProcessId(IntPtr handle, out int processId); - - public Form1() - { - Form6 form_intro = new Form6(); - form_intro.Show(); - form_intro.Refresh(); - - InitializeComponent(); - - String app_location = Application.StartupPath; - String portable_flag = Application.StartupPath + "\\" + "portable.ini"; - if (File.Exists(portable_flag)) - { - is_portable = true; - this.Text = "FFmpeg Batch AV Converter Portable"; - if (!Directory.Exists(Path.Combine(Application.StartupPath, "settings"))) - { - try - { - Directory.CreateDirectory(Path.Combine(Application.StartupPath, "settings")); - reset_portable(); - } - catch (Exception excpt) - { - MessageBox.Show(Strings.err_port + Environment.NewLine + excpt.Message, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - else is_portable = false; - - int id = 0; // The id of the hotkey. - RegisterHotKey(this.Handle, id, (int)KeyModifier.Control + (int)KeyModifier.Shift, Keys.P.GetHashCode()); - - check_res(); - - String f_remember_w = String.Empty; - if (is_portable == false) - { - f_remember_w = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_remember_w.ini"; - } - else - { - f_remember_w = port_path + "ff_remember_w_portable.ini"; - } - - if (File.Exists(f_remember_w)) - { - if (Settings.Default.w_max == false) - { - Rectangle resolution = Screen.PrimaryScreen.Bounds; - Boolean out_r_h = false; - Boolean out_r_w = false; - this.StartPosition = FormStartPosition.Manual; - this.Location = Settings.Default.wLocation; - int lin = 0; - foreach (String line in File.ReadLines(f_remember_w)) - { - if (lin == 0) - { - if (Convert.ToInt32(line) <= resolution.Height) - { - this.Height = Convert.ToInt32(line); - out_r_h = false; - } - else out_r_h = true; - } - else if (lin == 1) - { - if (Convert.ToInt32(line) <= resolution.Width) - { - this.Width = Convert.ToInt32(line); - out_r_w = false; - } - else out_r_w = true; - } - lin++; - } - if (out_r_w == true && out_r_h == true) this.StartPosition = FormStartPosition.CenterScreen; - } - else this.WindowState = FormWindowState.Maximized; - } - - lvwColumnSorter3 = new ListViewColumnSorter(); - this.listView3.ListViewItemSorter = lvwColumnSorter3; - lvwColumnSorter_Full = new ListViewColumnSorter(); - this.listView1.ListViewItemSorter = lvwColumnSorter_Full; - WebClient webClient1 = new WebClient(); - } - - protected override void WndProc(ref Message m) - { - base.WndProc(ref m); - - if (m.Msg == 0x0312) - { - if (Settings.Default.no_ctrl_p == true) return; - /* Note that the three lines below are not needed if you only want to register one hotkey. - * The below lines are useful in case you want to register multiple keys, which you can use a switch with the id as argument, or if you want to know which key/modifier was pressed for some particular reason. */ - - Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF); // The key of the hotkey that was pressed. - KeyModifier modifier = (KeyModifier)((int)m.LParam & 0xFFFF); // The modifier of the hotkey that was pressed. - int id = m.WParam.ToInt32(); // The id of the hotkey that was pressed. - this.Invoke(new MethodInvoker(delegate - { - this.TopMost = true; - this.TopMost = false; - this.Activate(); - btn_abort_all.PerformClick(); - this.WindowState = FormWindowState.Normal; - })); - } - } - - private void RefreshResources(Control ctrl, ComponentResourceManager res) - { - ctrl.SuspendLayout(); - this.Invoke(new MethodInvoker(delegate - { - res.ApplyResources(ctrl, ctrl.Name, Thread.CurrentThread.CurrentUICulture); - })); - foreach (Control control in ctrl.Controls) RefreshResources(control, res); // recursion - ctrl.ResumeLayout(false); - } - - private String get_file_dur(String path) - { - Process tmp = new Process(); - tmp.StartInfo.FileName = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - String ffprobe_frames = " " + '\u0022' + "--Inform=General;%Duration/String3%" + '\u0022'; - tmp.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + path + '\u0022'; - - tmp.StartInfo.RedirectStandardOutput = true; - tmp.StartInfo.UseShellExecute = false; - tmp.StartInfo.CreateNoWindow = true; - tmp.EnableRaisingEvents = true; - tmp.Start(); - - String duracion = tmp.StandardOutput.ReadToEnd(); - tmp.WaitForExit(); - - if (duracion == null) return "00:00:00"; - else - { - TimeSpan time; - if (TimeSpan.TryParse(duracion, out time)) - { - return duracion; - } - else return "00:00:00"; - } - } - - private void button1_Click(object sender, EventArgs e) - { - Pg1.Focus(); - if (!File.Exists(Path.Combine(Application.StartupPath, "ffmpeg.exe"))) - { - MessageBox.Show(Strings.no_ffmpeg, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - openFileDialog1.Filter = Strings.av + " |*.mp4; *.mkv; *.ts; *.mxf; *.mp3; *.wav; *.flac; *.m4a; *.avi; *.mts; *.flv; *.alac; *.aac; *.mpg; *.mp2; *.mpe; *.ogv; *.webm; *.aiff; *.vob; *.wma; *.wmv; *.mov; *.mka; *.m2ts; *.ac3; *.ogg; *.avs|" + Strings.imgs + " (*.jpg; *.png; *.gif) | *.jpg; *.png; *.gif|" + Strings.all_files + " (*.*) | *.*"; - - if (tabControl1.SelectedIndex == 3) - { - btn_add_urls.PerformClick(); - return; - } - else if (tabControl1.SelectedIndex == 1) - { - openFileDialog1.Filter = Strings.av + " |*.mp4; *.mkv; *.mxf; *.mp3; *.wav; *.flac; *.avi; *.mts; *.flv; *.alac; *.aac; *.mpg; *.mp2; *.mpe; *.ogv; *.webm; *.aiff; *.vob; *.wma; *.wmv; *.mov; *.mka; *.srt; *.m2ts; *.idx; *.ac3; *.jpg; *.png; *.gif; *.psd; *.tiff; *.ass; *.ogg|" + Strings.all_files + " (*.*) | *.*"; - } - else if (tabControl1.SelectedIndex == 2) - { - openFileDialog1.Filter = Strings.av + " | *.mp4; *.mkv; *.mxf; *.avi; *.mts; *.flv; *.mpg; *.mp2; *.mpe; *.ogv; *.webm; *.aiff; *.vob; *.wmv; *.mov; *.mka; *.m2ts; *.ogg| " + Strings.all_files + " (*.*) | *.*"; - } - - if (openFileDialog1.ShowDialog() == DialogResult.Cancel) from_wizard = false; - } - - private void openFileDialog1_FileOk(object sender, CancelEventArgs e) - { - openFileDialog1.InitialDirectory = Path.GetDirectoryName(openFileDialog1.FileNames[0]); - initial_tab = tabControl1.SelectedIndex; - change_tab_1 = false; - change_tab_2 = false; - - if (tabControl1.SelectedIndex == 1) - { - tabControl1.SelectedIndex = 0; - change_tab_1 = true; - } - else if (tabControl1.SelectedIndex == 2) - { - tabControl1.SelectedIndex = 0; - change_tab_2 = true; - } - - string[] file_drop = (string[])openFileDialog1.FileNames; - - List files2 = new List(); - - int num_drop = 0; - foreach (String dropped in file_drop) - { - if (File.Exists(dropped)) - { - files2.Add(dropped); - } - - num_drop = files2.Count(); - - if (num_drop >= 10000) - { - DialogResult a = MessageBox.Show(Strings.adding + " " + num_drop + " " + Strings.some_time, Strings.many_files, MessageBoxButtons.OKCancel, MessageBoxIcon.Question); - if (a == DialogResult.Cancel) - { - return; - } - } - } - - files_to_add = files2; - canceled_file_adding = false; - btn_cancel_add.Enabled = true; - btn_cancel_add.Visible = true; - btn_cancel_add.Refresh(); - BG_Files.RunWorkerAsync(); - } - private void check_fade() - { - //Video fading - listView1.Invoke(new MethodInvoker(delegate - { - - if (fade_v_in.CheckState == CheckState.Checked && fade_v_out.CheckState == CheckState.Unchecked) - { - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[3].Text != Strings.n_a && item.SubItems[3].Text != "0:00:00" && item.SubItems[3].Text != "00:00:00" && item.SubItems[3].Text != Strings.pending) - { - if (TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds < Convert.ToDouble(num_v_in.Value)) - { - MessageBox.Show(Strings.fade1, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - fade_ok = false; - return; - } - } - } - } - - if (fade_v_in.CheckState == CheckState.Unchecked && fade_v_out.CheckState == CheckState.Checked) - { - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[3].Text != Strings.n_a && item.SubItems[3].Text != "0:00:00" && item.SubItems[3].Text != "00:00:00" && item.SubItems[3].Text != Strings.pending) - { - if (TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds < Convert.ToDouble(num_v_out.Value)) - { - MessageBox.Show(Strings.fade2, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - fade_ok = false; - return; - } - } - } - } - if (fade_v_in.CheckState == CheckState.Checked && fade_v_out.CheckState == CheckState.Checked) - { - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[3].Text != Strings.n_a && item.SubItems[3].Text != "0:00:00" && item.SubItems[3].Text != "00:00:00" && item.SubItems[3].Text != Strings.pending) - { - if (TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds < (Convert.ToDouble(num_v_in.Value) + Convert.ToDouble(num_v_out.Value))) - { - MessageBox.Show(Strings.fade3, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - fade_ok = false; - return; - } - } - } - } - //Audio fading - if (fade_a_in.CheckState == CheckState.Checked && fade_a_out.CheckState == CheckState.Unchecked) - { - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[3].Text != Strings.n_a && item.SubItems[3].Text != "0:00:00" && item.SubItems[3].Text != "00:00:00" && item.SubItems[3].Text != Strings.pending) - { - if (TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds < Convert.ToDouble(num_a_in.Value)) - { - MessageBox.Show(Strings.fade4, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - fade_ok = false; - return; - } - } - } - } - - if (fade_a_in.CheckState == CheckState.Unchecked && fade_a_out.CheckState == CheckState.Checked) - { - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[3].Text != Strings.n_a && item.SubItems[3].Text != "0:00:00" && item.SubItems[3].Text != "00:00:00" && item.SubItems[3].Text != Strings.pending) - { - if (TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds < Convert.ToDouble(num_a_out.Value)) - { - MessageBox.Show(Strings.fade5, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - fade_ok = false; - return; - } - } - } - } - if (fade_a_in.CheckState == CheckState.Checked && fade_a_out.CheckState == CheckState.Checked) - { - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[3].Text != Strings.n_a && item.SubItems[3].Text != "0:00:00" && item.SubItems[3].Text != "00:00:00" && item.SubItems[3].Text != Strings.pending) - { - if (TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds < (Convert.ToDouble(num_a_in.Value) + Convert.ToDouble(num_a_out.Value))) - { - MessageBox.Show(Strings.fade6, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - fade_ok = false; - return; - } - } - } - } - //End audio fading - })); - } - - private Boolean dups_lv1() - { - String first_dup = ""; - String to_show = ""; - - if (chk_recreate.CheckState == CheckState.Checked) - { - List no_overw = new List(); - - string path_without = ""; - String out_path = txt_path_main.Text; - - lbl_items.Text = Strings.parsing2 + "..."; - lbl_items.Refresh(); - pg_adding.Visible = true; - pg_adding.Maximum = listView1.Items.Count; - pg_adding.Value = 0; - pg_adding.Refresh(); - int ii = 0; - - foreach (ListViewItem item in listView1.Items) - { - ii++; - pg_adding.Value = ii; - if (txt_path_main.Text.Length == 2) - { - if (txt_path_main.Text.Substring(0, 2) == ".\\") - out_path = item.SubItems[1].Text + txt_path_main.Text.Replace(".\\", ""); - } - else - { - if (txt_path_main.Text.Substring(0, 2) == ".\\") - out_path = item.SubItems[1].Text + txt_path_main.Text.Replace("..", ""); - } - - path_without = out_path + "\\" + item.SubItems[1].Text.Substring(Path.GetPathRoot(item.SubItems[1].Text).Length); - if (item.Text.Length > 3) - { - if (item.Text.Substring(item.Text.Length - 3, 3).ToLower() == "avs") - { - //String avs_out = avs_output(item.SubItems[1].Text + "\\" + item.Text); - String avs_out = path_without + "\\" + Path.GetFileNameWithoutExtension(item.Text) + "." + txt_format.Text; - //no_overw.Add(path_without + "\\" + Path.GetFileNameWithoutExtension(item.Text) + "." + txt_format.Text); - if (!File.Exists(avs_out)) no_overw.Add(avs_out); - else no_overw.Add(avs_out + item.Index.ToString()); - } - } - else no_overw.Add(path_without + "\\" + Path.GetFileNameWithoutExtension(item.Text) + "." + txt_format.Text); - } - - pg_adding.Visible = false; - lbl_items.Text = ""; - lbl_items.Refresh(); - var duplicates = no_overw.GroupBy(s => s).SelectMany(grp => grp.Skip(1)); - int count = no_overw.Count; - no_overw = no_overw.Distinct().ToList(); - - if (no_overw.Count < count) - { - int i = 0; - - foreach (String str in duplicates) - { - if (i == 0) first_dup = str; - if (i < 5) to_show = to_show + Environment.NewLine + str; - i++; - } - MessageBox.Show((count - no_overw.Count).ToString() + " " + Strings.names_overw + Environment.NewLine + Environment.NewLine + to_show, Strings.overw1, MessageBoxButtons.OK, MessageBoxIcon.Warning); - listView1.SelectedIndices.Clear(); - int s = listView1.FindItemWithText(Path.GetFileNameWithoutExtension(first_dup)).Index; - listView1.Items[s].Selected = true; - listView1.Select(); - listView1.EnsureVisible(s); - - return true; - } - return false; - } - else - { - List no_overw = new List(); - - string path_without = ""; - String out_path = txt_path_main.Text; - - foreach (ListViewItem item in listView1.Items) - { - if (txt_path_main.Text.Length == 2) - { - if (txt_path_main.Text.Substring(0, 2) == ".\\") - out_path = item.SubItems[1].Text + txt_path_main.Text.Replace(".\\", ""); - } - else - { - if (txt_path_main.Text.Substring(0, 2) == ".\\") - out_path = item.SubItems[1].Text + txt_path_main.Text.Replace(".", ""); - } - - path_without = out_path; - no_overw.Add(path_without + "\\" + Path.GetFileNameWithoutExtension(item.Text) + "." + txt_format.Text); - } - - var duplicates = no_overw.GroupBy(s => s).SelectMany(grp => grp.Skip(1)); - int count = no_overw.Count; - no_overw = no_overw.Distinct().ToList(); - - if (no_overw.Count < count) - { - int i = 0; - foreach (String str in duplicates) - { - if (i == 0) first_dup = str; - if (i < 5) to_show = to_show + Environment.NewLine + str; - i++; - } - MessageBox.Show((count - no_overw.Count).ToString() + " " + Strings.names_overw + Environment.NewLine + Environment.NewLine + to_show, Strings.overw1, MessageBoxButtons.OK, MessageBoxIcon.Warning); - listView1.SelectedIndices.Clear(); - int s = listView1.FindItemWithText(Path.GetFileNameWithoutExtension(first_dup)).Index; - listView1.Items[s].Selected = true; - listView1.Select(); - listView1.EnsureVisible(s); - return true; - } - return false; - } - } - - private void auto_shut() - { - int index = 0; - combo_shut.Invoke(new MethodInvoker(delegate - { - index = combo_shut.SelectedIndex; - })); - - if (index < 3) - { - Disable_Controls(); - disable_abort_btn(); - - this.Invoke(new MethodInvoker(delegate - { - chkshut.Enabled = false; - btn_pause.Enabled = false; - Timer_apaga.Start(); - TopMost = true; - TB1.Enabled = true; - TB1.Visible = true; - btn_cancel_shut.Enabled = true; - btn_cancel_shut.Visible = true; - btn_abort_all.Enabled = false; - TB1.Text = Strings.computer_will + " " + shut_type + " " + Strings.in_60; - btn_cancel_shut.Text = Strings.press_c + " " + shut_type; - })); - notifyIcon1.BalloonTipText = Strings.computer_will + " " + shut_type + " " + Strings.in_60; - notifyIcon1.BalloonTipIcon = ToolTipIcon.Warning; - notifyIcon1.BalloonTipTitle = "FFmpeg Batch AV Converter"; - notifyIcon1.ShowBalloonTip(0); - } - else if (index == 3) - { - this.InvokeEx(f => this.Enabled = false); - Form14 frm_run = new Form14(); - frm_run.txt_path.Text = run_command; - frm_run.args = run_command_args; - frm_run.timer1.Interval = 1000; - frm_run.ShowDialog(); - this.InvokeEx(f => this.Enabled = true); - Enable_Controls(); - } - } - private void start_multiple() - { - lbl_est_size.Text = ""; - lbl_bitrate.Text = ""; - cancel_queue = false; - notifyIcon1.Visible = true; - pic_no_errors.Visible = false; - pic_warnings.Visible = false; - pic_recording.Visible = false; - errors_enc = 0; - lbl_multip.Text = String.Empty; - //Validated list, start processing - if ((fade_v_in.Checked == true && num_v_in.Value == 0) || (fade_v_out.Checked == true && num_v_out.Value == 0) || (fade_a_in.Checked == true && num_a_in.Value == 0) || (fade_a_out.Checked == true && num_a_out.Value == 0)) - { - MessageBox.Show(Strings.fading_zero, Strings.fading_zero2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - txt_remain.Text = Strings.remain_time + " " + "00h:00m:00s"; - - if (listView1.SelectedIndices.Count == 0) - { - listView1.Items[0].Selected = true; - listView1.Items[0].Focused = true; - listView1.Focus(); - } - - Boolean pr2_ok = false; - foreach (String item in tried_params) - { - if (item == multi_pr1) - { - tried_ok = true; - break; - } - } - - if (tried_ok == true) - { - foreach (String item in tried_params) - { - if (item == (multi_pr2)) - { - pr2_ok = true; - break; - } - } - if (pr2_ok != true) tried_ok = false; - } - - if (tried_ok == true && multi_pr3.Length == 0) - { - foreach (String item in tried_params) - { - if (item == (multi_pr2)) - { - tried_ok = true; - break; - } - } - } - - if (tried_ok == false) - { - try - { - BG_Try_multi.RunWorkerAsync(); - } - catch - { - tried_ok = true; - } - - return; - } - tried_ok = false; - - //Remove test file/folder - - String file_prueba = ""; - String sel_test = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - file_prueba = sel_test; - String destino = Path.Combine(Path.GetTempPath(), "\\" + "FFBatch_test"); - String borrar = destino + "\\" + Path.GetFileNameWithoutExtension(file_prueba) + "." + txt_format.Text; - - if (File.Exists(borrar)) - { - try - { - File.Delete(borrar); - } - catch { } - } - - if (Directory.Exists(destino) && Directory.GetFiles(destino).Length == 0) - { - Directory.Delete(destino); - } - - //END Remove test file/folder - - //Pending duration - - if (dur_ok == false) - { - list_pending_dur.Items.Clear(); - foreach (ListViewItem item in listView1.Items) - { - list_pending_dur.Items.Add((ListViewItem)item.Clone()); - } - BG_Dur.RunWorkerAsync(); - return; - } - - //Check queued items - - if (warn_success_items == true) - { - Boolean no_queued = true; - Boolean has_complete = false; - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[5].Text == Strings.queued) - { - no_queued = false; - } - else if (item.SubItems[5].Text == Strings.success || item.SubItems[5].Text == Strings.replaced) - { - has_complete = true; - } - } - - if (no_queued == true && listView1.Items.Count > 1) - { - DialogResult a = MessageBox.Show(Strings.items_q + " " + '\u0022' + Strings.queued + '\u0022' + ". " + Strings.all_files + " " + Strings.already_proc, Strings.not_queued, MessageBoxButtons.OKCancel, MessageBoxIcon.Question); - if (a == DialogResult.Cancel) return; - } - - else if (no_queued == false && has_complete == true) - { - DialogResult a = MessageBox.Show(Strings.already_encoded + " " + '\u0022' + Strings.queued + '\u0022' + Strings.continu, Strings.some_q, MessageBoxButtons.OKCancel, MessageBoxIcon.Question); - if (a == DialogResult.Cancel) return; - } - //End check queued items - } - - cancel_queue = false; - Pg1.Value = 0; - //pg_current.Value = 0; - Disable_Controls(); - - btn_skip_main.Enabled = true; - //textBox4.Text = "0%"; - working = true; - runnin_n_presets = true; - - ListView list_proc = new ListView(); - foreach (ListViewItem item in listView1.Items) - { - list_proc.Items.Add((ListViewItem)item.Clone()); - item.SubItems[5].Text = Strings.queued; - item.BackColor = Color.White; - } - String hw_decode = String.Empty; - if (cb_hwdecode.SelectedItem.ToString() != "none") - { - hw_decode = "-hwaccel " + cb_hwdecode.SelectedItem.ToString(); - } - - //Save selected hw decoder - - String path2 = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_hw_dcd.ini"; - if (is_portable == true) - { - path2 = port_path + "ff_hw_dcd_portable.ini"; - } - String txt_hw_dcd = cb_hwdecode.SelectedItem.ToString(); - if (txt_hw_dcd != "none") - { - File.WriteAllText(path2, txt_hw_dcd); - } - else - { - if (File.Exists(path2)) File.Delete(path2); - } - - //End save hw decoder - - // Fade validation - fade_ok = true; - check_fade(); - if (fade_ok == false) - { - Enable_Controls(); - return; - } - // END Fade validation - - Pg1.Maximum = listView1.Items.Count; - listView1.SelectedIndices.Clear(); - - total_duration = 0; - Double total_prog = 0; - - //Get total duration of files - - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[3].Text != Strings.n_a && item.SubItems[3].Text != "0:00:00" && item.SubItems[3].Text != "00:00:00" && item.SubItems[3].Text != Strings.pending) - { - total_duration = total_duration + TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds - TimeSpan.Parse(ss_time_input.Text).TotalSeconds; - } - else - { - total_duration = total_duration + 0; - } - } - - if (n_multi_presets == 2) total_duration = total_duration * 2; - else if (n_multi_presets == 3) total_duration = total_duration * 3; - - Pg1.Minimum = 0; - Pg1.Maximum = 100; - String remain_time = "0"; - //End get total duration of files - - List list_lines = new List(); - - time_n_tasks = 0; - timer_tasks.Start(); - timer_est_size.Start(); - time_est_size = 0; - String file = String.Empty; - - panel2.Enabled = true; - chk_delete_source.Enabled = true; - foreach (Control ct in panel2.Controls) - { - if (ct.Name != chk_delete_source.Name) - { - this.InvokeEx(f => ct.Enabled = false); - } - } - - String f_in_color = combo_vin_col.SelectedIndex == 1 ? "White" : "Black"; - String f_out_color = combo_vout_color.SelectedIndex == 1 ? "White" : "Black"; - - String in_color = combo_vin_col.SelectedIndex == 2 ? ":alpha=1" : ":color=" + f_in_color; - String out_color = combo_vout_color.SelectedIndex == 2 ? ":alpha=1" : ":color=" + f_out_color; - - int preset_run = 1; - int to_go = n_multi_presets; - - procs.Clear(); - - for (int ii = 0; ii < listView1.Items.Count; ii++) - { - procs.Add("proc_urls_" + ii.ToString(), new Process()); - } - - - new System.Threading.Thread(() => - { - System.Threading.Thread.CurrentThread.IsBackground = true; - - for (int list_index = 0; list_index < listView1.Items.Count; list_index++) - { - System.Threading.Thread.Sleep(50); //Allow kill process to send cancel_queue - - listView1.Invoke(new MethodInvoker(delegate - { - file = listView1.Items[list_index].SubItems[1].Text + "\\" + listView1.Items[list_index].Text; - })); - - if (cancel_queue == true) - { - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - working = false; - time_est_size = 0; - Enable_Controls(); - MessageBox.Show(Strings.queue_abort, Strings.task_abort, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; - } - - this.InvokeEx(f => timer_est_size.Start()); - - String ffm = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - String fullPath = file; - - //Begin Shifting - String shifting = ""; - if (chk_shift.Checked == true) - { - shifting = " -itsoffset " + Num_Shift.Value.ToString().Replace(",", ".") + " -i " + '\u0022' + file + '\u0022' + " -map 1:v -map 0:a "; - } - //End Shifting - - //Begin fading and volume changing - String change_vol_fade = ""; - if (chk_vol.Checked == true) - { - change_vol_fade = "-af " + '\u0022' + "volume=" + vol_ch.Value.ToString() + "dB " + '\u0022' + " "; - } - - String fade_filter = String.Empty; - Decimal fade_frames = 0; - - if (fade_v_in.CheckState == CheckState.Checked || fade_v_out.CheckState == CheckState.Checked) - { - String ff_frames = String.Empty; - Process get_frames = new Process(); - get_frames.StartInfo.FileName = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - String ffprobe_frames = " " + '\u0022' + "--Inform=Video;%FrameRate%" + '\u0022'; - get_frames.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + list_proc.Items[list_index].SubItems[1].Text + "\\" + list_proc.Items[list_index].Text + '\u0022'; - get_frames.StartInfo.RedirectStandardOutput = true; - get_frames.StartInfo.UseShellExecute = false; - get_frames.StartInfo.CreateNoWindow = true; - get_frames.EnableRaisingEvents = true; - get_frames.Start(); - - ff_frames = get_frames.StandardOutput.ReadLine(); - get_frames.WaitForExit(); - - if (get_frames.ExitCode == 0 && ff_frames != null) - { - fade_frames = decimal.Parse(ff_frames) / 1000; - } - get_frames.Dispose(); - } - - if (fade_v_in.CheckState == CheckState.Checked && fade_v_out.CheckState == CheckState.Unchecked) - { - Decimal fff_in = Math.Round(num_v_in.Value * fade_frames, 0); - fade_filter = "-vf " + '\u0022' + "fade=in:0:" + fff_in.ToString() + in_color + '\u0022'; - } - - if (fade_v_in.CheckState == CheckState.Unchecked && fade_v_out.CheckState == CheckState.Checked) - { - Double dur_frames = TimeSpan.Parse(list_proc.Items[list_index].SubItems[3].Text).TotalSeconds * Convert.ToDouble(fade_frames); - Decimal fade_out_total = Math.Round(Convert.ToDecimal(dur_frames), 3, MidpointRounding.AwayFromZero); - Decimal fade_out_initial = Math.Round(fade_out_total - (num_v_out.Value * fade_frames), 0, MidpointRounding.AwayFromZero); - Decimal fff_out = Math.Round(num_v_out.Value * fade_frames, 0, MidpointRounding.AwayFromZero); - - fade_filter = "-vf " + '\u0022' + "fade=out:" + fade_out_initial.ToString() + ":" + fff_out.ToString() + out_color + '\u0022'; - } - - if (fade_v_in.CheckState == CheckState.Checked && fade_v_out.CheckState == CheckState.Checked) - { - Decimal fff_in = Math.Round(num_v_in.Value * fade_frames, 0, MidpointRounding.AwayFromZero); - Double dur_frames = TimeSpan.Parse(list_proc.Items[list_index].SubItems[3].Text).TotalSeconds * Convert.ToDouble(fade_frames); - Decimal fade_out_total = Math.Round(Convert.ToDecimal(dur_frames), 3, MidpointRounding.AwayFromZero); - Decimal fade_out_initial = Math.Round(fade_out_total - (num_v_out.Value * fade_frames), 0, MidpointRounding.AwayFromZero); - Decimal fff_out = Math.Round(num_v_out.Value * fade_frames, 0, MidpointRounding.AwayFromZero); - - fade_filter = "-vf " + '\u0022' + "fade=in:0:" + fff_in.ToString() + in_color + ", " + "fade=out:" + fade_out_initial.ToString() + ":" + fff_out.ToString() + out_color + '\u0022'; - } - - //Audio fading - if (fade_a_in.CheckState == CheckState.Checked && fade_a_out.CheckState == CheckState.Unchecked) - { - if (chk_vol.Checked == false) - { - change_vol_fade = "-af " + '\u0022' + "afade=t=in:ss=0:d=" + num_a_in.Value.ToString() + '\u0022'; - } - else - { - change_vol_fade = "-af " + '\u0022' + "afade=t=in:ss=0:d=" + num_a_in.Value.ToString() + ", " + "volume=" + vol_ch.Value.ToString() + "dB " + '\u0022'; - } - } - - if (fade_a_in.CheckState == CheckState.Unchecked && fade_a_out.CheckState == CheckState.Checked) - { - Double af_out = TimeSpan.Parse(list_proc.Items[list_index].SubItems[3].Text).TotalSeconds - Convert.ToDouble(num_a_out.Value); - Decimal af_out_dec = Math.Round(Convert.ToDecimal(af_out), 0, MidpointRounding.AwayFromZero); - if (chk_vol.Checked == false) - { - change_vol_fade = "-af " + '\u0022' + "afade=t=out:st=" + af_out_dec + ":d=" + num_a_out.Value.ToString() + '\u0022'; - } - else - { - change_vol_fade = "-af " + '\u0022' + "afade=t=out:st=" + af_out_dec + ":d=" + num_a_out.Value.ToString() + ", " + "volume=" + vol_ch.Value.ToString() + "dB " + '\u0022'; - } - } - if (fade_a_in.CheckState == CheckState.Checked && fade_a_out.CheckState == CheckState.Checked) - { - Double af_out = TimeSpan.Parse(list_proc.Items[list_index].SubItems[3].Text).TotalSeconds - Convert.ToDouble(num_a_out.Value); - Decimal af_out_dec = Math.Round(Convert.ToDecimal(af_out), 0, MidpointRounding.AwayFromZero); - - if (chk_vol.Checked == false) - { - change_vol_fade = "-af " + '\u0022' + "afade=t=in:ss=0:d=" + num_a_in.Value.ToString() + ", " + "afade=t=out:st=" + af_out_dec + ":d=" + num_a_out.Value.ToString() + '\u0022'; - } - else - { - change_vol_fade = "-af " + '\u0022' + "afade=t=in:ss=0:d=" + num_a_in.Value.ToString() + ", " + "afade=t=out:st=" + af_out_dec + ":d=" + num_a_out.Value.ToString() + ", " + "volume=" + vol_ch.Value.ToString() + "dB " + '\u0022'; - } - } - //End audio fading - - //End fading - - //End Change Volume - - if (txt_path_main.Text.Contains(".\\")) - { - if (txt_path_main.Text != ".\\") - destino = file.Substring(0, fullPath.LastIndexOf('\\')) + txt_path_main.Text.Replace(".", String.Empty); - else - { - destino = Path.GetDirectoryName(file); - } - } - else - { - if (chk_recreate.CheckState == CheckState.Checked) - { - String pre_dest = Path.GetDirectoryName(file); - destino = Path.Combine(txt_path_main.Text, pre_dest.Substring(3, pre_dest.Length - 3)); - } - else - { - destino = txt_path_main.Text; - } - } - - String pre_input_var = ""; - if (txt_pre_input.Text != "") - { - pre_input_var = txt_pre_input.Text; - } - - String pre_ss = ""; - if (TimeSpan.Parse(ss_time_input.Text).TotalSeconds != 0) - { - pre_ss = " -ss " + ss_time_input.Text; - } - - add_suffix = ""; - - if (chk_suffix.Checked == true && txt_suffix.Text != String.Empty) - { - add_suffix = txt_suffix.Text; - } - String add_pr_suffix = String.Empty; - if (ren_multi == true) - { - add_pr_suffix = "_" + preset_run.ToString(); - } - - String ext_output1 = String.Empty; - - if (preset_run == 1) - { - ext_output1 = multi_pr1_ext; - textbox_params = multi_pr1; - } - else if (preset_run == 2) - { - ext_output1 = multi_pr2_ext; - textbox_params = multi_pr2; - } - else if (preset_run == 3) - { - ext_output1 = multi_pr3_ext; - textbox_params = multi_pr3; - } - ext_output1 = "." + ext_output1; - - String file2 = file; - - if (textbox_params.Contains("%fn")) - { - textbox_params = textbox_params.Replace("%fn", Path.GetFileNameWithoutExtension(file)); - } - if (textbox_params.Contains("%fp")) - { - textbox_params = textbox_params.Replace("%fp", Path.GetDirectoryName(file)); - } - if (textbox_params.Contains("%fd")) - { - var dirName = new DirectoryInfo(Path.GetDirectoryName(file)).Name; - textbox_params = textbox_params.Replace("%fd", dirName); - } - - while (textbox_params.Contains("%1")) - { - if (textbox_params.Contains("%1")) - { - file2 = file2.Replace("\\", "\\\\\\\\"); - file2 = file2.Replace(":", ":" + "\\\\"); - textbox_params = textbox_params.Replace("%1", '\u0022' + file2 + '\u0022'); - } - } - - while (textbox_params.Contains("%2")) - { - if (textbox_params.Contains("%2")) - { - file2 = file2.Replace("\\", "\\\\\\\\"); - file2 = file2.Replace(":", ":" + "\\\\"); - textbox_params = textbox_params.Replace("%2", '\u0022' + Path.Combine(Path.GetDirectoryName(file2), Path.GetFileNameWithoutExtension(file2)) + '\u0022'); - } - } - - String output_file = output_file = '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file) + add_suffix + add_pr_suffix + ext_output1 + '\u0022'; - - String AppParam = hw_decode + " " + pre_input_var + " " + pre_ss + " -i " + "" + '\u0022' + file + '\u0022' + " " + shifting + " -y " + textbox_params + " " + fade_filter + " " + change_vol_fade + " " + output_file; - - if (!Directory.Exists(destino)) - { - Directory.CreateDirectory(destino); - } - - var tmp = procs["proc_urls_" + list_index.ToString()]; - - tmp.StartInfo.FileName = ffm; - tmp.StartInfo.Arguments = AppParam; - - valid_prog = false; - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.processing); - - tmp.StartInfo.RedirectStandardInput = true; - tmp.StartInfo.RedirectStandardError = true; - tmp.StartInfo.UseShellExecute = false; - tmp.StartInfo.CreateNoWindow = true; - tmp.EnableRaisingEvents = true; - tmp.Start(); - - System.Threading.Thread.Sleep(50); - combo_prio.Invoke(new MethodInvoker(delegate - { - if (combo_prio.SelectedIndex != 2) - { - Change_mem_prio(); - } - })); - - this.InvokeEx(f => validate_duration = listView1.Items[list_index].SubItems[3].Text); - if (validate_duration != Strings.n_a && validate_duration != "0:00:00" && validate_duration != "00:00:00" && validate_duration != Strings.pending) - { - valid_prog = true; - } - - String err_txt = ""; - Double interval = 0; - Decimal est_bitrate = 0; - Decimal est_size = 0; - this.InvokeEx(f => durat_n = TimeSpan.Parse(listView1.Items[list_index].SubItems[3].Text).TotalSeconds - TimeSpan.Parse(ss_time_input.Text).TotalSeconds); - - lbl_speed.Text = String.Empty; - Double sec_prog = 0; - this.Invoke(new MethodInvoker(delegate - { - lbl_multip.Enabled = true; - lbl_multip.Visible = true; - lbl_multip.Text = Strings.Encoding + " " + "Preset" + " " + preset_run.ToString() + " " + Strings.of1 + " " + to_go.ToString(); - })); - - while (!tmp.StandardError.EndOfStream) - { - err_txt = tmp.StandardError.ReadLine(); - list_lines.Add(err_txt); - - if (err_txt.Contains("time=") && err_txt.Contains("time=-") == false) - { - if (valid_prog == true) - { - int start_time_index = err_txt.IndexOf("time=") + 5; - sec_prog = TimeSpan.Parse(err_txt.Substring(start_time_index, 8)).TotalSeconds; - - Double percent = (sec_prog * 100 / durat_n); - - total_prog = total_prog + (sec_prog - interval); - interval = sec_prog; - int percent2 = Convert.ToInt32(percent); - - Double percent_tot = (total_prog * 100 / total_duration); - int percent_tot_2 = Convert.ToInt32(percent_tot); - - if (percent_tot_2 <= 100) - { - this.Invoke(new MethodInvoker(delegate - { - Pg1.Value = percent_tot_2; - Pg1.Refresh(); - - Pg1.Text = Math.Round(percent_tot, 1).ToString() + "%"; - TaskbarProgress.SetValue(this.Handle, percent_tot, Pg1.Maximum); - })); - } - - if (percent2 <= 100) - { - if (Math.Round(percent, 1).ToString().Contains(".") || Math.Round(percent, 1).ToString().Contains(",")) - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Math.Round(percent, 1).ToString() + "%"); - } - else - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Math.Round(percent, 1).ToString() + CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0" + "%"); - } - } - - if (cancel_queue == false) - { - //Estimated remaining time - - remain_time = err_txt.Substring(err_txt.LastIndexOf("speed=") + 6, err_txt.Length - err_txt.LastIndexOf("speed=") - 6); - if (time_est_size % 3 == 0) this.InvokeEx(f => f.lbl_speed.Text = Strings.speed + " " + remain_time); - remain_time = remain_time.Replace("x", String.Empty); - Double timing1 = 0; - - if (System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",") - { - timing1 = Math.Round(Double.Parse(remain_time.Replace(".", ",")), 2); - } - else - { - timing1 = Math.Round(Double.Parse(remain_time), 2); - } - - Decimal timing = (decimal)timing1; - Decimal total_dur_dec = Convert.ToDecimal(total_duration); - Decimal total_prog_dec = Convert.ToDecimal(total_prog); - Decimal remain_secs = 0; - - if (timing > 0) - { - remain_secs = (decimal)(total_dur_dec - total_prog_dec) / timing; - } - - if (remain_secs > 60) - { - remain_secs = remain_secs + 60; - } - - String remain_from_secs = String.Empty; - - TimeSpan t = TimeSpan.FromSeconds(Convert.ToDouble(remain_secs)); - remain_from_secs = string.Format("{0:D2}h:{1:D2}", t.Hours, t.Minutes); - - if (remain_secs >= 43200) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + Math.Round(remain_secs / 3600).ToString() + " " + Strings.hours); - } - - if (remain_secs >= 3600 && remain_secs < 43200) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + remain_from_secs + " " + Strings.minutes_abrev); - } - - if (remain_secs < 3600 && remain_secs >= 600) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 1, 2) + " " + Strings.minutes); - } - - if (remain_secs < 600 && remain_secs >= 120) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 2, 1) + " " + Strings.minutes); - } - - if (remain_secs <= 59 && remain_secs != 0) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + Convert.ToInt16(remain_secs) + " " + Strings.seconds); - } - - if (remain_secs == 0) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + Strings.about_finish); - } - } - - //End remaining time - - //Estimated size and bitrate - - String read_size = String.Empty; - if (err_txt.Contains("size=") && (time_est_size % 3 == 0)) - { - int size_index = err_txt.IndexOf("size=") + 5; - read_size = err_txt.Substring(size_index, 8); - if (Convert.ToDecimal(sec_prog) != 0) - { - est_bitrate = (Math.Round(Convert.ToDecimal(read_size) * 8 / Convert.ToDecimal(sec_prog), 0)); - } - else - { - est_bitrate = 0; - } - - if (Convert.ToDecimal(read_size) > 1 && time_n_tasks > 1) - { - if (est_bitrate < 9999) - { - if (est_bitrate > 48) - { - this.InvokeEx(f => f.lbl_bitrate.Text = Strings.avg_bit + ": " + est_bitrate + " " + "Kb/s"); - } - else - { - this.InvokeEx(f => f.lbl_bitrate.Text = Strings.avg_bit + ": "); - } - } - else - { - this.InvokeEx(f => f.lbl_bitrate.Text = Strings.avg_bit + ": " + (Math.Round(est_bitrate / 1000, 0)) + " " + "Mb/s"); - } - //Estimated size - est_size = Convert.ToDecimal(durat_n) * est_bitrate / 8; - - if (est_size > 1000000) - { - this.InvokeEx(f => f.lbl_est_size.Text = Strings.est_size + " " + (Math.Round(est_size / 1000000, 1)).ToString() + " " + "GB"); - } - else - { - if (Math.Round(est_size / 1000, 0) > 0) - { - this.InvokeEx(f => f.lbl_est_size.Text = Strings.est_size + " " + (Math.Round(est_size / 1000, 0)).ToString() + " " + "MB"); - } - else - { - this.InvokeEx(f => f.lbl_est_size.Text = Strings.est_size + " "); - } - } - } - - this.InvokeEx(f => f.lbl_est_size.Refresh()); - } - } - } - } - tmp.WaitForExit(); - tmp.StartInfo.Arguments = String.Empty; - timer_est_size.Stop(); - time_est_size = 0; - this.Invoke(new MethodInvoker(delegate - { - lbl_speed.Text = String.Empty; - lbl_est_size.Text = String.Empty; - lbl_bitrate.Text = String.Empty; - })); - list_lines.Add(""); - list_lines.Add("---------------------End of " + Path.GetFileName(file) + " log-------------------------------"); - list_lines.Add(""); - - if (tmp.ExitCode == 0) - { - if (skipped == false) - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.success); - this.InvokeEx(f => f.listView1.Items[list_index].BackColor = listView1.BackColor); - } - else - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.skipped); - total_prog = (total_prog + durat_n - sec_prog) / n_multi_presets; - skipped = false; - } - //this.InvokeEx(f => f.listView1.Items[list_index].EnsureVisible()); - } - else - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.error); - errors_enc = errors_enc + 1; - total_prog = total_prog + durat_n - sec_prog; - } - - if (list_index == listView1.Items.Count - 1) - { - n_multi_presets = n_multi_presets - 1; - preset_run = preset_run + 1; - list_index = -1; - } - if (n_multi_presets == 0) - { - runnin_n_presets = false; - - this.Invoke(new MethodInvoker(delegate - { - lbl_multip.Visible = false; - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - Pg1.Value = 100; - Pg1.Text = "100%"; - Pg1.Refresh(); - })); - list_index = listView1.Items.Count - 1; - working = false; - timer_est_size.Stop(); - time_est_size = 0; - - if (no_save_logs == false) - { - //Save log - string[] array_err = list_lines.ToArray(); - String path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.log"; - if (is_portable == true) path = port_path + "ff_batch_portable.log"; - - StreamWriter SaveFile = new StreamWriter(path); - SaveFile.WriteLine("FFmpeg log sesion: " + System.DateTime.Now); - SaveFile.WriteLine("-------------------------------"); - foreach (String item in array_err) - { - SaveFile.WriteLine(item); - } - SaveFile.Close(); - - File.AppendAllText(path, "-----------------------"); - File.AppendAllText(path, Environment.NewLine + Strings.end_log + Environment.NewLine); - File.AppendAllText(path, "-----------------------"); - FileInfo fileInfo = new FileInfo(path); - - var bytes = fileInfo.Length; - - var kilobytes = (double)bytes / 1024; - var megabytes = kilobytes / 1024; - var gigabytes = megabytes / 1024; - - //Format size view - String size = ""; - String separator = "."; - - if (bytes > 1000000000) - { - if (gigabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String gigas = gigabytes.ToString(); - if (gigas.Length >= 5) - { - gigas = gigas.Substring(0, gigas.LastIndexOf(separator) + 3); - size = (gigas + " " + "GB"); - } - else - { - size = (gigas + " " + "GB"); - } - } - - if (bytes >= 1048576 && bytes <= 1000000000) - { - if (megabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - String megas = megabytes.ToString(); - if (megas.Length > 5) - { - megas = megas.Substring(0, megas.LastIndexOf(separator)); - size = (megas + " " + "MB"); - } - else - { - size = (megas + " " + "MB"); - } - } - - if (bytes >= 1024 && bytes < 1048576) - - { - if (kilobytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String kbs = kilobytes.ToString(); - if (kbs.Length >= 5) - { - kbs = kbs.Substring(0, kbs.LastIndexOf(separator)); - size = (kbs + " " + "KB"); - } - else - { - size = (kbs + " " + "KB"); - } - } - if (bytes > -1 && bytes < 1024) - { - String bits = bytes.ToString(); - size = (bits + " Bytes"); - } - - //End Format size view - timer_tasks.Stop(); - TimeSpan t = TimeSpan.FromSeconds(time_n_tasks); - String tx_elapsed = string.Format("{0:D2}h:{1:D2}m:{2:D2}s", - t.Hours, - t.Minutes, - t.Seconds); - File.AppendAllText(path, Environment.NewLine); - File.AppendAllText(path, Environment.NewLine + Strings.total_time + " " + tx_elapsed); - File.AppendAllText(path, Environment.NewLine + Strings.log_size + " " + size); - //End save log - } - - this.Invoke(new MethodInvoker(delegate - { - if (errors_enc == 0) pic_no_errors.Visible = true; - else - { - toolT002.RemoveAll(); - pic_no_errors.Visible = false; - pic_recording.Visible = false; - toolT002.SetToolTip(this.pic_warnings, Strings.there_w + " " + errors_enc.ToString() + " " + Strings.errors_se); - pic_warnings.Visible = true; - } - })); - - //Automatic shutdown check - if (chkshut.Checked && cancel_queue == false) - { - auto_shut(); - return; - } - //End shutdown check - else - { - if (cancel_queue == false) - { - if (chk_delete_source.CheckState == CheckState.Checked) - { - Disable_Controls(); - System.Threading.Thread.Sleep(500); - list_proc.Items.Clear(); - listView1.Invoke(new MethodInvoker(delegate - { - foreach (ListViewItem item in listView1.Items) - { - list_proc.Items.Add((ListViewItem)item.Clone()); - } - })); - - Label prog_txt = new Label(); - ProgressBar pg_del = new ProgressBar(); - - this.Invoke(new MethodInvoker(delegate - { - prog_txt.Parent = panel1; - prog_txt.Top = 95; - prog_txt.Left = 80; - prog_txt.Width = 250; - prog_txt.TabIndex = 1; - prog_txt.BackColor = panel1.BackColor; - prog_txt.BorderStyle = BorderStyle.None; - prog_txt.TextAlign = ContentAlignment.MiddleLeft; - prog_txt.BringToFront(); - prog_txt.Text = Strings.to_recycle; - - pg_del.Parent = panel1; - pg_del.Top = 98; - pg_del.Left = 315; - pg_del.Width = 302; - pg_del.Height = 15; - pg_del.TabIndex = 0; - pg_del.BackColor = this.BackColor; - pg_del.Minimum = 0; - pg_del.BringToFront(); - pg_del.Maximum = list_proc.Items.Count; - pg_del.Show(); - pg_del.Refresh(); - })); - - int i = 0; - int err = 0; - - foreach (ListViewItem item in list_proc.Items) - { - if (item.SubItems[5].Text == Strings.success) - { - try - { - FileSystem.DeleteFile(item.SubItems[1].Text + "\\" + item.Text, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); - this.InvokeEx(f => pg_del.Value = i); - i = i + 1; - } - catch - { - err = err + 1; - } - - this.InvokeEx(f => prog_txt.Text = Strings.to_recycle + i.ToString() + " " + Strings.of1 + " " + list_proc.Items.Count); - this.InvokeEx(f => prog_txt.Refresh()); - } - } - this.Invoke(new MethodInvoker(delegate - { - prog_txt.Visible = false; - prog_txt.Dispose(); - pg_del.Visible = false; - pg_del.Dispose(); - })); - - Enable_Controls(); - - if (err > 0) MessageBox.Show(err.ToString() + " " + Strings.not_recycled2, Strings.not_recycled3, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - - Boolean all_ok = true; - foreach (ListViewItem item in list_proc.Items) - { - if (item.SubItems[5].Text != Strings.success) - { - all_ok = false; - break; - } - } - if (all_ok == true) - { - this.InvokeEx(f => f.btn_refresh.PerformClick()); - } - } - if (errors_enc == 0 && play_on_end) - { - play_end(); - } - else if (play_on_end == true) System.Media.SystemSounds.Asterisk.Play(); - - if (Form.ActiveForm == null) - { - if (errors_enc == 0) - { - notifyIcon1.BalloonTipText = Strings.enc_comp; - notifyIcon1.BalloonTipIcon = ToolTipIcon.Info; - notifyIcon1.BalloonTipTitle = Strings.enc_comp2; - notifyIcon1.ShowBalloonTip(0); - } - else - { - notifyIcon1.BalloonTipText = Strings.enc_comp3 + " " + errors_enc.ToString() + " " + Strings.errors1; - notifyIcon1.BalloonTipIcon = ToolTipIcon.Warning; - notifyIcon1.BalloonTipTitle = Strings.enc_comp2; - notifyIcon1.ShowBalloonTip(0); - } - } - - if (chk_open_compl.Checked) - { - if (Directory.GetFiles(destino).Length != 0) - { - Process open_processed = new Process(); - open_processed.StartInfo.FileName = "explorer.exe"; - open_processed.StartInfo.Arguments = '\u0022' + destino + '\u0022'; - open_processed.Start(); - } - else - { - if (Directory.Exists(destino)) - { - Directory.Delete(destino); - } - } - } - } - else - { - this.Invoke(new MethodInvoker(delegate - { - Pg1.Text = "100%"; - Pg1.Refresh(); - MessageBox.Show(Strings.queue_abort, Strings.aborted, MessageBoxButtons.OK, MessageBoxIcon.Error); - })); - } - } - } - } - - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - Enable_Controls(); - }).Start(); - } - - private void detect_silence() - { - Pg1.Focus(); - if (!File.Exists(Path.Combine(Application.StartupPath, "ffmpeg.exe"))) - { - MessageBox.Show(Strings.no_ffmpeg, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - String ffm = Path.Combine(Application.StartupPath, "AeroWizard.dll"); - if (!File.Exists(ffm)) - { - MessageBox.Show(Strings.no_aerowiz, Strings.required_file, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (listView1.Items.Count == 0) - { - MessageBox.Show(Strings.list_empty, Strings.no_files, MessageBoxButtons.OK, MessageBoxIcon.Information); - return; - } - - foreach (ListViewItem file2 in listView1.Items) - { - if (!File.Exists(file2.SubItems[1].Text + "\\" + file2.Text)) - { - MessageBox.Show(Strings.file_not_found + " " + file2.Text, Strings.file_not_found2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - - pg_adding.Visible = true; - pg_adding.Value = 0; - pg_adding.Maximum = listView1.Items.Count; - LB_Wait.Visible = true; - txt_adding_p.Visible = true; - - LB_Wait.Text = String.Empty; - LB_Wait.Visible = false; - pg_adding.Visible = false; - txt_adding_p.Text = String.Empty; - - String f_nologs = String.Empty; - if (is_portable == false) - { - f_nologs = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_nologs.ini"; - } - else - { - f_nologs = port_path + "ff_nologs_portable.ini"; - } - - no_save_logs = File.Exists(f_nologs); - //End do not save logs - - if (no_save_logs == true) - { - DialogResult a = MessageBox.Show(Strings.log_req, Strings.log_dis, MessageBoxButtons.YesNo, MessageBoxIcon.Question); - if (a == DialogResult.No) return; - else - { - no_save_logs = false; - try - { - File.Delete(f_nologs); - } - catch (Exception excpt) - { - MessageBox.Show(Strings.log_enab + Environment.NewLine + Environment.NewLine + excpt.Message); - } - } - } - - AeroWizard4 wizard4 = new AeroWizard4(); - wizard4.StartPosition = FormStartPosition.CenterScreen; - wizard4.ShowDialog(); - if (wizard4.ok_silence == true) - { - silence_params = wizard4.pr1_first_params; - start_silence(); - } - else - { - return; - } - } - - private void start_silence() - { - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - cancel_queue = false; - notifyIcon1.Visible = true; - lbl_multip.Text = String.Empty; - //Validated list, start processing - - txt_remain.Text = Strings.remain_time + " " + "00h:00m:00s"; - - if (listView1.SelectedIndices.Count == 0) - { - listView1.Items[0].Selected = true; - listView1.Items[0].Focused = true; - listView1.Focus(); - } - - //Remove test file/folder - - String file_prueba = ""; - String sel_test = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - file_prueba = sel_test; - String destino = Path.Combine(Path.GetTempPath(), "\\" + "FFBatch_test"); - String borrar = destino + "\\" + Path.GetFileNameWithoutExtension(file_prueba) + "." + txt_format.Text; - - cancel_queue = false; - Pg1.Value = 0; - //pg_current.Value = 0; - Disable_Controls(); - - btn_skip_main.Enabled = true; - //textBox4.Text = "0%"; - working = true; - runnin_n_presets = true; - - ListView list_proc = new ListView(); - foreach (ListViewItem item in listView1.Items) - { - list_proc.Items.Add((ListViewItem)item.Clone()); - item.SubItems[5].Text = Strings.queued; - item.BackColor = Color.White; - } - - //End save hw decoder - - Pg1.Maximum = listView1.Items.Count; - listView1.SelectedIndices.Clear(); - - total_duration = 0; - Double total_prog = 0; - - //Get total duration of files - - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[3].Text != Strings.n_a && item.SubItems[3].Text != "0:00:00" && item.SubItems[3].Text != "00:00:00" && item.SubItems[3].Text != Strings.pending) - { - total_duration = total_duration + TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds - TimeSpan.Parse(ss_time_input.Text).TotalSeconds; - } - else - { - total_duration = total_duration + 0; - } - } - - Pg1.Minimum = 0; - Pg1.Maximum = 100; - String remain_time = "0"; - //End get total duration of files - - List list_lines = new List(); - - procs.Clear(); - - for (int ii = 0; ii < listView1.Items.Count; ii++) - { - procs.Add("proc_urls_" + ii.ToString(), new Process()); - } - - time_n_tasks = 0; - timer_tasks.Start(); - timer_est_size.Start(); - time_est_size = 0; - String file = String.Empty; - - panel2.Enabled = true; - chk_delete_source.Enabled = true; - - Boolean silence_found = false; - - foreach (Control ct in panel2.Controls) - { - if (ct.Name != chk_delete_source.Name) - { - this.InvokeEx(f => ct.Enabled = false); - } - } - - new System.Threading.Thread(() => - { - System.Threading.Thread.CurrentThread.IsBackground = true; - - for (int list_index = 0; list_index < listView1.Items.Count; list_index++) - { - System.Threading.Thread.Sleep(50); //Allow kill process to send cancel_queue - - listView1.Invoke(new MethodInvoker(delegate - { - file = listView1.Items[list_index].SubItems[1].Text + "\\" + listView1.Items[list_index].Text; - })); - - if (cancel_queue == true) - { - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - working = false; - time_est_size = 0; - - Enable_Controls(); - MessageBox.Show(Strings.queue_abort, Strings.task_abort, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; - } - this.InvokeEx(f => timer_est_size.Start()); - - String ffm = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - String fullPath = file; - - if (txt_path_main.Text.Contains(".\\")) - { - if (txt_path_main.Text != ".\\") - destino = file.Substring(0, fullPath.LastIndexOf('\\')) + txt_path_main.Text.Replace(".", String.Empty); - else - { - destino = Path.GetDirectoryName(file); - } - } - else - { - if (chk_recreate.CheckState == CheckState.Checked) - { - String pre_dest = Path.GetDirectoryName(file); - destino = Path.Combine(txt_path_main.Text, pre_dest.Substring(3, pre_dest.Length - 3)); - } - else - { - destino = txt_path_main.Text; - } - } - - String pre_input_var = ""; - if (txt_pre_input.Text != "") - { - pre_input_var = txt_pre_input.Text; - } - - String pre_ss = ""; - if (TimeSpan.Parse(ss_time_input.Text).TotalSeconds != 0) - { - pre_ss = " -ss " + ss_time_input.Text; - } - - add_suffix = ""; - - if (chk_suffix.Checked == true && txt_suffix.Text != String.Empty) - { - add_suffix = txt_suffix.Text; - } - - String AppParam = pre_input_var + " " + pre_ss + " -i " + "" + '\u0022' + file + '\u0022' + " " + silence_params + " -loglevel info -stats"; - - if (!Directory.Exists(destino)) - { - Directory.CreateDirectory(destino); - } - - var tmp = procs["proc_urls_" + list_index.ToString()]; - - tmp.StartInfo.FileName = ffm; - tmp.StartInfo.Arguments = AppParam; - tmp.StartInfo.RedirectStandardInput = true; - tmp.StartInfo.RedirectStandardError = true; - tmp.StartInfo.UseShellExecute = false; - tmp.StartInfo.CreateNoWindow = true; - tmp.EnableRaisingEvents = true; - tmp.Start(); - - valid_prog = false; - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.processing); - - System.Threading.Thread.Sleep(50); - combo_prio.Invoke(new MethodInvoker(delegate - { - if (combo_prio.SelectedIndex != 2) - { - Change_mem_prio(); - } - })); - - this.InvokeEx(f => validate_duration = listView1.Items[list_index].SubItems[3].Text); - if (validate_duration != Strings.n_a && validate_duration != "0:00:00" && validate_duration != "00:00:00" && validate_duration != Strings.pending) - { - valid_prog = true; - } - - String err_txt = ""; - - String silence_duration = String.Empty; - String silence_start = String.Empty; - Double interval = 0; - this.InvokeEx(f => durat_n = TimeSpan.Parse(listView1.Items[list_index].SubItems[3].Text).TotalSeconds - TimeSpan.Parse(ss_time_input.Text).TotalSeconds); - - lbl_speed.Text = String.Empty; - Double sec_prog = 0; - Boolean silence_found_file = false; - - while (!tmp.StandardError.EndOfStream) - { - err_txt = tmp.StandardError.ReadLine(); - - if (err_txt.ToLower().Contains("silence")) - { - silence_found = true; - silence_found_file = true; - list_lines.Add(err_txt); - try - { - if (err_txt.ToLower().Contains("silence_start:")) silence_start = err_txt.Substring(err_txt.LastIndexOf("silence_start:") + 15, 6); - if (err_txt.ToLower().Contains("silence_duration:")) silence_duration = err_txt.Substring(err_txt.LastIndexOf("silence_duration:") + 18, 6); - } - catch { } - } - if (err_txt.Contains("time=") && err_txt.Contains("time=-") == false) - { - if (valid_prog == true) - { - int start_time_index = err_txt.IndexOf("time=") + 5; - sec_prog = TimeSpan.Parse(err_txt.Substring(start_time_index, 8)).TotalSeconds; - - Double percent = (sec_prog * 100 / durat_n); - - total_prog = total_prog + (sec_prog - interval); - interval = sec_prog; - int percent2 = Convert.ToInt32(percent); - - Double percent_tot = (total_prog * 100 / total_duration); - int percent_tot_2 = Convert.ToInt32(percent_tot); - - if (percent_tot_2 <= 100) - { - this.Invoke(new MethodInvoker(delegate - { - Pg1.Value = percent_tot_2; - Pg1.Refresh(); - - Pg1.Text = Math.Round(percent_tot, 1).ToString() + "%"; - TaskbarProgress.SetValue(this.Handle, percent_tot, Pg1.Maximum); - })); - } - - if (percent2 <= 100) - { - if (Math.Round(percent, 1).ToString().Contains(".") || Math.Round(percent, 1).ToString().Contains(",")) - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Math.Round(percent, 1).ToString() + "%"); - } - else - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Math.Round(percent, 1).ToString() + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0" + "%"); - } - } - - if (cancel_queue == false) - { - //Estimated remaining time - - remain_time = err_txt.Substring(err_txt.LastIndexOf("speed=") + 6, err_txt.Length - err_txt.LastIndexOf("speed=") - 6); - if (time_est_size % 3 == 0) this.InvokeEx(f => f.lbl_speed.Text = Strings.speed + " " + remain_time); - remain_time = remain_time.Replace("x", String.Empty); - Double timing1 = 0; - - if (!remain_time.Contains("N/A")) - { - if (System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",") - { - timing1 = Math.Round(Double.Parse(remain_time.Replace(".", ",")), 2); - } - else - { - timing1 = Math.Round(Double.Parse(remain_time), 2); - } - - - Decimal timing = (decimal)timing1; - Decimal total_dur_dec = Convert.ToDecimal(total_duration); - Decimal total_prog_dec = Convert.ToDecimal(total_prog); - Decimal remain_secs = 0; - - if (timing > 0) - { - remain_secs = (decimal)(total_dur_dec - total_prog_dec) / timing; - } - - if (remain_secs > 60) - { - remain_secs = remain_secs + 60; - } - - String remain_from_secs = String.Empty; - - TimeSpan t = TimeSpan.FromSeconds(Convert.ToDouble(remain_secs)); - remain_from_secs = string.Format("{0:D2}h:{1:D2}", t.Hours, t.Minutes); - - if (remain_secs >= 43200) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + Math.Round(remain_secs / 3600).ToString() + " " + Strings.hours); - } - - if (remain_secs >= 3600 && remain_secs < 43200) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + remain_from_secs + " " + Strings.minutes_abrev); - } - - if (remain_secs < 3600 && remain_secs >= 600) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 1, 2) + " " + Strings.minutes); - } - - if (remain_secs < 600 && remain_secs >= 120) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 2, 1) + " " + Strings.minutes); - } - - if (remain_secs <= 59 && remain_secs != 0) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + Convert.ToInt16(remain_secs) + " " + Strings.seconds); - } - - if (remain_secs == 0) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + Strings.about_finish); - } - } - } - //End remaining time - } - } - } - tmp.WaitForExit(); - tmp.StartInfo.Arguments = String.Empty; - timer_est_size.Stop(); - time_est_size = 0; - - this.Invoke(new MethodInvoker(delegate - { - lbl_speed.Text = String.Empty; - lbl_est_size.Text = String.Empty; - lbl_bitrate.Text = String.Empty; - })); - - list_lines.Add(""); - list_lines.Add("---------------------End of " + Path.GetFileName(file) + " log-------------------------------"); - list_lines.Add(""); - - if (tmp.ExitCode == 0) - { - if (skipped == false) - { - if (silence_found_file == false) - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.success); - } - else - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.silence_start + " " + silence_start + " " + Strings.dur1 + " " + silence_duration); - this.InvokeEx(f => f.listView1.Items[list_index].BackColor = Color.LightGoldenrodYellow); - } - } - else - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.skipped); - total_prog = (total_prog + durat_n - sec_prog) / n_multi_presets; - skipped = false; - } - } - else - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.error); - total_prog = total_prog + durat_n - sec_prog; - } - - if (list_index == listView1.Items.Count - 1) - { - runnin_n_presets = false; - list_index = listView1.Items.Count - 1; - working = false; - timer_est_size.Stop(); - time_est_size = 0; - this.Invoke(new MethodInvoker(delegate - { - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - lbl_multip.Visible = false; - Pg1.Value = 100; - Pg1.Text = "100%"; - })); - - if (no_save_logs == false) - { - //Save log - string[] array_err = list_lines.ToArray(); - String path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.log"; - if (is_portable == true) path = port_path + "ff_batch_portable.log"; - - StreamWriter SaveFile = new StreamWriter(path); - SaveFile.WriteLine("FFmpeg log sesion: " + System.DateTime.Now); - SaveFile.WriteLine("-------------------------------"); - foreach (String item in array_err) - { - SaveFile.WriteLine(item); - } - SaveFile.Close(); - - File.AppendAllText(path, "-----------------------"); - File.AppendAllText(path, Environment.NewLine + Strings.end_log + Environment.NewLine); - File.AppendAllText(path, "-----------------------"); - FileInfo fileInfo = new FileInfo(path); - - var bytes = fileInfo.Length; - - var kilobytes = (double)bytes / 1024; - var megabytes = kilobytes / 1024; - var gigabytes = megabytes / 1024; - - //Format size view - String size = ""; - String separator = "."; - - if (bytes > 1000000000) - { - if (gigabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String gigas = gigabytes.ToString(); - if (gigas.Length >= 5) - { - gigas = gigas.Substring(0, gigas.LastIndexOf(separator) + 3); - size = (gigas + " " + "GB"); - } - else - { - size = (gigas + " " + "GB"); - } - } - - if (bytes >= 1048576 && bytes <= 1000000000) - { - if (megabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - String megas = megabytes.ToString(); - if (megas.Length > 5) - { - megas = megas.Substring(0, megas.LastIndexOf(separator)); - size = (megas + " " + "MB"); - } - else - { - size = (megas + " " + "MB"); - } - } - - if (bytes >= 1024 && bytes < 1048576) - - { - if (kilobytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String kbs = kilobytes.ToString(); - if (kbs.Length >= 5) - { - kbs = kbs.Substring(0, kbs.LastIndexOf(separator)); - size = (kbs + " " + "KB"); - } - else - { - size = (kbs + " " + "KB"); - } - } - if (bytes > -1 && bytes < 1024) - { - String bits = bytes.ToString(); - size = (bits + " Bytes"); - } - - //End Format size view - timer_tasks.Stop(); - TimeSpan t = TimeSpan.FromSeconds(time_n_tasks); - String tx_elapsed = string.Format("{0:D2}h:{1:D2}m:{2:D2}s", - t.Hours, - t.Minutes, - t.Seconds); - File.AppendAllText(path, Environment.NewLine); - File.AppendAllText(path, Environment.NewLine + Strings.total_time + " " + tx_elapsed); - File.AppendAllText(path, Environment.NewLine + Strings.log_size + " " + size); - //End save log - } - - //Automatic shutdown check - if (chkshut.Checked && cancel_queue == false) - { - auto_shut(); - return; - } - //End shutdown check - else - { - if (cancel_queue == false) - { - if (chk_delete_source.CheckState == CheckState.Checked) - { - Disable_Controls(); - System.Threading.Thread.Sleep(500); - list_proc.Items.Clear(); - listView1.Invoke(new MethodInvoker(delegate - { - foreach (ListViewItem item in listView1.Items) - { - list_proc.Items.Add((ListViewItem)item.Clone()); - } - })); - - Label prog_txt = new Label(); - ProgressBar pg_del = new ProgressBar(); - this.Invoke(new MethodInvoker(delegate - { - prog_txt.Parent = panel1; - prog_txt.Top = 95; - prog_txt.Left = 80; - prog_txt.Width = 250; - prog_txt.TabIndex = 1; - prog_txt.BackColor = panel1.BackColor; - prog_txt.BorderStyle = BorderStyle.None; - prog_txt.TextAlign = ContentAlignment.MiddleLeft; - prog_txt.BringToFront(); - prog_txt.Text = Strings.to_recycle; - pg_del.Parent = panel1; - pg_del.Top = 98; - pg_del.Left = 315; - pg_del.Width = 302; - pg_del.Height = 15; - pg_del.TabIndex = 0; - pg_del.BackColor = this.BackColor; - pg_del.Minimum = 0; - pg_del.BringToFront(); - pg_del.Maximum = list_proc.Items.Count; - pg_del.Show(); - pg_del.Refresh(); - })); - - int i = 0; - int err = 0; - - foreach (ListViewItem item in list_proc.Items) - { - if (item.SubItems[5].Text == Strings.success) - { - try - { - FileSystem.DeleteFile(item.SubItems[1].Text + "\\" + item.Text, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); - this.InvokeEx(f => pg_del.Value = i); - i = i + 1; - } - catch - { - err = err + 1; - } - - this.InvokeEx(f => prog_txt.Text = Strings.to_recycle + i.ToString() + " " + Strings.of1 + " " + list_proc.Items.Count); - this.InvokeEx(f => prog_txt.Refresh()); - } - } - listView1.Invoke(new MethodInvoker(delegate - { - prog_txt.Visible = false; - prog_txt.Dispose(); - pg_del.Visible = false; - pg_del.Dispose(); - })); - - Enable_Controls(); - - if (err > 0) MessageBox.Show(err.ToString() + " " + Strings.not_recycled2, Strings.not_recycled3, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - - Boolean all_ok = true; - foreach (ListViewItem item in list_proc.Items) - { - if (item.SubItems[5].Text != Strings.success) - { - all_ok = false; - break; - } - } - if (all_ok == true) - { - this.InvokeEx(f => f.btn_refresh.PerformClick()); - } - } - - if (play_on_end == true) play_end(); - - if (Form.ActiveForm == null) - { - notifyIcon1.BalloonTipText = Strings.ff_silence_c; - notifyIcon1.BalloonTipIcon = ToolTipIcon.Info; - notifyIcon1.BalloonTipTitle = Strings.silence_c; - notifyIcon1.ShowBalloonTip(0); - } - - if (chk_open_compl.Checked) - { - if (Directory.GetFiles(destino).Length != 0) - { - Process open_processed = new Process(); - open_processed.StartInfo.FileName = "explorer.exe"; - open_processed.StartInfo.Arguments = '\u0022' + destino + '\u0022'; - open_processed.Start(); - } - else - { - if (Directory.Exists(destino)) - { - Directory.Delete(destino); - } - } - } - } - else - { - this.InvokeEx(f => f.Pg1.Text = "100%"); - this.InvokeEx(f => MessageBox.Show(Strings.queue_abort, Strings.aborted, MessageBoxButtons.OK, MessageBoxIcon.Error)); - } - } - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - Enable_Controls(); - if (silence_found == true) - { - Enable_Controls(); - if (play_on_end == true) - { - System.Media.SystemSounds.Asterisk.Play(); - } - this.InvokeEx(f => MessageBox.Show(Strings.silence_detect, Strings.silence_found, MessageBoxButtons.OK, MessageBoxIcon.Warning)); - } - } - } - }).Start(); - } - private void two_pass_encoding() - { - cancel_queue = false; - notifyIcon1.Visible = true; - lbl_multip.Text = String.Empty; - //Validated list, start processing - if ((fade_v_in.Checked == true && num_v_in.Value == 0) || (fade_v_out.Checked == true && num_v_out.Value == 0) || (fade_a_in.Checked == true && num_a_in.Value == 0) || (fade_a_out.Checked == true && num_a_out.Value == 0)) - { - MessageBox.Show(Strings.fading_zero, Strings.fading_zero2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - txt_remain.Text = Strings.remain_time + " " + "00h:00m:00s"; - - if (listView1.SelectedIndices.Count == 0) - { - listView1.Items[0].Selected = true; - listView1.Items[0].Focused = true; - listView1.Focus(); - } - String destino = Path.GetTempPath() + "\\" + "FFBatch_test"; - //Pending duration - - if (dur_ok == false) - { - list_pending_dur.Items.Clear(); - foreach (ListViewItem item in listView1.Items) - { - list_pending_dur.Items.Add((ListViewItem)item.Clone()); - } - BG_Dur.RunWorkerAsync(); - return; - } - - //Check queued items - - if (warn_success_items == true) - { - Boolean no_queued = true; - Boolean has_complete = false; - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[5].Text == Strings.queued) - { - no_queued = false; - } - if (item.SubItems[5].Text == Strings.success || item.SubItems[5].Text == Strings.replaced) - { - has_complete = true; - } - } - - if (no_queued == true && listView1.Items.Count > 1) - { - DialogResult a = MessageBox.Show(Strings.items_q + " " + '\u0022' + Strings.queued + '\u0022' + ". " + Strings.all_files + " " + Strings.already_proc, Strings.not_queued, MessageBoxButtons.OKCancel, MessageBoxIcon.Question); - if (a == DialogResult.Cancel) return; - } - - if (no_queued == false && has_complete == true) - { - DialogResult a = MessageBox.Show(Strings.already_encoded + " " + '\u0022' + Strings.queued + '\u0022' + Strings.continu, Strings.some_q, MessageBoxButtons.OKCancel, MessageBoxIcon.Question); - if (a == DialogResult.Cancel) return; - } - //End check queued items - } - - cancel_queue = false; - Pg1.Value = 0; - //pg_current.Value = 0; - - btn_skip_main.Enabled = true; - //textBox4.Text = "0%"; - working = true; - runnin_n_presets = true; - - ListView list_proc = new ListView(); - foreach (ListViewItem item in listView1.Items) - { - list_proc.Items.Add((ListViewItem)item.Clone()); - item.SubItems[5].Text = Strings.queued; - item.BackColor = Color.White; - } - String hw_decode = String.Empty; - if (cb_hwdecode.SelectedItem.ToString() != "none") - { - hw_decode = "-hwaccel " + cb_hwdecode.SelectedItem.ToString(); - } - - //Save selected hw decoder - - String path2 = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_hw_dcd.ini"; - if (is_portable == true) - { - path2 = port_path + "ff_hw_dcd_portable.ini"; - } - String txt_hw_dcd = cb_hwdecode.SelectedItem.ToString(); - if (txt_hw_dcd != "none") - { - File.WriteAllText(path2, txt_hw_dcd); - } - else - { - if (File.Exists(path2)) File.Delete(path2); - } - - //End save hw decoder - - // Fade validation - fade_ok = true; - check_fade(); - if (fade_ok == false && Settings.Default.quick_queue == false) - { - Enable_Controls(); - return; - } - // END Fade validation - - listView1.SelectedIndices.Clear(); - - total_duration = 0; - Double total_prog = 0; - - //Get total duration of files - DateTime time; - - Pg1.Minimum = 0; - Pg1.Maximum = 100; - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - Pg1.Refresh(); - String remain_time = "0"; - //End get total duration of files - - List list_lines = new List(); - - procs.Clear(); - - for (int ii = 0; ii < listView1.Items.Count; ii++) - { - procs.Add("proc_urls_" + ii.ToString(), new Process()); - } - - time_n_tasks = 0; - timer_tasks.Start(); - timer_est_size.Start(); - time_est_size = 0; - String file = String.Empty; - - panel2.Enabled = true; - chk_delete_source.Enabled = true; - Disable_Controls(); - foreach (Control ct in panel2.Controls) - { - if (ct.Name != chk_delete_source.Name) - { - this.InvokeEx(f => ct.Enabled = false); - } - } - - String f_in_color = "Black"; - String f_out_color = "Black"; - if (combo_vin_col.SelectedIndex == 1) f_in_color = "White"; - if (combo_vout_color.SelectedIndex == 1) f_out_color = "White"; - - String in_color = ":color=" + f_in_color; - String out_color = ":color=" + f_out_color; - if (combo_vin_col.SelectedIndex == 2) in_color = ":alpha=1"; - if (combo_vout_color.SelectedIndex == 2) out_color = ":alpha=1"; - - n_multi_presets = 2; - int preset_run = 1; - int to_go = n_multi_presets; - - String ext_output1 = String.Empty; - String pre_i = txt_pre_input.Text; - Double dur_rpl = 0; - - new System.Threading.Thread(() => - { - System.Threading.Thread.CurrentThread.IsBackground = true; - - foreach (ListViewItem item in list_proc.Items) - { - if (cancel_queue == true) - { - Enable_Controls(); - working = false; - break; - return; - } - - if (DateTime.TryParse(item.SubItems[3].Text, out time)) - { - total_duration = total_duration + TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds - TimeSpan.Parse(ss_time_input.Text).TotalSeconds; - } - else - { - file = item.SubItems[1].Text + "\\" + item.Text; - Type ts = Type.GetTypeFromProgID("Shell.Application"); - dynamic shell = Activator.CreateInstance(ts); - Folder rFolder = shell.NameSpace(Path.GetDirectoryName(file)); - FolderItem rFiles = rFolder.ParseName(Path.GetFileName(file)); - String videostype = rFolder.GetDetailsOf(rFiles, 2).Trim(); - String videoSize = rFolder.GetDetailsOf(rFiles, 1).Trim(); - - listView1.Invoke(new MethodInvoker(delegate - { - listView1.Items[item.Index].SubItems[2].Text = videostype; - listView1.Items[item.Index].SubItems[4].Text = videoSize; - })); - - DateTime tm = new DateTime(); - String ndur = "00:00:00"; - String dur_q = rFolder.GetDetailsOf(rFiles, 27).Trim(); - - if (DateTime.TryParse(dur_q, out tm)) - { - total_duration = total_duration + TimeSpan.Parse(dur_q).TotalSeconds - TimeSpan.Parse(ss_time_input.Text).TotalSeconds; - listView1.Invoke(new MethodInvoker(delegate - { - if (listView1.Items[item.Index].SubItems[3].Text == "-") listView1.Items[item.Index].SubItems[3].Text = dur_q; - })); - } - else - { - ndur = get_file_dur(file); - total_duration = total_duration + TimeSpan.Parse(ndur).TotalSeconds; - listView1.Invoke(new MethodInvoker(delegate - { - if (listView1.Items[item.Index].SubItems[3].Text == "-") listView1.Items[item.Index].SubItems[3].Text = ndur; - })); - } - } - } - - Boolean is_vp9 = false; - if (multi_two_pr1.ToLower().Contains("libvpx-vp9")) - { - is_vp9 = true; - } - else - { - total_duration = total_duration * 2; - } - - for (int list_index = 0; list_index < listView1.Items.Count;) - { - System.Threading.Thread.Sleep(50); //Allow kill process to send cancel_queue - - listView1.Invoke(new MethodInvoker(delegate - { - file = listView1.Items[list_index].SubItems[1].Text + "\\" + listView1.Items[list_index].Text; - - })); - - if (cancel_queue == true) - { - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - working = false; - time_est_size = 0; - //this.InvokeEx(f => f.button2.Enabled = true); - Enable_Controls(); - MessageBox.Show(Strings.queue_abort, Strings.task_abort, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; - } - int fframes = 0; - ProgressBarWithText pg_lv_vp9 = new ProgressBarWithText(); - - if (is_vp9 == true) - { - this.Invoke(new MethodInvoker(delegate - { - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - Pg1.Refresh(); - pg_lv_vp9.Parent = panel1; - pg_lv_vp9.Top = 123; - pg_lv_vp9.Left = 342; - pg_lv_vp9.Width = 120; - pg_lv_vp9.Height = 15; - pg_lv_vp9.BringToFront(); - pg_lv_vp9.Show(); - })); - - if (preset_run == 1) - { - String ff_frames = String.Empty; - Process get_frames = new Process(); - get_frames.StartInfo.FileName = Path.Combine(Application.StartupPath, "mediainfo.exe"); - String ffprobe_frames = "--Output=" + '\u0022' + "Video;%FrameCount%" + '\u0022'; - get_frames.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + list_proc.Items[list_index].SubItems[1].Text + "\\" + list_proc.Items[list_index].Text + '\u0022'; - get_frames.StartInfo.RedirectStandardOutput = true; - get_frames.StartInfo.UseShellExecute = false; - get_frames.StartInfo.CreateNoWindow = true; - get_frames.EnableRaisingEvents = true; - get_frames.Start(); - - ff_frames = get_frames.StandardOutput.ReadLine(); - get_frames.WaitForExit(); - - if (get_frames.ExitCode == 0) - { - if (ff_frames != null) - { - if (ff_frames.ToLower() != Strings.n_a) - { - int try_ff = 0; - if (int.TryParse(ff_frames, out try_ff)) - { - fframes = try_ff; - } - } - else - { - fframes = 0; - } - } - } - else - { - fframes = 0; - } - - get_frames.Dispose(); - this.InvokeEx(f => pg_lv_vp9.Maximum = fframes); - } - } - - this.InvokeEx(f => timer_est_size.Start()); - - String ffm = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - String fullPath = file; - - //Begin Shifting - String shifting = ""; - if (chk_shift.Checked == true) - { - shifting = " -itsoffset " + Num_Shift.Value.ToString().Replace(",", ".") + " -i " + '\u0022' + file + '\u0022' + " -map 1:v -map 0:a "; - } - //End Shifting - - //Begin fading and volume changing - String change_vol_fade = ""; - if (chk_vol.Checked == true) - { - change_vol_fade = "-af " + '\u0022' + "volume=" + vol_ch.Value.ToString() + "dB " + '\u0022' + " "; - } - - String fade_filter = String.Empty; - Decimal fade_frames = 0; - - if (fade_v_in.CheckState == CheckState.Checked || fade_v_out.CheckState == CheckState.Checked || fframes == 0) - { - String ff_frames = String.Empty; - Process get_frames = new Process(); - get_frames.StartInfo.FileName = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - String ffprobe_frames = " " + '\u0022' + "--Inform=Video;%FrameRate%" + '\u0022'; - get_frames.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + list_proc.Items[list_index].SubItems[1].Text + "\\" + list_proc.Items[list_index].Text + '\u0022'; - get_frames.StartInfo.RedirectStandardOutput = true; - get_frames.StartInfo.UseShellExecute = false; - get_frames.StartInfo.CreateNoWindow = true; - get_frames.EnableRaisingEvents = true; - get_frames.Start(); - - ff_frames = get_frames.StandardOutput.ReadLine(); - - get_frames.WaitForExit(); - - if (get_frames.ExitCode == 0 && ff_frames != null) - { - try - { - fade_frames = decimal.Parse(ff_frames) / 1000; - } - catch { fade_frames = 0; } - } - get_frames.Dispose(); - } - - if (fade_v_in.CheckState == CheckState.Checked && fade_v_out.CheckState == CheckState.Unchecked) - { - Decimal fff_in = Math.Round(num_v_in.Value * fade_frames, 0); - fade_filter = "-vf " + '\u0022' + "fade=in:0:" + fff_in.ToString() + in_color + '\u0022'; - } - - if (fade_v_in.CheckState == CheckState.Unchecked && fade_v_out.CheckState == CheckState.Checked) - { - Double dur_frames = TimeSpan.Parse(list_proc.Items[list_index].SubItems[3].Text).TotalSeconds * Convert.ToDouble(fade_frames); - Decimal fade_out_total = Math.Round(Convert.ToDecimal(dur_frames), 3, MidpointRounding.AwayFromZero); - Decimal fade_out_initial = Math.Round(fade_out_total - (num_v_out.Value * fade_frames), 0, MidpointRounding.AwayFromZero); - Decimal fff_out = Math.Round(num_v_out.Value * fade_frames, 0, MidpointRounding.AwayFromZero); - - fade_filter = "-vf " + '\u0022' + "fade=out:" + fade_out_initial.ToString() + ":" + fff_out.ToString() + out_color + '\u0022'; - } - - if (fade_v_in.CheckState == CheckState.Checked && fade_v_out.CheckState == CheckState.Checked) - { - Decimal fff_in = Math.Round(num_v_in.Value * fade_frames, 0, MidpointRounding.AwayFromZero); - Double dur_frames = TimeSpan.Parse(list_proc.Items[list_index].SubItems[3].Text).TotalSeconds * Convert.ToDouble(fade_frames); - Decimal fade_out_total = Math.Round(Convert.ToDecimal(dur_frames), 3, MidpointRounding.AwayFromZero); - Decimal fade_out_initial = Math.Round(fade_out_total - (num_v_out.Value * fade_frames), 0, MidpointRounding.AwayFromZero); - Decimal fff_out = Math.Round(num_v_out.Value * fade_frames, 0, MidpointRounding.AwayFromZero); - - fade_filter = "-vf " + '\u0022' + "fade=in:0:" + fff_in.ToString() + in_color + ", " + "fade=out:" + fade_out_initial.ToString() + ":" + fff_out.ToString() + out_color + '\u0022'; - } - - //Audio fading - if (fade_a_in.CheckState == CheckState.Checked && fade_a_out.CheckState == CheckState.Unchecked) - { - if (chk_vol.Checked == false) - { - change_vol_fade = "-af " + '\u0022' + "afade=t=in:ss=0:d=" + num_a_in.Value.ToString() + '\u0022'; - } - else - { - change_vol_fade = "-af " + '\u0022' + "afade=t=in:ss=0:d=" + num_a_in.Value.ToString() + ", " + "volume=" + vol_ch.Value.ToString() + "dB " + '\u0022'; - } - } - - if (fade_a_in.CheckState == CheckState.Unchecked && fade_a_out.CheckState == CheckState.Checked) - { - Double af_out = TimeSpan.Parse(list_proc.Items[list_index].SubItems[3].Text).TotalSeconds - Convert.ToDouble(num_a_out.Value); - Decimal af_out_dec = Math.Round(Convert.ToDecimal(af_out), 0, MidpointRounding.AwayFromZero); - if (chk_vol.Checked == false) - { - change_vol_fade = "-af " + '\u0022' + "afade=t=out:st=" + af_out_dec + ":d=" + num_a_out.Value.ToString() + '\u0022'; - } - else - { - change_vol_fade = "-af " + '\u0022' + "afade=t=out:st=" + af_out_dec + ":d=" + num_a_out.Value.ToString() + ", " + "volume=" + vol_ch.Value.ToString() + "dB " + '\u0022'; - } - } - if (fade_a_in.CheckState == CheckState.Checked && fade_a_out.CheckState == CheckState.Checked) - { - Double af_out = TimeSpan.Parse(list_proc.Items[list_index].SubItems[3].Text).TotalSeconds - Convert.ToDouble(num_a_out.Value); - Decimal af_out_dec = Math.Round(Convert.ToDecimal(af_out), 0, MidpointRounding.AwayFromZero); - - if (chk_vol.Checked == false) - { - change_vol_fade = "-af " + '\u0022' + "afade=t=in:ss=0:d=" + num_a_in.Value.ToString() + ", " + "afade=t=out:st=" + af_out_dec + ":d=" + num_a_out.Value.ToString() + '\u0022'; - } - else - { - change_vol_fade = "-af " + '\u0022' + "afade=t=in:ss=0:d=" + num_a_in.Value.ToString() + ", " + "afade=t=out:st=" + af_out_dec + ":d=" + num_a_out.Value.ToString() + ", " + "volume=" + vol_ch.Value.ToString() + "dB " + '\u0022'; - } - } - //End audio fading - - //End fading - - //End Change Volume - - if (txt_path_main.Text.Contains(".\\")) - { - destino = file.Substring(0, fullPath.LastIndexOf('\\')) + txt_path_main.Text.Replace(".", String.Empty); - } - else - { - if (chk_recreate.CheckState == CheckState.Checked) - { - String pre_dest = Path.GetDirectoryName(file); - destino = Path.Combine(txt_path_main.Text, pre_dest.Substring(3, pre_dest.Length - 3)); - } - else - { - destino = txt_path_main.Text; - } - } - - String pre_input_var = ""; - if (txt_pre_input.Text != "") - { - pre_input_var = txt_pre_input.Text; - } - - String pre_ss = ""; - if (TimeSpan.Parse(ss_time_input.Text).TotalSeconds != 0) - { - pre_ss = " -ss " + ss_time_input.Text; - } - - add_suffix = ""; - - if (chk_suffix.Checked == true && txt_suffix.Text != String.Empty) - { - add_suffix = txt_suffix.Text; - } - String add_pr_suffix = String.Empty; - if (ren_multi == true) - { - add_pr_suffix = "_" + preset_run.ToString(); - } - - if (preset_run == 1) - { - ext_output1 = "nul"; - textbox_params = multi_1st_pass; - } - if (preset_run == 2) - { - ext_output1 = "." + multi_two_ext; - textbox_params = multi_two_pr1; - } - - String file2 = file; - - //Variables - - - while (textbox_params.Contains("%fn")) - { - if (textbox_params.Contains("%fn")) - { - textbox_params = textbox_params.Replace("%fn", Path.GetFileNameWithoutExtension(file2)); - } - } - - while (pre_i.Contains("%fn")) - { - if (pre_i.Contains("%fn")) - { - pre_i = pre_i.Replace("%fn", Path.GetFileNameWithoutExtension(file2)); - } - } - - while (textbox_params.Contains("%ff")) - { - if (textbox_params.Contains("%ff")) - { - textbox_params = textbox_params.Replace("%ff", Path.GetFileName(file2)); - } - } - - while (pre_i.Contains("%ff")) - { - if (pre_i.Contains("%ff")) - { - pre_i = pre_i.Replace("%ff", Path.GetFileName(file2)); - } - } - - //%fdur variable operations - - String dur_secs = dur_rpl.ToString(); - String to_replace = String.Empty; - - while (textbox_params.Contains("%fdur")) - { - if (textbox_params.Contains("%fdur")) - { - to_replace = ""; - - int operador = textbox_params.LastIndexOf("%fdur") + 5; - int length = 0; - int limit = textbox_params.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(textbox_params.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace = textbox_params.Substring(textbox_params.LastIndexOf("%fdur"), 5 + length); - Double result = Convert.ToDouble(new DataTable().Compute(to_replace.Replace("%fdur", dur_secs), null)); - textbox_params = ReplaceLastOccurrence(textbox_params, to_replace, Math.Round(result).ToString()); - } - } - - while (pre_i.Contains("%fdur")) - { - - if (pre_i.Contains("%fdur")) - { - to_replace = ""; - - int operador = pre_i.LastIndexOf("%fdur") + 5; - int length = 0; - int limit = pre_i.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(pre_i.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace = pre_i.Substring(pre_i.LastIndexOf("%fdur"), 5 + length); - Double result = Convert.ToDouble(new DataTable().Compute(to_replace.Replace("%fdur", dur_secs), null)); - pre_i = ReplaceLastOccurrence(pre_i, to_replace, Math.Round(result).ToString()); - } - } - - //Bitrate variable - - dur_secs = get_bitrate(file, dur_rpl.ToString()).ToString(); - to_replace = String.Empty; - - while (textbox_params.Contains("%fbitr")) - { - if (textbox_params.Contains("%fbitr")) - { - to_replace = ""; - - int operador = textbox_params.LastIndexOf("%fbitr") + 6; - int length = 0; - int limit = textbox_params.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(textbox_params.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace = textbox_params.Substring(textbox_params.LastIndexOf("%fbitr"), 6 + length); - - Double result = Convert.ToDouble(new DataTable().Compute(to_replace.Replace("%fbitr", dur_secs), null)); - textbox_params = ReplaceLastOccurrence(textbox_params, to_replace, Math.Round(result).ToString() + "K"); - } - } - - while (pre_i.Contains("%fbitr")) - { - if (pre_i.Contains("%fbitr")) - { - to_replace = ""; - - int operador = pre_i.LastIndexOf("%fbitr") + 6; - int length = 0; - int limit = pre_i.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(pre_i.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace = pre_i.Substring(pre_i.LastIndexOf("%fbitr"), 6 + length); - - Double result = Convert.ToDouble(new DataTable().Compute(to_replace.Replace("%fbitr", dur_secs), null)); - pre_i = ReplaceLastOccurrence(pre_i, to_replace, Math.Round(result).ToString() + "K"); - } - } - - //End bitrate variable - String AppParam = String.Empty; - String templog = Path.GetTempPath() + "\\" + "FF_pass2.log"; - - if (preset_run == 1) AppParam = hw_decode + " " + pre_input_var + " " + pre_ss + " -y -i " + "" + '\u0022' + file + '\u0022' + " " + shifting + " " + textbox_params + " -passlogfile " + '\u0022' + templog + '\u0022' + " " + ext_output1; - else AppParam = hw_decode + " " + pre_input_var + " " + pre_ss + " -i " + "" + '\u0022' + file + '\u0022' + " " + shifting + " -y " + textbox_params + " -passlogfile " + '\u0022' + templog + '\u0022' + " " + fade_filter + " " + change_vol_fade + " " + '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file) + add_suffix + add_pr_suffix + ext_output1 + '\u0022'; - - Double row_duration = 0; - - if (target_size == true) - { - Boolean go_ahead = true; - Double target_secs = 0; - DateTime t2; - String file_dur = ""; - listView1.Invoke(new MethodInvoker(delegate - { - file_dur = listView1.Items[list_index].SubItems[3].Text; - })); - - if (DateTime.TryParse(file_dur, out t2)) target_secs = TimeSpan.Parse(file_dur).TotalSeconds; - else - { - Type ts = Type.GetTypeFromProgID("Shell.Application"); - dynamic shell = Activator.CreateInstance(ts); - Folder rFolder = shell.NameSpace(Path.GetDirectoryName(file)); - FolderItem rFiles = rFolder.ParseName(Path.GetFileName(file)); - String dur_q = rFolder.GetDetailsOf(rFiles, 27).Trim(); - try { target_secs = TimeSpan.Parse(dur_q).TotalSeconds; } catch { go_ahead = false; } - } - if (go_ahead == true) - { - Double bitr = target_mb * 8 * 1024 / (target_secs - TimeSpan.Parse(ss_time_input.Text).TotalSeconds); - bitr = Math.Round(bitr * 0.998, 0) - target_aud_bit; - if (bitr < 100) bitr = 100; - String bitrs = bitr.ToString() + "K"; - - String target_params = " -c:v " + target_codec + " -b:v " + bitrs + " -preset " + target_profile + " " + textbox_params + " "; - if (target_one_pass == false) - { - if (preset_run == 1) AppParam = hw_decode + " " + pre_input_var + " " + pre_ss + " -y -i " + "" + '\u0022' + file + '\u0022' + " " + shifting + " " + target_params + " -an -sn -f mp4" + " -passlogfile " + '\u0022' + templog + '\u0022' + " " + ext_output1; - else AppParam = hw_decode + " " + pre_input_var + " " + pre_ss + " -i " + "" + '\u0022' + file + '\u0022' + " " + shifting + " -y " + "-c:a " + target_aud_cod + " -b:a " + target_aud_bit + "K " + target_params + " " + "-passlogfile " + '\u0022' + templog + '\u0022' + " " + fade_filter + " " + change_vol_fade + " " + '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file) + add_suffix + add_pr_suffix + ext_output1 + '\u0022'; - } - else - { - if (preset_run == 1) AppParam = ""; - else - { - AppParam = hw_decode + " " + pre_input_var + " " + pre_ss + " -i " + "" + '\u0022' + file + '\u0022' + " " + shifting + " -y " + "-c:a " + target_aud_cod + " -b:a " + target_aud_bit + "K " + target_params + " " + fade_filter + " " + change_vol_fade + " " + '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file) + add_suffix + add_pr_suffix + ext_output1 + '\u0022'; - AppParam = AppParam.Replace("-pass 2", " "); - } - } - } - else - { - MessageBox.Show(Strings.err_dest); - Enable_Controls(); working = false; - return; - } - } - - var tmp = procs["proc_urls_" + list_index.ToString()]; - - if (!Directory.Exists(destino)) - { - Directory.CreateDirectory(destino); - } - - tmp.StartInfo.FileName = ffm; - tmp.StartInfo.Arguments = AppParam + " -hide_banner"; - - //valid_prog = false; - - if (preset_run == 1) this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.processing); - - tmp.StartInfo.RedirectStandardInput = true; - tmp.StartInfo.RedirectStandardError = true; - tmp.StartInfo.UseShellExecute = false; - tmp.StartInfo.CreateNoWindow = true; - tmp.EnableRaisingEvents = true; - if (target_size == true && target_one_pass == true && preset_run == 1) - { - preset_run = 2; - continue; - } - else tmp.Start(); - - System.Threading.Thread.Sleep(50); - combo_prio.Invoke(new MethodInvoker(delegate - { - if (combo_prio.SelectedIndex != 2) - { - Change_mem_prio(); - } - })); - - if (Settings.Default.quick_queue == false) this.InvokeEx(f => durat_n = TimeSpan.Parse(listView1.Items[list_index].SubItems[3].Text).TotalSeconds - TimeSpan.Parse(ss_time_input.Text).TotalSeconds); - else this.InvokeEx(f => durat_n = row_duration - TimeSpan.Parse(ss_time_input.Text).TotalSeconds); - - //Recalculate total frames for vp9 - - if (fframes == 0) - { - try - { - fframes = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(fade_frames) * durat_n)); - } - catch { } - - this.Invoke(new MethodInvoker(delegate - { - pg_lv_vp9.Minimum = 0; - pg_lv_vp9.Maximum = fframes; - })); - } - //End recalculate total frames for vp9 - - this.InvokeEx(f => validate_duration = listView1.Items[list_index].SubItems[3].Text); - if (validate_duration != Strings.n_a && validate_duration != "0:00:00" && validate_duration != "00:00:00" && validate_duration != Strings.pending) - { - valid_prog = true; - } - - String err_txt = ""; - Double interval = 0; - Decimal est_bitrate = 0; - Decimal est_size = 0; - Double sec_prog = 0; - lbl_speed.Invoke(new MethodInvoker(delegate - { - lbl_speed.Text = String.Empty; - lbl_multip.Enabled = true; - lbl_multip.Visible = true; - })); - - if (preset_run == 1) this.InvokeEx(f => f.lbl_multip.Text = Strings.pass1); - if (preset_run == 2) - { - this.InvokeEx(f => f.lbl_multip.Text = Strings.pass2); - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = "50%"); - } - try - { - while (!tmp.StandardError.EndOfStream) - { - err_txt = tmp.StandardError.ReadLine(); - list_lines.Add(err_txt); - if (is_vp9 == false) - { - if (err_txt.Contains("time=") && err_txt.Contains("time=-") == false) - { - if (valid_prog == true && !err_txt.Contains("N/A")) - { - this.InvokeEx(f => durat_n = TimeSpan.Parse(listView1.Items[list_index].SubItems[3].Text).TotalSeconds - TimeSpan.Parse(ss_time_input.Text).TotalSeconds); - durat_n = durat_n * 2; - int start_time_index = err_txt.IndexOf("time=") + 5; - sec_prog = TimeSpan.Parse(err_txt.Substring(start_time_index, 8)).TotalSeconds; - - Double percent = (sec_prog * 100 / durat_n); - - total_prog = total_prog + (sec_prog - interval); - interval = sec_prog; - int percent2 = Convert.ToInt32(percent); - - Double percent_tot = (total_prog * 100 / total_duration); - if (target_size == true && target_one_pass == true) percent_tot = percent_tot * 2; - int percent_tot_2 = Convert.ToInt32(percent_tot); - - this.Invoke(new MethodInvoker(delegate - { - if (percent_tot_2 <= 100) - { - Pg1.Value = percent_tot_2; - Pg1.Refresh(); - - if (Math.Round(percent_tot, 1).ToString().Contains(".") || Math.Round(percent_tot, 1).ToString().Contains(",")) - { - Pg1.Text = Math.Round(percent_tot, 1).ToString() + "%"; - } - else - { - Pg1.Text = Math.Round(percent_tot, 1).ToString() + ".0" + "%"; - } - - TaskbarProgress.SetValue(this.Handle, percent_tot, Pg1.Maximum); - } - - if (percent2 <= 100) - { - if (preset_run == 2) - { - if (percent2 <= 50) - { - if (Math.Round(percent, 1).ToString().Contains(".") || Math.Round(percent, 1).ToString().Contains(",")) - { - listView1.Items[list_index].SubItems[5].Text = Math.Round(percent + 50, 1).ToString() + "%"; - } - else - { - listView1.Items[list_index].SubItems[5].Text = Math.Round(percent + 50, 1).ToString() + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0" + "%"; - } - } - else - { - if (Math.Round(percent, 1).ToString().Contains(".") || Math.Round(percent, 1).ToString().Contains(",")) - { - listView1.Items[list_index].SubItems[5].Text = "100%"; - } - else - { - listView1.Items[list_index].SubItems[5].Text = "100%"; - } - } - } - else - { - if (Math.Round(percent, 1).ToString().Contains(".") || Math.Round(percent, 1).ToString().Contains(",")) - { - listView1.Items[list_index].SubItems[5].Text = Math.Round(percent, 1).ToString() + "%"; - } - else - { - listView1.Items[list_index].SubItems[5].Text = Math.Round(percent, 1).ToString() + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0" + "%"; - } - } - - if (preset_run == 2) - { - if (Math.Round(percent, 1).ToString().Contains(".") || Math.Round(percent, 1).ToString().Contains(",")) - { - listView1.Items[list_index].SubItems[5].Text = Math.Round(percent + 50, 1).ToString() + "%"; - } - else - { - listView1.Items[list_index].SubItems[5].Text = Math.Round(percent + 50, 1).ToString() + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0" + "%"; - } - } - else - { - if (Math.Round(percent, 1).ToString().Contains(".") || Math.Round(percent, 1).ToString().Contains(",")) - { - listView1.Items[list_index].SubItems[5].Text = Math.Round(percent, 1).ToString() + "%"; - } - else - { - listView1.Items[list_index].SubItems[5].Text = Math.Round(percent, 1).ToString() + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0" + "%"; - } - } - } - })); - - if (cancel_queue == false) - { - //Estimated remaining time - - remain_time = err_txt.Substring(err_txt.LastIndexOf("speed=") + 6, err_txt.Length - err_txt.LastIndexOf("speed=") - 6); - if (time_est_size % 3 == 0) this.InvokeEx(f => f.lbl_speed.Text = Strings.speed + " " + remain_time); - remain_time = remain_time.Replace("x", String.Empty); - Double timing1 = 0; - - if (CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",") - { - timing1 = Math.Round(Double.Parse(remain_time.Replace(".", ",")), 2); - } - else - { - timing1 = Math.Round(Double.Parse(remain_time), 2); - } - - Decimal timing = (decimal)timing1; - Decimal total_dur_dec = Convert.ToDecimal(total_duration); - Decimal total_prog_dec = Convert.ToDecimal(total_prog); - Decimal remain_secs = 0; - - - if (timing > 0) - { - remain_secs = (decimal)(total_dur_dec - total_prog_dec) / timing; - } - - if (remain_secs > 60) - { - remain_secs = remain_secs + 60; - } - if (target_size == true && target_one_pass == true) remain_secs = remain_secs / 2; - - String remain_from_secs = String.Empty; - - TimeSpan t = TimeSpan.FromSeconds(Convert.ToDouble(remain_secs)); - remain_from_secs = string.Format("{0:D2}h:{1:D2}", t.Hours, t.Minutes); - - this.Invoke(new MethodInvoker(delegate - { - - if (remain_secs >= 43200) txt_remain.Text = Strings.remain_time + " " + Math.Round(remain_secs / 3600).ToString() + " " + Strings.hours; - if (remain_secs >= 3600 && remain_secs < 43200) txt_remain.Text = Strings.remain_time + " " + remain_from_secs + " " + Strings.minutes_abrev; - if (remain_secs < 3600 && remain_secs >= 600) txt_remain.Text = Strings.remain_time + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 1, 2) + " " + Strings.minutes; - if (remain_secs < 600 && remain_secs >= 120) txt_remain.Text = Strings.remain_time + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 2, 1) + " " + Strings.minutes; - if (remain_secs <= 59 && remain_secs != 0) txt_remain.Text = Strings.remain_time + " " + Convert.ToInt16(remain_secs) + " " + Strings.seconds; - if (remain_secs <= 0) txt_remain.Text = Strings.remain_time + " " + Strings.about_finish; - - })); - } - - //End remaining time - - if (preset_run == 2) - { - //Estimated size and bitrate - - String read_size = String.Empty; - if (err_txt.Contains("size=") && (time_est_size % 3 == 0)) - { - int size_index = err_txt.IndexOf("size=") + 5; - read_size = err_txt.Substring(size_index, 8); - if (Convert.ToDecimal(sec_prog) != 0) - { - est_bitrate = (Math.Round(Convert.ToDecimal(read_size) * 8 / Convert.ToDecimal(sec_prog), 0)) / 2; - } - else - { - est_bitrate = 0; - } - - if (Convert.ToDecimal(read_size) > 1 && time_n_tasks > 1) - { - if (est_bitrate < 9999) - { - if (est_bitrate > 48) - { - this.InvokeEx(f => f.lbl_bitrate.Text = Strings.avg_bit + ": " + est_bitrate + " " + "Kb/s"); - } - else - { - this.InvokeEx(f => f.lbl_bitrate.Text = Strings.avg_bit + ": "); - } - } - else - { - this.InvokeEx(f => f.lbl_bitrate.Text = Strings.avg_bit + ": " + (Math.Round(est_bitrate / 1000, 0)) + " " + "Mb/s"); - } - //Estimated size - est_size = Convert.ToDecimal(durat_n) * est_bitrate / 8; - - if (est_size > 1000000) - { - this.InvokeEx(f => f.lbl_est_size.Text = Strings.est_size + " " + (Math.Round(est_size / 1000000, 1)).ToString() + " " + "GB"); - } - else - { - if (Math.Round(est_size / 1000, 0) > 0) - { - this.InvokeEx(f => f.lbl_est_size.Text = Strings.est_size + " " + (Math.Round(est_size / 1000, 0)).ToString() + " " + "MB"); - } - else - { - this.InvokeEx(f => f.lbl_est_size.Text = Strings.est_size + " "); - } - } - } - - this.InvokeEx(f => f.lbl_est_size.Refresh()); - } - } - } - } - } - else - { - //Progress bar vp9 - - if (err_txt.ToLower().Contains("frame=")) - { - try - { - int start_fps_index = err_txt.IndexOf("frame="); - int try_ff = 0; - - if (int.TryParse(err_txt.Substring(start_fps_index + 6, 5), out try_ff) && fframes != 0 && fframes <= pg_lv_vp9.Maximum) - { - if (try_ff <= pg_lv_vp9.Maximum) - { - this.Invoke(new MethodInvoker(delegate - { - pg_lv_vp9.Value = try_ff; - pg_lv_vp9.Text = (try_ff * 100 / fframes).ToString() + "%"; - pg_lv_vp9.Refresh(); - listView1.Items[list_index].SubItems[5].Text = (try_ff * 100 / fframes / 2).ToString() + "%"; - })); - } - } - else - { - this.InvokeEx(f => pg_lv_vp9.Value = 0); - } - } - catch { } - //End Progress bar - } - } - } - } - catch { } - - tmp.WaitForExit(); - tmp.StartInfo.Arguments = String.Empty; - timer_est_size.Stop(); - time_est_size = 0; - this.Invoke(new MethodInvoker(delegate - { - pg_lv_vp9.Dispose(); - lbl_speed.Text = String.Empty; - lbl_est_size.Text = String.Empty; - lbl_bitrate.Text = String.Empty; - if (preset_run == 2) listView1.Items[list_index].SubItems[5].Text = "50%"; - - })); - - list_lines.Add(""); - list_lines.Add("---------------------End of " + Path.GetFileName(file) + " log-------------------------------"); - list_lines.Add(""); - - if (preset_run == 2) - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = "100%"); - //this.InvokeEx(f => pg_lv.Visible = false); - if (tmp.ExitCode == 0) - { - if (skipped == false) - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.success); - //this.InvokeEx(f => f.listView1.Items[list_index].BackColor = listView1.BackColor); - } - else - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.skipped); - total_prog = (total_prog + durat_n - sec_prog) / n_multi_presets; - skipped = false; - } - } - else - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.error); - this.InvokeEx(f => f.listView1.Items[list_index].BackColor = Color.PaleGoldenrod); - total_prog = total_prog + durat_n - sec_prog; - } - preset_run = 1; - list_index = list_index + 1; - } - else - { - if (tmp.ExitCode != 0) - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.error); - this.InvokeEx(f => f.listView1.Items[list_index].BackColor = Color.PaleGoldenrod); - total_prog = total_prog + durat_n - sec_prog; - list_index = list_index + 1; - preset_run = 1; - } - if (tmp.ExitCode == 0) - { - if (skipped == false) - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = "50%"); - preset_run = 2; - } - else - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.skipped); - total_prog = (total_prog + durat_n - sec_prog) / n_multi_presets; - skipped = false; - list_index = list_index + 1; - preset_run = 1; - } - } - } - - if (list_index == listView1.Items.Count) - { - runnin_n_presets = false; - this.Invoke(new MethodInvoker(delegate - { - lbl_multip.Visible = false; - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - Pg1.Value = Pg1.Maximum; - Pg1.Text = "100%"; - Pg1.Refresh(); - })); - - working = false; - timer_est_size.Stop(); - time_est_size = 0; - - if (no_save_logs == false) - { - //Save log - string[] array_err = list_lines.ToArray(); - String path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.log"; - if (is_portable == true) path = port_path + "ff_batch_portable.log"; - - StreamWriter SaveFile = new StreamWriter(path); - SaveFile.WriteLine("FFmpeg log sesion: " + System.DateTime.Now); - SaveFile.WriteLine("-------------------------------"); - foreach (String item in array_err) - { - SaveFile.WriteLine(item); - } - SaveFile.Close(); - - File.AppendAllText(path, "-----------------------"); - File.AppendAllText(path, Environment.NewLine + Strings.end_log + Environment.NewLine); - File.AppendAllText(path, "-----------------------"); - FileInfo fileInfo = new FileInfo(path); - - var bytes = fileInfo.Length; - - var kilobytes = (double)bytes / 1024; - var megabytes = kilobytes / 1024; - var gigabytes = megabytes / 1024; - - //Format size view - String size = ""; - String separator = "."; - - if (bytes > 1000000000) - { - if (gigabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String gigas = gigabytes.ToString(); - if (gigas.Length >= 5) - { - gigas = gigas.Substring(0, gigas.LastIndexOf(separator) + 3); - size = (gigas + " " + "GB"); - } - else - { - size = (gigas + " " + "GB"); - } - } - - if (bytes >= 1048576 && bytes <= 1000000000) - { - if (megabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - String megas = megabytes.ToString(); - if (megas.Length > 5) - { - megas = megas.Substring(0, megas.LastIndexOf(separator)); - size = (megas + " " + "MB"); - } - else - { - size = (megas + " " + "MB"); - } - } - - if (bytes >= 1024 && bytes < 1048576) - - { - if (kilobytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String kbs = kilobytes.ToString(); - if (kbs.Length >= 5) - { - kbs = kbs.Substring(0, kbs.LastIndexOf(separator)); - size = (kbs + " " + "KB"); - } - else - { - size = (kbs + " " + "KB"); - } - } - if (bytes > -1 && bytes < 1024) - { - String bits = bytes.ToString(); - size = (bits + " Bytes"); - } - - //End Format size view - timer_tasks.Stop(); - TimeSpan t = TimeSpan.FromSeconds(time_n_tasks); - String tx_elapsed = string.Format("{0:D2}h:{1:D2}m:{2:D2}s", - t.Hours, - t.Minutes, - t.Seconds); - File.AppendAllText(path, Environment.NewLine); - File.AppendAllText(path, Environment.NewLine + Strings.total_time + " " + tx_elapsed); - File.AppendAllText(path, Environment.NewLine + Strings.log_size + " " + size); - //End save log - } - - //Automatic shutdown check - - if (chkshut.Checked && cancel_queue == false) - { - auto_shut(); - return; - } - //End shutdown check - else - { - if (cancel_queue == false) - { - if (chk_delete_source.CheckState == CheckState.Checked) - { - Disable_Controls(); - System.Threading.Thread.Sleep(500); - list_proc.Items.Clear(); - listView1.Invoke(new MethodInvoker(delegate - { - foreach (ListViewItem item in listView1.Items) - { - list_proc.Items.Add((ListViewItem)item.Clone()); - } - })); - - Label prog_txt = new Label(); - ProgressBar pg_del = new ProgressBar(); - - this.Invoke(new MethodInvoker(delegate - { - - prog_txt.Parent = panel1; - prog_txt.Top = 95; - prog_txt.Left = 80; - prog_txt.Width = 250; - prog_txt.TabIndex = 1; - prog_txt.BackColor = panel1.BackColor; - prog_txt.BorderStyle = BorderStyle.None; - prog_txt.TextAlign = ContentAlignment.MiddleLeft; - prog_txt.BringToFront(); - prog_txt.Text = Strings.to_recycle; - pg_del.Parent = panel1; - pg_del.Top = 98; - pg_del.Left = 315; - pg_del.Width = 302; - pg_del.Height = 15; - pg_del.TabIndex = 0; - pg_del.BackColor = this.BackColor; - pg_del.Minimum = 0; - pg_del.BringToFront(); - pg_del.Maximum = list_proc.Items.Count; - pg_del.Show(); - pg_del.Refresh(); - - })); - - - int i = 0; - int err = 0; - - foreach (ListViewItem item in list_proc.Items) - { - if (item.SubItems[5].Text == Strings.success) - { - try - { - FileSystem.DeleteFile(item.SubItems[1].Text + "\\" + item.Text, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); - this.InvokeEx(f => pg_del.Value = i); - i = i + 1; - } - catch - { - err = err + 1; - } - - this.InvokeEx(f => prog_txt.Text = Strings.to_recycle + i.ToString() + " " + Strings.of1 + " " + list_proc.Items.Count); - this.InvokeEx(f => prog_txt.Refresh()); - } - } - this.Invoke(new MethodInvoker(delegate - { - prog_txt.Visible = false; - prog_txt.Dispose(); - pg_del.Visible = false; - pg_del.Dispose(); - })); - - Enable_Controls(); - - if (err > 0) MessageBox.Show(err.ToString() + " " + Strings.not_recycled2, Strings.not_recycled3, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - - Boolean all_ok = true; - foreach (ListViewItem item in list_proc.Items) - { - if (item.SubItems[5].Text != Strings.success) - { - all_ok = false; - break; - } - } - if (all_ok == true) - { - this.InvokeEx(f => f.btn_refresh.PerformClick()); - } - } - - if (play_on_end == true) play_end(); - if (Form.ActiveForm == null) - { - notifyIcon1.BalloonTipText = Strings.enc_comp; - notifyIcon1.BalloonTipIcon = ToolTipIcon.Info; - notifyIcon1.BalloonTipTitle = Strings.enc_comp2; - notifyIcon1.ShowBalloonTip(0); - } - - if (chk_open_compl.Checked) - { - if (Directory.GetFiles(destino).Length != 0) - { - Process open_processed = new Process(); - open_processed.StartInfo.FileName = "explorer.exe"; - open_processed.StartInfo.Arguments = '\u0022' + destino + '\u0022'; - open_processed.Start(); - } - else - { - if (Directory.Exists(destino)) - { - Directory.Delete(destino); - } - } - } - } - else - { - this.InvokeEx(f => f.Pg1.Text = "100%"); - this.InvokeEx(f => MessageBox.Show(Strings.queue_abort, Strings.aborted, MessageBoxButtons.OK, MessageBoxIcon.Error)); - } - } - } - } - - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - Enable_Controls(); - }).Start(); - } - private void check_res() - { - SystemEvents.DisplaySettingsChanged += new EventHandler(SystemEvents_DisplaySettingsChanged); - - foreach (Control ct1 in this.Controls) - { - points.Add(ct1.Name, new Point(ct1.Left, ct1.Top)); - } - foreach (Control ct1 in this.Controls) - { - sizes.Add(ct1.Name, new Size(ct1.Width, ct1.Height)); - } - - Rectangle resolution = Screen.PrimaryScreen.Bounds; - if (resolution.Width > 1366 && resolution.Height > 768) - { - big_res = true; - this.Width = this.Width + 30; - foreach (Control ct in this.Controls) - { - ct.Left = ct.Left + 15; - } - this.Height = this.Height + 25; - foreach (Control ct in this.Controls) - { - ct.Top = ct.Top + 6; - } - - group_prog.Height = group_prog.Height + 6; - - foreach (Control ct in group_prog.Controls) - { - ct.Top = ct.Top + 3; - } - pic_title.Top = pic_title.Top - 9; - btn_change_ff.Top = btn_change_ff.Top - 9; - btn_clear_list.Left = btn_clear_list.Left - 2; - btn_add_files.Left = btn_add_files.Left - 2; - tabControl1.Left = tabControl1.Left + 2; - tabControl1.Width = tabControl1.Width - 2; - } - else - { - big_res = false; - } - } - - private void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e) - { - resize(); - } - - private void check_back_updates() - { - new System.Threading.Thread(() => - { - System.Threading.Thread.CurrentThread.IsBackground = true; - Thread.Sleep(500); - String current_ver = btn_update.Text; - - String content2 = String.Empty; - try - { - WebClient client = new WebClientWithTimeout(); - Stream stream = client.OpenRead(down_ver); - StreamReader reader = new StreamReader(stream); - String content = reader.ReadToEnd(); - content2 = content; - } - catch - { - try - { - //Backup server - WebClient client = new WebClientWithTimeout(); - Stream stream = client.OpenRead(down_ver2); - StreamReader reader = new StreamReader(stream); - String content = reader.ReadToEnd(); - content2 = content; - } - catch - { - this.Invoke(new MethodInvoker(delegate - { - lbl_updates.Text = Strings.up_err; - lbl_updates.Cursor = Cursors.Hand; - btn_update.Text = current_ver; - })); - return; - } - } - - try - { - if (Convert.ToInt16(content2.Replace(".", String.Empty).Substring(0, 3)) > Convert.ToInt16(Application.ProductVersion.Replace(".", String.Empty))) - { - this.InvokeEx(f => f.lbl_updates.Text = Strings.version + " " + content2.Substring(0, 5) + " " + Strings.available); - this.InvokeEx(f => f.lbl_updates.Cursor = Cursors.Hand); - String f_skip_ver = String.Empty; - if (is_portable == false) - { - f_skip_ver = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_skip_ver.ini"; - } - else - { - f_skip_ver = port_path + "ff_skip_ver_portable.ini"; - } - if (File.Exists(f_skip_ver)) - { - String skipped_ver = File.ReadAllText(f_skip_ver); - if (skipped_ver == content2.Substring(0, 5)) return; - } - this.InvokeEx(f => this.Enabled = false); - Form21 frm21 = new Form21(); - frm21.lbl_ver.Text = Strings.version + " " + content2.Substring(0, 5); - frm21.textBox1.Text = content2.Substring(6, content2.Length - 6); - this.Invoke(new MethodInvoker(delegate - { - this.Enabled = true; - this.TopMost = true; - this.TopMost = false; - frm21.ShowDialog(this); - })); - - if (frm21.cancel == false && frm21.update == true && frm21.skip_ver == false) - { - try - { - File.Delete(f_skip_ver); - } - catch { } - - Process.Start("https://sourceforge.net/p/ffmpeg-batch/wiki"); - } - if (frm21.cancel == false && frm21.update == false && frm21.skip_ver == true) - { - try - { - File.WriteAllText(f_skip_ver, content2.Substring(0, 5)); - } - catch (Exception excpt) - { - MessageBox.Show(Strings.skip_err + Environment.NewLine + Environment.NewLine + excpt.Message, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - } - catch (Exception excpt) - { - MessageBox.Show(Strings.err_check + Environment.NewLine + Environment.NewLine + excpt.Message, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - - this.InvokeEx(f => f.btn_update.Text = current_ver); - }).Start(); - } - - private void check_internet() - { - internet_up = true; - - System.Threading.Thread.CurrentThread.IsBackground = true; - String current_ver = btn_update.Text; - - String content2 = String.Empty; - try - { - WebClient client = new WebClientWithTimeout(); - Stream stream = client.OpenRead("http://google.com/generate_204"); - StreamReader reader = new StreamReader(stream); - String content = reader.ReadToEnd(); - content2 = content; - } - catch - { - try - { - //Backup server - WebClient client = new WebClientWithTimeout(); - Stream stream = client.OpenRead("http://www.baidu.com/baidu.html?from=noscript"); - StreamReader reader = new StreamReader(stream); - String content = reader.ReadToEnd(); - content2 = content; - } - catch - { - DialogResult a = MessageBox.Show(Strings.err_connect, Strings.err_con2, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); - if (a == DialogResult.OK) internet_up = true; - else internet_up = false; - } - } - } - - private void abort_view1() - { - Pg1.Focus(); - - timer_queue.Enabled = false; - - if (is_portable == false) this.Text = "FFmpeg Batch AV Converter"; - else this.Text = "FFmpeg Batch AV Converter Portable"; - if (recording_scr == true) - { - working = false; - recording_scr = false; - StreamWriter write_q = process_rec.StandardInput; - write_q.Write("q"); - this.InvokeEx(f => f.pic_recording.Visible = false); - Enable_Controls(); - return; - } - if (working == false) - { - int num = 0; - Process[] localByName = Process.GetProcessesByName("ffmpeg"); - num = localByName.Length; - if (num > 0 && localByName[0].Id == ff_ver_proc) return; - - if (num > 0) - { - DialogResult a = MessageBox.Show(Strings.ff_running, Strings.ff_run2, MessageBoxButtons.YesNo, MessageBoxIcon.Warning); - if (a == DialogResult.Yes) - { - foreach (Process p in localByName) - { - try - { - p.Kill(); - } - catch - { - MessageBox.Show(Strings.err_close_procs + "ID" + " " + p.Id, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - } - cancelados_paralelos = true; - return; - } - - working = false; - aborted = true; - cancel_queue = true; - cancelados_paralelos = true; - btn_abort_all.Enabled = false; - lbl_multip.Visible = false; - runnin_n_presets = false; - - if (multi_running == true) - { - timer_aborting.Start(); - multi_running = false; - - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[5].Text != Strings.success && item.SubItems[5].Text != Strings.ready && item.SubItems[5].Text != Strings.queued && item.SubItems[5].Text != Strings.replaced && item.SubItems[5].Text != Strings.renamed && item.SubItems[5].Text != Strings.deleted && item.SubItems[5].Text != Strings.not_renamed && item.SubItems[5].Text != Strings.recycled && item.SubItems[5].Text != Strings.not_recycled && item.SubItems[5].Text != Strings.not_deleted) - { - item.SubItems[5].Text = Strings.aborting; - } - } - - foreach (Process proc in procs.Values) - { - if (proc.StartInfo.Arguments != String.Empty) - { - try - { - StreamWriter write_q = proc.StandardInput; - write_q.Write("q"); - } - catch { } - } - } - return; - } - - foreach (Process proc in procs.Values) - { - if (proc.StartInfo.Arguments != String.Empty) - { - try - { - StreamWriter write_q = proc.StandardInput; - write_q.Write("q"); - return; - } - catch { } - } - } - Boolean cleaned = true; - - foreach (Process proc in ProcessExtensions.GetChildProcesses(Process.GetCurrentProcess())) - { - try - { - proc.Kill(); - } - catch - { - try - { - Thread.Sleep(10); - proc.Kill(); - } - catch { cleaned = false; } - } - } - } - - private void init_lang() - { - Thread.CurrentThread.CurrentUICulture = new CultureInfo(Settings.Default.app_lang); - Thread.CurrentThread.CurrentCulture = new CultureInfo(Settings.Default.app_lang); - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); - RefreshResources(this, resources); - post_lang(); - combo_prio_add(); - btn_update.Text = Strings.version + " " + Application.ProductVersion; - load_priority(); - remember_tab(); - resize(); - } - - private void get_frame() - { - //Attempt to extract frame as image - try - { - - DateTime time2; - Double seconds = 0; - if (tabControl1.SelectedIndex == 0) - { - if (!DateTime.TryParse(listView1.SelectedItems[0].SubItems[3].Text, out time2)) current_fr = 0; - } - if (tabControl1.SelectedIndex == 1) - { - if (!DateTime.TryParse(listView1.Items[listView2.SelectedItems[0].Index].SubItems[3].Text, out time2)) current_fr = 0; - } - - String file_img = ""; - if (tabControl1.SelectedIndex == 0) file_img = Path.GetFullPath(listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text); - if (tabControl1.SelectedIndex == 1) file_img = Path.GetFullPath(listView2.SelectedItems[0].Text); - - String time_frame = ""; - Double t_to = (double)current_fr; - - TimeSpan t1 = TimeSpan.FromMilliseconds((t_to)); - String tx_1 = string.Format("{0:D2}:{1:D2}:{2:D2}.{3:D3}", - (int)t1.TotalHours, - t1.Minutes, - t1.Seconds, - t1.Milliseconds); - time_frame = tx_1; - - Task t = Task.Run(() => - { - - Process proc_img = new System.Diagnostics.Process(); - String ffm_img = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - String fullPath_img = file_img; - String AppParam_img = ""; - String destino = Path.Combine(Path.GetTempPath(), "FFBatch_test"); - - String rel_path = Path.GetDirectoryName(file_img).Replace(":", "_").Replace("\\", "_") + Path.GetExtension(file_img).Replace(".", "_"); - String target_img = Path.GetTempPath() + "FFBatch_Test" + "\\" + Path.GetFileNameWithoutExtension(file_img) + "_480_" + rel_path + "_" + (current_fr / 1000) + "." + "jpg"; - - if (File.Exists(target_img)) - { - Image img_tmp; - using (var bmpTemp = new Bitmap(target_img)) - { - img_tmp = new Bitmap(bmpTemp); - pic_frame.Invoke(new MethodInvoker(delegate - { - pic_frame.Image = img_tmp; - })); - return; - } - } - - AppParam_img = " -ss " + tx_1 + " -skip_frame nokey" + " -i " + "" + '\u0022' + file_img + '\u0022' + " -vsync 0 -frames:v 1 " + " -vf scale=480:-1" + " -q:v 6 " + "-f image2 -y " + '\u0022' + target_img + '\u0022'; - - proc_img.StartInfo.RedirectStandardOutput = false; - proc_img.StartInfo.RedirectStandardError = false; - proc_img.StartInfo.UseShellExecute = true; - proc_img.StartInfo.CreateNoWindow = false; - proc_img.EnableRaisingEvents = false; - proc_img.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - - proc_img.StartInfo.FileName = ffm_img; - proc_img.StartInfo.Arguments = AppParam_img; - - proc_img.Start(); - proc_img.WaitForExit(2000); - - - Image img_tmp1; - try - { - using (var bmpTemp = new Bitmap(target_img)) - { - img_tmp1 = new Bitmap(bmpTemp); - pic_frame.Invoke(new MethodInvoker(delegate - { - pic_frame.Image = img_tmp1; - - })); - } - } - catch { } - }); - - } - catch { } - - } - private void main_progress_bar() - { - Pg1.Parent = group_prog; - Pg1.Value = 0; - Pg1.Top = group_prog.Height / 2 - 8; - Pg1.Left = 261; - Pg1.Width = 735; - Pg1.Height = 21; - Pg1.Value = 0; - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - Pg1.Show(); - } - - private void Form1_Load(object sender, EventArgs e) - { - Task t2 = Task.Run(() => - { - get_ffmpeg_v(); - get_ff_ver(); - }); - - combo_vin_col.SelectedIndex = 0; - combo_vout_color.SelectedIndex = 0; - combo_ext_m3u.SelectedIndex = 0; - chk_subfolders.FlatAppearance.CheckedBackColor = Color.FromArgb(255, 225, 235, 251); - combo_ext.SelectedIndex = 0; - Combo_def_sub_mux.SelectedIndex = 0; - Combo_ext_sub_mux.SelectedIndex = 0; - notifyIcon1.Visible = false; - listView1.LabelWrap = true; - combo_vin_col.SelectedIndex = 0; - combo_vout_color.SelectedIndex = 0; - combo_shut.SelectedIndex = 0; - - //Warn successful items - - String f_warn_suc = String.Empty; - if (is_portable == false) - { - f_warn_suc = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_warn_suc.ini"; - } - else - { - f_warn_suc = port_path + "ff_warn_suc_portable.ini"; - } - - warn_success_items = !File.Exists(f_warn_suc); - //End warn sucessful items - - //Warn 0 - - String f_warn_0 = String.Empty; - if (is_portable == false) - { - f_warn_0 = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_warn_0.ini"; - } - else - { - f_warn_0 = port_path + "ff_warn_0_portable.ini"; - } - - no_warn_0_dur = File.Exists(f_warn_0); - //End warn 0 - - //Startup delay - - String f_delay = String.Empty; - if (is_portable == false) - { - f_delay = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_delay.ini"; - } - else - { - f_delay = port_path + "ff_delay_portable.ini"; - } - - if (File.Exists(f_delay)) - { - int i = Convert.ToInt32(File.ReadAllText(f_delay)); - Thread.Sleep(i * 1000); - } - //End startup delay - - pic_pause.Image = btn_pause.Image; - listView1.OwnerDraw = true; - listView3.OwnerDraw = true; - - typeof(DataGridView).InvokeMember( - "DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, - null, listView1, new object[] { true }); - typeof(DataGridView).InvokeMember( - "DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, - null, listView3, new object[] { true }); - - if (!Directory.Exists(Path.Combine(Path.GetTempPath(), "FFBatch_test"))) - { - try - { - Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "FFBatch_test")); - watch_other_instance.Path = Path.Combine(Path.GetTempPath(), "FFBatch_test"); - } - catch (Exception excpt) - { - watch_other_instance.Path = String.Empty; - MessageBox.Show(Strings.err_write_temp + Environment.NewLine + Environment.NewLine + excpt.Message); - } - } - else - { - watch_other_instance.Path = Path.Combine(Path.GetTempPath(), "FFBatch_test"); - } - - this.MainMenuStrip = main_menu; - this.Cursor = Cursors.WaitCursor; - - read_main_config(); - - //Autorun setting - - String f_autorun = String.Empty; - String f_multi = String.Empty; - if (is_portable == false) - { - f_autorun = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_autorun.ini"; - f_multi = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_autorun_m.ini"; - } - else - { - f_autorun = port_path + "ff_autorun_portable.ini"; - f_multi = port_path + "ff_autorun_m_portable.ini"; - } - if (File.Exists(f_autorun)) - { - start_seq = true; - chk_autor.ImageIndex = 1; - if (File.Exists(f_multi)) start_multi = true; - else start_multi = false; - } - else - { - chk_autor.ImageIndex = 0; - start_seq = false; - start_multi = false; - } - - //End autorun - - read_config_files(); - - this.Cursor = Cursors.Arrow; - //Select language - - String f_lang = String.Empty; - if (is_portable == false) - { - f_lang = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_lang.ini"; - } - else - { - f_lang = port_path + "ff_lang_portable.ini"; - } - - if (File.Exists(f_lang)) - { - language = File.ReadAllText(f_lang); - Settings.Default.app_lang = language; - Settings.Default.Save(); - String cultur = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName; - if (language == "en") - { - if (cultur == "es" || cultur == "ar" || cultur == "pt" || cultur == "it" || cultur == "zh") - { - init_lang(); - post_lang(); - } - } - else - { - if (language == "es") - { - if (cultur != "es") init_lang(); - } - - else if (language == "it") - { - if (cultur != "it") init_lang(); - } - - else if (language == "pt-BR") - { - if (cultur != "pt") init_lang(); - } - - else if (language == "zh-Hans") - { - if (cultur != "zh") init_lang(); - } - else if (language == "ar-EG") - { - if (cultur != "ar") init_lang(); - } - - post_lang(); - combo_prio_add(); - btn_update.Text = Strings.version + " " + Application.ProductVersion; - load_priority(); - remember_tab(); - resize(); - } - } - else - { - Thread.Sleep(100); - for (int i = Application.OpenForms.Count - 1; i >= 0; i--) - { - if (Application.OpenForms[i].Name == "Form6") - { - this.InvokeEx(f => Application.OpenForms[i].Close()); - break; - } - } - - Form24 frm24 = new Form24(); - frm24.ShowDialog(); - - switch (frm24.combo_lang.SelectedIndex) - { - case 0: - language = "en"; - break; - case 1: - language = "es"; - break; - case 2: - language = "it"; - break; - case 3: - language = "pt-BR"; - break; - case 4: - language = "zh-Hans"; - break; - case 5: - language = "ar-EG"; - break; - default: - language = "en"; - break; - } - - File.WriteAllText(f_lang, language); - Settings.Default.app_lang = language; - Settings.Default.Save(); - init_lang(); - btn_update.Text = Strings.version + " " + Application.ProductVersion; - } - //End select language - load_priority(); - - n_threads.Maximum = Environment.ProcessorCount; - n_downs.Maximum = n_threads.Maximum; - - if (Settings.Default.dark_os == false) - { - if (Settings.Default.dark_mode == true) - { - foreach (Control c in this.Controls) UpdateColorDark(c); - post_dark(); - } - else if (Settings.Default.dark_mode == false && Settings.Default.auto_dark == true) - { - String t_sunset0 = Settings.Default.dark_sunset.ToShortTimeString(); - String t_sunset1 = t_sunset0.Substring(0, t_sunset0.IndexOf(":")); - String t_sunset2 = t_sunset0.Substring(t_sunset0.IndexOf(":") + 1, t_sunset0.Length - t_sunset0.IndexOf(":") - 1); - TimeSpan sunset_t = new TimeSpan(Convert.ToInt32(t_sunset1), Convert.ToInt32(t_sunset2), 0); - DateTime sunset0 = DateTime.Now.Date + sunset_t; - - String t_sunrise0 = Settings.Default.dark_sunrise.ToShortTimeString(); - String t_sunrise1 = t_sunrise0.Substring(0, t_sunrise0.IndexOf(":")); - String t_sunrise2 = t_sunrise0.Substring(t_sunrise0.IndexOf(":") + 1, t_sunrise0.Length - t_sunrise0.IndexOf(":") - 1); - TimeSpan sunrise_t = new TimeSpan(Convert.ToInt32(t_sunrise1), Convert.ToInt32(t_sunrise2), 0); - DateTime sunrise0 = DateTime.Now.Date + sunrise_t; - - TimeSpan r_sunset = DateTime.Now - sunset0; - TimeSpan r_sunrise = DateTime.Now - sunrise0; - - if (r_sunset.TotalSeconds > 0 && r_sunrise.TotalSeconds < 0) - { - foreach (Control c in this.Controls) UpdateColorDark(c); - post_dark(); - Settings.Default.dark_mode = true; - } - } - } - - if (Settings.Default.dark_os == true) - { - if (IsNightLightEnabled() == true) - { - foreach (Control c in this.Controls) UpdateColorDark(c); - post_dark(); - Settings.Default.dark_mode = true; - } - else Settings.Default.dark_mode = false; - } - } - - private void combo_prio_add() - { - combo_prio.Items.Clear(); - combo_prio.Items.Add(Strings.High); - combo_prio.Items.Add(Strings.Above_normal); - combo_prio.Items.Add(Strings.Normal); - combo_prio.Items.Add(Strings.Below_normal); - combo_prio.Items.Add(Strings.Idle); - combo_presets.Text = Strings.default_param; - } - private static bool IsNightLightEnabled() - { - const string BlueLightReductionStateKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\CloudStore\Store\DefaultAccount\Current\default$windows.data.bluelightreduction.bluelightreductionstate\windows.data.bluelightreduction.bluelightreductionstate"; - using (var key = Registry.CurrentUser.OpenSubKey(BlueLightReductionStateKey)) - { - var data = key?.GetValue("Data"); - if (data is null) - return false; - var byteData = (byte[])data; - return byteData.Length > 24 && byteData[23] == 0x10 && byteData[24] == 0x00; - } - } - - private void load_priority() - { - - String f_prio = String.Empty; - String saved_prio = String.Empty; - - this.Invoke(new MethodInvoker(delegate - { - if (is_portable == false) - { - f_prio = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_priority.ini"; - } - else - { - f_prio = port_path + "ff_priority_portable.ini"; - } - - if (File.Exists(f_prio)) - { - saved_prio = File.ReadAllText(f_prio); - if (saved_prio != String.Empty) - { - combo_prio.SelectedIndex = Convert.ToInt16(saved_prio); - current_prio = Convert.ToInt16(saved_prio); - } - } - else - { - combo_prio.SelectedIndex = 2; - } - btn_save_prio.Enabled = false; - })); - } - private void get_ff_ver() - { - Task t = Task.Run(() => - { - try - { - WebClient client = new WebClient(); - String stream = client.DownloadString("https://www.gyan.dev/ffmpeg/builds/release-version"); - latest_ff = stream; - } - catch (Exception exc) - { - latest_ff = Strings.error; - } - }); - } - - private void read_hw_dec() - { - //HW_Decoders - - String f_hw_dcd = String.Empty; - Boolean bug_1 = false; - String all_file = String.Empty; - - if (is_portable == false) - { - f_hw_dcd = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_hw_dcd.ini"; - } - else - { - f_hw_dcd = port_path + "ff_hw_dcd_portable.ini"; - } - - this.Invoke(new MethodInvoker(delegate - { - - if (File.Exists(f_hw_dcd)) - { - all_file = File.ReadAllText(f_hw_dcd); - if (f_hw_dcd.Contains("*")) bug_1 = true; - } - else - { - bug_1 = true; - } - if (bug_1 == false) - { - int dcd_saved = 0; - String[] saved_hw_dcd = File.ReadAllLines(f_hw_dcd); - foreach (string line in File.ReadLines(f_hw_dcd)) - { - cb_hwdecode.Items.Add(line.Replace("*","")); - } - cb_hwdecode.SelectedIndex = dcd_saved; - } - else - { - cb_hwdecode.Items.Add("none"); - decoders.Add("none"); - cb_hwdecode.SelectedIndex = 0; - String selected = cb_hwdecode.SelectedItem.ToString(); - if (hw_decoders == true) return; - - if (hw_decoders == false) - { - hw_decoders = true; - - //Read hardware decoders - Process consola_hw = new Process(); - - consola_hw.StartInfo.FileName = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - consola_hw.StartInfo.Arguments = " -hwaccels"; - consola_hw.StartInfo.RedirectStandardOutput = true; - consola_hw.StartInfo.RedirectStandardError = true; - consola_hw.StartInfo.UseShellExecute = false; - consola_hw.StartInfo.CreateNoWindow = true; - consola_hw.EnableRaisingEvents = true; - - String duracion = String.Empty; - String std_out = String.Empty; - consola_hw.Start(); - Boolean hw_found = false; - - while (!consola_hw.StandardOutput.EndOfStream) - { - std_out = consola_hw.StandardOutput.ReadLine(); - - if (std_out.Contains("Hardware acceleration methods:")) - { - if (selected != "auto") cb_hwdecode.Items.Add("auto"); - hw_found = true; - decoders.Add("auto"); - continue; - } - - if (hw_found == true && std_out != String.Empty && std_out != selected) - { - cb_hwdecode.Items.Add(std_out.Replace("*", "")); - decoders.Add(std_out); - } - } - consola_hw.WaitForExit(); - consola_hw.Close(); - File.WriteAllLines(f_hw_dcd, decoders); - } - } - })); - } - - private void read_saved_path() - { - String path_s = String.Empty; - if (is_portable == false) - { - path_s = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_path.ini"; - } - else - { - path_s = port_path + "ff_path_portable.ini"; - } - - if (File.Exists(path_s)) - { - String saved_path = File.ReadAllText(path_s); - - if (saved_path != String.Empty) - { - if (Directory.Exists(saved_path) == true) - { - txt_path_main.Text = saved_path; - txt_path_main.BackColor = Color.White; - } - else - { - if (saved_path.Contains(".\\")) - { - txt_path_main.Text = saved_path; - txt_path_main.BackColor = txt_parameters.BackColor; - txt_path_main.BackColor = this.BackColor; - } - } - } - else - { - File.Delete(path_s); - txt_path_main.BackColor = this.BackColor; - } - } - else - { - txt_path_main.Text = ".\\FFBatch"; - txt_path_main.BackColor = this.BackColor; - } - - //End read saved path - } - - private void read_main_config() - { - //Read saved path URL - - this.Invoke(new MethodInvoker(delegate - { - String path_s2 = String.Empty; - if (is_portable == false) - { - path_s2 = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_path_url.ini"; - } - else - { - path_s2 = port_path + "ff_path_url_portable.ini"; - } - - if (File.Exists(path_s2)) - { - String saved_path = File.ReadAllText(path_s2); - - if (saved_path.Length != 0) - { - if (Directory.Exists(saved_path) == true) - { - txt_path_m3u.Text = saved_path; - } - } - else - { - File.Delete(path_s2); - } - } - - //End read saved path URL - - //Read configuration - - SetStyle(ControlStyles.SupportsTransparentBackColor, true); - - combo_presets.Items.Add(Strings.default_param); - combo_presets.SelectedIndex = 0; - - String path = String.Empty; - String path_pr = String.Empty; - if (is_portable == false) - { - path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.ini"; - path_pr = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_presets.ini"; - } - else - { - path = port_path + "ff_batch_portable.ini"; - path_pr = port_path + "ff_presets_portable.ini"; - } - - int linea = 0; - combo_presets.SelectedIndex = combo_presets.FindString((Strings.default_param)); - - foreach (string line in File.ReadLines(path)) - { - linea = linea + 1; - if (linea == 1) - { - txt_parameters.Text = line; - continue; - } - - if (linea == 2) - { - txt_format.Text = line; - continue; - } - - if (line == "Yes") - - { - chk_open_compl.CheckState = CheckState.Checked; - continue; - } - - if (line == "No") - { - chk_open_compl.CheckState = CheckState.Unchecked; - continue; - } - - if (line == "Vn") - { - chk_suffix.CheckState = CheckState.Unchecked; - continue; - } - if (line.Length > 1 && line.Substring(0, 2) == "Vs") - { - chk_suffix.CheckState = CheckState.Checked; - txt_suffix.Text = line.Substring(3, line.Length - 3); - continue; - } - - if (line == "grid_yes") - { - listView1.GridLines = true; - listView2.GridLines = true; - listView3.GridLines = true; - continue; - } - if (line == "grid_no") - { - listView1.GridLines = false; - listView2.GridLines = false; - listView3.GridLines = false; - continue; - } - - if (line == "keep_yes") - { - chk_recreate.CheckState = CheckState.Checked; - continue; - } - if (line == "keep_no") - { - chk_recreate.CheckState = CheckState.Unchecked; - continue; - } - - if (line == "subf_yes") - { - chk_subfolders.CheckState = CheckState.Checked; - add_subfs = true; - continue; - } - if (line == "subf_no") - { - chk_subfolders.CheckState = CheckState.Unchecked; - add_subfs = false; - continue; - } - } - if (File.Exists(path_pr)) - { - foreach (string line in File.ReadLines(path_pr)) - { - if (line.Length > 8) - { - if (line.Substring(0, 7).ToLower() == "version") - { - txt_config_ver.Text = line.Substring(8, line.Length - 8); - continue; - } - } - - if (line.Contains("PR: ")) - { - combo_presets.Items.Add(line.Substring(4, line.LastIndexOf(" & ") - 4)); - } - } - } - - btn_save_config.ImageKey = "Save_settings_39.png"; - - //End read configuration - })); - } - - private void read_config_files() - { - Task t2 = Task.Run(() => - { - - this.Invoke(new MethodInvoker(delegate - { - - form4.cb_filterby.Items.Add(Strings.status); - form4.cb_filterby.Items.Add(Strings.file_ext); - form4.cb_filterby.Items.Add(Strings.f_size); - form4.cb_filterby.Items.Add(Strings.f_bitr); - form4.cb_filterby.Items.Add(Strings.Video_codec); - form4.cb_filterby.Items.Add(Strings.v_bitr); - form4.cb_filterby.Items.Add(Strings.Audio_codec); - form4.cb_filterby.Items.Add(Strings.fr_rate); - form4.cb_filterby.Items.Add(Strings.frame_size); - form4.cb_filterby.Items.Add(Strings.c_str + " (FF)"); - form4.cb_filterby.Items.Add(Strings.c_str + " (MI)"); - form4.cb_filterby.Items.Add(Strings.Metadata); - - //YouTube - - chk_yt_chapt.Checked = Settings.Default.yt_chaps; - chk_down_limit.Checked = Settings.Default.yt_limit; - n_down_speed.Value = Settings.Default.yt_limit_n; - chk_best_yt.Checked = Settings.Default.force_mp4_b; - chk_cache_yt.Checked = Settings.Default.yt_clear_c; - chk_embed_meta.Checked = Settings.Default.yt_embed_m; - - //Battery mode - PowerLineStatus pls = SystemInformation.PowerStatus.PowerLineStatus; - if (pls.ToString().ToLower() == "offline" && Settings.Default.pause_bat == true) pic_batt.Visible = true; - else pic_batt.Visible = false; - - //N-threads read - n_threads.Maximum = Environment.ProcessorCount; - n_downs.Maximum = n_threads.Maximum; - - if (n_threads.Maximum > 2) - { - n_threads.Minimum = 2; - n_downs.Minimum = 2; - } - else - { - n_threads.Minimum = 1; - n_downs.Minimum = 1; - } - - try - { - if (Environment.ProcessorCount > 2) - { - n_threads.Value = Environment.ProcessorCount / 2; - n_downs.Value = Environment.ProcessorCount / 2; - } - else - { - n_threads.Value = 2; - n_downs.Value = 2; - } - } - catch - { - if (n_threads.Maximum >= 2) - { - n_threads.Value = 2; - n_downs.Value = 2; - } - } - - - String no_out_pop = String.Empty; - if (is_portable == false) - { - no_out_pop = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_pop_up.ini"; - } - else - { - no_out_pop = port_path + "ff_pop_up_portable.ini"; - } - - if (File.Exists(no_out_pop)) - { - no_output_pop = true; - } - - String path_first = String.Empty; - if (is_portable == false) - { - path_first = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_first.ini"; - } - else - { - path_first = port_path + "ff_first_portable.ini"; - } - if (!File.Exists(path_first)) - { - first_run = true; - File.WriteAllText(path_first, String.Empty); - } - - String f_thr = String.Empty; - if (is_portable == false) - { - f_thr = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_nthreads.ini"; - } - else - { - f_thr = port_path + "ff_nthreads_portable.ini"; - } - - if (File.Exists(f_thr)) - { - String saved_th = File.ReadAllText(f_thr); - int test = 0; - - if (int.TryParse(saved_th, out test)) - { - if (Convert.ToInt16(saved_th) <= n_threads.Maximum) - { - n_threads.Value = Convert.ToInt16(saved_th); - } - else n_threads.Value = 2; - } - } - - //End N-threads read - - //Begin n_downloads - - String f_thr2 = String.Empty; - if (is_portable == false) - { - f_thr2 = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_downs.ini"; - } - else - { - f_thr2 = port_path + "ff_downs_portable.ini"; - } - - if (File.Exists(f_thr2)) - { - String saved_th2 = File.ReadAllText(f_thr2); - - if (Convert.ToInt16(saved_th2) <= Environment.ProcessorCount) n_downs.Value = Convert.ToInt16(saved_th2); - else n_downs.Value = 2; - } - //End N-downloads - - pic_title.BackColor = Color.Transparent; - combo_prio.Text = "Priority"; - - //Disable try preset - - String f_try = String.Empty; - if (is_portable == false) - { - f_try = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_try.ini"; - } - else - { - f_try = port_path + "ff_try_portable.ini"; - } - - if (File.Exists(f_try)) - { - chk_try.Checked = true; - } - else - { - chk_try.Checked = false; - } - //End Disable preset - - //Send params to console - - String f_params_console = String.Empty; - if (is_portable == false) - { - f_params_console = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_par_con.ini"; - } - else - { - f_params_console = port_path + "ff_par_con_portable.ini"; - } - - send_par_consol = !File.Exists(f_params_console); - //End send params to console - - //Concat video filter - - String f_concat = String.Empty; - if (is_portable == false) - { - f_concat = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_concat.ini"; - } - else - { - f_concat = port_path + "ff_concat_portable.ini"; - } - - if (File.Exists(f_concat)) - { - check_concat.Checked = true; - } - else - { - check_concat.Checked = false; - } - first_concat = false; - //End concat video filter - - //Ignore encoded items - - ignore_encoded = get_ingnorenc(); - - //End ignore encoded items - - //Do not save logs - - String f_nologs = String.Empty; - if (is_portable == false) - { - f_nologs = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_nologs.ini"; - } - else - { - f_nologs = port_path + "ff_nologs_portable.ini"; - } - - no_save_logs = (File.Exists(f_nologs)); - //End do not save logs - - //Verbose logs - - String f_verbose = String.Empty; - if (is_portable == false) - { - f_verbose = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_verbose.ini"; - } - else - { - f_verbose = port_path + "ff_verbose_portable.ini"; - } - - verbose_logs = File.Exists(f_verbose); - //End Verbose logs - - //Full report - - String f_report = String.Empty; - if (is_portable == false) - { - f_report = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_report.ini"; - } - else - { - f_report = port_path + "ff_report_portable.ini"; - } - - full_report = File.Exists(f_report); - //End full report - - //Do not cache network files - - String f_nocache = String.Empty; - if (is_portable == false) - { - f_nocache = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_nocache.ini"; - } - else - { - f_nocache = port_path + "ff_nocache_portable.ini"; - } - - no_save_cache = File.Exists(f_nocache); - //End do cache network files - - //Use OS cache dialog - - String f_oscache = String.Empty; - if (is_portable == false) - { - f_oscache = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_oscache.ini"; - } - else - { - f_oscache = port_path + "ff_oscache_portable.ini"; - } - - os_save_cache = File.Exists(f_oscache); - //End use OS cache dialog - - //Delete source files to recycle bin - - String f_delete = String.Empty; - if (is_portable == false) - { - f_delete = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_delete.ini"; - } - else - { - f_delete = port_path + "ff_delete_portable.ini"; - } - - if (File.Exists(f_delete)) - { - chk_delete_source.CheckState = CheckState.Checked; - } - else - { - chk_delete_source.CheckState = CheckState.Unchecked; - } - - //END delete source files to recycle bin - - //Read play sound - - String ff_play_sound = String.Empty; - if (is_portable == false) - { - ff_play_sound = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_play.ini"; - } - else - { - ff_play_sound = port_path + "ff_play_portable.ini"; - } - - if (!File.Exists(ff_play_sound)) - { - play_on_end = false; - } - else - { - String read_play = File.ReadAllText(ff_play_sound); - if (read_play.Length != 0) - { - play_on_end = true; - play_file_path = read_play; - } - else - { - play_on_end = false; - } - } - //End Read play sound - - String f_remember_w = String.Empty; - if (is_portable == false) - { - f_remember_w = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_remember_w.ini"; - } - else - { - f_remember_w = port_path + "ff_remember_w_portable.ini"; - } - remember_w = File.Exists(f_remember_w); - //Fix pre-input - - String f_fix_pre = String.Empty; - if (is_portable == false) - { - f_fix_pre = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_fix_pre.ini"; - } - else - { - f_fix_pre = port_path + "ff_fix_pre_portable.ini"; - } - if (File.Exists(f_fix_pre)) - { - fix_pre = true; - txt_pre_input.Text = File.ReadAllText(f_fix_pre); - } - else - { - fix_pre = false; - txt_pre_input.Text = String.Empty; - } - - //End fix pre_input - - //Save trim check - - String f_trim = String.Empty; - if (is_portable == false) - { - f_trim = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_trim.ini"; - } - else - { - f_trim = port_path + "ff_trim_portable.ini"; - } - if (File.Exists(f_trim)) - { - chk_trim2.CheckState = CheckState.Checked; - } - else - { - chk_trim2.CheckState = CheckState.Unchecked; - } - - //End save trim check - - //Delete full - - String f_delete_full = String.Empty; - if (is_portable == false) - { - f_delete_full = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_delete_full.ini"; - } - else - { - f_delete_full = port_path + "ff_delete_full_portable.ini"; - } - - if (File.Exists(f_delete_full)) delete_def = true; - else delete_def = false; - //End delete full - - //Delete one - - String f_delete_one = String.Empty; - if (is_portable == false) - { - f_delete_one = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_delete_one.ini"; - } - else - { - f_delete_one = port_path + "ff_delete_one_portable.ini"; - } - if (File.Exists(f_delete_one)) delete_one = true; - else delete_one = false; - - //End delete one - - //Keep file dates - - String f_dates = String.Empty; - if (is_portable == false) - { - f_dates = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_dates.ini"; - } - else - { - f_dates = port_path + "ff_dates_portable.ini"; - } - - if (File.Exists(f_dates)) - { - keep_dates = true; - } - else - { - keep_dates = false; - } - - if (Settings.Default.pause_bat == true) timer_battery.Start(); - - })); - }); - } - - private Boolean get_ingnorenc() - { - String f_ignore_enc = String.Empty; - if (is_portable == false) - { - f_ignore_enc = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_ignore_enc.ini"; - } - else - { - f_ignore_enc = port_path + "ff_ignore_enc_portable.ini"; - } - - return File.Exists(f_ignore_enc); - } - - private void add_col_start() - { - if (Settings.Default.quick_queue == true) return; - String f_cols = String.Empty; - if (is_portable == false) - { - f_cols = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_cols.ini"; - } - else - { - f_cols = port_path + "ff_cols_portable.ini"; - } - - if (!File.Exists(f_cols)) return; - String check = File.ReadAllText(f_cols); - if (!check.Contains(";")) return; - - int cur_w = 0; - - foreach (String str in File.ReadLines(f_cols)) - { - int ps = str.LastIndexOf(";") + 1; - String str2 = str.Substring(0, ps - 1); - int width = Convert.ToInt32(str.Substring(ps, str.Length - ps)); - - if (str2.Substring(0, ps - 1) == Strings.filename) - { - listView1.Columns[0].Width = width; - } - - if (str2 == Strings.path) - { - listView1.Columns[1].Width = width; - } - - if (str2 == Strings.file_type) - { - listView1.Columns[2].Width = width; - } - - if (str2 == Strings.duration) - { - listView1.Columns[3].Width = width; - } - if (str2 == Strings.size) - { - listView1.Columns[4].Width = width; - } - if (str2 == Strings.status) - { - listView1.Columns[5].Width = width; - } - - if (str2 == Strings.height) - { - ColumnHeader columnHeader = listView1.Columns.Add(Strings.width, width, HorizontalAlignment.Center); - ColumnHeader columnHeader2 = listView1.Columns.Add(Strings.height, width, HorizontalAlignment.Center); - } - - if (str2 == Strings.Video_codec) - { - ColumnHeader columnHeader = listView1.Columns.Add(Strings.Video_codec, width, HorizontalAlignment.Left); - } - - if (str2 == Strings.Audio_codec) - { - ColumnHeader columnHeader = listView1.Columns.Add(Strings.Audio_codec, width, HorizontalAlignment.Center); - } - - if (str2 == Strings.v_bitr) - { - ColumnHeader columnHeader = listView1.Columns.Add(Strings.v_bitr, width, HorizontalAlignment.Center); - } - if (str2 == Strings.a_bitr) - { - ColumnHeader columnHeader = listView1.Columns.Add(Strings.a_bitr, width, HorizontalAlignment.Center); - } - if (str2 == Strings.Encoding_parameters) - { - ColumnHeader columnHeader = listView1.Columns.Add(Strings.Encoding_parameters, width, HorizontalAlignment.Center); - } - - if (str2.TrimEnd() == Settings.Default.cust_med_col.TrimEnd()) - { - ColumnHeader columnHeader = listView1.Columns.Add(Settings.Default.cust_med_col, width, HorizontalAlignment.Center); - } - - if (str2 == Strings.bitrate && !str2.ToLower().Contains("video") && !str2.ToLower().Contains("audio") && !str2.ToLower().TrimEnd().Contains(Settings.Default.cust_med_col.ToLower().TrimEnd()) && !str2.ToLower().Contains("vídeo") && !str2.ToLower().Contains("视频") && !str2.ToLower().Contains("音")) - { - ColumnHeader columnHeader = listView1.Columns.Add(Strings.bitrate, width, HorizontalAlignment.Center); - } - } - } - private void button3_Click(object sender, EventArgs e) - { - Pg1.Focus(); - String path_log_backup = String.Empty; - String path, path_pre = String.Empty; - if (is_portable == false) - { - path_log_backup = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch_bck.ini"; - path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.ini"; - path_pre = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch_pre.ini"; - } - else - { - path_log_backup = port_path + "ff_batch_bck_portable.ini"; - path = port_path + "ff_batch_portable.ini"; - path_pre = port_path + "ff_batch_pre_portable.ini"; - if (!File.Exists(path)) reset_portable(); - } - - File.Copy(path, path_log_backup, true); - - String[] lines = File.ReadAllLines(path); - - for (int i = 0; i < lines.Length - 1; i++) - { - lines[0] = txt_parameters.Text; - lines[1] = txt_format.Text; - - if (chk_open_compl.Checked) - { - lines[2] = "Yes"; - } - else - { - lines[2] = "No"; - } - - if (chk_suffix.Checked) - { - lines[3] = "Vs " + txt_suffix.Text; - } - else - { - lines[3] = "Vn"; - } - - if (listView1.GridLines == true) - { - lines[4] = "grid_yes"; - } - else - { - lines[4] = "grid_no"; - } - - if (chk_recreate.Checked) - { - lines[5] = "keep_yes"; - } - else - { - lines[5] = "keep_no"; - } - - if (chk_subfolders.Checked) - { - lines[6] = "subf_yes"; - } - else - { - lines[6] = "subf_no"; - } - } - File.WriteAllLines(path, lines); - - btn_save_config.ImageKey = "Save_settings_39.png"; - - toolTip_settings.SetToolTip(this.btn_save_config, Strings.params_def); - btn_load_config.PerformClick(); - } - - private void button5_Click(object sender, EventArgs e) - { - Pg1.Focus(); - del_queue(); - - if (Settings.Default.dark_mode == false) pic_frame.Image = pic_reading.ErrorImage; - else pic_frame.Image = pic_dark.Image; - current_fr = 4000; - lbl_a_th.Text = "-"; - lbl_s_th.Text = "-"; - lbl_v_th.Text = "-"; - lbl_gb_th.Text = "-"; - lbl_mux_jobs.Text = Strings.jobs + " " + frm_mux_jobs.dg_pr.RowCount.ToString(); - lbl_est_size.Text = ""; - lbl_size.Text = ""; - lbl_bitrate.Text = ""; - LB_Wait.Visible = false; - txt_remain.Text = Strings.remain_time + " " + "00h:00m:00s"; - lbl_elapsed.Text = Strings.time_elapsed + " " + "00h:00m:00s"; - listView1.Items.Clear(); - listView2.Items.Clear(); - listView3.Items.Clear(); - dg1.Rows.Clear(); - ss_time_input.Text = "0:00:00.000"; - txt_folder_subs.Text = String.Empty; - txt_folder_subs.BackColor = Control.DefaultBackColor; - lbl_items.Text = ""; - lbl_dur_list.Text = ""; - lbl_speed.Text = String.Empty; - Pg1.Value = 0; - Pg1.Text = "0" + CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - Pg1.Refresh(); - list_tracks.Items.Clear(); - combo_item_lang_2.SelectedIndex = -1; - Combo_sub_lang_mux.SelectedIndex = -1; - lbl_tr_n.Text = Strings.tracks + " " + "0"; - lbl_urls_time.Text = ""; - txt_mux_type.Text = String.Empty; - btn_try_pr.Image = img_try.Images[0]; - lbl_urls_time.Text = ""; - lbl_n_urls.Text = ""; - pic_warnings.Visible = false; - pic_no_errors.Visible = false; - pic_recording.Visible = false; - clean_imgs(); - } - - private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) - { - String save_path_queue = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "saved_queue_temp.ffq"; - if (is_portable == true) save_path_queue = port_path + "saved_queue_temp.ffq"; - String save_path_queue0 = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "saved_queue_temp0.ffq"; - if (is_portable == true) save_path_queue0 = port_path + "saved_queue_temp0.ffq"; - - try - { - if (File.Exists(save_path_queue) && reloaded_q == false) - { - reloaded_q = true; - int ii = 0; - foreach (String str in File.ReadLines(save_path_queue)) - { - if (ii == 0) txt_parameters.Text = str; - return; - } - combo_presets.Text = Strings.saved; - try - { - File.Delete(save_path_queue); - } - catch { } - return; - } - else if (File.Exists(save_path_queue0) && reloaded_q == false) - { - reloaded_q = true; - int ii = 0; - foreach (String str in File.ReadLines(save_path_queue0)) - { - if (ii == 0) txt_parameters.Text = str; - return; - } - combo_presets.Text = Strings.saved; - try - { - File.Delete(save_path_queue0); - } - catch { } - return; - } - - String path; - String path_pr; - - if (is_portable == false) - { - path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.ini"; - path_pr = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_presets.ini"; - } - else - { - path = port_path + "ff_batch_portable.ini"; - path_pr = port_path + "ff_presets_portable.ini"; - } - - if (combo_presets.SelectedIndex == 0) - { - txt_pre_input.BackColor = txt_parameters.BackColor; - - if (is_portable == false) - { - if (!Directory.Exists(Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch"))) - { - Directory.CreateDirectory(Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch")); - } - } - else - { - if (!Directory.Exists(port_path)) - { - Directory.CreateDirectory(port_path); - } - } - - if (!File.Exists(path)) - { - File.WriteAllText(path, "-c copy" + Environment.NewLine + "mp4" + Environment.NewLine + "Yes" - + Environment.NewLine + "Vn" + Environment.NewLine + "grid_yes" + Environment.NewLine + "keep_no" - + Environment.NewLine + "subf_no"); - } - - if (!File.Exists(path_pr) && File.Exists(path)) - { - List presets_old = new List(); - List new_config = new List(); - foreach (string line in File.ReadLines(path)) - { - if (line.Length > 4) - { - if (line.Substring(0, 4) == "PR: ") - { - presets_old.Add(line + Environment.NewLine); - } - } - if (!line.Contains("PR: ") && line.Substring(0, 2).ToLower() != "ve") new_config.Add(line + Environment.NewLine); - } - - File.Delete(path); - foreach (String st in presets_old) File.AppendAllText(path_pr, st); - foreach (String st in new_config) - { - File.AppendAllText(path, st); - } - } - - int linea = 0; - foreach (string line in File.ReadLines(path)) - { - linea = linea + 1; - - if (linea == 1) - { - txt_parameters.Text = line; - } - - if (linea == 2) - { - txt_format.Text = line; - } - - if (line == "Yes") - - { - chk_open_compl.CheckState = CheckState.Checked; - } - - if (line == "No") - { - chk_open_compl.CheckState = CheckState.Unchecked; - } - } - } - else - { - String pre_name = String.Empty; - if (File.Exists(path_pr)) path = path_pr; - int i = 0; - foreach (string line in File.ReadLines(path)) - { - if (line.Length > 8) - { - if (line.Substring(0, 7).ToLower() == "version") - { - txt_config_ver.Text = line.Substring(8, line.Length - 8); - continue; - } - } - - if (line.Length > 4 && line.Substring(4, line.IndexOf(" & ") - 4) == combo_presets.SelectedItem.ToString()) - { - int cortar = line.LastIndexOf("%") - line.LastIndexOf(" & "); - txt_format.Text = line.Substring(line.LastIndexOf("%") + 2); - try - { - txt_parameters.Text = line.Substring(line.LastIndexOf(" & ") + 3, cortar - 4); - } - catch - { - MessageBox.Show(Strings.invalid_pres, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - continue; - } - } - } - btn_save_preset.Enabled = false; - String path_pr_pre = String.Empty; - - if (is_portable == false) - { - path_pr_pre = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_presets_pre.ini"; - } - - else - { - path_pr_pre = port_path + "ff_presets_pre_portable.ini"; - } - - //Read pre-input - - if (combo_presets.SelectedIndex == 0) - { - String path_pre = String.Empty; - - if (is_portable == false) - { - path_pre = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch_pre.ini"; - } - else - { - path_pre = port_path + "ff_batch_pre_portable.ini"; - } - - String pre_input = String.Empty; - if (File.Exists(path_pre)) pre_input = File.ReadAllText(path_pre); - - if (pre_input.Length > 0) - txt_pre_input.Text = pre_input.Substring(8, pre_input.Length - 8); - } - else - { - if (fix_pre == false) txt_pre_input.Text = ""; - } - //End read-pre-input - - if (File.Exists(path_pr_pre)) - { - foreach (string line in File.ReadLines(path_pr_pre)) - { - if (line.Length > 5) if (line.Substring(0, line.LastIndexOf("&&&") - 1) == combo_presets.Text) txt_pre_input.Text = line.Substring(line.LastIndexOf("&&&") + 4, line.Length - line.LastIndexOf("&&&") - 4); - } - } - } - catch - { - if (File.Exists(save_path_queue)) File.Delete(save_path_queue); - if (File.Exists(save_path_queue0)) File.Delete(save_path_queue0); - } - } - - private void cti1_Click(object sender, EventArgs e) - { - if (listView1.SelectedItems.Count > 0) - { - String fullPath = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - String destino = Path.GetDirectoryName(fullPath); - - if (Directory.Exists(destino)) - { - Process process = new System.Diagnostics.Process(); - process.StartInfo.FileName = "explorer.exe"; - process.StartInfo.Arguments = "\u0022" + destino + "\u0022"; - process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; - process.Start(); - } - else - { - MessageBox.Show(Strings.no_path, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - - private void cti2_Click(object sender, EventArgs e) - { - if (listView1.SelectedItems.Count > 0) - { - String fullPath = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - if (File.Exists(fullPath)) - { - try { System.Diagnostics.Process.Start(fullPath); } - catch (Exception exc) { MessageBox.Show(exc.Message, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); }; - } - else - { - MessageBox.Show(Strings.file_not_found, Strings.file_miss, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - - private void ctm1_Opening(object sender, CancelEventArgs e) - { - ct1_params.Visible = false; - ct1_rem_param.Visible = false; - - if (listView1.SelectedIndices.Count > 0) - { - ct1_params.Visible = true; - } - - if (Settings.Default.dark_mode == true) - { - ctm1.BackColor = Color.FromArgb(255, 64, 64, 64); - ctm1.ForeColor = Color.White; - } - else - { - ctm1.BackColor = SystemColors.InactiveBorder; - ctm1.ForeColor = Control.DefaultForeColor; - } - - cti6.Visible = false; - if (runnin_n_presets == true) e.Cancel = true; - - ctm1_queue.Enabled = false; - - if (working == true) - { - ct_move_bottom.Enabled = false; - ct_move_top.Enabled = false; - - cti1.Enabled = false; - cti2.Enabled = false; - cti3.Enabled = false; - cti4.Enabled = false; - cti5.Enabled = false; - if (listView1.SelectedItems.Count > 0) ctdel.Enabled = true; - ct1_total_frames.Enabled = false; - ct1_streams.Enabled = false; - ctm1_queue.Enabled = false; - cti1_cols.Enabled = false; - cti_remove_col.Enabled = false; - ctm1_encode.Visible = false; - - if (listView1.SelectedItems[0].SubItems[5].Text != Strings.aborted && listView1.SelectedItems[0].SubItems[5].Text != Strings.queued && listView1.SelectedItems[0].SubItems[5].Text != Strings.aborting && listView1.SelectedItems[0].SubItems[5].Text != Strings.success) - { - cti6.Visible = true; - cti6.Text = Strings.stop_proc + " " + "\u0022" + Path.GetFileName(listView1.SelectedItems[0].Text) + "\u0022"; - } - - if (cust_p_col != 0 && listView1.SelectedIndices.Count > 0) - { - foreach (ListViewItem it in listView1.SelectedItems) - { - try - { - if (it.SubItems[cust_p_col].Text != "-") - { - ct1_rem_param.Visible = true; - break; - } - } - catch - { - e.Cancel = true; - return; - } - } - } - else ct1_rem_param.Visible = false; - - foreach (ListViewItem item in listView1.SelectedItems) - { - if (item.SubItems[5].Text == Strings.queued) - { - ctdel.Enabled = true; - if (multi_running == false) ctdel.Text = Strings.rem_from_list; - else ctdel.Text = Strings.skip_from_list; - } - else - { - ctdel.Enabled = false; - break; - } - } - } - else - { - ctm1_encode.Visible = false; - if (!Clipboard.ContainsText()) - { - ct1_paste_m3u.Visible = false; - ct1_paste_youtube.Visible = false; - } - else - { - if (Clipboard.GetText().ToLower().Contains("youtu.be") || Clipboard.GetText().ToLower().Contains("youtube.com")) - { - ct1_paste_youtube.Visible = true; - ct1_paste_m3u.Visible = false; - } - else - { - ct1_paste_youtube.Visible = false; - - if (Clipboard.GetText().ToLower().Contains("http") == true) - { - if (Clipboard.GetText().ToLower().Contains("m3u") == true) - { - ct1_paste_m3u.Text = Strings.Paste_M3u_URL; - } - else - { - ct1_paste_m3u.Text = Strings.Paste_any_URL; - } - ct1_paste_m3u.Visible = true; - } - else - { - ct1_paste_m3u.Visible = false; - } - } - - cti1_cols.Enabled = (listView1.Columns.Count <= 14 && listView1.Columns.Count >= 6); - cti_remove_col.Enabled = listView1.Columns.Count > 6; - } - - if (listView1.SelectedItems.Count > 0) - { - ct1_sep_cod.Visible = true; - cti1.Enabled = true; - cti2.Enabled = true; - - if (cust_p_col != 0) - { - foreach (ListViewItem it in listView1.SelectedItems) - { - try - { - if (it.SubItems[cust_p_col].Text != "-") - { - ct1_rem_param.Visible = true; - break; - } - } - catch - { - MessageBox.Show(Strings.Refresh_list, Strings.warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); - refresh_full(); - e.Cancel = true; - return; - } - } - } - - String fullPath = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - String destino = ""; - if (txt_path_main.Text.Contains(".\\")) - { - destino = fullPath.Substring(0, fullPath.LastIndexOf('\\')) + txt_path_main.Text.Replace(".", String.Empty); - } - else - { - destino = txt_path_main.Text; - } - - cti3.Enabled = Directory.Exists(destino); - - String second_path = ""; - if (txt_format.Text == "nul") - { - String[] split = txt_parameters.Text.Split(' '); - for (int i = 0; i < split.Length; i++) - { - if (split[i].Contains("\\") == true) - { - String pre_path = split[i].Replace("%fp", Path.GetDirectoryName(fullPath)).Replace("%", "_"); - - second_path = Path.GetDirectoryName(pre_path.Replace('\u0022', ' ')); - cti3.Enabled = Directory.Exists(second_path); - } - } - } - - cti4.Enabled = true; - cti5.Enabled = true; - ctdel.Enabled = true; - ctdel.Enabled = true; - if (multi_running == false) ctdel.Text = Strings.rem_from_list; - else ctdel.Text = Strings.skip_from_list; - ct1_total_frames.Enabled = true; - ct1_streams.Enabled = true; - ctm_add_files.Visible = false; - ctm_add_folder.Visible = false; - ctm_paste_path.Visible = false; - ct_move_bottom.Enabled = true; - ct_move_top.Enabled = true; - toolStripSeparator2.Visible = false; - ctm1_queue.Enabled = false; - foreach (ListViewItem item in listView1.SelectedItems) - { - if (item.SubItems[5].Text != Strings.queued) - { - ctm1_queue.Enabled = true; - break; - } - } - ctm1_encode.Visible = true; - } - else - { - ct1_sep_cod.Visible = false; - e.Cancel = false; - ctm_add_files.Visible = true; - ctm_add_folder.Visible = true; - ctm_paste_path.Visible = true; - ctm1_queue.Enabled = false; - ct_move_bottom.Enabled = false; - ct_move_top.Enabled = false; - toolStripSeparator2.Visible = true; - cti1.Enabled = false; - cti2.Enabled = false; - cti3.Enabled = false; - cti4.Enabled = false; - cti5.Enabled = false; - ctdel.Enabled = false; - ct1_total_frames.Enabled = false; - ct1_streams.Enabled = false; - toolStripSeparator2.Visible = true; - } - } - } - - private void timer1_Tick(object sender, EventArgs e) - { - if (cancelados_paralelos == true) - { - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - return; - } - if (time_n_tasks < 1) return; - if (Settings.Default.quick_queue == true) return; - - Double weight = 0; - Double dg_multi_prog = 0; - total_multi_duration = 0; - int new_ssto = 0; - - if (Settings.Default.quick_queue == false) - { - foreach (ListViewItem item in listView1.Items) - { - DateTime time2; - if (DateTime.TryParse(item.SubItems[3].Text, out time2)) - { - if (ss_to == true) - { - new_ssto = get_ss_to(txt_pre_input.Text, TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds); - - if (new_ssto > 0) total_multi_duration = total_multi_duration + new_ssto - TimeSpan.Parse(ss_time_input.Text).TotalSeconds; - else total_multi_duration = total_multi_duration + TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds - TimeSpan.Parse(ss_time_input.Text).TotalSeconds; - } - else total_multi_duration = total_multi_duration + TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds - TimeSpan.Parse(ss_time_input.Text).TotalSeconds; - } - } - - Pg1.Maximum = listView1.Items.Count * 100; - start_total_time = start_total_time + 0.5; - - - TimeSpan t9 = TimeSpan.FromSeconds(start_total_time); - String tx_elapsed = string.Format("{0:D2}h:{1:D2}m:{2:D2}s", - t9.Hours, - t9.Minutes, - t9.Seconds); - lbl_elapsed.Text = Strings.time_elapsed + " " + tx_elapsed; - - try - { - foreach (ListViewItem item_p in listView1.Items) - { - - if (item_p.SubItems[3].Text == Strings.n_a) - { - weight = 1 / listView1.Items.Count; - } - else - { - weight = (TimeSpan.Parse(item_p.SubItems[3].Text).TotalSeconds - TimeSpan.Parse(ss_time_input.Text).TotalSeconds) / total_multi_duration; - } - - if (item_p.SubItems[5].Text.Contains("%")) - { - String item_round = item_p.SubItems[5].Text.Replace(",", System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator).Replace(".", System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator); - dg_multi_prog = dg_multi_prog + Math.Round(Convert.ToDouble(item_round.Replace("%", "")) * weight * listView1.Items.Count, 1); - } - - else - { - if (item_p.SubItems[5].Text != Strings.queued && item_p.SubItems[5].Text != Strings.processing) - { - dg_multi_prog = dg_multi_prog + (100 * weight * listView1.Items.Count); - } - } - } - - Pg1.Value = (int)dg_multi_prog; - Double pg_v = Math.Round(dg_multi_prog / listView1.Items.Count, 1); - if (Math.Round(dg_multi_prog / listView1.Items.Count, 1) > 100) - { - pg_v = 100; - Pg1.Text = "100%"; - } - else - { - - if (Math.Round(dg_multi_prog / listView1.Items.Count, 1).ToString().Contains(".") || Math.Round(dg_multi_prog / listView1.Items.Count, 1).ToString().Contains(",")) - { - Pg1.Text = Math.Round(dg_multi_prog / listView1.Items.Count, 1).ToString() + "%"; - } - else - { - Pg1.Text = Math.Round(dg_multi_prog / listView1.Items.Count, 1).ToString() + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - } - } - - TaskbarProgress.SetValue(this.Handle, Convert.ToInt32(dg_multi_prog), Pg1.Maximum); - - - if (Pg1.Value / listView1.Items.Count > 0 && start_total_time > 4 && Settings.Default.quick_queue == false) - { - Double remain_secs = time_n_tasks * 100 / (Pg1.Value / listView1.Items.Count) - start_total_time; - String remain_string = String.Empty; - - TimeSpan t = TimeSpan.FromSeconds(remain_secs); - remain_string = string.Format("{0:D2}h:{1:D2}", - t.Hours, - t.Minutes); - - if (remain_secs >= 43200) - { - txt_remain.Text = Strings.remain_time + " " + Math.Round(remain_secs / 3600).ToString() + " " + Strings.hours; - this.Text = Pg1.Text + " / " + Math.Round(remain_secs / 3600).ToString() + " " + Strings.hours; - } - - if (remain_secs >= 3600 && remain_secs < 43200) - { - txt_remain.Text = Strings.remain_time + " " + remain_string + " " + Strings.minutes_abrev; - this.Text = Pg1.Text + " / " + remain_string + " " + Strings.minutes_abrev; - } - - if (remain_secs < 3600 && remain_secs >= 600) - { - txt_remain.Text = Strings.remain_time + " " + remain_string.Substring(remain_string.LastIndexOf(":") + 1, 2) + " " + Strings.minutes; - this.Text = Pg1.Text + " / " + remain_string.Substring(remain_string.LastIndexOf(":") + 1, 2) + " " + Strings.minutes_abrev; - } - if (remain_secs < 600 && remain_secs >= 120) - { - txt_remain.Text = Strings.remain_time + " " + remain_string.Substring(remain_string.LastIndexOf(":") + 2, 1) + " " + Strings.minutes; - this.Text = Pg1.Text + " / " + remain_string.Substring(remain_string.LastIndexOf(":") + 2, 1) + " " + Strings.minutes_abrev; - } - - if (remain_secs < 120 && remain_secs > 59) - { - txt_remain.Text = Strings.remain_time + " " + Strings.about_1; - this.Text = Pg1.Text + " / " + remain_string.Substring(remain_string.LastIndexOf(":") + 2, 1) + " " + Strings.minutes_abrev; - } - - if (remain_secs <= 59) - { - txt_remain.Text = Strings.remain_time + " " + Strings.less_one; - this.Text = Pg1.Text + " / " + Convert.ToInt16(Math.Abs(remain_secs)) + " s"; - } - if (remain_secs <= 0) - { - txt_remain.Text = Strings.remain_time + " " + Strings.almost_done; - this.Text = Pg1.Text + " / " + Strings.almost_done; - } - txt_remain.Refresh(); - Decimal speeds = 0; - Decimal fps = 0; - String sep = System.Globalization.CultureInfo.CurrentUICulture.NumberFormat.NumberDecimalSeparator; - - try - { - Decimal deci = 0; - - foreach (String str in multi_speeds) - { - if (str.Contains(sep)) - { - deci = Convert.ToDecimal(str, CultureInfo.CurrentUICulture); - } - else - { - if (str.Contains(",")) deci = Convert.ToDecimal(str.Replace(",", ".")); - else deci = Convert.ToDecimal(str.Replace(".", ",")); - } - speeds = Math.Round(Decimal.Add(speeds, deci), 2); - } - } - catch (Exception excpt) - { - speeds = 0; - } - - try - { - Decimal deci = 0; - foreach (String str in multi_fps) - { - if (str.Contains(sep)) - { - deci = Convert.ToDecimal(str, CultureInfo.CurrentUICulture); - fps = Decimal.Add(fps, deci); - } - else - { - if (str.Contains(",")) deci = Convert.ToDecimal(str.Replace(",", ".")); - else deci = Convert.ToDecimal(str.Replace(".", ",")); - fps = Decimal.Add(fps, deci); - } - } - } - catch { fps = 0; } - - String fps_perf = fps.ToString(); - if (fps_perf == "0") - { - lbl_speed.Text = Strings.speed + " " + speeds.ToString() + "x"; - } - else - { - lbl_speed.Text = Strings.speed + " " + speeds.ToString() + "x" + " | " + fps_perf.TrimEnd() + " fps"; - } - } - else - { - txt_remain.Text = Strings.remain_time + " " + Strings.calcul; - txt_remain.Refresh(); - } - - } - catch - { - txt_remain.Text = Strings.remain_time + " " + Strings.calcul; - txt_remain.Refresh(); - } - } - - } - - private void cti3_Click(object sender, EventArgs e) - { - String fullPath = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - String destino = ""; - if (txt_format.Text != "nul") - { - if (txt_path_main.Text.Contains(".\\")) - { - destino = fullPath.Substring(0, fullPath.LastIndexOf('\\')) + txt_path_main.Text.Replace(".", String.Empty); - } - else - { - destino = txt_path_main.Text; - } - - if (Directory.Exists(destino)) - { - Process process = new System.Diagnostics.Process(); - process.StartInfo.FileName = "explorer.exe"; - process.StartInfo.Arguments = "\u0022" + destino + "\u0022"; - process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; - process.Start(); - } - else - { - MessageBox.Show(Strings.no_path, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } - String second_path = ""; - if (txt_format.Text == "nul") - { - String[] split = txt_parameters.Text.Split(' '); - for (int i = 0; i < split.Length; i++) - { - if (split[i].Contains("\\") == true) - { - String pre_path = split[i].Replace("%fp", Path.GetDirectoryName(fullPath)).Replace("%", "_"); - - second_path = Path.GetDirectoryName(pre_path.Replace('\u0022', ' ')); - - if (Directory.Exists(second_path)) - { - Process process = new System.Diagnostics.Process(); - process.StartInfo.FileName = "explorer.exe"; - process.StartInfo.Arguments = "\u0022" + second_path + "\u0022"; - process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; - process.Start(); - } - else - { - MessageBox.Show(Strings.no_path, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } - } - } - } - - private void cti4_Click(object sender, EventArgs e) - { - media_info(); - } - - private void media_info() - { - if (listView1.Items.Count == 1) listView1.Items[0].Selected = true; - - String ffm = Path.Combine(Application.StartupPath, "mediainfo.exe"); - if (!File.Exists(ffm)) - { - MessageBox.Show(Strings.no_mediainfo, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (listView1.SelectedItems.Count == 1) - { - String file1 = Path.Combine(Application.StartupPath + "\\", "mediainfo.exe"); - String fullPath = "\u0022" + listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text + "\u0022"; - String testPath = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - if (!File.Exists(testPath)) - { - MessageBox.Show(Strings.file_not_found, Strings.file_miss, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - this.Cursor = Cursors.WaitCursor; - - Form frmInfo = new Form(); - frmInfo.Name = Strings.multi_info; - frmInfo.Text = "FFmpeg Batch AV Converter"; - if (is_portable == true) frmInfo.Text = "FFmpeg Batch AV Converter Portable"; - frmInfo.Icon = this.Icon; - frmInfo.Height = 721; - frmInfo.Width = 492; - frmInfo.FormBorderStyle = FormBorderStyle.FixedSingle; - frmInfo.MaximizeBox = false; - frmInfo.MinimizeBox = false; - frmInfo.BackColor = this.BackColor; - - var fuente_list = new System.Drawing.Font("Microsoft Sans Serif", 9, FontStyle.Regular); - - ListView LB1 = new ListView(); - LB1.Parent = frmInfo; - LB1.ShowItemToolTips = true; - LB1.Left = 14; - LB1.Top = 56; - LB1.Height = 587; - LB1.Width = 447; - LB1.SmallImageList = img_streams; - LB1.View = View.Details; - LB1.FullRowSelect = true; - LB1.GridLines = true; - LB1.Columns.Add("", 130); - LB1.Columns.Add("", 295); - LB1.HeaderStyle = ColumnHeaderStyle.None; - LB1.Refresh(); - - TextBox titulo = new TextBox(); - titulo.Parent = frmInfo; - titulo.Top = 6; - titulo.Left = 14; - titulo.Width = 448; - titulo.TabIndex = 0; - var fuente = new System.Drawing.Font("Microsoft Sans Serif", 10, FontStyle.Bold); - titulo.BackColor = this.BackColor; - - titulo.Font = fuente; - titulo.BorderStyle = BorderStyle.Fixed3D; - titulo.TextAlign = HorizontalAlignment.Center; - titulo.ReadOnly = true; - - if (full_report == false) titulo.Text = Strings.multi_summary; - else titulo.Text = Strings.multi_full; - - Button boton_ok = new Button(); - boton_ok.Parent = frmInfo; - boton_ok.Left = 73; - boton_ok.Top = 650; - boton_ok.Width = 330; - boton_ok.Height = 27; - boton_ok.Text = Strings.close_win; - boton_ok.Click += new EventHandler(boton_ok_Click); - frmInfo.CancelButton = boton_ok; - - Button btn_next = new Button(); - btn_next.Parent = frmInfo; - btn_next.Left = 404; - btn_next.Top = 650; - btn_next.Width = 59; - btn_next.Height = 27; - btn_next.Text = Strings.next; - btn_next.Click += new EventHandler(btn_next_Click); - - Button btn_prev = new Button(); - btn_prev.Parent = frmInfo; - btn_prev.Left = 14; - btn_prev.Top = 650; - btn_prev.Width = 59; - btn_prev.Height = 27; - btn_prev.Text = Strings.prev0; - btn_prev.Click += new EventHandler(btn_prev_Click); - - String fichero = Path.GetFileName(listView1.SelectedItems[0].Text); - TextBox titulo2 = new TextBox(); - titulo2.Parent = frmInfo; - titulo2.Top = 34; - titulo2.Left = 14; - titulo2.Width = 440; - titulo2.BackColor = this.BackColor; - - titulo2.BorderStyle = BorderStyle.None; - titulo2.TextAlign = HorizontalAlignment.Center; - titulo2.ReadOnly = true; - - titulo2.Text = fichero; - - if (Settings.Default.dark_mode == true) - { - foreach (Control c in frmInfo.Controls) UpdateColorDark(c); - frmInfo.BackColor = Color.FromArgb(255, 64, 64, 64); - } - - int indx = 0; - List salida1 = new List(); - var font_item = new System.Drawing.Font("Microsoft Sans Serif", 8, FontStyle.Bold); - - String[] fields_mi = new string[] { "Format ", "Bit depth", "General", "Bit rate", "bit rate", "Duration", "Audio", "Frame rate ", "Width", "Height", "Color space", "Chroma subsampling", "Channel(s)", "Channel positions", "Sampling rate ", "Maximum bit rate", "File size", "Format profile", "Display aspect ratio", "Stream size", "Text", "Language", "Recorded date", "Performer", "Album", "Genre", "Track name" }; - - Process process = new System.Diagnostics.Process(); - process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; - process.StartInfo.FileName = file1; - process.StartInfo.Arguments = fullPath; - process.StartInfo.UseShellExecute = false; - process.StartInfo.CreateNoWindow = true; - process.StartInfo.RedirectStandardOutput = true; - process.StartInfo.StandardOutputEncoding = Encoding.UTF8; - process.Start(); - - while (!process.StandardOutput.EndOfStream) - { - salida1.Add(process.StandardOutput.ReadLine()); - } - process.WaitForExit(); - LB1.BeginUpdate(); - - foreach (String salida2 in salida1) - { - Boolean match = false; - if (full_report == false) - { - foreach (String str in fields_mi) - { - if (salida2.Contains(str)) - { - match = true; - break; - } - } - } - else match = true; - - if (salida2 == "" || salida2 == "Video" || match == true) - - { - int derecha = 0; - - if (!salida2.Contains(" : ")) - { - LB1.Items.Add(salida2.ToUpper()); - LB1.Items[indx].Font = font_item; - LB1.Items[indx].ForeColor = Color.DarkBlue; - if (salida2 != String.Empty) - { - LB1.Items[indx].SubItems[0].BackColor = Color.FromArgb(255, 220, 238, 255); - if (salida2.Contains("Video")) - { - LB1.Items[indx].ImageIndex = 0; - LB1.Items[indx].SubItems[0].BackColor = Color.FromArgb(255, 255, 242, 222); - } - if (salida2.Contains("Audio")) LB1.Items[indx].ImageIndex = 1; - if (salida2.Contains("Text")) LB1.Items[indx].ImageIndex = 2; - if (salida2.Contains("General")) - { - LB1.Items[indx].ImageIndex = 5; - LB1.Items[indx].SubItems[0].BackColor = Color.FromArgb(255, 255, 248, 220); - } - } - - indx = indx + 1; - } - else - - { - if (!salida2.Contains("SPF")) - { - LB1.Items.Add(salida2.Substring(0, salida2.LastIndexOf(" : ")).Replace(" ", "")); - derecha = salida2.Length - (salida2.LastIndexOf(" :")); - LB1.Items[indx].SubItems.Add(salida2.Substring(salida2.LastIndexOf(" :") + 4, derecha - 4).Replace("kb", "Kb")); - indx = indx + 1; - } - } - } - } - - for (int x = 0; x < 2; x++) - { - LB1.Items.RemoveAt(LB1.Items.Count - 1); - } - - int duraciones = 0; - String elemento = ""; - for (int i = 0; i < LB1.Items.Count; i++) - { - elemento = LB1.Items[i].Text; - - if (elemento.Contains(Strings.duration)) - { - duraciones = duraciones + 1; - - if (duraciones > 1) - { - LB1.Items.RemoveAt(i); - } - } - } - - foreach (ListViewItem item in LB1.Items) - { - if (item.Text == String.Empty) - { - item.Remove(); - } - } - LB1.EndUpdate(); - frmInfo.StartPosition = FormStartPosition.CenterParent; - this.Cursor = Cursors.Arrow; - frmInfo.ShowDialog(); - } - else - - { - MessageBox.Show(Strings.no_item_sel, Strings.information, MessageBoxButtons.OK, MessageBoxIcon.Information); - } - this.Cursor = Cursors.Arrow; - } - - private void button6_Click(object sender, EventArgs e) - { - Pg1.Focus(); - if (!File.Exists(Path.Combine(Application.StartupPath, "ffmpeg.exe"))) - { - MessageBox.Show(Strings.no_ffmpeg, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - folderBrowserDialog1.Description = Strings.not_subfolders; - if (add_subfs == true) - { - folderBrowserDialog1.Description = Strings.yes_subfolders; - } - - folderBrowserDialog1.ShowNewFolderButton = false; - - change_tab_1 = false; - change_tab_2 = false; - - list_not_empty = listView1.Items.Count > 0; - - if (tabControl1.SelectedIndex == 1) - { - change_tab_1 = true; - } - else if (tabControl1.SelectedIndex == 2) - { - change_tab_2 = true; - } - int fl = 0; - if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) - { - Form11_2 frm11_2 = new Form11_2(); - Task t2 = Task.Run(() => - { - frm11_2.label1.Text = Strings.reading_path; - frm11_2.ShowDialog(); - }); - Thread.Sleep(100); - List files2 = new List(); - - foreach (String file in Directory.GetFiles(folderBrowserDialog1.SelectedPath)) - { - if (!File.GetAttributes(file).HasFlag(FileAttributes.Hidden) && is_excluded(file) == false) - { - files2.Add(file); - fl = fl + 1; - if (frm11_2.abort_validate) return; - try - { - frm11_2.Invoke(new MethodInvoker(delegate - { - frm11_2.label2.Text = fl.ToString() + " " + Strings.files; - })); - } - catch { } - } - } - - int num_drop = files2.Count(); - - String f_err = String.Empty; - - if (add_subfs == true) - { - string[] dirs = Directory.GetDirectories(folderBrowserDialog1.SelectedPath); - - foreach (string ds in dirs) - { - try - { - foreach (string f in Directory.GetFiles(ds, "*.*", System.IO.SearchOption.AllDirectories)) - { - f_err = f; - if (!File.GetAttributes(f).HasFlag(FileAttributes.Hidden) && is_excluded(f) == false) - { - files2.Add(f); - fl = fl + 1; - num_drop++; - if (frm11_2.abort_validate) return; - try - { - frm11_2.Invoke(new MethodInvoker(delegate - { - frm11_2.label2.Text = fl.ToString() + " " + Strings.files; - })); - } - catch { } - } - } - } - catch (System.Exception excpt) - { - try - { - frm11_2.Invoke(new MethodInvoker(delegate - { - frm11_2.TopMost = true; - frm11_2.TopMost = false; - })); - } - catch { } - - DialogResult a = new DialogResult(); - if (excpt.HResult == -2147024893) - { - a = MessageBox.Show(Strings.err_long_path + Environment.NewLine + Environment.NewLine + f_err + Environment.NewLine + Environment.NewLine + Properties.Strings.contin, Strings.error3, MessageBoxButtons.OKCancel, MessageBoxIcon.Error); - } - else a = MessageBox.Show(Strings.error2 + " " + excpt.Message + " " + Strings.contin, Strings.error3, MessageBoxButtons.OKCancel, MessageBoxIcon.Error); - if (a == DialogResult.Cancel) - { - try - { - frm11_2.Invoke(new MethodInvoker(delegate - { - frm11_2.Dispose(); - })); - } - catch { } - return; - } - } - } - } - Thread.Sleep(100); - try - { - frm11_2.Invoke(new MethodInvoker(delegate - { - frm11_2.Dispose(); - })); - } - catch { } - - if (num_drop == 0) - { - MessageBox.Show(Strings.folder_empty, Strings.information, MessageBoxButtons.OK, MessageBoxIcon.Information); - return; - } - - files_to_add = files2; - canceled_file_adding = false; - btn_cancel_add.Enabled = true; - btn_cancel_add.Visible = true; - btn_cancel_add.Refresh(); - BG_Files.RunWorkerAsync(); - } - else from_wizard = false; - } - - private void ctdel_Click(object sender, EventArgs e) - { - if (listView1.SelectedItems.Count == 0) return; - - if (multi_running == true) - { - foreach (ListViewItem item in listView1.SelectedItems) - { - item.SubItems[5].Text = Strings.skipped; - if (item.SubItems[3].Text != Strings.n_a && item.SubItems[3].Text != "0:00:00" && item.SubItems[3].Text != "00:00:00" && item.SubItems[3].Text != Strings.pending) - { - if (Settings.Default.quick_queue == false) total_duration = total_duration - TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds; - } - } - return; - } - listView1.BeginUpdate(); - - if (working == false) - { - if (listView1.SelectedItems.Count < 1000) foreach (ListViewItem item in listView1.SelectedItems) listView1.Items.Remove(item); - else remove_selected(); - } - - if (working == true) - { - foreach (ListViewItem item in listView1.SelectedItems) if (item.SubItems[5].Text == Strings.queued) listView1.Items.RemoveAt(item.Index); - } - - listView1.EndUpdate(); - lbl_items.Text = listView1.Items.Count + " " + Strings.files; - - calc_total_dur(); - calc_list_size(); - - if (working == true && multi_running == false && Settings.Default.quick_queue == false) - { - total_duration = 0; - - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[3].Text != Strings.n_a && item.SubItems[3].Text != "0:00:00" && item.SubItems[3].Text != "00:00:00" && item.SubItems[3].Text != Strings.pending && item.SubItems[3].Text != "-") - { - total_duration = total_duration + TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds - TimeSpan.Parse(ss_time_input.Text).TotalSeconds; - } - else - { - total_duration = total_duration + 0; - } - } - } - } - - private void remove_selected() - { - List files2 = new List(); - int num_drop = 0; - - foreach (ListViewItem item in listView1.Items) - { - String filename = item.SubItems[1].Text + "\\" + item.Text; - if (File.Exists(filename) && item.Selected == false) - { - files2.Add(filename); - } - } - num_drop = files2.Count(); - - files_to_add = files2; - listView1.Items.Clear(); - - canceled_file_adding = false; - - btn_cancel_add.Enabled = true; - btn_cancel_add.Visible = true; - btn_cancel_add.Refresh(); - - BG_Files.RunWorkerAsync(); - } - - private void ctm_add_files_Click(object sender, EventArgs e) - { - this.btn_add_files.PerformClick(); - } - - private void ctm_add_folder_Click(object sender, EventArgs e) - { - this.btn_add_folders.PerformClick(); - } - - private void boton_ok_Click(object sender, System.EventArgs e) - { - Form.ActiveForm.Close(); - } - - private void btn_next_Click(object sender, System.EventArgs e) - { - Form.ActiveForm.Close(); - if (listView1.SelectedItems[0].Index < listView1.Items.Count - 1) - { - listView1.Items[listView1.SelectedIndices[0] + 1].Selected = true; - listView1.Items[listView1.SelectedIndices[0]].Selected = false; - listView1.Select(); - cti4.PerformClick(); - } - } - - private void btn_prev_Click(object sender, System.EventArgs e) - { - Form.ActiveForm.Close(); - if (listView1.SelectedItems[0].Index > 0) - { - int selected_item = listView1.SelectedIndices[0]; - listView1.Items[selected_item].Selected = false; - listView1.Items[selected_item - 1].Selected = true; - listView1.Select(); - cti4.PerformClick(); - } - } - - private void boton_ok_wave_Click(object sender, System.EventArgs e) - { - Form.ActiveForm.Close(); - } - - //private void boton_kill_Click(object sender, System.EventArgs e) - //{ - // cancelados_paralelos = true; - // cancel_queue = true; - - // Form.ActiveForm.Close(); - - // Process[] localByName = Process.GetProcessesByName("ffmpeg"); - // foreach (Process p in localByName) - // p.Kill(); - // System.Threading.Thread.Sleep(250); - // Process[] localByName2 = Process.GetProcessesByName("ffmpeg"); - // foreach (Process p2 in localByName2) - // p2.Kill(); - //} - - private void boton_ok_ff_Click(object sender, System.EventArgs e) - { - Form.ActiveForm.Close(); - this.InvokeEx(f => this.Enabled = true); - } - - private void boton_copy_ff_Click(object sender, System.EventArgs e) - { - String lista = String.Empty; - - for (int i = 0; i < LB1_o_try.Items.Count; i++) - { - lista = lista + Environment.NewLine + LB1_o_try.Items[i].ToString(); - } - - String temp_file = Path.Combine(Path.GetTempPath(), "temp_copy_clp.ff"); - if (File.Exists(temp_file)) - { - try - { - File.Delete(temp_file); - } - catch - { - MessageBox.Show(Strings.err_clipb); - } - } - - File.WriteAllText(Path.Combine(Path.GetTempPath(), "temp_copy_clp.ff"), lista); - Process.Start("notepad.exe", Path.Combine(Path.GetTempPath(), "temp_copy_clp.ff")); - } - - private void LB1_o_Click(object sender, System.EventArgs e) - { - //Form.ActiveForm.Close(); - } - - private void Timer_apaga_Tick(object sender, EventArgs e) - { - tiempo_apaga = tiempo_apaga - 1; - this.InvokeEx(f => TaskbarProgress.SetValue(this.Handle, 100, 100)); - - if (tiempo_apaga % 2 == 0) - { - TB1.ForeColor = Color.Black; - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.Paused)); - } - else - { - TB1.ForeColor = Color.DarkRed; - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.Error)); - } - - TB1.Text = Strings.computer_will + " " + combo_shut.SelectedItem.ToString().ToUpper() + " IN " + (tiempo_apaga / 2).ToString() + " " + Strings.seconds; - - if (tiempo_apaga == 0) - { - if (combo_shut.SelectedIndex == 0) - { - Process apagar = new System.Diagnostics.Process(); - apagar.StartInfo.FileName = "shutdown.exe"; - apagar.StartInfo.Arguments = "-s -t 60"; - apagar.StartInfo.CreateNoWindow = true; - apagar.Start(); - //Application.Exit(); - TB1.Text = Strings.autoshut_st; - } - else if (combo_shut.SelectedIndex == 1) Application.SetSuspendState(PowerState.Hibernate, true, true); - else if (combo_shut.SelectedIndex == 2) Application.SetSuspendState(PowerState.Suspend, true, true); - Timer_apaga.Stop(); - } - } - - private void disable_abort_btn() - { - this.Invoke(new MethodInvoker(delegate - { - btn_abort_all.Enabled = false; - tabControl1.Enabled = false; - btn_stop_m3u8.Enabled = false; - })); - } - - private void button10_Click(object sender, EventArgs e) - { - this.Invoke(new MethodInvoker(delegate - { - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.Normal); - TaskbarProgress.SetValue(this.Handle, 0, 100); - })); - - this.TopMost = false; - Enable_Controls(); - chkshut.Enabled = true; - btn_pause.Enabled = true; - txt_parameters.Enabled = true; - btn_save_config.Enabled = true; - btn_load_config.Enabled = true; - - chk_open_compl.Enabled = true; - - Timer_apaga.Stop(); - TB1.Visible = false; - TB1.Text = Strings.autoshut_en; - btn_cancel_shut.Visible = false; - - chkshut.CheckState = CheckState.Unchecked; - notifyIcon1.Visible = false; - txt_remain.Text = Strings.remain_time; - - if (tiempo_apaga == 0) - { - Process no_apagar = new System.Diagnostics.Process(); - no_apagar.StartInfo.FileName = "shutdown.exe"; - no_apagar.StartInfo.Arguments = "-a"; - no_apagar.StartInfo.UseShellExecute = false; - no_apagar.StartInfo.CreateNoWindow = true; - no_apagar.Start(); - } - tiempo_apaga = 120; - } - - private void comboBox1_DropDown(object sender, EventArgs e) - { - if (combo_presets.Text == "") - { - return; - } - - String path = String.Empty; - String path_pr = String.Empty; - - if (is_portable == false) - { - path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.ini"; - path_pr = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_presets.ini"; - } - else - { - path = port_path + "ff_batch_portable.ini"; - path_pr = port_path + "ff_presets_portable.ini"; - } - - if (combo_presets.SelectedIndex == 0) - { - int linea = 0; - foreach (string line in File.ReadLines(path)) - { - linea = linea + 1; - - if (linea == 1) - { - txt_parameters.Text = line; - } - else if (linea == 2) - { - txt_format.Text = line; - } - - if (line == "Yes") - - { - chk_open_compl.CheckState = CheckState.Checked; - } - - if (line == "No") - { - chk_open_compl.CheckState = CheckState.Unchecked; - } - } - } - else - { - if (File.Exists(path_pr)) path = path_pr; - foreach (string line in File.ReadLines(path)) - { - if (line.Contains(combo_presets.Text)) - { - int cortar = line.LastIndexOf("%") - line.LastIndexOf(" & "); - - txt_format.Text = line.Substring(line.LastIndexOf("%") + 2); - txt_parameters.Text = line.Substring(line.LastIndexOf(" & ") + 3, cortar - 3); - } - } - } - } - - Double get_dur_secs(String item) - { - TimeSpan t = new TimeSpan(); - if (TimeSpan.TryParse(item, out t)) { return t.TotalSeconds; } - else return 0; - } - private void button13_Click(object sender, EventArgs e) - { - Pg1.Focus(); - if (!File.Exists(Path.Combine(Application.StartupPath, "ffmpeg.exe"))) - { - MessageBox.Show(Strings.no_ffmpeg, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - String path = "cmd.exe"; - String param = String.Empty; - Process ff_ext = new Process(); - - String textbox_params = txt_parameters.Text; - String pre_i = txt_pre_input.Text; - String file_prueba = ""; - String file_prueba2 = ""; - Double dur_rpl = 0; - if (listView1.Items.Count > 0) - { - file_prueba = listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text; - dur_rpl = get_dur_secs(listView1.Items[0].SubItems[3].Text); - } - - if (listView1.Items.Count == 0) param = "/k " + "ffmpeg.exe -version " + '\u0022' + "chcp 65001 >nul " + '\u0022'; - else - { - if (send_par_consol == true) - { - if (!Directory.Exists(Path.GetTempPath() + "FFBatch_test")) - { - try - { - Directory.CreateDirectory(Path.GetTempPath() + "FFBatch_test"); - } - catch (Exception excpt) - { - MessageBox.Show(Strings.err_test_temp + Environment.NewLine + excpt.Message, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - } - } - //Variables - - - while (textbox_params.Contains("%fn")) - { - if (textbox_params.Contains("%fn")) - { - textbox_params = textbox_params.Replace("%fn", Path.GetFileNameWithoutExtension(file_prueba)); - } - } - - while (pre_i.Contains("%fn")) - { - if (pre_i.Contains("%fn")) - { - pre_i = pre_i.Replace("%fn", Path.GetFileNameWithoutExtension(file_prueba)); - } - } - - while (textbox_params.Contains("%ff")) - { - if (textbox_params.Contains("%ff")) - { - textbox_params = textbox_params.Replace("%ff", Path.GetFileName(file_prueba)); - } - } - - while (pre_i.Contains("%ff")) - { - if (pre_i.Contains("%ff")) - { - pre_i = pre_i.Replace("%ff", Path.GetFileName(file_prueba)); - } - } - - //%fdur variable operations - - //int count = Regex.Matches(textbox_params, pattern_dur).Count; - - String dur_secs = dur_rpl.ToString(); - String to_replace = String.Empty; - - while (textbox_params.Contains("%fdur")) - { - if (textbox_params.Contains("%fdur")) - { - to_replace = ""; - - int operador = textbox_params.LastIndexOf("%fdur") + 5; - int length = 0; - int limit = textbox_params.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(textbox_params.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace = textbox_params.Substring(textbox_params.LastIndexOf("%fdur"), 5 + length); - Double result = Convert.ToDouble(new DataTable().Compute(to_replace.Replace("%fdur", dur_secs), null)); - textbox_params = ReplaceLastOccurrence(textbox_params, to_replace, Math.Round(result).ToString()); - } - } - - while (pre_i.Contains("%fdur")) - { - - if (pre_i.Contains("%fdur")) - { - to_replace = ""; - - int operador = pre_i.LastIndexOf("%fdur") + 5; - int length = 0; - int limit = pre_i.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(pre_i.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace = pre_i.Substring(pre_i.LastIndexOf("%fdur"), 5 + length); - Double result = Convert.ToDouble(new DataTable().Compute(to_replace.Replace("%fdur", dur_secs), null)); - pre_i = ReplaceLastOccurrence(pre_i, to_replace, Math.Round(result).ToString()); - } - } - - //Bitrate variable - - dur_secs = get_bitrate(file_prueba, dur_rpl.ToString()).ToString(); - to_replace = String.Empty; - - while (textbox_params.Contains("%fbitr")) - { - if (textbox_params.Contains("%fbitr")) - { - to_replace = ""; - - int operador = textbox_params.LastIndexOf("%fbitr") + 6; - int length = 0; - int limit = textbox_params.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(textbox_params.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace = textbox_params.Substring(textbox_params.LastIndexOf("%fbitr"), 6 + length); - - Double result = Convert.ToDouble(new DataTable().Compute(to_replace.Replace("%fbitr", dur_secs), null)); - textbox_params = ReplaceLastOccurrence(textbox_params, to_replace, Math.Round(result).ToString() + "K"); - } - } - - while (pre_i.Contains("%fbitr")) - { - if (pre_i.Contains("%fbitr")) - { - to_replace = ""; - - int operador = pre_i.LastIndexOf("%fbitr") + 6; - int length = 0; - int limit = pre_i.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(pre_i.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace = pre_i.Substring(pre_i.LastIndexOf("%fbitr"), 6 + length); - - Double result = Convert.ToDouble(new DataTable().Compute(to_replace.Replace("%fbitr", dur_secs), null)); - pre_i = ReplaceLastOccurrence(pre_i, to_replace, Math.Round(result).ToString() + "K"); - } - } - - //End bitrate variable - - //Target size - if (textbox_params.Contains("[[target_size=")) - { - int f = textbox_params.IndexOf("[[target_size=") + 14; - int mb = textbox_params.IndexOf("MB"); - int l = textbox_params.IndexOf("Kbps]]"); - Double target_mb = Convert.ToDouble(textbox_params.Substring(f, mb - f)); - String aud_bitr = textbox_params.Substring(mb + 3, l - mb - 3); - String replaced = get_bitrate_target(target_mb, dur_rpl, Convert.ToDecimal(aud_bitr)).ToString(); - to_replace = textbox_params.Substring(f - 14, l - f + 14 + 6); - textbox_params = textbox_params.Replace(to_replace, replaced); - } - - //End target size - - while (textbox_params.Contains("%fp")) - { - if (textbox_params.Contains("%fp")) - { - textbox_params = textbox_params.Replace("%fp", Path.GetDirectoryName(file_prueba)); - } - } - - while (pre_i.Contains("%fp")) - { - if (pre_i.Contains("%fp")) - { - pre_i = pre_i.Replace("%fp", Path.GetDirectoryName(file_prueba)); - } - } - - while (textbox_params.Contains("%fd")) - { - if (textbox_params.Contains("%fd")) - { - var dirName = new DirectoryInfo(Path.GetDirectoryName(file_prueba)).Name; - textbox_params = textbox_params.Replace("%fd", dirName); - } - } - - while (pre_i.Contains("%fd")) - { - if (pre_i.Contains("%fd")) - { - var dirName = new DirectoryInfo(Path.GetDirectoryName(file_prueba)).Name; - pre_i = pre_i.Replace("%fd", dirName); - } - } - - while (textbox_params.Contains("%1")) - { - if (textbox_params.Contains("%1")) - { - file_prueba2 = file_prueba2.Replace("\\", "\\\\\\\\"); - file_prueba2 = file_prueba2.Replace(":", ":" + "\\\\"); - textbox_params = textbox_params.Replace("%1", '\u0022' + file_prueba2 + '\u0022'); - } - } - - while (pre_i.Contains("%1")) - { - if (pre_i.Contains("%1")) - { - file_prueba2 = file_prueba2.Replace("\\", "\\\\\\\\"); - file_prueba2 = file_prueba2.Replace(":", ":" + "\\\\"); - pre_i = pre_i.Replace("%1", '\u0022' + file_prueba2 + '\u0022'); - } - } - - while (textbox_params.Contains("%2")) - { - if (textbox_params.Contains("%2")) - { - file_prueba2 = file_prueba2.Replace("\\", "\\\\\\\\"); - file_prueba2 = file_prueba2.Replace(":", ":" + "\\\\"); - textbox_params = textbox_params.Replace("%2", '\u0022' + Path.Combine(Path.GetDirectoryName(file_prueba2), Path.GetFileNameWithoutExtension(file_prueba2)) + '\u0022'); - } - } - - while (pre_i.Contains("%2")) - { - if (pre_i.Contains("%2")) - { - file_prueba2 = file_prueba2.Replace("\\", "\\\\\\\\"); - file_prueba2 = file_prueba2.Replace(":", ":" + "\\\\"); - pre_i = pre_i.Replace("%2", '\u0022' + Path.Combine(Path.GetDirectoryName(file_prueba2), Path.GetFileNameWithoutExtension(file_prueba2)) + '\u0022'); - } - } - //End variables - - param = "/k " + "ffmpeg.exe " + pre_i + " -i " + '\u0022' + listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text + '\u0022' + " " + textbox_params + " -y " + '\u0022' + Path.GetTempPath() + "FFBatch_test" + "\\" + Path.GetFileNameWithoutExtension(listView1.Items[0].Text) + "." + txt_format.Text + '\u0022'; - Clipboard.SetText(param.Substring(3, param.Length - 3)); - } - else param = "/k " + "ffmpeg.exe -version " + '\u0022' + "chcp 65001 >nul " + '\u0022'; - } - - ff_ext.StartInfo.FileName = path; - ff_ext.StartInfo.Arguments = param; - ff_ext.Start(); - if (listView1.Items.Count == 0) Clipboard.GetText(); - ff_ext.WaitForExit(); - } - - private void chkshut_CheckedChanged(object sender, EventArgs e) - { - Pg1.Focus(); - if (btn_cancel_shut.Visible == true) - { - return; - } - - if (chkshut.Checked == false) - { - TB1.Visible = false; - chkshut.ImageIndex = 0; - combo_shut.Enabled = false; - group_prog.Focus(); - lbl_after_enc.Enabled = false; - } - else - { - chkshut.ImageIndex = 1; - combo_shut.Enabled = true; - chk_delete_source.CheckState = CheckState.Unchecked; - lbl_after_enc.Enabled = true; - } - } - - private void drop_files(String[] files_drop) - { - listView1.BackgroundImage = null; - if (Settings.Default.dark_mode == false) listView1.BackColor = SystemColors.Window; - else listView1.BackColor = Color.FromArgb(255, 64, 64, 64); - - change_tab_1 = false; - change_tab_2 = false; - - string[] file_drop = (string[])files_drop; - - List files2 = new List(); - - int num_drop = 0; - - //Load queue file - - if (file_drop.Count() == 1 && Path.GetExtension(file_drop[0]) == ".ffq") - { - int linea = 0; - int not_found = 0; - combo_presets.Text = ""; - List itemsToAdd = new List(); - - foreach (string line in File.ReadLines(file_drop[0])) - { - if (linea == 0) - { - txt_parameters.Text = line; - } - else if (linea == 1) - { - txt_format.Text = line; - } - else if (linea == 2) - { - chk_recreate.CheckState = line == "Unchecked" ? CheckState.Unchecked : CheckState.Checked; - } - - else if (linea == 3) - { - if (line == "Unchecked") chk_suffix.CheckState = CheckState.Unchecked; - else - { - chk_suffix.CheckState = CheckState.Checked; - txt_suffix.Text = line; - } - } - else if (linea == 4) - { - txt_path_main.Text = line; - } - else if (linea > 4) - { - Boolean missing = false; - listView1.SmallImageList = imageList2; - - itemsToAdd.Add(new ListViewItem(Path.GetFileName(line.Substring(0, line.LastIndexOf(" --0 "))), 1)); - //ListViewItem elemento = new ListViewItem(line.Substring(0, line.LastIndexOf(" --0 ")), 1); - //Begin get file icon - - Icon iconForFile = SystemIcons.WinLogo; - - // Check to see if the image collection contains an image - // for this extension, using the extension as a key. - if (File.Exists(line.Substring(0, line.LastIndexOf(" --0 ")))) - { - - if (line.Substring(0, 2) != "\\\\") - { - if (!imageList2.Images.ContainsKey(Path.GetExtension(line.Substring(0, line.LastIndexOf(" --0 "))))) - { - // If not, add the image to the image list. - iconForFile = System.Drawing.Icon.ExtractAssociatedIcon(line.Substring(0, line.LastIndexOf(" --0 "))); - imageList2.Images.Add(Path.GetExtension(line.Substring(0, line.LastIndexOf(" --0 "))), iconForFile); - } - //listView1.Items.Add(elemento); - itemsToAdd[linea - 5].ImageKey = Path.GetExtension(Path.GetExtension(line.Substring(0, line.LastIndexOf(" --0 ")))); - } - else - { - itemsToAdd[linea - 5].ImageIndex = 0; - } - } - - else - { - not_found = not_found + 1; - missing = true; - } - - String type = line.Substring(line.LastIndexOf(" --0 ") + 5, line.Length - (line.LastIndexOf(" --0") + 5)); - type = type.Substring(0, type.LastIndexOf(" --1")); - String dur = line.Substring(line.LastIndexOf(" --1 ") + 5, line.Length - (line.LastIndexOf(" --1") + 5)); - dur = dur.Substring(0, dur.LastIndexOf(" --2")); - String size = line.Substring(line.LastIndexOf(" --2 ") + 5, line.Length - (line.LastIndexOf(" --2") + 5)); - size = size.Substring(0, size.LastIndexOf(" --3")); - String status = line.Substring(line.LastIndexOf(" --3 ") + 5, line.Length - (line.LastIndexOf(" --3") + 5)); - - itemsToAdd[linea - 5].SubItems.Add(Path.GetDirectoryName(line.Substring(0, line.LastIndexOf(" --0 ")))); - itemsToAdd[linea - 5].SubItems.Add(type); - itemsToAdd[linea - 5].SubItems.Add(dur); - itemsToAdd[linea - 5].SubItems.Add(size); - if (missing == false) itemsToAdd[linea - 5].SubItems.Add(status); - else - { - itemsToAdd[linea - 5].SubItems.Add(Strings.file_not_f); - itemsToAdd[linea - 5].BackColor = Color.LightGoldenrodYellow; - } - } - linea = linea + 1; - } - listView1.Items.AddRange(itemsToAdd.ToArray()); - - this.Cursor = Cursors.Arrow; - - if (tabControl1.SelectedIndex == 0) - { - calc_list_size(); - calc_total_dur(); - lbl_items.Text = listView1.Items.Count.ToString() + " " + Strings.files; - - if (not_found > 0 && no_warn_0_dur == false) - { - this.Cursor = Cursors.Arrow; - MessageBox.Show(Strings.queue_ok + Environment.NewLine + not_found.ToString() + " " + Strings.queue_not_f + " " + Environment.NewLine + Environment.NewLine + Strings.sort_status + " " + '\u0022' + Strings.file_not_f + '\u0022' + ".", Strings.missing_f, MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - this.Cursor = Cursors.Arrow; - if (start_seq == true) - { - if (start_multi == false) btn_seq.PerformClick(); - else btn_multi_m.PerformClick(); - } - return; - } - } - //End load queue file - - int fl = 0; - Form11_2 frm11_2 = new Form11_2(); - frm11_2.TopMost = true; - - if (files2.Count > 500) - { - Task t2 = Task.Run(() => - { - frm11_2.label1.Text = Strings.reading_path; - frm11_2.ShowDialog(); - }); - - } - Thread.Sleep(100); - String f_err = String.Empty; - - foreach (String dropped in file_drop) - { - if (Path.GetFileNameWithoutExtension(dropped).Contains("~1")) - { - MessageBox.Show(Strings.err_long_path + Environment.NewLine + Environment.NewLine + dropped, Strings.error3, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (File.Exists(dropped) && is_excluded(dropped) == false) - { - files2.Add(dropped); - num_drop = files2.Count(); - - if (frm11_2.abort_validate) return; - else - { - try - { - frm11_2.Invoke(new MethodInvoker(delegate - { - frm11_2.label2.Text = fl.ToString() + " " + Strings.files; - })); - } - catch { } - } - } - else - { - if (Directory.Exists(dropped)) - { - if (add_subfs == false) - { - foreach (String file in Directory.GetFiles(dropped)) - { - if (!File.GetAttributes(file).HasFlag(FileAttributes.Hidden) && is_excluded(file) == false) - { - files2.Add(file); - fl = fl + 1; - num_drop = num_drop + 1; - - if (frm11_2.abort_validate) return; - else - { - try - { - frm11_2.Invoke(new MethodInvoker(delegate - { - frm11_2.label2.Text = fl.ToString() + " " + Strings.files; - })); - } - catch { } - } - } - } - } - else - { - try - { - foreach (string f in Directory.GetFiles(dropped, "*.*", System.IO.SearchOption.AllDirectories)) - { - f_err = f; - if (!File.GetAttributes(f).HasFlag(FileAttributes.Hidden) && is_excluded(f) == false) - { - files2.Add(f); - fl = fl + 1; - num_drop = num_drop + 1; - - if (frm11_2.abort_validate == true) return; - else - { - try - { - frm11_2.Invoke(new MethodInvoker(delegate - { - frm11_2.label2.Text = fl.ToString() + " " + Strings.files; - })); - } - catch { } - } - } - } - } - catch (System.Exception excpt) - { - try - { - frm11_2.Invoke(new MethodInvoker(delegate - { - frm11_2.TopMost = true; - frm11_2.TopMost = false; - })); - } - catch { } - try - { - frm11_2.Invoke(new MethodInvoker(delegate - { - frm11_2.Dispose(); - })); - } - catch { } - - - if (excpt.HResult == -2147024893) - { - MessageBox.Show(Strings.err_long_path + Environment.NewLine + Environment.NewLine + f_err, Strings.error3, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - else MessageBox.Show(Strings.error2 + " " + excpt.Message, Strings.error3, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - } - } - } - - Thread.Sleep(100); - try - { - frm11_2.Invoke(new MethodInvoker(delegate - { - frm11_2.Dispose(); - })); - } - catch { } - - files_to_add = files2; - canceled_file_adding = false; - btn_cancel_add.Enabled = true; - btn_cancel_add.Visible = true; - btn_cancel_add.Refresh(); - BG_Files.RunWorkerAsync(); - } - - private Boolean is_excluded(String str0) - { - String ext = Path.GetExtension(str0).TrimStart('.'); - Boolean excluded = false; - foreach (String str in Settings.Default.excl_list) - { - if (str.ToLower() == ext.ToLower()) - { - return true; - break; - } - } - return false; - } - - private void listView1_DragDrop(object sender, DragEventArgs e) - { - string[] file_drop = (string[])e.Data.GetData(DataFormats.FileDrop); - this.TopMost = true; - drop_files(file_drop); - this.TopMost = false; - this.Activate(); - } - - private void listView1_DragEnter(object sender, DragEventArgs e) - { - if (e.Data.GetDataPresent(DataFormats.FileDrop, false)) - - { - e.Effect = DragDropEffects.All; - if (Settings.Default.dark_mode == true) listView1.BackColor = Color.FromArgb(255, 128, 128, 128); - else - { - using (Bitmap bmp1 = new Bitmap(listView1.ClientSize.Width, listView1.ClientSize.Height - 24)) - { - using (var g1 = Graphics.FromImage(bmp1)) - { - g1.DrawImage(pic_drag.Image, 0, 0, bmp1.Width, bmp1.Height); - listView1.BackgroundImage = bmp1; - } - } - } - } - else - { - e.Effect = DragDropEffects.None; - } - } - private void listView1_KeyUp(object sender, KeyEventArgs e) - { - if (e.KeyCode != Keys.Delete || multi_running == true) return; - - if (working == true) - { - Boolean remove = true; - foreach (ListViewItem item in listView1.SelectedItems) - { - if (item.SubItems[5].Text != Strings.queued) - { - remove = false; - break; - } - } - - if (e.KeyCode == Keys.Delete && remove == true) - { - ctdel.PerformClick(); - } - return; - } - - if (e.KeyCode == Keys.Delete) - { - ctdel.PerformClick(); - } - } - - private void listView1_DoubleClick(object sender, EventArgs e) - { - media_info(); - } - - private void listView1_ColumnClick(object sender, ColumnClickEventArgs e) - { - if (working == true) return; - System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentUICulture; - String separator = ci.NumberFormat.NumberDecimalSeparator; - String sep_th = ci.NumberFormat.CurrencyGroupSeparator; - - ListView myListView = (ListView)sender; - - if (e.Column == 4) - { - lvwColumnSorter_Full.SortColumn = 4; - if (size_sorted == false) - { - size_sorted = true; - lvwColumnSorter_Full.Order = SortOrder.Descending; - } - else - { - size_sorted = false; - lvwColumnSorter_Full.Order = SortOrder.Ascending; - } - - if (listView1.Items.Count > 6000) this.Cursor = Cursors.WaitCursor; - listView1.BeginUpdate(); - - foreach (ListViewItem item in listView1.Items) - { - String filename = item.SubItems[1].Text + "\\" + item.Text; - if (File.Exists(filename)) - { - FileInfo fi = new FileInfo(filename); - item.SubItems[4].Text = fi.Length.ToString("D13"); - } - else - { - item.SubItems[4].Text = "0000000000000"; - } - } - ColumnHeader new_sorting_column = listView1.Columns[e.Column]; - - // Figure out the new sorting order. - - System.Data.SqlClient.SortOrder sort_order; - if (SortingColumn == null) - { - // New column. Sort ascending. - sort_order = System.Data.SqlClient.SortOrder.Ascending; - } - else - { - // See if this is the same column. - if (new_sorting_column == SortingColumn) - { - // Same column. Switch the sort order. - if (SortingColumn.Text.StartsWith("< ")) - { - sort_order = System.Data.SqlClient.SortOrder.Descending; - } - else - { - sort_order = System.Data.SqlClient.SortOrder.Ascending; - } - } - else - { - // New column. Sort ascending. - sort_order = System.Data.SqlClient.SortOrder.Ascending; - } - - // Remove the old sort indicator. - SortingColumn.Text = SortingColumn.Text.Substring(2); - } - - // Display the new sort order. - SortingColumn = new_sorting_column; - if (sort_order == System.Data.SqlClient.SortOrder.Ascending) - { - SortingColumn.Text = "< " + SortingColumn.Text; - } - else - { - SortingColumn.Text = "> " + SortingColumn.Text; - } - - // Create a comparer. - listView1.ListViewItemSorter = - new ListViewComparer(e.Column, sort_order); - - // Sort. - listView1.Sort(); - - foreach (ListViewItem item in listView1.Items) - { - //Format size view - long bytes = long.Parse(item.SubItems[4].Text); - - Double kilobytes = (double)bytes / 1024; - Double megabytes = kilobytes / 1024; - Double gigabytes = megabytes / 1024; - - String size = ""; - - if (bytes > 1000000000) - { - String gigas = gigabytes.ToString(); - if (gigas.Length >= 5) - { - gigas = gigas.Substring(0, gigas.LastIndexOf(separator) + 3); - size = (gigas + " " + "GB"); - } - else - { - size = (gigas + " " + "GB"); - } - } - - if (bytes >= 1048576 && bytes <= 1000000000) - { - String megas = megabytes.ToString(); - if (megas.Length > 5) - { - megas = megas.Substring(0, megas.LastIndexOf(separator) + 2); - size = (megas + " " + "MB"); - } - else - { - size = (megas + " " + "MB"); - } - } - - if (bytes >= 1024 && bytes < 1048576) - - { - String kbs = kilobytes.ToString(); - if (kbs.Length >= 5) - { - kbs = kbs.Substring(0, kbs.LastIndexOf(separator)); - size = (kbs + " " + "KB"); - } - else - { - size = (kbs + " " + "KB"); - } - } - if (bytes > -1 && bytes < 1024) - { - String bits = bytes.ToString(); - size = (bits + " Bytes"); - } - item.SubItems[4].Text = size; - - //End Format size view - } - this.Cursor = Cursors.Arrow; - listView1.EndUpdate(); - } - - if (e.Column != 4) - { - if (listView1.Columns[e.Column].Text.Contains(Strings.v_bitr)) - { - lvwColumnSorter_Full.SortColumn = listView1.Columns[e.Column].Index; - if (size_sorted == false) - { - size_sorted = true; - lvwColumnSorter_Full.Order = SortOrder.Descending; - } - else - { - size_sorted = false; - lvwColumnSorter_Full.Order = SortOrder.Ascending; - } - - if (listView1.Items.Count > 6000) this.Cursor = Cursors.WaitCursor; - listView1.BeginUpdate(); - - foreach (ListViewItem item in listView1.Items) - { - String filename = item.SubItems[1].Text + "\\" + item.Text; - if (item.SubItems[e.Column].Text.Length < 1) item.SubItems[e.Column].Text = "-"; - String subit = "0"; - - if (File.Exists(filename)) - { - //Format size view - - subit = item.SubItems[e.Column].Text; - - Boolean has_dot = false; - if (subit.Contains(".") || subit.Contains(",")) - { - has_dot = true; - subit = subit.Replace(".", separator); - subit = subit.Replace(",", separator); - } - //subit = Regex.Replace(subit, "[^.0-9]", ""); - - int pad = 0; - if (item.SubItems[e.Column].Text.ToLower().Contains("kb/s")) - { - if (has_dot == true) - { - subit = subit.Substring(0, subit.Length - 1); - } - - pad = 16 - subit.Length; - for (int ii = 0; ii < pad; ii++) subit = "0" + subit; - } - if (item.SubItems[e.Column].Text.ToLower().Contains("mb/s") || item.SubItems[e.Column].Text.ToLower().Contains("gb/s")) - { - if (has_dot == false) subit = subit + "000"; - else subit = (subit + "00"); - //subit = subit.Replace(sep_th, " "); - pad = 16 - subit.Length; - for (int ii = 0; ii < pad; ii++) subit = "0" + subit; - - } - if (item.SubItems[e.Column].Text.ToLower().Contains("gb/s")) - { - if (has_dot == false) subit = subit + "0000"; - else subit = subit + "000"; - pad = 16 - subit.Length; - for (int ii = 0; ii < pad; ii++) subit = "0" + subit; - } - subit = Regex.Replace(subit, "[^.0-9]", "").Replace(separator, ""); - item.SubItems[e.Column].Text = subit; - } - else - { - item.SubItems[e.Column].Text = "-"; - } - - if (item.SubItems[e.Column].Text.Length == 0) - { - item.SubItems[e.Column].Text = "-"; - } - } - - ColumnHeader new_sorting_column = listView1.Columns[e.Column]; - - // Figure out the new sorting order. - - System.Data.SqlClient.SortOrder sort_order; - if (SortingColumn == null) - { - // New column. Sort ascending. - sort_order = System.Data.SqlClient.SortOrder.Ascending; - } - else - { - // See if this is the same column. - if (new_sorting_column == SortingColumn) - { - // Same column. Switch the sort order. - if (SortingColumn.Text.StartsWith("< ")) - { - sort_order = System.Data.SqlClient.SortOrder.Descending; - } - else - { - sort_order = System.Data.SqlClient.SortOrder.Ascending; - } - } - else - { - // New column. Sort ascending. - sort_order = System.Data.SqlClient.SortOrder.Ascending; - } - - // Remove the old sort indicator. - SortingColumn.Text = SortingColumn.Text.Substring(2); - } - - // Display the new sort order. - SortingColumn = new_sorting_column; - if (sort_order == System.Data.SqlClient.SortOrder.Ascending) - { - SortingColumn.Text = "< " + SortingColumn.Text; - } - else - { - SortingColumn.Text = "> " + SortingColumn.Text; - } - - // Create a comparer. - listView1.ListViewItemSorter = - new ListViewComparer(e.Column, sort_order); - - // Sort. - listView1.Sort(); - - foreach (ListViewItem item in listView1.Items) - { - String size = "0"; - if (String.IsNullOrWhiteSpace(item.SubItems[e.Column].Text.Trim('0')) == false && item.SubItems[e.Column].Text != "-") size = item.SubItems[e.Column].Text.TrimStart('0'); - //if (item.SubItems[e.Column].Text != "-" && item.SubItems[e.Column].Text != "0000000000000000" && item.SubItems[e.Column].Text != "000000000000") size = item.SubItems[e.Column].Text.TrimStart('0'); - - Decimal bytes = Decimal.Parse(size); - - if (bytes > 10000000) size = (bytes / 1000000) + " " + "Gb/s"; - if (bytes >= 10000 && bytes < 10000000) - { - size = (bytes / 1000) + " " + "Mb/s"; - // if (size.Length == 9) size = (size.Substring(0, 1) + sep_th + size.Substring(1, size.Length - 1)); - } - - //if (bytes < 100000 && bytes > 10000) size = bytes / 1000 + " " + "Mb/s"; - if (bytes < 10000) size = bytes + " " + "Kb/s"; - - //if (bytes > -1 && bytes < 1024) { size = (bytes) + " " + "b/s"; } - item.SubItems[e.Column].Text = size; - - //End Format size view - } - this.Cursor = Cursors.Arrow; - listView1.EndUpdate(); - } - else if (listView1.Columns[e.Column].Text.Contains(Strings.a_bitr)) - { - lvwColumnSorter_Full.SortColumn = listView1.Columns[e.Column].Index; - if (size_sorted == false) - { - size_sorted = true; - lvwColumnSorter_Full.Order = SortOrder.Descending; - } - else - { - size_sorted = false; - lvwColumnSorter_Full.Order = SortOrder.Ascending; - } - - if (listView1.Items.Count > 6000) this.Cursor = Cursors.WaitCursor; - listView1.BeginUpdate(); - - foreach (ListViewItem item in listView1.Items) - { - String filename = item.SubItems[1].Text + "\\" + item.Text; - if (item.SubItems[e.Column].Text.Length < 1) item.SubItems[e.Column].Text = "-"; - String subit = "0"; - - if (File.Exists(filename)) - { - //Format size view - - subit = item.SubItems[e.Column].Text; - - Boolean has_dot = false; - if (subit.Contains(".") || subit.Contains(",")) - { - has_dot = true; - subit = subit.Replace(".", separator); - subit = subit.Replace(",", separator); - } - subit = Regex.Replace(subit, "[^.0-9]", ""); - - int pad = 0; - if (item.SubItems[e.Column].Text.ToLower().Contains("kb/s")) - { - if (has_dot == true) - { - subit = subit.Substring(0, subit.Length - 1); - } - - pad = 16 - subit.Length; - for (int ii = 0; ii < pad; ii++) subit = "0" + subit; - } - if (item.SubItems[e.Column].Text.ToLower().Contains("mb/s") || item.SubItems[e.Column].Text.ToLower().Contains("gb/s")) - { - if (has_dot == false) subit = subit + "000"; - else subit = (subit + "00"); - - pad = 16 - subit.Length; - for (int ii = 0; ii < pad; ii++) subit = "0" + subit; - } - if (item.SubItems[e.Column].Text.ToLower().Contains("gb/s")) - { - if (has_dot == false) subit = subit + "0000"; - else subit = subit + "000"; - pad = 16 - subit.Length; - for (int ii = 0; ii < pad; ii++) subit = "0" + subit; - } - item.SubItems[e.Column].Text = subit; - } - else - { - item.SubItems[e.Column].Text = "-"; - } - - if (item.SubItems[e.Column].Text == "-" || item.SubItems[e.Column].Text.Length == 0) - { - item.SubItems[e.Column].Text = "-"; - } - } - - ColumnHeader new_sorting_column = listView1.Columns[e.Column]; - - // Figure out the new sorting order. - - System.Data.SqlClient.SortOrder sort_order; - if (SortingColumn == null) - { - // New column. Sort ascending. - sort_order = System.Data.SqlClient.SortOrder.Ascending; - } - else - { - // See if this is the same column. - if (new_sorting_column == SortingColumn) - { - // Same column. Switch the sort order. - if (SortingColumn.Text.StartsWith("< ")) - { - sort_order = System.Data.SqlClient.SortOrder.Descending; - } - else - { - sort_order = System.Data.SqlClient.SortOrder.Ascending; - } - } - else - { - // New column. Sort ascending. - sort_order = System.Data.SqlClient.SortOrder.Ascending; - } - - // Remove the old sort indicator. - SortingColumn.Text = SortingColumn.Text.Substring(2); - } - - // Display the new sort order. - SortingColumn = new_sorting_column; - if (sort_order == System.Data.SqlClient.SortOrder.Ascending) - { - SortingColumn.Text = "< " + SortingColumn.Text; - } - else - { - SortingColumn.Text = "> " + SortingColumn.Text; - } - - // Create a comparer. - listView1.ListViewItemSorter = - new ListViewComparer(e.Column, sort_order); - - // Sort. - listView1.Sort(); - - foreach (ListViewItem item in listView1.Items) - { - String size = "0"; - if (item.SubItems[e.Column].Text != "-" && item.SubItems[e.Column].Text != "0000000000000000") size = item.SubItems[e.Column].Text.TrimStart('0'); - - Decimal bytes = Decimal.Parse(size); - - if (bytes > 10000000) size = (bytes / 1000000) + " " + "Gb/s"; - if (bytes >= 10000 && bytes < 10000000) - { - size = (bytes / 1000) + " " + "Mb/s"; - // if (size.Length == 9) size = (size.Substring(0, 1) + sep_th + size.Substring(1, size.Length - 1)); - } - - //if (bytes < 100000 && bytes > 10000) size = bytes / 1000 + " " + "Mb/s"; - if (bytes < 10000) size = bytes + " " + "Kb/s"; - - //if (bytes > -1 && bytes < 1024) { size = (bytes) + " " + "b/s"; } - item.SubItems[e.Column].Text = size; - - //End Format size view - } - this.Cursor = Cursors.Arrow; - listView1.EndUpdate(); - } - else if (listView1.Columns[e.Column].Text.Contains(Strings.bitrate)) - { - - lvwColumnSorter_Full.SortColumn = listView1.Columns[e.Column].Index; - if (size_sorted == false) - { - size_sorted = true; - lvwColumnSorter_Full.Order = SortOrder.Descending; - } - else - { - size_sorted = false; - lvwColumnSorter_Full.Order = SortOrder.Ascending; - } - - if (listView1.Items.Count > 6000) this.Cursor = Cursors.WaitCursor; - listView1.BeginUpdate(); - - foreach (ListViewItem item in listView1.Items) - { - String filename = item.SubItems[1].Text + "\\" + item.Text; - if (item.SubItems[e.Column].Text.Length < 1) item.SubItems[e.Column].Text = "-"; - String subit = "0"; - - if (File.Exists(filename)) - { - //Format size view - - subit = item.SubItems[e.Column].Text; - if (subit.ToLower().Contains("mb/s")) subit = subit + "000"; - if (subit.ToLower().Contains("gb/s")) subit = subit + "000000"; - int c_ths = 0; - if (subit.Contains(sep_th)) - { - c_ths = subit.Count(f => f == Convert.ToChar(sep_th)); - subit = subit.Replace(sep_th, ""); - } - if (subit.Contains(separator)) - { - subit = subit.Replace(separator, ""); - subit = subit.Substring(0, subit.Length - 1); - } - subit = Regex.Replace(subit, "[^0-9]", ""); - - int pad = 0; - - //if (c_ths == 1) subit = subit + "0"; - //if (c_ths == 2) subit = subit + "00"; - //if (c_ths == 3) subit = subit + "000"; - pad = 16 - subit.Length; - for (int ii = 0; ii < pad; ii++) subit = "0" + subit; - - - - item.SubItems[e.Column].Text = subit; - } - else - { - item.SubItems[e.Column].Text = "-"; - } - - if (item.SubItems[e.Column].Text.Length == 0) - { - item.SubItems[e.Column].Text = "-"; - } - } - - ColumnHeader new_sorting_column = listView1.Columns[e.Column]; - - // Figure out the new sorting order. - - System.Data.SqlClient.SortOrder sort_order; - if (SortingColumn == null) - { - // New column. Sort ascending. - sort_order = System.Data.SqlClient.SortOrder.Ascending; - } - else - { - // See if this is the same column. - if (new_sorting_column == SortingColumn) - { - // Same column. Switch the sort order. - if (SortingColumn.Text.StartsWith("< ")) - { - sort_order = System.Data.SqlClient.SortOrder.Descending; - } - else - { - sort_order = System.Data.SqlClient.SortOrder.Ascending; - } - } - else - { - // New column. Sort ascending. - sort_order = System.Data.SqlClient.SortOrder.Ascending; - } - - // Remove the old sort indicator. - SortingColumn.Text = SortingColumn.Text.Substring(2); - } - - // Display the new sort order. - SortingColumn = new_sorting_column; - if (sort_order == System.Data.SqlClient.SortOrder.Ascending) - { - SortingColumn.Text = "< " + SortingColumn.Text; - } - else - { - SortingColumn.Text = "> " + SortingColumn.Text; - } - - // Create a comparer. - listView1.ListViewItemSorter = - new ListViewComparer(e.Column, sort_order); - - // Sort. - listView1.Sort(); - - foreach (ListViewItem item in listView1.Items) - { - String size = "0"; - if (item.SubItems[e.Column].Text != "-" && item.SubItems[e.Column].Text != "0000000000000000" && item.SubItems[e.Column].Text.Length > 0) size = item.SubItems[e.Column].Text.TrimStart('0'); - - Decimal bytes = 0; - try { bytes = Decimal.Parse(size); } catch { } - - if (bytes >= 1000000) size = (bytes / 1000000).ToString("#,##0.0") + " " + "Gb/s"; - if (bytes >= 10000 && bytes < 1000000) - { - size = (bytes / 1000).ToString("#,##0.0") + " " + "Mb/s"; - //if (size.Length == 9) size = (size.Substring(0, 1) + sep_th + size.Substring(1, size.Length - 1)); - } - - ////if (bytes < 100000 && bytes > 10000) size = bytes / 1000 + " " + "Mb/s"; - if (bytes < 10000) size = bytes.ToString("#,##0") + " " + "Kb/s"; - //size = bytes.ToString("#,##0") + " " + "Kb/s"; - - //if (bytes > -1 && bytes < 1024) { size = (bytes) + " " + "b/s"; } - item.SubItems[e.Column].Text = size; - - //End Format size view - } - this.Cursor = Cursors.Arrow; - listView1.EndUpdate(); - } - - //Rest of columns - else - { - ColumnHeader new_sorting_column = listView1.Columns[e.Column]; - - // Figure out the new sorting order. - - System.Data.SqlClient.SortOrder sort_order; - if (SortingColumn == null) - { - // New column. Sort ascending. - sort_order = System.Data.SqlClient.SortOrder.Ascending; - } - else - { - // See if this is the same column. - if (new_sorting_column == SortingColumn) - { - // Same column. Switch the sort order. - if (SortingColumn.Text.StartsWith("< ")) - { - sort_order = System.Data.SqlClient.SortOrder.Descending; - } - else - { - sort_order = System.Data.SqlClient.SortOrder.Ascending; - } - } - else - { - // New column. Sort ascending. - sort_order = System.Data.SqlClient.SortOrder.Ascending; - } - - // Remove the old sort indicator. - SortingColumn.Text = SortingColumn.Text.Substring(2); - } - - // Display the new sort order. - SortingColumn = new_sorting_column; - if (sort_order == System.Data.SqlClient.SortOrder.Ascending) - { - SortingColumn.Text = "< " + SortingColumn.Text; - } - else - { - SortingColumn.Text = "> " + SortingColumn.Text; - } - - // Create a comparer. - listView1.ListViewItemSorter = - new ListViewComparer(e.Column, sort_order); - - // Sort. - listView1.Sort(); - } - } - } - - //private void button19_Click(object sender, EventArgs e) - //{ - // listView1.View = View.Details; - // listView2.View = View.Details; - // listView3.View = View.Details; - //} - - private void button12_Click(object sender, EventArgs e) - { - Pg1.Focus(); - - if (tabControl1.SelectedIndex == 0) - { - this.Cursor = Cursors.WaitCursor; - //Backup listview1 - ListViewItem[] itemsToAdd = new ListViewItem[listView1.Items.Count]; - ListView lv_clean = new ListView(); - listView1.BeginUpdate(); - lv_clean.Items.AddRange((from ListViewItem item in listView1.Items select (ListViewItem)item.Clone()).ToArray()); - - foreach (ListViewItem n_a in lv_clean.Items) - { - if (n_a.SubItems[3].Text == Strings.n_a || n_a.SubItems[3].Text == "0:00:00" || n_a.SubItems[3].Text == "00:00:00" || n_a.SubItems[3].Text == "00:00:00.000") - { - n_a.Remove(); - } - } - listView1.Items.Clear(); - listView1.Items.AddRange((from ListViewItem item in lv_clean.Items select (ListViewItem)item.Clone()).ToArray()); - lbl_items.Text = listView1.Items.Count + " " + Strings.files; - calc_total_dur(); - calc_list_size(); - listView1.EndUpdate(); - } - - if (tabControl1.SelectedIndex == 3) - { - if (dg1.RowCount == 0) return; - this.Cursor = Cursors.WaitCursor; - dg1.EndEdit(); - dg1.ClearSelection(); - - for (int i = 1; i < dg1.RowCount; i++) - - { - if (dg1.Rows[i].Cells[5].Value.ToString() == Strings.error) - - { - dg1.Rows.RemoveAt(i); - i--; - } - } - - if (dg1.Rows[0].Cells[1] != null && dg1.Rows[0].Cells[5].Value.ToString() == Strings.error) - { - dg1.Rows.RemoveAt(0); - this.Cursor = Cursors.Arrow; - return; - } - dg1.Refresh(); - } - this.Cursor = Cursors.Arrow; - } - - private void CopyAction(object sender, EventArgs e) - { - if (Rtxt.SelectedText != String.Empty) Clipboard.SetText(Rtxt.SelectedText); - } - - private void Disable_Controls() - { - save_path_state = btn_save_path.Enabled; - save_preset_state = btn_save_preset.Enabled; - current_save_prio = btn_save_prio.Enabled; - total_time = false; - - this.Invoke(new MethodInvoker(delegate - { - foreach (Control p in this.Controls) - { - if (p.Name != panel1.Name && p.Name != tabControl1.Name && p.Name != group_subs.Name && p.Name != group_prog.Name && p.Name != groupBox_m3u.Name && p.Name != groupBox9.Name && p.Name != groupBox1.Name && p.Name != groupBox4.Name) - { - p.Enabled = false; - } - btn_pause.Enabled = true; - } - if (Settings.Default.dark_mode == true) - { - Bitmap bm = new Bitmap(listView1.ClientSize.Width, listView1.ClientSize.Height); - Graphics.FromImage(bm).Clear(listView1.BackColor); - listView1.BackgroundImage = bm; - - bm = new Bitmap(listView3.ClientSize.Width, listView3.ClientSize.Height); - Graphics.FromImage(bm).Clear(listView1.BackColor); - listView3.BackgroundImage = bm; - } - - foreach (Control ct in groupBox_m3u.Controls) - { - ct.Enabled = false; - } - - btn_stop_m3u8.Enabled = true; - - foreach (Control ct in panel1.Controls) - { - ct.Enabled = false; - } - - foreach (Control ct_g in group_subs.Controls) - { - ct_g.Enabled = false; - } - - foreach (Control ct in groupBox9.Controls) - { - ct.Enabled = false; - } - foreach (Control ct in groupBox1.Controls) - { - ct.Enabled = false; - } - - groupBox4.Enabled = true; - foreach (Control ct in groupBox4.Controls) - { - if (ct.Name != chk_delete_source.Name) - ct.Enabled = false; - } - - TB1.Enabled = true; - chkshut.Enabled = true; - - if (chkshut.CheckState == CheckState.Checked) - { - combo_shut.Enabled = true; - } - - lbl_items.Enabled = true; - lbl_dur_list.Enabled = true; - lbl_size.Enabled = true; - btn_pause.Enabled = true; - listView2.Enabled = false; - Bitmap bm2 = null; - try - { - bm2 = new Bitmap(listView2.ClientSize.Width, listView2.ClientSize.Height); - Graphics.FromImage(bm2).Clear(listView2.BackColor); - } - catch { } - - listView2.BackgroundImage = bm2; - - list_tracks.Enabled = false; - try - { - bm2 = new Bitmap(list_tracks.ClientSize.Width, list_tracks.ClientSize.Height); - Graphics.FromImage(bm2).Clear(list_tracks.BackColor); - } - catch { } - - list_tracks.BackgroundImage = bm2; - btn_mux.Enabled = false; - - listView1.Enabled = true; - txt_remain.Enabled = true; - lbl_tot_prog.Enabled = true; - Pg1.Enabled = true; - LB_Wait.Enabled = true; - pg_adding.Enabled = true; - txt_adding_p.Enabled = true; - combo_prio.Enabled = true; - item_up.Enabled = true; - item_down.Enabled = true; - - if (runnin_n_presets == true) - { - btn_add_files.Enabled = false; - btn_add_folders.Enabled = false; - chk_subfolders.Enabled = false; - } - if (multi_running == true) btn_skip_main.Enabled = true; - })); - - } - private void Enable_Controls() - { - timer_tasks.Stop(); - TimeSpan t = TimeSpan.FromSeconds(time_n_tasks); - String tx_elapsed = string.Format("{0:D2}h:{1:D2}m:{2:D2}s", - t.Hours, - t.Minutes, - t.Seconds); - - this.Invoke(new MethodInvoker(delegate - { - foreach (Control p in this.Controls) - { - p.Enabled = true; - foreach (Control p2 in p.Controls) - { - p2.Enabled = true; - foreach (Control p3 in p.Controls) - { - p3.Enabled = true; - } - } - } - foreach (Control p2 in group_prog.Controls) p2.Enabled = true; - foreach (Control ct in panel1.Controls) ct.Enabled = true; - - foreach (Control ct in panel2.Controls) ct.Enabled = true; - foreach (Control ct_g in group_subs.Controls) ct_g.Enabled = true; - foreach (Control ct_g in groupBox1.Controls) ct_g.Enabled = true; - - if (save_path_state == false) btn_save_path.Enabled = false; - if (save_preset_state == false) btn_save_preset.Enabled = false; - if (current_save_prio == false) btn_save_prio.Enabled = false; - - foreach (Control ct in groupBox_m3u.Controls) ct.Enabled = true; - - foreach (Control ct in groupBox9.Controls) ct.Enabled = true; - foreach (Control ct in groupBox2.Controls) ct.Enabled = true; - foreach (Control ct in groupBox4.Controls) ct.Enabled = true; - - if (chkshut.CheckState == CheckState.Checked) combo_shut.Enabled = true; - else combo_shut.Enabled = false; - - listView2.Enabled = true; - list_tracks.Enabled = true; - btn_mux.Enabled = true; - txt_remain.Text = ""; - - if (Enable_txt_hard_Subs == true) txt_hard_subs.Enabled = true; - else txt_hard_subs.Enabled = false; - - txt_remain.Text = Strings.remain_time + " " + "00h:00m:00s"; - pg_adding.Visible = false; - - if (chk_m3u_params.CheckState == CheckState.Checked) txt_m3u_params.Enabled = true; - else txt_m3u_params.Enabled = false; - - if (chk_output_server.CheckState == CheckState.Checked) txt_output_server.Enabled = true; - else txt_output_server.Enabled = false; - - if (combo_prio.SelectedIndex != 2) lbl_cpu_pr.Enabled = true; - else lbl_cpu_pr.Enabled = false; - - if (chkshut.Checked) lbl_after_enc.Enabled = true; - else lbl_after_enc.Enabled = false; - - })); - check_jobs(); - } - private void Create_Tooltips() - { - ToolTip toolT_pre_ss = new ToolTip(); - ToolTip toolT4z = new ToolTip(); - ToolTip toolT44z = new ToolTip(); - ToolTip toolT5z = new ToolTip(); - ToolTip toolT2z = new ToolTip(); - ToolTip toolT1z = new ToolTip(); - ToolTip toolT0z = new ToolTip(); - ToolTip toolT00z = new ToolTip(); - ToolTip toolT002 = new ToolTip(); - ToolTip toolT001 = new ToolTip(); - ToolTip toolTipaH7 = new ToolTip(); - ToolTip toolTipaH8 = new ToolTip(); - ToolTip toolTipaH6 = new ToolTip(); - ToolTip toolTipaA6 = new ToolTip(); - ToolTip toolTipaA5 = new ToolTip(); - ToolTip toolTipaA4 = new ToolTip(); - ToolTip toolTipaA3 = new ToolTip(); - ToolTip toolTipa33 = new ToolTip(); - ToolTip toolTipa3 = new ToolTip(); - ToolTip toolTip03 = new ToolTip(); - ToolTip toolTip022 = new ToolTip(); - ToolTip toolTip02 = new ToolTip(); - ToolTip toolTip033 = new ToolTip(); - ToolTip toolTip04 = new ToolTip(); - ToolTip toolTip0 = new ToolTip(); - ToolTip toolTip1 = new ToolTip(); - ToolTip toolTip2 = new ToolTip(); - ToolTip toolTip3 = new ToolTip(); - ToolTip toolTip4 = new ToolTip(); - ToolTip toolTip5 = new ToolTip(); - ToolTip toolTip6 = new ToolTip(); - ToolTip toolTip6_2 = new ToolTip(); - ToolTip toolTip8 = new ToolTip(); - ToolTip toolTipZ8 = new ToolTip(); - ToolTip toolTip12 = new ToolTip(); - ToolTip toolTip13 = new ToolTip(); - ToolTip toolTip15 = new ToolTip(); - ToolTip toolTip16 = new ToolTip(); - ToolTip toolTip18 = new ToolTip(); - ToolTip toolTip20 = new ToolTip(); - ToolTip toolTip21 = new ToolTip(); - ToolTip toolTip22 = new ToolTip(); - ToolTip toolTip24 = new ToolTip(); - ToolTip toolTip25 = new ToolTip(); - ToolTip toolTip26 = new ToolTip(); - ToolTip toolTip27 = new ToolTip(); - ToolTip toolTip30 = new ToolTip(); - ToolTip toolTip32 = new ToolTip(); - ToolTip toolTip33 = new ToolTip(); - ToolTip toolTip34 = new ToolTip(); - ToolTip toolTip35 = new ToolTip(); - ToolTip toolTip36 = new ToolTip(); - ToolTip toolTip37 = new ToolTip(); - ToolTip toolTip38 = new ToolTip(); - ToolTip toolTip39 = new ToolTip(); - ToolTip toolTip40 = new ToolTip(); - ToolTip toolTip41 = new ToolTip(); - ToolTip toolTip42 = new ToolTip(); - ToolTip toolTip43 = new ToolTip(); - ToolTip toolTip17 = new ToolTip(); - ToolTip toolTip45 = new ToolTip(); - ToolTip toolTip46 = new ToolTip(); - ToolTip toolTip47 = new ToolTip(); - - toolT_pre_ss.RemoveAll(); - toolT4z.RemoveAll(); - toolT44z.RemoveAll(); - toolT5z.RemoveAll(); - toolT2z.RemoveAll(); - toolT1z.RemoveAll(); - toolT0z.RemoveAll(); - toolT00z.RemoveAll(); - toolT002.RemoveAll(); - toolT001.RemoveAll(); - toolTipaH7.RemoveAll(); - toolTipaH8.RemoveAll(); - toolTipaH6.RemoveAll(); - tool_undo_filter.RemoveAll(); - toolTipaA6.RemoveAll(); - toolTipaA5.RemoveAll(); - toolTipaA4.RemoveAll(); - toolTipaA3.RemoveAll(); - toolTipa33.RemoveAll(); - toolTipa3.RemoveAll(); - toolTip_settings.RemoveAll(); - toolTip03.RemoveAll(); - toolTip022.RemoveAll(); - toolTip02.RemoveAll(); - toolTip033.RemoveAll(); - toolTip04.RemoveAll(); - toolTip0.RemoveAll(); - toolTip1.RemoveAll(); - toolTip1.RemoveAll(); - toolTip3.RemoveAll(); - toolTip4.RemoveAll(); - toolTip5.RemoveAll(); - toolTip6.RemoveAll(); - toolTip6_2.RemoveAll(); - toolTip8.RemoveAll(); - toolTipZ8.RemoveAll(); - toolTip12.RemoveAll(); - toolTip13.RemoveAll(); - toolTip15.RemoveAll(); - toolTip16.RemoveAll(); - toolTip18.RemoveAll(); - toolTip20.RemoveAll(); - toolTip21.RemoveAll(); - toolTip22.RemoveAll(); - toolTip24.RemoveAll(); - toolTip25.RemoveAll(); - toolTip26.RemoveAll(); - toolTip27.RemoveAll(); - toolTip30.RemoveAll(); - toolTip32.RemoveAll(); - toolTip33.RemoveAll(); - toolTip34.RemoveAll(); - toolTip35.RemoveAll(); - toolTip36.RemoveAll(); - toolTip37.RemoveAll(); - toolTip38.RemoveAll(); - toolTip39.RemoveAll(); - toolTip40.RemoveAll(); - toolTip41.RemoveAll(); - toolTip42.RemoveAll(); - toolTip43.RemoveAll(); - toolTip17.RemoveAll(); - toolTip45.RemoveAll(); - toolTip46.RemoveAll(); - toolTip47.RemoveAll(); - - toolT_pre_ss.AutoPopDelay = 9000; - toolT_pre_ss.InitialDelay = 750; - toolT_pre_ss.ReshowDelay = 500; - toolT_pre_ss.ShowAlways = true; - toolT_pre_ss.SetToolTip(this.lbl_pre_input, Strings.pre_ss); - - toolT4z.AutoPopDelay = 9000; - toolT4z.InitialDelay = 750; - toolT4z.ReshowDelay = 500; - toolT4z.ShowAlways = true; - toolT4z.SetToolTip(this.btn_track_up, Strings.track_up); - - toolT44z.AutoPopDelay = 9000; - toolT44z.InitialDelay = 750; - toolT44z.ReshowDelay = 500; - toolT44z.ShowAlways = true; - toolT44z.SetToolTip(this.btn_add_folders, Strings.open_folder_d + Environment.NewLine + Strings.right_man_path); - - toolT5z.AutoPopDelay = 9000; - toolT5z.InitialDelay = 750; - toolT5z.ReshowDelay = 500; - toolT5z.ShowAlways = true; - toolT5z.SetToolTip(this.btn_track_down, Strings.track_down); - - toolT2z.AutoPopDelay = 9000; - toolT2z.InitialDelay = 750; - toolT2z.ReshowDelay = 500; - toolT2z.ShowAlways = true; - toolT2z.SetToolTip(this.pic_title, Strings.about_don); - - toolT1z.AutoPopDelay = 9000; - toolT1z.InitialDelay = 750; - toolT1z.ReshowDelay = 500; - toolT1z.ShowAlways = true; - toolT1z.SetToolTip(this.btn_add_col, Strings.add_col_l); - - toolT0z.AutoPopDelay = 9000; - toolT0z.InitialDelay = 750; - toolT0z.ReshowDelay = 500; - toolT0z.ShowAlways = true; - toolT0z.SetToolTip(this.btn_display_log, Strings.last_log); - - toolT00z.AutoPopDelay = 9000; - toolT00z.InitialDelay = 750; - toolT00z.ReshowDelay = 500; - toolT00z.ShowAlways = true; - toolT00z.SetToolTip(this.btn_edit_presets, Strings.edit_pres); - - toolT002.AutoPopDelay = 9000; - toolT002.InitialDelay = 750; - toolT002.ReshowDelay = 500; - toolT002.ShowAlways = true; - //toolT002.SetToolTip(this.pic_warnings, Strings.error_last_ses); - - toolT001.AutoPopDelay = 9000; - toolT001.InitialDelay = 750; - toolT001.ReshowDelay = 500; - toolT001.ShowAlways = true; - toolT001.SetToolTip(this.pic_no_errors, Strings.all_items_ok); - - toolTipaH7.AutoPopDelay = 9000; - toolTipaH7.InitialDelay = 750; - toolTipaH7.ReshowDelay = 500; - toolTipaH7.ShowAlways = true; - toolTipaH7.SetToolTip(this.btn_inc_font, Strings.inc_font); - - toolTipaH8.AutoPopDelay = 9000; - toolTipaH8.InitialDelay = 750; - toolTipaH8.ReshowDelay = 500; - toolTipaH8.ShowAlways = true; - toolTipaH8.SetToolTip(this.btn_decr_font, Strings.dec_font); - - toolTipaH6.AutoPopDelay = 9000; - toolTipaH6.InitialDelay = 750; - toolTipaH6.ReshowDelay = 500; - toolTipaH6.ShowAlways = true; - toolTipaH6.SetToolTip(this.combo_prio, Strings.end_prio); - - tool_undo_filter.AutoPopDelay = 9000; - tool_undo_filter.InitialDelay = 750; - tool_undo_filter.ReshowDelay = 500; - tool_undo_filter.ShowAlways = true; - tool_undo_filter.SetToolTip(this.btn_undo_filter, Strings.undo_fil); - - toolTipaA6.AutoPopDelay = 9000; - toolTipaA6.InitialDelay = 750; - toolTipaA6.ReshowDelay = 500; - toolTipaA6.ShowAlways = true; - toolTipaA6.SetToolTip(this.btn_filter, Strings.filter_list); - - toolTipaA5.AutoPopDelay = 9000; - toolTipaA5.InitialDelay = 750; - toolTipaA5.ReshowDelay = 500; - toolTipaA5.ShowAlways = true; - toolTipaA5.SetToolTip(this.chk_overw, Strings.allow_overw); - - toolTipaA4.AutoPopDelay = 9000; - toolTipaA4.InitialDelay = 750; - toolTipaA4.ReshowDelay = 500; - toolTipaA4.ShowAlways = true; - toolTipaA4.SetToolTip(this.chk_trim2, Strings.check_trim1 + Environment.NewLine + Strings.check_trim2); - - toolTipaA3.AutoPopDelay = 5000; - toolTipaA3.InitialDelay = 750; - toolTipaA3.ReshowDelay = 500; - toolTipaA3.ShowAlways = true; - toolTipaA3.SetToolTip(this.check_concat, Strings.concat_mux); - - toolTipa33.AutoPopDelay = 5000; - toolTipa33.InitialDelay = 750; - toolTipa33.ReshowDelay = 500; - toolTipa33.ShowAlways = true; - toolTipa33.SetToolTip(this.chk_recreate, Strings.recreate); - - toolTipa3.AutoPopDelay = 5000; - toolTipa3.InitialDelay = 750; - toolTipa3.ReshowDelay = 500; - toolTipa3.ShowAlways = true; - toolTipa3.SetToolTip(this.btn_ref_dcd, Strings.act_Dec); - - toolTip_settings.AutoPopDelay = 5000; - toolTip_settings.InitialDelay = 750; - toolTip_settings.ReshowDelay = 500; - toolTip_settings.ShowAlways = true; - toolTip_settings.SetToolTip(this.btn_save_config, Strings.save_def); - - toolTip03.AutoPopDelay = 5000; - toolTip03.InitialDelay = 750; - toolTip03.ReshowDelay = 500; - toolTip03.ShowAlways = true; - toolTip03.SetToolTip(this.btn_change_ff, Strings.replace_ff); - - toolTip022.AutoPopDelay = 5000; - toolTip022.InitialDelay = 750; - toolTip022.ReshowDelay = 500; - toolTip022.ShowAlways = true; - toolTip022.SetToolTip(this.chk_try, Strings.dis_try + Environment.NewLine + "Check it in case of trouble processing queue."); - - toolTip02.AutoPopDelay = 5000; - toolTip02.InitialDelay = 750; - toolTip02.ReshowDelay = 500; - toolTip02.ShowAlways = true; - toolTip02.SetToolTip(this.item_up, Strings.q_up); - - toolTip033.AutoPopDelay = 5000; - toolTip033.InitialDelay = 750; - toolTip033.ReshowDelay = 500; - toolTip033.ShowAlways = true; - toolTip033.SetToolTip(this.item_down, Strings.q_down); - - toolTip04.AutoPopDelay = 5000; - toolTip04.InitialDelay = 750; - toolTip04.ReshowDelay = 500; - toolTip04.ShowAlways = true; - toolTip04.SetToolTip(this.requeue, Strings.Reset_list_items_to_queued); - - toolTip0.AutoPopDelay = 5000; - toolTip0.InitialDelay = 750; - toolTip0.ReshowDelay = 500; - toolTip0.ShowAlways = true; - toolTip0.SetToolTip(this.chk_delete_source, Strings.set_del); - - toolTip1.AutoPopDelay = 5000; - toolTip1.InitialDelay = 750; - toolTip1.ReshowDelay = 500; - toolTip1.ShowAlways = true; - toolTip1.SetToolTip(this.listView1, Strings.drag1); - - toolTip2.AutoPopDelay = 5000; - toolTip2.InitialDelay = 750; - toolTip2.ReshowDelay = 500; - toolTip1.ShowAlways = true; - toolTip1.SetToolTip(this.btn_del_preset, Strings.del_pres); - - toolTip3.AutoPopDelay = 5000; - toolTip3.InitialDelay = 750; - toolTip3.ReshowDelay = 500; - toolTip3.ShowAlways = true; - toolTip3.SetToolTip(this.btn_try_pr, Strings.try_ff); - - toolTip4.AutoPopDelay = 5000; - toolTip4.InitialDelay = 750; - toolTip4.ReshowDelay = 500; - toolTip4.ShowAlways = true; - toolTip4.SetToolTip(this.btn_clean_list, Strings.Remove_invalid_items); - - toolTip5.AutoPopDelay = 5000; - toolTip5.InitialDelay = 750; - toolTip5.ReshowDelay = 500; - toolTip5.ShowAlways = true; - toolTip5.SetToolTip(this.chkshut, Strings.auto_sh); - - toolTip6.AutoPopDelay = 5000; - toolTip6.InitialDelay = 500; - toolTip6.ReshowDelay = 500; - toolTip6.ShowAlways = true; - toolTip6.SetToolTip(this.txt_path_main, Strings.reset_out); - - toolTip6_2.AutoPopDelay = 5000; - toolTip6_2.InitialDelay = 500; - toolTip6_2.ReshowDelay = 500; - toolTip6_2.ShowAlways = true; - toolTip6_2.SetToolTip(this.btn_reset_path, Strings.reset_out); - - toolTip8.AutoPopDelay = 5000; - toolTip8.InitialDelay = 750; - toolTip8.ReshowDelay = 500; - toolTip8.ShowAlways = true; - toolTip8.SetToolTip(this.btn_seq, Strings.start_set); - - toolTipZ8.AutoPopDelay = 5000; - toolTipZ8.InitialDelay = 750; - toolTipZ8.ReshowDelay = 500; - toolTipZ8.ShowAlways = true; - toolTipZ8.SetToolTip(this.btn_abort_all, Strings.abort_enc); - - toolTip12.AutoPopDelay = 5000; - toolTip12.InitialDelay = 750; - toolTip12.ReshowDelay = 500; - toolTip12.ShowAlways = true; - toolTip12.SetToolTip(this.chk_open_compl, Strings.open_out); - - toolTip13.AutoPopDelay = 5000; - toolTip13.InitialDelay = 750; - toolTip13.ReshowDelay = 500; - toolTip13.ShowAlways = true; - toolTip13.SetToolTip(this.button22, Strings.wavef); - - toolTip15.AutoPopDelay = 1500; - toolTip15.InitialDelay = 750; - toolTip15.ReshowDelay = 500; - toolTip15.ShowAlways = true; - toolTip15.SetToolTip(this.label13, Strings.reset_out); - - toolTip16.AutoPopDelay = 1500; - toolTip16.InitialDelay = 750; - toolTip16.ReshowDelay = 500; - toolTip16.ShowAlways = true; - toolTip16.SetToolTip(this.button23, Strings.cl_tracks); - - toolTip18.AutoPopDelay = 1500; - toolTip18.InitialDelay = 750; - toolTip18.ReshowDelay = 500; - toolTip18.ShowAlways = true; - toolTip18.SetToolTip(this.btn_mux, Strings.mux_st); - - toolTip20.AutoPopDelay = 1500; - toolTip20.InitialDelay = 750; - toolTip20.ReshowDelay = 500; - toolTip20.ShowAlways = true; - toolTip20.SetToolTip(this.btn_set_track_param, Strings.rest_params); - - toolTip21.AutoPopDelay = 1500; - toolTip21.InitialDelay = 750; - toolTip21.ReshowDelay = 500; - toolTip21.ShowAlways = true; - toolTip21.SetToolTip(this.btn_update, Strings.Check_for_updates); - - toolTip22.AutoPopDelay = 1500; - toolTip22.InitialDelay = 750; - toolTip22.ReshowDelay = 500; - toolTip22.ShowAlways = true; - toolTip22.SetToolTip(this.txt_track_param, Strings.not_include + " " + "-c:v / -c:a / -c:s"); - - toolTip24.AutoPopDelay = 1500; - toolTip24.InitialDelay = 750; - toolTip24.ReshowDelay = 500; - toolTip24.ShowAlways = true; - toolTip24.SetToolTip(this.btn_save_preset, Strings.save_pres); - - toolTip25.AutoPopDelay = 1500; - toolTip25.InitialDelay = 750; - toolTip25.ReshowDelay = 500; - toolTip25.ShowAlways = true; - toolTip25.SetToolTip(this.btn_add_tracks, Strings.add_track_l); - - toolTip26.AutoPopDelay = 3500; - toolTip26.InitialDelay = 750; - toolTip26.ReshowDelay = 500; - toolTip26.ShowAlways = true; - toolTip26.SetToolTip(this.btn_capture, Strings.rec_screen); - - toolTip27.AutoPopDelay = 3500; - toolTip27.InitialDelay = 750; - toolTip27.ReshowDelay = 500; - toolTip27.ShowAlways = true; - toolTip27.SetToolTip(this.chk_suffix, Strings.add_txt_out); - - toolTip30.AutoPopDelay = 3500; - toolTip30.InitialDelay = 750; - toolTip30.ReshowDelay = 500; - toolTip30.ShowAlways = true; - toolTip30.SetToolTip(this.chk_subfolders, Strings.add_subfolders); - - toolTip32.AutoPopDelay = 3500; - toolTip32.InitialDelay = 750; - toolTip32.ReshowDelay = 500; - toolTip32.ShowAlways = true; - toolTip32.SetToolTip(this.btn_refresh, Strings.Refresh_list); - - toolTip33.AutoPopDelay = 3500; - toolTip33.InitialDelay = 750; - toolTip33.ReshowDelay = 500; - toolTip33.ShowAlways = true; - toolTip33.SetToolTip(this.label2, Strings.out_ext); - - toolTip34.AutoPopDelay = 3500; - toolTip34.InitialDelay = 750; - toolTip34.ReshowDelay = 500; - toolTip34.ShowAlways = true; - toolTip34.SetToolTip(this.txt_format, Strings.out_ext); - - toolTip35.AutoPopDelay = 3500; - toolTip35.InitialDelay = 750; - toolTip35.ReshowDelay = 500; - toolTip35.ShowAlways = true; - toolTip35.SetToolTip(this.btn_start_m3u, Strings.start_one); - - toolTip36.AutoPopDelay = 3500; - toolTip36.InitialDelay = 750; - toolTip36.ReshowDelay = 500; - toolTip36.ShowAlways = true; - toolTip36.SetToolTip(this.btn_n_urls, Strings.down_multi); - - toolTip37.AutoPopDelay = 3500; - toolTip37.InitialDelay = 750; - toolTip37.ReshowDelay = 500; - toolTip37.ShowAlways = true; - toolTip37.SetToolTip(this.btn_validate_url, Strings.check_urls); - - toolTip38.AutoPopDelay = 3500; - toolTip38.InitialDelay = 750; - toolTip38.ReshowDelay = 500; - toolTip38.ShowAlways = true; - toolTip38.SetToolTip(this.btn_url_info, Strings.multimedia_i); - - toolTip39.AutoPopDelay = 3500; - toolTip39.InitialDelay = 750; - toolTip39.ReshowDelay = 500; - toolTip39.ShowAlways = true; - toolTip39.SetToolTip(this.btn_multi_m, Strings.multi_proc); - - toolTip40.AutoPopDelay = 3500; - toolTip40.InitialDelay = 750; - toolTip40.ReshowDelay = 500; - toolTip40.ShowAlways = true; - toolTip40.SetToolTip(this.btn_save_path, Strings.path_def); - - toolTip41.AutoPopDelay = 3500; - toolTip41.InitialDelay = 750; - toolTip41.ReshowDelay = 500; - toolTip41.ShowAlways = true; - toolTip41.SetToolTip(this.btn_save_prio, Strings.save_prio); - - toolTip42.AutoPopDelay = 3500; - toolTip42.InitialDelay = 750; - toolTip42.ReshowDelay = 500; - toolTip42.ShowAlways = true; - toolTip42.SetToolTip(this.btn_pause, Strings.pause1); - - toolTip43.AutoPopDelay = 3500; - toolTip43.InitialDelay = 750; - toolTip43.ReshowDelay = 500; - toolTip43.ShowAlways = true; - toolTip43.SetToolTip(this.btn_skip_main, Strings.abort_current); - - toolTip17.AutoPopDelay = 3500; - toolTip17.InitialDelay = 750; - toolTip17.ReshowDelay = 500; - toolTip17.ShowAlways = true; - toolTip17.SetToolTip(this.btn_help, Strings.open_user_guide); - - toolTip45.AutoPopDelay = 3500; - toolTip45.InitialDelay = 750; - toolTip45.ReshowDelay = 500; - toolTip45.ShowAlways = true; - toolTip45.SetToolTip(this.btn_multiple_presets, Strings.three_pres); - - toolTip46.AutoPopDelay = 3500; - toolTip46.InitialDelay = 750; - toolTip46.ReshowDelay = 500; - toolTip46.ShowAlways = true; - toolTip46.SetToolTip(this.pic_file_add_input, Strings.add_input); - - toolTip47.AutoPopDelay = 3500; - toolTip47.InitialDelay = 750; - toolTip47.ReshowDelay = 500; - toolTip47.ShowAlways = true; - toolTip47.SetToolTip(this.pic_add_variable, Strings.add_variable); - - toolTipMon.AutoPopDelay = 3500; - toolTipMon.InitialDelay = 750; - toolTipMon.ReshowDelay = 500; - toolTipMon.ShowAlways = true; - toolTipMon.SetToolTip(this.pic_mon, Strings.mon_ing + " " + Settings.Default.fd_monitored); - } - - private void button21_Click_1(object sender, EventArgs e) - { - folderBrowserDialog1.ShowNewFolderButton = true; - - if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) - { - txt_path_main.Text = folderBrowserDialog1.SelectedPath; - txt_path_main.BackColor = txt_parameters.BackColor; - txt_path_mux.Text = folderBrowserDialog1.SelectedPath; - txt_path_mux.BackColor = txt_parameters.BackColor; - btn_reset_path.BackColor = txt_parameters.BackColor; - btn_save_path.Enabled = true; - if (listView1.Items.Count == 0) return; - - try - { - File.WriteAllText(folderBrowserDialog1.SelectedPath + "\\" + "FFBatch_test.txt", "FFBatch_test"); - System.Threading.Thread.Sleep(10); - File.Delete(folderBrowserDialog1.SelectedPath + "\\" + "FFBatch_test.txt"); - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.write_error1 + " " + Environment.NewLine + excpt.Message, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Warning); - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - return; - } - } - } - - private void textBox3_DoubleClick(object sender, EventArgs e) - { - txt_path_main.Text = ".\\FFBatch"; - txt_path_main.BackColor = this.BackColor; - txt_path_mux.Text = ".\\FFBatch"; - txt_path_mux.BackColor = this.BackColor; - btn_save_path.Enabled = true; - } - - private void chk_vol_CheckedChanged(object sender, EventArgs e) - { - if (chk_vol.Checked == true) - { - vol_ch.Enabled = true; - vol_ch.BackColor = Color.LightYellow; - } - else - { - vol_ch.Enabled = false; - vol_ch.BackColor = Color.White; - } - } - - private void chk_shift_CheckedChanged(object sender, EventArgs e) - { - Num_Shift.Enabled = chk_shift.Checked; - } - - private void button22_Click(object sender, EventArgs e) - { - if (listView1.Items.Count == 0) - { - MessageBox.Show(Strings.list_empty, Strings.no_files, MessageBoxButtons.OK, MessageBoxIcon.Information); - return; - } - - //Validated list, start processing - - if (listView1.SelectedIndices.Count == 0) - { - listView1.Items[0].Selected = true; - listView1.Items[0].Focused = true; - listView1.Focus(); - } - - if (!File.Exists(listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text)) - { - MessageBox.Show(Strings.file_not_found + " " + listView1.SelectedItems[0].Text, Strings.file_not_f, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - //Try preset - - String sel_test = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - this.Cursor = Cursors.WaitCursor; - - String file_prueba = ""; - - file_prueba = sel_test; - String fichero = Path.GetFileName(file_prueba); - - String destino_test = file_prueba.Substring(0, file_prueba.LastIndexOf('\\')) + "\\" + "FFBatch_wave"; - if (!Directory.Exists(destino_test)) - { - Directory.CreateDirectory(destino_test); - } - - Form frmAWait_Wave = new Form(); - frmAWait_Wave.Name = Strings.proc_aud; - frmAWait_Wave.Text = Strings.proc_aud; - frmAWait_Wave.Height = 100; - frmAWait_Wave.Width = 340; - frmAWait_Wave.MinimizeBox = false; - frmAWait_Wave.MaximizeBox = false; - frmAWait_Wave.Icon = this.Icon; - frmAWait_Wave.ControlBox = false; - - frmAWait_Wave.BackColor = this.BackColor; - Button boton_cancel_wav = new Button(); - boton_cancel_wav.Parent = frmAWait_Wave; - boton_cancel_wav.Left = 40; - boton_cancel_wav.Top = 20; - boton_cancel_wav.Width = 250; - boton_cancel_wav.Height = 27; - boton_cancel_wav.Text = Strings.cancel_wav; - boton_cancel_wav.BackColor = frmAWait_Wave.BackColor; - boton_cancel_wav.TextAlign = ContentAlignment.MiddleCenter; - boton_cancel_wav.Click += new EventHandler(boton_cancel_wav_Click); - frmAWait_Wave.StartPosition = FormStartPosition.CenterScreen; - frmAWait_Wave.Show(); - - new System.Threading.Thread(() => - { - System.Threading.Thread.CurrentThread.IsBackground = true; - /* run your code here */ - - Process consola_pre = new Process(); - consola_pre.StartInfo.FileName = "ffmpeg.exe"; - consola_pre.StartInfo.Arguments = " -i " + "" + '\u0022' + file_prueba + '\u0022' + " -y " + "-filter_complex " + '\u0022' + "showwavespic=colors=#0000A0:s=800x180" + '\u0022' + " -frames:v 1" + " " + '\u0022' + destino_test + "\\" + Path.GetFileNameWithoutExtension(file_prueba) + "." + "png" + '\u0022'; - consola_pre.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - - consola_pre.Start(); - consola_pre.WaitForExit(); - this.InvokeEx(f => frmAWait_Wave.Close()); - - if (consola_pre.ExitCode != 0) - { - this.InvokeEx(f => f.Cursor = Cursors.Arrow); - - MessageBox.Show(Strings.wave_abort, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - this.InvokeEx(f => f.Cursor = Cursors.Arrow); - - if (Directory.GetFiles(destino_test).Length == 0) - { - Directory.Delete(destino_test); - } - - return; - } - else - { - this.InvokeEx(f => f.Cursor = Cursors.Arrow); - //Form wave image - Form frmAddWave = new Form(); - frmAddWave.Name = Strings.file_wave; - frmAddWave.Text = Strings.wavef; - frmAddWave.Icon = this.Icon; - frmAddWave.Height = 280; - frmAddWave.Width = 810; - frmAddWave.FormBorderStyle = FormBorderStyle.Fixed3D; - frmAddWave.MaximizeBox = false; - frmAddWave.MinimizeBox = false; - frmAddWave.BackColor = this.BackColor; - - TextBox txt_titulo = new TextBox(); - txt_titulo.Parent = frmAddWave; - txt_titulo.Top = 5; - txt_titulo.Left = 5; - txt_titulo.Width = 800; - txt_titulo.TextAlign = HorizontalAlignment.Center; - txt_titulo.BorderStyle = BorderStyle.None; - this.InvokeEx(f => txt_titulo.Text = listView1.SelectedItems[0].Text); - txt_titulo.BackColor = Control.DefaultBackColor; - txt_titulo.Enabled = false; - txt_titulo.BackColor = this.BackColor; - - PictureBox pic_wave = new PictureBox(); - pic_wave.SizeMode = PictureBoxSizeMode.Zoom; - pic_wave.Parent = frmAddWave; - pic_wave.Left = 0; - pic_wave.Top = 20; - pic_wave.BackColor = this.BackColor; - String pic_file = destino_test + "\\" + Path.GetFileNameWithoutExtension(file_prueba) + "." + "png"; - Image img; - using (Bitmap bmpTemp = new Bitmap(pic_file)) - { - img = new Bitmap(bmpTemp); - } - pic_wave.Image = img; - if (File.Exists(pic_file)) - { - File.Delete(pic_file); - } - if (Directory.Exists(destino_test)) - { - int num = Directory.EnumerateFiles(destino_test, "*.*").Count(); - if (num == 0) - { - Directory.Delete(destino_test); - } - } - - pic_wave.Width = 800; - pic_wave.Height = 180; - pic_wave.BorderStyle = BorderStyle.FixedSingle; - - Button boton_ok_wave = new Button(); - boton_ok_wave.Parent = frmAddWave; - boton_ok_wave.Left = 330; - boton_ok_wave.Top = 205; - boton_ok_wave.Width = 120; - boton_ok_wave.Height = 27; - boton_ok_wave.Text = Strings.close_win; - boton_ok_wave.BackColor = this.BackColor; - boton_ok_wave.Click += new EventHandler(boton_ok_wave_Click); - - frmAddWave.StartPosition = FormStartPosition.CenterScreen; - frmAddWave.ShowDialog(); - frmAddWave.Disposed += new EventHandler(frmAddWave_Disposed); - } - }).Start(); - //END try preset - } - - private void boton_cancel_wav_Click(object sender, EventArgs e) - { - Process[] localByName = Process.GetProcessesByName("ffmpeg"); - foreach (Process p in localByName) - p.Kill(); - System.Threading.Thread.Sleep(500); - Process[] localByName2 = Process.GetProcessesByName("ffmpeg"); - foreach (Process p2 in localByName2) - p2.Kill(); - - //throw new NotImplementedException(); - } - - private void frmAddWave_Disposed(object sender, EventArgs e) - { - //throw new NotImplementedException(); - } - - private void Form1_FormClosing(object sender, FormClosingEventArgs e) - { - list_cols(); - - String path_pr, path_pre = ""; - if (is_portable == false) - { - path_pr = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_presets.ini"; - path_pre = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_presets_pre.ini"; - } - else - { - path_pr = port_path + "ff_presets_portable.ini"; - path_pre = port_path + "ff_presets_pre_portable.ini"; - } - if (File.Exists(path_pr)) - { - var lines = File.ReadAllLines(path_pr).Where(arg => !string.IsNullOrWhiteSpace(arg)); - File.WriteAllLines(path_pr, lines); - } - if (File.Exists(path_pre)) - { - var lines2 = File.ReadAllLines(path_pre).Where(arg => !string.IsNullOrWhiteSpace(arg)); - File.WriteAllLines(path_pre, lines2); - } - - String f_autorun = String.Empty; - String f_multi = String.Empty; - if (is_portable == false) - { - f_autorun = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_autorun.ini"; - f_multi = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_autorun_m.ini"; - } - else - { - f_autorun = port_path + "ff_autorun_portable.ini"; - f_multi = port_path + "ff_autorun_m_portable.ini"; - } - if (start_seq == true) - { - DialogResult a; - if (start_multi == false) - { - a = MessageBox.Show(Strings.auto_ask, Strings.question, MessageBoxButtons.YesNo, MessageBoxIcon.Question); - } - else - { - a = MessageBox.Show(Strings.auto_ask2, Strings.question, MessageBoxButtons.YesNo, MessageBoxIcon.Question); - } - if (a == DialogResult.No) - { - try - { - File.Delete(f_autorun); - File.Delete(f_multi); - } - catch - { - } - } - } - - System.Drawing.Rectangle bounds = this.WindowState != FormWindowState.Normal ? this.RestoreBounds : this.DesktopBounds; - Settings.Default.wLocation = bounds.Location; - Settings.Default.Save(); - - //Remember window and size - - Rectangle rect = Screen.PrimaryScreen.Bounds; - - String f_remember_w = String.Empty; - if (is_portable == false) - { - f_remember_w = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_remember_w.ini"; - } - else - { - f_remember_w = port_path + "ff_remember_w_portable.ini"; - } - try - { - if (remember_w == false) - { - if (File.Exists(f_remember_w)) File.Delete(f_remember_w); - } - else - { - File.WriteAllText(f_remember_w, this.Height.ToString() + Environment.NewLine + this.Width.ToString()); - if (this.WindowState == FormWindowState.Maximized) - Settings.Default.w_max = true; - else Settings.Default.w_max = false; - Settings.Default.Save(); - } - } - catch - { - MessageBox.Show(Strings.un_err_set, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - //End remember window - - if (remember_last_tab == true) - { - String f_remember = String.Empty; - if (is_portable == false) - { - f_remember = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_remember.ini"; - } - else - { - f_remember = port_path + "ff_remember_portable.ini"; - } - - File.WriteAllText(f_remember, tabControl1.SelectedIndex.ToString()); - } - if (combo_presets.Text.Length < 9) combo_presets.Text = "-----" + combo_presets.Text; - if (combo_presets.Text.Length > 9) - { - if (btn_save_config.ImageKey != "Save_settings_39.png" || combo_presets.Text.Substring(combo_presets.Text.Length - 9, 9) == "-(online)") - { - String messg = Strings.setting_c; - if (combo_presets.Text == Strings.new_preset || combo_presets.Text.Substring(combo_presets.Text.Length - 9, 9) == "-(online)") messg = Strings.setting_pr_c; - DialogResult a = MessageBox.Show(messg, Strings.sett_not_s, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); - if (a == DialogResult.Cancel) e.Cancel = true; - if (a == DialogResult.Yes) - { - if (combo_presets.Text == Strings.new_preset || combo_presets.Text.Substring(combo_presets.Text.Length - 9, 9) == "-(online)") - { - if (combo_presets.Text == Strings.new_preset) combo_presets.Text = Strings.latest_preset; - if (combo_presets.Text.Substring(combo_presets.Text.Length - 9, 9) == "-(online)") combo_presets.Text = combo_presets.Text.Substring(0, combo_presets.Text.Length - 9); - save_preset(); - Thread.Sleep(150); - } - btn_save_config.PerformClick(); - } - } - } - - String temp_file = Path.Combine(Path.GetTempPath(), "temp_copy_clp.ff"); - if (File.Exists(temp_file)) - { - try - { - File.Delete(temp_file); - } - catch (Exception exc) { MessageBox.Show(exc.Message); } - } - String temp_concat = Path.Combine(Path.GetTempPath(), "concat.txt"); - if (File.Exists(temp_concat)) - { - try - { - File.Delete(temp_concat); - } - catch { } - } - - if (working == true) - { - if (paused == false) - { - MessageBox.Show(Strings.q_abort, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - e.Cancel = true; - return; - } - else - { - DialogResult a = MessageBox.Show(Strings.q_paused, Strings.warning, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); - if (a == DialogResult.No || a == DialogResult.Cancel) - { - e.Cancel = true; - return; - } - else - { - Settings.Default.pause_bat = false; - timer_battery.Stop(); - btn_pause.PerformClick(); - this.Cursor = Cursors.WaitCursor; - Thread.Sleep(750); - //Abort - if (recording_scr == true) - { - Enable_Controls(); - working = false; - recording_scr = false; - - StreamWriter write_q = process_rec.StandardInput; - write_q.Write("q"); - this.Cursor = Cursors.Arrow; - return; - } - - if (multi_running == true) - { - working = false; - multi_running = false; - aborted = true; - cancelados_paralelos = true; - - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[5].Text != Strings.success && item.SubItems[5].Text != Strings.ready && item.SubItems[5].Text != Strings.queued && item.SubItems[5].Text != Strings.replaced && item.SubItems[5].Text != Strings.renamed && item.SubItems[5].Text != Strings.deleted && item.SubItems[5].Text != Strings.not_renamed && item.SubItems[5].Text != Strings.recycled && item.SubItems[5].Text != Strings.not_recycled && item.SubItems[5].Text != Strings.not_deleted) - { - item.SubItems[5].Text = Strings.aborting; - } - } - - foreach (Process proc in procs.Values) - { - cancelados_paralelos = true; - if (proc.StartInfo.Arguments != String.Empty) - - { - try - { - StreamWriter write_q = proc.StandardInput; - write_q.Write("q"); - } - catch (Exception exc) - { - //MessageBox.Show(Strings.error2 + " " + exc.Message + " " + Strings.some_procs, Strings.abort_inc, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - return; - } - - foreach (Process proc in procs.Values) - { - if (proc.StartInfo.Arguments != String.Empty) - { - try - { - proc.Kill(); - working = false; - } - catch { - try - { - Thread.Sleep(150); - proc.Kill(); - working = false; - } - catch { } - } - } - } - int num1 = 0; - Process[] localByName1 = Process.GetProcessesByName("ffmpeg"); - num1 = localByName1.Length; - if (num1 == 1 && localByName1[0].Id == ff_ver_proc) return; - - if (num1 > 0) - { - this.Cursor = Cursors.Arrow; - MessageBox.Show(Strings.ffs, Strings.warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - - cancel_queue = true; - cancelados_paralelos = true; - } - } - this.Cursor = Cursors.Arrow; - } - - //Child processes - - Boolean cleaned = true; - try - { - foreach (Process proc in ProcessExtensions.GetChildProcesses(Process.GetCurrentProcess())) - { - try - { - proc.Kill(); - } - catch - { - try - { - Thread.Sleep(10); - proc.Kill(); - } - catch { cleaned = false; } - } - } - } catch { } - if (cleaned == false) MessageBox.Show(Strings.orphan, Strings.orphan2, MessageBoxButtons.OK, MessageBoxIcon.Warning); - - //Remaining ffmpeg - int num = 0; - Process[] localByName = Process.GetProcessesByName("ffmpeg"); - num = localByName.Length; - if (num == 1 && localByName[0].Id == ff_ver_proc) return; - - if (num > 0) - { - MessageBox.Show(Strings.ffs, Strings.warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - notifyIcon1.Dispose(); - } - - private void notifyIcon1_BalloonTipClicked(object sender, EventArgs e) - { - this.TopMost = true; - this.TopMost = false; - this.BringToFront(); - this.Focus(); - } - - private void label13_DoubleClick(object sender, EventArgs e) - { - txt_path_main.Text = ".\\FFBatch"; - txt_path_main.BackColor = Control.DefaultBackColor; - } - - private void label13_Click(object sender, EventArgs e) - { - txt_path_main.Text = ".\\FFBatch"; - txt_path_main.BackColor = Control.DefaultBackColor; - } - - private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) - { - listView1.SelectedIndices.Clear(); - listView2.SelectedIndices.Clear(); - listView3.SelectedIndices.Clear(); - - if (tabControl1.SelectedIndex == 0) - { - btn_add_col.Visible = true; - btn_filter.Visible = true; - btn_undo_filter.Visible = true; - lbl_size.Visible = true; - lbl_dur_list.Visible = true; - lbl_items.Visible = true; - lbl_urls_time.Visible = false; - lbl_search_url.Visible = false; - txt_search_url.Visible = false; - lbl_n_urls.Visible = false; - - groupBox_m3u.Visible = false; - groupBox9.Visible = false; - groupBox2.Visible = false; - list_tracks.Visible = false; - chk_open_compl.Visible = true; - chkshut.Visible = true; - combo_ext.Visible = false; - label19.Visible = false; - btn_set_mux_def.Visible = false; - lbl_tr_n.Visible = false; - - group_subs.Visible = false; - label17.Visible = false; - combo_item_lang_2.Visible = false; - - btn_clean_list.Visible = true; - label13.Visible = true; - txt_path_main.Visible = true; - btn_br_path.Visible = true; - chkshut.Visible = true; - btn_pause.Visible = true; - btn_mux.Visible = false; - btn_extract.Visible = false; - txt_track_format.Visible = false; - //btn_mux_cancel.Visible = false; - btn_del_track.Visible = false; - btn_default_track.Visible = false; - button23.Visible = false; - pic_encode_param.Visible = false; - lbl_mux_par.Visible = false; - txt_track_param.Visible = false; - btn_set_track_param.Visible = false; - groupBox1.Visible = true; - panel1.Visible = true; - list_tracks.Visible = false; - btn_add_tracks.Visible = false; - btn_mux_job.Visible = false; - btn_mux_show_jobs.Visible = false; - lbl_mux_jobs.Visible = false; - - return; - } - else if (tabControl1.SelectedIndex == 1) - { - listView1.SelectedIndices.Clear(); - btn_add_col.Visible = false; - btn_filter.Visible = false; - btn_undo_filter.Visible = false; - lbl_size.Visible = true; - lbl_tr_n.Visible = true; - lbl_dur_list.Visible = true; - lbl_items.Visible = true; - lbl_urls_time.Visible = false; - lbl_search_url.Visible = false; - txt_search_url.Visible = false; - lbl_n_urls.Visible = false; - txt_search_url.Visible = false; - groupBox_m3u.Visible = false; - groupBox9.Visible = true; - groupBox2.Visible = true; - list_tracks.Visible = true; - chkshut.Visible = true; - btn_pause.Visible = true; - - chk_open_compl.Visible = false; - btn_set_mux_def.Visible = true; - btn_set_track_param.Visible = true; - - combo_ext.Visible = true; - label19.Visible = true; - group_subs.Visible = false; - label17.Visible = true; - combo_item_lang_2.Visible = true; - - label13.Visible = false; - txt_path_main.Visible = false; - btn_br_path.Visible = false; - - lbl_mux_jobs.Visible = true; - btn_mux.Visible = true; - btn_add_tracks.Visible = true; - btn_mux_job.Visible = true; - btn_mux_show_jobs.Visible = true; - btn_extract.Visible = true; - txt_track_format.Visible = true; - btn_del_track.Visible = true; - btn_default_track.Visible = true; - //btn_mux_cancel.Visible = true; - btn_mux.Refresh(); - button23.Visible = true; - pic_encode_param.Visible = true; - lbl_mux_par.Visible = true; - txt_track_param.Visible = true; - btn_set_track_param.Visible = true; - groupBox1.Visible = false; - panel1.Visible = false; - list_tracks.Visible = true; - list_tracks.Refresh(); - txt_path_mux.Text = txt_path_main.Text; - txt_path_mux.BackColor = txt_path_main.BackColor; - - int list_int = 0; - - if (listView1.Items.Count > 500) - { - DialogResult a = MessageBox.Show(Strings.streams_f + " " + listView1.Items.Count + " " + Strings.files_long_t, Strings.too_many_files, MessageBoxButtons.YesNo, MessageBoxIcon.Question); - if (a == DialogResult.No) - { - tabControl1.SelectedIndex = 0; - return; - } - listView2.Clear(); - bg_add_tab2.RunWorkerAsync(); - return; - } - else - { - listView2.Clear(); - bg_add_tab2.RunWorkerAsync(); - return; - } - //} - - listView2.Clear(); - bg_add_tab2.RunWorkerAsync(); - } - else if (tabControl1.SelectedIndex == 2) - { - listView1.SelectedIndices.Clear(); - btn_add_col.Visible = false; - btn_filter.Visible = false; - btn_undo_filter.Visible = false; - lbl_mux_jobs.Visible = false; - btn_add_tracks.Visible = false; - btn_mux_job.Visible = false; - btn_mux_show_jobs.Visible = false; - lbl_tr_n.Visible = false; - lbl_size.Visible = true; - lbl_dur_list.Visible = true; - lbl_items.Visible = true; - lbl_urls_time.Visible = false; - lbl_search_url.Visible = false; - txt_search_url.Visible = false; - lbl_n_urls.Visible = false; - - groupBox_m3u.Visible = false; - groupBox9.Visible = false; - groupBox2.Visible = false; - list_tracks.Visible = false; - group_subs.Visible = true; - chkshut.Visible = true; - btn_pause.Visible = true; - btn_set_mux_def.Visible = false; - btn_extract.Visible = false; - txt_track_format.Visible = false; - btn_del_track.Visible = false; - btn_default_track.Visible = false; - btn_set_track_param.Visible = false; - group_subs.Visible = true; - TB1.Visible = false; - - int list_int = 0; - - if (listView1.Items.Count == listView3.Items.Count) - { - foreach (ListViewItem item in listView1.Items) - { - if (listView3.Items[list_int].Text == item.SubItems[1].Text + "\\" + item.Text) - { - list_int = list_int + 1; - } - } - - if (list_int == listView1.Items.Count) - { - return; - } - } - else - { - if (listView1.Items.Count > 1000) - { - DialogResult a = MessageBox.Show(Strings.adding + " " + listView1.Items.Count + " " + Strings.some_time, Strings.many_parsed, MessageBoxButtons.OKCancel, MessageBoxIcon.Question); - if (a == DialogResult.Cancel) - { - tabControl1.SelectedIndex = 0; - - return; - } - listView3.Items.Clear(); - add_to_tab_3(); - } - else - { - listView3.Items.Clear(); - add_to_tab_3(); - return; - } - } - - listView3.Items.Clear(); - add_to_tab_3(); - } - else if (tabControl1.SelectedIndex == 3) - { - listView1.SelectedIndices.Clear(); - btn_add_col.Visible = false; - btn_filter.Visible = false; - btn_undo_filter.Visible = false; - lbl_mux_jobs.Visible = false; - btn_add_tracks.Visible = false; - btn_mux_job.Visible = false; - btn_mux_show_jobs.Visible = false; - lbl_size.Visible = false; - lbl_tr_n.Visible = false; - lbl_dur_list.Visible = false; - lbl_items.Visible = false; - group_subs.Visible = false; - list_tracks.Visible = false; - groupBox_m3u.Visible = true; - groupBox9.Visible = false; - groupBox2.Visible = false; - chkshut.Visible = true; - btn_pause.Visible = true; - lbl_urls_time.Visible = true; - lbl_search_url.Visible = true; - txt_search_url.Visible = true; - lbl_n_urls.Visible = true; - if (yt_chk == false) - { - yt_chk = true; - youtube_dl_ver(); //youtube-dl version - } - if (txt_path_m3u.Text == Strings.no_path2 || txt_path_m3u.Text.Length == 0) - { - txt_path_m3u.Text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos), "M3u8"); - } - } - } - - private void add_to_tab_3() - - { - listView3.SmallImageList = listView1.SmallImageList; - foreach (ListViewItem item in listView1.Items) - { - this.Cursor = Cursors.WaitCursor; - ListViewItem elemento = new ListViewItem(item.SubItems[1].Text + "\\" + item.Text, 1); - if (!File.Exists(item.SubItems[1].Text + "\\" + item.Text)) continue; - //Begin get file icon - Icon iconForFile = SystemIcons.WinLogo; - - if (!elemento.Text.Contains("\\\\") && - !imageList2.Images.ContainsKey(Path.GetExtension(elemento.Text))) - { - iconForFile = System.Drawing.Icon.ExtractAssociatedIcon(elemento.Text); - this.InvokeEx(f => f.imageList2.Images.Add(Path.GetExtension(elemento.Text), iconForFile)); - } - - if (!elemento.Text.Contains("\\\\")) - { - elemento.ImageKey = Path.GetExtension(elemento.Text); - } - else - { - elemento.ImageIndex = 0; - } - listView3.Items.Add(elemento); - } - - foreach (ListViewItem item in listView3.Items) - { - Path.GetFileNameWithoutExtension(item.Text); - String is_srt = ""; - try - { - is_srt = item.Text.Substring(item.Text.LastIndexOf(".")); - } - catch { } - - if (is_srt == ".srt") - { - listView3.Items.RemoveAt(item.Index); - } - - String is_Vobsub = ""; - try - { - is_Vobsub = item.Text.Substring(item.Text.LastIndexOf(".")); - } - catch { } - - if (is_Vobsub == ".idx" || is_Vobsub == ".sub") - { - listView3.Items.RemoveAt(item.Index); - } - - String is_ass = ""; - try { is_ass = item.Text.Substring(item.Text.LastIndexOf(".")); } - catch { } - - if (is_srt == ".ass") - { - listView3.Items.RemoveAt(item.Index); - } - - String subs_path = String.Empty; - String Sub_File_SRT = String.Empty; - String Sub_File_Vobsub = String.Empty; - String Sub_File_ASS = String.Empty; - - try - { - if (txt_folder_subs.Text == String.Empty) - { - Sub_File_SRT = Path.Combine(Path.GetDirectoryName(item.Text), Path.GetFileNameWithoutExtension(item.Text)); - } - else - { - String path_sub = txt_folder_subs.Text; - Path.GetFileName(item.Text); - Sub_File_SRT = path_sub + "\\" + Path.GetFileNameWithoutExtension(item.Text); - } - } - catch { } - - if (item.SubItems[0].Text.Contains(Strings.no_sub_file) == false) - { - Boolean srt_lang = false; - Boolean idx_lang = false; - Boolean ass_lang = false; - String fn1 = ""; - String fn2 = ""; - String fn3 = ""; - - foreach (String str in Combo_sub_lang_mux.Items) - { - fn1 = Sub_File_SRT + "." + str.Substring(str.Length - 4, 3) + ".srt"; - String lang = str.Substring(str.Length - 4, 3); - if (File.Exists(fn1)) - { - item.SubItems.Add(Strings.srt_sub); - item.SubItems.Add(lang); - - Sub_File_SRT = fn1; - srt_lang = true; - break; - } - - fn2 = Sub_File_SRT + "." + str.Substring(str.Length - 4, 3) + ".idx"; - lang = str.Substring(str.Length - 4, 3); - if (File.Exists(fn2)) - { - item.SubItems.Add(Strings.vob_sub); - item.SubItems.Add(lang); - idx_lang = true; - Sub_File_SRT = fn2; - break; - } - fn3 = Sub_File_SRT + "." + str.Substring(str.Length - 4, 3) + ".ass"; - lang = str.Substring(str.Length - 4, 3); - if (File.Exists(fn3)) - { - item.SubItems.Add(Strings.as_sub); - item.SubItems.Add(lang); - ass_lang = true; - Sub_File_SRT = fn3; - break; - } - } - - if (File.Exists(Sub_File_SRT + ".srt")) Sub_File_SRT = Sub_File_SRT + ".srt"; - if (File.Exists(Sub_File_SRT + ".idx")) Sub_File_SRT = Sub_File_SRT + ".idx"; - if (File.Exists(Sub_File_SRT + ".ass")) Sub_File_SRT = Sub_File_SRT + ".ass"; - - if (File.Exists(Sub_File_SRT)) - { - if (srt_lang == false && idx_lang == false && ass_lang == false) - { - if (Path.GetExtension(Sub_File_SRT) == ".srt") item.SubItems.Add(Strings.srt_sub); - if (Path.GetExtension(Sub_File_SRT) == ".idx") item.SubItems.Add(Strings.vob_sub); - if (Path.GetExtension(Sub_File_SRT) == ".ass") item.SubItems.Add(Strings.as_sub); - item.SubItems.Add("und"); - } - - var a = TextFileEncodingDetector.DetectTextFileEncoding(Sub_File_SRT); - if (a != null) - { - String txt_enc = a.ToString().Replace("System.Text.", ""); - item.SubItems.Add(txt_enc.Replace(Strings.Encoding, "")); - } - else - { - item.SubItems.Add(Strings.unknown); - } - item.SubItems.Add(Strings.yes); - item.SubItems.Add(Strings.ready); - } - else - { - item.SubItems.Add(Strings.no_sub2); - item.SubItems.Add("-"); - item.SubItems.Add("-"); - item.SubItems.Add("-"); - item.SubItems.Add("No Sub"); - } - } - - } - Combo_sub_lang_mux.Text = ""; - this.Cursor = Cursors.Arrow; - } - - private void ctm2_Opening_1(object sender, CancelEventArgs e) - { - if (Settings.Default.dark_mode == true) - { - ctm2.BackColor = Color.FromArgb(255, 64, 64, 64); - ctm2.ForeColor = Color.White; - } - else - { - ctm2.BackColor = SystemColors.InactiveBorder; - ctm2.ForeColor = Control.DefaultForeColor; - } - - if (listView2.SelectedItems.Count == 0) - { - e.Cancel = true; - ct2_a.Enabled = false; - ct2_v.Enabled = false; - ct2_s.Enabled = false; - } - else - { - ct2_a.Enabled = true; - ct2_v.Enabled = true; - ct2_s.Enabled = true; - combo_def_und_lang.Text = Strings.lang_tracks; - } - } - - private void ct2_v_Click(object sender, EventArgs e) - { - Boolean has_video = false; - Boolean stream_found = false; - foreach (ListViewItem track_item in list_tracks.Items) - { - if (track_item.SubItems[2].Text.Contains("Video")) - { - has_video = true; - MessageBox.Show(Strings.alr_track, Strings.information, MessageBoxButtons.OK, MessageBoxIcon.Warning); - return; - } - } - - foreach (ListViewItem item in listView2.SelectedItems) - { - for (int i = 1; i < item.SubItems.Count; i++) - { - if (item.SubItems[i].Text.Contains("Video")) - { - stream_found = true; - - list_tracks.Items.Add(listView2.SelectedItems[0].Text, 0); - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add((i - 1).ToString()); - - if (listView2.SelectedItems[0].SubItems[i].Text.Substring(0, 1) == "(") - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(listView2.SelectedItems[0].SubItems[i].Text.Substring(7, listView2.SelectedItems[0].SubItems[i].Text.Length - 7)); - } - else - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(listView2.SelectedItems[0].SubItems[i].Text); - } - - if (listView2.SelectedItems[0].SubItems[i].Text.Substring(0, 1) == "(") - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(listView2.SelectedItems[0].SubItems[i].Text.Substring(1, 3)); - } - else - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(def_lang_und_tracks); - } - - if (has_video == false) - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(Strings.yes); - } - else - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(Strings.no); - } - - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(def_mux_video_enc); - - list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text = Regex.Replace(list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text, @"\([^()]*\)", string.Empty); - list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text = Regex.Replace(list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text, @"\[[^()]*\]", string.Empty); - RegexOptions options = RegexOptions.None; - Regex regex = new Regex("[ ]{2,}", options); - list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text = regex.Replace(list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text, " "); - } - tracks_background(); - } - - foreach (ListViewItem track_item in list_tracks.Items) - { - if (track_item.SubItems[3].Text.Contains("Video")) - { - list_tracks.Items.RemoveAt(track_item.Index); - list_tracks.Items.Insert(0, track_item); - } - } - - if (stream_found == false) - { - MessageBox.Show(Strings.no_video, Strings.no_video2, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - - private void ct2_a_Click(object sender, EventArgs e) - { - Boolean has_audio = false; - foreach (ListViewItem track_item in list_tracks.Items) - { - if (track_item.SubItems[2].Text.Contains("Audio")) - { - has_audio = true; - break; - } - } - - foreach (ListViewItem item in listView2.SelectedItems) - { - Boolean stream_found = false; - for (int i = 1; i < item.SubItems.Count; i++) - { - if (item.SubItems[i].Text.Contains("Audio")) - { - stream_found = true; - - list_tracks.Items.Add(listView2.SelectedItems[0].Text, 1); - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add((i - 1).ToString()); - - if (listView2.SelectedItems[0].SubItems[i].Text.Substring(0, 1) == "(") - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(listView2.SelectedItems[0].SubItems[i].Text.Substring(7, listView2.SelectedItems[0].SubItems[i].Text.Length - 7)); - } - else - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(listView2.SelectedItems[0].SubItems[i].Text); - } - - if (listView2.SelectedItems[0].SubItems[i].Text.Substring(0, 1) == "(") - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(listView2.SelectedItems[0].SubItems[i].Text.Substring(1, 3)); - } - else - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(def_lang_und_tracks); - } - - if (has_audio == false) - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(Strings.yes); - } - else - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(Strings.no); - } - - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(def_mux_audio_enc); - list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text = Regex.Replace(list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text, @"\([^()]*\)", string.Empty); - list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text = Regex.Replace(list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text, @"\[[^()]*\]", string.Empty); - RegexOptions options = RegexOptions.None; - Regex regex = new Regex("[ ]{2,}", options); - list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text = regex.Replace(list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text, " "); - } - } - - if (stream_found == false) - { - MessageBox.Show(Strings.no_audio, Strings.no_audio2, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - tracks_background(); - } - - private void ct2_s_Click(object sender, EventArgs e) - { - if (notifyIcon1 != null) - { - notifyIcon1.Dispose(); - } - - Boolean has_subs = false; - foreach (ListViewItem track_item in list_tracks.Items) - { - if (track_item.SubItems[2].Text.Contains("Subtitle")) - { - has_subs = true; - break; - } - } - - foreach (ListViewItem item in listView2.SelectedItems) - { - Boolean stream_found = false; - for (int i = 1; i < item.SubItems.Count; i++) - { - if (item.SubItems[i].Text.Contains("Subtitle")) - { - stream_found = true; - list_tracks.Items.Add(listView2.SelectedItems[0].Text, 2); - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add((i - 1).ToString()); - - if (listView2.SelectedItems[0].SubItems[i].Text.Substring(0, 1) == "(") - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(listView2.SelectedItems[0].SubItems[i].Text.Substring(7, listView2.SelectedItems[0].SubItems[i].Text.Length - 7)); - } - else - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(listView2.SelectedItems[0].SubItems[i].Text); - } - - if (listView2.SelectedItems[0].SubItems[i].Text.Substring(0, 1) == "(") - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(listView2.SelectedItems[0].SubItems[i].Text.Substring(1, 3)); - } - else - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(def_lang_und_tracks); - } - - if (has_subs == false) - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(Strings.yes); - } - else - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(Strings.no); - } - if (item.SubItems[i].Text.Contains("dvd_subtitle") || item.SubItems[i].Text.Contains("hdmv_pgs_subtitle")) - - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add("copy"); - } - else - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(def_mux_subs_enc); - } - } - - foreach (ListViewItem track_item in list_tracks.Items) - { - if (track_item.SubItems[2].Text.Contains("Subtitle")) - { - list_tracks.Items.RemoveAt(track_item.Index); - list_tracks.Items.Insert(list_tracks.Items.Count, track_item); - } - } - } - - if (stream_found == false) - { - MessageBox.Show(Strings.no_subs1, Strings.no_subs2, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - tracks_background(); - } - - private void btn_mux_Click(object sender, EventArgs e) - { - Pg1.Focus(); - lbl_est_size.Text = ""; - lbl_bitrate.Text = ""; - - if (!File.Exists(Path.Combine(Application.StartupPath, "ffmpeg.exe"))) - { - MessageBox.Show(Strings.no_ffmpeg, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (check_ff_md5() == false) - { - Form25 frm25 = new Form25(); - frm25.ShowDialog(); - return; - } - - cancel_queue = false; - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - - foreach (ListViewItem file in list_tracks.Items) - { - if (!File.Exists(file.Text)) - { - MessageBox.Show(Strings.file_not_found + " " + file.Text, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - - if (list_tracks.Items.Count == 0) - { - MessageBox.Show(Strings.tracks_empty, Strings.no_files, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; - } - - Boolean video_track_in = false; - foreach (ListViewItem tracks_item in list_tracks.Items) - { - if (tracks_item.SubItems[2].Text.Contains("Video")) - { - video_track_in = true; - break; - } - } - - if (video_track_in == false) - { - MessageBox.Show(Strings.vid_req, Strings.no_video2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - String is_overw = String.Empty; - if (txt_path_main.Text.Contains(".\\")) - { - if (txt_path_main.Text == ".\\") - { - is_overw = Path.GetDirectoryName(list_tracks.Items[0].Text) + "\\" + Path.GetFileNameWithoutExtension(list_tracks.Items[0].Text) + "." + combo_ext.SelectedItem.ToString(); - } - else - { - is_overw = Path.GetDirectoryName(list_tracks.Items[0].Text) + txt_path_main.Text.Replace(".", String.Empty) + "\\" + Path.GetFileNameWithoutExtension(list_tracks.Items[0].Text) + "." + combo_ext.SelectedItem.ToString(); - } - } - - if (is_overw == list_tracks.Items[0].Text) - { - MessageBox.Show(Strings.overw_not2, Strings.overw_not_all, MessageBoxButtons.OK, MessageBoxIcon.Error); - - return; - } - - DateTime time2; - if (!DateTime.TryParse(ss_time_input.Text, out time2)) - { - MessageBox.Show(Strings.pre_input4, Strings.pre_input2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (txt_path_mux.Text.Length < 2) - { - MessageBox.Show(Strings.invalid_path); - return; - } - - //Validated list, start processing - //Pending duration - - if (dur_ok == false) - { - list_pending_dur.Items.Clear(); - foreach (ListViewItem item in listView1.Items) - { - list_pending_dur.Items.Add((ListViewItem)item.Clone()); - } - BG_Dur.RunWorkerAsync(); - return; - } - - Disable_Controls(); - txt_remain.Text = Strings.remain_time + " " + "00h:00m:00s"; - time_n_tasks = 0; - timer_tasks.Start(); - timer_est_size.Start(); - - cancel_queue = false; - Pg1.Value = 0; - - pic_no_errors.Visible = false; - pic_recording.Visible = false; - pic_warnings.Visible = false; - - working = true; - - //Copy list of tracks for thread processing - ListView list_proc = new ListView(); - foreach (ListViewItem item in list_tracks.Items) - { - list_proc.Items.Add((ListViewItem)item.Clone()); - } - //End of copy list of tracks for thread processing - - Pg1.Maximum = list_proc.Items.Count; - - Double total_duration = 0; - Double total_prog = 0; - - //Get specific track list video duration - //Duration - - Process probe = new Process(); - String ffprobe_frames = ""; - probe.StartInfo.FileName = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - Boolean has_audio_for_image = false; - - durat_n = get_dur_secs(get_file_dur(list_proc.Items[0].Text)); - total_duration = durat_n; - - //End duration - - //End - - Pg1.Minimum = 0; - Pg1.Maximum = 100; - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - lbl_speed.Text = String.Empty; - lbl_elapsed.Text = Strings.time_elapsed + " " + "00h:00m:00s"; - - List list_lines = new List(); - String mux_ext = combo_ext.Text; - - String hw_decode = String.Empty; - if (cb_hwdecode.SelectedItem.ToString() != "none") - { - hw_decode = "-hwaccel " + cb_hwdecode.SelectedItem.ToString(); - } - - //Save selected hw decoder - - String path2 = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_hw_dcd.ini"; - if (is_portable == true) - { - path2 = port_path + "ff_hw_dcd_portable.ini"; - } - String txt_hw_dcd = cb_hwdecode.SelectedItem.ToString(); - if (txt_hw_dcd != "none") - { - File.WriteAllText(path2, txt_hw_dcd); - } - else - { - if (File.Exists(path2)) File.Delete(path2); - } - - //End save hw decoder - - procs.Clear(); - procs.Add("proc_urls_0", new Process()); - - new System.Threading.Thread(() => - { - System.Threading.Thread.CurrentThread.IsBackground = true; - - String remain_time = "0"; - String ffm = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - String file = list_proc.Items[0].Text; - String fullPath = file; - String destino = ""; - - if (txt_path_main.Text.Contains(".\\")) - { - destino = file.Substring(0, fullPath.LastIndexOf('\\')) + txt_path_main.Text.Replace(".", String.Empty); - } - else - { - destino = txt_path_main.Text; - } - - if (!Directory.Exists(destino)) - { - Directory.CreateDirectory(destino); - } - - //Create joint inputs variable - String inputs = String.Empty; - foreach (ListViewItem input_item in list_proc.Items) - { - if (input_item.SubItems[2].Text.Contains("Subtitle") && !input_item.SubItems[2].Text.Contains("hdmv_pgs") && !input_item.SubItems[2].Text.Contains("dvd_subtitle")) - { - inputs = inputs + " -sub_charenc UTF-8" + " -i " + '\u0022' + input_item.Text + '\u0022'; - } - else - { - if (input_item.BackColor != Color.LightYellow) - { - inputs = inputs + " -i " + '\u0022' + input_item.Text + '\u0022'; - } - else - { - String ext_image = Path.GetExtension(list_proc.Items[0].Text); - - //Attempt to extract frame as image - Process proc_img = new System.Diagnostics.Process(); - String ffm_img = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - - String file_img = Path.GetFullPath(list_proc.Items[0].Text); - String fullPath_img = file_img; - String AppParam_img = ""; - - if (ext_image != ".jpg" && ext_image != ".jpeg" && ext_image != ".png" && ext_image != ".gif" && ext_image != ".bmp" && ext_image != ".tiff" && ext_image != ".psd") - { - AppParam_img = " -ss " + ss_time_input.Text + " -i " + "" + '\u0022' + file_img + '\u0022' + " -vframes 1 -f image2" + " -qscale:v 2" + " -vf scale=1280:-2" + " -y " + '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file_img) + "." + "jpg" + '\u0022'; - } - else - { - AppParam_img = " -i " + "" + '\u0022' + file_img + '\u0022' + " -qscale:v 2" + " -vf scale=1280:-2" + " -y " + '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file_img) + "." + "jpg" + '\u0022'; - } - proc_img.StartInfo.RedirectStandardOutput = false; - proc_img.StartInfo.RedirectStandardError = false; - proc_img.StartInfo.UseShellExecute = true; - proc_img.StartInfo.CreateNoWindow = false; - proc_img.EnableRaisingEvents = false; - proc_img.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - - proc_img.StartInfo.FileName = ffm_img; - proc_img.StartInfo.Arguments = AppParam_img; - - proc_img.Start(); - proc_img.WaitForExit(); - if (proc_img.ExitCode == 0) - { - String extracted_img = "" + '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file_img) + ".jpg" + '\u0022' + ""; - inputs = inputs + " -i " + extracted_img; - } - else - { - MessageBox.Show(Strings.err_ext_vid, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - Enable_Controls(); - working = false; - return; - } - //End extract frame as image - } - } - } - //End create joint inputs variable - - //Create mapping inputs variable - String input_map = String.Empty; - //Add video track, it must be first - if (list_proc.Items[0].BackColor == Color.LightYellow) - { - //Video track is an still image - - //Attempt to extract first frame from video track as image - - input_map = input_map + " -map 0:0" + " -c:v libx264 -r 1 -crf 29 -preset veryfast -x264-params keyint=1 -pix_fmt yuv420p"; - } - else - { - input_map = input_map + " -map 0:" + list_proc.Items[0].SubItems[1].Text + " -c:v " + list_proc.Items[0].SubItems[5].Text + " -metadata:s:v:0 language=" + list_proc.Items[0].SubItems[3].Text; - } - - int int_auds = 0; - int i_subs = 0; - - for (int i = 1; i < list_tracks.Items.Count; i++) - - { - //Audio tracks - if (list_proc.Items[i].SubItems[2].Text.Contains("Audio")) - { - String is_default = String.Empty; - if (list_proc.Items[i].SubItems[4].Text == Strings.yes) - { - is_default = "-disposition:a:" + (int_auds).ToString() + " default"; - } - else - { - is_default = "-disposition:a:" + (int_auds).ToString() + " 0"; - } - String track_codec = " -c:a copy "; - if (list_proc.Items[i].SubItems[5].Text != "copy") - { - track_codec = " -c:a:" + int_auds + " " + list_proc.Items[i].SubItems[5].Text; - } - input_map = input_map + " -map " + (i).ToString() + ":" + list_proc.Items[i].SubItems[1].Text + track_codec + " -metadata:s:a:" + (int_auds).ToString() + " language=" + list_proc.Items[i].SubItems[3].Text + " " + is_default; - int_auds = int_auds + 1; - } - } - - for (int i = 1; i < list_tracks.Items.Count; i++) - - { - //Subtitle tracks - if (list_proc.Items[i].SubItems[2].Text.Contains("Subtitle")) - { - String is_default = String.Empty; - if (list_proc.Items[i].SubItems[4].Text == Strings.yes) - { - is_default = "-disposition:s:" + (i_subs).ToString() + " default"; - } - else - { - is_default = "-disposition:s:" + (i_subs).ToString() + " 0"; - } - - input_map = input_map + " -map " + (i).ToString() + ":" + list_proc.Items[i].SubItems[1].Text + " -c:s " + list_proc.Items[i].SubItems[5].Text + " -metadata:s:s:" + (i_subs).ToString() + " language=" + list_proc.Items[i].SubItems[3].Text + " " + is_default; - - i_subs = i_subs + 1; - } - } - - // Average frames - int fframes = 0; - Decimal dec = 0; - Decimal tot_frames2 = 0; - - try - { - String ff_frames = String.Empty; - - Process get_frames = new Process(); - get_frames.StartInfo.FileName = Path.Combine(Application.StartupPath, "mediainfo.exe"); - ffprobe_frames = "--Output=" + '\u0022' + "Video;%FrameCount%" + '\u0022'; - get_frames.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + file + '\u0022'; - get_frames.StartInfo.RedirectStandardOutput = true; - get_frames.StartInfo.UseShellExecute = false; - get_frames.StartInfo.CreateNoWindow = true; - get_frames.EnableRaisingEvents = true; - get_frames.Start(); - - ff_frames = get_frames.StandardOutput.ReadLine(); - get_frames.WaitForExit(); - - if (get_frames.ExitCode == 0) - { - if (ff_frames != null) - { - dec = decimal.Parse(ff_frames); - if (dec.ToString().Substring(dec.ToString().Length - 1, 1) == "0") dec = dec / 10; - } - else - { - dec = 0; - } - - get_frames.Dispose(); - tot_frames2 = tot_frames2 + dec; - } - } - catch - { - dec = 0; - } - - // End average frames - - String AppParam = String.Empty; - - if (list_proc.Items[0].BackColor == Color.LightYellow) - { - AppParam = hw_decode + " -loop 1 -r 6 " + inputs + input_map + " -shortest " + "-y " + '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file) + "." + mux_ext + '\u0022'; - } - else - { - AppParam = hw_decode + " " + inputs + input_map + " -y " + '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file) + "." + mux_ext + '\u0022'; - } - - if (!Directory.Exists(destino)) - { - Directory.CreateDirectory(destino); - } - - valid_prog = false; - - var tmp = procs["proc_urls_0"]; - - tmp.StartInfo.FileName = ffm; - tmp.StartInfo.Arguments = AppParam + " -hide_banner"; - tmp.StartInfo.RedirectStandardError = true; - tmp.StartInfo.RedirectStandardInput = true; - tmp.StartInfo.UseShellExecute = false; - tmp.StartInfo.CreateNoWindow = true; - tmp.EnableRaisingEvents = true; - tmp.Start(); - - System.Threading.Thread.Sleep(50); - combo_prio.Invoke(new MethodInvoker(delegate - { - if (combo_prio.SelectedIndex != 2) - { - Change_mem_prio(); - } - })); - - valid_prog = true; - - String err_txt = ""; - Double interval = 0; - - while (!tmp.StandardError.EndOfStream) - { - try - { - err_txt = tmp.StandardError.ReadLine(); - list_lines.Add(err_txt); - - Decimal est_bitrate = 0; - Decimal est_size = 0; - - if (err_txt.Contains("time=") && err_txt.Contains("time=-") == false && err_txt.Contains("time=N/A") == false) - { - total_prog = durat_n; - int start_time_index = err_txt.IndexOf("time=") + 5; - Double sec_prog = TimeSpan.Parse(err_txt.Substring(start_time_index, 8)).TotalSeconds; - Double percent = 0; - if (durat_n > 0) percent = (sec_prog * 100 / durat_n); - - total_prog = total_prog + (sec_prog - interval); - interval = sec_prog; - int percent2 = Convert.ToInt32(percent); - - if (percent2 <= 100) - { - this.Invoke(new MethodInvoker(delegate - { - Pg1.Value = percent2; - Pg1.Refresh(); - if (Math.Round(percent, 1).ToString().Contains(".") || Math.Round(percent, 1).ToString().Contains(",")) - { - Pg1.Text = Math.Round(percent, 1).ToString() + "%"; - } - else - { - Pg1.Text = Math.Round(percent, 1).ToString() + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0" + "%"; - } - - TaskbarProgress.SetValue(this.Handle, Pg1.Value, Pg1.Maximum); - })); - } - - //Estimated remaining time - - remain_time = err_txt.Substring(err_txt.LastIndexOf("speed=") + 6, err_txt.Length - err_txt.LastIndexOf("speed=") - 6); - if (time_est_size % 3 == 0) this.InvokeEx(f => f.lbl_speed.Text = Strings.speed + " " + remain_time); - remain_time = remain_time.Replace("x", String.Empty); - Double timing1 = 0; - - if (System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",") - { - timing1 = Math.Round(Double.Parse(remain_time.Replace(".", ",")), 2); - } - else - { - timing1 = Math.Round(Double.Parse(remain_time), 2); - } - Decimal timing = (decimal)timing1; - Decimal total_dur_dec = Convert.ToDecimal(interval); - Decimal total_prog_dec = Convert.ToDecimal(total_prog); - - Decimal remain_secs = 0; - if (timing > 0) - { - remain_secs = (decimal)(total_prog_dec - total_dur_dec) / timing; - } - - if (remain_secs > 60) - { - remain_secs = remain_secs + 60; - } - String remain_from_secs = ""; - - TimeSpan t = TimeSpan.FromSeconds(Convert.ToDouble(remain_secs)); - remain_from_secs = string.Format("{0:D2}h:{1:D2}", - t.Hours, - t.Minutes); - - this.Invoke(new MethodInvoker(delegate - { - if (remain_secs >= 3600) txt_remain.Text = Strings.remain_time + " " + remain_from_secs + " " + Strings.minutes_abrev; - if (remain_secs < 3600 && remain_secs >= 600) txt_remain.Text = Strings.remain_time + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 1, 2) + " " + Strings.minutes; - if (remain_secs < 600 && remain_secs >= 120) txt_remain.Text = Strings.remain_time + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 2, 1) + " " + Strings.minutes; - if (remain_secs <= 59) txt_remain.Text = Strings.remain_time + " " + Convert.ToInt16(Math.Abs(remain_secs)) + " " + Strings.seconds; - })); - - //End remaining time - - //Estimated size and bitrate - - String read_size = String.Empty; - if (err_txt.Contains("size=") && (time_est_size % 2 == 0)) - { - int size_index = err_txt.IndexOf("size=") + 5; - read_size = err_txt.Substring(size_index, 8); - - if (Convert.ToDecimal(sec_prog) != 0) - { - est_bitrate = (Math.Round(Convert.ToDecimal(read_size) * 8 / Convert.ToDecimal(sec_prog), 0)); - } - else - { - est_bitrate = 0; - } - - if (Convert.ToDecimal(read_size) > 1 && time_n_tasks > 1) - { - this.Invoke(new MethodInvoker(delegate - { - if (est_bitrate < 9999) - { - lbl_bitrate.Text = Strings.avg_bit + ": " + est_bitrate + " " + "Kb/s"; - } - else - { - lbl_bitrate.Text = Strings.avg_bit + ": " + (Math.Round(est_bitrate / 1000, 0)) + " " + "Mb/s"; - } - //Estimated size - est_size = Convert.ToDecimal(durat_n) * est_bitrate / 8; - - if (est_size > 1000000) - { - lbl_est_size.Text = Strings.est_size + " " + (Math.Round(est_size / 1000000, 1)).ToString() + " " + "GB"; - } - else - { - if (est_size > 0) lbl_est_size.Text = Strings.est_size + " " + (Math.Round(est_size / 1000, 0)).ToString() + " " + "MB"; - } - })); - - } - } - } - } - catch { } - } - - tmp.WaitForExit(); - tmp.StartInfo.Arguments = String.Empty; - this.Invoke(new MethodInvoker(delegate - { - Pg1.Value = 100; - Pg1.Text = "100%"; - Pg1.Refresh(); - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - })); - - list_lines.Add(""); - list_lines.Add("---------------------End of " + Path.GetFileName(file) + " log-------------------------------"); - list_lines.Add(""); - - working = false; - - //Averages - if (time_n_tasks == 0) time_n_tasks = 1; - Double avg_enc = Math.Round((total_duration / time_n_tasks), 1); - Decimal deci = Convert.ToDecimal(time_n_tasks, CultureInfo.CurrentUICulture); - - try - { - if (cancel_queue == false) - { - if (tot_frames2 != 0) - { - list_lines.Add(Environment.NewLine + (Strings.avg_perf + " " + avg_enc.ToString() + "x" + " | " + Math.Round(tot_frames2 / time_n_tasks, 1)).ToString() + " fps"); - this.InvokeEx(f => f.lbl_speed.Text = (Strings.avgs + " " + avg_enc.ToString() + "x" + " | " + Math.Round(tot_frames2 / time_n_tasks, 1)).ToString() + " fps"); - } - else - { - list_lines.Add(Environment.NewLine + Strings.avg_perf + " " + avg_enc.ToString() + "x"); - this.InvokeEx(f => f.lbl_speed.Text = Strings.avgs + " " + avg_enc.ToString() + "x"); - } - } - } - catch { } - - //End averages - - if (no_save_logs == false) - { - string[] array_err = list_lines.ToArray(); - String path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.log"; - if (is_portable == true) path = port_path + "ff_batch_portable.log"; - - StreamWriter SaveFile = new StreamWriter(path); - SaveFile.WriteLine("FFmpeg log sesion: " + System.DateTime.Now); - SaveFile.WriteLine("-------------------------------"); - foreach (String item in array_err) - { - SaveFile.WriteLine(item); - } - SaveFile.Close(); - - File.AppendAllText(path, "-----------------------"); - File.AppendAllText(path, Environment.NewLine + Strings.end_log); - FileInfo fileInfo = new FileInfo(path); - - var bytes = fileInfo.Length; - - var kilobytes = (double)bytes / 1024; - var megabytes = kilobytes / 1024; - var gigabytes = megabytes / 1024; - - //Format size view - String size = ""; - String separator = "."; - - if (bytes > 1000000000) - { - if (gigabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String gigas = gigabytes.ToString(); - if (gigas.Length >= 5) - { - gigas = gigas.Substring(0, gigas.LastIndexOf(separator) + 3); - size = (gigas + " " + "GB"); - } - else - { - size = (gigas + " " + "GB"); - } - } - - if (bytes >= 1048576 && bytes <= 1000000000) - { - if (megabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - String megas = megabytes.ToString(); - if (megas.Length > 5) - { - megas = megas.Substring(0, megas.LastIndexOf(separator)); - size = (megas + " " + "MB"); - } - else - { - size = (megas + " " + "MB"); - } - } - - if (bytes >= 1024 && bytes < 1048576) - - { - if (kilobytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String kbs = kilobytes.ToString(); - if (kbs.Length >= 5) - { - kbs = kbs.Substring(0, kbs.LastIndexOf(separator)); - size = (kbs + " " + "KB"); - } - else - { - size = (kbs + " " + "KB"); - } - } - if (bytes > -1 && bytes < 1024) - { - String bits = bytes.ToString(); - size = (bits + " Bytes"); - } - - //End Format size view - File.AppendAllText(path, Environment.NewLine + Strings.log_size + " " + size); - - //End save log - } - - Enable_Controls(); - timer_est_size.Stop(); - time_est_size = 0; - - if (tmp.ExitCode == 0 && cancel_queue == false) - { - if (chkshut.Checked) - { - this.InvokeEx(f => f.groupBox2.Enabled = true); - foreach (Control ct in groupBox2.Controls) - { - this.InvokeEx(f => ct.Enabled = false); - } - auto_shut(); - return; - } - - //End shutdown check - else - { - //Output single info - System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentUICulture; - String sep_th = ci.NumberFormat.CurrencyGroupSeparator; - String dest_mux = destino + "\\" + Path.GetFileNameWithoutExtension(file) + "." + mux_ext; - - if (File.Exists(dest_mux)) - { - - String unit = ""; - String dur = ""; - this.Invoke(new MethodInvoker(delegate - { - lbl_est_size.Text = String.Empty; - lbl_bitrate.Text = String.Empty; - - List lines_ouput = new List(); - probe.StartInfo.FileName = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - ffprobe_frames = " " + "--Output=General;%OverallBitRate/String%" + "\\n" + "%FileSize/String3%" + "\\n" + "%Duration/String3%"; - probe.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + dest_mux + '\u0022'; - probe.StartInfo.RedirectStandardOutput = true; - probe.StartInfo.UseShellExecute = false; - probe.StartInfo.CreateNoWindow = true; - probe.EnableRaisingEvents = true; - probe.Start(); - - while (!probe.StandardOutput.EndOfStream) - { - lines_ouput.Add(probe.StandardOutput.ReadLine()); - } - probe.WaitForExit(); - - if (lines_ouput[0] != null && lines_ouput[0].Length > 0) - { - if (lines_ouput[0].ToLower().Contains(" kb/s")) unit = "Kb/s"; - if (lines_ouput[0].ToLower().Contains(" mb/s")) unit = "Mb/s"; - if (lines_ouput[0].ToLower().Contains(" gb/s")) unit = "Gb/s"; - lines_ouput[0] = lines_ouput[0].Replace(" kb/s", "").Replace(" Mb/s", "").Replace(" Gb/s", ""); - lines_ouput[0] = lines_ouput[0].Replace(" ", sep_th); - lbl_bitrate.Text = Strings.bitrate + ":" + " " + lines_ouput[0] + " " + unit; - } - if (lines_ouput[1] != null && lines_ouput[1].Length > 0) lbl_est_size.Text = Strings.f_size + ":" + " " + lines_ouput[1].Replace("MiB", "MB").Replace("GiB", "GB").Replace("KiB", "KB"); - if (lines_ouput[2] != null && lines_ouput[2].Length > 0) dur = lines_ouput[2]; - })); - - if (no_output_pop == false) - { - Form26 frm26 = new Form26(); - frm26.out_file = dest_mux; - frm26.dur_file = dur; - if (Settings.Default.dark_mode == false) frm26.pic_img = pic_reading.Image; - else frm26.pic_img = pic_reading.InitialImage; - frm26.tot_bit = lbl_bitrate.Text; - frm26.out_size = lbl_est_size.Text; - this.Invoke(new MethodInvoker(delegate - { - frm26.Show(this); - if (frm26.no_pop == true) no_output_pop = true; - })); - } - - } - - //End output single info - - if (play_on_end == true) play_end(); - if (Form.ActiveForm == null) - { - notifyIcon1.Visible = true; - notifyIcon1.BalloonTipText = Strings.mux_ok; - notifyIcon1.BalloonTipIcon = ToolTipIcon.Info; - notifyIcon1.BalloonTipTitle = Strings.mux_ok2; - notifyIcon1.ShowBalloonTip(0); - } - - if (chk_open_compl.Checked) - { - if (Directory.GetFiles(destino).Length != 0) - { - destino = destino.Replace("\\\\", "\\"); - Process open_processed = new Process(); - open_processed.StartInfo.FileName = "explorer.exe"; - open_processed.StartInfo.Arguments = '\u0022' + destino + '\u0022'; - open_processed.Start(); - } - else - { - if (Directory.Exists(destino)) - { - Directory.Delete(destino); - } - } - } - } - } - else - { - if (tmp.ExitCode == 0) - { - this.InvokeEx(f => f.Pg1.Text = "100%"); - this.InvokeEx(f => MessageBox.Show(Strings.mux_abort1, Strings.aborted, MessageBoxButtons.OK, MessageBoxIcon.Error)); - } - else - { - this.InvokeEx(f => f.Pg1.Text = "100%"); - Boolean unsupported = false; - foreach (String lin in list_lines) - { - if (lin.Contains("Could not write header")) unsupported = true; - } - if (unsupported == true) this.InvokeEx(f => MessageBox.Show(Strings.mux_fail1 + " " + Environment.NewLine + Environment.NewLine + Strings.unsupported1 + Environment.NewLine + Environment.NewLine + Strings.check_log, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error)); - else this.InvokeEx(f => MessageBox.Show(Strings.mux_fail1 + " " + Environment.NewLine + Environment.NewLine + err_txt.TrimStart() + Environment.NewLine + Environment.NewLine + Strings.check_log, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error)); - } - } - - }).Start(); - } - - private void ct2_all_Click(object sender, EventArgs e) - { - foreach (ListViewItem item in listView2.SelectedItems) - { - if (list_tracks.Items.Count == 0) - { - tracks_empty = true; - } - else - { - tracks_empty = false; - } - try - { - if (item.SubItems[1].Text == Strings.no_streams1) - { - MessageBox.Show(Strings.no_streams2, Strings.no_streams1, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - catch - { - MessageBox.Show(Strings.no_streams2, Strings.no_streams1, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - for (int i = 1; i < item.SubItems.Count; i++) - { - //Video - Boolean has_video = false; - foreach (ListViewItem track_item in list_tracks.Items) - { - if (track_item.SubItems[2].Text.Contains("Video")) - { - has_video = true; - } - } - - if (item.SubItems[i].Text.Contains("Video") && has_video == false) - { - list_tracks.Items.Add(item.Text, 0); - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add((i - 1).ToString()); - - if (item.SubItems[i].Text.Substring(0, 1) == "(") - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(item.SubItems[i].Text.Substring(7, item.SubItems[i].Text.Length - 7)); - } - else - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(item.SubItems[i].Text); - } - - if (item.SubItems[i].Text.Substring(0, 1) == "(") - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(item.SubItems[i].Text.Substring(1, 3)); - } - else - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(def_lang_und_tracks); - } - - if (has_video == false) - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(Strings.yes); - } - else - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(Strings.no); - } - - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(def_mux_video_enc); - - list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text = Regex.Replace(list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text, @"\([^()]*\)", string.Empty); - list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text = Regex.Replace(list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text, @"\[[^()]*\]", string.Empty); - RegexOptions options = RegexOptions.None; - Regex regex = new Regex("[ ]{2,}", options); - list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text = regex.Replace(list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text, " "); - } - - foreach (ListViewItem track_item in list_tracks.Items) - { - if (track_item.SubItems[2].Text.Contains("Video")) - { - list_tracks.Items.RemoveAt(track_item.Index); - list_tracks.Items.Insert(0, track_item); - } - } - - // Audio - - Boolean has_audio = false; - foreach (ListViewItem track_item in list_tracks.Items) - { - if (track_item.SubItems[2].Text.Contains("Audio")) - { - has_audio = true; - break; - } - } - - if (item.SubItems[i].Text.Contains("Audio")) - { - list_tracks.Items.Add(item.Text, 1); - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add((i - 1).ToString()); - - if (item.SubItems[i].Text.Substring(0, 1) == "(") - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(item.SubItems[i].Text.Substring(7, item.SubItems[i].Text.Length - 7)); - } - else - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(item.SubItems[i].Text); - } - - if (item.SubItems[i].Text.Substring(0, 1) == "(") - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(item.SubItems[i].Text.Substring(1, 3)); - } - else - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(def_lang_und_tracks); - } - - if (has_audio == false) - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(Strings.yes); - } - else - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(Strings.no); - } - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(def_mux_audio_enc); - - list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text = Regex.Replace(list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text, @"\([^()]*\)", string.Empty); - list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text = Regex.Replace(list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text, @"\[[^()]*\]", string.Empty); - RegexOptions options = RegexOptions.None; - Regex regex = new Regex("[ ]{2,}", options); - list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text = regex.Replace(list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text, " "); - } - - //Subtitles - - Boolean has_subs = false; - foreach (ListViewItem track_item in list_tracks.Items) - { - if (track_item.SubItems[2].Text.Contains("Subtitle")) - { - has_subs = true; - break; - } - } - - if (item.SubItems[i].Text.Contains("Subtitle")) - { - list_tracks.Items.Add(item.Text, 2); - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add((i - 1).ToString()); - - if (item.SubItems[i].Text.Substring(0, 1) == "(") - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(item.SubItems[i].Text.Substring(7, item.SubItems[i].Text.Length - 7)); - } - else - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(item.SubItems[i].Text); - } - - if (item.SubItems[i].Text.Substring(0, 1) == "(") - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(item.SubItems[i].Text.Substring(1, 3)); - } - else if (item.SubItems[i].Text.Substring(3, 1) == ")") - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(item.SubItems[i].Text.Substring(0, 3)); - } - else - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(def_lang_und_tracks); - } - - if (has_subs == false) - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(Strings.yes); - } - else - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(Strings.no); - } - if (item.SubItems[i].Text.Contains("dvd_subtitle") || item.SubItems[i].Text.Contains("hdmv_pgs_subtitle")) - - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add("copy"); - } - else - { - list_tracks.Items[list_tracks.Items.Count - 1].SubItems.Add(def_mux_subs_enc); - } - list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text = Regex.Replace(list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text, @"\([^()]*\)", string.Empty); - RegexOptions options = RegexOptions.None; - Regex regex = new Regex("[ ]{2,}", options); - list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text = regex.Replace(list_tracks.Items[list_tracks.Items.Count - 1].SubItems[2].Text, " "); - } - - foreach (ListViewItem track_item in list_tracks.Items) - { - if (track_item.SubItems[2].Text.Contains("Subtitle")) - { - list_tracks.Items.RemoveAt(track_item.Index); - list_tracks.Items.Insert(list_tracks.Items.Count, track_item); - } - } - } - } - - lbl_tr_n.Text = Strings.tracks + " " + list_tracks.Items.Count.ToString(); - tracks_background(); - } - - private void listView2_DoubleClick(object sender, EventArgs e) - { - ct2_all.PerformClick(); - } - - private void list_tracks_KeyUp(object sender, KeyEventArgs e) - { - if (e.KeyCode == Keys.Delete) - { - foreach (ListViewItem elemento in list_tracks.SelectedItems) - { - list_tracks.Items.Remove(elemento); - pic_encode_param.Image = null; - } - } - lbl_tr_n.Text = Strings.tracks + " " + list_tracks.Items.Count.ToString(); - //Review audio track defaults - Boolean has_default = false; - foreach (ListViewItem audio_item in list_tracks.Items) - { - if (audio_item.SubItems[2].Text.Contains("Audio") && - audio_item.SubItems[4].Text == Strings.yes) - { - has_default = true; - break; - } - } - if (has_default == false) - { - foreach (ListViewItem audio_item in list_tracks.Items) - { - if (audio_item.SubItems[2].Text.Contains("Audio")) - { - audio_item.SubItems[4].Text = Strings.yes; - return; - } - } - } - //End review audio track defaults - } - - private void ctm3_Opening(object sender, CancelEventArgs e) - { - if (Settings.Default.dark_mode == true) - { - ctm3.BackColor = Color.FromArgb(255, 64, 64, 64); - ctm3.ForeColor = Color.White; - } - else - { - ctm3.BackColor = SystemColors.InactiveBorder; - ctm3.ForeColor = Control.DefaultForeColor; - } - - if (list_tracks.Items.Count > 1 && list_tracks.SelectedItems.Count > 1) - { - foreach (ToolStripItem ct in ctm3.Items) - { - ct.Visible = false; - } - ct3_save_track.Visible = true; - ct3_del.Visible = true; - return; - } - - foreach (ToolStripItem ct in ctm3.Items) - { - ct.Visible = true; - } - - if (list_tracks.Items.Count == 0 || list_tracks.SelectedIndices.Count == 0) - { - ct3_combo_language.Text = Strings.Language; - e.Cancel = true; - } - - if (list_tracks.SelectedIndices.Count > 1) - { - foreach (ToolStripItem ct in ctm3.Items) - { - ct.Visible = false; - ct3_del.Visible = true; - } - } - if (list_tracks.SelectedIndices.Count == 1) ct3_combo_language.Text = Strings.Language; - } - - private void ct3_combo_language_SelectedIndexChanged(object sender, EventArgs e) - { - if (list_tracks.SelectedIndices.Count > 0) - { - foreach (ListViewItem item in list_tracks.SelectedItems) - { - item.SubItems[3].Text = ct3_combo_language.SelectedItem.ToString().Substring(ct3_combo_language.SelectedItem.ToString().Length - 4, 3); - } - ctm3.Close(); - } - } - - private void ct3_default_Click(object sender, EventArgs e) - { - if (list_tracks.SelectedIndices.Count == 0 || list_tracks.SelectedItems[0].SubItems[3].Text.Contains("Video")) - { - return; - } - - if (list_tracks.SelectedItems[0].SubItems[4].Text == Strings.yes) - { - list_tracks.SelectedItems[0].SubItems[4].Text = Strings.no; - } - else - { - list_tracks.SelectedItems[0].SubItems[4].Text = Strings.yes; - } - - //Review audio defaults - int default_items = 0; - - for (int i = 0; i < list_tracks.Items.Count; i++) - { - if (list_tracks.Items[i].SubItems[2].Text.Contains("Audio") && - list_tracks.Items[i].SubItems[4].Text == Strings.yes) - { - default_items = default_items + 1; - } - } - - if (default_items > 1) - { - foreach (ListViewItem audio_item in list_tracks.Items) - { - if (audio_item.SubItems[2].Text.Contains("Audio") && - audio_item.Text != list_tracks.SelectedItems[0].Text) - { - audio_item.SubItems[2].Text = Strings.no; - } - } - } - else - { - foreach (ListViewItem audio_item in list_tracks.Items) - { - if (audio_item.SubItems[2].Text.Contains("Audio") && - audio_item.Text != list_tracks.SelectedItems[0].Text) - { - audio_item.SubItems[4].Text = Strings.yes; - return; - } - } - } - - //End review audio track defaults - - //Begin subtitle defaults - - //Review audio defaults - int default_subs = 0; - for (int i = 0; i < list_tracks.Items.Count; i++) - { - if (list_tracks.Items[i].SubItems[2].Text.Contains("Subtitle") && - list_tracks.Items[i].SubItems[4].Text == Strings.yes) - { - default_subs = default_subs + 1; - } - } - - if (default_subs > 1) - { - foreach (ListViewItem audio_item in list_tracks.Items) - { - if (audio_item.SubItems[2].Text.Contains("Subtitle") && - audio_item != list_tracks.SelectedItems[0]) - { - audio_item.SubItems[4].Text = Strings.no; - } - } - } - //End subtitle defaults - } - - private void ct3_del_Click(object sender, EventArgs e) - { - foreach (ListViewItem elemento in list_tracks.SelectedItems) - { - list_tracks.Items.Remove(elemento); - pic_encode_param.Image = null; - } - lbl_tr_n.Text = Strings.tracks + " " + list_tracks.Items.Count.ToString(); - //Review audio track defaults - - Boolean has_default = false; - foreach (ListViewItem audio_item in list_tracks.Items) - { - if (audio_item.SubItems[3].Text.Contains("Audio") && - audio_item.SubItems[5].Text == Strings.yes) - { - has_default = true; - break; - } - } - - if (has_default == false) - { - foreach (ListViewItem audio_item in list_tracks.Items) - { - if (audio_item.SubItems[3].Text.Contains("Audio")) - { - audio_item.SubItems[5].Text = Strings.yes; - return; - } - } - } - //End review audio track defaults - } - - private void button23_Click(object sender, EventArgs e) - { - Pg1.Focus(); - list_tracks.Items.Clear(); - txt_track_param.Text = String.Empty; - pic_encode_param.Image = null; - combo_item_lang_2.SelectedIndex = -1; - txt_track_format.Text = String.Empty; - lbl_tr_n.Text = Strings.tracks + " " + "0"; - txt_mux_type.Text = String.Empty; - } - - private void list_tracks_DoubleClick(object sender, EventArgs e) - { - ct3_default.PerformClick(); - } - - private void list_tracks_SelectedIndexChanged(object sender, EventArgs e) - { - if (list_tracks.SelectedIndices.Count > 0) - { - txt_track_param.Text = list_tracks.SelectedItems[0].SubItems[5].Text; - combo_item_lang_2.Text = list_tracks.SelectedItems[0].SubItems[3].Text; - - // -c reminder - if (list_tracks.SelectedItems[0].SubItems[2].Text.ToLower().Contains("video")) txt_mux_type.Text = "-c:v"; - if (list_tracks.SelectedItems[0].SubItems[2].Text.ToLower().Contains("audio")) txt_mux_type.Text = "-c:a"; - if (list_tracks.SelectedItems[0].SubItems[2].Text.ToLower().Contains("subtitle")) txt_mux_type.Text = "-c:s"; - - //Track extension - string ext_track = list_tracks.SelectedItems[0].SubItems[2].Text.ToLower(); - - if (ext_track.Contains("h264")) txt_track_format.Text = "m4v"; - else if (ext_track.Contains("h265")) txt_track_format.Text = "mkv"; - else if (ext_track.Contains("hevc")) txt_track_format.Text = "mkv"; - else if (ext_track.Contains("webm")) txt_track_format.Text = "webm"; - else if (ext_track.Contains("rawvideo")) txt_track_format.Text = "avi"; - else if (ext_track.Contains("divx")) txt_track_format.Text = "avi"; - else if (ext_track.Contains("xvid")) txt_track_format.Text = "avi"; - else if (ext_track.Contains("mov")) txt_track_format.Text = "mov"; - else if (ext_track.Contains("aac")) txt_track_format.Text = "aac"; - else if (ext_track.Contains("m4a")) txt_track_format.Text = "m4a"; - else if (ext_track.Contains("ac3")) txt_track_format.Text = "ac3"; - else if (ext_track.Contains("mp3")) txt_track_format.Text = "mp3"; - else if (ext_track.Contains("pcm")) txt_track_format.Text = "wav"; - else if (ext_track.Contains("flac")) txt_track_format.Text = "flac"; - else if (ext_track.Contains("truehd")) txt_track_format.Text = "thd"; - else if (ext_track.Contains("dts")) txt_track_format.Text = "dts"; - else if (ext_track.Contains("vp7")) txt_track_format.Text = "webm"; - else if (ext_track.Contains("vp8")) txt_track_format.Text = "webm"; - else if (ext_track.Contains("vp9")) txt_track_format.Text = "webm"; - else if (ext_track.Contains("wma")) txt_track_format.Text = "wma"; - else if (ext_track.Contains("wvc1")) txt_track_format.Text = "wmv"; - else if (ext_track.Contains("vorbis")) txt_track_format.Text = "ogg"; - else if (ext_track.Contains("theora")) txt_track_format.Text = "ogv"; - else if (ext_track.Contains("mjpeg")) txt_track_format.Text = "jpg"; - else if (ext_track.Contains("subrip")) txt_track_format.Text = "srt"; - else if (ext_track.Contains("ass")) txt_track_format.Text = "ass"; - else txt_track_format.Text = "mkv"; - - //End track extension - - if (list_tracks.SelectedItems[0].SubItems[5].Text == Strings.image_audio) - { - pic_encode_param.Image = img_streams.Images[4]; - } - else - { - pic_encode_param.Image = img_streams.Images[list_tracks.SelectedItems[0].ImageIndex]; - } - } - else - { - txt_track_param.Text = String.Empty; - combo_item_lang_2.Text = String.Empty; - pic_encode_param.Image = null; - txt_mux_type.Text = String.Empty; - txt_track_format.Text = String.Empty; - } - - if (list_tracks.SelectedIndices.Count > 1) - { - txt_track_format.Text = String.Empty; - txt_mux_type.Text = String.Empty; - } - } - - private void btn_set_track_param_Click(object sender, EventArgs e) - { - ct3_encode_default.PerformClick(); - } - - private void ct3_encode_default_Click(object sender, EventArgs e) - { - if (list_tracks.SelectedIndices.Count > 0) - { - if (list_tracks.SelectedItems[0].SubItems[2].Text.Contains("Subtitle")) - - { - if (list_tracks.SelectedItems[0].SubItems[2].Text.Contains("dvd_subtitle") || (list_tracks.SelectedItems[0].SubItems[3].Text.Contains("hdmv_pgs_subtitle"))) - - { - list_tracks.SelectedItems[0].SubItems[5].Text = "copy"; - } - else - { - def_mux_subs_enc = "copy"; - list_tracks.SelectedItems[0].SubItems[5].Text = "copy"; ; - } - } - else - { - list_tracks.SelectedItems[0].SubItems[5].Text = "copy"; - if (list_tracks.SelectedItems[0].BackColor == Color.LightYellow) - { - list_tracks.SelectedItems[0].BackColor = Color.White; - } - - def_mux_audio_enc = "copy"; - def_mux_video_enc = "copy"; - } - txt_track_param.Text = "copy"; - } - } - - private void txt_track_param_TextChanged(object sender, EventArgs e) - { - if (list_tracks.SelectedIndices.Count > 0) - { - if (txt_track_param.Text != String.Empty && list_tracks.SelectedItems[0].SubItems[5].Text != Strings.image_audio) - { - list_tracks.SelectedItems[0].SubItems[5].Text = txt_track_param.Text; - } - } - - if (txt_track_param.Text.Contains("-c:") || txt_track_param.Text.Contains("acodec") || txt_track_param.Text.Contains("acodec") || txt_track_param.Text.Contains("vcodec")) - { - MessageBox.Show(Strings.codec_params + " " + '\u0022' + "-c:v" + '\u0022' + ", " + '\u0022' + "-c:a" + '\u0022' + ",-acodec, -vcodec" + " " + Strings.not_requ, Strings.param_in, MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } - - private void combo_item_lang_2_SelectedIndexChanged(object sender, EventArgs e) - { - if (list_tracks.Items.Count > 0) - { - foreach (ListViewItem item in list_tracks.Items) - { - item.SubItems[3].Text = combo_item_lang_2.SelectedItem.ToString().Substring(combo_item_lang_2.SelectedItem.ToString().Length - 4, 3); - } - } - } - - private void listView2_DragEnter(object sender, DragEventArgs e) - { - if (e.Data.GetDataPresent(DataFormats.FileDrop, false)) - { - e.Effect = DragDropEffects.All; - if (Settings.Default.dark_mode == false) - - { - using (var bmp1 = new Bitmap(listView2.ClientSize.Width, listView2.ClientSize.Height - 24)) - { - using (var g1 = Graphics.FromImage(bmp1)) - { - g1.DrawImage(pic_drag.Image, 0, 0, bmp1.Width, bmp1.Height); - listView2.BackgroundImage = bmp1; - } - } - } - } - else e.Effect = DragDropEffects.None; - } - - private void listView2_DragDrop(object sender, DragEventArgs e) - { - listView2.BackgroundImage = null; - change_tab_1 = false; - change_tab_2 = false; - - if (tabControl1.SelectedIndex == 1) - { - change_tab_1 = true; - } - else if (tabControl1.SelectedIndex == 2) - { - change_tab_2 = true; - } - - tabControl1.SelectedIndex = 0; - - string[] file_drop = (string[])e.Data.GetData(DataFormats.FileDrop); - - List files2 = new List(); - - int num_drop = 0; - - foreach (String dropped in file_drop) - { - if (Path.GetFileNameWithoutExtension(dropped).Contains("~1")) - { - MessageBox.Show(Strings.err_long_path + Environment.NewLine + Environment.NewLine + dropped, Strings.error3, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (File.Exists(dropped)) - { - files2.Add(dropped); - num_drop = files2.Count(); - } - else - { - if (Directory.Exists(dropped)) - { - if (add_subfs == false) - { - foreach (String file in Directory.GetFiles(dropped)) - { - if (!File.GetAttributes(file).HasFlag(FileAttributes.Hidden)) - { - files2.Add(file); - num_drop = num_drop + 1; - } - } - } - else - { - try - { - foreach (string f in Directory.GetFiles(dropped, "*.*", System.IO.SearchOption.AllDirectories)) - { - if (!File.GetAttributes(f).HasFlag(FileAttributes.Hidden)) - { - files2.Add(f); - num_drop = num_drop + 1; - } - } - } - catch (System.Exception excpt) - { - if (excpt.HResult == -2147024893) - { - MessageBox.Show(Strings.err_long_path + Environment.NewLine + Environment.NewLine + dropped, Strings.error3, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - else MessageBox.Show(Strings.error2 + " " + excpt.Message, Strings.error3, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - } - } - } - - if (num_drop >= 5000) - { - DialogResult a = MessageBox.Show(Strings.adding + " " + num_drop + " " + Strings.files_time, Strings.many_files, MessageBoxButtons.OKCancel, MessageBoxIcon.Question); - if (a == DialogResult.Cancel) - { - return; - } - } - - files_to_add = files2; - canceled_file_adding = false; - btn_cancel_add.Enabled = true; - btn_cancel_add.Visible = true; - btn_cancel_add.Refresh(); - BG_Files.RunWorkerAsync(); - } - - private void listView3_ColumnClick(object sender, ColumnClickEventArgs e) - { - if (e.Column == 0) - { - if (e.Column == lvwColumnSorter3.SortColumn) - { - // Reverse the current sort direction for this column. - if (lvwColumnSorter3.Order == SortOrder.Ascending) - { - lvwColumnSorter3.Order = SortOrder.Descending; - } - else - { - lvwColumnSorter3.Order = SortOrder.Ascending; - } - } - else - { - // Set the column number that is to be sorted; default to ascending. - lvwColumnSorter3.SortColumn = e.Column; - lvwColumnSorter3.Order = SortOrder.Ascending; - } - - // Perform the sort with these new sort options. - this.listView3.Sort(); - } - } - - private void Combo_sub_lang_mux_SelectedIndexChanged(object sender, EventArgs e) - { - foreach (ListViewItem item in listView3.Items) - { - if (item.SubItems[1].Text.Contains(Strings.no_sub_file) == false) - { - item.SubItems[2].Text = Combo_sub_lang_mux.SelectedItem.ToString().Substring(Combo_sub_lang_mux.SelectedItem.ToString().LastIndexOf("(") + 1, 3); - } - } - } - - private void Combo_def_sub_mux_SelectedIndexChanged(object sender, EventArgs e) - { - foreach (ListViewItem item in listView3.Items) - { - if (item.SubItems[1].Text.Contains(Strings.no_sub_file) == false) - { - item.SubItems[4].Text = Combo_def_sub_mux.SelectedItem.ToString(); - } - } - } - - private void ct3_default_enc_Click(object sender, EventArgs e) - { - if (list_tracks.SelectedIndices.Count > 0) - { - if (list_tracks.SelectedItems[0].SubItems[5].Text.Contains(Strings.image_audio)) - { - return; - } - - if (list_tracks.SelectedItems[0].SubItems[2].Text.Contains("Subtitle")) - - { - def_mux_subs_enc = list_tracks.SelectedItems[0].SubItems[5].Text; - } - - if (list_tracks.SelectedItems[0].SubItems[2].Text.Contains("Audio")) - - { - def_mux_audio_enc = list_tracks.SelectedItems[0].SubItems[5].Text; - } - - if (list_tracks.SelectedItems[0].SubItems[2].Text.Contains("Video")) - - { - def_mux_video_enc = list_tracks.SelectedItems[0].SubItems[5].Text; - } - } - } - - private void combo_def_und_lang_Click(object sender, EventArgs e) - { - } - - private void combo_def_und_lang_SelectedIndexChanged(object sender, EventArgs e) - { - def_lang_und_tracks = combo_def_und_lang.SelectedItem.ToString().Substring(combo_def_und_lang.SelectedItem.ToString().Length - 4, 3); - - ctm2.Close(); - } - - private void button24_Click_1(object sender, EventArgs e) - { - folderBrowserDialog1.ShowNewFolderButton = false; - - if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) - { - txt_folder_subs.Text = folderBrowserDialog1.SelectedPath; - txt_folder_subs.BackColor = txt_parameters.BackColor; - listView3.Items.Clear(); - tabControl1.SelectedIndex = 0; - tabControl1.SelectedIndex = 2; - } - } - - private void ctm4_Opening(object sender, CancelEventArgs e) - { - if (Settings.Default.dark_mode == true) - { - ctm4.BackColor = Color.FromArgb(255, 64, 64, 64); - ctm4.ForeColor = Color.White; - } - else - { - ctm4.BackColor = SystemColors.InactiveBorder; - ctm4.ForeColor = Control.DefaultForeColor; - } - - if (listView3.SelectedIndices.Count == 0) - { - e.Cancel = true; - return; - } - if (listView3.SelectedItems[0].SubItems[1].Text == Strings.no_sub2) - { - Combo_single_subs_lang.Enabled = false; - ct4_conv.Enabled = false; - } - else - { - Combo_single_subs_lang.Enabled = true; - ct4_conv.Enabled = true; - } - } - - private void ct4_browse_Click(object sender, EventArgs e) - { - openFileDialog2.Filter = Strings.subtitles + " |*.srt;*.idx;*.ass| " + Strings.all_files + " " + "(*.*) | *.*"; - openFileDialog2.ShowDialog(); - } - - private void openFileDialog2_FileOk_1(object sender, CancelEventArgs e) - { - listView3.SelectedItems[0].SubItems[1].Text = openFileDialog2.FileName; - listView3.SelectedItems[0].SubItems[2].Text = get_sub_lang(openFileDialog2.FileName); - listView3.SelectedItems[0].SubItems[3].Text = Strings.unknown; - - var a = TextFileEncodingDetector.DetectTextFileEncoding(openFileDialog2.FileName); - if (a != null) - { - String txt_enc = a.ToString().Replace("System.Text.", ""); - listView3.SelectedItems[0].SubItems[3].Text = txt_enc.Replace(Strings.Encoding, ""); - } - else - { - listView3.SelectedItems[0].SubItems[3].Text = Strings.unknown; - } - - listView3.SelectedItems[0].SubItems[5].Text = Strings.yes; - listView3.SelectedItems[0].SubItems[5].Text = Strings.ready; - } - - - private void Combo_single_subs_lang_SelectedIndexChanged(object sender, EventArgs e) - { - if (listView3.SelectedIndices.Count > 0) - { - foreach (ListViewItem item in listView3.SelectedItems) - { - item.SubItems[2].Text = Combo_single_subs_lang.SelectedItem.ToString().Substring(Combo_single_subs_lang.SelectedItem.ToString().Length - 4, 3); - } - ctm4.Close(); - } - } - - private void btn_sub_mux_Click(object sender, EventArgs e) - { - cancel_queue = false; - - if (!File.Exists(Path.Combine(Application.StartupPath, "ffmpeg.exe"))) - { - MessageBox.Show(Strings.no_ffmpeg, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (check_ff_md5() == false) - { - Form25 frm25 = new Form25(); - frm25.ShowDialog(); - return; - } - - notifyIcon1.Visible = true; - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - foreach (ListViewItem file in listView3.Items) - { - if (!File.Exists(file.Text)) - { - MessageBox.Show(Strings.file_not_found + " " + file.Text, Strings.file_not_found2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - if (!chk_burn.Checked) - { - foreach (ListViewItem item in listView3.Items) - { - if (item.SubItems[1].Text == Strings.no_sub2) - { - MessageBox.Show(Strings.no_subs3, Strings.information, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - } - - if (listView3.Items.Count == 0) - { - MessageBox.Show(Strings.list_empty, Strings.information, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; - } - - String is_overw = txt_output_subs.Text + "\\" + Path.GetFileNameWithoutExtension(listView3.Items[0].Text) + "." + Combo_ext_sub_mux.SelectedItem.ToString(); - if (is_overw == listView3.Items[0].Text && chk_suffix.Checked == false) - { - MessageBox.Show(Strings.overw_not_en + " " + '\u0022' + Strings.ren_out + '\u0022' + " " + Strings.checkb, Strings.overw_not_all, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (Combo_ext_sub_mux.SelectedIndex == 1) - { - foreach (ListViewItem item in listView3.Items) - { - if (item.SubItems[1].Text.ToLower().Contains("idx")) - { - MessageBox.Show(Strings.vob_unsupport, Strings.container1, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - } - - //Validate subs encoding - Boolean non_eng = false; - Boolean non_utf = false; - - foreach (ListViewItem item in listView3.Items) - { - if (item.SubItems[2].Text != "eng") - { - non_eng = true; - } - if (item.SubItems[3].Text.Contains("UTF") == false && item.SubItems[3].Text.Contains("Unicode") == false) - { - non_utf = true; - } - } - - if (non_utf == true && (Combo_sub_lang_mux.SelectedIndex != 0 || non_eng == true) && chk_burn.CheckState == CheckState.Unchecked) - { - DialogResult a = MessageBox.Show(Strings.non_utf1, Strings.warning, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); - if (a == DialogResult.Cancel) - { - return; - } - } - - if (chk_burn.CheckState == CheckState.Checked) - { - foreach (ListViewItem item in listView3.Items) - { - if (item.SubItems[1].Text.Contains("[") || item.SubItems[1].Text.Contains("]") || ((item.Text.Contains("[") || item.Text.Contains("]")) && item.SubItems[1].Text.Contains(Strings.available))) - { - MessageBox.Show(Strings.subs_wrong1, Strings.warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); - return; - } - } - } - - //Validated list, start processing - - txt_remain.Text = Strings.remain_time + " " + "00h:00m:00s"; - cancel_queue = false; - Pg1.Value = 0; - //pg_current.Value = 0; - Disable_Controls(); - - time_n_tasks = 0; - timer_tasks.Start(); - - //textBox4.Text = "0%"; - - working = true; - - ListView list_proc = new ListView(); - foreach (ListViewItem item in listView3.Items) - { - list_proc.Items.Add((ListViewItem)item.Clone()); - item.BackColor = Color.White; - item.SubItems[5].Text = Strings.queued; - } - - Pg1.Maximum = list_proc.Items.Count; - listView3.SelectedIndices.Clear(); - - Double total_duration = 0; - Double total_prog = 0; - - //Get total duration of files - //Pending duration - - if (dur_ok == false) - { - list_pending_dur.Items.Clear(); - foreach (ListViewItem item in listView1.Items) - { - list_pending_dur.Items.Add((ListViewItem)item.Clone()); - } - BG_Dur.RunWorkerAsync(); - return; - } - - total_duration = Convert.ToInt32(lbl_dur_list.Text.Substring(0, 2)) * 3600; - total_duration = total_duration + Convert.ToInt32(lbl_dur_list.Text.Substring(4, 2)) * 60; - total_duration = total_duration + Convert.ToInt32(lbl_dur_list.Text.Substring(8, 2)); - - Pg1.Minimum = 0; - Pg1.Maximum = 100; - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - - //End get total duration of files - - List list_lines = new List(); - String sub_mux_ext = Combo_ext_sub_mux.SelectedItem.ToString(); - String path_sub = txt_folder_subs.Text; - - String prev_subs_mp4 = String.Empty; - Boolean mkv_selected = true; - - if (Combo_ext_sub_mux.SelectedIndex == 1) - { - prev_subs_mp4 = "-c:s mov_text "; - mkv_selected = false; - } - else - { - prev_subs_mp4 = "-c:s copy "; - } - - if (hard_sub == true) - { - prev_subs_mp4 = String.Empty; - } - - String hw_decode = String.Empty; - if (cb_hwdecode.SelectedItem.ToString() != "none") - { - hw_decode = "-hwaccel " + cb_hwdecode.SelectedItem.ToString(); - } - - //Save selected hw decoder - - String path2 = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_hw_dcd.ini"; - if (is_portable == true) - { - path2 = port_path + "ff_hw_dcd_portable.ini"; - } - String txt_hw_dcd = cb_hwdecode.SelectedItem.ToString(); - if (txt_hw_dcd != "none") - { - File.WriteAllText(path2, txt_hw_dcd); - } - else - { - if (File.Exists(path2)) File.Delete(path2); - } - - //End save hw decoder - - procs.Clear(); - - for (int ii = 0; ii < listView1.Items.Count; ii++) - { - procs.Add("proc_urls_" + ii.ToString(), new Process()); - } - - new System.Threading.Thread(() => - { - System.Threading.Thread.CurrentThread.IsBackground = true; - /* run your code here */ - - String remain_time = "0"; - - //int list_index = 0; - //foreach (ListViewItem file in list_proc.Items) - for (int list_index = 0; list_index < list_proc.Items.Count; list_index++) - { - String file = list_proc.Items[list_index].Text; - // Get specific task list video duration - Process probe = new Process(); - probe.StartInfo.FileName = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - String ffprobe_frames = " " + '\u0022' + "--Inform=General;%Duration/String3%" + '\u0022'; - probe.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + file + '\u0022'; - - probe.StartInfo.RedirectStandardOutput = true; - probe.StartInfo.UseShellExecute = false; - probe.StartInfo.CreateNoWindow = true; - probe.EnableRaisingEvents = true; - probe.Start(); - - String duracion = probe.StandardOutput.ReadLine(); - - probe.WaitForExit(); - - if (duracion != null) - { - TimeSpan time; - if (TimeSpan.TryParse(duracion, out time)) - { - durat_n = TimeSpan.Parse(duracion).TotalSeconds; - } - else durat_n = 0; - } - else - { - durat_n = 0; - } - - //End duration - - //Get number of source file subtitle tracks - Process ff_str = new Process(); - ff_str.StartInfo.FileName = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - ff_str.StartInfo.Arguments = " -i " + '\u0022' + file + '\u0022'; - ff_str.StartInfo.RedirectStandardOutput = true; - ff_str.StartInfo.RedirectStandardError = true; - ff_str.StartInfo.UseShellExecute = false; - ff_str.StartInfo.CreateNoWindow = true; - ff_str.EnableRaisingEvents = true; - ff_str.Start(); - - String stream = ""; - int source_subs = 0; - String is_default = String.Empty; - - while (!ff_str.StandardError.EndOfStream) - { - stream = ff_str.StandardError.ReadLine(); - - if (stream.Contains("Stream #0:")) - { - if (stream.Contains("Subtitle")) - { - source_subs = source_subs + 1; - if (stream.Contains("mov_text") && mkv_selected == true) - { - MessageBox.Show(Strings.source_mov_text, Strings.mp4_subs, MessageBoxButtons.OK, MessageBoxIcon.Information); - Enable_Controls(); - return; - } - else - { - prev_subs_mp4 = "-c:s copy "; - } - - if (list_proc.Items[list_index].SubItems[4].Text == Strings.yes) - { - is_default = is_default + " -disposition:s:" + (source_subs + 1).ToString() + " 0"; - } - } - } - } - - //End get number of subtitle tracks - - if (cancel_queue == true) - { - this.Invoke(new MethodInvoker(delegate - { - btn_seq.Enabled = true; - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - })); - - Enable_Controls(); - working = false; - MessageBox.Show(Strings.queue_abort, Strings.task_abort, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; - } - - String ffm = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - String fullPath = file; - String destino = ""; - - if (txt_output_subs.Text == ".\\FFBatch") - { - destino = file.Substring(0, fullPath.LastIndexOf('\\')) + "\\" + "FFBatch"; - } - else - { - destino = txt_output_subs.Text; - } - String link_sub = list_proc.Items[list_index].SubItems[1].Text; - - if (txt_folder_subs.Text == String.Empty) - { - if (list_proc.Items[list_index].SubItems[1].Text == Strings.srt_sub) - { - link_sub = file.Substring(0, file.LastIndexOf(".")) + ".srt"; - if (!File.Exists(link_sub)) link_sub = file.Substring(0, file.LastIndexOf(".")) + "." + list_proc.Items[list_index].SubItems[2].Text + ".srt"; - } - else if (list_proc.Items[list_index].SubItems[1].Text == Strings.vob_sub) - { - link_sub = file.Substring(0, file.LastIndexOf(".")) + ".idx"; - if (!File.Exists(link_sub)) link_sub = file.Substring(0, file.LastIndexOf(".")) + "." + list_proc.Items[list_index].SubItems[2].Text + ".idx"; - } - else if (list_proc.Items[list_index].SubItems[1].Text == Strings.as_sub) - { - link_sub = file.Substring(0, file.LastIndexOf(".")) + ".ass"; - if (!File.Exists(link_sub)) link_sub = file.Substring(0, file.LastIndexOf(".")) + "." + list_proc.Items[list_index].SubItems[2].Text + ".ass"; - } - } - else - { - if (list_proc.Items[list_index].SubItems[1].Text == Strings.srt_sub) - { - link_sub = path_sub + "\\" + Path.GetFileNameWithoutExtension(file) + ".srt"; - if (!File.Exists(link_sub)) link_sub = path_sub + "\\" + Path.GetFileNameWithoutExtension(file) + "." + list_proc.Items[list_index].SubItems[2].Text + ".srt"; - } - else if (list_proc.Items[list_index].SubItems[1].Text == Strings.vob_sub) - { - link_sub = path_sub + "\\" + Path.GetFileNameWithoutExtension(file) + ".idx"; - if (!File.Exists(link_sub)) link_sub = path_sub + "\\" + Path.GetFileNameWithoutExtension(file) + "." + list_proc.Items[list_index].SubItems[2].Text + ".idx"; - } - else if (list_proc.Items[list_index].SubItems[1].Text == Strings.as_sub) - { - link_sub = path_sub + "\\" + Path.GetFileNameWithoutExtension(file) + ".ass"; - if (!File.Exists(link_sub)) link_sub = path_sub + "\\" + Path.GetFileNameWithoutExtension(file) + "." + list_proc.Items[list_index].SubItems[2].Text + ".ass"; - } - } - if (list_proc.Items[list_index].SubItems[1].Text == Strings.no_sub2) - { - link_sub = String.Empty; - } - - if (list_proc.Items[list_index].SubItems[4].Text == Strings.yes) - { - is_default = is_default + " -disposition:s:" + (source_subs).ToString() + " default"; - } - - String sub_enc = "-c:s copy"; - - if (sub_mux_ext == "mp4") - { - sub_enc = "-c:s mov_text"; - } - if (mkv_selected == true) - { - sub_enc = prev_subs_mp4; - } - add_suffix = ""; - if (chk_suffix.Checked == true) - { - add_suffix = "_FFB"; - } - - String AppParam = ""; - if (hard_sub == true) - { - if (chk_burn_input.Checked == false) - { - link_sub = link_sub.Replace("\\", "\\\\\\\\"); - link_sub = link_sub.Replace(":", "\\\\" + ":" + "\\\\"); - AppParam = hw_decode + " -i " + "" + '\u0022' + file + '\u0022' + " -vf subtitles=" + '\u0022' + link_sub + '\u0022' + " " + txt_hard_subs.Text + " -y " + '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file) + add_suffix + "." + sub_mux_ext + '\u0022'; - } - else - { - String file2 = file; - file2 = file2.Replace("\\", "/\\"); - file2 = file2.Replace(":", "\\\\:"); - AppParam = hw_decode + " -i " + "" + '\u0022' + file + '\u0022' + " -vf " + '\u0022' + "subtitles=" + file2 + ":si=" + n_subs_str.Value.ToString() + '\u0022' + " -sn " + txt_hard_subs.Text + " -y " + '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file) + add_suffix + "." + sub_mux_ext + '\u0022'; - } - } - else - { - AppParam = hw_decode + " -i " + "" + '\u0022' + file + '\u0022' + " -sub_charenc UTF-8 " + "-i " + '\u0022' + link_sub + '\u0022' + " -map 0 -c:v copy -c:a copy " + prev_subs_mp4 + "-map 1:0 " + sub_enc + " " + "-metadata:s:s:" + source_subs + " language=" + list_proc.Items[list_index].SubItems[2].Text + " " + is_default + " -y " + '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file) + add_suffix + "." + sub_mux_ext + '\u0022'; - } - - if (!Directory.Exists(destino)) - { - try - { - Directory.CreateDirectory(destino); - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.error2 + " " + excpt.Message, Strings.write_error2, MessageBoxButtons.OK, MessageBoxIcon.Error); - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - Enable_Controls(); - return; - } - } - - valid_prog = false; - this.InvokeEx(f => f.listView3.Items[list_index].SubItems[5].Text = Strings.processing); - - var tmp = procs["proc_urls_" + list_index.ToString()]; - tmp.StartInfo.FileName = ffm; - tmp.StartInfo.Arguments = AppParam + " -hide_banner"; - tmp.StartInfo.RedirectStandardError = true; - tmp.StartInfo.RedirectStandardInput = true; - tmp.StartInfo.UseShellExecute = false; - tmp.StartInfo.CreateNoWindow = true; - tmp.EnableRaisingEvents = true; - tmp.Start(); - System.Threading.Thread.Sleep(50); - combo_prio.Invoke(new MethodInvoker(delegate - { - if (combo_prio.SelectedIndex != 2) - { - Change_mem_prio(); - } - })); - - valid_prog = true; - - String err_txt = ""; - Double interval = 0; - - while (!tmp.StandardError.EndOfStream) - { - err_txt = tmp.StandardError.ReadLine(); - list_lines.Add(err_txt); - - try - { - if (err_txt.Contains("time=") && err_txt.Contains("time=-") == false) - { - if (valid_prog == true) - { - int start_time_index = err_txt.IndexOf("time=") + 5; - Double sec_prog = TimeSpan.Parse(err_txt.Substring(start_time_index, 8)).TotalSeconds; - Double percent = (sec_prog * 100 / durat_n); - - total_prog = total_prog + (sec_prog - interval); - interval = sec_prog; - int percent2 = Convert.ToInt32(percent); - - Double percent_tot = total_prog * 100 / total_duration; - int percent_tot_2 = Convert.ToInt32(percent_tot); - - if (percent_tot_2 <= 100) - { - this.InvokeEx(f => f.Pg1.Value = percent_tot_2); - this.InvokeEx(f => f.Pg1.Refresh()); - if (Math.Round(percent_tot, 1).ToString().Contains(".") || Math.Round(percent_tot, 1).ToString().Contains(",")) - { - this.InvokeEx(f => f.Pg1.Text = Math.Round(percent_tot, 1).ToString() + "%"); - } - else - { - this.InvokeEx(f => f.Pg1.Text = Math.Round(percent_tot, 1).ToString() + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0" + "%"); - } - - this.InvokeEx(f => TaskbarProgress.SetValue(this.Handle, percent_tot, Pg1.Maximum)); - } - if (percent2 <= 100) - { - int progg = Convert.ToInt16(percent2); - - if (Math.Round(percent, 1).ToString().Contains(".") || Math.Round(percent, 1).ToString().Contains(",")) - { - this.InvokeEx(f => f.listView3.Items[list_index].SubItems[5].Text = Math.Round(percent, 1).ToString() + "%"); - } - else - { - this.InvokeEx(f => f.listView3.Items[list_index].SubItems[5].Text = Math.Round(percent, 1).ToString() + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0" + "%"); - } - } - //Estimated remaining time - - remain_time = err_txt.Substring(err_txt.LastIndexOf("speed=") + 6, err_txt.Length - err_txt.LastIndexOf("speed=") - 6); - remain_time = remain_time.Replace("x", String.Empty); - Double timing1 = 0; - - if (System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",") - { - timing1 = Math.Round(Double.Parse(remain_time.Replace(".", ",")), 2); - } - else - { - timing1 = Math.Round(Double.Parse(remain_time), 2); - } - Decimal timing = (decimal)timing1; - Decimal total_dur_dec = Convert.ToDecimal(total_duration); - Decimal total_prog_dec = Convert.ToDecimal(total_prog); - - Decimal remain_secs = 0; - if (timing > 0) - { - remain_secs = (decimal)(total_dur_dec - total_prog_dec) / timing; - } - - if (remain_secs > 60) - { - remain_secs = remain_secs + 60; - } - String remain_from_secs = ""; - - TimeSpan t = TimeSpan.FromSeconds(Convert.ToDouble(remain_secs)); - remain_from_secs = string.Format("{0:D2}h:{1:D2}", - t.Hours, - t.Minutes); - - this.Invoke(new MethodInvoker(delegate - { - if (remain_secs >= 3600) - { - txt_remain.Text = Strings.remain_time + " " + remain_from_secs + " " + Strings.minutes_abrev; - } - - if (remain_secs < 3600 && remain_secs >= 600) - { - txt_remain.Text = Strings.remain_time + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 1, 2) + " " + Strings.minutes; - } - if (remain_secs < 600 && remain_secs >= 120) - { - txt_remain.Text = Strings.remain_time + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 2, 1) + " " + Strings.minutes; - } - - if (remain_secs <= 59) - { - txt_remain.Text = Strings.remain_time + " " + Convert.ToInt16(remain_secs) + " " + Strings.seconds; - } - })); - - //End remaining time - } - } - } catch { } - //Read output, get progress - } - tmp.WaitForExit(); - tmp.StartInfo.Arguments = String.Empty; - - list_lines.Add(""); - list_lines.Add("---------------------End of " + Path.GetFileName(file) + " log-------------------------------"); - list_lines.Add(""); - - Boolean single_error = false; - - if (tmp.ExitCode == 0 && aborted == false) - { - this.InvokeEx(f => f.listView3.Items[list_index].SubItems[5].Text = Strings.success); - } - else - { - listView3.Invoke(new MethodInvoker(delegate - { - if (listView3.Items[list_index].SubItems[1].Text == Strings.no_sub2) - { - this.InvokeEx(f => f.listView3.Items[list_index].SubItems[5].Text = "No Sub"); - } - else - { - this.InvokeEx(f => f.listView3.Items[list_index].SubItems[5].Text = Strings.error); - } - })); - - if (listView3.Items.Count == 1) - { - single_error = true; - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - cancel_queue = true; - MessageBox.Show(Strings.error_subx + " " + Environment.NewLine + Environment.NewLine + list_lines[list_lines.Count - 5].ToString() + list_lines[list_lines.Count - 4].ToString() + list_lines[list_lines.Count - 3].ToString() + list_lines[list_lines.Count - 2].ToString() + list_lines[list_lines.Count - 1].ToString(), Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - if (list_index == list_proc.Items.Count - 1) - { - this.Invoke(new MethodInvoker(delegate - { - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - Pg1.Value = 100; - Pg1.Text = "100%"; - })); - - working = false; - //Save log - if (no_save_logs == false) - { - string[] array_err = list_lines.ToArray(); - String path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.log"; - if (is_portable == true) path = port_path + "ff_batch_portable.log"; - - StreamWriter SaveFile = new StreamWriter(path); - SaveFile.WriteLine("FFmpeg log sesion: " + System.DateTime.Now); - SaveFile.WriteLine("-------------------------------"); - foreach (String item in array_err) - { - SaveFile.WriteLine(item); - } - SaveFile.Close(); - - File.AppendAllText(path, "-----------------------"); - File.AppendAllText(path, Environment.NewLine + Strings.end_log); - FileInfo fileInfo = new FileInfo(path); - - var bytes = fileInfo.Length; - - var kilobytes = (double)bytes / 1024; - var megabytes = kilobytes / 1024; - var gigabytes = megabytes / 1024; - - //Format size view - String size = ""; - String separator = "."; - - if (bytes > 1000000000) - { - if (gigabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String gigas = gigabytes.ToString(); - if (gigas.Length >= 5) - { - gigas = gigas.Substring(0, gigas.LastIndexOf(separator) + 3); - size = (gigas + " " + "GB"); - } - else - { - size = (gigas + " " + "GB"); - } - } - - if (bytes >= 1048576 && bytes <= 1000000000) - { - if (megabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - String megas = megabytes.ToString(); - if (megas.Length > 5) - { - megas = megas.Substring(0, megas.LastIndexOf(separator)); - size = (megas + " " + "MB"); - } - else - { - size = (megas + " " + "MB"); - } - } - - if (bytes >= 1024 && bytes < 1048576) - - { - if (kilobytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String kbs = kilobytes.ToString(); - if (kbs.Length >= 5) - { - kbs = kbs.Substring(0, kbs.LastIndexOf(separator)); - size = (kbs + " " + "KB"); - } - else - { - size = (kbs + " " + "KB"); - } - } - if (bytes > -1 && bytes < 1024) - { - String bits = bytes.ToString(); - size = (bits + " Bytes"); - } - - //End Format size view - TimeSpan t = TimeSpan.FromSeconds(time_n_tasks); - String tx_elapsed = string.Format("{0:D2}h:{1:D2}m:{2:D2}s", - t.Hours, - t.Minutes, - t.Seconds); - File.AppendAllText(path, Environment.NewLine); - File.AppendAllText(path, Environment.NewLine + Strings.total_time + " " + tx_elapsed); - File.AppendAllText(path, Environment.NewLine + Strings.log_size + " " + size); - - //End save log - } - //Automatic shutdown check - - if (chkshut.Checked && cancel_queue == false) - { - auto_shut(); - return; - } - //End shutdown check - else - { - //End shutdown check - if (cancel_queue == false) - { - if (play_on_end == true) play_end(); - if (Form.ActiveForm == null) - { - notifyIcon1.BalloonTipText = Strings.enc_comp; - notifyIcon1.BalloonTipIcon = ToolTipIcon.Info; - notifyIcon1.BalloonTipTitle = Strings.enc_comp2; - notifyIcon1.ShowBalloonTip(0); - } - if (chk_open_compl.Checked) - { - if (Directory.GetFiles(destino).Length != 0 && single_error == false) - { - Process open_processed = new Process(); - open_processed.StartInfo.FileName = "explorer.exe"; - open_processed.StartInfo.Arguments = '\u0022' + destino + '\u0022'; - open_processed.Start(); - } - else - { - if (Directory.Exists(destino) && Directory.GetFiles(destino).Length == 0) - { - Directory.Delete(destino); - } - } - } - } - else - { - if (single_error == false) - { - Pg1.Text = "100%"; - this.InvokeEx(f => MessageBox.Show(Strings.queue_abort, Strings.aborted, MessageBoxButtons.OK, MessageBoxIcon.Error)); - } - } - } - } - } - - Enable_Controls(); - - if (sub_mux_ext == "mp4") - { - this.InvokeEx(f => f.Combo_def_sub_mux.Enabled = false); - } - else - { - this.InvokeEx(f => f.Combo_def_sub_mux.Enabled = true); - } - }).Start(); - } - private void button25_Click(object sender, EventArgs e) - { - folderBrowserDialog1.ShowNewFolderButton = true; - - if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) - { - txt_output_subs.Text = folderBrowserDialog1.SelectedPath; - txt_output_subs.BackColor = txt_parameters.BackColor; - } - } - - private void button26_Click(object sender, EventArgs e) - { - btn_clear_list.PerformClick(); - } - - private void Combo_ext_sub_mux_SelectedIndexChanged(object sender, EventArgs e) - { - if (Combo_ext_sub_mux.SelectedIndex == 1) - { - Combo_def_sub_mux.Enabled = false; - Combo_def_sub_mux.SelectedIndex = 1; - foreach (ListViewItem item in listView3.Items) - { - if (item.SubItems[5].Text != "No Sub") - { - item.SubItems[5].Text = Strings.no; - } - } - } - else - { - Combo_def_sub_mux.Enabled = true; - Combo_def_sub_mux.SelectedIndex = 0; - foreach (ListViewItem item in listView3.Items) - { - if (item.SubItems[5].Text != "No Sub") - { - item.SubItems[5].Text = Strings.yes; - } - } - } - } - - private void combo_ext_SelectedIndexChanged(object sender, EventArgs e) - { - if (combo_ext.SelectedIndex == 0) return; - if (combo_ext.SelectedIndex == 1) - { - if (list_tracks.Items.Count != 0 && list_tracks.Items[0].BackColor == Color.LightYellow) - { - return; - } - else - { - if (select_mp4 == false) - { - MessageBox.Show(Strings.mp4_warn, Strings.mp4_warn2, MessageBoxButtons.OK, MessageBoxIcon.Information); - select_mp4 = true; - } - - //|| combo_ext.SelectedIndex == 2 - } - } - - if (combo_ext.SelectedIndex == 2 && warn_mux_mov == false) - { - MessageBox.Show(Strings.mov_warn, Strings.mov_warn2, MessageBoxButtons.OK, MessageBoxIcon.Information); - warn_mux_mov = true; - } - - else if (combo_ext.SelectedIndex == 7 && warn_mux_webm == false) - { - MessageBox.Show(Strings.webm_warn, Strings.webm_warn2, MessageBoxButtons.OK, MessageBoxIcon.Information); - warn_mux_webm = true; - } - } - - private void listView3_DragDrop(object sender, DragEventArgs e) - { - change_tab_1 = false; - change_tab_2 = false; - - if (tabControl1.SelectedIndex == 1) - { - change_tab_1 = true; - } - else if (tabControl1.SelectedIndex == 2) - { - change_tab_2 = true; - } - - tabControl1.SelectedIndex = 0; - - string[] file_drop = (string[])e.Data.GetData(DataFormats.FileDrop); - - List files2 = new List(); - - int num_drop = 0; - - foreach (String dropped in file_drop) - { - if (Path.GetFileNameWithoutExtension(dropped).Contains("~1")) - { - MessageBox.Show(Strings.err_long_path + Environment.NewLine + Environment.NewLine + dropped, Strings.error3, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (File.Exists(dropped)) - { - files2.Add(dropped); - num_drop = files2.Count(); - } - else - { - if (Directory.Exists(dropped)) - { - if (add_subfs == false) - { - foreach (String file in Directory.GetFiles(dropped)) - { - if (!File.GetAttributes(file).HasFlag(FileAttributes.Hidden)) - { - files2.Add(file); - num_drop = num_drop + 1; - } - } - } - else - { - try - { - foreach (string f in Directory.GetFiles(dropped, "*.*", System.IO.SearchOption.AllDirectories)) - { - if (!File.GetAttributes(f).HasFlag(FileAttributes.Hidden)) - { - files2.Add(f); - num_drop = num_drop + 1; - } - } - } - catch (System.Exception excpt) - { - if (excpt.HResult == -2147024893) - { - MessageBox.Show(Strings.err_long_path + Environment.NewLine + Environment.NewLine + dropped, Strings.error3, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - else MessageBox.Show(Strings.error2 + " " + excpt.Message, Strings.error3, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - } - } - } - - if (num_drop >= 5000) - { - DialogResult a = MessageBox.Show(Strings.adding + " " + num_drop + " " + Strings.files_time, Strings.many_files, MessageBoxButtons.OKCancel, MessageBoxIcon.Question); - if (a == DialogResult.Cancel) - { - return; - } - } - - files_to_add = files2; - canceled_file_adding = false; - btn_cancel_add.Enabled = true; - btn_cancel_add.Visible = true; - btn_cancel_add.Refresh(); - BG_Files.RunWorkerAsync(); - } - - private void listView3_DragEnter(object sender, DragEventArgs e) - { - if (e.Data.GetDataPresent(DataFormats.FileDrop, false)) - e.Effect = DragDropEffects.All; - else - e.Effect = DragDropEffects.None; - } - - private void listView3_DoubleClick(object sender, EventArgs e) - { - if (listView3.SelectedIndices.Count > 0) - { - if (listView3.SelectedItems[0].SubItems[1].Text == Strings.no_sub2) - { - ct4_browse.PerformClick(); - } - } - } - - private void ct4_del_Click(object sender, EventArgs e) - { - if (listView3.SelectedIndices.Count > 0) - { - foreach (ListViewItem item in listView3.SelectedItems) - { - listView3.Items.RemoveAt(item.Index); - foreach (ListViewItem item2 in listView1.Items) - { - if (item2.Text == item.Text) - { - listView1.Items.RemoveAt(item2.Index); - } - } - foreach (ListViewItem item3 in listView2.Items) - { - if (item3.Text == item.Text) - { - listView2.Items.RemoveAt(item3.Index); - } - } - } - - lbl_items.Text = listView1.Items.Count + " " + Strings.files; - - Double new_dur = 0; - Double current_dur = 0; - - for (int i = 0; i < listView1.Items.Count; i++) - { - if (listView1.Items[i].SubItems[3].Text != Strings.n_a && listView1.Items[i].SubItems[3].Text != Strings.pending) - { - current_dur = TimeSpan.Parse(listView1.Items[i].SubItems[3].Text).TotalSeconds; - new_dur = new_dur + current_dur; - } - } - TimeSpan t = TimeSpan.FromSeconds(new_dur); - String dur = string.Format("{0:D2}h:{1:D2}m:{2:D2}s.{3:D3}ms", - (int)t.TotalHours, - t.Minutes, - t.Seconds, - t.Milliseconds); - lbl_dur_list.Text = dur.Substring(0, 11); - calc_list_size(); - } - } - - private void listView3_KeyUp(object sender, KeyEventArgs e) - { - if (e.KeyCode == Keys.Delete) - { - ct4_del.PerformClick(); - } - } - - private void listView3_Click(object sender, EventArgs e) - { - if (working == true) - { - listView3.SelectedIndices.Clear(); - return; - } - } - - //private void ct3_image_aud_Click(object sender, EventArgs e) - //{ - // if (list_tracks.SelectedItems[0].SubItems[2].Text.Contains("Video")) - // { - // list_tracks.SelectedItems[0].BackColor = Color.LightYellow; - // list_tracks.SelectedItems[0].SubItems[5].Text = Strings.image_audio; - - // String ext_image = Path.GetExtension(list_tracks.SelectedItems[0].Text); - - // if (ext_image != ".jpg" && ext_image != ".jpeg" && ext_image != ".png" && ext_image != ".gif" && ext_image != ".bmp" && ext_image != ".tiff" && ext_image != ".psd") - // { - // if (Extract_img == false) - // { - // if (ss_time_input.Text == "0:00:00") - // { - // MessageBox.Show(Strings.first_frame, Strings.image_audio, MessageBoxButtons.OK, MessageBoxIcon.Information); - // } - - // Extract_img = true; - // } - // } - // combo_ext.SelectedIndex = 1; - // pic_encode_param.Image = img_streams.Images[4]; - // } - // else - // { - // MessageBox.Show(Strings.track_img, Strings.image_audio, MessageBoxButtons.OK, MessageBoxIcon.Error); - // return; - // } - //} - - private void notifyIcon1_Click(object sender, EventArgs e) - { - this.WindowState = FormWindowState.Normal; - this.ShowInTaskbar = true; - this.TopMost = true; - this.TopMost = false; - this.BringToFront(); - this.Focus(); - } - - private void txt_pre_input_Click(object sender, EventArgs e) - { - if (Settings.Default.dark_mode == false) txt_pre_input.BackColor = Color.LightGoldenrodYellow; - else txt_pre_input.BackColor = Color.FromArgb(255, 128, 128, 128); - - } - - private void txt_pre_input_TextChanged(object sender, EventArgs e) - { - btn_fix_pre.Enabled = true; - if (txt_pre_input.Text.Length == 0) - { - txt_pre_input.BackColor = txt_parameters.BackColor; - } - else - { - if (Settings.Default.dark_mode == false) txt_pre_input.BackColor = Color.LightGoldenrodYellow; - else txt_pre_input.BackColor = Color.FromArgb(255, 128, 128, 128); - if (combo_presets.SelectedIndex != 0) btn_save_preset.Enabled = true; - } - } - - private void textBox2_Click(object sender, EventArgs e) - { - if (Settings.Default.dark_mode == false) txt_format.BackColor = Color.LightYellow; - else txt_format.BackColor = Color.FromArgb(255, 128, 128, 128); - } - - private void button27_Click(object sender, EventArgs e) - { - if (list_tracks.SelectedIndices.Count > 0) - { - if (list_tracks.SelectedItems[0].SubItems[5].Text.Contains(Strings.image_audio)) - { - return; - } - - if (list_tracks.SelectedItems[0].SubItems[3].Text.Contains("Subtitle")) - - { - def_mux_subs_enc = list_tracks.SelectedItems[0].SubItems[5].Text; - } - - if (list_tracks.SelectedItems[0].SubItems[3].Text.Contains("Audio")) - - { - def_mux_audio_enc = list_tracks.SelectedItems[0].SubItems[5].Text; - } - - if (list_tracks.SelectedItems[0].SubItems[3].Text.Contains("Video")) - - { - def_mux_video_enc = list_tracks.SelectedItems[0].SubItems[5].Text; - } - } - } - - private void txt_pre_input_Leave(object sender, EventArgs e) - { - if (txt_pre_input.Text == "") - { - txt_pre_input.BackColor = txt_parameters.BackColor; - } - else - { - if (Settings.Default.dark_mode == false) txt_pre_input.BackColor = Color.LightGoldenrodYellow; - else txt_pre_input.BackColor = Color.FromArgb(255, 128, 128, 128); - } - } - - private void timer_tasks_Tick(object sender, EventArgs e) - { - if (paused == true) return; - - time_n_tasks = time_n_tasks + 1; - - TimeSpan t9 = TimeSpan.FromSeconds(time_n_tasks); - String tx_elapsed1 = string.Format("{0:D2}h:{1:D2}m:{2:D2}s", - t9.Hours, - t9.Minutes, - t9.Seconds); - this.InvokeEx(f => f.lbl_elapsed.Text = Strings.time_elapsed + " " + tx_elapsed1); - - if (total_time == true) - { - TimeSpan t = TimeSpan.FromSeconds(time_n_tasks); - String tx_elapsed = string.Format("{0:D2}h:{1:D2}m:{2:D2}s", - t.Hours, - t.Minutes, - t.Seconds); - this.InvokeEx(f => f.txt_remain.Text = Strings.time_elapsed + " " + tx_elapsed); - this.InvokeEx(f => f.txt_remain.Refresh()); - } - } - - private void ss_time_input_TextChanged(object sender, EventArgs e) - { - if (ss_time_input.Text == "0:00:00.000") - { - if (Settings.Default.dark_mode == false) ss_time_input.BackColor = SystemColors.Window; - else ss_time_input.BackColor = Color.FromArgb(255, 96, 96, 96); - - return; - } - - DateTime time; - if (!DateTime.TryParse(ss_time_input.Text, out time)) - { - if (Settings.Default.dark_mode == false) ss_time_input.BackColor = ss_time_input.BackColor = Color.Orange; - else ss_time_input.BackColor = ss_time_input.BackColor = Color.DarkRed; - - } - else - { - if (Settings.Default.dark_mode == false) ss_time_input.BackColor = SystemColors.Window; - else ss_time_input.BackColor = Color.FromArgb(255, 96, 96, 96); - } - - if (ss_time_input.Text.Length > 14) - { - MessageBox.Show(Strings.time_bad, Strings.time_err, MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - } - - private void ss_time_input_Leave(object sender, EventArgs e) - { - if (ss_time_input.Text == "0:00:00.000") - { - if (Settings.Default.dark_mode == false) ss_time_input.BackColor = SystemColors.Window; - else ss_time_input.BackColor = Color.FromArgb(255, 96, 96, 96); - - return; - } - - DateTime time; - if (!DateTime.TryParse(ss_time_input.Text, out time)) - { - if (Settings.Default.dark_mode == false) ss_time_input.BackColor = ss_time_input.BackColor = Color.Orange; - else ss_time_input.BackColor = ss_time_input.BackColor = Color.DarkRed; - - } - else - { - if (Settings.Default.dark_mode == false) ss_time_input.BackColor = SystemColors.Window; - else ss_time_input.BackColor = Color.FromArgb(255, 96, 96, 96); - } - - if (ss_time_input.Text.Length > 14) - { - MessageBox.Show(Strings.time_bad, Strings.time_err, MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - } - - private void ss_time_input_DoubleClick(object sender, EventArgs e) - { - ss_time_input.Text = "0:00:00.000"; - } - - private void btn_add_tracks_Click(object sender, EventArgs e) - { - Pg1.Focus(); - if (listView2.Items.Count == 1) - { - listView2.Items[0].Selected = true; - } - if (listView2.SelectedItems.Count > 1) - { - MessageBox.Show(Strings.one_track, Strings.information, MessageBoxButtons.OK); - return; - } - ct2_all.PerformClick(); - tracks_background(); - - if (listView2.Items.Count > 1 && listView2.SelectedIndices.Count == 0) - { - MessageBox.Show(Strings.no_file_str, Strings.no_file, MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } - - private void calc_list_size() - { - tot_size = 0; - - foreach (ListViewItem file in listView1.Items) - { - String filename = file.SubItems[1].Text + "\\" + file.Text; - FileInfo fileInfo = new FileInfo(filename); - if (File.Exists(filename)) - tot_size = tot_size + fileInfo.Length; - } - - var bytes = tot_size; - var kilobytes = (double)bytes / 1024; - var megabytes = kilobytes / 1024; - var gigabytes = megabytes / 1024; - - //Format size view - - //Get separator - String separator = "."; - - if (bytes > 1000000000) - { - if (gigabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String gigas = gigabytes.ToString(); - if (gigas.Length >= 5) - { - gigas = gigas.Substring(0, gigas.LastIndexOf(separator) + 3); - this.InvokeEx(f => f.lbl_size.Text = gigas + " " + "GB"); - } - else - { - this.InvokeEx(f => f.lbl_size.Text = gigas + " " + "GB"); - } - } - - if (bytes >= 1048576 && bytes < 1000000000) - { - if (megabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - String megas = megabytes.ToString(); - if (megas.Length > 5) - { - megas = megas.Substring(0, megas.LastIndexOf(separator)); - this.InvokeEx(f => f.lbl_size.Text = megas + " " + "MB"); - } - else - { - this.InvokeEx(f => f.lbl_size.Text = megas + " " + "MB"); - } - } - - if (bytes >= 1024 && bytes < 1048576) - { - if (kilobytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - String kbs = kilobytes.ToString(); - if (kbs.Length >= 5) - { - kbs = kbs.Substring(0, kbs.LastIndexOf(separator)); - this.InvokeEx(f => f.lbl_size.Text = kbs + " " + "KB"); - } - else - { - this.InvokeEx(f => f.lbl_size.Text = kbs + " " + "KB"); - } - } - if (bytes > -1 && bytes < 1024) - { - String bits = bytes.ToString(); - this.InvokeEx(f => f.lbl_size.Text = bits + " Bytes"); - } - - //End Format size view - } - - private void calc_list_dur() - - { - //Show total duration - Double Total_dur = 0; - DateTime time; - - - foreach (ListViewItem item in listView1.Items) - { - String filename = item.SubItems[1].Text + "\\" + item.Text; - - if (item.SubItems[3].Text != "0:00:00" && item.SubItems[3].Text != Strings.n_a && item.SubItems[3].Text != Strings.pending && item.SubItems[3].Text != "00:00:00") - { - if (DateTime.TryParse(item.SubItems[3].Text, out time)) Total_dur = Total_dur + TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds; - } - } - - TimeSpan t = TimeSpan.FromSeconds(Total_dur); - String dur = string.Format("{0:D2}h:{1:D2}m:{2:D2}s.{3:D3}ms", - (int)t.TotalHours, - t.Minutes, - t.Seconds, - t.Milliseconds); - lbl_dur_list.Text = dur.Substring(0, 11); - - //End show total duration - } - - private void btn_capture_Click(object sender, EventArgs e) - { - cancel_queue = false; - notifyIcon1.Visible = true; - - //Try preset - - this.Cursor = Cursors.WaitCursor; - - String destino_test = ""; - - if (txt_path_main.Text.Contains(".\\")) - { - if (txt_path_main.Text == (".\\")) - { - destino_test = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos)); - } - else - { - destino_test = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos), txt_path_main.Text.Replace("..\\", String.Empty)); - } - } - else - { - destino_test = txt_path_main.Text; - } - - if (!Directory.Exists(destino_test)) - { - try - { - Directory.CreateDirectory(destino_test); - } - catch - { - MessageBox.Show(Strings.error_writing, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - Process consola_pre = new Process(); - consola_pre.StartInfo.FileName = "ffmpeg.exe"; - consola_pre.StartInfo.Arguments = " -f gdigrab " + txt_pre_input.Text + " -i desktop" + " -t 00:00:00.000 " + " -y " + txt_parameters.Text + " -y " + '\u0022' + destino_test + "\\" + "Rec_Screen_test" + "." + txt_format.Text + '\u0022'; - consola_pre.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - consola_pre.Start(); - consola_pre.WaitForExit(); - String test = destino_test + "\\" + "Rec_Screen_test" + "." + txt_format.Text; - if (File.Exists(destino_test + "\\" + "Rec_Screen_test" + "." + txt_format.Text)) - { - try - { - File.Delete(destino_test + "\\" + "Rec_Screen_test" + "." + txt_format.Text); - } - catch { } - } - if (consola_pre.ExitCode != 0) - { - this.Cursor = Cursors.Arrow; - MessageBox.Show(Strings.scr_fail + Environment.NewLine + Environment.NewLine + Strings.try_scr_pr, Strings.rec_fail, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - this.Cursor = Cursors.Arrow; - - //END try preset - - //SELECT AUDIO - abort_capture = true; - Form frm_audio_input = new Form(); - frm_audio_input.Icon = this.Icon; - - frm_audio_input.Height = 303; - frm_audio_input.Width = 477; - frm_audio_input.FormBorderStyle = FormBorderStyle.Fixed3D; - frm_audio_input.MaximizeBox = false; - frm_audio_input.MinimizeBox = false; - frm_audio_input.Text = Strings.scr_cap; - - Label lbl_11 = new Label(); - lbl_11.Left = 15; - lbl_11.Top = 213; - lbl_11.Width = 440; - lbl_11.Text = Strings.app_min_1; - lbl_11.Parent = frm_audio_input; - - Label lbl_12 = new Label(); - lbl_12.Left = 15; - lbl_12.Top = 234; - lbl_12.Width = 440; - lbl_12.Text = Strings.stop_any; - lbl_12.Parent = frm_audio_input; - - CB1_o.Items.Clear(); - CB1_o.Parent = frm_audio_input; - CB1_o.Left = 15; - CB1_o.Top = 42; - CB1_o.Height = 235; - CB1_o.Width = 429; - CB1_o.DropDownStyle = ComboBoxStyle.DropDownList; - CB1_o.SelectedIndexChanged += new EventHandler(CB1_o_SelectedIndexChanged); - - Label lbl_driver = new Label(); - lbl_driver.Left = 15; - lbl_driver.Top = 72; - lbl_driver.Width = 360; - lbl_driver.Text = Strings.capt_virtual; - lbl_driver.Parent = frm_audio_input; - - LinkLabel boton_driver = new LinkLabel(); - boton_driver.Parent = frm_audio_input; - boton_driver.Left = 381; - boton_driver.Top = 72; - boton_driver.Width = 159; - boton_driver.Height = 20; - boton_driver.Text = Strings.download; - boton_driver.Click += new EventHandler(boton_driver_Click); - - TextBox titulo = new TextBox(); - titulo.Parent = frm_audio_input; - titulo.Top = 10; - titulo.Left = 15; - titulo.Width = 415; - - var fuente = new System.Drawing.Font("Microsoft Sans Serif", 11, FontStyle.Regular); - titulo.Font = fuente; - titulo.BorderStyle = BorderStyle.Fixed3D; - titulo.TextAlign = HorizontalAlignment.Left; - titulo.ReadOnly = true; - titulo.Text = Strings.selc_dev; - titulo.ForeColor = Color.SteelBlue; - titulo.BorderStyle = BorderStyle.None; - titulo.Refresh(); - - Button boton_ok_audio = new Button(); - boton_ok_audio.Parent = frm_audio_input; - boton_ok_audio.Left = 15; - boton_ok_audio.Top = 98; - boton_ok_audio.Width = 429; - boton_ok_audio.Height = 68; - boton_ok_audio.Text = Strings.start_cap; - boton_ok_audio.TabIndex = 0; - boton_ok_audio.TextAlign = ContentAlignment.BottomCenter; - boton_ok_audio.Image = btn_capture.Image; - boton_ok_audio.ImageAlign = ContentAlignment.TopCenter; - boton_ok_audio.Click += new EventHandler(boton_ok_audio_Click); - - Button boton_cancel_audio = new Button(); - boton_cancel_audio.Parent = frm_audio_input; - boton_cancel_audio.Left = 259; - boton_cancel_audio.Top = 174; - boton_cancel_audio.Width = 185; - boton_cancel_audio.Height = 27; - boton_cancel_audio.Text = Strings.abort_cap; - boton_cancel_audio.TextAlign = ContentAlignment.MiddleCenter; - boton_cancel_audio.ImageList = img_abort; - boton_cancel_audio.Image = img_abort.Images[0]; - boton_cancel_audio.ImageAlign = ContentAlignment.MiddleRight; - boton_cancel_audio.Click += new EventHandler(boton_cancel_audio_Click); - - Button boton_refresh_audio = new Button(); - boton_refresh_audio.Parent = frm_audio_input; - boton_refresh_audio.Left = 15; - boton_refresh_audio.Top = 174; - boton_refresh_audio.Width = 185; - boton_refresh_audio.Height = 27; - boton_refresh_audio.Text = Strings.Refresh_list; - boton_refresh_audio.TextAlign = ContentAlignment.MiddleCenter; - boton_refresh_audio.Image = btn_refresh.Image; - boton_refresh_audio.ImageAlign = ContentAlignment.MiddleLeft; - boton_refresh_audio.Click += new EventHandler(boton_refresh_audio_Click); - - Button boton_show_rec = new Button(); - boton_show_rec.Parent = frm_audio_input; - boton_show_rec.Left = 211; - boton_show_rec.Top = 174; - boton_show_rec.Width = 36; - boton_show_rec.Height = 27; - boton_show_rec.ImageList = img_abort; - boton_show_rec.Image = img_abort.Images[1]; - boton_show_rec.ImageAlign = ContentAlignment.MiddleCenter; - boton_show_rec.Click += new EventHandler(boton_show_rec_Click); - - Process consola = new Process(); - - consola.StartInfo.FileName = "ffmpeg.exe"; - - frm_audio_input.StartPosition = FormStartPosition.CenterScreen; - - consola.StartInfo.Arguments = " -list_devices true -f dshow -i dummy"; - - consola.StartInfo.RedirectStandardOutput = true; - consola.StartInfo.RedirectStandardError = true; - consola.StartInfo.UseShellExecute = false; - consola.StartInfo.CreateNoWindow = true; - consola.StartInfo.StandardErrorEncoding = Encoding.UTF8; - consola.EnableRaisingEvents = true; - - consola.Start(); - - CB1_o.Items.Add(Strings.none); - String out_ff = String.Empty; - Boolean start_audio_sources = false; - while (!consola.StandardError.EndOfStream) - { - out_ff = consola.StandardError.ReadLine(); - if (out_ff.Contains("DirectShow audio devices")) - { - start_audio_sources = true; - } - - if (start_audio_sources == true) - { - if (out_ff.Substring(out_ff.Length - 2, 2) != "}" + "\u0022" && out_ff.Contains("DirectShow audio devices") == false && out_ff.Contains("Alternative name") == false && out_ff.Contains("dummy") == false) - { - //if (out_ff.Contains("ó")) out_ff = out_ff.Replace("ó", "ó"); - int trim1 = out_ff.IndexOf("\u0022") + "\u0022".Length; - int trim2 = out_ff.LastIndexOf("\u0022"); - if (trim2 - trim1 > 0) this.InvokeEx(f => CB1_o.Items.Add(out_ff.Substring(trim1, trim2 - trim1))); - } - } - } - consola.StartInfo.Arguments = String.Empty; - CB1_o.Refresh(); - CB1_o.SelectedIndex = 0; - if (CB1_o.Items.Count == 1) CB1_o.Enabled = false; - - for (int i = 0; i < CB1_o.Items.Count; i++) - { - if (CB1_o.Items[i].ToString() == prev_dev_audio) - { - CB1_o.SelectedIndex = i; - break; - } - } - - this.Cursor = Cursors.Arrow; - frm_audio_input.ShowDialog(); - - //END AUDIO SELECT - if (abort_capture == true) return; - - //Validated list, start processing - recording_scr = true; - txt_remain.Text = Strings.remain_time + " " + "00h:00m:00s"; - - cancel_queue = false; - Pg1.Value = 0; - //pg_current.Value = 0; - Disable_Controls(); - chk_delete_source.Enabled = false; - - //textBox4.Text = "0%"; - - working = true; - - ListView list_proc = new ListView(); - foreach (ListViewItem item in listView1.Items) - { - list_proc.Items.Add(item.Text); - item.BackColor = Color.White; - } - - Pg1.Maximum = list_proc.Items.Count; - listView1.SelectedIndices.Clear(); - lbl_elapsed.Text = Strings.time_elapsed + " " + "00h:00m:00s"; - time_n_tasks = 0; - - new System.Threading.Thread(() => - { - System.Threading.Thread.CurrentThread.IsBackground = true; - - String ffm = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - - String destino = ""; - - if (txt_path_main.Text.Contains(".\\")) - { - if (txt_path_main.Text == (".\\")) - { - destino = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos)); - } - else - { - destino = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos), txt_path_main.Text.Replace("..\\", String.Empty)); - } - } - else - { - destino = txt_path_main.Text; - } - capture_count = capture_count + 1; - - if (File.Exists(destino + "\\" + "Rec_Screen_" + capture_count.ToString() + "." + txt_format.Text) == true) - { - MessageBox.Show(Strings.file + " " + destino + "\\" + "Rec_Screen_" + capture_count.ToString() + "." + txt_format.Text + " exits", "Destination file exists", MessageBoxButtons.OK, MessageBoxIcon.Error); - Enable_Controls(); - working = false; - return; - } - //Recording countdown - this.Invoke(new MethodInvoker(delegate - { - btn_abort_all.Enabled = false; - lbl_capture.Enabled = true; - lbl_capture.Text = ""; - lbl_capture.Visible = true; - lbl_capture.Text = Strings.capt_3; - lbl_capture.Refresh(); - Thread.Sleep(1000); - lbl_capture.Text = Strings.capt_2; - lbl_capture.Refresh(); - Thread.Sleep(1000); - lbl_capture.Text = Strings.capt_1; - lbl_capture.Refresh(); - this.WindowState = FormWindowState.Minimized; - Thread.Sleep(1000); - timer_tasks.Start(); - lbl_capture.Text = ""; - lbl_capture.Visible = false; - btn_abort_all.Enabled = true; - })); - //End recording countdown - - String pre_input_var = ""; - if (txt_pre_input.Text != "") - { - pre_input_var = txt_pre_input.Text; - } - String AppParam = String.Empty; - if (audio_capture_device == Strings.none) - { - AppParam = " -f gdigrab " + pre_input_var + " -i desktop " + txt_parameters.Text + " -y " + '\u0022' + destino + "\\" + "Rec_Screen_" + capture_count.ToString() + "." + txt_format.Text + '\u0022'; - } - else - { - AppParam = " -f dshow -i audio=" + '\u0022' + audio_capture_device + '\u0022' + " -f gdigrab " + pre_input_var + " -i desktop " + txt_parameters.Text + " -y " + '\u0022' + destino + "\\" + "Rec_Screen_" + capture_count.ToString() + "." + txt_format.Text + '\u0022'; - } - - if (!Directory.Exists(destino)) - { - Directory.CreateDirectory(destino); - } - - valid_prog = false; - this.InvokeEx(f => f.pic_warnings.Visible = false); - this.InvokeEx(f => f.pic_recording.Visible = true); - - process_rec.StartInfo.FileName = ffm; - process_rec.StartInfo.Arguments = AppParam; - - process_rec.StartInfo.RedirectStandardError = false; - process_rec.StartInfo.RedirectStandardInput = true; - process_rec.StartInfo.UseShellExecute = false; - process_rec.StartInfo.CreateNoWindow = true; - process_rec.EnableRaisingEvents = true; - process_rec.Start(); - process_rec.WaitForExit(); - recording_scr = false; - timer1.Stop(); - this.InvokeEx(f => f.pic_recording.Visible = false); - Enable_Controls(); - working = false; - - if (process_rec.ExitCode == 1) - { - MessageBox.Show(Strings.invalid_param, Strings.invalid_p_2, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - - if (process_rec.ExitCode != -1073741510 && process_rec.ExitCode != 1 && process_rec.ExitCode != 0) - { - MessageBox.Show(Strings.scsr_term, Strings.capt_term, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - - timer_tasks.Stop(); - TimeSpan t = TimeSpan.FromSeconds(time_n_tasks); - String tx_elapsed = string.Format("{0:D2}h:{1:D2}m:{2:D2}s", - t.Hours, - t.Minutes, - t.Seconds); - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + "00h:00m:00s"); - - if (chk_open_compl.Checked) - { - if (Directory.GetFiles(destino).Length != 0 && process_rec.ExitCode == 0) - { - Process open_processed = new Process(); - open_processed.StartInfo.FileName = "explorer.exe"; - open_processed.StartInfo.Arguments = '\u0022' + destino + '\u0022'; - open_processed.Start(); - } - } - }).Start(); - } - - private void boton_driver_Click(object sender, EventArgs e) - { - Process.Start("https://github.com/rdp/screen-capture-recorder-to-video-windows-free/releases/tag/v0.12.11"); - } - - private void boton_show_rec_Click(object sender, EventArgs e) - { - Process.Start("control", "mmsys.cpl,,1"); - } - - private void boton_refresh_audio_Click(object sender, EventArgs e) - { - Process consola = new Process(); - - consola.StartInfo.FileName = "ffmpeg.exe"; - consola.StartInfo.Arguments = " -list_devices true -f dshow -i dummy"; - - consola.StartInfo.RedirectStandardOutput = true; - consola.StartInfo.RedirectStandardError = true; - consola.StartInfo.UseShellExecute = false; - consola.StartInfo.CreateNoWindow = true; - consola.StartInfo.StandardErrorEncoding = Encoding.UTF8; - consola.EnableRaisingEvents = true; - - consola.Start(); - - CB1_o.Items.Clear(); - CB1_o.Items.Add(Strings.none); - String out_ff = String.Empty; - Boolean start_audio_sources = false; - while (!consola.StandardError.EndOfStream) - { - out_ff = consola.StandardError.ReadLine(); - if (out_ff.Contains("DirectShow audio devices")) - { - start_audio_sources = true; - } - - if (start_audio_sources == true) - { - if (out_ff.Substring(out_ff.Length - 2, 2) != "}" + "\u0022" && out_ff.Contains("DirectShow audio devices") == false && out_ff.Contains("Alternative name") == false && out_ff.Contains("dummy") == false) - { - //if (out_ff.Contains("ó")) out_ff = out_ff.Replace("ó", "ó"); - int trim1 = out_ff.IndexOf("\u0022") + "\u0022".Length; - int trim2 = out_ff.LastIndexOf("\u0022"); - if (trim2 - trim1 > 0) this.InvokeEx(f => CB1_o.Items.Add(out_ff.Substring(trim1, trim2 - trim1))); - } - } - } - CB1_o.Refresh(); - CB1_o.SelectedIndex = 0; - if (CB1_o.Items.Count > 1) - { - CB1_o.Enabled = true; - CB1_o.DroppedDown = true; - } - else - { - CB1_o.Enabled = false; - } - - consola.StartInfo.Arguments = String.Empty; - this.Cursor = Cursors.Arrow; - } - - private void boton_cancel_path_Click(object sender, EventArgs e) - { - ActiveForm.Close(); - } - - private void boton_cancel_audio_Click(object sender, EventArgs e) - { - ActiveForm.Close(); - } - - private void chk_burn_CheckedChanged(object sender, EventArgs e) - { - if (chk_burn.CheckState == CheckState.Checked) - { - hard_sub = true; - txt_hard_subs.Enabled = true; - Enable_txt_hard_Subs = true; - Combo_def_sub_mux.Enabled = false; - Combo_sub_lang_mux.Enabled = false; - chk_burn_input.Enabled = true; - } - else - { - hard_sub = false; - txt_hard_subs.Enabled = false; - Enable_txt_hard_Subs = false; - Combo_def_sub_mux.Enabled = true; - Combo_sub_lang_mux.Enabled = true; - chk_burn_input.Enabled = false; - } - } - - private void txt_fin_TextChanged(object sender, EventArgs e) - { - DateTime time; - if (!DateTime.TryParse(txt_fin.Text, out time)) - { - txt_fin.BackColor = Color.Orange; - } - else - { - if (Settings.Default.dark_mode == false) txt_fin.BackColor = SystemColors.Window; - else txt_fin.BackColor = Color.FromArgb(255, 96, 96, 96); - } - - if (txt_fin.Text.Length > 12) - { - MessageBox.Show(Strings.time_bad, Strings.time_err, MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - } - - private void txt_fin_DoubleClick_1(object sender, EventArgs e) - { - if (listView1.SelectedIndices.Count > 0) - { - txt_fin.Text = listView1.SelectedItems[0].SubItems[3].Text; - } - else - { - txt_fin.Text = "0:00:00.000"; - } - } - - private void txt_ini_TextChanged(object sender, EventArgs e) - { - DateTime time; - - if (!DateTime.TryParse(txt_ini.Text, out time)) - { - txt_ini.BackColor = Color.Orange; - } - else - { - if (Settings.Default.dark_mode == false) txt_ini.BackColor = SystemColors.Window; - else txt_ini.BackColor = Color.FromArgb(255, 96, 96, 96); - } - - if (txt_ini.Text.Length > 12) - { - MessageBox.Show(Strings.time_bad, Strings.time_err, MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - } - - private void txt_ini_Leave(object sender, EventArgs e) - { - if (txt_ini.Text == "0:00:00.000") - { - if (Settings.Default.dark_mode == false) txt_ini.BackColor = SystemColors.Window; - else txt_ini.BackColor = Color.FromArgb(255, 96, 96, 96); - return; - } - - DateTime time2; - if (!DateTime.TryParse(txt_ini.Text, out time2)) - { - txt_ini.BackColor = Color.Orange; - } - else - { - if (Settings.Default.dark_mode == false) txt_ini.BackColor = SystemColors.Window; - else txt_ini.BackColor = Color.FromArgb(255, 96, 96, 96); - } - } - - private void txt_ini_DoubleClick(object sender, EventArgs e) - { - txt_ini.Text = "0:00:00.000"; - } - - private void txt_fin_Leave(object sender, EventArgs e) - { - if (txt_fin.Text == "0:00:00.000") - { - if (Settings.Default.dark_mode == false) txt_fin.BackColor = SystemColors.Window; - else txt_fin.BackColor = Color.FromArgb(255, 96, 96, 96); - return; - } - - DateTime time2; - if (!DateTime.TryParse(txt_fin.Text, out time2)) - { - txt_fin.BackColor = Color.Orange; - } - else - { - if (Settings.Default.dark_mode == false) txt_fin.BackColor = SystemColors.Window; - else txt_fin.BackColor = Color.FromArgb(255, 96, 96, 96); - } - } - - private void cti5_Click(object sender, EventArgs e) - { - if (listView1.SelectedItems.Count > 0) - { - String fullPath = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - if (File.Exists(fullPath)) - { - if (listView1.SelectedItems[0].SubItems[3].Text != Strings.pending && listView1.SelectedItems[0].SubItems[3].Text != Strings.n_a) - { - txt_fin.Text = listView1.SelectedItems[0].SubItems[3].Text; - txt_fin.BackColor = Color.LightYellow; - return; - } - } - else - { - MessageBox.Show(Strings.file_not_found, Strings.file_miss, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - - private void ct4_conv_Click(object sender, EventArgs e) - { - if (listView3.SelectedItems[0].SubItems[1].Text == Strings.vob_sub) - { - MessageBox.Show(Strings.vob_conv, Strings.information, MessageBoxButtons.OK, MessageBoxIcon.Information); - return; - } - - String dest; - String sub_ext; - String source_sub; - - foreach (ListViewItem item in listView3.SelectedItems) - { - if (item.SubItems[1].Text == Strings.srt_sub) - { - sub_ext = "srt"; - if (txt_folder_subs.Text.Length == 0) - { - source_sub = Path.Combine(Path.GetDirectoryName(item.Text), Path.GetFileNameWithoutExtension(item.Text) + "." + sub_ext); - if (!File.Exists(source_sub)) source_sub = Path.Combine(Path.GetDirectoryName(item.Text), Path.GetFileNameWithoutExtension(item.Text) + "." + item.SubItems[2].Text + "." + sub_ext); - dest = Path.Combine(Path.GetDirectoryName(item.Text), Path.GetFileNameWithoutExtension(item.Text) + "_utf8." + sub_ext); - } - else - { - source_sub = Path.Combine(txt_folder_subs.Text, Path.GetFileNameWithoutExtension(item.Text) + "." + sub_ext); - if (!File.Exists(source_sub)) source_sub = Path.Combine(txt_folder_subs.Text, Path.GetFileNameWithoutExtension(item.Text) + "." + item.SubItems[2].Text + "." + sub_ext); - dest = Path.Combine(txt_folder_subs.Text, Path.GetFileNameWithoutExtension(item.Text) + "_utf8." + sub_ext); - } - } - else if (item.SubItems[1].Text == Strings.as_sub) - { - sub_ext = "ass"; - if (txt_folder_subs.Text.Length == 0) - { - source_sub = Path.Combine(Path.GetDirectoryName(item.Text), Path.GetFileNameWithoutExtension(item.Text) + "." + sub_ext); - if (!File.Exists(source_sub)) source_sub = Path.Combine(Path.GetDirectoryName(item.Text), Path.GetFileNameWithoutExtension(item.Text) + "." + item.SubItems[2].Text + "." + sub_ext); - dest = Path.Combine(Path.GetDirectoryName(item.Text), Path.GetFileNameWithoutExtension(item.Text) + "_utf8." + sub_ext); - } - else - { - source_sub = Path.Combine(txt_folder_subs.Text, Path.GetFileNameWithoutExtension(item.Text) + "." + sub_ext); - if (!File.Exists(source_sub)) source_sub = Path.Combine(txt_folder_subs.Text, Path.GetFileNameWithoutExtension(item.Text) + "." + item.SubItems[2].Text + "." + sub_ext); - dest = Path.Combine(txt_folder_subs.Text, Path.GetFileNameWithoutExtension(item.Text) + "_utf8." + sub_ext); - } - } - else - { - sub_ext = item.SubItems[1].Text; - source_sub = item.SubItems[1].Text; - dest = Path.Combine(Path.GetDirectoryName(item.SubItems[1].Text), Path.GetFileNameWithoutExtension(item.SubItems[1].Text) + "_utf8" + Path.GetExtension(item.SubItems[1].Text)); - } - - String f1 = File.ReadAllText(source_sub, Encoding.Default); - - File.WriteAllText(Path.Combine(Path.GetDirectoryName(item.Text), dest), f1, Encoding.UTF8); - item.SubItems[1].Text = dest; - - var a = TextFileEncodingDetector.DetectTextFileEncoding(dest); - if (a != null) - { - String txt_enc = a.ToString().Replace("System.Text.", ""); - item.SubItems[3].Text = txt_enc.Replace(Strings.Encoding, ""); - } - else - { - item.SubItems[3].Text = Strings.unknown; - } - } - } - - private void refresh_full() - { - List files2 = new List(); - int num_drop = 0; - - foreach (ListViewItem item in listView1.Items) - { - String filename = item.SubItems[1].Text + "\\" + item.Text; - if (File.Exists(filename)) - { - files2.Add(filename); - } - } - num_drop = files2.Count(); - - files_to_add = files2; - listView1.Items.Clear(); - - canceled_file_adding = false; - - btn_cancel_add.Enabled = true; - btn_cancel_add.Visible = true; - btn_cancel_add.Refresh(); - - BG_Files.RunWorkerAsync(); - } - - private void clean_cols() - { - listView1.Invoke(new MethodInvoker(delegate - { - foreach (ColumnHeader col in listView1.Columns) - { - String c = col.Text.Replace("<", "").Replace(">", "").TrimStart(); - - if (c != Properties.Strings.filename && c != Properties.Strings.path && c != Properties.Strings.file_type && c != Properties.Strings.size && c != Properties.Strings.duration && c != Properties.Strings.status) - { - listView1.Columns.Remove(col); - } - } - })); - } - - private String get_sub_lang(String fn) - { - foreach (String str in Combo_sub_lang_mux.Items) - { - String fn1 = fn.Substring(fn.LastIndexOf(".") - 3, 3); - String lang = str.Substring(str.Length - 4, 3); - if (fn1 == lang) - { - return lang; - break; - } - } - return "und"; - } - - private void btn_refresh_Click(object sender, EventArgs e) - { - Pg1.Focus(); - if (tabControl1.SelectedIndex == 3) - { - btn_validate_url.PerformClick(); - return; - } - - if (listView1.Items.Count == 0) - { - return; - } - //Clean file thumbs - String destino_test = Path.GetTempPath() + "\\" + "FFBatch_test"; - try - { - if (Directory.Exists(destino_test) && Directory.GetFiles(destino_test).Length > 0) - { - foreach (String file in Directory.GetFiles(destino_test)) - { - try - { - File.Delete(file); - } - catch { } - } - } - } - catch { } - - refresh_full(); - calc_list_dur(); - - lbl_items.Text = listView1.Items.Count + " " + Strings.files; - - if (tabControl1.SelectedIndex == 0 || tabControl1.SelectedIndex == 1) - { - chk_open_compl.Visible = true; - combo_ext.Visible = false; - label19.Visible = false; - btn_set_mux_def.Visible = false; - - group_subs.Visible = false; - label17.Visible = false; - combo_item_lang_2.Visible = false; - btn_clean_list.Visible = true; - - label13.Visible = true; - txt_path_main.Visible = true; - btn_br_path.Visible = true; - chkshut.Visible = true; - btn_mux.Visible = false; - - button23.Visible = false; - pic_encode_param.Visible = false; - lbl_mux_par.Visible = false; - txt_track_param.Visible = false; - btn_set_track_param.Visible = false; - groupBox1.Visible = true; - panel1.Visible = true; - list_tracks.Visible = false; - return; - } - if (tabControl1.SelectedIndex == 1) - { - bg_add_tab2.RunWorkerAsync(); - } - - else if (tabControl1.SelectedIndex == 2) - { - btn_set_mux_def.Visible = false; - btn_set_track_param.Visible = false; - - group_subs.Visible = true; - - TB1.Visible = false; - txt_hard_subs.Text = txt_parameters.Text; - //Check listview1 vs listview2 - int list_int = 0; - if (listView1.Items.Count == listView3.Items.Count) - { - foreach (ListViewItem item in listView1.Items) - { - if (listView3.Items[list_int].Text == item.Text) - { - list_int = list_int + 1; - } - } - } - if (list_int == listView1.Items.Count) - { - return; - } - else - { - listView3.Items.Clear(); - } - - listView3.SmallImageList = listView1.SmallImageList; - foreach (ListViewItem item in listView1.Items) - { - this.Cursor = Cursors.WaitCursor; - ListViewItem elemento = new ListViewItem(item.Text, 1); - //Begin get file icon - Icon iconForFile = SystemIcons.WinLogo; - - // Check to see if the image collection contains an image - // for this extension, using the extension as a key. - if (!imageList2.Images.ContainsKey(Path.GetExtension(item.Text))) - { - // If not, add the image to the image list. - iconForFile = System.Drawing.Icon.ExtractAssociatedIcon(item.Text); - imageList2.Images.Add(Path.GetExtension(item.Text), iconForFile); - } - - elemento.ImageKey = Path.GetExtension(item.Text); - //End get file icon - - listView3.Items.Add(elemento); - } - - foreach (ListViewItem item in listView3.Items) - { - String extension = item.Text.Substring(item.Text.LastIndexOf(".")); - - if (extension == ".srt" || extension == ".idx" || extension == ".sub" || extension == ".ass") - { - listView3.Items.RemoveAt(item.Index); - } - - String subs_path = String.Empty; - String Sub_File_SRT = String.Empty; - String Sub_File_Vobsub = String.Empty; - String Sub_File_ASS = String.Empty; - - if (txt_folder_subs.Text == String.Empty) - { - Sub_File_SRT = item.Text.Substring(0, item.Text.LastIndexOf(".")) + ".srt"; - Sub_File_Vobsub = item.Text.Substring(0, item.Text.LastIndexOf(".")) + ".idx"; - Sub_File_ASS = item.Text.Substring(0, item.Text.LastIndexOf(".")) + ".ass"; - } - else - { - String path_sub = txt_folder_subs.Text; - Path.GetFileName(item.Text); - Sub_File_SRT = path_sub + "\\" + Path.GetFileName(item.Text).Substring(0, Path.GetFileName(item.Text).LastIndexOf(".")) + ".srt"; - Sub_File_Vobsub = path_sub + "\\" + Path.GetFileName(item.Text).Substring(0, Path.GetFileName(item.Text).LastIndexOf(".")) + ".idx"; - Sub_File_ASS = path_sub + "\\" + Path.GetFileName(item.Text).Substring(0, Path.GetFileName(item.Text).LastIndexOf(".")) + ".ass"; - } - - if (item.SubItems[1].Text.Contains(Strings.no_sub_file) == false) - { - if (File.Exists(Sub_File_SRT)) - { - item.SubItems.Add(Strings.srt_sub); - item.SubItems.Add("und"); - - var a = TextFileEncodingDetector.DetectTextFileEncoding(Sub_File_SRT); - if (a != null) - { - String txt_enc = a.ToString().Replace("System.Text.", ""); - item.SubItems.Add(txt_enc.Replace(Strings.Encoding, "")); - } - else - { - item.SubItems.Add(Strings.unknown); - } - item.SubItems.Add(Strings.yes); - item.SubItems.Add(Strings.ready); - } - - if (File.Exists(Sub_File_Vobsub)) - { - item.SubItems.Add(Strings.vob_sub); - item.SubItems.Add("und"); - - item.SubItems.Add("-"); - item.SubItems.Add(Strings.yes); - item.SubItems.Add(Strings.ready); - } - if (File.Exists(Sub_File_ASS)) - { - item.SubItems.Add(Strings.as_sub); - item.SubItems.Add("und"); - - var a = TextFileEncodingDetector.DetectTextFileEncoding(Sub_File_ASS); - if (a != null) - { - String txt_enc = a.ToString().Replace("System.Text.", ""); - item.SubItems.Add(txt_enc.Replace(Strings.Encoding, "")); - } - else - { - item.SubItems.Add(Strings.unknown); - } - item.SubItems.Add(Strings.yes); - item.SubItems.Add(Strings.ready); - } - } - - if (!File.Exists(Sub_File_Vobsub) && !File.Exists(Sub_File_SRT) && !File.Exists(Sub_File_ASS)) - { - item.SubItems.Add(Strings.no_sub2); - item.SubItems.Add("-"); - item.SubItems.Add("-"); - item.SubItems.Add("-"); - item.SubItems.Add("No Sub"); - } - } - Combo_sub_lang_mux.Text = ""; - this.Cursor = Cursors.Arrow; - } - } - - - private void chk_subfolders_CheckedChanged(object sender, EventArgs e) - { - add_subfs = chk_subfolders.Checked; - Boolean prev_state = chk_subfolders.CheckState == CheckState.Unchecked; - - String path = String.Empty; - if (is_portable == false) - { - path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.ini"; - } - else - { - path = port_path + "ff_batch_portable.ini"; - } - - int linea = 0; - - foreach (string line in File.ReadLines(path)) - { - linea = linea + 1; - - if (linea == 7) - { - if (line == "subf_yes") - { - if (prev_state == false) - { - btn_save_config.ImageKey = "Save_settings_39.png"; - toolTip_settings.SetToolTip(this.btn_save_config, Strings.params_def); - } - else - { - btn_save_config.ImageKey = "save_pending.png"; - toolTip_settings.SetToolTip(this.btn_save_config, Strings.setting_mod); - } - } - - else if (line == "subf_no") - { - if (prev_state == true) - { - btn_save_config.ImageKey = "Save_settings_39.png"; - toolTip_settings.SetToolTip(this.btn_save_config, Strings.params_def); - } - else - { - btn_save_config.ImageKey = "save_pending.png"; - toolTip_settings.SetToolTip(this.btn_save_config, Strings.setting_mod); - } - } - } - } - } - - private void textBox2_Leave(object sender, EventArgs e) - { - txt_format.BackColor = txt_parameters.BackColor; - } - - private void chk_suffix_CheckedChanged(object sender, EventArgs e) - { - if (chk_suffix.CheckState == CheckState.Checked) - { - txt_suffix.Enabled = true; - txt_suffix.BackColor = Color.White; - } - else - { - txt_suffix.Enabled = false; - txt_suffix.BackColor = SystemColors.InactiveBorder; - } - - Boolean prev_state = chk_suffix.CheckState == CheckState.Unchecked; - - String path = String.Empty; - if (is_portable == false) - { - path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.ini"; - } - else - { - path = port_path + "ff_batch_portable.ini"; - } - - int linea = 0; - - foreach (string line in File.ReadLines(path)) - { - linea = linea + 1; - - if (linea == 4) - { - if (line != "Vn") - { - if (prev_state == false) - { - btn_save_config.ImageKey = "Save_settings_39.png"; - toolTip_settings.SetToolTip(this.btn_save_config, Strings.params_def); - } - else - { - btn_save_config.ImageKey = "save_pending.png"; - toolTip_settings.SetToolTip(this.btn_save_config, Strings.setting_mod); - } - } - else - { - if (prev_state == true) - { - btn_save_config.ImageKey = "Save_settings_39.png"; - toolTip_settings.SetToolTip(this.btn_save_config, Strings.params_def); - } - else - { - btn_save_config.ImageKey = "save_pending.png"; - toolTip_settings.SetToolTip(this.btn_save_config, Strings.setting_mod); - } - } - break; - } - } - } - - private void txt_suffix_TextChanged(object sender, EventArgs e) - { - if (txt_suffix.Text.Contains("/") || txt_suffix.Text.Contains(":") || txt_suffix.Text.Contains("*") || txt_suffix.Text.Contains("?") || txt_suffix.Text.Contains("¿") || txt_suffix.Text.Contains('\u0022') || txt_suffix.Text.Contains("<") || txt_suffix.Text.Contains(">") || txt_suffix.Text.Contains("|") || txt_suffix.Text.Contains("\\")) - { - MessageBox.Show(Strings.invalid_char + " " + "(\\/:*?'\u0022'<>|", Strings.invalid_ch2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - txt_suffix.Text = txt_suffix.Text.Replace("/", ""); - txt_suffix.Text = txt_suffix.Text.Replace(":", ""); - txt_suffix.Text = txt_suffix.Text.Replace("*", ""); - txt_suffix.Text = txt_suffix.Text.Replace("?", ""); - txt_suffix.Text = txt_suffix.Text.Replace("¿", ""); - txt_suffix.Text = txt_suffix.Text.Replace("@", ""); - txt_suffix.Text = txt_suffix.Text.Replace("\u0022", ""); - txt_suffix.Text = txt_suffix.Text.Replace("<", ""); - txt_suffix.Text = txt_suffix.Text.Replace(">", ""); - txt_suffix.Text = txt_suffix.Text.Replace("|", ""); - txt_suffix.Text = txt_suffix.Text.Replace("\\", ""); - } - } - - private void txt_suffix_Leave(object sender, EventArgs e) - { - if (txt_suffix.Text == String.Empty) - { - txt_suffix.Text = "_FFB"; - } - } - - private void btn_cancel_add_Click(object sender, EventArgs e) - { - canceled_add = true; - canceled_file_adding = true; - btn_cancel_add.Visible = false; - dur_ok = false; - group_prog.Focus(); - - if (working == true) - { - wc.CancelAsync(); - cancel_cache = true; - } - else - { - try - { - wc2.CancelAsync(); - } - catch { } - try - { - wc_dl2.CancelAsync(); - } - catch { } - } - } - - private void BG_Dur_DoWork(object sender, DoWorkEventArgs e) - { - dur_ok = false; - canceled_add = false; - this.Invoke(new MethodInvoker(delegate - { - listView1.BeginUpdate(); - Disable_Controls(); - btn_abort_all.Enabled = false; - btn_cancel_add.Enabled = true; - btn_cancel_add.Visible = true; - btn_cancel_add.Refresh(); - LB_Wait.Visible = true; - LB_Wait.Text = Strings.parsing; - LB_Wait.Refresh(); - pg_adding.Visible = true; - pg_adding.Value = 0; - txt_adding_p.Visible = true; - txt_adding_p.Refresh(); - pg_adding.Maximum = list_pending_dur.Items.Count; - })); - - int invalids = 0; - - procs.Clear(); - - for (int ii = 0; ii < list_pending_dur.Items.Count; ii++) - { - procs.Add("proc_urls_" + ii.ToString(), new Process()); - } - - ParallelOptions par_op = new ParallelOptions(); - CancellationTokenSource cts = new System.Threading.CancellationTokenSource(); - par_op.CancellationToken = cts.Token; - try { par_op.MaxDegreeOfParallelism = Convert.ToInt16(n_threads.Value); } catch { par_op.MaxDegreeOfParallelism = 2; } - fatal_parallel = false; - - int current = 0; - object lockCurrent = new object(); - - IEnumerable items_lv = Enumerable.Range(0, list_pending_dur.Items.Count); - - ParallelLoopResult result = new ParallelLoopResult(); - try - { - result = Parallel.ForEach(Partitioner.Create(items_lv, EnumerablePartitionerOptions.NoBuffering), par_op, (i2) => - { - int i = 0; - lock (lockCurrent) - { - i = current; - current++; - } - this.Invoke(new MethodInvoker(delegate - { - pg_adding.Value = pg_adding.Value + 1; - txt_adding_p.Text = (pg_adding.Value * 100 / list_pending_dur.Items.Count + "%"); - txt_adding_p.Refresh(); - })); - - var tmp = procs["proc_urls_" + i.ToString()]; - - if (canceled_add == false) - { - if (list_pending_dur.Items[i].SubItems[3].Text == Strings.pending) - { - tmp.StartInfo.FileName = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - String ffprobe_frames = " " + '\u0022' + "--Inform=General;%Duration/String3%" + '\u0022'; - tmp.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + list_pending_dur.Items[i].SubItems[1].Text + "\\" + list_pending_dur.Items[i].Text + '\u0022'; - - tmp.StartInfo.RedirectStandardOutput = true; - tmp.StartInfo.UseShellExecute = false; - tmp.StartInfo.CreateNoWindow = true; - tmp.EnableRaisingEvents = true; - tmp.Start(); - - String duracion = tmp.StandardOutput.ReadToEnd(); - tmp.WaitForExit(); - - if (duracion != null) - { - TimeSpan time = new TimeSpan(); - if (TimeSpan.TryParse(duracion, out time)) - { - this.InvokeEx(f => f.listView1.Items[i].SubItems[3].Text = duracion.Substring(0, 12)); - - if (duracion.Length >= 12) - { - if (duracion.Substring(0, 11) == "0:00:00.000" || duracion.Substring(0, 12) == "00:00:00.000") - { - invalids = invalids + 1; - this.InvokeEx(f => f.listView1.Items[i].BackColor = Color.LightGoldenrodYellow); - } - } - } - else - { - this.InvokeEx(f => f.listView1.Items[i].SubItems[3].Text = Strings.n_a); - invalids = invalids + 1; - this.InvokeEx(f => f.listView1.Items[i].BackColor = Color.LightGoldenrodYellow); - } - } - else - { - this.InvokeEx(f => f.listView1.Items[i].SubItems[3].Text = Strings.n_a); - invalids = invalids + 1; - this.InvokeEx(f => f.listView1.Items[i].BackColor = Color.LightGoldenrodYellow); - } - } - } - else { cts.Cancel(); } - }); - } - catch (Exception exc) - { - fatal_parallel_msg = exc.Message; - fatal_parallel = true; - } - - if (result.IsCompleted == true) fatal_parallel = false; - else if (cts.IsCancellationRequested == false) fatal_parallel = true; - else fatal_parallel = false; - //End parallel - if (invalids > 0 && no_warn_0_dur) - { - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - Form7 form_added = new Form7(); - form_added.pic_clean.Image = btn_clean_list.Image; - form_added.label1.Text = listView1.Items.Count + " " + Strings.files; - form_added.label2.Text = invalids + " " + Strings.files; - if (listView1.Items.Count < 10) { } - else if (listView1.Items.Count < 100) - { - form_added.label4.Left = form_added.label4.Left + 8; - } - else if (listView1.Items.Count < 1000) - { - form_added.label4.Left = form_added.label4.Left + 18; - } - - else if (listView1.Items.Count < 10000) - { - form_added.label4.Left = form_added.label4.Left + 27; - } - else - { - form_added.label4.Left = form_added.label4.Left + 36; - } - - if (invalids < 10) { } - else if (invalids < 100) - { - form_added.label5.Left = form_added.label5.Left + 8; - } - else if (invalids < 1000) - { - form_added.label5.Left = form_added.label5.Left + 18; - } - else if (invalids < 10000) - { - form_added.label5.Left = form_added.label5.Left + 27; - } - else - { - form_added.label5.Left = form_added.label5.Left + 36; - } - - form_added.ShowDialog(); - form_added.Refresh(); - } - - dur_ok = !canceled_add; - } - - private void BG_Dur_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) - { - lbl_items.Text = listView1.Items.Count + " " + Strings.files; - LB_Wait.Text = ""; - txt_adding_p.Visible = false; - listView1.EndUpdate(); - Enable_Controls(); - chkshut.Enabled = true; - btn_pause.Enabled = true; - btn_cancel_add.Visible = false; - txt_adding_p.Text = ""; - txt_adding_p.Visible = false; - lbl_items.Visible = true; - lbl_dur_list.Visible = true; - lbl_size.Visible = true; - pg_adding.Visible = false; - LB_Wait.Visible = false; - tabControl1.Enabled = true; - - tried_params.Clear(); - btn_cancel_add.Visible = false; - if (canceled_add == true) - { - MessageBox.Show(Strings.dur_comp, Strings.pars_inc, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - else - { - if (tabControl1.SelectedIndex == 0) - { - if (was_started.Text == btn_seq.Text) - { - btn_seq.PerformClick(); - } - else if (was_started.Text == btn_multiple_presets.Text) - { - start_multiple(); - } - else if (was_started.Text == btn_multi_m.Text) - { - btn_multi_m.PerformClick(); - } - else if (was_started.Text == btn_concat.Text) - { - btn_concat.PerformClick(); - } - else if (was_started.Text == btn_trim.Text) - { - btn_trim.PerformClick(); - } - } - else if (tabControl1.SelectedIndex == 1) - { - btn_mux.PerformClick(); - } - else if (tabControl1.SelectedIndex == 2) - { - btn_sub_mux.PerformClick(); - } - } - } - - private void create_temp() - { - String temp_ = Path.Combine(Path.GetTempPath(), "FFBatch_test"); - if (!Directory.Exists(temp_)) Directory.CreateDirectory(temp_); - } - - private void BG_Files_DoWork(object sender, DoWorkEventArgs e) - { - if (LB_Wait.Text == Strings.add_col1) return; - int has_tbit = 0; - int has_enc_params = 0; - - foreach (ColumnHeader col in listView1.Columns) - { - if (col.Text.Replace("<", "").Replace(">", "").TrimStart() == Properties.Strings.bitrate && !col.Text.ToLower().Contains("video") && !col.Text.ToLower().Contains("audio") && !col.Text.ToLower().Contains("vídeo") && !col.Text.ToLower().Contains("视频") && !col.Text.ToLower().Contains("音")) - { - has_tbit = col.Index; - } - if (col.Text.Replace("<", "").Replace(">", "").TrimStart() == Properties.Strings.Encoding_parameters) - { - has_enc_params = col.Index; - break; - } - } - this.Invoke(new MethodInvoker(delegate - { - foreach (ColumnHeader col in listView1.Columns) - { - listView1.Columns[col.Index].Text = listView1.Columns[col.Index].Text.Replace("<", " ").Replace(">", " "); - } - })); - - if (listView1.Items.Count > 0) - { - List files_already = new List(); - listView1.Invoke(new MethodInvoker(delegate - { - foreach (ListViewItem item in listView1.Items) - { - files_already.Add(item.SubItems[1].Text + "\\" + item.Text); - } - })); - - files_to_add = files_to_add.Except(files_already).ToList(); - } - this.Invoke(new MethodInvoker(delegate - { - listView1.SmallImageList = imageList2; - - //Disable_Controls(); - group_prog.Focus(); - btn_abort_all.Enabled = false; - chkshut.Enabled = false; - btn_pause.Enabled = false; - tabControl1.Enabled = false; - LB_Wait.Visible = true; - btn_cancel_add.Enabled = true; - })); - - create_temp(); - - Type ts = Type.GetTypeFromProgID("Shell.Application"); - dynamic shell = Activator.CreateInstance(ts); - - //Es carpeta - - int i = 0; - invalids = 0; - pending_dur = 0; - - this.Invoke(new MethodInvoker(delegate - { - pg_adding.Value = 0; - pg_adding.Maximum = files_to_add.Count; - txt_adding_p.Visible = true; - txt_adding_p.Refresh(); - lbl_items.Visible = false; - lbl_items.Refresh(); - lbl_dur_list.Visible = false; - lbl_dur_list.Refresh(); - lbl_size.Visible = false; - lbl_size.Refresh(); - pg_adding.Visible = true; - LB_Wait.Refresh(); - txt_adding_p.Text = ""; - listView1.BeginUpdate(); - - })); - - if (files_to_add.Count > 0) this.InvokeEx(f => f.LB_Wait.Text = Properties.Strings.adding + " " + files_to_add.Count + " " + Properties.Strings.files); - else this.InvokeEx(f => f.LB_Wait.Text = Properties.Strings.find_dups); - - procs.Clear(); - media_list.Clear(); - - for (int ii = 0; ii < files_to_add.Count; ii++) - { - procs.Add("proc_urls_" + ii.ToString(), new Process()); - media_list.Add("lines_out_" + ii.ToString(), new List()); - } - - ListViewItem[] itemsToAdd = new ListViewItem[files_to_add.Count]; - String[] ext_nodur = new string[] { ".jpg", ".gif", ".bmp", ".png", ".tif", ".psd", ".txt", ".ini", ".zip", ".htm", ".html", ".css", ".js", ".rar", ".doc", ".docx", ".xls", ".xlsx", ".dll", ".exe", ".ico", ".pdf", ".log", ".cat", "mui", ".xml" }; - - int current = 0; - object lockCurrent = new object(); - - ParallelOptions parop = new ParallelOptions(); - CancellationTokenSource cts = new System.Threading.CancellationTokenSource(); - parop.CancellationToken = cts.Token; - - Parallel.For(0, files_to_add.Count, parop, n => - { - lock (lockCurrent) - { - n = current; - current++; - } - - if (canceled_file_adding == true) return; - - itemsToAdd[n] = new ListViewItem(Path.GetFileName(files_to_add[n])); - - if (canceled_file_adding == false) - { - i = i + 1; - this.Invoke(new MethodInvoker(delegate - { - if (i <= pg_adding.Maximum) - { - - pg_adding.Value = i; - txt_adding_p.Text = (i * 100 / files_to_add.Count).ToString() + "%"; - TaskbarProgress.SetValue(this.Handle, i * 100 / files_to_add.Count, 100); - } - else - { - this.InvokeEx(f => f.pg_adding.Value = pg_adding.Maximum); - this.InvokeEx(f => f.txt_adding_p.Text = "100%"); - } - - })); - - Icon iconForFile = SystemIcons.WinLogo; - - this.Invoke(new MethodInvoker(delegate - { - - if (!files_to_add[n].Contains("\\\\")) - { - if (!imageList2.Images.ContainsKey(System.IO.Path.GetExtension(files_to_add[n]))) - { - iconForFile = System.Drawing.Icon.ExtractAssociatedIcon(files_to_add[n]); - imageList2.Images.Add(System.IO.Path.GetExtension(files_to_add[n]), iconForFile); - itemsToAdd[n].ImageKey = System.IO.Path.GetExtension(files_to_add[n]); - } - } - - if (!files_to_add[n].Contains("\\\\")) - { - itemsToAdd[n].ImageKey = System.IO.Path.GetExtension(files_to_add[n]); - } - else - { - itemsToAdd[n].ImageIndex = 0; - } - - })); - - itemsToAdd[n].SubItems.Add(Path.GetDirectoryName(files_to_add[n])); - - String file = Path.GetDirectoryName(files_to_add[n]) + "\\" + Path.GetFileName(files_to_add[n]); - String dur_file = Properties.Strings.pending; - - if (Properties.Settings.Default.quick_queue == false) - { - Boolean no_av = false; - String videosLength = String.Empty; - - Folder rFolder = shell.NameSpace(Path.GetDirectoryName(files_to_add[n])); - FolderItem rFiles = rFolder.ParseName(System.IO.Path.GetFileName(files_to_add[n])); - String videostype = rFolder.GetDetailsOf(rFiles, 2).Trim(); - String videoSize = rFolder.GetDetailsOf(rFiles, 1).Trim(); - itemsToAdd[n].SubItems.Add(videostype); - String f_ext = Path.GetExtension(files_to_add[n]).ToLower(); - foreach (String no_ext in ext_nodur) - { - if (f_ext == no_ext) - { - itemsToAdd[n].SubItems.Add("00:00:00"); - if (Properties.Settings.Default.dark_mode == true) - { - itemsToAdd[n].BackColor = Color.FromArgb(255, 128, 128, 128); - } - else itemsToAdd[n].BackColor = Color.LightGoldenrodYellow; - - no_av = true; - invalids = invalids + 1; - break; - } - } - - if (no_av == false) - { - DateTime time; - videosLength = rFolder.GetDetailsOf(rFiles, 27).Trim(); - dur_file = videosLength; - - if ((!DateTime.TryParse(videosLength, out time))) - { - itemsToAdd[n].SubItems.Add(Properties.Strings.pending); - pending_dur = pending_dur + 1; - } - else - { - itemsToAdd[n].SubItems.Add(videosLength); - } - } - - //End testing - - itemsToAdd[n].SubItems.Add(videoSize); - itemsToAdd[n].SubItems.Add(Properties.Strings.queued); - } - else - { - itemsToAdd[n].SubItems.Add("-"); - itemsToAdd[n].SubItems.Add("-"); - itemsToAdd[n].SubItems.Add("-"); - itemsToAdd[n].SubItems.Add(Properties.Strings.queued); - } - - if (listView1.Columns.Count > 6) - { - if (listView1.Columns.Count == 7 && has_tbit == 6) itemsToAdd[n].SubItems.Add(Properties.Strings.pending); - else if (listView1.Columns.Count == 7 && has_enc_params == 6) itemsToAdd[n].SubItems.Add("-"); - else if (listView1.Columns.Count == 8 && has_tbit == 6 && has_enc_params == 7) - { - itemsToAdd[n].SubItems.Add("-"); - itemsToAdd[n].SubItems.Add("-"); - } - else if (listView1.Columns.Count == 8 && has_tbit == 7 && has_enc_params == 6) - { - itemsToAdd[n].SubItems.Add("-"); - itemsToAdd[n].SubItems.Add("-"); - } - - else - { - foreach (ColumnHeader col in listView1.Columns) - { - if (col.Text.Replace("<", "").Replace(">", "").TrimStart() == Properties.Strings.width) - { - i--; - itemsToAdd[n].SubItems.Add("-"); - i++; - } - - if (col.Text.Replace("<", "").Replace(">", "").TrimStart() == Properties.Strings.height) - { - i--; - itemsToAdd[n].SubItems.Add("-"); - i++; - } - - if (col.Text.Replace("<", "").Replace(">", "").TrimStart() == Properties.Strings.Video_codec) - { - i--; - itemsToAdd[n].SubItems.Add("-"); - i++; - } - - if (col.Text.Replace("<", "").Replace(">", "").TrimStart() == Properties.Strings.Audio_codec) - { - i--; - itemsToAdd[n].SubItems.Add("-"); - i++; - } - - if (col.Text.Replace("<", "").Replace(">", "").TrimStart() == Properties.Strings.v_bitr) - { - i--; - itemsToAdd[n].SubItems.Add("-"); - i++; - } - - if (col.Text.Replace("<", "").Replace(">", "").TrimStart() == Properties.Strings.a_bitr) - { - i--; - itemsToAdd[n].SubItems.Add("-"); - i++; - } - - ////Custom parameters - - if (col.Text.Replace("<", "").Replace(">", "").TrimStart() == Properties.Settings.Default.cust_med_col) - { - i--; - itemsToAdd[n].SubItems.Add("-"); - i++; - } - - //End custom parameters - - if (col.Text.Replace("<", "").Replace(">", "").TrimStart() == Properties.Strings.Encoding_parameters) - { - i--; - itemsToAdd[n].SubItems.Add("-"); - i++; - } - - if (col.Text.Replace("<", "").Replace(">", "").TrimStart() == Properties.Strings.bitrate && !col.Text.ToLower().Contains("video") && !col.Text.ToLower().Contains("audio") && !col.Text.ToLower().Contains("vídeo") && !col.Text.ToLower().Contains("视频") && !col.Text.ToLower().Contains("音")) - { - i--; - itemsToAdd[n].SubItems.Add(Properties.Strings.pending); - i++; - } - } - } - } - } - }); - - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - - if (canceled_file_adding == true) - { - this.Invoke(new MethodInvoker(delegate - { - pg_adding.Value = 0; - pg_adding.Maximum = i; - LB_Wait.Text = Properties.Strings.cancelling; - })); - - i = i - Environment.ProcessorCount; - ListViewItem[] itemsToAdd2 = new ListViewItem[i]; - for (int n2 = 0; n2 < i; n2++) - { - this.InvokeEx(f => f.pg_adding.Value = n2); - itemsToAdd2[n2] = itemsToAdd[n2]; - } - this.InvokeEx(f => f.listView1.Items.AddRange(itemsToAdd2)); - } - else - { - this.InvokeEx(f => f.listView1.Items.AddRange(itemsToAdd.ToArray())); - } - } - - private void BG_Files_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) - { - if (LB_Wait.Text == Strings.add_col1) return; - total_multi_duration = 0; - if (Settings.Default.quick_queue == false) - { - calc_list_size(); - calc_total_dur(); - } - - String other_file = Path.Combine(Path.GetTempPath(), "FFBatch_test") + "\\" + "Other_instance.fftmp"; - if (File.Exists(other_file)) - { - try - { - File.Delete(other_file); - } - catch { } - } - - group_prog.Focus(); - btn_cancel_add.Enabled = true; - btn_cancel_add.Visible = true; - btn_cancel_add.Refresh(); - - if (canceled_file_adding == false) - { - canceled_add = false; - if (change_tab_1 == true) - { - change_tab_1 = false; - tabControl1.SelectedIndex = 0; - tabControl1.SelectedIndex = 1; - } - } - else - { - canceled_add = true; - - if (change_tab_1 == true) - { - change_tab_1 = false; - tabControl1.SelectedIndex = 0; - } - } - - BG_P_Dur.RunWorkerAsync(); - listView1.EndUpdate(); - - btn_undo_filter.Enabled = false; - Boolean has_vcodec = false; - if (from_wizard == true) - { - btn_wizard.Enabled = true; - btn_wizard.PerformClick(); - from_wizard = false; - } - } - - private void calc_total_dur() - { - Double Total_dur = 0; - foreach (ListViewItem item in listView1.Items) - { - if (Settings.Default.quick_queue == true) continue; - if (item.SubItems[3].Text != "0:00:00" && item.SubItems[3].Text != Strings.n_a && item.SubItems[3].Text != "00:00:00" && item.SubItems[3].Text != Strings.pending) - { - try - { - Total_dur = Total_dur + TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds; - } - catch (System.Exception) - { - item.SubItems[3].Text = Strings.n_a; - if (Settings.Default.dark_mode == true) - { - item.BackColor = Color.FromArgb(255, 128, 128, 128); - } - else item.BackColor = Color.LightGoldenrodYellow; - } - } - } - - TimeSpan t = TimeSpan.FromSeconds(Total_dur); - String dur = string.Format("{0:D2}h:{1:D2}m:{2:D2}s.{3:D3}ms", - (int)t.TotalHours, - t.Minutes, - t.Seconds, - t.Milliseconds); - lbl_dur_list.Text = dur.Substring(0, 11); - } - - public Double get_bitrate(String file, String dur_file) - { - Double bytes = 0; - try - { - FileInfo fi = new FileInfo(file); - Double size = fi.Length; - Double dur = 0; - - TimeSpan time; - if (TimeSpan.TryParse(dur_file, out time)) - { - dur = TimeSpan.Parse(dur_file).TotalSeconds; - if (dur > 0) bytes = Math.Round((size / dur * 8 / 1000), 0); - else bytes = 0; - } - return bytes; - } - catch { return 0; } - } - - private void BG_P_Dur_DoWork(object sender, DoWorkEventArgs e) - { - //PAUSE while parsing - - if (working == true) - { - paused = true; - int tab = 0; - tabControl1.Invoke(new MethodInvoker(delegate - { - tab = tabControl1.SelectedIndex; - })); - - if (tab == 0) - { - //listView1.Invoke(new MethodInvoker(delegate - //{ - // foreach (ListViewItem item in listView1.Items) - // { - // if (working == true && multi_running == false) - // { - // process_glob.Suspend(); - // } - // } - //})); - - if (working == true && multi_running == true) - if (working == true) - { - foreach (Process proc in procs.Values) - { - try - { - proc.Suspend(); - } - catch { } - } - } - } - - if (tab == 1) - { - if (working == true && multi_running == false) - { - foreach (Process proc in procs.Values) - { - try - { - proc.Suspend(); - } - catch { } - } - } - } - else if (tab == 2) - { - foreach (Process proc in procs.Values) - { - try - { - proc.Suspend(); - } - catch { } - } - } - else if (tab == 3) - { - foreach (DataGridViewRow row in dg1.Rows) - { - if (m3u_running == true && m3u_single_running == true) - { - foreach (Process proc in procs.Values) - { - try - { - proc.Suspend(); - } - catch { } - } - } - } - - if (m3u_running == true && m3u_single_running == false) - { - foreach (Process proc in procs.Values) - { - try - { - proc.Suspend(); - } - catch - { - } - } - } - } - - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.Paused)); - } - - //END PAUSE ENCODING, PENDING RESUME - tried_params.Clear(); - list_not_empty = listView1.Items.Count > 0; - - if (list_not_empty == true) - { - pending_dur = 0; - listView1.Invoke(new MethodInvoker(delegate - { - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[3].Text == Strings.pending) - { - pending_dur = pending_dur + 1; - } - } - })); - } - - this.Invoke(new MethodInvoker(delegate - { - pg_adding.Value = 0; - if (pending_dur > 0) LB_Wait.Text = Strings.parsing2 + " " + pending_dur + " " + Strings.files; - else LB_Wait.Text = Strings.parsing2; - LB_Wait.Refresh(); - pg_adding.Maximum = pending_dur; - })); - - Boolean warn_avs = false; - - ListView lstv2 = new ListView(); - if (pending_dur > 0) - { - listView1.Invoke(new MethodInvoker(delegate - { - lstv2.Columns.AddRange((from ColumnHeader Col in listView1.Columns - select (ColumnHeader)Col.Clone()).ToArray()); - lstv2.Items.AddRange((from ListViewItem item in listView1.Items select (ListViewItem)item.Clone()).ToArray()); - })); - } - - this.InvokeEx(f => f.listView1.BeginUpdate()); - - int current = 0; - object lockCurrent = new object(); - - procs.Clear(); - for (int ii = 0; ii < lstv2.Items.Count; ii++) - { - procs.Add("proc_urls_" + ii.ToString(), new Process()); - } - - ParallelOptions par_op = new ParallelOptions(); - CancellationTokenSource cts = new CancellationTokenSource(); - par_op.CancellationToken = cts.Token; - if (Environment.ProcessorCount > 1) par_op.MaxDegreeOfParallelism = Environment.ProcessorCount / 2; - else par_op.MaxDegreeOfParallelism = 1; - ParallelLoopResult res = new ParallelLoopResult(); - - try - { - res = Parallel.For(0, lstv2.Items.Count, par_op, (i2) => - { - int i = 0; - lock (lockCurrent) - { - i = current; - current++; - } - - if (canceled_file_adding == true) cts.Cancel(); - - if (canceled_add == false) - { - - if (lstv2.Items[i].SubItems[3].Text == Strings.pending) - { - var probe = procs["proc_urls_" + i.ToString()]; - String file = lstv2.Items[i].SubItems[1].Text + "\\" + lstv2.Items[i].Text; - probe.StartInfo.RedirectStandardOutput = true; - probe.StartInfo.FileName = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - String ffprobe_frames = " " + '\u0022' + "--Inform=General;%Duration/String3%" + '\u0022'; - probe.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + file + '\u0022'; - probe.StartInfo.UseShellExecute = false; - probe.StartInfo.CreateNoWindow = true; - probe.EnableRaisingEvents = true; - - List files_in = new List(); - if (Path.GetExtension(lstv2.Items[i].Text).ToLower() == ".avs") - { - if (warn_avs == false) - { - var a = TextFileEncodingDetector.DetectTextFileEncoding(file); - if (a != null) - { - if (a.ToString().ToLower().Contains("utf") || a.ToString().ToLower().Contains("unicode")) - { - MessageBox.Show(Strings.in_avis + " " + a.ToString().Replace("System.Text.", "").Replace("Encoding", "") + " " + Strings.not_sup_bom + Environment.NewLine + Environment.NewLine + Strings.ansi_rec + Environment.NewLine + Environment.NewLine + Strings.non_eng_rec, Strings.warning, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - warn_avs = true; - } - } - else - { - if (warn_avs == false) - { - if (Settings.Default.app_lang != "en") MessageBox.Show(Strings.vs_files_warn, Strings.warning, MessageBoxButtons.OK, MessageBoxIcon.Information); - warn_avs = true; - } - } - } - - List lines_ouput = new List(); - String[] txt = File.ReadAllLines(file); - foreach (String str in txt) - { - if (str.ToLower().Contains("source(") || str.ToLower().Contains("source2(")) - { - int start = str.IndexOf("(") + 1; - int end = str.IndexOf(","); - if (end > 0) - { - file = str.Substring(start, end - start); - if (file.Contains('\u0022')) file = file.Substring(1, file.Length - 2); - files_in.Add(file.Replace("/", "\\")); - } - else - { - file = str.Substring(start + 1, str.Length - start - 3); - if (file.Contains('\u0022')) file = file.Substring(1, file.Length - 2); - files_in.Add(file.Replace("/", "\\")); - } - } - } - } - - if (files_in.Count > 1) - { - lstv2.Items[i].SubItems[3].Text = get_avs_time(files_in.Distinct().ToList()); - } - else - { - this.Invoke(new MethodInvoker(delegate - { - if (pg_adding.Value < pg_adding.Maximum) - { - pg_adding.Value = pg_adding.Value + 1; - txt_adding_p.Text = (pg_adding.Value * 100 / pending_dur + "%"); - txt_adding_p.Refresh(); - TaskbarProgress.SetValue(this.Handle, pg_adding.Value * 100 / pending_dur, 100); - } - })); - - String duracion = String.Empty; - - probe.Start(); - - while (!probe.StandardOutput.EndOfStream) - { - duracion = probe.StandardOutput.ReadLine(); - - if (duracion != null) - { - TimeSpan time = new TimeSpan(); - if (TimeSpan.TryParse(duracion, out time)) - { - lstv2.Items[i].SubItems[3].Text = duracion.Substring(0, 12); - - if (duracion.Length >= 12) - { - if (duracion.Substring(0, 11) == "0:00:00.000" || duracion.Substring(0, 12) == "00:00:00.000") - { - invalids = invalids + 1; - lstv2.Items[i].BackColor = Color.LightGoldenrodYellow; - } - } - } - else - { - invalids = invalids + 1; - lstv2.Items[i].SubItems[3].Text = Strings.n_a; - lstv2.Items[i].BackColor = Color.LightGoldenrodYellow; - } - } - else - { - invalids = invalids + 1; - lstv2.Items[i].SubItems[3].Text = Strings.n_a; - lstv2.Items[i].BackColor = Color.LightGoldenrodYellow; - } - } - } - } - } - }); - - } catch { } - - listView1.Invoke(new MethodInvoker(delegate - { - if (pending_dur > 0) - { - listView1.Items.Clear(); - listView1.Items.AddRange((from ListViewItem item in lstv2.Items select (ListViewItem)item.Clone()).ToArray()); - } - })); - - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - Boolean is_LV1 = false; - tabControl1.Invoke(new MethodInvoker(delegate - { - if (tabControl1.SelectedIndex == 0) is_LV1 = true; - })); - - dur_ok = !canceled_add; - - Enable_Controls(); - - this.Invoke(new MethodInvoker(delegate - { - listView1.EndUpdate(); - lbl_items.Text = listView1.Items.Count + " " + Strings.files; - LB_Wait.Text = ""; - btn_cancel_add.Visible = false; - pg_adding.Visible = false; - txt_adding_p.Visible = false; - lbl_dur_list.Refresh(); - txt_remain.Text = Strings.remain_time + " " + "00h:00m:00s"; - chkshut.Enabled = true; - btn_pause.Enabled = true; - btn_pause.Enabled = true; - btn_abort_all.Enabled = true; - txt_adding_p.Text = ""; - txt_adding_p.Visible = false; - lbl_items.Visible = true; - lbl_dur_list.Visible = true; - lbl_size.Visible = true; - LB_Wait.Visible = false; - tabControl1.Enabled = true; - listView1.EndUpdate(); - })); - - pop_invalids = false; - if (invalids > 0 && is_LV1 == true && initial_tab != 2) - { - pop_invalids = true; - } - } - - private String get_avs_time(List lista) - { - TimeSpan total_time = new TimeSpan(); - foreach (String file in lista) - { - Process probe = new Process(); - probe.StartInfo.RedirectStandardOutput = true; - probe.StartInfo.FileName = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - String ffprobe_frames = " " + '\u0022' + "--Inform=General;%Duration/String3%" + '\u0022'; - probe.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + file + '\u0022'; - probe.StartInfo.UseShellExecute = false; - probe.StartInfo.CreateNoWindow = true; - probe.EnableRaisingEvents = true; - probe.Start(); - - String duracion = probe.StandardOutput.ReadLine(); - probe.WaitForExit(); - - if (duracion != null) - { - TimeSpan time = new TimeSpan(); - if (TimeSpan.TryParse(duracion, out time)) - { - total_time = total_time + time; - } - } - } - TimeSpan time2 = new TimeSpan(); - if (total_time.TotalSeconds == 0) return Strings.n_a; - else return total_time.ToString().Substring(0, 12); - - } - - private void BG_P_Dur_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) - { - int tbit_col = 0; - - foreach (ColumnHeader col in listView1.Columns) - { - if (col.Text.Replace("<", "").Replace(">", "").TrimStart() == Strings.bitrate) - { - listView1.Invoke(new MethodInvoker(delegate - { - tbit_col = col.Index; - })); - } - } - - if (tbit_col != 0) - { - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[tbit_col].Text != Strings.pending) continue; - Double bytes = 0; - try - { - FileInfo fi = new FileInfo(item.SubItems[1].Text + "\\" + item.Text); - Double size = fi.Length; - Double dur = 0; - - TimeSpan time; - if (TimeSpan.TryParse(item.SubItems[3].Text, out time)) - { - dur = TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds; - if (dur > 0) bytes = Math.Round((size / dur * 8 / 1000), 0); - else bytes = 0; - } - - String subit = ""; - if (bytes >= 1000000) subit = (bytes / 1000000).ToString("#,##0.0") + " " + "Gb/s"; - else if (bytes >= 10000 && bytes < 1000000) - subit = (bytes / 1000).ToString("#,##0.0") + " " + "Mb/s"; - else if (bytes < 10000) subit = bytes.ToString("#,##0") + " " + "Kb/s"; - else if (bytes == 0 || bytes > 100000000000000) subit = "0 Kb/s"; - item.SubItems[tbit_col].Text = subit; - } - catch { try { item.SubItems[tbit_col].Text = "0 Kb/s"; } catch { } } - } - } - - if (listView1.Columns.Count > 6 && tbit_col != 6) BG_R_Cols.RunWorkerAsync(); - else if (listView1.Columns.Count > 7 && tbit_col == 6) BG_R_Cols.RunWorkerAsync(); - - int tab = 0; - - tabControl1.Invoke(new MethodInvoker(delegate - { - tab = tabControl1.SelectedIndex; - })); - - paused = false; - if (tab == 0) - { - foreach (ListViewItem item in listView1.Items) - { - if (working == true && multi_running == false) - { - resume_glob(); - } - } - if (working == true && multi_running == true) - { - foreach (Process proc in procs.Values) - { - try - { - proc.Resume(); - } - catch { } - } - } - - } - Boolean cleaned = false; - if (Settings.Default.filter_zero == true) - { - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[3].Text == "0:00:00" || item.SubItems[3].Text == "00:00:00" || item.SubItems[3].Text == Strings.n_a) - { - item.Remove(); - cleaned = true; - } - } - } - - if (tabControl1.SelectedIndex == 1) - { - if (working == true) resume_glob(); - } - else if (tabControl1.SelectedIndex == 2) - { - foreach (ListViewItem item in listView3.Items) - { - if (working == true) resume_glob(); - } - } - else if (tabControl1.SelectedIndex == 3) - { - foreach (DataGridViewRow row in dg1.Rows) - { - if (m3u_single_running == true && m3u_running == true) - { - resume_glob(); - } - } - - if (m3u_single_running == false && m3u_running == true) - { - foreach (Process proc in procs.Values) - { - try - { - proc.Resume(); - } - catch { } - } - } - } - - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.Normal)); - - //END RESUME - - if (cleaned == true) - { - calc_list_size(); - calc_total_dur(); - lbl_items.Text = listView1.Items.Count.ToString() + " " + Strings.files; - } - - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - - if (pop_invalids == true && no_warn_0_dur == false) - { - Form7 form_added = new Form7(); - form_added.pic_clean.Image = btn_clean_list.Image; - form_added.label1.Text = listView1.Items.Count + " " + Strings.files; - form_added.label2.Text = invalids + " " + Strings.files; - - if (listView1.Items.Count > 10 && listView1.Items.Count < 100) - { - form_added.label4.Left = form_added.label4.Left + 8; - } - - if (listView1.Items.Count >= 100 && listView1.Items.Count < 1000) - { - form_added.label4.Left = form_added.label4.Left + 18; - } - - if (listView1.Items.Count >= 1000 && listView1.Items.Count < 10000) - { - form_added.label4.Left = form_added.label4.Left + 27; - } - if (listView1.Items.Count > 10000) - { - form_added.label4.Left = form_added.label4.Left + 36; - } - - if (invalids > 10 && invalids < 100) - { - form_added.label5.Left = form_added.label5.Left + 8; - } - - if (invalids >= 100 && invalids < 1000) - { - form_added.label5.Left = form_added.label5.Left + 18; - } - - if (invalids >= 1000 && invalids < 10000) - { - form_added.label5.Left = form_added.label5.Left + 27; - } - if (invalids > 10000) - { - form_added.label5.Left = form_added.label5.Left + 36; - } - - form_added.ShowDialog(); - form_added.Refresh(); - } - - - if (change_tab_1 == true) - { - if (listView1.Items.Count > 200) - { - DialogResult a = MessageBox.Show(Strings.streams_f + " " + listView1.Items.Count + " " + Strings.some_time, Strings.many_parsed, MessageBoxButtons.OKCancel, MessageBoxIcon.Question); - if (a == DialogResult.Cancel) - { - tabControl1.SelectedIndex = 0; - return; - } - } - bg_add_tab2.RunWorkerAsync(); - } - - if (change_tab_2 == true) - { - tabControl1.SelectedIndex = 0; - tabControl1.SelectedIndex = 2; - } - - if (working == true) - { - Disable_Controls(); - timer_tasks.Start(); - btn_add_files.Enabled = true; - btn_add_folders.Enabled = true; - btn_skip_main.Enabled = true; - chk_subfolders.Enabled = true; - - if (runnin_n_presets == true) - { - btn_add_files.Enabled = true; - btn_add_folders.Enabled = true; - btn_skip_main.Enabled = true; - } - - panel2.Enabled = true; - chk_delete_source.Enabled = true; - foreach (Control ct in panel2.Controls) - { - if (ct.Name != chk_delete_source.Name) - { - this.InvokeEx(f => ct.Enabled = false); - } - } - total_duration = 0; - - foreach (ListViewItem item in listView1.Items) - { - if (Settings.Default.quick_queue == true) continue; - - if (item.SubItems[3].Text != Strings.n_a && item.SubItems[3].Text != "0:00:00" && item.SubItems[3].Text != "00:00:00" && item.SubItems[3].Text != Strings.pending) - { - total_duration = total_duration + TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds - TimeSpan.Parse(ss_time_input.Text).TotalSeconds; - } - else - { - total_duration = total_duration + 0; - } - } - } - btn_undo_filter.Enabled = false; - if (tab == 0 && listView1.Items.Count == 1) - { - listView1.Items[0].Selected = true; - } - - if (start_seq == true) - { - Thread.Sleep(500); - if (start_multi == false) btn_seq.PerformClick(); - else btn_multi_m.PerformClick(); - } - if (tab == 0) - { - if (Settings.Default.monitor_fd == true && watched_tick == true) - { - if (ignore_encoded == true) - { - if (all_enc_watch() == true) return; - } - if (working == false) - { - Thread.Sleep(200); - BG_Seq.RunWorkerAsync(); - watched_tick = false; - } - } - } - } - - private void avoid_overw() - { - avoid_overwriting = false; - if (listView1.Items.Count < 2) return; - - int i = 0; - foreach (ListViewItem item in listView1.Items) - { - if (Path.GetDirectoryName(item.Text) != Path.GetDirectoryName(listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text)) - { - avoid_overwriting = true; - return; - } - i++; - } - pg_adding.Visible = false; - } - - private void button19_Click_1(object sender, EventArgs e) - { - Pg1.Focus(); - dg1.Rows.Clear(); - if (Settings.Default.dark_mode == false) pic_frame.Image = pic_reading.ErrorImage; - else pic_frame.Image = pic_dark.Image; - lbl_urls_time.Text = ""; - } - - private void open_file_m3u_FileOk(object sender, CancelEventArgs e) - { - FileInfo fl = new FileInfo(open_file_m3u.FileName); - if (fl.Length > 10485760) - { - MessageBox.Show(Strings.file_big, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - dg1.Rows.Clear(); - Array.Clear(lines_txt_m3u, 0, lines_txt_m3u.Length); - stop_validating_url = false; - opening_youtubes = false; - String[] lines = File.ReadAllLines(open_file_m3u.FileName); - lines_txt_m3u = lines; - dg1.SuspendLayout(); - BG_pre_validate_url_txt.RunWorkerAsync(); - } - - private void post_file_url() - { - if (adding_youtube == false) - { - //String[] lines = File.ReadAllLines(open_file_m3u.FileName); - - if (lines_txt_m3u.Length > 4000) - { - MessageBox.Show(Strings.max_links, Strings.max_list, MessageBoxButtons.OK, MessageBoxIcon.Warning); - return; - } - - List images = new List(); - Boolean has_img = false; - Boolean has_m3u = false; - - for (int i = 0; i <= lines_txt_m3u.Count() - 1; i++) - { - if (lines_txt_m3u[i].ToLower().Contains("youtu.be") || lines_txt_m3u[i].ToLower().Contains("youtube.com")) - { - adding_youtube = true; - } - else - { - has_m3u = true; - } - if (adding_youtube == true && has_m3u == true) - { - MessageBox.Show(Strings.mix_urls2, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Warning); - return; - } - } - - for (int i = 0; i <= lines_txt_m3u.Count() - 1; i++) - { - String out_file = String.Empty; - lines_txt_m3u[i] = lines_txt_m3u[i].Trim(); - if (lines_txt_m3u[i] == String.Empty) continue; - - if (lines_txt_m3u[i].ToLower().Contains("youtu.be") || lines_txt_m3u[i].ToLower().Contains("youtube.com")) - { - adding_youtube = true; - break; - } - - PictureBox pic = new PictureBox(); - int l = 0; - String img_m3u = String.Empty; - - if (lines_txt_m3u[i].Contains("tvg-logo=") && has_img == false) - { - l = lines_txt_m3u[i].Substring(0, lines_txt_m3u[i].IndexOf("tvg-logo=")).Length; - img_m3u = lines_txt_m3u[i].Substring(l + 10, lines_txt_m3u[i].Length - l - 10); - img_m3u = img_m3u.Substring(0, img_m3u.IndexOf('\u0022')); - - try - { - pic.Load(img_m3u); - images.Add(pic.Image); - has_img = true; - continue; - } - catch - { - images.Clear(); - has_img = false; - continue; - } - } - else - { - } - - if (!lines_txt_m3u[i].ToString().Contains("#EXTM3U") && !lines_txt_m3u[i].ToString().Contains("#EXTINF") && (lines_txt_m3u[i].Substring(0, 4).ToLower() == "http" || lines_txt_m3u[i].Substring(0, 5).ToLower() == "https")) - { - if (i >= 0) - { - out_file = Path.GetFileNameWithoutExtension(lines_txt_m3u[i]); - if (has_img == true) - { - dg1.Rows.Add(images[0], lines_txt_m3u[i], "", "", out_file, ""); - dg_thumbs[dg1.RowCount - 1] = images[0]; - has_img = false; - images.Clear(); - } - else - { - dg1.Rows.Add(pic_noimg.Image, lines_txt_m3u[i], "", "", out_file, ""); - dg_thumbs[dg1.RowCount - 1] = pic_noimg.Image; - } - } - } - } - } - - if (adding_youtube == true) - { - //String[] lines_txt_m3u = File.ReadAlllines_txt_m3u(open_file_m3u.FileName); - if (lines_txt_m3u.Length > 2000) - { - MessageBox.Show(Strings.max_links, Strings.max_list, MessageBoxButtons.OK, MessageBoxIcon.Warning); - return; - } - - for (int i = 0; i <= lines_txt_m3u.Count() - 1; i++) - { - String out_file = String.Empty; - - lines_txt_m3u[i] = lines_txt_m3u[i].Trim(); - if (lines_txt_m3u[i] == "") continue; - - if (lines_txt_m3u[i].ToLower().Contains("youtu.be") || lines_txt_m3u[i].ToLower().Contains("youtube.com")) - { - if (i >= 0) - { - out_file = Path.GetFileNameWithoutExtension(lines_txt_m3u[i]); - dg1.Rows.Add(pic_noimg.Image, lines_txt_m3u[i], "", "", out_file, ""); - } - } - } - } - - foreach (DataGridViewRow row in dg1.Rows) - { - row.ReadOnly = true; - } - foreach (Control ct in groupBox_m3u.Controls) - { - ct.Enabled = false; - } - btn_cancel_validate.Enabled = true; - Boolean has_playlist = false; - foreach (DataGridViewRow row in dg1.Rows) - { - if (row.Cells[1].Value.ToString().ToLower().Contains("playlist")) - { - has_playlist = true; - break; - } - } - - clean_imgs(); - - if (adding_youtube == false) - { - BG_Validate_URLs.RunWorkerAsync(); - } - else - { - if (has_playlist == true) - { - foreach (DataGridViewRow row in dg1.Rows) - { - row.ReadOnly = false; - } - foreach (Control ct in groupBox_m3u.Controls) - { - ct.Enabled = true; - } - - BG_Validate_PLSS.RunWorkerAsync(); - } - else - { - BG_Validate_URLs_YT.RunWorkerAsync(); - } - } - } - - private void clean_imgs() - { - for (int i = 0; i == 1000; i++) dg_thumbs[i] = null; - } - - private void button31_Click(object sender, EventArgs e) - { - Pg1.Focus(); - adding_youtube = false; - open_file_m3u.Filter = Strings.links + " " + " | *.m3u; *.m3u8; *.txt| " + Strings.all_files + " (*.*) | *.*"; - open_file_m3u.ShowDialog(); - } - - private void validate_gen_link() - { - Boolean one_ok = false; - - dg1.Rows[dg1.RowCount - 1].Cells[5].Value = Strings.var_url; - - if (dg1.Rows[dg1.RowCount - 1].Cells[1].Value == null) - { - dg1.Rows[dg1.RowCount - 1].Cells[5].Value = String.Empty; - dg1.Rows[dg1.RowCount - 1].Cells[4].Value = String.Empty; - dg1.Rows[dg1.RowCount - 1].Cells[3].Value = String.Empty; - dg1.Rows[dg1.RowCount - 1].Cells[2].Value = String.Empty; - //dg1.Rows[dg1.RowCount - 1].DefaultCellStyle.BackColor = dg1.DefaultCellStyle.BackColor; - return; - } - - if (dg1.Rows[dg1.RowCount - 1].Cells[1].Value.ToString().Contains("http") == false) - { - dg1.Rows[dg1.RowCount - 1].Cells[5].Value = Strings.error; - dg1.Rows[dg1.RowCount - 1].DefaultCellStyle.BackColor = Color.LightGoldenrodYellow; - return; - } - - dg1.Refresh(); - cell_zoom(); - - Process probe = new Process(); - probe.StartInfo.FileName = Path.Combine(Application.StartupPath, "yt-dlp.exe"); - if (!File.Exists(Path.Combine(Application.StartupPath, "yt-dlp.exe"))) - { - MessageBox.Show(Strings.yt_not, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - release_datagrid(); - return; - } - probe.StartInfo.WorkingDirectory = Application.StartupPath; - probe.StartInfo.Arguments = "--get-duration --get-title --get-thumbnail " + dg1.Rows[dg1.RowCount - 1].Cells[1].Value.ToString(); - probe.StartInfo.RedirectStandardOutput = true; - probe.StartInfo.UseShellExecute = false; - probe.StartInfo.CreateNoWindow = true; - probe.EnableRaisingEvents = true; - probe.Start(); - - String filename = ""; - String out_thumb = ""; - String duracion = ""; - - while (!probe.StandardOutput.EndOfStream) - { - filename = probe.StandardOutput.ReadLine(); - out_thumb = probe.StandardOutput.ReadLine(); - duracion = probe.StandardOutput.ReadLine(); - } - - PictureBox pic = new PictureBox(); - if (out_thumb != null) - { - if (out_thumb.Contains("http")) - { - try - { - if (out_thumb.Contains("?")) out_thumb = out_thumb.Substring(0, out_thumb.IndexOf("?")); - new System.Threading.Thread(() => - { - System.Threading.Thread.CurrentThread.IsBackground = true; - try { pic.Load(out_thumb); } catch { } - dg_thumbs[dg1.RowCount - 1] = pic.Image; - dg1.Invoke(new MethodInvoker(delegate - { - dg1.Rows[dg1.RowCount - 1].Cells[0].Value = pic.Image; - pic_frame.Image = dg_thumbs[dg1.RowCount - 1]; - if (pic_frame.Image == null) pic_frame.Image = pic_frame.InitialImage; - lbl_a_th.Text = "-"; - lbl_s_th.Text = "-"; - lbl_v_th.Text = "-"; - lbl_gb_th.Text = "-"; - })); - }).Start(); - } - catch - { - dg_thumbs[dg1.RowCount - 1] = pic_noimg.Image; - } - } - } - else - { - dg_thumbs[dg1.RowCount - 1] = pic_noimg.Image; - } - //cell_stretch(); - - probe.WaitForExit(10000); - probe.StartInfo.Arguments = ""; - - if (duracion == null || duracion == string.Empty) - { - dg1.Invoke(new MethodInvoker(delegate - { - dg1.Rows[dg1.RowCount - 1].DefaultCellStyle.BackColor = Color.LightGoldenrodYellow; - dg1.Rows[dg1.RowCount - 1].Cells[2].Value = Strings.n_a; - dg1.Rows[dg1.RowCount - 1].Cells[3].Value = "\u221E"; - int index_length = dg1.Rows[dg1.RowCount - 1].Cells[1].Value.ToString().Length; - - if (dg1.Rows[dg1.RowCount - 1].Cells[1].Value.ToString().Substring(index_length - 1, 1) == "/") - { - dg1.Rows[dg1.RowCount - 1].Cells[1].Value = dg1.Rows[dg1.RowCount - 1].Cells[1].Value.ToString().Substring(0, index_length - 1); - index_length = index_length - 1; - } - - int index_fn = dg1.Rows[dg1.RowCount - 1].Cells[1].Value.ToString().LastIndexOf("/"); - int ind_final = index_length - index_fn; - String dest = dg1.Rows[dg1.RowCount - 1].Cells[1].Value.ToString().Substring(index_fn + 1, ind_final - 1); - dg1.Rows[dg1.RowCount - 1].Cells[4].Value = dest; - if (Settings.Default.dark_mode == false) - { - dg1.Rows[dg1.RowCount - 1].DefaultCellStyle.BackColor = dg1.DefaultCellStyle.BackColor; - } - else dg1.Rows[dg1.RowCount - 1].DefaultCellStyle.BackColor = Color.FromArgb(255, 96, 96, 96); - dg1.Rows[dg1.RowCount - 1].Cells[5].Value = Strings.ready; - })); - } - - if (duracion != null && filename != "") - { - dg1.Invoke(new MethodInvoker(delegate - { - if (duracion == "0") - { - dg1.Rows[dg1.RowCount - 1].Cells[2].Value = duracion; - dg1.Rows[dg1.RowCount - 1].Cells[3].Value = "Live"; - } - else - { - if (duracion.Length < 6) duracion = "00:" + duracion; - dg1.Rows[dg1.RowCount - 1].Cells[2].Value = duracion; - dg1.Rows[dg1.RowCount - 1].Cells[3].Value = duracion; - } - dg1.Rows[dg1.RowCount - 1].Cells[4].Value = filename; - if (Settings.Default.dark_mode == false) - { - dg1.Rows[dg1.RowCount - 1].DefaultCellStyle.BackColor = dg1.DefaultCellStyle.BackColor; - } - else dg1.Rows[dg1.RowCount - 1].DefaultCellStyle.BackColor = Color.FromArgb(255, 96, 96, 96); - one_ok = true; - dg1.Rows[dg1.RowCount - 1].Cells[5].Value = Strings.ready; - this.InvokeEx(f => f.dg1.Rows[dg1.RowCount - 1].Cells[5].Style.BackColor = Color.LightGreen); - })); - } - - if (dg1.RowCount > 1) - { - dg1.ClearSelection(); - dg1.Rows[dg1.RowCount - 1].Cells[1].Selected = true; - dg1.CurrentCell = dg1.Rows[dg1.RowCount - 1].Cells[1]; - } - urls_duration(); - if (one_ok == true) - { - chk_m3u_params.Left = 14; - chk_output_server.Enabled = false; - chk_m3u_params.Text = Strings.yt_params; - } - this.Enabled = true; release_datagrid(); - dg1.Rows[dg1.RowCount - 1].Cells[1].Selected = true; - } - - private void Validate_added_row() - { - - if (dg1.Rows[dg1.RowCount - 1].Cells[1].Value.ToString().ToLower().Contains("m3u") == false) - { - validate_gen_link(); - return; - } - - dg1.Rows[dg1.RowCount - 1].Cells[5].Value = Strings.var_url; - - if (dg1.Rows[dg1.RowCount - 1].Cells[1].Value == null) - { - dg1.Rows[dg1.RowCount - 1].Cells[5].Value = String.Empty; - dg1.Rows[dg1.RowCount - 1].Cells[4].Value = String.Empty; - dg1.Rows[dg1.RowCount - 1].Cells[3].Value = String.Empty; - dg1.Rows[dg1.RowCount - 1].Cells[2].Value = String.Empty; - //dg1.Rows[dg1.RowCount - 1].DefaultCellStyle.BackColor = dg1.DefaultCellStyle.BackColor; - return; - } - - if (dg1.Rows[dg1.RowCount - 1].Cells[1].Value.ToString().Contains("http") == false) - { - dg1.Rows[dg1.RowCount - 1].Cells[5].Value = Strings.error; - dg1.Rows[dg1.RowCount - 1].DefaultCellStyle.BackColor = Color.LightGoldenrodYellow; - return; - } - - dg1.Refresh(); - - Process probe = new Process(); - List lines_ouput = new List(); - String duracion = "00:00:00"; - probe.StartInfo.FileName = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - probe.StartInfo.Arguments = "-i " + " " + '\u0022' + dg1.Rows[dg1.RowCount - 1].Cells[1].Value.ToString() + '\u0022'; - - probe.StartInfo.RedirectStandardError = true; - probe.StartInfo.UseShellExecute = false; - probe.StartInfo.CreateNoWindow = true; - probe.EnableRaisingEvents = true; - - probe.Start(); - - while (!probe.StandardError.EndOfStream) - { - lines_ouput.Add(probe.StandardError.ReadLine()); - } - foreach (string str in lines_ouput) - { - if (str.ToLower().Contains("duration:")) - { - duracion = str.ToLower().Trim(); - break; - } - } - int dur_start = duracion.IndexOf("duration: ") + 10; - int dur_end = duracion.IndexOf(",") - 10; - duracion = duracion.Substring(dur_start, dur_end); - //MessageBox.Show(duracion); - - probe.WaitForExit(10000); - - if (duracion == null) - { - dg1.Rows[dg1.RowCount - 1].Cells[5].Value = Strings.error; - dg1.Rows[dg1.RowCount - 1].Cells[5].Style.BackColor = Color.LightGoldenrodYellow; - return; - } - - if (duracion != null) - { - TimeSpan time; - if (TimeSpan.TryParse(duracion, out time)) - { - dg1.Rows[dg1.RowCount - 1].Cells[2].Value = duracion; - dg1.Rows[dg1.RowCount - 1].Cells[3].Value = duracion; - dg1.Rows[dg1.RowCount - 1].Cells[4].Value = Path.GetFileNameWithoutExtension(dg1.Rows[dg1.RowCount - 1].Cells[1].Value.ToString()) + "_FF" + (dg1.RowCount).ToString(); - dg1.Rows[dg1.RowCount - 1].Cells[5].Value = Strings.ready; - //dg1.Rows[dg1.RowCount - 1].DefaultCellStyle.BackColor = dg1.DefaultCellStyle.BackColor; - - if (duracion.Length >= 12) - { - if (duracion.Substring(0, 11) == "0:00:00.000" || duracion.Substring(0, 12) == "00:00:00.000") - { - //dg1.Rows[dg1.RowCount - 1].DefaultCellStyle.BackColor = dg1.DefaultCellStyle.BackColor; - dg1.Rows[dg1.RowCount - 1].Cells[5].Value = Strings.ready; - } - } - } - - if (duracion == Strings.n_a) - { - dg1.Rows[dg1.RowCount - 1].Cells[2].Value = Strings.n_a; - dg1.Rows[dg1.RowCount - 1].Cells[3].Value = "\u221E"; - dg1.Rows[dg1.RowCount - 1].Cells[4].Value = Path.GetFileNameWithoutExtension(dg1.Rows[dg1.RowCount - 1].Cells[1].Value.ToString()) + "_FF" + (dg1.RowCount - 1).ToString(); - //dg1.Rows[dg1.RowCount - 1].DefaultCellStyle.BackColor = dg1.DefaultCellStyle.BackColor; - dg1.Rows[dg1.RowCount - 1].Cells[5].Value = Strings.ready; - } - } - urls_duration(); - } - - private void Validate_added_row_YT_PL() - { - if (!File.Exists(Path.Combine(Application.StartupPath, "yt-dlp.exe"))) - { - MessageBox.Show(Strings.yt_not, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - release_datagrid(); - return; - } - this.Enabled = false; - List list_lines = new List(); - Form11 frm_prog = new Form11(); - - new System.Threading.Thread(() => - { - System.Threading.Thread.CurrentThread.IsBackground = true; - frm_prog.ShowDialog(); - frm_prog.Refresh(); - }).Start(); - - Task t2 = Task.Run(() => - { - Process probe = new Process(); - probe.StartInfo.FileName = Path.Combine(Application.StartupPath, "yt-dlp.exe"); - probe.StartInfo.WorkingDirectory = Application.StartupPath; - probe.StartInfo.Arguments = "--flat-playlist --dump-json " + pl_url; - probe.StartInfo.RedirectStandardOutput = true; - probe.StartInfo.UseShellExecute = false; - probe.StartInfo.StandardOutputEncoding = Encoding.UTF8; - probe.StartInfo.CreateNoWindow = true; - probe.EnableRaisingEvents = true; - - probe.Start(); - - while (!probe.StandardOutput.EndOfStream) - { - if (frm_prog.abort_validate == false) - { - list_lines.Add(probe.StandardOutput.ReadLine()); - } - else - { - probe.StandardOutput.ReadToEnd(); - } - } - //foreach (String str in list_lines) MessageBox.Show(str); - probe.WaitForExit(); - try - { - frm_prog.Invoke(new MethodInvoker(delegate - { - frm_prog.Dispose(); - })); - } - catch { } - }); - - t2.Wait(); - - if (frm_prog.abort_validate == false) - { - if (list_lines.Count > 2000) - { - MessageBox.Show(Strings.max_links, Strings.max_list, MessageBoxButtons.OK, MessageBoxIcon.Warning); - release_datagrid(); - this.Enabled = true; - return; - } - - foreach (String lin in list_lines) - { - //if (lin != null && lin != "") dg1.Rows.Add(pic_noimg.Image, "https://www.youtube.com/watch?v=" + lin.Substring(lin.IndexOf('\u0022' + "url" + '\u0022' + ": " + '\u0022') + 8, 11), "-", "-", "", ""); - if (lin != null && lin != "") - { - int start = lin.IndexOf('\u0022' + "url" + '\u0022' + ": "); - int end = lin.IndexOf(", " + '\u0022' + "title" + '\u0022' + ": "); - String url = lin.Substring(start + 8, 43); - - dg1.Rows.Add(pic_noimg.Image, url, "-", "-", "", ""); - } - } - this.Focus(); - - //this.Enabled = false; - BG_Validate_URLs_YT.RunWorkerAsync(); - this.TopMost = true; - this.TopMost = false; - } - else - { - this.Enabled = true; - release_datagrid(); - this.Focus(); - } - } - - private void cell_zoom() - { - dg1.Invoke(new MethodInvoker(delegate - { - for (int i = 0; i < dg1.Columns.Count; i++) - if (dg1.Columns[i] is DataGridViewImageColumn) - { - ((DataGridViewImageColumn)dg1.Columns[i]).ImageLayout = DataGridViewImageCellLayout.Zoom; - dg1.Refresh(); - break; - } - dg1.Refresh(); - })); - } - - private void BG_Validate_URLs_DoWork(object sender, DoWorkEventArgs e) - { - this.InvokeEx(f => this.Enabled = false); - cell_zoom(); - - dg1.ReadOnly = false; - m3u_params_checked = chk_m3u_params.Checked; - output_server_checked = chk_output_server.Checked; - groupBox_m3u.Invoke(new MethodInvoker(delegate - { - foreach (Control ct in groupBox_m3u.Controls) - { - ct.Enabled = true; - } - })); - - chk_m3u_params.Invoke(new MethodInvoker(delegate - { - if (chk_m3u_params.CheckState == CheckState.Checked) - { - txt_m3u_params.Enabled = true; - } - else - { - txt_m3u_params.Enabled = false; - } - })); - - chk_output_server.Invoke(new MethodInvoker(delegate - { - if (chk_output_server.CheckState == CheckState.Checked) - { - txt_output_server.Enabled = true; - } - else - { - txt_output_server.Enabled = false; - } - })); - - this.Invoke(new MethodInvoker(delegate - { - foreach (DataGridViewRow row in dg1.Rows) - { - row.ReadOnly = false; - } - - foreach (Control ct in groupBox_m3u.Controls) - { - ct.Enabled = false; - } - btn_cancel_validate.Enabled = true; - })); - - procs.Clear(); - for (int ii = 0; ii < dg1.RowCount; ii++) - { - procs.Add("proc_urls_" + ii.ToString(), new Process()); - } - clean_imgs(); - - int prog = 0; - - Form9 form_prog2 = new Form9(); - form_prog2.abort_validate = false; - - ParallelOptions par_op = new ParallelOptions(); - System.Threading.CancellationTokenSource cts = new System.Threading.CancellationTokenSource(); - par_op.CancellationToken = cts.Token; - par_op.MaxDegreeOfParallelism = (int)n_downs.Value; - - new System.Threading.Thread(() => - { - System.Threading.Thread.CurrentThread.IsBackground = true; - form_prog2.StartPosition = FormStartPosition.CenterScreen; - form_prog2.progressBar1.Style = ProgressBarStyle.Continuous; - form_prog2.progressBar1.Maximum = dg1.RowCount + 1; - form_prog2.progressBar1.Value = 1; - form_prog2.Refresh(); - form_prog2.label1.Text = Strings.val_m3u; - form_prog2.lab_count.Text = "1/" + dg1.RowCount; - form_prog2.lab_count.Refresh(); - form_prog2.Refresh(); - this.Invoke(new MethodInvoker(delegate - { - form_prog2.ShowDialog(this); - form_prog2.Refresh(); - })); - - }).Start(); - - int current = 0; - object lockCurrent = new object(); - - var workItems = Enumerable.Range(0, dg1.RowCount); - int errors = 0; - fatal_parallel = false; - - ParallelLoopResult result = new ParallelLoopResult(); - - try - { - result = Parallel.ForEach(Partitioner.Create(workItems, EnumerablePartitionerOptions.NoBuffering), par_op, (i2) => - { - int i = 0; - lock (lockCurrent) - { - i = current; - current++; - } - - if (form_prog2.abort_validate == true) - { - cancelados_paralelos = true; - cts.Cancel(); - } - if (cts.IsCancellationRequested == true) form_prog2.abort_validate = true; - - if (dg1.Rows[i].Cells[1].Value == null) form_prog2.abort_validate = true; - - if (stop_validating_url == true) form_prog2.abort_validate = true; - - if (dg1.Rows[i].Cells[5].Value.ToString() == Strings.ready || dg1.Rows[i].Cells[5].Value.ToString() == Strings.processing || dg1.Rows[i].Cells[5].Value.ToString() == Strings.success) - { - prog = prog + 1; - try - { - form_prog2.Invoke(new MethodInvoker(delegate - { - if (form_prog2.progressBar1.Value < form_prog2.progressBar1.Maximum) - { - form_prog2.progressBar1.Value = form_prog2.progressBar1.Value + 1; - this.InvokeEx(f => TaskbarProgress.SetValue(this.Handle, form_prog2.progressBar1.Value, form_prog2.progressBar1.Maximum)); - } - form_prog2.progressBar1.Refresh(); - form_prog2.lab_count.Text = (prog).ToString() + "/" + dg1.Rows.Count; - form_prog2.lab_count.Refresh(); - })); - } - catch { } - return; - } - - this.InvokeEx(f => f.dg1.Rows[i].Cells[5].Value = Strings.var_url); - this.InvokeEx(f => f.dg1.Refresh()); - var tmp = procs["proc_urls_" + i.ToString()]; - - if (dg1.Rows[i].Cells[1].Value.ToString().ToLower().Contains("m3u")) - { - tmp.StartInfo.RedirectStandardOutput = true; - tmp.StartInfo.FileName = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - tmp.StartInfo.Arguments = "-i " + '\u0022' + dg1.Rows[i].Cells[1].Value.ToString() + '\u0022'; - tmp.StartInfo.RedirectStandardOutput = true; - tmp.StartInfo.RedirectStandardError = true; - tmp.StartInfo.UseShellExecute = false; - tmp.StartInfo.CreateNoWindow = true; - tmp.EnableRaisingEvents = true; - - String duracion = String.Empty; - String std_out = String.Empty; - List lines_ouput = new List(); - - if (cts.IsCancellationRequested == false) - { - tmp.Start(); - - //Check - while (!tmp.StandardError.EndOfStream) - { - lines_ouput.Add(tmp.StandardError.ReadLine()); - } - foreach (string str in lines_ouput) - { - if (str.ToLower().Contains("duration:")) - { - duracion = str.ToLower().Trim(); - break; - } - } - int dur_start = duracion.IndexOf("duration: ") + 10; - int dur_end = duracion.IndexOf(",") - 10; - duracion = duracion.Substring(dur_start, dur_end); - - tmp.WaitForExit(10000); - - if (duracion == null) duracion = Strings.n_a; - else - { - TimeSpan time = new TimeSpan(); - if (!TimeSpan.TryParse(duracion, out time)) - { - duracion = Strings.n_a; - } - } - tmp.StartInfo.Arguments = String.Empty; - } - else return; - - prog = prog + 1; - - form_prog2.Invoke(new MethodInvoker(delegate - { - if (form_prog2.progressBar1.Value < form_prog2.progressBar1.Maximum) - { - form_prog2.progressBar1.Value = form_prog2.progressBar1.Value + 1; - this.InvokeEx(f => TaskbarProgress.SetValue(this.Handle, form_prog2.progressBar1.Value, form_prog2.progressBar1.Maximum)); - } - form_prog2.progressBar1.Refresh(); - form_prog2.lab_count.Text = (prog).ToString() + "/" + dg1.Rows.Count; - form_prog2.lab_count.Refresh(); - })); - - if (duracion == null || duracion == string.Empty) - { - this.InvokeEx(f => f.dg1.Rows[i].Cells[5].Value = Strings.error); - this.InvokeEx(f => f.dg1.Rows[i].Cells[5].Style.BackColor = Color.LightGoldenrodYellow); - errors = errors + 1; - } - - if (duracion != null && cts.IsCancellationRequested == false) - { - TimeSpan time; - if (TimeSpan.TryParse(duracion, out time)) - { - this.Invoke(new MethodInvoker(delegate - { - dg1.Rows[i].Cells[2].Value = duracion; - dg1.Rows[i].Cells[3].Value = duracion; - dg1.Rows[i].Cells[4].Value = dg1.Rows[i].Cells[4].Value.ToString() + "_FF" + (i + 1).ToString(); - dg1.Rows[i].Cells[5].Value = Strings.ready; - dg1.Rows[i].DefaultCellStyle.BackColor = dg1.DefaultCellStyle.BackColor; - dg1.Rows[i].Cells[5].Style.BackColor = Color.LightGreen; - })); - - - if (duracion.Length >= 12) - { - if (duracion.Substring(0, 11) == "0:00:00.000" || duracion.Substring(0, 12) == "00:00:00.000") - { - Total_dur_urls = Total_dur_urls + TimeSpan.Parse(dg1.Rows[i].Cells[3].Value.ToString()).TotalSeconds; - this.Invoke(new MethodInvoker(delegate - { - dg1.Rows[i].DefaultCellStyle.BackColor = dg1.DefaultCellStyle.BackColor; - dg1.Rows[i].Cells[5].Value = Strings.ready; - dg1.Rows[i].Cells[5].Style.BackColor = Color.LightGreen; - })); - - } - } - } - - if (duracion == Strings.n_a) - { - this.Invoke(new MethodInvoker(delegate - { - dg1.Rows[i].Cells[2].Value = Strings.n_a; - dg1.Rows[i].Cells[3].Value = "\u221E"; - dg1.Rows[i].Cells[4].Value = dg1.Rows[i].Cells[4].Value.ToString() + "_FF" + (i + 1).ToString(); - dg1.Rows[i].DefaultCellStyle.BackColor = dg1.DefaultCellStyle.BackColor; - dg1.Rows[i].Cells[5].Value = Strings.ready; - })); - - try - { - Total_dur_urls = Total_dur_urls + TimeSpan.Parse(dg1.Rows[i].Cells[3].Value.ToString()).TotalSeconds; - } - catch { } - } - } - - form_prog2.Invoke(new MethodInvoker(delegate - { - if (errors > 0 && form_prog2.abort_validate == false) - { - form_prog2.lab_err.Text = Strings.errors + " " + errors.ToString(); - form_prog2.lab_err.Refresh(); - form_prog2.pictureBox1.Visible = true; - form_prog2.pictureBox1.Refresh(); - } - })); - } - else - { - //Generic link - String filename = ""; - String out_thumb = ""; - String duracion2 = ""; - - tmp.StartInfo.FileName = Path.Combine(Application.StartupPath, "yt-dlp.exe"); - if (!File.Exists(Path.Combine(Application.StartupPath, "yt-dlp.exe"))) - { - MessageBox.Show(Strings.yt_not, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - release_datagrid(); - return; - } - tmp.StartInfo.WorkingDirectory = Application.StartupPath; - tmp.StartInfo.Arguments = "--get-duration --get-title --get-thumbnail " + dg1.Rows[i].Cells[1].Value.ToString(); - tmp.StartInfo.RedirectStandardOutput = true; - tmp.StartInfo.UseShellExecute = false; - tmp.StartInfo.CreateNoWindow = true; - tmp.EnableRaisingEvents = true; - if (cts.IsCancellationRequested == false) - { - tmp.Start(); - - while (!tmp.StandardOutput.EndOfStream) - { - filename = tmp.StandardOutput.ReadLine(); - out_thumb = tmp.StandardOutput.ReadLine(); - duracion2 = tmp.StandardOutput.ReadLine(); - } - - PictureBox pic = new PictureBox(); - - if (out_thumb.Contains("http")) - { - try - { - if (out_thumb.Contains("?")) out_thumb = out_thumb.Substring(0, out_thumb.IndexOf("?")); - new System.Threading.Thread(() => - { - System.Threading.Thread.CurrentThread.IsBackground = true; - try { pic.Load(out_thumb); } catch { dg_thumbs[i] = pic_noimg.Image; } - dg_thumbs[i] = pic.Image; - dg1.Invoke(new MethodInvoker(delegate - { - dg1.Rows[i].Cells[0].Value = pic.Image; - })); - }).Start(); - } - catch - { - dg_thumbs[i] = pic_noimg.Image; - } - } - else - { - dg_thumbs[i] = pic_noimg.Image; - } - //cell_stretch(); - } - else return; - - tmp.WaitForExit(10000); - tmp.StartInfo.Arguments = ""; - - if (duracion2 == null || duracion2 == string.Empty) - { - dg1.Invoke(new MethodInvoker(delegate - { - dg1.Rows[i].DefaultCellStyle.BackColor = Color.LightGoldenrodYellow; - dg1.Rows[i].Cells[2].Value = Strings.n_a; - dg1.Rows[i].Cells[3].Value = "\u221E"; - int index_length = dg1.Rows[i].Cells[1].Value.ToString().Length; - - if (dg1.Rows[i].Cells[1].Value.ToString().Substring(index_length - 1, 1) == "/") - { - dg1.Rows[i].Cells[1].Value = dg1.Rows[i].Cells[1].Value.ToString().Substring(0, index_length - 1); - index_length = index_length - 1; - } - - int index_fn = dg1.Rows[i].Cells[1].Value.ToString().LastIndexOf("/"); - int ind_final = index_length - index_fn; - String dest = dg1.Rows[i].Cells[1].Value.ToString().Substring(index_fn + 1, ind_final - 1); - dg1.Rows[i].Cells[4].Value = dest; - if (Settings.Default.dark_mode == false) - { - dg1.Rows[i].DefaultCellStyle.BackColor = dg1.DefaultCellStyle.BackColor; - } - else dg1.Rows[i].DefaultCellStyle.BackColor = Color.FromArgb(255, 96, 96, 96); - dg1.Rows[i].Cells[5].Value = Strings.ready; - //this.InvokeEx(f => f.dg1.Rows[dg1.RowCount - 1].Cells[5].Style.BackColor = Color.LightGoldenrodYellow); - })); - } - - if (duracion2 != null && filename != "") - { - dg1.Invoke(new MethodInvoker(delegate - { - if (duracion2 == "0") - { - dg1.Rows[dg1.RowCount - 1].Cells[2].Value = duracion2; - dg1.Rows[dg1.RowCount - 1].Cells[3].Value = "Live"; - } - else - { - if (duracion2.Length < 6) duracion2 = "00:" + duracion2; - dg1.Rows[dg1.RowCount - 1].Cells[2].Value = duracion2; - dg1.Rows[dg1.RowCount - 1].Cells[3].Value = duracion2; - } - dg1.Rows[dg1.RowCount - 1].Cells[4].Value = filename; - if (Settings.Default.dark_mode == false) - { - dg1.Rows[dg1.RowCount - 1].DefaultCellStyle.BackColor = dg1.DefaultCellStyle.BackColor; - } - else dg1.Rows[dg1.RowCount - 1].DefaultCellStyle.BackColor = Color.FromArgb(255, 96, 96, 96); - one_ok = true; - dg1.Rows[dg1.RowCount - 1].Cells[5].Value = Strings.ready; - this.InvokeEx(f => f.dg1.Rows[dg1.RowCount - 1].Cells[5].Style.BackColor = Color.LightGreen); - })); - } - } - }); - - try - { - form_prog2.Invoke(new MethodInvoker(delegate - { form_prog2.Close(); })); - } - catch - { - try - { - form_prog2.Invoke(new MethodInvoker(delegate - { form_prog2.Close(); })); - } - catch { } - form_prog2.abort_validate = true; - } - } - catch (Exception exc) - { - fatal_parallel_msg = exc.Message; - fatal_parallel = true; - - try - { - form_prog2.Invoke(new MethodInvoker(delegate - { form_prog2.Close(); })); - } - catch - { - form_prog2.abort_validate = true; - } - } - if (result.IsCompleted == true) fatal_parallel = false; - else - { - if (cts.IsCancellationRequested == false) fatal_parallel = true; - else fatal_parallel = false; - } - } - - private void BG_Validate_URLs_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) - { - this.Enabled = true; - chk_m3u_params.Text = Strings.m3u_params; - chk_m3u_params.Left = 22; - chk_m3u_params.Checked = m3u_params_checked; - chk_output_server.Checked = output_server_checked; - if (m3u_params_checked == false) txt_m3u_params.Enabled = false; - if (output_server_checked == false) txt_output_server.Enabled = false; - for (int i = Application.OpenForms.Count - 1; i >= 0; i--) - { - if (Application.OpenForms[i].Name == "Form9") - try { Application.OpenForms[i].Close(); } catch { } - } - - foreach (DataGridViewRow row in dg1.Rows) - { - row.Cells[0].Value = dg_thumbs[row.Index]; - if (row.Cells[3].Value == null) continue; - if (row.Cells[3].Value.ToString() != "" && row.Cells[3].Value.ToString() != "-" && row.Cells[3].Value.ToString() != Strings.n_a && row.Cells[3].Value.ToString() != "\u221E") - { - Total_dur_urls = Total_dur_urls + TimeSpan.Parse(row.Cells[3].Value.ToString()).TotalSeconds; - } - } - - TimeSpan t = TimeSpan.FromSeconds(Total_dur_urls); - String dur = string.Format("{0:D2}h:{1:D2}m:{2:D2}s.{3:D3}ms", - (int)t.TotalHours, - t.Minutes, - t.Seconds, - t.Milliseconds); - - this.InvokeEx(f => f.lbl_urls_time.Visible = true); - this.InvokeEx(f => f.lbl_urls_time.Text = dur.Substring(0, 11)); - if (dur.Substring(0, 11) == "00h:00m:00s") - { this.InvokeEx(f => f.lbl_urls_time.Text = ""); } - //cell_stretch(); - urls_duration(); - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - } - - private void chk_m3u_params_CheckedChanged(object sender, EventArgs e) - { - if (chk_m3u_params.CheckState == CheckState.Checked) - { - txt_m3u_params.Enabled = true; - } - else - { - txt_m3u_params.Enabled = false; - } - } - - private void button16_Click_1(object sender, EventArgs e) - { - if (folderBrowser_m3u.ShowDialog() == DialogResult.OK) - { - if (folderBrowser_m3u.SelectedPath != txt_path_m3u.Text) btn_save_path_url.Enabled = true; - txt_path_m3u.Text = folderBrowser_m3u.SelectedPath; - txt_path_m3u.BackColor = Color.White; - - try - { - File.WriteAllText(folderBrowser_m3u.SelectedPath + "\\" + "FFBatch_test.txt", "FFBatch_test"); - System.Threading.Thread.Sleep(10); - File.Delete(folderBrowser_m3u.SelectedPath + "\\" + "FFBatch_test.txt"); - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.write_error1 + " " + Environment.NewLine + excpt.Message, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Warning); - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - return; - } - } - } - - private void ct_validate_url_Click(object sender, EventArgs e) - { - dg1.EndEdit(); - dg1.ClearSelection(); - - for (int i = 1; i < dg1.RowCount; i++) - - { - if (dg1.Rows[i].Cells[5].Value.ToString() == Strings.error || dg1.Rows[i].Cells[5].Value.ToString() == Strings.failed) - - { - dg1.Rows.RemoveAt(i); - i--; - } - } - - if (dg1.Rows[0].Cells[1] != null && dg1.Rows[0].Cells[5].Value.ToString() == Strings.error) - { - dg1.Rows.RemoveAt(0); - return; - } - dg1.Refresh(); - } - - private void ct_del_m3u_Click(object sender, EventArgs e) - { - dg1.EndEdit(); - dg1.ClearSelection(); - - for (int i = 1; i < dg1.RowCount; i++) - - { - if (dg1.RowCount == 1 && dg1.Rows[0].Cells[1].Value == null) - { - dg1.Rows.Clear(); - return; - } - - if (dg1.Rows[i].Cells[1].Value == null) - - { - dg1.Rows.RemoveAt(i); - i--; - } - } - } - - private void ct_paste_m3u_Click(object sender, EventArgs e) - { - check_internet(); if (internet_up == false) return; - if (Clipboard.GetText().Length > 1024) return; - - if (has_you_row() == true) - { - MessageBox.Show(Strings.mix_urls, Strings.information, MessageBoxButtons.OK, MessageBoxIcon.Information); - return; - } - - foreach (DataGridViewRow row in dg1.Rows) - { - if (row.Cells[1].Value.ToString().Contains(Clipboard.GetText().Substring(0, Clipboard.GetText().Length - 1))) - { - MessageBox.Show(Strings.url_alr); - return; - } - } - - if (Clipboard.GetText() != String.Empty && Clipboard.GetText().ToLower().Contains("http")) - { - - dg1.Rows.Add(pic_noimg.Image, Clipboard.GetText(), "", "", "", ""); - foreach (DataGridViewRow row in dg1.Rows) - { - row.ReadOnly = true; - } - foreach (Control ct in groupBox_m3u.Controls) - { - ct.Enabled = false; - } - - Validate_added_row(); - - foreach (DataGridViewRow row in dg1.Rows) - { - row.ReadOnly = false; - } - foreach (Control ct in groupBox_m3u.Controls) - { - ct.Enabled = true; - } - - if (chk_m3u_params.CheckState == CheckState.Checked) - { - txt_m3u_params.Enabled = true; - } - else - { - txt_m3u_params.Enabled = false; - } - - if (chk_output_server.CheckState == CheckState.Checked) - { - txt_output_server.Enabled = true; - } - else - { - txt_output_server.Enabled = false; - } - } - } - - private void release_datagrid() - { - this.InvokeEx(f => this.Enabled = true); - - dg1.Invoke(new MethodInvoker(delegate - { - ((DataGridViewImageColumn)dg1.Columns[0]).ImageLayout = DataGridViewImageCellLayout.Stretch; - })); - - this.Invoke(new MethodInvoker(delegate - { - dg1.ReadOnly = false; - - foreach (Control ct in groupBox_m3u.Controls) - { - ct.Enabled = true; - } - - if (chk_m3u_params.CheckState == CheckState.Checked) - { - txt_m3u_params.Enabled = true; - } - else - { - txt_m3u_params.Enabled = false; - } - - if (chk_output_server.CheckState == CheckState.Checked) - { - txt_output_server.Enabled = true; - } - else - { - txt_output_server.Enabled = false; - } - - foreach (DataGridViewRow row in dg1.Rows) - { - row.ReadOnly = false; - } - })); - } - - private void get_mixed_urls() - { - Boolean has_youtube = false; - Boolean has_m3u = false; - foreach (DataGridViewRow row in dg1.Rows) - { - if (row.Cells[1].Value.ToString().ToLower().Contains("youtu.be") || row.Cells[1].Value.ToString().ToLower().Contains("youtube.com")) - { - has_youtube = true; - } - else - { - has_m3u = true; - } - } - if (has_m3u == true && has_youtube == true) - { - mixed_urls = true; - MessageBox.Show(Strings.mix_urls, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - else mixed_urls = false; - } - - private Boolean url_repeat() - { - Boolean remove_dups = false; - Boolean dups = false; - - for (int i = 0; i < dg1.RowCount - 1; i++) //compare data - { - var Row = dg1.Rows[i]; - string abc = Row.Cells[4].Value.ToString(); - - for (int j = i + 1; j < dg1.RowCount; j++) - { - var Row2 = dg1.Rows[j]; - string def = Row2.Cells[4].Value.ToString(); - if (abc == def) - { - dups = true; - if (remove_dups == false) - { - DialogResult a = MessageBox.Show(Strings.dup_url + " " + Environment.NewLine + Environment.NewLine + '\u0022' + abc + '\u0022' + Environment.NewLine + Environment.NewLine + Strings.remove_dup, Strings.out_dup, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); - if (a == DialogResult.Yes) - { - remove_dups = true; - } - else - { - remove_dups = false; - return true; - } - } - if (remove_dups == true) - { - Row.Cells[4].Value = Row2.Cells[4].Value; - dg1.Rows.Remove(Row2); - j--; - } - } - } - } - if (dups == true && remove_dups == false) return true; - else return false; - } - - private void download_any() - { - List list_lines = new List(); - List list_err = new List(); - List er = new List(); - pic_warnings.Visible = false; - pic_no_errors.Visible = false; - int total_videos = dg1.RowCount; - int pending_urls = total_videos; - aborted_url = false; - Boolean killed = false; - Pg1.Value = 0; - Pg1.Maximum = 100; - Pg1.Text = "0%"; - int pg2 = 0; - Pg1.Refresh(); - - working = true; - m3u_single_running = true; - cancelados_paralelos = false; - aborted_url = false; - errors_enc = 0; - pic_no_errors.Visible = false; - pic_warnings.Visible = false; - pic_recording.Visible = false; - - //Disable Datagrid edition - foreach (DataGridViewRow row in dg1.Rows) - { - row.ReadOnly = true; - row.Cells[5].Value = Strings.ready; - } - - procs.Clear(); - - for (int ii = 0; ii < dg1.RowCount; ii++) - { - procs.Add("proc_urls_" + ii.ToString(), new Process()); - } - - String format_out = combo_ext_m3u.SelectedItem.ToString(); - String down_speed = ""; - - if (chk_best_yt.Checked) bestv_a = "-f bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio"; - else bestv_a = String.Empty; - - if (chk_down_limit.Checked == true) down_speed = "-r " + Convert.ToInt32(n_down_speed.Value).ToString() + "M"; - String embed_subs = ""; - if (chk_yout_subs.Checked == true) embed_subs = "--embed-subs --all-subs"; - String auto_subs = ""; - if (chk_auto_subs.Checked == true) - { - auto_subs = "--write-auto-sub --sub-lang en,es,it,pt,de,hi,ar,cn"; - if (chk_yout_subs.Checked == true) embed_subs = "--embed-subs"; - } - String embed_meta = ""; - if (chk_embed_meta.Checked == true) embed_meta = "--add-metadata"; - String write_subs = ""; - if (chk_save_subtitles.Checked == true) embed_meta = "--write-sub"; - - String convert_subs = ""; - if (chk_convert_srt.Checked == true) embed_meta = "--convert-subs=srt"; - String m3u_params = txt_m3u_params.Text; - - foreach (DataGridViewRow row in dg1.Rows) - { - if (row.Cells[4].Value.ToString().Contains("/") || row.Cells[4].Value.ToString().Contains(":") || row.Cells[4].Value.ToString().Contains("*") || row.Cells[4].Value.ToString().Contains("?") || row.Cells[4].Value.ToString().Contains("¿") || row.Cells[4].Value.ToString().Contains('\u0022') || row.Cells[4].Value.ToString().Contains("<") || row.Cells[4].Value.ToString().Contains(">") || row.Cells[4].Value.ToString().Contains("|") || row.Cells[4].Value.ToString().Contains("\\")) - { - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("/", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace(":", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("*", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("?", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("¿", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("@", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("\u0022", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("@", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("<", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace(">", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("|", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("\\", ""); - } - - if (row.Cells[4].Value.ToString().Length > 224) row.Cells[4].Value = row.Cells[4].Value.ToString().Substring(0, 224); - } - - Disable_Controls(); - time_n_tasks = 0; - lbl_elapsed.Text = Strings.total_time + " " + "00h:00m:00s"; - timer_tasks.Start(); - - new System.Threading.Thread(() => - { - System.Threading.Thread.CurrentThread.IsBackground = true; - - for (int list_index = 0; list_index < dg1.RowCount; list_index++) - { - System.Threading.Thread.Sleep(50); //Allow kill process to send cancel_queue - Boolean quit = false; - - if (cancel_queue == true) - { - working = false; - m3u_running = false; - m3u_single_running = false; - timer_tasks.Stop(); - timer2.Stop(); - cancelados_paralelos = false; - aborted_url = false; - Timer_display.Enabled = false; - release_datagrid(); - - this.InvokeEx(f => f.lbl_dw_speed.Text = ""); - Enable_Controls(); - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - - MessageBox.Show(Strings.queue_abort, Strings.task_abort, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - - return; - } - - //Skip current - if (skip_current_url == true) - { - skip_current_url = false; - - continue; - } - - String file = ""; - dg1.Invoke(new MethodInvoker(delegate - { - file = dg1.Rows[list_index].Cells[1].Value.ToString(); - })); - - String ffm = Path.Combine(Application.StartupPath, "yt-dlp.exe"); - String destino = txt_path_m3u.Text; - - if (!Directory.Exists(destino)) - { - try - { - Directory.CreateDirectory(destino); - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.write_error2 + " " + excpt.Message, Strings.write_error, MessageBoxButtons.OK, MessageBoxIcon.Error); - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - //this.InvokeEx(f => f.lbl_d_v.Text = ""); - return; - } - } - - var tmp = procs["proc_urls_" + list_index.ToString()]; - - tmp.StartInfo.FileName = ffm; - - string replace_m3u_param = "-bsf:a aac_adtstoasc -c copy"; - if (m3u_params.Contains("-f ")) - { - tmp.StartInfo.Arguments = bestv_a + " " + Clear_cache + " " + m3u_params.Replace(replace_m3u_param, "") + " " + down_speed + " " + embed_subs + " " + auto_subs + " " + embed_meta + " " + write_subs + " " + convert_subs + " -o " + '\u0022' + destino + "\\" + dg1.Rows[list_index].Cells[4].Value.ToString() + "." + format_out + '\u0022' + " " + file; - } - else - { - if (bestv_a.Length == 0) - { - tmp.StartInfo.Arguments = Clear_cache + " -f " + format_out + " " + m3u_params.Replace(replace_m3u_param, "") + " " + down_speed + " " + embed_subs + " " + auto_subs + " " + embed_meta + " -o " + '\u0022' + destino + "\\" + dg1.Rows[list_index].Cells[4].Value.ToString() + "." + format_out + '\u0022' + " " + file; - } - else - { - tmp.StartInfo.Arguments = bestv_a + " " + Clear_cache + " " + m3u_params.Replace(replace_m3u_param, "") + " " + down_speed + " " + embed_subs + " " + auto_subs + " " + embed_meta + " -o " + '\u0022' + destino + "\\" + dg1.Rows[list_index].Cells[4].Value.ToString() + "." + format_out + '\u0022' + " " + file; - } - } - - tmp.StartInfo.WorkingDirectory = Application.StartupPath; - - if (!File.Exists(Path.Combine(Application.StartupPath, "yt-dlp.exe"))) - { - cancel_queue = true; - working = false; - timer_tasks.Stop(); - Enable_Controls(); - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - this.InvokeEx(f => timer_yt.Stop()); - //this.InvokeEx(f => f.lbl_down_time.Text = ""); - MessageBox.Show(Strings.yt_not, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - this.InvokeEx(f => timer_yt.Start()); - - tmp.StartInfo.RedirectStandardOutput = true; - tmp.StartInfo.StandardOutputEncoding = Encoding.UTF8; - tmp.StartInfo.RedirectStandardInput = true; - tmp.StartInfo.RedirectStandardError = true; - tmp.StartInfo.StandardErrorEncoding = Encoding.UTF8; - tmp.StartInfo.UseShellExecute = false; - tmp.StartInfo.CreateNoWindow = true; - tmp.EnableRaisingEvents = true; - tmp.Start(); - - String err_txt = ""; - String error_out = ""; - String tr_speed = ""; - Double interval = 0; - Decimal est_bitrate = 0; - Decimal est_size = 0; - Double sec_prog = 0; - int progress = 0; - //this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.Normal)); - String pl_title = ""; - - while (!tmp.StandardOutput.EndOfStream) - { - err_txt = tmp.StandardOutput.ReadLine(); - list_lines.Add(err_txt); - - if (err_txt.Contains("[download] Downloading playlist: ")) pl_title = err_txt.Replace("[download] Downloading playlist: ", ""); - - if (err_txt.Contains("[youtube:tab] Downloading page ")) - { - lbl_speed.Invoke(new MethodInvoker(delegate - { - if (pl_title.Length == 0) lbl_speed.Text = Strings.brow_page + " " + err_txt.Replace("[youtube:tab] Downloading page ", ""); - else lbl_speed.Text = Strings.browsing + " " + "\u0022" + pl_title + "\u0022" + " Page " + err_txt.Replace("[youtube:tab] Downloading page ", ""); - })); - } - - if (err_txt.Contains("[youtube:tab] playlist ") && err_txt.Contains("Downloading ") && err_txt.Contains("videos")) - { - int ind1 = err_txt.LastIndexOf("Downloading "); - int ind2 = err_txt.Length; - String n_vs = err_txt.Substring(ind1, ind2 - ind1).Replace("Downloading ", "").Replace("videos", "").Trim(); ; - lbl_speed.Invoke(new MethodInvoker(delegate - { - lbl_speed.Text = Strings.total + ": " + n_vs.Replace("Videos: Downloading ", "").Replace("videos", "").Trim(); - //lbl_d_v.Visible = true; - //lbl_d_v.Text = "Starting downloads..."; - total_videos = Convert.ToInt32(n_vs.Replace("Videos: Downloading ", "").Replace("videos", "").Trim()); - Pg1.Maximum = total_videos * 100; - this.InvokeEx(f => f.Pg1.Text = "0 of " + total_videos.ToString()); - })); - } - if (err_txt.Contains("[download] Destination: ")) - { - lbl_speed.Invoke(new MethodInvoker(delegate - { - lbl_speed.Text = Path.GetFileName(err_txt.Replace("Downloading video: ", "")); - })); - } - - String prog_cell = ""; - - if (err_txt.Contains("%")) - { - try - { - this.InvokeEx(f => f.lbl_speed.TextAlign = ContentAlignment.MiddleLeft); - this.InvokeEx(f => f.lbl_speed.Width = 349); - Double prog_y = Double.Parse(err_txt.Substring(err_txt.IndexOf("%") - 4, 4)); - prog_y = prog_y / 10; - progress = Convert.ToInt32(prog_y); - pg2 = progress; - this.InvokeEx(f => f.dg1.Rows[list_index].Cells[5].Value = progress.ToString() + "%"); - prog_cell = progress.ToString() + "%"; - } - catch { } - } - if (err_txt.Contains("ETA") && show_est == true) - { - try - { - int ind1 = err_txt.LastIndexOf("ETA"); - String unit = ""; - String est_time = err_txt.Substring(ind1, err_txt.Length - ind1).Replace("ETA", "").Trim(); - if (err_txt.ToLower().Contains("mib/s")) unit = " MB/s"; - if (err_txt.ToLower().Contains("kib/s")) unit = " KB/s"; - this.InvokeEx(f => f.txt_remain.Text = err_txt.Substring(err_txt.IndexOf("at ") + 3, 5) + " " + unit + " - " + est_time); - } - catch { } - } - - try - { - if ((progress / pending_urls) > Pg1.Value) - { - this.Invoke(new MethodInvoker(delegate - { - Pg1.Value = progress / pending_urls; - Pg1.Text = Pg1.Value.ToString() + "%"; - TaskbarProgress.SetValue(this.Handle, Pg1.Value, Pg1.Maximum); - })); - } - } - catch { } - } - - while (!tmp.StandardError.EndOfStream) - { - error_out = tmp.StandardError.ReadLine(); - } - tmp.WaitForExit(); - - pending_urls = pending_urls - 1; - - tmp.StartInfo.Arguments = String.Empty; - this.Invoke(new MethodInvoker(delegate - { - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - timer_yt.Stop(); - lbl_speed.Text = ""; - txt_remain.Text = ""; - })); - - list_lines.Add(""); - list_lines.Add("---------End of download log---------"); - list_lines.Add(""); - - if (tmp.ExitCode == 0) - - { - if (skipped == false && aborted_url == false) - { - this.InvokeEx(f => f.dg1.Rows[list_index].Cells[5].Value = Strings.success); - } - else - { - this.InvokeEx(f => f.dg1.Rows[list_index].Cells[5].Value = Strings.skipped); - skipped = false; - } - if (aborted_url == true) - { - this.InvokeEx(f => f.dg1.Rows[list_index].Cells[5].Value = Strings.aborted); - aborted_url = false; - } - if (stopped_recording == true) - { - this.InvokeEx(f => f.dg1.Rows[list_index].Cells[5].Value = Strings.finish); - this.InvokeEx(f => f.dg1.Rows[list_index].Cells[5].Style.BackColor = Color.White); - } - } - else - { - if (skipped == true) - { - this.InvokeEx(f => f.dg1.Rows[list_index].Cells[5].Value = Strings.skipped); - skipped = false; - } - else - { - this.InvokeEx(f => f.dg1.Rows[list_index].Cells[5].Value = Strings.failed); - errors_enc = errors_enc + 1; - //this.InvokeEx(f => f.dg1.Rows[list_index].Cells[5].Style.BackColor = Color.PaleGoldenrod); - } - } - - if (list_index + 1 == total_videos || quit == true) - { - timer2.Stop(); - this.Invoke(new MethodInvoker(delegate - { - Pg1.Style = ProgressBarStyle.Continuous; - pic_recording.Visible = false; - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - Pg1.Value = Pg1.Maximum; - Pg1.Text = "100%"; - lbl_dw_speed.Text = ""; - Timer_display.Enabled = false; - })); - - - m3u_single_running = false; - working = false; - m3u_running = false; - cancelados_paralelos = false; - timer_tasks.Stop(); - release_datagrid(); - //Save log - if (no_save_logs == false) - { - string[] array_err = list_lines.ToArray(); - - String path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.log"; - if (is_portable == true) path = port_path + "ff_batch_portable.log"; - - StreamWriter SaveFile = new StreamWriter(path); - SaveFile.WriteLine("Batch log sesion: " + System.DateTime.Now); - SaveFile.WriteLine("-----------------------"); - foreach (String item in array_err) - { - SaveFile.WriteLine(item); - } - String msg_er = String.Empty; - if (er.Count > 0) SaveFile.WriteLine(msg_er); - SaveFile.Close(); - - File.AppendAllText(path, "-----------------------"); - File.AppendAllText(path, Environment.NewLine + Strings.end_log); - FileInfo fileInfo = new FileInfo(path); - - var bytes = fileInfo.Length; - - var kilobytes = (double)bytes / 1024; - var megabytes = kilobytes / 1024; - var gigabytes = megabytes / 1024; - - //Format size view - String size = ""; - String separator = "."; - - if (bytes > 1000000000) - { - if (gigabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String gigas = gigabytes.ToString(); - if (gigas.Length >= 5) - { - gigas = gigas.Substring(0, gigas.LastIndexOf(separator) + 3); - size = (gigas + " " + "GB"); - } - else - { - size = (gigas + " " + "GB"); - } - } - - if (bytes >= 1048576 && bytes <= 1000000000) - { - if (megabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - String megas = megabytes.ToString(); - if (megas.Length > 5) - { - megas = megas.Substring(0, megas.LastIndexOf(separator)); - size = (megas + " " + "MB"); - } - else - { - size = (megas + " " + "MB"); - } - } - - if (bytes >= 1024 && bytes < 1048576) - - { - if (kilobytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String kbs = kilobytes.ToString(); - if (kbs.Length >= 5) - { - kbs = kbs.Substring(0, kbs.LastIndexOf(separator)); - size = (kbs + " " + "KB"); - } - else - { - size = (kbs + " " + "KB"); - } - } - if (bytes > -1 && bytes < 1024) - { - String bits = bytes.ToString(); - size = (bits + " Bytes"); - } - - //End Format size view - File.AppendAllText(path, Environment.NewLine + Strings.log_size + " " + size); - - //End save log - } - this.Invoke(new MethodInvoker(delegate - { - toolT002.RemoveAll(); - if (errors_enc == 0) - { - pic_no_errors.Visible = true; - - if (dg1.RowCount == 1) - { - String cur_out = destino + "\\" + dg1.Rows[list_index].Cells[4].Value.ToString() + "." + format_out; - System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentUICulture; - String sep_th = ci.NumberFormat.CurrencyGroupSeparator; - String unit = ""; - String dur = ""; - - this.Invoke(new MethodInvoker(delegate - { - lbl_est_size.Text = String.Empty; - lbl_bitrate.Text = String.Empty; - Process probe = new Process(); - - List lines_ouput = new List(); - probe.StartInfo.FileName = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - String ffprobe_frames = " " + "--Output=General;%OverallBitRate/String%" + "\\n" + "%FileSize/String3%" + "\\n" + "%Duration/String3%"; - probe.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + cur_out + '\u0022'; - probe.StartInfo.RedirectStandardOutput = true; - probe.StartInfo.UseShellExecute = false; - probe.StartInfo.CreateNoWindow = true; - probe.EnableRaisingEvents = true; - probe.Start(); - - while (!probe.StandardOutput.EndOfStream) - { - lines_ouput.Add(probe.StandardOutput.ReadLine()); - } - probe.WaitForExit(); - - if (lines_ouput[0] != null && lines_ouput[0].Length > 0) - { - if (lines_ouput[0].ToLower().Contains(" kb/s")) unit = "Kb/s"; - if (lines_ouput[0].ToLower().Contains(" mb/s")) unit = "Mb/s"; - if (lines_ouput[0].ToLower().Contains(" gb/s")) unit = "Gb/s"; - lines_ouput[0] = lines_ouput[0].Replace(" kb/s", "").Replace(" Mb/s", "").Replace(" Gb/s", ""); - lines_ouput[0] = lines_ouput[0].Replace(" ", sep_th); - lbl_bitrate.Text = Strings.bitrate + ":" + " " + lines_ouput[0] + " " + unit; - } - if (lines_ouput[1] != null && lines_ouput[1].Length > 0) lbl_est_size.Text = Strings.f_size + ":" + " " + lines_ouput[1].Replace("MiB", "MB").Replace("GiB", "GB").Replace("KiB", "KB"); - if (lines_ouput[2] != null && lines_ouput[2].Length > 0) dur = lines_ouput[2]; - })); - - if (no_output_pop == false) - { - Form26 frm26 = new Form26(); - frm26.out_file = cur_out; - frm26.dur_file = dur; - if (Settings.Default.dark_mode == false) frm26.pic_img = pic_reading.Image; - else frm26.pic_img = pic_reading.InitialImage; - frm26.tot_bit = lbl_bitrate.Text; - frm26.out_size = lbl_est_size.Text; - this.Invoke(new MethodInvoker(delegate - { - frm26.Show(this); - if (frm26.no_pop == true) no_output_pop = true; - })); - } - } - - //End output single info - } - else - { - pic_no_errors.Visible = false; - pic_recording.Visible = false; - toolT002.SetToolTip(this.pic_warnings, Strings.there_w + " " + errors_enc.ToString() + " " + Strings.errors_se); - pic_warnings.Visible = true; - } - })); - - //Automatic shutdown check - if (chkshut.Checked && cancel_queue == false) - { - auto_shut(); - return; - } - //End shutdown check - else - { - if (cancel_queue == false) - { - if (Form.ActiveForm == null) - { - notifyIcon1.BalloonTipText = Strings.url_down_c; - notifyIcon1.BalloonTipIcon = ToolTipIcon.Info; - notifyIcon1.BalloonTipTitle = Strings.url_down_c2; - notifyIcon1.ShowBalloonTip(0); - if (play_on_end == true && er.Count == 0) play_end(); - if (er.Count > 0) - { - String warnings = ""; - foreach (String st in er) warnings = warnings + st; - MessageBox.Show(Strings.warn_down + " " + Environment.NewLine + Environment.NewLine + warnings + Environment.NewLine + Environment.NewLine + Strings.check_log, Strings.warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - } - - if (chk_open_compl.Checked) - { - if (Directory.GetFiles(destino).Length != 0) - { - Process open_processed = new Process(); - open_processed.StartInfo.FileName = "explorer.exe"; - open_processed.StartInfo.Arguments = '\u0022' + destino + '\u0022'; - open_processed.Start(); - } - } - } - else - { - m3u_single_running = false; - cancelados_paralelos = false; - - this.Invoke(new MethodInvoker(delegate - { - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - Pg1.Value = Pg1.Maximum; - Pg1.Text = "100%"; - lbl_dw_speed.Text = ""; - })); - - if (quit == false && stopped_recording == false) this.InvokeEx(f => MessageBox.Show(Strings.queue_abort, Strings.aborted, MessageBoxButtons.OK, MessageBoxIcon.Error)); - - } - } - } - } - - Enable_Controls(); - //String borrar = destino_test + "\\" + Path.GetFileNameWithoutExtension(file_prueba) + "." + txt_format.Text; - }).Start(); - } - - private void btn_start_m3u_Click(object sender, EventArgs e) - { - Pg1.Focus(); - lbl_est_size.Text = ""; - lbl_bitrate.Text = ""; - cancel_queue = false; - notifyIcon1.Visible = true; - if (m3u_single_running == true) return; - Boolean unknown_link = false; - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - foreach (DataGridViewRow row in dg1.Rows) - { - if (row.Cells[5].Value.ToString() == Strings.error || row.Cells[5].Value.ToString() == Strings.unknown) - { - MessageBox.Show(Strings.errors_list, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - - if (dg1.RowCount == 0) - { - MessageBox.Show(Strings.down_empty, Strings.no_files, MessageBoxButtons.OK, MessageBoxIcon.Information); - return; - } - - if (txt_m3u_params.Text == String.Empty) - { - MessageBox.Show(Strings.params_empty2, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (txt_path_m3u.Text == Strings.no_path2 && chk_output_server.CheckState == CheckState.Unchecked) - { - MessageBox.Show(Strings.select_out, Strings.out_conf, MessageBoxButtons.OK, MessageBoxIcon.Warning); - return; - } - String output_server = String.Empty; - - if (chk_output_server.CheckState == CheckState.Checked && txt_output_server.Text == String.Empty) - { - MessageBox.Show(Strings.out_serv1, Strings.warning, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; - } - else - { - output_server = txt_output_server.Text; - } - - get_mixed_urls(); - if (mixed_urls == true) return; - - foreach (DataGridViewRow row in dg1.Rows) - { - if (!row.Cells[1].Value.ToString().ToLower().Contains("youtu.be") && !row.Cells[1].Value.ToString().ToLower().Contains("youtube") && !row.Cells[1].Value.ToString().ToLower().Contains("m3u")) - { - unknown_link = true; - break; - } - } - - if (unknown_link == true) - { - download_any(); - return; - } - - if (!dg1.Rows[0].Cells[1].Value.ToString().ToLower().Contains("youtu.be") && !dg1.Rows[0].Cells[1].Value.ToString().ToLower().Contains("youtube.com")) - { - foreach (DataGridViewRow row in dg1.Rows) - { - if (row.Cells[5].Value.ToString() == Strings.ready && row.Cells[2].Value.ToString() != Strings.n_a) - { - if (TimeSpan.Parse(row.Cells[3].Value.ToString()).TotalSeconds > TimeSpan.Parse(row.Cells[2].Value.ToString()).TotalSeconds) - { - MessageBox.Show(Strings.capture_time2 + " " + row.Cells[4].Value.ToString() + " " + Strings.exc_dur, Strings.wrong_c_dur, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - } - } - foreach (DataGridViewRow row in dg1.Rows) - { - if (row.Cells[4].Value.ToString().Contains("/") || row.Cells[4].Value.ToString().Contains(":") || row.Cells[4].Value.ToString().Contains("*") || row.Cells[4].Value.ToString().Contains("?") || row.Cells[4].Value.ToString().Contains("¿") || row.Cells[4].Value.ToString().Contains('\u0022') || row.Cells[4].Value.ToString().Contains("<") || row.Cells[4].Value.ToString().Contains(">") || row.Cells[4].Value.ToString().Contains("|") || row.Cells[4].Value.ToString().Contains("\\")) - { - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("/", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace(":", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("*", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("?", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("¿", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("@", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("\u0022", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("<", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace(">", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("|", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("\\", ""); - } - } - - //Pending validation - Boolean pre_validate = false; - - foreach (DataGridViewRow row in dg1.Rows) - { - if (row.Cells[5].Value.ToString() == String.Empty) - { - pre_validate = true; - } - } - if (pre_validate == true) - { - DialogResult a = MessageBox.Show(Strings.val_urls, Strings.val_pending, MessageBoxButtons.OKCancel, MessageBoxIcon.Question); - if (a == DialogResult.OK) - { - was_started.Text = btn_start_m3u.Text; - btn_validate_url.PerformClick(); - return; - } - else - { - return; - } - } - if (url_repeat() == true) return; - - foreach (DataGridViewRow row in dg1.Rows) - { - if (row.Cells[3].Value.ToString() == "\u221E") - { - MessageBox.Show(Strings.undef_dur_all, Strings.undef_seq, MessageBoxButtons.OK, MessageBoxIcon.Warning); - //return; - } - } - - String destino_test = Path.Combine(txt_path_m3u.Text, "FFBatch_test"); - String file_prueba = dg1.Rows[0].Cells[1].Value.ToString(); - String file_output = dg1.Rows[0].Cells[5].Value.ToString() + "." + combo_ext_m3u.SelectedItem.ToString(); - String fichero = Path.GetFileName(file_prueba); - - if (chk_try.CheckState == CheckState.Unchecked) - { //Try preset - if (!file_prueba.ToLower().Contains("youtu.be") && !file_prueba.ToLower().Contains("youtube.com")) - { - Form11 frm_prog = new Form11(); - new System.Threading.Thread(() => - { - System.Threading.Thread.CurrentThread.IsBackground = true; - frm_prog.label1.Text = Strings.trying; - frm_prog.label1.Refresh(); - frm_prog.ShowDialog(); - frm_prog.Refresh(); - }).Start(); - - if (!Directory.Exists(destino_test)) - { - try - { - Directory.CreateDirectory(destino_test); - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.error_test_f + " " + excpt.Message, Strings.write_error2, MessageBoxButtons.OK, MessageBoxIcon.Error); - this.Cursor = Cursors.Arrow; - return; - } - } - - Process consola_pre = new Process(); - - consola_pre.StartInfo.FileName = Application.StartupPath + "\\" + "ffmpeg.exe"; - consola_pre.StartInfo.Arguments = " -i " + file_prueba + " -t 0.25 " + txt_m3u_params.Text + " -y " + '\u0022' + destino_test + "\\" + file_output + '\u0022'; - consola_pre.StartInfo.CreateNoWindow = true; - consola_pre.StartInfo.RedirectStandardError = true; - consola_pre.StartInfo.RedirectStandardOutput = true; - consola_pre.StartInfo.UseShellExecute = false; - consola_pre.Start(); - frm_prog.procId = consola_pre.Id; - String err_txt_1 = ""; - - while (!consola_pre.StandardError.EndOfStream) - { - err_txt_1 = consola_pre.StandardError.ReadLine(); - this.InvokeEx(f => f.listBox4.Items.Add(err_txt_1)); - this.InvokeEx(f => f.listBox4.Refresh()); - } - - consola_pre.WaitForExit(6000); - consola_pre.StartInfo.Arguments = String.Empty; - - if (consola_pre.StartInfo.Arguments != String.Empty) - { - consola_pre.Kill(); - try - { - frm_prog.Invoke(new MethodInvoker(delegate - { - frm_prog.Dispose(); - })); - } - catch { } - MessageBox.Show("Timeout trying to process url", Strings.url_out2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (consola_pre.ExitCode != 0) - { - try - { - frm_prog.Invoke(new MethodInvoker(delegate - { - frm_prog.Dispose(); - })); - } - catch { } - listBox4.TopIndex = listBox4.Items.Count - 1; - listBox4.Refresh(); - this.Cursor = Cursors.Arrow; - if (File.Exists(Path.Combine(destino_test, file_output))) - { - File.Delete(Path.Combine(destino_test, file_output)); - } - - if (Directory.GetFiles(destino_test).Length == 0) - { - Directory.Delete(destino_test); - } - if (frm_prog.abort_validate == false) - { - MessageBox.Show(Strings.ebc_fail_ff, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - else - { - this.Cursor = Cursors.Arrow; - - frm_prog.Invoke(new MethodInvoker(delegate - { - frm_prog.pic.Visible = false; - frm_prog.pic_ok.Visible = true; - frm_prog.pic_ok.Refresh(); - })); - Thread.Sleep(175); - try - { - frm_prog.Invoke(new MethodInvoker(delegate - { - frm_prog.Dispose(); - })); - } - catch { } - if (File.Exists(Path.Combine(destino_test, file_output))) - { - File.Delete(Path.Combine(destino_test, file_output)); - } - - if (Directory.GetFiles(destino_test).Length == 0) - { - Directory.Delete(destino_test); - } - } - } - else - { - this.Cursor = Cursors.Arrow; - try - { - if (File.Exists(Path.Combine(destino_test, file_output))) - { - File.Delete(Path.Combine(destino_test, file_output)); - } - - if (Directory.GetFiles(destino_test).Length == 0) - { - Directory.Delete(destino_test); - } - } - catch { } - } - //END try preset - } - - //Mixed youtubes - int has_lives = 0; - int has_no_lives = 0; - - foreach (DataGridViewRow row in dg1.Rows) - { - if (row.Cells[1].Value.ToString().ToLower().Contains("youtu.be") || row.Cells[1].Value.ToString().ToLower().Contains("youtube.com")) - { - if (row.Cells[3].Value.ToString() == "Live") has_lives++; - else has_no_lives++; - } - } - - if (has_no_lives > 0 && has_lives > 0) - { - MessageBox.Show(Strings.mix_urls2, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - //End mixed youtubes - - //Start pre-processing - cancel_queue = false; - Pg1.Value = 0; - //pg_current.Value = 0; - Disable_Controls(); - //textBox4.Text = "0%"; - - working = true; - m3u_single_running = true; - cancelados_paralelos = false; - aborted_url = false; - errors_enc = 0; - pic_no_errors.Visible = false; - pic_warnings.Visible = false; - pic_recording.Visible = false; - - //Disable Datagrid edition - foreach (DataGridViewRow row in dg1.Rows) - { - row.ReadOnly = true; - row.Cells[5].Value = Strings.ready; - row.Cells[5].Style.BackColor = Color.White; - } - - DataGridView list_proc = new DataGridView(); - foreach (DataGridViewColumn col in dg1.Columns) - { - list_proc.Columns.Add((DataGridViewColumn)col.Clone()); - } - - foreach (DataGridViewRow row in dg1.Rows) - { - list_proc.Rows.Add(row.Cells[0].Value, row.Cells[1].Value.ToString(), row.Cells[2].Value.ToString(), row.Cells[3].Value.ToString(), row.Cells[4].Value.ToString(), row.Cells[5].Value.ToString()); - } - - //Get total duration of files - - Pg1.Maximum = dg1.RowCount; - - Double total_prog = 0; - int i_dur = 0; - - Double row_duration = 0; - total_multi_duration = 0; - - foreach (DataGridViewRow row in dg1.Rows) - { - row.Cells[5].Value = Strings.ready; - - DateTime time2; - if (DateTime.TryParse(row.Cells[3].Value.ToString(), out time2)) - - { - total_duration = total_duration + TimeSpan.Parse(row.Cells[3].Value.ToString()).TotalSeconds; - total_multi_duration = total_multi_duration + TimeSpan.Parse(row.Cells[3].Value.ToString()).TotalSeconds; - } - else - { - //total_duration = total_duration + 0; - } - - i_dur = i_dur + 1; - } - - Pg1.Minimum = 0; - Pg1.Maximum = 100; - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - String remain_time = "0"; - //End get total duration of files - - List list_lines = new List(); - procs.Clear(); - - for (int ii = 0; ii < dg1.RowCount; ii++) - { - procs.Add("proc_urls_" + ii.ToString(), new Process()); - } - - time_n_tasks = 0; - timer_tasks.Start(); - timer_est_size.Start(); - - if (dg1.Rows[0].Cells[1].Value.ToString().ToLower().Contains("youtu.be") || dg1.Rows[0].Cells[1].Value.ToString().ToLower().Contains("youtube.com")) - { - timer2.Start(); - } - - String m3u_params = txt_m3u_params.Text; - - if (chk_m3u_params.CheckState == CheckState.Unchecked) m3u_params = ""; - String m3u_output_ext = combo_ext_m3u.SelectedItem.ToString(); - m3u_running = true; - String format_out = combo_ext_m3u.SelectedItem.ToString(); - String down_speed = ""; - String chapters = ""; - if (chk_yt_chapt.Checked) chapters = "--split-chapters"; - - if (chk_best_yt.Checked) bestv_a = "-f bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio"; - else bestv_a = String.Empty; - - if (chk_down_limit.Checked == true) down_speed = "-r " + Convert.ToInt32(n_down_speed.Value).ToString() + "M"; - String embed_subs = ""; - if (chk_yout_subs.Checked == true) embed_subs = "--embed-subs --all-subs"; - String auto_subs = ""; - if (chk_yout_subs.Checked == true) - { - embed_subs = "--embed-subs"; - if (chk_auto_subs.Checked == true) - { - auto_subs = "--write-auto-sub --sub-lang en,es,it,pt,de,hi,ar,cn"; - } - } - - String embed_meta = ""; - if (chk_embed_meta.Checked == true) embed_meta = "--add-metadata"; - String write_subs = ""; - if (chk_save_subtitles.Checked == true) embed_meta = "--write-sub"; - - String convert_subs = ""; - if (chk_convert_srt.Checked == true) embed_meta = "--convert-subs=srt"; - stopped_recording = false; - Timer_display.Enabled = true; - Boolean chapters_err = false; - - new System.Threading.Thread(() => - { - System.Threading.Thread.CurrentThread.IsBackground = true; - - Disable_Controls(); - Boolean quit = false; - - for (int list_index = 0; list_index < dg1.RowCount; list_index++) - { - System.Threading.Thread.Sleep(50); //Allow kill process to send cancel_queue - - String file = list_proc.Rows[list_index].Cells[1].Value.ToString(); - var tmp = procs["proc_urls_" + list_index.ToString()]; - - //cancel queue REVIEW - if (cancel_queue == true) - { - working = false; - m3u_running = false; - m3u_single_running = false; - timer2.Stop(); - timer_tasks.Stop(); - timer_est_size.Stop(); - cancelados_paralelos = false; - aborted_url = false; - Timer_display.Enabled = false; - release_datagrid(); - - this.InvokeEx(f => f.lbl_dw_speed.Text = ""); - Enable_Controls(); - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - - MessageBox.Show(Strings.queue_abort, Strings.task_abort, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - - return; - } - //End cancel queue - - //Skip current - if (skip_current_url == true) - { - skip_current_url = false; - - continue; - } - - //End skip current - - String url_capture_time = String.Empty; - DateTime time2; - if (DateTime.TryParse(list_proc.Rows[list_index].Cells[3].Value.ToString(), out time2)) - - { - if (TimeSpan.Parse(list_proc.Rows[list_index].Cells[3].Value.ToString()).TotalSeconds > 0) - { - row_duration = TimeSpan.Parse(list_proc.Rows[list_index].Cells[3].Value.ToString()).TotalSeconds; - url_capture_time = " -t " + row_duration.ToString(); - } - else - { - url_capture_time = String.Empty; - } - } - - String ffm = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - String fullPath = file; - String destino = txt_path_m3u.Text; - - if (chk_yt_chapt.Checked && chapters_err == false) - { - destino = "chapter:" + txt_path_m3u.Text + "\\" + dg1.Rows[list_index].Cells[4].Value.ToString() + "\\" + "%(section_number)s. %(section_title)s.%(ext)s"; - } - - String pre_input_var = ""; - if (txt_pre_input.Text != "") - { - pre_input_var = txt_pre_input.Text; - } - - String pre_ss = ""; - if (TimeSpan.Parse(ss_time_input.Text).TotalSeconds != 0) - { - pre_ss = " -ss " + ss_time_input.Text; - } - - add_suffix = ""; - - if (chk_suffix.Checked == true && txt_suffix.Text != String.Empty) - { - add_suffix = txt_suffix.Text; - } - - String ext_output1 = txt_format.Text; - if (txt_format.Text == String.Empty) - { - ext_output1 = Path.GetExtension(file); - } - else - { - ext_output1 = "." + txt_format.Text; - } - - String AppParam = String.Empty; - - chk_m3u_params.Invoke(new MethodInvoker(delegate - { - if (file.ToLower().Contains("m3u") && chk_m3u_params.Checked == false) m3u_params = " -bsf:a aac_adtstoasc -c copy " + m3u_params; - })); - - if (chk_output_server.CheckState == CheckState.Checked) - { - AppParam = pre_input_var + " " + pre_ss + " -i " + "" + file + " -y " + m3u_params + url_capture_time + " " + output_server; - } - else - { - AppParam = pre_input_var + " " + pre_ss + " -i " + "" + file + " -y " + m3u_params + url_capture_time + " " + '\u0022' + Path.Combine(destino, list_proc.Rows[list_index].Cells[4].Value.ToString() + "." + m3u_output_ext); - } - - if (!Directory.Exists(destino)) - { - if (chk_yt_chapt.Checked == false) - { - try - { - Directory.CreateDirectory(destino); - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.err_write_out + " " + excpt.Message, Strings.write_error2, MessageBoxButtons.OK, MessageBoxIcon.Error); - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - Enable_Controls(); - this.InvokeEx(f => f.Timer_display.Enabled = false); - return; - } - } - else - { - try - { - Directory.CreateDirectory(txt_path_m3u.Text); - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.err_write_out + " " + excpt.Message, Strings.write_error2, MessageBoxButtons.OK, MessageBoxIcon.Error); - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - Enable_Controls(); - this.InvokeEx(f => f.Timer_display.Enabled = false); - return; - } - } - } - - if (file_prueba.ToLower().Contains("youtu.be") || file_prueba.ToLower().Contains("youtube.com") || !file_prueba.ToLower().Contains("m3u")) - { - tmp.StartInfo.FileName = Path.Combine(Application.StartupPath, "yt-dlp.exe"); - tmp.StartInfo.WorkingDirectory = Application.StartupPath; - if (m3u_params.Contains("-f ")) - { - tmp.StartInfo.Arguments = bestv_a + " " + Clear_cache + " " + m3u_params + " " + down_speed + " " + embed_subs + " " + auto_subs + " " + embed_meta + " " + write_subs + " " + convert_subs + " -o " + '\u0022' + destino + "\\" + dg1.Rows[list_index].Cells[4].Value.ToString() + "." + format_out + '\u0022' + " " + file; - if (chk_yt_chapt.Checked && chapters_err == false) - { - tmp.StartInfo.Arguments = bestv_a + " " + Clear_cache + " " + m3u_params + " " + down_speed + " " + embed_subs + " " + auto_subs + " " + embed_meta + " " + write_subs + " " + convert_subs + " -P " + txt_path_m3u.Text + " " + chapters + " -o " + '\u0022' + destino + '\u0022' + " " + file; - tmp.StartInfo.WorkingDirectory = txt_path_m3u.Text; - } - } - else - { - if (bestv_a.Length == 0) - { - tmp.StartInfo.Arguments = Clear_cache + " -f " + format_out + " " + m3u_params + " " + down_speed + " " + embed_subs + " " + auto_subs + " " + embed_meta + " -o " + '\u0022' + destino + "\\" + dg1.Rows[list_index].Cells[4].Value.ToString() + "." + format_out + '\u0022' + " " + file; - if (chk_yt_chapt.Checked && chapters_err == false) - { - tmp.StartInfo.Arguments = Clear_cache + " -f " + format_out + " " + m3u_params + " " + down_speed + " " + embed_subs + " " + auto_subs + " " + embed_meta + " -P " + txt_path_m3u.Text + " " + chapters + " -o " + '\u0022' + destino + '\u0022' + " " + file; - tmp.StartInfo.WorkingDirectory = txt_path_m3u.Text; - } - } - else - { - tmp.StartInfo.Arguments = bestv_a + " " + Clear_cache + " " + m3u_params + " " + down_speed + " " + embed_subs + " " + auto_subs + " " + embed_meta + " -o " + '\u0022' + destino + "\\" + dg1.Rows[list_index].Cells[4].Value.ToString() + "." + format_out + '\u0022' + " " + file; - if (chk_yt_chapt.Checked && chapters_err == false) - { - tmp.StartInfo.Arguments = bestv_a + " " + Clear_cache + " " + m3u_params + " " + down_speed + " " + embed_subs + " " + auto_subs + " " + embed_meta + " -P " + txt_path_m3u.Text + " " + chapters + " -o " + '\u0022' + destino + '\u0022' + " " + file; - tmp.StartInfo.WorkingDirectory = txt_path_m3u.Text; - } - } - } - this.InvokeEx(f => f.Pg1.Maximum = 100 * dg1.Rows.Count); - - } - else - { - tmp.StartInfo.FileName = ffm; - tmp.StartInfo.Arguments = AppParam; - } - - if (dg1.Rows[list_index].Cells[3].Value.ToString() == "Live") - { - this.InvokeEx(f => f.dg1.Rows[list_index].Cells[5].Value = Strings.recording1); - try - { - File.Delete(destino + "\\" + dg1.Rows[list_index].Cells[4].Value.ToString() + "." + format_out); - } - catch { } - } - else this.InvokeEx(f => f.dg1.Rows[list_index].Cells[5].Value = Strings.processing); - - if (!File.Exists(Path.Combine(Application.StartupPath, "yt-dlp.exe"))) - { - quit = true; - cancel_queue = true; - working = false; - m3u_running = false; - m3u_single_running = false; - timer2.Stop(); - timer_tasks.Stop(); - timer_est_size.Stop(); - cancelados_paralelos = false; - aborted_url = false; - release_datagrid(); - this.InvokeEx(f => f.Timer_display.Enabled = false); - this.InvokeEx(f => f.lbl_dw_speed.Text = ""); - Enable_Controls(); - - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - MessageBox.Show(Strings.yt_not, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (dg1.Rows[list_index].Cells[3].Value.ToString() == "Live") - { - tmp.StartInfo.RedirectStandardOutput = false; - tmp.StartInfo.RedirectStandardError = false; - this.Invoke(new MethodInvoker(delegate - { - pic_recording.Visible = true; - Pg1.Style = ProgressBarStyle.Marquee; - Pg1.MarqueeAnimationSpeed = 50; - })); - } - else - { - - tmp.StartInfo.RedirectStandardOutput = true; - tmp.StartInfo.RedirectStandardError = true; - tmp.StartInfo.StandardOutputEncoding = Encoding.UTF8; - tmp.StartInfo.StandardErrorEncoding = Encoding.UTF8; - tmp.EnableRaisingEvents = true; - this.InvokeEx(f => f.Pg1.Style = ProgressBarStyle.Continuous); - this.InvokeEx(f => f.pic_recording.Visible = false); - } - - tmp.StartInfo.CreateNoWindow = true; - tmp.StartInfo.UseShellExecute = false; - tmp.StartInfo.RedirectStandardInput = true; - chapters_err = false; - if (quit == false) tmp.Start(); - - combo_prio.Invoke(new MethodInvoker(delegate - { - if (combo_prio.SelectedIndex != 2) - { - Change_mem_prio(); - } - })); - - this.InvokeEx(f => validate_duration = dg1.Rows[list_index].Cells[3].Value.ToString()); - - DateTime time3; - if (DateTime.TryParse(list_proc.Rows[list_index].Cells[3].Value.ToString(), out time3)) - { - if (TimeSpan.Parse(list_proc.Rows[list_index].Cells[3].Value.ToString()).TotalSeconds != 0) - { - valid_prog = true; - } - } - else - { - valid_prog = false; - } - - String err_txt = ""; - String tr_speed = ""; - Double interval = 0; - Decimal est_bitrate = 0; - Decimal est_size = 0; - Double sec_prog = 0; - - if (!file.ToLower().Contains("youtu.be") && !file.ToLower().Contains("youtube.com")) - { - while (!tmp.StandardError.EndOfStream) - { - err_txt = tmp.StandardError.ReadLine(); - list_lines.Add(err_txt); - - if (err_txt.Contains("time=") && err_txt.Contains("time=-") == false) - { - if (valid_prog == true) - { - this.InvokeEx(f => durat_n = row_duration); - int start_time_index = err_txt.IndexOf("time=") + 5; - sec_prog = TimeSpan.Parse(err_txt.Substring(start_time_index, 8)).TotalSeconds; - Double percent = (sec_prog * 100 / durat_n); - - total_prog = total_prog + (sec_prog - interval); - interval = sec_prog; - int percent2 = Convert.ToInt32(percent); - - Double percent_tot = (total_prog * 100 / total_duration); - int percent_tot_2 = Convert.ToInt32(percent_tot); - - if (percent_tot_2 <= 100) - { - this.InvokeEx(f => f.Pg1.Value = percent_tot_2); - this.InvokeEx(f => f.Pg1.Refresh()); - if (Math.Round(percent_tot, 1).ToString().Contains(".") || Math.Round(percent_tot, 1).ToString().Contains(",")) - { - this.InvokeEx(f => f.Pg1.Text = Math.Round(percent_tot, 1).ToString() + "%"); - } - else - { - this.InvokeEx(f => f.Pg1.Text = Math.Round(percent_tot, 1).ToString() + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0" + "%"); - } - this.InvokeEx(f => TaskbarProgress.SetValue(this.Handle, percent_tot, Pg1.Maximum)); - } - if (percent2 <= 100) - { - //this.InvokeEx(f => pg_lv.Value = Convert.ToInt16(percent2)); - if (Math.Round(percent, 1).ToString().Contains(".") || Math.Round(percent, 1).ToString().Contains(",")) - { - this.InvokeEx(f => f.dg1.Rows[list_index].Cells[5].Value = Math.Round(percent, 1).ToString() + "%"); - // this.InvokeEx(f => pg_lv.Text = Math.Round(percent, 1).ToString() + "%"); - // this.InvokeEx(f => pg_lv.Refresh()); - } - //this.InvokeEx(f => pg_lv.Refresh()); - } - - //Estimated remaining time - try - { - remain_time = err_txt.Substring(err_txt.LastIndexOf("speed=") + 6, err_txt.Length - err_txt.LastIndexOf("speed=") - 6); - remain_time = remain_time.Replace("x", String.Empty); - Double timing1 = 0; - - if (System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",") - { - timing1 = Math.Round(Double.Parse(remain_time.Replace(".", ",")), 2); - } - else - { - timing1 = Math.Round(Double.Parse(remain_time), 2); - } - - Decimal timing = (decimal)timing1; - Decimal total_dur_dec = Convert.ToDecimal(total_duration); - Decimal total_prog_dec = Convert.ToDecimal(total_prog); - Decimal remain_secs = 0; - if (timing > 0) - { - remain_secs = (decimal)(total_dur_dec - total_prog_dec) / timing; - } - - if (remain_secs > 60) - { - remain_secs = remain_secs + 60; - } - - String remain_from_secs = ""; - - TimeSpan t = TimeSpan.FromSeconds(Convert.ToDouble(remain_secs)); - remain_from_secs = string.Format("{0:D2}h:{1:D2}", - t.Hours, - t.Minutes); - - if (remain_secs >= 43200) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + Math.Round(remain_secs / 3600).ToString() + " " + Strings.hours); - } - - if (remain_secs >= 3600 && remain_secs < 43200) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + remain_from_secs + " " + Strings.minutes_abrev); - } - - if (remain_secs < 3600 && remain_secs >= 600) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 1, 2) + " " + Strings.minutes); - } - if (remain_secs < 600 && remain_secs >= 120) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 2, 1) + " " + Strings.minutes); - } - - if (remain_secs <= 59) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + Convert.ToInt16(remain_secs) + " " + Strings.seconds); - } - } - catch { } - - //End remaining time - } - } - - //Estimated size and bitrate - - String read_size = String.Empty; - if (err_txt.Contains("size=") && (time_est_size % 3 == 0)) - { - int size_index = err_txt.IndexOf("size=") + 5; - read_size = err_txt.Substring(size_index, 8); - try - { - est_bitrate = Math.Round(Convert.ToDecimal(read_size) * 8 / Convert.ToDecimal(sec_prog), 0); - - if (Convert.ToDecimal(read_size) > 1 && time_n_tasks > 1) - { - if (est_bitrate < 9999) - { - this.InvokeEx(f => f.lbl_bitrate.Text = Strings.avg_bit + ": " + est_bitrate + " " + "Kb/s"); - } - else - { - this.InvokeEx(f => f.lbl_bitrate.Text = Strings.avg_bit + ": " + (Math.Round(est_bitrate / 1000, 0)) + " " + "Mb/s"); - } - //Estimated size - est_size = Convert.ToDecimal(durat_n) * est_bitrate / 8; - - if (est_size > 1000000) - { - this.InvokeEx(f => f.lbl_est_size.Text = Strings.est_size + " " + (Math.Round(est_size / 1000000, 1)).ToString() + " " + "GB"); - } - else - { - this.InvokeEx(f => f.lbl_est_size.Text = Strings.est_size + " " + (Math.Round(est_size / 1000, 0)).ToString() + " " + "MB"); - } - } - } - catch { } - - this.InvokeEx(f => f.lbl_est_size.Refresh()); - } - - //Read output, get progress - this.InvokeEx(f => f.listBox4.Items.Add(err_txt)); - this.InvokeEx(f => f.listBox4.TopIndex = listBox4.Items.Count - 1); - } - } - else - { - if (dg1.Rows[list_index].Cells[3].Value.ToString() != "Live") - { - while (!tmp.StandardOutput.EndOfStream) - { - err_txt = tmp.StandardOutput.ReadLine(); - list_lines.Add(err_txt); - if (err_txt.ToLower().Contains(err_chaps)) chapters_err = true; - if (err_txt.Contains("%")) - { - try - { - Double prog_y = Double.Parse(err_txt.Substring(err_txt.IndexOf("%") - 4, 4)); - prog_y = prog_y / 10; - int progress = Convert.ToInt32(prog_y); - this.InvokeEx(f => dg1.Rows[list_index].Cells[5].Value = progress.ToString() + "%"); - } - catch { } - } - - if (display_eta == true) - { - String size1 = ""; - if (err_txt.ToLower().Contains("of") && err_txt.ToLower().Contains("at") && !err_txt.Contains("Destination:") && !err_txt.Contains("[Merger]:")) - { - int ind_tr1 = err_txt.ToLower().IndexOf("of ") + 3; - int ind_tr_e1 = err_txt.ToLower().IndexOf("at"); - int leng1 = ind_tr_e1 - ind_tr1; - try { size1 = Strings.f_size + ": " + err_txt.Substring(ind_tr1, leng1).Replace("~", "").Trim(' ').Replace("GiB", " GB").Replace("MiB", " MB"); } catch { } - } - - String tr_r = ""; - if (err_txt.ToLower().Contains("mib/s")) - { - int ind_tr = err_txt.ToLower().IndexOf("at ") + 3; - int ind_tr_e = err_txt.ToLower().IndexOf("mib/s"); - int leng = ind_tr_e - ind_tr; - tr_r = err_txt.Substring(ind_tr, leng); - tr_speed = Strings.transfer_r + " " + tr_r.Trim(' ') + " MB/s"; - } - if (err_txt.ToLower().Contains("kib/s")) - { - int ind_tr = err_txt.ToLower().IndexOf("at ") + 3; - int ind_tr_e = err_txt.ToLower().IndexOf("kib/s"); - int leng = ind_tr_e - ind_tr; - tr_r = err_txt.Substring(ind_tr, leng); - tr_speed = Strings.transfer_r + " " + tr_r.Trim(' ') + " KB/s"; - } - if (tr_speed.Length > 0 )this.InvokeEx(f => f.lbl_dw_speed.Text = size1 + " -- " + tr_speed); - } - - this.InvokeEx(f => f.listBox4.Items.Add(err_txt)); - this.InvokeEx(f => f.listBox4.TopIndex = listBox4.Items.Count - 1); - } - } - else - { - this.InvokeEx(f => f.Pg1.Text = Strings.recording1); - this.InvokeEx(f => f.Pg1.Refresh()); - } - } - - List er = new List(); - String msg_er = String.Empty; - - if (dg1.Rows[list_index].Cells[3].Value.ToString() != "Live") - { - while (!tmp.StandardError.EndOfStream) - { - er.Add(tmp.StandardError.ReadLine().Replace("yt-dlp.exe:", "")); - } - } - - if (er.Count > 0) - { - foreach (String st in er) - { - if (st.ToLower().Contains("usage: youtube-dl") == false) - { - msg_er = msg_er + st; - } - } - } - if (list_index == 0 && msg_er != String.Empty) - { - this.InvokeEx(f => f.pic_recording.Visible = false); - if (msg_er.ToLower().Contains("warning")) MessageBox.Show(msg_er, Strings.warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); - else - { - if (!msg_er.Contains("ERROR: Interrupted by user")) MessageBox.Show(msg_er, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - quit = true; - working = false; - m3u_running = false; - m3u_single_running = false; - timer2.Stop(); - timer_tasks.Stop(); - timer_est_size.Stop(); - cancelados_paralelos = false; - aborted_url = false; - release_datagrid(); - Enable_Controls(); - this.Invoke(new MethodInvoker(delegate - { - Timer_display.Enabled = false; - lbl_dw_speed.Text = ""; - Pg1.Style = ProgressBarStyle.Continuous; - pic_recording.Visible = false; - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - })); - - - if (msg_er.Contains("ERROR: Interrupted by user")) - { - foreach (String f in Directory.GetFiles(txt_path_m3u.Text, "*.*", System.IO.SearchOption.AllDirectories)) - { - if ((Path.GetExtension(f) == ".part" || Path.GetExtension(f) == ".ytdl") && f.Contains(dg1.Rows[list_index].Cells[4].Value.ToString())) - { - try - { - File.Delete(f); - } - catch { } - } - } - } - return; - } - } - tmp.WaitForExit(); - tmp.StartInfo.Arguments = String.Empty; - - timer_est_size.Stop(); - time_est_size = 0; - - this.InvokeEx(f => f.lbl_est_size.Text = String.Empty); - this.InvokeEx(f => f.lbl_bitrate.Text = String.Empty); - - if (chk_yt_chapt.Checked && chapters_err == true) list_lines.Add(Strings.err_chap); - list_lines.Add(""); - list_lines.Add("---------End of " + Path.GetFileName(file) + " log---------"); - list_lines.Add(""); - - if (tmp.ExitCode == 0) - - { - if (skipped == false && aborted_url == false) - { - this.InvokeEx(f => f.dg1.Rows[list_index].Cells[5].Value = Strings.success); - if (chk_yt_chapt.Checked && chapters_err == true) - { - this.InvokeEx(f => f.dg1.Rows[list_index].Cells[5].Value = Strings.error); - - list_index--; - } - else chapters_err = false; - } - else - { - this.InvokeEx(f => f.dg1.Rows[list_index].Cells[5].Value = Strings.skipped); - total_prog = total_prog + durat_n - sec_prog; - skipped = false; - } - if (aborted_url == true) - { - this.InvokeEx(f => f.dg1.Rows[list_index].Cells[5].Value = Strings.aborted); - aborted_url = false; - } - if (stopped_recording == true) - { - this.InvokeEx(f => f.dg1.Rows[list_index].Cells[5].Value = "Stopped"); - this.InvokeEx(f => f.dg1.Rows[list_index].Cells[5].Style.BackColor = Color.White); - } - } - else - { - if (skipped == true) - { - this.InvokeEx(f => f.dg1.Rows[list_index].Cells[5].Value = Strings.skipped); - total_prog = total_prog + durat_n - sec_prog; - skipped = false; - } - else - { - this.InvokeEx(f => f.dg1.Rows[list_index].Cells[5].Value = Strings.failed); - errors_enc = errors_enc + 1; - } - } - - if (list_index + 1 == list_proc.RowCount - 1 || quit == true) - { - timer2.Stop(); - this.Invoke(new MethodInvoker(delegate - { - Pg1.Style = ProgressBarStyle.Continuous; - pic_recording.Visible = false; - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - Pg1.Value = Pg1.Maximum; - Pg1.Text = "100%"; - lbl_dw_speed.Text = ""; - Timer_display.Enabled = false; - })); - - m3u_single_running = false; - working = false; - m3u_running = false; - cancelados_paralelos = false; - release_datagrid(); - //Save log - if (no_save_logs == false) - { - string[] array_err = list_lines.ToArray(); - - String path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.log"; - if (is_portable == true) path = port_path + "ff_batch_portable.log"; - - StreamWriter SaveFile = new StreamWriter(path); - SaveFile.WriteLine("Batch log sesion: " + System.DateTime.Now); - SaveFile.WriteLine("-----------------------"); - foreach (String item in array_err) - { - SaveFile.WriteLine(item); - } - if (er.Count > 0) SaveFile.WriteLine(msg_er); - SaveFile.Close(); - - File.AppendAllText(path, "-----------------------"); - File.AppendAllText(path, Environment.NewLine + Strings.end_log); - FileInfo fileInfo = new FileInfo(path); - - var bytes = fileInfo.Length; - - var kilobytes = (double)bytes / 1024; - var megabytes = kilobytes / 1024; - var gigabytes = megabytes / 1024; - - //Format size view - String size = ""; - String separator = "."; - - if (bytes > 1000000000) - { - if (gigabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String gigas = gigabytes.ToString(); - if (gigas.Length >= 5) - { - gigas = gigas.Substring(0, gigas.LastIndexOf(separator) + 3); - size = (gigas + " " + "GB"); - } - else - { - size = (gigas + " " + "GB"); - } - } - - if (bytes >= 1048576 && bytes <= 1000000000) - { - if (megabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - String megas = megabytes.ToString(); - if (megas.Length > 5) - { - megas = megas.Substring(0, megas.LastIndexOf(separator)); - size = (megas + " " + "MB"); - } - else - { - size = (megas + " " + "MB"); - } - } - - if (bytes >= 1024 && bytes < 1048576) - - { - if (kilobytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String kbs = kilobytes.ToString(); - if (kbs.Length >= 5) - { - kbs = kbs.Substring(0, kbs.LastIndexOf(separator)); - size = (kbs + " " + "KB"); - } - else - { - size = (kbs + " " + "KB"); - } - } - if (bytes > -1 && bytes < 1024) - { - String bits = bytes.ToString(); - size = (bits + " Bytes"); - } - - //End Format size view - File.AppendAllText(path, Environment.NewLine + Strings.log_size + " " + size); - - //End save log - } - this.Invoke(new MethodInvoker(delegate - { - toolT002.RemoveAll(); - if (errors_enc == 0) pic_no_errors.Visible = true; - else - { - pic_no_errors.Visible = false; - pic_recording.Visible = false; - toolT002.SetToolTip(this.pic_warnings, Strings.there_w + " " + errors_enc.ToString() + " " + Strings.errors_se); - pic_warnings.Visible = true; - } - })); - - //Automatic shutdown check - if (chkshut.Checked && cancel_queue == false) - { - auto_shut(); - return; - } - //End shutdown check - else - { - if (cancel_queue == false) - { - if (play_on_end == true && er.Count == 0) play_end(); - - if (er.Count > 0) - { - String warnings = ""; - foreach (String st in er) warnings = warnings + st; - MessageBox.Show(Strings.warn_down + " " + Environment.NewLine + Environment.NewLine + warnings + Environment.NewLine + Environment.NewLine + Strings.check_log, Strings.warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - else - { - if (dg1.RowCount == 1 && chk_yt_chapt.Checked == false) - { - String cur_out = destino + "\\" + dg1.Rows[list_index].Cells[4].Value.ToString() + "." + format_out; - System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentUICulture; - String sep_th = ci.NumberFormat.CurrencyGroupSeparator; - String unit = ""; - String dur = ""; - this.Invoke(new MethodInvoker(delegate - { - lbl_est_size.Text = String.Empty; - lbl_bitrate.Text = String.Empty; - Process probe = new Process(); - - List lines_ouput = new List(); - probe.StartInfo.FileName = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - String ffprobe_frames = " " + "--Output=General;%OverallBitRate/String%" + "\\n" + "%FileSize/String3%" + "\\n" + "%Duration/String3%"; - probe.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + cur_out + '\u0022'; - probe.StartInfo.RedirectStandardOutput = true; - probe.StartInfo.UseShellExecute = false; - probe.StartInfo.CreateNoWindow = true; - probe.EnableRaisingEvents = true; - probe.Start(); - - while (!probe.StandardOutput.EndOfStream) - { - lines_ouput.Add(probe.StandardOutput.ReadLine()); - } - probe.WaitForExit(); - - if (lines_ouput[0] != null && lines_ouput[0].Length > 0) - { - if (lines_ouput[0].ToLower().Contains(" kb/s")) unit = "Kb/s"; - if (lines_ouput[0].ToLower().Contains(" mb/s")) unit = "Mb/s"; - if (lines_ouput[0].ToLower().Contains(" gb/s")) unit = "Gb/s"; - lines_ouput[0] = lines_ouput[0].Replace(" kb/s", "").Replace(" Mb/s", "").Replace(" Gb/s", ""); - lines_ouput[0] = lines_ouput[0].Replace(" ", sep_th); - lbl_bitrate.Text = Strings.bitrate + ":" + " " + lines_ouput[0] + " " + unit; - } - if (lines_ouput[1] != null && lines_ouput[1].Length > 0) lbl_est_size.Text = Strings.f_size + ":" + " " + lines_ouput[1].Replace("MiB", "MB").Replace("GiB", "GB").Replace("KiB", "KB"); - if (lines_ouput[2] != null && lines_ouput[2].Length > 0) dur = lines_ouput[2]; - })); - - if (no_output_pop == false) - { - Form26 frm26 = new Form26(); - frm26.out_file = cur_out; - frm26.dur_file = dur; - if (Settings.Default.dark_mode == false) frm26.pic_img = pic_reading.Image; - else frm26.pic_img = pic_reading.InitialImage; - frm26.tot_bit = lbl_bitrate.Text; - frm26.out_size = lbl_est_size.Text; - this.Invoke(new MethodInvoker(delegate - { - frm26.Show(this); - if (frm26.no_pop == true) no_output_pop = true; - })); - } - } - - //End output single info - } - - if (Form.ActiveForm == null) - { - notifyIcon1.BalloonTipText = Strings.url_down_c; - notifyIcon1.BalloonTipIcon = ToolTipIcon.Info; - notifyIcon1.BalloonTipTitle = Strings.url_down_c2; - notifyIcon1.ShowBalloonTip(0); - } - - if (chk_open_compl.Checked) - { - if (Directory.GetFiles(destino).Length != 0) - { - Process open_processed = new Process(); - open_processed.StartInfo.FileName = "explorer.exe"; - open_processed.StartInfo.Arguments = '\u0022' + destino + '\u0022'; - open_processed.Start(); - } - else - { - if (Directory.Exists(destino_test)) - { - try - { - Directory.Delete(destino_test); - } - catch { } - } - } - } - } - else - { - m3u_single_running = false; - cancelados_paralelos = false; - this.Invoke(new MethodInvoker(delegate - { - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - Pg1.Value = Pg1.Maximum; - Pg1.Text = "100%"; - lbl_dw_speed.Text = ""; - })); - - - if (quit == false && stopped_recording == false) - { - this.InvokeEx(f => MessageBox.Show(Strings.queue_abort, Strings.aborted, MessageBoxButtons.OK, MessageBoxIcon.Error)); - - foreach (String f in Directory.GetFiles(txt_path_m3u.Text, "*.*", System.IO.SearchOption.AllDirectories)) - { - if ((Path.GetExtension(f) == ".part" || Path.GetExtension(f) == ".ytdl") && f.Contains(dg1.Rows[list_index].Cells[4].Value.ToString())) - { - try - { - File.Delete(f); - } - catch { } - } - } - - } - //if (stopped_recording == true) this.InvokeEx(f => MessageBox.Show(Strings.queue_abort, "Stopped", MessageBoxButtons.OK, MessageBoxIcon.Error)); - } - } - } - } - - Enable_Controls(); - }).Start(); - } - - private void dg1_KeyUp(object sender, KeyEventArgs e) - { - if (m3u_running == true || m3u_single_running == true) return; - - if (e.KeyCode == Keys.Delete) - { - foreach (DataGridViewCell cell in dg1.SelectedCells) - { - try - { - if (dg1.Rows[cell.RowIndex].Cells[0].Selected == true || dg1.Rows[cell.RowIndex].Cells[1].Selected == true) - { - foreach (DataGridViewCell cell2 in dg1.Rows[cell.RowIndex].Cells) - { - cell2.Selected = false; - } - - dg1.Rows.RemoveAt(cell.RowIndex); - } - } - catch (Exception ex) - { - //MessageBox.Show("Item could not be removed. " + Environment.NewLine + Environment.NewLine + ex.Message); - } - } - } - } - - private void btn_validate_url_Click_1(object sender, EventArgs e) - { - if (dg1.Rows.Count == 0) return; - check_internet(); - if (internet_up == false) return; - Boolean all_ready = true; - - foreach (DataGridViewRow row in dg1.Rows) - { - if (row.Cells[5].Value.ToString() == Strings.ready == false && row.Cells[5].Value.ToString() == Strings.success == false) - { - row.Cells[0].Value = pic_noimg.Image; - row.Cells[5].Value = ""; - row.Cells[5].Style.BackColor = row.DefaultCellStyle.BackColor; - } - } - dg1.Refresh(); - - cell_zoom(); - - dg1.Refresh(); - stop_validating_url = false; - - foreach (DataGridViewRow row in dg1.Rows) - { - row.ReadOnly = true; - } - - foreach (Control ct in groupBox_m3u.Controls) - { - ct.Enabled = false; - } - - btn_cancel_validate.Enabled = true; - - if (dg1.Rows[0].Cells[1].Value.ToString().ToLower().Contains("youtu.be") || dg1.Rows[0].Cells[1].Value.ToString().ToLower().Contains("youtube.com")) - { - BG_Validate_URLs_YT.RunWorkerAsync(); - } - else - { - opening_youtubes = false; - BG_Validate_URLs.RunWorkerAsync(); - } - } - - private void combo_ext_m3u_SelectedIndexChanged(object sender, EventArgs e) - { - if (dg1.Rows.Count == 0) - { - if (combo_ext_m3u.SelectedIndex == 0) - { - txt_m3u_params.Text = "-bsf:a aac_adtstoasc -c copy"; - } - - if (combo_ext_m3u.SelectedIndex == 1) - { - txt_m3u_params.Text = "-fflags +genpts"; - } - } - else - { - if (dg1.Rows[0].Cells[1].Value.ToString().ToLower().Contains("youtu.be") && !dg1.Rows[0].Cells[1].Value.ToString().ToLower().Contains("youtube.com")) - { - if (combo_ext_m3u.SelectedIndex == 0) - { - txt_m3u_params.Text = "-bsf:a aac_adtstoasc -c copy"; - } - - if (combo_ext_m3u.SelectedIndex == 1) - { - txt_m3u_params.Text = "-fflags +genpts"; - } - } - } - } - - private void btn_stop_m3u8_Click(object sender, EventArgs e) - { - if (dg1.SelectedCells.Count != 1) return; - String type = ""; - - if (working == true && m3u_single_running == true) - { - Process[] localByName = Process.GetProcessesByName("yt-dlp"); - foreach (Process p in localByName) - { - try - { - if (p.Id == procs["proc_urls_" + dg1.Rows[dg1.SelectedCells[0].RowIndex].Index.ToString()].Id) - { - foreach (Process pr in p.GetChildProcesses()) - { - pr.Kill(); - } - p.Kill(); - } - } catch { } - } - Process[] localByName2 = Process.GetProcessesByName("ffmpeg"); - foreach (Process p in localByName2) - { - if (p.Id == procs["proc_urls_" + dg1.Rows[dg1.SelectedCells[0].RowIndex].Index.ToString()].Id) - { - foreach (Process pr in p.GetChildProcesses()) - { - pr.Kill(); - } - p.Kill(); - } - } - skipped = true; - } - } - - private void btn_cancel_validate_Click(object sender, EventArgs e) - { - stop_validating_url = true; - if (checking_url_m3u == true) - { - try - { - foreach (Process proc in procs.Values) proc.Kill(); - } - - catch { } - return; - } - System.Threading.Thread.Sleep(100); - Process[] localByName0 = Process.GetProcessesByName("yt-dlp"); - foreach (Process p0 in localByName0) - { - p0.Kill(); - } - System.Threading.Thread.Sleep(100); - - Process[] localByName22 = Process.GetProcessesByName("yt-dlp"); - foreach (Process p3 in localByName22) - { - p3.Kill(); - } - } - - private void chk_output_server_CheckedChanged(object sender, EventArgs e) - { - if (chk_output_server.CheckState == CheckState.Checked) - { - txt_output_server.Enabled = true; - txt_path_m3u.Enabled = false; - btn_browse_path_m3u.Enabled = false; - } - else - { - txt_output_server.Enabled = false; - txt_path_m3u.Enabled = true; - btn_browse_path_m3u.Enabled = true; - } - } - - private void ctm_m3u_Opening(object sender, CancelEventArgs e) - { - if (Settings.Default.dark_mode == true) - { - ctm_m3u.BackColor = Color.FromArgb(255, 64, 64, 64); - ctm_m3u.ForeColor = Color.White; - } - else - { - ctm_m3u.BackColor = SystemColors.InactiveBorder; - ctm_m3u.ForeColor = Control.DefaultForeColor; - } - - if (Clipboard.ContainsText() == false) - { - ct_paste_m3u.Enabled = false; - ct_paste_youtube.Enabled = false; - } - - if (Clipboard.GetText().ToLower().Contains("youtu.be") == true || Clipboard.GetText().ToLower().Contains("youtube.com") == true) - { - ct_paste_youtube.Enabled = true; - ct_paste_m3u.Enabled = false; - } - else - { - ct_paste_youtube.Enabled = false; - if (Clipboard.GetText().ToLower().Contains("http") == true) - { - if (Clipboard.GetText().ToLower().Contains("m3u") == true) - { - ct_paste_m3u.Text = Strings.Paste_M3u_URL; - } - else - { - ct_paste_m3u.Text = Strings.Paste_any_URL; - } - ct_paste_m3u.Enabled = true; - } - else - { - ct_paste_m3u.Enabled = false; - } - } - - if (dg1.RowCount == 0) - { - ct_del_m3u.Enabled = false; - ct_validate_url.Enabled = false; - ct_remove_url.Enabled = false; - ct_ren_urls.Enabled = false; - } - else - { - ct_del_m3u.Enabled = true; - ct_validate_url.Enabled = true; - ct_ren_urls.Enabled = true; - } - if (dg1.SelectedCells.Count > 0) - { - ct_play_vlc.Enabled = true; - ct_show_urls.Enabled = true; - ct_remove_url.Enabled = true; - ct3_ready.Enabled = true; - } - else - { - ct_show_urls.Enabled = false; - ct_play_vlc.Enabled = false; - ct_remove_url.Enabled = false; - ct3_ready.Enabled = false; - } - - if (m3u_running == true) - { - ct_paste_m3u.Enabled = false; - ct_paste_youtube.Enabled = false; - ct_del_m3u.Enabled = false; - ct_validate_url.Enabled = false; - ct_show_urls.Enabled = false; - ct_play_vlc.Enabled = false; - ctm_stop_url.Enabled = false; - ct_remove_url.Enabled = false; - - if (dg1.SelectedCells.Count == 1 && dg1.Rows[dg1.SelectedCells[0].RowIndex].Cells[5].Value.ToString() != Strings.ready && dg1.Rows[dg1.SelectedCells[0].RowIndex].Cells[5].Value.ToString() != Strings.success && dg1.Rows[dg1.SelectedCells[0].RowIndex].Cells[5].Value.ToString() != Strings.failed) - { - ctm_stop_url.Enabled = true; - ctm_stop_url.Text = Strings.stop_capt + " " + '\u0022' + dg1.Rows[dg1.SelectedCells[0].RowIndex].Cells[4].Value.ToString() + '\u0022'; - } - } - } - - private void ct_play_vlc_Click(object sender, EventArgs e) - { - if (dg1.SelectedCells.Count > 0) - { - try - { - Process vlc_proc = new Process(); - vlc_proc.StartInfo.FileName = "vlc.exe"; - vlc_proc.StartInfo.Arguments = dg1.Rows[dg1.SelectedCells[0].RowIndex].Cells[1].Value.ToString(); - vlc_proc.Start(); - } - catch (System.Exception exctp) - { - MessageBox.Show(Strings.err_pl_vlc + " " + exctp.Message, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - } - } - } - - private void dg1_DragEnter(object sender, DragEventArgs e) - { - if (e.Data.GetDataPresent(DataFormats.FileDrop, false)) - e.Effect = DragDropEffects.All; - else - e.Effect = DragDropEffects.None; - } - - private void dg1_DragDrop(object sender, DragEventArgs e) - { - string[] file_drop = (string[])e.Data.GetData(DataFormats.FileDrop); - if (file_drop.Count() > 1) - { - MessageBox.Show(Strings.multi_drop, Strings.multi_drop2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; - } - - long length = new FileInfo(file_drop[0]).Length; - - if (length > 1048576) - { - MessageBox.Show(Strings.drop_big, Strings.file_big, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - dg1.Rows.Clear(); - stop_validating_url = false; - - String[] lines = File.ReadAllLines(file_drop[0]); - - for (int i = 0; i < lines.Count(); i++) - { - String out_file = String.Empty; - - if (lines[i].ToString().Length > 4 && lines[i].Substring(0, 4).ToLower() == "http") - { - if (i > 0) - { - if (lines[i - 1].ToString().Substring(0, 7) == "#EXTINF") - { - out_file = lines[i - 1].Substring(lines[i - 1].LastIndexOf(",") + 1, lines[i - 1].Length - lines[i - 1].LastIndexOf(",") - 1); - - dg1.Rows.Add(lines[i], "", "", out_file, ""); - } - else - { - out_file = Path.GetFileNameWithoutExtension(lines[i]); - dg1.Rows.Add(lines[i], "", "", out_file, ""); - } - } - } - } - - foreach (DataGridViewRow row in dg1.Rows) - { - row.ReadOnly = true; - } - foreach (Control ct in groupBox_m3u.Controls) - { - ct.Enabled = false; - } - btn_cancel_validate.Enabled = true; - - BG_Validate_URLs.RunWorkerAsync(); - } - - private void txt_search_url_TextChanged(object sender, EventArgs e) - { - foreach (DataGridViewRow row in dg1.Rows) - { - if (row.Cells[1].Value.ToString().ToLower().Contains(txt_search_url.Text.ToLower()) || row.Cells[4].Value.ToString().ToLower().Contains(txt_search_url.Text.ToLower())) - { - dg1.ClearSelection(); - dg1.Rows[row.Index].Cells[1].Selected = true; - dg1.CurrentCell = dg1.Rows[row.Index].Cells[1]; - break; - } - else - { - dg1.ClearSelection(); - dg1.Rows[0].Cells[1].Selected = true; - dg1.CurrentCell = dg1.Rows[0].Cells[1]; - } - } - } - - private void btn_clean_errors_Click(object sender, EventArgs e) - { - btn_clean_list.PerformClick(); - } - - //private void timer_urls_Tick(object sender, EventArgs e) - //{ - // if (probe_urls.StartInfo.Arguments != String.Empty) - // { - // probe_urls.Kill(); - // } - //} - - private void btn_url_info_Click(object sender, EventArgs e) - { - checking_url_m3u = false; - if (dg1.SelectedCells.Count == 0) return; - if (dg1.Rows[dg1.SelectedCells[0].RowIndex].Cells[1].Value.ToString().ToLower().Contains("youtu.be") || dg1.Rows[dg1.SelectedCells[0].RowIndex].Cells[1].Value.ToString().ToLower().Contains("youtube.com")) - { - Form8 frm8_streams = new Form8(); - - if (dg1.SelectedCells.Count != 1) return; - else - { - frm8_streams.url_dg_item = dg1.Rows[dg1.SelectedCells[0].RowIndex].Cells[1].Value.ToString(); - frm8_streams.pic_yout.Image = dg_thumbs[dg1.SelectedCells[0].RowIndex]; - frm8_streams.ShowDialog(); - if (frm8_streams.format_ID != "") - { - chk_m3u_params.Checked = true; - if (txt_m3u_params.Text == "-bsf:a aac_adtstoasc -c copy" || txt_m3u_params.Text == "-fflags +genpts" || txt_m3u_params.Text.Contains("-f ")) txt_m3u_params.Text = ""; - txt_m3u_params.Text = "-f " + frm8_streams.format_ID + " " + txt_m3u_params.Text; - if (frm8_streams.format_ext.ToLower().Contains("webm")) - { - combo_ext_m3u.SelectedIndex = combo_ext_m3u.FindString("webm"); - } - if (frm8_streams.format_ext.ToLower().Contains("mp4")) - { - combo_ext_m3u.SelectedIndex = combo_ext_m3u.FindString("mp4"); - } - } - } - return; - } - - Form5 frm5 = new Form5(); - frm5.lv1_item = dg1.Rows[dg1.SelectedCells[0].RowIndex].Cells[1].Value.ToString(); - frm5.pic_http = dg_thumbs[dg1.SelectedCells[0].RowIndex]; - if (btn_change_ff.Text.ToLower().Contains("full")) frm5.ff_ess = false; - else frm5.ff_ess = true; - frm5.ShowDialog(); - } - - private void ct_show_urls_Click(object sender, EventArgs e) - { - btn_url_info.PerformClick(); - } - - private void btn_n_urls_Click(object sender, EventArgs e) - { - Pg1.Focus(); - lbl_est_size.Text = ""; - lbl_bitrate.Text = ""; - cancelados_paralelos = false; - notifyIcon1.Visible = true; - if (m3u_running == true || m3u_single_running == true) return; - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - foreach (DataGridViewRow row in dg1.Rows) - { - if (row.Cells[5].Value.ToString() == Strings.error || row.Cells[5].Value.ToString() == Strings.unknown) - { - MessageBox.Show(Strings.errors_list, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - - if (dg1.RowCount == 0) - { - MessageBox.Show(Strings.down_empty, Strings.no_files, MessageBoxButtons.OK, MessageBoxIcon.Information); - return; - } - - if (txt_m3u_params.Text == String.Empty && chk_m3u_params.Text.ToLower().Contains("youtube")) - { - MessageBox.Show(Strings.capt_params, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (txt_path_m3u.Text == Strings.no_path2 && chk_output_server.CheckState == CheckState.Unchecked) - { - MessageBox.Show(Strings.select_out, Strings.out_conf, MessageBoxButtons.OK, MessageBoxIcon.Warning); - return; - } - output_server_m = ""; - if (chk_output_server.CheckState == CheckState.Checked && txt_output_server.Text == String.Empty) - { - MessageBox.Show(Strings.out_serv1, Strings.warning, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; - } - else - { - output_server_m = txt_output_server.Text; - } - - get_mixed_urls(); //Mixed youtubes - if (mixed_urls == true) return; - - // Live youtubes - has_lives_multi = false; - - int has_lives = 0; - int has_no_lives = 0; - - foreach (DataGridViewRow row in dg1.Rows) - { - if (row.Cells[1].Value.ToString().ToLower().Contains("youtu.be") || row.Cells[1].Value.ToString().ToLower().Contains("youtube.com")) - { - if (row.Cells[3].Value.ToString() == "Live") has_lives++; - else has_no_lives++; - } - } - - if (has_no_lives > 0 && has_lives > 0) - { - MessageBox.Show(Strings.mix_urls2, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (has_lives > 0) has_lives_multi = true; - else has_lives_multi = false; - //End live youtubes - - foreach (DataGridViewRow row in dg1.Rows) - { - if (row.Cells[5].Value.ToString() == Strings.ready && row.Cells[2].Value.ToString() != Strings.n_a) - { - if (row.Cells[3].Value.ToString() != "00:00" && row.Cells[3].Value.ToString() != "Live") - { - if (TimeSpan.Parse(row.Cells[3].Value.ToString()).TotalSeconds > TimeSpan.Parse(row.Cells[2].Value.ToString()).TotalSeconds) - { - MessageBox.Show(Strings.capture_time2 + " " + row.Cells[4].Value.ToString() + Strings.exc_dur, Strings.wrong_c_dur, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - } - } - foreach (DataGridViewRow row in dg1.Rows) - { - if (row.Cells[4].Value.ToString().Contains("/") || row.Cells[4].Value.ToString().Contains(":") || row.Cells[4].Value.ToString().Contains("*") || row.Cells[4].Value.ToString().Contains("?") || row.Cells[4].Value.ToString().Contains("¿") || row.Cells[4].Value.ToString().Contains('\u0022') || row.Cells[4].Value.ToString().Contains("<") || row.Cells[4].Value.ToString().Contains(">") || row.Cells[4].Value.ToString().Contains("|") || row.Cells[4].Value.ToString().Contains("\\")) - { - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("/", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace(":", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("*", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("?", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("¿", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("@", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("\u0022", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("<", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace(">", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("|", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("\\", ""); - } - } - - //Pending validation - Boolean pre_validate = false; - - foreach (DataGridViewRow row in dg1.Rows) - { - if (row.Cells[5].Value.ToString() == String.Empty) - { - pre_validate = true; - } - } - if (pre_validate == true) - { - DialogResult a = MessageBox.Show(Strings.val_urls, Strings.val_pending, MessageBoxButtons.OKCancel, MessageBoxIcon.Question); - if (a == DialogResult.OK) - { - was_started.Text = btn_start_m3u.Text; - btn_validate_url.PerformClick(); - return; - } - else - { - return; - } - } - - if (url_repeat() == true) return; - - multi_dest = ""; - multi_dest = dg1.Rows[0].Cells[1].Value.ToString(); - String file_output = dg1.Rows[0].Cells[5].Value.ToString() + "." + combo_ext_m3u.SelectedItem.ToString(); - String fichero = Path.GetFileName(multi_dest); - - String destino_test = Path.Combine(txt_path_m3u.Text, "FFBatch_test"); - - if (!multi_dest.ToLower().Contains("youtu.be") && !multi_dest.ToLower().Contains("youtube.com")) - { - this.Cursor = Cursors.WaitCursor; - - if (!Directory.Exists(destino_test)) - { - try - { - Directory.CreateDirectory(destino_test); - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.error_test_f + " " + excpt.Message, Strings.write_error2, MessageBoxButtons.OK, MessageBoxIcon.Error); - this.Cursor = Cursors.Arrow; - return; - } - } - - if (chk_try.CheckState == CheckState.Unchecked) - { - //Try preset - - Form11 frm_prog = new Form11(); - - new System.Threading.Thread(() => - { - System.Threading.Thread.CurrentThread.IsBackground = true; - frm_prog.label1.Text = Strings.trying; - frm_prog.label1.Refresh(); - frm_prog.ShowDialog(); - frm_prog.Refresh(); - }).Start(); - - Process consola_pre = new Process(); - - consola_pre.StartInfo.FileName = "ffmpeg.exe"; - consola_pre.StartInfo.Arguments = " -i " + multi_dest + " -t 0.5 " + txt_m3u_params.Text + " -y " + '\u0022' + destino_test + "\\" + file_output + '\u0022'; - consola_pre.StartInfo.CreateNoWindow = true; - consola_pre.StartInfo.RedirectStandardError = true; - consola_pre.StartInfo.RedirectStandardOutput = true; - consola_pre.StartInfo.UseShellExecute = false; - - consola_pre.Start(); - frm_prog.procId = consola_pre.Id; - String err_txt_1 = ""; - - while (!consola_pre.StandardError.EndOfStream) - { - err_txt_1 = consola_pre.StandardError.ReadLine(); - this.InvokeEx(f => f.listBox4.Items.Add(err_txt_1)); - this.InvokeEx(f => f.listBox4.Refresh()); - } - - consola_pre.WaitForExit(7000); - - consola_pre.StartInfo.Arguments = String.Empty; - - if (consola_pre.StartInfo.Arguments != String.Empty) - { - consola_pre.Kill(); - try - { - frm_prog.Invoke(new MethodInvoker(delegate - { - frm_prog.Dispose(); - })); - } - catch { } - - MessageBox.Show(Strings.url_out, Strings.url_out2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (consola_pre.ExitCode != 0) - { - this.Cursor = Cursors.Arrow; - try - { - frm_prog.Invoke(new MethodInvoker(delegate - { - frm_prog.Dispose(); - })); - } - catch { } - - listBox4.TopIndex = listBox4.Items.Count - 1; - listBox4.Refresh(); - - this.Cursor = Cursors.Arrow; - if (File.Exists(Path.Combine(destino_test, file_output))) - { - File.Delete(Path.Combine(destino_test, file_output)); - } - - if (Directory.GetFiles(destino_test).Length == 0) - { - Directory.Delete(destino_test); - } - if (frm_prog.abort_validate == false) - { - MessageBox.Show(Strings.ebc_fail_ff, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - else - { - frm_prog.Invoke(new MethodInvoker(delegate - { - frm_prog.pic.Visible = false; - frm_prog.pic_ok.Visible = true; - frm_prog.pic_ok.Refresh(); - })); - Thread.Sleep(175); - try - { - frm_prog.Invoke(new MethodInvoker(delegate - { - frm_prog.Dispose(); - })); - } - catch { } - - this.Cursor = Cursors.Arrow; - if (File.Exists(Path.Combine(destino_test, file_output))) - { - File.Delete(Path.Combine(destino_test, file_output)); - } - - if (Directory.GetFiles(destino_test).Length == 0) - { - Directory.Delete(destino_test); - } - } - } - //END try preset - } - else - { - if (!File.Exists(Path.Combine(Application.StartupPath, "yt-dlp.exe"))) - { - this.Cursor = Cursors.Arrow; - release_datagrid(); - MessageBox.Show(Strings.yt_not, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - this.Cursor = Cursors.Arrow; - - //Start pre-processing - cancel_queue = false; - Pg1.Value = 0; - //pg_current.Value = 0; - Disable_Controls(); - //textBox4.Text = "0%"; - - working = true; - m3u_single_running = false; - txt_remain.Text = ""; - - //Disable Datagrid edition - - foreach (DataGridViewRow row in dg1.Rows) - { - row.ReadOnly = true; - row.Cells[5].Value = Strings.ready; - row.Cells[5].Style.BackColor = Color.White; - } - - DataGridView list_proc = new DataGridView(); - foreach (DataGridViewColumn col in dg1.Columns) - { - list_proc.Columns.Add((DataGridViewColumn)col.Clone()); - } - - foreach (DataGridViewRow row in dg1.Rows) - { - list_proc.Rows.Add(row.Cells[1].Value.ToString(), row.Cells[2].Value.ToString(), row.Cells[3].Value.ToString(), row.Cells[4].Value.ToString(), row.Cells[5].Value.ToString()); - } - - Pg1.Minimum = 0; - Pg1.Maximum = 100; - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - //String remain_time = "0"; - - //Total duration - - total_multi_duration = 0; - foreach (DataGridViewRow row in dg1.Rows) - { - DateTime time2; - if (DateTime.TryParse(row.Cells[3].Value.ToString(), out time2)) - - { - total_multi_duration = total_multi_duration + TimeSpan.Parse((row.Cells[3].Value.ToString())).TotalSeconds; - } - } - //End total duration - - procs.Clear(); - multi_logs.Clear(); - for (int ii = 0; ii < dg1.RowCount; ii++) - { - procs.Add("proc_urls_" + ii.ToString(), new Process()); - multi_logs.Add("log_n_" + ii.ToString(), ""); - } - - show_total_prog_m = false; - foreach (DataGridViewRow row in dg1.Rows) - { - TimeSpan time = new TimeSpan(); - if (TimeSpan.TryParse(row.Cells[3].Value.ToString(), out time)) - { - show_total_prog_m = true; - } - else - { - show_total_prog_m = false; - break; - } - } - if (show_total_prog_m == true) - { - Pg1.Value = 0; - Pg1.Maximum = dg1.RowCount * 100; - } - - m3u_params_m = txt_m3u_params.Text; - if (chk_m3u_params.CheckState == CheckState.Unchecked) m3u_params_m = ""; - m3u_output_ext_m = combo_ext_m3u.SelectedItem.ToString(); - - format_out_m = m3u_output_ext_m; - down_speed_m = ""; embed_subs_m = ""; embed_meta_m = ""; write_subs_m = ""; convert_subs_m = ""; - - if (chk_best_yt.Checked) bestv_a = "-f bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio"; - else bestv_a = String.Empty; - - if (chk_down_limit.Checked == true) down_speed_m = "-r " + Convert.ToInt32(n_down_speed.Value).ToString() + "M"; - if (chk_yout_subs.Checked == true) embed_subs_m = "--embed-subs --all-subs"; - if (chk_auto_subs.Checked == true) - { - auto_subs_m = ""; - if (chk_yout_subs.Checked == true) - { - embed_subs_m = "--embed-subs"; - if (chk_auto_subs.Checked == true) - { - auto_subs_m = "--write-auto-sub --sub-lang en,es,it,pt,de,hi,ar,cn"; - } - } - } - if (chk_embed_meta.Checked == true) embed_meta_m = "--add-metadata"; - if (chk_save_subtitles.Checked == true) embed_meta_m = "--write-sub"; - if (chk_convert_srt.Checked == true) embed_meta_m = "--convert-subs=srt"; - - - if (chk_yt_chapt.Checked) chapters_m = "--split-chapters"; - - time_n_tasks = 0; - timer_tasks.Start(); - timer2.Start(); - - m3u_running = true; - aborted_url = false; - pic_no_errors.Visible = false; - pic_warnings.Visible = false; - pic_recording.Visible = false; - errors_enc = 0; - - if (has_lives_multi == true) - { - pic_recording.Visible = true; - Pg1.Style = ProgressBarStyle.Marquee; - Pg1.MarqueeAnimationSpeed = 50; - } - else - { - Pg1.Style = ProgressBarStyle.Continuous; - pic_recording.Visible = false; - } - - try - { - BG_Multi_Down.RunWorkerAsync(); - } - catch - { - MessageBox.Show(Strings.queue_prog_a); - } - } - - private void ctm_stop_url_Click(object sender, EventArgs e) - { - if (dg1.SelectedCells.Count == 1 && dg1.Rows[dg1.SelectedCells[0].RowIndex].Cells[5].Value.ToString() != Strings.success && dg1.Rows[dg1.SelectedCells[0].RowIndex].Cells[5].Value.ToString() != Strings.ready) - { - if (m3u_single_running == false) - { - if (dg1.Rows[dg1.SelectedCells[0].RowIndex].Cells[1].Value.ToString().ToLower().Contains("youtu.be") || dg1.Rows[dg1.SelectedCells[0].RowIndex].Cells[1].Value.ToString().ToLower().Contains("youtube.com")) - { - if (dg1.Rows[dg1.SelectedCells[0].RowIndex].Cells[5].Value.ToString() == Strings.recording1) - { - dg1.Rows[dg1.SelectedCells[0].RowIndex].Cells[5].Value = Strings.stopping; - Send_CTRLC(procs["proc_urls_" + dg1.Rows[dg1.SelectedCells[0].RowIndex].Index.ToString()]); - } - else - { - Process[] localByName = Process.GetProcessesByName("yt-dlp"); - foreach (Process p in localByName) - { - try - { - if (p.Id == procs["proc_urls_" + dg1.Rows[dg1.SelectedCells[0].RowIndex].Index.ToString()].Id) - { - foreach (Process pr in p.GetChildProcesses()) - { - pr.Kill(); - } - p.Kill(); - } - } - catch { } - } - } - } - else - { - try - { - StreamWriter write_q = procs["proc_urls_" + dg1.Rows[dg1.SelectedCells[0].RowIndex].Index.ToString()].StandardInput; - write_q.Write("q"); - } catch { } - aborted_url = true; - } - } - else - { - if (dg1.Rows[dg1.SelectedCells[0].RowIndex].Cells[1].Value.ToString().ToLower().Contains("youtu.be") || dg1.Rows[dg1.SelectedCells[0].RowIndex].Cells[1].Value.ToString().ToLower().Contains("youtube.com")) - { - if (dg1.Rows[dg1.SelectedCells[0].RowIndex].Cells[5].Value.ToString() == Strings.recording1) - { - //Live YouTube abort - timer2.Stop(); - aborted_url = false; - stopped_recording = true; - foreach (Process proc in procs.Values) - { - try - { - Send_CTRLC(proc); - aborted_url = true; - } - catch { } - } - Pg1.MarqueeAnimationSpeed = 15; - Pg1.Text = Strings.stopping2; - Pg1.Refresh(); - - } - else - { - Process[] localByName = Process.GetProcessesByName("yt-dlp"); - foreach (Process p in localByName) - { - try { p.Kill(); } - catch { } - } - } - } - else - { - foreach (Process proc in procs.Values) - { - try - { - StreamWriter write_q = proc.StandardInput; - write_q.Write("q"); - } - catch { } - } - aborted_url = true; - } - } - } - } - - private void BG_Try_preset_DoWork(object sender, DoWorkEventArgs e) - { - if (chk_try.CheckState == CheckState.Checked) - { - tried_ok = true; - return; - } - else tried_ok = false; - filter_chars(); - - String pre_i = ""; - txt_pre_input.Invoke(new MethodInvoker(delegate - { - pre_i = txt_pre_input.Text; - })); - - - this.InvokeEx(f => this.Enabled = false); - Form11 frm_prog = new Form11(); - - new System.Threading.Thread(() => - { - System.Threading.Thread.CurrentThread.IsBackground = true; - frm_prog.reading = Strings.trying; - frm_prog.label1.Refresh(); - frm_prog.ShowDialog(); - frm_prog.Refresh(); - }).Start(); - - this.InvokeEx(f => this.Cursor = Cursors.WaitCursor); - ListBox LB1_o = new ListBox(); - Process consola_pre = new Process(); - String file_prueba = ""; - String sel_test = ""; - - Double size_dur = 0; - Double file_size = 0; - Double dur_rpl = 0; - String dur_fbit = String.Empty; - - listView1.Invoke(new MethodInvoker(delegate - { - sel_test = listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text; - if (!File.Exists(sel_test)) - { - MessageBox.Show(Strings.file_not_f, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (Properties.Settings.Default.quick_queue == false) - { - dur_rpl = TimeSpan.Parse(listView1.Items[0].SubItems[3].Text).TotalSeconds; - dur_fbit = listView1.Items[0].SubItems[3].Text; - } - else - { - dur_rpl = 0; - dur_fbit = "00:00:00"; - } - - FileInfo fs = new FileInfo(sel_test); - file_size = fs.Length; - try - { - size_dur = TimeSpan.Parse(listView1.Items[0].SubItems[3].Text).TotalSeconds; - } - catch { size_dur = 0; } - })); - - file_prueba = sel_test; - String destino_test = Path.GetTempPath() + "\\" + "FFBatch_test"; - Boolean bad_chars = false; - Boolean unsupported = false; - String second_path = ""; - - if (txt_format.Text == "nul") - { - String[] split = txt_parameters.Text.Split(' '); - for (int i = 0; i < split.Length; i++) - { - if (split[i].Contains("\\") == true) - { - String pre_path = split[i].Replace("%fp", Path.GetDirectoryName(sel_test)).Replace("%fn", Path.GetFileNameWithoutExtension(sel_test)).Replace("%", "_"); - second_path = Path.GetDirectoryName(pre_path.Replace('\u0022', ' ')); - - if (!Directory.Exists(second_path)) - { - try - { - Directory.CreateDirectory(second_path); - } - catch - { - } - } - } - } - } - - Task tt = Task.Run(() => - { - String fichero = Path.GetFileName(file_prueba); - - if (!Directory.Exists(destino_test)) - { - try - { - Directory.CreateDirectory(destino_test); - } - catch (System.Exception excpt) - { - this.InvokeEx(f => MessageBox.Show(this, Strings.error2 + " " + excpt.Message, Strings.write_error2, MessageBoxButtons.OK, MessageBoxIcon.Error)); - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - return; - } - } - - String ext_output = txt_format.Text; - if (txt_format.Text == String.Empty) - { - ext_output = Path.GetExtension(file_prueba); - } - else - { - ext_output = "." + txt_format.Text; - } - if (txt_format.Text == "nul") ext_output = "nul"; - - textbox_params = txt_parameters.Text; - - String file_prueba2 = file_prueba; - - while (textbox_params.Contains("%fn")) - { - if (textbox_params.Contains("%fn")) - { - textbox_params = textbox_params.Replace("%fn", Path.GetFileNameWithoutExtension(file_prueba)); - } - } - - while (pre_i.Contains("%fn")) - { - if (pre_i.Contains("%fn")) - { - pre_i = pre_i.Replace("%fn", Path.GetFileNameWithoutExtension(file_prueba)); - } - } - - while (textbox_params.Contains("%ff")) - { - if (textbox_params.Contains("%ff")) - { - textbox_params = textbox_params.Replace("%ff", Path.GetFileName(file_prueba)); - } - } - - while (pre_i.Contains("%ff")) - { - if (pre_i.Contains("%ff")) - { - pre_i = pre_i.Replace("%ff", Path.GetFileName(file_prueba)); - } - } - - String dur_secs = dur_rpl.ToString(); - String to_replace = String.Empty; - - while (textbox_params.Contains("%fdur")) - { - - if (textbox_params.Contains("%fdur")) - { - to_replace = ""; - - int operador = textbox_params.LastIndexOf("%fdur") + 5; - int length = 0; - int limit = textbox_params.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(textbox_params.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace = textbox_params.Substring(textbox_params.LastIndexOf("%fdur"), 5 + length); - Double result = Convert.ToDouble(new DataTable().Compute(to_replace.Replace("%fdur", dur_secs), null)); - textbox_params = ReplaceLastOccurrence(textbox_params, to_replace, Math.Round(result).ToString()); - } - } - - while (pre_i.Contains("%fdur")) - { - - if (pre_i.Contains("%fdur")) - { - to_replace = ""; - - int operador = pre_i.LastIndexOf("%fdur") + 5; - int length = 0; - int limit = pre_i.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(pre_i.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace = pre_i.Substring(pre_i.LastIndexOf("%fdur"), 5 + length); - Double result = Convert.ToDouble(new DataTable().Compute(to_replace.Replace("%fdur", dur_secs), null)); - pre_i = ReplaceLastOccurrence(pre_i, to_replace, Math.Round(result).ToString()); - } - } - - //Bitrate variable - - dur_secs = get_bitrate(file_prueba, dur_fbit).ToString(); - to_replace = String.Empty; - - while (textbox_params.Contains("%fbitr")) - { - if (textbox_params.Contains("%fbitr")) - { - to_replace = ""; - - int operador = textbox_params.LastIndexOf("%fbitr") + 6; - int length = 0; - int limit = textbox_params.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(textbox_params.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace = textbox_params.Substring(textbox_params.LastIndexOf("%fbitr"), 6 + length); - - Double result = Convert.ToDouble(new DataTable().Compute(to_replace.Replace("%fbitr", dur_secs), null)); - textbox_params = ReplaceLastOccurrence(textbox_params, to_replace, Math.Round(result).ToString() + "K"); - } - } - - while (pre_i.Contains("%fbitr")) - { - if (pre_i.Contains("%fbitr")) - { - to_replace = ""; - - int operador = pre_i.LastIndexOf("%fbitr") + 6; - int length = 0; - int limit = pre_i.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(pre_i.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace = pre_i.Substring(pre_i.LastIndexOf("%fbitr"), 6 + length); - - Double result = Convert.ToDouble(new DataTable().Compute(to_replace.Replace("%fbitr", dur_secs), null)); - pre_i = ReplaceLastOccurrence(pre_i, to_replace, Math.Round(result).ToString() + "K"); - } - } - - //End bitrate variable - - // Target size - if (textbox_params.Contains("[[target_size=")) - { - int f = textbox_params.IndexOf("[[target_size=") + 14; - int mb = textbox_params.IndexOf("MB"); - int l = textbox_params.IndexOf("Kbps]]"); - Double target_mb = Convert.ToDouble(textbox_params.Substring(f, mb - f)); - String aud_bitr = textbox_params.Substring(mb + 3, l - mb - 3); - String replaced = get_bitrate_target(target_mb, dur_rpl, Convert.ToDecimal(aud_bitr)).ToString(); - to_replace = textbox_params.Substring(f - 14, l - f + 14 + 6); - textbox_params = textbox_params.Replace(to_replace, replaced); - } - - //End target size - - while (textbox_params.Contains("%fp")) - { - if (textbox_params.Contains("%fp")) - { - textbox_params = textbox_params.Replace("%fp", Path.GetDirectoryName(file_prueba)); - } - } - - while (pre_i.Contains("%fp")) - { - if (pre_i.Contains("%fp")) - { - pre_i = pre_i.Replace("%fp", Path.GetDirectoryName(file_prueba)); - } - } - - while (textbox_params.Contains("%fd")) - { - if (textbox_params.Contains("%fd")) - { - var dirName = new DirectoryInfo(Path.GetDirectoryName(file_prueba)).Name; - textbox_params = textbox_params.Replace("%fd", dirName); - } - } - - while (pre_i.Contains("%fd")) - { - if (pre_i.Contains("%fd")) - { - var dirName = new DirectoryInfo(Path.GetDirectoryName(file_prueba)).Name; - pre_i = pre_i.Replace("%fd", dirName); - } - } - - while (textbox_params.Contains("%1")) - { - if (textbox_params.Contains("%1")) - { - file_prueba2 = file_prueba2.Replace("\\", "\\\\\\\\"); - file_prueba2 = file_prueba2.Replace(":", ":" + "\\\\"); - textbox_params = textbox_params.Replace("%1", '\u0022' + file_prueba2 + '\u0022'); - } - } - - while (pre_i.Contains("%1")) - { - if (pre_i.Contains("%1")) - { - file_prueba2 = file_prueba2.Replace("\\", "\\\\\\\\"); - file_prueba2 = file_prueba2.Replace(":", ":" + "\\\\"); - pre_i = pre_i.Replace("%1", '\u0022' + file_prueba2 + '\u0022'); - } - } - - while (textbox_params.Contains("%2")) - { - if (textbox_params.Contains("%2")) - { - file_prueba2 = file_prueba2.Replace("\\", "\\\\\\\\"); - file_prueba2 = file_prueba2.Replace(":", ":" + "\\\\"); - textbox_params = textbox_params.Replace("%2", '\u0022' + Path.Combine(Path.GetDirectoryName(file_prueba2), Path.GetFileNameWithoutExtension(file_prueba2)) + '\u0022'); - } - } - - while (pre_i.Contains("%2")) - { - if (pre_i.Contains("%2")) - { - file_prueba2 = file_prueba2.Replace("\\", "\\\\\\\\"); - file_prueba2 = file_prueba2.Replace(":", ":" + "\\\\"); - pre_i = pre_i.Replace("%2", '\u0022' + Path.Combine(Path.GetDirectoryName(file_prueba2), Path.GetFileNameWithoutExtension(file_prueba2)) + '\u0022'); - } - } - - while (textbox_params.Contains("%pff")) - { - if (textbox_params.Contains("%pff")) - { - file_prueba2 = file_prueba2.Replace("\\", "/\\"); - file_prueba2 = file_prueba2.Replace(":", "\\\\://\\"); - - textbox_params = textbox_params.Replace("%pff", Path.GetDirectoryName(file_prueba2)); - } - } - - while (textbox_params.Contains("%f1")) - { - if (textbox_params.Contains("%f1")) - { - file_prueba2 = file_prueba2.Replace("\\", "/\\"); - file_prueba2 = file_prueba2.Replace(":", "\\\\:"); - textbox_params = textbox_params.Replace("%f1", file_prueba2); - } - } - - while (textbox_params.Contains("%f2")) - { - if (textbox_params.Contains("%f2")) - { - file_prueba2 = file_prueba2.Replace("\\", "/\\"); - file_prueba2 = file_prueba2.Replace(":", "\\\\://\\"); - textbox_params = textbox_params.Replace("%f2", Path.Combine(Path.GetDirectoryName(file_prueba2), Path.GetFileNameWithoutExtension(file_prueba2))); - } - } - - while (pre_i.Contains("%pff")) - { - if (pre_i.Contains("%pff")) - { - file_prueba2 = file_prueba2.Replace("\\", "/\\"); - file_prueba2 = file_prueba2.Replace(":", "\\\\://\\"); - - pre_i = pre_i.Replace("%pff", Path.GetDirectoryName(file_prueba2)); - } - } - - while (pre_i.Contains("%f1")) - { - if (pre_i.Contains("%f1")) - { - file_prueba2 = file_prueba2.Replace("\\", "/\\"); - file_prueba2 = file_prueba2.Replace(":", "\\\\://\\"); - - pre_i = pre_i.Replace("%f1", file_prueba2); - } - } - - while (pre_i.Contains("%f2")) - { - if (pre_i.Contains("%f2")) - { - file_prueba2 = file_prueba2.Replace("\\", "/\\"); - file_prueba2 = file_prueba2.Replace(":", "\\\\://\\"); - pre_i = pre_i.Replace("%f2", Path.Combine(Path.GetDirectoryName(file_prueba2), Path.GetFileNameWithoutExtension(file_prueba2))); - } - } - - consola_pre.StartInfo.FileName = "ffmpeg.exe"; - - if (textbox_params.Contains(" (segment_size) ")) - { - Double split_size = Convert.ToDouble(split_by_size); - String ff_frames = String.Empty; - Double ov_bitrate = 0; - ov_bitrate = file_size / size_dur; - Double bit_r = 0; - bit_r = ov_bitrate / 1000000; - bit_r = split_size / bit_r; - bit_r = Math.Round(bit_r, 2); - textbox_params = textbox_params.Replace(" (segment_size) ", " " + bit_r.ToString().Replace(",", ".") + " "); - } - - consola_pre.StartInfo.Arguments = pre_i + " " + hw_decode_glob + " -i " + "" + '\u0022' + file_prueba + '\u0022' + "" + " -y " + textbox_params + " -t 0.2 " + '\u0022' + destino_test + "\\" + Path.GetFileNameWithoutExtension(file_prueba) + ext_output + '\u0022' + " -loglevel warning -stats"; - - if (consola_pre.StartInfo.Arguments.Contains("[[split_chapters]]")) consola_pre.StartInfo.Arguments = consola_pre.StartInfo.Arguments.Replace("[[split_chapters]]", ""); - - if (ext_output == "nul") consola_pre.StartInfo.Arguments = pre_i + " " + hw_decode_glob + " -loglevel warning -stats" + " -i " + "" + '\u0022' + file_prueba + '\u0022' + " " + textbox_params; - - consola_pre.StartInfo.RedirectStandardError = true; - consola_pre.StartInfo.StandardErrorEncoding = Encoding.UTF8; - consola_pre.StartInfo.UseShellExecute = false; - consola_pre.StartInfo.CreateNoWindow = true; - consola_pre.EnableRaisingEvents = true; - consola_pre.StartInfo.WorkingDirectory = Application.StartupPath; - - consola_pre.Start(); - frm_prog.procId = consola_pre.Id; - - while (!consola_pre.StandardError.EndOfStream) - { - this.Invoke(new MethodInvoker(delegate - { - LB1_o.Items.Add(consola_pre.StandardError.ReadLine()); - LB1_o.TopIndex = LB1_o.Items.Count - 1; - LB1_o.Refresh(); - })); - } - - consola_pre.WaitForExit(); - consola_pre.StartInfo.Arguments = String.Empty; - this.InvokeEx(f => this.Enabled = true); - }); - - if (!tt.Wait(1000) && consola_pre.StartInfo.Arguments != String.Empty) - { - this.InvokeEx(f => this.Enabled = true); - frm_prog.Invoke(new MethodInvoker(delegate - { - frm_prog.pic.Visible = false; - frm_prog.pic_ok.Visible = true; - frm_prog.pic_ok.Refresh(); - })); - Thread.Sleep(175); - try - { - frm_prog.Invoke(new MethodInvoker(delegate - { - frm_prog.Dispose(); - })); - } - catch { } - try { consola_pre.Kill(); } catch { } - tried_ok = true; - this.InvokeEx(f => f.btn_try_pr.Image = img_try.Images[1]); - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - - if (Directory.Exists(destino_test) && Directory.GetFiles(destino_test).Length > 0) - { - foreach (String file in Directory.GetFiles(destino_test)) - { - try - { - File.Delete(file); - } - catch - { - } - } - } - - LB1_o.Items.Clear(); - tried_params.Add(txt_parameters.Text); - return; - } - - if (bad_chars == false) - { - if (consola_pre.ExitCode != 0) - { - if (frm_prog.abort_validate == false) - { - if (Directory.Exists(destino_test) && Directory.GetFiles(destino_test).Length > 0) - { - foreach (String file in Directory.GetFiles(destino_test)) - { - try - { - File.Delete(file); - } - catch - { - } - } - } - - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - foreach (String lin in LB1_o.Items) - { - if (lin.Contains("not load the requested plugin") || lin.Contains("Cannot load nvcuda.dll")) - { - unsupported = true; - } - } - tried_ok = false; - try - { - frm_prog.Invoke(new MethodInvoker(delegate - { - frm_prog.Dispose(); - })); - } - catch { } - this.InvokeEx(f => f.btn_try_pr.Image = img_try.Images[2]); - int n_lines = LB1_o.Items.Count; - - if (unsupported == true) - { - this.Invoke(new MethodInvoker(delegate - { - this.Cursor = Cursors.Arrow; - this.Enabled = true; - this.TopLevel = true; - })); - - MessageBox.Show(Strings.test_failed + " " + Environment.NewLine + Environment.NewLine + Strings.unsup_enc + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 1].ToString() + Environment.NewLine + Environment.NewLine + Strings.try_pr, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - else - { - this.Invoke(new MethodInvoker(delegate - { - this.Cursor = Cursors.Arrow; - this.Enabled = true; - this.TopLevel = true; - - if (n_lines >= 4) - { - MessageBox.Show(this, Strings.test_failed + " " + Environment.NewLine + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 4].ToString() + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 3].ToString() + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 2].ToString() + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 1].ToString() + Environment.NewLine + Environment.NewLine + Strings.try_pr, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - if (n_lines == 3) - { - MessageBox.Show(this, Strings.test_failed + " " + Environment.NewLine + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 3].ToString() + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 2].ToString() + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 1].ToString() + Environment.NewLine + Environment.NewLine + Strings.try_pr, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - if (n_lines == 2) - { - MessageBox.Show(this, Strings.test_failed + " " + Environment.NewLine + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 2].ToString() + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 1].ToString() + Environment.NewLine + Environment.NewLine + Strings.try_pr, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - if (n_lines == 1) - { - MessageBox.Show(this, Strings.test_failed + " " + Environment.NewLine + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 1].ToString() + Environment.NewLine + Environment.NewLine + Strings.try_pr, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - })); - } - - return; - } - } - else - { - try - { - frm_prog.Invoke(new MethodInvoker(delegate - { - frm_prog.pic.Visible = false; - frm_prog.pic_ok.Visible = true; - frm_prog.pic_ok.Refresh(); - })); - } - catch { } - System.Threading.Thread.Sleep(175); - try - { - frm_prog.Invoke(new MethodInvoker(delegate - { - frm_prog.Dispose(); - })); - } - catch { } - if (Directory.Exists(destino_test) && Directory.GetFiles(destino_test).Length > 0) - { - foreach (String file in Directory.GetFiles(destino_test)) - { - try - { - File.Delete(file); - } - catch - { - } - } - } - - - tried_params.Add(txt_parameters.Text); - tried_ok = true; - } - } - //END try preset - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - - LB1_o.Items.Clear(); - consola_pre.Dispose(); - } - - private void BG_Try_preset_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) - { - String file_prueba = ""; - String sel_test = ""; - if (listView1.SelectedIndices.Count > 0) sel_test = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - else sel_test = listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text; - file_prueba = sel_test; - String destino = Path.Combine(Path.GetTempPath(), "FFBatch_test"); - String borrar = destino + "\\" + Path.GetFileNameWithoutExtension(file_prueba) + "." + txt_format.Text; - - if (File.Exists(borrar)) - { - try { File.Delete(borrar); } catch { } - } - - //Re-route to pressed button - if (tried_ok == true) - { - if (was_started.Text == btn_seq.Text) - { - btn_seq.PerformClick(); - } - - if (was_started.Text == btn_multi_m.Text) - { - btn_multi_m.PerformClick(); - } - if (was_started.Text == btn_concat.Text) - { - btn_concat.PerformClick(); - } - if (was_started.Text == btn_trim.Text) - { - btn_trim.PerformClick(); - } - } - } - - private void frm_output2_FormClosing(object sender, System.EventArgs e) - { - this.Invoke(new MethodInvoker(delegate - { - btn_try_pr.Enabled = true; - this.Enabled = true; - })); - } - - Boolean IsDigitsOnly(String str) - { - foreach (char c in str) - { - if (c != '0' && c != '1' && c != '2' && c != '3' && c != '4' && c != '5' && c != '6' && c != '7' && c != '8' && c != '9' && c != '.' && c != '+' && c != '-' && c != '*' && c != '/') - return false; - } - return true; - } - private String ReplaceLastOccurrence(string source, string find, string replace) - { - int place = source.LastIndexOf(find); - - if (place == -1) - return source; - - return source.Remove(place, find.Length).Insert(place, replace); - } - - private String get_bitrate_target(Double target_mb, Double dur, Decimal aud_bitr) - { - Double bitr = target_mb * 8 * 1024; - bitr = Math.Round((bitr / dur * 0.998)) - (double)aud_bitr; - if (bitr < 100) bitr = 100; - String bitrs = bitr.ToString() + "K"; - return "-vb " + bitrs; - } - private void BG_Try_button_DoWork(object sender, DoWorkEventArgs e) - { - String pre_i = ""; - txt_pre_input.Invoke(new MethodInvoker(delegate - { - pre_i = txt_pre_input.Text; - })); - - Boolean failed = false; - Double size_dur = 0; - Double file_size = 0; - Double dur_rpl = 0; - String dur_fbit = String.Empty; - String sel_test = ""; - this.InvokeEx(f => f.btn_try_pr.Image = img_try.Images[0]); - listView1.Invoke(new MethodInvoker(delegate - { - sel_test = listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text; - if (!File.Exists(sel_test)) - { - MessageBox.Show(Strings.file_not_f); - failed = true; - return; - } - - if (Properties.Settings.Default.quick_queue == false) - { - dur_rpl = TimeSpan.Parse(listView1.Items[0].SubItems[3].Text).TotalSeconds; - dur_fbit = listView1.Items[0].SubItems[3].Text; - } - else - { - dur_rpl = 0; - dur_fbit = "00:00:00"; - } - - FileInfo fs = new FileInfo(sel_test); - file_size = fs.Length; - try - { - size_dur = TimeSpan.Parse(listView1.Items[0].SubItems[3].Text).TotalSeconds; - } - catch { size_dur = 0; } - })); - - if (failed == true) return; - this.InvokeEx(f => this.Cursor = Cursors.WaitCursor); - this.InvokeEx(f => f.btn_try_pr.Enabled = false); - - frm_output2.Name = Strings.try_ff2; - frm_output2.Icon = this.Icon; - - frm_output2.Height = 575; - frm_output2.Width = 977; - frm_output2.FormBorderStyle = FormBorderStyle.Fixed3D; - frm_output2.MaximizeBox = false; - frm_output2.MinimizeBox = false; - - var fuente_list = new System.Drawing.Font("Microsoft Sans Serif", 8, FontStyle.Regular); - - LB1_o_try.Items.Clear(); - LB1_o_try.Parent = frm_output2; - LB1_o_try.Left = 20; - LB1_o_try.Top = 65; - LB1_o_try.Height = 425; - LB1_o_try.Width = 920; - LB1_o_try.Font = fuente_list; - LB1_o_try.Click += new EventHandler(LB1_o_Click); - - TextBox titulo = new TextBox(); - titulo.Parent = frm_output2; - titulo.Top = 15; - titulo.Left = 20; - titulo.Width = 921; - titulo.TabIndex = 0; - var fuente = new System.Drawing.Font("Microsoft Sans Serif", 11, FontStyle.Bold); - - titulo.Font = fuente; - titulo.BorderStyle = BorderStyle.Fixed3D; - titulo.TextAlign = HorizontalAlignment.Center; - titulo.ReadOnly = true; - - titulo.Text = Strings.proc_ff; - - Button boton_ok_ff = new Button(); - boton_ok_ff.Parent = frm_output2; - boton_ok_ff.Left = 480; - boton_ok_ff.Top = 495; - boton_ok_ff.Width = 461; - boton_ok_ff.Height = 27; - boton_ok_ff.Text = Strings.proc_file; - boton_ok_ff.Click += new EventHandler(boton_ok_ff_Click); - - Button boton_copy_ff = new Button(); - boton_copy_ff.Parent = frm_output2; - boton_copy_ff.Left = 20; - boton_copy_ff.Top = 495; - boton_copy_ff.Width = 461; - boton_copy_ff.Height = 27; - boton_copy_ff.Text = Strings.clipb; - boton_copy_ff.Click += new EventHandler(boton_copy_ff_Click); - - Process consola = new Process(); - String file_prueba = ""; - file_prueba = sel_test; - String destino = Path.GetTempPath() + "\\" + "FFBatch_test"; - Boolean timed_out = false; - frm_output2.FormClosing += frm_output2_FormClosing; - - Task tt = Task.Run(() => - { - String fichero = Path.GetFileName(file_prueba); - TextBox titulo2 = new TextBox(); - titulo2.Parent = frm_output2; - titulo2.Top = 42; - titulo2.Left = 47; - titulo2.Width = 867; - - var fuente2 = new System.Drawing.Font("Microsoft Sans Serif", 10, FontStyle.Regular); - - titulo2.Font = fuente2; - titulo2.BorderStyle = BorderStyle.None; - titulo2.TextAlign = HorizontalAlignment.Center; - titulo2.ReadOnly = true; - - titulo2.Text = (fichero); - - frm_output2.StartPosition = FormStartPosition.CenterScreen; - - if (!Directory.Exists(destino)) - { - try - { - Directory.CreateDirectory(destino); - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.error2 + " " + excpt.Message, Strings.write_error2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - - String ext_output = txt_format.Text; - if (txt_format.Text == String.Empty) - { - ext_output = Path.GetExtension(file_prueba); - } - else - { - ext_output = "." + txt_format.Text; - } - if (txt_format.Text == "nul") ext_output = "nul"; - textbox_params = txt_parameters.Text; - - if (textbox_params.Contains(" (segment_size) ")) - { - Double split_size = Convert.ToDouble(split_by_size); - String ff_frames = String.Empty; - Double ov_bitrate = 0; - ov_bitrate = file_size / size_dur; - Double bit_r = 0; - bit_r = ov_bitrate / 1000000; - bit_r = split_size / bit_r; - bit_r = Math.Round(bit_r, 2); - textbox_params = textbox_params.Replace(" (segment_size) ", " " + bit_r.ToString().Replace(",", ".") + " "); - } - - - String file_prueba2 = file_prueba; - - while (textbox_params.Contains("%fn")) - { - if (textbox_params.Contains("%fn")) - { - textbox_params = textbox_params.Replace("%fn", Path.GetFileNameWithoutExtension(file_prueba)); - } - } - - while (pre_i.Contains("%fn")) - { - if (pre_i.Contains("%fn")) - { - pre_i = pre_i.Replace("%fn", Path.GetFileNameWithoutExtension(file_prueba)); - } - } - - while (textbox_params.Contains("%ff")) - { - if (textbox_params.Contains("%ff")) - { - textbox_params = textbox_params.Replace("%ff", Path.GetFileName(file_prueba)); - } - } - - while (pre_i.Contains("%ff")) - { - if (pre_i.Contains("%ff")) - { - pre_i = pre_i.Replace("%ff", Path.GetFileName(file_prueba)); - } - } - - //%fdur variable operations - - //int count = Regex.Matches(textbox_params, pattern_dur).Count; - - String dur_secs = dur_rpl.ToString(); - String to_replace = String.Empty; - - while (textbox_params.Contains("%fdur")) - { - if (textbox_params.Contains("%fdur")) - { - to_replace = ""; - - int operador = textbox_params.LastIndexOf("%fdur") + 5; - int length = 0; - int limit = textbox_params.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(textbox_params.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace = textbox_params.Substring(textbox_params.LastIndexOf("%fdur"), 5 + length); - Double result = Convert.ToDouble(new DataTable().Compute(to_replace.Replace("%fdur", dur_secs), null)); - textbox_params = ReplaceLastOccurrence(textbox_params, to_replace, Math.Round(result).ToString()); - } - } - - while (pre_i.Contains("%fdur")) - { - - if (pre_i.Contains("%fdur")) - { - to_replace = ""; - - int operador = pre_i.LastIndexOf("%fdur") + 5; - int length = 0; - int limit = pre_i.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(pre_i.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace = pre_i.Substring(pre_i.LastIndexOf("%fdur"), 5 + length); - Double result = Convert.ToDouble(new DataTable().Compute(to_replace.Replace("%fdur", dur_secs), null)); - pre_i = ReplaceLastOccurrence(pre_i, to_replace, Math.Round(result).ToString()); - } - } - - //Bitrate variable - - dur_secs = get_bitrate(file_prueba, dur_fbit).ToString(); - to_replace = String.Empty; - - while (textbox_params.Contains("%fbitr")) - { - if (textbox_params.Contains("%fbitr")) - { - to_replace = ""; - - int operador = textbox_params.LastIndexOf("%fbitr") + 6; - int length = 0; - int limit = textbox_params.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(textbox_params.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace = textbox_params.Substring(textbox_params.LastIndexOf("%fbitr"), 6 + length); - - Double result = Convert.ToDouble(new DataTable().Compute(to_replace.Replace("%fbitr", dur_secs), null)); - textbox_params = ReplaceLastOccurrence(textbox_params, to_replace, Math.Round(result).ToString() + "K"); - } - } - - while (pre_i.Contains("%fbitr")) - { - if (pre_i.Contains("%fbitr")) - { - to_replace = ""; - - int operador = pre_i.LastIndexOf("%fbitr") + 6; - int length = 0; - int limit = pre_i.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(pre_i.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace = pre_i.Substring(pre_i.LastIndexOf("%fbitr"), 6 + length); - - Double result = Convert.ToDouble(new DataTable().Compute(to_replace.Replace("%fbitr", dur_secs), null)); - pre_i = ReplaceLastOccurrence(pre_i, to_replace, Math.Round(result).ToString() + "K"); - } - } - - //End bitrate variable - - //Target size - if (textbox_params.Contains("[[target_size=")) - { - int f = textbox_params.IndexOf("[[target_size=") + 14; - int mb = textbox_params.IndexOf("MB"); - int l = textbox_params.IndexOf("Kbps]]"); - Double target_mb = Convert.ToDouble(textbox_params.Substring(f, mb - f)); - String aud_bitr = textbox_params.Substring(mb + 3, l - mb - 3); - String replaced = get_bitrate_target(target_mb, dur_rpl, Convert.ToDecimal(aud_bitr)).ToString(); - to_replace = textbox_params.Substring(f - 14, l - f + 14 + 6); - textbox_params = textbox_params.Replace(to_replace, replaced); - } - - //End target size - - while (textbox_params.Contains("%fp")) - { - if (textbox_params.Contains("%fp")) - { - textbox_params = textbox_params.Replace("%fp", Path.GetDirectoryName(file_prueba)); - } - } - - while (pre_i.Contains("%fp")) - { - if (pre_i.Contains("%fp")) - { - pre_i = pre_i.Replace("%fp", Path.GetDirectoryName(file_prueba)); - } - } - - while (textbox_params.Contains("%fd")) - { - if (textbox_params.Contains("%fd")) - { - var dirName = new DirectoryInfo(Path.GetDirectoryName(file_prueba)).Name; - textbox_params = textbox_params.Replace("%fd", dirName); - } - } - - while (pre_i.Contains("%fd")) - { - if (pre_i.Contains("%fd")) - { - var dirName = new DirectoryInfo(Path.GetDirectoryName(file_prueba)).Name; - pre_i = pre_i.Replace("%fd", dirName); - } - } - - while (textbox_params.Contains("%1")) - { - if (textbox_params.Contains("%1")) - { - file_prueba2 = file_prueba2.Replace("\\", "\\\\\\\\"); - file_prueba2 = file_prueba2.Replace(":", ":" + "\\\\"); - textbox_params = textbox_params.Replace("%1", '\u0022' + file_prueba2 + '\u0022'); - } - } - - while (pre_i.Contains("%1")) - { - if (pre_i.Contains("%1")) - { - file_prueba2 = file_prueba2.Replace("\\", "\\\\\\\\"); - file_prueba2 = file_prueba2.Replace(":", ":" + "\\\\"); - pre_i = pre_i.Replace("%1", '\u0022' + file_prueba2 + '\u0022'); - } - } - - while (textbox_params.Contains("%2")) - { - if (textbox_params.Contains("%2")) - { - file_prueba2 = file_prueba2.Replace("\\", "\\\\\\\\"); - file_prueba2 = file_prueba2.Replace(":", ":" + "\\\\"); - textbox_params = textbox_params.Replace("%2", '\u0022' + Path.Combine(Path.GetDirectoryName(file_prueba2), Path.GetFileNameWithoutExtension(file_prueba2)) + '\u0022'); - } - } - - while (pre_i.Contains("%2")) - { - if (pre_i.Contains("%2")) - { - file_prueba2 = file_prueba2.Replace("\\", "\\\\\\\\"); - file_prueba2 = file_prueba2.Replace(":", ":" + "\\\\"); - pre_i = pre_i.Replace("%2", '\u0022' + Path.Combine(Path.GetDirectoryName(file_prueba2), Path.GetFileNameWithoutExtension(file_prueba2)) + '\u0022'); - } - } - - while (textbox_params.Contains("%pff")) - { - if (textbox_params.Contains("%pff")) - { - file_prueba2 = file_prueba2.Replace("\\", "/\\"); - file_prueba2 = file_prueba2.Replace(":", "\\\\://\\"); - - textbox_params = textbox_params.Replace("%pff", Path.GetDirectoryName(file_prueba2)); - } - } - - while (textbox_params.Contains("%f1")) - { - if (textbox_params.Contains("%f1")) - { - file_prueba2 = file_prueba2.Replace("\\", "/\\"); - file_prueba2 = file_prueba2.Replace(":", "\\\\:"); - - textbox_params = textbox_params.Replace("%f1", file_prueba2); - } - } - - while (textbox_params.Contains("%f2")) - { - if (textbox_params.Contains("%f2")) - { - file_prueba2 = file_prueba2.Replace("\\", "/\\"); - file_prueba2 = file_prueba2.Replace(":", "\\\\://\\"); - textbox_params = textbox_params.Replace("%f2", Path.Combine(Path.GetDirectoryName(file_prueba2), Path.GetFileNameWithoutExtension(file_prueba2))); - } - } - - while (pre_i.Contains("%pff")) - { - if (pre_i.Contains("%pff")) - { - file_prueba2 = file_prueba2.Replace("\\", "/\\"); - file_prueba2 = file_prueba2.Replace(":", "\\\\://\\"); - - pre_i = pre_i.Replace("%pff", Path.GetDirectoryName(file_prueba2)); - } - } - - while (pre_i.Contains("%f1")) - { - if (pre_i.Contains("%f1")) - { - file_prueba2 = file_prueba2.Replace("\\", "/\\"); - file_prueba2 = file_prueba2.Replace(":", "\\\\://\\"); - - pre_i = pre_i.Replace("%f1", file_prueba2); - } - } - - while (pre_i.Contains("%f2")) - { - if (pre_i.Contains("%f2")) - { - file_prueba2 = file_prueba2.Replace("\\", "/\\"); - file_prueba2 = file_prueba2.Replace(":", "\\\\://\\"); - pre_i = pre_i.Replace("%f2", Path.Combine(Path.GetDirectoryName(file_prueba2), Path.GetFileNameWithoutExtension(file_prueba2))); - } - } - - String second_path = ""; - if (textbox_params == "nul") - { - String[] split = txt_parameters.Text.Split(' '); - for (int i = 0; i < split.Length; i++) - { - if (split[i].Contains("\\") == true) - { - String pre_path = split[i].Replace("%fp", Path.GetDirectoryName(file_prueba2)).Replace("%fn", Path.GetFileNameWithoutExtension(file_prueba2)).Replace("%", "_"); - second_path = Path.GetDirectoryName(pre_path.Replace('\u0022', ' ')); - - if (!Directory.Exists(second_path)) - { - try - { - Directory.CreateDirectory(second_path); - } - catch - { - } - } - } - } - } - - consola.StartInfo.FileName = "ffmpeg.exe"; - consola.StartInfo.Arguments = pre_i + " " + hw_decode_glob + " -i " + "" + '\u0022' + file_prueba + '\u0022' + " -t 0.2" + " -y " + textbox_params + " " + '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file_prueba) + ext_output + '\u0022' + " -loglevel warning -stats"; - - if (textbox_params.Contains("[[split_chapters]]")) consola.StartInfo.Arguments = consola.StartInfo.Arguments.Replace("[[split_chapters]]", ""); - - - String test = consola.StartInfo.Arguments; - if (ext_output == "nul") consola.StartInfo.Arguments = pre_i + " " + hw_decode_glob + " -loglevel warning -stats" + " -i " + '\u0022' + file_prueba + '\u0022' + " -y " + textbox_params; - - consola.StartInfo.RedirectStandardError = true; - consola.StartInfo.StandardErrorEncoding = Encoding.UTF8; - consola.StartInfo.UseShellExecute = false; - consola.StartInfo.CreateNoWindow = true; - consola.EnableRaisingEvents = true; - consola.StartInfo.WorkingDirectory = Application.StartupPath; - consola.Start(); - this.InvokeEx(f => boton_ok_ff.Text = Strings.close_win); - - while (!consola.StandardError.EndOfStream) - { - this.Invoke(new MethodInvoker(delegate - { - LB1_o_try.Items.Add(consola.StandardError.ReadLine()); - LB1_o_try.TopIndex = LB1_o_try.Items.Count - 1; - LB1_o_try.Refresh(); - })); - } - - //consola.WaitForExit(); - consola.StartInfo.Arguments = String.Empty; - - if (consola.ExitCode == 0) - { - consola.StartInfo.Arguments = String.Empty; - LB1_o_try.Items.Add(""); - LB1_o_try.Items.Add(Strings.ff_test_ok); - LB1_o_try.TopIndex = LB1_o_try.Items.Count - 1; - LB1_o_try.BackColor = Color.LightGreen; - LB1_o_try.SetSelected(LB1_o_try.Items.Count - 1, true); - this.Invoke(new MethodInvoker(delegate - { - btn_try_pr.Image = img_try.Images[1]; - btn_try_pr.Enabled = true; - this.Cursor = Cursors.Arrow; - this.Enabled = true; - })); - - //frm_output2.ShowDialog(); - - String borrar1 = destino + "\\" + Path.GetFileNameWithoutExtension(file_prueba) + "." + txt_format.Text; - - if (File.Exists(borrar1)) - { - try { File.Delete(borrar1); } catch { } - } - - return; - } - else - { - this.InvokeEx(f => this.Enabled = false); - consola.StartInfo.Arguments = String.Empty; - if (timed_out == false) - { - this.Invoke(new MethodInvoker(delegate - { - btn_try_pr.Image = img_try.Images[2]; - LB1_o_try.Items.Add(""); - LB1_o_try.Items.Add(Strings.enc_test_fail); - LB1_o_try.TopIndex = LB1_o_try.Items.Count - 1; - LB1_o_try.BackColor = Color.LightSalmon; - LB1_o_try.SetSelected(LB1_o_try.Items.Count - 1, true); - this.Cursor = Cursors.Arrow; - })); - - if (failed == false) - { - frm_output2.ShowDialog(); - } - String borrar2 = destino + "\\" + Path.GetFileNameWithoutExtension(file_prueba) + "." + txt_format.Text; - - if (File.Exists(borrar2)) - { - try { File.Delete(borrar2); } catch { } - } - - return; - } - } - }); - - if (!tt.Wait(6000) && consola.StartInfo.Arguments != String.Empty) - { - failed = true; - timed_out = true; - consola.Kill(); - LB1_o_try.Items.Add(""); - LB1_o_try.Items.Add(Strings.ff_test_ok); - LB1_o_try.TopIndex = LB1_o_try.Items.Count - 1; - LB1_o_try.BackColor = Color.LightGreen; - this.Invoke(new MethodInvoker(delegate - { - LB1_o_try.SetSelected(LB1_o_try.Items.Count - 1, true); - this.Cursor = Cursors.Arrow; - btn_try_pr.Image = img_try.Images[1]; - btn_try_pr.Enabled = true; - this.Enabled = true; - frm_output2.Refresh(); - })); - } - - String borrar = destino + "\\" + Path.GetFileNameWithoutExtension(file_prueba) + "." + txt_format.Text; - - if (File.Exists(borrar)) - { - try - { - File.Delete(borrar); - } - catch { } - } - } - - private void cti6_Click(object sender, EventArgs e) - { - if (listView1.Items[listView1.SelectedIndices[0]].SubItems[5].Text != Strings.success && listView1.Items[listView1.SelectedIndices[0]].SubItems[5].Text != Strings.queued && listView1.Items[listView1.SelectedIndices[0]].SubItems[5].Text != Strings.aborted && listView1.Items[listView1.SelectedIndices[0]].SubItems[5].Text != Strings.skipped) - { - if (multi_running == false) - { - foreach (Process proc in procs.Values) - { - try - { - StreamWriter write_q = proc.StandardInput; - write_q.Write("q"); - } - catch { } - } - aborted_url = true; - listView1.Items[listView1.SelectedIndices[0]].SubItems[5].Text = Strings.aborting; - skipped = true; - return; - } - else - { - foreach (ListViewItem item in listView1.SelectedItems) - { - skipped = true; - aborted_url = true; - item.SubItems[5].Text = Strings.aborting; - try - { - StreamWriter write_q = procs["proc_urls_" + item.Index.ToString()].StandardInput; - write_q.Write("q"); - } catch { } - } - return; - } - } - } - - private void combo_prio_SelectedIndexChanged(object sender, EventArgs e) - { - btn_save_prio.Enabled = true; - if (just_started == true) btn_save_prio.Enabled = false; - just_started = false; - //mem_prio.SelectedItem = combo_prio.SelectedItem; - - if (combo_prio.SelectedIndex == current_prio) - { - btn_save_prio.Enabled = false; - } - else - { - btn_save_prio.Enabled = true; - } - - if (working == true) - { - System.Threading.Thread.Sleep(50); - Change_mem_prio(); - } - if (btn_save_prio.Enabled == false) - { - current_save_prio = false; - } - else - { - current_save_prio = true; - } - if (combo_prio.SelectedIndex != 2) lbl_cpu_pr.Enabled = true; - else lbl_cpu_pr.Enabled = false; - } - - private void Change_mem_prio() - { - if (working == true) System.Threading.Thread.Sleep(500); - - int tab = 0; - tabControl1.Invoke(new MethodInvoker(delegate - { - tab = tabControl1.SelectedIndex; - })); - - if (tab == 2) - { - if (working == true) - { - try - { - foreach (Process proc in procs.Values) - { - if (combo_prio.SelectedIndex == 0) proc.PriorityClass = ProcessPriorityClass.High; - if (combo_prio.SelectedIndex == 1) proc.PriorityClass = ProcessPriorityClass.AboveNormal; - if (combo_prio.SelectedIndex == 2) proc.PriorityClass = ProcessPriorityClass.Normal; - if (combo_prio.SelectedIndex == 3) proc.PriorityClass = ProcessPriorityClass.BelowNormal; - if (combo_prio.SelectedIndex == 4) proc.PriorityClass = ProcessPriorityClass.Idle; - } - } - catch { } - } - } - - if (tab == 0) - { - if (working == true && multi_running == false) - { - try - { - foreach (Process proc in procs.Values) - { - if (combo_prio.SelectedIndex == 0) proc.PriorityClass = ProcessPriorityClass.High; - if (combo_prio.SelectedIndex == 1) proc.PriorityClass = ProcessPriorityClass.AboveNormal; - if (combo_prio.SelectedIndex == 2) proc.PriorityClass = ProcessPriorityClass.Normal; - if (combo_prio.SelectedIndex == 3) proc.PriorityClass = ProcessPriorityClass.BelowNormal; - if (combo_prio.SelectedIndex == 4) proc.PriorityClass = ProcessPriorityClass.Idle; - } - } - catch - { - } - } - - if (working == true && multi_running == true) - { - Process[] localFFB = Process.GetProcessesByName("FFBatch"); - foreach (Process proc in localFFB) - { - var proc_child = proc.GetChildProcesses(); - - foreach (Process proc_ch in proc_child) - { - if (combo_prio.SelectedIndex == 0) proc_ch.PriorityClass = ProcessPriorityClass.High; - if (combo_prio.SelectedIndex == 1) proc_ch.PriorityClass = ProcessPriorityClass.AboveNormal; - if (combo_prio.SelectedIndex == 2) proc_ch.PriorityClass = ProcessPriorityClass.Normal; - if (combo_prio.SelectedIndex == 3) proc_ch.PriorityClass = ProcessPriorityClass.BelowNormal; - if (combo_prio.SelectedIndex == 4) proc_ch.PriorityClass = ProcessPriorityClass.Idle; - Process[] localByName = Process.GetProcessesByName("FFBatch"); - if (localByName.Length == 1) - { - foreach (Process proc1 in localByName) - { - if (combo_prio.SelectedIndex >= 2) proc1.PriorityClass = ProcessPriorityClass.Normal; - else proc1.PriorityClass = proc_ch.PriorityClass; - } - } - } - } - } - } - - if (tab == 3) - { - if (working == true && m3u_single_running == true) - { - try - { - foreach (Process proc in procs.Values) - { - if (combo_prio.SelectedIndex == 0) proc.PriorityClass = ProcessPriorityClass.High; - if (combo_prio.SelectedIndex == 1) proc.PriorityClass = ProcessPriorityClass.AboveNormal; - if (combo_prio.SelectedIndex == 2) proc.PriorityClass = ProcessPriorityClass.Normal; - if (combo_prio.SelectedIndex == 3) proc.PriorityClass = ProcessPriorityClass.BelowNormal; - if (combo_prio.SelectedIndex == 4) proc.PriorityClass = ProcessPriorityClass.Idle; - } - } - catch - { - } - } - if (working == true && m3u_running == true) - { - Process[] localFFB = Process.GetProcessesByName("FFBatch"); - foreach (Process proc in localFFB) - { - var proc_child = proc.GetChildProcesses(); - - foreach (Process proc_ch in proc_child) - { - if (combo_prio.SelectedIndex == 0) proc_ch.PriorityClass = ProcessPriorityClass.High; - if (combo_prio.SelectedIndex == 1) proc_ch.PriorityClass = ProcessPriorityClass.AboveNormal; - if (combo_prio.SelectedIndex == 2) proc_ch.PriorityClass = ProcessPriorityClass.Normal; - if (combo_prio.SelectedIndex == 3) proc_ch.PriorityClass = ProcessPriorityClass.BelowNormal; - if (combo_prio.SelectedIndex == 4) proc_ch.PriorityClass = ProcessPriorityClass.Idle; - - Process[] localByName = Process.GetProcessesByName("FFBatch"); - if (localByName.Length == 1) - { - foreach (Process proc1 in localByName) - { - if (combo_prio.SelectedIndex >= 2) proc1.PriorityClass = ProcessPriorityClass.Normal; - else proc1.PriorityClass = proc_ch.PriorityClass; - } - } - } - } - } - } - } - - private void btn_reset_path_Click(object sender, EventArgs e) - { - Pg1.Focus(); - txt_path_main.Text = ".\\FFBatch"; - txt_path_mux.Text = ".\\FFBatch"; - txt_path_main.BackColor = groupBox1.BackColor; - txt_path_mux.BackColor = groupBox1.BackColor; - String path_s = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_path.ini"; - if (is_portable == true) path_s = port_path + "ff_path_portable.ini"; - if (File.Exists(path_s)) - { - File.Delete(path_s); - btn_save_path.Enabled = true; - } - else - { - btn_save_path.Enabled = false; - } - } - - public class WebClientWithTimeout : WebClient - { - protected override WebRequest GetWebRequest(Uri address) - { - WebRequest wr = base.GetWebRequest(address); - wr.Timeout = 5000; // timeout in milliseconds (ms) - return wr; - } - } - - private void btn_update_Click(object sender, EventArgs e) - { - Pg1.Focus(); - lbl_updates.Text = String.Empty; - String current_ver = btn_update.Text; - btn_update.Refresh(); - String content1 = String.Empty; - - try - { - WebClient client = new WebClientWithTimeout(); - Stream stream = client.OpenRead(down_ver); - StreamReader reader = new StreamReader(stream); - String content = reader.ReadToEnd(); - content1 = content; - } - catch - { - try - { - //Backup server - WebClient client = new WebClientWithTimeout(); - Stream stream = client.OpenRead(down_ver2); - StreamReader reader = new StreamReader(stream); - String content = reader.ReadToEnd(); - content1 = content; - } - catch - { - this.InvokeEx(f => f.lbl_updates.Text = Strings.up_err); - this.InvokeEx(f => f.btn_update.Text = current_ver); - return; - } - } - - try - { - if (Convert.ToInt16(content1.Replace(".", String.Empty).Substring(0, 3)) > Convert.ToInt16(Application.ProductVersion.Replace(".", String.Empty))) - { - String f_skip_ver = String.Empty; - if (is_portable == false) - { - f_skip_ver = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_skip_ver.ini"; - } - else - { - f_skip_ver = port_path + "ff_skip_ver_portable.ini"; - } - - Form21 frm21 = new Form21(); - frm21.lbl_ver.Text = Strings.version + " " + content1.Substring(0, 5); - frm21.textBox1.Text = content1.Substring(6, content1.Length - 6); - //frm211.textBox1.Font = new Font(FontFamily.GenericMonospace, frm211.textBox1.Font.Size); - frm21.ShowDialog(this); - if (frm21.cancel == false && frm21.update == true && frm21.skip_ver == false) - { - try - { - File.Delete(f_skip_ver); - } - catch { } - - Process.Start("https://sourceforge.net/p/ffmpeg-batch/wiki"); - } - if (frm21.cancel == false && frm21.update == false && frm21.skip_ver == true) - { - try - { - File.WriteAllText(f_skip_ver, content1.Substring(0, 5)); - } - catch (Exception excpt) - { - MessageBox.Show(Strings.skip_err + Environment.NewLine + Environment.NewLine + excpt.Message, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - else - { - MessageBox.Show(Strings.latestv + Environment.NewLine + Environment.NewLine + "FFmpeg Batch A/V Converter version " + content1.Substring(0, 5), Strings.up1, MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } - catch (Exception excpt) - { - DialogResult a = MessageBox.Show(Strings.err_check + Environment.NewLine + Environment.NewLine + excpt.Message + Environment.NewLine + Environment.NewLine + Strings.check_web_up, Strings.error, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Error); - if (a == DialogResult.Yes) Process.Start(proj_web); - } - - btn_update.Text = current_ver; - } - - private void check_sort_dur() - { - //Sort by duration - String f_sort_dur = String.Empty; - if (is_portable == false) - { - f_sort_dur = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_sort_dur.ini"; - } - else - { - f_sort_dur = port_path + "ff_sort_dur_portable.ini"; - } - - if (!File.Exists(f_sort_dur)) - { - tip_sort_dur = false; - sort_multi_dur = false; - } - else - { - tip_sort_dur = true; - sort_multi_dur = true; - } - - //End Sort by duration - } - - private void btn_multi_m_Click(object sender, EventArgs e) - - { - Pg1.Focus(); - - lbl_est_size.Text = ""; - lbl_bitrate.Text = ""; - - Pg1.Text = "0" + CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - - was_started.Text = btn_multi_m.Text; - if (listView1.Items.Count == 1) - { - btn_seq.PerformClick(); - return; - } - - cancelados_paralelos = false; - - if (no_warn_0_dur == false) - { - foreach (ListViewItem file in listView1.Items) - { - if (!File.Exists(file.SubItems[1].Text + "\\" + file.Text)) - { - MessageBox.Show(Strings.file_not_found + " " + file.Text, Strings.file_not_found2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - } - - if (listView1.Items.Count == 0) - { - MessageBox.Show(Strings.list_empty, Strings.no_files, MessageBoxButtons.OK, MessageBoxIcon.Information); - return; - } - - if (!File.Exists(Path.Combine(Application.StartupPath, "ffmpeg.exe"))) - { - MessageBox.Show(Strings.no_ffmpeg, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (check_ff_md5() == false) - { - Form25 frm25 = new Form25(); - frm25.ShowDialog(); - return; - } - - if (ss_time_input.Text != "0:00:00.000" && Settings.Default.quick_queue == false) - { - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[3].Text != Strings.n_a && item.SubItems[3].Text != "0:00:00" && item.SubItems[3].Text != "00:00:00" && item.SubItems[3].Text != Strings.pending) - { - if (TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds <= TimeSpan.Parse(ss_time_input.Text).TotalSeconds) - { - MessageBox.Show(Strings.pre_input3 + " " + '\u0022' + Path.GetFileName(item.Text) + '\u0022', Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - } - } - - if (dur_ok == false && Settings.Default.quick_queue == false) - { - list_pending_dur.Clear(); - foreach (ListViewItem item in listView1.Items) - { - list_pending_dur.Items.Add((ListViewItem)item.Clone()); - } - BG_Dur.RunWorkerAsync(); - return; - } - - avoid_overw(); - - //Check path is writable - String destino1 = String.Empty; - Boolean rel_path = false; - String lv1 = listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text; - if (txt_path_main.Text.Contains(".\\")) - { - destino1 = lv1.Substring(0, lv1.LastIndexOf('\\')) + txt_path_main.Text.Replace(".", String.Empty); - rel_path = true; - } - else - { - if (chk_recreate.CheckState == CheckState.Checked) - { - String pre_dest = Path.GetDirectoryName(lv1); - if (pre_dest.Substring(0, 2) == "\\\\") destino1 = Path.Combine(txt_path_main.Text, pre_dest.Substring(2, pre_dest.Length - 2)); - else destino1 = Path.Combine(txt_path_main.Text, pre_dest.Substring(3, pre_dest.Length - 3)); - rel_path = true; - } - else - { - destino1 = txt_path_main.Text; - } - } - - try - { - if (rel_path == true) - { - Directory.CreateDirectory(destino1); - System.Threading.Thread.Sleep(10); - } - else - { - if (!Directory.Exists(destino1)) Directory.CreateDirectory(destino1); - File.WriteAllText(destino1 + "\\" + "FFBatch_test.txt", "FFBatch_test"); - System.Threading.Thread.Sleep(10); - File.Delete(destino1 + "\\" + "FFBatch_test.txt"); - } - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.write_error1 + " " + excpt.Message, Strings.write_error2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - //End path is writable - - if (all_enc() == true && ignore_encoded == true) return; - - //Sort by duration - - if (Settings.Default.quick_queue == false) check_sort_dur(); - - String f_sort_dur = String.Empty; - if (is_portable == false) - { - f_sort_dur = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_sort_dur.ini"; - } - else - { - f_sort_dur = port_path + "ff_sort_dur_portable.ini"; - } - - if (File.Exists(f_sort_dur)) - { - try - { - if (File.ReadAllText(f_sort_dur) == Strings.yes) - { - lvwColumnSorter_Full.SortColumn = 3; - lvwColumnSorter_Full.Order = SortOrder.Descending; - this.listView1.Sort(); - } - } - catch - { - } - } - - if (tip_sort_dur == false && Settings.Default.quick_queue == false) - { - DialogResult a = MessageBox.Show(Strings.sort_list2 + Environment.NewLine + Environment.NewLine + Strings.sort_list, Strings.sort_list2, MessageBoxButtons.YesNo, MessageBoxIcon.Question); - if (a == DialogResult.Yes) - { - lvwColumnSorter_Full.SortColumn = 3; - lvwColumnSorter_Full.Order = SortOrder.Descending; - this.listView1.Sort(); - File.WriteAllText(f_sort_dur, Strings.yes); - } - else - { - File.WriteAllText(f_sort_dur, Strings.no); - } - tip_sort_dur = true; - } - - //Validated list, start processing - - if (fade_v_in.Checked == true || fade_v_out.Checked == true || fade_a_in.Checked == true || fade_a_out.Checked == true) - { - MessageBox.Show(Strings.fadein1, Strings.warning, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; - } - - txt_remain.Text = ""; - txt_remain.Refresh(); - total_time = true; - n_th_suffix = String.Empty; - n_th_source_ext = String.Empty; - - if (listView1.SelectedIndices.Count == 0) - { - listView1.Items[0].Selected = true; - listView1.Items[0].Focused = true; - listView1.Focus(); - } - - //Save selected hw decoder - - String path2 = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_hw_dcd.ini"; - if (is_portable == true) - { - path2 = port_path + "ff_hw_dcd_portable.ini"; - } - String txt_hw_dcd = cb_hwdecode.SelectedItem.ToString(); - if (txt_hw_dcd != "none") - { - File.WriteAllText(path2, txt_hw_dcd); - } - else - { - if (File.Exists(path2)) File.Delete(path2); - } - - //End save hw decoder - - ////Try preset - foreach (String item in tried_params) - { - if (item == (txt_parameters.Text)) - { - tried_ok = true; - } - } - - if (tried_ok == false) - { - try - { - BG_Try_preset.RunWorkerAsync(); - } - catch - { - tried_ok = true; - } - return; - } - tried_ok = false; - - //Remove test file/folder - String file_prueba = ""; - String sel_test = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - file_prueba = sel_test; - String destino = Path.GetTempPath() + "\\" + "FFBatch_test"; - String borrar = destino + "\\" + Path.GetFileNameWithoutExtension(file_prueba) + "." + txt_format.Text; - - if (File.Exists(borrar)) - { - try - { - File.Delete(borrar); - } - catch { } - } - - //END try preset - - //Save selected theads - - String path = String.Empty; - if (is_portable == false) - { - path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_nthreads.ini"; - } - else - { - path = port_path + "ff_nthreads_portable.ini"; - } - - String txt_threads = String.Empty; - txt_threads = n_threads.Value.ToString(); - File.WriteAllText(path, txt_threads); - //End save selected threads - - if (to_overwrite() == false) return; - - //Check queued items - - if (warn_success_items == true) - { - Boolean has_complete = false; - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[5].Text != Strings.queued) - { - has_complete = true; - break; - } - } - - if (has_complete == true) - { - DialogResult a = MessageBox.Show(Strings.already_encoded + " " + '\u0022' + Strings.queued + '\u0022' + " " + Strings.reset_items + Environment.NewLine + Environment.NewLine + Strings.cont_any, Strings.some_q, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); - if (a == DialogResult.Cancel || a == DialogResult.No) - { - return; - } - } - } - else - { - if (ignore_encoded == false) foreach (ListViewItem item in listView1.Items) item.SubItems[5].Text = Strings.queued; - } - //End check queued items - - //Verify names will not cause overwrite - if (txt_format.Text != String.Empty) - { - if (dups_lv1() == true) return; - } - - String is_overw = txt_path_main.Text + "\\" + Path.GetFileNameWithoutExtension(listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text) + "." + txt_format.Text; - - if (is_overw == listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text && chk_suffix.Checked == false) - { - if (chk_overw.CheckState == CheckState.Unchecked) - { - MessageBox.Show(Strings.overw_not_en + " " + '\u0022' + Strings.ren_out + '\u0022' + " " + Strings.checkb, Strings.overw_not_all, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - - if (txt_parameters.Text.Contains("libx264") || txt_parameters.Text.Contains("libx265") || txt_parameters.Text.Contains("jpeg2000") || txt_parameters.Text.Contains("libtheora") || txt_parameters.Text.Contains("libxvid") || txt_parameters.Text.Contains("mpeg2") || txt_parameters.Text.Contains("webp") || txt_parameters.Text.Contains("mpeg4") || txt_parameters.Text.Contains("libvpx") || txt_parameters.Text.Contains("prores")) - { - if (n_threads.Value > 4 && listView1.Items.Count > 4) - { - DialogResult a = MessageBox.Show(Strings.multi_vid, Strings.question, MessageBoxButtons.YesNo, MessageBoxIcon.Question); - if (a == DialogResult.No) return; - } - } - - cancel_queue = false; - cancelados_paralelos = false; - group_prog.Focus(); - - - LB_Wait.Text = String.Empty; - LB_Wait.Visible = false; - pg_adding.Visible = false; - txt_adding_p.Text = String.Empty; - multi_dest = destino; - - notifyIcon1.Visible = true; - Pg1.Value = 0; - Pg1.Maximum = listView1.Items.Count * 100; - Pg1.Text = ""; - lbl_elapsed.Text = Strings.time_elapsed + " " + "00h:00m:00s"; - - if (BG_Multi_M.IsBusy) - { - BG_Multi_M.Dispose(); - return; - } - - listView1.Items[0].Selected = true; - pic_no_errors.Visible = false; - pic_warnings.Visible = false; - pic_recording.Visible = false; - errors_enc = 0; - start_total_time = 0; - time_n_tasks = 0; - timer_tasks.Start(); - timer1.Start(); - multi_running = true; - working = true; - timer_queue.Enabled = true; - - atempo = String.Empty; - if (txt_parameters.Text.ToLower().Contains("atempo=")) - { - int at_ind = txt_parameters.Text.LastIndexOf("atempo=") + 7; - int at_end = 0; - Boolean end_char = false; - - for (int i = 0; i < txt_parameters.Text.Length - at_ind; i++) - { - if (txt_parameters.Text.Substring(at_ind + i, 1) == "," || txt_parameters.Text.Substring(at_ind + i, 1) == "\u0022" || txt_parameters.Text.Substring(at_ind + i, 1) == "'" || txt_parameters.Text.Substring(at_ind + i, 1) == " " || txt_parameters.Text.Substring(at_ind + i, 1) == "[") - { - at_end = at_ind + i; - end_char = true; - break; - } - } - - if (end_char == true) atempo = txt_parameters.Text.Substring(at_ind, at_end - at_ind); - else if (at_ind + 2 == txt_parameters.Text.Length) - { - atempo = txt_parameters.Text.Substring(at_ind, 2); - } - else if (at_ind + 3 == txt_parameters.Text.Length) - { - atempo = txt_parameters.Text.Substring(at_ind, 3); - } - - else if (at_ind + 4 == txt_parameters.Text.Length) - { - atempo = txt_parameters.Text.Substring(at_ind, 4); - } - else atempo = String.Empty; - } - - //Total duration - total_multi_duration = 0; - - ss_to = false; - if (txt_pre_input.Text.Contains("-ss") || txt_pre_input.Text.Contains("-t")) ss_to = true; - int new_ssto = 0; - - if (Settings.Default.quick_queue == false) - { - foreach (ListViewItem item in listView1.Items) - { - DateTime time2; - if (DateTime.TryParse(item.SubItems[3].Text, out time2)) - - { - if (ss_to == true) - { - new_ssto = get_ss_to(txt_pre_input.Text, TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds); - - if (new_ssto > 0) total_multi_duration = total_multi_duration + new_ssto - TimeSpan.Parse(ss_time_input.Text).TotalSeconds; - else total_multi_duration = total_multi_duration + TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds - TimeSpan.Parse(ss_time_input.Text).TotalSeconds; - } - else total_multi_duration = total_multi_duration + TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds - TimeSpan.Parse(ss_time_input.Text).TotalSeconds; - } - } - } - - atemp = 1; - if (atempo != String.Empty) - { - if (Double.TryParse(atempo, out atemp) == true) - { - atemp = Convert.ToDouble(atempo, System.Globalization.CultureInfo.InvariantCulture); - total_multi_duration = total_multi_duration / atemp; - } - } - //End total duration - - //Custom item params - custom_m_params.Clear(); - if (cust_p_col != 0) - { - try - { - foreach (ListViewItem it in listView1.Items) - { - custom_m_params.Add(it.SubItems[cust_p_col].Text); - } - } - catch { } - } - - //End custom item params - filter_chars(); - lbl_items.Text = "0 " + Strings.of1 + " " + listView1.Items.Count.ToString(); - timer_queue.Enabled = true; - BG_Multi_M.RunWorkerAsync(); - } - - private void textBox2_KeyUp(object sender, KeyEventArgs e) - { - if (e.KeyCode == Keys.Enter) - { - btn_seq.PerformClick(); - } - } - - private void extract_streams_job() - { - Pg1.Focus(); - cancel_queue = false; - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - - foreach (ListViewItem file in list_tracks.Items) - { - if (!File.Exists(file.Text)) - { - MessageBox.Show(Strings.file_not_found + " " + file.Text, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - - String is_overw = txt_path_main.Text + "\\" + Path.GetFileNameWithoutExtension(list_tracks.Items[0].Text) + "." + txt_track_format; - - if (is_overw == list_tracks.Items[0].Text) - { - MessageBox.Show(Strings.overw_main, Strings.overw_not_all, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - DateTime time2; - if (!DateTime.TryParse(ss_time_input.Text, out time2)) - { - MessageBox.Show(Strings.pre_input4, Strings.pre_input2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - //Validated list, start processing - //Pending duration - - if (dur_ok == false) - { - list_pending_dur.Items.Clear(); - foreach (ListViewItem item in listView1.Items) - { - list_pending_dur.Items.Add((ListViewItem)item.Clone()); - } - BG_Dur.RunWorkerAsync(); - return; - } - - //Copy list of tracks for thread processing - - //End of copy list of tracks for thread processing - - Double total_duration = 0; - Double total_prog = 0; - - //Duration - - this.Cursor = Cursors.WaitCursor; - - List durations = new List(); - String duracion = String.Empty; - - foreach (ListViewItem item in list_tracks.Items) - { - Process probe = new Process(); - probe.StartInfo.FileName = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - String ffprobe_frames1 = " " + '\u0022' + "--Inform=General;%Duration/String3%" + '\u0022'; - probe.StartInfo.Arguments = ffprobe_frames1 + " " + '\u0022' + item.Text + '\u0022'; - - probe.StartInfo.RedirectStandardOutput = true; - probe.StartInfo.UseShellExecute = false; - probe.StartInfo.CreateNoWindow = true; - probe.EnableRaisingEvents = true; - probe.Start(); - - duracion = probe.StandardOutput.ReadLine(); - - probe.WaitForExit(); - - if (duracion != null) - { - DateTime time; - if (DateTime.TryParse(duracion, out time)) - { - //total_duration = Convert.ToDouble(duracion.Substring(0, 7)); - - durat_n = TimeSpan.Parse(duracion).TotalSeconds; - durations.Add(durat_n); - total_duration = total_duration + durat_n; - - //total_duration = durat_n; - } - } - else - { - durat_n = 0; - durations.Add(0); - //total_duration = 0; - } - - //End duration - } - - //End - - Pg1.Minimum = 0; - Pg1.Maximum = 100; - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - lbl_speed.Text = String.Empty; - - List list_lines = new List(); - String mux_ext = txt_track_format.Text; - - pic_no_errors.Visible = false; - pic_recording.Visible = false; - pic_warnings.Visible = false; - - time_est_size = 0; - String err_txt = ""; - timer_est_size.Start(); - - String destino = ""; - int count = 0; - - foreach (ListViewItem item in list_tracks.Items) - { - String remain_time = "0"; - - String ffm = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - - String file = item.Text; - String fullPath = file; - count = count + 1; - - //Track extension - string ext_track = item.SubItems[2].Text.ToLower(); - - if (ext_track.Contains("h264")) mux_ext = "m4v"; - else if (ext_track.Contains("h265")) mux_ext = "mkv"; - else if (ext_track.Contains("hevc")) mux_ext = "mkv"; - else if (ext_track.Contains("webm")) mux_ext = "webm"; - else if (ext_track.Contains("rawvideo")) mux_ext = "avi"; - else if (ext_track.Contains("divx")) mux_ext = "avi"; - else if (ext_track.Contains("xvid")) mux_ext = "avi"; - else if (ext_track.Contains("mov")) mux_ext = "mov"; - else if (ext_track.Contains("aac")) mux_ext = "aac"; - else if (ext_track.Contains("m4a")) mux_ext = "m4a"; - else if (ext_track.Contains("ac3")) mux_ext = "ac3"; - else if (ext_track.Contains("mp3")) mux_ext = "mp3"; - else if (ext_track.Contains("pcm")) mux_ext = "wav"; - else if (ext_track.Contains("flac")) mux_ext = "flac"; - else if (ext_track.Contains("truehd")) mux_ext = "thd"; - else if (ext_track.Contains("dts")) mux_ext = "dts"; - else if (ext_track.Contains("vp7")) mux_ext = "webm"; - else if (ext_track.Contains("vp8")) mux_ext = "webm"; - else if (ext_track.Contains("vp9")) mux_ext = "webm"; - else if (ext_track.Contains("wma")) mux_ext = "wma"; - else if (ext_track.Contains("wvc1")) mux_ext = "wmv"; - else if (ext_track.Contains("vorbis")) mux_ext = "ogg"; - else if (ext_track.Contains("theora")) mux_ext = "ogv"; - else if (ext_track.Contains("mjpeg")) mux_ext = "jpg"; - else if (ext_track.Contains("subrip")) mux_ext = "srt"; - else if (ext_track.Contains("ass")) mux_ext = "ass"; - else mux_ext = "mkv"; - - //End Stream format - - destino = ""; - - if (txt_path_main.Text.Contains(".\\")) - { - destino = file.Substring(0, fullPath.LastIndexOf('\\')) + txt_path_main.Text.Replace(".", String.Empty); ; - } - else - { - destino = txt_path_main.Text; - } - - if (!Directory.Exists(destino)) - { - try - { - Directory.CreateDirectory(destino); - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.error2 + " " + excpt.Message, Strings.write_error2, MessageBoxButtons.OK, MessageBoxIcon.Error); - this.Cursor = Cursors.Arrow; - Enable_Controls(); - working = false; - return; - } - } - - //Create joint inputs variable - String inputs = String.Empty; - - String stream_type = String.Empty; - if (item.SubItems[2].Text.ToLower().Contains("subtitle")) - { - stream_type = "s"; - } - - if (item.SubItems[2].Text.ToLower().Contains("audio")) - { - stream_type = "a"; - } - if (item.SubItems[2].Text.ToLower().Contains("video")) - { - stream_type = "v"; - } - //{ - //inputs = inputs + " -sub_charenc UTF-8" + " -i " + '\u0022' + input_item.Text + '\u0022'; - //} - inputs = " -i " + '\u0022' + item.Text + '\u0022'; - - //End create joint inputs variable - - String dur = ""; - TimeSpan t_dur = TimeSpan.FromSeconds(durat_n); - dur = string.Format("{0:D2}:{1:D2}:{2:D2}", - (int)t_dur.TotalHours, - t_dur.Minutes, - t_dur.Seconds); - - String output_file = '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file) + "_" + stream_type + "_demux_" + count.ToString() + "." + mux_ext + '\u0022'; - String AppParam = inputs + " -map 0:" + item.SubItems[1].Text + " -c copy " + "-y "; - - frm_mux_jobs.dg_pr.Rows.Add(frm_mux_jobs.dg_pr.RowCount + 1, Path.GetFileName(list_tracks.Items[0].Text), AppParam, list_tracks.Items.Count.ToString(), dur, output_file); - - try - { - Task t = Task.Run(() => - { - try - { - Directory.Delete(destino); - } - catch { } - }); - } - catch { } - btn_mux_show_jobs.Enabled = true; - if (frm_mux_jobs.dg_pr.RowCount > 0) lbl_mux_jobs.Text = Strings.jobs + " " + frm_mux_jobs.dg_pr.RowCount; - else lbl_mux_jobs.Text = String.Empty; - } - } - - private void extract_streams() - { - Pg1.Focus(); - cancel_queue = false; - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - - foreach (ListViewItem file in list_tracks.Items) - { - if (!File.Exists(file.Text)) - { - MessageBox.Show(Strings.file_not_found + " " + file.Text, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - - String is_overw = txt_path_main.Text + "\\" + Path.GetFileNameWithoutExtension(list_tracks.Items[0].Text) + "." + txt_track_format; - - if (is_overw == list_tracks.Items[0].Text) - { - MessageBox.Show(Strings.overw_main, Strings.overw_not_all, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - DateTime time2; - if (!DateTime.TryParse(ss_time_input.Text, out time2)) - { - MessageBox.Show(Strings.pre_input4, Strings.pre_input2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - //Validated list, start processing - //Pending duration - - if (dur_ok == false) - { - list_pending_dur.Items.Clear(); - foreach (ListViewItem item in listView1.Items) - { - list_pending_dur.Items.Add((ListViewItem)item.Clone()); - } - BG_Dur.RunWorkerAsync(); - return; - } - - Disable_Controls(); - txt_remain.Text = Strings.remain_time + " " + "00h:00m:00s"; - time_n_tasks = 0; - lbl_elapsed.Text = Strings.time_elapsed + " " + "00h:00m:00s"; - timer_tasks.Start(); - - cancel_queue = false; - Pg1.Value = 0; - //pg_current.Value = 0; - //textBox4.Text = "0%"; - - working = true; - - //Copy list of tracks for thread processing - ListView list_proc = new ListView(); - foreach (ListViewItem item in list_tracks.SelectedItems) - { - list_proc.Items.Add((ListViewItem)item.Clone()); - } - //End of copy list of tracks for thread processing - - Double total_duration = 0; - Double total_prog = 0; - - //Duration - - List durations = new List(); - - procs.Clear(); - - for (int ii = 0; ii < list_proc.Items.Count; ii++) - { - procs.Add("proc_urls_" + ii.ToString(), new Process()); - } - - foreach (ListViewItem item in list_proc.Items) - { - Process probe = new Process(); - probe.StartInfo.FileName = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - String ffprobe_frames1 = " " + '\u0022' + "--Inform=General;%Duration/String3%" + '\u0022'; - probe.StartInfo.Arguments = ffprobe_frames1 + " " + '\u0022' + item.Text + '\u0022'; - - probe.StartInfo.RedirectStandardOutput = true; - probe.StartInfo.UseShellExecute = false; - probe.StartInfo.CreateNoWindow = true; - probe.EnableRaisingEvents = true; - probe.Start(); - - String duracion = probe.StandardOutput.ReadLine(); - - probe.WaitForExit(); - - if (duracion != null) - { - DateTime time; - if (DateTime.TryParse(duracion, out time)) - { - //total_duration = Convert.ToDouble(duracion.Substring(0, 7)); - - durat_n = TimeSpan.Parse(duracion).TotalSeconds; - durat_n = Math.Round(durat_n, 0); - durations.Add(durat_n); - total_duration = total_duration + durat_n; - //total_duration = durat_n; - } - } - else - { - durat_n = 0; - durations.Add(0); - //total_duration = 0; - } - - //End duration - } - - //End - - Pg1.Minimum = 0; - Pg1.Maximum = 100; - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - lbl_speed.Text = String.Empty; - - List list_lines = new List(); - String mux_ext = txt_track_format.Text; - - pic_no_errors.Visible = false; - pic_recording.Visible = false; - pic_warnings.Visible = false; - - time_est_size = 0; - String err_txt = ""; - timer_est_size.Start(); - - String destino = ""; - int count = 0; - Boolean is_ok = false; - - new System.Threading.Thread(() => - { - System.Threading.Thread.CurrentThread.IsBackground = true; - - foreach (ListViewItem item in list_proc.Items) - { - String remain_time = "0"; - String ffm = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - String file = item.Text; - String fullPath = file; - count = count + 1; - var tmp = procs["proc_urls_" + item.Index.ToString()]; - - //Track extension - string ext_track = item.SubItems[2].Text.ToLower(); - - if (ext_track.ToLower().Contains("h264")) mux_ext = "m4v"; - else if (ext_track.ToLower().Contains("h265")) mux_ext = "mkv"; - else if (ext_track.ToLower().Contains("hevc")) mux_ext = "mkv"; - else if (ext_track.ToLower().Contains("webm")) mux_ext = "webm"; - else if (ext_track.ToLower().Contains("rawvideo")) mux_ext = "avi"; - else if (ext_track.ToLower().Contains("divx")) mux_ext = "avi"; - else if (ext_track.ToLower().Contains("xvid")) mux_ext = "avi"; - else if (ext_track.ToLower().Contains("mov")) mux_ext = "mov"; - else if (ext_track.ToLower().Contains("aac")) mux_ext = "aac"; - else if (ext_track.ToLower().Contains("m4a")) mux_ext = "m4a"; - else if (ext_track.ToLower().Contains("ac3")) mux_ext = "ac3"; - else if (ext_track.ToLower().Contains("mp3")) mux_ext = "mp3"; - else if (ext_track.ToLower().Contains("pcm")) mux_ext = "wav"; - else if (ext_track.ToLower().Contains("flac")) mux_ext = "flac"; - else if (ext_track.ToLower().Contains("truehd")) mux_ext = "thd"; - else if (ext_track.ToLower().Contains("dts")) mux_ext = "dts"; - else if (ext_track.ToLower().Contains("vp7")) mux_ext = "webm"; - else if (ext_track.ToLower().Contains("vp8")) mux_ext = "webm"; - else if (ext_track.ToLower().Contains("vp9")) mux_ext = "webm"; - else if (ext_track.ToLower().Contains("wma")) mux_ext = "wma"; - else if (ext_track.ToLower().Contains("wvc1")) mux_ext = "wmv"; - else if (ext_track.ToLower().Contains("vorbis")) mux_ext = "ogg"; - else if (ext_track.ToLower().Contains("theora")) mux_ext = "ogv"; - else if (ext_track.ToLower().Contains("mjpeg")) mux_ext = "jpg"; - else if (ext_track.ToLower().Contains("subrip")) mux_ext = "srt"; - else if (ext_track.ToLower().Contains("ass")) mux_ext = "ass"; - else mux_ext = "mkv"; - - //End Stream format - - destino = ""; - - if (txt_path_main.Text.Contains(".\\")) - { - destino = file.Substring(0, fullPath.LastIndexOf('\\')) + txt_path_main.Text.Replace(".", String.Empty); ; - } - else - { - destino = txt_path_main.Text; - } - - if (!Directory.Exists(destino)) - { - try - { - Directory.CreateDirectory(destino); - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.error2 + " " + excpt.Message, Strings.write_error2, MessageBoxButtons.OK, MessageBoxIcon.Error); - this.Cursor = Cursors.Arrow; - Enable_Controls(); - working = false; - return; - } - } - - //Create joint inputs variable - String inputs = String.Empty; - - String stream_type = String.Empty; - if (item.SubItems[2].Text.ToLower().Contains("subtitle")) - { - stream_type = "s"; - } - - if (item.SubItems[2].Text.ToLower().Contains("audio")) - { - stream_type = "a"; - } - if (item.SubItems[2].Text.ToLower().Contains("video")) - { - stream_type = "v"; - } - //{ - //inputs = inputs + " -sub_charenc UTF-8" + " -i " + '\u0022' + input_item.Text + '\u0022'; - //} - inputs = " -i " + '\u0022' + item.Text + '\u0022' + " -map 0:" + item.SubItems[1].Text + " -c copy "; - - //End create joint inputs variable - - String AppParam = inputs + "-y " + '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file) + "_" + stream_type + "_demux_" + count.ToString() + "." + mux_ext + '\u0022'; - - if (!Directory.Exists(destino)) - { - Directory.CreateDirectory(destino); - } - - tmp.StartInfo.FileName = ffm; - tmp.StartInfo.Arguments = AppParam; - valid_prog = false; - - //this.InvokeEx(f => f.pg_current.Value = 0); - //this.InvokeEx(f => f.pg_current.Refresh()); - - - tmp.StartInfo.RedirectStandardError = true; - tmp.StartInfo.RedirectStandardInput = true; - tmp.StartInfo.UseShellExecute = false; - tmp.StartInfo.CreateNoWindow = true; - tmp.EnableRaisingEvents = true; - - if (working == true) tmp.Start(); - else continue; - - System.Threading.Thread.Sleep(50); - combo_prio.Invoke(new MethodInvoker(delegate - { - if (combo_prio.SelectedIndex != 2) - { - Change_mem_prio(); - } - })); - - if (total_duration > 0) - { - valid_prog = true; - } - else - { - valid_prog = false; - } - - err_txt = ""; - Double interval = 0; - Decimal est_bitrate = 0; - Decimal est_size = 0; - Double sec_prog = 0; - - while (!tmp.StandardError.EndOfStream) - { - try - { - err_txt = tmp.StandardError.ReadLine(); - list_lines.Add(err_txt); - - if (valid_prog == true) - { - if (err_txt.Contains("time=") && err_txt.Contains("time=-") == false) - { - durat_n = total_duration; - total_prog = durat_n; - - int start_time_index = err_txt.IndexOf("time=") + 5; - sec_prog = TimeSpan.Parse(err_txt.Substring(start_time_index, 8)).TotalSeconds; - Double percent = (sec_prog * 100 / durat_n); - - total_prog = total_prog + (sec_prog - interval); - interval = sec_prog; - int percent2 = Convert.ToInt32(percent); - - if (percent2 <= 100) - { - //this.InvokeEx(f => f.pg_current.Value = percent2); - //this.InvokeEx(f => f.//textBox4.Text = (percent2).ToString() + "%"); - - if (percent2 > Pg1.Value) - { - this.InvokeEx(f => f.Pg1.Value = percent2); - this.InvokeEx(f => f.Pg1.Refresh()); - this.InvokeEx(f => TaskbarProgress.SetValue(this.Handle, percent2, Pg1.Maximum)); - if (Math.Round(percent, 1).ToString().Contains(".") || Math.Round(percent, 1).ToString().Contains(",")) - { - this.InvokeEx(f => f.Pg1.Text = Math.Round(percent, 1).ToString() + "%"); - } - else - { - this.InvokeEx(f => f.Pg1.Text = Math.Round(percent, 1).ToString() + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0" + "%"); - } - this.InvokeEx(f => f.Pg1.Refresh()); - } - //this.InvokeEx(f => f.textBox5.Text = (percent2).ToString() + "%"); - } - - //Estimated remaining time - - remain_time = err_txt.Substring(err_txt.LastIndexOf("speed=") + 6, err_txt.Length - err_txt.LastIndexOf("speed=") - 6); - if (time_est_size % 3 == 0) this.InvokeEx(f => f.lbl_speed.Text = Strings.speed + " " + remain_time); - remain_time = remain_time.Replace("x", String.Empty); - Double timing1 = 0; - - if (System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",") - { - timing1 = Math.Round(Double.Parse(remain_time.Replace(".", ",")), 2); - } - else - { - timing1 = Math.Round(Double.Parse(remain_time), 2); - } - Decimal timing = (decimal)timing1; - Decimal total_dur_dec = Convert.ToDecimal(interval); - Decimal total_prog_dec = Convert.ToDecimal(total_prog); - - Decimal remain_secs = 0; - if (timing > 0) - { - remain_secs = (decimal)(total_prog_dec - total_dur_dec) / timing; - } - - if (remain_secs > 60) - { - remain_secs = remain_secs + 60; - } - String remain_from_secs = ""; - - TimeSpan t = TimeSpan.FromSeconds(Convert.ToDouble(remain_secs)); - remain_from_secs = string.Format("{0:D2}h:{1:D2}", - t.Hours, - t.Minutes); - - if (remain_secs >= 3600) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + remain_from_secs + " " + Strings.minutes_abrev); - } - - if (remain_secs < 3600 && remain_secs >= 600) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 1, 2) + " " + Strings.minutes); - } - if (remain_secs < 600 && remain_secs >= 120) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 2, 1) + " " + Strings.minutes); - } - - if (remain_secs <= 59) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + Convert.ToInt16(remain_secs) + " " + Strings.seconds); - } - - //End remaining time - } - } - - //Estimated size and bitrate - - String read_size = String.Empty; - if (err_txt.Contains("size=") && (time_est_size % 3 == 0)) - { - int size_index = err_txt.IndexOf("size=") + 5; - read_size = err_txt.Substring(size_index, 8); - try - { - est_bitrate = (Math.Round(Convert.ToDecimal(read_size) * 8 / Convert.ToDecimal(sec_prog), 0)); - } - catch - { - } - - try - { - if (Convert.ToDecimal(read_size) > 1 && time_n_tasks > 1) - { - if (est_bitrate < 9999) - { - this.InvokeEx(f => f.lbl_bitrate.Text = Strings.avg_bit + ": " + est_bitrate + " " + "Kb/s"); - } - else - { - this.InvokeEx(f => f.lbl_bitrate.Text = Strings.avg_bit + ": " + (Math.Round(est_bitrate / 1000, 0)) + " " + "Mb/s"); - } - //Estimated size - est_size = Convert.ToDecimal(durat_n) * est_bitrate / 8; - - if (est_size > 1000000) - { - this.InvokeEx(f => f.lbl_est_size.Text = Strings.est_size + " " + (Math.Round(est_size / 1000000, 1)).ToString() + " " + "GB"); - } - else - { - this.InvokeEx(f => f.lbl_est_size.Text = Strings.est_size + " " + (Math.Round(est_size / 1000, 0)).ToString() + " " + "MB"); - } - } - } - catch - { - } - - this.InvokeEx(f => f.lbl_est_size.Refresh()); - } - } - catch { } - } - - tmp.WaitForExit(); - tmp.StartInfo.Arguments = String.Empty; - if (tmp.ExitCode == 0) is_ok = true; - else is_ok = false; - timer_est_size.Stop(); - time_est_size = 0; - total_duration = total_duration - durations[count - 1]; - list_lines.Add(""); - list_lines.Add("---------------------End of " + Path.GetFileName(file) + " log-------------------------------"); - list_lines.Add(""); - this.Invoke(new MethodInvoker(delegate - { - lbl_speed.Text = String.Empty; - lbl_est_size.Text = String.Empty; - lbl_bitrate.Text = String.Empty; - })); - } - this.Invoke(new MethodInvoker(delegate - { - Pg1.Value = 100; - Pg1.Text = "100%"; - Pg1.Refresh(); - })); - - working = false; - //Save log - if (no_save_logs == false) - { - string[] array_err = list_lines.ToArray(); - String path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.log"; - if (is_portable == true) path = port_path + "ff_batch_portable.log"; - - StreamWriter SaveFile = new StreamWriter(path); - SaveFile.WriteLine("FFmpeg log sesion: " + System.DateTime.Now); - SaveFile.WriteLine("-------------------------------"); - foreach (String item in array_err) - { - SaveFile.WriteLine(item); - } - SaveFile.Close(); - - File.AppendAllText(path, "-----------------------"); - File.AppendAllText(path, Environment.NewLine + Strings.end_log); - FileInfo fileInfo = new FileInfo(path); - - var bytes = fileInfo.Length; - - var kilobytes = (double)bytes / 1024; - var megabytes = kilobytes / 1024; - var gigabytes = megabytes / 1024; - - //Format size view - String size = ""; - String separator = "."; - - if (bytes > 1000000000) - { - if (gigabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String gigas = gigabytes.ToString(); - if (gigas.Length >= 5) - { - gigas = gigas.Substring(0, gigas.LastIndexOf(separator) + 3); - size = (gigas + " " + "GB"); - } - else - { - size = (gigas + " " + "GB"); - } - } - - if (bytes >= 1048576 && bytes <= 1000000000) - { - if (megabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - String megas = megabytes.ToString(); - if (megas.Length > 5) - { - megas = megas.Substring(0, megas.LastIndexOf(separator)); - size = (megas + " " + "MB"); - } - else - { - size = (megas + " " + "MB"); - } - } - - if (bytes >= 1024 && bytes < 1048576) - - { - if (kilobytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String kbs = kilobytes.ToString(); - if (kbs.Length >= 5) - { - kbs = kbs.Substring(0, kbs.LastIndexOf(separator)); - size = (kbs + " " + "KB"); - } - else - { - size = (kbs + " " + "KB"); - } - } - if (bytes > -1 && bytes < 1024) - { - String bits = bytes.ToString(); - size = (bits + " Bytes"); - } - - //End Format size view - File.AppendAllText(path, Environment.NewLine + Strings.log_size + " " + size); - - //End save log - } - - Enable_Controls(); - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - - if (is_ok && cancel_queue == false) - { - if (chkshut.Checked) - { - this.Invoke(new MethodInvoker(delegate - { - groupBox2.Enabled = true; - foreach (Control ct in groupBox2.Controls) - { - ct.Enabled = false; - } - })); - auto_shut(); - return; - } - - //End shutdown check - else - { - if (play_on_end == true) play_end(); - if (Form.ActiveForm == null) - { - notifyIcon1.Visible = true; - notifyIcon1.BalloonTipText = Strings.stream_saved; - notifyIcon1.BalloonTipIcon = ToolTipIcon.Info; - notifyIcon1.BalloonTipTitle = Strings.stream_saved2; - notifyIcon1.ShowBalloonTip(0); - - } - - if (chk_open_compl.Checked) - { - if (Directory.GetFiles(destino).Length != 0) - { - Process open_processed = new Process(); - open_processed.StartInfo.FileName = "explorer.exe"; - open_processed.StartInfo.Arguments = '\u0022' + destino + '\u0022'; - open_processed.Start(); - } - else - { - if (Directory.Exists(destino)) - { - Directory.Delete(destino); - } - } - } - } - } - else - { - if (is_ok) - { - this.InvokeEx(f => f.Pg1.Text = "100%"); - this.InvokeEx(f => MessageBox.Show(Strings.str_abort, Strings.aborted, MessageBoxButtons.OK, MessageBoxIcon.Error)); - } - else - { - this.InvokeEx(f => f.Pg1.Text = "100%"); - Boolean unsupported = false; - foreach (String lin in list_lines) - { - if (lin.Contains("Could not write header")) unsupported = true; - } - if (unsupported == true) this.InvokeEx(f => MessageBox.Show(Strings.err_oc + " " + Environment.NewLine + Environment.NewLine + "Possibly incompatible container for selected track" + Environment.NewLine + Environment.NewLine + Strings.check_log, Strings.err_save_track, MessageBoxButtons.OK, MessageBoxIcon.Error)); - else this.InvokeEx(f => MessageBox.Show(Strings.err_oc + " " + Environment.NewLine + Environment.NewLine + err_txt.TrimStart() + Environment.NewLine + Environment.NewLine + Strings.check_log, Strings.err_save_track, MessageBoxButtons.OK, MessageBoxIcon.Error)); - } - } - }).Start(); - } - - private void ct3_save_track_Click(object sender, EventArgs e) - { - if (list_tracks.SelectedItems.Count == 1) - { - btn_extract.PerformClick(); - return; - } - - extract_streams(); - } - - private void btn_save_path_Click(object sender, EventArgs e) - { - String path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_path.ini"; - if (is_portable == true) path = port_path + "ff_path_portable.ini"; - String path_to_save = String.Empty; - path_to_save = txt_path_main.Text; - File.WriteAllText(path, path_to_save); - btn_save_path.Enabled = false; - } - - private void btn_save_prio_Click(object sender, EventArgs e) - { - btn_save_prio.Enabled = false; - String path = String.Empty; - if (is_portable == false) - { - path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_priority.ini"; - } - else - { - path = port_path + "ff_priority_portable.ini"; - } - - String path_to_prio = String.Empty; - - if (combo_prio.SelectedIndex != 2) - { - path_to_prio = combo_prio.SelectedIndex.ToString(); - File.WriteAllText(path, path_to_prio); - } - else - { - if (File.Exists(path)) - { - File.Delete(path); - } - } - Pg1.Focus(); - } - - private void btn_del_track_Click(object sender, EventArgs e) - { - Pg1.Focus(); - if (list_tracks.SelectedIndices.Count > 0) - { - Boolean has_default = false; - - foreach (ListViewItem elemento in list_tracks.SelectedItems) - { - list_tracks.Items.Remove(elemento); - pic_encode_param.Image = null; - } - - //Review audio track defaults - - foreach (ListViewItem audio_item in list_tracks.Items) - { - if (audio_item.SubItems[3].Text.Contains("Audio")) - { - if (audio_item.SubItems[5].Text == Strings.yes) - { - has_default = true; - } - } - } - - if (has_default == false) - { - foreach (ListViewItem audio_item in list_tracks.Items) - { - if (audio_item.SubItems[3].Text.Contains("Audio")) - { - audio_item.SubItems[5].Text = Strings.yes; - return; - } - } - } - //End review audio track defaults - lbl_tr_n.Text = Strings.tracks + list_tracks.Items.Count.ToString(); - } - else - { - MessageBox.Show(Strings.no_track_sel, Strings.no_track_sel2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - } - } - - private void btn_default_track_Click(object sender, EventArgs e) - { - Pg1.Focus(); - if (list_tracks.SelectedIndices.Count == 1) - { - if (list_tracks.SelectedIndices.Count == 0 || list_tracks.SelectedItems[0].SubItems[3].Text.Contains("Video")) - { - return; - } - - if (list_tracks.SelectedItems[0].SubItems[4].Text == Strings.yes) - { - list_tracks.SelectedItems[0].SubItems[4].Text = Strings.no; - } - else - { - list_tracks.SelectedItems[0].SubItems[4].Text = Strings.yes; - } - - //Review audio defaults - int default_items = 0; - - for (int i = 0; i < list_tracks.Items.Count; i++) - { - if (list_tracks.Items[i].SubItems[3].Text.Contains("Audio")) - { - if (list_tracks.Items[i].SubItems[4].Text == Strings.yes) - { - default_items = default_items + 1; - } - } - } - - if (default_items > 1) - { - foreach (ListViewItem audio_item in list_tracks.Items) - { - if (audio_item.SubItems[3].Text.Contains("Audio")) - { - if (audio_item.Text != list_tracks.SelectedItems[0].Text) - { - audio_item.SubItems[4].Text = Strings.no; - } - } - } - } - - if (default_items == 0) - { - foreach (ListViewItem audio_item in list_tracks.Items) - { - if (audio_item.SubItems[3].Text.Contains("Audio")) - { - if (audio_item.Text != list_tracks.SelectedItems[0].Text) - { - audio_item.SubItems[4].Text = Strings.yes; - return; - } - } - } - } - - //End review audio track defaults - - //Begin subtitle defaults - - //Review audio defaults - int default_subs = 0; - for (int i = 0; i < list_tracks.Items.Count; i++) - { - if (list_tracks.Items[i].SubItems[3].Text.Contains("Subtitle")) - { - if (list_tracks.Items[i].SubItems[4].Text == Strings.yes) - { - default_subs = default_subs + 1; - } - } - } - - if (default_subs > 1) - { - foreach (ListViewItem audio_item in list_tracks.Items) - { - if (audio_item.SubItems[3].Text.Contains("Subtitle")) - { - if (audio_item != list_tracks.SelectedItems[0]) - { - audio_item.SubItems[4].Text = Strings.no; - } - } - } - } - - //End subtitle defaults - } - else - { - MessageBox.Show(Strings.one_track, Strings.warning, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - } - } - - private void tracks_background() - { - check_jobs(); - foreach (ListViewItem item in list_tracks.Items) - { - if (Settings.Default.dark_mode == false) - { - if (item.SubItems[2].Text.ToLower().Contains("video")) - { - item.BackColor = Color.PapayaWhip; - } - - if (item.SubItems[2].Text.ToLower().Contains("audio")) - { - item.BackColor = Color.AliceBlue; - } - if (item.SubItems[2].Text.ToLower().Contains("subtitle")) - { - item.BackColor = Color.LightGoldenrodYellow; - } - } - else - { - if (item.SubItems[2].Text.ToLower().Contains("video")) - { - item.BackColor = Color.FromArgb(255, 96, 60, 60); - } - - if (item.SubItems[2].Text.ToLower().Contains("audio")) - { - item.BackColor = Color.FromArgb(255, 60, 60, 96); - } - if (item.SubItems[2].Text.ToLower().Contains("subtitle")) - { - item.BackColor = Color.FromArgb(255, 96, 96, 60); - } - } - } - //Duplicates - if (tracks_empty == true) return; - - for (int i = 0; i < list_tracks.Items.Count; i++) - { - for (int j = i + 1; j < list_tracks.Items.Count; j++) - { - if (list_tracks.Items[i].Text == list_tracks.Items[j].Text && list_tracks.Items[i].SubItems[1].Text == list_tracks.Items[j].SubItems[1].Text) - { - list_tracks.Items.RemoveAt(j); - } - } - } - //End Duplicates - lbl_tr_n.Text = Strings.tracks + " " + list_tracks.Items.Count.ToString(); - } - - private void check_jobs() - { - if (frm_mux_jobs.dg_pr.RowCount > 0) - { - this.InvokeEx(f => f.lbl_mux_jobs.Text = Strings.jobs + " " + frm_mux_jobs.dg_pr.RowCount); - } - else - { - this.InvokeEx(f => f.lbl_mux_jobs.Text = String.Empty); - this.InvokeEx(f => f.btn_mux_show_jobs.Enabled = false); - } - } - private void btn_pause_Click(object sender, EventArgs e) - { - Pg1.Focus(); - if (working == false) return; - if (tabControl1.SelectedIndex == 3) - if (dg1.Rows[0].Cells[5].Value.ToString() == Strings.recording1) return; - - if (btn_pause.Image != pic_resume.Image) - { - paused = true; - - if (tabControl1.SelectedIndex == 0) - { - if (working == true) - { - foreach (Process proc in procs.Values) - { - if (proc.StartInfo.Arguments == String.Empty) continue; - try - { - proc.Suspend(); - } - catch - { - Thread.Sleep(250); - try { proc.Suspend(); } catch - { - Thread.Sleep(250); - proc.Suspend(); - } - } - } - } - } - - if (tabControl1.SelectedIndex == 1) - { - if (working == true && multi_running == false) - { - foreach (Process proc in procs.Values) - { - if (proc.StartInfo.Arguments == String.Empty) continue; - try - { - proc.Suspend(); - } - catch - { - Thread.Sleep(250); - try { proc.Suspend(); } - catch - { - Thread.Sleep(250); - proc.Suspend(); - } - } - } - } - } - - if (tabControl1.SelectedIndex == 2) - { - foreach (ListViewItem item in listView3.Items) - { - if (working == true) - { - foreach (Process proc in procs.Values) - { - if (proc.StartInfo.Arguments == String.Empty) continue; - try - { - proc.Suspend(); - } - catch - { - Thread.Sleep(250); - try { proc.Suspend(); } - catch - { - Thread.Sleep(250); - proc.Suspend(); - } - } - } - } - } - } - - if (tabControl1.SelectedIndex == 3) - { - if (m3u_running == true && m3u_single_running == true) - { - foreach (Process proc in procs.Values) - { - if (proc.StartInfo.Arguments == String.Empty) continue; - try - { - proc.Suspend(); - } - catch - { - Thread.Sleep(250); - try { proc.Suspend(); } - catch - { - Thread.Sleep(250); - proc.Suspend(); - } - } - } - } - - if (m3u_running == true && m3u_single_running == false) - { - foreach (Process proc in procs.Values) - { - if (proc.StartInfo.Arguments == String.Empty) continue; - try - { - proc.Suspend(); - } - catch - { - } - } - } - } - this.Invoke(new MethodInvoker(delegate - { - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.Paused); - btn_abort_all.Enabled = false; - btn_abort_all.Enabled = false; - btn_skip_main.Enabled = false; - btn_stop_m3u8.Enabled = false; - btn_pause.Image = pic_resume.Image; - })); - - //if (Settings.Default.pause_bat == false) MessageBox.Show(Strings.paused1, Strings.paused2, MessageBoxButtons.OK); - } - else - { - if (Settings.Default.pause_bat == true && paused_bats > 0 && paused_battery == true) - { - DialogResult a = MessageBox.Show(Strings.on_battery2, Strings.on_battery1, MessageBoxButtons.YesNo, MessageBoxIcon.Question); - if (a == DialogResult.Yes) - { - Settings.Default.pause_bat = false; - pic_batt.Visible = false; - } - else return; - } - - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.Paused)); - - paused = false; - if (tabControl1.SelectedIndex == 0) - { - - if (working == true) - - { - foreach (Process proc in procs.Values) - { - if (proc.StartInfo.Arguments == String.Empty) continue; - try - { - proc.Resume(); - } - catch - { - try { Thread.Sleep(250); proc.Resume(); } catch - { - try { Thread.Sleep(250); proc.Resume(); } - catch { } - } - } - } - } - } - - if (tabControl1.SelectedIndex == 1) - { - if (working == true) resume_glob(); - } - - if (tabControl1.SelectedIndex == 2) - { - foreach (ListViewItem item in listView3.Items) - { - if (working == true) resume_glob(); - } - } - - if (tabControl1.SelectedIndex == 3) - { - foreach (DataGridViewRow row in dg1.Rows) - { - if (m3u_single_running == true && m3u_running == true) - { - resume_glob(); - } - } - - if (m3u_single_running == false && m3u_running == true) - { - foreach (Process proc in procs.Values) - { - try - { - proc.Resume(); - } - catch - { - } - } - } - } - - this.Invoke(new MethodInvoker(delegate - { - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.Normal); - btn_abort_all.Enabled = true; - btn_skip_main.Enabled = true; - btn_stop_m3u8.Enabled = true; - btn_skip_main.Enabled = true; - btn_pause.Image = pic_pause.Image; - })); - - } - } - - private void suspend_glob() - { - foreach (Process proc in procs.Values) - { - if (proc.StartInfo.Arguments == String.Empty) continue; - try - { - proc.Suspend(); - } - catch - { - try { Thread.Sleep(250); proc.Suspend(); } - catch - { - try { Thread.Sleep(250); proc.Suspend(); } - catch { } - } - } - } - } - - private void resume_glob() - { - foreach (Process proc in procs.Values) - { - if (proc.StartInfo.Arguments == String.Empty) continue; - try - { - proc.Resume(); - } - catch - { - try { Thread.Sleep(250); proc.Resume(); } - catch - { - try { Thread.Sleep(250); proc.Resume(); } - catch { } - } - } - } - } - private void auto_pause() - { - Pg1.Focus(); - if (working == false) return; - - if (tabControl1.SelectedIndex == 3) if (dg1.Rows[0].Cells[5].Value.ToString() == Strings.recording1) return; - - if (btn_pause.Image != pic_resume.Image) - { - paused = true; - - if (tabControl1.SelectedIndex == 0) - { - if (working == true && multi_running == false) - { - suspend_glob(); - } - - if (working == true && multi_running == true) - { - suspend_glob(); - } - } - - if (tabControl1.SelectedIndex == 1) - { - if (working == true && multi_running == false) suspend_glob(); - } - - if (tabControl1.SelectedIndex == 2) - { - if (working == true) suspend_glob(); - - } - - if (tabControl1.SelectedIndex == 3) - { - foreach (DataGridViewRow row in dg1.Rows) - { - if (m3u_running == true && m3u_single_running == true) - { - suspend_glob(); - } - } - - if (m3u_running == true && m3u_single_running == false) - { - suspend_glob(); - } - } - this.Invoke(new MethodInvoker(delegate - { - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.Paused); - btn_abort_all.Enabled = false; - btn_abort_all.Enabled = false; - btn_skip_main.Enabled = false; - btn_stop_m3u8.Enabled = false; - btn_pause.Image = pic_resume.Image; - })); - } - else - { - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.Paused)); - - paused = false; - if (tabControl1.SelectedIndex == 0) - { - if (working == true && multi_running == false) - { - resume_glob(); - } - - if (working == true && multi_running == true) - { - foreach (Process proc in procs.Values) - { - if (proc.StartInfo.Arguments == String.Empty) continue; - try - { - proc.Resume(); - } - catch - { - } - } - } - } - - if (tabControl1.SelectedIndex == 1) - { - if (working == true) resume_glob(); - } - - if (tabControl1.SelectedIndex == 2) - { - foreach (ListViewItem item in listView3.Items) - { - if (working == true) resume_glob(); - } - } - - if (tabControl1.SelectedIndex == 3) - { - foreach (DataGridViewRow row in dg1.Rows) - { - if (m3u_single_running == true && m3u_running == true) - { - resume_glob(); - } - } - - if (m3u_single_running == false && m3u_running == true) - { - foreach (Process proc in procs.Values) - { - try - { - proc.Resume(); - } - catch - { - } - } - } - } - - this.Invoke(new MethodInvoker(delegate - { - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.Normal); - btn_abort_all.Enabled = true; - btn_skip_main.Enabled = true; - btn_stop_m3u8.Enabled = true; - btn_skip_main.Enabled = true; - btn_pause.Image = pic_pause.Image; - })); - } - } - private void button16_Click_3(object sender, EventArgs e) - { - folderBrowserDialog1.ShowNewFolderButton = true; - - if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) - { - txt_path_main.Text = folderBrowserDialog1.SelectedPath; - txt_path_main.BackColor = txt_parameters.BackColor; - txt_path_mux.Text = folderBrowserDialog1.SelectedPath; - txt_path_mux.BackColor = txt_parameters.BackColor; - } - } - - private void textBox9_DoubleClick(object sender, EventArgs e) - { - txt_path_main.Text = ".\\FFBatch"; - txt_path_main.BackColor = Control.DefaultBackColor; - txt_path_mux.Text = ".\\FFBatch"; - txt_path_mux.BackColor = Control.DefaultBackColor; - } - - private void timer_est_size_Tick(object sender, EventArgs e) - { - time_est_size = time_est_size + 1; - } - - private void textBox1_KeyDown(object sender, KeyEventArgs e) - { - if (e.KeyCode == Keys.Enter) e.SuppressKeyPress = true; - } - - private void btn_skip_main_Click(object sender, EventArgs e) - { - Pg1.Focus(); - if (working == true && multi_running == false) - { - foreach (Process proc in procs.Values) - { - try - { - StreamWriter write_q = proc.StandardInput; - write_q.Write("q"); - } - catch { } - } - - aborted_url = true; - skipped = true; - } - if (working == true && multi_running == true) - { - if (listView1.SelectedItems.Count == 1) - { - if (listView1.SelectedItems[0].SubItems[5].Text != Strings.queued) cti6.PerformClick(); - if (listView1.SelectedItems[0].SubItems[5].Text == Strings.queued) ctdel.PerformClick(); - } - } - } - private void timer2_Tick(object sender, EventArgs e) - { - Double weight = 0; - Double dg_multi_prog = 0; - start_total_time = start_total_time + 0.5; - - foreach (DataGridViewRow row in dg1.Rows) - { - try - { - weight = TimeSpan.Parse(row.Cells[3].Value.ToString()).TotalSeconds / total_multi_duration; - if (row.Cells[5].Value.ToString().Contains("%") == true && cancelados_paralelos == false) - { - dg_multi_prog = dg_multi_prog + (Convert.ToDouble(row.Cells[5].Value.ToString().Replace("%", "")) * weight) * dg1.Rows.Count; - } - } - catch { } - - if (row.Cells[5].Value.ToString() == Strings.success || row.Cells[5].Value.ToString() == Strings.failed || row.Cells[5].Value.ToString() == Strings.aborted || row.Cells[5].Value.ToString() == Strings.aborting || row.Cells[5].Value.ToString() == Strings.skipped) - { - dg_multi_prog = dg_multi_prog + (100 * weight * dg1.Rows.Count); - } - } - - if (time_n_tasks > 1) - { - if (dg1.Rows[0].Cells[1].Value.ToString().ToLower().Contains("youtu.be") || dg1.Rows[0].Cells[1].Value.ToString().ToLower().Contains("youtube.com")) - { - try - { - if (Convert.ToInt32(dg_multi_prog) > Pg1.Maximum) Pg1.Value = Pg1.Maximum; - else - { - if (Convert.ToInt32(dg_multi_prog) >= Pg1.Value) - { - Pg1.Value = Convert.ToInt32(dg_multi_prog); - Pg1.Text = Convert.ToInt32(dg_multi_prog / dg1.Rows.Count).ToString() + "%"; - this.InvokeEx(f => TaskbarProgress.SetValue(this.Handle, Pg1.Value, Pg1.Maximum)); - } - } - } - catch { } - } - } - else - { - Pg1.Value = 0; - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - } - - if (Pg1.Value / dg1.Rows.Count > 0 && start_total_time > 4) - { - Double remain_secs = time_n_tasks * 100 / (Pg1.Value / dg1.Rows.Count) - start_total_time; - String remain_string = String.Empty; - - TimeSpan t = TimeSpan.FromSeconds(remain_secs); - remain_string = string.Format("{0:D2}h:{1:D2}", - t.Hours, - t.Minutes); - - if (remain_secs >= 43200) - { - txt_remain.Text = Strings.remain_time + " " + Math.Round(remain_secs / 3600).ToString() + " " + Strings.hours; - } - - if (remain_secs >= 3600 && remain_secs < 43200) - { - txt_remain.Text = Strings.remain_time + " " + remain_string + " " + Strings.minutes_abrev; - } - - if (remain_secs < 3600 && remain_secs >= 600) - { - txt_remain.Text = Strings.remain_time + " " + remain_string.Substring(remain_string.LastIndexOf(":") + 1, 2) + " " + Strings.minutes; - } - if (remain_secs < 600 && remain_secs >= 120) - { - txt_remain.Text = Strings.remain_time + " " + remain_string.Substring(remain_string.LastIndexOf(":") + 2, 1) + " " + Strings.minutes; - } - - if (remain_secs < 120 && remain_secs > 59) - { - txt_remain.Text = Strings.remain_time + " " + Strings.about_1; - } - - if (remain_secs <= 59) - { - txt_remain.Text = Strings.remain_time + " " + Strings.less_one; - } - if (remain_secs <= 0) - { - txt_remain.Text = Strings.remain_time + " " + Strings.almost_done; - } - txt_remain.Refresh(); - } - else - { - if (has_lives_multi == false) txt_remain.Text = Strings.remain_time + " " + Strings.calcul; - else txt_remain.Text = Strings.remain_time + " " + Strings.recording; - txt_remain.Refresh(); - } - } - - private void btn_extract_Click(object sender, EventArgs e) - { - Pg1.Focus(); - lbl_est_size.Text = ""; - lbl_bitrate.Text = ""; - - if (list_tracks.SelectedItems.Count > 1) - { - extract_streams(); - return; - } - - cancel_queue = false; - - if (!File.Exists(Path.Combine(Application.StartupPath, "ffmpeg.exe"))) - { - MessageBox.Show(Strings.no_ffmpeg, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (check_ff_md5() == false) - { - Form25 frm25 = new Form25(); - frm25.ShowDialog(); - return; - } - - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - if (list_tracks.SelectedIndices.Count > 1) - { - MessageBox.Show(Strings.only_one, Strings.multiple_tr, MessageBoxButtons.OK, MessageBoxIcon.Information); - return; - } - - foreach (ListViewItem file in list_tracks.Items) - { - if (!File.Exists(file.Text)) - { - MessageBox.Show(Strings.file_not_found + " " + file.Text, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - - if (list_tracks.Items.Count == 0) - { - MessageBox.Show(Strings.tracks_empty, Strings.no_files, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; - } - - if (list_tracks.SelectedItems.Count == 0) - { - MessageBox.Show(Strings.no_sel, Strings.warning, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; - } - - if (txt_track_format.Text == String.Empty && list_tracks.SelectedItems.Count > 0) - { - MessageBox.Show(Strings.track_Ext, Strings.warning, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; - } - - String is_overw = txt_path_main.Text + "\\" + Path.GetFileNameWithoutExtension(list_tracks.Items[0].Text) + "." + txt_track_format; - - if (is_overw == list_tracks.Items[0].Text) - { - MessageBox.Show(Strings.overw_main, Strings.overw_not_all, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - DateTime time2; - if (!DateTime.TryParse(ss_time_input.Text, out time2)) - { - MessageBox.Show(Strings.pre_input4, Strings.pre_input2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - //Validated list, start processing - //Pending duration - - if (dur_ok == false) - { - list_pending_dur.Items.Clear(); - foreach (ListViewItem item in listView1.Items) - { - list_pending_dur.Items.Add((ListViewItem)item.Clone()); - } - BG_Dur.RunWorkerAsync(); - return; - } - - Disable_Controls(); - txt_remain.Text = Strings.remain_time + " " + "00h:00m:00s"; - time_n_tasks = 0; - lbl_elapsed.Text = Strings.time_elapsed + " " + "00h:00m:00s"; - timer_tasks.Start(); - - cancel_queue = false; - Pg1.Value = 0; - //pg_current.Value = 0; - //textBox4.Text = "0%"; - - working = true; - - //Copy list of tracks for thread processing - ListView list_proc = new ListView(); - foreach (ListViewItem item in list_tracks.SelectedItems) - { - list_proc.Items.Add((ListViewItem)item.Clone()); - } - //End of copy list of tracks for thread processing - - Pg1.Maximum = list_proc.Items.Count; - - Double total_duration = 0; - Double total_prog = 0; - - //Duration - Process probe = new Process(); - probe.StartInfo.FileName = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - String ffprobe_frames2 = " " + '\u0022' + "--Inform=General;%Duration/String3%" + '\u0022'; - probe.StartInfo.Arguments = ffprobe_frames2 + " " + '\u0022' + list_proc.Items[0].Text + '\u0022'; - - probe.StartInfo.RedirectStandardOutput = true; - probe.StartInfo.UseShellExecute = false; - probe.StartInfo.CreateNoWindow = true; - probe.EnableRaisingEvents = true; - probe.Start(); - - String duracion = probe.StandardOutput.ReadLine(); - - probe.WaitForExit(); - - if (duracion != null) - { - DateTime time; - //total_duration = Convert.ToDouble(duracion.Substring(0, 7)); - if (DateTime.TryParse(duracion, out time)) - { - durat_n = TimeSpan.Parse(duracion).TotalSeconds; - total_duration = durat_n; - } - } - else - { - durat_n = 0; - total_duration = 0; - } - - //End duration - - //End - - Pg1.Minimum = 0; - Pg1.Maximum = 100; - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - lbl_speed.Text = String.Empty; - - List list_lines = new List(); - String mux_ext = txt_track_format.Text; - - pic_no_errors.Visible = false; - pic_recording.Visible = false; - pic_warnings.Visible = false; - - procs.Clear(); - procs.Add("proc_urls_0", new Process()); - - time_est_size = 0; - timer_est_size.Start(); - - new System.Threading.Thread(() => - { - System.Threading.Thread.CurrentThread.IsBackground = true; - - String remain_time = "0"; - - String ffm = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - - String file = list_proc.Items[0].Text; - String fullPath = file; - - String destino = ""; - - if (txt_path_main.Text.Contains(".\\")) - { - destino = file.Substring(0, fullPath.LastIndexOf('\\')) + txt_path_main.Text.Replace(".", String.Empty); ; - } - else - { - destino = txt_path_main.Text; - } - - if (!Directory.Exists(destino)) - { - try - { - Directory.CreateDirectory(destino); - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.error2 + " " + excpt.Message, Strings.write_error2, MessageBoxButtons.OK, MessageBoxIcon.Error); - this.Cursor = Cursors.Arrow; - Enable_Controls(); - working = false; - return; - } - } - - //Create joint inputs variable - String inputs = ""; - String stream_type = String.Empty; - if (list_proc.Items[0].SubItems[2].Text.ToLower().Contains("subtitle")) - { - stream_type = "s"; - } - - if (list_proc.Items[0].SubItems[2].Text.ToLower().Contains("audio")) - { - stream_type = "a"; - } - if (list_proc.Items[0].SubItems[2].Text.ToLower().Contains("video")) - { - stream_type = "v"; - } - //{ - //inputs = inputs + " -sub_charenc UTF-8" + " -i " + '\u0022' + input_item.Text + '\u0022'; - //} - inputs = " -i " + '\u0022' + list_proc.Items[0].Text + '\u0022' + " -map 0:" + list_proc.Items[0].SubItems[1].Text + " -c:" + stream_type + " " + txt_track_param.Text + " "; - - //End create joint inputs variable - - String AppParam = inputs + "-y " + '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file) + "_" + stream_type + "_demux" + "." + mux_ext + '\u0022'; - - if (!Directory.Exists(destino)) - { - Directory.CreateDirectory(destino); - } - var tmp = procs["proc_urls_0"]; - valid_prog = false; - tmp.StartInfo.FileName = ffm; - tmp.StartInfo.Arguments = AppParam; - tmp.StartInfo.RedirectStandardError = true; - tmp.StartInfo.RedirectStandardInput = true; - tmp.StartInfo.UseShellExecute = false; - tmp.StartInfo.CreateNoWindow = true; - tmp.EnableRaisingEvents = true; - tmp.Start(); - - System.Threading.Thread.Sleep(50); - combo_prio.Invoke(new MethodInvoker(delegate - { - if (combo_prio.SelectedIndex != 2) - { - Change_mem_prio(); - } - })); - - if (total_duration > 0) - { - valid_prog = true; - } - else - { - valid_prog = false; - } - - String err_txt = ""; - Double interval = 0; - Decimal est_bitrate = 0; - Decimal est_size = 0; - Double sec_prog = 0; - try - { - while (!tmp.StandardError.EndOfStream) - { - err_txt = tmp.StandardError.ReadLine(); - list_lines.Add(err_txt); - - if (valid_prog == true) - { - if (err_txt.Contains("time=") && err_txt.Contains("time=-") == false) - { - total_prog = durat_n; - int start_time_index = err_txt.IndexOf("time=") + 5; - sec_prog = TimeSpan.Parse(err_txt.Substring(start_time_index, 8)).TotalSeconds; - Double percent = (sec_prog * 100 / durat_n); - - total_prog = total_prog + (sec_prog - interval); - interval = sec_prog; - int percent2 = Convert.ToInt32(percent); - - if (percent2 <= 100) - { - //this.InvokeEx(f => f.pg_current.Value = percent2); - //this.InvokeEx(f => f.//textBox4.Text = (percent2).ToString() + "%"); - - this.InvokeEx(f => f.Pg1.Value = percent2); - this.InvokeEx(f => f.Pg1.Refresh()); - this.InvokeEx(f => TaskbarProgress.SetValue(this.Handle, percent2, Pg1.Maximum)); - if (Math.Round(percent, 1).ToString().Contains(".") || Math.Round(percent, 1).ToString().Contains(",")) - { - this.InvokeEx(f => f.Pg1.Text = Math.Round(percent, 1).ToString() + "%"); - } - else - { - this.InvokeEx(f => f.Pg1.Text = Math.Round(percent, 1).ToString() + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0" + "%"); - } - //this.InvokeEx(f => f.textBox5.Text = (percent2).ToString() + "%"); - } - - //Estimated remaining time - - remain_time = err_txt.Substring(err_txt.LastIndexOf("speed=") + 6, err_txt.Length - err_txt.LastIndexOf("speed=") - 6); - if (time_est_size % 3 == 0) this.InvokeEx(f => f.lbl_speed.Text = Strings.speed + " " + remain_time); - remain_time = remain_time.Replace("x", String.Empty); - Double timing1 = 0; - - if (System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",") - { - timing1 = Math.Round(Double.Parse(remain_time.Replace(".", ",")), 2); - } - else - { - timing1 = Math.Round(Double.Parse(remain_time), 2); - } - Decimal timing = (decimal)timing1; - Decimal total_dur_dec = Convert.ToDecimal(interval); - Decimal total_prog_dec = Convert.ToDecimal(total_prog); - - Decimal remain_secs = 0; - if (timing > 0) - { - remain_secs = (decimal)(total_prog_dec - total_dur_dec) / timing; - } - - if (remain_secs > 60) - { - remain_secs = remain_secs + 60; - } - String remain_from_secs = ""; - - TimeSpan t = TimeSpan.FromSeconds(Convert.ToDouble(remain_secs)); - remain_from_secs = string.Format("{0:D2}h:{1:D2}", - t.Hours, - t.Minutes); - - if (remain_secs >= 3600) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + remain_from_secs + " " + Strings.minutes_abrev); - } - - if (remain_secs < 3600 && remain_secs >= 600) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 1, 2) + " " + Strings.minutes); - } - if (remain_secs < 600 && remain_secs >= 120) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 2, 1) + " " + Strings.minutes); - } - - if (remain_secs <= 59) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + Convert.ToInt16(remain_secs) + " " + Strings.seconds); - } - - //End remaining time - } - } - - //Estimated size and bitrate - - String read_size = String.Empty; - if (err_txt.Contains("size=") && (time_est_size % 3 == 0)) - { - int size_index = err_txt.IndexOf("size=") + 5; - read_size = err_txt.Substring(size_index, 8); - try - { - est_bitrate = (Math.Round(Convert.ToDecimal(read_size) * 8 / Convert.ToDecimal(sec_prog), 0)); - } - catch - { - } - - try - { - if (Convert.ToDecimal(read_size) > 1 && time_n_tasks > 1) - { - if (est_bitrate < 9999) - { - this.InvokeEx(f => f.lbl_bitrate.Text = Strings.avg_bit + ": " + est_bitrate + " " + "Kb/s"); - } - else - { - this.InvokeEx(f => f.lbl_bitrate.Text = Strings.avg_bit + ": " + (Math.Round(est_bitrate / 1000, 0)) + " " + "Mb/s"); - } - //Estimated size - est_size = Convert.ToDecimal(durat_n) * est_bitrate / 8; - - if (est_size > 1000000) - { - this.InvokeEx(f => f.lbl_est_size.Text = Strings.est_size + " " + (Math.Round(est_size / 1000000, 1)).ToString() + " " + "GB"); - } - else - { - this.InvokeEx(f => f.lbl_est_size.Text = Strings.est_size + " " + (Math.Round(est_size / 1000, 0)).ToString() + " " + "MB"); - } - } - } - catch - { - } - - this.InvokeEx(f => f.lbl_est_size.Refresh()); - } - } - } - catch { } - - tmp.WaitForExit(); - tmp.StartInfo.Arguments = String.Empty; - timer_est_size.Stop(); - time_est_size = 0; - - this.Invoke(new MethodInvoker(delegate - { - lbl_speed.Text = String.Empty; - lbl_est_size.Text = String.Empty; - lbl_bitrate.Text = String.Empty; - Pg1.Value = 100; - Pg1.Text = "100%"; - })); - - list_lines.Add(""); - list_lines.Add("---------------------End of " + Path.GetFileName(file) + " log-------------------------------"); - list_lines.Add(""); - - - working = false; - //Save log - if (no_save_logs == false) - { - string[] array_err = list_lines.ToArray(); - String path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.log"; - if (is_portable == true) path = port_path + "ff_batch_portable.log"; - - StreamWriter SaveFile = new StreamWriter(path); - SaveFile.WriteLine("FFmpeg log sesion: " + System.DateTime.Now); - SaveFile.WriteLine("-------------------------------"); - foreach (String item in array_err) - { - SaveFile.WriteLine(item); - } - SaveFile.Close(); - - File.AppendAllText(path, "-----------------------"); - File.AppendAllText(path, Environment.NewLine + Strings.end_log); - FileInfo fileInfo = new FileInfo(path); - - var bytes = fileInfo.Length; - - var kilobytes = (double)bytes / 1024; - var megabytes = kilobytes / 1024; - var gigabytes = megabytes / 1024; - - //Format size view - String size = ""; - String separator = "."; - - if (bytes > 1000000000) - { - if (gigabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String gigas = gigabytes.ToString(); - if (gigas.Length >= 5) - { - gigas = gigas.Substring(0, gigas.LastIndexOf(separator) + 3); - size = (gigas + " " + "GB"); - } - else - { - size = (gigas + " " + "GB"); - } - } - - if (bytes >= 1048576 && bytes <= 1000000000) - { - if (megabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - String megas = megabytes.ToString(); - if (megas.Length > 5) - { - megas = megas.Substring(0, megas.LastIndexOf(separator)); - size = (megas + " " + "MB"); - } - else - { - size = (megas + " " + "MB"); - } - } - - if (bytes >= 1024 && bytes < 1048576) - - { - if (kilobytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String kbs = kilobytes.ToString(); - if (kbs.Length >= 5) - { - kbs = kbs.Substring(0, kbs.LastIndexOf(separator)); - size = (kbs + " " + "KB"); - } - else - { - size = (kbs + " " + "KB"); - } - } - if (bytes > -1 && bytes < 1024) - { - String bits = bytes.ToString(); - size = (bits + " Bytes"); - } - - //End Format size view - File.AppendAllText(path, Environment.NewLine + Strings.log_size + " " + size); - - //End save log - } - - Enable_Controls(); - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - - if (tmp.ExitCode == 0 && cancel_queue == false) - { - if (chkshut.Checked) - { - this.InvokeEx(f => f.groupBox2.Enabled = true); - foreach (Control ct in groupBox2.Controls) - { - this.InvokeEx(f => ct.Enabled = false); - } - auto_shut(); - return; - } - - //End shutdown check - else - { - //Output single info - - String dest_demux = destino + "\\" + Path.GetFileNameWithoutExtension(file) + "_" + stream_type + "_demux" + "." + mux_ext; - - if (File.Exists(dest_demux)) - { - //Display output info - if (File.Exists(dest_demux)) - { - - System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentUICulture; - String sep_th = ci.NumberFormat.CurrencyGroupSeparator; - String unit = ""; - String dur = ""; - this.Invoke(new MethodInvoker(delegate - { - lbl_est_size.Text = String.Empty; - lbl_bitrate.Text = String.Empty; - probe = new Process(); - - List lines_ouput = new List(); - probe.StartInfo.FileName = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - String ffprobe_frames = " " + "--Output=General;%OverallBitRate/String%" + "\\n" + "%FileSize/String3%" + "\\n" + "%Duration/String3%"; - probe.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + dest_demux + '\u0022'; - probe.StartInfo.RedirectStandardOutput = true; - probe.StartInfo.UseShellExecute = false; - probe.StartInfo.CreateNoWindow = true; - probe.EnableRaisingEvents = true; - probe.Start(); - - while (!probe.StandardOutput.EndOfStream) - { - lines_ouput.Add(probe.StandardOutput.ReadLine()); - } - probe.WaitForExit(); - - if (lines_ouput[0] != null && lines_ouput[0].Length > 0) - { - if (lines_ouput[0].ToLower().Contains(" kb/s")) unit = "Kb/s"; - if (lines_ouput[0].ToLower().Contains(" mb/s")) unit = "Mb/s"; - if (lines_ouput[0].ToLower().Contains(" gb/s")) unit = "Gb/s"; - lines_ouput[0] = lines_ouput[0].Replace(" kb/s", "").Replace(" Mb/s", "").Replace(" Gb/s", ""); - lines_ouput[0] = lines_ouput[0].Replace(" ", sep_th); - lbl_bitrate.Text = Strings.bitrate + ":" + " " + lines_ouput[0] + " " + unit; - } - if (lines_ouput[1] != null && lines_ouput[1].Length > 0) lbl_est_size.Text = Strings.f_size + ":" + " " + lines_ouput[1].Replace("MiB", "MB").Replace("GiB", "GB").Replace("KiB", "KB"); - if (lines_ouput[2] != null && lines_ouput[2].Length > 0) dur = lines_ouput[2]; - })); - - if (no_output_pop == false) - { - Form26 frm26 = new Form26(); - frm26.out_file = dest_demux; - frm26.dur_file = dur; - if (Settings.Default.dark_mode == false) frm26.pic_img = pic_reading.Image; - else frm26.pic_img = pic_reading.InitialImage; - frm26.tot_bit = lbl_bitrate.Text; - frm26.out_size = lbl_est_size.Text; - this.Invoke(new MethodInvoker(delegate - { - frm26.Show(this); - if (frm26.no_pop == true) no_output_pop = true; - })); - } - } - } - - //End output single info - - if (play_on_end == true) play_end(); - if (Form.ActiveForm == null) - { - notifyIcon1.Visible = true; - notifyIcon1.BalloonTipText = Strings.stream_saved; - notifyIcon1.BalloonTipIcon = ToolTipIcon.Info; - notifyIcon1.BalloonTipTitle = Strings.stream_saved2; - notifyIcon1.ShowBalloonTip(0); - } - - if (chk_open_compl.Checked) - { - if (Directory.GetFiles(destino).Length != 0) - { - Process open_processed = new Process(); - open_processed.StartInfo.FileName = "explorer.exe"; - open_processed.StartInfo.Arguments = '\u0022' + destino + '\u0022'; - open_processed.Start(); - } - else - { - if (Directory.Exists(destino)) - { - Directory.Delete(destino); - } - } - } - } - } - else - { - if (tmp.ExitCode == 0) - { - this.InvokeEx(f => f.Pg1.Text = "100%"); - this.InvokeEx(f => MessageBox.Show(Strings.str_abort, Strings.aborted, MessageBoxButtons.OK, MessageBoxIcon.Error)); - } - else - { - this.InvokeEx(f => f.Pg1.Text = "100%"); - Boolean unsupported = false; - foreach (String lin in list_lines) - { - if (lin.Contains("Could not write header")) unsupported = true; - } - if (unsupported == true) this.InvokeEx(f => MessageBox.Show(Strings.err_oc + " " + Environment.NewLine + Environment.NewLine + "Possibly incompatible container for selected track" + Environment.NewLine + Environment.NewLine + Strings.check_log, Strings.err_save_track, MessageBoxButtons.OK, MessageBoxIcon.Error)); - else this.InvokeEx(f => MessageBox.Show(Strings.err_oc + " " + Environment.NewLine + Environment.NewLine + err_txt.TrimStart() + Environment.NewLine + Environment.NewLine + Strings.check_log, Strings.err_save_track, MessageBoxButtons.OK, MessageBoxIcon.Error)); - } - } - }).Start(); - } - - private void btn_help_Click(object sender, EventArgs e) - { - String loc = Settings.Default.app_lang; - if (loc == "es") Process.Start(man_es_url); - else Process.Start(man_en_url); - } - - private void CB1_o_SelectedIndexChanged(object sender, EventArgs e) - { - audio_capture_device = CB1_o.SelectedItem.ToString(); - } - - private void boton_ok_path_Click(object sender, EventArgs e) - { - if (path_txt.Text == String.Empty) - { - MessageBox.Show(Strings.path_empty); - return; - } - if (path_txt.Text.Substring(0, 1) == "\\") - { - MessageBox.Show(Strings.please_not + " " + "\\" + Strings.characters); - return; - } - - if (path_txt.Text.Contains("¿") || path_txt.Text.Contains("?") || path_txt.Text.Contains(":") || path_txt.Text.Contains(".") || path_txt.Text.Contains("/") || path_txt.Text.Contains(">") || path_txt.Text.Contains(">") || path_txt.Text.Contains(",") || path_txt.Text.Contains("{") || path_txt.Text.Contains("}") || path_txt.Text.Contains("&") || path_txt.Text.Contains("%")) - { - MessageBox.Show(Strings.invalid_ch); - return; - } - - txt_path_main.Text = ".\\" + path_txt.Text; - txt_path_mux.Text = txt_path_main.Text; - txt_path_main.BackColor = groupBox1.BackColor; - //btn_reset_path.BackColor = groupBox1.BackColor; - path_txt.Text = String.Empty; - btn_save_path.Enabled = true; - ActiveForm.Close(); - } - - private void path_txt_KeyDown(object sender, KeyEventArgs e) - { - if (e.KeyCode == Keys.Enter) - { - if (path_txt.Text == String.Empty) - { - return; - } - if (path_txt.Text.Substring(0, 1) == "\\") - { - MessageBox.Show(Strings.please_not + " " + "\\" + Strings.characters); - return; - } - - if (path_txt.Text.Contains("¿") || path_txt.Text.Contains("?") || path_txt.Text.Contains(":") || path_txt.Text.Contains(".") || path_txt.Text.Contains("/") || path_txt.Text.Contains(">") || path_txt.Text.Contains(">") || path_txt.Text.Contains(",") || path_txt.Text.Contains("{") || path_txt.Text.Contains("}") || path_txt.Text.Contains("&") || path_txt.Text.Contains("%")) - { - MessageBox.Show(Strings.invalid_ch); - return; - } - - txt_path_main.Text = ".\\" + path_txt.Text; - txt_path_mux.Text = txt_path_main.Text; - txt_path_main.BackColor = groupBox1.BackColor; - //btn_reset_path.BackColor = groupBox1.BackColor; - path_txt.Text = String.Empty; - btn_save_path.Enabled = true; - ActiveForm.Close(); - } - } - - private void boton_ok_audio_Click(object sender, EventArgs e) - { - prev_dev_audio = CB1_o.SelectedItem.ToString(); - ActiveForm.Close(); - abort_capture = false; - - //throw new NotImplementedException(); - } - - private void btn_wizard_Click(object sender, EventArgs e) - { - Pg1.Focus(); - String ffm = Path.Combine(Application.StartupPath, "AeroWizard.dll"); - if (!File.Exists(ffm)) - { - MessageBox.Show(Strings.no_aerowiz, Strings.required_file, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (tabControl1.SelectedIndex != 0) tabControl1.SelectedIndex = 0; - - AeroWizard1 wizard1 = new AeroWizard1(); - wizard1.curr_ff = btn_change_ff.Text; - if (show_wiz == true) - { - wizard1.chk_start.Checked = true; - wizard1.chk_start_0.Checked = true; - } - else - { - wizard1.chk_start.Checked = false; - wizard1.chk_start_0.Checked = false; - } - wizard1.StartPosition = FormStartPosition.CenterScreen; - - if (listView1.Items.Count > 0) - { - if (listView1.SelectedIndices.Count == 1) - { - wizard1.lv1_item = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - wizard1.lv1_dur = listView1.SelectedItems[0].SubItems[3].Text; - } - else - { - wizard1.lv1_item = listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text; - wizard1.lv1_dur = listView1.Items[0].SubItems[3].Text; - } - } - - if (show_wiz_start == true) wizard1.start_no_files = true; - else wizard1.start_no_files = false; - if (is_portable == true) wizard1.is_portable = true; - else wizard1.is_portable = true; - wizard1.ShowDialog(); - - if (wizard1.online_pr == true) - { - presetsOnlineToolStripMenuItem.PerformClick(); - return; - } - - if (wizard1.add_files == true) - { - from_wizard = true; - btn_add_files.PerformClick(); - return; - } - if (wizard1.add_folder == true) - { - from_wizard = true; - btn_add_folders.PerformClick(); - return; - } - if (wizard1.chk_start.Checked == true || wizard1.chk_start_0.Checked == true) show_wiz = true; - else show_wiz = false; - if (wizard1.no_two == true) return; - if (wizard1.wiz_two_pass == true) - { - this.Cursor = Cursors.WaitCursor; - menu_two_pass_wizard.PerformClick(); - this.Cursor = Cursors.Arrow; - return; - } - if (wizard1.w_images == true) - { - this.Cursor = Cursors.WaitCursor; - menu_extract_images.PerformClick(); - this.Cursor = Cursors.Arrow; - return; - } - - if (wizard1.w_split == true) - { - this.Cursor = Cursors.WaitCursor; - menu_split.PerformClick(); - this.Cursor = Cursors.Arrow; - return; - } - if (wizard1.no_silence == true) return; - if (wizard1.wiz_silence == true) - { - this.Cursor = Cursors.WaitCursor; - this.Cursor = Cursors.Arrow; - detect_silence(); - return; - } - - if (wizard1.no_img_v == true) return; - if (wizard1.wiz_img_v == true) - { - this.Cursor = Cursors.WaitCursor; - this.Cursor = Cursors.Arrow; - menu_img_v.PerformClick(); - return; - } - - if (wizard1.wiz_params != String.Empty) - { - if (wizard1.sel_preset != String.Empty) - { - try - { - combo_presets.SelectedIndex = combo_presets.FindString(wizard1.sel_preset); - } - catch { } - } - else - { - combo_presets.SelectedIndex = combo_presets.Items.Count - 1; - combo_presets.Text = Strings.new_preset; - } - - txt_parameters.Text = wizard1.wiz_params; - txt_format.Text = wizard1.wiz_ext; - txt_pre_input.Text = wizard1.pre_input; - } - if (wizard1.wiz_preset != String.Empty && wizard1.wiz_save_preset == true) - { - combo_presets.SelectedIndex = combo_presets.Items.Count - 1; - txt_parameters.Text = wizard1.wiz_params; - txt_format.Text = wizard1.wiz_ext; - combo_presets.Text = wizard1.wiz_preset; - btn_save_preset.PerformClick(); - } - } - - private void txt_mux_type_Enter(object sender, EventArgs e) - { - txt_mux_type.Enabled = false; - txt_mux_type.Enabled = true; - } - - private void combo_def_und_lang_DropDown(object sender, EventArgs e) - { - combo_def_und_lang.SelectedIndex = 0; - } - - private void ct3_combo_language_DropDown(object sender, EventArgs e) - { - ct3_combo_language.SelectedIndex = 0; - } - - private void Combo_single_subs_lang_DropDown(object sender, EventArgs e) - { - Combo_single_subs_lang.SelectedIndex = 0; - } - - private void BG_refresh_dur_DoWork(object sender, DoWorkEventArgs e) - { - - this.Invoke(new MethodInvoker(delegate - { - listView1.BeginUpdate(); - Disable_Controls(); - btn_abort_all.Enabled = false; - group_prog.Focus(); - btn_cancel_add.Enabled = true; - btn_cancel_add.Visible = true; - btn_cancel_add.Refresh(); - LB_Wait.Visible = true; - LB_Wait.Text = Strings.ref_dur; - LB_Wait.Refresh(); - pg_adding.Visible = true; - pg_adding.Value = 0; - txt_adding_p.Visible = true; - txt_adding_p.Refresh(); - pg_adding.Maximum = listView1.Items.Count; - })); - - canceled_file_adding = false; - Process probe = new Process(); - - for (int i = 0; i < list_global_proc.Items.Count; i++) - { - if (canceled_file_adding == true) continue; - - this.Invoke(new MethodInvoker(delegate - { - pg_adding.Value = pg_adding.Value + 1; - txt_adding_p.Text = (pg_adding.Value * 100 / list_global_proc.Items.Count + "%"); - txt_adding_p.Refresh(); - })); - - if (list_global_proc.Items[i].SubItems[3].Text == Strings.pending || list_global_proc.Items[i].SubItems[3].Text == Strings.n_a) - { - probe.StartInfo.FileName = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - String ffprobe_frames = " " + '\u0022' + "--Inform=General;%Duration/String3%" + '\u0022'; - probe.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + list_global_proc.Items[i].Text + '\u0022'; - - probe.StartInfo.RedirectStandardOutput = true; - probe.StartInfo.UseShellExecute = false; - probe.StartInfo.CreateNoWindow = true; - probe.EnableRaisingEvents = true; - probe.Start(); - - String duracion = probe.StandardOutput.ReadLine(); - probe.WaitForExit(); - - if (duracion != null) - { - TimeSpan time; - if (TimeSpan.TryParse(duracion, out time)) - { - this.InvokeEx(f => f.listView1.Items[i].SubItems[3].Text = duracion); - - if (duracion.Length >= 12) - { - if (duracion.Substring(0, 11) == "0:00:00.000" || duracion.Substring(0, 12) == "00:00:00.000") - { - this.InvokeEx(f => f.listView1.Items[i].BackColor = Color.LightGoldenrodYellow); - } - } - } - else - { - this.InvokeEx(f => f.listView1.Items[i].SubItems[3].Text = Strings.n_a); - this.InvokeEx(f => f.listView1.Items[i].BackColor = Color.LightGoldenrodYellow); - } - } - else - { - this.InvokeEx(f => f.listView1.Items[i].SubItems[3].Text = Strings.n_a); - this.InvokeEx(f => f.listView1.Items[i].BackColor = Color.LightGoldenrodYellow); - } - } - } - - this.Invoke(new MethodInvoker(delegate - { - lbl_items.Text = listView1.Items.Count + " " + Strings.files; - LB_Wait.Text = ""; - txt_adding_p.Visible = false; - listView1.EndUpdate(); - Enable_Controls(); - chkshut.Enabled = true; - btn_pause.Enabled = true; - btn_cancel_add.Visible = false; - txt_adding_p.Text = ""; - txt_adding_p.Visible = false; - lbl_items.Visible = true; - lbl_dur_list.Visible = true; - lbl_size.Visible = true; - pg_adding.Visible = false; - LB_Wait.Visible = false; - tabControl1.Enabled = true; - })); - - } - - private void btn_edit_config_Click(object sender, EventArgs e) - { - Pg1.Focus(); - menu_settings.PerformClick(); - } - - private void combo_shut_SelectedIndexChanged(object sender, EventArgs e) - { - String f_run_end = String.Empty; - String f_run_each = String.Empty; - if (is_portable == false) - { - f_run_end = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_run_end.ini"; - f_run_each = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_run_each.ini"; - } - else - { - f_run_end = port_path + "ff_run_end_portable.ini"; - f_run_each = port_path + "ff_run_each_portable.ini"; - } - - if (combo_shut.SelectedIndex < 3) shut_type = combo_shut.SelectedItem.ToString(); - else - { - if (combo_shut.SelectedIndex == 3) - { - Form13 frm_run = new Form13(); - frm_run.run_each = false; - frm_run.Text = Strings.open_comp; - frm_run.label3.Text = Strings.sel_app; - - if (File.Exists(f_run_end)) - { - int linea = 0; - foreach (String line in File.ReadLines(f_run_end)) - { - if (linea == 0) frm_run.txt_path.Text = line; - if (linea == 1) frm_run.txt_args.Text = line; - linea = linea + 1; - } - } - - frm_run.ShowDialog(); - if (frm_run.cancel == false) - { - run_command = frm_run.txt_path.Text; - run_command_args = frm_run.txt_args.Text; - try - { - File.WriteAllText(f_run_end, frm_run.txt_path.Text + Environment.NewLine + frm_run.txt_args.Text); - } - catch { } - } - else - { - run_command = String.Empty; - run_command_args = frm_run.txt_args.Text; - combo_shut.SelectedIndex = 0; - chkshut.Checked = false; - } - } - if (combo_shut.SelectedIndex == 4) - { - Form13 frm_run = new Form13(); - frm_run.run_each = true; - frm_run.Text = Strings.runcomm; - frm_run.label3.Text = Strings.runcom2; - if (File.Exists(f_run_each)) - { - int linea = 0; - foreach (String line in File.ReadLines(f_run_each)) - { - if (linea == 0) frm_run.txt_path.Text = line; - if (linea == 1) frm_run.txt_args.Text = line; - linea = linea + 1; - } - } - frm_run.ShowDialog(); - if (frm_run.cancel == false) - { - run_command = frm_run.txt_path.Text; - run_command_args = frm_run.txt_args.Text; - try - { - File.WriteAllText(f_run_each, frm_run.txt_path.Text + Environment.NewLine + frm_run.txt_args.Text); - } - catch { } - } - else - { - run_command = String.Empty; - run_command_args = frm_run.txt_args.Text; - combo_shut.SelectedIndex = 0; - chkshut.Checked = false; - } - } - if (combo_shut.SelectedIndex == 5) - { - Form29 frm29 = new Form29(); - frm29.ShowDialog(); - if (frm29.chk_battery.Checked) Settings.Default.pause_bat = true; - else Settings.Default.pause_bat = false; - if (frm29.chk_bat_level.Checked) - { - Settings.Default.if_bat_low = true; - Settings.Default.bat_level = frm29.n_bat_l.Value; - } - else Settings.Default.if_bat_low = false; - } - } - } - - private void fade_v_in_CheckedChanged(object sender, EventArgs e) - { - if (fade_v_in.CheckState == CheckState.Checked) - { - num_v_in.Enabled = true; - combo_vin_col.Enabled = true; - if (txt_parameters.Text.Contains("-c:v copy") || txt_parameters.Text.Contains("-vcodec copy") || txt_parameters.Text.Contains("-c copy")) - { - MessageBox.Show(Strings.fade_str); - } - } - else - { - num_v_in.Enabled = false; - combo_vin_col.Enabled = false; - } - } - - private void fade_v_out_CheckedChanged(object sender, EventArgs e) - { - if (fade_v_out.CheckState == CheckState.Checked) - { - num_v_out.Enabled = true; - combo_vout_color.Enabled = true; - if (txt_parameters.Text.Contains("-c:v copy") || txt_parameters.Text.Contains("-vcodec copy") || txt_parameters.Text.Contains("-c copy")) - { - MessageBox.Show(Strings.fade_str); - } - if (txt_parameters.Text.Contains("-vf") || txt_parameters.Text.Contains("-filter:v")) - { - MessageBox.Show(Strings.fade_vf); - } - } - else - { - num_v_out.Enabled = false; - combo_vout_color.Enabled = false; - } - } - - private void fade_a_in_CheckedChanged(object sender, EventArgs e) - { - if (fade_a_in.CheckState == CheckState.Checked) - { - num_a_in.Enabled = true; - if (txt_parameters.Text.Contains("-c:a copy") || txt_parameters.Text.Contains("-acodec copy") || txt_parameters.Text.Contains("-c copy")) - { - MessageBox.Show(Strings.fade_str); - } - } - else - { - num_a_in.Enabled = false; - } - } - - private void fade_a_out_CheckedChanged(object sender, EventArgs e) - { - if (fade_a_out.CheckState == CheckState.Checked) - { - num_a_out.Enabled = true; - if (txt_parameters.Text.Contains("-c:a copy") || txt_parameters.Text.Contains("-acodec copy") || txt_parameters.Text.Contains("-c copy")) - { - MessageBox.Show(Strings.fade_str); - } - if (txt_parameters.Text.Contains("-af") || txt_parameters.Text.Contains("-filter:a")) - { - MessageBox.Show(Strings.fade_af); - } - } - else - { - num_a_out.Enabled = false; - } - } - - private void multiple_presets_Click(object sender, EventArgs e) - { - Pg1.Focus(); - lbl_est_size.Text = ""; - lbl_bitrate.Text = ""; - if (!File.Exists(Path.Combine(Application.StartupPath, "ffmpeg.exe"))) - { - MessageBox.Show(Strings.no_ffmpeg, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (check_ff_md5() == false) - { - Form25 frm25 = new Form25(); - frm25.ShowDialog(); - return; - } - - String ffm = Path.Combine(Application.StartupPath, "AeroWizard.dll"); - if (!File.Exists(ffm)) - { - MessageBox.Show(Strings.no_aerowiz, Strings.required_file, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (listView1.Items.Count == 0) - { - MessageBox.Show(Strings.list_empty, Strings.no_files, MessageBoxButtons.OK, MessageBoxIcon.Information); - return; - } - - foreach (ListViewItem file2 in listView1.Items) - { - if (!File.Exists(file2.SubItems[1].Text + "\\" + file2.Text)) - { - MessageBox.Show(Strings.file_not_found + " " + file2.Text, Strings.file_not_found2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - String element = listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text; - String is_overw = txt_path_main.Text + "\\" + Path.GetFileNameWithoutExtension(element) + "." + txt_format.Text; - - if (is_overw == element && chk_suffix.Checked == false) - { - MessageBox.Show(Strings.overw_not_en + " " + '\u0022' + Strings.ren_out + '\u0022' + " " + Strings.checkb, Strings.overw_not_all, MessageBoxButtons.OK, MessageBoxIcon.Error); - - return; - } - DateTime time2; - if (!DateTime.TryParse(ss_time_input.Text, out time2)) - { - MessageBox.Show(Strings.pre_input1, Strings.pre_input2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (ss_time_input.Text != "0:00:00") - { - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[3].Text != Strings.n_a && item.SubItems[3].Text != "0:00:00" && item.SubItems[3].Text != "00:00:00" && item.SubItems[3].Text != Strings.pending && Settings.Default.quick_queue == false) - { - if (TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds <= TimeSpan.Parse(ss_time_input.Text).TotalSeconds) - { - MessageBox.Show(Strings.pre_input3 + " " + '\u0022' + Path.GetFileName(item.Text) + '\u0022', Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - } - } - - DateTime time; - if (!DateTime.TryParse(ss_time_input.Text, out time)) - { - MessageBox.Show(Strings.pre_input1, Strings.pre_input2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - avoid_overw(); - - //Check path is writable - String destino1 = String.Empty; - Boolean rel_path = false; - if (txt_path_main.Text.Contains(".\\")) - { - destino1 = element.Substring(0, element.LastIndexOf('\\')) + txt_path_main.Text.Replace(".", String.Empty); - rel_path = true; - } - else - { - if (chk_recreate.CheckState == CheckState.Checked) - { - String pre_dest = Path.GetDirectoryName(element); - destino1 = Path.Combine(txt_path_main.Text, pre_dest.Substring(3, pre_dest.Length - 3)); - rel_path = true; - } - else - { - destino1 = txt_path_main.Text; - } - } - - try - { - if (rel_path == true) - { - Directory.CreateDirectory(destino1); - System.Threading.Thread.Sleep(25); - } - else - { - File.WriteAllText(destino1 + "\\" + "FFBatch_test.txt", "FFBatch_test"); - System.Threading.Thread.Sleep(25); - File.Delete(destino1 + "\\" + "FFBatch_test.txt"); - } - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.write_error1 + " " + excpt.Message, Strings.write_error2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - //End path is writable - if (avoid_overwriting == true && txt_path_main.Text.Contains(".\\") == false && txt_path_main.Text.Length < 4 && chk_recreate.CheckState != CheckState.Checked) - { - avoid_overwriting = false; - DialogResult a2 = MessageBox.Show(Strings.multiple_folders + " " + '\u0022' + Strings.recreate_path + '\u0022' + " " + "to avoid opossible overwritings." + Environment.NewLine + Environment.NewLine + Strings.continu, "Different input folders to single output folder", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); - if (a2 == DialogResult.No) return; - } - - //Wizard - AeroWizard2 wizard2 = new AeroWizard2(); - wizard2.StartPosition = FormStartPosition.CenterScreen; - wizard2.pr1_string = multi_pr1; - wizard2.pr1_string_ext = multi_pr1_ext; - wizard2.pr2_string = multi_pr2; - wizard2.pr2_string_ext = multi_pr2_ext; - wizard2.pr3_string = multi_pr3; - wizard2.pr3_string_ext = multi_pr3_ext; - wizard2.ShowDialog(); - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - if (wizard2.cancelled_w == true) return; - n_multi_presets = wizard2.n_presets_w; - multi_pr1 = wizard2.pr1_string; - multi_pr1_ext = wizard2.pr1_string_ext; - multi_pr2 = wizard2.pr2_string; - multi_pr2_ext = wizard2.pr2_string_ext; - multi_pr3 = wizard2.pr3_string; - multi_pr3_ext = wizard2.pr3_string_ext; - ren_multi = wizard2.rename_w; - start_multiple(); - } - - private void BG_Try_multi_DoWork(object sender, DoWorkEventArgs e) - { - tried_ok = false; - this.InvokeEx(f => this.Cursor = Cursors.WaitCursor); - ListBox LB1_o = new ListBox(); - Process consola_pre = new Process(); - String file_prueba = ""; - String sel_test = ""; - this.InvokeEx(f => sel_test = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text); - file_prueba = sel_test; - String destino_test = Path.GetTempPath() + "\\" + "FFBatch_test"; - Boolean bad_chars = false; - Boolean unsupported = false; - - Task tt = Task.Run(() => - { - String fichero = Path.GetFileName(file_prueba); - - if (!Directory.Exists(destino_test)) - { - try - { - Directory.CreateDirectory(destino_test); - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.error2 + " " + excpt.Message, Strings.write_error2, MessageBoxButtons.OK, MessageBoxIcon.Error); - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - return; - } - } - - String ext_output = "." + multi_pr1_ext; - textbox_params = multi_pr1; - String file_prueba2 = file_prueba; - - if (textbox_params.Contains("%fn")) - { - textbox_params = textbox_params.Replace("%fn", Path.GetFileNameWithoutExtension(file_prueba)); - } - if (textbox_params.Contains("%fp")) - { - textbox_params = textbox_params.Replace("%fp", Path.GetDirectoryName(file_prueba)); - } - if (textbox_params.Contains("%fd")) - { - var dirName = new DirectoryInfo(Path.GetDirectoryName(file_prueba)).Name; - textbox_params = textbox_params.Replace("%fd", dirName); - } - - if (textbox_params.Contains("%1")) - { - if (file_prueba2.Contains("[") || file_prueba2.Contains("]")) - { - MessageBox.Show(Strings.conflict_char, Strings.conflict_char2, MessageBoxButtons.OK, MessageBoxIcon.Warning); - Enable_Controls(); - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - tried_ok = false; - bad_chars = true; - return; - } - file_prueba2 = file_prueba2.Replace("\\", "\\\\\\\\"); - file_prueba2 = file_prueba2.Replace(":", ":" + "\\\\"); - textbox_params = textbox_params.Replace("%1", file_prueba2); - } - - String pre_i = ""; - txt_pre_input.Invoke(new MethodInvoker(delegate - { - pre_i = txt_pre_input.Text; - })); - - consola_pre.StartInfo.FileName = "ffmpeg.exe"; - consola_pre.StartInfo.Arguments = pre_i + " " + hw_decode_glob + " -i " + "" + '\u0022' + file_prueba + '\u0022' + "" + " -y " + textbox_params + " " + '\u0022' + destino_test + "\\" + Path.GetFileNameWithoutExtension(file_prueba) + ext_output + '\u0022'; - - consola_pre.StartInfo.RedirectStandardOutput = true; - consola_pre.StartInfo.RedirectStandardError = true; - consola_pre.StartInfo.UseShellExecute = false; - consola_pre.StartInfo.CreateNoWindow = true; - consola_pre.EnableRaisingEvents = true; - consola_pre.Start(); - - while (!consola_pre.StandardError.EndOfStream) - { - this.Invoke(new MethodInvoker(delegate - { - LB1_o.Items.Add(consola_pre.StandardError.ReadLine()); - LB1_o.TopIndex = LB1_o.Items.Count - 1; - LB1_o.Refresh(); - })); - } - - consola_pre.WaitForExit(); - consola_pre.StartInfo.Arguments = String.Empty; - }); - - if (!tt.Wait(675) && consola_pre.StartInfo.Arguments != String.Empty) - { - consola_pre.Kill(); - tried_ok = true; - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - - if (Directory.Exists(destino_test) && Directory.GetFiles(destino_test).Length > 0) - { - foreach (String file in Directory.GetFiles(destino_test)) - { - try - { - File.Delete(file); - } - catch - { - } - } - } - - if (Directory.GetFiles(destino_test).Length == 0) - { - Directory.Delete(destino_test); - } - //tried_params.Add(multi_pr1); - LB1_o.Items.Clear(); - return; - } - - if (bad_chars == false) - { - if (consola_pre.ExitCode != 0) - { - if (Directory.Exists(destino_test) && Directory.GetFiles(destino_test).Length > 0) - { - foreach (String file in Directory.GetFiles(destino_test)) - { - try - { - File.Delete(file); - } - catch - { - } - } - } - - if (Directory.GetFiles(destino_test).Length == 0) - { - Directory.Delete(destino_test); - } - - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - foreach (String lin in LB1_o.Items) - { - if (lin.Contains("not load the requested plugin") || lin.Contains("Cannot load nvcuda.dll")) - { - unsupported = true; - } - } - if (unsupported == true) MessageBox.Show(Strings.test_fail1 + " " + "1:" + " " + Environment.NewLine + Environment.NewLine + Strings.unsup_enc + Environment.NewLine + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 1].ToString() + Environment.NewLine + Environment.NewLine + Strings.try_pr, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - else MessageBox.Show(Strings.test_fail1 + " " + "1:" + " " + Environment.NewLine + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 1].ToString() + Environment.NewLine + Environment.NewLine + Strings.try_pr, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - - tried_ok = false; - return; - } - else - { - System.Threading.Thread.Sleep(50); - if (Directory.Exists(destino_test) && Directory.GetFiles(destino_test).Length > 0) - { - foreach (String file in Directory.GetFiles(destino_test)) - { - try - { - File.Delete(file); - } - catch - { - } - } - } - - if (Directory.Exists(destino_test) && Directory.GetFiles(destino_test).Length == 0) - { - Directory.Delete(destino_test); - } - //tried_params.Add(multi_pr1); - tried_ok = true; - } - } - //END try preset - - LB1_o.Items.Clear(); - consola_pre.Dispose(); - } - - private void BG_Try_multi_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) - { - String file_prueba = ""; - String sel_test = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - file_prueba = sel_test; - String destino = Path.Combine(Path.GetTempPath(), "\\" + "FFBatch_test"); - String borrar = destino + "\\" + Path.GetFileNameWithoutExtension(file_prueba) + "." + txt_format.Text; - - if (File.Exists(borrar)) - { - try - { - File.Delete(borrar); - } - catch - { - } - } - - if (Directory.Exists(destino) == true) - { - if (Directory.GetFiles(destino).Length == 0) - { - try - { - Directory.Delete(destino); - } - catch { } - } - } - if (tried_ok == true) bg_try_multi_2.RunWorkerAsync(); - else this.InvokeEx(f => this.Cursor = Cursors.Arrow); - } - - private void bg_try_multi_2_DoWork(object sender, DoWorkEventArgs e) - { - tried_ok = false; - this.InvokeEx(f => this.Cursor = Cursors.WaitCursor); - ListBox LB1_o = new ListBox(); - Process consola_pre = new Process(); - String file_prueba = ""; - String sel_test = ""; - this.InvokeEx(f => sel_test = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text); - file_prueba = sel_test; - String destino_test = Path.Combine(Path.GetTempPath(), "\\" + "FFBatch_test"); - Boolean bad_chars = false; - Boolean unsupported = false; - - Task tt = Task.Run(() => - { - String fichero = Path.GetFileName(file_prueba); - - if (!Directory.Exists(destino_test)) - { - try - { - Directory.CreateDirectory(destino_test); - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.error2 + " " + excpt.Message, Strings.write_error2, MessageBoxButtons.OK, MessageBoxIcon.Error); - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - return; - } - } - - String ext_output = "." + multi_pr2_ext; - - textbox_params = multi_pr2; - String file_prueba2 = file_prueba; - - if (textbox_params.Contains("%fn")) - { - textbox_params = textbox_params.Replace("%fn", Path.GetFileNameWithoutExtension(file_prueba)); - } - if (textbox_params.Contains("%fp")) - { - textbox_params = textbox_params.Replace("%fp", Path.GetDirectoryName(file_prueba)); - } - if (textbox_params.Contains("%fd")) - { - var dirName = new DirectoryInfo(Path.GetDirectoryName(file_prueba)).Name; - textbox_params = textbox_params.Replace("%fd", dirName); - } - - if (textbox_params.Contains("%1")) - { - if (file_prueba2.Contains("[") || file_prueba2.Contains("]")) - { - MessageBox.Show(Strings.conflict_char, Strings.conflict_char2, MessageBoxButtons.OK, MessageBoxIcon.Warning); - Enable_Controls(); - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - tried_ok = false; - bad_chars = true; - return; - } - file_prueba2 = file_prueba2.Replace("\\", "\\\\\\\\"); - file_prueba2 = file_prueba2.Replace(":", ":" + "\\\\"); - textbox_params = textbox_params.Replace("%1", file_prueba2); - } - - String pre_i = ""; - txt_pre_input.Invoke(new MethodInvoker(delegate - { - pre_i = txt_pre_input.Text; - })); - - consola_pre.StartInfo.FileName = "ffmpeg.exe"; - consola_pre.StartInfo.Arguments = pre_i + " " + hw_decode_glob + " -i " + "" + '\u0022' + file_prueba + '\u0022' + "" + " -y " + textbox_params + " " + '\u0022' + destino_test + "\\" + Path.GetFileNameWithoutExtension(file_prueba) + ext_output + '\u0022'; - consola_pre.StartInfo.RedirectStandardOutput = true; - consola_pre.StartInfo.RedirectStandardError = true; - consola_pre.StartInfo.UseShellExecute = false; - consola_pre.StartInfo.CreateNoWindow = true; - consola_pre.EnableRaisingEvents = true; - consola_pre.Start(); - - while (!consola_pre.StandardError.EndOfStream) - { - this.Invoke(new MethodInvoker(delegate - { - LB1_o.Items.Add(consola_pre.StandardError.ReadLine()); - LB1_o.TopIndex = LB1_o.Items.Count - 1; - LB1_o.Refresh(); - })); - } - - consola_pre.WaitForExit(); - consola_pre.StartInfo.Arguments = String.Empty; - }); - - if (!tt.Wait(675) && consola_pre.StartInfo.Arguments != String.Empty) - { - consola_pre.Kill(); - tried_ok = true; - - if (Directory.Exists(destino_test) && Directory.GetFiles(destino_test).Length > 0) - { - foreach (String file in Directory.GetFiles(destino_test)) - { - try - { - File.Delete(file); - } - catch - { - } - } - } - - if (Directory.GetFiles(destino_test).Length == 0) - { - Directory.Delete(destino_test); - } - - tried_params.Add(multi_pr2); - LB1_o.Items.Clear(); - return; - } - - if (bad_chars == false) - { - if (consola_pre.ExitCode != 0) - { - if (Directory.Exists(destino_test) && Directory.GetFiles(destino_test).Length > 0) - { - foreach (String file in Directory.GetFiles(destino_test)) - { - try - { - File.Delete(file); - } - catch - { - } - } - } - - if (Directory.GetFiles(destino_test).Length == 0) - { - Directory.Delete(destino_test); - } - - foreach (String lin in LB1_o.Items) - { - if (lin.Contains("not load the requested plugin") || lin.Contains("Cannot load nvcuda.dll")) - { - unsupported = true; - } - } - if (unsupported == true) MessageBox.Show(Strings.test_fail1 + " " + "2:" + " " + Environment.NewLine + Environment.NewLine + Strings.unsup_enc + Environment.NewLine + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 1].ToString() + Environment.NewLine + Environment.NewLine + Strings.try_pr, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - else MessageBox.Show(Strings.test_fail1 + " " + "2:" + " " + Environment.NewLine + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 1].ToString() + Environment.NewLine + Environment.NewLine + Strings.try_pr, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - tried_ok = false; - return; - } - else - { - System.Threading.Thread.Sleep(50); - if (Directory.Exists(destino_test) && Directory.GetFiles(destino_test).Length > 0) - { - foreach (String file in Directory.GetFiles(destino_test)) - { - try - { - File.Delete(file); - } - catch - { - } - } - } - - if (Directory.Exists(destino_test) && Directory.GetFiles(destino_test).Length == 0) - { - Directory.Delete(destino_test); - } - tried_params.Add(multi_pr2); - tried_ok = true; - } - } - //END try preset - - if (Directory.Exists(destino_test)) - { - if (Directory.GetFiles(destino_test).Length == 0) - { - Directory.Delete(destino_test); - } - } - LB1_o.Items.Clear(); - consola_pre.Dispose(); - } - - private void bg_try_multi_2_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) - { - this.Cursor = Cursors.Arrow; - String file_prueba = ""; - String sel_test = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - file_prueba = sel_test; - String destino = Path.GetTempPath() + "\\" + "FFBatch_test"; - String borrar = destino + "\\" + Path.GetFileNameWithoutExtension(file_prueba) + "." + txt_format.Text; - - if (File.Exists(borrar)) - { - try - { - File.Delete(borrar); - } - catch - { - } - } - - if (Directory.Exists(destino) == true) - { - if (Directory.GetFiles(destino).Length == 0) - { - Directory.Delete(destino); - } - } - if (tried_ok == true && n_multi_presets == 3) bg_multi_3.RunWorkerAsync(); - if (tried_ok == true && n_multi_presets == 2) - { - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - start_multiple(); - } - else this.InvokeEx(f => this.Cursor = Cursors.Arrow); - } - - private void bg_multi_3_DoWork(object sender, DoWorkEventArgs e) - { - tried_ok = false; - this.InvokeEx(f => this.Cursor = Cursors.WaitCursor); - ListBox LB1_o = new ListBox(); - Process consola_pre = new Process(); - String file_prueba = ""; - String sel_test = ""; - this.InvokeEx(f => sel_test = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text); - file_prueba = sel_test; - String destino_test = Path.Combine(Path.GetTempPath(), "\\" + "FFBatch_test"); - Boolean bad_chars = false; - Boolean unsupported = false; - - Task tt = Task.Run(() => - { - String fichero = Path.GetFileName(file_prueba); - - if (!Directory.Exists(destino_test)) - { - try - { - Directory.CreateDirectory(destino_test); - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.error2 + " " + excpt.Message, Strings.write_error2, MessageBoxButtons.OK, MessageBoxIcon.Error); - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - return; - } - } - - String ext_output = "." + multi_pr3_ext; - - textbox_params = multi_pr3; - String file_prueba2 = file_prueba; - - if (textbox_params.Contains("%fn")) - { - textbox_params = textbox_params.Replace("%fn", Path.GetFileNameWithoutExtension(file_prueba)); - } - if (textbox_params.Contains("%fp")) - { - textbox_params = textbox_params.Replace("%fp", Path.GetDirectoryName(file_prueba)); - } - if (textbox_params.Contains("%fd")) - { - var dirName = new DirectoryInfo(Path.GetDirectoryName(file_prueba)).Name; - textbox_params = textbox_params.Replace("%fd", dirName); - } - - if (textbox_params.Contains("%1")) - { - if (file_prueba2.Contains("[") || file_prueba2.Contains("]")) - { - MessageBox.Show(Strings.conflict_char, Strings.conflict_char2, MessageBoxButtons.OK, MessageBoxIcon.Warning); - Enable_Controls(); - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - tried_ok = false; - bad_chars = true; - return; - } - file_prueba2 = file_prueba2.Replace("\\", "\\\\\\\\"); - file_prueba2 = file_prueba2.Replace(":", ":" + "\\\\"); - textbox_params = textbox_params.Replace("%1", file_prueba2); - } - - consola_pre.StartInfo.FileName = "ffmpeg.exe"; - consola_pre.StartInfo.Arguments = hw_decode_glob + " -i " + "" + '\u0022' + file_prueba + '\u0022' + "" + " -y " + textbox_params + " " + '\u0022' + destino_test + "\\" + Path.GetFileNameWithoutExtension(file_prueba) + ext_output + '\u0022'; - consola_pre.StartInfo.RedirectStandardOutput = true; - consola_pre.StartInfo.RedirectStandardError = true; - consola_pre.StartInfo.UseShellExecute = false; - consola_pre.StartInfo.CreateNoWindow = true; - consola_pre.EnableRaisingEvents = true; - consola_pre.Start(); - - while (!consola_pre.StandardError.EndOfStream) - { - this.InvokeEx(f => LB1_o.Items.Add(consola_pre.StandardError.ReadLine())); - this.InvokeEx(f => LB1_o.TopIndex = LB1_o.Items.Count - 1); - this.InvokeEx(f => LB1_o.Refresh()); - } - - consola_pre.WaitForExit(); - consola_pre.StartInfo.Arguments = String.Empty; - }); - - if (!tt.Wait(675) && consola_pre.StartInfo.Arguments != String.Empty) - { - consola_pre.Kill(); - tried_ok = true; - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - - if (Directory.Exists(destino_test) && Directory.GetFiles(destino_test).Length > 0) - { - foreach (String file in Directory.GetFiles(destino_test)) - { - try - { - File.Delete(file); - } - catch - { - } - } - } - - if (Directory.GetFiles(destino_test).Length == 0) - { - Directory.Delete(destino_test); - } - - LB1_o.Items.Clear(); - return; - } - - if (bad_chars == false) - { - if (consola_pre.ExitCode != 0) - { - if (Directory.Exists(destino_test) && Directory.GetFiles(destino_test).Length > 0) - { - foreach (String file in Directory.GetFiles(destino_test)) - { - try - { - File.Delete(file); - } - catch - { - } - } - } - - if (Directory.GetFiles(destino_test).Length == 0) - { - Directory.Delete(destino_test); - } - - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - foreach (String lin in LB1_o.Items) - { - if (lin.Contains("not load the requested plugin") || lin.Contains("Cannot load nvcuda.dll")) - { - unsupported = true; - } - } - if (unsupported == true) MessageBox.Show(Strings.test_fail1 + " " + "3:" + " " + Environment.NewLine + Environment.NewLine + Strings.unsup_enc + Environment.NewLine + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 1].ToString() + Environment.NewLine + Environment.NewLine + Strings.try_pr, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - else MessageBox.Show(Strings.test_fail1 + " " + "3:" + " " + Environment.NewLine + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 1].ToString() + Environment.NewLine + Environment.NewLine + Strings.try_pr, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - - tried_ok = false; - return; - } - else - { - System.Threading.Thread.Sleep(50); - if (Directory.Exists(destino_test) && Directory.GetFiles(destino_test).Length > 0) - { - foreach (String file in Directory.GetFiles(destino_test)) - { - try - { - File.Delete(file); - } - catch - { - } - } - } - - if (Directory.Exists(destino_test) && Directory.GetFiles(destino_test).Length == 0) - { - Directory.Delete(destino_test); - } - - tried_ok = true; - } - } - //END try preset - - if (Directory.Exists(destino_test)) - { - if (Directory.GetFiles(destino_test).Length == 0) - { - Directory.Delete(destino_test); - } - } - LB1_o.Items.Clear(); - consola_pre.Dispose(); - } - - private void bg_multi_3_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) - { - String file_prueba = ""; - String sel_test = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - file_prueba = sel_test; - String destino = Path.Combine(Path.GetTempPath(), "\\" + "FFBatch_test"); - String borrar = destino + "\\" + Path.GetFileNameWithoutExtension(file_prueba) + "." + txt_format.Text; - - if (File.Exists(borrar)) - { - try - { - File.Delete(borrar); - } - catch - { - } - } - - if (Directory.Exists(destino) == true) - { - if (Directory.GetFiles(destino).Length == 0) - { - Directory.Delete(destino); - } - } - if (tried_ok == true) start_multiple(); - else this.InvokeEx(f => this.Cursor = Cursors.Arrow); - } - - private void BG_Concat_one_DoWork(object sender, DoWorkEventArgs e) - { - Disable_Controls(); - this.InvokeEx(f => txt_remain.Text = Strings.remaint + " " + " 00:00:00"); - time_n_tasks = 0; - timer_tasks.Start(); - cancel_queue = false; - this.InvokeEx(f => Pg1.Value = 0); - //pg_current.Value = 0; - this.InvokeEx(f => Pg1.Text = "0%"); - notifyIcon1.Visible = true; - - working = true; - - String ffm = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - - Pg1.Value = 0; - String params1 = txt_parameters.Text; - - int i = 0; - ListView list_proc = new ListView(); - - Double total_duration = 0; - int i_dur = 0; - - //Get total duration of files - List durs = new List(); - String duracion_intro = String.Empty; - String duracion_salida = String.Empty; - - listView1.Invoke(new MethodInvoker(delegate - { - foreach (ListViewItem item in listView1.Items) - { - list_proc.Items.Add(item.Text); - list_proc.Items[item.Index].SubItems.Add(item.SubItems[1].Text); - } - listView1.SelectedIndices.Clear(); - })); - - listView1.Invoke(new MethodInvoker(delegate - { - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[3].Text != Strings.n_a && item.SubItems[3].Text != "0:00:00" && item.SubItems[3].Text != "00:00:00" && item.SubItems[3].Text != Strings.pending) - { - total_duration = total_duration + TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds; - durs.Add(TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds); - if (concat_intro != String.Empty) - { - total_duration = total_duration + TimeSpan.Parse(concat_intro_dur).TotalSeconds; - } - - if (concat_end != String.Empty) - { - total_duration = total_duration + TimeSpan.Parse(concat_end_dur).TotalSeconds; - } - } - } - })); - - Double total_prog = 0; - - //End get total duration of files - - Pg1.Maximum = 100; - aborted = false; - - //End total duration - - List list_lines = new List(); - procs.Clear(); - procs.Add("proc_urls_0", new Process()); - - - new System.Threading.Thread(() => - { - System.Threading.Thread.CurrentThread.IsBackground = true; - - String remain_time = ""; - String path = String.Empty; - String inputs = String.Empty; - int list_index = 0; - int percent_elapsed = 0; - Double item_duration = 0; - int errors = 0; - - foreach (ListViewItem file in list_proc.Items) - { - String file1 = file.SubItems[1].Text + "\\" + file.Text; - inputs = ""; - String destino = ""; - String fullPath = file1; - if (txt_path_main.Text.Contains(".\\")) - { - if (txt_path_main.Text != ".\\") - destino = file1.Substring(0, fullPath.LastIndexOf('\\')) + txt_path_main.Text.Replace(".", String.Empty); - else - { - destino = Path.GetDirectoryName(file1); - } - } - else - { - if (chk_recreate.CheckState == CheckState.Checked) - { - String pre_dest = Path.GetDirectoryName(file1); - destino = Path.Combine(txt_path_main.Text, pre_dest.Substring(3, pre_dest.Length - 3)); - } - else - { - destino = txt_path_main.Text; - } - } - - String concat_name = Path.GetFileNameWithoutExtension(file1); - - //Aborted requested - if (cancel_queue == true) - { - working = false; - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - this.InvokeEx(f => f.Pg1.Value = 0); - //this.InvokeEx(f => f.pg_current.Value = 0); - Enable_Controls(); - MessageBox.Show(Strings.queue_abort, Strings.task_abort, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; - } - int concat_number = 1; - var lista_concat = new String[3]; - String path_conc = Path.Combine(Path.GetTempPath(), "concat.txt"); - - if (check_concat.Checked == true) - { - if (concat_intro.Length > 0) - { - inputs = inputs + " -i " + '\u0022' + concat_intro + '\u0022'; - concat_number = concat_number + 1; - } - - inputs = inputs + " -i " + '\u0022' + file1 + '\u0022'; - - if (concat_end.Length > 0) - { - inputs = inputs + " -i " + '\u0022' + concat_end + '\u0022'; - concat_number = concat_number + 1; - } - } - if (check_concat.Checked == false) - { - if (concat_intro.Length > 0) - { - if (concat_intro.Contains(" ")) - { - lista_concat[0] = "file " + "'" + concat_intro + "'"; - } - else - { - lista_concat[0] = "file " + "'" + concat_intro.Replace("\\", "\\\\") + "'"; - } - } - else lista_concat[0] = String.Empty; - - if (file1.Contains(" ")) - { - lista_concat[1] = "file " + "'" + file1 + "'"; - } - else - { - lista_concat[1] = "file " + "'" + file1.Replace("\\", "\\\\") + "'"; - } - - if (concat_end.Length > 0) - { - if (concat_end.Contains(" ")) - { - lista_concat[2] = "file " + "'" + concat_end + "'"; - } - else - { - lista_concat[2] = "file " + "'" + concat_end.Replace("\\", "\\\\") + "'"; - } - } - else lista_concat[2] = String.Empty; - - try - { - File.WriteAllLines(path_conc, lista_concat); - } - catch (Exception exc) - { - MessageBox.Show(Strings.err_concat + Environment.NewLine + Environment.NewLine + exc.Message + Environment.NewLine + Environment.NewLine + path); - working = false; - Enable_Controls(); - return; - } - } - //Change Volume - String change_vol = ""; - if (chk_vol.Checked == true) - { - change_vol = "-filter:a " + '\u0022' + "volume=" + vol_ch.Value.ToString() + "dB " + '\u0022' + " "; - } - //End change volume - if (!Directory.Exists(destino)) - { - try - { - Directory.CreateDirectory(destino); - } - catch - { - MessageBox.Show(Strings.dest_err, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - Enable_Controls(); - working = false; - return; - } - } - String AppParam = String.Empty; - - if (check_concat.Checked == true) AppParam = inputs + " -filter_complex " + '\u0022' + "concat=n=" + concat_number.ToString() + ":v=1:a=1[outv][outa]" + '\u0022' + " -map " + '\u0022' + "[outv]" + '\u0022' + " -map " + '\u0022' + "[outa]" + '\u0022' + " " + params1 + " -y " + '\u0022' + destino + "\\" + concat_name + "_joined" + "." + txt_format.Text + '\u0022'; - if (check_concat.Checked == false) AppParam = " -f concat -safe 0 -i " + '\u0022' + path_conc + '\u0022' + " " + txt_parameters.Text + " " + " -y " + change_vol + '\u0022' + destino + "\\" + concat_name + "_joined" + "." + txt_format.Text + '\u0022'; - - //Thread thread = new Thread(() => Clipboard.SetText(ffm + " " + AppParam)); - //thread.SetApartmentState(ApartmentState.STA); //Set the thread to STA - //thread.Start(); - //thread.Join(); //Wait for the thread to end - valid_prog = false; - - var tmp = procs["proc_urls_0"]; - tmp.StartInfo.FileName = ffm; - tmp.StartInfo.Arguments = AppParam; - tmp.StartInfo.RedirectStandardError = true; - tmp.StartInfo.StandardErrorEncoding = Encoding.UTF8; - tmp.StartInfo.RedirectStandardInput = true; - tmp.StartInfo.UseShellExecute = false; - tmp.StartInfo.CreateNoWindow = true; - tmp.EnableRaisingEvents = true; - tmp.Start(); - - System.Threading.Thread.Sleep(50); - combo_prio.Invoke(new MethodInvoker(delegate - { - if (combo_prio.SelectedIndex != 2) - { - Change_mem_prio(); - } - })); - - String err_txt = ""; - Double sec_prog = 0; - Double interval = 0; - Decimal est_bitrate = 0; - Decimal est_size = 0; - lbl_bitrate.Text = ""; - lbl_est_size.Text = ""; - - try - { - while (!tmp.StandardError.EndOfStream) - { - err_txt = tmp.StandardError.ReadLine(); - list_lines.Add(err_txt); - - if (err_txt.Contains("time=") && err_txt.Contains("time=-") == false) - { - this.InvokeEx(f => durat_n = TimeSpan.Parse(listView1.Items[list_index].SubItems[3].Text).TotalSeconds + TimeSpan.Parse(concat_intro_dur).TotalSeconds + TimeSpan.Parse(concat_end_dur).TotalSeconds); - int start_time_index = err_txt.IndexOf("time=") + 5; - sec_prog = TimeSpan.Parse(err_txt.Substring(start_time_index, 8)).TotalSeconds; - - Double percent = (sec_prog * 100 / durat_n); - - total_prog = total_prog + (sec_prog - interval); - interval = sec_prog; - int percent2 = Convert.ToInt32(percent); - - Double percent_tot = (total_prog * 100 / total_duration); - int percent_tot_2 = Convert.ToInt32(percent_tot); - - if (percent_tot_2 <= 100) - { - this.InvokeEx(f => f.Pg1.Value = percent_tot_2); - this.InvokeEx(f => f.Pg1.Refresh()); - - if (Math.Round(percent_tot, 1).ToString().Contains(".") || Math.Round(percent_tot, 1).ToString().Contains(",")) - { - this.InvokeEx(f => f.Pg1.Text = Math.Round(percent_tot, 1).ToString() + "%"); - } - else - { - this.InvokeEx(f => f.Pg1.Text = Math.Round(percent_tot, 1).ToString() + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0" + "%"); - } - - this.InvokeEx(f => TaskbarProgress.SetValue(this.Handle, percent_tot, Pg1.Maximum)); - } - - if (percent2 <= 100) - { - if (Math.Round(percent, 1).ToString().Contains(".") || Math.Round(percent, 1).ToString().Contains(",")) - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Math.Round(percent, 1).ToString() + "%"); - } - else - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Math.Round(percent, 1).ToString() + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0" + "%"); - } - } - //Estimated remaining time - try - { - remain_time = err_txt.Substring(err_txt.LastIndexOf("speed=") + 6, err_txt.Length - err_txt.LastIndexOf("speed=") - 6); - remain_time = remain_time.Replace("x", String.Empty); - - Double timing1 = 0; - - if (System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",") - { - timing1 = Math.Round(Double.Parse(remain_time.Replace(".", ",")), 2); - } - else - { - timing1 = Math.Round(Double.Parse(remain_time), 2); - } - Decimal timing = (decimal)timing1; - Decimal total_dur_dec = Convert.ToDecimal(total_duration); - Decimal total_prog_dec = Convert.ToDecimal(sec_prog); - Decimal remain_secs = 0; - if (timing > 0) - { - remain_secs = (decimal)(total_dur_dec - total_prog_dec) / timing; - } - - if (remain_secs > 60) - { - remain_secs = remain_secs + 60; - } - String remain_from_secs = ""; - - TimeSpan t = TimeSpan.FromSeconds(Convert.ToDouble(remain_secs)); - remain_from_secs = string.Format("{0:D2}h:{1:D2}", - t.Hours, - t.Minutes); - - if (remain_secs >= 3600) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remaint + " " + remain_from_secs + " " + Strings.minutes_abrev); - } - - if (remain_secs < 3600 && remain_secs >= 600) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remaint + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 1, 2) + " " + Strings.minutes); - } - if (remain_secs < 600 && remain_secs >= 120) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remaint + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 2, 1) + " " + Strings.minutes); - } - - if (remain_secs <= 59) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remaint + " " + Convert.ToInt16(remain_secs) + " second(s)"); - } - this.InvokeEx(f => f.txt_remain.Refresh()); - - //End remaining time - } - catch { } - //Estimated size and bitrate - - String read_size = String.Empty; - if (err_txt.Contains("size=") && (time_est_size % 3 == 0)) - { - int size_index = err_txt.IndexOf("size=") + 5; - read_size = err_txt.Substring(size_index, 8); - if (Convert.ToDecimal(sec_prog) != 0) - { - est_bitrate = (Math.Round(Convert.ToDecimal(read_size) * 8 / Convert.ToDecimal(sec_prog), 0)); - } - else - { - est_bitrate = 0; - } - - if (Convert.ToDecimal(read_size) > 1 && time_n_tasks > 1) - { - if (est_bitrate < 9999) - { - if (est_bitrate > 48) - { - this.InvokeEx(f => f.lbl_bitrate.Text = Strings.avg_bit + ": " + est_bitrate + " " + "Kb/s"); - } - else - { - this.InvokeEx(f => f.lbl_bitrate.Text = Strings.avg_bit + ": "); - } - } - else - { - this.InvokeEx(f => f.lbl_bitrate.Text = Strings.avg_bit + ": " + (Math.Round(est_bitrate / 1000, 0)) + " " + "Mb/s"); - } - //Estimated size - est_size = Convert.ToDecimal(durat_n) * est_bitrate / 8; - - if (est_size > 1000000) - { - this.InvokeEx(f => f.lbl_est_size.Text = Strings.est_size + " " + (Math.Round(est_size / 1000000, 1)).ToString() + " " + "GB"); - } - else - { - if (Math.Round(est_size / 1000, 0) > 0) - { - this.InvokeEx(f => f.lbl_est_size.Text = Strings.est_size + " " + (Math.Round(est_size / 1000, 0)).ToString() + " " + "MB"); - } - else - { - this.InvokeEx(f => f.lbl_est_size.Text = Strings.est_size + " "); - } - } - } - if (time_est_size % 3 == 0) this.InvokeEx(f => f.lbl_speed.Text = remain_time.Trim() + "x"); - this.InvokeEx(f => f.lbl_est_size.Refresh()); - } - } - } - } - catch { } - //While encoding - - tmp.WaitForExit(); - tmp.StartInfo.Arguments = String.Empty; - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - list_lines.Add(""); - - if (tmp.ExitCode == 0) - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.success); - } - else - { - errors = errors + 1; - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.error); - } - this.InvokeEx(f => f.lbl_bitrate.Text = ""); - this.InvokeEx(f => f.lbl_est_size.Text = ""); - this.InvokeEx(f => f.lbl_speed.Text = ""); - list_index++; - - if (list_index == list_proc.Items.Count) - { - working = false; - Enable_Controls(); - this.InvokeEx(f => f.Pg1.Value = Pg1.Maximum); - this.InvokeEx(f => f.Pg1.Text = "100" + "%"); - notifyIcon1.BalloonTipIcon = ToolTipIcon.Info; - - //Single output info - - if (listView1.Items.Count == 1 && errors == 0) - { - if (current_out.ToLower().Contains("nul")) return; - - String cur_out = destino + "\\" + concat_name + "_joined" + "." + txt_format.Text; - - System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentUICulture; - String sep_th = ci.NumberFormat.CurrencyGroupSeparator; - String unit = ""; - String dur = ""; - this.Invoke(new MethodInvoker(delegate - { - lbl_est_size.Text = String.Empty; - lbl_bitrate.Text = String.Empty; - Process probe = new Process(); - - List lines_ouput = new List(); - probe.StartInfo.FileName = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - String ffprobe_frames = " " + "--Output=General;%OverallBitRate/String%" + "\\n" + "%FileSize/String3%" + "\\n" + "%Duration/String3%"; - probe.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + cur_out + '\u0022'; - probe.StartInfo.RedirectStandardOutput = true; - probe.StartInfo.UseShellExecute = false; - probe.StartInfo.CreateNoWindow = true; - probe.EnableRaisingEvents = true; - probe.Start(); - - while (!probe.StandardOutput.EndOfStream) - { - lines_ouput.Add(probe.StandardOutput.ReadLine()); - } - probe.WaitForExit(); - - if (lines_ouput[0] != null && lines_ouput[0].Length > 0) - { - if (lines_ouput[0].ToLower().Contains(" kb/s")) unit = "Kb/s"; - if (lines_ouput[0].ToLower().Contains(" mb/s")) unit = "Mb/s"; - if (lines_ouput[0].ToLower().Contains(" gb/s")) unit = "Gb/s"; - lines_ouput[0] = lines_ouput[0].Replace(" kb/s", "").Replace(" Mb/s", "").Replace(" Gb/s", ""); - lines_ouput[0] = lines_ouput[0].Replace(" ", sep_th); - lbl_bitrate.Text = Strings.bitrate + ":" + " " + lines_ouput[0] + " " + unit; - } - if (lines_ouput[1] != null && lines_ouput[1].Length > 0) lbl_est_size.Text = Strings.f_size + ":" + " " + lines_ouput[1].Replace("MiB", "MB").Replace("GiB", "GB").Replace("KiB", "KB"); - if (lines_ouput[2] != null && lines_ouput[2].Length > 0) dur = lines_ouput[2]; - })); - - if (no_output_pop == false) - { - Form26 frm26 = new Form26(); - frm26.out_file = cur_out; - frm26.dur_file = dur; - if (Settings.Default.dark_mode == false) frm26.pic_img = pic_reading.Image; - else frm26.pic_img = pic_reading.InitialImage; - frm26.tot_bit = lbl_bitrate.Text; - frm26.out_size = lbl_est_size.Text; - this.Invoke(new MethodInvoker(delegate - { - frm26.ShowDialog(this); - if (frm26.no_pop == true) no_output_pop = true; - })); - } - } - //End output single info - - if (Form.ActiveForm == null) - { - if (errors == 0) - { - notifyIcon1.BalloonTipText = Strings.concat_compl; - notifyIcon1.BalloonTipTitle = Strings.conc_comp; - notifyIcon1.ShowBalloonTip(0); - } - else - { - notifyIcon1.BalloonTipText = Strings.concat_err; - notifyIcon1.BalloonTipTitle = Strings.conc_comp; - notifyIcon1.ShowBalloonTip(1); - } - } - else - { - if (errors > 0 && aborted == false) - { - MessageBox.Show(Strings.there_w + " " + errors.ToString() + " " + Strings.errors1 + " " + Strings.check_log, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - if (chk_open_compl.Checked && aborted == false && errors == 0) - { - try - { - if (Directory.GetFiles(destino).Length != 0) - { - Process open_processed = new Process(); - open_processed.StartInfo.FileName = "explorer.exe"; - open_processed.StartInfo.Arguments = '\u0022' + destino + '\u0022'; - open_processed.Start(); - } - else - { - if (Directory.Exists(destino)) - { - Directory.Delete(destino); - } - } - } - catch { } - } - - working = false; - Enable_Controls(); - try - { - if (Directory.GetFiles(destino).Length == 0) - { - if (Directory.Exists(destino)) - { - Directory.Delete(destino); - } - } - } - catch { } - - if (aborted == true) - { - MessageBox.Show(Strings.concat_abort, Strings.cancelled, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - - //Save log - string[] array_err = list_lines.ToArray(); - String path_l = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.log"; - if (is_portable == true) path_l = port_path + "ff_batch_portable.log"; - - if (no_save_logs == false) - { - StreamWriter SaveFile = new StreamWriter(path_l); - SaveFile.WriteLine("FFmpeg log session: " + System.DateTime.Now); - SaveFile.WriteLine("-------------------------------"); - foreach (String item in array_err) - { - SaveFile.WriteLine(item); - } - SaveFile.Close(); - - File.AppendAllText(path_l, "-----------------------"); - File.AppendAllText(path_l, Environment.NewLine + Strings.end_log + Environment.NewLine); - FileInfo fileInfo = new FileInfo(path_l); - - var bytes = fileInfo.Length; - - var kilobytes = (double)bytes / 1024; - var megabytes = kilobytes / 1024; - var gigabytes = megabytes / 1024; - - //Format size view - String size = ""; - String separator = "."; - - if (bytes > 1000000000) - { - if (gigabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String gigas = gigabytes.ToString(); - if (gigas.Length >= 5) - { - gigas = gigas.Substring(0, gigas.LastIndexOf(separator) + 3); - size = (gigas + " " + "GB"); - } - else - { - size = (gigas + " " + "GB"); - } - } - - if (bytes >= 1048576 && bytes <= 1000000000) - { - if (megabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - String megas = megabytes.ToString(); - if (megas.Length > 5) - { - megas = megas.Substring(0, megas.LastIndexOf(separator)); - size = (megas + " " + "MB"); - } - else - { - size = (megas + " " + "MB"); - } - } - - if (bytes >= 1024 && bytes < 1048576) - - { - if (kilobytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String kbs = kilobytes.ToString(); - if (kbs.Length >= 5) - { - kbs = kbs.Substring(0, kbs.LastIndexOf(separator)); - size = (kbs + " " + "KB"); - } - else - { - size = (kbs + " " + "KB"); - } - } - if (bytes > -1 && bytes < 1024) - { - String bits = bytes.ToString(); - size = (bits + " Bytes"); - } - - //End Format size view - File.AppendAllText(path_l, Environment.NewLine + Strings.log_size + " " + size); - - //End save log - } - - if (File.Exists(Path.Combine(Application.StartupPath, "concat.txt"))) - { - File.Delete(Path.Combine(Application.StartupPath, "concat.txt")); - } - - Enable_Controls(); - this.InvokeEx(f => f.btn_load_config.PerformClick()); - } - } - }).Start(); - } - - private void btn_concat_Click(object sender, EventArgs e) - { - Pg1.Focus(); - lbl_est_size.Text = ""; - lbl_bitrate.Text = ""; - - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - if (!File.Exists(Path.Combine(Application.StartupPath, "ffmpeg.exe"))) - { - MessageBox.Show(Strings.no_ffmpeg, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - was_started.Text = btn_concat.Text; - foreach (ListViewItem file in listView1.Items) - { - if (!File.Exists(file.SubItems[1].Text + "\\" + file.Text)) - { - MessageBox.Show(Strings.file_not_found + " " + file.Text, Strings.file_not_found2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - - if (listView1.Items.Count < 1) - { - MessageBox.Show(Strings.list_empty, Strings.add_files, MessageBoxButtons.OK, MessageBoxIcon.Information); - return; - } - - if (txt_parameters.Text == "" && check_concat.CheckState == CheckState.Unchecked) - { - MessageBox.Show(Strings.params_bl, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (txt_format.Text == "") - { - MessageBox.Show(Strings.format_bl, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (chk_shift.Checked == true) - { - MessageBox.Show(Strings.shift_n, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (chkshut.Checked) - { - TB1.Visible = true; - TB1.Text = Strings.autosh; - } - - foreach (ListViewItem item in listView1.Items) - { - if (item.Text.Contains("'") || item.SubItems[1].Text.Contains("'")) - { - MessageBox.Show(Strings.warn_colon + Environment.NewLine + Environment.NewLine + item.SubItems[1].Text + "\\" + item.Text + Environment.NewLine + Environment.NewLine + Strings.warn_colon2, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - - - //Pending duration - - if (dur_ok == false) - { - list_pending_dur.Items.Clear(); - foreach (ListViewItem item in listView1.Items) - { - list_pending_dur.Items.Add((ListViewItem)item.Clone()); - } - BG_Dur.RunWorkerAsync(); - return; - } - String img = ""; - try - { - img = listView1.Items[0].Text.Substring(listView1.Items[0].Text.LastIndexOf(".") + 1, 3); - } - catch - { - img = listView1.Items[0].Text.Substring(listView1.Items[0].Text.LastIndexOf(".") + 1, 2); - } - String img_aud = String.Empty; - if (img == "jpg" || img == "jpeg" || img == "png" || img == "gif") - { - if (images_from_wiz == false) - { - DialogResult a = MessageBox.Show(Strings.images_conc, Strings.images_c2, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); - if (a == DialogResult.Yes) images_v = true; - if (a == DialogResult.No) return; - if (a == DialogResult.Cancel) return; - } - } - - errors_enc = 0; - - if (images_v == true && images_from_wiz == false) - { - Form18 frm18 = new Form18(); - frm18.StartPosition = FormStartPosition.CenterParent; - frm18.ShowDialog(); - if (frm18.canceled == false) - { - images_time = frm18.numericUpDown1.Value.ToString(); - if (frm18.txt_audio_path.Enabled == true) img_aud = frm18.txt_audio_path.Text; - } - else images_v = false; - } - - if (images_from_wiz == false) - { - String dialog_param = txt_parameters.Text; - if (images_v == false) - { - frm22.tx_params = txt_parameters.Text; - if (listView1.Items.Count > 0) - { - frm22.txt_c_format.Text = Path.GetExtension(listView1.Items[0].Text).Replace(".", ""); - frm22.tx_params_ext = frm22.txt_c_format.Text; - frm22.tx_params_ext_or = txt_format.Text; - } - - if (concat_intro.Length > 0) - { - frm22.txt_intro.Text = concat_intro; - frm22.intro_dur = concat_intro_dur; - } - - if (concat_end.Length > 0) - { - frm22.txt_end.Text = concat_end; - frm22.end_dur = concat_end_dur; - } - if (batch_concat == true) frm22.chk_batch_concat.Checked = true; - else frm22.chk_batch_concat.Checked = false; - - frm22.ShowDialog(); - if (frm22.cancel == true) return; - dialog_param = frm22.txt_params.Text; - if (frm22.radio_demuxer.Checked) check_concat.Checked = false; - if (frm22.radio_filter.Checked) check_concat.Checked = true; - txt_parameters.Text = frm22.txt_params.Text; - txt_format.Text = frm22.txt_c_format.Text; - - if (frm22.chk_batch_concat.Checked == true) - { - batch_concat = true; - concat_intro = frm22.txt_intro.Text; - concat_intro_dur = frm22.intro_dur; - concat_end = frm22.txt_end.Text; - concat_end_dur = frm22.end_dur; - BG_Concat_one.RunWorkerAsync(); - return; - } - } - } - - if (images_from_wiz == true) images_v = true; - - batch_concat = false; - if (listView1.Items.Count < 2) - { - MessageBox.Show(Strings.two_files, Strings.add_files, MessageBoxButtons.OK, MessageBoxIcon.Information); - return; - } - - //Check path is writable - String destino1 = String.Empty; - Boolean rel_path = false; - String element = listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text; - if (txt_path_main.Text.Contains(".\\")) - { - destino1 = element.Substring(0, element.LastIndexOf('\\')) + txt_path_main.Text.Replace(".", String.Empty); - rel_path = true; - } - else - { - if (chk_recreate.CheckState == CheckState.Checked) - { - String pre_dest = Path.GetDirectoryName(element); - destino1 = Path.Combine(txt_path_main.Text, pre_dest.Substring(3, pre_dest.Length - 3)); - rel_path = true; - } - else - { - destino1 = txt_path_main.Text; - } - } - - try - { - if (rel_path == true) - { - Directory.CreateDirectory(destino1); - System.Threading.Thread.Sleep(10); - } - else - { - if (!Directory.Exists(destino1)) Directory.CreateDirectory(destino1); - File.WriteAllText(destino1 + "\\" + "FFBatch_test.txt", "FFBatch_test"); - System.Threading.Thread.Sleep(10); - File.Delete(destino1 + "\\" + "FFBatch_test.txt"); - } - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.write_error1 + " " + excpt.Message, Strings.write_error2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - //End path is writable - - Disable_Controls(); - txt_remain.Text = Strings.remain_time + " " + "00h:00m:00s"; - time_n_tasks = 0; - timer_tasks.Start(); - cancel_queue = false; - Pg1.Value = 0; - //pg_current.Value = 0; - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - notifyIcon1.Visible = true; - - working = true; - - String ffm = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - - Pg1.Value = 0; - - String primero_lista = element; - - String destino = ""; - if (txt_path_main.Text.Contains(".\\")) - { - destino = primero_lista.Substring(0, primero_lista.LastIndexOf('\\')) + txt_path_main.Text.Replace(".", String.Empty); ; - } - else - { - destino = txt_path_main.Text; - } - - if (!Directory.Exists(destino)) - { - try - { - Directory.CreateDirectory(destino); - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.error2 + " " + excpt.Message, Strings.write_error2, MessageBoxButtons.OK, MessageBoxIcon.Error); - this.Cursor = Cursors.Arrow; - Enable_Controls(); - working = false; - return; - } - } - - var lista_concat = new String[listView1.Items.Count]; - int i = 0; - - ListView list_proc = new ListView(); - - foreach (ListViewItem item in listView1.Items) - { - list_proc.Items.Add((ListViewItem)item.Clone()); - item.SubItems[5].Text = Strings.queued; - } - - listView1.SelectedIndices.Clear(); - Double total_duration = 0; - int i_dur = 0; - - //Get total duration of files - foreach (ListViewItem item in listView1.Items) - { - if (listView1.Items[i_dur].SubItems[3].Text != Strings.n_a && listView1.Items[i_dur].SubItems[3].Text != "0:00:00" && listView1.Items[i_dur].SubItems[3].Text != "00:00:00" && listView1.Items[i_dur].SubItems[3].Text != Strings.pending) - { - total_duration = total_duration + TimeSpan.Parse(listView1.Items[i_dur].SubItems[3].Text).TotalSeconds; - } - else - { - total_duration = total_duration + 0; - } - - i_dur = i_dur + 1; - } - //End get total duration of files - - Pg1.Maximum = 100; - foreach (ListViewItem item in listView1.Items) - { - item.SubItems[5].Text = Strings.processing; - } - - //End total duration - - List list_lines = new List(); - procs.Clear(); - procs.Add("proc_urls_0", new Process()); - - String concat_name = Path.GetFileNameWithoutExtension(element); - - new System.Threading.Thread(() => - { - System.Threading.Thread.CurrentThread.IsBackground = true; - - String remain_time = ""; - - String path = Path.Combine(Path.GetTempPath(), "concat.txt"); - String inputs = String.Empty; - - if (images_v == false) - { - foreach (ListViewItem item in list_proc.Items) - { - String file = item.SubItems[1].Text + "\\" + item.Text; - inputs = inputs + " -i " + '\u0022' + file + '\u0022'; - //Aborted requested - if (cancel_queue == true) - { - working = false; - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - this.InvokeEx(f => f.Pg1.Value = 0); - //this.InvokeEx(f => f.pg_current.Value = 0); - Enable_Controls(); - MessageBox.Show(Strings.queue_abort, Strings.task_abort, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; - } - - if (file.Contains(" ")) - { - lista_concat[i] = "file " + "'" + file + "'"; - i = i + 1; - } - else - { - lista_concat[i] = "file " + "'" + file.Replace("\\", "\\\\") + "'"; - i = i + 1; - } - } - } - if (images_v == true) - { - for (int i1 = 0; i1 < list_proc.Items.Count; i1++) - { - String file = list_proc.Items[i1].SubItems[1].Text + "\\" + list_proc.Items[i1].Text; - //Aborted requested - if (cancel_queue == true) - { - working = false; - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - this.InvokeEx(f => f.Pg1.Value = 0); - //this.InvokeEx(f => f.pg_current.Value = 0); - Enable_Controls(); - MessageBox.Show(Strings.queue_abort, Strings.task_abort, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; - } - if (file.Contains(" ")) - { - lista_concat[i1] = "file " + "'" + file + "'" + Environment.NewLine + "duration " + images_time; - if (i1 == list_proc.Items.Count - 1) lista_concat[i1] = lista_concat[i1] + Environment.NewLine + "file " + "'" + file + "'" + Environment.NewLine + "duration 1"; - } - else - { - lista_concat[i1] = "file " + "'" + file.Replace("\\", "\\\\") + "'" + Environment.NewLine + "duration " + images_time; - if (i1 == list_proc.Items.Count - 1) lista_concat[i1] = lista_concat[i1] + Environment.NewLine + "file " + "'" + file.Replace("\\", "\\\\") + "'" + Environment.NewLine + "duration 1"; ; - } - } - } - - try - { - File.WriteAllLines(path, lista_concat); - } - catch (Exception exc) - { - MessageBox.Show(Strings.err_concat + Environment.NewLine + Environment.NewLine + exc.Message + Environment.NewLine + Environment.NewLine + path); - working = false; - Enable_Controls(); - return; - } - - //Change Volume - String change_vol = ""; - if (chk_vol.Checked == true) - { - change_vol = "-filter:a " + '\u0022' + "volume=" + vol_ch.Value.ToString() + "dB " + '\u0022' + " "; - } - //End change volume - - //Duration variable - - String dur_secs0 = total_duration.ToString(); - String to_replace0 = String.Empty; - textbox_params = txt_parameters.Text; - String pre_i = txt_pre_input.Text; - - while (textbox_params.Contains("%fdur")) - { - - if (textbox_params.Contains("%fdur")) - { - to_replace0 = ""; - - int operador = textbox_params.LastIndexOf("%fdur") + 5; - int length = 0; - int limit = textbox_params.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(textbox_params.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace0 = textbox_params.Substring(textbox_params.LastIndexOf("%fdur"), 5 + length); - Double result = Convert.ToDouble(new DataTable().Compute(to_replace0.Replace("%fdur", dur_secs0), null)); - textbox_params = ReplaceLastOccurrence(textbox_params, to_replace0, Math.Round(result).ToString()); - } - } - - while (pre_i.Contains("%fdur")) - { - - if (pre_i.Contains("%fdur")) - { - to_replace0 = ""; - - int operador = pre_i.LastIndexOf("%fdur") + 5; - int length = 0; - int limit = pre_i.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(pre_i.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace0 = pre_i.Substring(pre_i.LastIndexOf("%fdur"), 5 + length); - Double result = Convert.ToDouble(new DataTable().Compute(to_replace0.Replace("%fdur", dur_secs0), null)); - pre_i = ReplaceLastOccurrence(pre_i, to_replace0, Math.Round(result).ToString()); - } - } - - //End duration variable - - String AppParam = String.Empty; - if (check_concat.CheckState == CheckState.Unchecked) - { - if (img_aud == String.Empty && images_from_wiz == false) AppParam = pre_i + " -f concat -safe 0 -i " + '\u0022' + path + '\u0022' + " " + textbox_params + " " + " -y " + change_vol + '\u0022' + destino + "\\" + concat_name + "_joined" + "." + txt_format.Text + '\u0022'; - else AppParam = pre_i + " -f concat -safe 0 -i " + '\u0022' + path + '\u0022' + " " + "-i " + '\u0022' + img_aud + '\u0022' + " " + textbox_params + " " + " -y " + change_vol + '\u0022' + destino + "\\" + concat_name + "_joined" + "." + txt_format.Text + '\u0022'; - } - else - { - AppParam = pre_i + inputs + " -filter_complex " + '\u0022' + "concat=n=" + list_proc.Items.Count + ":v=1:a=1" + '\u0022' + " " + textbox_params + " " + " -y " + change_vol + '\u0022' + destino + "\\" + concat_name + "_joined" + "." + txt_format.Text + '\u0022'; - } - if (images_from_wiz == true) - { - String img_aud_w = String.Empty; - if (img_aud_from_wiz.Length > 2) img_aud_w = "-i " + img_aud_from_wiz; - AppParam = pre_i + " -f concat -safe 0 -i " + '\u0022' + path + '\u0022' + " " + img_aud_w + " " + textbox_params + " " + " -y " + change_vol + '\u0022' + destino + "\\" + concat_name + "_joined" + "." + txt_format.Text + '\u0022'; - } - - if (images_from_wiz == true) - { - total_duration = Convert.ToDouble(img_dur_wiz); - images_v = false; - } - images_from_wiz = false; - - valid_prog = false; - - var tmp = procs["proc_urls_0"]; - - tmp.StartInfo.FileName = ffm; - tmp.StartInfo.Arguments = AppParam; - tmp.StartInfo.RedirectStandardError = true; - tmp.StartInfo.RedirectStandardInput = true; - tmp.StartInfo.UseShellExecute = false; - tmp.StartInfo.CreateNoWindow = true; - tmp.EnableRaisingEvents = true; - tmp.Start(); - - System.Threading.Thread.Sleep(50); - combo_prio.Invoke(new MethodInvoker(delegate - { - if (combo_prio.SelectedIndex != 2) - { - Change_mem_prio(); - } - })); - - String err_txt = ""; - - while (!tmp.StandardError.EndOfStream) - { - err_txt = tmp.StandardError.ReadLine(); - list_lines.Add(err_txt); - int percent2 = 0; - if (err_txt.Contains("time=") && err_txt.Contains("time=-") == false && images_v == false) - { - int start_time_index = err_txt.IndexOf("time=") + 5; - DateTime time2; - Double sec_prog = 0; - if (DateTime.TryParse(err_txt.Substring(start_time_index, 8), out time2)) - { - sec_prog = TimeSpan.Parse(err_txt.Substring(start_time_index, 8)).TotalSeconds; - } - - Double percent = (sec_prog * 100 / total_duration); - try - { - percent2 = Convert.ToInt32(percent); - } - catch - { - percent2 = 0; - } - - if (percent2 <= 100) - { - this.Invoke(new MethodInvoker(delegate - { - Pg1.Text = (percent2).ToString() + "%"; - Pg1.Value = percent2; - Pg1.Refresh(); - TaskbarProgress.SetValue(this.Handle, percent2, Pg1.Maximum); - })); - } - //Estimated remaining time - - remain_time = err_txt.Substring(err_txt.LastIndexOf("speed=") + 6, err_txt.Length - err_txt.LastIndexOf("speed=") - 6); - remain_time = remain_time.Replace("x", String.Empty); - Double timing1 = 0; - - if (remain_time.Contains("N/A") == false) - { - if (System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",") - { - timing1 = Math.Round(Double.Parse(remain_time.Replace(".", ",")), 2); - } - else - { - timing1 = Math.Round(Double.Parse(remain_time), 2); - } - } - Decimal timing = (decimal)timing1; - Decimal total_dur_dec = Convert.ToDecimal(total_duration); - Decimal total_prog_dec = Convert.ToDecimal(sec_prog); - Decimal remain_secs = 0; - if (timing > 0) - { - remain_secs = (decimal)(total_dur_dec - total_prog_dec) / timing; - } - - if (remain_secs > 60) - { - remain_secs = remain_secs + 60; - } - String remain_from_secs = ""; - - TimeSpan t = TimeSpan.FromSeconds(Convert.ToDouble(remain_secs)); - remain_from_secs = string.Format("{0:D2}h:{1:D2}", - t.Hours, - t.Minutes); - - if (remain_secs >= 3600) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + remain_from_secs + " " + Strings.minutes_abrev); - } - - if (remain_secs < 3600 && remain_secs >= 600) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 1, 2) + " " + Strings.minutes); - } - if (remain_secs < 600 && remain_secs >= 120) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 2, 1) + " " + Strings.minutes); - } - - if (remain_secs <= 59) - { - this.InvokeEx(f => f.txt_remain.Text = Strings.remain_time + " " + Convert.ToInt16(remain_secs) + " " + Strings.seconds); - } - - //End remaining time - } - - //Read output, get progress - } - tmp.WaitForExit(); - tmp.StartInfo.Arguments = String.Empty; - this.Invoke(new MethodInvoker(delegate - { - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - Pg1.Value = Pg1.Maximum; - Pg1.Text = Pg1.Value.ToString() + "%"; - })); - - list_lines.Add(""); - int proc_glob = tmp.ExitCode; - list_lines.Add(Strings.exit_code + ": " + proc_glob.ToString()); - if (tmp.ExitCode == 0) - { - errors_enc++; - foreach (ListViewItem item in list_proc.Items) - { - this.InvokeEx(f => f.listView1.Items[item.Index].SubItems[5].Text = Strings.success); - } - working = false; - Enable_Controls(); - - if (play_on_end == true) play_end(); - - if (proc_glob == 0) - { - if (current_out.ToLower().Contains("nul")) return; - - String cur_out = destino + "\\" + concat_name + "_joined" + "." + txt_format.Text; - - System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentUICulture; - String sep_th = ci.NumberFormat.CurrencyGroupSeparator; - String unit = ""; - String dur = ""; - this.Invoke(new MethodInvoker(delegate - { - lbl_est_size.Text = String.Empty; - lbl_bitrate.Text = String.Empty; - Process probe = new Process(); - - List lines_ouput = new List(); - probe.StartInfo.FileName = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - String ffprobe_frames = " " + "--Output=General;%OverallBitRate/String%" + "\\n" + "%FileSize/String3%" + "\\n" + "%Duration/String3%"; - probe.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + cur_out + '\u0022'; - probe.StartInfo.RedirectStandardOutput = true; - probe.StartInfo.UseShellExecute = false; - probe.StartInfo.CreateNoWindow = true; - probe.EnableRaisingEvents = true; - probe.Start(); - - while (!probe.StandardOutput.EndOfStream) - { - lines_ouput.Add(probe.StandardOutput.ReadLine()); - } - probe.WaitForExit(); - - if (lines_ouput[0] != null && lines_ouput[0].Length > 0) - { - if (lines_ouput[0].ToLower().Contains(" kb/s")) unit = "Kb/s"; - if (lines_ouput[0].ToLower().Contains(" mb/s")) unit = "Mb/s"; - if (lines_ouput[0].ToLower().Contains(" gb/s")) unit = "Gb/s"; - lines_ouput[0] = lines_ouput[0].Replace(" kb/s", "").Replace(" Mb/s", "").Replace(" Gb/s", ""); - lines_ouput[0] = lines_ouput[0].Replace(" ", sep_th); - lbl_bitrate.Text = Strings.bitrate + ":" + " " + lines_ouput[0] + " " + unit; - } - if (lines_ouput[1] != null && lines_ouput[1].Length > 0) lbl_est_size.Text = Strings.f_size + ":" + " " + lines_ouput[1].Replace("MiB", "MB").Replace("GiB", "GB").Replace("KiB", "KB"); - if (lines_ouput[2] != null && lines_ouput[2].Length > 0) dur = lines_ouput[2]; - })); - - if (no_output_pop == false) - { - Form26 frm26 = new Form26(); - frm26.out_file = cur_out; - frm26.dur_file = dur; - if (Settings.Default.dark_mode == false) frm26.pic_img = pic_reading.Image; - else frm26.pic_img = pic_reading.InitialImage; - frm26.tot_bit = lbl_bitrate.Text; - frm26.out_size = lbl_est_size.Text; - this.Invoke(new MethodInvoker(delegate - { - frm26.ShowDialog(this); - if (frm26.no_pop == true) no_output_pop = true; - })); - } - } - //End output single info - - if (Form.ActiveForm == null && errors_enc == 0) - { - notifyIcon1.BalloonTipText = Strings.concat_compl; - notifyIcon1.BalloonTipIcon = ToolTipIcon.Info; - notifyIcon1.BalloonTipTitle = Strings.conc_comp; - notifyIcon1.ShowBalloonTip(0); - } - - if (chk_open_compl.Checked && errors_enc == 0) - { - if (Directory.GetFiles(destino).Length != 0) - { - Process open_processed = new Process(); - open_processed.StartInfo.FileName = "explorer.exe"; - open_processed.StartInfo.Arguments = '\u0022' + destino + '\u0022'; - open_processed.Start(); - } - else - { - if (Directory.Exists(destino)) - { - Directory.Delete(destino); - } - } - } - } - else - { - working = false; - Enable_Controls(); - if (Directory.GetFiles(destino).Length == 0) - { - if (Directory.Exists(destino)) - { - Directory.Delete(destino); - } - } - if (cancel_queue == true) - { - foreach (ListViewItem item in list_proc.Items) - { - this.InvokeEx(f => f.listView1.Items[item.Index].SubItems[5].Text = Strings.aborted); - } - MessageBox.Show(Strings.concat_abort, Strings.aborted, MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - else - { - foreach (ListViewItem item in list_proc.Items) - { - this.InvokeEx(f => f.listView1.Items[item.Index].SubItems[5].Text = Strings.error); - } - - MessageBox.Show(Strings.concat_failed + Environment.NewLine + Environment.NewLine + '\u0022' + list_lines[list_lines.Count - 2] + '\u0022', "Concatenation failed", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - //Save log - string[] array_err = list_lines.ToArray(); - String path_l = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.log"; - if (is_portable == true) path_l = port_path + "ff_batch_portable.log"; - - if (no_save_logs == false) - { - StreamWriter SaveFile = new StreamWriter(path_l); - SaveFile.WriteLine("FFmpeg log session: " + System.DateTime.Now); - SaveFile.WriteLine("-------------------------------"); - foreach (String item in array_err) - { - SaveFile.WriteLine(item); - } - SaveFile.Close(); - - File.AppendAllText(path_l, "-----------------------"); - File.AppendAllText(path_l, Environment.NewLine + Strings.end_log + Environment.NewLine); - FileInfo fileInfo = new FileInfo(path_l); - - var bytes = fileInfo.Length; - - var kilobytes = (double)bytes / 1024; - var megabytes = kilobytes / 1024; - var gigabytes = megabytes / 1024; - - //Format size view - String size = ""; - String separator = "."; - - if (bytes > 1000000000) - { - if (gigabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String gigas = gigabytes.ToString(); - if (gigas.Length >= 5) - { - gigas = gigas.Substring(0, gigas.LastIndexOf(separator) + 3); - size = (gigas + " " + "GB"); - } - else - { - size = (gigas + " " + "GB"); - } - } - - if (bytes >= 1048576 && bytes <= 1000000000) - { - if (megabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - String megas = megabytes.ToString(); - if (megas.Length > 5) - { - megas = megas.Substring(0, megas.LastIndexOf(separator)); - size = (megas + " " + "MB"); - } - else - { - size = (megas + " " + "MB"); - } - } - - if (bytes >= 1024 && bytes < 1048576) - - { - if (kilobytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String kbs = kilobytes.ToString(); - if (kbs.Length >= 5) - { - kbs = kbs.Substring(0, kbs.LastIndexOf(separator)); - size = (kbs + " " + "KB"); - } - else - { - size = (kbs + " " + "KB"); - } - } - if (bytes > -1 && bytes < 1024) - { - String bits = bytes.ToString(); - size = (bits + " Bytes"); - } - - //End Format size view - File.AppendAllText(path_l, Environment.NewLine + Strings.log_size + " " + size); - - //End save log - } - - if (File.Exists(Path.Combine(Path.GetTempPath(), "concat.txt"))) - { - try - { - File.Delete(Path.Combine(Path.GetTempPath(), "concat.txt")); - } - catch { } - } - if (chkshut.Checked) - { - auto_shut(); - return; - } - Enable_Controls(); - this.InvokeEx(f => f.btn_load_config.PerformClick()); - - }).Start(); - } - private void play_end() - { - try - { - Task t = Task.Run(() => - { - soundPlayer.SoundLocation = play_file_path; - soundPlayer.Play(); - Thread.Sleep(8000); - soundPlayer.Stop(); - }); - } - catch { } - } - - private void Timer_idle_Tick(object sender, EventArgs e) - { - NativeMethods.SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_SYSTEM_REQUIRED); - } - - private void button7_Click_2(object sender, EventArgs e) - { - Pg1.Focus(); - Form frm_custom_path = new Form(); - frm_custom_path.Icon = this.Icon; - frm_custom_path.Height = 175; - frm_custom_path.Width = 518; - frm_custom_path.BackColor = Color.White; - frm_custom_path.FormBorderStyle = FormBorderStyle.Fixed3D; - frm_custom_path.MaximizeBox = false; - frm_custom_path.MinimizeBox = false; - frm_custom_path.Text = Strings.custom_rel; - - Panel frm_panel = new Panel(); - frm_panel.Top = 80; - frm_panel.Height = 55; - frm_panel.Left = 0; - frm_panel.BackColor = Control.DefaultBackColor; - frm_panel.Width = 518; - frm_panel.Parent = frm_custom_path; - - Label bord = new Label(); - bord.Top = 0; - bord.Height = 1; - bord.Left = 0; - bord.Width = 390; - bord.BorderStyle = BorderStyle.None; - bord.BackColor = Color.WhiteSmoke; - bord.Parent = frm_custom_path; - bord.Text = ""; - - Label texto = new Label(); - texto.Top = 20; - texto.Height = 20; - texto.Left = 77; - texto.Width = 195; - texto.Parent = frm_custom_path; - texto.Text = Strings.write_path; - - PictureBox pic = new PictureBox(); - pic.Top = 15; - pic.Left = 10; - pic.Height = 26; - pic.Width = 26; - pic.Parent = frm_custom_path; - Form19 frm19 = new Form19(); - pic.Image = frm19.pictureBox1.Image; - - Label texto2 = new Label(); - texto2.Top = 47; - texto2.Left = 7; - texto2.Width = 48; - texto2.Parent = frm_custom_path; - texto2.Text = Strings.path2; - - TextBox txt_ref = new TextBox(); - txt_ref.Left = 58; - txt_ref.Top = 44; - txt_ref.Width = 16; - txt_ref.Text = ".\\"; - txt_ref.Enabled = false; - txt_ref.Parent = frm_custom_path; - - path_txt.Parent = frm_custom_path; - path_txt.Top = 44; - path_txt.Left = 79; - path_txt.Width = 400; - path_txt.Focus(); - path_txt.TabIndex = 0; - path_txt.KeyDown += new KeyEventHandler(path_txt_KeyDown); - - Button boton_user_source_path = new Button(); - boton_user_source_path.Parent = frm_panel; - boton_user_source_path.Left = 78; - boton_user_source_path.Top = 15; - boton_user_source_path.BackColor = Control.DefaultBackColor; - boton_user_source_path.Width = 227; - boton_user_source_path.Height = 25; - boton_user_source_path.Text = Strings.use_source; - boton_user_source_path.TabIndex = 0; - boton_user_source_path.Click += new EventHandler(boton_user_source_path_Click); - - Button boton_ok_path = new Button(); - boton_ok_path.Parent = frm_panel; - boton_ok_path.Left = 417; - boton_ok_path.Top = 15; - boton_ok_path.BackColor = Control.DefaultBackColor; - boton_ok_path.Width = 70; - boton_ok_path.Height = 25; - boton_ok_path.Text = Strings.cancel; - boton_ok_path.TabIndex = 0; - boton_ok_path.Click += new EventHandler(boton_cancel_path_Click); - - Button boton_cancel_path = new Button(); - boton_cancel_path.Parent = frm_panel; - boton_cancel_path.Left = 343; - boton_cancel_path.BackColor = Control.DefaultBackColor; - boton_cancel_path.Top = 15; - boton_cancel_path.Width = 70; - boton_cancel_path.Height = 25; - boton_cancel_path.Text = Strings.ok; - - boton_cancel_path.Click += new EventHandler(boton_ok_path_Click); - - frm_custom_path.StartPosition = FormStartPosition.CenterParent; - frm_custom_path.ShowDialog(); - } - - private void boton_user_source_path_Click(object sender, EventArgs e) - { - if (txt_path_main.Text == ".\\" && btn_save_path.Enabled == false) btn_save_path.Enabled = true; - if (txt_path_main.Text != ".\\") btn_save_path.Enabled = true; - txt_path_main.Text = ".\\"; - txt_path_mux.Text = txt_path_main.Text; - txt_path_main.BackColor = groupBox1.BackColor; - //btn_reset_path.BackColor = groupBox1.BackColor; - - ActiveForm.Close(); - } - - private void item_up_Click(object sender, EventArgs e) - { - Pg1.Focus(); - if (tabControl1.SelectedIndex == 0) - { - if (listView1.SelectedItems.Count == 1) - { - if (listView1.SelectedItems[0].SubItems[5].Text == Strings.queued) - { - lvwColumnSorter_Full.Order = SortOrder.None; - var currentIndex = listView1.SelectedItems[0].Index; - var item = listView1.Items[listView1.SelectedIndices[0]]; - if (currentIndex > 0 && listView1.Items[currentIndex - 1].SubItems[5].Text == Strings.queued) - { - listView1.Items.RemoveAt(currentIndex); - listView1.Items.Insert(currentIndex - 1, item); - listView1.EnsureVisible(item.Index); - } - } - else MessageBox.Show(Strings.only_qu); - } - - if (listView1.SelectedItems.Count > 1 && listView1.SelectedItems[0].SubItems[5].Text == Strings.queued) - { - for (int i = 0; i < listView1.SelectedItems.Count; i++) - { - lvwColumnSorter_Full.Order = SortOrder.None; - var currentIndex = listView1.SelectedItems[i].Index; - var item = listView1.Items[listView1.SelectedIndices[i]]; - if (currentIndex > 0 && listView1.Items[currentIndex - 1].SubItems[5].Text == Strings.queued) - { - listView1.Items.RemoveAt(currentIndex); - listView1.Items.Insert(currentIndex - 1, item); - } - } - } - } - - if (tabControl1.SelectedIndex == 3) - { - if (dg1.SelectedCells.Count == 0 || dg1.SelectedCells.Count > 1) return; - DataGridView dgv = dg1; - try - { - int totalRows = dgv.Rows.Count; - // get index of the row for the selected cell - int rowIndex = dgv.SelectedCells[0].OwningRow.Index; - if (rowIndex == 0) - return; - // get index of the column for the selected cell - int colIndex = dgv.SelectedCells[0].OwningColumn.Index; - DataGridViewRow selectedRow = dgv.Rows[rowIndex]; - dgv.Rows.Remove(selectedRow); - dgv.Rows.Insert(rowIndex - 1, selectedRow); - dgv.ClearSelection(); - dgv.Rows[rowIndex - 1].Cells[colIndex].Selected = true; - } - catch { } - } - } - - private void item_down_Click(object sender, EventArgs e) - { - Pg1.Focus(); - if (tabControl1.SelectedIndex == 0) - { - if (listView1.SelectedItems.Count == 1) - { - if (listView1.SelectedItems[0].SubItems[5].Text == Strings.queued) - { - lvwColumnSorter_Full.Order = SortOrder.None; - var currentIndex = listView1.SelectedItems[0].Index; - var item = listView1.Items[listView1.SelectedIndices[0]]; - if (currentIndex > -1 && currentIndex < listView1.Items.Count - 1) - { - listView1.Items.RemoveAt(currentIndex); - listView1.Items.Insert(currentIndex + 1, item); - listView1.EnsureVisible(item.Index); - } - } - else MessageBox.Show(Strings.only_qu); - } - - if (listView1.SelectedIndices.Count > 1) - { - lvwColumnSorter_Full.Order = SortOrder.None; - for (int i = 0; i < listView1.SelectedItems.Count; i++) - { - var currentIndex = listView1.SelectedItems[i].Index; - var item = listView1.Items[listView1.SelectedIndices[i]]; - if (currentIndex > -1 && currentIndex < listView1.Items.Count - 1) - { - if (listView1.SelectedItems[i].SubItems[5].Text == Strings.queued) - { - listView1.Items.RemoveAt(currentIndex); - listView1.Items.Insert(currentIndex + 1, item); - } - } - } - } - } - - if (tabControl1.SelectedIndex == 3) - { - if (dg1.SelectedCells.Count == 0 || dg1.SelectedCells.Count > 1) return; - DataGridView dgv = dg1; - try - { - int totalRows = dgv.Rows.Count; - // get index of the row for the selected cell - int rowIndex = dgv.SelectedCells[0].OwningRow.Index; - if (rowIndex == totalRows - 1) - return; - // get index of the column for the selected cell - int colIndex = dgv.SelectedCells[0].OwningColumn.Index; - DataGridViewRow selectedRow = dgv.Rows[rowIndex]; - dgv.Rows.Remove(selectedRow); - dgv.Rows.Insert(rowIndex + 1, selectedRow); - dgv.ClearSelection(); - dgv.Rows[rowIndex + 1].Cells[colIndex].Selected = true; - } - catch { } - } - } - - private void requeue_Click(object sender, EventArgs e) - { - Pg1.Focus(); - if (tabControl1.SelectedIndex == 0) - { - foreach (ListViewItem item in listView1.Items) - { - item.SubItems[5].Text = Strings.queued; - item.BackColor = Color.White; - } - } - if (tabControl1.SelectedIndex == 3) - { - foreach (DataGridViewRow row in dg1.Rows) - { - row.Cells[5].Value = Strings.ready; - row.Cells[5].Style.BackColor = Color.White; - } - } - } - - private void chk_try_CheckedChanged(object sender, EventArgs e) - { - String f_try = String.Empty; - if (is_portable == false) - { - f_try = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_try.ini"; - } - else - { - f_try = port_path + "ff_try_portable.ini"; - } - - if (chk_try.Checked == false) - { - if (File.Exists(f_try)) - { - try - { - File.Delete(f_try); - } - catch - { - MessageBox.Show(Strings.err_set, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - else - { - if (!File.Exists(f_try)) - { - try - { - File.WriteAllText(f_try, String.Empty); - } - catch - { - MessageBox.Show(Strings.err_set, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - } - - private void obtain_ffmpeg() - { - //if (is_portable == true) return; - - Boolean writable = false; - try - { - FileStream fs = File.Create(Path.Combine(Application.StartupPath, Path.GetRandomFileName()), 1, FileOptions.DeleteOnClose); - writable = true; - } - catch - { - writable = false; - } - - OpenFileDialog browse_file = new OpenFileDialog(); - String file_path = String.Empty; - browse_file.Filter = "ffmpeg.exe |ffmpeg.exe"; - - if (browse_file.ShowDialog() == DialogResult.OK) - { - file_path = browse_file.FileName; - if (Path.GetFileName(file_path.ToLower()) != "ffmpeg.exe") - { - MessageBox.Show(Strings.ff_not, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - obtain_ffmpeg(); - get_ffmpeg_v(); - return; - } - } - else - { - is_ff_ok = false; - Form34 frm34 = new Form34(); - frm34.Icon = this.Icon; - if (!File.Exists("ffmpeg.exe")) frm34.lbl_ff_v.Text = Properties.Strings.file_not_found; - else frm34.lbl_ff_v.Text = btn_change_ff.Text; - frm34.ShowDialog(); - if (frm34.down_g == true) - { - down_ffAsync(down_ff_g); - } - if (frm34.down_v == true) - { - down_ffAsync(down_ff_v); - } - if (frm34.down_vh == true) - { - down_ffAsync(down_ff_vh); - } - if (frm34.browse_ff == true) - { - obtain_ffmpeg(); - get_ffmpeg_v(); - if (check_ff_md5() == false) - { - Form25 frm25 = new Form25(); - frm25.ShowDialog(); - if (frm25.check_ff == true) ff_ver(); - return; - } - } - return; - } - - String path = "cmd.exe"; - String param = "/C copy " + '\u0022' + file_path + '\u0022' + " " + '\u0022' + Application.StartupPath + '\u0022' + " / Y"; - Process ff_ext = new Process(); - ff_ext.StartInfo.FileName = path; - ff_ext.StartInfo.Arguments = param; - ff_ext.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - if (writable == false) ff_ext.StartInfo.Verb = "runas"; - try - { - ff_ext.Start(); - ff_ext.WaitForExit(); - is_ff_ok = true; - } - catch - { - MessageBox.Show(Strings.err_dest, Strings.write_error, MessageBoxButtons.OK, MessageBoxIcon.Error); - is_ff_ok = false; - } - } - - private void obtain_mediainfo() - { - if (is_portable == true) return; - - Boolean writable = false; - try - { - FileStream fs = File.Create(Path.Combine(Application.StartupPath, Path.GetRandomFileName()), 1, FileOptions.DeleteOnClose); - writable = true; - } - catch - { - writable = false; - } - - OpenFileDialog browse_file = new OpenFileDialog(); - String file_path = String.Empty; - browse_file.Filter = "mediainfo.exe |mediainfo.exe"; - - if (browse_file.ShowDialog() == DialogResult.OK) - { - file_path = browse_file.FileName; - if (Path.GetFileName(file_path.ToLower()) != "mediainfo.exe") - { - MessageBox.Show(Strings.med_not, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - obtain_mediainfo(); - return; - } - } - else - { - is_ff_ok = false; - return; - } - - String path = "cmd.exe"; - String param = "/C copy " + '\u0022' + file_path + '\u0022' + " " + '\u0022' + Application.StartupPath + '\u0022' + " / Y"; - Process ff_ext = new Process(); - ff_ext.StartInfo.FileName = path; - ff_ext.StartInfo.Arguments = param; - ff_ext.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - if (writable == false) ff_ext.StartInfo.Verb = "runas"; - try - { - ff_ext.Start(); - ff_ext.WaitForExit(); - is_ff_ok = true; - } - catch - { - MessageBox.Show(Strings.err_dest, Strings.write_error, MessageBoxButtons.OK, MessageBoxIcon.Error); - is_ff_ok = false; - } - } - - private void replace_ytdl() - { - try - { - FileStream fs = File.Create(Path.Combine(Application.StartupPath, Path.GetRandomFileName()), 1, FileOptions.DeleteOnClose); - writable_yl = true; - } - catch - { - writable_yl = false; - } - if (writable_yl == true) - { - try - { - File.Copy(Path.GetTempPath() + "\\" + "yt-dlp.exe", Application.StartupPath + "\\" + "yt-dlp.exe", true); - } - catch (Exception excp) - { - MessageBox.Show(Strings.err_yt_up, Strings.update_err, MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - } - else - { - Process prc = new Process(); - String path = "cmd.exe"; - String param = "/C copy " + '\u0022' + Path.GetTempPath() + "yt-dlp.exe" + '\u0022' + " " + '\u0022' + Application.StartupPath + "\\" + "yt-dlp.exe" + '\u0022' + " /Y"; - prc.StartInfo.FileName = path; - prc.StartInfo.Arguments = param; - - prc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - prc.StartInfo.Verb = "runas"; - lbl_yl_name.Text = Strings.updating; - try - { - prc.Start(); - } - catch (Exception excp) - { - MessageBox.Show(Strings.err_yt_2 + " " + Environment.NewLine + excp.Message + Environment.NewLine + " " + Strings.err_yt_up, Strings.update_err, MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - - Thread.Sleep(4000); - } - - this.Invoke(new MethodInvoker(delegate - { - foreach (Control ct in groupBox_m3u.Controls) - { - ct.Enabled = true; - } - btn_update_yt.Text = Strings.update; - txt_up_output.Visible = false; - pg_update_yl.Visible = false; - txt_up_output.Visible = false; - })); - } - - private void wc_dl_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) - { - if (e.Cancelled == true) - { - try - { - File.Delete(Path.GetTempPath() + "\\" + "yt-dlp.exe"); - } - catch { } - wc_dl.Dispose(); - return; - } - else - { - replace_ytdl(); - btn_update_yt.Visible = false; - youtube_dl_ver(); - try - { - File.Delete(Path.GetTempPath() + "\\" + "yt-dlp.exe"); - } - catch { } - } - txt_m3u_params.Enabled = false; - txt_output_server.Enabled = false; - } - - private void wc_dl2_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) - { - txt_adding_p.Text = ""; - pg_adding.Visible = false; - btn_cancel_add.Visible = false; - if (e.Cancelled == true) - { - LB_Wait.Text = ""; - try - { - File.Delete(Path.GetTempPath() + "FFBatch_test" + "\\" + "ffmpeg-release-full.7z"); - } - catch { } - wc_dl2.Dispose(); - return; - } - else - { - - Process ff_ext = new Process(); - ff_ext.StartInfo.FileName = Path.Combine(Application.StartupPath, "7z.exe"); - String archive = Path.Combine(Path.GetTempPath(), "FFBatch_test" + "\\" + "ffmpeg-release-full.7z"); - ff_ext.StartInfo.Arguments = "e " + archive + " -y " + " ffmpeg.exe -r"; - ff_ext.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - try - { - ff_ext.Start(); - LB_Wait.Text = Strings.copy + " " + Strings.file.ToLower() + "..." ; - ff_ext.WaitForExit(); - - pg_adding.Visible = false; - get_ffmpeg_v(); - if (check_ff_md5() == false) - { - Form25 frm25 = new Form25(); - frm25.ShowDialog(); - } - - try { File.Delete(archive); } - catch { } - } - catch (Exception exc) - { - MessageBox.Show(Strings.error + " " + exc.Message, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - LB_Wait.Text = ""; - } - - private void wc_dl_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) - { - this.Invoke(new MethodInvoker(delegate - { - pg_update_yl.Value = e.ProgressPercentage; - pg_update_yl.Refresh(); - })); - - } - - private void wc_dl2_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) - { - this.Invoke(new MethodInvoker(delegate - { - pg_adding.Value = e.ProgressPercentage; - pg_adding.Refresh(); - txt_adding_p.Text = e.ProgressPercentage + "%"; - txt_adding_p.Refresh(); - })); - - } - - private void wc2_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) - { - this.Invoke(new MethodInvoker(delegate - { - pg_adding.Visible = false; - txt_adding_p.Text = ""; - LB_Wait.Text = ""; - btn_cancel_add.Visible = false; - })); - - - if (e.Error == null) - { - Process p = Process.Start(Path.Combine(Path.GetTempPath(), vc_download)); - this.InvokeEx(f => this.Enabled = false); - p.WaitForExit(); - this.InvokeEx(f => this.Enabled = true); - if (p.ExitCode == 0) - { - Thread.Sleep(500); - //this.InvokeEx(f => lbl_yl_name.Left = lbl_yl_name.Left - 16); - //this.InvokeEx(f => lbl_yl_name.Width = lbl_yl_name.Width - 75); - this.InvokeEx(f => lbl_yl_name.Text = Strings.checking_y); - //this.InvokeEx(f => lbl_yt_v.Visible = false); - youtube_dl_ver(); - } - else - { - MessageBox.Show(Strings.yt_req_err, Strings.inst_err, MessageBoxButtons.OK, MessageBoxIcon.Error); - lbl_yl_name.Text = Strings.err_int_yt; - } - } - else - { - MessageBox.Show(Strings.err_down_u, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void wc2_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) - { - this.Invoke(new MethodInvoker(delegate - { - pg_adding.Maximum = 100; - pg_adding.Value = e.ProgressPercentage; - pg_adding.Refresh(); - txt_adding_p.Text = e.ProgressPercentage.ToString() + "%"; - txt_adding_p.Refresh(); - })); - - } - - private void check_VC() - { - wc2.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc2_DownloadProgressChanged); - wc2.DownloadFileCompleted += new AsyncCompletedEventHandler(wc2_DownloadFileCompleted); - - String vc_ver = "http://download.microsoft.com/download/C/6/D/C6D0FD4E-9E53-4897-9B91-836EBA2AACD3/vcredist_x86.exe"; - vc_download = "vc_redist.x86.exe"; - - this.Invoke(new MethodInvoker(delegate - { - - })); - this.InvokeEx(f => f.lbl_yl_name.Text = "Youtube-dl"); - this.InvokeEx(f => f.pic_ok.Visible = false); - this.InvokeEx(f => f.pic_ok.Visible = false); - - DialogResult a = MessageBox.Show(Strings.visualc_req + Environment.NewLine + Environment.NewLine + Strings.down_inst, Strings.add_comp, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); - if (a == DialogResult.Cancel || a == DialogResult.No) - { - this.Invoke(new MethodInvoker(delegate - { - lbl_yl_name.Text = Strings.err_int_yt; - pic_ok.Visible = false; - })); - return; - } - else - { - wc2.DownloadFileAsync(new System.Uri(vc_ver), Path.Combine(Path.GetTempPath(), vc_download)); - this.Invoke(new MethodInvoker(delegate - { - pg_adding.Visible = true; - btn_cancel_add.Visible = true; - LB_Wait.Visible = true; - txt_adding_p.Visible = true; - LB_Wait.Text = Strings.down_up; - LB_Wait.Refresh(); - pic_ok.Visible = false; - this.TopMost = true; - this.TopMost = false; - })); - } - } - - private void youtube_dl_ver() - { - this.InvokeEx(f => f.lbl_yl_name.Text = Strings.check_ytdl); - if (!File.Exists(Path.Combine(Application.StartupPath, "yt-dlp.exe"))) - { - this.Invoke(new MethodInvoker(delegate - { - lbl_yl_name.Text = Strings.yt_not; - lbl_yl_name.Refresh(); - btn_add_yts.Enabled = false; - btn_update_yt.Visible = true; - pic_wait_1.Visible = false; - pic_no_yt.Visible = true; - })); - - //return; - } - try { BG_check_ytdl.RunWorkerAsync(); } catch { } - - } - - private void resize() - { - int width_cols = 14 - listView1.Columns.Count; - lbl_multip.Left = Pg1.Left; lbl_multip.Top = lbl_elapsed.Top; - - if (big_res == false) - { - this.MinimumSize = new Size(1276, 590); - - tabControl1.Height = this.Height - 471; - listView1.Height = this.Height - 496; - listView2.Height = this.Height - 496; - listView3.Height = this.Height - 496; - - tabControl1.Width = this.Width - 18; - listView1.Width = this.Width - 25; - listView2.Width = this.Width - 25; - listView3.Width = this.Width - 25; - - groupBox_m3u.Top = this.Height - 369; - - list_tracks.Top = this.Height - 367; - groupBox9.Top = this.Height - 205; - groupBox2.Top = this.Height - 205; - group_subs.Top = this.Height - 370; - group_prog.Top = this.Height - 120; - - dg1.Height = this.Height - 496; - dg1.Width = this.Width - 23; - groupBox1.Top = this.Height - 370; - panel1.Top = this.Height - 370; - - group_subs.Width = this.Width - 25; - listView3.Columns[1].Width = this.Width - 963; - - groupBox1.Width = this.Width / 2 - 17; - group_prog.Width = this.Width - 26; - panel1.Left = this.Width / 2 - 9; - panel1.Width = this.Width / 2 - 13; - list_tracks.Width = this.Width - 23; - listView2.Columns[0].Width = this.Width - 645; - list_tracks.Columns[0].Width = this.Width - 655; - - btn_edit_presets.Left = this.Width / 2 - 47; - btn_del_preset.Left = this.Width / 2 - 73; - btn_save_preset.Left = this.Width / 2 - 100; - label2.Left = this.Width / 2 - 98; - txt_format.Left = this.Width / 2 - 55; - txt_config_ver.Left = this.Width / 2 - 55; - lbl_config.Left = this.Width / 2 - 98; - combo_presets.Width = this.Width / 2 - 170; - txt_parameters.Width = this.Width / 2 - 170; - - btn_cancel_shut.Width = this.Width - 41; - combo_prio.Left = this.Width - 181; - lbl_cpu_pr.Left = combo_prio.Left + 2; - btn_save_prio.Left = this.Width - 60; - Pg1.Width = group_prog.Width - 515; - btn_pause.Left = group_prog.Width - 247; - btn_abort_all.Left = group_prog.Width - 213; - lbl_updates.Left = this.Width - 141; - btn_update.Left = this.Width - 145; - item_up.Left = this.Width - 46; - item_down.Left = this.Width - 69; - requeue.Left = this.Width - 95; - btn_refresh.Left = this.Width - 124; - btn_clean_list.Left = this.Width - 145; - txt_search_url.Left = this.Width - 206; - lbl_search_url.Left = this.Width - 252; - lbl_size.Left = this.Width - 208; - lbl_dur_list.Left = this.Width - 283; - lbl_items.Left = this.Width - 369; - - btn_inc_font.Left = this.Width - 409; - btn_decr_font.Left = this.Width - 434; - btn_undo_filter.Left = this.Width - 463; - btn_filter.Left = this.Width - 492; - pic_warnings.Left = (group_prog.Width / 2) - 11; - pic_no_errors.Left = (group_prog.Width / 2) - 8; - pic_recording.Left = (group_prog.Width / 2) - 9; - lbl_elapsed.Left = pic_no_errors.Left - lbl_elapsed.Width - 30; - txt_remain.Left = (group_prog.Width / 2) + 35; - lbl_est_size.Left = (group_prog.Width / 2) + 205; - lbl_bitrate.Left = (group_prog.Width / 2) - 310; - lbl_speed.Left = (group_prog.Width / 2) - 102; - btn_cancel_shut.Width = group_prog.Width - 10; - TB1.Left = (group_prog.Width / 2) - 290; - - button24.Left = this.Width - 110; - button25.Left = this.Width - 110; - txt_folder_subs.Width = this.Width - 751; - txt_hard_subs.Width = this.Width - 678; - txt_output_subs.Width = this.Width - 751; - - Combo_def_sub_mux.Left = this.Width - 101; - lbl_def_sub_mux.Left = Combo_def_sub_mux.Left - lbl_def_sub_mux.Width - 2; - Combo_sub_lang_mux.Left = (group_subs.Width / 2) + 300; - lbl_lang_sub_mux.Left = Combo_sub_lang_mux.Left - lbl_lang_sub_mux.Width - 2; - - groupBox_m3u.Width = this.Width - 25; - dg1.Columns[4].Width = this.Width - 930; - - ss_time_input.Left = this.Width / 2 - 169; - lbl_pre_input.Left = this.Width / 2 - 256; - - btn_ref_dcd.Left = (int)(groupBox1.Width / 2) + 55; - cb_hwdecode.Left = (int)(groupBox1.Width / 2) - 4; - lbl_gpu.Left = (int)(groupBox1.Width / 2) - 76; - groupBox3.Left = (int)(groupBox1.Width / 2) - 66; - btn_try_pr.Left = this.Width / 2 - 250; - btn_display_log.Left = btn_try_pr.Left + btn_try_pr.Width; - btn_sh_strs.Left = btn_display_log.Left + btn_display_log.Width + 3; - groupBox4.Width = this.Width / 2 - 97; - panel2.Width = this.Width / 2 - 491; - - txt_path_main.Width = this.Width / 2 - 161; - btn_br_path.Left = this.Width / 2 - 143; - btn_cust_path.Left = btn_br_path.Left + btn_br_path.Width + 1; - btn_reset_path.Left = btn_cust_path.Left + btn_cust_path.Width + 4; - btn_save_path.Left = btn_reset_path.Left + btn_reset_path.Width + 3; - - btn_trim.Left = this.Width / 2 - 159; - txt_ini.Left = btn_trim.Left + btn_trim.Width + 21; - txt_fin.Left = btn_trim.Left + btn_trim.Width + 21; - chk_trim2.Left = txt_fin.Left - 2; - label5.Left = btn_trim.Left + btn_trim.Width; - label6.Left = label5.Left; - btn_concat.Left = this.Width / 2 - 229; - btn_capture.Left = this.Width / 2 - 299; - - chk_try.Left = lbl_multi_file.Left + lbl_multi_file.Width + 5 + (int)(this.Width / (1276 / 2)); - chk_delete_source.Left = chk_try.Left + chk_try.Width + 5 + (int)(this.Width / (1276 / 2)); - chk_overw.Left = chk_open_compl.Left + 394; - - groupBox2.Left = this.Width - 649; - groupBox2.Width = 627; - groupBox9.Width = this.Width - 657; - btn_mux.Left = this.Width - 729; - groupBox11.Left = this.Width - 731; - txt_track_format.Left = this.Width - 775; - btn_extract.Left = this.Width - 840; - groupBox6.Left = this.Width - 847; - btn_mux_job.Left = (int)(groupBox9.Width / 2) - 33; - btn_mux_show_jobs.Left = (int)(groupBox9.Width / 2) + 42; - groupBox_yout.Left = this.Width - 273; - btn_logs_url.Left = this.Width - 337; - btn_stop_m3u8.Left = this.Width - 397; - btn_browse_path_m3u.Left = this.Width - 337; - btn_save_path_url.Left = this.Width - 365; - txt_path_m3u.Width = this.Width - 982; - pic_title.Left = (this.Width / 2) - 130; - pic_batt.Left = pic_title.Left + pic_title.Width + 5; - pic_mon.Left = pic_batt.Left + pic_batt.Width + 5; - btn_change_ff.Left = (this.Width / 2) - 128; - btn_cancel_add.Left = this.Width - 575; - - pg_adding.Width = this.Width - 1178; - txt_adding_p.Left = pg_adding.Left + pg_adding.Width + 4; - txt_add_remain.Left = pg_adding.Left - pg_adding.Width / 4 + ((pg_adding.Width - 100) / 4); - txt_add_remain.Width = this.Width - 1178 + 50; - btn_add_col.Left = this.Width - 519; - - txt_paste_links.Left = (dg1.Width / 2) - (txt_paste_links.Width / 2); - txt_paste_links.Top = (dg1.Height / 2) - 10; - lbl_n_urls.Left = txt_search_url.Left - 100; - lbl_urls_time.Left = txt_search_url.Left - 173; - panel_thumb.Left = this.Width - 366; - } - - if (big_res == true) - { - this.MinimumSize = new Size(1276 + 30, 615); - - tabControl1.Left = 15; - groupBox1.Left = 15; - groupBox_m3u.Left = 15; - group_subs.Left = 15; - list_tracks.Left = 15; - group_prog.Left = 15; - tabControl1.Height = this.Height - 458 - 40; - listView1.Height = this.Height - 495 - 30; - listView2.Height = this.Height - 495 - 30; - listView3.Height = this.Height - 495 - 30; - - tabControl1.Width = this.Width - 45; - listView1.Width = this.Width - 50; - listView2.Width = this.Width - 50; - listView3.Width = this.Width - 50; - - dg1.Height = this.Height - 495 - 30; - dg1.Width = this.Width - 50; - groupBox1.Top = this.Height - 369 - 20; - panel1.Top = this.Height - 369 - 20; - panel1.Left = this.Width / 2 - 1; - panel1.Width = this.Width / 2 - 31; - groupBox1.Width = this.Width / 2 - 26; - - btn_edit_presets.Left = this.Width / 2 - 57; - btn_del_preset.Left = this.Width / 2 - 83; - btn_save_preset.Left = this.Width / 2 - 110; - label2.Left = this.Width / 2 - 108; - txt_format.Left = this.Width / 2 - 65; - txt_config_ver.Left = this.Width / 2 - 65; - lbl_config.Left = this.Width / 2 - 108; - combo_presets.Width = this.Width / 2 - 180; - txt_parameters.Width = this.Width / 2 - 180; ; - - group_prog.Width = this.Width - 46; - btn_cancel_shut.Width = this.Width - 61; - combo_prio.Left = this.Width - 201; - lbl_cpu_pr.Left = combo_prio.Left + 2; - btn_save_prio.Left = this.Width - 80; - Pg1.Width = this.Width - 560; - btn_pause.Left = this.Width - 293; - btn_abort_all.Left = this.Width - 259; - lbl_updates.Left = this.Width - 150; - btn_update.Left = this.Width - 155; - item_up.Left = this.Width - 56; - item_down.Left = this.Width - 79; - requeue.Left = this.Width - 108; - btn_refresh.Left = this.Width - 136; - btn_clean_list.Left = this.Width - 158; - txt_search_url.Left = this.Width - 216; - lbl_search_url.Left = this.Width - 262; - lbl_size.Left = this.Width - 216; - lbl_dur_list.Left = this.Width - 292; - lbl_items.Left = this.Width - 375; - btn_inc_font.Left = this.Width - 419; - btn_decr_font.Left = this.Width - 444; - btn_undo_filter.Left = this.Width - 473; - btn_filter.Left = this.Width - 502; - pic_warnings.Left = (group_prog.Width / 2) - 7; - pic_no_errors.Left = (group_prog.Width / 2) - 6; - pic_recording.Left = (group_prog.Width / 2) - 6; - lbl_elapsed.Left = pic_no_errors.Left - 168; - txt_remain.Left = (group_prog.Width / 2) + 34; - lbl_est_size.Left = (group_prog.Width / 2) + 205; - lbl_bitrate.Left = (group_prog.Width / 2) - 310; - lbl_speed.Left = (group_prog.Width / 2) - 97; - btn_cancel_shut.Width = group_prog.Width - 10; - TB1.Left = (group_prog.Width / 2) - 290; - group_subs.Width = this.Width - 49; - listView3.Columns[1].Width = this.Width - 988; - button24.Left = this.Width - 130; - button25.Left = this.Width - 130; - txt_folder_subs.Width = this.Width - 771; - txt_hard_subs.Width = this.Width - 698; - txt_output_subs.Width = this.Width - 771; - Combo_def_sub_mux.Left = this.Width - 111; - lbl_def_sub_mux.Left = Combo_def_sub_mux.Left - lbl_def_sub_mux.Width - 2; - - Combo_sub_lang_mux.Left = (group_subs.Width / 2) + 300; - lbl_lang_sub_mux.Left = Combo_sub_lang_mux.Left - lbl_lang_sub_mux.Width - 2; - groupBox_m3u.Width = this.Width - 49; - dg1.Columns[4].Width = this.Width - 954; - - ss_time_input.Left = this.Width / 2 - 179; - lbl_pre_input.Left = this.Width / 2 - 266; - - btn_ref_dcd.Left = (int)(groupBox1.Width / 2) + 55; - cb_hwdecode.Left = (int)(groupBox1.Width / 2) - 4; - lbl_gpu.Left = (int)(groupBox1.Width / 2) - 76; - groupBox3.Left = (int)(groupBox1.Width / 2) - 66; - btn_try_pr.Left = this.Width / 2 - 260; - btn_display_log.Left = btn_try_pr.Left + btn_try_pr.Width; - btn_sh_strs.Left = btn_display_log.Left + btn_display_log.Width + 3; - groupBox4.Width = this.Width / 2 - 115; - panel2.Left = this.Width / 2 - 182; - txt_path_main.Width = this.Width / 2 - 178; - btn_br_path.Left = this.Width / 2 - 160; - btn_cust_path.Left = btn_br_path.Left + btn_br_path.Width + 1; - btn_reset_path.Left = btn_cust_path.Left + btn_cust_path.Width + 4; - btn_save_path.Left = btn_reset_path.Left + btn_reset_path.Width + 3; - - btn_trim.Left = this.Width / 2 - 159; - label5.Left = btn_trim.Left + btn_trim.Width; - label6.Left = label5.Left; - - btn_trim.Left = this.Width / 2 - 179; - txt_ini.Left = btn_trim.Left + btn_trim.Width + 21; - txt_fin.Left = btn_trim.Left + btn_trim.Width + 21; - chk_trim2.Left = txt_fin.Left - 2; - label5.Left = btn_trim.Left + btn_trim.Width; - label6.Left = label5.Left; - btn_concat.Left = this.Width / 2 - 246; - btn_capture.Left = this.Width / 2 - 315; - chk_try.Left = lbl_multi_file.Left + lbl_multi_file.Width + 5 + (int)(this.Width / (1276 / 2)); - chk_delete_source.Left = chk_try.Left + chk_try.Width + 5 + (int)(this.Width / (1276 / 2)); - chk_overw.Left = chk_delete_source.Left + chk_delete_source.Width + 32; - - grp_fade.Width = this.Width / 2 - 264; - btn_multimedia.Left = (int)(panel1.Width / 2 - 48); - btn_capture.Left = (int)(panel1.Width / 2 + 22); - - fade_a_in.Left = (int)(panel1.Width / 2 - 85); - fade_a_out.Left = (int)(panel1.Width / 2 - 85); - num_a_in.Left = (int)(panel1.Width / 2 + 5); - num_a_out.Left = (int)(panel1.Width / 2 + 5); - label18.Left = (int)(panel1.Width / 2 + 50); - label23.Left = (int)(panel1.Width / 2 + 50); - - list_tracks.Width = this.Width - 49; - listView2.Width = this.Width - 49; - listView2.Columns[0].Width = this.Width - 677; - list_tracks.Columns[0].Width = this.Width - 677; - groupBox2.Left = this.Width - 658; - groupBox2.Width = 627; - groupBox9.Left = 15; - groupBox9.Width = this.Width - 678; - btn_mux.Left = this.Width - 749; - groupBox11.Left = this.Width - 751; - txt_track_format.Left = this.Width - 795; - btn_extract.Left = this.Width - 860; - groupBox6.Left = this.Width - 867; - btn_mux_job.Left = (int)(groupBox9.Width / 2) - 23; - btn_mux_show_jobs.Left = (int)(groupBox9.Width / 2) + 44; - groupBox_yout.Left = this.Width - 298; - btn_logs_url.Left = this.Width - 366; - btn_stop_m3u8.Left = this.Width - 422; - - btn_browse_path_m3u.Left = this.Width - 365; - btn_save_path_url.Left = this.Width - 392; - txt_path_m3u.Width = this.Width - 1010; - - pic_title.Left = (this.Width / 2) - 130; - pic_batt.Left = pic_title.Left + pic_title.Width + 5; - pic_mon.Left = pic_batt.Left + pic_batt.Width + 5; - btn_change_ff.Left = (this.Width / 2) - 128; - btn_cancel_add.Left = this.Width - 589; - pg_adding.Width = this.Width - 1214; - txt_adding_p.Left = pg_adding.Left + pg_adding.Width + 4; - txt_add_remain.Left = pg_adding.Left - pg_adding.Width / 4 + ((pg_adding.Width - 100) / 4); - txt_add_remain.Width = this.Width - 1202 + 50; - btn_add_col.Left = this.Width - 529; - - groupBox_m3u.Top = this.Height - 369 - 20; - - list_tracks.Top = this.Height - 366 - 20; - groupBox9.Top = this.Height - 205 - 20; - groupBox2.Top = this.Height - 205 - 20; - group_subs.Top = this.Height - 369 - 20; - group_prog.Top = this.Height - 118 - 15; - - txt_paste_links.Left = (dg1.Width / 2) - (txt_paste_links.Width / 2); - txt_paste_links.Top = (dg1.Height / 2) - 10; - lbl_n_urls.Left = txt_search_url.Left - 100; - lbl_urls_time.Left = txt_search_url.Left - 183; - panel_thumb.Left = this.Width - 386; - } - - } - - private void get_ffmpeg_v() - { - String err_txt = String.Empty; - String arch = String.Empty; - List ff_out_ver = new List(); - Process proc_v = new Process(); - ff_ena.Clear(); - - this.Invoke(new MethodInvoker(delegate - { - btn_change_ff.Text = Strings.loading1; - - try - { - proc_v.StartInfo.FileName = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - proc_v.StartInfo.Arguments = "-version"; - proc_v.StartInfo.RedirectStandardOutput = true; - proc_v.StartInfo.RedirectStandardError = true; - proc_v.StartInfo.UseShellExecute = false; - proc_v.StartInfo.CreateNoWindow = true; - proc_v.EnableRaisingEvents = true; - - proc_v.Start(); - - Boolean is_32 = false; - if (Environment.Is64BitProcess == false) - { - is_32 = true; - arch = "x86"; - } - else - { - if ((Environment.OSVersion.Version.Major > 5) || ((Environment.OSVersion.Version.Major == 5) && (Environment.OSVersion.Version.Minor >= 1))) - { - NativeMethods.IsWow64Process(proc_v.Handle, out is_32); - if (is_32 == true) arch = "x86"; - else - { - arch = "x64"; - } - } - } - ff_ver_proc = proc_v.Id; - - while (!proc_v.StandardOutput.EndOfStream) - { - ff_out_ver.Add(proc_v.StandardOutput.ReadLine()); - } - proc_v.WaitForExit(); - - foreach (String str in ff_out_ver) - { - if (str.ToLower().Contains("ffmpeg version")) - { - err_txt = str; - String ess = ""; if (err_txt.ToLower().Contains("essentials")) ess = "-essentials"; - String ful = ""; if (err_txt.ToLower().Contains("full")) ful = "-full"; - err_txt = err_txt.Substring(0, err_txt.IndexOf("Copyright")); - err_txt = err_txt.Replace("ff", "FF"); - err_txt = err_txt.Replace("_build-www.gyan.dev", ""); - err_txt = err_txt.Replace("-full", " Full"); - err_txt = err_txt.Replace("-essentials", " Essentials"); - if (err_txt.ToLower().Contains("-git")) err_txt = err_txt.Substring(0, err_txt.IndexOf("-git")) + ess + ful; - - if (err_txt.Length >= 52) - { - btn_change_ff.Text = err_txt.Substring(0, 52) + " " + arch; - } - else - { - btn_change_ff.Text = err_txt + " " + arch; - } - } - else - { - if (str.ToLower().Contains("--enable-")) - { - foreach (String st in str.Split(new string[] { "--enable-" }, StringSplitOptions.None)) - { - if (!st.ToLower().Contains("configuration") && !st.ToLower().Contains("version") && !st.ToLower().Contains("static")) - { - ff_ena.Add(st); - } - } - } - } - } - - } - catch - { - btn_change_ff.Text = Strings.ver_ff_u; - } - - })); - } - - private async Task down_ffAsync( String url) - { - txt_adding_p.Text = ""; - txt_adding_p.Visible = true; - btn_cancel_add.Visible = true; - LB_Wait.Visible = true; - LB_Wait.Text = Strings.Downloading + " ffmpeg.exe"; - pg_adding.Maximum = 100; - pg_adding.Value = 0; - pg_adding.Visible = true; - wc_dl2.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_dl2_DownloadProgressChanged); - wc_dl2.DownloadFileCompleted += new AsyncCompletedEventHandler(wc_dl2_DownloadFileCompleted); - await wc_dl2.DownloadFileTaskAsync(new System.Uri(url), Path.Combine(Path.GetTempPath(), "FFBatch_test" + "\\" + "ffmpeg-release-full.7z")); - - } - - private void Form1_Shown(object sender, EventArgs e) - { - for (int i = Application.OpenForms.Count - 1; i >= 0; i--) - { - if (Application.OpenForms[i].Name == "Form6") - { - Application.OpenForms[i].Close(); - break; - } - } - - frm33.pic_vid.Image = img_streams.Images[0]; - frm33.pic_aud.Image = img_streams.Images[1]; - frm33.pic_subs.Image = img_streams.Images[2]; - - foreach (String item in Combo_sub_lang_mux.Items) - { - Combo_single_subs_lang.Items.Add(item); - ct3_combo_language.Items.Add(item); - combo_item_lang_2.Items.Add(item); - } - - //Christmas tree - DateTime season = new DateTime(2024, 1, 8, 0, 0, 0); - if (DateTime.Now < season && Settings.Default.season_img == true) pic_season.Visible = true; - //Christmas tree - - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - add_col_start(); - read_saved_path(); - main_progress_bar(); - resize(); - - foreach (ColumnHeader col in listView1.Columns) - { - if (col.Text.Replace(">", "").Replace("<", "").Contains(Strings.Encoding_parameters)) - { - cust_p_col = col.Index; - break; - } - else cust_p_col = 0; - } - - //Create presets if file not available - String path_pr, path_pre = ""; - if (is_portable == false) - { - path_pr = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_presets.ini"; - path_pre = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch_pre.ini"; - } - else - { - path_pr = port_path + "ff_presets_portable.ini"; - path_pre = port_path + "ff_batch_pre_portable.ini"; - } - - if (!File.Exists(path_pr)) - { - File.WriteAllText(path_pr, "Version 1.0" + Environment.NewLine - + "PR: " + Strings.pr01 + " & -c copy % mp4" + Environment.NewLine - + "PR: " + Strings.pr02 + " & -c:v copy -c:a aac -cutoff 20K -b:a 256K -ac 2 % mkv" + Environment.NewLine + "PR: " + Strings.pr03 + " & -c:v copy -c:a ac3 -b:a 256K -ac 2 -c:s copy % mkv" + Environment.NewLine + "PR: " + Strings.pr04 + " & -c:v prores_ks -profile:v standard -vendor:v ap10 -pix_fmt yuv422p10le -c:a pcm_s16le -chunk_size 64K % mkv" + Environment.NewLine + "PR: " + Strings.pr05 + " & -c:v libx264 -crf 20 -c:a copy % mkv" + Environment.NewLine + "PR: " + Strings.pr06 + " & -c:v libx264 -crf 23 -preset ultrafast -c:a copy % mkv" + Environment.NewLine + "PR: " + Strings.pr07 + " & -c:v libx265 -crf 23 -c:a copy % mkv" + Environment.NewLine + "PR: " + Strings.pr08 + " & -c:v libx264 -crf 23 -vf scale=1280:720 -c:a aac -b:a 128K % mp4" + Environment.NewLine + "PR: " + Strings.pr09 + " & -c:v libx264 -crf 21 -vf " + "\u0022" + "transpose=1" + "\u0022" + " -c:a copy % mp4" + Environment.NewLine + "PR: " + Strings.pr10 + " & -c:v libx264 -crf 21 -vf " + "\u0022" + "transpose=0" + "\u0022" + " -c:a copy % mp4" + Environment.NewLine + "PR: " + Strings.pr11 + " & -c:v libx264 -crf 21 -vf " + "\u0022" + "transpose=2" + "\u0022" + " -c:a copy % mp4" + Environment.NewLine + "PR: " + Strings.pr12 + " & -c:v libx264 -crf 21 -vf " + "\u0022" + "transpose=3" + "\u0022" + " -c:a copy % mp4" + Environment.NewLine + "PR: " + Strings.pr13 + " & -c:v libx264 -crf 21 -vf " + "\u0022" + "transpose=2, transpose=2" + "\u0022" + " -c:a copy % mp4" + Environment.NewLine + "PR: " + Strings.pr14 + " & -map 0 -c copy -sn % mp4" + Environment.NewLine + "PR: " + Strings.pr15 + " & -vn -c:a flac -ar 44100 -sample_fmt s16 -ac 2 % flac" + Environment.NewLine + "PR: " + Strings.pr16 + " & -c:v copy -c:a libmp3lame -qscale:a 0 -ac 2 % mp3" + Environment.NewLine + "PR: " + Strings.pr17 + " & -vn -c:a libmp3lame -qscale:a 1 -ac 2 % mp3" + Environment.NewLine + "PR: " + Strings.pr18 + " & -vn -c:a libmp3lame -b:a 224K -ac 2 % mp3" + Environment.NewLine + "PR: " + Strings.pr19 + " & -vn -c:a pcm_s16le -ar 44100 -sample_fmt s16 -ac 2 % wav" + Environment.NewLine + "PR: " + Strings.pr20 + " & -map 0:2 -c:s copy % srt" + Environment.NewLine + "PR: " + Strings.pr21 + " & -vframes 1 -f image2 % png" + Environment.NewLine + "PR: " + Strings.pr21_2 + " & -c:v h264_amf -rc cqp -qp_p 20 -qp_i 20 -qp_b 20 -c:a copy % mkv" + Environment.NewLine + "PR: " + Strings.pr21_21 + " & -c:v hevc_amf -rc cqp -qp_p 20 -qp_i 20 -qp_b 20 -c:a copy % mkv" + Environment.NewLine + "PR: " + Strings.pr22 + " & -r 24 -c:a aac -b:a 128K % mkv" + Environment.NewLine + "PR: " + Strings.pr23 + " & -r 15 -vf scale=1280x720 -c:a aac -b:a 128K % mkv" + Environment.NewLine + "PR: " + Strings.pr24 + " & -c:v h264_nvenc -qp 20 -r 30 -c:a aac -b:a 128K % mkv" + Environment.NewLine + "PR: " + Strings.pr25 + " & -c:v h264_qsv -qp 20 -r 25 -c:a aac -b:a 128K % mkv" + Environment.NewLine + "PR: " + Strings.pr26 + " & -c:v libx264 -preset veryfast -vf " + '\u0022' + "fps=25,format=yuv420p,scale=1920:-2" + '\u0022' + " -c:a aac -b:a 64K % mp4"); - btn_load_config.PerformClick(); - } - - set_font_size(); - - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - if (Settings.Default.dark_mode == true) - { - pic_frame.Image = pic_dark.Image; - pic_frame.InitialImage = pic_dark.Image; - } - - //Sleep off - - String f_sleep = String.Empty; - if (is_portable == false) - { - f_sleep = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_sleep.ini"; - } - else - { - f_sleep = port_path + "ff_sleep_portable.ini"; - } - - if (File.Exists(f_sleep)) - { - NativeMethods.SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED); - Timer_idle.Enabled = true; - } - - //End sleep off - - is_ff_ok = true; - - String ffm = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - if (!File.Exists(ffm)) - { - Form34 frm34 = new Form34(); - if (!File.Exists("ffmpeg.exe")) frm34.lbl_ff_v.Text = Properties.Strings.file_not_found; - else frm34.lbl_ff_v.Text = btn_change_ff.Text; - frm34.Icon = this.Icon; - frm34.ShowDialog(); - if (frm34.down_g == true) - { - down_ffAsync(down_ff_g); - } - if (frm34.down_v == true) - { - down_ffAsync(down_ff_v); - } - if (frm34.down_vh == true) - { - down_ffAsync(down_ff_vh); - } - if (frm34.browse_ff == true) - { - obtain_ffmpeg(); - get_ffmpeg_v(); - if (check_ff_md5() == false) - { - Form25 frm25 = new Form25(); - frm25.ShowDialog(); - if (frm25.check_ff == true) ff_ver(); - return; - } - } - } - - String ffm3 = Path.Combine(Application.StartupPath, "mediainfo.exe"); - if (!File.Exists(ffm3)) - { - this.Enabled = false; - DialogResult a = MessageBox.Show(Strings.med_not_f, Strings.file_not_f, MessageBoxButtons.YesNo, MessageBoxIcon.Warning); - if (a == DialogResult.No) Application.Exit(); - if (a == DialogResult.Yes) - { - obtain_mediainfo(); - if (is_ff_ok == false) - { - Application.Exit(); - } - else - { - is_ff_ok = true; - this.Enabled = true; - } - } - } - - - //End FFmpeg version - - watch_ff.Path = Application.StartupPath; - - if (File.Exists("ffmpeg.exe")) read_hw_dec(); - - //Automatic update - - String f_updates = String.Empty; - if (is_portable == false) - { - f_updates = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_updates.ini"; - } - else - { - f_updates = port_path + "ff_updates_portable.ini"; - } - if (!File.Exists(f_updates)) - { - chk_auto_updates.Checked = true; - check_back_updates(); - } - else - { - chk_auto_updates.Checked = false; - } - Pg1.Focus(); - //End automatic updates - - btn_update.Text = Strings.version + " " + Application.ProductVersion; - remember_tab(); - - Boolean no_tab_change = false; - - //Get dropped files - - String[] arguments = Environment.GetCommandLineArgs(); - String[] file_drop = arguments.Skip(1).ToArray(); - - // Automatic queue recovery - - String save_path_queue = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "saved_queue_temp.ffq"; - if (is_portable == true) save_path_queue = port_path + "saved_queue_temp.ffq"; - - String save_path_queue0 = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "saved_queue_temp0.ffq"; - if (is_portable == true) save_path_queue0 = port_path + "saved_queue_temp0.ffq"; - - Boolean bad_queue = false; - Boolean file_bad = false; - - if (File.Exists(save_path_queue) && file_drop.Count() == 0) - { - String q = File.ReadAllText(save_path_queue); - if (q != null && q.Length > 10) - { - foreach (String line in File.ReadLines(save_path_queue)) - { - if (line.Contains(" ")) - { - file_bad = true; - bad_queue = true; - break; - } - } - if (!File.Exists(save_path_queue) || file_bad == true) - { - if (File.Exists(save_path_queue0)) - { - file_bad = false; - bad_queue = false; - try - { - File.Delete(save_path_queue); - File.Copy(save_path_queue0, save_path_queue); - - } - catch (Exception exc) { MessageBox.Show(exc.Message); } - } - } - } - else - { - bad_queue = true; - } - } - else - { - if (File.Exists(save_path_queue0) && file_drop.Count() == 0) - { - file_bad = false; - bad_queue = false; - try - { - File.Delete(save_path_queue); - File.Copy(save_path_queue0, save_path_queue); - - } - catch (Exception exc) { MessageBox.Show(exc.Message); } - } - } - - if (File.Exists(save_path_queue) && file_drop.Count() == 0) - { - int linea = 0; - int not_found = 0; - combo_presets.Text = ""; - this.Cursor = Cursors.WaitCursor; - List itemsToAdd = new List(); - try - { - foreach (string line in File.ReadLines(save_path_queue)) - { - if (linea == 0) - { - txt_parameters.Text = line; - } - if (linea == 1) - { - txt_format.Text = line; - } - - if (linea == 2) - { - if (line == "Unchecked") chk_recreate.CheckState = CheckState.Unchecked; - else chk_recreate.CheckState = CheckState.Checked; - } - - if (linea == 3) - { - if (line == "Unchecked") chk_suffix.CheckState = CheckState.Unchecked; - else - { - chk_suffix.CheckState = CheckState.Checked; - txt_suffix.Text = line; - } - } - - if (linea == 4) - { - txt_path_main.Text = line; - } - - if (linea > 4) - { - Boolean missing = false; - listView1.SmallImageList = imageList2; - - itemsToAdd.Add(new ListViewItem(Path.GetFileName(line.Substring(0, line.LastIndexOf(" --0 "))), 1)); - //ListViewItem elemento = new ListViewItem(line.Substring(0, line.LastIndexOf(" --0 ")), 1); - //Begin get file icon - Icon iconForFile = SystemIcons.WinLogo; - - // Check to see if the image collection contains an image - // for this extension, using the extension as a key. - if (File.Exists(line.Substring(0, line.LastIndexOf(" --0 ")))) - { - if (line.Substring(0, 2) != "\\\\") - { - if (!imageList2.Images.ContainsKey(Path.GetExtension(line.Substring(0, line.LastIndexOf(" --0 "))))) - { - // If not, add the image to the image list. - iconForFile = System.Drawing.Icon.ExtractAssociatedIcon(line.Substring(0, line.LastIndexOf(" --0 "))); - imageList2.Images.Add(Path.GetExtension(line.Substring(0, line.LastIndexOf(" --0 "))), iconForFile); - } - //listView1.Items.Add(elemento); - itemsToAdd[linea - 5].ImageKey = Path.GetExtension(Path.GetExtension(line.Substring(0, line.LastIndexOf(" --0 ")))); - } - else - { - itemsToAdd[linea - 5].ImageIndex = 0; - } - } - else - { - not_found = not_found + 1; - missing = true; - } - - - String type = line.Substring(line.LastIndexOf(" --0 ") + 5, line.Length - (line.LastIndexOf(" --0") + 5)); - type = type.Substring(0, type.LastIndexOf(" --1")); - String dur = line.Substring(line.LastIndexOf(" --1 ") + 5, line.Length - (line.LastIndexOf(" --1") + 5)); - dur = dur.Substring(0, dur.LastIndexOf(" --2")); - String size = line.Substring(line.LastIndexOf(" --2 ") + 5, line.Length - (line.LastIndexOf(" --2") + 5)); - size = size.Substring(0, size.LastIndexOf(" --3")); - String status = line.Substring(line.LastIndexOf(" --3 ") + 5, line.Length - (line.LastIndexOf(" --3") + 5)); - - itemsToAdd[linea - 5].SubItems.Add(Path.GetDirectoryName(line.Substring(0, line.LastIndexOf(" --0 ")))); - itemsToAdd[linea - 5].SubItems.Add(type); - itemsToAdd[linea - 5].SubItems.Add(dur); - itemsToAdd[linea - 5].SubItems.Add(size); - if (missing == false) itemsToAdd[linea - 5].SubItems.Add(status); - else - { - itemsToAdd[linea - 5].SubItems.Add(Strings.file_not_f); - itemsToAdd[linea - 5].BackColor = Color.LightGoldenrodYellow; - } - if (listView1.Columns.Count > 6) itemsToAdd[linea - 5].SubItems.Add("-"); - if (listView1.Columns.Count > 7) itemsToAdd[linea - 5].SubItems.Add("-"); - if (listView1.Columns.Count > 8) itemsToAdd[linea - 5].SubItems.Add("-"); - if (listView1.Columns.Count > 9) itemsToAdd[linea - 5].SubItems.Add("-"); - if (listView1.Columns.Count > 10) itemsToAdd[linea - 5].SubItems.Add("-"); - if (listView1.Columns.Count > 11) itemsToAdd[linea - 5].SubItems.Add("-"); - if (listView1.Columns.Count > 12) itemsToAdd[linea - 5].SubItems.Add("-"); - if (listView1.Columns.Count > 13) itemsToAdd[linea - 5].SubItems.Add("-"); - if (listView1.Columns.Count > 14) itemsToAdd[linea - 5].SubItems.Add("-"); - } - - linea = linea + 1; - } - if (bad_queue == false) listView1.Items.AddRange(itemsToAdd.ToArray()); - } - catch (Exception excpt) - { - this.Cursor = Cursors.Arrow; - MessageBox.Show(Strings.err_qf + Environment.NewLine + excpt.Message, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - btn_load_config.PerformClick(); - read_saved_path(); - return; - } - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[5].Text == Strings.error) item.BackColor = Color.Orange; - } - - this.Cursor = Cursors.Arrow; - - lbl_items.Text = listView1.Items.Count.ToString() + " " + Strings.files; - - if (not_found > 0 && no_warn_0_dur == false) - { - this.Cursor = Cursors.Arrow; - MessageBox.Show(Strings.queue_warn + Environment.NewLine + not_found.ToString() + " " + Strings.queue_not_f + " " + Environment.NewLine + Environment.NewLine + Strings.sort_status + ".", Strings.warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - - if (start_seq == true && bad_queue == false) - { - Thread.Sleep(2000); - if (start_multi == false) btn_seq.PerformClick(); - else btn_multi_m.PerformClick(); - } - return; - } - - else btn_load_config.PerformClick(); - - //End program crashed - - //Remember last tab - - String f_remember = String.Empty; - if (is_portable == false) - { - f_remember = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_remember.ini"; - } - else - { - f_remember = port_path + "ff_remember_portable.ini"; - } - - if (File.Exists(f_remember)) - { - remember_last_tab = true; - if (no_tab_change == false) this.InvokeEx(f => f.tabControl1.SelectedIndex = Convert.ToInt16(File.ReadAllText(f_remember))); - } - else - { - remember_last_tab = false; - } - - String f_show_wiz = String.Empty; - if (is_portable == false) - { - f_show_wiz = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_show_wiz.ini"; - } - else - { - f_show_wiz = port_path + "ff_show_wiz_portable.ini"; - } - if (!File.Exists(f_show_wiz) && File.Exists("ffmpeg.exe")) - { - show_wiz = true; - btn_wizard.PerformClick(); - } - else show_wiz = false; - - if (yt_chk == false) - { - yt_chk = true; - youtube_dl_ver(); - } - - //Sendto parameters - - if (file_drop.Count() != 0) - { - if (File.Exists(save_path_queue)) try { File.Delete(save_path_queue); } catch (Exception exc) { MessageBox.Show(exc.Message); } - if (File.Exists(save_path_queue0)) try { File.Delete(save_path_queue0); } catch (Exception exc) { MessageBox.Show(exc.Message); } - - show_wiz_start = false; - change_tab_1 = false; - change_tab_2 = false; - no_tab_change = true; - - this.Cursor = Cursors.WaitCursor; - int fl = 0; - List files2 = new List(); - - int num_drop = 0; - if (file_drop.Count() == 1 && Path.GetExtension(file_drop[0]) == ".ffq") - //Load queue file - { - int linea = 0; - int not_found = 0; - combo_presets.Text = ""; - List itemsToAdd = new List(); - try - { - foreach (string line in File.ReadLines(file_drop[0])) - { - if (linea == 0) - { - txt_parameters.Text = line; - } - if (linea == 1) - { - txt_format.Text = line; - } - - if (linea == 2) - { - if (line == "Unchecked") chk_recreate.CheckState = CheckState.Unchecked; - else chk_recreate.CheckState = CheckState.Checked; - } - - if (linea == 3) - { - if (line == "Unchecked") chk_suffix.CheckState = CheckState.Unchecked; - else - { - chk_suffix.CheckState = CheckState.Checked; - txt_suffix.Text = line; - } - } - - if (linea == 4) - { - txt_path_main.Text = line; - } - - if (linea > 4) - { - Boolean missing = false; - listView1.SmallImageList = imageList2; - - itemsToAdd.Add(new ListViewItem(Path.GetFileName(line.Substring(0, line.LastIndexOf(" --0 "))), 1)); - //ListViewItem elemento = new ListViewItem(line.Substring(0, line.LastIndexOf(" --0 ")), 1); - //Begin get file icon - Icon iconForFile = SystemIcons.WinLogo; - - // Check to see if the image collection contains an image - // for this extension, using the extension as a key. - if (File.Exists(line.Substring(0, line.LastIndexOf(" --0 ")))) - { - if (line.Substring(0, 2) != "\\\\") - { - if (!imageList2.Images.ContainsKey(Path.GetExtension(line.Substring(0, line.LastIndexOf(" --0 "))))) - { - // If not, add the image to the image list. - iconForFile = System.Drawing.Icon.ExtractAssociatedIcon(line.Substring(0, line.LastIndexOf(" --0 "))); - imageList2.Images.Add(Path.GetExtension(line.Substring(0, line.LastIndexOf(" --0 "))), iconForFile); - } - //listView1.Items.Add(elemento); - itemsToAdd[linea - 5].ImageKey = Path.GetExtension(Path.GetExtension(line.Substring(0, line.LastIndexOf(" --0 ")))); - } - else - { - itemsToAdd[linea - 5].ImageIndex = 0; - } - } - else - { - not_found = not_found + 1; - missing = true; - } - - String type = line.Substring(line.LastIndexOf(" --0 ") + 5, line.Length - (line.LastIndexOf(" --0") + 5)); - type = type.Substring(0, type.LastIndexOf(" --1")); - String dur = line.Substring(line.LastIndexOf(" --1 ") + 5, line.Length - (line.LastIndexOf(" --1") + 5)); - dur = dur.Substring(0, dur.LastIndexOf(" --2")); - String size = line.Substring(line.LastIndexOf(" --2 ") + 5, line.Length - (line.LastIndexOf(" --2") + 5)); - size = size.Substring(0, size.LastIndexOf(" --3")); - String status = line.Substring(line.LastIndexOf(" --3 ") + 5, line.Length - (line.LastIndexOf(" --3") + 5)); - - itemsToAdd[linea - 5].SubItems.Add(Path.GetDirectoryName(line.Substring(0, line.LastIndexOf(" --0 ")))); - itemsToAdd[linea - 5].SubItems.Add(type); - itemsToAdd[linea - 5].SubItems.Add(dur); - itemsToAdd[linea - 5].SubItems.Add(size); - if (missing == false) itemsToAdd[linea - 5].SubItems.Add(status); - else - { - itemsToAdd[linea - 5].SubItems.Add(Strings.file_not_f); - itemsToAdd[linea - 5].BackColor = Color.LightGoldenrodYellow; - } - } - linea = linea + 1; - } - listView1.Items.AddRange(itemsToAdd.ToArray()); - } - catch (Exception excpt) - { - this.Cursor = Cursors.Arrow; - MessageBox.Show(Strings.err_qf + Environment.NewLine + excpt.Message, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - btn_load_config.PerformClick(); - read_saved_path(); - return; - } - - this.Cursor = Cursors.Arrow; - calc_list_size(); - calc_total_dur(); - lbl_items.Text = listView1.Items.Count.ToString() + " " + Strings.files; - - if (not_found > 0 && no_warn_0_dur == false) - { - this.Cursor = Cursors.Arrow; - MessageBox.Show(Strings.queue_ok + Environment.NewLine + not_found.ToString() + " " + Strings.queue_not_f + " " + Environment.NewLine + Environment.NewLine + Strings.sort_status + " " + '\u0022' + Strings.file_not_f + '\u0022' + ".", Strings.missing_f, MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - this.Cursor = Cursors.Arrow; - if (start_seq == true) - { - Thread.Sleep(500); - if (start_multi == false) btn_seq.PerformClick(); - else btn_multi_m.PerformClick(); - } - return; - } - - if (file_drop.Count() == 1 && Path.GetExtension(file_drop[0]) == ".txt") - { - int not_found = 0; - int linea = 0; - - List itemsToAdd = new List(); - - foreach (string line in File.ReadLines(file_drop[0])) - { - Boolean missing = false; - itemsToAdd.Add(new ListViewItem(Path.GetFileName(line))); - if (File.Exists(line)) - { - listView1.SmallImageList = imageList2; - - Icon iconForFile = SystemIcons.WinLogo; - - if (!imageList2.Images.ContainsKey(Path.GetExtension(line))) - { - // If not, add the image to the image list. - iconForFile = System.Drawing.Icon.ExtractAssociatedIcon(line); - imageList2.Images.Add(Path.GetExtension(line), iconForFile); - } - - //listView1.Items.Add(elemento); - itemsToAdd[linea].ImageKey = Path.GetExtension(Path.GetExtension(line)); - } - else - { - not_found = not_found + 1; - missing = true; - } - - if (File.Exists(line)) itemsToAdd[linea].SubItems.Add(Path.GetDirectoryName(line)); - else itemsToAdd[linea].SubItems.Add(Strings.pending); - itemsToAdd[linea].SubItems.Add(Strings.pending); - itemsToAdd[linea].SubItems.Add(Strings.pending); - itemsToAdd[linea].SubItems.Add(Strings.pending); - itemsToAdd[linea].SubItems.Add(Strings.pending); - - linea = linea + 1; - } - listView1.Items.AddRange(itemsToAdd.ToArray()); - - this.Cursor = Cursors.Arrow; - calc_list_size(); - calc_total_dur(); - - lbl_items.Text = listView1.Items.Count.ToString() + " " + Strings.files; - - if (not_found > 0 && no_warn_0_dur == false) - { - this.Cursor = Cursors.Arrow; - MessageBox.Show(Strings.queue_warn + Environment.NewLine + not_found.ToString() + " " + Strings.queue_not_f + " " + Environment.NewLine + Environment.NewLine + Strings.sort_status + ".", Strings.warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - else btn_refresh.PerformClick(); - this.Cursor = Cursors.Arrow; - return; - } - - //End load queue file - Form11_2 frm11_2 = new Form11_2(); - Task t3 = Task.Run(() => - { - frm11_2.label1.Text = Strings.reading_path; - frm11_2.ShowDialog(); - }); - Thread.Sleep(100); - - foreach (String dropped in file_drop) - { - if (File.Exists(dropped)) - { - files2.Add(dropped); - num_drop = files2.Count; - } - else - { - if (Directory.Exists(dropped)) - { - if (add_subfs == false) - { - foreach (String file in Directory.GetFiles(dropped)) - { - if (!File.GetAttributes(file).HasFlag(FileAttributes.Hidden) && is_excluded(file) == false) - { - files2.Add(file); - fl = fl + 1; - num_drop = num_drop + 1; - if (frm11_2.abort_validate == true) return; - else - { - try - { - frm11_2.Invoke(new MethodInvoker(delegate - { - frm11_2.label2.Text = fl.ToString() + " " + Strings.files; - })); - } - catch { } - } - } - } - } - else - { - try - { - foreach (string f in Directory.GetFiles(dropped, "*.*", System.IO.SearchOption.AllDirectories)) - { - if (!File.GetAttributes(f).HasFlag(FileAttributes.Hidden) && is_excluded(f) == false) - { - files2.Add(f); - fl = fl + 1; - num_drop = num_drop + 1; - if (frm11_2.abort_validate == true) - { - this.Cursor = Cursors.Arrow; - return; - } - else - { - try - { - frm11_2.Invoke(new MethodInvoker(delegate - { - frm11_2.label2.Text = fl.ToString() + " " + Strings.files; - })); - } - catch { } - } - } - } - } - catch (System.Exception excpt) - { - try - { - frm11_2.Invoke(new MethodInvoker(delegate - { - frm11_2.TopMost = true; - frm11_2.TopMost = false; - })); - } - catch { } - - if (excpt.HResult == -2147024893) - { - MessageBox.Show(Strings.err_long_path + Environment.NewLine + Environment.NewLine + dropped, Strings.error3, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - else MessageBox.Show(Strings.error2 + " " + excpt.Message, Strings.error3, MessageBoxButtons.OK, MessageBoxIcon.Error); - this.Cursor = Cursors.Arrow; - return; - } - } - } - } - } - Thread.Sleep(100); - try - { - frm11_2.Invoke(new MethodInvoker(delegate - { - frm11_2.Dispose(); - })); - } - catch { } - - files_to_add = files2; - canceled_file_adding = false; - btn_cancel_add.Enabled = true; - btn_cancel_add.Visible = true; - btn_cancel_add.Refresh(); - BG_Files.RunWorkerAsync(); - this.Cursor = Cursors.Arrow; - - //End Sendto files - } - else - { - if (Settings.Default.monitor_fd == true) - { - if (!Directory.Exists(Settings.Default.fd_monitored)) - { - Settings.Default.monitor_fd = false; - Settings.Default.Save(); - return; - } - - if (txt_path_main.Text.Contains(".\\") && Settings.Default.monitor_fd == true && Settings.Default.mon_fd_subs == true) - { - MessageBox.Show(Strings.mon_no_rel, Strings.warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); - Settings.Default.monitor_fd = false; - Settings.Default.mon_fd_subs = false; - pic_mon.Visible = false; - Settings.Default.Save(); - } - else - { - pic_mon.Visible = true; - System.IO.SearchOption sh = new System.IO.SearchOption(); - if (Settings.Default.mon_fd_subs == true) sh = System.IO.SearchOption.AllDirectories; - else sh = System.IO.SearchOption.TopDirectoryOnly; - - string[] file_drop2 = (string[])Directory.GetFiles(Settings.Default.fd_monitored, "*.*", sh); - drop_files(file_drop2); - timer_watch.Enabled = true; - timer_watch.Interval = (int)Settings.Default.mon_int * 1000; - timer_watch.Start(); - } - } - } - } - private void ff_ver() - { - //FFmpeg version - - btn_change_ff.Text = Strings.loading1; - Process proc_v = new Process(); - proc_v.StartInfo.FileName = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - proc_v.StartInfo.Arguments = "-version"; - - proc_v.StartInfo.RedirectStandardOutput = true; - proc_v.StartInfo.RedirectStandardError = true; - proc_v.StartInfo.UseShellExecute = false; - proc_v.StartInfo.CreateNoWindow = true; - proc_v.EnableRaisingEvents = true; - try - { - proc_v.Start(); - proc_v.WaitForExit(); - - Boolean is_32 = false; - String arch = String.Empty; - if ((Environment.OSVersion.Version.Major > 5) - || ((Environment.OSVersion.Version.Major == 5) && (Environment.OSVersion.Version.Minor >= 1))) - { - NativeMethods.IsWow64Process(proc_v.Handle, out is_32); - if (is_32 == true) arch = "x86"; - else - { - arch = "x64"; - } - } - String err_txt = String.Empty; - err_txt = proc_v.StandardOutput.ReadLine(); - - err_txt = err_txt.Substring(0, err_txt.IndexOf("Copyright")); - err_txt = err_txt.Replace("ff", "FF"); - err_txt = err_txt.Replace("_build-www.gyan.dev", ""); - err_txt = err_txt.Replace("-full", " Full"); - err_txt = err_txt.Replace("-essentials", " Essentials"); - if (err_txt.ToLower().Contains("-git")) err_txt = err_txt.Substring(0, err_txt.IndexOf("-git")); - - //err_txt = err_txt.Replace("gyan.dev", ""); - if (err_txt.Length >= 42) - { - btn_change_ff.Text = err_txt.Substring(0, 42) + " " + arch; - } - else - { - btn_change_ff.Text = err_txt + " " + arch; - } - } - catch - { - MessageBox.Show(Strings.err_pars_ff, Strings.ff_error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - } - } - - private void checkBox3_CheckedChanged(object sender, EventArgs e) - { - Boolean prev_state = false; - if (chk_open_compl.CheckState == CheckState.Checked) prev_state = false; - if (chk_open_compl.CheckState == CheckState.Unchecked) prev_state = true; - - String path = String.Empty; - if (is_portable == false) - { - path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.ini"; - } - else - { - path = port_path + "ff_batch_portable.ini"; - if (!File.Exists(path)) reset_portable(); - } - - int linea = 0; - - foreach (string line in File.ReadLines(path)) - { - linea = linea + 1; - - if (linea == 3) - { - if (line == "Yes") - { - if (prev_state == false) - { - btn_save_config.ImageKey = "Save_settings_39.png"; - toolTip_settings.SetToolTip(this.btn_save_config, Strings.params_def); - } - else - { - btn_save_config.ImageKey = "save_pending.png"; - toolTip_settings.SetToolTip(this.btn_save_config, Strings.setting_mod); - } - } - - if (line == "No") - { - if (prev_state == true) - { - btn_save_config.ImageKey = "Save_settings_39.png"; - toolTip_settings.SetToolTip(this.btn_save_config, Strings.params_def); - } - else - { - btn_save_config.ImageKey = "save_pending.png"; - toolTip_settings.SetToolTip(this.btn_save_config, Strings.setting_mod); - } - } - } - } - } - - private void checkBox1_CheckedChanged(object sender, EventArgs e) - { - Boolean prev_state = false; - if (chk_recreate.CheckState == CheckState.Checked) prev_state = false; - if (chk_recreate.CheckState == CheckState.Unchecked) prev_state = true; - - String path = String.Empty; - if (is_portable == false) - { - path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.ini"; - } - else - { - path = port_path + "ff_batch_portable.ini"; - } - - int linea = 0; - - foreach (string line in File.ReadLines(path)) - { - linea = linea + 1; - - if (linea == 6) - { - if (line == "keep_yes") - { - if (prev_state == false) - { - btn_save_config.ImageKey = "Save_settings_39.png"; - toolTip_settings.SetToolTip(this.btn_save_config, Strings.params_def); - } - else - { - btn_save_config.ImageKey = "save_pending.png"; - toolTip_settings.SetToolTip(this.btn_save_config, Strings.setting_mod); - } - } - - if (line == "keep_no") - { - if (prev_state == true) - { - btn_save_config.ImageKey = "Save_settings_39.png"; - toolTip_settings.SetToolTip(this.btn_save_config, Strings.params_def); - } - else - { - btn_save_config.ImageKey = "save_pending.png"; - toolTip_settings.SetToolTip(this.btn_save_config, Strings.setting_mod); - } - } - } - } - } - - private void btn_exit_Click(object sender, EventArgs e) - { - del_queue(); - Application.Exit(); - } - - private void combo_prio_Click(object sender, EventArgs e) - { - //Load priority - - String f_prio = String.Empty; - if (is_portable == false) - { - f_prio = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_priority.ini"; - } - else - { - f_prio = port_path + "ff_priority_portable.ini"; - } - - if (File.Exists(f_prio)) - { - String saved_prio = File.ReadAllText(f_prio); - if (saved_prio != String.Empty) - { - current_prio = Convert.ToInt16(saved_prio); - } - } - else - { - current_prio = 2; - } - - //End load priority - } - - private void cb_hwdecode_SelectedIndexChanged_1(object sender, EventArgs e) - { - int current_dcd = cb_hwdecode.SelectedIndex; - String f_hw_dcd = String.Empty; - if (is_portable == false) - { - f_hw_dcd = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_hw_dcd.ini"; - } - else - { - f_hw_dcd = port_path + "ff_hw_dcd_portable.ini"; - } - decoders.Clear(); - decoders.Add(cb_hwdecode.SelectedItem.ToString()); - - String path_c = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch"); - if (is_portable == true) path_c = port_path; - - if (!Directory.Exists(path_c)) - { - try - { - Directory.CreateDirectory(path_c); - File.WriteAllText(f_hw_dcd, decoders[0]); - } - catch - { - } - } - else - { - File.WriteAllText(f_hw_dcd, decoders[0]); - } - } - - private void btn_ref_dcd_Click(object sender, EventArgs e) - { - cb_hwdecode.Items.Clear(); - String f_hw_dcd = String.Empty; - if (is_portable == false) - { - f_hw_dcd = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_hw_dcd.ini"; - } - else - { - f_hw_dcd = port_path + "ff_hw_dcd_portable.ini"; - } - if (File.Exists(f_hw_dcd)) - { - try - { - File.Delete(f_hw_dcd); - } - catch - { - MessageBox.Show(Strings.err_dec, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - - cb_hwdecode.Items.Add("none"); - decoders.Add("none"); - cb_hwdecode.SelectedIndex = 0; - String selected = cb_hwdecode.SelectedItem.ToString(); - hw_decoders = false; - if (hw_decoders == false) - { - hw_decoders = true; - - //Read hardware decoders - Process consola_hw = new Process(); - - consola_hw.StartInfo.FileName = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - consola_hw.StartInfo.Arguments = " -hwaccels"; - consola_hw.StartInfo.RedirectStandardOutput = true; - consola_hw.StartInfo.RedirectStandardError = true; - consola_hw.StartInfo.UseShellExecute = false; - consola_hw.StartInfo.CreateNoWindow = true; - consola_hw.EnableRaisingEvents = true; - - String duracion = String.Empty; - String std_out = String.Empty; - consola_hw.Start(); - Boolean hw_found = false; - - while (!consola_hw.StandardOutput.EndOfStream) - { - std_out = consola_hw.StandardOutput.ReadLine(); - - if (std_out.Contains("Hardware acceleration methods:")) - { - if (selected != "auto") cb_hwdecode.Items.Add("auto"); - hw_found = true; - decoders.Add("auto"); - continue; - } - - if (hw_found == true && std_out != String.Empty && std_out != selected) - { - cb_hwdecode.Items.Add(std_out); - decoders.Add(std_out); - } - } - consola_hw.WaitForExit(); - consola_hw.Close(); - File.WriteAllLines(f_hw_dcd, decoders); - cb_hwdecode.DroppedDown = true; - } - } - - private void btn_save_preset_Click(object sender, EventArgs e) - { - save_preset(); - combo_presets.SelectedIndex = combo_presets.Items.Count - 1; - MessageBox.Show(Strings.pres_saved, Strings.saved, MessageBoxButtons.OK, MessageBoxIcon.Information); - btn_load_config.PerformClick(); - combo_presets.SelectedIndex = combo_presets.Items.Count - 1; - } - - private void save_preset() - { - if (txt_parameters.Text.Length < 6) - { - MessageBox.Show(Strings.params_short, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (combo_presets.Text == Strings.default_param) - { - btn_save_config.PerformClick(); - return; - } - if (combo_presets.Text.Length == 0) - { - MessageBox.Show(Strings.pres_empt); - return; - } - if (combo_presets.Text == Strings.default_param) - { - return; - } - - String path_d_pr = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_presets.ini"; - String path2_d_pr = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_presets2.txt"; - String path_d_pr_pre = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_presets_pre.ini"; - if (is_portable == true) - { - path_d_pr = port_path + "ff_presets_portable.ini"; - path_d_pr_pre = port_path + "ff_presets_pre_portable.ini"; - path2_d_pr = port_path + "ff_presets2.txt"; - } - - if (is_portable == false) - { - File.Create(Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_presets2.txt").Dispose(); - } - else - { - File.Create(port_path + "ff_presets2.txt").Dispose(); - } - - int ind = 0; - foreach (string line in File.ReadLines(path_d_pr)) - { - ind = ind + 1; - String linea_sin = String.Empty; - - if (!line.Contains("PR: ")) - { - linea_sin = line + Environment.NewLine; - File.AppendAllText(path2_d_pr, linea_sin); - } - - if (line.LastIndexOf(" & ") >= 0) - { - - if (line.Substring(4, line.LastIndexOf(" & ") - 4) != combo_presets.Text) - { - if (ind <= File.ReadLines(path_d_pr).Count() - 1) - { - linea_sin = line + Environment.NewLine; - File.AppendAllText(path2_d_pr, linea_sin); - } - else - { - File.AppendAllText(path2_d_pr, line); - } - } - } - } - - File.Delete(path_d_pr); - File.Copy(path2_d_pr, path_d_pr); - File.Delete(path2_d_pr); - System.Threading.Thread.Sleep(50); - btn_save_preset.Enabled = false; - - String path_pr = ""; - if (is_portable == true) path_pr = port_path + "ff_presets_portable.ini"; - else path_pr = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_presets.ini"; - - String parameters = Regex.Replace(txt_parameters.Text, @"^\s+$[\r\n]*", string.Empty, RegexOptions.Multiline); - String createText = "PR: " + combo_presets.Text + " & " + parameters + " % " + txt_format.Text; - File.AppendAllText(path_pr, Environment.NewLine + createText); - - String presets_txt = File.ReadAllText(path_pr); - String pres_blanks = Regex.Replace(presets_txt, @"^\s+$[\r\n]*", string.Empty, RegexOptions.Multiline); - File.WriteAllText(path_pr, pres_blanks); - - if (txt_pre_input.Text.Length > 0) - { - File.AppendAllText(path_d_pr_pre, Environment.NewLine + combo_presets.Text + " &&& " + txt_pre_input.Text); - } - else - { - List list_file = new List(); - if (File.Exists(path_d_pr_pre)) - { - foreach (String line in File.ReadLines(path_d_pr_pre)) - { - if (line.Length > 5) - { - if (line.Substring(0, line.LastIndexOf("&&&") - 1) != combo_presets.Text) - { - list_file.Add(line); - } - } - } - } - - File.WriteAllText(path_d_pr_pre, String.Empty); - foreach (String line in list_file) File.AppendText(line); - } - - combo_presets.Items.Clear(); - combo_presets.Items.Add(Strings.default_param); - String path2 = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.ini"; - if (is_portable == true) path2 = port_path + "ff_batch_portable.ini"; - int linea = 0; - - foreach (string line in File.ReadLines(path2)) - { - linea = linea + 1; - if (linea == 1) - { - txt_parameters.Text = line; - continue; - } - - if (linea == 2) - { - txt_format.Text = line; - continue; - } - - if (line == "Yes") - - { - chk_open_compl.CheckState = CheckState.Checked; - continue; - } - - if (line == "No") - { - chk_open_compl.CheckState = CheckState.Unchecked; - continue; - } - - if (line == "Vn") - { - chk_suffix.CheckState = CheckState.Unchecked; - continue; - } - if (line.Length > 1 && line.Substring(0, 2) == "Vs") - { - chk_suffix.CheckState = CheckState.Checked; - txt_suffix.Text = line.Substring(3, line.Length - 3); - continue; - } - //} - - if (line == "grid_yes") - { - listView1.GridLines = true; - listView2.GridLines = true; - listView3.GridLines = true; - continue; - } - if (line == "grid_no") - { - listView1.GridLines = false; - listView2.GridLines = false; - listView3.GridLines = false; - continue; - } - - if (line == "keep_yes") - { - chk_recreate.CheckState = CheckState.Checked ; - continue; - } - if (line == "keep_no") - { - chk_recreate.CheckState = CheckState.Unchecked; - continue; - } - - if (line == "subf_yes") - { - chk_subfolders.CheckState = CheckState.Checked; - add_subfs = true; - continue; - } - if (line == "subf_no") - { - chk_subfolders.CheckState = CheckState.Unchecked; - add_subfs = false; - continue; - } - } - - - if (File.Exists(path_pr) == true) - { - foreach (string line in File.ReadLines(path_pr)) - { - if (line.Length > 8) - { - if (line.Substring(0, 7).ToLower() == "version") - { - txt_config_ver.Text = line.Substring(8, line.Length - 8); - continue; - } - } - - if (line.Length > 4 && line.Substring(0, 4) == "PR: ") - { - combo_presets.Items.Add(line.Substring(4, line.LastIndexOf(" & ") - 4)); - } - } - } - } - - private void txt_format_TextChanged(object sender, EventArgs e) - { - btn_save_preset.Enabled = true; - if (just_started5 == true) btn_save_preset.Enabled = false; - just_started5 = false; - } - - private void combo_presets_TextChanged(object sender, EventArgs e) - { - btn_save_preset.Enabled = true; - if (combo_presets.Text == Strings.new_preset) - { - btn_save_config.ImageKey = "save_pending.png"; - } - } - - private void cti4_2_Click(object sender, EventArgs e) - { - listView1.GridLines = !listView1.GridLines; - listView2.GridLines = !listView2.GridLines; - listView3.GridLines = !listView3.GridLines; - - Boolean prev_state = false; - if (listView1.GridLines == true) prev_state = false; - if (listView1.GridLines == false) prev_state = true; - - String path = String.Empty; - if (is_portable == false) - { - path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.ini"; - } - else - { - path = port_path + "ff_batch_portable.ini"; - } - - int linea = 0; - - foreach (string line in File.ReadLines(path)) - { - linea = linea + 1; - - if (linea == 5) - { - if (line == "grid_yes") - { - if (prev_state == false) - { - btn_save_config.ImageKey = "Save_settings_39.png"; - toolTip_settings.SetToolTip(this.btn_save_config, Strings.params_def); - } - else - { - btn_save_config.ImageKey = "save_pending.png"; - toolTip_settings.SetToolTip(this.btn_save_config, Strings.setting_mod); - } - } - - if (line == "grid_no") - { - if (prev_state == true) - { - btn_save_config.ImageKey = "Save_settings_39.png"; - toolTip_settings.SetToolTip(this.btn_save_config, Strings.params_def); - } - else - { - btn_save_config.ImageKey = "save_pending.png"; - toolTip_settings.SetToolTip(this.btn_save_config, Strings.setting_mod); - } - } - } - } - } - - private void check_concat_CheckedChanged(object sender, EventArgs e) - { - String f_concat = String.Empty; - if (is_portable == false) - { - f_concat = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_concat.ini"; - } - else - { - f_concat = port_path + "ff_concat_portable.ini"; - } - - if (check_concat.Checked == false) - { - if (File.Exists(f_concat)) - { - try - { - File.Delete(f_concat); - } - catch - { - MessageBox.Show(Strings.err_set, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - else - { - if (!File.Exists(f_concat)) - { - try - { - File.WriteAllText(f_concat, String.Empty); - } - catch - { - MessageBox.Show(Strings.err_set, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - } - - private void chk_auto_updates_CheckedChanged(object sender, EventArgs e) - { - String f_updates = String.Empty; - if (is_portable == false) - { - f_updates = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_updates.ini"; - } - else - { - f_updates = port_path + "ff_updates_portable.ini"; - } - - if (chk_auto_updates.CheckState == CheckState.Checked) - { - if (File.Exists(f_updates)) - { - try - { - File.Delete(f_updates); - } - catch - { - MessageBox.Show(Strings.err_set, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - else - { - if (!File.Exists(f_updates)) - { - try - { - File.WriteAllText(f_updates, String.Empty); - } - catch - { - MessageBox.Show(Strings.err_set, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - } - - private void main_f_1_Click(object sender, EventArgs e) - { - btn_clear_list.PerformClick(); - } - - private void main_f_2_Click(object sender, EventArgs e) - { - btn_add_files.PerformClick(); - } - - private void main_f_3_Click(object sender, EventArgs e) - { - btn_add_folders.PerformClick(); - } - - private void menu_reload_settings_Click(object sender, EventArgs e) - { - btn_load_config.PerformClick(); - } - - private void menu_save_settings_Click(object sender, EventArgs e) - { - btn_save_config.PerformClick(); - } - - private void tryCurrentPresetToolStripMenuItem_Click(object sender, EventArgs e) - { - btn_try_pr.PerformClick(); - } - - private void openFfmpegConsoleToolStripMenuItem_Click(object sender, EventArgs e) - { - btn_show_console.PerformClick(); - } - - private void quickGuideToolStripMenuItem_Click(object sender, EventArgs e) - { - btn_help.PerformClick(); - } - - private void helpForumToolStripMenuItem_Click(object sender, EventArgs e) - { - Process.Start("https://forum.videohelp.com/threads/386028-FFmpeg-Batch-for-Windows"); - } - - private void checkForUpdateToolStripMenuItem_Click(object sender, EventArgs e) - { - btn_update.PerformClick(); - } - - private int get_ss_to(String lapse, Double dur) - { - int tstd = 0; - int tsendd = 0; - int test = 0; - int final = 0; - TimeSpan test_sp = new TimeSpan(); - - while (lapse.Contains("%fdur")) - { - if (lapse.Contains("%fdur")) - { - String to_replace0 = ""; - - int operador = lapse.LastIndexOf("%fdur") + 5; - int length = 0; - int limit = lapse.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(lapse.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace0 = lapse.Substring(lapse.LastIndexOf("%fdur"), 5 + length); - Double result = Convert.ToDouble(new DataTable().Compute(to_replace0.Replace("%fdur", dur.ToString()), null)); - lapse = ReplaceLastOccurrence(lapse, to_replace0, Math.Round(result).ToString()); - } - } - - List list_par = new List(); - - try - { - if (lapse.ToLower().Contains("-ss") && lapse.ToLower().Contains("-to")) - { - String ss = ""; - String to = ""; - Regex regex = new Regex(@"\s"); - - String[] param = regex.Split(lapse.ToLower()); - list_par.Clear(); - - foreach (String str in param) - { - if (str.Contains(" ") == false && str.Length > 0) - { - list_par.Add(str); - } - } - - for (int i = 0; i < list_par.Count - 1; i++) - { - - if (list_par[i] == "-ss") - { - if (!list_par[i + 1].Contains(":")) - { - while (Int32.TryParse(list_par[i + 1], out test) == false) - { - i++; - } - ss = list_par[i + 1]; - } - else - { - while (TimeSpan.TryParse(list_par[i + 1], out test_sp) == false) - { - i++; - } - ss = TimeSpan.Parse(list_par[i + 1]).TotalSeconds.ToString(); - } - } - } - - for (int i = 0; i < list_par.Count - 1; i++) - { - if (list_par[i].Trim(' ') == "-to") - { - if (!list_par[i + 1].Contains(":")) - { - while (Int32.TryParse(list_par[i + 1], out test) == false) - { - i++; - } - to = list_par[i + 1]; - } - else - { - while (TimeSpan.TryParse(list_par[i + 1], out test_sp) == false) - { - i++; - } - to = TimeSpan.Parse(list_par[i + 1]).TotalSeconds.ToString(); - } - } - } - - if (Int32.TryParse(ss, out test)) tstd = Convert.ToInt32(ss); - if (Int32.TryParse(to, out test)) tsendd = Convert.ToInt32(to); - - final = tsendd - tstd; - } - - if (lapse.ToLower().Contains("-ss") && !lapse.ToLower().Contains("-to")) - { - String ss = ""; - Regex regex = new Regex(@"\s"); - String[] param = regex.Split(lapse.ToLower()); - list_par.Clear(); - - foreach (String str in param) - { - if (str.Contains(" ") == false && str.Length > 0) - { - list_par.Add(str); - } - } - - for (int i = 0; i < list_par.Count - 1; i++) - { - if (list_par[i].Contains(" ")) continue; - if (list_par[i] == "-ss") - { - if (!list_par[i + 1].Contains(":")) - { - while (Int32.TryParse(list_par[i + 1], out test) == false) - { - i++; - } - ss = list_par[i + 1]; - } - else - { - while (TimeSpan.TryParse(list_par[i + 1], out test_sp) == false) - { - i++; - } - ss = TimeSpan.Parse(list_par[i + 1]).TotalSeconds.ToString(); - } - } - } - - if (Int32.TryParse(ss, out test)) - { - final = (int)dur - Convert.ToInt32(ss); - } - else final = (int)dur; - - } - if (!lapse.ToLower().Contains("-ss") && lapse.ToLower().Contains("-to")) - { - String to = ""; - - Regex regex = new Regex(@"\s"); - String[] param = regex.Split(lapse.ToLower()); - list_par.Clear(); - - foreach (String str in param) - { - if (str.Contains(" ") == false && str.Length > 0) - { - list_par.Add(str); - } - } - - for (int i = 0; i < list_par.Count - 1; i++) - { - if (list_par[i].Contains(" ")) continue; - - if (list_par[i] == "-to") - { - if (!list_par[i + 1].Contains(":")) - { - while (Int32.TryParse(list_par[i + 1], out test) == false) - { - i++; - } - to = param[i + 1]; - } - else - { - while (TimeSpan.TryParse(list_par[i + 1], out test_sp) == false) - { - i++; - } - to = TimeSpan.Parse(list_par[i + 1]).TotalSeconds.ToString(); - } - } - } - - if (Int32.TryParse(to, out test)) - { - final = Convert.ToInt32(to); - } - else final = (int)dur; - - } - - if (lapse.ToLower().Contains("-t") && !lapse.ToLower().Contains("-to")) - { - String to = ""; - - Regex regex = new Regex(@"\s"); - String[] param = regex.Split(lapse.ToLower()); - list_par.Clear(); - - foreach (String str in param) - { - if (str.Contains(" ") == false && str.Length > 0) - { - list_par.Add(str); - } - } - - for (int i = 0; i < list_par.Count - 1; i++) - { - if (list_par[i].Contains(" ")) continue; - - if (list_par[i] == "-t") - { - if (!list_par[i + 1].Contains(":")) - { - while (Int32.TryParse(list_par[i + 1], out test) == false) - { - i++; - } - to = param[i + 1]; - } - else - { - while (TimeSpan.TryParse(list_par[i + 1], out test_sp) == false) - { - i++; - } - to = TimeSpan.Parse(list_par[i + 1]).TotalSeconds.ToString(); - } - } - } - - if (Int32.TryParse(to, out test)) - { - final = Convert.ToInt32(to); - } - else final = (int)dur; - } - if (final <= 0) return (int)dur; - else return final; - - } - catch { return (int)dur; } - } - - private void menu_about_Click(object sender, EventArgs e) - { - Form2 form2 = new Form2(); - form2.StartPosition = FormStartPosition.CenterParent; - form2.ShowDialog(); - } - - private void menu_settings_Click(object sender, EventArgs e) - { - pr_default.Text = txt_parameters.Text; - form3.StartPosition = FormStartPosition.CenterParent; - form3.lbl_ff_ver.Text = btn_change_ff.Text.Replace("FFmpeg version", Strings.version); - form3.ff_ver = latest_ff; - String current_lang = Settings.Default.app_lang; - if (language == "en") form3.combo_lang.SelectedIndex = 0; - if (language == "es") form3.combo_lang.SelectedIndex = 1; - if (language == "it") form3.combo_lang.SelectedIndex = 2; - if (language == "pt-BR") form3.combo_lang.SelectedIndex = 3; - if (language == "zh-Hans") form3.combo_lang.SelectedIndex = 4; - if (language == "ar-EG") form3.combo_lang.SelectedIndex = 5; - - if (chk_open_compl.Checked) form3.check_open_output.Checked = true; - else form3.check_open_output.Checked = false; - - Boolean current_dark = Settings.Default.dark_mode; - - timer_watch.Enabled = false; - form3.main_out_path = txt_path_main.Text; - form3.ff_ena.Clear(); - foreach (String st in ff_ena) - { - form3.ff_ena.Add(st); - } - - form3.ShowDialog(); - if (form3.chk_monitor.Checked == true) timer_watch.Enabled = true; - if (form3.cancel == true) - { - Settings.Default.app_lang = current_lang; - Settings.Default.dark_mode = current_dark; - Settings.Default.Save(); - return; - } - if (form3.change_ff_ver == true) - { - btn_change_ff.PerformClick(); - return; - } - - if (Settings.Default.dark_mode != current_dark) - { - btn_clear_list.PerformClick(); //Refresh issues - btn_refresh.PerformClick(); - } - - if (Settings.Default.dark_mode == true) - { - foreach (Control c in this.Controls) UpdateColorDark(c); - this.BackColor = Color.FromArgb(255, 64, 64, 64); - post_dark(); - - } - else - { - foreach (Control c in this.Controls) UpdateColorDefault(c); - this.BackColor = SystemColors.InactiveBorder; - post_color_def(); - } - - if (form3.chk_dark.Checked) - { - Settings.Default.auto_dark = true; - Settings.Default.dark_sunset = form3.n_sunset.Value; - Settings.Default.dark_sunrise = form3.n_sunrise.Value; - if (form3.chk_dark_win.Checked) Settings.Default.dark_os = true; - - } - else Settings.Default.auto_dark = false; - Settings.Default.Save(); - - if (current_lang != form3.lang_set) - { - if (form3.combo_lang.SelectedIndex == 0) language = "en"; - if (form3.combo_lang.SelectedIndex == 1) language = "es"; - if (form3.combo_lang.SelectedIndex == 2) language = "it"; - if (form3.combo_lang.SelectedIndex == 3) language = "pt-BR"; - if (form3.combo_lang.SelectedIndex == 4) language = "zh-Hans"; - if (form3.combo_lang.SelectedIndex == 5) language = "ar-EG"; - - String f_lang = String.Empty; - if (is_portable == false) - { - f_lang = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_lang.ini"; - } - else - { - f_lang = port_path + "ff_lang_portable.ini"; - } - - if (File.Exists(f_lang)) - { - File.WriteAllText(f_lang, language); - - Settings.Default.app_lang = language; - Settings.Default.Save(); - init_lang(); - post_lang(); - if (tabControl1.SelectedIndex != 0) tabControl1.SelectedIndex = 0; - btn_update.Text = Strings.version + " " + Application.ProductVersion; - } - - Create_Tooltips(); - load_priority(); - } - - if (form3.edit_presets == true) - { - Form15 frm_pr = new Form15(); - frm_pr.ShowDialog(); - if (frm_pr.saved == true) btn_load_config.PerformClick(); - return; - } - - if (form3.chk_battery.Checked) - { - Settings.Default.pause_bat = true; - timer_battery.Start(); - - if (form3.chk_bat_level.Checked) - { - Settings.Default.if_bat_low = true; - Settings.Default.bat_level = form3.n_bat_l.Value; - } - else - { - Settings.Default.if_bat_low = false; - } - } - else - { - Settings.Default.pause_bat = false; - Settings.Default.if_bat_low = false; - pic_batt.Visible = false; - } - - if (form3.chk_monitor.Checked) - { - if (txt_path_main.Text.Contains(".\\") && form3.chk_monitor.Checked == true && form3.chk_w_subs.Checked == true) - { - MessageBox.Show(Strings.mon_no_rel, Strings.warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); - if (form3.chk_monitor.Checked == true) pic_mon.Visible = true; - else pic_mon.Visible = false; - } - else - { - pic_mon.Visible = true; - Settings.Default.mon_fd_subs = form3.chk_w_subs.Checked; - Settings.Default.monitor_fd = true; - Settings.Default.fd_monitored = form3.txt_monitor.Text; - Settings.Default.mon_int = form3.n_monitor.Value; - toolTipMon.RemoveAll(); - toolTipMon.SetToolTip(this.pic_mon, Strings.mon_ing + " " + Settings.Default.fd_monitored); - timer_watch.Enabled = true; - timer_watch.Interval = (int)form3.n_monitor.Value * 1000; - - System.IO.SearchOption sh = new System.IO.SearchOption(); - if (Settings.Default.mon_fd_subs == true) sh = System.IO.SearchOption.AllDirectories; - else sh = System.IO.SearchOption.TopDirectoryOnly; - - string[] file_drop2 = (string[])Directory.GetFiles(Settings.Default.fd_monitored, "*.*", sh); - drop_files(file_drop2); - timer_watch.Enabled = true; - } - } - else - { - pic_mon.Visible = false; - Settings.Default.monitor_fd = false; - timer_watch.Enabled = false; - } - - if (form3.chk_no_overw.Checked == true) Settings.Default.no_dest_overw = true; - else Settings.Default.no_dest_overw = false; - if (form3.chk_filter_zero.Checked == true) Settings.Default.filter_zero = true; - else Settings.Default.filter_zero = false; - - if (form3.totray == false) Settings.Default.to_tray = false; - else Settings.Default.to_tray = true; - - if (form3.chk_ctrl_p.Checked == true) Settings.Default.no_ctrl_p = true; - else Settings.Default.no_ctrl_p = false; - - if (form3.chk_thumb_big.Checked == true) Settings.Default.large_th = true; - else Settings.Default.large_th = false; - - if (form3.chk_quick_q.Checked == true) - { - Settings.Default.quick_queue = true; - clean_cols(); - } - else - { - Settings.Default.quick_queue = false; - foreach (ListViewItem item in listView1.Items) - if (item.SubItems[3].Text == "-") item.SubItems[3].Text = Strings.pending; - } - if (form3.no_dest_overwrite == true) Settings.Default.no_dest_overw = true; - else Settings.Default.no_dest_overw = false; - - Settings.Default.Save(); - - if (form3.presets_online == true) - { - Form27 frm27 = new Form27(); - frm27.StartPosition = FormStartPosition.CenterParent; - frm27.ShowDialog(); - if (frm27.desc_pr.Length > 0) - { - combo_presets.SelectedIndex = combo_presets.Items.Count - 1; - combo_presets.Text = frm27.desc_pr; - txt_pre_input.Text = frm27.pre_in_pr; - txt_parameters.Text = frm27.params_pr; - txt_format.Text = frm27.format_pr; - } - return; - } - - - if (form3.reset_asked == true) - { - menu_reset.PerformClick(); - return; - } - if (form3.cancel == true) - { - if (form3.reload_config == true) btn_load_config.PerformClick(); - return; - } - - - if (form3.recreate == true) chk_recreate.CheckState = CheckState.Checked; - else chk_recreate.CheckState = CheckState.Unchecked; - - if (form3.check_open_c == true) chk_open_compl.CheckState = CheckState.Checked; - else chk_open_compl.CheckState = CheckState.Unchecked; - - if (form3.suffix == true) - { - chk_suffix.CheckState = CheckState.Checked; - txt_suffix.Enabled = true; - txt_suffix.Text = form3.txt_suffix_str; - } - else - { - chk_suffix.CheckState = CheckState.Unchecked; - txt_suffix.Text = "_FFB"; - txt_suffix.Enabled = false; - } - - if (form3.subfolders == true) chk_subfolders.CheckState = CheckState.Checked; - else chk_subfolders.CheckState = CheckState.Unchecked; - - if (form3.try_preset == true) chk_try.CheckState = CheckState.Checked; - else chk_try.CheckState = CheckState.Unchecked; - - if (form3.updates == true) chk_auto_updates.CheckState = CheckState.Checked; - else chk_auto_updates.CheckState = CheckState.Unchecked; - - if (form3.concat_filter == true) check_concat.CheckState = CheckState.Checked; - else check_concat.CheckState = CheckState.Unchecked; - - - String f_autorun = String.Empty; - String f_multi = String.Empty; - if (is_portable == false) - { - f_autorun = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_autorun.ini"; - f_multi = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_autorun_m.ini"; - } - else - { - f_autorun = port_path + "ff_autorun_portable.ini"; - f_multi = port_path + "ff_autorun_m_portable.ini"; - } - if (form3.autorun == true) - { - start_seq = true; - chk_autor.ImageIndex = 1; - File.WriteAllText(f_autorun, ""); - if (form3.automulti == true) - { - start_multi = true; - File.WriteAllText(f_multi, ""); - } - else - { - try - { - start_multi = false; - File.Delete(f_multi); - } - catch - { - MessageBox.Show(Strings.err_set, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - else - { - start_seq = false; - start_multi = false; - - try - { - File.Delete(f_autorun); - File.Delete(f_multi); - } - catch - { - MessageBox.Show(Strings.err_set, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - //End autorun - - String f_sleep = String.Empty; - if (is_portable == false) - { - f_sleep = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_sleep.ini"; - } - else - { - f_sleep = port_path + "ff_sleep_portable.ini"; - } - if (form3.to_sleep == true) - { - File.WriteAllText(f_sleep, ""); - Timer_idle.Enabled = true; - - } - else - { - Timer_idle.Enabled = false; - try - { - File.Delete(f_sleep); - } - catch { } - } - - txt_parameters.Text = form3.txt_preset_str; - txt_format.Text = form3.txt_format_str; - - btn_save_config.PerformClick(); - - // Sort Multi - - String f_sort_dur = String.Empty; - if (is_portable == false) - { - f_sort_dur = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_sort_dur.ini"; - } - else - { - f_sort_dur = port_path + "ff_sort_dur_portable.ini"; - } - try - { - if (form3.sort_multi == true) - File.WriteAllText(f_sort_dur, ""); - else File.Delete(f_sort_dur); - } - catch - { - MessageBox.Show(Strings.un_err_set, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - - // End sort multi - - // Send to console - - String f_params_console = String.Empty; - if (is_portable == false) - { - f_params_console = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_par_con.ini"; - } - else - { - f_params_console = port_path + "ff_par_con_portable.ini"; - } - try - { - if (form3.send_params_console == false) - { - send_par_consol = false; - File.WriteAllText(f_params_console, String.Empty); - } - else - { - send_par_consol = true; - if (File.Exists(f_params_console)) File.Delete(f_params_console); - } - } - catch - { - MessageBox.Show(Strings.un_err_set, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - // End send params console - - //Warn successful items - - String f_warn_suc = String.Empty; - if (is_portable == false) - { - f_warn_suc = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_warn_suc.ini"; - } - else - { - f_warn_suc = port_path + "ff_warn_suc_portable.ini"; - } - try - { - if (form3.warn_successful == false) - { - warn_success_items = false; - File.WriteAllText(f_warn_suc, String.Empty); - } - else - { - warn_success_items = true; - if (File.Exists(f_warn_suc)) File.Delete(f_warn_suc); - } - } - catch - { - MessageBox.Show(Strings.un_err_set, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - //End warn successful items - - //Ignore encoded files - - String f_ignore_enc = String.Empty; - if (is_portable == false) - { - f_ignore_enc = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_ignore_enc.ini"; - } - else - { - f_ignore_enc = port_path + "ff_ignore_enc_portable.ini"; - } - try - { - if (form3.ignore_encoded == false) - { - ignore_encoded = false; - if (File.Exists(f_ignore_enc)) File.Delete(f_ignore_enc); - - } - else - { - ignore_encoded = true; - File.WriteAllText(f_ignore_enc, String.Empty); - } - } - catch - { - MessageBox.Show(Strings.un_err_set, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - //End ignore encoded files - - - //Warn 0 - - String f_warn_0 = String.Empty; - if (is_portable == false) - { - f_warn_0 = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_warn_0.ini"; - } - else - { - f_warn_0 = port_path + "ff_warn_0_portable.ini"; - } - try - { - if (form3.no_warn_0 == true) - { - no_warn_0_dur = true; - File.WriteAllText(f_warn_0, String.Empty); - } - else - { - no_warn_0_dur = false; - if (File.Exists(f_warn_0)) File.Delete(f_warn_0); - } - } - catch - { - MessageBox.Show(Strings.un_err_set, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - //End warn 0 - - //Do not save logs - - String f_nologs = String.Empty; - if (is_portable == false) - { - f_nologs = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_nologs.ini"; - } - else - { - f_nologs = port_path + "ff_nologs_portable.ini"; - } - try - { - if (form3.not_save_logs == false) - { - no_save_logs = false; - if (File.Exists(f_nologs)) File.Delete(f_nologs); - } - else - { - no_save_logs = true; - File.WriteAllText(f_nologs, String.Empty); - String path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.log"; - if (is_portable == true) path = port_path + "ff_batch_portable.log"; - - if (File.Exists(path)) - { - DialogResult a = MessageBox.Show(Strings.del_last, Strings.del_file, MessageBoxButtons.YesNo, MessageBoxIcon.Question); - if (a == DialogResult.Yes) - { - try - { - File.Delete(path); - } - catch (Exception excpt) - { - MessageBox.Show(Strings.err_del_log + Environment.NewLine + Environment.NewLine + excpt.Message, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - } - } - catch - { - MessageBox.Show(Strings.un_err_set, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - - //End do not save logs - - //Verbose logs - - String f_verbose = String.Empty; - if (is_portable == false) - { - f_verbose = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_verbose.ini"; - } - else - { - f_verbose = port_path + "ff_verbose_portable.ini"; - } - try - { - if (form3.verbose_logs == false) - { - verbose_logs = false; - if (File.Exists(f_verbose)) File.Delete(f_verbose); - } - else - { - verbose_logs = true; - File.WriteAllText(f_verbose, String.Empty); - } - } - catch - { - MessageBox.Show(Strings.un_err_set, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - - //End verbose logs - - //Full report - - String f_report = String.Empty; - if (is_portable == false) - { - f_report = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_report.ini"; - } - else - { - f_report = port_path + "ff_report_portable.ini"; - } - try - { - if (form3.full_report == false) - { - full_report = false; - if (File.Exists(f_report)) File.Delete(f_report); - } - else - { - full_report = true; - File.WriteAllText(f_report, String.Empty); - } - } - catch - { - MessageBox.Show(Strings.un_err_set, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - - //End full report - - //Do not cache network files - - String f_no_cache = String.Empty; - if (is_portable == false) - { - f_no_cache = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_nocache.ini"; - } - else - { - f_no_cache = port_path + "ff_nocache_portable.ini"; - } - try - { - if (form3.not_save_cache == false) - { - no_save_cache = false; - if (File.Exists(f_no_cache)) File.Delete(f_no_cache); - } - else - { - no_save_cache = true; - File.WriteAllText(f_no_cache, String.Empty); - } - } - catch - { - MessageBox.Show(Strings.un_err_set, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - //End do not cache network files - - //use OS cache dialog - - String f_os_cache = String.Empty; - if (is_portable == false) - { - f_os_cache = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_oscache.ini"; - } - else - { - f_os_cache = port_path + "ff_oscache_portable.ini"; - } - try - { - if (form3.use_cache_os == false) - { - os_save_cache = false; - if (File.Exists(f_os_cache)) File.Delete(f_os_cache); - } - else - { - os_save_cache = true; - File.WriteAllText(f_os_cache, String.Empty); - } - } - catch - { - MessageBox.Show(Strings.un_err_set, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - //End use OS cache dialog - - //Remember tab - - String f_remember = String.Empty; - if (is_portable == false) - { - f_remember = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_remember.ini"; - } - else - { - f_remember = port_path + "ff_remember_portable.ini"; - } - - if (form3.chk_remember_tab.Checked == false) - { - remember_last_tab = false; - if (File.Exists(f_remember)) - { - try - { - File.Delete(f_remember); - } - catch { } - } - } - else - { - remember_last_tab = true; - File.WriteAllText(f_remember, tabControl1.SelectedIndex.ToString()); - } - - //End remember tab - - //Save play sound - - String ff_play_sound = String.Empty; - if (is_portable == false) - { - ff_play_sound = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_play.ini"; - } - else - { - ff_play_sound = port_path + "ff_play_portable.ini"; - } - - if (form3.play_file.Length != 0) - { - try - { - File.WriteAllText(ff_play_sound, form3.play_file); - play_on_end = true; - play_file_path = form3.play_file; - } - catch (Exception excpt) - { - MessageBox.Show(Strings.err_set + Environment.NewLine + Environment.NewLine + excpt.Message, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - play_on_end = false; - } - } - else - { - play_on_end = false; - if (File.Exists(ff_play_sound)) - { - try - { - File.Delete(ff_play_sound); - } - catch { } - } - } - //End save play sound - - //Remember window and size - - String f_remember_w = String.Empty; - if (is_portable == false) - { - f_remember_w = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_remember_w.ini"; - } - else - { - f_remember_w = port_path + "ff_remember_w_portable.ini"; - } - try - { - if (form3.remember_w == false) - { - remember_w = false; - if (File.Exists(f_remember_w)) File.Delete(f_remember_w); - } - else - { - remember_w = true; - Rectangle rect = Screen.PrimaryScreen.Bounds; - File.WriteAllText(f_remember_w, rect.Width + Environment.NewLine + rect.Height); - if (this.WindowState == FormWindowState.Maximized) - Settings.Default.w_max = true; - else Settings.Default.w_max = false; - Settings.Default.Save(); - } - } - catch - { - MessageBox.Show(Strings.un_err_set, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - //End remember window - - //Delete full - - String f_delete_full = String.Empty; - if (is_portable == false) - { - f_delete_full = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_delete_full.ini"; - } - else - { - f_delete_full = port_path + "ff_delete_full_portable.ini"; - } - try - { - if (form3.delete_def == false) - { - delete_def = false; - if (File.Exists(f_delete_full)) File.Delete(f_delete_full); - } - else - { - delete_def = true; - File.WriteAllText(f_delete_full, ""); - } - } - catch - { - } - //End delete full - - //Delete one - - String f_delete_one = String.Empty; - if (is_portable == false) - { - f_delete_one = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_delete_one.ini"; - } - else - { - f_delete_one = port_path + "ff_delete_one_portable.ini"; - } - try - { - if (form3.delete_one == false) - { - delete_one = false; - if (File.Exists(f_delete_one)) File.Delete(f_delete_one); - } - else - { - delete_one = true; - File.WriteAllText(f_delete_one, ""); - } - } - catch - { - } - //End delete one - - //Keep Dates - - String f_dates = String.Empty; - if (is_portable == false) - { - f_dates = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_dates.ini"; - } - else - { - f_dates = port_path + "ff_dates_portable.ini"; - } - try - { - - if (form3.keep_dates == true) - { - keep_dates = true; - File.WriteAllText(f_dates, ""); - } - else - { - keep_dates = false; - File.Delete(f_dates); - } - } - catch (Exception exc) { MessageBox.Show(Strings.err_set + Environment.NewLine + Environment.NewLine + exc.Message, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); } - } - - private void menu_reset_Click(object sender, EventArgs e) - { - DialogResult a = MessageBox.Show(Strings.reset_default, Strings.conf_act, MessageBoxButtons.YesNo, MessageBoxIcon.Warning); - if (a == DialogResult.No) - { - return; - } - - Settings.Default.wLocation = new System.Drawing.Point(0, 0); - Settings.Default.Save(); - - String path = String.Empty; - String path2 = String.Empty; - String path_pr = String.Empty; - String path_pr_pre = String.Empty; - if (is_portable == false) - { - path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.ini"; - path_pr = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_presets.ini"; - path_pr_pre = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_presets_pre.ini"; - path2 = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_hw_dcd"; - } - else - { - path = port_path + "ff_batch_portable.ini"; - path_pr = port_path + "ff_presets_portable.ini"; - path_pr_pre = port_path + "ff_presets_pre_portable.ini"; - path2 = port_path + "ff_hw_dcd_portable"; - } - - if (!Directory.Exists(Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch"))) - { - Directory.CreateDirectory(Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch")); - } - - if (File.Exists(path)) - { - File.Delete(path); - } - if (File.Exists(path2)) - { - File.Delete(path2); - } - - if (File.Exists(path_pr_pre)) - { - try { File.Delete(path_pr_pre); } catch { } - } - - combo_prio.SelectedIndex = 2; - btn_save_prio.PerformClick(); - - clean_cols(); - list_cols(); - - String f_md5 = String.Empty; - if (is_portable == false) { f_md5 = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_md5.ini"; } - else { f_md5 = port_path + "ff_md5_portable.ini"; } - - if (File.Exists(f_md5)) - { - try - { - File.Delete(f_md5); - } - catch { } - } - - String no_out_pop = String.Empty; - if (is_portable == false) - { - no_out_pop = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_first.ini"; - } - else - { - no_out_pop = port_path + "ff_first_portable.ini"; - } - if (File.Exists(no_out_pop)) - { - try - { - File.Delete(no_out_pop); - } - catch { } - } - - String f_skip_ver = String.Empty; - if (is_portable == false) - { - f_skip_ver = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_skip_ver.ini"; - } - else - { - f_skip_ver = port_path + "ff_skip_ver_portable.ini"; - } - - if (File.Exists(f_skip_ver)) - { - try - { - File.Delete(f_skip_ver); - } - catch { } - } - - //Sleep off - - String f_sleep = String.Empty; - if (is_portable == false) - { - f_sleep = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_sleep.ini"; - } - else - { - f_sleep = port_path + "ff_sleep_portable.ini"; - } - - if (!File.Exists(f_sleep)) - { - try - { - prevent_sleep = false; - Timer_idle.Enabled = false; - File.Delete(f_sleep); - } - catch - { - } - } - else - { - prevent_sleep = true; - Timer_idle.Enabled = true; - } - - //End sleep off - - //Disable try preset - - String f_try = String.Empty; - if (is_portable == false) - { - f_try = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_try.ini"; - } - else - { - f_try = port_path + "ff_try_portable.ini"; - } - - if (File.Exists(f_try)) - { - try - { - File.Delete(f_try); - chk_try.CheckState = CheckState.Unchecked; - } - catch - { - } - } - - //End Disable preset - - //Concat video filter - - String f_concat = String.Empty; - if (is_portable == false) - { - f_concat = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_concat.ini"; - } - else - { - f_concat = port_path + "ff_concat_portable.ini"; - } - - if (File.Exists(f_concat)) - { - try - { - File.Delete(f_concat); - check_concat.CheckState = CheckState.Unchecked; - } - catch - { - } - } - //End concat video filter - - String save_path_queue = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "saved_queue_temp.ffq"; - if (is_portable == true) save_path_queue = port_path + "saved_queue_temp.ffq"; - String save_path_queue0 = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "saved_queue_temp0.ffq"; - if (is_portable == true) save_path_queue0 = port_path + "saved_queue_temp0.ffq"; - try - { - File.Delete(save_path_queue); - File.Delete(save_path_queue0); - - } - catch { } - - String f_lang = String.Empty; - if (is_portable == false) - { - f_lang = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_lang.ini"; - } - else - { - f_lang = port_path + "ff_lang_portable.ini"; - } - try - { - File.Delete(f_lang); - } - catch { } - - Form24 frm24 = new Form24(); - frm24.ShowDialog(); - if (frm24.combo_lang.SelectedIndex == 0) language = "en"; - if (frm24.combo_lang.SelectedIndex == 1) language = "es"; - if (frm24.combo_lang.SelectedIndex == 2) language = "it"; - if (frm24.combo_lang.SelectedIndex == 3) language = "pt-BR"; - if (frm24.combo_lang.SelectedIndex == 4) language = "zh-Hans"; - if (frm24.combo_lang.SelectedIndex == 5) language = "ar-EG"; - - File.WriteAllText(f_lang, language); - Settings.Default.app_lang = language; - Settings.Default.Save(); - init_lang(); - btn_update.Text = Strings.version + " " + Application.ProductVersion; - - File.WriteAllText(path, "-c copy" + Environment.NewLine + "mp4" + Environment.NewLine + "Yes" - + Environment.NewLine + "Vn" + Environment.NewLine + "grid_yes" + Environment.NewLine + "keep_no" - + Environment.NewLine + "subf_no"); - - File.WriteAllText(path_pr, "Version 1.0" + Environment.NewLine - + "PR: " + Strings.pr01 + " & -c copy % mp4" + Environment.NewLine - + "PR: " + Strings.pr02 + " & -c:v copy -c:a aac -cutoff 20K -b:a 256K -ac 2 % mkv" + Environment.NewLine + "PR: " + Strings.pr03 + " & -c:v copy -c:a ac3 -b:a 256K -ac 2 -c:s copy % mkv" + Environment.NewLine + "PR: " + Strings.pr04 + " & -c:v prores_ks -profile:v standard -vendor:v ap10 -pix_fmt yuv422p10le -c:a pcm_s16le -chunk_size 64K % mkv" + Environment.NewLine + "PR: " + Strings.pr05 + " & -c:v libx264 -crf 20 -c:a copy % mkv" + Environment.NewLine + "PR: " + Strings.pr06 + " & -c:v libx264 -crf 23 -preset ultrafast -c:a copy % mkv" + Environment.NewLine + "PR: " + Strings.pr07 + " & -c:v libx265 -crf 23 -c:a copy % mkv" + Environment.NewLine + "PR: " + Strings.pr08 + " & -c:v libx264 -crf 23 -vf scale=1280:720 -c:a aac -b:a 128K % mp4" + Environment.NewLine + "PR: " + Strings.pr09 + " & -c:v libx264 -crf 21 -vf " + "\u0022" + "transpose=1" + "\u0022" + " -c:a copy % mp4" + Environment.NewLine + "PR: " + Strings.pr10 + " & -c:v libx264 -crf 21 -vf " + "\u0022" + "transpose=0" + "\u0022" + " -c:a copy % mp4" + Environment.NewLine + "PR: " + Strings.pr11 + " & -c:v libx264 -crf 21 -vf " + "\u0022" + "transpose=2" + "\u0022" + " -c:a copy % mp4" + Environment.NewLine + "PR: " + Strings.pr12 + " & -c:v libx264 -crf 21 -vf " + "\u0022" + "transpose=3" + "\u0022" + " -c:a copy % mp4" + Environment.NewLine + "PR: " + Strings.pr13 + " & -c:v libx264 -crf 21 -vf " + "\u0022" + "transpose=2, transpose=2" + "\u0022" + " -c:a copy % mp4" + Environment.NewLine + "PR: " + Strings.pr14 + " & -c copy -sn % mp4" + Environment.NewLine + "PR: " + Strings.pr15 + " & -vn -c:a flac -ar 44100 -sample_fmt s16 -ac 2 % flac" + Environment.NewLine + "PR: " + Strings.pr16 + " & -c:v copy -c:a libmp3lame -qscale:a 0 -ac 2 % mp3" + Environment.NewLine + "PR: " + Strings.pr17 + " & -vn -c:a libmp3lame -qscale:a 1 -ac 2 % mp3" + Environment.NewLine + "PR: " + Strings.pr18 + " & -vn -c:a libmp3lame -b:a 224K -ac 2 % mp3" + Environment.NewLine + "PR: " + Strings.pr19 + " & -vn -c:a pcm_s16le -ar 44100 -sample_fmt s16 -ac 2 % wav" + Environment.NewLine + "PR: " + Strings.pr20 + " & -map 0:2 -c:s copy % srt" + Environment.NewLine + "PR: " + Strings.pr21 + " & -vframes 1 -f image2 % png" + Environment.NewLine + "PR: " + Strings.pr21_2 + " & -c:v h264_amf -rc cqp -qp_p 20 -qp_i 20 -qp_b 20 -c:a copy % mkv" + Environment.NewLine + "PR: " + Strings.pr21_21 + " & -c:v hevc_amf -rc cqp -qp_p 20 -qp_i 20 -qp_b 20 -c:a copy % mkv" + Environment.NewLine + "PR: " + Strings.pr22 + " & -r 24 -c:a aac -b:a 128K % mkv" + Environment.NewLine + "PR: " + Strings.pr23 + " & -r 15 -vf scale=1280x720 -c:a aac -b:a 128K % mkv" + Environment.NewLine + "PR: " + Strings.pr24 + " & -c:v h264_nvenc -qp 20 -r 30 -c:a aac -b:a 128K % mkv" + Environment.NewLine + "PR: " + Strings.pr25 + " & -c:v h264_qsv -qp 20 -r 25 -c:a aac -b:a 128K % mkv" + Environment.NewLine + "PR: " + Strings.pr26 + " & -c:v libx264 -preset veryfast -vf " + '\u0022' + "fps=25,format=yuv420p,scale=1920:-2" + '\u0022' + " -c:a aac -b:a 64K % mp4"); - btn_load_config.PerformClick(); - - txt_pre_input.Text = String.Empty; - Settings.Default.Reset(); - btn_fix_pre.PerformClick(); - } - - private void reset_portable() - { - String path = String.Empty; - String path2 = String.Empty; - String path_pr = String.Empty; - path = port_path + "ff_batch_portable.ini"; - path_pr = port_path + "ff_presets_portable.ini"; - path2 = port_path + "ff_hw_dcd_portable"; - - if (File.Exists(path)) - { - File.Delete(path); - } - if (File.Exists(path2)) - { - File.Delete(path2); - } - - combo_prio.SelectedIndex = 2; - btn_save_prio.PerformClick(); - - //Sleep off - - String f_sleep = String.Empty; - if (is_portable == false) - { - f_sleep = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_sleep.ini"; - } - else - { - f_sleep = port_path + "ff_sleep_portable.ini"; - } - - if (File.Exists(f_sleep)) - { - try - { - File.Delete(f_sleep); - } - catch - { - } - } - - //End sleep off - - //Disable try preset - - String f_try = String.Empty; - if (is_portable == false) - { - f_try = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_try.ini"; - } - else - { - f_try = port_path + "ff_try_portable.ini"; - } - - if (File.Exists(f_try)) - { - try - { - File.Delete(f_try); - chk_try.CheckState = CheckState.Unchecked; - } - catch - { - } - } - - //End Disable preset - - //Concat video filter - - String f_concat = String.Empty; - if (is_portable == false) - { - f_concat = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_concat.ini"; - } - else - { - f_concat = port_path + "ff_concat_portable.ini"; - } - - if (File.Exists(f_concat)) - { - try - { - File.Delete(f_concat); - check_concat.CheckState = CheckState.Unchecked; - } - catch - { - } - } - - //End concat video filter - File.WriteAllText(path, "-c copy" + Environment.NewLine + "mp4" + Environment.NewLine + "Yes" - + Environment.NewLine + "Vn" + Environment.NewLine + "grid_yes" + Environment.NewLine + "keep_no" - + Environment.NewLine + "subf_no"); - - File.WriteAllText(path_pr, "Version 1.0" + Environment.NewLine - + "PR: " + Strings.pr01 + " & -c copy % mp4" + Environment.NewLine - + "PR: " + Strings.pr02 + " & -c:v copy -c:a aac -cutoff 20K -b:a 256K -ac 2 % mkv" + Environment.NewLine + "PR: " + Strings.pr03 + " & -c:v copy -c:a ac3 -b:a 256K -ac 2 -c:s copy % mkv" + Environment.NewLine + "PR: " + Strings.pr04 + " & -c:v prores_ks -profile:v standard -vendor:v ap10 -pix_fmt yuv422p10le -c:a pcm_s16le -chunk_size 64K % mkv" + Environment.NewLine + "PR: " + Strings.pr05 + " & -c:v libx264 -crf 20 -c:a copy % mkv" + Environment.NewLine + "PR: " + Strings.pr06 + " & -c:v libx264 -crf 23 -preset ultrafast -c:a copy % mkv" + Environment.NewLine + "PR: " + Strings.pr07 + " & -c:v libx265 -crf 23 -c:a copy % mkv" + Environment.NewLine + "PR: " + Strings.pr08 + " & -c:v libx264 -crf 23 -vf scale=1280:720 -c:a aac -b:a 128K % mp4" + Environment.NewLine + "PR: " + Strings.pr09 + " & -c:v libx264 -crf 21 -vf " + "\u0022" + "transpose=1" + "\u0022" + " -c:a copy % mp4" + Environment.NewLine + "PR: " + Strings.pr10 + " & -c:v libx264 -crf 21 -vf " + "\u0022" + "transpose=0" + "\u0022" + " -c:a copy % mp4" + Environment.NewLine + "PR: " + Strings.pr11 + " & -c:v libx264 -crf 21 -vf " + "\u0022" + "transpose=2" + "\u0022" + " -c:a copy % mp4" + Environment.NewLine + "PR: " + Strings.pr12 + " & -c:v libx264 -crf 21 -vf " + "\u0022" + "transpose=3" + "\u0022" + " -c:a copy % mp4" + Environment.NewLine + "PR: " + Strings.pr13 + " & -c:v libx264 -crf 21 -vf " + "\u0022" + "transpose=2, transpose=2" + "\u0022" + " -c:a copy % mp4" + Environment.NewLine + "PR: " + Strings.pr14 + " & -c copy -sn % mp4" + Environment.NewLine + "PR: " + Strings.pr15 + " & -vn -c:a flac -ar 44100 -sample_fmt s16 -ac 2 % flac" + Environment.NewLine + "PR: " + Strings.pr16 + " & -c:v copy -c:a libmp3lame -qscale:a 0 -ac 2 % mp3" + Environment.NewLine + "PR: " + Strings.pr17 + " & -vn -c:a libmp3lame -qscale:a 1 -ac 2 % mp3" + Environment.NewLine + "PR: " + Strings.pr18 + " & -vn -c:a libmp3lame -b:a 224K -ac 2 % mp3" + Environment.NewLine + "PR: " + Strings.pr19 + " & -vn -c:a pcm_s16le -ar 44100 -sample_fmt s16 -ac 2 % wav" + Environment.NewLine + "PR: " + Strings.pr20 + " & -map 0:2 -c:s copy % srt" + Environment.NewLine + "PR: " + Strings.pr21 + " & -vframes 1 -f image2 % png" + Environment.NewLine + "PR: " + Strings.pr21_2 + " & -c:v h264_amf -rc cqp -qp_p 20 -qp_i 20 -qp_b 20 -c:a copy % mkv" + Environment.NewLine + "PR: " + Strings.pr21_21 + " & -c:v hevc_amf -rc cqp -qp_p 20 -qp_i 20 -qp_b 20 -c:a copy % mkv" + Environment.NewLine + "PR: " + Strings.pr22 + " & -r 24 -c:a aac -b:a 128K % mkv" + Environment.NewLine + "PR: " + Strings.pr23 + " & -r 15 -vf scale=1280x720 -c:a aac -b:a 128K % mkv" + Environment.NewLine + "PR: " + Strings.pr24 + " & -c:v h264_nvenc -qp 20 -r 30 -c:a aac -b:a 128K % mkv" + Environment.NewLine + "PR: " + Strings.pr25 + " & -c:v h264_qsv -qp 20 -r 25 -c:a aac -b:a 128K % mkv" + Environment.NewLine + "PR: " + Strings.pr26 + " & -c:v libx264 -preset veryfast -vf " + '\u0022' + "fps=25,format=yuv420p,scale=1920:-2" + '\u0022' + " -c:a aac -b:a 64K % mp4"); - - //Remove custom columns - String f_cols = String.Empty; - if (is_portable == false) - { - f_cols = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_cols.ini"; - } - else - { - f_cols = port_path + "ff_cols_portable.ini"; - } - try - { - File.Delete(f_cols); - foreach (ColumnHeader col in listView1.Columns) if (col.Text.Contains(Strings.width)) listView1.Columns.Remove(col); - foreach (ColumnHeader col in listView1.Columns) if (col.Text.Contains(Strings.height)) listView1.Columns.Remove(col); - foreach (ColumnHeader col in listView1.Columns) if (col.Text.Contains(Strings.Video_codec)) listView1.Columns.Remove(col); - foreach (ColumnHeader col in listView1.Columns) if (col.Text.Contains(Strings.Audio_codec)) listView1.Columns.Remove(col); - foreach (ColumnHeader col in listView1.Columns) if (col.Text.Contains(Strings.v_bitr)) listView1.Columns.Remove(col); - foreach (ColumnHeader col in listView1.Columns) if (col.Text.Contains(Strings.a_bitr)) listView1.Columns.Remove(col); - foreach (ColumnHeader col in listView1.Columns) if (col.Text.Contains(Settings.Default.cust_med_col)) listView1.Columns.Remove(col); - foreach (ColumnHeader col in listView1.Columns) if (col.Text.Contains(Strings.Encoding_parameters)) - { - listView1.Columns.Remove(col); - cust_p_col = 0; - } - foreach (ColumnHeader col in listView1.Columns) if (col.Text.Replace("<", "").Replace(">", "").TrimStart() == Strings.bitrate && !col.Text.ToLower().Contains("video") && !col.Text.ToLower().Contains("audio") && !col.Text.ToLower().Contains("vídeo") && !col.Text.ToLower().Contains("视频") && !col.Text.ToLower().Contains("音")) listView1.Columns.Remove(col); - resize(); - } - catch { } - txt_pre_input.Text = String.Empty; - btn_fix_pre.PerformClick(); - } - - private void preset_menu_Click(object sender, EventArgs e) - { - btn_wizard.PerformClick(); - } - - private void toolStripMenuItem1_Click(object sender, EventArgs e) - { - btn_exit.PerformClick(); - } - - private void chk_overw_CheckedChanged(object sender, EventArgs e) - { - String path_first = String.Empty; - if (is_portable == false) - { - path_first = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_first.ini"; - } - else - { - path_first = port_path + "ff_first_portable.ini"; - } - - Boolean not_show = true; - String not_first = File.ReadAllText(path_first); - - if (not_first.Contains("chk_overw") == false) not_show = false; - - if (chk_overw.CheckState == CheckState.Checked) - { - if (Settings.Default.dark_mode == false) chk_overw.BackColor = Color.LightGoldenrodYellow; - else chk_overw.BackColor = Color.FromArgb(255, 128, 128, 128); - if (not_show == false) - { - File.WriteAllText(path_first, "chk_overw"); - } - } - else - { - chk_overw.BackColor = this.BackColor; - } - if (chk_delete_source.Checked == true && chk_overw.Checked == true) - { - delete_def = false; - delete_one = true; - rec_overw(); - MessageBox.Show(Strings.del_overw2); - } - } - - - private void main_f_4_Click(object sender, EventArgs e) - { - if (listView1.Items.Count == 0) - { - MessageBox.Show(Strings.list_empty, Strings.list_bl, MessageBoxButtons.OK, MessageBoxIcon.Information); - return; - } - if (txt_parameters.Text == "") - { - MessageBox.Show(Strings.params_bl, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - this.Cursor = Cursors.WaitCursor; - save_ffq.DefaultExt = "ffq"; - save_ffq.InitialDirectory = Path.GetDirectoryName(Environment.SpecialFolder.MyDocuments.ToString()); - save_ffq.RestoreDirectory = true; - save_ffq.Filter = Strings.q_files + " " + " | *.ffq| " + Strings.all_files + " (*.*) | *.*"; - if (save_ffq.ShowDialog() != DialogResult.OK) - { - this.Cursor = Cursors.Arrow; - return; - } - String save_path = save_ffq.FileName; - List list_file = new List(); - list_file.Add(txt_parameters.Text); - list_file.Add(txt_format.Text); - list_file.Add(chk_recreate.CheckState.ToString()); - - if (chk_suffix.CheckState == CheckState.Unchecked) list_file.Add(chk_suffix.CheckState.ToString()); - else - { - list_file.Add(txt_suffix.Text); - } - - list_file.Add(txt_path_main.Text); - foreach (ListViewItem item in listView1.Items) - { - list_file.Add(item.SubItems[1].Text + "\\" + item.Text + " --0 " + item.SubItems[2].Text + " --1 " + item.SubItems[3].Text + " --2 " + item.SubItems[4].Text + " --3 " + item.SubItems[5].Text); - } - - try - { - File.WriteAllLines(save_path, list_file); - } - catch (Exception excp) - { - MessageBox.Show(Strings.err_save_qu + Environment.NewLine + Environment.NewLine + excp.Message, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - this.Cursor = Cursors.Arrow; - } - - private void main_f_5_Click(object sender, EventArgs e) - { - file_dialog_ffq.DefaultExt = "ffq"; - file_dialog_ffq.InitialDirectory = Path.GetDirectoryName(Environment.SpecialFolder.MyDocuments.ToString()); - file_dialog_ffq.RestoreDirectory = true; - file_dialog_ffq.Filter = Strings.q_files + " " + " |*.ffq;*.txt|" + Strings.all_files + " (*.*) | *.*"; - if (file_dialog_ffq.ShowDialog() != DialogResult.OK) return; - listView1.Items.Clear(); - String save_path = file_dialog_ffq.FileName; - this.Cursor = Cursors.WaitCursor; - - int linea = 0; - int not_found = 0; - combo_presets.Text = ""; - List itemsToAdd = new List(); - - Boolean ffq_format = false; - if (Path.GetExtension(file_dialog_ffq.FileName) == ".ffq") - { - ffq_format = true; - try - { - foreach (string line in File.ReadLines(save_path)) - { - if (linea == 0) - { - txt_parameters.Text = line; - } - - if (linea == 1) - { - txt_format.Text = line; - } - - if (linea == 2) - { - if (line == "Unchecked") chk_recreate.CheckState = CheckState.Unchecked; - else chk_recreate.CheckState = CheckState.Checked; - } - - if (linea == 3) - { - if (line == "Unchecked") chk_suffix.CheckState = CheckState.Unchecked; - else - { - chk_suffix.CheckState = CheckState.Checked; - txt_suffix.Text = line; - } - } - - if (linea == 4) - { - txt_path_main.Text = line; - } - - if (linea > 4) - { - Boolean missing = false; - listView1.SmallImageList = imageList2; - - itemsToAdd.Add(new ListViewItem(Path.GetFileName(line.Substring(0, line.LastIndexOf(" --0 "))), 1)); - - Icon iconForFile = SystemIcons.WinLogo; - - // Check to see if the image collection contains an image - // for this extension, using the extension as a key. - if (File.Exists(line.Substring(0, line.LastIndexOf(" --0 ")))) - { - if (line.Substring(0, 2) != "\\\\") - { - if (!imageList2.Images.ContainsKey(Path.GetExtension(line.Substring(0, line.LastIndexOf(" --0 "))))) - { - // If not, add the image to the image list. - iconForFile = System.Drawing.Icon.ExtractAssociatedIcon(line.Substring(0, line.LastIndexOf(" --0 "))); - imageList2.Images.Add(Path.GetExtension(line.Substring(0, line.LastIndexOf(" --0 "))), iconForFile); - } - //listView1.Items.Add(elemento); - itemsToAdd[linea - 5].ImageKey = Path.GetExtension(Path.GetExtension(line.Substring(0, line.LastIndexOf(" --0 ")))); - } - else - { - itemsToAdd[linea - 5].ImageIndex = 0; - } - } - else - { - not_found = not_found + 1; - missing = true; - } - - //listView1.Items.Add(line.Substring(0,line.LastIndexOf(" --0 "))); - String type = line.Substring(line.LastIndexOf(" --0 ") + 5, line.Length - (line.LastIndexOf(" --0") + 5)); - type = type.Substring(0, type.LastIndexOf(" --1")); - String dur = line.Substring(line.LastIndexOf(" --1 ") + 5, line.Length - (line.LastIndexOf(" --1") + 5)); - dur = dur.Substring(0, dur.LastIndexOf(" --2")); - String size = line.Substring(line.LastIndexOf(" --2 ") + 5, line.Length - (line.LastIndexOf(" --2") + 5)); - size = size.Substring(0, size.LastIndexOf(" --3")); - String status = line.Substring(line.LastIndexOf(" --3 ") + 5, line.Length - (line.LastIndexOf(" --3") + 5)); - - itemsToAdd[linea - 5].SubItems.Add(Path.GetDirectoryName(line.Substring(0, line.LastIndexOf(" --0 ")))); - itemsToAdd[linea - 5].SubItems.Add(type); - itemsToAdd[linea - 5].SubItems.Add(dur); - itemsToAdd[linea - 5].SubItems.Add(size); - if (missing == false) itemsToAdd[linea - 5].SubItems.Add(status); - else - { - itemsToAdd[linea - 5].SubItems.Add(Strings.file_not_f); - itemsToAdd[linea - 5].BackColor = Color.LightGoldenrodYellow; - } - } - linea = linea + 1; - } - listView1.Items.AddRange(itemsToAdd.ToArray()); - } - catch (Exception excpt) - { - this.Cursor = Cursors.Arrow; - MessageBox.Show(Strings.err_qf + Environment.NewLine + excpt.Message, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - btn_load_config.PerformClick(); - read_saved_path(); - return; - } - this.Cursor = Cursors.Arrow; - if (start_seq == true) - { - Thread.Sleep(500); - if (start_multi == false) btn_seq.PerformClick(); - else btn_multi_m.PerformClick(); - } - return; - } - - if (Path.GetExtension(file_dialog_ffq.FileName) == ".txt") - { - ffq_format = true; - try - { - foreach (string line in File.ReadLines(save_path)) - { - Boolean missing = false; - listView1.SmallImageList = imageList2; - - itemsToAdd.Add(new ListViewItem(Path.GetFileName(line))); - - Icon iconForFile = SystemIcons.WinLogo; - - // Check to see if the image collection contains an image - // for this extension, using the extension as a key. - if (File.Exists(line)) - { - if (!imageList2.Images.ContainsKey(Path.GetExtension(line))) - { - // If not, add the image to the image list. - iconForFile = System.Drawing.Icon.ExtractAssociatedIcon(line); - imageList2.Images.Add(Path.GetExtension(line), iconForFile); - } - - //listView1.Items.Add(elemento); - itemsToAdd[linea].ImageKey = Path.GetExtension(Path.GetExtension(line)); - } - else - { - not_found = not_found + 1; - missing = true; - } - - itemsToAdd[linea].SubItems.Add(Path.GetDirectoryName(line)); - itemsToAdd[linea].SubItems.Add(Strings.pending); - itemsToAdd[linea].SubItems.Add(Strings.pending); - itemsToAdd[linea].SubItems.Add(Strings.pending); - itemsToAdd[linea].BackColor = Color.White; - - if (missing == false) itemsToAdd[linea].SubItems.Add(Strings.queued); - else - { - itemsToAdd[linea].SubItems.Add(Strings.file_not_f); - itemsToAdd[linea].BackColor = Color.LightGoldenrodYellow; - } - - linea = linea + 1; - } - listView1.Items.AddRange(itemsToAdd.ToArray()); - } - catch (Exception excpt) - { - this.Cursor = Cursors.Arrow; - MessageBox.Show(Strings.err_qf + Environment.NewLine + excpt.Message, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - btn_load_config.PerformClick(); - read_saved_path(); - return; - } - this.Cursor = Cursors.Arrow; - if (start_seq == true) - { - Thread.Sleep(500); - if (start_multi == false) btn_seq.PerformClick(); - else btn_multi_m.PerformClick(); - } - return; - } - - this.Cursor = Cursors.Arrow; - if (tabControl1.SelectedIndex == 0) - { - if (ffq_format == true) - { - calc_list_size(); - calc_total_dur(); - } - lbl_items.Text = listView1.Items.Count.ToString() + " " + Strings.files; - - if (not_found > 0 && no_warn_0_dur == false) - { - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - MessageBox.Show(Strings.queue_warn + Environment.NewLine + not_found.ToString() + " " + Strings.queue_not_f + " " + Environment.NewLine + Environment.NewLine + Strings.sort_status + ".", Strings.warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - else btn_refresh.PerformClick(); - } - } - - private void toolStripMenuItem4_Click(object sender, EventArgs e) - { - btn_change_ff.PerformClick(); - } - - private void ctm1_queue_Click(object sender, EventArgs e) - { - if (listView1.SelectedIndices.Count > 0) - { - foreach (ListViewItem item in listView1.SelectedItems) - { - item.SubItems[5].Text = Strings.queued; - } - } - } - - private void main_m_logs_Click(object sender, EventArgs e) - { - btn_display_log.PerformClick(); - } - - private void btn_save_queue_Click(object sender, EventArgs e) - { - Pg1.Focus(); - frm33.StartPosition = FormStartPosition.CenterParent; - frm33.ShowDialog(); - if (prev_map.Length > 0) txt_parameters.Text = txt_parameters.Text.Replace(prev_map, ""); - if (frm33.mapp.Length > 0) - { - txt_parameters.Text = frm33.mapp + txt_parameters.Text; - prev_map = frm33.mapp; - } - } - - private void toolStripMenuItem2_Click(object sender, EventArgs e) - { - btn_clean_list.PerformClick(); - } - - private void toolStripMenuItem1_Click_1(object sender, EventArgs e) - { - btn_refresh.PerformClick(); - } - - private void toolStripMenuItem3_Click(object sender, EventArgs e) - { - requeue.PerformClick(); - } - - private void btn_filter_Click(object sender, EventArgs e) - { - Pg1.Focus(); - if (LB_Wait.Text == Strings.add_col1) return; - Form5 frm5 = new Form5(); - - if (listView1.Items.Count == 0 || tabControl1.SelectedIndex != 0) return; - if (listView1.SelectedIndices.Count == 1) - { - form4.lv1_item = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - frm5.lv1_item = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - } - else - { - form4.lv1_item = listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text; - frm5.lv1_item = listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text; - } - - form4.ShowDialog(this); - if (form4.cancel_filter == true) return; - - btn_undo_filter.ImageList = img_undo; - btn_undo_filter.ImageKey = "undo_20.png"; - - unfilter_lv1.Clear(); - filtered_lv1.Clear(); - unfilter_lv1.SmallImageList = imageList2; - - //Backup current listView1 - this.Cursor = Cursors.WaitCursor; - - filtered_lv1.Clear(); - unfilter_lv1.Clear(); - - //Backup listview1 - - unfilter_lv1.Columns.AddRange((from ColumnHeader Col in listView1.Columns - select (ColumnHeader)Col.Clone()).ToArray()); - - filtered_lv1.Columns.AddRange((from ColumnHeader Col in listView1.Columns - select (ColumnHeader)Col.Clone()).ToArray()); - - unfilter_lv1.Items.AddRange((from ListViewItem item in listView1.Items - select (ListViewItem)item.Clone()).ToArray()); - - filtered_lv1.Items.AddRange((from ListViewItem item in listView1.Items - select (ListViewItem)item.Clone()).ToArray()); - - this.Cursor = Cursors.Arrow; - //End backup current lisView1 - - btn_undo_filter.Enabled = true; - - //Apply status filter - - if (form4.filter_type == Strings.status) - { - for (int n = 0; n < listView1.Items.Count; n++) - { - if (listView1.Items[n].SubItems[5].Text == form4.filter_value && form4.filter_action == Strings.remove) - { - listView1.Items[n].Remove(); - filtered_lv1.Items[n].Remove(); - n = n - 1; - } - else - { - if ((listView1.Items[n].SubItems[5].Text == form4.filter_value) == false && form4.filter_action == Strings.keep) - { - listView1.Items[n].Remove(); - filtered_lv1.Items[n].Remove(); - n = n - 1; - } - } - } - - if (form4.remove_invalid == true) btn_clean_list.PerformClick(); - lbl_items.Text = listView1.Items.Count + " " + Strings.files; - calc_list_dur(); - calc_list_size(); - } - - //End apply status filter - - //Apply extension filter - - if (form4.filter_type == Strings.file_ext) - { - int ni = listView1.Items.Count; - if (listView1.Items.Count > 2500) - { - pg_adding.Value = 0; - pg_adding.Visible = true; - pg_adding.Maximum = listView1.Items.Count; - LB_Wait.Visible = true; - txt_adding_p.Visible = true; - LB_Wait.Text = Strings.app_f; - } - - for (int n = 0; n < listView1.Items.Count; n++) - { - if (ni > 2500) - { - pg_adding.Value = pg_adding.Value + 1; - this.InvokeEx(f => TaskbarProgress.SetValue(this.Handle, pg_adding.Value, pg_adding.Maximum)); - txt_adding_p.Text = (pg_adding.Value * 100 / ni).ToString() + "%"; - txt_adding_p.Refresh(); - LB_Wait.Refresh(); - pg_adding.Refresh(); - } - - if (Path.GetExtension(listView1.Items[n].Text).ToLower() == "." + form4.filter_value.ToLower() && form4.filter_action == Strings.remove) - { - listView1.Items[n].Remove(); - filtered_lv1.Items[n].Remove(); - n = n - 1; - } - else - { - if ((Path.GetExtension(listView1.Items[n].Text).ToLower() == "." + form4.filter_value.ToLower()) == false && form4.filter_action == Strings.keep) - { - listView1.Items[n].Remove(); - filtered_lv1.Items[n].Remove(); - n = n - 1; - } - } - } - - if (form4.remove_invalid == true) btn_clean_list.PerformClick(); - pg_adding.Visible = false; - txt_adding_p.Visible = false; - pg_adding.Value = 0; - LB_Wait.Text = String.Empty; - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - listView1.EndUpdate(); - lbl_items.Text = listView1.Items.Count + " " + Strings.files; - calc_list_dur(); - calc_list_size(); - } - //End apply Extension filter - - if (form4.filter_type == Strings.f_bitr) - { - if (form4.remove_invalid == true) btn_clean_list.PerformClick(); - if (listView1.Items.Count > 999) - { - start_total_time = 0; - time_n_tasks = 0; - timer_adding.Enabled = true; - timer_adding.Start(); - txt_add_remain.Enabled = true; - pg_adding.Maximum = listView1.Items.Count; - pg_adding.Value = 0; - } - String ftype = "file_bitrate"; - BG_Vfilter.RunWorkerAsync(argument: ftype); - } - - //File size filter - if (form4.filter_type == Strings.f_size) - { - listView1.BeginUpdate(); - this.Cursor = Cursors.WaitCursor; - - int ni = listView1.Items.Count; - if (listView1.Items.Count > 5000) - { - pg_adding.Value = 0; - pg_adding.Visible = true; - pg_adding.Maximum = listView1.Items.Count; - LB_Wait.Visible = true; - txt_adding_p.Visible = true; - LB_Wait.Text = Strings.app_f; - } - - for (int n = 0; n < listView1.Items.Count; n++) - { - if (ni > 5000) - { - pg_adding.Value = pg_adding.Value + 1; - this.InvokeEx(f => TaskbarProgress.SetValue(this.Handle, pg_adding.Value, pg_adding.Maximum)); - txt_adding_p.Text = (pg_adding.Value * 100 / ni).ToString() + "%"; - txt_adding_p.Refresh(); - LB_Wait.Refresh(); - pg_adding.Refresh(); - } - - long size = new FileInfo(listView1.Items[n].SubItems[1].Text + "\\" + listView1.Items[n].Text).Length; - long compare = long.Parse(form4.filter_value) * 1048576; - - if (size >= compare && form4.filter_action == Strings.remove) - { - listView1.Items[n].Remove(); - filtered_lv1.Items[n].Remove(); - n = n - 1; - } - else - { - if (size < compare && form4.filter_action == Strings.keep) - { - listView1.Items[n].Remove(); - filtered_lv1.Items[n].Remove(); - n = n - 1; - } - } - } - listView1.EndUpdate(); - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - this.Cursor = Cursors.Arrow; - - if (form4.remove_invalid == true) btn_clean_list.PerformClick(); - pg_adding.Visible = false; - txt_adding_p.Visible = false; - pg_adding.Value = 0; - LB_Wait.Text = String.Empty; - lbl_items.Text = listView1.Items.Count + " " + Strings.files; - calc_list_dur(); - calc_list_size(); - } - - //Apply video codec filter - - if (form4.filter_type == Strings.Video_codec) - { - if (form4.remove_invalid == true) btn_clean_list.PerformClick(); - if (listView1.Items.Count > 999) - { - start_total_time = 0; - time_n_tasks = 0; - timer_adding.Enabled = true; - timer_adding.Start(); - txt_add_remain.Enabled = true; - pg_adding.Maximum = listView1.Items.Count; - pg_adding.Value = 0; - } - String ftype = "video_codec"; - BG_Vfilter.RunWorkerAsync(argument: ftype); - } - - if (form4.filter_type == Strings.v_bitr) - { - if (form4.remove_invalid == true) btn_clean_list.PerformClick(); - if (listView1.Items.Count > 999) - { - start_total_time = 0; - time_n_tasks = 0; - timer_adding.Enabled = true; - timer_adding.Start(); - txt_add_remain.Enabled = true; - pg_adding.Maximum = listView1.Items.Count; - pg_adding.Value = 0; - } - String ftype = "video_bitrate"; - BG_Vfilter.RunWorkerAsync(argument: ftype); - } - - //Audio codec - if (form4.filter_type == Strings.Audio_codec) - { - if (form4.remove_invalid == true) btn_clean_list.PerformClick(); - if (listView1.Items.Count > 999) - { - start_total_time = 0; - time_n_tasks = 0; - timer_adding.Enabled = true; - timer_adding.Start(); - txt_add_remain.Enabled = true; - pg_adding.Maximum = listView1.Items.Count; - pg_adding.Value = 0; - } - String ftype = "audio_codec"; - BG_Vfilter.RunWorkerAsync(argument: ftype); - } - - //Frame rate - if (form4.filter_type == Strings.fr_rate) - { - if (form4.remove_invalid == true) btn_clean_list.PerformClick(); - if (listView1.Items.Count > 999) - { - start_total_time = 0; - time_n_tasks = 0; - timer_adding.Enabled = true; - timer_adding.Start(); - txt_add_remain.Enabled = true; - pg_adding.Maximum = listView1.Items.Count; - pg_adding.Value = 0; - } - String ftype = "frame_rate"; - BG_Vfilter.RunWorkerAsync(argument: ftype); - } - - if (form4.filter_type == "Frame size") - { - if (form4.remove_invalid == true) btn_clean_list.PerformClick(); - if (listView1.Items.Count > 999) - { - start_total_time = 0; - time_n_tasks = 0; - timer_adding.Enabled = true; - timer_adding.Start(); - txt_add_remain.Enabled = true; - pg_adding.Maximum = listView1.Items.Count; - pg_adding.Value = 0; - } - String ftype = "frame_size"; - BG_Vfilter.RunWorkerAsync(argument: ftype); - } - - if (form4.filter_type == Strings.c_str) - { - if (form4.remove_invalid == true) btn_clean_list.PerformClick(); - if (listView1.Items.Count > 999) - { - start_total_time = 0; - time_n_tasks = 0; - timer_adding.Enabled = true; - timer_adding.Start(); - txt_add_remain.Enabled = true; - pg_adding.Maximum = listView1.Items.Count; - pg_adding.Value = 0; - } - String ftype = "custom_ff"; - BG_Vfilter.RunWorkerAsync(argument: ftype); - } - - if (form4.filter_type == Strings.c_str + " " + "(MI)") - { - if (form4.remove_invalid == true) btn_clean_list.PerformClick(); - if (listView1.Items.Count > 999) - { - start_total_time = 0; - time_n_tasks = 0; - timer_adding.Enabled = true; - timer_adding.Start(); - txt_add_remain.Enabled = true; - pg_adding.Maximum = listView1.Items.Count; - pg_adding.Value = 0; - } - String ftype = "custom_mi"; - BG_Vfilter.RunWorkerAsync(argument: ftype); - } - - if (form4.filter_type == Strings.Metadata) - { - if (form4.remove_invalid == true) btn_clean_list.PerformClick(); - if (listView1.Items.Count > 999) - { - start_total_time = 0; - time_n_tasks = 0; - timer_adding.Enabled = true; - timer_adding.Start(); - txt_add_remain.Enabled = true; - pg_adding.Maximum = listView1.Items.Count; - pg_adding.Value = 0; - } - String ftype = "metadata"; - BG_Vfilter.RunWorkerAsync(argument: ftype); - } - - lbl_items.Text = listView1.Items.Count + " " + Strings.files; - calc_list_dur(); - calc_list_size(); - } - - private void btn_undo_filter_Click(object sender, EventArgs e) - { - Pg1.Focus(); - LB_Wait.Visible = false; - if (btn_undo_filter.ImageKey == "undo_20.png") - { - btn_undo_filter.ImageKey = "redo_20.png"; - tool_undo_filter.SetToolTip(this.btn_undo_filter, Strings.r_fil); - - //Fill with original listview items - listView1.Items.Clear(); - listView1.Items.AddRange((from ListViewItem item in unfilter_lv1.Items select (ListViewItem)item.Clone()).ToArray()); - } - else - { - btn_undo_filter.ImageKey = "undo_20.png"; - tool_undo_filter.SetToolTip(this.btn_undo_filter, Strings.undo_fil); - btn_undo_filter.Refresh(); - - //Fill with filtered listview items - listView1.Items.Clear(); - listView1.Items.AddRange((from ListViewItem item in filtered_lv1.Items select (ListViewItem)item.Clone()).ToArray()); - } - - lbl_items.Text = listView1.Items.Count + " " + Strings.files; - calc_list_dur(); - calc_list_size(); - } - - private void BG_Vfilter_DoWork(object sender, DoWorkEventArgs e) - { - String ftype = (String)e.Argument; - - Disable_Controls(); - this.Invoke(new MethodInvoker(delegate - { - btn_abort_all.Enabled = false; - btn_pause.Enabled = false; - pg_adding.Value = 0; - pg_adding.Maximum = listView1.Items.Count; - pg_adding.Visible = true; - pg_adding.Enabled = true; - txt_adding_p.Visible = true; - txt_adding_p.Enabled = true; - txt_adding_p.Refresh(); - LB_Wait.Visible = true; - LB_Wait.Enabled = true; - lbl_items.Visible = false; - lbl_items.Refresh(); - lbl_dur_list.Visible = false; - lbl_dur_list.Refresh(); - lbl_size.Visible = false; - lbl_size.Refresh(); - pg_adding.Value = 0; - pg_adding.Minimum = 0; - pg_adding.Maximum = listView1.Items.Count; - btn_cancel_add.Visible = true; - btn_cancel_add.Enabled = true; - listView1.BeginUpdate(); - })); - - canceled_file_adding = false; - - int i = 0; - int removed = 0; - //selected.Clear(); - String select_stream = String.Empty; - - if (ftype == "file_bitrate") - { - if (Settings.Default.quick_queue) - { - MessageBox.Show(Strings.filter_not_qfl); - return; - } - this.Invoke(new MethodInvoker(delegate - { - LB_Wait.Text = Strings.app_f; - LB_Wait.Refresh(); - foreach (ListViewItem item in listView1.Items) - { - i++; - String file = item.SubItems[1].Text + "\\" + item.Text; - String dur_item = item.SubItems[3].Text; - - Boolean to_remove = false; - Boolean match = false; - Double bytes = 0; - FileInfo fi = new FileInfo(file); - Double size = fi.Length; - Double dur = 0; - TimeSpan time; - - if (TimeSpan.TryParse(dur_item, out time)) - { - dur = TimeSpan.Parse(dur_item).TotalSeconds; - if (dur > 0) bytes = Math.Round((size / dur * 8 / 1000), 0); - else bytes = 0; - } - else bytes = 0; - - Int32 filter_value = Int32.Parse(form4.filter_value); - if (filter_value <= (int)bytes && (int)bytes != 0) - { - match = true; - } - - if (match == true && form4.filter_action == Strings.remove) to_remove = true; - if (match == true && form4.filter_action == Strings.keep) to_remove = false; - if (match == false && form4.filter_action == Strings.remove) to_remove = false; - if (match == false && form4.filter_action == Strings.keep) to_remove = true; - - if (to_remove == true) - { - listView1.Items.Remove(item); - removed = removed + 1; - pg_adding.Maximum = listView1.Items.Count + removed; - } - - pg_adding.Value = pg_adding.Value + 1; - TaskbarProgress.SetValue(this.Handle, pg_adding.Value, pg_adding.Maximum); - pg_adding.Refresh(); - txt_adding_p.Text = (i * 100 / pg_adding.Maximum).ToString() + "%"; - txt_adding_p.Refresh(); - } - listView1.EndUpdate(); - })); - } //End file bitrate - - - ListView lstv2 = new ListView(); - listView1.Invoke(new MethodInvoker(delegate - { - lstv2.Columns.AddRange((from ColumnHeader Col in listView1.Columns - select (ColumnHeader)Col.Clone()).ToArray()); - lstv2.Items.AddRange((from ListViewItem item in listView1.Items select (ListViewItem)item.Clone()).ToArray()); - })); - - procs.Clear(); - media_list.Clear(); - multi_logs.Clear(); - to_rem.Clear(); - matched.Clear(); - - for (int ii = 0; ii < lstv2.Items.Count; ii++) - { - procs.Add("proc_urls_" + ii.ToString(), new Process()); - media_list.Add("lines_out_" + ii.ToString(), new List()); - multi_logs.Add("item_" + ii.ToString(), String.Empty); - to_rem.Add("rem_" + ii.ToString(), false); - matched.Add("match_" + ii.ToString(), false); - } - - ParallelOptions par_op = new ParallelOptions(); - CancellationTokenSource cts = new CancellationTokenSource(); - par_op.CancellationToken = cts.Token; - if (Environment.ProcessorCount > 1) par_op.MaxDegreeOfParallelism = Environment.ProcessorCount / 2; - else par_op.MaxDegreeOfParallelism = 1; - ParallelLoopResult res = new ParallelLoopResult(); - - try - { - res = Parallel.For(0, lstv2.Items.Count, par_op, (n) => - { - if (canceled_file_adding == true) cts.Cancel(); - - int fade_frames = 0; - String ff_frames = String.Empty; - - var ff_str = procs["proc_urls_" + n.ToString()]; - var lines_err = media_list["lines_out_" + n.ToString()]; - var lines_out = media_list["lines_out_" + n.ToString()]; - var item = multi_logs["item_" + n.ToString()]; - var to_remove = to_rem["rem_" + n.ToString()]; - var match = matched["match_" + n.ToString()]; - - item = lstv2.Items[n].SubItems[1].Text + "\\" + lstv2.Items[n].Text; - - if (canceled_file_adding == false) - { - ff_str.StartInfo.RedirectStandardOutput = true; - ff_str.StartInfo.RedirectStandardError = true; - ff_str.StartInfo.UseShellExecute = false; - ff_str.StartInfo.CreateNoWindow = true; - ff_str.EnableRaisingEvents = true; - - if (ftype == "video_codec" || ftype == "audio_codec" || ftype == "custom_ff") - { - - if (match_filter_ff(Path.Combine(Application.StartupPath, "ffmpeg.exe"), "-i " + '\u0022' + item + '\u0022' + " -hide_banner", form4.filter_action, ftype, n)) - { - removed = removed + 1; - } - } - - if (ftype == "frame_rate") - { - if (match_filter(Path.Combine(Application.StartupPath, "mediainfo.exe"), '\u0022' + "--Inform=Video;%FrameRate%-%FrameRate_Nominal%" + '\u0022' + " " + '\u0022' + item + '\u0022', form4.filter_action, ftype, n)) - { - removed = removed + 1; - } - } - - if (ftype == "frame_size") - { - if (match_filter(Path.Combine(Application.StartupPath, "mediainfo.exe"), '\u0022' + "--Inform=Video;%Width%" + "x" + "%Height%" + '\u0022' + " " + '\u0022' + item + '\u0022', form4.filter_action, ftype, n)) - { - removed = removed + 1; - } - } - - if (ftype == "custom_mi") - { - if (match_filter(Path.Combine(Application.StartupPath, "mediainfo.exe"), '\u0022' + item + '\u0022', form4.filter_action, ftype, n)) - { - removed = removed + 1; - } - } - - if (ftype == "metadata") - { - if (match_filter(Path.Combine(Application.StartupPath, "mediainfo.exe"), '\u0022' + "--Output=General;%" + form4.stream_n + "%" + '\u0022' + " " + '\u0022' + item + '\u0022', form4.filter_action, ftype, n)) - { - removed = removed + 1; - } - } - - if (ftype == "video_bitrate") - { - if (match_filter(Path.Combine(Application.StartupPath, "mediainfo.exe"), '\u0022' + "--Inform=Video;%BitRate% " + '\u0022' + " " + '\u0022' + item + '\u0022', form4.filter_action, ftype, n)) - { - removed = removed + 1; - } - } - } - else - { - cts.Cancel(); - timer_adding.Stop(); - this.Invoke(new MethodInvoker(delegate - { - listView1.Items.Clear(); - LB_Wait.Visible = false; - btn_undo_filter.Enabled = true; - btn_undo_filter.ImageKey = "undo_20.png"; - btn_undo_filter.PerformClick(); - btn_undo_filter.Enabled = false; - - txt_add_remain.Text = String.Empty; - txt_add_remain.Visible = false; - txt_add_remain.Refresh(); - })); - } - - i++; - - if (ftype != "file_bitrate") - { - this.Invoke(new MethodInvoker(delegate - { - LB_Wait.Text = Strings.app_f; - LB_Wait.Refresh(); - pg_adding.Value = pg_adding.Value + 1; - TaskbarProgress.SetValue(this.Handle, pg_adding.Value, pg_adding.Maximum); - pg_adding.Refresh(); - txt_adding_p.Text = (i * 100 / pg_adding.Maximum).ToString() + "%"; - txt_adding_p.Refresh(); - })); - } - }); - - } catch { } - - timer_adding.Stop(); - - if (ftype != "file_bitrate") - { - listView1.Invoke(new MethodInvoker(delegate - { - LB_Wait.Text = Strings.remove_item; - foreach (ListViewItem it in listView1.Items) - { - if (it.Text == Strings.remove) it.Remove(); - } - })); - } - } - - private void BG_Vfilter_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) - { - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - listView1.EndUpdate(); - listView1.Refresh(); - txt_add_remain.Text = String.Empty; - txt_add_remain.Visible = false; - txt_add_remain.Refresh(); - LB_Wait.Text = Strings.Removed + " " + (unfilter_lv1.Items.Count - listView1.Items.Count).ToString() + " " + Strings.files; - end_bg_filters(); - } - - Boolean match_filter(String exe, String param, String filter, String ftype, int n) - { - Process ff_str = new Process(); - ff_str.StartInfo.RedirectStandardOutput = true; - ff_str.StartInfo.UseShellExecute = false; - ff_str.StartInfo.CreateNoWindow = true; - ff_str.EnableRaisingEvents = true; - ff_str.StartInfo.FileName = exe; - ff_str.StartInfo.Arguments = param; - - Boolean match = false; - List strs = new List(); - ff_str.Start(); - - while (!ff_str.StandardOutput.EndOfStream) - { - strs.Add(ff_str.StandardOutput.ReadLine()); - } - ff_str.WaitForExit(); - - foreach (String str in strs) - { - if (ftype == "video_bitrate") - { - int test = 0; - if (str != null) - { - if (Int32.TryParse(str, out test)) - { - test = Int32.Parse(str); - } - else test = 0; - } - else - { - test = 0; - } - - Int32 filter_value = Int32.Parse(form4.filter_value); - - if (filter_value * 1000 <= test) - { - match = true; - break; - } - else match = false; - } - - if (ftype == "frame_rate") - { - if (str != null) - { - if (str.Length > 0) - { - if (form4.filter_value.Length <= 2) form4.filter_value = form4.filter_value + "."; - if (str.Contains(form4.filter_value)) - { - match = true; - break; - - } - else match = false; - } - else - { - match = false; - } - } - } - - if (ftype.Contains("frame_size")) - { - if (str != null) - { - if (str.ToLower().Contains("x")) - { - if (form4.filter_value == str && str != String.Empty) - { - match = true; - break; - } - else match = false; - } - else match = false; - } - else match = false; - } - - if (ftype.Contains("custom_mi")) - { - if (str != null) - { - if (str.ToLower().Contains(form4.filter_value.ToLower())) - { - match = true; - break; - } - else match = false; - } - else match = false; - } - - if (ftype.Contains("metadata")) - { - if (str.ToLower().Contains(form4.filter_value.ToLower())) - { - match = true; - break; - } - } - } - - Boolean to_remove = false; - - if (match == true && form4.filter_action == Strings.remove) to_remove = true; - if (match == true && form4.filter_action == Strings.keep) to_remove = false; - if (match == false && form4.filter_action == Strings.remove) to_remove = false; - if (match == false && form4.filter_action == Strings.keep) to_remove = true; - - if (to_remove == true) - { - listView1.Invoke(new MethodInvoker(delegate - { - listView1.Items[n].Text = Strings.remove; - })); - - //sel_filter.Add(n); - return true; - } - else return false; - } - - Boolean match_filter_ff(String exe, String param, String filter, String ftype, int n) - { - String select_stream = form4.stream_n; - - Boolean has_video_stream = false; - Boolean has_video_first_stream = false; - Boolean has_streams = false; - Boolean is_video = false; - - if (form4.stream_n == Strings.f_str) select_stream = "Stream #0:0"; - if (form4.stream_n == Strings.s_str) select_stream = "Stream #0:1"; - if (form4.stream_n == Strings.any_str) select_stream = "Stream #"; - - Process ff_str = new Process(); - ff_str.StartInfo.RedirectStandardError = true; - ff_str.StartInfo.UseShellExecute = false; - ff_str.StartInfo.CreateNoWindow = true; - ff_str.EnableRaisingEvents = true; - ff_str.StartInfo.FileName = exe; - ff_str.StartInfo.Arguments = param; - - Boolean match = false; - List strs = new List(); - ff_str.Start(); - - while (!ff_str.StandardError.EndOfStream) - { - strs.Add(ff_str.StandardError.ReadLine()); - } - ff_str.WaitForExit(); - - foreach (String line in strs) - { - if (line.ToLower().Contains("invalid data")) has_streams = false; - if (line.Contains("Stream #")) has_streams = true; - if (line.Contains("Stream #") == true && line.Contains("Video:") == true) has_video_stream = true; - if (line.Contains("Stream #0:0") == true && line.Contains("Video:") == true) has_video_first_stream = true; - - if (select_stream == "Stream #0:0" && line.Contains(select_stream)) - { - has_streams = true; - if (line.ToLower().Contains(form4.filter_value)) - { - match = true; - } - else - { - match = false; - } - break; - } - - if (select_stream == "Stream #0:1" && line.Contains(select_stream)) - { - has_streams = true; - - if (line.ToLower().Contains(form4.filter_value)) - { - match = true; - } - else - { - match = false; - } - break; - } - - if (select_stream == ("Stream #") && line.ToLower().Contains("stream #")) - { - has_streams = true; - if (line.ToLower().Contains(form4.filter_value)) - { - match = true; - break; - } - } - } - - Boolean to_remove = false; - - if (match == true && form4.filter_action == Strings.remove) to_remove = true; - if (match == true && form4.filter_action == Strings.keep) to_remove = false; - if (match == false && form4.filter_action == Strings.remove) to_remove = false; - if (match == false && form4.filter_action == Strings.keep) to_remove = true; - - if (ftype == "video_codec") - { - if (has_video_first_stream == false && form4.remove_not_video == true) to_remove = true; - } - - if (to_remove == true || has_streams == false) - { - listView1.Invoke(new MethodInvoker(delegate - { - listView1.Items[n].Text = Strings.remove; - })); - - //sel_filter.Add(n); - return true; - } - else return false; - } - private void end_bg_filters() - { - Enable_Controls(); - - this.Invoke(new MethodInvoker(delegate - { - sel_filter.Clear(); - btn_cancel_add.Visible = false; - txt_adding_p.Visible = false; - pg_adding.Visible = false; - lbl_items.Visible = true; - lbl_items.Text = listView1.Items.Count.ToString() + " " + Strings.files; - lbl_items.Refresh(); - lbl_dur_list.Visible = true; - lbl_dur_list.Refresh(); - lbl_size.Visible = true; - lbl_size.Refresh(); - })); - calc_list_dur(); - calc_list_size(); - } - - private void timer_adding_Tick(object sender, EventArgs e) - { - start_total_time = start_total_time + 1; - time_n_tasks = time_n_tasks + 1; - this.InvokeEx(f => f.txt_add_remain.Text = Strings.remain_time); - this.InvokeEx(f => f.txt_add_remain.Refresh()); - - try - { - if (Convert.ToUInt16(txt_adding_p.Text.Replace("%", "")) > 1 || start_total_time > 9) - { - this.InvokeEx(f => f.txt_add_remain.Visible = true); - Double remain_secs = time_n_tasks * 100 / Convert.ToUInt16(txt_adding_p.Text.Replace("%", "")) - start_total_time; - //Double remain_secs = start_total_time; - String remain_string = String.Empty; - - TimeSpan t = TimeSpan.FromSeconds(remain_secs); - remain_string = string.Format("{0:D2}h:{1:D2}", - t.Hours, - t.Minutes); - - if (remain_secs >= 43200) - { - this.InvokeEx(f => f.txt_add_remain.Text = Strings.remain_time + " " + Math.Round(remain_secs / 3600).ToString() + " " + Strings.hours); - } - - if (remain_secs >= 3600 && remain_secs < 43200) - { - this.InvokeEx(f => f.txt_add_remain.Text = Strings.remain_time + " " + remain_string + " " + Strings.minutes_abrev); - } - - if (remain_secs < 3600 && remain_secs >= 600) - { - this.InvokeEx(f => f.txt_add_remain.Text = Strings.remain_time + " " + remain_string.Substring(remain_string.LastIndexOf(":") + 1, 2) + " " + Strings.minutes); - } - if (remain_secs < 600 && remain_secs >= 120) - { - this.InvokeEx(f => f.txt_add_remain.Text = Strings.remain_time + " " + remain_string.Substring(remain_string.LastIndexOf(":") + 2, 1) + " " + Strings.minutes); - } - - if (remain_secs < 120 && remain_secs > 59) - { - this.InvokeEx(f => f.txt_add_remain.Text = Strings.remain_time + " " + Strings.about_1); - } - - if (remain_secs <= 59) - { - this.InvokeEx(f => f.txt_add_remain.Text = Strings.remain_time + " " + Strings.less_one); - } - if (remain_secs <= 0) - { - this.InvokeEx(f => f.txt_add_remain.Text = Strings.remain_time + " " + Strings.almost_done); - } - this.InvokeEx(f => f.txt_remain.Refresh()); - } - else - { - this.InvokeEx(f => f.txt_add_remain.Text = Strings.remain_time + " " + Strings.calcul); - this.InvokeEx(f => f.txt_add_remain.Refresh()); - } - } - catch - { - this.InvokeEx(f => f.txt_add_remain.Text = Strings.remain_time + " " + Strings.calcul); - this.InvokeEx(f => f.txt_add_remain.Refresh()); - } - this.InvokeEx(f => f.txt_add_remain.Refresh()); - } - - private void toolStripMenuItem6_Click(object sender, EventArgs e) - { - - Form5 frm5 = new Form5(); - frm5.lv1_item = listView2.SelectedItems[0].Text; - current_fr = 0; - if (btn_change_ff.Text.ToLower().Contains("full")) frm5.ff_ess = false; - else frm5.ff_ess = false; - frm5.ShowDialog(); - } - - private void toolStripMenuItem7_Click(object sender, EventArgs e) - { - if (listView1.Items.Count == 1) listView1.Items[0].Selected = true; - cti4.PerformClick(); - } - - private void toolStripMenuItem5_Click(object sender, EventArgs e) - { - Process.Start("https://sourceforge.net/p/ffmpeg-batch/news/"); - } - - private void toolStripMenuItem9_Click(object sender, EventArgs e) - { - btn_multiple_presets.PerformClick(); - } - - private void ct1_streams_Click(object sender, EventArgs e) - { - main_menu_streams.PerformClick(); - } - - private void BG_Try_twopass_DoWork(object sender, DoWorkEventArgs e) - { - tried_ok = false; - if (chk_try.CheckState == CheckState.Checked) - { - tried_ok = true; - return; - } - - two_try_fail = false; - this.InvokeEx(f => this.Cursor = Cursors.WaitCursor); - ListBox LB1_o = new ListBox(); - Process consola_pre = new Process(); - String file_prueba = ""; - String sel_test = ""; - listView1.Invoke(new MethodInvoker(delegate - { - if (listView1.SelectedIndices.Count == 1) this.InvokeEx(f => sel_test = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text); - else this.InvokeEx(f => sel_test = listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text); - })); - - file_prueba = sel_test; - String destino_test = Path.GetTempPath() + "\\" + "FFBatch_test"; - Boolean bad_chars = false; - Boolean unsupported = false; - - Task tt = Task.Run(() => - { - String fichero = Path.GetFileName(file_prueba); - - if (!Directory.Exists(destino_test)) - { - try - { - Directory.CreateDirectory(destino_test); - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.error2 + " " + excpt.Message, Strings.write_error2, MessageBoxButtons.OK, MessageBoxIcon.Error); - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - return; - } - } - - String ext_output = "nul"; - - textbox_params = multi_1st_pass; - String templog = Path.GetTempPath() + "\\" + "FF_pass2.log"; - consola_pre.StartInfo.FileName = "ffmpeg.exe"; - consola_pre.StartInfo.Arguments = hw_decode_glob + " -i " + "" + '\u0022' + file_prueba + '\u0022' + " -t 00:00:0.250 " + textbox_params + " -y -passlogfile " + '\u0022' + templog + '\u0022' + " " + ext_output; - consola_pre.StartInfo.RedirectStandardError = true; - consola_pre.StartInfo.UseShellExecute = false; - consola_pre.StartInfo.CreateNoWindow = true; - consola_pre.EnableRaisingEvents = true; - consola_pre.Start(); - - while (!consola_pre.StandardError.EndOfStream) - { - this.InvokeEx(f => LB1_o.Items.Add(consola_pre.StandardError.ReadLine())); - this.InvokeEx(f => LB1_o.TopIndex = LB1_o.Items.Count - 1); - this.InvokeEx(f => LB1_o.Refresh()); - } - - consola_pre.WaitForExit(); - consola_pre.StartInfo.Arguments = String.Empty; - }); - - if (!tt.Wait(2500) && consola_pre.StartInfo.Arguments != String.Empty) - { - consola_pre.Kill(); - tried_ok = true; - two_try_fail = false; - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - - if (Directory.Exists(destino_test) && Directory.GetFiles(destino_test).Length > 0) - { - foreach (String file in Directory.GetFiles(destino_test)) - { - try - { - File.Delete(file); - } - catch - { - } - } - } - - if (Directory.GetFiles(destino_test).Length == 0) - { - Directory.Delete(destino_test); - } - LB1_o.Items.Clear(); - tried_params.Add(txt_parameters.Text); - return; - } - - if (bad_chars == false) - { - if (consola_pre.ExitCode != 0) - { - two_try_fail = true; - tried_ok = false; - if (Directory.Exists(destino_test) && Directory.GetFiles(destino_test).Length > 0) - { - foreach (String file in Directory.GetFiles(destino_test)) - { - try - { - File.Delete(file); - } - catch - { - } - } - } - - if (Directory.GetFiles(destino_test).Length == 0) - { - Directory.Delete(destino_test); - } - - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - foreach (String lin in LB1_o.Items) - { - if (lin.Contains("not load the requested plugin") || lin.Contains("Cannot load nvcuda.dll")) - { - unsupported = true; - } - } - if (unsupported == true) MessageBox.Show(Strings.fail_1stp + " " + Environment.NewLine + Environment.NewLine + Strings.unsup_enc + Environment.NewLine + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 4].ToString() + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 3].ToString() + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 2].ToString() + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 1].ToString() + Environment.NewLine + Environment.NewLine + Strings.try_pr, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - else MessageBox.Show(Strings.fail_1stp + " " + Environment.NewLine + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 4].ToString() + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 3].ToString() + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 2].ToString() + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 1].ToString() + Environment.NewLine + Environment.NewLine + Strings.try_pr, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - tried_ok = false; - return; - } - else - { - tried_params.Add(multi_two_pr1); - } - } - //END try preset - - LB1_o.Items.Clear(); - consola_pre.Dispose(); - } - - private void BG_Try_twopass_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) - { - if (two_try_fail == false) BG_Try_Two_Final.RunWorkerAsync(); - } - - private void BG_Try_Two_Final_DoWork(object sender, DoWorkEventArgs e) - { - tried_ok = false; - if (chk_try.CheckState == CheckState.Checked) - { - tried_ok = true; - return; - } - - this.InvokeEx(f => this.Cursor = Cursors.WaitCursor); - ListBox LB1_o = new ListBox(); - Process consola_pre = new Process(); - String file_prueba = ""; - String sel_test = ""; - listView1.Invoke(new MethodInvoker(delegate - { - if (listView1.SelectedIndices.Count == 1) this.InvokeEx(f => sel_test = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text); - else this.InvokeEx(f => sel_test = listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text); - })); - - file_prueba = sel_test; - String destino_test = Path.GetTempPath() + "\\" + "FFBatch_test"; - Boolean bad_chars = false; - Boolean unsupported = false; - - Task tt = Task.Run(() => - { - String fichero = Path.GetFileName(file_prueba); - - if (!Directory.Exists(destino_test)) - { - try - { - Directory.CreateDirectory(destino_test); - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.error2 + " " + excpt.Message, Strings.write_error2, MessageBoxButtons.OK, MessageBoxIcon.Error); - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - return; - } - } - - String ext_output = multi_two_ext; - if (txt_format.Text == String.Empty) - { - ext_output = Path.GetExtension(file_prueba); - } - else - { - ext_output = "." + multi_two_ext; - } - - textbox_params = multi_two_pr1; - String file_prueba2 = file_prueba; - - if (textbox_params.Contains("%fn")) - { - textbox_params = textbox_params.Replace("%fn", Path.GetFileNameWithoutExtension(file_prueba)); - } - if (textbox_params.Contains("%fp")) - { - textbox_params = textbox_params.Replace("%fp", Path.GetDirectoryName(file_prueba)); - } - if (textbox_params.Contains("%fd")) - { - var dirName = new DirectoryInfo(Path.GetDirectoryName(file_prueba)).Name; - textbox_params = textbox_params.Replace("%fd", dirName); - } - - if (textbox_params.Contains("%1")) - { - if (file_prueba2.Contains("[") || file_prueba2.Contains("]")) - { - MessageBox.Show(Strings.conflict_char, Strings.conflict_char2, MessageBoxButtons.OK, MessageBoxIcon.Warning); - Enable_Controls(); - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - tried_ok = false; - bad_chars = true; - return; - } - file_prueba2 = file_prueba2.Replace("\\", "\\\\\\\\"); - file_prueba2 = file_prueba2.Replace(":", ":" + "\\\\"); - textbox_params = textbox_params.Replace("%1", file_prueba2); - } - - while (textbox_params.Contains("%pff")) - { - if (textbox_params.Contains("%pff")) - { - file_prueba2 = file_prueba2.Replace("\\", "/\\"); - file_prueba2 = file_prueba2.Replace(":", "\\\\://\\"); - - textbox_params = textbox_params.Replace("%pff", Path.GetDirectoryName(file_prueba2)); - } - } - - while (textbox_params.Contains("%f1")) - { - if (textbox_params.Contains("%f1")) - { - file_prueba2 = file_prueba2.Replace("\\", "/\\"); - file_prueba2 = file_prueba2.Replace(":", "\\\\:"); - - textbox_params = textbox_params.Replace("%f1", file_prueba2); - } - } - - while (textbox_params.Contains("%f2")) - { - if (textbox_params.Contains("%f2")) - { - file_prueba2 = file_prueba2.Replace("\\", "/\\"); - file_prueba2 = file_prueba2.Replace(":", "\\\\://\\"); - textbox_params = textbox_params.Replace("%f2", Path.Combine(Path.GetDirectoryName(file_prueba2), Path.GetFileNameWithoutExtension(file_prueba2))); - } - } - - String templog = Path.GetTempPath() + "\\" + "FF_pass2.log"; - consola_pre.StartInfo.FileName = "ffmpeg.exe"; - consola_pre.StartInfo.Arguments = hw_decode_glob + " -y -i " + "" + '\u0022' + file_prueba + '\u0022' + " -t 00:00:0.250 " + "-y " + textbox_params + " -passlogfile " + '\u0022' + templog + '\u0022' + " " + '\u0022' + destino_test + "\\" + Path.GetFileNameWithoutExtension(file_prueba) + ext_output + '\u0022'; - consola_pre.StartInfo.RedirectStandardError = true; - consola_pre.StartInfo.UseShellExecute = false; - consola_pre.StartInfo.CreateNoWindow = true; - consola_pre.EnableRaisingEvents = true; - consola_pre.Start(); - - while (!consola_pre.StandardError.EndOfStream) - { - this.InvokeEx(f => LB1_o.Items.Add(consola_pre.StandardError.ReadLine())); - this.InvokeEx(f => LB1_o.TopIndex = LB1_o.Items.Count - 1); - this.InvokeEx(f => LB1_o.Refresh()); - } - - consola_pre.WaitForExit(); - consola_pre.StartInfo.Arguments = String.Empty; - }); - - if (!tt.Wait(2500) && consola_pre.StartInfo.Arguments != String.Empty) - { - consola_pre.Kill(); - tried_ok = true; - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - - if (Directory.Exists(destino_test) && Directory.GetFiles(destino_test).Length > 0) - { - foreach (String file in Directory.GetFiles(destino_test)) - { - try - { - File.Delete(file); - } - catch - { - } - } - } - - if (Directory.GetFiles(destino_test).Length == 0) - { - Directory.Delete(destino_test); - } - LB1_o.Items.Clear(); - tried_params.Add(txt_parameters.Text); - return; - } - - if (bad_chars == false) - { - if (consola_pre.ExitCode != 0) - { - if (Directory.Exists(destino_test) && Directory.GetFiles(destino_test).Length > 0) - { - foreach (String file in Directory.GetFiles(destino_test)) - { - try - { - File.Delete(file); - } - catch - { - } - } - } - - if (Directory.GetFiles(destino_test).Length == 0) - { - Directory.Delete(destino_test); - } - - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - foreach (String lin in LB1_o.Items) - { - if (lin.Contains("not load the requested plugin") || lin.Contains("Cannot load nvcuda.dll")) - { - unsupported = true; - } - } - if (unsupported == true) MessageBox.Show(Strings.fail_2ndp + " " + Environment.NewLine + Environment.NewLine + Strings.unsup_enc + Environment.NewLine + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 4].ToString() + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 3].ToString() + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 2].ToString() + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 1].ToString() + Environment.NewLine + Environment.NewLine + Strings.try_pr, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - else MessageBox.Show(Strings.fail_2ndp + " " + Environment.NewLine + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 4].ToString() + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 3].ToString() + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 2].ToString() + Environment.NewLine + LB1_o.Items[LB1_o.Items.Count - 1].ToString() + Environment.NewLine + Environment.NewLine + Strings.try_pr, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - tried_ok = false; - return; - } - else - { - System.Threading.Thread.Sleep(50); - if (Directory.Exists(destino_test) && Directory.GetFiles(destino_test).Length > 0) - { - foreach (String file in Directory.GetFiles(destino_test)) - { - try - { - File.Delete(file); - } - catch - { - } - } - } - - if (Directory.Exists(destino_test) && Directory.GetFiles(destino_test).Length == 0) - { - Directory.Delete(destino_test); - } - tried_params.Add(txt_parameters.Text); - tried_ok = true; - } - } - //END try preset - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - - if (Directory.Exists(destino_test)) - { - if (Directory.GetFiles(destino_test).Length == 0) - { - Directory.Delete(destino_test); - } - } - LB1_o.Items.Clear(); - consola_pre.Dispose(); - } - - private void BG_Try_Two_Final_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) - { - String file_prueba = ""; - String sel_test = String.Empty; - listView1.Invoke(new MethodInvoker(delegate - { - if (listView1.SelectedIndices.Count == 1) this.InvokeEx(f => sel_test = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text); - else this.InvokeEx(f => sel_test = listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text); - })); - file_prueba = sel_test; - String destino = Path.Combine(Path.GetTempPath(), "FFBatch_test"); - String borrar = destino + "\\" + Path.GetFileNameWithoutExtension(file_prueba) + "." + txt_format.Text; - - if (File.Exists(borrar)) - { - try - { - File.Delete(borrar); - } - catch - { - } - } - - if (Directory.Exists(destino) == true) - { - if (Directory.GetFiles(destino).Length == 0) - { - Directory.Delete(destino); - } - } - - if (tried_ok == true) two_pass_encoding(); - } - - private void menu_two_pass_wizard_Click(object sender, EventArgs e) - { - if (!File.Exists(Path.Combine(Application.StartupPath, "ffmpeg.exe"))) - { - MessageBox.Show(Strings.no_ffmpeg, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - String ffm = Path.Combine(Application.StartupPath, "AeroWizard.dll"); - if (!File.Exists(ffm)) - { - MessageBox.Show(Strings.no_aerowiz, Strings.required_file, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (listView1.Items.Count == 0) - { - MessageBox.Show(Strings.list_empty, Strings.no_files, MessageBoxButtons.OK, MessageBoxIcon.Information); - return; - } - - foreach (ListViewItem file2 in listView1.Items) - { - if (!File.Exists(file2.SubItems[1].Text + "\\" + file2.Text)) - { - MessageBox.Show(Strings.file_not_found + " " + file2.Text, Strings.file_not_f, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - - String is_overw = txt_path_main.Text + "\\" + Path.GetFileNameWithoutExtension(listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text) + "." + txt_format.Text; - - if (is_overw == listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text && chk_suffix.Checked == false) - { - MessageBox.Show(Strings.overw_not_en + " " + '\u0022' + Strings.ren_out + '\u0022' + " " + Strings.checkb, Strings.overw_not_all, MessageBoxButtons.OK, MessageBoxIcon.Error); - - return; - } - DateTime time2; - if (!DateTime.TryParse(ss_time_input.Text, out time2)) - { - MessageBox.Show(Strings.pre_input1, Strings.pre_input2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (ss_time_input.Text != "0:00:00") - { - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[3].Text != Strings.n_a && item.SubItems[3].Text != "0:00:00" && item.SubItems[3].Text != "00:00:00" && item.SubItems[3].Text != Strings.pending && Settings.Default.quick_queue == false) - { - if (TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds <= TimeSpan.Parse(ss_time_input.Text).TotalSeconds) - { - MessageBox.Show(Strings.pre_input3 + " " + '\u0022' + Path.GetFileName(item.Text) + '\u0022', Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - } - } - - DateTime time; - if (!DateTime.TryParse(ss_time_input.Text, out time)) - { - MessageBox.Show(Strings.pre_input1, Strings.pre_input2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - avoid_overw(); - - if (avoid_overwriting == true && txt_path_main.Text.Contains(".\\") == false && txt_path_main.Text.Length < 4 && chk_recreate.CheckState != CheckState.Checked) - { - avoid_overwriting = false; - DialogResult a2 = MessageBox.Show(Strings.multiple_folders + " " + '\u0022' + Strings.recreate_path + '\u0022' + " " + Strings.avoid_overw + Environment.NewLine + Environment.NewLine + Strings.continu, Strings.warning, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); - if (a2 == DialogResult.No) return; - } - - //Check path is writable - String destino1 = String.Empty; - Boolean rel_path = false; - if (txt_path_main.Text.Contains(".\\")) - { - String destino0 = listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text; - destino1 = destino0.Substring(0, destino0.LastIndexOf('\\')) + txt_path_main.Text.Replace(".", String.Empty); - rel_path = true; - } - else - { - if (chk_recreate.CheckState == CheckState.Checked) - { - String pre_dest = listView1.Items[0].SubItems[1].Text; - destino1 = Path.Combine(txt_path_main.Text, pre_dest.Substring(3, pre_dest.Length - 3)); - rel_path = true; - } - else - { - destino1 = txt_path_main.Text; - } - } - - try - { - if (rel_path == true) - { - Directory.CreateDirectory(destino1); - System.Threading.Thread.Sleep(10); - } - else - { - File.WriteAllText(destino1 + "\\" + "FFBatch_test.txt", "FFBatch_test"); - System.Threading.Thread.Sleep(10); - File.Delete(destino1 + "\\" + "FFBatch_test.txt"); - } - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.write_error1 + " " + excpt.Message, Strings.write_error2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - //End path is writable - - //Wizard - AeroWizard3 wizard3 = new AeroWizard3(); - wizard3.StartPosition = FormStartPosition.CenterScreen; - - if (listView1.SelectedIndices.Count == 1) - { - wizard3.lv1_item = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - } - else - { - wizard3.lv1_item = listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text; - } - wizard3.pr1_string_two_params = multi_two_pr1; - wizard3.pr1_string_two_ext = multi_two_ext; - if (saved_pres_two.Length > 0) - { - wizard3.saved_pres = saved_pres_two; - } - if (saved_ext_two.Length > 0) - { - wizard3.saved_ext = saved_ext_two; - } - - wizard3.ShowDialog(); - saved_pres_two = wizard3.saved_pres; - saved_ext_two = wizard3.saved_ext; - - if (wizard3.cancelled_w == true) return; - - multi_1st_pass = wizard3.pr1_first_params; - multi_two_pr1 = wizard3.pr1_string_two_params; - multi_two_ext = wizard3.pr1_string_two_ext; - - if (wizard3.is_target) - { - target_size = true; - target_mb = (int)wizard3.n_target_size.Value; - if (wizard3.combo_size.SelectedIndex == 1) target_mb = target_mb * 1000; - target_codec = wizard3.combo_codec_t.SelectedItem.ToString(); - target_profile = wizard3.profile_target.SelectedItem.ToString(); - target_aud_cod = wizard3.combo_audio_target.SelectedItem.ToString(); - target_aud_bit = (int)wizard3.num_aud_target.Value; - target_one_pass = wizard3.chk_one_pass.Checked; - } - else target_size = false; - - if (tried_ok == false && Settings.Default.quick_queue == false && wizard3.is_target == false) - { - try - { - BG_Try_twopass.RunWorkerAsync(); - } - catch - { - tried_ok = true; - } - return; - } - tried_ok = false; - - //Remove test file/folder - - String file_prueba = ""; - String sel_test = String.Empty; - if (listView1.SelectedIndices.Count == 1) sel_test = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - else sel_test = listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text; - file_prueba = sel_test; - String destino = Path.GetTempPath() + "\\" + "FFBatch_test"; - String borrar = destino + "\\" + Path.GetFileNameWithoutExtension(file_prueba) + "." + txt_format.Text; - - if (File.Exists(borrar)) - { - try - { - File.Delete(borrar); - } - catch - { - } - } - - if (Directory.Exists(destino) == true) - { - if (Directory.GetFiles(destino).Length == 0) - { - Directory.Delete(destino); - } - } - - //END Remove test file/folder - two_pass_encoding(); - } - - private void btn_try_pr_Click(object sender, EventArgs e) - { - Pg1.Focus(); - if (!File.Exists(Path.Combine(Application.StartupPath, "ffmpeg.exe"))) - { - MessageBox.Show(Strings.no_ffmpeg, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (listView1.Items.Count == 0) - { - MessageBox.Show(Strings.one_try, Strings.list_bl, MessageBoxButtons.OK, MessageBoxIcon.Information); - return; - } - - if (listView1.SelectedIndices.Count == 0) - { - listView1.Items[0].Selected = true; - listView1.Items[0].Focused = true; - listView1.Focus(); - } - - if (cb_hwdecode.SelectedItem.ToString() != "none") - { - hw_decode_glob = "-hwaccel " + cb_hwdecode.SelectedItem.ToString(); - } - filter_chars(); - BG_Try_button.RunWorkerAsync(); - } - - public void CopyCache() - { - this.Invoke(new MethodInvoker(delegate - { - btn_abort_all.Enabled = false; - btn_skip_main.Enabled = false; - btn_pause.Enabled = false; - txt_adding_p.Visible = true; - pg_adding.Maximum = 100; - pg_adding.Minimum = 0; - pg_adding.Value = 0; - pg_adding.Style = ProgressBarStyle.Continuous; - pg_adding.Visible = true; - pg_adding.Enabled = true; - pg_adding.Refresh(); - LB_Wait.Visible = true; - LB_Wait.Text = Strings.caching_f; - LB_Wait.Refresh(); - btn_cancel_add.Visible = true; - btn_cancel_add.Enabled = true; - btn_cancel_add.Refresh(); - wc.Headers.Clear(); - wc.Dispose(); - })); - - net_speed(); - Boolean already_cached = false; - if (File.Exists(Path.Combine(Path.GetTempPath(), "FFBatch_test", Path.GetFileName(file_to_copy)))) - { - FileInfo fi = new FileInfo(Path.Combine(Path.GetTempPath(), "FFBatch_test", Path.GetFileName(file_to_copy))); - FileInfo fi2 = new FileInfo(file_to_copy); - if (fi.Length == fi2.Length) - { - already_cached = true; - cached = true; - this.Invoke(new MethodInvoker(delegate - { - pg_adding.Visible = false; - txt_add_remain.Visible = false; - LB_Wait.Visible = false; - btn_cancel_add.Visible = false; - txt_adding_p.Visible = false; - txt_add_remain.Visible = false; - txt_add_remain.Enabled = false; - btn_abort_all.Enabled = true; - btn_skip_main.Enabled = true; - btn_pause.Enabled = true; - })); - } - else - { - already_cached = false; - } - } - if (already_cached == false) - { - Task t = Task.Run(() => - { - this.InvokeEx(f => wc.DownloadFileAsync(new System.Uri(file_to_copy), Path.Combine(Path.GetTempPath(), "FFBatch_test", Path.GetFileName(file_to_copy)))); - }); - t.Wait(); - } - } - - public void Extract(object sender, AsyncCompletedEventArgs e) - { - cached = true; - this.Invoke(new MethodInvoker(delegate - { - pg_adding.Visible = false; - txt_add_remain.Visible = false; - LB_Wait.Visible = false; - btn_cancel_add.Visible = false; - txt_adding_p.Visible = false; - txt_add_remain.Visible = false; - txt_add_remain.Enabled = false; - btn_abort_all.Enabled = true; - btn_skip_main.Enabled = true; - btn_pause.Enabled = true; - })); - - - if (e.Cancelled == true) - { - try - { - File.Delete(Path.Combine(Path.GetTempPath(), "FFBatch_test", Path.GetFileName(file_to_copy)).Replace("\\\\", "\\")); - } - catch { } - } - } - - private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e) - { - this.Invoke(new MethodInvoker(delegate - { - pg_adding.Value = e.ProgressPercentage; - pg_adding.Refresh(); - txt_adding_p.Text = e.ProgressPercentage.ToString() + "%"; - txt_adding_p.Refresh(); - })); - } - - private void pictureBox1_DoubleClick(object sender, EventArgs e) - { - menu_about.PerformClick(); - } - - private void net_speed() - { - int i_net = 0; - float current = 0; - float accum = 0; - String data = String.Empty; - Boolean valid = false; - - Task t = Task.Run(() => - { - this.InvokeEx(f => f.txt_add_remain.Text = String.Empty); - - while (cached == false) - { - Thread.Sleep(2000); - i_net = i_net + 1; - try - { - PerformanceCounter pc = new PerformanceCounter("Process", "IO Data Bytes/sec", "FFbatch"); - current = pc.NextValue(); - } - catch { } - - accum = accum + current; - try - { - data = Math.Round(Convert.ToDecimal(accum / 2 / 1048576 / i_net), 2).ToString(); - valid = true; - } - catch - { - valid = false; - } - if (valid == true && data != "0") - { - this.InvokeEx(f => f.txt_add_remain.Text = Strings.avg_transf + " " + data + " MB/s"); - } - else - { - this.InvokeEx(f => f.txt_add_remain.Text = String.Empty); - } - this.InvokeEx(f => f.txt_add_remain.Refresh()); - } - }); - } - - private void ct1_total_frames_Click(object sender, EventArgs e) - { - String file = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - String ff_frames = String.Empty; - String ff_rate = String.Empty; - String ff_dur = String.Empty; - Decimal tot_frames = 0; - Decimal ff_rate_dec = 0; - Decimal ff_dur_dec = 0; - this.Cursor = Cursors.WaitCursor; - Task t = Task.Run(() => - { - Process get_frames = new Process(); - get_frames.StartInfo.FileName = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - String ffprobe_frames = " " + '\u0022' + "--Inform=Video;%FrameCount%,%FrameRate%" + '\u0022'; - get_frames.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + file + '\u0022'; - get_frames.StartInfo.RedirectStandardOutput = true; - get_frames.StartInfo.UseShellExecute = false; - get_frames.StartInfo.CreateNoWindow = true; - get_frames.EnableRaisingEvents = true; - get_frames.Start(); - - while (!get_frames.StandardOutput.EndOfStream) - { - ff_frames = get_frames.StandardOutput.ReadLine(); - } - get_frames.WaitForExit(); - - try - { - int ff_rate_1 = ff_frames.IndexOf(","); - ff_rate = ff_frames.Substring(ff_frames.IndexOf(",") + 1, ff_frames.Length - ff_rate_1 - 1); - ff_frames = ff_frames.Substring(0, ff_frames.IndexOf(",")); - } - catch - { - ff_frames = null; - ff_rate = null; - } - - if (get_frames.ExitCode == 0) - { - if (ff_frames != null) - { - try - { - tot_frames = decimal.Parse(ff_frames) / 1000; - } - catch - { - tot_frames = 0; - ff_rate_dec = 0; - } - } - else - { - tot_frames = 0; - ff_rate_dec = 0; - } - if (ff_rate != null) - { - try - { - ff_rate_dec = decimal.Parse(ff_rate); - } - catch - { - tot_frames = 0; - ff_rate_dec = 0; - } - } - else - { - tot_frames = 0; - ff_rate_dec = 0; - } - } - else - { - tot_frames = 0; - ff_rate_dec = 0; - ff_dur_dec = 0; - } - - if (ff_rate_dec == 0) - { - List strs = new List(); - get_frames.StartInfo.FileName = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - get_frames.StartInfo.Arguments = "-an -sn -dn -i " + '\u0022' + file + '\u0022' + " -hide_banner"; - get_frames.StartInfo.RedirectStandardError = true; - get_frames.Start(); - - while (!get_frames.StandardError.EndOfStream) - { - strs.Add(get_frames.StandardError.ReadLine()); - } - get_frames.WaitForExit(); - - foreach (String str in strs) - { - if (str != null) - { - if (str.Contains("Stream #") && str.Contains("fps,")) - { - String[] split = str.Split(','); - foreach (String st in split) - { - if (st.Contains("fps")) - { - Decimal test = 0; - String fps = st.Replace("fps", "").TrimEnd(); - if (Decimal.TryParse(fps, out test)) - { - if (CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",") fps = fps.Replace(".", ","); - ff_rate_dec = decimal.Parse(fps); - ff_rate = ff_rate_dec.ToString(); - break; - } - else ff_rate_dec = 0; - break; - } - } - break; - } - } - } - } - - Process get_frames2 = new Process(); - get_frames2.StartInfo.FileName = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - ffprobe_frames = " " + '\u0022' + "--Inform=General;%Duration%" + '\u0022'; - get_frames2.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + file + '\u0022'; - get_frames2.StartInfo.RedirectStandardOutput = true; - get_frames2.StartInfo.UseShellExecute = false; - get_frames2.StartInfo.CreateNoWindow = true; - get_frames2.EnableRaisingEvents = true; - get_frames2.Start(); - - ff_dur = get_frames2.StandardOutput.ReadLine(); - - get_frames2.WaitForExit(); - - if (get_frames2.ExitCode == 0) - { - if (ff_dur != null) - { - try - { - ff_dur_dec = decimal.Parse(ff_dur) / 1000; - } - catch - { - ff_dur_dec = 0; - } - } - else - { - ff_dur_dec = 0; - } - } - }); - - if (!t.Wait(10000)) - { - this.Cursor = Cursors.Arrow; - return; - } - - if (tot_frames == 0 && ff_rate_dec > 0 && ff_dur_dec > 0) tot_frames = Math.Round((ff_rate_dec * ff_dur_dec), 0); - - this.Cursor = Cursors.Arrow; - Form frmInfo = new Form(); - frmInfo.Name = Strings.mstats; - frmInfo.Text = Strings.mstats; - frmInfo.Icon = this.Icon; - frmInfo.Height = 228; - frmInfo.Width = 336; - frmInfo.FormBorderStyle = FormBorderStyle.Fixed3D; - frmInfo.MaximizeBox = false; - frmInfo.MinimizeBox = false; - frmInfo.BackColor = this.BackColor; - - TextBox titulo2 = new TextBox(); - titulo2.Parent = frmInfo; - titulo2.Top = 12; - titulo2.Left = 9; - titulo2.Width = 293; - titulo2.BackColor = this.BackColor; - titulo2.BorderStyle = BorderStyle.None; - titulo2.TextAlign = HorizontalAlignment.Center; - titulo2.ReadOnly = true; - titulo2.TabIndex = 2; - titulo2.Text = Path.GetFileName(listView1.SelectedItems[0].Text); - - Label line = new Label(); - line.Parent = frmInfo; - line.Left = 0; - line.Top = 41; - line.Height = 2; - line.BorderStyle = BorderStyle.Fixed3D; - line.Width = 336; - - Label line2 = new Label(); - line2.Parent = frmInfo; - line2.Left = 0; - line2.Top = 136; - line2.Height = 2; - line2.BorderStyle = BorderStyle.Fixed3D; - line2.Width = 336; - - Button boton_ok_st = new Button(); - boton_ok_st.Parent = frmInfo; - boton_ok_st.Left = 85; - boton_ok_st.Top = 148; - boton_ok_st.Width = 145; - boton_ok_st.Height = 27; - boton_ok_st.Text = Strings.close; - boton_ok_st.TabIndex = 0; - boton_ok_st.Click += new EventHandler(boton_ok_st_Click); - frmInfo.CancelButton = boton_ok_st; - - Label lbl_frm_rate = new Label(); - lbl_frm_rate.Parent = frmInfo; - lbl_frm_rate.Left = 20; - lbl_frm_rate.Top = 55; - lbl_frm_rate.Width = 90; - lbl_frm_rate.Text = Strings.fr_rate + ":"; - - Label lbl_frm_rate2 = new Label(); - lbl_frm_rate2.Parent = frmInfo; - lbl_frm_rate2.Left = 123; - lbl_frm_rate2.Top = 55; - lbl_frm_rate2.Width = 110; - if (ff_rate_dec != 0) lbl_frm_rate2.Text = ff_rate + " fps."; - else lbl_frm_rate2.Text = "-"; - - Label lbl_seconds = new Label(); - lbl_seconds.Parent = frmInfo; - lbl_seconds.Left = 20; - lbl_seconds.Top = 81; - lbl_seconds.Width = 90; - lbl_seconds.Text = Strings.total_sec + ":"; - - Label lbl_seconds2 = new Label(); - lbl_seconds2.Parent = frmInfo; - lbl_seconds2.Left = 123; - lbl_seconds2.Top = 81; - lbl_seconds2.Width = 110; - if (ff_dur_dec != 0) lbl_seconds2.Text = ff_dur_dec.ToString() + " " + Strings.seconds + "."; - else lbl_seconds2.Text = "-"; - - Label lbl_fr_count = new Label(); - lbl_fr_count.Parent = frmInfo; - lbl_fr_count.Left = 20; - lbl_fr_count.Top = 107; - lbl_fr_count.Width = 95; - lbl_fr_count.Text = "Total frames:"; - - Label lbl_fr_count2 = new Label(); - lbl_fr_count2.Parent = frmInfo; - lbl_fr_count2.Left = 123; - lbl_fr_count2.Top = 107; - lbl_fr_count2.Width = 110; - if (tot_frames != 0) lbl_fr_count2.Text = tot_frames.ToString().TrimStart('0').Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator, String.Empty) + " frames."; - else lbl_fr_count2.Text = "-"; - frmInfo.StartPosition = FormStartPosition.CenterParent; - frmInfo.ShowDialog(); - } - - private void boton_ok_st_Click(object sender, EventArgs e) - { - ActiveForm.Close(); - } - - private void watch_other_instance_Created(object sender, FileSystemEventArgs e) - { - String other_file = Path.Combine(Path.GetTempPath(), "FFBatch_test") + "\\" + "Other_instance.fftmp"; - if (File.Exists(other_file) && working == false) - { - List files2 = new List(); - int num_drop = 0; - this.BringToFront(); - foreach (String dropped in File.ReadLines(other_file)) - { - if (File.Exists(dropped)) - { - files2.Add(dropped); - num_drop = files2.Count(); - } - else - { - if (Directory.Exists(dropped)) - { - if (add_subfs == false) - { - foreach (String file in Directory.GetFiles(dropped)) - { - if (!File.GetAttributes(file).HasFlag(FileAttributes.Hidden)) - { - files2.Add(file); - num_drop = num_drop + 1; - } - } - } - else - { - try - { - foreach (string f in Directory.GetFiles(dropped, "*.*", System.IO.SearchOption.AllDirectories)) - { - if (!File.GetAttributes(f).HasFlag(FileAttributes.Hidden)) - { - files2.Add(f); - num_drop = num_drop + 1; - } - } - } - catch (System.Exception excpt) - { - DialogResult a = MessageBox.Show(Strings.error2 + " " + excpt.Message, Strings.error3, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - } - } - } - - if (num_drop >= 5000) - { - DialogResult a = MessageBox.Show(Strings.adding + " " + num_drop + " " + Strings.files_time, Strings.many_files, MessageBoxButtons.OKCancel, MessageBoxIcon.Question); - if (a == DialogResult.Cancel) - { - return; - } - } - - files_to_add = files2; - canceled_file_adding = false; - btn_cancel_add.Enabled = true; - btn_cancel_add.Visible = true; - btn_cancel_add.Refresh(); - BG_Files.RunWorkerAsync(); - - try - { - File.Delete(other_file); - } - catch { } - } - } - - private void chk_delete_source_CheckedChanged(object sender, EventArgs e) - { - String f_delete = String.Empty; - if (is_portable == false) - { - f_delete = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_delete.ini"; - } - else - { - f_delete = port_path + "ff_delete_portable.ini"; - } - - if (chk_delete_source.Checked == false) - { - chk_delete_source.BackColor = this.BackColor; - if (File.Exists(f_delete)) - { - try - { - File.Delete(f_delete); - } - catch - { - MessageBox.Show(Strings.err_set, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - else - { - chk_delete_source.BackColor = Color.LightGoldenrodYellow; - if (!File.Exists(f_delete)) - { - try - { - File.WriteAllText(f_delete, String.Empty); - } - catch - { - MessageBox.Show(Strings.err_set, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - if (chk_delete_source.Checked == true && chk_overw.Checked == true) - { - delete_def = false; - delete_one = true; - rec_overw(); - MessageBox.Show(Strings.del_overw2); - } - } - - private void rec_overw() - { - String f_delete_one = String.Empty; - if (is_portable == false) - { - f_delete_one = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_delete_one.ini"; - } - else - { - f_delete_one = port_path + "ff_delete_one_portable.ini"; - } - - try - { - File.WriteAllText(f_delete_one, ""); - } - catch { } - - //End delete one - - // Delete full - String f_delete_full = String.Empty; - if (is_portable == false) - { - f_delete_full = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_delete_full.ini"; - } - else - { - f_delete_full = port_path + "ff_delete_full_portable.ini"; - } - - try { File.Delete(f_delete_full); } catch { } - //End delete full - } - - private void wiz_silence_menu_Click(object sender, EventArgs e) - { - detect_silence(); - } - - private void lbl_updates_Click(object sender, EventArgs e) - { - if (lbl_updates.Text == Strings.up_err) - { - DialogResult a = MessageBox.Show(Strings.err_check + Environment.NewLine + Environment.NewLine + Strings.check_web_up, Strings.error, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); - if (a == DialogResult.Yes) Process.Start(proj_web); - } - else btn_update.PerformClick(); - } - - private void btn_abort_all_Click(object sender, EventArgs e) - { - Pg1.Focus(); - String save_path_queue = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "saved_queue_temp.ffq"; - if (is_portable == true) save_path_queue = port_path + "saved_queue_temp.ffq"; - String save_path_queue0 = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "saved_queue_temp0.ffq"; - if (is_portable == true) save_path_queue0 = port_path + "saved_queue_temp0.ffq"; - - try - { - File.Delete(save_path_queue); - } - catch { } - try - { - File.Delete(save_path_queue0); - } - catch { } - - if (tabControl1.SelectedIndex == 0) abort_view1(); - if (tabControl1.SelectedIndex == 1) abort_mux(); - if (tabControl1.SelectedIndex == 2) abort_sub_mux(); - if (tabControl1.SelectedIndex == 3) abort_m3u(); - } - - private void abort_mux() - { - Pg1.Focus(); - if (working == false) return; - working = false; - cancel_queue = true; - - foreach (Process proc in procs.Values) - { - if (proc.StartInfo.Arguments.Length >= 0) - { - StreamWriter write_q = proc.StandardInput; - write_q.Write("q"); - return; - } - } - } - - private void abort_sub_mux() - { - if (working == false) return; - cancel_queue = true; - working = false; - aborted = true; - - foreach (Process proc in procs.Values) - { - if (proc.StartInfo.Arguments.Length >= 0) - { - StreamWriter write_q = proc.StandardInput; - write_q.Write("q"); - return; - } - } - } - - public Boolean Send_CTRLC(Process p) - { - if (AttachConsole((uint)p.Id)) - { - SetConsoleCtrlHandler(null, true); - try - { - if (!GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0)) - return false; - p.WaitForExit(10000); - } - finally - { - FreeConsole(); - SetConsoleCtrlHandler(null, false); - } - return true; - } - return false; - } - - private void abort_m3u() - { - if (m3u_running == true) - { - working = false; - m3u_running = false; - cancelados_paralelos = true; - aborted = true; - - foreach (DataGridViewRow row in dg1.Rows) - { - if ((row.Cells[5].Value.ToString().Contains(Strings.success) == false) && row.Cells[5].Value.ToString() != Strings.ready && row.Cells[5].Value.ToString() != Strings.skipped) - { - row.Cells[5].Value = Strings.aborting; - } - if (row.Cells[5].Value.ToString().Contains(Strings.recording1) == true) row.Cells[5].Value = "Stopping"; - } - Boolean proc_exist = false; - if (m3u_single_running == false) - { - Process[] localByName0 = Process.GetProcessesByName("yt-dlp"); - foreach (Process p in localByName0) - { - foreach (DataGridViewRow row in dg1.Rows) - { - if (dg1.Rows[0].Cells[3].Value.ToString() == "Live") - { - timer2.Stop(); - aborted_url = false; - stopped_recording = true; - Pg1.MarqueeAnimationSpeed = 15; - Pg1.Text = Strings.stopping2; - Pg1.Refresh(); - Send_CTRLC(p); - } - else - { - try - { - p.Kill(); - } - catch { } - } - // } - } - } - //FFmpeg m3u running - Process[] ffs = Process.GetProcessesByName("ffmpeg"); - foreach (Process p in ffs) - { - foreach (DataGridViewRow row in dg1.Rows) - { - try - { - if (p.Id == procs["proc_urls_" + row.Index.ToString()].Id) - { - proc_exist = true; - } - } - catch - { - proc_exist = false; - continue; - } - - if (p.Id == procs["proc_urls_" + row.Index.ToString()].Id) - { - try - { - p.Kill(); - } - catch { } - } - } - } - timer2.Stop(); - } - - if (m3u_single_running == true) - { - aborted_url = true; - - //Live YouTube abort - if (dg1.Rows[0].Cells[3].Value.ToString() == "Live") - { - timer2.Stop(); - aborted_url = false; - stopped_recording = true; - Pg1.MarqueeAnimationSpeed = 15; - Pg1.Text = Strings.stopping2; - Pg1.Refresh(); - - foreach (Process proc in procs.Values) - { - try - { - Send_CTRLC(proc); - } - catch { } - try - { - Thread.Sleep(250); - Send_CTRLC(proc); - } - catch { } - } - } - else - { - foreach (Process proc in procs.Values) - { - try - { - StreamWriter write_q2 = proc.StandardInput; - write_q2.Write("q"); - } - catch { } - try - { - Process[] localByName0 = Process.GetProcessesByName("yt-dlp"); - foreach (Process p in localByName0) - { - try { Send_CTRLC(proc); } - catch { } - } - } - catch { } - } - } - - aborted_url = true; - aborted = true; - cancel_queue = true; - cancelados_paralelos = false; - } - return; - } - - cancel_queue = true; - cancelados_paralelos = true; - - //process_glob.Kill(); - Process[] localByName = Process.GetProcessesByName("yt-dlp"); - foreach (Process p in localByName) - { - try { p.Kill(); } - catch { } - } - - System.Threading.Thread.Sleep(250); - Process[] localByName2 = Process.GetProcessesByName("ffmpeg"); - foreach (Process p in localByName2) - { - p.Kill(); - } - System.Threading.Thread.Sleep(500); - - Process[] localByName3 = Process.GetProcessesByName("ffmpeg"); - foreach (Process p2 in localByName3) - { - p2.Kill(); - } - - } - - private void btn_multimedia_Click(object sender, EventArgs e) - { - Pg1.Focus(); - if (listView1.Items.Count == 0) - { - MessageBox.Show(Strings.list_empty, Strings.list_bl, MessageBoxButtons.OK, MessageBoxIcon.Information); - return; - } - else - { - if (listView1.SelectedItems.Count == 0) - { - MessageBox.Show(Strings.no_f_sel); - return; - } - } - media_info(); - } - - private void button1_Click_1(object sender, EventArgs e) - { - Pg1.Focus(); - try - { - listView1.Font = new Font("Microsoft Sans Serif", listView1.Font.Size + 1); - listView2.Font = new Font("Microsoft Sans Serif", listView2.Font.Size + 1); - listView3.Font = new Font("Microsoft Sans Serif", listView3.Font.Size + 1); - list_tracks.Font = new Font("Microsoft Sans Serif", list_tracks.Font.Size + 1); - combo_presets.Font = new Font("Microsoft Sans Serif", combo_presets.Font.Size + 1); - txt_path_main.Font = new Font("Microsoft Sans Serif", txt_path_main.Font.Size + 1); - txt_pre_input.Font = new Font("Microsoft Sans Serif", txt_pre_input.Font.Size + 1); - txt_parameters.Font = new Font("Microsoft Sans Serif", txt_parameters.Font.Size + 1); - tabControl1.Font = new Font("Microsoft Sans Serif", tabControl1.Font.Size + 1); - dg1.Font = new Font("Microsoft Sans Serif", dg1.Font.Size + 0.5f); - Settings.Default.font_size = Settings.Default.font_size + 1; - Settings.Default.Save(); - } - catch { } - } - - private void button5_Click_1(object sender, EventArgs e) - { - Pg1.Focus(); - try - { - listView1.Font = new Font("Microsoft Sans Serif", listView1.Font.Size - 1); - listView2.Font = new Font("Microsoft Sans Serif", listView2.Font.Size - 1); - listView3.Font = new Font("Microsoft Sans Serif", listView3.Font.Size - 1); - list_tracks.Font = new Font("Microsoft Sans Serif", list_tracks.Font.Size - 1); - combo_presets.Font = new Font("Microsoft Sans Serif", combo_presets.Font.Size - 1); - txt_parameters.Font = new Font("Microsoft Sans Serif", txt_parameters.Font.Size - 1); - txt_path_main.Font = new Font("Microsoft Sans Serif", txt_path_main.Font.Size - 1); - txt_pre_input.Font = new Font("Microsoft Sans Serif", txt_pre_input.Font.Size - 1); - tabControl1.Font = new Font("Microsoft Sans Serif", tabControl1.Font.Size - 1); - dg1.Font = new Font("Microsoft Sans Serif", dg1.Font.Size - 0.5f); - Settings.Default.font_size = Settings.Default.font_size - 1; - Settings.Default.Save(); - } - catch { } - } - - private void set_font_size() - { - try - { - if (dg1.Font.Size == 0) return; - listView1.Font = new Font("Microsoft Sans Serif", listView1.Font.Size + font_size); - listView2.Font = new Font("Microsoft Sans Serif", listView2.Font.Size + font_size); - listView3.Font = new Font("Microsoft Sans Serif", listView3.Font.Size + font_size); - list_tracks.Font = new Font("Microsoft Sans Serif", list_tracks.Font.Size + font_size); - txt_path_main.Font = new Font("Microsoft Sans Serif", txt_path_main.Font.Size + font_size); - txt_pre_input.Font = new Font("Microsoft Sans Serif", txt_pre_input.Font.Size + font_size); - combo_presets.Font = new Font("Microsoft Sans Serif", combo_presets.Font.Size + font_size); - txt_parameters.Font = new Font("Microsoft Sans Serif", txt_parameters.Font.Size + font_size); - tabControl1.Font = new Font("Microsoft Sans Serif", tabControl1.Font.Size + font_size); - dg1.Font = new Font("Microsoft Sans Serif", dg1.Font.Size + (font_size / 2)); - } - catch - { - } - } - - private Boolean has_m3u_row() - { - foreach (DataGridViewRow row in dg1.Rows) - { - if (!row.Cells[1].Value.ToString().ToLower().Contains("youtu.be") && !row.Cells[1].Value.ToString().ToLower().Contains("youtube.com")) - { - return true; - } - } - return false; - } - - private Boolean has_you_row() - { - foreach (DataGridViewRow row in dg1.Rows) - { - if (row.Cells[1].Value.ToString().ToLower().Contains("youtu.be") || row.Cells[1].Value.ToString().ToLower().Contains("youtube.com")) - { - return true; - } - } - return false; - } - - private void ct_paste_youtube_Click(object sender, EventArgs e) - { - check_internet(); - - if (internet_up == false) return; - String copied = Clipboard.GetText(); - - if (!copied.ToLower().Contains("youtu.be") && !copied.ToLower().Contains("youtube.com")) - { - MessageBox.Show(Strings.invalid_yt); - return; - } - - if (copied.ToLower().Substring(copied.Length - 7, 7) == "/videos" || copied.ToLower().Substring(copied.Length - 9, 9) == "/featured" || copied.ToLower().Contains("channel")) - { - MessageBox.Show(Strings.yt_channel, Strings.information, MessageBoxButtons.OK, MessageBoxIcon.Information); - return; - } - - if (has_m3u_row() == true) - { - MessageBox.Show(Strings.mix_urls, Strings.information, MessageBoxButtons.OK, MessageBoxIcon.Information); - return; - } - - if (copied.Contains("&list=")) copied = copied.Substring(0, copied.IndexOf("&list=")); - - if (copied != String.Empty && copied.ToLower().Contains("http")) - { - foreach (DataGridViewRow r in dg1.Rows) - { - if (r.Cells[1].Value.ToString() == copied) - { - MessageBox.Show(Strings.url_alr); - return; - } - } - - foreach (DataGridViewRow row in dg1.Rows) - { - row.ReadOnly = true; - } - foreach (Control ct in groupBox_m3u.Controls) - { - ct.Enabled = false; - } - - if (copied.ToLower().Contains("playlist")) - { - pl_url = copied; - dg1.Rows.Clear(); - Validate_added_row_YT_PL(); - } - else - { - //this.Enabled = false; - btn_cancel_validate.Enabled = true; - dg1.Rows.Add(pic_noimg.Image, copied, "", "", "", ""); - BG_Single_yt.RunWorkerAsync(); - } - } - } - - private void btn_add_yts_Click(object sender, EventArgs e) - { - Pg1.Focus(); - if (!File.Exists(Path.Combine(Application.StartupPath, "yt-dlp.exe"))) - { - MessageBox.Show(Strings.yt_not, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - release_datagrid(); - return; - } - check_internet(); - if (internet_up == false) return; - adding_youtube = true; - open_file_m3u.Filter = Strings.txt_f + " " + " | *.txt; *.text| " + Strings.all_files + " (*.*) | *.*"; - open_file_m3u.ShowDialog(); - } - - //private void clonedg() - //{ - // var targetRows = new List(); - - // foreach (DataGridViewRow sourceRow in dg1.Rows) - // { - // if (!sourceRow.IsNewRow) - // { - // var targetRow = (DataGridViewRow)sourceRow.Clone(); - - // foreach (DataGridViewCell cell in sourceRow.Cells) - // { - // targetRow.Cells[cell.ColumnIndex].Value = cell.Value; - // } - // targetRows.Add(targetRow); - // } - // } - //} - - private void BG_Validate_URLs_YT_DoWork(object sender, DoWorkEventArgs e) - { - m3u_params_checked = chk_m3u_params.Checked; - output_server_checked = chk_output_server.Checked; - this.InvokeEx(f => this.Enabled = false); - cell_zoom(); - - dg1.ReadOnly = false; - - groupBox_m3u.Invoke(new MethodInvoker(delegate - { - foreach (Control ct in groupBox_m3u.Controls) - { - ct.Enabled = true; - } - })); - - chk_m3u_params.Invoke(new MethodInvoker(delegate - { - if (chk_m3u_params.CheckState == CheckState.Checked) - { - txt_m3u_params.Enabled = true; - } - else - { - txt_m3u_params.Enabled = false; - } - })); - - chk_output_server.Invoke(new MethodInvoker(delegate - { - if (chk_output_server.CheckState == CheckState.Checked) - { - txt_output_server.Enabled = true; - } - else - { - txt_output_server.Enabled = false; - } - })); - - foreach (DataGridViewRow row in dg1.Rows) - { - dg1.Invoke(new MethodInvoker(delegate - { - row.ReadOnly = false; - - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("/", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace(":", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("*", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("?", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("¿", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("@", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("\u0022", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("<", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace(">", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("|", ""); - row.Cells[4].Value = row.Cells[4].Value.ToString().Replace("\\", ""); - })); - } - - foreach (Control ct in groupBox_m3u.Controls) - { - this.InvokeEx(f => ct.Enabled = false); - } - - this.InvokeEx(f => f.btn_cancel_validate.Enabled = true); - - procs.Clear(); - m_images.Clear(); - for (int ii = 0; ii < dg1.RowCount; ii++) - { - procs.Add("proc_urls_" + ii.ToString(), new Process()); - m_images.Add("pics_" + ii.ToString(), new PictureBox()); - } - clean_imgs(); - - ParallelOptions par_op = new ParallelOptions(); - System.Threading.CancellationTokenSource cts = new System.Threading.CancellationTokenSource(); - par_op.CancellationToken = cts.Token; - par_op.MaxDegreeOfParallelism = (int)n_downs.Value; - - int prog = 0; - this.InvokeEx(f => this.Enabled = false); - one_ok = false; - fatal_parallel = false; - fatal_parallel_msg = ""; - cancelados_paralelos = false; - - Form9 form_prog2 = new Form9(); - form_prog2.abort_validate = false; - - this.InvokeEx(f => TaskbarProgress.SetValue(this.Handle, 1, dg1.RowCount + 1)); - - new System.Threading.Thread(() => - { - System.Threading.Thread.CurrentThread.IsBackground = true; - form_prog2.StartPosition = FormStartPosition.CenterScreen; - form_prog2.progressBar1.Style = ProgressBarStyle.Continuous; - form_prog2.progressBar1.Maximum = dg1.RowCount + 1; - form_prog2.progressBar1.Value = 1; - form_prog2.Refresh(); - form_prog2.label1.Text = Strings.val_yt; - form_prog2.lab_count.Text = "1/" + dg1.RowCount; - form_prog2.lab_count.Refresh(); - form_prog2.Refresh(); - this.Invoke(new MethodInvoker(delegate - { - form_prog2.ShowDialog(this); - form_prog2.Refresh(); - })); - - }).Start(); - var workItems = Enumerable.Range(0, dg1.RowCount); - int errors = 0; - - int current = 0; - object lockCurrent = new object(); - - fatal_parallel = false; - String path_pic = Path.Combine(Path.GetTempPath(), "FFBatch_test"); - dg_thumbs.Initialize(); - - ParallelLoopResult result = new ParallelLoopResult(); - try - { - result = Parallel.ForEach(Partitioner.Create(workItems, EnumerablePartitionerOptions.NoBuffering), par_op, (file_int2) => - { - int file_int = 0; - lock (lockCurrent) - { - file_int = current; - current++; - } - - if (form_prog2.abort_validate == true) - { - cancelados_paralelos = true; - cts.Cancel(); - } - - if (cts.IsCancellationRequested == true) form_prog2.abort_validate = true; - - if (dg1.Rows[file_int].Cells[1].Value == null) form_prog2.abort_validate = true; - - if (stop_validating_url == true) form_prog2.abort_validate = true; - - if (dg1.Rows[file_int].Cells[5].Value.ToString() == Strings.ready || dg1.Rows[file_int].Cells[5].Value.ToString() == Strings.processing || dg1.Rows[file_int].Cells[5].Value.ToString() == Strings.success) - { - prog = prog + 1; - try - { - form_prog2.Invoke(new MethodInvoker(delegate - { - if (form_prog2.progressBar1.Value < form_prog2.progressBar1.Maximum) - { - form_prog2.progressBar1.Value = form_prog2.progressBar1.Value + 1; - this.InvokeEx(f => TaskbarProgress.SetValue(this.Handle, form_prog2.progressBar1.Value, form_prog2.progressBar1.Maximum)); - } - form_prog2.progressBar1.Refresh(); - form_prog2.lab_count.Text = (prog).ToString() + "/" + dg1.Rows.Count; - form_prog2.lab_count.Refresh(); - })); - } - catch { } - return; - } - - this.InvokeEx(f => f.dg1.Rows[file_int].Cells[5].Value = Strings.var_url); - this.InvokeEx(f => f.dg1.Refresh()); - if (dg1.Rows[file_int].Cells[1].Value.ToString().ToLower().Contains("playlist") == true) - { - dg1.Rows[file_int].Cells[2].Value = "00:00:00"; - dg1.Rows[file_int].Cells[3].Value = "00:00:00"; - dg1.Rows[file_int].Cells[4].Value = Strings.yt_pl; - dg1.Rows[file_int].Cells[5].Value = Strings.yt_pl; - form_prog2.abort_validate = true; - } - var tmp = procs["proc_urls_" + file_int.ToString()]; - var imgs_th = m_images["pics_" + file_int.ToString()]; - - tmp.StartInfo.FileName = Path.Combine(Application.StartupPath, "yt-dlp.exe"); - tmp.StartInfo.Arguments = "--get-duration --get-title --get-thumbnail " + '\u0022' + dg1.Rows[file_int].Cells[1].Value.ToString() + '\u0022'; - tmp.StartInfo.RedirectStandardOutput = true; - tmp.StartInfo.UseShellExecute = false; - tmp.StartInfo.CreateNoWindow = true; - tmp.EnableRaisingEvents = true; - - String filename = ""; - String out_thumb = ""; - String duracion = ""; - - if (cts.IsCancellationRequested == false) - { - tmp.Start(); - - while (!tmp.StandardOutput.EndOfStream) - { - if (form_prog2.abort_validate == true) - { - cts.Cancel(); - } - else - { - filename = tmp.StandardOutput.ReadLine(); - out_thumb = tmp.StandardOutput.ReadLine(); - duracion = tmp.StandardOutput.ReadLine(); - } - } - } - else - { - try - { - form_prog2.Invoke(new MethodInvoker(delegate - { - form_prog2.Close(); - })); - } - catch { } - release_datagrid(); - this.InvokeEx(f => this.Enabled = true); - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - - return; - } - tmp.WaitForExit(); - prog = prog + 1; - - form_prog2.Invoke(new MethodInvoker(delegate - { - if (form_prog2.progressBar1.Value < form_prog2.progressBar1.Maximum) - { - form_prog2.progressBar1.Value = form_prog2.progressBar1.Value + 1; - this.InvokeEx(f => TaskbarProgress.SetValue(this.Handle, form_prog2.progressBar1.Value, form_prog2.progressBar1.Maximum)); - } - form_prog2.progressBar1.Refresh(); - form_prog2.lab_count.Text = (prog).ToString() + "/" + dg1.Rows.Count; - form_prog2.lab_count.Refresh(); - })); - - try - { - if (out_thumb.ToLower().Substring(0, 4) == "http") - { - - - - imgs_th.Load(out_thumb); - dg_thumbs[file_int] = imgs_th.Image; - } - } - catch { dg_thumbs[file_int] = pic_noimg.Image; } - - if (duracion == null || duracion == string.Empty) - { - dg1.Invoke(new MethodInvoker(delegate - { - dg1.Rows[file_int].Cells[2].Value = ""; - dg1.Rows[file_int].Cells[3].Value = ""; - dg1.Rows[file_int].Cells[5].Value = Strings.error; - this.InvokeEx(f => f.dg1.Rows[file_int].Cells[5].Style.BackColor = Color.LightGoldenrodYellow); - errors = errors + 1; - })); - } - - if (duracion != null && filename != "") - { - dg1.Invoke(new MethodInvoker(delegate - { - if (duracion == "0") - { - dg1.Rows[file_int].Cells[2].Value = duracion; - dg1.Rows[file_int].Cells[3].Value = "Live"; - } - else - { - if (duracion.Length < 6) duracion = "00:" + duracion; - dg1.Rows[file_int].Cells[2].Value = duracion; - dg1.Rows[file_int].Cells[3].Value = duracion; - } - dg1.Rows[file_int].Cells[4].Value = filename; - //dg1.Rows[file_int].DefaultCellStyle.BackColor = dg1.DefaultCellStyle.BackColor; - one_ok = true; - dg1.Rows[file_int].Cells[5].Value = Strings.ready; - this.InvokeEx(f => f.dg1.Rows[file_int].Cells[5].Style.BackColor = Color.LightGreen); - })); - } - try - { - form_prog2.Invoke(new MethodInvoker(delegate - { - if (errors > 0 && form_prog2.abort_validate == false) - { - form_prog2.lab_err.Text = Strings.errors + " " + errors.ToString(); - form_prog2.lab_err.Refresh(); - form_prog2.pictureBox1.Visible = true; - form_prog2.pictureBox1.Refresh(); - } - })); - } - catch { } - - tmp.StartInfo.Arguments = String.Empty; - }); //Parallel - } //Try Parallel - catch (Exception exc) - { - fatal_parallel_msg = exc.Message; - fatal_parallel = true; - - try - { - form_prog2.Invoke(new MethodInvoker(delegate - { form_prog2.Close(); })); - } - catch { form_prog2.abort_validate = true; } - } - if (result.IsCompleted == true) fatal_parallel = false; - else - { - if (cts.IsCancellationRequested == false) fatal_parallel = true; - else fatal_parallel = false; - } - - //End Parallel - try - { - form_prog2.Invoke(new MethodInvoker(delegate - { form_prog2.Close(); })); - } - catch { form_prog2.abort_validate = true; } - } - - private void BG_Validate_URLs_YT_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) - { - if (m3u_params_checked == false) txt_m3u_params.Enabled = false; - if (output_server_checked == false) txt_output_server.Enabled = false; - - if (fatal_parallel == true) MessageBox.Show(Strings.err_proc_q + Environment.NewLine + Environment.NewLine + fatal_parallel_msg, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - - if (one_ok == true) - { - this.InvokeEx(f => f.chk_m3u_params.Left = 12); - this.InvokeEx(f => f.chk_output_server.Enabled = false); - this.InvokeEx(f => f.chk_m3u_params.Text = Strings.yt_params); - } - - //Paint image - - foreach (DataGridViewRow row in dg1.Rows) - { - row.Cells[0].Value = dg_thumbs[row.Index]; - if (row.Cells[3].Value == null) continue; - if (row.Cells[3].Value.ToString() == "00:60") - { - row.Cells[3].Value = "01:00"; - row.Cells[2].Value = "01:00"; - } - if (row.Cells[3].Value.ToString() == "60:00") - { - row.Cells[3].Value = "01:00:00"; - row.Cells[2].Value = "01:00:00"; - } - if (row.Cells[3].Value.ToString() != "" && row.Cells[3].Value.ToString() != "-" && row.Cells[3].Value.ToString() != Strings.n_a && row.Cells[3].Value.ToString() != "\u221E" && row.Cells[3].Value.ToString() != "Live" && row.Cells[3].Value.ToString() != Strings.error) - { - Total_dur_urls = Total_dur_urls + TimeSpan.Parse(row.Cells[3].Value.ToString()).TotalSeconds; - } - } - - this.TopMost = true; - this.TopMost = false; - TimeSpan t = TimeSpan.FromSeconds(Total_dur_urls); - String dur = string.Format("{0:D2}h:{1:D2}m:{2:D2}s.{3:D3}ms", - (int)t.TotalHours, - t.Minutes, - t.Seconds, - t.Milliseconds); - - this.InvokeEx(f => f.lbl_urls_time.Visible = true); - this.InvokeEx(f => f.lbl_urls_time.Text = dur.Substring(0, 11)); - if (dur.Substring(0, 11) == "00h:00m:00s") this.InvokeEx(f => f.lbl_urls_time.Text = ""); - //cell_stretch(); - urls_duration(); - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - } - - private void BG_Validate_PLSS_DoWork(object sender, DoWorkEventArgs e) - { - - } - - private void BG_Validate_PLSS_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) - { - this.TopMost = true; - this.TopMost = false; - - if (dg1.Rows[0].Cells[1].Value.ToString().ToLower().Contains("playlist")) - { - BG_Validate_added_row_YT_PL_S.RunWorkerAsync(); - } - } - - private void urls_duration() - { - TimeSpan t = TimeSpan.FromSeconds(Total_dur_urls); - String dur = string.Format("{0:D2}h:{1:D2}m:{2:D2}s.{3:D3}ms", - (int)t.TotalHours, - t.Minutes, - t.Seconds, - t.Milliseconds); - - this.InvokeEx(f => f.lbl_urls_time.Visible = true); - this.InvokeEx(f => f.lbl_urls_time.Text = dur.Substring(0, 11)); - if (dur.Substring(0, 11) == "00h:00m:00s") - { this.InvokeEx(f => f.lbl_urls_time.Text = ""); } - } - - private void dg1_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e) - { - if (dg1.RowCount > 0) lbl_n_urls.Text = dg1.RowCount.ToString() + " url(s)"; - else lbl_n_urls.Text = ""; - Total_dur_urls = 0; - foreach (DataGridViewRow row in dg1.Rows) - { - if (row.Cells[3].Value == null) continue; - if (row.Cells[3].Value.ToString() != "" && row.Cells[3].Value.ToString() != "-" && row.Cells[3].Value.ToString() != Strings.n_a && row.Cells[3].Value.ToString() != "\u221E") - { - Total_dur_urls = Total_dur_urls + TimeSpan.Parse(row.Cells[3].Value.ToString()).TotalSeconds; - } - } - urls_duration(); - if (dg1.RowCount > 0) txt_paste_links.Visible = false; - else txt_paste_links.Visible = true; - //dg_thumbs[e.RowIndex] = pic_noimg.Image; - } - - - - private void dg1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) - { - dg1.Rows[e.RowIndex].Height = 45; - if (dg1.RowCount > 0) txt_paste_links.Visible = false; - else txt_paste_links.Visible = true; - lbl_n_urls.Text = dg1.RowCount.ToString() + " url(s)"; - } - - private void btn_save_path_url_Click(object sender, EventArgs e) - { - String path_s = ""; - if (is_portable == false) - { - path_s = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_path_url.ini"; - } - else - { - path_s = port_path + "ff_path_url_portable.ini"; - } - - String path_to_save = String.Empty; - path_to_save = txt_path_m3u.Text; - File.WriteAllText(path_s, path_to_save); - btn_save_path_url.Enabled = false; - } - - private void btn_save_downs_Click(object sender, EventArgs e) - { - //Save selected theads - - String path = String.Empty; - if (is_portable == false) - { - path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_downs.ini"; - } - else - { - path = port_path + "ff_downs_portable.ini"; - } - - String txt_threads = txt_threads = n_downs.Value.ToString(); - File.WriteAllText(path, txt_threads); - btn_save_downs.Enabled = false; - //End save selected threads - } - - private void n_downs_ValueChanged(object sender, EventArgs e) - { - //Save selected theads - - String path = String.Empty; - if (is_portable == false) - { - path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_downs.ini"; - } - else - { - path = port_path + "ff_downs_portable.ini"; - } - - if (File.Exists(path)) - { - String saved_th2 = File.ReadAllText(path); - if (n_downs.Value.ToString() != saved_th2) btn_save_downs.Enabled = true; - else btn_save_downs.Enabled = false; - } - else btn_save_downs.Enabled = true; - } - - - - private void chk_cache_yt_CheckedChanged(object sender, EventArgs e) - { - Settings.Default.yt_clear_c = chk_cache_yt.Checked; - if (chk_cache_yt.Checked == true) Clear_cache = "--rm-cache-dir"; - else Clear_cache = ""; - } - - private void chk_down_limit_CheckedChanged(object sender, EventArgs e) - { - Settings.Default.yt_limit = chk_down_limit.Checked; - if (chk_down_limit.Checked == true) n_down_speed.Enabled = true; - else n_down_speed.Enabled = false; - } - - private void chk_save_subtitles_CheckedChanged(object sender, EventArgs e) - { - if (chk_save_subtitles.Checked == true) chk_convert_srt.Enabled = true; - else chk_convert_srt.Enabled = false; - } - - private void dg1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) - { - try - { - if (e.Button == MouseButtons.Right || dg1.RowCount > 0) - { - // Add this - dg1.CurrentCell = dg1.Rows[e.RowIndex].Cells[e.ColumnIndex]; - // Can leave these here - doesn't hurt - dg1.Rows[e.RowIndex].Selected = true; - dg1.Focus(); - } - } - catch { } - } - - private void ct_remove_url_Click(object sender, EventArgs e) - { - foreach (DataGridViewCell cell in dg1.SelectedCells) - { - try - { - foreach (DataGridViewCell cell2 in dg1.Rows[cell.RowIndex].Cells) - { - cell2.Selected = false; - } - - dg1.Rows.RemoveAt(cell.RowIndex); - } - catch - { - } - } - } - - private void timer_update_Tick(object sender, EventArgs e) - { - if (pg_update_yl.Value >= pg_update_yl.Maximum) pg_update_yl.Value = pg_update_yl.Maximum; - else pg_update_yl.Value = pg_update_yl.Value + 1; - pg_update_yl.Refresh(); - } - - private void btn_logs_url_Click(object sender, EventArgs e) - { - btn_display_log.PerformClick(); - } - - private void BG_pre_validate_url_txt_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) - { - post_file_url(); - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - urls_duration(); - lbl_n_urls.Text = dg1.RowCount.ToString() + " url(s)"; - } - - private void ct1_paste_youtube_Click(object sender, EventArgs e) - { - tabControl1.SelectedTab = tabControl1.TabPages[3]; - this.Refresh(); - ct_paste_youtube.PerformClick(); - } - - private void ct1_paste_m3u_Click(object sender, EventArgs e) - { - tabControl1.SelectedTab = tabControl1.TabPages[3]; - this.Refresh(); - ct_paste_m3u.PerformClick(); - } - - private void BG_Multi_M_DoWork(object sender, DoWorkEventArgs e) - { - warn_enc = 0; - String hw_decode = String.Empty; - - cb_hwdecode.Invoke(new MethodInvoker(delegate - { - if (cb_hwdecode.SelectedItem.ToString() != "none") - { - hw_decode = "-hwaccel " + cb_hwdecode.SelectedItem.ToString(); - } - })); - - procs.Clear(); - multi_logs.Clear(); - multi_params.Clear(); - multi_speeds.Clear(); - multi_fps.Clear(); - - lbl_speed.Invoke(new MethodInvoker(delegate - { - lbl_speed.Text = ""; - })); - - List destis = new List(); - List list_lines = new List(); - list_successful_m.Clear(); - list_failed_m.Clear(); - - for (int ii = 0; ii < listView1.Items.Count; ii++) - { - procs.Add("proc_urls_" + ii.ToString(), new Process()); - destis.Add("destis_" + ii.ToString()); - multi_logs.Add("log_n_" + ii.ToString(), ""); - multi_params.Add("path_n_" + ii.ToString(), ""); - } - - listView1.Invoke(new MethodInvoker(delegate - { - foreach (ListViewItem item in listView1.Items) - { - multi_speeds.Add("0"); - multi_fps.Add("0"); - } - })); - - this.InvokeEx(f => f.Pg1.Text = "0%"); - - opened_m = false; - aborted = false; - Decimal tot_frames2 = 0; - int current_f = 0; - warn_space = true; - - Disable_Controls(); - this.InvokeEx(f => f.btn_add_files.Enabled = true); - - ParallelOptions par_op = new ParallelOptions(); - CancellationTokenSource cts = new System.Threading.CancellationTokenSource(); - par_op.CancellationToken = cts.Token; - par_op.MaxDegreeOfParallelism = Convert.ToInt16(n_threads.Value); - - IEnumerable items_lv = Enumerable.Range(0, listView1.Items.Count); - ParallelLoopResult result = new ParallelLoopResult(); - - int current = 0; - object lockCurrent = new object(); - - try - { - result = Parallel.ForEach(Partitioner.Create(items_lv, EnumerablePartitionerOptions.NoBuffering), par_op, (file_int2) => - { - int file_int = 0; - lock (lockCurrent) - { - file_int = current; - current++; - } - - if (cancelados_paralelos == true || aborted == true) - { - cts.Cancel(); - timer1.Stop(); - timer_tasks.Stop(); - working = false; - multi_running = false; - return; - } - - Boolean skipped = false; - String item_capture_time = String.Empty; - String fullPath = ""; - - DateTime file_crea = new DateTime(); - DateTime file_written = new DateTime(); - DateTime file_modif = new DateTime(); - - Double total_prog = 0; - Double row_duration = 0; - Double dur_rpl = 0; - Boolean valid_prog2 = false; - TimeSpan time2; - int space_timer = 0; - String avs_out = ""; - Boolean status = false; - String dur_fbit = ""; - - listView1.Invoke(new MethodInvoker(delegate - { - if (listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text == Strings.skipped) skipped = true; - if (listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text == Strings.success || listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text == Strings.skipped) status = true; - else status = false; - - if (TimeSpan.TryParse(listView1.Items[Convert.ToInt32(file_int)].SubItems[3].Text, out time2)) - { - row_duration = TimeSpan.Parse(listView1.Items[Convert.ToInt32(file_int)].SubItems[3].Text).TotalSeconds - TimeSpan.Parse(ss_time_input.Text).TotalSeconds; - dur_rpl = TimeSpan.Parse(listView1.Items[Convert.ToInt32(file_int)].SubItems[3].Text).TotalSeconds; - dur_fbit = listView1.Items[Convert.ToInt32(file_int)].SubItems[3].Text; - valid_prog2 = true; - } - else - { - row_duration = 0; - dur_fbit = "0K"; - valid_prog2 = false; - } - - fullPath = listView1.Items[Convert.ToInt32(file_int)].SubItems[1].Text + "\\" + listView1.Items[Convert.ToInt32(file_int)].Text; - if (!File.Exists(fullPath)) - { - listView1.Items[Convert.ToInt32(file_int)].SubItems[1].Text = Strings.file_not_f; - return; - } - if (fullPath.Substring(fullPath.Length - 3, 3).ToLower() == "avs") - { - avs_out = Path.GetDirectoryName(fullPath) + "\\" + Path.GetFileNameWithoutExtension(fullPath) + "." + txt_format.Text; - if (!File.Exists(avs_out)) avs_out = fullPath; - } - - file_crea = File.GetCreationTime(fullPath); - file_written = File.GetLastWriteTime(fullPath); - file_modif = File.GetLastAccessTime(fullPath); - - })); - - if (skipped == true) - { - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.skipped); - current_f++; - this.InvokeEx(f => f.lbl_items.Text = current_f.ToString() + " " + Strings.of1 + " " + listView1.Items.Count.ToString()); - return; - } - - String ffm = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - - // Average frames - int fframes = 0; - Decimal dec = 0; - try - { - String ff_frames = String.Empty; - - Process get_frames = new Process(); - get_frames.StartInfo.FileName = Path.Combine(Application.StartupPath, "mediainfo.exe"); - String ffprobe_frames = "--Output=" + '\u0022' + "Video;%FrameCount%" + '\u0022'; - get_frames.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + fullPath + '\u0022'; - get_frames.StartInfo.RedirectStandardOutput = true; - get_frames.StartInfo.UseShellExecute = false; - get_frames.StartInfo.CreateNoWindow = true; - get_frames.EnableRaisingEvents = true; - get_frames.Start(); - - ff_frames = get_frames.StandardOutput.ReadLine(); - get_frames.WaitForExit(3000); - - if (get_frames.ExitCode == 0) - { - if (ff_frames != null) - { - dec = decimal.Parse(ff_frames); - if (dec.ToString().Substring(dec.ToString().Length - 1, 1) == "0") dec = dec / 10; - } - else - { - dec = 0; - } - - get_frames.Dispose(); - tot_frames2 = tot_frames2 + dec; - - DateTime time0; - Double ss_secs = 0; - this.Invoke(new MethodInvoker(delegate - { - if (DateTime.TryParse(ss_time_input.Text, out time0) && Settings.Default.quick_queue == false) - { - ss_secs = TimeSpan.Parse(ss_time_input.Text).TotalSeconds / TimeSpan.Parse(listView1.Items[file_int].SubItems[3].Text).TotalSeconds; - } - tot_frames2 = tot_frames2 - (tot_frames2 * (decimal)ss_secs); - })); - } - } - catch - { - dec = 0; - } - - // End average frames - - //Begin Shifting - String shifting = ""; - if (chk_shift.Checked == true) - { - shifting = " -itsoffset " + Num_Shift.Value.ToString().Replace(",", ".") + " -i " + '\u0022' + fullPath + '\u0022' + " -map 1:v -map 0:a "; - } - - //End Shifting - - //Change Volume - String change_vol = ""; - if (chk_vol.Checked == true) - { - change_vol = "-filter:a " + '\u0022' + "volume=" + vol_ch.Value.ToString() + "dB " + '\u0022' + " "; - } - //End change volume - - if (txt_path_main.Text.Contains(".\\")) - { - if (txt_path_main.Text != ".\\") - { - destis[file_int] = fullPath.Substring(0, fullPath.LastIndexOf('\\')) + txt_path_main.Text.Replace(".", String.Empty); - } - else - { - destis[file_int] = Path.GetDirectoryName(fullPath); - } - } - else - { - if (chk_recreate.CheckState == CheckState.Checked) - { - String pre_dest = Path.GetDirectoryName(fullPath); - if (pre_dest.Substring(0, 2) == "\\\\") destis[file_int] = Path.Combine(txt_path_main.Text, pre_dest.Substring(2, pre_dest.Length - 2)); - else destis[file_int] = Path.Combine(txt_path_main.Text, pre_dest.Substring(3, pre_dest.Length - 3)); - - } - else - { - destis[file_int] = txt_path_main.Text; - } - } - if (!Directory.Exists(destis[file_int])) - { - Directory.CreateDirectory(destis[file_int]); - } - multi_dest = destis[file_int]; - - String pre_input_var = ""; - if (txt_pre_input.Text != "") - { - pre_input_var = txt_pre_input.Text; - } - - String pre_ss = ""; - if (TimeSpan.Parse(ss_time_input.Text).TotalSeconds != 0) - { - pre_ss = " -ss " + ss_time_input.Text; - } - - add_suffix = ""; - if (chk_suffix.Checked == true && txt_suffix.Text != String.Empty) - { - add_suffix = txt_suffix.Text; - n_th_suffix = add_suffix; - } - - String ext_output1 = txt_format.Text; - if (txt_format.Text.Length == 0) - { - ext_output1 = Path.GetExtension(fullPath); - } - else - { - ext_output1 = "." + txt_format.Text; - } - n_th_source_ext = ext_output1; - - if (txt_format.Text == "nul") ext_output1 = "nul"; - - var tmp = procs["proc_urls_" + file_int.ToString()]; - var n_logs = multi_logs["log_n_" + file_int.ToString()]; - var tmp_params = multi_params["path_n_" + file_int.ToString()]; - tmp_params = txt_parameters.Text; - - //Custom item parameters - if (cust_p_col != 0) - { - try - { - if (custom_m_params[file_int] != "-") - { - int start = custom_m_params[file_int].LastIndexOf("[["); - int end = custom_m_params[file_int].LastIndexOf("]]"); - int cut = end - start + 2; - int length = custom_m_params[file_int].Length; - tmp_params = custom_m_params[file_int].Substring(0, length - cut); - - if (start != -1 && end != -1) - { - ext_output1 = "." + custom_m_params[file_int].Substring(start + 2, cut - 4); - n_th_source_ext = ext_output1; - } - } - } - catch { } - } - //End custom item parameters - - - String file2 = fullPath; - while (tmp_params.Contains("%fn")) - { - if (tmp_params.Contains("%fn")) - { - tmp_params = tmp_params.Replace("%fn", Path.GetFileNameWithoutExtension(file2)); - } - } - - while (pre_input_var.Contains("%fn")) - { - if (pre_input_var.Contains("%fn")) - { - pre_input_var = pre_input_var.Replace("%fn", Path.GetFileNameWithoutExtension(file2)); - } - } - - while (tmp_params.Contains("%fp")) - { - if (tmp_params.Contains("%fp")) - { - tmp_params = tmp_params.Replace("%fp", Path.GetDirectoryName(file2)); - } - } - - while (pre_input_var.Contains("%fp")) - { - if (pre_input_var.Contains("%fp")) - { - pre_input_var = pre_input_var.Replace("%fp", Path.GetDirectoryName(file2)); - } - } - - while (tmp_params.Contains("%ff")) - { - if (tmp_params.Contains("%ff")) - { - tmp_params = tmp_params.Replace("%ff", Path.GetFileName(file2)); - } - } - - while (pre_input_var.Contains("%ff")) - { - if (pre_input_var.Contains("%ff")) - { - pre_input_var = pre_input_var.Replace("%ff", Path.GetFileName(file2)); - } - } - - String dur_secs = dur_rpl.ToString(); - String to_replace = String.Empty; - Double result2 = 0; - - while (tmp_params.Contains("%fdur")) - { - - if (tmp_params.Contains("%fdur")) - { - to_replace = ""; - - int operador = tmp_params.LastIndexOf("%fdur") + 5; - int length = 0; - int limit = tmp_params.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(tmp_params.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace = tmp_params.Substring(tmp_params.LastIndexOf("%fdur"), 5 + length); - result2 = Convert.ToDouble(new DataTable().Compute(to_replace.Replace("%fdur", dur_secs), null)); - tmp_params = ReplaceLastOccurrence(tmp_params, to_replace, Math.Round(result2).ToString()); - } - } - - while (pre_input_var.Contains("%fdur")) - { - - if (pre_input_var.Contains("%fdur")) - { - to_replace = ""; - - int operador = pre_input_var.LastIndexOf("%fdur") + 5; - int length = 0; - int limit = pre_input_var.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(pre_input_var.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace = pre_input_var.Substring(pre_input_var.LastIndexOf("%fdur"), 5 + length); - result2 = Convert.ToDouble(new DataTable().Compute(to_replace.Replace("%fdur", dur_secs), null)); - pre_input_var = ReplaceLastOccurrence(pre_input_var, to_replace, Math.Round(result2).ToString()); - } - } - - //Bitrate variable - - dur_secs = get_bitrate(file2, dur_fbit).ToString(); - to_replace = String.Empty; - - while (tmp_params.Contains("%fbitr")) - { - if (tmp_params.Contains("%fbitr")) - { - to_replace = ""; - - int operador = tmp_params.LastIndexOf("%fbitr") + 6; - int length = 0; - int limit = tmp_params.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(tmp_params.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace = tmp_params.Substring(tmp_params.LastIndexOf("%fbitr"), 6 + length); - - Double result0 = Convert.ToDouble(new DataTable().Compute(to_replace.Replace("%fbitr", dur_secs), null)); - tmp_params = ReplaceLastOccurrence(tmp_params, to_replace, Math.Round(result0).ToString() + "K"); - } - } - - while (pre_input_var.Contains("%fbitr")) - { - if (pre_input_var.Contains("%fbitr")) - { - to_replace = ""; - - int operador = pre_input_var.LastIndexOf("%fbitr") + 6; - int length = 0; - int limit = pre_input_var.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(pre_input_var.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace = pre_input_var.Substring(pre_input_var.LastIndexOf("%fbitr"), 6 + length); - - Double result0 = Convert.ToDouble(new DataTable().Compute(to_replace.Replace("%fbitr", dur_secs), null)); - pre_input_var = ReplaceLastOccurrence(pre_input_var, to_replace, Math.Round(result0).ToString() + "K"); - } - } - - //End bitrate variable - - //Target size - if (tmp_params.Contains("[[target_size=")) - { - int f = tmp_params.IndexOf("[[target_size=") + 14; - int mb = tmp_params.IndexOf("MB"); - int l = tmp_params.IndexOf("Kbps]]"); - Double target_mb = Convert.ToDouble(tmp_params.Substring(f, mb - f)); - String aud_bitr = tmp_params.Substring(mb + 3, l - mb - 3); - String replaced = get_bitrate_target(target_mb, dur_rpl, Convert.ToDecimal(aud_bitr)).ToString(); - to_replace = tmp_params.Substring(f - 14, l - f + 14 + 6); - tmp_params = tmp_params.Replace(to_replace, replaced); - } - //End target size - - while (tmp_params.Contains("%fd")) - { - if (tmp_params.Contains("%fd")) - { - var dirName = new DirectoryInfo(Path.GetDirectoryName(file2)).Name; - tmp_params = tmp_params.Replace("%fd", dirName); - } - } - - while (pre_input_var.Contains("%fd")) - { - if (pre_input_var.Contains("%fd")) - { - var dirName = new DirectoryInfo(Path.GetDirectoryName(file2)).Name; - pre_input_var = pre_input_var.Replace("%fd", dirName); - } - } - - while (tmp_params.Contains("%1")) - { - if (tmp_params.Contains("%1")) - { - file2 = file2.Replace("\\", "\\\\\\\\"); - file2 = file2.Replace(":", ":" + "\\\\"); - tmp_params = tmp_params.Replace("%1", '\u0022' + file2 + '\u0022'); - } - } - - while (pre_input_var.Contains("%1")) - { - if (pre_input_var.Contains("%1")) - { - file2 = file2.Replace("\\", "\\\\\\\\"); - file2 = file2.Replace(":", ":" + "\\\\"); - pre_input_var = pre_input_var.Replace("%1", '\u0022' + file2 + '\u0022'); - } - } - - while (tmp_params.Contains("%2")) - { - if (tmp_params.Contains("%2")) - { - file2 = file2.Replace("\\", "\\\\\\\\"); - file2 = file2.Replace(":", ":" + "\\\\"); - tmp_params = tmp_params.Replace("%2", '\u0022' + Path.Combine(Path.GetDirectoryName(file2), Path.GetFileNameWithoutExtension(file2)) + '\u0022'); - } - } - - while (pre_input_var.Contains("%2")) - { - if (pre_input_var.Contains("%2")) - { - file2 = file2.Replace("\\", "\\\\\\\\"); - file2 = file2.Replace(":", ":" + "\\\\"); - pre_input_var = pre_input_var.Replace("%2", '\u0022' + Path.Combine(Path.GetDirectoryName(file2), Path.GetFileNameWithoutExtension(file2)) + '\u0022'); - } - } - - //New variables for filters - - while (tmp_params.Contains("%pff")) - { - if (tmp_params.Contains("%pff")) - { - file2 = file2.Replace("\\", "/\\"); - file2 = file2.Replace(":", "\\\\://\\"); - - tmp_params = tmp_params.Replace("%pff", Path.GetDirectoryName(file2)); - } - } - - while (tmp_params.Contains("%f1")) - { - if (tmp_params.Contains("%f1")) - { - file2 = file2.Replace("\\", "/\\"); - file2 = file2.Replace(":", "\\\\:"); - - tmp_params = tmp_params.Replace("%f1", file2); - } - } - - while (tmp_params.Contains("%f2")) - { - if (tmp_params.Contains("%f2")) - { - file2 = file2.Replace("\\", "/\\"); - file2 = file2.Replace(":", "\\\\://\\"); - tmp_params = tmp_params.Replace("%f2", Path.Combine(Path.GetDirectoryName(file2), Path.GetFileNameWithoutExtension(file2))); - } - } - - while (pre_input_var.Contains("%pff")) - { - if (pre_input_var.Contains("%pff")) - { - file2 = file2.Replace("\\", "/\\"); - file2 = file2.Replace(":", "\\\\://\\"); - - pre_input_var = pre_input_var.Replace("%pff", Path.GetDirectoryName(file2)); - } - } - - while (pre_input_var.Contains("%f1")) - { - if (pre_input_var.Contains("%f1")) - { - file2 = file2.Replace("\\", "/\\"); - file2 = file2.Replace(":", "\\\\://\\"); - - pre_input_var = pre_input_var.Replace("%f1", file2); - } - } - - while (pre_input_var.Contains("%f2")) - { - if (pre_input_var.Contains("%f2")) - { - file2 = file2.Replace("\\", "/\\"); - file2 = file2.Replace(":", "\\\\://\\"); - pre_input_var = pre_input_var.Replace("%f2", Path.Combine(Path.GetDirectoryName(file2), Path.GetFileNameWithoutExtension(file2))); - } - } - - String file_out = Path.GetFileNameWithoutExtension(fullPath); - if (fullPath.Substring(fullPath.Length - 3, 3).ToLower() == "avs") - { - file_out = Path.GetFileNameWithoutExtension(avs_out); - } - - tmp.StartInfo.Arguments = hw_decode + " " + pre_input_var + " " + pre_ss + " -i " + "" + '\u0022' + fullPath + '\u0022' + " " + shifting + " " + " -y " + tmp_params + " " + change_vol + '\u0022' + destis[file_int] + "\\" + file_out + add_suffix + ext_output1 + '\u0022' + " -hide_banner"; - if (ext_output1 == "nul") tmp.StartInfo.Arguments = hw_decode + " " + pre_input_var + " " + pre_ss + " -i " + "" + '\u0022' + fullPath + '\u0022' + " " + shifting + " " + tmp_params + " " + change_vol + " " + " -hide_banner"; - - String second_path = ""; - if (ext_output1 == "nul") - { - String[] split = txt_parameters.Text.Split(' '); - for (int i = 0; i < split.Length; i++) - { - if (split[i].Contains("\\") == true) - { - String pre_path = split[i].Replace("%fp", Path.GetDirectoryName(file2)).Replace("%fn", Path.GetFileNameWithoutExtension(file2)).Replace("%", "_"); - second_path = Path.GetDirectoryName(pre_path.Replace('\u0022', ' ')); - - if (!Directory.Exists(second_path)) - { - try - { - Directory.CreateDirectory(second_path); - } - catch - { - } - } - } - } - } - - String current_out = destis[file_int] + "\\" + Path.GetFileNameWithoutExtension(fullPath) + add_suffix + ext_output1; - Boolean to_overw = false; - - if (chk_overw.CheckState == CheckState.Checked) - { - if (current_out == fullPath) - { - tmp.StartInfo.Arguments = hw_decode + " " + pre_input_var + " " + pre_ss + " -i " + "" + '\u0022' + fullPath + '\u0022' + " " + shifting + " " + " -y " + tmp_params + " " + change_vol + '\u0022' + destis[file_int] + "\\" + file_out + "_fftemp" + add_suffix + ext_output1 + '\u0022' + " -hide_banner"; - to_overw = true; - } - } - - if (current_out == fullPath && chk_overw.CheckState == CheckState.Unchecked) - { - MessageBox.Show(Strings.source_overw + Environment.NewLine + Environment.NewLine + current_out, Strings.overw_not, MessageBoxButtons.OK, MessageBoxIcon.Error); - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - working = false; - time_est_size = 0; - cts.Cancel(); - Enable_Controls(); - cancelados_paralelos = true; - } - - //Monitor available space - - DriveInfo dest_drive2 = new DriveInfo(Application.StartupPath); - - FileInfo f_root2 = new FileInfo(current_out); - try - { - dest_drive2 = new DriveInfo(f_root2.Directory.Root.FullName); - } - catch { warn_space = false; } - - if (dest_drive2.AvailableFreeSpace != null && warn_space == true) - { - if (dest_drive2.AvailableFreeSpace <= 500000000) - { - DialogResult a = DialogResult.Cancel; - - a = MessageBox.Show(Strings.warn_sp, Strings.low_sp + " (" + (dest_drive2.AvailableFreeSpace / 1000000).ToString() + "MB)", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); - if (a == DialogResult.Yes) - { - aborted = true; - this.InvokeEx(f => f.lbl_est_size.Text = ""); - this.InvokeEx(f => f.lbl_bitrate.Text = ""); - cts.Cancel(); - return; - } - } - } - //End monitor available space - - //Duration for quick file listing - - Type ts = Type.GetTypeFromProgID("Shell.Application"); - dynamic shell = Activator.CreateInstance(ts); - Folder rFolder = shell.NameSpace(Path.GetDirectoryName(fullPath)); - FolderItem rFiles = rFolder.ParseName(Path.GetFileName(fullPath)); - String videostype = rFolder.GetDetailsOf(rFiles, 2).Trim(); - String videoSize = rFolder.GetDetailsOf(rFiles, 1).Trim(); - - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[2].Text = videostype); - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[4].Text = videoSize); - - DateTime time; - String dur_q = rFolder.GetDetailsOf(rFiles, 27).Trim(); - - - if ((DateTime.TryParse(dur_q, out time))) - { - row_duration = TimeSpan.Parse(dur_q).TotalSeconds; - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[3].Text = dur_q); - - - } - else - { - String ndur = get_file_dur(fullPath); - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[3].Text = ndur); - row_duration = TimeSpan.Parse(ndur).TotalSeconds; - } - - //End duration quick file listing - - if (Settings.Default.no_dest_overw == true && File.Exists(current_out)) - { - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.skipped); - list_successful_m.Add(fullPath); - return; - } - - if (verbose_logs == false) tmp.StartInfo.Arguments = tmp.StartInfo.Arguments + " -loglevel warning -stats"; - - FileInfo f_root = new FileInfo(destis[file_int]); - DriveInfo dest_drive = new DriveInfo(Application.StartupPath); - - if (cts.IsCancellationRequested == false) - { - if (ignore_encoded == true && status == true) - { - current_f++; - this.InvokeEx(f => f.lbl_items.Text = current_f.ToString() + " " + Strings.of1 + " " + listView1.Items.Count.ToString()); - return; - } - - //Split chapters - - aborted_url = false; - skipped = false; - - if (tmp_params.Contains("[[split_chapters]]")) - { - String prev_params = tmp.StartInfo.Arguments; - if (list_chaps_m.Count == 0) get_chapters(fullPath); - else list_chaps = list_chaps_m.ToList(); - List tmp_chaps = list_chaps.ToList(); - - if (tmp_chaps.Count > 0) - { - int ich = 0; - - foreach (String[] chap in tmp_chaps) - { - ich++; - Double new_dur = 0; - String rep_out = destis[file_int] + "\\" + file_out + "." + txt_format.Text; - try - { - String start1 = chap[0].Replace("-ss ", ""); - if (start1.Contains(".")) start1 = start1.Substring(0, start1.LastIndexOf(".")); - - String end1 = chap[1].Replace("-to ", ""); - if (end1.Contains(".")) end1 = end1.Substring(0, end1.LastIndexOf(".")); - - int new_dur0 = Convert.ToInt32(end1) - Convert.ToInt32(start1); - new_dur = Convert.ToDouble(new_dur0); - tmp.StartInfo.Arguments = tmp.StartInfo.Arguments.Replace("[[split_chapters]]", (chap[0] + " " + chap[1]) + " "); - } - catch - { - tmp.StartInfo.Arguments = tmp.StartInfo.Arguments.Replace("[[split_chapters]]", "chapter_error "); - } - - String new_dest = destis[file_int] + "\\" + Path.GetFileNameWithoutExtension(fullPath) + "\\" + file_out + "_" + ich.ToString() + "." + txt_format.Text; - String padding = String.Empty; - if (ich < 10) padding = "0"; - if (chap[2].Length > 0) new_dest = destis[file_int] + "\\" + Path.GetFileNameWithoutExtension(fullPath) + "\\" + file_out + "_" + chap[2] + "_" + padding + ich.ToString() + "." + txt_format.Text; - if (!Directory.Exists(destis[file_int] + "\\" + Path.GetFileNameWithoutExtension(fullPath))) - { - Directory.CreateDirectory(destis[file_int] + "\\" + Path.GetFileNameWithoutExtension(fullPath)); - } - tmp.StartInfo.Arguments = ReplaceLastOccurrence(tmp.StartInfo.Arguments, rep_out, new_dest); - - //Process every chapter - - tmp.StartInfo.FileName = ffm; - tmp.StartInfo.RedirectStandardInput = true; - tmp.StartInfo.RedirectStandardError = true; - tmp.StartInfo.UseShellExecute = false; - tmp.StartInfo.CreateNoWindow = true; - tmp.StartInfo.WorkingDirectory = Path.GetDirectoryName(fullPath); - tmp.EnableRaisingEvents = true; - - - tmp.Start(); - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.processing); - - combo_prio.Invoke(new MethodInvoker(delegate - { - if (combo_prio.SelectedIndex != 2) - { - try - { - if (combo_prio.SelectedIndex == 0) tmp.PriorityClass = ProcessPriorityClass.High; - if (combo_prio.SelectedIndex == 1) tmp.PriorityClass = ProcessPriorityClass.AboveNormal; - if (combo_prio.SelectedIndex == 2) tmp.PriorityClass = ProcessPriorityClass.Normal; - if (combo_prio.SelectedIndex == 3) tmp.PriorityClass = ProcessPriorityClass.BelowNormal; - if (combo_prio.SelectedIndex == 4) tmp.PriorityClass = ProcessPriorityClass.Idle; - Process[] localByName = Process.GetProcessesByName("FFBatch"); - if (localByName.Length == 1) - { - foreach (Process proc1 in localByName) - { - if (combo_prio.SelectedIndex >= 2) proc1.PriorityClass = ProcessPriorityClass.Normal; - else proc1.PriorityClass = tmp.PriorityClass; - } - } - } - catch { } - } - })); - - - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.processing); - - FileInfo f_root0 = new FileInfo(destis[file_int]); - DriveInfo dest_drive0 = new DriveInfo(Application.StartupPath); - try - { - dest_drive0 = new DriveInfo(f_root0.Directory.Root.FullName); - } - catch { warn_space = false; } - - String err_txt2 = ""; - Double interval2 = 0; - Double durat_n22 = 0; - this.InvokeEx(f => multi_logs["log_n_" + file_int.ToString()] = Strings.logging_f + " " + '\u0022' + listView1.Items[Convert.ToInt32(file_int)].Text + '\u0022' + Environment.NewLine); - if (paused == true) - { - try - { - tmp.Suspend(); - } - catch { Thread.Sleep(200); tmp.Suspend(); } - } - else - { - try - { - tmp.Resume(); - } - catch { Thread.Sleep(200); tmp.Resume(); } - } - - //REVIEW - while (!tmp.StandardError.EndOfStream) - { - err_txt2 = tmp.StandardError.ReadLine(); - space_timer++; - multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine + n_logs + err_txt2; - - if (err_txt2.Contains("time=") && err_txt2.Contains("time=-") == false && !err_txt2.Contains("time=N/A")) - { - if (valid_prog2 == true) - { - this.InvokeEx(f => f.txt_remain.Refresh()); - this.InvokeEx(f => durat_n22 = new_dur); - durat_n22 = durat_n22 / atemp; - int start_time_index = err_txt2.IndexOf("time=") + 5; - Double sec_prog = TimeSpan.Parse(err_txt2.Substring(start_time_index, 8)).TotalSeconds; - Double percent = (sec_prog * 100 / durat_n22); - - total_prog = total_prog + (sec_prog - interval2); - interval2 = sec_prog; - int percent2 = 0; - try - { - percent2 = Convert.ToInt32(percent); - } - catch - { - } - - if (percent2 <= 100) - { - if (Math.Round(percent, 1).ToString().Contains(".") || Math.Round(percent, 1).ToString().Contains(",")) - { - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Math.Round(percent, 1).ToString() + "%"); - } - else - { - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Math.Round(percent, 1).ToString() + ".0" + "%"); - } - } - } - - try - { - if (err_txt2.Contains("fps=")) - { - multi_fps[file_int] = (err_txt2.Substring(err_txt2.LastIndexOf("fps=") + 4, 4)).TrimStart(); - } - else - { - multi_fps[file_int] = "0"; - } - } - catch { multi_fps[file_int] = "0"; } - try - { - if (err_txt2.ToLower().Contains("speed=")) - { - multi_speeds[file_int] = (err_txt2.Substring(err_txt2.LastIndexOf("speed=") + 6, err_txt2.Length - err_txt2.LastIndexOf("speed=") - 6)).Replace("x", ""); - } - else - { - multi_speeds[file_int] = "0"; - } - } - catch { multi_speeds[file_int] = "0"; } - } - - //Monitor available space - if (space_timer % 30 == 0 && dest_drive.AvailableFreeSpace <= 500000000 && warn_space == true) - { - foreach (Process proc in procs.Values) - { - try - { - proc.Suspend(); - } - catch - { - } - } - DialogResult a = MessageBox.Show(Strings.warn_sp, Strings.low_sp + " (" + (dest_drive2.AvailableFreeSpace / 1000000).ToString() + "MB)", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); - foreach (Process proc in procs.Values) - { - try - { - proc.Resume(); - } - catch - { - - } - } - - if (a == DialogResult.Yes) - { - cts.Cancel(); - aborted = true; - cancelados_paralelos = true; - - foreach (Process proc in procs.Values) - { - cancelados_paralelos = true; - if (proc.StartInfo.Arguments != String.Empty) - - { - try - { - StreamWriter write_q = proc.StandardInput; - write_q.Write("q"); - } - catch { } - } - } - } - - warn_space = false; - } - //End monitor space - } - tmp.WaitForExit(); - this.InvokeEx(f => multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine); - tmp.StartInfo.Arguments = String.Empty; - multi_speeds[file_int] = "0"; - multi_fps[file_int] = "0"; - current_f++; - - this.InvokeEx(f => f.lbl_items.Text = current_f.ToString() + " " + Strings.of1 + " " + (listView1.Items.Count * tmp_chaps.Count).ToString()); - - if (Settings.Default.quick_queue == true) - { - Double perc = (double)current_f * 100 / (double)listView1.Items.Count; - this.Invoke(new MethodInvoker(delegate - { - Pg1.Value = current_f * 100; - Pg1.Text = Math.Round(perc, 0) + "%"; - TaskbarProgress.SetValue(this.Handle, Pg1.Value, Pg1.Maximum); - txt_remain.Text = Strings.remain_time + " " + Strings.n_a; - })); - } - if (tmp.ExitCode == 0) - { - this.InvokeEx(f => multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine + Strings.output + " " + current_out + " " + Strings.success + " (OK)"); - this.InvokeEx(f => multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine); - - list_successful_m.Add(fullPath); - if (cancelados_paralelos == false && cts.IsCancellationRequested == false) - { - if (aborted_url == false) - { - if (File.Exists(fullPath) == true) - { - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.success); - - if (chk_delete_source.CheckState == CheckState.Checked && delete_def == false && delete_one == true) - { - try - { - FileSystem.DeleteFile(fullPath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.recycled); - } - catch (Exception exc) - { - MessageBox.Show(exc.Message); - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.not_recycled); - warn_enc++; - } - } - if (chk_delete_source.CheckState == CheckState.Checked && delete_def == true && delete_one == true) - { - try - { - FileInfo fs = new FileInfo(fullPath); - if (fs.IsReadOnly == true) fs.IsReadOnly = false; - File.Delete(fullPath); - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.deleted); - } - catch - { - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.not_deleted); - warn_enc++; - } - } - - if (chk_overw.CheckState == CheckState.Checked) - { - if (current_out == fullPath) - { - String sourc = destis[file_int] + "\\" + Path.GetFileNameWithoutExtension(fullPath) + "_fftemp" + add_suffix + ext_output1; - - try - { - if (File.Exists(sourc)) - { - File.Delete(fullPath); - FileSystem.RenameFile(sourc, Path.GetFileNameWithoutExtension(fullPath) + add_suffix + ext_output1); - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.replaced); - } - else - { - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.not_replaced); - warn_enc++; - this.InvokeEx(f => multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine + Strings.warning_file + " " + +'\u0022' + listView1.Items[Convert.ToInt32(file_int)].Text + '\u0022' + " " + Strings.warning_not_rep + " " + "(_fftemp)." + Environment.NewLine); - } - } - catch (Exception excpt) - { - try - { - FileSystem.RenameFile(sourc, Path.GetFileNameWithoutExtension(fullPath) + add_suffix + ext_output1); - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.replaced); - } - catch - { - try - { - FileSystem.RenameFile('\u0022' + sourc + '\u0022', '\u0022' + Path.GetFileNameWithoutExtension(fullPath) + add_suffix + ext_output1 + '\u0022'); - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.replaced); - } - catch - { - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.renamed); - warn_enc++; - this.InvokeEx(f => multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine + Strings.warning_file + " " + '\u0022' + listView1.Items[Convert.ToInt32(file_int)].Text + '\u0022' + " " + Strings.warning_not_rep + " " + "(_fftemp)." + Environment.NewLine); - } - } - } - } - } - } - } - if (aborted_url == true) - { - if (skipped == false) - { - this.InvokeEx(f => multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine + Strings.output + " " + current_out + " (" + Strings.aborted.ToUpper() + ")"); - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.aborted); - } - else - { - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.skipped); - try - { - File.Delete(current_out); - } - catch { } - } - aborted_url = false; - skipped = false; - } - - if (row_duration >= 30) save_queue(); - - //Run on each file - int index = 0; - Boolean sh_check = false; - combo_shut.Invoke(new MethodInvoker(delegate - { - index = combo_shut.SelectedIndex; - })); - - chkshut.Invoke(new MethodInvoker(delegate - { - if (chkshut.Checked == true) sh_check = true; - })); - - if (index == 4 && cancel_queue == false && sh_check == true) - { - this.InvokeEx(f => this.Enabled = false); - Form14 frm_run = new Form14(); - frm_run.txt_path.Text = run_command; - String dest_f = '\u0022' + destis[file_int] + "\\" + Path.GetFileNameWithoutExtension(fullPath) + add_suffix + ext_output1 + '\u0022'; - if (ext_output1 == "nul") dest_f = '\u0022' + destis[file_int] + "\\" + Path.GetFileNameWithoutExtension(fullPath) + add_suffix + Path.GetExtension(fullPath).Replace(".", "") + '\u0022'; - - frm_run.args = dest_f + " " + run_command_args; - frm_run.timer1.Interval = 100; - frm_run.ShowDialog(); - this.InvokeEx(f => this.Enabled = true); - Enable_Controls(); - - if (frm_run.proc.ExitCode == 0) - { - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = "OK & Run"); - multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine + n_logs + Strings.ext_com_ok + " " + dest_f + Environment.NewLine; - } - else - { - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = "OK & Error"); - multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine + n_logs + Strings.ext_com_err + " " + dest_f + Environment.NewLine; - } - - this.Invoke(new MethodInvoker(delegate - { - multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine; - this.TopMost = true; - this.TopMost = false; - })); - } - - //End run on each file - } - else - { - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.aborted); - - if (cancelados_paralelos == false) - { - aborted_url = false; - } - } - - if (keep_dates == true) - { - try - { - File.SetCreationTime(current_out, file_crea); - File.SetLastWriteTime(current_out, file_written); - File.SetLastAccessTime(current_out, file_modif); - } - catch { } - } - } - else - { - list_failed_m.Add(fullPath); - this.InvokeEx(f => multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine + Strings.exit_code + ": " + tmp.ExitCode.ToString()); - this.InvokeEx(f => multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine + Strings.output + " " + current_out + " (" + Strings.failed.ToUpper() + ")"); - if (File.Exists(fullPath)) this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.failed); - else this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.file_not_f); - errors_enc = errors_enc + 1; - - } - - this.Invoke(new MethodInvoker(delegate - { - multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine; - multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine + "--------End of " + '\u0022' + listView1.Items[Convert.ToInt32(file_int)].Text + '\u0022' + " log--------" + Environment.NewLine; - multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine; - })); - - //End chapter loop item - tmp.StartInfo.Arguments = prev_params; - continue; - - } - // End process severy chapter - } - else - { - this.InvokeEx(f => f.listView1.Items[file_int].SubItems[5].Text = Strings.skipped); - tmp.StartInfo.Arguments = tmp.StartInfo.Arguments.Replace("[[split_chapters]]", ""); - } - } - - - // END split chapters - - tmp.StartInfo.FileName = ffm; - tmp.StartInfo.RedirectStandardInput = true; - tmp.StartInfo.RedirectStandardError = true; - tmp.StartInfo.StandardErrorEncoding = Encoding.UTF8; - tmp.StartInfo.UseShellExecute = false; - tmp.StartInfo.CreateNoWindow = true; - tmp.StartInfo.WorkingDirectory = Path.GetDirectoryName(fullPath); - tmp.EnableRaisingEvents = true; - - - if (!tmp.StartInfo.Arguments.Contains("[[split_chapters]]")) - { - tmp.Start(); - } - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.processing); - - combo_prio.Invoke(new MethodInvoker(delegate - { - if (combo_prio.SelectedIndex != 2) - { - try - { - if (combo_prio.SelectedIndex == 0) tmp.PriorityClass = ProcessPriorityClass.High; - if (combo_prio.SelectedIndex == 1) tmp.PriorityClass = ProcessPriorityClass.AboveNormal; - if (combo_prio.SelectedIndex == 2) tmp.PriorityClass = ProcessPriorityClass.Normal; - if (combo_prio.SelectedIndex == 3) tmp.PriorityClass = ProcessPriorityClass.BelowNormal; - if (combo_prio.SelectedIndex == 4) tmp.PriorityClass = ProcessPriorityClass.Idle; - Process[] localByName = Process.GetProcessesByName("FFBatch"); - if (localByName.Length == 1) - { - foreach (Process proc1 in localByName) - { - if (combo_prio.SelectedIndex >= 2) proc1.PriorityClass = ProcessPriorityClass.Normal; - else proc1.PriorityClass = tmp.PriorityClass; - } - } - } - catch { } - } - })); - - } - else - { - timer1.Stop(); - this.InvokeEx(f => f.listView1.Enabled = true); - working = false; - multi_running = false; - Enable_Controls(); - cancelados_paralelos = false; - return; - } - - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.processing); - - try - { - dest_drive = new DriveInfo(f_root.Directory.Root.FullName); - } - catch { warn_space = false; } - - String err_txt = ""; - Double interval = 0; - Double durat_n2 = 0; - this.InvokeEx(f => multi_logs["log_n_" + file_int.ToString()] = Strings.logging_f + " " + '\u0022' + listView1.Items[Convert.ToInt32(file_int)].Text + '\u0022' + Environment.NewLine); - if (paused == true) - { - try - { - tmp.Suspend(); - } - catch { Thread.Sleep(200); tmp.Suspend(); } - } - else - { - try - { - tmp.Resume(); - } - catch { Thread.Sleep(200); tmp.Resume(); } - } - - //REVIEW - while (!tmp.StandardError.EndOfStream) - { - err_txt = tmp.StandardError.ReadLine(); - space_timer++; - multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine + n_logs + err_txt; - - if (err_txt.Contains("time=") && err_txt.Contains("time=-") == false && !err_txt.Contains("time=N/A")) - { - this.InvokeEx(f => f.txt_remain.Refresh()); - this.InvokeEx(f => durat_n2 = row_duration); - durat_n2 = durat_n2 / atemp; - int start_time_index = err_txt.IndexOf("time=") + 5; - Double sec_prog = 0; - try - { - sec_prog = TimeSpan.Parse(err_txt.Substring(start_time_index, 8)).TotalSeconds; - } - catch { sec_prog = 0; } - Double percent = (sec_prog * 100 / durat_n2); - - total_prog = total_prog + (sec_prog - interval); - interval = sec_prog; - int percent2 = 0; - try - { - percent2 = Convert.ToInt32(percent); - } - catch - { - } - - if (percent2 <= 100) - { - if (Math.Round(percent, 1).ToString().Contains(".") || Math.Round(percent, 1).ToString().Contains(",")) - { - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Math.Round(percent, 1).ToString() + "%"); - } - else - { - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Math.Round(percent, 1).ToString() + ".0" + "%"); - } - } - - - try - { - if (err_txt.Contains("fps=")) - { - multi_fps[file_int] = (err_txt.Substring(err_txt.LastIndexOf("fps=") + 4, 4)).TrimStart(); - } - else - { - multi_fps[file_int] = "0"; - } - } - catch { multi_fps[file_int] = "0"; } - try - { - if (err_txt.ToLower().Contains("speed=")) - { - multi_speeds[file_int] = (err_txt.Substring(err_txt.LastIndexOf("speed=") + 6, err_txt.Length - err_txt.LastIndexOf("speed=") - 6)).Replace("x", ""); - } - else - { - multi_speeds[file_int] = "0"; - } - } - catch { multi_speeds[file_int] = "0"; } - } - - //Monitor available space - if (space_timer % 30 == 0 && dest_drive.AvailableFreeSpace <= 500000000 && warn_space == true) - { - foreach (Process proc in procs.Values) - { - try - { - proc.Suspend(); - } - catch - { - } - } - DialogResult a = MessageBox.Show(Strings.warn_sp, Strings.low_sp + " (" + (dest_drive2.AvailableFreeSpace / 1000000).ToString() + "MB)", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); - foreach (Process proc in procs.Values) - { - try - { - proc.Resume(); - } - catch - { - - } - } - - if (a == DialogResult.Yes) - { - cts.Cancel(); - aborted = true; - cancelados_paralelos = true; - - foreach (Process proc in procs.Values) - { - cancelados_paralelos = true; - if (proc.StartInfo.Arguments != String.Empty) - - { - try - { - StreamWriter write_q = proc.StandardInput; - write_q.Write("q"); - } - catch { } - } - } - } - - warn_space = false; - } - //End monitor space - } - tmp.WaitForExit(); - this.InvokeEx(f => multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine); - tmp.StartInfo.Arguments = String.Empty; - multi_speeds[file_int] = "0"; - multi_fps[file_int] = "0"; - current_f++; - - this.InvokeEx(f => f.lbl_items.Text = current_f.ToString() + " " + Strings.of1 + " " + listView1.Items.Count.ToString()); - - if (Settings.Default.quick_queue == true) - { - Double perc = (double)current_f * 100 / (double)listView1.Items.Count; - this.Invoke(new MethodInvoker(delegate - { - Pg1.Value = current_f * 100; - Pg1.Text = Math.Round(perc, 0) + "%"; - TaskbarProgress.SetValue(this.Handle, Pg1.Value, Pg1.Maximum); - txt_remain.Text = Strings.remain_time + " " + Strings.n_a; - })); - - } - if (tmp.ExitCode == 0 && aborted_url == false) - { - this.Invoke(new MethodInvoker(delegate - { - multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine + Strings.output + " " + current_out + " " + Strings.success + " (OK)"; - multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine; - })); - list_successful_m.Add(fullPath); - if (cancelados_paralelos == false && cts.IsCancellationRequested == false) - { - if (aborted_url == false) - { - if (File.Exists(fullPath) == true) - { - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.success); - - if (chk_delete_source.CheckState == CheckState.Checked && delete_def == false && delete_one == true) - { - try - { - FileSystem.DeleteFile(fullPath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.recycled); - } - catch (Exception exc) - { - MessageBox.Show(exc.Message); - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.not_recycled); - warn_enc++; - } - } - if (chk_delete_source.CheckState == CheckState.Checked && delete_def == true && delete_one == true) - { - try - { - FileInfo fs = new FileInfo(fullPath); - if (fs.IsReadOnly == true) fs.IsReadOnly = false; - File.Delete(fullPath); - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.deleted); - } - catch - { - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.not_deleted); - warn_enc++; - } - } - - if (chk_overw.CheckState == CheckState.Checked) - { - if (current_out == fullPath) - { - String sourc = destis[file_int] + "\\" + Path.GetFileNameWithoutExtension(fullPath) + "_fftemp" + add_suffix + ext_output1; - - try - { - if (File.Exists(sourc)) - { - File.Delete(fullPath); - FileSystem.RenameFile(sourc, Path.GetFileNameWithoutExtension(fullPath) + add_suffix + ext_output1); - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.replaced); - } - else - { - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.not_replaced); - warn_enc++; - this.InvokeEx(f => multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine + Strings.warning_file + " " + +'\u0022' + listView1.Items[Convert.ToInt32(file_int)].Text + '\u0022' + " " + Strings.warning_not_rep + " " + "(_fftemp)." + Environment.NewLine); - } - } - catch (Exception excpt) - { - try - { - FileSystem.RenameFile(sourc, Path.GetFileNameWithoutExtension(fullPath) + add_suffix + ext_output1); - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.replaced); - } - catch - { - try - { - FileSystem.RenameFile('\u0022' + sourc + '\u0022', '\u0022' + Path.GetFileNameWithoutExtension(fullPath) + add_suffix + ext_output1 + '\u0022'); - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.replaced); - } - catch - { - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.renamed); - warn_enc++; - this.InvokeEx(f => multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine + Strings.warning_file + " " + '\u0022' + listView1.Items[Convert.ToInt32(file_int)].Text + '\u0022' + " " + Strings.warning_not_rep + " " + "(_fftemp)." + Environment.NewLine); - } - } - } - } - } - } - } - if (aborted_url == true) - { - if (skipped == false) - { - this.InvokeEx(f => multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine + Strings.output + " " + current_out + " (" + Strings.aborted.ToUpper() + ")"); - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.aborted); - } - else - { - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.skipped); - try - { - File.Delete(current_out); - } - catch { } - } - aborted_url = false; - skipped = false; - } - - if (row_duration >= 30) save_queue(); - - //Run on each file - int index = 0; - Boolean sh_check = false; - combo_shut.Invoke(new MethodInvoker(delegate - { - index = combo_shut.SelectedIndex; - })); - - chkshut.Invoke(new MethodInvoker(delegate - { - if (chkshut.Checked == true) sh_check = true; - })); - - if (index == 4 && cancel_queue == false && sh_check == true) - { - this.InvokeEx(f => this.Enabled = false); - Form14 frm_run = new Form14(); - frm_run.txt_path.Text = run_command; - String dest_f = '\u0022' + destis[file_int] + "\\" + Path.GetFileNameWithoutExtension(fullPath) + add_suffix + ext_output1 + '\u0022'; - if (ext_output1 == "nul") dest_f = '\u0022' + destis[file_int] + "\\" + Path.GetFileNameWithoutExtension(fullPath) + add_suffix + Path.GetExtension(fullPath).Replace(".", "") + '\u0022'; - - frm_run.args = dest_f + " " + run_command_args; - frm_run.timer1.Interval = 100; - frm_run.ShowDialog(); - this.InvokeEx(f => this.Enabled = true); - Enable_Controls(); - - if (frm_run.proc.ExitCode == 0) - { - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = "OK & Run"); - multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine + n_logs + Strings.ext_com_ok + " " + dest_f + Environment.NewLine; - } - else - { - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = "OK & Error"); - multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine + n_logs + Strings.ext_com_err + " " + dest_f + Environment.NewLine; - } - this.Invoke(new MethodInvoker(delegate - { - multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine; - this.TopMost = true; - this.TopMost = false; - })); - - } - - //End run on each file - } - else - { - this.InvokeEx(f => f.listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.aborted); - - if (cancelados_paralelos == false) - { - aborted_url = false; - } - } - - if (keep_dates == true) - { - try - { - File.SetCreationTime(current_out, file_crea); - File.SetLastWriteTime(current_out, file_written); - File.SetLastAccessTime(current_out, file_modif); - } - catch { } - } - } - else - { - list_failed_m.Add(fullPath); - errors_enc = errors_enc + 1; - this.Invoke(new MethodInvoker(delegate - { - multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine + Strings.exit_code + ": " + tmp.ExitCode.ToString(); - multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine + Strings.output + " " + current_out + " (" + Strings.failed.ToUpper() + ")"; - - if (aborted_url == true || skipped == true) listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.skipped; - else if (File.Exists(fullPath)) listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.failed; - else listView1.Items[Convert.ToInt32(file_int)].SubItems[5].Text = Strings.file_not_f; - })); - } - - this.Invoke(new MethodInvoker(delegate - { - multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine; - multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine + "--------End of " + '\u0022' + listView1.Items[Convert.ToInt32(file_int)].Text + '\u0022' + " log--------" + Environment.NewLine; - multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine; - })); - - //file_int++; - }); - } - - catch (Exception exc) - { - fatal_parallel_msg = exc.Message; - fatal_parallel = true; - } - - if (result.IsCompleted == true) fatal_parallel = false; - else - { - if (cts.IsCancellationRequested == false) fatal_parallel = true; - else fatal_parallel = false; - } - String avgs = ""; - //Averages - - if (start_total_time == 0) start_total_time = 1; - Double avg_enc = Math.Round((total_multi_duration / start_total_time), 1); - - try - { - if (cancelados_paralelos == false) - { - if (tot_frames2 != 0) - { - avgs = Environment.NewLine + (Strings.avg_perf + " " + avg_enc.ToString() + "x" + " | " + Math.Round(tot_frames2 / (decimal)start_total_time, 0)).ToString() + " fps"; - this.InvokeEx(f => f.lbl_speed.Text = (Strings.avgs + " " + avg_enc.ToString() + "x" + " | " + Math.Round(tot_frames2 / (decimal)start_total_time, 0)).ToString() + " fps"); - } - else - { - avgs = Environment.NewLine + (Strings.avg_perf + " " + avg_enc.ToString() + "x"); - this.InvokeEx(f => f.lbl_speed.Text = (Strings.avgs + " " + avg_enc.ToString() + "x")); - } - } - } - catch { } - - //End averages - - if (no_save_logs == false) - { - String[] array_err = list_lines.ToArray(); - - String path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.log"; - if (is_portable == true) path = port_path + "ff_batch_portable.log"; - try - { - StreamWriter SaveFile = new StreamWriter(path); - SaveFile.WriteLine("Multi-file log session: " + System.DateTime.Now); - SaveFile.WriteLine("-----------------------------------------------------"); - SaveFile.Write(string.Join(Environment.NewLine, multi_logs.Select(a => $"{a.Value}"))); - SaveFile.Close(); - File.AppendAllText(path, avgs + Environment.NewLine + Environment.NewLine); - int count = 0; - this.InvokeEx(f => count = listView1.Items.Count); - File.AppendAllText(path, count.ToString() + " " + Strings.files + " " + Strings.queued.ToLower() + Environment.NewLine); - count = count - errors_enc; - File.AppendAllText(path, count.ToString() + " " + Strings.files + " " + Strings.encoded2.ToLower() + Environment.NewLine); - File.AppendAllText(path, errors_enc.ToString() + " " + Strings.errors1 + Environment.NewLine); - File.AppendAllText(path, warn_enc.ToString() + " " + Strings.warn1 + Environment.NewLine + Environment.NewLine); - File.AppendAllText(path, "-------------------------------------------------------"); - File.AppendAllText(path, Environment.NewLine + Strings.end_log + Environment.NewLine); - File.AppendAllText(path, "------------------------------------------------------"); - File.AppendAllText(path, Environment.NewLine); - FileInfo fileInfo = new FileInfo(path); - - var bytes = fileInfo.Length; - - var kilobytes = (double)bytes / 1024; - var megabytes = kilobytes / 1024; - var gigabytes = megabytes / 1024; - - //Format size view - String size = ""; - String separator = "."; - - if (bytes > 1000000000) - { - if (gigabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String gigas = gigabytes.ToString(); - if (gigas.Length >= 5) - { - gigas = gigas.Substring(0, gigas.LastIndexOf(separator) + 3); - size = (gigas + " " + "GB"); - } - else - { - size = (gigas + " " + "GB"); - } - } - - if (bytes >= 1048576 && bytes <= 1000000000) - { - if (megabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - String megas = megabytes.ToString(); - if (megas.Length > 5) - { - megas = megas.Substring(0, megas.LastIndexOf(separator)); - size = (megas + " " + "MB"); - } - else - { - size = (megas + " " + "MB"); - } - } - - if (bytes >= 1024 && bytes < 1048576) - - { - if (kilobytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String kbs = kilobytes.ToString(); - if (kbs.Length >= 5) - { - kbs = kbs.Substring(0, kbs.LastIndexOf(separator)); - size = (kbs + " " + "KB"); - } - else - { - size = (kbs + " " + "KB"); - } - } - if (bytes > -1 && bytes < 1024) - { - String bits = bytes.ToString(); - size = (bits + " Bytes"); - } - - //End Format size view - File.AppendAllText(path, Environment.NewLine + Strings.log_size + " " + size); - } - catch { } - //End save log - } - } - - private void BG_Multi_M_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) - { - timer_queue.Enabled = false; - aborted_url = false; - skipped = false; - del_queue(); - - //lbl_items.Text = listView1.Items.Count.ToString() + " " + Strings.files; - listView1.SelectedIndices.Clear(); - - try { clean_ffb_test(); } catch { } - - Boolean pending_item = false; - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[5].Text == Strings.queued) - { - pending_item = true; - break; - } - } - if (pending_item == true && aborted == false) - { - ignore_encoded = true; - BG_Multi_M.RunWorkerAsync(); - return; - } - else ignore_encoded = get_ingnorenc(); - - this.Text = "FFmpeg Batch AV Converter"; - - if (is_portable == true) this.Text = "FFmpeg Batch AV Converter Portable"; - timer_aborting.Stop(); - - // Close abort form - for (int i = Application.OpenForms.Count - 1; i >= 0; i--) - { - if (Application.OpenForms[i].Name == "Form12") - { - this.InvokeEx(f => Application.OpenForms[i].Close()); - break; - } - } - //End close abort form - listView1.SelectedItems.Clear(); - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - timer1.Stop(); - timer_tasks.Stop(); - Pg1.Value = Pg1.Maximum; - Pg1.Text = "100%"; - Pg1.Refresh(); - listView1.Enabled = true; - working = false; - multi_running = false; - Enable_Controls(); - if (Settings.Default.quick_queue == true) - { - calc_list_dur(); - calc_list_size(); - } - - if (cancelados_paralelos == false && fatal_parallel == false) - { - //Open on completion - String primero_lista = listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text; - String destino2 = String.Empty; - if (chk_open_compl.Checked == true) - { - if (txt_path_main.Text.Contains(".\\")) - { - destino2 = destino2 = primero_lista.Substring(0, primero_lista.LastIndexOf('\\')) + txt_path_main.Text.Replace(".", String.Empty); ; - } - else - { - destino2 = txt_path_main.Text; - } - } - - if (chk_delete_source.CheckState == CheckState.Checked && delete_def == false && delete_one == false) - { - Disable_Controls(); - - Label prog_txt = new Label(); - prog_txt.Parent = panel1; - prog_txt.Top = 95; - prog_txt.Left = 80; - prog_txt.Width = 250; - prog_txt.TabIndex = 1; - prog_txt.BackColor = panel1.BackColor; - prog_txt.BorderStyle = BorderStyle.None; - prog_txt.TextAlign = ContentAlignment.MiddleLeft; - prog_txt.BringToFront(); - prog_txt.Text = Strings.to_recycle; - - - int i = 0; - int err = 0; - - if (list_successful_m.Count > 0) - { - try - { - FileOperationAPIWrapper.SendToRecycleBin(list_successful_m, FileOperationAPIWrapper.FileOperationFlags.FOF_WANTNUKEWARNING); - - foreach (ListViewItem item in listView1.Items) - { - String fullpath = item.SubItems[1].Text + "\\" + item.Text; - if (!File.Exists(fullpath)) item.SubItems[5].Text = Strings.recycled; - } - } - catch - { - MessageBox.Show(Strings.not_recycled3, Strings.warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - } - - prog_txt.Visible = false; - prog_txt.Dispose(); - - Enable_Controls(); - //if (err > 0) MessageBox.Show(err.ToString() + " " + Strings.not_recycled2 + Strings.check_log, Strings.not_recycled3, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - - if (list_failed_m.Count > 0) - { - String path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.log"; - if (is_portable == true) path = port_path + "ff_batch_portable.log"; - - File.AppendAllText(path, Environment.NewLine + Environment.NewLine + Strings.source_not_deleted); - File.AppendAllText(path, Environment.NewLine + "-------------------------------"); - foreach (String item in list_failed_m) - { - File.AppendAllText(path, Environment.NewLine + item); - } - } - - //End delete source - } - - if (chk_delete_source.CheckState == CheckState.Checked && delete_def == true && delete_one == false) - { - Disable_Controls(); - - Label prog_txt = new Label(); - prog_txt.Parent = panel1; - prog_txt.Top = 95; - prog_txt.Left = 80; - prog_txt.Width = 250; - prog_txt.TabIndex = 1; - prog_txt.BackColor = panel1.BackColor; - prog_txt.BorderStyle = BorderStyle.None; - prog_txt.TextAlign = ContentAlignment.MiddleLeft; - prog_txt.BringToFront(); - prog_txt.Text = Strings.deleting_files; - - ProgressBar pg_del = new ProgressBar(); - pg_del.Parent = panel1; - pg_del.Top = 98; - pg_del.Left = 315; - pg_del.Width = 152; - pg_del.Height = 15; - pg_del.TabIndex = 0; - pg_del.BackColor = this.BackColor; - pg_del.Minimum = 0; - pg_del.BringToFront(); - pg_del.Maximum = listView1.Items.Count; - pg_del.Show(); - pg_del.Refresh(); - int i = 0; - int err = 0; - - foreach (String item in list_successful_m) - { - try - { - FileInfo fs = new FileInfo(item); - if (fs.IsReadOnly == true) fs.IsReadOnly = false; - File.Delete(item); - pg_del.Value = i; - i = i + 1; - - foreach (ListViewItem item2 in listView1.Items) - { - if (item2.Text == Path.GetFileName(item)) - { - item2.SubItems[5].Text = Strings.deleted; - } - } - } - catch - { - err = err + 1; - - foreach (ListViewItem item2 in listView1.Items) - { - if (item2.Text == Path.GetFileName(item)) - { - item2.SubItems[5].Text = Strings.not_deleted; - } - } - } - prog_txt.Text = Strings.deleting_f + " " + i.ToString() + " " + Strings.of1 + " " + list_global_proc.Items.Count; - prog_txt.Refresh(); - } - prog_txt.Visible = false; - prog_txt.Dispose(); - pg_del.Visible = false; - pg_del.Dispose(); - Enable_Controls(); - - if (err > 0) MessageBox.Show(err.ToString() + " " + Strings.not_recycled2 + " " + Strings.check_log, Strings.not_recycled3, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - - if (list_failed_m.Count > 0) - { - String path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.log"; - if (is_portable == true) path = port_path + "ff_batch_portable.log"; - - File.AppendAllText(path, Environment.NewLine + Environment.NewLine + Strings.source_not_deleted); - File.AppendAllText(path, Environment.NewLine + "-------------------------------"); - foreach (String item in list_failed_m) - { - File.AppendAllText(path, Environment.NewLine + item); - } - } - - //End delete source - } - toolT002.RemoveAll(); - - if (errors_enc == 0) - { - pic_no_errors.Visible = true; - //Delete source - - //Automatic shutdown check - if (chkshut.Checked) - { - auto_shut(); - return; - } - - if (warn_enc > 0) - { - pic_no_errors.Visible = false; - pic_recording.Visible = false; - toolT002.SetToolTip(this.pic_warnings, Strings.there_w + " " + warn_enc.ToString() + " " + Strings.warnings_last_s); - pic_warnings.Visible = true; - } - } - else - { - pic_no_errors.Visible = false; - pic_recording.Visible = false; - toolT002.SetToolTip(this.pic_warnings, Strings.there_w + " " + errors_enc.ToString() + " " + Strings.errors_se); - pic_warnings.Visible = true; - } - - if (errors_enc == 0) - { - if (play_on_end == true) play_end(); - } - else if (play_on_end == true) System.Media.SystemSounds.Asterisk.Play(); - - if (this.ContainsFocus == false) - { - if (errors_enc == 0 && warn_enc == 0) - { - notifyIcon1.BalloonTipText = Strings.enc_comp + ". " + Environment.NewLine + procs.Count.ToString() + " " + Strings.files + " " + Strings.encoded + "."; - notifyIcon1.BalloonTipIcon = ToolTipIcon.Info; - notifyIcon1.BalloonTipTitle = Strings.enc_comp2; - notifyIcon1.ShowBalloonTip(0); - } - if (errors_enc > 0) - { - notifyIcon1.BalloonTipText = Strings.enc_comp3 + " " + errors_enc.ToString() + " " + Strings.errors1; - notifyIcon1.BalloonTipIcon = ToolTipIcon.Warning; - notifyIcon1.BalloonTipTitle = Strings.enc_comp2; - notifyIcon1.ShowBalloonTip(0); - } - if (errors_enc == 0 && warn_enc > 0) - { - if (errors_enc == 0 && warn_enc > 0) - { - notifyIcon1.BalloonTipText = Strings.enc_warns; - notifyIcon1.BalloonTipIcon = ToolTipIcon.Warning; - notifyIcon1.BalloonTipTitle = Strings.enc_comp2; - notifyIcon1.ShowBalloonTip(0); - } - } - } - - if (chk_open_compl.Checked == true && opened_m == false) - { - opened_m = true; - try - { - if (Directory.GetFiles(destino2).Length != 0) - { - Process open_processed = new Process(); - open_processed.StartInfo.FileName = "explorer.exe"; - open_processed.StartInfo.Arguments = '\u0022' + multi_dest + '\u0022'; - open_processed.Start(); - } - else - { - if (Directory.Exists(destino2)) - { - Directory.Delete(destino2); - } - } - } - catch - { - } - } - - return; - } - else - { - if (aborted == true) - { - aborted = false; - MessageBox.Show(Strings.queue_abort, Strings.task_abort, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - } - cancelados_paralelos = false; - } - } - - private void clean_ffb_test() - { - //Clean ffbatch_test - String destino_test = Path.GetTempPath() + "\\" + "FFBatch_test"; - try - { - if (Directory.Exists(destino_test) && Directory.GetFiles(destino_test).Length > 0) - { - foreach (String file in Directory.GetFiles(destino_test)) - { - try - { - File.Delete(file); - } - catch { } - } - } - } - catch { } - - if (Directory.Exists(destino_test) && Directory.GetFiles(destino_test).Length == 0) - try { Directory.Delete(destino_test); } catch { } - - try - { - if (Directory.Exists(destino_test)) - { - if (Directory.GetFiles(destino_test).Length == 0) - { - try - { - Directory.Delete(destino_test); - } - catch { } - } - } - } - catch { } - - try { Directory.Delete(destino_test, recursive: true); } catch { } - - //End clean TEMP ffbatch_test - } - - private void BG_Validate_added_row_YT_PL_S_DoWork(object sender, DoWorkEventArgs e) - { - this.InvokeEx(f => this.Enabled = false); - foreach (DataGridViewRow row in dg1.Rows) row.Cells[5].Value = Strings.get_cont; - - if (dg1.Rows[dg1.RowCount - 1].Cells[1].Value == null) - { - dg1.Rows[dg1.RowCount - 1].Cells[5].Value = String.Empty; - dg1.Rows[dg1.RowCount - 1].Cells[4].Value = String.Empty; - dg1.Rows[dg1.RowCount - 1].Cells[3].Value = String.Empty; - dg1.Rows[dg1.RowCount - 1].Cells[2].Value = String.Empty; - //dg1.Rows[dg1.RowCount - 1].DefaultCellStyle.BackColor = dg1.DefaultCellStyle.BackColor; - return; - } - - if (dg1.Rows[dg1.RowCount - 1].Cells[1].Value.ToString().Contains("http") == false) - { - dg1.Rows[dg1.RowCount - 1].Cells[5].Value = Strings.error; - dg1.Rows[dg1.RowCount - 1].DefaultCellStyle.BackColor = Color.LightGoldenrodYellow; - return; - } - - dg1.Invoke(new MethodInvoker(delegate - { - dg1.Refresh(); - dg1_temp.Rows.Clear(); - dg1_temp.Columns.Clear(); - dg1.AllowUserToAddRows = false; - foreach (DataGridViewColumn col in dg1.Columns) dg1_temp.Columns.Add((DataGridViewColumn)col.Clone()); ; - })); - - int prog = 0; - - procs.Clear(); - for (int ii = 0; ii < dg1.RowCount; ii++) - { - procs.Add("proc_urls_" + ii.ToString(), new Process()); - } - - ParallelOptions par_op = new ParallelOptions(); - par_op.MaxDegreeOfParallelism = (int)n_downs.Value; - System.Threading.CancellationTokenSource cts = new System.Threading.CancellationTokenSource(); - par_op.CancellationToken = cts.Token; - - var workItems = Enumerable.Range(0, dg1.RowCount); - ParallelLoopResult result = new ParallelLoopResult(); - fatal_parallel = false; - fatal_parallel_msg = ""; - - int current = 0; - object lockCurrent = new object(); - - Form9 form_prog2 = new Form9(); - - new System.Threading.Thread(() => - { - System.Threading.Thread.CurrentThread.IsBackground = true; - - form_prog2.progressBar1.Visible = false; - form_prog2.pictureBox2.Visible = true; - form_prog2.label1.Text = Strings.pl_contents; - form_prog2.lab_count.Text = ""; - form_prog2.lab_count.Refresh(); - form_prog2.Refresh(); - form_prog2.progressBar1.Refresh(); - this.Invoke(new MethodInvoker(delegate - { - form_prog2.ShowDialog(this); - })); - - }).Start(); - - try - { - result = Parallel.ForEach(Partitioner.Create(workItems, EnumerablePartitionerOptions.NoBuffering), par_op, (ii2) => - { - int ii = 0; - lock (lockCurrent) - { - ii = current; - current++; - } - - var probe = procs["proc_urls_" + ii.ToString()]; - - if (form_prog2.abort_validate == true || stop_validating_url == true) - { - cts.Cancel(); - } - - if (cts.IsCancellationRequested == true) form_prog2.abort_validate = true; - - if (dg1.Rows[ii].Cells[1].Value == null) form_prog2.abort_validate = true; - - if (stop_validating_url == true) form_prog2.abort_validate = true; - - probe.StartInfo.FileName = Path.Combine(Application.StartupPath, "yt-dlp.exe"); - probe.StartInfo.WorkingDirectory = Application.StartupPath; - probe.StartInfo.Arguments = "--flat-playlist --dump-json " + dg1.Rows[ii].Cells[1].Value.ToString(); - probe.StartInfo.RedirectStandardOutput = true; - probe.StartInfo.UseShellExecute = false; - probe.StartInfo.StandardOutputEncoding = Encoding.UTF8; - probe.StartInfo.CreateNoWindow = true; - probe.EnableRaisingEvents = true; - - probe.Start(); - String line = ""; - - while (!probe.StandardOutput.EndOfStream) - { - if (form_prog2.abort_validate == true || stop_validating_url == true) - { - cts.Cancel(); - } - else - { - line = probe.StandardOutput.ReadLine(); - - if (line != null && line != "") dg1_temp.Rows.Add(pic_noimg.Image, "https://www.youtube.com/watch?v=" + line.Substring(line.IndexOf('\u0022' + "url" + '\u0022' + ": " + '\u0022') + 8, 11), "-", "-", "", ""); - } - } - probe.WaitForExit(); - probe.StartInfo.Arguments = String.Empty; - ii++; - }); - } - catch { } - - form_prog2.Invoke(new MethodInvoker(delegate - { form_prog2.Close(); })); - - if (result.IsCompleted == true) fatal_parallel = false; - else - { - if (cts.IsCancellationRequested == false) fatal_parallel = true; - else fatal_parallel = false; - } - - //End Parallel - try - { - form_prog2.Invoke(new MethodInvoker(delegate - { form_prog2.Close(); })); - } - catch { form_prog2.abort_validate = true; } - } - - private void BG_Validate_added_row_YT_PL_S_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) - { - playlists_int = dg1_temp.RowCount; - if (dg1_temp.RowCount > 2000) - { - MessageBox.Show(Strings.max_links, Strings.max_list, MessageBoxButtons.OK, MessageBoxIcon.Warning); - release_datagrid(); - return; - } - else - { - if (stop_validating_url == false && fatal_parallel == false) - { - dg1.Rows.Clear(); - foreach (DataGridViewRow row2 in dg1_temp.Rows) - { - DataGridViewRow clonedRow = (DataGridViewRow)row2.Clone(); - for (Int32 index = 0; index < row2.Cells.Count; index++) - { - clonedRow.Cells[index].Value = row2.Cells[index].Value; - } - dg1.Rows.Add(clonedRow); - } - foreach (DataGridViewRow row3 in dg1.Rows) - { - if (row3.Cells[1].Value == null) dg1.Rows.RemoveAt(row3.Index); - } - dg1.Refresh(); - } - dg1.ReadOnly = false; - this.Enabled = true; - this.TopMost = true; - this.TopMost = false; - btn_validate_url.PerformClick(); - } - } - - private void timer_aborting_Tick(object sender, EventArgs e) - { - timer_aborting.Stop(); - Form12 frm_abort = new Form12(); - try - { - this.Invoke(new MethodInvoker(delegate - { - frm_abort.ShowDialog(this); - frm_abort.Refresh(); - })); - - } - catch { } - } - - private void BG_Multi_Down_DoWork(object sender, DoWorkEventArgs e) - { - Disable_Controls(); - aborted = false; - cancelados_paralelos = false; - m3u_running = true; - m3u_single_running = false; - fatal_parallel = false; - fatal_parallel_msg = ""; - Boolean quit = false; - List list_lines = new List(); - List er = new List(); - String msg_er = String.Empty; - - ParallelOptions par_op = new ParallelOptions(); - par_op.MaxDegreeOfParallelism = (int)n_downs.Value; - CancellationTokenSource cts = new System.Threading.CancellationTokenSource(); - par_op.CancellationToken = cts.Token; - - int current = 0; - object lockCurrent = new object(); - - ParallelLoopResult result = new ParallelLoopResult(); - var workItems = Enumerable.Range(0, dg1.RowCount); - try - { - result = Parallel.ForEach(Partitioner.Create(workItems, EnumerablePartitionerOptions.NoBuffering), par_op, (file_int2) => - { - int file_int = 0; - lock (lockCurrent) - { - file_int = current; - current++; - } - - Boolean skip = false; - //String all_logs = ""; - - if (dg1.Rows[file_int].IsNewRow) skip = true; - - DataGridViewRow tmp_row = dg1.Rows[file_int]; - - if (cancelados_paralelos == true || aborted == true) - { - cts.Cancel(); - return; - } - - String url_capture_time = String.Empty; - - Double total_prog = 0; - Double row_duration = 0; - - TimeSpan time2; - if (TimeSpan.TryParse(tmp_row.Cells[3].Value.ToString(), out time2)) - { - row_duration = TimeSpan.Parse(tmp_row.Cells[3].Value.ToString()).TotalSeconds; - url_capture_time = " -t " + row_duration.ToString(); - } - else - { - row_duration = 0; - url_capture_time = String.Empty; - } - - String ffm = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - String file = tmp_row.Cells[1].Value.ToString(); - String destino = txt_path_m3u.Text; - if (chk_yt_chapt.Checked) - { - destino = "chapter:" + txt_path_m3u.Text + "\\" + dg1.Rows[file_int].Cells[4].Value.ToString() + "\\" + "%(section_number)s. %(section_title)s.%(ext)s"; - } - - String pre_input_var = ""; - if (txt_pre_input.Text != "") - { - pre_input_var = txt_pre_input.Text; - } - - String pre_ss = ""; - if (TimeSpan.Parse(ss_time_input.Text).TotalSeconds != 0) - { - pre_ss = " -ss " + ss_time_input.Text; - } - - add_suffix = ""; - - String ext_output1 = txt_format.Text; - if (txt_format.Text == String.Empty) - { - ext_output1 = Path.GetExtension(file); - } - else - { - ext_output1 = "." + txt_format.Text; - } - - String AppParam = String.Empty; - - if (chk_output_server.CheckState == CheckState.Checked) - { - AppParam = pre_input_var + " " + pre_ss + " -i " + file + " " + url_capture_time + " " + m3u_params_m + " -y " + output_server_m; - } - else - { - AppParam = pre_input_var + " " + pre_ss + " -i " + file + " " + url_capture_time + " " + m3u_params_m + " -y " + '\u0022' + Path.Combine(destino, tmp_row.Cells[4].Value.ToString() + "." + m3u_output_ext_m); - } - - if (!Directory.Exists(destino)) - { - if (chk_yt_chapt.Checked == false) - { - try - { - Directory.CreateDirectory(destino); - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.err_write_out + " " + excpt.Message, Strings.write_error2, MessageBoxButtons.OK, MessageBoxIcon.Error); - this.Cursor = Cursors.Arrow; - return; - } - } - else - { - try - { - Directory.CreateDirectory(txt_path_m3u.Text); - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.err_write_out + " " + excpt.Message, Strings.write_error2, MessageBoxButtons.OK, MessageBoxIcon.Error); - this.Cursor = Cursors.Arrow; - return; - } - } - } - var tmp = procs["proc_urls_" + tmp_row.Index]; - var n_logs = multi_logs["log_n_" + tmp_row.Index.ToString()]; - - if (!multi_dest.ToLower().Contains("m3u")) - { - tmp.StartInfo.FileName = Path.Combine(Application.StartupPath, "yt-dlp.exe"); - if (m3u_params_m.Contains("-f ")) - { - tmp.StartInfo.Arguments = bestv_a + " " + Clear_cache + " " + m3u_params_m + " " + down_speed_m + " " + embed_subs_m + " " + auto_subs_m + " " + embed_meta_m + " " + write_subs_m + " " + convert_subs_m + " -o " + '\u0022' + destino + "\\" + tmp_row.Cells[4].Value.ToString() + "." + format_out_m + '\u0022' + " " + file; - if (chk_yt_chapt.Checked) - { - tmp.StartInfo.Arguments = bestv_a + " " + Clear_cache + " " + m3u_params_m + " " + down_speed_m + " " + embed_subs_m + " " + auto_subs_m + " " + embed_meta_m + " " + write_subs_m + " " + convert_subs_m + " " + chapters_m + " -o " + '\u0022' + destino + '\u0022' + " " + file; - tmp.StartInfo.WorkingDirectory = txt_path_m3u.Text; - } - } - else - { - if (bestv_a.Length == 0) - { - tmp.StartInfo.Arguments = Clear_cache + " " + m3u_params_m + " " + down_speed_m + " " + embed_subs_m + " " + auto_subs_m + " " + embed_meta_m + " -o " + '\u0022' + destino + "\\" + tmp_row.Cells[4].Value.ToString() + "." + format_out_m + '\u0022' + " " + file; - tmp.StartInfo.WorkingDirectory = Application.StartupPath; - if (chk_yt_chapt.Checked) - { - tmp.StartInfo.Arguments = Clear_cache + " -f " + format_out_m + " " + m3u_params_m + " " + down_speed_m + " " + embed_subs_m + " " + auto_subs_m + " " + embed_meta_m + " " + chapters_m + " -o " + '\u0022' + destino + '\u0022' + " " + file; - tmp.StartInfo.WorkingDirectory = txt_path_m3u.Text; - } - - - } - else - { - tmp.StartInfo.Arguments = bestv_a + " " + Clear_cache + " " + m3u_params_m + " " + down_speed_m + " " + embed_subs_m + " " + auto_subs_m + " " + embed_meta_m + " -o " + '\u0022' + destino + "\\" + tmp_row.Cells[4].Value.ToString() + "." + format_out_m + '\u0022' + " " + file; - tmp.StartInfo.WorkingDirectory = Application.StartupPath; - if (chk_yt_chapt.Checked) - { - tmp.StartInfo.Arguments = bestv_a + " " + Clear_cache + " " + m3u_params_m + " " + down_speed_m + " " + embed_subs_m + " " + auto_subs_m + " " + embed_meta_m + " " + chapters_m + " -o " + '\u0022' + destino + '\u0022' + " " + file; - tmp.StartInfo.WorkingDirectory = txt_path_m3u.Text; - } - - - } - } - } - else - { - tmp.StartInfo.FileName = ffm; - tmp.StartInfo.Arguments = AppParam; - } - - tmp.StartInfo.RedirectStandardInput = true; - tmp.StartInfo.RedirectStandardOutput = true; - tmp.StartInfo.RedirectStandardError = true; - tmp.StartInfo.StandardOutputEncoding = Encoding.UTF8; - tmp.StartInfo.StandardErrorEncoding = Encoding.UTF8; - tmp.StartInfo.UseShellExecute = false; - tmp.StartInfo.CreateNoWindow = true; - tmp.EnableRaisingEvents = true; - - dg1.Invoke(new MethodInvoker(delegate - { - if (dg1.Rows[file_int].Cells[3].Value.ToString() == "Live") dg1.Rows[file_int].Cells[5].Value = Strings.recording1; - else dg1.Rows[file_int].Cells[5].Value = Strings.init1; - })); - - if (cts.IsCancellationRequested == false && quit == false) - { - tmp.Start(); - - combo_prio.Invoke(new MethodInvoker(delegate - { - if (combo_prio.SelectedIndex != 2) - { - try - { - if (combo_prio.SelectedIndex == 0) tmp.PriorityClass = ProcessPriorityClass.High; - if (combo_prio.SelectedIndex == 1) tmp.PriorityClass = ProcessPriorityClass.AboveNormal; - if (combo_prio.SelectedIndex == 2) tmp.PriorityClass = ProcessPriorityClass.Normal; - if (combo_prio.SelectedIndex == 3) tmp.PriorityClass = ProcessPriorityClass.BelowNormal; - if (combo_prio.SelectedIndex == 4) tmp.PriorityClass = ProcessPriorityClass.Idle; - Process[] localByName = Process.GetProcessesByName("FFBatch"); - if (localByName.Length == 1) - { - foreach (Process proc1 in localByName) - { - if (combo_prio.SelectedIndex >= 2) proc1.PriorityClass = ProcessPriorityClass.Normal; - else proc1.PriorityClass = tmp.PriorityClass; - } - } - } - catch { } - } - })); - } - else - { - timer2.Stop(); - timer_tasks.Stop(); - this.Invoke(new MethodInvoker(delegate - { - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - Pg1.Value = Pg1.Maximum; - Pg1.Text = "100%"; - Pg1.Refresh(); - })); - working = false; - m3u_running = false; - Enable_Controls(); - cancelados_paralelos = false; - return; - } - - // this.InvokeEx(f => validate_duration = tmp_row.Cells[3].Value.ToString()); - Boolean valid_prog2 = false; - TimeSpan time3; - if (TimeSpan.TryParse(tmp_row.Cells[3].Value.ToString(), out time3)) - { - if (TimeSpan.Parse(tmp_row.Cells[3].Value.ToString()).TotalSeconds > 0) - { - valid_prog2 = true; - } - } - else - { - valid_prog2 = false; - } - - String err_txt = ""; - Double interval = 0; - Double sec_prog = 0; - Boolean chapters_err = false; - - //REVIEW - multi_logs["log_n_" + tmp_row.Index.ToString()] = Strings.logging_f + " " + tmp_row.Cells[4].Value.ToString() + Environment.NewLine; - - if (file.ToLower().Contains("m3u")) - { - while (!tmp.StandardError.EndOfStream) - { - err_txt = tmp.StandardError.ReadLine(); - multi_logs["log_n_" + tmp_row.Index.ToString()] = multi_logs["log_n_" + tmp_row.Index.ToString()] + Environment.NewLine + n_logs + err_txt; - - if (err_txt.Contains("time=") && err_txt.Contains("time=-") == false) - { - if (valid_prog2 == true) - { - this.InvokeEx(f => durat_n = row_duration); - int start_time_index = err_txt.IndexOf("time=") + 5; - sec_prog = TimeSpan.Parse(err_txt.Substring(start_time_index, 8)).TotalSeconds; - Double percent = (sec_prog * 100 / durat_n); - - total_prog = total_prog + (sec_prog - interval); - interval = sec_prog; - int percent2 = Convert.ToInt32(percent); - - if (percent2 <= 100) - { - this.InvokeEx(f => f.dg1.Rows[tmp_row.Index].Cells[5].Value = percent2.ToString() + "%"); - - if (show_total_prog_m == true) - { - Double dg_multi_prog = 0; - foreach (DataGridViewRow row_p in dg1.Rows) - { - try - { - if (row_p.Cells[5].Value.ToString().Contains("%") == true) - { - this.InvokeEx(f => dg_multi_prog = dg_multi_prog + Convert.ToDouble(row_p.Cells[5].Value.ToString().Replace("%", ""))); - } - - if (row_p.Cells[5].Value.ToString() == Strings.success || row_p.Cells[5].Value.ToString() == Strings.failed || row_p.Cells[5].Value.ToString() == Strings.aborted) - { - this.InvokeEx(f => dg_multi_prog = dg_multi_prog + 100); - } - } - catch { } - } - - this.InvokeEx(f => f.Pg1.Value = Convert.ToInt32(dg_multi_prog)); - if (Math.Round(dg_multi_prog / dg1.Rows.Count, 1).ToString().Contains(".") || Math.Round(dg_multi_prog / dg1.Rows.Count, 1).ToString().Contains(",")) - { - this.InvokeEx(f => f.Pg1.Text = Math.Round(dg_multi_prog / dg1.Rows.Count, 1).ToString() + "%"); - } - else - { - this.InvokeEx(f => f.Pg1.Text = Math.Round(dg_multi_prog / dg1.Rows.Count, 1).ToString() + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0" + "%"); - } - - this.InvokeEx(f => TaskbarProgress.SetValue(this.Handle, dg_multi_prog, Pg1.Maximum)); - - //this.InvokeEx(f => pg_lv.Value = Convert.ToInt16(percent2)); - if (Math.Round(percent, 1).ToString().Contains(".") || Math.Round(percent, 1).ToString().Contains(",")) - { - this.InvokeEx(f => f.dg1.Rows[tmp_row.Index].Cells[5].Value = Math.Round(percent, 1).ToString() + "%"); - } - if (cancelados_paralelos != true) - { - //this.InvokeEx(f => pg_lv.Refresh()); - } - else - { - //this.InvokeEx(f => pg_lv.Visible = false); - } - } - } - } - } - } // while - } - else - { - if (has_lives_multi == false) - { - //this.InvokeEx(f => pg_lv.Maximum = 100); - int progress = 0; - while (!tmp.StandardOutput.EndOfStream) - { - err_txt = tmp.StandardOutput.ReadLine(); - if (err_txt.ToLower().Contains(err_chaps)) chapters_err = true; - multi_logs["log_n_" + tmp_row.Index.ToString()] = multi_logs["log_n_" + tmp_row.Index.ToString()] + Environment.NewLine + n_logs + err_txt; - - if (err_txt.Contains("%")) - { - try - { - Double prog_y = Double.Parse(err_txt.Substring(err_txt.IndexOf("%") - 4, 4)); - prog_y = prog_y / 10; - progress = Convert.ToInt32(prog_y); - } - catch { } - this.InvokeEx(f => f.dg1.Rows[tmp_row.Index].Cells[5].Value = progress.ToString() + "%"); - //this.InvokeEx(f => pg_lv.Refresh()); - } - } - } - } - - er.Clear(); - msg_er = String.Empty; - - multi_logs["log_n_" + tmp_row.Index.ToString()] = multi_logs["log_n_" + tmp_row.Index.ToString()] + Environment.NewLine; - - while (!tmp.StandardError.EndOfStream) - { - er.Add(tmp.StandardError.ReadLine().Replace("yt-dlp.exe:", "")); - } - - if (er.Count > 0) - { - try - { - foreach (String st in er) - { - if (st == null) continue; - if (st.ToLower().Contains("usage: youtube-dl") == false) - { - msg_er = msg_er + st; - multi_logs["log_n_" + tmp_row.Index.ToString()] = multi_logs["log_n_" + tmp_row.Index.ToString()] + n_logs + msg_er; - } - } - } - catch { } - } - - tmp.WaitForExit(); - - if (chk_yt_chapt.Checked && chapters_err == true) - { - multi_logs["log_n_" + tmp_row.Index.ToString()] = multi_logs["log_n_" + tmp_row.Index.ToString()] + Environment.NewLine; - multi_logs["log_n_" + tmp_row.Index.ToString()] = multi_logs["log_n_" + tmp_row.Index.ToString()] + Strings.err_chap; - } - multi_logs["log_n_" + tmp_row.Index.ToString()] = multi_logs["log_n_" + tmp_row.Index.ToString()] + Environment.NewLine; - multi_logs["log_n_" + tmp_row.Index.ToString()] = multi_logs["log_n_" + tmp_row.Index.ToString()] + "Exit code: " + tmp.ExitCode.ToString(); - multi_logs["log_n_" + tmp_row.Index.ToString()] = multi_logs["log_n_" + tmp_row.Index.ToString()] + Environment.NewLine; - multi_logs["log_n_" + tmp_row.Index.ToString()] = multi_logs["log_n_" + tmp_row.Index.ToString()] + Environment.NewLine + "--------End of " + dg1.Rows[tmp_row.Index].Cells[4].Value.ToString() + " log--------" + Environment.NewLine; - tmp.StartInfo.Arguments = String.Empty; - - if (tmp.ExitCode == 0) - { - if (aborted_url == false) - { - this.InvokeEx(f => f.dg1.Rows[tmp_row.Index].Cells[5].Value = Strings.success); - if (chk_yt_chapt.Checked && chapters_err == true) - { - this.InvokeEx(f => f.dg1.Rows[tmp_row.Index].Cells[5].Value = Strings.error); - errors_enc++; - } - } - else - { - this.InvokeEx(f => f.dg1.Rows[tmp_row.Index].Cells[5].Value = Strings.aborted); - - if (cancelados_paralelos == false) - { - aborted_url = false; - } - } - } - else - { - this.InvokeEx(f => f.dg1.Rows[tmp_row.Index].Cells[5].Value = Strings.failed); - this.InvokeEx(f => f.dg1.Rows[tmp_row.Index].Cells[5].Style.BackColor = Color.PaleGoldenrod); - } - - file_int++; - //End loop - }); - } - catch (Exception exc) - { - fatal_parallel_msg = exc.Message; - fatal_parallel = true; - } - if (result.IsCompleted == true) fatal_parallel = false; - else - { - if (cts.IsCancellationRequested == false) fatal_parallel = true; - else fatal_parallel = false; - } - if (no_save_logs == false && quit == false && has_lives_multi == false) - { - String[] array_err = list_lines.ToArray(); - - String path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.log"; - if (is_portable == true) path = port_path + "ff_batch_portable.log"; - - try - { - StreamWriter SaveFile = new StreamWriter(path); - SaveFile.WriteLine("Multiple downloads log sesion: " + System.DateTime.Now); - SaveFile.WriteLine("-----------------------------------------------------"); - SaveFile.Write(string.Join(Environment.NewLine, multi_logs.Select(a => $"{a.Value}"))); - if (er.Count > 0) SaveFile.WriteLine(msg_er); - SaveFile.Close(); - - File.AppendAllText(path, "--------------------------"); - File.AppendAllText(path, Environment.NewLine + Strings.end_log); - File.AppendAllText(path, Environment.NewLine); - FileInfo fileInfo = new FileInfo(path); - - var bytes = fileInfo.Length; - - var kilobytes = (double)bytes / 1024; - var megabytes = kilobytes / 1024; - var gigabytes = megabytes / 1024; - - //Format size view - String size = ""; - String separator = "."; - - if (bytes > 1000000000) - { - if (gigabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String gigas = gigabytes.ToString(); - if (gigas.Length >= 5) - { - gigas = gigas.Substring(0, gigas.LastIndexOf(separator) + 3); - size = (gigas + " " + "GB"); - } - else - { - size = (gigas + " " + "GB"); - } - } - - if (bytes >= 1048576 && bytes <= 1000000000) - { - if (megabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - String megas = megabytes.ToString(); - if (megas.Length > 5) - { - megas = megas.Substring(0, megas.LastIndexOf(separator)); - size = (megas + " " + "MB"); - } - else - { - size = (megas + " " + "MB"); - } - } - - if (bytes >= 1024 && bytes < 1048576) - - { - if (kilobytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String kbs = kilobytes.ToString(); - if (kbs.Length >= 5) - { - kbs = kbs.Substring(0, kbs.LastIndexOf(separator)); - size = (kbs + " " + "KB"); - } - else - { - size = (kbs + " " + "KB"); - } - } - if (bytes > -1 && bytes < 1024) - { - String bits = bytes.ToString(); - size = (bits + " Bytes"); - } - - //End Format size view - File.AppendAllText(path, Environment.NewLine + Strings.log_size + " " + size); - } - catch { } - - //End save log - } - } - - private void BG_Multi_Down_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) - { - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - timer_tasks.Stop(); - timer2.Stop(); - working = false; - m3u_running = false; - Pg1.Value = Pg1.Maximum; - Pg1.Text = "100%"; - Pg1.Style = ProgressBarStyle.Continuous; - pic_recording.Visible = false; - - try { clean_ffb_test(); } catch { } - - foreach (DataGridViewRow row1 in dg1.Rows) - { - row1.ReadOnly = false; - } - - int faileds = 0; - this.InvokeEx(f => toolT002.RemoveAll()); - if (errors_enc == 0) - { - foreach (DataGridViewRow row in dg1.Rows) - { - if (row.Cells[5].Value.ToString().Contains(Strings.failed)) faileds++; - } - - if (faileds == 0) pic_no_errors.Visible = true; - else - { - pic_no_errors.Visible = false; - pic_recording.Visible = false; - toolT002.SetToolTip(this.pic_warnings, Strings.there_w + " " + faileds.ToString() + " " + Strings.errors_se); - pic_warnings.Visible = true; - } - } - else - { - pic_no_errors.Visible = false; - pic_recording.Visible = false; - toolT002.SetToolTip(this.pic_warnings, Strings.there_w + " " + errors_enc.ToString() + " " + Strings.errors_se); - pic_warnings.Visible = true; - } - - //Automatic shutdown - if (chkshut.Checked && cancelados_paralelos == false) - { - auto_shut(); - return; - } - - //End automatic shutdown - else - { - //cancel queue REVIEW - if (cancelados_paralelos == true) - { - foreach (DataGridViewRow row1 in dg1.Rows) - { - row1.ReadOnly = false; - } - Enable_Controls(); - foreach (DataGridViewRow row1 in dg1.Rows) - { - row1.ReadOnly = false; - } - - this.Cursor = Cursors.Arrow; - ct_paste_m3u.Enabled = true; - ct_del_m3u.Enabled = true; - ct_show_urls.Enabled = true; - ct_validate_url.Enabled = true; - ct_play_vlc.Enabled = true; - ctm_stop_url.Enabled = false; - if (aborted == true) - { - aborted = false; - if (has_lives_multi == false) MessageBox.Show(Strings.queue_abort, Strings.task_abort, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - else MessageBox.Show(Strings.live_end, Strings.task_abort, MessageBoxButtons.OK, MessageBoxIcon.Information); - } - return; - } - - //End cancel queue - - Enable_Controls(); - foreach (DataGridViewRow row1 in dg1.Rows) - { - row1.ReadOnly = false; - } - - this.Cursor = Cursors.Arrow; - ct_paste_m3u.Enabled = true; - ct_del_m3u.Enabled = true; - ct_show_urls.Enabled = true; - ct_validate_url.Enabled = true; - ct_play_vlc.Enabled = true; - ctm_stop_url.Enabled = false; - - notifyIcon1.BalloonTipText = Strings.url_comp; - notifyIcon1.BalloonTipIcon = ToolTipIcon.Info; - notifyIcon1.BalloonTipTitle = Strings.url_comp2; - notifyIcon1.ShowBalloonTip(0); - - if (play_on_end == true) play_end(); - - if (chk_open_compl.Checked == true) - { - String destino2 = txt_path_m3u.Text; - if (Directory.GetFiles(destino2).Length != 0) - { - Process open_processed = new Process(); - open_processed.StartInfo.FileName = "explorer.exe"; - open_processed.StartInfo.Arguments = '\u0022' + destino2 + '\u0022'; - open_processed.Start(); - } - } - } - - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - timer2.Stop(); - timer_tasks.Stop(); - Pg1.Value = Pg1.Maximum; - Pg1.Text = "100%"; - Pg1.Refresh(); - working = false; - m3u_running = false; - Enable_Controls(); - if (aborted == true && fatal_parallel == false) - { - aborted = false; - if (has_lives_multi == false) MessageBox.Show(Strings.url_ab, Strings.task_abort, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - } - cancelados_paralelos = false; - } - - private void dg1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) - { - String cell = dg1.Rows[e.RowIndex].Cells[1].Value.ToString().ToLower(); - - if (e.ColumnIndex == 3) - { - if (cell.Contains("youtu.be") || cell.Contains("youtube.com")) - { - DateTime outTime; - Boolean time_ok = DateTime.TryParse(dg1.Rows[e.RowIndex].Cells[3].Value.ToString(), out outTime); - - if (time_ok == true) - { - if (outTime.Second != 0) e.Cancel = true; - } - else e.Cancel = true; - } - } - } - - private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) - { - e.DrawDefault = true; - } - - private void listView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) - { - int prog = 0; - - if (e.SubItem.Text.Contains("%") && e.ColumnIndex == 5) - { - try - { - prog = int.Parse(e.SubItem.Text.Replace("%", "").Replace(",", "").Replace(".", "")); - } - catch { prog = 0; } - if (e.SubItem.Text.Contains(",") || e.SubItem.Text.Contains(".")) prog = prog / 10; - if (prog < 0) prog = 0; - Rectangle rect = new Rectangle(); - rect.X = e.Bounds.X + 1; - rect.Y = e.Bounds.Y; - rect.Width = e.Bounds.Width * prog / 100; - rect.Height = e.Bounds.Height - 2; - - Rectangle newRect = new Rectangle(e.Bounds.X + 1, - e.Bounds.Y, e.Bounds.Width - 2, - e.Bounds.Height - 2); - using ( - Brush gridBrush = new SolidBrush(Color.LightGray), - backColorBrush = new SolidBrush(Color.White)) - { - using (Pen gridLinePen = new Pen(gridBrush)) - { // Erase the subitem. - e.Graphics.FillRectangle(backColorBrush, e.Bounds); - } - } - - if (e.ColumnIndex == 5) - { - e.DrawDefault = false; - e.DrawBackground(); - e.Graphics.DrawImage(img_prog.Image, rect); - e.Graphics.DrawRectangle(Pens.LightGray, newRect); - e.Graphics.DrawString(e.SubItem.Text, e.SubItem.Font, new SolidBrush(e.SubItem.ForeColor), e.SubItem.Bounds.Location.X + (e.Bounds.Width / 2) - e.SubItem.Text.Length * 3, e.SubItem.Bounds.Location.Y + 1); - } - else e.DrawDefault = true; - } - else - { - if (e.Item.SubItems[5].Text.Contains(Strings.success) || e.Item.SubItems[5].Text.Contains(Strings.replaced) || e.Item.SubItems[5].Text.Contains(Strings.recycled) || e.Item.SubItems[5].Text.Contains(Strings.deleted) || e.Item.SubItems[5].Text.Contains(Strings.skipped) || e.Item.SubItems[5].Text.Contains("OK & Run")) - { - Rectangle rect = new Rectangle(); - rect.X = e.Bounds.X + e.Bounds.Width - 18; - rect.Y = e.Bounds.Y; - rect.Width = 16; - rect.Height = 16; - - if (e.ColumnIndex == 5) - { - e.DrawDefault = false; - e.DrawBackground(); - if (e.Item.SubItems[5].Text.Contains(Strings.success)) - { - e.Graphics.DrawImage(img_icons.Images[2], rect); - e.Graphics.DrawString(e.SubItem.Text, e.SubItem.Font, new SolidBrush(e.SubItem.ForeColor), e.SubItem.Bounds.Location.X + (e.SubItem.Bounds.Width / 2) - (e.SubItem.Text.Length * 3), e.SubItem.Bounds.Location.Y + 1); - } - if (e.Item.SubItems[5].Text.Contains(Strings.replaced) || e.Item.SubItems[5].Text.Contains("OK & Run")) - { - e.Graphics.DrawImage(img_icons.Images[7], rect); - e.Graphics.DrawString(e.SubItem.Text, e.SubItem.Font, new SolidBrush(e.SubItem.ForeColor), e.SubItem.Bounds.Location.X + (e.SubItem.Bounds.Width / 2) - (e.SubItem.Text.Length * 3), e.SubItem.Bounds.Location.Y + 1); - } - if (e.Item.SubItems[5].Text.Contains(Strings.recycled)) - { - e.Graphics.DrawImage(img_icons.Images[1], rect); - e.Graphics.DrawString(e.SubItem.Text, e.SubItem.Font, new SolidBrush(e.SubItem.ForeColor), e.SubItem.Bounds.Location.X + (e.SubItem.Bounds.Width / 2) - (e.SubItem.Text.Length * 3), e.SubItem.Bounds.Location.Y + 1); - } - if (e.Item.SubItems[5].Text.Contains(Strings.deleted)) - { - e.Graphics.DrawImage(img_icons.Images[5], rect); - e.Graphics.DrawString(e.SubItem.Text, e.SubItem.Font, new SolidBrush(e.SubItem.ForeColor), e.SubItem.Bounds.Location.X + (e.SubItem.Bounds.Width / 2) - (e.SubItem.Text.Length * 3), e.SubItem.Bounds.Location.Y + 1); - } - if (e.Item.SubItems[5].Text.Contains(Strings.skipped)) - { - e.Graphics.DrawImage(img_icons.Images[0], rect); - e.Graphics.DrawString(e.SubItem.Text, e.SubItem.Font, new SolidBrush(e.SubItem.ForeColor), e.SubItem.Bounds.Location.X + (e.SubItem.Bounds.Width / 2) - (e.SubItem.Text.Length * 3), e.SubItem.Bounds.Location.Y + 1); - } - } - else e.DrawDefault = true; - } - else - { - if (e.Item.SubItems[5].Text.Contains(Strings.aborted) || e.Item.SubItems[5].Text.Contains(Strings.failed) || e.Item.SubItems[5].Text.Contains(Strings.error) || e.Item.SubItems[5].Text.Contains(Strings.file_not_f)) - { - Rectangle rect = new Rectangle(); - rect.X = e.Item.SubItems[5].Bounds.X + e.Bounds.Width - 18; - rect.Y = e.Item.SubItems[5].Bounds.Y + 1; - rect.Width = 14; - rect.Height = 14; - - if (e.ColumnIndex == 5) - { - e.DrawDefault = false; - e.DrawBackground(); - e.Graphics.DrawImage(img_icons.Images[6], rect); - e.Graphics.DrawString(e.SubItem.Text, e.SubItem.Font, new SolidBrush(e.SubItem.ForeColor), e.SubItem.Bounds.Location.X + (e.SubItem.Bounds.Width / 2) - (e.SubItem.Text.Length * 3), e.SubItem.Bounds.Location.Y + 1); - } - else e.DrawDefault = true; - } - else - { - if (e.Item.SubItems[5].Text.Contains(Strings.renamed) || e.Item.SubItems[5].Text.Contains(Strings.not_replaced) || e.Item.SubItems[5].Text.Contains(Strings.recycled) || e.Item.SubItems[5].Text.Contains(Strings.not_recycled) || e.Item.SubItems[5].Text.Contains(Strings.not_deleted) || e.Item.SubItems[5].Text.Contains("OK & Error")) - { - Rectangle rect_r = new Rectangle(); - rect_r.X = e.Item.SubItems[5].Bounds.X + e.Bounds.Width - 18; - rect_r.Y = e.Item.SubItems[5].Bounds.Y + 1; - rect_r.Width = 14; - rect_r.Height = 14; - - if (e.ColumnIndex == 5) - { - e.DrawDefault = false; - e.DrawBackground(); - e.Graphics.DrawImage(img_icons.Images[4], rect_r); - if (e.Item.SubItems[5].Text.Contains(Strings.not_replaced) || e.Item.SubItems[5].Text.Contains(Strings.not_recycled) || e.Item.SubItems[5].Text.Contains(Strings.not_deleted) || e.Item.SubItems[5].Text.Contains("OK & Error")) - { - e.Graphics.DrawString(e.SubItem.Text, e.SubItem.Font, new SolidBrush(e.SubItem.ForeColor), e.SubItem.Bounds.Location.X + (e.SubItem.Bounds.Width / 2) - (e.SubItem.Text.Length * 3), e.SubItem.Bounds.Location.Y + 1); - } - if (e.Item.SubItems[5].Text.Contains(Strings.renamed)) - { - e.Graphics.DrawString(e.SubItem.Text, e.SubItem.Font, new SolidBrush(e.SubItem.ForeColor), e.SubItem.Bounds.Location.X + (e.SubItem.Bounds.Width / 2) - (e.SubItem.Text.Length * 3), e.SubItem.Bounds.Location.Y + 1); - } - } - else e.DrawDefault = true; - } - else - { - if (e.Item.SubItems[5].Text.Contains(Strings.queued)) - { - e.DrawDefault = true; - } - else - { - if (e.Item.SubItems[5].Text.Contains(Strings.processing)) - { - if (e.ColumnIndex == 5) - { - e.DrawDefault = false; - e.DrawBackground(); - e.Graphics.DrawString(e.SubItem.Text, e.SubItem.Font, new SolidBrush(e.SubItem.ForeColor), e.SubItem.Bounds.Location.X + (e.SubItem.Bounds.Width / 2) - (e.SubItem.Text.Length * 3), e.SubItem.Bounds.Location.Y + 1); - } - else e.DrawDefault = true; - } - else - { - e.DrawDefault = true; - } - } - } - } - } - } - } - - private void dg1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) - { - if (e.ColumnIndex == 5 && e.RowIndex > -1) - { - Image img = pic_ok.Image; - Rectangle rect = new Rectangle(); - - if (e.Value.ToString().Contains("%")) - { - Decimal dec_prog = Convert.ToDecimal(dg1.Rows[e.RowIndex].Cells[5].Value.ToString().Replace("%", "")); - int prog = (int)(dec_prog); - - rect = new Rectangle(e.CellBounds.X + 1, e.CellBounds.Y + 1, e.CellBounds.Width * prog / 100, - e.CellBounds.Height - 2); - img = img_prog.Image; - } - if (e.Value.ToString().Contains(Strings.success)) - { - rect = new Rectangle(e.CellBounds.X + e.CellBounds.Width - 19, e.CellBounds.Y + e.CellBounds.Height / 2 - 8, 16, 16); - img = pic_ok.Image; - } - if (e.Value.ToString().Contains(Strings.failed) || e.Value.ToString().Contains(Strings.error) || e.Value.ToString().Contains(Strings.aborting) || e.Value.ToString().Contains(Strings.aborted)) - { - rect = new Rectangle(e.CellBounds.X + e.CellBounds.Width - 19, e.CellBounds.Y + e.CellBounds.Height / 2 - 8, 16, 16); - img = img_icons.Images[6]; - } - if (e.Value.ToString().Contains(Strings.recording1)) - { - rect = new Rectangle(e.CellBounds.X + e.CellBounds.Width - 16, e.CellBounds.Y + e.CellBounds.Height / 2 - 5, 12, 12); - img = img_icons.Images[3]; - } - - using (Brush gridBrush = new SolidBrush(this.dg1.GridColor), backColorBrush = new SolidBrush(e.CellStyle.BackColor)) - { - using (Pen gridLinePen = new Pen(gridBrush)) - { - // Erase the cell. - e.Graphics.FillRectangle(backColorBrush, e.CellBounds); - - // Draw the grid lines (only the right and bottom lines; - // DataGridView takes care of the others). - e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, - e.CellBounds.Bottom - 1, e.CellBounds.Right - 1, - e.CellBounds.Bottom - 1); - e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1, - e.CellBounds.Top, e.CellBounds.Right - 1, - e.CellBounds.Bottom); - } - } - e.Graphics.DrawImage(img, rect); - e.PaintContent(e.ClipBounds); - e.Handled = true; - } - } - - private void listView3_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) - { - e.DrawDefault = true; - } - - private void listView3_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) - { - int prog = 0; - if (e.SubItem.Text.Contains("%")) - { - prog = int.Parse(e.SubItem.Text.Replace("%", "").Replace(",", "").Replace(".", "")); - if (e.SubItem.Text.Contains(",") || e.SubItem.Text.Contains(".")) prog = prog / 10; - if (prog < 0) prog = 0; - Rectangle rect = new Rectangle(); - rect.X = e.Bounds.X; - rect.Y = e.Bounds.Y; - rect.Width = e.Bounds.Width * prog / 100; - rect.Height = e.Bounds.Height; - - Rectangle newRect = new Rectangle(e.Bounds.X + 1, - e.Bounds.Y, e.Bounds.Width - 2, - e.Bounds.Height - 2); - using ( - Brush gridBrush = new SolidBrush(Color.LightGray), - backColorBrush = new SolidBrush(Color.White)) - { - using (Pen gridLinePen = new Pen(gridBrush)) - { // Erase the subitem. - e.Graphics.FillRectangle(backColorBrush, e.Bounds); - } - } - e.DrawDefault = false; - e.DrawBackground(); - e.Graphics.DrawRectangle(Pens.LightGray, newRect); - e.Graphics.DrawImage(img_prog.Image, rect); - e.Graphics.DrawString(e.SubItem.Text, e.SubItem.Font, new SolidBrush(e.SubItem.ForeColor), e.SubItem.Bounds.Location.X + (e.Bounds.Width / 2) - e.SubItem.Text.Length * 3, e.SubItem.Bounds.Location.Y + 1); - } - else - { - if (e.SubItem.Text.Contains(Strings.success)) - { - Rectangle rect = new Rectangle(); - rect.X = e.Bounds.X + e.Bounds.Width - 18; - rect.Y = e.Bounds.Y; - rect.Width = 16; - rect.Height = 16; - e.DrawDefault = false; - e.DrawBackground(); - e.Graphics.DrawImage(img_icons.Images[2], rect); - e.Graphics.DrawString(e.SubItem.Text, e.SubItem.Font, new SolidBrush(e.SubItem.ForeColor), e.SubItem.Bounds.Location.X + (e.Bounds.Width / 2) - e.SubItem.Text.Length * 3 - 2, e.SubItem.Bounds.Location.Y + 1); - } - else - { - if (e.SubItem.Text.Contains(Strings.aborted) || e.SubItem.Text.Contains(Strings.error) || e.SubItem.Text.Contains("No Sub")) - { - Rectangle rect = new Rectangle(); - rect.X = e.Bounds.X + e.Bounds.Width - 18; - rect.Y = e.Bounds.Y + 1; - rect.Width = 14; - rect.Height = 14; - e.DrawDefault = false; - e.DrawBackground(); - e.Graphics.DrawImage(img_icons.Images[6], rect); - e.Graphics.DrawString(e.SubItem.Text, e.SubItem.Font, new SolidBrush(e.SubItem.ForeColor), e.SubItem.Bounds.Location.X + (e.Bounds.Width / 2) - e.SubItem.Text.Length * 3 - 2, e.SubItem.Bounds.Location.Y + 1); - } - else - { - if (e.SubItem.Text.Contains(Strings.queued) || e.SubItem.Text.Contains(Strings.processing)) - { - e.DrawDefault = false; - e.DrawBackground(); - e.Graphics.DrawString(e.SubItem.Text, e.SubItem.Font, new SolidBrush(e.SubItem.ForeColor), e.SubItem.Bounds.Location.X + (e.Bounds.Width / 2) - e.SubItem.Text.Length * 3 - 2, e.SubItem.Bounds.Location.Y + 1); - } - else - { - e.DrawDefault = true; - } - } - } - } - } - - - private void BG_check_ytdl_DoWork(object sender, DoWorkEventArgs e) - { - t_out_yt = true; - String ver = String.Empty; - Process tmp = new Process(); - tmp.StartInfo.FileName = Path.Combine(Application.StartupPath, "yt-dlp.exe"); - - tmp.StartInfo.Arguments = "--version"; - tmp.StartInfo.RedirectStandardOutput = true; - tmp.StartInfo.UseShellExecute = false; - tmp.StartInfo.CreateNoWindow = true; - tmp.EnableRaisingEvents = true; - - if (File.Exists(tmp.StartInfo.FileName)) - { - try - { - tmp.Start(); - - ver = tmp.StandardOutput.ReadToEnd().Trim(); - tmp.WaitForExit(); - t_out_yt = false; - if (tmp.ExitCode != 0) - { - this.InvokeEx(f => f.pic_wait_1.Visible = false); - this.InvokeEx(f => f.pic_no_yt.Visible = false); - check_VC(); - return; - } - } - catch { } - } - else - { - lbl_yl_name.Text = Strings.yt_not; - } - try - { - WebClient client = new WebClientWithTimeout(); - String content = client.DownloadString(yl_latest); - String[] lines = content.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries); - String latest_v = ""; - foreach (String line in lines) - { - if (line.Contains("yt-dlp ")) - { - latest_v = line.Substring(line.IndexOf("yt-dlp ", 11)).Replace("yt-dlp ", ""); - latest_v = latest_v.Substring(0, 10); - break; - } - } - - Boolean found_ver = false; - if (content.Contains(ver) && File.Exists("yt-dlp.exe")) found_ver = true; - else found_ver = false; - - yl_latest_exe = yl_latest_exe + "download/" + latest_v + "/" + "yt-dlp.exe"; - - this.InvokeEx(f => f.pic_wait_1.Visible = false); - if (found_ver == true) - { - this.Invoke(new MethodInvoker(delegate - { - lbl_yl_name.Text = "yt-dlp" + " " + Strings.version.ToLower() + " " + ver; - btn_update_yt.Visible = false; - pic_ok.Visible = true; - pic_no_yt.Visible = false; - })); - - } - else - { - this.Invoke(new MethodInvoker(delegate - { - lbl_yl_name.Text = Strings.New + " " + "yt-dlp " + latest_v + " " + Strings.found; - if (!File.Exists("yt-dlp.exe")) - { - lbl_yl_name.Text = Strings.yt_not; - t_out_yt = false; - } - btn_update_yt.Visible = true; - pic_ok.Visible = false; - pic_no_yt.Visible = false; - })); - } - } - catch - { - this.Invoke(new MethodInvoker(delegate - { - lbl_yl_name.Text = Strings.err_yt_u; - if (!File.Exists("yt-dlp.exe")) - { - lbl_yl_name.Text = Strings.yt_not; - t_out_yt = false; - } - pic_no_yt.Visible = true; - pic_ok.Visible = false; - pic_wait_1.Visible = false; - })); - } - } - - private void BG_Single_yt_DoWork(object sender, DoWorkEventArgs e) - { - Boolean one_ok = false; - String path_pic = Path.Combine(Path.GetTempPath(), "FFBatch_test"); - - dg1.Invoke(new MethodInvoker(delegate - { - dg1.Rows[dg1.RowCount - 1].Cells[5].Value = Strings.var_url; - - if (dg1.Rows[dg1.RowCount - 1].Cells[1].Value == null) - { - dg1.Rows[dg1.RowCount - 1].Cells[5].Value = String.Empty; - dg1.Rows[dg1.RowCount - 1].Cells[4].Value = String.Empty; - dg1.Rows[dg1.RowCount - 1].Cells[3].Value = String.Empty; - dg1.Rows[dg1.RowCount - 1].Cells[2].Value = String.Empty; - //dg1.Rows[dg1.RowCount - 1].DefaultCellStyle.BackColor = dg1.DefaultCellStyle.BackColor; - return; - } - - if (dg1.Rows[dg1.RowCount - 1].Cells[1].Value.ToString().Contains("http") == false) - { - dg1.Rows[dg1.RowCount - 1].Cells[5].Value = Strings.error; - - return; - } - dg1.Refresh(); - cell_zoom(); - })); - - Process probe = new Process(); - probe.StartInfo.FileName = Path.Combine(Application.StartupPath, "yt-dlp.exe"); - if (!File.Exists(Path.Combine(Application.StartupPath, "yt-dlp.exe"))) - { - MessageBox.Show(Strings.yt_not, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - release_datagrid(); - return; - } - probe.StartInfo.WorkingDirectory = Application.StartupPath; - probe.StartInfo.Arguments = "--get-duration --get-title --get-thumbnail " + dg1.Rows[dg1.RowCount - 1].Cells[1].Value.ToString(); - probe.StartInfo.RedirectStandardOutput = true; - probe.StartInfo.UseShellExecute = false; - probe.StartInfo.CreateNoWindow = true; - probe.EnableRaisingEvents = true; - probe.Start(); - - String filename = ""; - String out_thumb = ""; - String duracion = ""; - - while (!probe.StandardOutput.EndOfStream) - { - filename = probe.StandardOutput.ReadLine(); - out_thumb = probe.StandardOutput.ReadLine(); - duracion = probe.StandardOutput.ReadLine(); - } - - PictureBox pic = new PictureBox(); - thumbs_count++; - if (out_thumb.Contains("http")) - { - try - { - if (out_thumb.Contains("?")) out_thumb = out_thumb.Substring(0, out_thumb.IndexOf("?")); - - new System.Threading.Thread(() => - { - System.Threading.Thread.CurrentThread.IsBackground = true; - try - { - if (out_thumb.ToLower().Contains("webp")) - { - WebClient client = new WebClient(); - client.DownloadFile(out_thumb, path_pic + "\\" + "pic_ffb_" + thumbs_count.ToString() + ".webp"); - client.Dispose(); - Process pr = new Process(); - pr.StartInfo.FileName = "ffmpeg.exe"; - pr.StartInfo.UseShellExecute = false; - pr.StartInfo.CreateNoWindow = true; ; - pr.StartInfo.Arguments = "-i " + '\u0022' + path_pic + "\\" + "pic_ffb_" + thumbs_count.ToString() + ".webp" + '\u0022' + " -f image2 -y " + '\u0022' + path_pic + "\\" + "pic_ffb_" + thumbs_count.ToString() + ".bmp" + '\u0022'; - pr.Start(); - pr.WaitForExit(1000); - Image img; - using (var bmpTemp = new Bitmap(Path.Combine(path_pic, "pic_ffb_" + thumbs_count.ToString() + ".bmp"))) - { - img = new Bitmap(bmpTemp); - pic.Image = img; - } - } - else pic.Load(out_thumb); - - dg_thumbs[dg1.RowCount - 1] = pic.Image; - dg1.Invoke(new MethodInvoker(delegate - { - dg1.Rows[dg1.RowCount - 1].Cells[0].Value = pic.Image; - pic_frame.Image = pic.Image; - if (pic_frame.Image == null) pic_frame.Image = pic_frame.InitialImage; - lbl_a_th.Text = "-"; - lbl_s_th.Text = "-"; - lbl_v_th.Text = "-"; - lbl_gb_th.Text = "-"; - })); - } - catch - { - dg1.Rows[dg1.RowCount - 1].Cells[0].Value = pic_noimg.Image; - } - }).Start(); - } - catch - { - dg_thumbs[dg1.RowCount - 1] = pic_noimg.Image; - } - } - else - { - dg_thumbs[dg1.RowCount - 1] = pic_noimg.Image; - } - //cell_stretch(); - - probe.WaitForExit(10000); - probe.StartInfo.Arguments = ""; - pic.Dispose(); - - if (duracion == null || duracion == string.Empty) - { - dg1.Invoke(new MethodInvoker(delegate - { - dg1.Rows[dg1.RowCount - 1].Cells[2].Value = ""; - dg1.Rows[dg1.RowCount - 1].Cells[3].Value = ""; - dg1.Rows[dg1.RowCount - 1].Cells[5].Value = Strings.error; - - })); - } - - if (duracion != null && filename != "") - { - dg1.Invoke(new MethodInvoker(delegate - { - if (duracion == "0") - { - dg1.Rows[dg1.RowCount - 1].Cells[2].Value = duracion; - dg1.Rows[dg1.RowCount - 1].Cells[3].Value = "Live"; - } - else - { - if (duracion.Length < 6) duracion = "00:" + duracion; - dg1.Rows[dg1.RowCount - 1].Cells[2].Value = duracion; - dg1.Rows[dg1.RowCount - 1].Cells[3].Value = duracion; - } - dg1.Rows[dg1.RowCount - 1].Cells[4].Value = filename; - //dg1.Rows[dg1.RowCount - 1].DefaultCellStyle.BackColor = dg1.DefaultCellStyle.BackColor; - one_ok = true; - dg1.Rows[dg1.RowCount - 1].Cells[5].Value = Strings.ready; - this.InvokeEx(f => f.dg1.Rows[dg1.RowCount - 1].Cells[5].Style.BackColor = Color.LightGreen); - })); - } - - if (duracion == null && filename != "") - { - dg1.Invoke(new MethodInvoker(delegate - { - one_ok = true; - dg1.Rows[dg1.RowCount - 1].Cells[2].Value = "0"; - dg1.Rows[dg1.RowCount - 1].Cells[3].Value = "Live"; - dg1.Rows[dg1.RowCount - 1].Cells[4].Value = filename; - dg1.Rows[dg1.RowCount - 1].Cells[5].Value = Strings.ready; - dg1.Rows[dg1.RowCount - 1].Cells[5].Style.BackColor = Color.LightGreen; - })); - } - - if (dg1.RowCount > 1) - { - dg1.Invoke(new MethodInvoker(delegate - { - dg1.ClearSelection(); - dg1.Rows[dg1.RowCount - 1].Cells[1].Selected = true; - dg1.CurrentCell = dg1.Rows[dg1.RowCount - 1].Cells[1]; - })); - } - urls_duration(); - if (one_ok == true) - { - this.Invoke(new MethodInvoker(delegate - { - chk_m3u_params.Left = 14; - chk_output_server.Enabled = false; - chk_m3u_params.Text = Strings.yt_params; - })); - } - release_datagrid(); - } - - private void btn_edit_presets_Click(object sender, EventArgs e) - { - Form15 frm_pr = new Form15(); - frm_pr.ShowDialog(); - if (frm_pr.saved == true) btn_load_config.PerformClick(); - if (frm_pr.online_pr == true) - { - Form27 frm27 = new Form27(); - frm27.StartPosition = FormStartPosition.CenterParent; - frm27.ShowDialog(); - if (frm27.desc_pr.Length > 0) - { - combo_presets.SelectedIndex = combo_presets.Items.Count - 1; - combo_presets.Text = frm27.desc_pr; - txt_pre_input.Text = frm27.pre_in_pr; - txt_parameters.Text = frm27.params_pr.Replace("\\*", "*").Replace("\\:", ":"); - txt_format.Text = frm27.format_pr; - } - } - } - - private void btn_del_preset_Click(object sender, EventArgs e) - { - Pg1.Focus(); - if (combo_presets.SelectedIndex == -1) - { - return; - } - if (combo_presets.SelectedIndex == 0) - { - MessageBox.Show(Strings.def_rn, Strings.default_param, MessageBoxButtons.OK, MessageBoxIcon.Information); - return; - } - DialogResult a = MessageBox.Show(Strings.rem_pres, Strings.conf_act, MessageBoxButtons.YesNo, MessageBoxIcon.Question); - if (a == DialogResult.Yes) - { - String path, path_pr = ""; - if (is_portable == false) - { - path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.ini"; - path_pr = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_presets.ini"; - } - else - { - path = port_path + "ff_batch_portable.ini"; - path_pr = port_path + "ff_presets_portable.ini"; - } - - String path2 = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch2.txt"; - String path2_pr = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_presets2.txt"; - if (is_portable == true) - { - path2 = port_path + "ff_batch2.txt"; - path2_pr = port_path + "ff_presets2.txt"; - } - if (is_portable == false) - { - File.Create(Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch2.txt").Dispose(); - File.Create(Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_presets2.txt").Dispose(); - } - else - { - File.Create(port_path + "ff_batch2.txt").Dispose(); - File.Create(port_path + "ff_presets2.txt").Dispose(); - } - - if (File.Exists(path_pr)) - { - path = path_pr; - path2 = path2_pr; - } - - int ind = 0; - foreach (string line in File.ReadLines(path)) - { - ind = ind + 1; - String linea_sin = String.Empty; - - if (!line.Contains("PR: ")) - { - linea_sin = line + Environment.NewLine; - File.AppendAllText(path2, linea_sin); - } - - if (line.LastIndexOf(" & ") >= 0) - { - if (line.Substring(4, line.LastIndexOf(" & ") - 4) != combo_presets.SelectedItem.ToString()) - { - if (ind <= File.ReadLines(path).Count() - 1) - { - linea_sin = line + Environment.NewLine; - File.AppendAllText(path2, linea_sin); - } - else - { - File.AppendAllText(path2, line); - } - } - } - } - File.Delete(path); - File.Copy(path2, path); - File.Delete(path2); - - String path1 = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.ini"; - String path1_pr = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_presets.ini"; - if (is_portable == true) - { - path1 = port_path + "ff_batch_portable.ini"; - path1_pr = port_path + "ff_presets_portable.ini"; - } - - combo_presets.Items.Clear(); - combo_presets.Items.Add(Strings.default_param); - int linea = 0; - - foreach (string line in File.ReadLines(path1)) - { - linea = linea + 1; - - if (linea == 1) - { - txt_parameters.Text = line; - } - - if (linea == 2) - { - txt_format.Text = line; - } - - if (line == "Yes") - - { - chk_open_compl.CheckState = CheckState.Checked; - } - - if (line == "No") - { - chk_open_compl.CheckState = CheckState.Unchecked; - } - - if (!File.Exists(path1_pr)) - { - if (line.Contains("PR: ")) - { - combo_presets.Items.Add(line.Substring(4, line.LastIndexOf(" & ") - 4)); - } - } - } - if (File.Exists(path1_pr)) - { - foreach (string line in File.ReadLines(path_pr)) - { - if (line.Length > 8) - { - if (line.Substring(0, 7).ToLower() == "version") - { - txt_config_ver.Text = line.Substring(8, line.Length - 8); - continue; - } - } - - if (line.Contains("PR: ")) - { - combo_presets.Items.Add(line.Substring(4, line.LastIndexOf(" & ") - 4)); - } - } - } - - combo_presets.SelectedIndex = 0; - } - } - - private void pic_warnings_Click(object sender, EventArgs e) - { - if (pic_warnings.Visible == true) btn_display_log.PerformClick(); - } - - private void btn_display_log_Click(object sender, EventArgs e) - { - Pg1.Focus(); - String path_log_file = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.log"; - if (is_portable == true) path_log_file = port_path + "ff_batch_portable.log"; - if (!File.Exists(path_log_file)) - { - if (no_save_logs == true) MessageBox.Show(Strings.no_log_f, Strings.file_not_f, MessageBoxButtons.OK, MessageBoxIcon.Error); - else - if (no_save_logs == false) MessageBox.Show(Strings.no_log1, Strings.file_not_f, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - long length = new FileInfo(path_log_file).Length; - if (length > 20000000) - { - DialogResult a = MessageBox.Show(Strings.log_siz + " " + (length / 1024).ToString() + " KB " + Strings.time_load, Strings.warning, MessageBoxButtons.YesNo, MessageBoxIcon.Question); - if (a == DialogResult.No) return; - } - - //Form frm_output = new Form(); - frm_log.Name = Strings.last_log1; - frm_log.Text = "FFmpeg Batch AV Converter"; - frm_log.Icon = this.Icon; - - frm_log.Height = 675; - frm_log.Width = 977; - frm_log.FormBorderStyle = FormBorderStyle.Fixed3D; - frm_log.MaximizeBox = false; - frm_log.MinimizeBox = false; - - var fuente_list = new System.Drawing.Font("Microsoft Sans Serif", 9, FontStyle.Regular); - - Rtxt.Parent = frm_log; - Rtxt.Left = 20; - Rtxt.Top = 65; - Rtxt.Height = 525; - Rtxt.Width = 920; - Rtxt.Font = fuente_list; - - - ContextMenu Rtxt_menu = new ContextMenu(); - Rtxt.ContextMenu = Rtxt_menu; - MenuItem CopyItem = new MenuItem(Strings.copy); - Rtxt_menu.MenuItems.Add(CopyItem); - CopyItem.Click += new EventHandler(CopyAction); - - TextBox titulo = new TextBox(); - titulo.Parent = frm_log; - titulo.Top = 15; - titulo.Left = 20; - titulo.Width = 921; - titulo.TabIndex = 0; - var fuente = new System.Drawing.Font("Microsoft Sans Serif", 11, FontStyle.Bold); - - titulo.Font = fuente; - titulo.BorderStyle = BorderStyle.Fixed3D; - titulo.TextAlign = HorizontalAlignment.Center; - titulo.ReadOnly = true; - - titulo.Text = Strings.last_b_l; - - Button boton_ok_ff = new Button(); - boton_ok_ff.Parent = frm_log; - boton_ok_ff.Left = 20; - boton_ok_ff.Top = 595; - boton_ok_ff.Width = 920; - boton_ok_ff.Height = 27; - boton_ok_ff.Text = Strings.last_b_l; - boton_ok_ff.Click += new EventHandler(boton_ok_ff_Click); - - TextBox titulo2 = new TextBox(); - titulo2.Parent = frm_log; - titulo2.Top = 42; - titulo2.Left = 47; - titulo2.Width = 867; - - var fuente2 = new System.Drawing.Font("Microsoft Sans Serif", 10, FontStyle.Regular); - - titulo2.Font = fuente2; - titulo2.BorderStyle = BorderStyle.None; - titulo2.TextAlign = HorizontalAlignment.Center; - titulo2.ReadOnly = true; - - titulo2.Text = "ff_batch.log"; - if (is_portable == true) titulo2.Text = "ff_batch_portable.log"; - - frm_log.StartPosition = FormStartPosition.CenterScreen; - Rtxt.Text = File.ReadAllText(path_log_file); - boton_ok_ff.Text = Strings.close_win; - frm_log.ShowDialog(); - frm_log.Refresh(); - } - - private void btn_fix_pre_Click(object sender, EventArgs e) - { - btn_fix_pre.Enabled = false; - String f_fix_pre = String.Empty; - if (is_portable == false) - { - f_fix_pre = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_fix_pre.ini"; - } - else - { - f_fix_pre = port_path + "ff_fix_pre_portable.ini"; - } - - if (txt_pre_input.Text.Length > 0) - { - File.WriteAllText(f_fix_pre, txt_pre_input.Text); - fix_pre = true; - } - else - { - fix_pre = false; - if (File.Exists(f_fix_pre)) - { - try - { - File.Delete(f_fix_pre); - } - catch - { - MessageBox.Show(Strings.err_set); - } - } - } - } - - private void add_video_mux_job() - { - Pg1.Focus(); - cancel_queue = false; - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - - foreach (ListViewItem file0 in list_tracks.Items) - { - if (!File.Exists(file0.Text)) - { - MessageBox.Show(Strings.file_not_found + " " + file0.Text, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - - if (list_tracks.Items.Count == 0) - { - MessageBox.Show(Strings.tracks_empty, Strings.no_files, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; - } - - Boolean video_track_in = false; - foreach (ListViewItem tracks_item in list_tracks.Items) - { - if (tracks_item.SubItems[2].Text.Contains("Video")) - { - video_track_in = true; - } - } - - if (video_track_in == false) - { - MessageBox.Show(Strings.vid_req, Strings.no_video2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - String is_overw = String.Empty; - if (txt_path_main.Text.Contains(".\\")) - { - if (txt_path_main.Text == ".\\") - { - is_overw = Path.GetDirectoryName(list_tracks.Items[0].Text) + "\\" + Path.GetFileNameWithoutExtension(list_tracks.Items[0].Text) + "." + combo_ext.SelectedItem.ToString(); - } - else - { - is_overw = Path.GetDirectoryName(list_tracks.Items[0].Text) + txt_path_main.Text.Replace(".", String.Empty) + "\\" + Path.GetFileNameWithoutExtension(list_tracks.Items[0].Text) + "." + combo_ext.SelectedItem.ToString(); - } - } - - if (is_overw == list_tracks.Items[0].Text) - { - MessageBox.Show(Strings.overw_not2, Strings.overw_not_all, MessageBoxButtons.OK, MessageBoxIcon.Error); - - return; - } - - DateTime time2; - if (!DateTime.TryParse(ss_time_input.Text, out time2)) - { - MessageBox.Show(Strings.pre_input4, Strings.pre_input2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - //Validated list, start processing - //Pending duration - - if (dur_ok == false) - { - list_pending_dur.Items.Clear(); - foreach (ListViewItem item in listView1.Items) - { - list_pending_dur.Items.Add((ListViewItem)item.Clone()); - } - BG_Dur.RunWorkerAsync(); - return; - } - - txt_remain.Text = Strings.remain_time + " " + "00h:00m:00s"; - time_n_tasks = 0; - - cancel_queue = false; - Pg1.Value = 0; - - //Copy list of tracks for thread processing - ListView list_proc = new ListView(); - foreach (ListViewItem item in list_tracks.Items) - { - list_proc.Items.Add((ListViewItem)item.Clone()); - } - //End of copy list of tracks for thread processing - - Pg1.Maximum = list_proc.Items.Count; - - Double total_duration = 0; - Double total_prog = 0; - - //Get specific track list video duration - //Duration - Boolean has_audio_for_image = false; - Process probe = new Process(); - - probe.StartInfo.FileName = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - String ffprobe_frames = " " + '\u0022' + "--Inform=General;%Duration/String3%" + '\u0022'; - probe.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + list_proc.Items[1].Text + '\u0022'; - - probe.StartInfo.RedirectStandardOutput = true; - probe.StartInfo.UseShellExecute = false; - probe.StartInfo.CreateNoWindow = true; - probe.EnableRaisingEvents = true; - probe.Start(); - - String duracion = probe.StandardOutput.ReadLine(); - - probe.WaitForExit(); - DateTime time; - if (duracion != null) - { - TimeSpan time0; - if (TimeSpan.TryParse(duracion, out time0)) - { - durat_n = TimeSpan.Parse(duracion).TotalSeconds; - total_duration = TimeSpan.Parse(duracion).TotalSeconds; - } - else - { - total_duration = durat_n; - } - } - else - { - duracion = "0"; - durat_n = 0; - total_duration = 0; - } - //End duration - - //End - - Pg1.Minimum = 0; - Pg1.Maximum = 100; - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - lbl_speed.Text = String.Empty; - lbl_elapsed.Text = Strings.time_elapsed + " " + "00h:00m:00s"; - - List list_lines = new List(); - String mux_ext = combo_ext.Text; - - String hw_decode = String.Empty; - if (cb_hwdecode.SelectedItem.ToString() != "none") - { - hw_decode = "-hwaccel " + cb_hwdecode.SelectedItem.ToString(); - } - - //Save selected hw decoder - - String path2 = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_hw_dcd.ini"; - if (is_portable == true) - { - path2 = port_path + "ff_hw_dcd_portable.ini"; - } - String txt_hw_dcd = cb_hwdecode.SelectedItem.ToString(); - if (txt_hw_dcd != "none") - { - File.WriteAllText(path2, txt_hw_dcd); - } - else - { - if (File.Exists(path2)) File.Delete(path2); - } - - //End save hw decoder - - String remain_time = "0"; - - String ffm = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - - String file = list_proc.Items[0].Text; - String fullPath = file; - String destino = ""; - - if (txt_path_main.Text.Contains(".\\")) - { - destino = file.Substring(0, fullPath.LastIndexOf('\\')) + txt_path_main.Text.Replace(".", String.Empty); - } - else - { - destino = txt_path_main.Text; - } - - if (!Directory.Exists(destino)) - { - Directory.CreateDirectory(destino); - } - - //Create joint inputs variable - String inputs = String.Empty; - foreach (ListViewItem input_item in list_proc.Items) - { - if (input_item.SubItems[2].Text.Contains("Subtitle") && !input_item.SubItems[2].Text.Contains("hdmv_pgs") && !input_item.SubItems[2].Text.Contains("dvd_subtitle")) - { - inputs = inputs + " -sub_charenc UTF-8" + " -i " + '\u0022' + input_item.Text + '\u0022'; - } - else - { - if (input_item.BackColor != Color.LightYellow) - { - inputs = inputs + " -i " + '\u0022' + input_item.Text + '\u0022'; - } - else - { - String ext_image = Path.GetExtension(list_proc.Items[0].Text); - - //Attempt to extract frame as image - Process proc_img = new System.Diagnostics.Process(); - String ffm_img = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - - String file_img = Path.GetFullPath(list_proc.Items[0].Text); - String fullPath_img = file_img; - String AppParam_img = ""; - - if (ext_image != ".jpg" && ext_image != ".jpeg" && ext_image != ".png" && ext_image != ".gif" && ext_image != ".bmp" && ext_image != ".tiff" && ext_image != ".psd") - { - AppParam_img = " -ss " + ss_time_input.Text + " -i " + "" + '\u0022' + file_img + '\u0022' + " -vframes 1 -f image2" + " -qscale:v 2" + " -vf scale=1280:-2" + " -y " + '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file_img) + "." + "jpg" + '\u0022'; - } - else - { - AppParam_img = " -i " + "" + '\u0022' + file_img + '\u0022' + " -qscale:v 2" + " -vf scale=1280:-2" + " -y " + '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file_img) + "." + "jpg" + '\u0022'; - } - proc_img.StartInfo.RedirectStandardError = false; - proc_img.StartInfo.UseShellExecute = true; - proc_img.StartInfo.CreateNoWindow = false; - proc_img.EnableRaisingEvents = false; - proc_img.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - - proc_img.StartInfo.FileName = ffm_img; - proc_img.StartInfo.Arguments = AppParam_img; - - proc_img.Start(); - proc_img.WaitForExit(); - if (proc_img.ExitCode == 0) - { - String extracted_img = "" + '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file_img) + ".jpg" + '\u0022' + ""; - inputs = inputs + " -i " + extracted_img; - } - else - { - MessageBox.Show(Strings.err_ext_vid, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - Enable_Controls(); - working = false; - return; - } - //End extract frame as image - } - } - } - //End create joint inputs variable - - //Create mapping inputs variable - String input_map = String.Empty; - //Add video track, it must be first - if (list_proc.Items[0].BackColor == Color.LightYellow) - { - //Video track is an still image - - //Attempt to extract first frame from video track as image - - input_map = input_map + " -map 0:0" + " -c:v libx264 -r 1 -crf 29 -preset veryfast -x264-params keyint=1 -pix_fmt yuv420p"; - } - else - { - input_map = input_map + " -map 0:" + list_proc.Items[0].SubItems[1].Text + " -c:v " + list_proc.Items[0].SubItems[5].Text + " -metadata:s:v:0 language=" + list_proc.Items[0].SubItems[3].Text; - } - - int int_auds = 0; - int i_subs = 0; - - for (int i = 1; i < list_tracks.Items.Count; i++) - - { - //Audio tracks - if (list_proc.Items[i].SubItems[2].Text.Contains("Audio")) - { - String is_default = String.Empty; - if (list_proc.Items[i].SubItems[4].Text == Strings.yes) - { - is_default = "-disposition:a:" + (int_auds).ToString() + " default"; - } - else - { - is_default = "-disposition:a:" + (int_auds).ToString() + " 0"; - } - String track_codec = " -c:a copy "; - if (list_proc.Items[i].SubItems[5].Text != "copy") - { - track_codec = " -c:a:" + int_auds + " " + list_proc.Items[i].SubItems[5].Text; - } - input_map = input_map + " -map " + (i).ToString() + ":" + list_proc.Items[i].SubItems[1].Text + track_codec + " -metadata:s:a:" + (int_auds).ToString() + " language=" + list_proc.Items[i].SubItems[3].Text + " " + is_default; - int_auds = int_auds + 1; - } - } - - for (int i = 1; i < list_tracks.Items.Count; i++) - - { - //Subtitle tracks - if (list_proc.Items[i].SubItems[2].Text.Contains("Subtitle")) - { - String is_default = String.Empty; - if (list_proc.Items[i].SubItems[4].Text == Strings.yes) - { - is_default = "-disposition:s:" + (i_subs).ToString() + " default"; - } - else - { - is_default = "-disposition:s:" + (i_subs).ToString() + " 0"; - } - - input_map = input_map + " -map " + (i).ToString() + ":" + list_proc.Items[i].SubItems[1].Text + " -c:s " + list_proc.Items[i].SubItems[5].Text + " -metadata:s:s:" + (i_subs).ToString() + " language=" + list_proc.Items[i].SubItems[3].Text + " " + is_default; - - i_subs = i_subs + 1; - } - } - - String AppParam = String.Empty; - - if (list_proc.Items[0].BackColor == Color.LightYellow) - { - AppParam = hw_decode + " -loop 1 -r 6 " + inputs + input_map + " -shortest " + "-y "; - } - else - { - AppParam = hw_decode + " " + inputs + input_map + " -y "; - } - String output_file = '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file) + "." + mux_ext + '\u0022'; - - if (!Directory.Exists(destino)) - { - Directory.CreateDirectory(destino); - } - - foreach (DataGridViewRow row in frm_mux_jobs.dg_pr.Rows) - { - if (row.Cells[5].Value.ToString() == output_file) - { - MessageBox.Show(Strings.out_ren, Strings.out_overw, MessageBoxButtons.OK, MessageBoxIcon.Information); - output_file = '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file) + "_mux_" + frm_mux_jobs.dg_pr.RowCount + "." + mux_ext + '\u0022'; - } - } - if (duracion.Contains(".")) duracion = duracion.Substring(0, duracion.LastIndexOf(".")); - else duracion = duracion.Substring(0, duracion.LastIndexOf(":")); - frm_mux_jobs.dg_pr.Rows.Add(frm_mux_jobs.dg_pr.RowCount + 1, Path.GetFileName(list_proc.Items[0].Text), AppParam, list_tracks.Items.Count.ToString(), duracion, output_file); - - try - { - Task t = Task.Run(() => - { - try - { - Directory.Delete(destino); - } - catch { } - }); - } - catch { } - btn_mux_show_jobs.Enabled = true; - if (frm_mux_jobs.dg_pr.RowCount > 0) lbl_mux_jobs.Text = Strings.jobs + " " + frm_mux_jobs.dg_pr.RowCount; - else lbl_mux_jobs.Text = String.Empty; - MessageBox.Show(lbl_mux_jobs.Text); - } - - private void add_single_stream_job() - { - Pg1.Focus(); - cancel_queue = false; - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - - if (list_tracks.Items.Count == 0) - { - MessageBox.Show(Strings.tracks_empty, Strings.no_files, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; - } - - if (list_tracks.SelectedIndices.Count != 1) - { - MessageBox.Show(Strings.sel_track, Strings.multiple_tr, MessageBoxButtons.OK, MessageBoxIcon.Information); - return; - } - - foreach (ListViewItem file0 in list_tracks.Items) - { - if (!File.Exists(file0.Text)) - { - MessageBox.Show(Strings.file_not_found + " " + file0.Text, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - - if (list_tracks.Items.Count == 0) - { - MessageBox.Show(Strings.tracks_empty, Strings.no_files, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; - } - - if (txt_track_format.Text == String.Empty && list_tracks.SelectedItems.Count > 0) - { - MessageBox.Show(Strings.track_Ext, Strings.warning, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; - } - - String is_overw = txt_path_main.Text + "\\" + Path.GetFileNameWithoutExtension(list_tracks.Items[0].Text) + "." + txt_track_format; - - if (is_overw == list_tracks.Items[0].Text) - { - MessageBox.Show(Strings.overw_main, Strings.overw_not_all, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - DateTime time2; - if (!DateTime.TryParse(ss_time_input.Text, out time2)) - { - MessageBox.Show(Strings.pre_input4, Strings.pre_input2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - //Validated list, start processing - //Pending duration - - if (dur_ok == false) - { - list_pending_dur.Items.Clear(); - foreach (ListViewItem item in listView1.Items) - { - list_pending_dur.Items.Add((ListViewItem)item.Clone()); - } - BG_Dur.RunWorkerAsync(); - return; - } - - cancel_queue = false; - - //Copy list of tracks for thread processing - ListView list_proc = new ListView(); - foreach (ListViewItem item in list_tracks.SelectedItems) - { - list_proc.Items.Add((ListViewItem)item.Clone()); - } - //End of copy list of tracks for thread processing - - //Duration - Process probe = new Process(); - probe.StartInfo.FileName = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - String ffprobe_frames2 = " " + '\u0022' + "--Inform=General;%Duration/String3%" + '\u0022'; - probe.StartInfo.Arguments = ffprobe_frames2 + " " + '\u0022' + list_proc.Items[0].Text + '\u0022'; - - probe.StartInfo.RedirectStandardOutput = true; - probe.StartInfo.UseShellExecute = false; - probe.StartInfo.CreateNoWindow = true; - probe.EnableRaisingEvents = true; - probe.Start(); - - String duracion = probe.StandardOutput.ReadLine(); - - probe.WaitForExit(); - DateTime time0; - if (duracion != null) - { - if (DateTime.TryParse(duracion, out time0)) - { - durat_n = TimeSpan.Parse(duracion).TotalSeconds; - total_duration = TimeSpan.Parse(duracion).TotalSeconds; - total_duration = durat_n; - } - } - else - { - duracion = "0"; - durat_n = 0; - total_duration = 0; - } - - //End duration - - //End - - Pg1.Minimum = 0; - Pg1.Maximum = 100; - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - lbl_speed.Text = String.Empty; - - List list_lines = new List(); - String mux_ext = txt_track_format.Text; - - String ffm = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - - String file = list_proc.Items[0].Text; - String fullPath = file; - - String destino = ""; - - if (txt_path_main.Text.Contains(".\\")) - { - destino = file.Substring(0, fullPath.LastIndexOf('\\')) + txt_path_main.Text.Replace(".", String.Empty); ; - } - else - { - destino = txt_path_main.Text; - } - - if (!Directory.Exists(destino)) - { - try - { - Directory.CreateDirectory(destino); - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.error2 + " " + excpt.Message, Strings.write_error2, MessageBoxButtons.OK, MessageBoxIcon.Error); - this.Cursor = Cursors.Arrow; - Enable_Controls(); - working = false; - return; - } - } - - //Create joint inputs variable - String inputs = String.Empty; - foreach (ListViewItem input_item in list_proc.Items) - { - String stream_type = String.Empty; - if (input_item.SubItems[2].Text.ToLower().Contains("subtitle")) - { - stream_type = "s"; - } - - if (input_item.SubItems[2].Text.ToLower().Contains("audio")) - { - stream_type = "a"; - } - if (input_item.SubItems[2].Text.ToLower().Contains("video")) - { - stream_type = "v"; - } - //{ - //inputs = inputs + " -sub_charenc UTF-8" + " -i " + '\u0022' + input_item.Text + '\u0022'; - //} - inputs = " -i " + '\u0022' + input_item.Text + '\u0022' + " -map 0:" + input_item.SubItems[1].Text + " -c:" + stream_type + " " + txt_track_param.Text + " "; - } - //End create joint inputs variable - - String AppParam = inputs + "-y "; - String output_file = '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file) + "." + mux_ext + '\u0022'; - - if (!Directory.Exists(destino)) - { - Directory.CreateDirectory(destino); - } - - foreach (DataGridViewRow row in frm_mux_jobs.dg_pr.Rows) - { - if (row.Cells[5].Value.ToString() == output_file) - { - MessageBox.Show(Strings.out_ren, Strings.out_overw, MessageBoxButtons.OK, MessageBoxIcon.Information); - output_file = '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file) + "_mux_" + frm_mux_jobs.dg_pr.RowCount + "." + mux_ext + '\u0022'; - } - } - if (duracion.Contains(".")) duracion = duracion.Substring(0, duracion.LastIndexOf(".")); - else duracion = duracion.Substring(0, duracion.LastIndexOf(":")); - frm_mux_jobs.dg_pr.Rows.Add(frm_mux_jobs.dg_pr.RowCount + 1, Path.GetFileName(list_proc.Items[0].Text), AppParam, list_tracks.Items.Count.ToString(), duracion, output_file); - - try - { - Task t = Task.Run(() => - { - try - { - Directory.Delete(destino); - } - catch { } - }); - } - catch { } - btn_mux_show_jobs.Enabled = true; - if (frm_mux_jobs.dg_pr.RowCount > 0) lbl_mux_jobs.Text = Strings.jobs + " " + frm_mux_jobs.dg_pr.RowCount; - else lbl_mux_jobs.Text = String.Empty; - MessageBox.Show(lbl_mux_jobs.Text); - } - - private void btn_mux_job_Click(object sender, EventArgs e) - { - if (list_tracks.Items.Count == 0) - { - if (listView2.Items.Count > 1 && listView2.SelectedItems.Count > 1) - { - ct2_save_allstreams.PerformClick(); - } - else - { - MessageBox.Show(Strings.track_empty, Strings.notrack_info, MessageBoxButtons.OK, MessageBoxIcon.Information); - return; - } - } - - if (!File.Exists(Path.Combine(Application.StartupPath, "ffmpeg.exe"))) - { - MessageBox.Show(Strings.no_ffmpeg, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (check_ff_md5() == false) - { - Form25 frm25 = new Form25(); - frm25.ShowDialog(); - return; - } - if (list_tracks.Items.Count == 1) add_single_stream_job(); - if (list_tracks.Items.Count > 1) add_video_mux_job(); - } - - private void btn_mux_show_jobs_Click(object sender, EventArgs e) - { - Pg1.Focus(); - frm_mux_jobs.ShowDialog(); - - if (frm_mux_jobs.dg_pr.RowCount > 0) lbl_mux_jobs.Text = Strings.jobs + " " + frm_mux_jobs.dg_pr.RowCount; - else - { - lbl_mux_jobs.Text = String.Empty; - btn_mux_show_jobs.Enabled = false; - } - if (frm_mux_jobs.view_logs == true) - { - show_mux_logs(); - return; - } - if (frm_mux_jobs.start_jobs == true) start_mux_jobs(); - } - - private void show_mux_logs() - { - Pg1.Focus(); - String path_log_file = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.log"; - if (!File.Exists(path_log_file)) - { - if (no_save_logs == true) MessageBox.Show(Strings.no_log_f, Strings.file_not_f, MessageBoxButtons.OK, MessageBoxIcon.Error); - else - if (no_save_logs == false) MessageBox.Show(Strings.no_log1, Strings.file_not_f, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - long length = new FileInfo(path_log_file).Length; - if (length > 20000000) - { - DialogResult a = MessageBox.Show(Strings.log_siz + " " + (length / 1024).ToString() + " KB " + Strings.time_load, Strings.warning, MessageBoxButtons.YesNo, MessageBoxIcon.Question); - if (a == DialogResult.No) return; - } - - //Form frm_output = new Form(); - frm_log.Name = Strings.last_log1; - frm_log.Text = "FFmpeg Batch AV Converter"; - frm_log.Icon = this.Icon; - - frm_log.Height = 675; - frm_log.Width = 977; - frm_log.FormBorderStyle = FormBorderStyle.Fixed3D; - frm_log.MaximizeBox = false; - frm_log.MinimizeBox = false; - - var fuente_list = new System.Drawing.Font("Microsoft Sans Serif", 9, FontStyle.Regular); - - Rtxt.Parent = frm_log; - Rtxt.Left = 20; - Rtxt.Top = 65; - Rtxt.Height = 525; - Rtxt.Width = 920; - Rtxt.Font = fuente_list; - - ContextMenu Rtxt_menu = new ContextMenu(); - Rtxt.ContextMenu = Rtxt_menu; - MenuItem CopyItem = new MenuItem(Strings.copy); - Rtxt_menu.MenuItems.Add(CopyItem); - CopyItem.Click += new EventHandler(CopyAction); - - TextBox titulo = new TextBox(); - titulo.Parent = frm_log; - titulo.Top = 15; - titulo.Left = 20; - titulo.Width = 921; - titulo.TabIndex = 0; - var fuente = new System.Drawing.Font("Microsoft Sans Serif", 11, FontStyle.Bold); - - titulo.Font = fuente; - titulo.BorderStyle = BorderStyle.Fixed3D; - titulo.TextAlign = HorizontalAlignment.Center; - titulo.ReadOnly = true; - - titulo.Text = Strings.last_b_l; - - Button boton_ok_ff = new Button(); - boton_ok_ff.Parent = frm_log; - boton_ok_ff.Left = 20; - boton_ok_ff.Top = 595; - boton_ok_ff.Width = 920; - boton_ok_ff.Height = 27; - boton_ok_ff.Text = Strings.last_b_l; - boton_ok_ff.Click += new EventHandler(boton_ok_ff_Click); - - TextBox titulo2 = new TextBox(); - titulo2.Parent = frm_log; - titulo2.Top = 42; - titulo2.Left = 47; - titulo2.Width = 867; - - var fuente2 = new System.Drawing.Font("Microsoft Sans Serif", 10, FontStyle.Regular); - - titulo2.Font = fuente2; - titulo2.BorderStyle = BorderStyle.None; - titulo2.TextAlign = HorizontalAlignment.Center; - titulo2.ReadOnly = true; - - titulo2.Text = "ff_batch.log"; - - frm_log.StartPosition = FormStartPosition.CenterScreen; - Rtxt.Text = File.ReadAllText(path_log_file); - boton_ok_ff.Text = Strings.close_win; - frm_log.ShowDialog(); - frm_log.Refresh(); - } - - private void start_mux_jobs() - { - Pg1.Focus(); - lbl_est_size.Text = ""; - lbl_bitrate.Text = ""; - - if (!File.Exists(Path.Combine(Application.StartupPath, "ffmpeg.exe"))) - { - MessageBox.Show(Strings.no_ffmpeg, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (check_ff_md5() == false) - { - Form25 frm25 = new Form25(); - frm25.ShowDialog(); - return; - } - - cancel_queue = false; - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - Disable_Controls(); - txt_remain.Text = Strings.remain_time + " " + "00h:00m:00s"; - time_n_tasks = 0; - timer_tasks.Start(); - timer_est_size.Start(); - - cancel_queue = false; - Pg1.Value = 0; - working = true; - - //Copy list of tracks for thread processing - - DataGridView list_proc = new DataGridView(); - list_proc.Columns.Add("Nr", ""); - list_proc.Columns.Add(Strings.filename, ""); - list_proc.Columns.Add("Parameters", ""); - list_proc.Columns.Add("Streams", ""); - list_proc.Columns.Add(Strings.duration, ""); - list_proc.Columns.Add("Output", ""); - - foreach (DataGridViewRow item in frm_mux_jobs.dg_pr.Rows) - { - list_proc.Rows.Add(item.Cells[0].Value, item.Cells[1].Value, item.Cells[2].Value, item.Cells[3].Value, item.Cells[4].Value, item.Cells[5].Value); - } - - //End of copy list of tracks for thread processing - - Double total_duration = 0; - Double total_prog = 0; - - //Duration - foreach (DataGridViewRow row in frm_mux_jobs.dg_pr.Rows) - { - total_duration = total_duration + TimeSpan.Parse(row.Cells[4].Value.ToString()).TotalSeconds; - } - - //durat_n = TimeSpan.Parse(row.Cells[5].Value.ToString()).TotalSeconds; - //End duration - - Pg1.Minimum = 0; - Pg1.Maximum = 100; - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - lbl_speed.Text = String.Empty; - lbl_elapsed.Text = Strings.time_elapsed + " " + "00h:00m:00s"; - - List list_lines = new List(); - pic_no_errors.Visible = false; - pic_recording.Visible = false; - pic_warnings.Visible = false; - - int i = 0; - int rows = list_proc.RowCount - 1; - - procs.Clear(); - procs.Add("proc_urls_0", new Process()); - var tmp = procs["proc_urls_0"]; - - groupBox2.Enabled = true; - foreach (Control p in groupBox2.Controls) - { - if (p.Name != lbl_mux_jobs.Name) - { - this.InvokeEx(f => p.Enabled = false); - } - } - - new System.Threading.Thread(() => - { - System.Threading.Thread.CurrentThread.IsBackground = true; - - foreach (DataGridViewRow row in list_proc.Rows) - { - if (cancel_queue == true) - { - working = false; - time_est_size = 0; - tmp.StartInfo.Arguments = String.Empty; - Enable_Controls(); - this.Invoke(new MethodInvoker(delegate - { - Pg1.Value = 100; - Pg1.Text = "100%"; - Pg1.Refresh(); - this.Text = "FFmpeg Batch AV Converter"; - if (is_portable == true) - this.Text = "FFmpeg Batch AV Converter Portable"; - lbl_speed.Text = String.Empty; - lbl_est_size.Text = String.Empty; - lbl_bitrate.Text = String.Empty; - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - })); - - MessageBox.Show(Strings.queue_abort, Strings.task_abort, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; - } - - String remain_time = "0"; - if (row.IsNewRow == true) - { - i++; - continue; - } - - String destino = row.Cells[5].Value.ToString(); - destino = destino.Substring(1, destino.Length - 2); - destino = Path.GetDirectoryName(destino); - String ffm = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - String AppParam = row.Cells[2].Value.ToString(); - - if (!Directory.Exists(destino)) - { - Directory.CreateDirectory(destino); - } - this.InvokeEx(f => f.lbl_mux_jobs.Text = Strings.jobs + " " + (i + 1).ToString() + " " + Strings.of1 + " " + rows.ToString()); - - valid_prog = false; - tmp.StartInfo.FileName = ffm; - tmp.StartInfo.Arguments = AppParam + " " + row.Cells[5].Value.ToString(); - tmp.StartInfo.RedirectStandardError = true; - tmp.StartInfo.RedirectStandardInput = true; - tmp.StartInfo.UseShellExecute = false; - tmp.StartInfo.CreateNoWindow = true; - tmp.EnableRaisingEvents = true; - tmp.Start(); - - System.Threading.Thread.Sleep(50); - combo_prio.Invoke(new MethodInvoker(delegate - { - if (combo_prio.SelectedIndex != 2) - { - Change_mem_prio(); - } - })); - - valid_prog = true; - - String err_txt = ""; - Double interval = 0; - Decimal est_bitrate = 0; - Decimal est_size = 0; - this.InvokeEx(f => f.lbl_speed.Text = String.Empty); - Double sec_prog = 0; - try - { - while (!tmp.StandardError.EndOfStream) - { - err_txt = tmp.StandardError.ReadLine(); - list_lines.Add(err_txt); - - if (err_txt.Contains("time=") && err_txt.Contains("time=-") == false) - { - if (valid_prog == true) - { - this.InvokeEx(f => durat_n = TimeSpan.Parse(row.Cells[4].Value.ToString()).TotalSeconds); - int start_time_index = err_txt.IndexOf("time=") + 5; - sec_prog = TimeSpan.Parse(err_txt.Substring(start_time_index, 8)).TotalSeconds; - - Double percent = (sec_prog * 100 / durat_n); - - total_prog = total_prog + (sec_prog - interval); - interval = sec_prog; - int percent2 = Convert.ToInt32(percent); - - Double percent_tot = (total_prog * 100 / total_duration); - int percent_tot_2 = Convert.ToInt32(percent_tot); - - if (percent_tot_2 <= 100) - { - this.InvokeEx(f => f.Pg1.Value = percent_tot_2); - this.InvokeEx(f => f.Pg1.Refresh()); - - if (Math.Round(percent_tot, 1).ToString().Contains(".") || Math.Round(percent_tot, 1).ToString().Contains(",")) - { - this.InvokeEx(f => f.Pg1.Text = Math.Round(percent_tot, 1).ToString() + "%"); - } - else - { - this.InvokeEx(f => f.Pg1.Text = Math.Round(percent_tot, 1).ToString() + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0" + "%"); - } - this.InvokeEx(f => f.Pg1.Refresh()); - - this.InvokeEx(f => TaskbarProgress.SetValue(this.Handle, percent_tot, Pg1.Maximum)); - } - - if (cancel_queue == false) - { - //Estimated remaining time - - remain_time = err_txt.Substring(err_txt.LastIndexOf("speed=") + 6, err_txt.Length - err_txt.LastIndexOf("speed=") - 6); - if (time_est_size % 3 == 0) this.InvokeEx(f => f.lbl_speed.Text = Strings.speed + " " + remain_time); - remain_time = remain_time.Replace("x", String.Empty); - Double timing1 = 0; - - if (System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",") - { - timing1 = Math.Round(Double.Parse(remain_time.Replace(".", ",")), 2); - } - else - { - timing1 = Math.Round(Double.Parse(remain_time), 2); - } - - Decimal timing = (decimal)timing1; - Decimal total_dur_dec = Convert.ToDecimal(total_duration); - Decimal total_prog_dec = Convert.ToDecimal(total_prog); - Decimal remain_secs = 0; - if (timing > 0) - { - remain_secs = (decimal)(total_dur_dec - total_prog_dec) / timing; - } - - if (remain_secs > 60) - { - remain_secs = remain_secs + 60; - } - - String remain_from_secs = ""; - - TimeSpan t = TimeSpan.FromSeconds(Convert.ToDouble(remain_secs)); - remain_from_secs = string.Format("{0:D2}h:{1:D2}", - t.Hours, - t.Minutes); - - this.Invoke(new MethodInvoker(delegate - { - if (remain_secs >= 43200) - { - txt_remain.Text = Strings.remain_time + " " + Math.Round(remain_secs / 3600).ToString() + " " + Strings.hours; - this.Text = Pg1.Text + " / " + Math.Round(remain_secs / 3600).ToString() + " " + Strings.hours; - } - - if (remain_secs >= 3600 && remain_secs < 43200) - { - txt_remain.Text = Strings.remain_time + " " + remain_from_secs + " " + Strings.minutes_abrev; - this.Text = Pg1.Text + " / " + remain_from_secs + " " + Strings.minutes_abrev; - } - - if (remain_secs < 3600 && remain_secs >= 600) - { - txt_remain.Text = Strings.remain_time + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 1, 2) + " " + Strings.minutes; - this.Text = Pg1.Text + " / " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 1, 2) + " " + Strings.minutes_abrev; - } - if (remain_secs < 600 && remain_secs >= 120) - { - txt_remain.Text = Strings.remain_time + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 2, 1) + " " + Strings.minutes; - this.Text = Pg1.Text + " / " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 2, 1) + " " + Strings.minutes_abrev; - } - - if (remain_secs <= 59 && remain_secs != 0) - { - txt_remain.Text = Strings.remain_time + " " + Convert.ToInt16(Math.Abs(remain_secs)) + " " + Strings.seconds; - this.Text = Pg1.Text + " / " + Convert.ToInt16(Math.Abs(remain_secs)) + " s"; - } - if (remain_secs == 0) - { - txt_remain.Text = Strings.remain_time + " " + Strings.about_finish; - this.Text = Pg1.Text; - } - })); - - } - //End remaining time - - //Estimated size and bitrate - - String read_size = String.Empty; - if (err_txt.Contains("size=") && (time_est_size % 3 == 0)) - { - int size_index = err_txt.IndexOf("size=") + 5; - read_size = err_txt.Substring(size_index, 8); - if (Convert.ToDecimal(sec_prog) != 0) - { - est_bitrate = (Math.Round(Convert.ToDecimal(read_size) * 8 / Convert.ToDecimal(sec_prog), 0)); - } - else - { - est_bitrate = 0; - } - - if (Convert.ToDecimal(read_size) > 1 && time_n_tasks > 1) - { - if (est_bitrate < 9999) - { - if (est_bitrate > 48) - { - this.InvokeEx(f => f.lbl_bitrate.Text = Strings.avg_bit + ": " + est_bitrate + " " + "Kb/s"); - } - else - { - this.InvokeEx(f => f.lbl_bitrate.Text = Strings.avg_bit + ": "); - } - } - else - { - this.InvokeEx(f => f.lbl_bitrate.Text = Strings.avg_bit + ": " + (Math.Round(est_bitrate / 1000, 0)) + " " + "Mb/s"); - } - //Estimated size - est_size = Convert.ToDecimal(durat_n) * est_bitrate / 8; - - if (est_size > 1000000) - { - this.InvokeEx(f => f.lbl_est_size.Text = Strings.est_size + " " + (Math.Round(est_size / 1000000, 1)).ToString() + " " + "GB"); - } - else - { - if (Math.Round(est_size / 1000, 0) > 0) - { - this.InvokeEx(f => f.lbl_est_size.Text = Strings.est_size + " " + (Math.Round(est_size / 1000, 0)).ToString() + " " + "MB"); - } - else - { - this.InvokeEx(f => f.lbl_est_size.Text = Strings.est_size + " "); - } - } - } - - this.InvokeEx(f => f.lbl_est_size.Refresh()); - } - } - } - } - } - catch { } - - tmp.WaitForExit(); - tmp.StartInfo.Arguments = String.Empty; - - if (tmp.ExitCode == 0) - { - if (cancel_queue == false) this.InvokeEx(f => f.frm_mux_jobs.dg_pr.Rows[row.Index].DefaultCellStyle.BackColor = Color.LightGreen); - else this.InvokeEx(f => f.frm_mux_jobs.dg_pr.Rows[row.Index].DefaultCellStyle.BackColor = Color.LightSalmon); - } - else - { - this.InvokeEx(f => f.frm_mux_jobs.dg_pr.Rows[row.Index].DefaultCellStyle.BackColor = Color.LightSalmon); - errors_enc = errors_enc + 1; - } - - i++; - - if (i == list_proc.RowCount - 1) - { - tmp.StartInfo.Arguments = String.Empty; - this.Invoke(new MethodInvoker(delegate - { - lbl_mux_jobs.Text = Strings.jobs + " " + list_proc.RowCount.ToString(); - Pg1.Value = 100; - Pg1.Text = "100%"; - Pg1.Refresh(); - lbl_speed.Text = String.Empty; - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - lbl_est_size.Text = String.Empty; - lbl_bitrate.Text = String.Empty; - this.Text = "FFmpeg Batch AV Converter"; - if (is_portable == true) this.Text = "FFmpeg Batch AV Converter Portable"; - })); - - list_lines.Add(""); - list_lines.Add("---------------------End of " + Path.GetFileName(row.Cells[1].Value.ToString()) + " log-------------------------------"); - list_lines.Add(""); - - working = false; - // - if (no_save_logs == false) - { - string[] array_err = list_lines.ToArray(); - String path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.log"; - if (is_portable == true) path = port_path + "ff_batch_portable.log"; - - StreamWriter SaveFile = new StreamWriter(path); - SaveFile.WriteLine("FFmpeg log sesion: " + System.DateTime.Now); - SaveFile.WriteLine("-------------------------------"); - foreach (String item in array_err) - { - SaveFile.WriteLine(item); - } - SaveFile.Close(); - - File.AppendAllText(path, "-----------------------"); - File.AppendAllText(path, Environment.NewLine + Strings.end_log); - FileInfo fileInfo = new FileInfo(path); - - var bytes = fileInfo.Length; - - var kilobytes = (double)bytes / 1024; - var megabytes = kilobytes / 1024; - var gigabytes = megabytes / 1024; - - //Format size view - String size = ""; - String separator = "."; - - if (bytes > 1000000000) - { - if (gigabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String gigas = gigabytes.ToString(); - if (gigas.Length >= 5) - { - gigas = gigas.Substring(0, gigas.LastIndexOf(separator) + 3); - size = (gigas + " " + "GB"); - } - else - { - size = (gigas + " " + "GB"); - } - } - - if (bytes >= 1048576 && bytes <= 1000000000) - { - if (megabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - String megas = megabytes.ToString(); - if (megas.Length > 5) - { - megas = megas.Substring(0, megas.LastIndexOf(separator)); - size = (megas + " " + "MB"); - } - else - { - size = (megas + " " + "MB"); - } - } - - if (bytes >= 1024 && bytes < 1048576) - - { - if (kilobytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String kbs = kilobytes.ToString(); - if (kbs.Length >= 5) - { - kbs = kbs.Substring(0, kbs.LastIndexOf(separator)); - size = (kbs + " " + "KB"); - } - else - { - size = (kbs + " " + "KB"); - } - } - if (bytes > -1 && bytes < 1024) - { - String bits = bytes.ToString(); - size = (bits + " Bytes"); - } - - //End Format size view - File.AppendAllText(path, Environment.NewLine + Strings.log_size + " " + size); - - //End save log - } - - Enable_Controls(); - timer_est_size.Stop(); - time_est_size = 0; - - if (cancel_queue == false) - { - if (chkshut.Checked) - { - if (errors_enc == 0) - { - this.Invoke(new MethodInvoker(delegate - { - groupBox2.Enabled = true; - foreach (Control ct in groupBox2.Controls) - { - ct.Enabled = false; - } - })); - - auto_shut(); - return; - } - } - //End shutdown check - else - { - this.InvokeEx(f => toolT002.RemoveAll()); - if (play_on_end == true) play_end(); - if (errors_enc == 0) this.InvokeEx(f => f.pic_no_errors.Visible = true); - else - { - this.Invoke(new MethodInvoker(delegate - { - pic_no_errors.Visible = false; - pic_recording.Visible = false; - toolT002.SetToolTip(this.pic_warnings, Strings.there_w + " " + errors_enc.ToString() + " " + Strings.errors_se); - pic_warnings.Visible = true; - })); - } - - if (Form.ActiveForm == null) - { - if (errors_enc == 0) - { - notifyIcon1.Visible = true; - notifyIcon1.BalloonTipText = Strings.batch_mux; - notifyIcon1.BalloonTipIcon = ToolTipIcon.Info; - notifyIcon1.BalloonTipTitle = Strings.b_mux_c; - notifyIcon1.ShowBalloonTip(0); - } - else - { - notifyIcon1.Visible = true; - notifyIcon1.BalloonTipText = Strings.b_mux_err; - notifyIcon1.BalloonTipIcon = ToolTipIcon.Warning; - notifyIcon1.BalloonTipTitle = Strings.b_mux_c; - notifyIcon1.ShowBalloonTip(0); - } - } - - if (chk_open_compl.Checked) - { - if (Directory.GetFiles(destino).Length != 0) - { - destino = destino.Replace("\\\\", "\\"); - Process open_processed = new Process(); - open_processed.StartInfo.FileName = "explorer.exe"; - open_processed.StartInfo.Arguments = '\u0022' + destino + '\u0022'; - open_processed.Start(); - } - else - { - if (Directory.Exists(destino)) - { - Directory.Delete(destino); - } - } - } - } - } - else - { - if (cancel_queue == false) - { - this.InvokeEx(f => f.Pg1.Text = "100%"); - this.InvokeEx(f => MessageBox.Show(Strings.mux_abort1, Strings.aborted, MessageBoxButtons.OK, MessageBoxIcon.Error)); - } - } - - listView1.Invoke(new MethodInvoker(delegate - { - frm_mux_jobs.ShowDialog(); - if (frm_mux_jobs.view_logs == true) - { - show_mux_logs(); - return; - } - })); - } - } - }).Start(); - } - - private void menu_extract_images_Click(object sender, EventArgs e) - { - AeroWizard5 wiz_img = new AeroWizard5(); - wiz_img.pr1_first_params = ""; - wiz_img.StartPosition = FormStartPosition.CenterParent; - wiz_img.list_count = listView1.Items.Count; - wiz_img.ShowDialog(); - if (wiz_img.canceled == true) return; - - if (wiz_img.save_preset == false) - { - combo_presets.Text = Strings.new_preset; - txt_parameters.Text = wiz_img.pr1_first_params; - txt_format.Text = "nul"; - } - else - { - combo_presets.SelectedIndex = combo_presets.Items.Count - 1; - combo_presets.Text = wiz_img.txt_preset_name.Text; - txt_parameters.Text = wiz_img.pr1_first_params; - txt_format.Text = "nul"; - btn_save_preset.PerformClick(); - } - if (wiz_img.radio_keys.Checked) txt_pre_input.Text = "-skip_frame nokey"; - if (wiz_img.start_enc == true) btn_seq.PerformClick(); - } - - private void Form1_Resize(object sender, EventArgs e) - { - if (this.WindowState == FormWindowState.Minimized && Settings.Default.to_tray == true) - { - notifyIcon1.Visible = true; - notifyIcon1.ShowBalloonTip(3000, Strings.to_tray1, Strings.to_tray2, ToolTipIcon.Info); - this.ShowInTaskbar = false; - notifyIcon1.Visible = true; - return; - } - else - { - try { notifyIcon1.Visible = false; } catch { } - this.ShowInTaskbar = true; - } - - resize(); - } - - private void txt_path_main_TextChanged(object sender, EventArgs e) - { - txt_path_main.BackColor = Color.White; - btn_save_path.Enabled = true; - } - - private void txt_path_mux_TextChanged(object sender, EventArgs e) - { - txt_path_main.Text = txt_path_mux.Text; - } - - private void btn_add_col_Click(object sender, EventArgs e) - { - Pg1.Focus(); - if (LB_Wait.Text == Strings.add_col1) return; - Form17 frm_add_col = new Form17(); - frm_add_col.cb_col.Items.Clear(); - Boolean has_res = false; - Boolean has_vid = false; - Boolean has_aud = false; - Boolean has_bit = false; - Boolean has_abit = false; - Boolean has_tbit = false; - Boolean has_custom_med = false; - Boolean has_cust_params = false; - - foreach (ColumnHeader col in listView1.Columns) - { - String col_t = col.Text.Replace("<", "").Replace(">", "").TrimStart(); - - - if (col_t.Contains(Strings.width)) has_res = true; - if (col_t.Contains(Strings.Video_codec)) has_vid = true; - if (col_t.Contains(Strings.Audio_codec)) has_aud = true; - if (col_t.Contains(Strings.v_bitr)) has_bit = true; - if (col_t.Contains(Strings.a_bitr)) has_abit = true; - if (col_t.Contains(Strings.Encoding_parameters)) has_cust_params = true; - if (col_t == Settings.Default.cust_med_col) has_custom_med = true; - if (col_t == Strings.bitrate && !col.Text.ToLower().Contains("video") && !col.Text.ToLower().Contains("audio") && !col.Text.ToLower().Contains("vídeo") && !col.Text.ToLower().Contains("视频") && !col.Text.ToLower().Contains("音")) has_tbit = true; - } - - if (has_tbit == false) frm_add_col.cb_col.Items.Add(Strings.bitrate); - if (has_vid == false) frm_add_col.cb_col.Items.Add(Strings.Video_codec); - if (has_bit == false) frm_add_col.cb_col.Items.Add(Strings.v_bitr); - if (has_res == false) frm_add_col.cb_col.Items.Add(Strings.resolution); - if (has_aud == false) frm_add_col.cb_col.Items.Add(Strings.Audio_codec); - if (has_abit == false) frm_add_col.cb_col.Items.Add(Strings.a_bitr); - if (has_custom_med == false) frm_add_col.cb_col.Items.Add(Strings.custom); - if (has_cust_params == false) frm_add_col.cb_col.Items.Add(Strings.Encoding_parameters); - - if (listView1.Columns.Count < 7) frm_add_col.btn_del_col.Enabled = false; - else frm_add_col.btn_del_col.Enabled = true; - if (listView1.Columns.Count < 8) frm_add_col.btn_all.Enabled = false; - else frm_add_col.btn_all.Enabled = true; - - frm_add_col.ShowDialog(); - if (frm_add_col.canceled == true) return; - if (!frm_add_col.to_remove && !frm_add_col.to_remove_all) - { - selected_add_col = frm_add_col.cb_col.SelectedItem.ToString(); - if (frm_add_col.cb_custom_med.SelectedIndex != -1) - { - Settings.Default.cust_med_col = frm_add_col.cb_custom_med.SelectedItem.ToString(); - - if (frm_add_col.cb_custom_med.SelectedIndex > 1 && frm_add_col.cb_custom_med.SelectedIndex < 18) - { Settings.Default.cust_med_col_t = 0; } - else { - Settings.Default.cust_med_col_t = 1; } - Settings.Default.Save(); - } - - foreach (ListViewItem item in listView1.Items) - { - item.SubItems.Add("-"); - - } - - if (frm_add_col.cb_col.SelectedItem.ToString() == Strings.resolution) - { - Boolean already_added = false; - col_width = 0; - foreach (ColumnHeader head_col in listView1.Columns) - { - if (head_col.Text.Contains(Strings.width)) - { - col_width = head_col.Index; - already_added = true; - break; - } - } - if (already_added == false) - { - ColumnHeader columnHeader = listView1.Columns.Add(Strings.width, 50, HorizontalAlignment.Center); - ColumnHeader columnHeader2 = listView1.Columns.Add(Strings.height, 50, HorizontalAlignment.Center); - } - foreach (ColumnHeader head_col in listView1.Columns) - { - if (head_col.Text.Contains(Strings.width)) - { - col_width = head_col.Index; - break; - } - } - if (already_added == false) - { - - foreach (ListViewItem item in listView1.Items) - { - item.SubItems.Add("-"); - } - - pre_add_col(); - BG_R_Cols.RunWorkerAsync(); - } - } - if (frm_add_col.cb_col.SelectedItem.ToString() == Strings.Video_codec) - { - Boolean already_vcodec = false; - foreach (ColumnHeader head_col in listView1.Columns) - { - if (head_col.Text.Contains(Strings.Video_codec)) - { - already_vcodec = true; - break; - } - } - if (already_vcodec == false) - { - ColumnHeader columnHeader = listView1.Columns.Add(Strings.Video_codec, 100, HorizontalAlignment.Left); - } - if (already_vcodec == false) - { - pre_add_col(); - BG_R_Cols.RunWorkerAsync(); - } - } - if (frm_add_col.cb_col.SelectedItem.ToString() == Strings.Audio_codec) - { - Boolean already_acodec = false; - foreach (ColumnHeader head_col in listView1.Columns) - { - if (head_col.Text.Contains(Strings.Audio_codec)) - { - already_acodec = true; - break; - } - } - if (already_acodec == false) - { - ColumnHeader columnHeader = listView1.Columns.Add(Strings.Audio_codec, 100, HorizontalAlignment.Center); - - } - if (already_acodec == false) - { - pre_add_col(); - BG_R_Cols.RunWorkerAsync(); - } - } - - if (frm_add_col.cb_col.SelectedItem.ToString() == Strings.v_bitr) - { - Boolean already_vbitr = false; - foreach (ColumnHeader head_col in listView1.Columns) - { - if (head_col.Text.Contains(Strings.v_bitr)) - { - already_vbitr = true; - break; - } - } - if (already_vbitr == false) - { - ColumnHeader columnHeader = listView1.Columns.Add(Strings.v_bitr, 100, HorizontalAlignment.Center); - } - if (already_vbitr == false) - { - pre_add_col(); - BG_R_Cols.RunWorkerAsync(); - } - } - - if (frm_add_col.cb_col.SelectedItem.ToString() == Strings.a_bitr) - { - Boolean already_abr = false; - foreach (ColumnHeader head_col in listView1.Columns) - { - if (head_col.Text.Contains(Strings.a_bitr)) - { - already_abr = true; - break; - } - } - if (already_abr == false) - { - ColumnHeader columnHeader = listView1.Columns.Add(Strings.a_bitr, 100, HorizontalAlignment.Center); - - } - if (already_abr == false) - { - pre_add_col(); - BG_R_Cols.RunWorkerAsync(); - } - } - - if (frm_add_col.cb_col.SelectedItem.ToString() == Strings.Encoding_parameters) - { - Boolean already_cust = false; - foreach (ColumnHeader head_col in listView1.Columns) - { - if (head_col.Text.Contains(Strings.Encoding_parameters)) - { - already_cust = true; - break; - } - } - if (already_cust == false) - { - ColumnHeader columnHeader = listView1.Columns.Add(Strings.Encoding_parameters, 150, HorizontalAlignment.Center); - - } - if (already_cust == false) - { - pre_add_col(); - BG_R_Cols.RunWorkerAsync(); - } - } - - //Custom media info - - if (frm_add_col.cb_col.SelectedItem.ToString() == Strings.custom) - { - Boolean already_cust_med = false; - foreach (ColumnHeader head_col in listView1.Columns) - { - if (head_col.Text.Contains(Settings.Default.cust_med_col)) - { - already_cust_med = true; - break; - } - } - if (already_cust_med == false) - { - ColumnHeader columnHeader = listView1.Columns.Add(Settings.Default.cust_med_col, 150, HorizontalAlignment.Center); - } - if (already_cust_med == false) - { - pre_add_col(); - BG_R_Cols.RunWorkerAsync(); - } - } - - //End custom media info - - if (frm_add_col.cb_col.SelectedItem.ToString() == Strings.bitrate) - { - ColumnHeader columnHeader = listView1.Columns.Add(Strings.bitrate, 100, HorizontalAlignment.Center); - pre_add_col(); - refresh_full(); - } - } - if (frm_add_col.to_remove_all == true) - { - clean_cols(); - } - if (frm_add_col.to_remove == true) - { - remove_last_col(); - } - - list_cols(); - - if (listView1.Columns.Count >= 15) - { - cti1_cols.Enabled = false; - } - if (listView1.Columns.Count <= 15 && listView1.Columns.Count >= 6) - { - cti1_cols.Enabled = true; - } - if (listView1.Columns.Count > 6) - { - cti_remove_col.Enabled = true; - } - else - { - cti_remove_col.Enabled = false; - } - } - - private void list_cols() - { - String f_cols = String.Empty; - if (is_portable == false) - { - f_cols = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_cols.ini"; - } - else - { - f_cols = port_path + "ff_cols_portable.ini"; - } - String cols_lv = string.Empty; - foreach (ColumnHeader col in listView1.Columns) - { - cols_lv = cols_lv + col.Text.Trim().Replace(">", "").Replace("<", "") + ";" + col.Width.ToString() + Environment.NewLine; - } - File.WriteAllText(f_cols, cols_lv); - } - - private void pre_add_col() - { - listView1.Invoke(new MethodInvoker(delegate - { - if (listView1.Items.Count == 0 || tabControl1.SelectedIndex != 0) return; - })); - } - - private void listView1_KeyDown(object sender, KeyEventArgs e) - { - if (e.Control && e.KeyCode == Keys.A) - { - foreach (ListViewItem item in listView1.Items) item.Selected = true; - return; - } - - if (listView1.Items.Count == 0) - { - if (e.Control && e.KeyCode == Keys.V) - { - if (Directory.Exists(Clipboard.GetText())) - { - add_paste_folder(Clipboard.GetText()); - } - } - } - } - - private void cti1_cols_Click(object sender, EventArgs e) - { - btn_add_col.PerformClick(); - } - - private void listView1_ColumnWidthChanged(object sender, ColumnWidthChangedEventArgs e) - { - if (listView1.Columns[e.ColumnIndex].Width < _minimumColumnWidth) - { - if (e.ColumnIndex == 5) - { - listView1.Columns[e.ColumnIndex].Width = 104; - } - if (e.ColumnIndex == 0) - { - listView1.Columns[e.ColumnIndex].Width = 204; - } - if (e.ColumnIndex == 1) - { - listView1.Columns[e.ColumnIndex].Width = 204; - } - - if (e.ColumnIndex != 5 && e.ColumnIndex != 0 && e.ColumnIndex != 1) - { - listView1.Columns[e.ColumnIndex].Width = _minimumColumnWidth; - } - } - } - - private void cti_remove_col_Click(object sender, EventArgs e) - { - remove_last_col(); - list_cols(); - } - - private void remove_last_col() - { - Boolean has_resol = false; - if (listView1.Columns.Count > 6) - { - foreach (ColumnHeader col in listView1.Columns) - { - if (col.Index == listView1.Columns.Count - 1) - { - if (col.Text.Contains(Strings.height)) has_resol = true; - listView1.Columns.Remove(col); - } - } - } - - if (has_resol == true) - { - foreach (ColumnHeader col in listView1.Columns) - { - if (col.Index == listView1.Columns.Count - 1) - { - if (col.Text.Contains(Strings.width)) - listView1.Columns.Remove(col); - } - } - } - refresh_full(); - } - - private void chk_trim2_CheckedChanged(object sender, EventArgs e) - { - String f_trim = String.Empty; - if (is_portable == false) - { - f_trim = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_trim.ini"; - } - else - { - f_trim = port_path + "ff_trim_portable.ini"; - } - - if (chk_trim2.CheckState == CheckState.Checked) - { - File.WriteAllText(f_trim, String.Empty); - } - else - { - try - { - File.Delete(f_trim); - } - catch - { - MessageBox.Show(Strings.err_set, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - - private void pic_title_Click(object sender, EventArgs e) - { - menu_about.PerformClick(); - } - - private String safe_out_ffname(String outf) - { - outf = outf.Replace("/", "_"); - outf = outf.Replace(":", "_"); - outf = outf.Replace("*", "_"); - outf = outf.Replace("?", "_"); - outf = outf.Replace("¿", "_"); - outf = outf.Replace("@", "_"); - outf = outf.Replace("\u0022", "_"); - outf = outf.Replace("<", "_"); - outf = outf.Replace(">", "_"); - outf = outf.Replace("|", "_"); - outf = outf.Replace(";", "_"); - outf = outf.Replace("\\", "_"); - outf = outf.Replace("(", "_"); - outf = outf.Replace(")", "_"); - return outf; - } - - private void get_chapters(String file_ch) - { - String ff_frames = String.Empty; - Process get_chap = new Process(); - String args = " -y -an -vn -sn -f ffmetadata "; - String output = Path.Combine(Path.GetTempPath(), "FFBatch_Test") + "\\" + Path.GetFileNameWithoutExtension(safe_out_ffname(file_ch)) + ".txt"; - get_chap.StartInfo.FileName = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - get_chap.StartInfo.Arguments = "-i " + '\u0022' + file_ch + '\u0022' + args + '\u0022' + output + '\u0022'; - get_chap.StartInfo.CreateNoWindow = true; - get_chap.EnableRaisingEvents = true; - get_chap.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - get_chap.Start(); - get_chap.WaitForExit(); - String chaps_file = String.Empty; - list_chaps.Clear(); - - if (get_chap.ExitCode == 0 && File.Exists(output)) chaps_file = File.ReadAllText(output); - else - { - MessageBox.Show(Strings.no_chaps); - return; - } - Boolean titles = false; - if (chaps_file.Contains("title=")) titles = true; - - String[] chaps = chaps_file.Split(new[] { "[CHAPTER]", "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries); - String tb = String.Empty; - Double tbd = 0; - String tst = String.Empty; - Double tstd = 0; - String tstend = String.Empty; - Double tsendd = 0; - String tsttit = String.Empty; - - if (titles == true) - { - foreach (String chap in chaps) - { - if (chap.Contains("TIMEBASE=1/")) - { - int tbase = chap.LastIndexOf("TIMEBASE=1/"); - tb = chap.Substring(tbase + 11, (chap.Length - tbase - 11)); - tbd = Convert.ToDouble(tb); - //MessageBox.Show("Base: " + tb); - } - if (chap.Contains("START=")) - { - int tstart = chap.LastIndexOf("START="); - tst = chap.Substring(tstart + 6, chap.Length - tstart - 6); - tstd = Convert.ToDouble(tst); - } - if (chap.Contains("END=")) - { - int tsend = chap.LastIndexOf("END="); - tstend = chap.Substring(tsend + 4, chap.Length - tsend - 4); - tsendd = Convert.ToDouble(tstend); - } - - if (chap.Contains("title=")) - { - int tstitle = chap.LastIndexOf("title="); - tsttit = chap.Substring(tstitle + 6, chap.Length - tstitle - 6); - String[] sstt = new String[] { "-ss " + (tstd / tbd).ToString().Replace(",", "."), "-to " + (tsendd / tbd).ToString().Replace(",", "."), tsttit }; - list_chaps.Add(sstt); - } - } - } - else - { - foreach (String chap in chaps) - { - if (chap.Contains("TIMEBASE=1/")) - { - int tbase = chap.LastIndexOf("TIMEBASE=1/"); - tb = chap.Substring(tbase + 11, (chap.Length - tbase - 11)); - tbd = Convert.ToDouble(tb); - //MessageBox.Show("Base: " + tb); - } - if (chap.Contains("START=")) - { - int tstart = chap.LastIndexOf("START="); - tst = chap.Substring(tstart + 6, chap.Length - tstart - 6); - tstd = Convert.ToDouble(tst); - } - if (chap.Contains("END=")) - { - int tsend = chap.LastIndexOf("END="); - tstend = chap.Substring(tsend + 4, chap.Length - tsend - 4); - tsendd = Convert.ToDouble(tstend); - String[] sstt = new String[] { "-ss " + (tstd / tbd).ToString().Replace(",", "."), "-to " + (tsendd / tbd).ToString().Replace(",", "."), tsttit }; - list_chaps.Add(sstt); - } - } - } - } - - private void menu_split_Click(object sender, EventArgs e) - { - AeroWizard6 wiz_split = new AeroWizard6(); - wiz_split.pr1_first_params = ""; - wiz_split.StartPosition = FormStartPosition.CenterParent; - wiz_split.list_count = listView1.Items.Count; - if (listView1.Items.Count > 0) - { - if (listView1.SelectedIndices.Count == 0) - { - foreach (ListViewItem item in listView1.Items) - { - wiz_split.list_files.Add(item.SubItems[1].Text + "\\" + item.Text); - } - - } - else - { - foreach (ListViewItem item in listView1.SelectedItems) - { - wiz_split.list_files.Add(item.SubItems[1].Text + "\\" + item.Text); - } - } - } - else wiz_split.list_files.Clear(); - - wiz_split.combo_ext.SelectedIndex = 0; - wiz_split.combo_Seconds.SelectedIndex = 2; - wiz_split.ShowDialog(); - if (wiz_split.canceled == true) return; - - split_by_size = wiz_split.combo_size.Text; - - if (wiz_split.by_int_chaps == true || wiz_split.manual_chaps == true) - { - if (!txt_parameters.Text.Contains("[[split_chapters]]")) - { - txt_parameters.Text = "[[split_chapters]]" + " " + txt_parameters.Text; - } - if (wiz_split.manual_chaps == true) - { - list_chaps_m.Clear(); - - Double tstd = 0; - Double tsendd = 0; - - String[] chaps = new String[] { "", "" }; - foreach (String str in wiz_split.txt_chaps.Text.Split(new[] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries)) - { - String ss = str.Substring(4, str.LastIndexOf("-to") - 5); - tstd = TimeSpan.Parse(ss).TotalSeconds; - String to = str.Substring(str.LastIndexOf("-to") + 4, str.Length - (str.LastIndexOf("-to")) - 4); - tsendd = TimeSpan.Parse(to).TotalSeconds; - chaps = new String[] { "-ss " + tstd.ToString().Replace(",", "."), "-to " + tsendd.ToString().Replace(",", ".") }; - list_chaps_m.Add(chaps); - } - //foreach (String[] chap in list_chaps_m) MessageBox.Show(chap[0] + " " + chap[1]); - } - else list_chaps_m.Clear(); - combo_presets.Text = Strings.new_preset; - txt_format.Text = ""; - return; - } - - if (wiz_split.save_preset == false) - { - combo_presets.Text = Strings.new_preset; - txt_parameters.Text = wiz_split.pr1_first_params; - txt_format.Text = "nul"; - } - else - { - combo_presets.SelectedIndex = combo_presets.Items.Count - 1; - combo_presets.Text = wiz_split.txt_preset_name.Text; - txt_parameters.Text = wiz_split.pr1_first_params; - txt_format.Text = "nul"; - btn_save_preset.PerformClick(); - } - - if (wiz_split.start_enc == true) btn_seq.PerformClick(); - } - - private void btn_track_up_Click(object sender, EventArgs e) - { - if (list_tracks.SelectedItems.Count == 1) - { - lvwColumnSorter_Full.Order = SortOrder.None; - var currentIndex = list_tracks.SelectedItems[0].Index; - var item = list_tracks.Items[list_tracks.SelectedIndices[0]]; - if (currentIndex > 0) // && list_tracks.Items[currentIndex - 1].SubItems[5].Text == Strings.queued) - { - list_tracks.Items.RemoveAt(currentIndex); - list_tracks.Items.Insert(currentIndex - 1, item); - } - } - } - - private void btn_track_down_Click(object sender, EventArgs e) - { - if (list_tracks.SelectedItems.Count == 1) - { - lvwColumnSorter_Full.Order = SortOrder.None; - var currentIndex = list_tracks.SelectedItems[0].Index; - var item = list_tracks.Items[list_tracks.SelectedIndices[0]]; - if (currentIndex > -1 && currentIndex < list_tracks.Items.Count - 1) - { - list_tracks.Items.RemoveAt(currentIndex); - list_tracks.Items.Insert(currentIndex + 1, item); - } - } - } - - public void add_paste_folder(string path1) - { - Pg1.Focus(); - if (!File.Exists(Path.Combine(Application.StartupPath, "ffmpeg.exe"))) - { - MessageBox.Show(Strings.no_ffmpeg, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (listView1.Items.Count == 0) - { - list_not_empty = false; - } - else - { - list_not_empty = true; - } - - if (tabControl1.SelectedIndex == 1) - { - change_tab_1 = true; - } - if (tabControl1.SelectedIndex == 2) - { - change_tab_2 = true; - } - if (!Directory.Exists(path1)) - { - MessageBox.Show(Strings.path_not, Strings.path_not2); - return; - } - Form11_2 frm11_2 = new Form11_2(); - Task t2 = Task.Run(() => - { - frm11_2.label1.Text = Strings.reading_path; - frm11_2.ShowDialog(); - }); - Thread.Sleep(100); - List files2 = new List(); - int fl = 0; - foreach (string file in Directory.GetFiles(path1)) - { - if (!File.GetAttributes(file).HasFlag(FileAttributes.Hidden)) - { - files2.Add(file); - fl = fl + 1; - if (frm11_2.abort_validate == true) return; - else - { - try - { - frm11_2.Invoke(new MethodInvoker(delegate - { - frm11_2.label2.Text = fl.ToString() + " " + Strings.files; - })); - } - catch { } - } - } - } - int num_drop = files2.Count(); - - if (add_subfs == true) - { - string[] dirs = Directory.GetDirectories(path1); - - foreach (string ds in dirs) - { - try - { - foreach (string f in Directory.GetFiles(ds, "*.*", System.IO.SearchOption.AllDirectories)) - { - if (!File.GetAttributes(f).HasFlag(FileAttributes.Hidden)) - { - files2.Add(f); - fl = fl + 1; - num_drop++; - if (frm11_2.abort_validate == true) return; - else - { - try - { - frm11_2.Invoke(new MethodInvoker(delegate - { - frm11_2.label2.Text = fl.ToString() + " " + Strings.files; - })); - } - catch { } - } - } - } - } - catch (System.Exception excpt) - { - try - { - } - catch { } - DialogResult a = MessageBox.Show(Strings.error2 + " " + excpt.Message + " " + Strings.contin, Strings.error3, MessageBoxButtons.OKCancel, MessageBoxIcon.Error); - if (a == DialogResult.Cancel) - { - try - { - frm11_2.Invoke(new MethodInvoker(delegate - { - frm11_2.Dispose(); - })); - } - catch { } - - return; - } - try - { - frm11_2.Invoke(new MethodInvoker(delegate - { - frm11_2.TopMost = true; - frm11_2.TopMost = false; - })); - } - catch { } - } - } - } - Thread.Sleep(100); - try - { - frm11_2.Invoke(new MethodInvoker(delegate - { - frm11_2.Dispose(); - })); - } - catch { } - - if (num_drop == 0) - { - DialogResult a = MessageBox.Show(Strings.folder_empty, Strings.information, MessageBoxButtons.OK, MessageBoxIcon.Information); - return; - } - - files_to_add = files2; - canceled_file_adding = false; - btn_cancel_add.Enabled = true; - btn_cancel_add.Visible = true; - btn_cancel_add.Refresh(); - BG_Files.RunWorkerAsync(); - } - - private void btn_add_folders_MouseDown(object sender, MouseEventArgs e) - { - if (e.Button == MouseButtons.Right) - { - show_path_dialog(); - } - } - - private void show_path_dialog() - { - Form19 frm19 = new Form19(); - frm19.subfs = add_subfs; - frm19.ShowDialog(); - if (frm19.canceled == false) - { - add_paste_folder(frm19.textBox1.Text); - } - } - - private void ctm_paste_path_Click(object sender, EventArgs e) - { - show_path_dialog(); - } - - private void ct_move_top_Click(object sender, EventArgs e) - { - if (listView1.SelectedItems.Count == 1 && listView1.SelectedItems[0].SubItems[5].Text == Strings.queued) - { - lvwColumnSorter_Full.Order = SortOrder.None; - var currentIndex = listView1.SelectedItems[0].Index; - var item = listView1.Items[listView1.SelectedIndices[0]]; - if (currentIndex > 0 && listView1.Items[currentIndex - 1].SubItems[5].Text == Strings.queued) - { - listView1.Items.RemoveAt(currentIndex); - listView1.Items.Insert(0, item); - listView1.EnsureVisible(0); - } - } - - else if (listView1.SelectedItems.Count >= 1 && listView1.SelectedItems[0].SubItems[5].Text == Strings.queued) - { - lvwColumnSorter_Full.Order = SortOrder.None; - for (int i = 0; i < listView1.SelectedItems.Count; i++) - { - var currentIndex = listView1.SelectedItems[i].Index; - var item = listView1.Items[listView1.SelectedIndices[i]]; - if (currentIndex > 0 && listView1.Items[currentIndex - 1].SubItems[5].Text == Strings.queued) - { - listView1.Items.RemoveAt(currentIndex); - listView1.Items.Insert(0, item); - } - } - listView1.EnsureVisible(0); - } - else MessageBox.Show(Strings.only_qu); - } - - private void ct_move_bottom_Click(object sender, EventArgs e) - { - if (listView1.SelectedItems.Count == 1 && listView1.SelectedItems[0].SubItems[5].Text == Strings.queued) - { - lvwColumnSorter_Full.Order = SortOrder.None; - var currentIndex = listView1.SelectedItems[0].Index; - var item = listView1.Items[listView1.SelectedIndices[0]]; - if (currentIndex > -1 && currentIndex < listView1.Items.Count - 1) - { - listView1.Items.RemoveAt(currentIndex); - listView1.Items.Insert(listView1.Items.Count, item); - listView1.EnsureVisible(listView1.Items.Count - 1); - } - } - - else if (listView1.SelectedItems.Count > 1 && listView1.SelectedItems[0].SubItems[5].Text == Strings.queued) - { - lvwColumnSorter_Full.Order = SortOrder.None; - for (int i = 0; i < listView1.SelectedItems.Count; i++) - { - int currentIndex = listView1.SelectedItems[i].Index; - ListViewItem item = listView1.Items[currentIndex]; - listView1.Items.RemoveAt(currentIndex); - listView1.Items.Insert(listView1.Items.Count, item); - } - } - - else MessageBox.Show(Strings.only_qu); - } - - private void ct3_up_Click(object sender, EventArgs e) - { - if (list_tracks.SelectedItems.Count == 1) - { - lvwColumnSorter_Full.Order = SortOrder.None; - var currentIndex = list_tracks.SelectedItems[0].Index; - var item = list_tracks.Items[list_tracks.SelectedIndices[0]]; - if (currentIndex > 0) - { - list_tracks.Items.RemoveAt(currentIndex); - list_tracks.Items.Insert(currentIndex - 1, item); - } - } - } - - private void ct3_down_Click(object sender, EventArgs e) - { - if (list_tracks.SelectedItems.Count == 1) - { - lvwColumnSorter_Full.Order = SortOrder.None; - var currentIndex = list_tracks.SelectedItems[0].Index; - var item = list_tracks.Items[list_tracks.SelectedIndices[0]]; - if (currentIndex > -1 && currentIndex < list_tracks.Items.Count - 1) - { - list_tracks.Items.RemoveAt(currentIndex); - list_tracks.Items.Insert(currentIndex + 1, item); - } - } - } - - private void ct_ren_urls_Click(object sender, EventArgs e) - { - Form20 frm20 = new Form20(); - frm20.ShowDialog(); - if (frm20.canceled == false) - { - if (dg1.SelectedCells.Count == 1) - { - for (int i = dg1.SelectedCells[0].RowIndex; i < dg1.RowCount; i++) - { - if (i < 10) dg1.Rows[i].Cells[4].Value = frm20.textBox1.Text + "0" + (i + 1 - dg1.SelectedCells[0].RowIndex).ToString(); - else dg1.Rows[i].Cells[4].Value = frm20.textBox1.Text + (i + 1 - dg1.SelectedCells[0].RowIndex).ToString(); - } - } - if (dg1.SelectedCells.Count > 1) - { - if (dg1.Rows[0].Cells[4].Selected == false && dg1.Rows[0].Cells[5].Selected == false) - { - foreach (DataGridViewCell cell in dg1.SelectedCells) - { - dg1.Rows[cell.RowIndex].Cells[4].Value = frm20.textBox1.Text + cell.RowIndex.ToString(); - } - } - else - { - foreach (DataGridViewCell cell in dg1.SelectedCells) - { - dg1.Rows[cell.RowIndex].Cells[4].Value = frm20.textBox1.Text + (cell.RowIndex + 1).ToString(); - } - } - } - } - } - - private void dg1_CellClick(object sender, DataGridViewCellEventArgs e) - { - try - { - pic_frame.Image = dg_thumbs[dg1.SelectedCells[0].RowIndex]; - if (pic_frame.Image == null) pic_frame.Image = pic_frame.InitialImage; - lbl_a_th.Text = "-"; - lbl_s_th.Text = "-"; - lbl_v_th.Text = "-"; - lbl_gb_th.Text = "-"; - } - catch { } - } - - private void btn_all_yt_Click(object sender, EventArgs e) - { - lbl_est_size.Text = ""; - lbl_bitrate.Text = ""; - - String paramet = ""; - String params1 = ""; - - if (chk_m3u_params.CheckState == CheckState.Unchecked) params1 = ""; - String m3u_output_ext = combo_ext_m3u.SelectedItem.ToString(); - - if (chk_best_yt.Checked) bestv_a = " -f bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio"; - else bestv_a = String.Empty; - - String down_speed = ""; - if (chk_down_limit.Checked == true) down_speed = " -r " + Convert.ToInt32(n_down_speed.Value).ToString() + "M"; - String embed_subs = ""; - if (chk_yout_subs.Checked == true) embed_subs = " --embed-subs --all-subs"; - String auto_subs = ""; - if (chk_auto_subs.Checked == true) - { - auto_subs = " --write-auto-sub --sub-lang en,es,it,pt,de,hi,ar,cn"; - if (chk_yout_subs.Checked == true) embed_subs = " --embed-subs"; - } - String embed_meta = ""; - - if (chk_embed_meta.Checked == true) embed_meta = " --add-metadata"; - String write_subs = ""; - if (chk_save_subtitles.Checked == true) embed_meta = " --write-sub"; - String convert_subs = ""; - if (chk_convert_srt.Checked == true) embed_meta = " --convert-subs=srt"; - String clear_cache = ""; - if (chk_cache_yt.Checked == true) clear_cache = " --rm-cache-dir"; - - paramet = params1 + bestv_a + clear_cache + down_speed + embed_subs + auto_subs + write_subs + convert_subs; - - Form23 frm23 = new Form23(); - frm23.txt_path_main.Text = txt_path_m3u.Text; - if (chk_open_compl.Checked) frm23.open_complete = true; - else frm23.open_complete = false; - - frm23.pre_params = paramet; - frm23.txt_channel.Text = current_channel; - frm23.ShowDialog(); - current_channel = frm23.txt_channel.Text; - } - - private void Timer_display_Tick(object sender, EventArgs e) - { - display_eta = !display_eta; - } - - - - private void btn_update_yt_Click_1(object sender, EventArgs e) - { - lbl_yl_name.Text = Strings.Downloading; - pic_no_yt.Visible = false; - pg_update_yl.Style = ProgressBarStyle.Continuous; - pg_update_yl.Maximum = 100; - pg_update_yl.Value = 0; - - if (btn_update_yt.Text == Strings.cancel) - { - wc_dl.CancelAsync(); - btn_update_yt.Text = Strings.update; - lbl_yl_name.Text = "youtube-dl new"; - txt_up_output.Text = ""; - txt_up_output.Visible = false; - pg_update_yl.Visible = false; - foreach (Control ct in groupBox_m3u.Controls) ct.Enabled = true; - return; - } - - Boolean writable = false; - try - { - FileStream fs = File.Create(Path.Combine(Application.StartupPath, Path.GetRandomFileName()), 1, FileOptions.DeleteOnClose); - writable = true; - } - catch - { - writable = false; - } - foreach (Control ct in groupBox_m3u.Controls) ct.Enabled = false; - btn_update_yt.Enabled = true; txt_up_output.Enabled = true; pic_ok.Enabled = true; - // lbl_yt_v.Enabled = true; - - wc_dl.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_dl_DownloadProgressChanged); - wc_dl.DownloadFileCompleted += new AsyncCompletedEventHandler(wc_dl_DownloadFileCompleted); - - btn_update_yt.Enabled = true; - btn_update_yt.Text = Strings.cancel; - groupBox_yout.Enabled = true; - pg_update_yl.Visible = true; - txt_up_output.Visible = true; - - vc_download = "yt-dlp.exe"; - wc_dl.DownloadFileAsync(new System.Uri(yl_latest_exe), Path.Combine(Path.GetTempPath(), vc_download)); - } - - private void BG_check_ytdl_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) - { - pic_wait_1.Visible = false; - //btn_all_yt.Enabled = true; - - if (t_out_yt == true) - { - lbl_yl_name.Text = Strings.err_yt_u; - pic_ok.Visible = false; - pic_no_yt.Visible = true; - pic_wait_1.Visible = false; - } - } - - private void dg1_KeyDown(object sender, KeyEventArgs e) - { - if (m3u_running == true || m3u_single_running == true) return; - if (dg1.RowCount == 0) - { - if (e.Control && e.KeyCode == Keys.V) - { - if (Clipboard.GetText().ToLower().Contains("youtu.be") == true || Clipboard.GetText().ToLower().Contains("youtube.com") == true) - { - ct_paste_youtube.PerformClick(); - } - else - { - if (Clipboard.GetText().ToLower().Contains("http") == true) ct_paste_m3u.PerformClick(); - } - } - } - } - - private void txt_paste_links_Click(object sender, EventArgs e) - { - dg1.Select(); - txt_paste_links.ForeColor = Color.LightGray; - } - - private void chk_yout_subs_CheckedChanged(object sender, EventArgs e) - { - if (chk_yout_subs.Checked == true) chk_auto_subs.Enabled = true; - else chk_auto_subs.Enabled = false; - } - - private void post_lang() - { - main_menu.Items[0].Text = Strings.file; - main_menu.Items[1].Text = Strings.edit; - main_menu.Items[2].Text = Strings.tools; - main_menu.Items[3].Text = Strings.help; - main_f_1.Text = Strings.clear_list; - main_f_2.Text = Strings.add_file; - main_f_3.Text = Strings.add_folder; - main_f_5.Text = Strings.load_queue_file; - main_f_4.Text = Strings.save_current_queue; - main_f_exit.Text = Strings.exit; - presetsOnlineToolStripMenuItem.Text = Strings.online_pr; - - menu_refresh.Text = Strings.Refresh_list; - menu_invalid.Text = Strings.Remove_invalid_items; - menu_queue.Text = Strings.Reset_list_items_to_queued; - menu_try.Text = Strings.Try_current_preset; - menu_console.Text = Strings.Open_ffmpeg_console; - menu_logs.Text = Strings.Display_last_log; - menu_wizards.Text = Strings.Application_wizard; - - menu_reload_settings.Text = Strings.Reload_settings; - menu_save_settings.Text = Strings.Save_settings; - menu_reset.Text = Strings.Reset_to_factory_defaults; - menu_ffm.Text = Strings.Replace_ffmpeg_executable; - menu_media_info.Text = Strings.Display_multimedia_file_info; - main_menu_streams.Text = Strings.Display_file_streams; - menu_presets.Text = Strings.Multiple_presets_wizard; - menu_two_pass_wizard.Text = Strings.Two_pass_encoding_wizard; - wiz_silence_menu.Text = Strings.Detect_silence_wizard; - menu_img_v.Text = Strings.img_to_v; - menu_extract_images.Text = Strings.Images_extraction_wizard; - menu_split.Text = Strings.AV_split_wizard; - menu_settings.Text = Strings.Settings; - - menu_guide.Text = Strings.User_guide; - menu_news.Text = Strings.Project_news; - menu_forum.Text = Strings.Help_forum; - menu_updates.Text = Strings.Check_for_updates; - menu_about.Text = Strings.About; - - combo_vin_col.Items.Clear(); - combo_vout_color.Items.Clear(); - combo_vin_col.Items.Add(Strings.black); - combo_vin_col.Items.Add(Strings.white); - combo_vin_col.Items.Add("Alpha"); - combo_vout_color.Items.Add(Strings.black); - combo_vout_color.Items.Add(Strings.white); - combo_vout_color.Items.Add("Alpha"); - - listView1.Columns[0].Text = Strings.filename; - listView1.Columns[1].Text = Strings.path; - listView1.Columns[2].Text = Strings.file_type; - listView1.Columns[3].Text = Strings.duration; - listView1.Columns[4].Text = Strings.size; - listView1.Columns[5].Text = Strings.status; - - listView2.Columns[0].Text = Strings.filename; - - listView3.Columns[0].Text = Strings.filename; - listView3.Columns[1].Text = Strings.Subtitle_file; - listView3.Columns[2].Text = Strings.Language; - listView3.Columns[3].Text = Strings.Encoding; - listView3.Columns[4].Text = Strings.Default; - listView3.Columns[5].Text = Strings.status; - - list_tracks.Columns[0].Text = Strings.Stream_file; - list_tracks.Columns[2].Text = Strings.Type; - list_tracks.Columns[3].Text = Strings.Language; - list_tracks.Columns[4].Text = Strings.Default_track; - list_tracks.Columns[5].Text = Strings.Encoding_parameters; - - dg1.Columns[0].HeaderText = Strings.Thumbnail; - dg1.Columns[1].HeaderText = Strings.URL; - dg1.Columns[2].HeaderText = Strings.duration; - dg1.Columns[3].HeaderText = Strings.Capture_time; - dg1.Columns[4].HeaderText = Strings.Output_name; - dg1.Columns[5].HeaderText = Strings.status; - - combo_shut.Items.Clear(); - combo_shut.Items.Add(Strings.Power_off); - combo_shut.Items.Add(Strings.Hibernate); - combo_shut.Items.Add(Strings.Suspend); - combo_shut.Items.Add(Strings.Run_at_the_end); - combo_shut.Items.Add(Strings.Run_on_each_file); - combo_shut.Items.Add(Strings.pause_bat_ac); - - ctm_add_files.Text = Strings.add_file; - ctm_add_folder.Text = Strings.add_folder; - ctm_paste_path.Text = Strings.Paste_write_path; - ct1_paste_youtube.Text = Strings.Paste_YouTube_URL; - ct1_paste_m3u.Text = Strings.Paste_M3u_URL; - cti2.Text = Strings.Play_file; - cti1.Text = Strings.Open_file_path; - cti3.Text = Strings.Open_output_folder; - ctdel.Text = Strings.Remove_file_from_list; - ct2_del.Text = Strings.Remove_file_from_list; - ct_move_top.Text = Strings.Move_item_to_top; - ct_move_bottom.Text = Strings.Move_item_to_bottom; - ctm1_queue.Text = Strings.Reset_item_status_to_queue; - cti4.Text = Strings.Display_multimedia_file_info; - ct1_streams.Text = Strings.Display_file_streams; - ct1_total_frames.Text = Strings.Get_total_seconds_frames; - cti1_cols.Text = Strings.Add_custom_column; - cti_remove_col.Text = Strings.Remove_last_custom_column; - cti4_2.Text = Strings.Show_hide_grid; - cti5.Text = Strings.Set_as_trim_end_time; - cti6.Text = Strings.Stop_task; - ctm1_encode.Text = Strings.encode; - ct1_crop.Text = Strings.crop1; - ct1_params.Text = Strings.set_cust_p; - ct1_rem_param.Text = Strings.rem_cust_p; - ctm1_excl.Text = Strings.excl_list; - - ct2_all.Text = Strings.add_all_str; - ct2_v.Text = Strings.add_vtrack; - ct2_a.Text = Strings.add_atrack; - ct2_s.Text = Strings.add_strack; - combo_def_und_lang.Text = Strings.lang_tracks; - ct2_str.Text = Strings.Display_file_streams; - ct2_save_allstreams.Text = Strings.save_all_str; - - ct3_default.Text = Strings.change_def; - ct3_del.Text = Strings.remove_item; - ct3_up.Text = Strings.move_up; - ct3_down.Text = Strings.move_down; - ct3_default_enc.Text = Strings.set_enc_def; - ct3_encode_default.Text = Strings.reste_enc; - ct3_combo_language.Text = Strings.item_lang; - ct3_save_track.Text = Strings.save_track; - - ct4_browse.Text = Strings.brow_sub; - ct4_del.Text = Strings.remove_item; - ct4_conv.Text = Strings.conv_utf8; - Combo_single_subs_lang.Text = Strings.sub_lang; - - ct3_ready.Text = Strings.URL + " " + Strings.ready; - ct_paste_youtube.Text = Strings.Paste_YouTube_URL; - ct_paste_m3u.Text = Strings.Paste_M3u_URL; - ct_remove_url.Text = Strings.rem_row; - ct_del_m3u.Text = Strings.rem_blanks; - ct_validate_url.Text = Strings.rem_err_rows; - ct_ren_urls.Text = Strings.ren_out_fn; - ct_show_urls.Text = Strings.dis_url_streams; - ct_play_vlc.Text = Strings.play_vlc; - ctm_stop_url.Text = Strings.Stop_task; - txt_help_subs.Text = Strings.subs_help; - - ct_path_vf.Text = Strings.path_i_add; - ct_path_input.Text = Strings.path_iparam; - - combo_shut.SelectedIndex = 0; - Combo_def_sub_mux.Items.Clear(); - Combo_def_sub_mux.Items.Add(Strings.yes); - Combo_def_sub_mux.Items.Add(Strings.no); - Create_Tooltips(); - btn_update.Text = Strings.version + " " + Application.ProductVersion; - } - - private void remember_tab() - { - //Remember last tab - - String f_remember = String.Empty; - if (is_portable == false) - { - f_remember = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_remember.ini"; - } - else - { - f_remember = port_path + "ff_remember_portable.ini"; - } - - if (File.Exists(f_remember)) - { - remember_last_tab = true; - tabControl1.Invoke(new MethodInvoker(delegate - { - tabControl1.SelectedIndex = 0; - tabControl1.SelectedIndex = Convert.ToInt16(File.ReadAllText(f_remember)); - })); - } - else - { - remember_last_tab = false; - } - } - - private void chk_autor_Click(object sender, EventArgs e) - { - Pg1.Focus(); - - String f_autorun = String.Empty; - String f_multi = String.Empty; - if (is_portable == false) - { - f_autorun = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_autorun.ini"; - f_multi = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_autorun_m.ini"; - } - else - { - f_autorun = port_path + "ff_autorun_portable.ini"; - f_autorun = port_path + "ff_autorun_m_portable.ini"; - } - if (start_seq == false) - { - start_seq = !start_seq; - File.WriteAllText(f_autorun, ""); - chk_autor.ImageIndex = 1; - if (File.Exists(f_multi)) start_multi = true; - else start_multi = false; - } - else - { - start_seq = !start_seq; - chk_autor.ImageIndex = 0; - start_seq = false; - start_multi = false; - try - { - File.Delete(f_autorun); - File.Delete(f_multi); - } - catch - { - } - } - } - - private void chk_autor_MouseHover(object sender, EventArgs e) - { - toolTip01.AutoPopDelay = 5000; - toolTip01.InitialDelay = 750; - toolTip01.ReshowDelay = 500; - toolTip01.ShowAlways = true; - if (start_seq) toolTip01.SetToolTip(this.chk_autor, Strings.autorun_en); - else - { - toolTip01.SetToolTip(this.chk_autor, Strings.autorun_dis); - } - } - - private void chk_autor_MouseLeave(object sender, EventArgs e) - { - toolTip01.SetToolTip(this.chk_autor, String.Empty); - } - - private void menu_img_v_Click(object sender, EventArgs e) - { - AeroWizard7 wiz_img = new AeroWizard7(); - wiz_img.pr1_first_params = ""; - wiz_img.pr1_pre_params = ""; - wiz_img.StartPosition = FormStartPosition.CenterParent; - wiz_img.list_count = listView1.Items.Count; - wiz_img.ShowDialog(); - if (wiz_img.canceled == true) return; - - if (wiz_img.radio_1_v.Checked) - { - combo_presets.Text = Strings.new_preset; - txt_parameters.Text = wiz_img.pr1_first_params; - txt_pre_input.Text = wiz_img.pr1_pre_params; - txt_format.Text = wiz_img.pr1_out_format; - images_from_wiz = true; - img_dur_wiz = wiz_img.pr1_img_dur; - if (wiz_img.start_enc == true) btn_seq.PerformClick(); - } - if (wiz_img.radio_multi_v.Checked) - { - combo_presets.Text = Strings.new_preset; - txt_parameters.Text = wiz_img.pr1_first_params; - txt_format.Text = wiz_img.pr1_out_format; - images_time = wiz_img.pr1_imgs_time; - images_from_wiz = true; - img_aud_from_wiz = wiz_img.pr1_img_aud; - img_dur_wiz = wiz_img.pr1_img_dur; - btn_concat.PerformClick(); - } - - if (wiz_img.radio_img_aud.Checked) - { - combo_presets.Text = Strings.new_preset; - txt_parameters.Text = wiz_img.pr1_first_params; - txt_pre_input.Text = wiz_img.pr1_pre_params; - txt_format.Text = wiz_img.pr1_out_format; - images_time = wiz_img.pr1_imgs_time; - images_from_wiz = false; - img_aud_from_wiz = wiz_img.pr1_img_aud; - img_dur_wiz = wiz_img.pr1_img_dur; - if (wiz_img.start_enc == true) btn_seq.PerformClick(); - } - } - - private void btn_load_config_Click(object sender, EventArgs e) - { - Pg1.Focus(); - Boolean ver = false; - ss_time_input.Text = "0:00:00.000"; - - String f_fix_pre = String.Empty; - if (is_portable == false) - { - f_fix_pre = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_fix_pre.ini"; - } - else - { - f_fix_pre = port_path + "ff_fix_pre_portable.ini"; - } - if (File.Exists(f_fix_pre)) - { - fix_pre = true; - txt_pre_input.Text = File.ReadAllText(f_fix_pre); - } - else - { - fix_pre = false; - txt_pre_input.Text = ""; - txt_pre_input.BackColor = txt_parameters.BackColor; - } - - txt_suffix.Text = "_FFB"; - - combo_presets.Items.Clear(); - combo_presets.Items.Add(Strings.default_param); - String path = String.Empty; - String path_pr, path_pre, path_pr_pre = String.Empty; - if (is_portable == false) - { - path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.ini"; - path_pr = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_presets.ini"; - path_pr_pre = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_presets_pre.ini"; - path_pre = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch_pre.ini"; - } - else - { - path = port_path + "ff_batch_portable.ini"; - path_pr = port_path + "ff_presets_portable.ini"; - path_pr_pre = port_path + "ff_presets_pre_portable.ini"; - path_pre = port_path + "ff_batch_portable_pre.ini"; - } - - Boolean f_presets_exist = false; - int linea = 0; - if (File.Exists(path_pr)) f_presets_exist = true; - - combo_presets.SelectedIndex = combo_presets.FindString(Strings.default_param); - - foreach (string line in File.ReadLines(path)) - { - linea = linea + 1; - if (linea == 1) - { - this.InvokeEx(f => f.txt_parameters.Text = line); - continue; - } - - if (linea == 2) - { - this.InvokeEx(f => f.txt_format.Text = line); - continue; - } - - if (line == "Yes") - - { - this.InvokeEx(f => f.chk_open_compl.CheckState = CheckState.Checked); - continue; - } - - if (line == "No") - { - this.InvokeEx(f => f.chk_open_compl.CheckState = CheckState.Unchecked); - continue; - } - - //if (linea == 4) - //{ - if (line == "Vn") - { - this.InvokeEx(f => f.chk_suffix.CheckState = CheckState.Unchecked); - continue; - } - if (line.Length > 1 && line.Substring(0, 2) == "Vs") - { - this.InvokeEx(f => f.chk_suffix.CheckState = CheckState.Checked); - this.InvokeEx(f => f.txt_suffix.Text = line.Substring(3, line.Length - 3)); - continue; - } - //} - - if (line == "grid_yes") - { - this.InvokeEx(f => f.listView1.GridLines = true); - this.InvokeEx(f => f.listView2.GridLines = true); - this.InvokeEx(f => f.listView3.GridLines = true); - continue; - } - if (line == "grid_no") - { - this.InvokeEx(f => f.listView1.GridLines = false); - this.InvokeEx(f => f.listView2.GridLines = false); - this.InvokeEx(f => f.listView3.GridLines = false); - continue; - } - - if (line == "keep_yes") - { - this.InvokeEx(f => f.chk_recreate.CheckState = CheckState.Checked); - continue; - } - if (line == "keep_no") - { - this.InvokeEx(f => f.chk_recreate.CheckState = CheckState.Unchecked); - continue; - } - - if (line == "subf_yes") - { - this.InvokeEx(f => f.chk_subfolders.CheckState = CheckState.Checked); - add_subfs = true; - continue; - } - if (line == "subf_no") - { - this.InvokeEx(f => f.chk_subfolders.CheckState = CheckState.Unchecked); - add_subfs = false; - continue; - } - if (f_presets_exist == false) - { - if (line.Contains("Version") == true) - { - this.InvokeEx(f => f.txt_config_ver.Text = line.Replace("Version ", String.Empty)); - continue; - } - - if (line.Contains("PR: ")) - { - this.InvokeEx(f => f.combo_presets.Items.Add(line.Substring(4, line.LastIndexOf(" & ") - 4))); - continue; - } - } - } - if (f_presets_exist == true) - { - foreach (string line in File.ReadLines(path_pr)) - { - if (line.Length > 8) - { - if (line.Substring(0, 7).ToLower() == "version") - { - txt_config_ver.Text = line.Substring(8, line.Length - 8); - continue; - } - } - - if (line.Contains("PR: ")) - { - this.InvokeEx(f => f.combo_presets.Items.Add(line.Substring(4, line.LastIndexOf(" & ") - 4))); - } - } - } - if (File.Exists(path_pr_pre)) - { - foreach (string line in File.ReadLines(path_pr_pre)) - { - if (line.Contains(combo_presets.Text)) txt_pre_input.Text = line.Substring(line.LastIndexOf("&&&"), line.Length - line.LastIndexOf("&&&)")); - } - } - - btn_save_config.ImageKey = "Save_settings_39.png"; - } - - private void ct2_save_allstreams_Click(object sender, EventArgs e) - { - canceled_file_adding = false; - btn_cancel_add.Enabled = true; - //btn_cancel_add.Visible = true; - //btn_cancel_add.Refresh(); - pg_adding.Visible = true; - LB_Wait.Visible = true; - LB_Wait.Text = Strings.adding + " " + listView2.SelectedItems.Count + " " + Strings.files; - LB_Wait.Refresh(); - txt_adding_p.Text = ""; - pg_adding.Maximum = listView2.SelectedItems.Count; - - foreach (ListViewItem item in listView2.SelectedItems) - { - list_tracks.Items.Clear(); - foreach (ListViewItem item2 in listView2.Items) item2.Selected = false; - listView2.Items[item.Index].Selected = true; - ct2_all.PerformClick(); - - foreach (ListViewItem item2 in list_tracks.Items) - { - item2.Selected = true; - } - - if (item.Index <= pg_adding.Maximum) - { - pg_adding.Value = item.Index; - txt_adding_p.Text = (item.Index * 100 / files_to_add.Count).ToString() + "%"; - TaskbarProgress.SetValue(this.Handle, item.Index * 100 / listView2.SelectedItems.Count, 100); - } - else - { - pg_adding.Value = pg_adding.Maximum; - txt_adding_p.Text = "100%"; - } - - extract_streams_job(); - } - - LB_Wait.Text = ""; - listView2.EndUpdate(); - //btn_cancel_add.Visible = false; - pg_adding.Visible = false; - txt_adding_p.Visible = false; - lbl_dur_list.Refresh(); - this.Cursor = Cursors.Arrow; - - list_tracks.Items.Clear(); - frm_mux_jobs.ShowDialog(); - if (frm_mux_jobs.view_logs == true) - { - show_mux_logs(); - return; - } - if (frm_mux_jobs.start_jobs == true) start_mux_jobs(); - } - - private void listView1_SelectedIndexChanged(object sender, EventArgs e) - { - if (listView1.Items.Count > 1 && listView1.SelectedItems.Count != 1) - { - if (Settings.Default.dark_mode == false) pic_frame.Image = pic_reading.ErrorImage; - else pic_frame.Image = pic_dark.Image; - lbl_s_th.Text = "-"; - lbl_a_th.Text = "-"; - lbl_v_th.Text = "-"; - lbl_gb_th.Text = "-"; - return; - } - if (listView1.SelectedIndices.Count == 0 && listView1.Items.Count == 1) return; - - current_fr = 4000; - - Process proc_img = new System.Diagnostics.Process(); - - if (listView1.SelectedIndices.Count == 1) - { - //Attempt to extract frame as image - String dur_lv1 = listView1.SelectedItems[0].SubItems[3].Text; - String lv1_item = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - lbl_s_th.Text = "-"; lbl_s_th.Refresh(); - lbl_v_th.Text = "-"; lbl_v_th.Refresh(); - lbl_a_th.Text = "-"; lbl_a_th.Refresh(); - lbl_gb_th.Text = "-"; lbl_gb_th.Refresh(); - if (Settings.Default.dark_mode == false) pic_frame.Image = pic_reading.Image; - else pic_frame.Image = pic_reading.InitialImage; - - if (!File.Exists(lv1_item)) return; - - if (!Directory.Exists(Path.Combine(Path.GetTempPath(), "FFBatch_Test"))) Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "FFBatch_Test")); - - String time_frame = ""; - Double t_to = (double)current_fr; - TimeSpan t1 = TimeSpan.FromMilliseconds((t_to)); - String tx_1 = string.Format("{0:D2}:{1:D2}:{2:D2}.{3:D3}", - (int)t1.TotalHours, - t1.Minutes, - t1.Seconds, - t1.Milliseconds); - time_frame = tx_1; - String repl_frm = time_frame.Replace(",", "").Replace(".", "").Replace(":", ""); - - String ffm_img = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - String itfull = ""; - - if (tabControl1.SelectedIndex == 0 && listView1.SelectedItems.Count == 1) itfull = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - if (tabControl1.SelectedIndex == 1 && listView2.SelectedItems.Count == 1) itfull = listView2.SelectedItems[0].Text; - - String file_img = Path.GetFullPath(lv1_item); - String fullPath_img = file_img; - String AppParam_img = ""; - String config_info = Path.Combine(Path.GetTempPath(), "FFBatch_Test") + "\\" + "mediaconfig.txt"; - String rel_path = Path.GetDirectoryName(file_img).Replace(":", "_").Replace("\\", "_") + Path.GetExtension(file_img).Replace(".", "_"); - String target_img = Path.GetTempPath() + "FFBatch_Test" + "\\" + Path.GetFileNameWithoutExtension(file_img) + "_480_" + rel_path + "_" + current_fr + "." + "jpg"; - String target_info = Path.GetTempPath() + "FFBatch_Test" + "\\" + Path.GetFileNameWithoutExtension(file_img) + rel_path + "_" + "." + "txt"; - - String m_info_path = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - - Task t = Task.Run(() => - { - List lines_ouput = new List(); - - Process get_frames = new Process(); - - this.Invoke(new MethodInvoker(delegate - { - try - { - if (!File.Exists(target_info)) - { - String[] config_lines = new String[3]; - config_lines[0] = "Video;%Format%" + "\\n" + "%Width%" + "\\n" + "%Height%" + "\\n" + "%DisplayAspectRatio/String%" + "\\n"; - config_lines[1] = "Audio;%Format%" + "\\n"; - config_lines[2] = "General;%OverallBitRate/String%" + "\\n"; - - File.WriteAllLines(config_info, config_lines); - get_frames.StartInfo.FileName = m_info_path; - - String ffprobe_frames = " " + "--Inform=file://" + config_info; - get_frames.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + itfull + '\u0022'; - get_frames.StartInfo.RedirectStandardOutput = true; - get_frames.StartInfo.UseShellExecute = false; - get_frames.StartInfo.CreateNoWindow = true; - get_frames.EnableRaisingEvents = true; - - get_frames.Start(); - - while (!get_frames.StandardOutput.EndOfStream) - { - lines_ouput.Add(get_frames.StandardOutput.ReadLine()); - } - - get_frames.WaitForExit(); - if (get_frames.ExitCode == 0) - { - if (lines_ouput[1].ToLower().Contains("visual")) lines_ouput[1] = lines_ouput[1].Replace("Visual", ""); - try { lbl_v_th.Text = lines_ouput[1].Replace("Video", "") + " " + lines_ouput[4]; } catch { } - try { lbl_s_th.Text = lines_ouput[2] + "x" + lines_ouput[3]; } catch { } - - try { lbl_a_th.Text = lines_ouput[5].ToLower(); } - catch - { - lbl_a_th.Text = lines_ouput[1].ToLower(); - lbl_s_th.Text = "-"; - lbl_v_th.Text = "-"; - lbl_gb_th.Text = lines_ouput[0]; - } - String ext_a0 = Path.GetExtension(file_img); - - if (ext_a0 == ".flac" || ext_a0 == ".mp3" || ext_a0 == ".oga" || ext_a0 == ".ape" || ext_a0 == ".wav" || ext_a0 == ".aac" || ext_a0 == ".ac3" || ext_a0 == ".mpa" || ext_a0 == ".mka" || ext_a0 == ".wave" || ext_a0 == ".mp1" || ext_a0 == ".dsd" || ext_a0 == ".wma" || ext_a0 == ".amr" || ext_a0 == ".opus" || ext_a0 == ".eac3" || ext_a0 == ".alac" || ext_a0 == ".m4a") - { - lbl_v_th.Text = ext_a0.Replace(".", ""); - } - - try - { - if (lines_ouput[0].Length > 0) - { - System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentUICulture; - String sep_th = ci.NumberFormat.CurrencyGroupSeparator; - if (lines_ouput[0].Substring(1, 1) == " ") - { - lines_ouput[0] = lines_ouput[0].Substring(0, 1) + sep_th + lines_ouput[0].Substring(2, lines_ouput[0].Length - 2); - } - lbl_gb_th.Text = lines_ouput[0]; - } - } - catch { lbl_gb_th.Text = "-"; } - } - else - { - lbl_s_th.Text = "-"; - lbl_v_th.Text = "-"; - lbl_a_th.Text = "-"; - lbl_gb_th.Text = "-"; - } - - String info = lbl_v_th.Text + Environment.NewLine + lbl_a_th.Text + Environment.NewLine + lbl_s_th.Text + Environment.NewLine + lbl_gb_th.Text; - File.WriteAllText(target_info, info); - } - else - { - String[] lines = new String[4]; - int l = 0; - foreach (String line in File.ReadLines(target_info)) - { - lines[l] = line; - l++; - } - - lbl_v_th.Text = lines[0]; - lbl_a_th.Text = lines[1]; - lbl_s_th.Text = lines[2]; - lbl_gb_th.Text = lines[3]; - } - } - catch { } - })); - - //End Get Info - - if (File.Exists(target_img)) - { - Image img_tmp1; - using (var bmpTemp = new Bitmap(target_img)) - { - img_tmp1 = new Bitmap(bmpTemp); - - pic_frame.Invoke(new MethodInvoker(delegate - { - try - { - pic_frame.Image = img_tmp1; - panel_thumb.Refresh(); - } - catch - { - if (Settings.Default.dark_mode == false) pic_frame.Image = pic_reading.Image; - else pic_frame.Image = pic_reading.InitialImage; - } - })); - } - return; - } - - AppParam_img = " -ss " + time_frame + " -i " + "" + '\u0022' + file_img + '\u0022' + " -an -sn -qscale:v 2" + " -vf scale=480:-1" + " -f image2 -y " + '\u0022' + target_img + '\u0022'; - - String ext_a = Path.GetExtension(file_img); - if (ext_a == ".flac" || ext_a == ".mp3") AppParam_img = " -i " + "" + '\u0022' + file_img + '\u0022' + " -f image2 -y " + '\u0022' + target_img + '\u0022'; - - proc_img.StartInfo.RedirectStandardOutput = false; - proc_img.StartInfo.RedirectStandardError = false; - proc_img.StartInfo.UseShellExecute = false; - proc_img.StartInfo.CreateNoWindow = true; - proc_img.EnableRaisingEvents = false; - proc_img.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - - proc_img.StartInfo.FileName = ffm_img; - proc_img.StartInfo.Arguments = AppParam_img; - - if (Settings.Default.dark_mode == false) pic_frame.Image = pic_reading.Image; - else pic_frame.Image = pic_reading.InitialImage; - - proc_img.Start(); - proc_img.WaitForExit(5000); - - if (File.Exists(target_img)) - { - Image img_tmp; - using (var bmpTemp = new Bitmap(target_img)) - { - img_tmp = new Bitmap(bmpTemp); - pic_frame.Invoke(new MethodInvoker(delegate - { - try - { - pic_frame.Image = img_tmp; - panel_thumb.Refresh(); - } - catch - { - if (Settings.Default.dark_mode == false) pic_frame.Image = pic_reading.Image; - else pic_frame.Image = pic_reading.InitialImage; - panel_thumb.Refresh(); - } - })); - } - } - else - { - String ext_a0 = Path.GetExtension(file_img); - - if (ext_a0 == ".flac" || ext_a0 == ".mp3" || ext_a0 == ".oga" || ext_a0 == ".ape" || ext_a0 == ".wav" || ext_a0 == ".aac" || ext_a0 == ".ac3" || ext_a0 == ".mpa" || ext_a0 == ".mka" || ext_a0 == ".wave" || ext_a0 == ".mp1" || ext_a0 == ".dsd" || ext_a0 == ".wma" || ext_a0 == ".amr" || ext_a0 == ".opus" || ext_a0 == ".eac3" || ext_a0 == ".alac" || ext_a0 == ".m4a") - { - pic_frame.Invoke(new MethodInvoker(delegate - { - try - { - if (lbl_a_th.Text != ext_a0.Replace(".", "")) lbl_v_th.Text = ext_a0.Replace(".", ""); - else lbl_v_th.Text = "Audio"; - PictureBox pic2 = new PictureBox(); - pic2.Image = pic_frame.ErrorImage; - pic_frame.Image = pic2.Image; - } - catch - { - pic_frame.Invoke(new MethodInvoker(delegate - { - if (Settings.Default.dark_mode == false) pic_frame.Image = pic_reading.Image; - else pic_frame.Image = pic_reading.InitialImage; - })); - } - })); - } - - if (ext_a0 == ".jpg" || ext_a0 == ".jpeg" || ext_a0 == ".png" || ext_a0 == ".gif" || ext_a0 == ".tif" || ext_a0 == ".bmp" || ext_a0 == ".ico" || ext_a0 == ".bmp") - { - pic_frame.Invoke(new MethodInvoker(delegate - { - try - { - PictureBox pic2 = new PictureBox(); - pic2.Image = new Bitmap(file_img); - pic_frame.Image = pic2.Image; - } - catch - { - pic_frame.Invoke(new MethodInvoker(delegate - { - if (Settings.Default.dark_mode == false) pic_frame.Image = pic_reading.Image; - else pic_frame.Image = pic_reading.InitialImage; - })); - } - })); - - get_frames.StartInfo.Arguments = "--Inform=Image;%Width%x%Height%" + " " + '\u0022' + itfull + '\u0022'; - get_frames.StartInfo.FileName = m_info_path; - - get_frames.StartInfo.RedirectStandardOutput = true; - get_frames.StartInfo.UseShellExecute = false; - get_frames.StartInfo.CreateNoWindow = true; - get_frames.EnableRaisingEvents = false; - get_frames.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - - get_frames.Start(); - String outp = "-"; - while (!get_frames.StandardOutput.EndOfStream) - { - outp = get_frames.StandardOutput.ReadLine(); - } - get_frames.WaitForExit(); - pic_frame.Invoke(new MethodInvoker(delegate - { - lbl_v_th.Text = "Image"; - lbl_s_th.Text = outp; - lbl_a_th.Text = ext_a0.Replace(".", ""); - })); - } - } - }); - } - } - - private void pic_frame_Click(object sender, EventArgs e) - { - if (tabControl1.SelectedIndex == 2) return; - show_str_thumb(); - } - - private void listView2_SelectedIndexChanged(object sender, EventArgs e) - { - if (listView2.Items.Count > 1 && listView2.SelectedItems.Count != 1) - { - pic_frame.Image = pic_frame.InitialImage; - lbl_s_th.Text = "-"; - lbl_a_th.Text = "-"; - lbl_v_th.Text = "-"; - return; - } - if (listView2.SelectedIndices.Count == 0 && listView2.Items.Count == 1) return; - - current_fr = 4000; - - Process proc_img = new System.Diagnostics.Process(); - - if (listView2.SelectedIndices.Count == 1) - { - //Attempt to extract frame as image - String dur_lv1 = listView1.Items[listView2.SelectedItems[0].Index].SubItems[3].Text; - String lv1_item = listView2.SelectedItems[0].Text; - lbl_s_th.Text = "-"; lbl_s_th.Refresh(); - lbl_v_th.Text = "-"; lbl_v_th.Refresh(); - lbl_a_th.Text = "-"; lbl_a_th.Refresh(); - pic_frame.Image = pic_frame.InitialImage; - lbl_gb_th.Text = "-"; lbl_gb_th.Refresh(); - - if (!File.Exists(lv1_item)) return; - - if (!Directory.Exists(Path.Combine(Path.GetTempPath(), "FFBatch_Test"))) Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "FFBatch_Test")); - - String time_frame = ""; - Double t_to = (double)current_fr; - TimeSpan t1 = TimeSpan.FromMilliseconds((t_to)); - String tx_1 = string.Format("{0:D2}:{1:D2}:{2:D2}.{3:D3}", - (int)t1.TotalHours, - t1.Minutes, - t1.Seconds, - t1.Milliseconds); - time_frame = tx_1; - String repl_frm = time_frame.Replace(",", "").Replace(".", "").Replace(":", ""); - - String ffm_img = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - String itfull = ""; - - if (tabControl1.SelectedIndex == 0 && listView1.SelectedItems.Count == 1) itfull = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - if (tabControl1.SelectedIndex == 1 && listView2.SelectedItems.Count == 1) itfull = listView2.SelectedItems[0].Text; - - String file_img = Path.GetFullPath(lv1_item); - String fullPath_img = file_img; - String AppParam_img = ""; - String config_info = Path.Combine(Path.GetTempPath(), "FFBatch_Test") + "\\" + "mediaconfig.txt"; - String rel_path = Path.GetDirectoryName(file_img).Replace(":", "_").Replace("\\", "_") + Path.GetExtension(file_img).Replace(".", "_"); - String target_img = Path.GetTempPath() + "FFBatch_Test" + "\\" + Path.GetFileNameWithoutExtension(file_img) + "_480_" + rel_path + "_" + current_fr + "." + "jpg"; - String target_info = Path.GetTempPath() + "FFBatch_Test" + "\\" + Path.GetFileNameWithoutExtension(file_img) + rel_path + "_" + "." + "txt"; - - String m_info_path = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - - Task t = Task.Run(() => - { - List lines_ouput = new List(); - - Process get_frames = new Process(); - - this.Invoke(new MethodInvoker(delegate - { - try - { - if (!File.Exists(target_info)) - { - String[] config_lines = new String[3]; - config_lines[0] = "Video;%Format%" + "\\n" + "%Width%" + "\\n" + "%Height%" + "\\n" + "%DisplayAspectRatio/String%" + "\\n"; - config_lines[1] = "Audio;%Format%" + "\\n"; - config_lines[2] = "General;%OverallBitRate/String%" + "\\n"; - - File.WriteAllLines(config_info, config_lines); - get_frames.StartInfo.FileName = m_info_path; - - String ffprobe_frames = " " + "--Inform=file://" + config_info; - get_frames.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + itfull + '\u0022'; - get_frames.StartInfo.RedirectStandardOutput = true; - get_frames.StartInfo.UseShellExecute = false; - get_frames.StartInfo.CreateNoWindow = true; - get_frames.EnableRaisingEvents = true; - - get_frames.Start(); - - while (!get_frames.StandardOutput.EndOfStream) - { - lines_ouput.Add(get_frames.StandardOutput.ReadLine()); - } - //foreach (String str in lines_ouput) MessageBox.Show(str); - - get_frames.WaitForExit(); - if (get_frames.ExitCode == 0) - { - if (lines_ouput[1].ToLower().Contains("visual")) lines_ouput[1] = lines_ouput[1].Replace("Visual", ""); - try { lbl_v_th.Text = lines_ouput[1].Replace("Video", "") + " " + lines_ouput[4]; } catch { } - try { lbl_s_th.Text = lines_ouput[2] + "x" + lines_ouput[3]; } catch { } - - try { lbl_a_th.Text = lines_ouput[5].ToLower(); } - catch - { - lbl_a_th.Text = lines_ouput[1].ToLower(); - lbl_s_th.Text = "-"; - lbl_v_th.Text = "-"; - lbl_gb_th.Text = lines_ouput[0]; - } - String ext_a0 = Path.GetExtension(file_img); - - if (ext_a0 == ".flac" || ext_a0 == ".mp3" || ext_a0 == ".oga" || ext_a0 == ".ape" || ext_a0 == ".wav" || ext_a0 == ".aac" || ext_a0 == ".ac3" || ext_a0 == ".mpa" || ext_a0 == ".mka" || ext_a0 == ".wave" || ext_a0 == ".mp1" || ext_a0 == ".dsd" || ext_a0 == ".wma" || ext_a0 == ".amr" || ext_a0 == ".opus" || ext_a0 == ".eac3" || ext_a0 == ".alac" || ext_a0 == ".m4a") - { - lbl_v_th.Text = ext_a0.Replace(".", ""); - } - - try - { - if (lines_ouput[0].Length > 0) - { - System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentUICulture; - String sep_th = ci.NumberFormat.CurrencyGroupSeparator; - if (lines_ouput[0].Substring(1, 1) == " ") - { - lines_ouput[0] = lines_ouput[0].Substring(0, 1) + sep_th + lines_ouput[0].Substring(2, lines_ouput[0].Length - 2); - } - lbl_gb_th.Text = lines_ouput[0]; - } - } - catch { lbl_gb_th.Text = "-"; } - } - else - { - lbl_s_th.Text = "-"; - lbl_v_th.Text = "-"; - lbl_a_th.Text = "-"; - lbl_gb_th.Text = "-"; - } - - String info = lbl_v_th.Text + Environment.NewLine + lbl_a_th.Text + Environment.NewLine + lbl_s_th.Text + Environment.NewLine + lbl_gb_th.Text; - File.WriteAllText(target_info, info); - } - else - { - String[] lines = new String[4]; - int l = 0; - foreach (String line in File.ReadLines(target_info)) - { - lines[l] = line; - l++; - } - - lbl_v_th.Text = lines[0]; - lbl_a_th.Text = lines[1]; - lbl_s_th.Text = lines[2]; - lbl_gb_th.Text = lines[3]; - } - } - catch { } - })); - - //End Get Info - - if (File.Exists(target_img)) - { - Image img_tmp1; - using (var bmpTemp = new Bitmap(target_img)) - { - img_tmp1 = new Bitmap(bmpTemp); - - pic_frame.Invoke(new MethodInvoker(delegate - { - try - { - pic_frame.Image = img_tmp1; - panel_thumb.Refresh(); - } - catch - { - pic_frame.Image = pic_frame.InitialImage; - } - })); - } - return; - } - - AppParam_img = " -ss " + time_frame + " -i " + "" + '\u0022' + file_img + '\u0022' + " -qscale:v 0" + " -vf scale=480:-1" + " -f image2 -y " + '\u0022' + target_img + '\u0022'; - - String ext_a = Path.GetExtension(file_img); - if (ext_a == ".flac" || ext_a == ".mp3") AppParam_img = " -i " + "" + '\u0022' + file_img + '\u0022' + " -f image2 -y " + '\u0022' + target_img + '\u0022'; - - proc_img.StartInfo.RedirectStandardOutput = false; - proc_img.StartInfo.RedirectStandardError = false; - proc_img.StartInfo.UseShellExecute = false; - proc_img.StartInfo.CreateNoWindow = true; - proc_img.EnableRaisingEvents = false; - proc_img.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - - proc_img.StartInfo.FileName = ffm_img; - proc_img.StartInfo.Arguments = AppParam_img; - - if (Settings.Default.dark_mode == false) pic_frame.Image = pic_reading.Image; - else pic_frame.Image = pic_reading.InitialImage; - - proc_img.Start(); - proc_img.WaitForExit(5000); - - if (File.Exists(target_img)) - { - Image img_tmp; - using (var bmpTemp = new Bitmap(target_img)) - { - img_tmp = new Bitmap(bmpTemp); - pic_frame.Invoke(new MethodInvoker(delegate - { - try - { - pic_frame.Image = img_tmp; - panel_thumb.Refresh(); - } - catch - { - pic_frame.Image = pic_frame.InitialImage; - panel_thumb.Refresh(); - } - })); - } - } - else - { - String ext_a0 = Path.GetExtension(file_img); - - if (ext_a0 == ".flac" || ext_a0 == ".mp3" || ext_a0 == ".oga" || ext_a0 == ".ape" || ext_a0 == ".wav" || ext_a0 == ".aac" || ext_a0 == ".ac3" || ext_a0 == ".mpa" || ext_a0 == ".mka" || ext_a0 == ".wave" || ext_a0 == ".mp1" || ext_a0 == ".dsd" || ext_a0 == ".wma" || ext_a0 == ".amr" || ext_a0 == ".opus" || ext_a0 == ".eac3" || ext_a0 == ".alac" || ext_a0 == ".m4a") - { - pic_frame.Invoke(new MethodInvoker(delegate - { - try - { - if (lbl_a_th.Text != ext_a0.Replace(".", "")) lbl_v_th.Text = ext_a0.Replace(".", ""); - else lbl_v_th.Text = "Audio"; - PictureBox pic2 = new PictureBox(); - pic2.Image = pic_frame.ErrorImage; - pic_frame.Image = pic2.Image; - } - catch - { - pic_frame.Invoke(new MethodInvoker(delegate - { - pic_frame.Image = pic_frame.InitialImage; - })); - } - })); - } - - if (ext_a0 == ".jpg" || ext_a0 == ".jpeg" || ext_a0 == ".png" || ext_a0 == ".gif" || ext_a0 == ".tif" || ext_a0 == ".bmp" || ext_a0 == ".ico" || ext_a0 == ".bmp") - { - pic_frame.Invoke(new MethodInvoker(delegate - { - try - { - PictureBox pic2 = new PictureBox(); - pic2.Image = new Bitmap(file_img); - pic_frame.Image = pic2.Image; - } - catch - { - pic_frame.Invoke(new MethodInvoker(delegate - { - pic_frame.Image = pic_frame.InitialImage; - })); - } - })); - - get_frames.StartInfo.Arguments = "--Inform=Image;%Width%x%Height%" + " " + '\u0022' + itfull + '\u0022'; - get_frames.StartInfo.FileName = m_info_path; - - get_frames.StartInfo.RedirectStandardOutput = true; - get_frames.StartInfo.UseShellExecute = false; - get_frames.StartInfo.CreateNoWindow = true; - get_frames.EnableRaisingEvents = false; - get_frames.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - - get_frames.Start(); - String outp = "-"; - while (!get_frames.StandardOutput.EndOfStream) - { - outp = get_frames.StandardOutput.ReadLine(); - } - get_frames.WaitForExit(); - pic_frame.Invoke(new MethodInvoker(delegate - { - lbl_v_th.Text = "Image"; - lbl_s_th.Text = outp; - lbl_a_th.Text = ext_a0.Replace(".", ""); - })); - } - } - }); - } - } - - private void main_menu_streams_Click(object sender, EventArgs e) - { - show_str_thumb(); - } - - private void show_str_thumb() - { - Form5 frm5 = new Form5(); - if (tabControl1.SelectedIndex == 0) - { - if (listView1.Items.Count == 0) - { - MessageBox.Show(Strings.no_item_sel, Strings.no_file, MessageBoxButtons.OK); - return; - } - if (listView1.Items.Count == 1) - { - listView1.Items[0].Selected = true; - frm5.lv1_item = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - frm5.dur_lv1 = listView1.SelectedItems[0].SubItems[3].Text; - } - else - { - if (listView1.SelectedIndices.Count == 1) - { - frm5.lv1_item = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - frm5.dur_lv1 = listView1.SelectedItems[0].SubItems[3].Text; - } - else return; - } - } - - if (tabControl1.SelectedIndex == 1) - { - if (listView2.Items.Count == 0) - { - MessageBox.Show(Strings.no_item_sel, Strings.no_file, MessageBoxButtons.OK, MessageBoxIcon.Information); - return; - } - if (listView2.Items.Count == 1) - { - listView2.Items[0].Selected = true; - frm5.lv1_item = listView2.SelectedItems[0].Text; - frm5.dur_lv1 = listView1.Items[listView2.SelectedItems[0].Index].SubItems[3].Text; - } - else - { - if (listView2.SelectedIndices.Count == 1) - { - frm5.lv1_item = listView2.SelectedItems[0].Text; - frm5.dur_lv1 = listView1.Items[listView2.SelectedItems[0].Index].SubItems[3].Text; - } - else return; - } - } - - if (tabControl1.SelectedIndex == 3) - { - if (dg1.SelectedRows.Count > 0) - { - frm5.lv1_item = dg1.Rows[dg1.SelectedCells[0].RowIndex].Cells[1].Value.ToString(); - btn_url_info.PerformClick(); - } - else return; - } - - frm5.current_fr = current_fr; - foreach (String str in already_scan) - { - if (str == frm5.lv1_item) - { - frm5.already_scan = true; - break; - } - } - frm5.pic_frame.Image = pic_frame.Image; - frm5.refresh = false; - frm5.current_fr = 0; - if (btn_change_ff.Text.ToLower().Contains("essential")) frm5.ff_ess = true; - else frm5.ff_ess = false; - frm5.ShowDialog(); - if (frm5.refresh == true) - { - frm5.Dispose(); - main_menu_streams.PerformClick(); - return; - } - if (frm5.already_scan == true) already_scan.Add(frm5.lv1_item); - if (frm5.trim_st == true) txt_ini.Text = frm5.trim_start; - if (frm5.trim_e == true) txt_fin.Text = frm5.trim_end; - frm5.Dispose(); - } - - private void Form1_FormClosed(object sender, FormClosedEventArgs e) - { - notifyIcon1.Dispose(); - try { clean_ffb_test(); } catch { } - } - - private void btn_min1_Click(object sender, EventArgs e) - { - Pg1.Focus(); - String dur_lv1 = ""; - String lv1_item = ""; - current_fr = current_fr - 30000; - - if (tabControl1.SelectedIndex == 0) - { - if (listView1.SelectedIndices.Count == 1) - { - dur_lv1 = listView1.SelectedItems[0].SubItems[3].Text; - lv1_item = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - } - - if (listView1.SelectedIndices.Count == 0 && listView1.Items.Count == 1) - { - listView1.Items[0].Selected = true; - dur_lv1 = listView1.Items[0].SubItems[3].Text; - lv1_item = listView1.Items[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - } - if (listView1.Items.Count == 1 && listView1.SelectedItems.Count == 0) - { - dur_lv1 = listView1.Items[0].SubItems[3].Text; - lv1_item = listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text; - } - - if (listView1.Items.Count == 0) return; - if (listView1.Items.Count > 0 && listView1.SelectedItems.Count == 0) return; - } - - if (tabControl1.SelectedIndex == 1) - { - if (listView2.SelectedIndices.Count == 1) - { - dur_lv1 = listView1.Items[listView2.SelectedItems[0].Index].SubItems[3].Text; - lv1_item = listView2.SelectedItems[0].Text; - } - if (listView2.SelectedIndices.Count == 0 && listView2.Items.Count == 1) - { - listView2.Items[0].Selected = true; - dur_lv1 = listView1.Items[listView2.Items[0].Index].SubItems[3].Text; - lv1_item = listView2.Items[0].Text; - } - if (listView2.Items.Count == 1 && listView2.SelectedItems.Count == 0) - { - dur_lv1 = listView1.Items[listView2.Items[0].Index].SubItems[3].Text; - lv1_item = listView2.Items[0].Text; - } - if (listView2.Items.Count == 0) return; - if (listView2.Items.Count > 0 && listView2.SelectedItems.Count == 0) return; - } - - if (current_fr == -30000) - { - current_fr = 0; - return; - } - if (current_fr < 0) current_fr = 0; - - get_frame(); - } - - private void btn_plus1_Click(object sender, EventArgs e) - { - Pg1.Focus(); - - current_fr = current_fr + 30000; - String dur_lv1 = ""; - String lv1_item = ""; - - if (tabControl1.SelectedIndex == 0) - { - if (listView1.SelectedIndices.Count == 1) - { - dur_lv1 = listView1.SelectedItems[0].SubItems[3].Text; - lv1_item = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - } - - if (listView1.SelectedIndices.Count == 0 && listView1.Items.Count == 1) - { - listView1.Items[0].Selected = true; - dur_lv1 = listView1.Items[0].SubItems[3].Text; - lv1_item = listView1.Items[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - } - if (listView1.Items.Count == 1 && listView1.SelectedItems.Count == 0) - { - dur_lv1 = listView1.Items[0].SubItems[3].Text; - lv1_item = listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text; - } - if (listView1.Items.Count == 0) return; - if (listView1.Items.Count > 0 && listView1.SelectedItems.Count == 0) return; - } - - if (tabControl1.SelectedIndex == 1) - { - if (listView2.SelectedIndices.Count == 1) - { - dur_lv1 = listView1.Items[listView2.SelectedItems[0].Index].SubItems[3].Text; - lv1_item = listView2.SelectedItems[0].Text; - } - if (listView2.SelectedIndices.Count == 0 && listView2.Items.Count == 1) - { - listView2.Items[0].Selected = true; - dur_lv1 = listView1.Items[listView2.Items[0].Index].SubItems[3].Text; - lv1_item = listView2.Items[0].Text; - } - if (listView2.Items.Count == 1 && listView2.SelectedItems.Count == 0) - { - dur_lv1 = listView1.Items[listView2.Items[0].Index].SubItems[3].Text; - lv1_item = listView2.Items[0].Text; - } - if (listView2.Items.Count == 0) return; - if (listView2.Items.Count > 0 && listView2.SelectedItems.Count == 0) return; - } - - DateTime time2; - Double miliseconds = 0; - - if (DateTime.TryParse(dur_lv1, out time2)) - { - miliseconds = TimeSpan.Parse(dur_lv1).TotalMilliseconds; - } - int secs = (int)miliseconds; - - if (current_fr == secs + 30000) - { - current_fr = secs; - return; - } - if (secs < current_fr) current_fr = secs; - get_frame(); - } - - private void ct2_del_Click(object sender, EventArgs e) - { - try - { - foreach (ListViewItem item in listView2.SelectedItems) - { - listView1.FindItemWithText(Path.GetFileName(item.Text)); - listView1.Items.RemoveAt(item.Index); - listView2.Items.RemoveAt(item.Index); - } - } - catch { } - - //listView2.Items.RemoveAt(listView2.SelectedItems[0].Index); - - listView1.BeginUpdate(); - foreach (ListViewItem item in listView1.SelectedItems) - { - if (working == false) - { - listView1.Items.Remove(item); - - foreach (ListViewItem item2 in listView3.Items) - { - if (item2.Text == item.Text) - { - listView3.Items.RemoveAt(item2.Index); - } - } - } - else - { - if (item.SubItems[5].Text == Strings.queued) - { - listView1.Items.RemoveAt(item.Index); - } - } - } - - listView1.EndUpdate(); - lbl_items.Text = listView1.Items.Count + " " + Strings.files; - - calc_total_dur(); - calc_list_size(); - - if (working == true && multi_running == false) - { - total_duration = 0; - - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[3].Text != Strings.n_a && item.SubItems[3].Text != "0:00:00" && item.SubItems[3].Text != "00:00:00" && item.SubItems[3].Text != Strings.pending) - { - total_duration = total_duration + TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds - TimeSpan.Parse(ss_time_input.Text).TotalSeconds; - } - else - { - total_duration = total_duration + 0; - } - } - } - } - - private void listView1_DragLeave(object sender, EventArgs e) - { - listView1.BackgroundImage = null; - if (Settings.Default.dark_mode == false) listView1.BackColor = SystemColors.Window; - else listView1.BackColor = Color.FromArgb(255, 64, 64, 64); - } - - private Boolean check_ff_md5() - { - if (File.Exists("ffmpeg.exe") == false) return false; - //Check MD5 ffmpeg - - String ffm = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - String f_md5 = String.Empty; - if (is_portable == false) { f_md5 = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_md5.ini"; } - else { f_md5 = port_path + "ff_md5_portable.ini"; } - String saved = Strings.none; - String code = ""; - String psk = "FFBatch2022_()*_"; - if (File.Exists(f_md5)) - { - saved = StringCipher.Decrypt(File.ReadAllText(f_md5), psk); - } - - using (var md5 = MD5.Create()) - { - using (var stream = File.OpenRead(ffm)) - { - var hash = md5.ComputeHash(stream); - code = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); - } - } - if (saved != code) - { - MessageBox.Show(Strings.md5_fail1 + Environment.NewLine + Environment.NewLine + Strings.md5_trust + Environment.NewLine + Environment.NewLine + Strings.md5_reinst, Strings.md5_fail, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return false; - } - - return true; - } - - public void UpdateColorDark(Control myControl) - { - myControl.BackColor = Color.FromArgb(255, 64, 64, 64); - myControl.ForeColor = Color.White; - foreach (Control subC in myControl.Controls) - { - UpdateColorDark(subC); - } - } - - public void UpdateColorDefault(Control myControl) - { - myControl.BackColor = SystemColors.InactiveBorder; - myControl.ForeColor = Control.DefaultForeColor; - foreach (Control subC in myControl.Controls) - { - UpdateColorDefault(subC); - } - } - - private void post_dark() - { - pic_frame.Image = pic_dark.Image; - pic_frame.InitialImage = pic_reading.InitialImage; - this.BackColor = Color.FromArgb(255, 64, 64, 64); - listView1.BackColor = Color.FromArgb(255, 64, 64, 64); listView1.Refresh(); - listView2.BackColor = Color.FromArgb(255, 64, 64, 64); listView2.Refresh(); - listView3.BackColor = Color.FromArgb(255, 64, 64, 64); listView3.Refresh(); - dg1.BackgroundColor = Color.Gray; - dg1.RowsDefaultCellStyle.BackColor = Color.Gray; - } - - private void post_color_def() - { - pic_frame.Image = pic_reading.ErrorImage; - pic_frame.InitialImage = pic_reading.Image; - this.BackColor = SystemColors.InactiveBorder; - listView1.BackColor = SystemColors.Window; listView1.Refresh(); - listView2.BackColor = SystemColors.Window; listView2.Refresh(); - listView3.BackColor = SystemColors.Window; listView3.Refresh(); - list_tracks.BackColor = SystemColors.Window; - listView3.BackColor = Color.White; - txt_parameters.BackColor = Color.White; - combo_presets.BackColor = Color.White; - dg1.BackgroundColor = SystemColors.InactiveBorder; - dg1.RowsDefaultCellStyle.BackColor = Color.White; - main_menu.BackColor = SystemColors.InactiveBorder; - } - - private void timer_yt_Tick(object sender, EventArgs e) - { - show_est = !show_est; - } - - private void dg1_CellMouseEnter(object sender, DataGridViewCellEventArgs e) - { - if (e.ColumnIndex == 0) this.Cursor = Cursors.Hand; - else this.Cursor = Cursors.Arrow; - } - - private void dg1_CellMouseLeave(object sender, DataGridViewCellEventArgs e) - { - this.Cursor = Cursors.Arrow; - } - - private void dg1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) - { - try - { - if (dg1.Rows.Count > 0 && dg1.Rows[e.RowIndex].Cells[0].Selected == true && dg1.Rows[e.RowIndex].Cells[5].Value.ToString() != String.Empty && dg1.Rows.Count > 0) - { - if (dg_thumbs[dg1.SelectedCells[0].RowIndex] != null && dg_thumbs[dg1.SelectedCells[0].RowIndex].Width > 160) - { - Form10 frm = new Form10(); - frm.pic_y.Image = dg_thumbs[dg1.SelectedCells[0].RowIndex]; - frm.ShowDialog(); - } - } - } - catch { } - } - - private void dg1_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e) - { - if (e.ColumnIndex == 0) this.Cursor = Cursors.Hand; - else this.Cursor = Cursors.Arrow; - } - - private void dg1_MouseLeave(object sender, EventArgs e) - { - this.Cursor = Cursors.Arrow; - } - - private void listView2_DragLeave(object sender, EventArgs e) - { - listView2.BackgroundImage = null; - if (Settings.Default.dark_mode == false) listView2.BackColor = SystemColors.Window; - else - listView2.BackColor = Color.FromArgb(255, 64, 64, 64); - } - - private void BG_Selected_items_DoWork(object sender, DoWorkEventArgs e) - { - int current_f = 0; - warn_enc = 0; - - String hw_decode = String.Empty; - - cb_hwdecode.Invoke(new MethodInvoker(delegate - { - if (cb_hwdecode.SelectedItem.ToString() != "none") - { - hw_decode = "-hwaccel " + cb_hwdecode.SelectedItem.ToString(); - } - })); - - procs.Clear(); - multi_logs.Clear(); - multi_params.Clear(); - multi_speeds.Clear(); - multi_fps.Clear(); - - lbl_speed.Invoke(new MethodInvoker(delegate - { - lbl_speed.Text = ""; - })); - - List destis = new List(); - List list_lines = new List(); - list_successful_m.Clear(); - list_failed_m.Clear(); - - foreach (int i in selecs) - { - procs.Add("proc_urls_" + i.ToString(), new Process()); - destis.Add("destis_" + i.ToString()); - multi_logs.Add("log_n_" + i.ToString(), ""); - multi_params.Add("path_n_" + i.ToString(), ""); - } - - listView1.Invoke(new MethodInvoker(delegate - { - - foreach (ListViewItem item in listView1.SelectedItems) - { - multi_speeds.Add("0"); - multi_fps.Add("0"); - } - })); - - this.InvokeEx(f => f.Pg1.Text = "0%"); - - Disable_Controls(); - this.InvokeEx(f => f.btn_add_files.Enabled = true); - - ParallelOptions par_op = new ParallelOptions(); - CancellationTokenSource cts = new System.Threading.CancellationTokenSource(); - par_op.CancellationToken = cts.Token; - par_op.MaxDegreeOfParallelism = Convert.ToInt16(n_threads.Value); - - opened_m = false; - aborted = false; - Decimal tot_frames2 = 0; - warn_space = true; - int list_count = 0; - - IEnumerable items_lv = Enumerable.Range(0, selecs.Count); - ParallelLoopResult result = new ParallelLoopResult(); - - int current = 0; - object lockCurrent = new object(); - - try - { - result = Parallel.ForEach(Partitioner.Create(items_lv, EnumerablePartitionerOptions.NoBuffering), par_op, (file_int2) => - { - int file_int = 0; - lock (lockCurrent) - { - file_int = current; - current++; - } - - if (cancelados_paralelos == true || aborted == true) - { - cts.Cancel(); - timer_selecs.Stop(); - timer_tasks.Stop(); - working = false; - multi_running = false; - return; - } - - Boolean skipped = false; - String item_capture_time = String.Empty; - String fullPath = ""; - Double total_prog = 0; - Double row_duration = 0; - Boolean valid_prog2 = false; - TimeSpan time2; - Double dur_rpl = 0; - String dur_fbit = ""; - int space_timer = 0; - - listView1.Invoke(new MethodInvoker(delegate - { - if (listView1.Items[selecs[file_int]].SubItems[5].Text == Strings.skipped) skipped = true; - if (TimeSpan.TryParse(listView1.Items[selecs[file_int]].SubItems[3].Text, out time2)) - { - row_duration = TimeSpan.Parse(listView1.Items[selecs[file_int]].SubItems[3].Text).TotalSeconds - TimeSpan.Parse(ss_time_input.Text).TotalSeconds; - valid_prog2 = true; - dur_fbit = listView1.Items[selecs[file_int]].SubItems[3].Text; - } - else - { - row_duration = 0; - valid_prog2 = false; - dur_fbit = "0K"; - } - - fullPath = listView1.Items[selecs[file_int]].SubItems[1].Text + "\\" + listView1.Items[selecs[file_int]].Text; - - })); - - if (skipped == true) - { - this.InvokeEx(f => f.listView1.Items[selecs[file_int]].SubItems[5].Text = Strings.skipped); - return; - } - - String ffm = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - - // Average frames - int fframes = 0; - Decimal dec = 0; - try - { - String ff_frames = String.Empty; - - Process get_frames = new Process(); - get_frames.StartInfo.FileName = Path.Combine(Application.StartupPath, "mediainfo.exe"); - String ffprobe_frames = "--Output=" + '\u0022' + "Video;%FrameCount%" + '\u0022'; - get_frames.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + fullPath + '\u0022'; - get_frames.StartInfo.RedirectStandardOutput = true; - get_frames.StartInfo.UseShellExecute = false; - get_frames.StartInfo.CreateNoWindow = true; - get_frames.EnableRaisingEvents = true; - get_frames.Start(); - - ff_frames = get_frames.StandardOutput.ReadLine(); - get_frames.WaitForExit(3000); - - if (get_frames.ExitCode == 0) - { - if (ff_frames != null) - { - dec = decimal.Parse(ff_frames); - if (dec.ToString().Substring(dec.ToString().Length - 1, 1) == "0") dec = dec / 10; - } - else - { - dec = 0; - } - - get_frames.Dispose(); - tot_frames2 = tot_frames2 + dec; - } - } - catch - { - dec = 0; - } - - // End average frames - - //Begin Shifting - String shifting = ""; - if (chk_shift.Checked == true) - { - shifting = " -itsoffset " + Num_Shift.Value.ToString().Replace(",", ".") + " -i " + '\u0022' + fullPath + '\u0022' + " -map 1:v -map 0:a "; - } - - //End Shifting - - //Change Volume - String change_vol = ""; - if (chk_vol.Checked == true) - { - change_vol = "-filter:a " + '\u0022' + "volume=" + vol_ch.Value.ToString() + "dB " + '\u0022' + " "; - } - //End change volume - - if (txt_path_main.Text.Contains(".\\")) - { - if (txt_path_main.Text != ".\\") - { - destis[file_int] = fullPath.Substring(0, fullPath.LastIndexOf('\\')) + txt_path_main.Text.Replace(".", String.Empty); - } - else - { - destis[file_int] = Path.GetDirectoryName(fullPath); - } - } - else - { - if (chk_recreate.CheckState == CheckState.Checked) - { - String pre_dest = Path.GetDirectoryName(fullPath); - destis[file_int] = Path.Combine(txt_path_main.Text, pre_dest.Substring(3, pre_dest.Length - 3)); - } - else - { - destis[file_int] = txt_path_main.Text; - } - } - if (!Directory.Exists(destis[file_int])) - { - Directory.CreateDirectory(destis[file_int]); - } - multi_dest = destis[file_int]; - - String pre_input_var = ""; - if (txt_pre_input.Text != "") - { - pre_input_var = txt_pre_input.Text; - } - - String pre_ss = ""; - if (TimeSpan.Parse(ss_time_input.Text).TotalSeconds != 0) - { - pre_ss = " -ss " + ss_time_input.Text; - } - - add_suffix = ""; - if (chk_suffix.Checked == true && txt_suffix.Text != String.Empty) - { - add_suffix = txt_suffix.Text; - n_th_suffix = add_suffix; - } - - String ext_output1 = txt_format.Text; - if (txt_format.Text.Length == 0) - { - ext_output1 = Path.GetExtension(fullPath); - } - else - { - ext_output1 = "." + txt_format.Text; - } - n_th_source_ext = ext_output1; - - // textbox_params = txt_parameters.Text; - - var tmp = procs["proc_urls_" + selecs[file_int].ToString()]; - var n_logs = multi_logs["log_n_" + selecs[file_int].ToString()]; - var tmp_params = multi_params["path_n_" + selecs[file_int].ToString()]; - tmp_params = txt_parameters.Text; - - //Custom item parameters - if (cust_p_col != 0) - { - try - { - if (custom_m_params[file_int] != "-") - { - int start = custom_m_params[file_int].LastIndexOf("[["); - int end = custom_m_params[file_int].LastIndexOf("]]"); - int cut = end - start + 2; - int length = custom_m_params[file_int].Length; - tmp_params = custom_m_params[file_int].Substring(0, length - cut); - - if (start != -1 && end != -1) - { - ext_output1 = "." + custom_m_params[file_int].Substring(start + 2, cut - 4); - n_th_source_ext = ext_output1; - } - } - } - catch { } - } - //End custom item parameters - - if (txt_format.Text == "nul") ext_output1 = "nul"; - - String file2 = fullPath; - while (tmp_params.Contains("%fn")) - { - if (tmp_params.Contains("%fn")) - { - tmp_params = tmp_params.Replace("%fn", Path.GetFileNameWithoutExtension(file2)); - } - } - while (tmp_params.Contains("%fp")) - { - if (tmp_params.Contains("%fp")) - { - tmp_params = tmp_params.Replace("%fp", Path.GetDirectoryName(file2)); - } - } - - - while (tmp_params.Contains("%ff")) - { - if (tmp_params.Contains("%ff")) - { - tmp_params = tmp_params.Replace("%ff", Path.GetFileName(file2)); - } - } - - String dur_secs = dur_rpl.ToString(); - String to_replace = String.Empty; - Double result2 = 0; - - while (tmp_params.Contains("%fdur")) - { - - if (tmp_params.Contains("%fdur")) - { - to_replace = ""; - - int operador = tmp_params.LastIndexOf("%fdur") + 5; - int length = 0; - int limit = tmp_params.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(tmp_params.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace = tmp_params.Substring(tmp_params.LastIndexOf("%fdur"), 5 + length); - result2 = Convert.ToDouble(new DataTable().Compute(to_replace.Replace("%fdur", dur_secs), null)); - tmp_params = ReplaceLastOccurrence(tmp_params, to_replace, Math.Round(result2).ToString()); - } - } - - while (pre_input_var.Contains("%fdur")) - { - - if (pre_input_var.Contains("%fdur")) - { - to_replace = ""; - - int operador = pre_input_var.LastIndexOf("%fdur") + 5; - int length = 0; - int limit = pre_input_var.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(pre_input_var.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace = pre_input_var.Substring(pre_input_var.LastIndexOf("%fdur"), 5 + length); - result2 = Convert.ToDouble(new DataTable().Compute(to_replace.Replace("%fdur", dur_secs), null)); - pre_input_var = ReplaceLastOccurrence(pre_input_var, to_replace, Math.Round(result2).ToString()); - } - } - - //Bitrate variable - - dur_secs = get_bitrate(file2, dur_fbit).ToString(); - to_replace = String.Empty; - - while (tmp_params.Contains("%fbitr")) - { - if (tmp_params.Contains("%fbitr")) - { - to_replace = ""; - - int operador = tmp_params.LastIndexOf("%fbitr") + 6; - int length = 0; - int limit = tmp_params.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(tmp_params.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace = tmp_params.Substring(tmp_params.LastIndexOf("%fbitr"), 6 + length); - - Double result0 = Convert.ToDouble(new DataTable().Compute(to_replace.Replace("%fbitr", dur_secs), null)); - tmp_params = ReplaceLastOccurrence(tmp_params, to_replace, Math.Round(result0).ToString() + "K"); - } - } - - while (pre_input_var.Contains("%fbitr")) - { - if (pre_input_var.Contains("%fbitr")) - { - to_replace = ""; - - int operador = pre_input_var.LastIndexOf("%fbitr") + 6; - int length = 0; - int limit = pre_input_var.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(pre_input_var.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace = pre_input_var.Substring(pre_input_var.LastIndexOf("%fbitr"), 6 + length); - - Double result0 = Convert.ToDouble(new DataTable().Compute(to_replace.Replace("%fbitr", dur_secs), null)); - pre_input_var = ReplaceLastOccurrence(pre_input_var, to_replace, Math.Round(result0).ToString() + "K"); - } - } - - //End bitrate variable - - //Target size - if (tmp_params.Contains("[[target_size=")) - { - int f = tmp_params.IndexOf("[[target_size=") + 14; - int mb = tmp_params.IndexOf("MB"); - int l = tmp_params.IndexOf("Kbps]]"); - Double target_mb = Convert.ToDouble(tmp_params.Substring(f, mb - f)); - String aud_bitr = tmp_params.Substring(mb + 3, l - mb - 3); - String replaced = get_bitrate_target(target_mb, dur_rpl, Convert.ToDecimal(aud_bitr)).ToString(); - to_replace = tmp_params.Substring(f - 14, l - f + 14 + 6); - tmp_params = tmp_params.Replace(to_replace, replaced); - } - //End target size - - while (tmp_params.Contains("%fd")) - { - if (tmp_params.Contains("%fd")) - { - var dirName = new DirectoryInfo(Path.GetDirectoryName(file2)).Name; - tmp_params = tmp_params.Replace("%fd", dirName); - } - } - - while (tmp_params.Contains("%1")) - { - if (tmp_params.Contains("%1")) - { - file2 = file2.Replace("\\", "\\\\\\\\"); - file2 = file2.Replace(":", ":" + "\\\\"); - tmp_params = tmp_params.Replace("%1", '\u0022' + file2 + '\u0022'); - } - } - - while (tmp_params.Contains("%2")) - { - if (tmp_params.Contains("%2")) - { - file2 = file2.Replace("\\", "\\\\\\\\"); - file2 = file2.Replace(":", ":" + "\\\\"); - tmp_params = tmp_params.Replace("%2", '\u0022' + Path.Combine(Path.GetDirectoryName(file2), Path.GetFileNameWithoutExtension(file2)) + '\u0022'); - } - } - - tmp.StartInfo.Arguments = hw_decode + " " + pre_input_var + " " + pre_ss + " -i " + "" + '\u0022' + fullPath + '\u0022' + " " + shifting + " " + " -y " + tmp_params + " " + change_vol + '\u0022' + destis[file_int] + "\\" + Path.GetFileNameWithoutExtension(fullPath) + add_suffix + ext_output1 + '\u0022' + " -hide_banner"; - if (ext_output1 == "nul") tmp.StartInfo.Arguments = hw_decode + " " + pre_input_var + " " + pre_ss + " -i " + "" + '\u0022' + fullPath + '\u0022' + " " + shifting + " " + tmp_params + " " + change_vol + " " + " -hide_banner"; - - String second_path = ""; - if (ext_output1 == "nul") - { - String[] split = txt_parameters.Text.Split(' '); - for (int i = 0; i < split.Length; i++) - { - if (split[i].Contains("\\") == true) - { - String pre_path = split[i].Replace("%fp", Path.GetDirectoryName(file2)).Replace("%fn", Path.GetFileNameWithoutExtension(file2)).Replace("%", "_"); - second_path = Path.GetDirectoryName(pre_path.Replace('\u0022', ' ')); - - if (!Directory.Exists(second_path)) - { - try - { - Directory.CreateDirectory(second_path); - } - catch - { - } - } - } - } - } - - String current_out = destis[file_int] + "\\" + Path.GetFileNameWithoutExtension(fullPath) + add_suffix + ext_output1; - Boolean to_overw = false; - - if (chk_overw.CheckState == CheckState.Checked) - { - if (current_out == fullPath) - { - tmp.StartInfo.Arguments = hw_decode + " " + pre_input_var + " " + pre_ss + " -i " + "" + '\u0022' + fullPath + '\u0022' + " " + shifting + " " + " -y " + tmp_params + " " + change_vol + '\u0022' + destis[file_int] + "\\" + Path.GetFileNameWithoutExtension(fullPath) + "_fftemp" + add_suffix + ext_output1 + '\u0022' + " -hide_banner"; - to_overw = true; - } - } - - if (current_out == fullPath && chk_overw.CheckState == CheckState.Unchecked) - { - MessageBox.Show(Strings.source_overw + Environment.NewLine + Environment.NewLine + current_out, Strings.overw_not, MessageBoxButtons.OK, MessageBoxIcon.Error); - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - working = false; - time_est_size = 0; - cts.Cancel(); - Enable_Controls(); - cancelados_paralelos = true; - } - - //Monitor available space - - DriveInfo dest_drive2 = new DriveInfo(Application.StartupPath); - - FileInfo f_root2 = new FileInfo(current_out); - try - { - dest_drive2 = new DriveInfo(f_root2.Directory.Root.FullName); - } - catch { warn_space = false; } - - if (dest_drive2.AvailableFreeSpace != null && warn_space == true) - { - if (dest_drive2.AvailableFreeSpace <= 500000000) - { - DialogResult a = DialogResult.Cancel; - - a = MessageBox.Show(Strings.warn_sp, Strings.low_sp + " (" + (dest_drive2.AvailableFreeSpace / 1000000).ToString() + "MB)", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); - if (a == DialogResult.Yes) - { - aborted = true; - this.InvokeEx(f => f.lbl_est_size.Text = ""); - this.InvokeEx(f => f.lbl_bitrate.Text = ""); - cts.Cancel(); - return; - } - } - } - //End monitor available space - - //Duration for quick file listing - - Type ts = Type.GetTypeFromProgID("Shell.Application"); - dynamic shell = Activator.CreateInstance(ts); - Folder rFolder = shell.NameSpace(Path.GetDirectoryName(fullPath)); - FolderItem rFiles = rFolder.ParseName(Path.GetFileName(fullPath)); - String videostype = rFolder.GetDetailsOf(rFiles, 2).Trim(); - String videoSize = rFolder.GetDetailsOf(rFiles, 1).Trim(); - - this.InvokeEx(f => f.listView1.Items[selecs[file_int]].SubItems[2].Text = videostype); - this.InvokeEx(f => f.listView1.Items[selecs[file_int]].SubItems[4].Text = videoSize); - - DateTime time; - String dur_q = rFolder.GetDetailsOf(rFiles, 27).Trim(); - - if ((DateTime.TryParse(dur_q, out time))) - { - row_duration = TimeSpan.Parse(dur_q).TotalSeconds; - this.InvokeEx(f => f.listView1.Items[selecs[file_int]].SubItems[3].Text = dur_q); - valid_prog2 = true; - } - else valid_prog2 = false; - - if (verbose_logs == false) tmp.StartInfo.Arguments = tmp.StartInfo.Arguments + " -loglevel warning -stats"; - if (cts.IsCancellationRequested == false) - { - tmp.StartInfo.FileName = ffm; - tmp.StartInfo.RedirectStandardInput = true; - tmp.StartInfo.RedirectStandardError = true; - tmp.StartInfo.UseShellExecute = false; - tmp.StartInfo.CreateNoWindow = true; - tmp.StartInfo.WorkingDirectory = Path.GetDirectoryName(fullPath); - tmp.EnableRaisingEvents = true; - - tmp.Start(); - this.InvokeEx(f => f.listView1.Items[selecs[file_int]].SubItems[5].Text = Strings.processing); - - combo_prio.Invoke(new MethodInvoker(delegate - { - if (combo_prio.SelectedIndex != 2) - { - try - { - if (combo_prio.SelectedIndex == 0) tmp.PriorityClass = ProcessPriorityClass.High; - if (combo_prio.SelectedIndex == 1) tmp.PriorityClass = ProcessPriorityClass.AboveNormal; - if (combo_prio.SelectedIndex == 2) tmp.PriorityClass = ProcessPriorityClass.Normal; - if (combo_prio.SelectedIndex == 3) tmp.PriorityClass = ProcessPriorityClass.BelowNormal; - if (combo_prio.SelectedIndex == 4) tmp.PriorityClass = ProcessPriorityClass.Idle; - Process[] localByName = Process.GetProcessesByName("FFBatch"); - if (localByName.Length == 1) - { - foreach (Process proc1 in localByName) - { - if (combo_prio.SelectedIndex >= 2) proc1.PriorityClass = ProcessPriorityClass.Normal; - else proc1.PriorityClass = tmp.PriorityClass; - } - } - } - catch { } - } - })); - } - else - { - timer_selecs.Stop(); - this.InvokeEx(f => f.listView1.Enabled = true); - working = false; - multi_running = false; - Enable_Controls(); - cancelados_paralelos = false; - return; - } - - this.InvokeEx(f => f.listView1.Items[selecs[file_int]].SubItems[5].Text = Strings.processing); - - FileInfo f_root = new FileInfo(destis[file_int]); - DriveInfo dest_drive = new DriveInfo(Application.StartupPath); - try - { - dest_drive = new DriveInfo(f_root.Directory.Root.FullName); - } - catch { warn_space = false; } - - String err_txt = ""; - Double interval = 0; - Double durat_n2 = 0; - this.InvokeEx(f => multi_logs["log_n_" + selecs[file_int].ToString()] = Strings.logging_f + " " + '\u0022' + listView1.Items[selecs[file_int]].Text + '\u0022' + Environment.NewLine); - //REVIEW - while (!tmp.StandardError.EndOfStream) - { - err_txt = tmp.StandardError.ReadLine(); - space_timer++; - multi_logs["log_n_" + selecs[file_int].ToString()] = multi_logs["log_n_" + selecs[file_int].ToString()] + Environment.NewLine + n_logs + err_txt; - - if (err_txt.Contains("time=") && err_txt.Contains("time=-") == false && !err_txt.Contains("time=N/A")) - { - if (valid_prog2 == true) - { - this.InvokeEx(f => f.txt_remain.Refresh()); - this.InvokeEx(f => durat_n2 = row_duration); - int start_time_index = err_txt.IndexOf("time=") + 5; - Double sec_prog = TimeSpan.Parse(err_txt.Substring(start_time_index, 8)).TotalSeconds; - Double percent = (sec_prog * 100 / durat_n2); - - total_prog = total_prog + (sec_prog - interval); - interval = sec_prog; - int percent2 = 0; - try - { - percent2 = Convert.ToInt32(percent); - } - catch - { - } - - if (percent2 <= 100) - { - if (Math.Round(percent, 1).ToString().Contains(".") || Math.Round(percent, 1).ToString().Contains(",")) - { - this.InvokeEx(f => f.listView1.Items[selecs[file_int]].SubItems[5].Text = Math.Round(percent, 1).ToString() + "%"); - } - else - { - this.InvokeEx(f => f.listView1.Items[selecs[file_int]].SubItems[5].Text = Math.Round(percent, 1).ToString() + ".0" + "%"); - } - } - } - try - { - if (err_txt.Contains("fps=")) - { - multi_fps[file_int] = (err_txt.Substring(err_txt.LastIndexOf("fps=") + 4, 4)).TrimStart(); - } - else - { - multi_fps[file_int] = "0"; - } - } - catch { multi_fps[file_int] = "0"; } - try - { - if (err_txt.ToLower().Contains("speed=")) - { - multi_speeds[file_int] = (err_txt.Substring(err_txt.LastIndexOf("speed=") + 6, err_txt.Length - err_txt.LastIndexOf("speed=") - 6)).Replace("x", ""); - } - else - { - multi_speeds[file_int] = "0"; - } - } - catch { multi_speeds[file_int] = "0"; } - } - - //Monitor available space - if (space_timer % 30 == 0 && dest_drive.AvailableFreeSpace <= 500000000 && warn_space == true) - { - foreach (Process proc in procs.Values) - { - try - { - proc.Suspend(); - } - catch - { - } - } - DialogResult a = MessageBox.Show(Strings.warn_sp, Strings.low_sp + " (" + (dest_drive2.AvailableFreeSpace / 1000000).ToString() + "MB)", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); - foreach (Process proc in procs.Values) - { - try - { - proc.Resume(); - } - catch - { - } - } - - if (a == DialogResult.Yes) - { - cts.Cancel(); - aborted = true; - cancelados_paralelos = true; - - foreach (Process proc in procs.Values) - { - cancelados_paralelos = true; - if (proc.StartInfo.Arguments != String.Empty) - - { - try - { - StreamWriter write_q = proc.StandardInput; - write_q.Write("q"); - } - catch { } - } - } - } - - warn_space = false; - } - //End monitor space - } - tmp.WaitForExit(); - tmp.StartInfo.Arguments = String.Empty; - current_f++; - multi_speeds[file_int] = "0"; - multi_fps[file_int] = "0"; - this.InvokeEx(f => f.lbl_items.Text = current_f.ToString() + " " + Strings.of1 + " " + listView1.SelectedItems.Count.ToString()); - this.InvokeEx(f => multi_logs["log_n_" + selecs[file_int].ToString()] = multi_logs["log_n_" + selecs[file_int].ToString()] + Environment.NewLine + "--------End of " + '\u0022' + listView1.Items[selecs[file_int]].Text + '\u0022' + " log--------" + Environment.NewLine); - - if (tmp.ExitCode == 0) - { - list_successful_m.Add(fullPath); - if (cancelados_paralelos == false && cts.IsCancellationRequested == false) - { - if (aborted_url == false) - { - if (File.Exists(fullPath) == true) - { - this.InvokeEx(f => f.listView1.Items[selecs[file_int]].SubItems[5].Text = Strings.success); - - if (chk_overw.CheckState == CheckState.Checked) - { - if (current_out == fullPath) - { - String sourc = destis[file_int] + "\\" + Path.GetFileNameWithoutExtension(fullPath) + "_fftemp" + add_suffix + ext_output1; - - try - { - if (File.Exists(sourc)) - { - File.Delete(fullPath); - FileSystem.RenameFile(sourc, Path.GetFileNameWithoutExtension(fullPath) + add_suffix + ext_output1); - this.InvokeEx(f => f.listView1.Items[selecs[file_int]].SubItems[5].Text = Strings.replaced); - } - else - { - this.InvokeEx(f => f.listView1.Items[selecs[file_int]].SubItems[5].Text = Strings.not_replaced); - warn_enc++; - this.InvokeEx(f => multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine + Strings.warning_file + " " + +'\u0022' + listView1.Items[selecs[file_int]].Text + '\u0022' + " " + Strings.warning_not_rep + " " + "(_fftemp)." + Environment.NewLine); - } - } - catch (Exception excpt) - { - try - { - FileSystem.RenameFile(sourc, Path.GetFileNameWithoutExtension(fullPath) + add_suffix + ext_output1); - this.InvokeEx(f => f.listView1.Items[selecs[file_int]].SubItems[5].Text = Strings.replaced); - } - catch - { - try - { - FileSystem.RenameFile('\u0022' + sourc + '\u0022', '\u0022' + Path.GetFileNameWithoutExtension(fullPath) + add_suffix + ext_output1 + '\u0022'); - this.InvokeEx(f => f.listView1.Items[selecs[file_int]].SubItems[5].Text = Strings.replaced); - } - catch - { - this.InvokeEx(f => f.listView1.Items[selecs[file_int]].SubItems[5].Text = Strings.renamed); - warn_enc++; - this.InvokeEx(f => multi_logs["log_n_" + selecs[file_int].ToString()] = multi_logs["log_n_" + selecs[file_int].ToString()] + Environment.NewLine + Strings.warning_file + " " + '\u0022' + listView1.Items[selecs[file_int]].Text + '\u0022' + " " + Strings.warning_not_rep + " " + "(_fftemp)." + Environment.NewLine); - } - } - } - } - } - - if (chk_delete_source.CheckState == CheckState.Checked && delete_def == false && delete_one == true) - { - try - { - FileSystem.DeleteFile(fullPath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); - this.InvokeEx(f => f.listView1.Items[selecs[file_int]].SubItems[5].Text = Strings.recycled); - } - catch - { - this.InvokeEx(f => f.listView1.Items[selecs[file_int]].SubItems[5].Text = Strings.not_recycled); - warn_enc++; - } - } - if (chk_delete_source.CheckState == CheckState.Checked && delete_def == true && delete_one == true) - { - try - { - FileInfo fs = new FileInfo(fullPath); - if (fs.IsReadOnly == true) fs.IsReadOnly = false; - File.Delete(fullPath); - this.InvokeEx(f => f.listView1.Items[selecs[file_int]].SubItems[5].Text = Strings.deleted); - } - catch - { - this.InvokeEx(f => f.listView1.Items[selecs[file_int]].SubItems[5].Text = Strings.not_deleted); - warn_enc++; - } - } - } - } - if (aborted_url == true) - { - if (skipped == false) this.InvokeEx(f => f.listView1.Items[selecs[file_int]].SubItems[5].Text = Strings.aborted); - else - { - this.InvokeEx(f => f.listView1.Items[selecs[file_int]].SubItems[5].Text = Strings.skipped); - try - { - File.Delete(current_out); - } - catch { } - } - aborted_url = false; - skipped = false; - } - - //Run on each file - int index = 0; - Boolean sh_check = false; - this.Invoke(new MethodInvoker(delegate - { - index = combo_shut.SelectedIndex; - if (chkshut.Checked == true) sh_check = true; - })); - - - if (index == 4 && cancel_queue == false && sh_check == true) - { - this.InvokeEx(f => this.Enabled = false); - Form14 frm_run = new Form14(); - frm_run.txt_path.Text = run_command; - String dest_f = '\u0022' + destis[file_int] + "\\" + Path.GetFileNameWithoutExtension(fullPath) + add_suffix + ext_output1 + '\u0022'; - if (ext_output1 == "nul") dest_f = '\u0022' + destis[file_int] + "\\" + Path.GetFileNameWithoutExtension(fullPath) + add_suffix + Path.GetExtension(fullPath).Replace(".", "") + '\u0022'; - - frm_run.args = dest_f + " " + run_command_args; - frm_run.timer1.Interval = 100; - frm_run.ShowDialog(); - this.InvokeEx(f => this.Enabled = true); - Enable_Controls(); - - if (frm_run.proc.ExitCode == 0) - { - this.InvokeEx(f => f.listView1.Items[selecs[file_int]].SubItems[5].Text = "OK & Run"); - multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine + n_logs + Strings.ext_com_ok + " " + dest_f + Environment.NewLine; - } - else - { - this.InvokeEx(f => f.listView1.Items[selecs[file_int]].SubItems[5].Text = "OK & Error"); - multi_logs["log_n_" + file_int.ToString()] = multi_logs["log_n_" + file_int.ToString()] + Environment.NewLine + n_logs + Strings.ext_com_err + " " + dest_f + Environment.NewLine; - } - this.InvokeEx(f => this.TopMost = true); - this.InvokeEx(f => this.TopMost = false); - } - - //End run on each file - } - else - { - this.InvokeEx(f => f.listView1.Items[selecs[file_int]].SubItems[5].Text = Strings.aborted); - - if (cancelados_paralelos == false) - { - aborted_url = false; - } - } - } - else - { - list_failed_m.Add(fullPath); - if (File.Exists(fullPath)) this.InvokeEx(f => f.listView1.Items[selecs[file_int]].SubItems[5].Text = Strings.failed); - else this.InvokeEx(f => f.listView1.Items[selecs[file_int]].SubItems[5].Text = Strings.file_not_f); - errors_enc = errors_enc + 1; - } - }); - } - catch (Exception exc) - { - fatal_parallel_msg = exc.Message; - fatal_parallel = true; - } - - if (result.IsCompleted == true) fatal_parallel = false; - else - { - if (cts.IsCancellationRequested == false) fatal_parallel = true; - else fatal_parallel = false; - } - String avgs = ""; - //Averages - - if (start_total_time == 0) start_total_time = 1; - Double avg_enc = Math.Round((total_multi_duration / start_total_time), 1); - - try - { - if (cancelados_paralelos == false) - { - if (tot_frames2 != 0) - { - avgs = Environment.NewLine + (Strings.avg_perf + " " + avg_enc.ToString() + "x" + " | " + Math.Round(tot_frames2 / (decimal)start_total_time, 1)).ToString() + " fps"; - this.InvokeEx(f => f.lbl_speed.Text = (Strings.avgs + " " + avg_enc.ToString() + "x" + " | " + Math.Round(tot_frames2 / (decimal)start_total_time, 1)).ToString() + " fps"); - } - else - { - avgs = Environment.NewLine + (Strings.avg_perf + " " + avg_enc.ToString() + "x"); - this.InvokeEx(f => f.lbl_speed.Text = (Strings.avgs + " " + avg_enc.ToString() + "x")); - } - } - } - catch { } - - //End averages - - if (no_save_logs == false) - { - String[] array_err = list_lines.ToArray(); - - String path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.log"; - if (is_portable == true) path = port_path + "ff_batch_portable.log"; - try - { - StreamWriter SaveFile = new StreamWriter(path); - SaveFile.WriteLine("Multi-file log session: " + System.DateTime.Now); - SaveFile.WriteLine("-----------------------------------------------------"); - SaveFile.Write(string.Join(Environment.NewLine, multi_logs.Select(a => $"{a.Value}"))); - SaveFile.Close(); - File.AppendAllText(path, avgs + Environment.NewLine + Environment.NewLine); - File.AppendAllText(path, "--------------------------"); - File.AppendAllText(path, Environment.NewLine + Strings.end_log); - File.AppendAllText(path, Environment.NewLine); - FileInfo fileInfo = new FileInfo(path); - - var bytes = fileInfo.Length; - - var kilobytes = (double)bytes / 1024; - var megabytes = kilobytes / 1024; - var gigabytes = megabytes / 1024; - - //Format size view - String size = ""; - String separator = "."; - - if (bytes > 1000000000) - { - if (gigabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String gigas = gigabytes.ToString(); - if (gigas.Length >= 5) - { - gigas = gigas.Substring(0, gigas.LastIndexOf(separator) + 3); - size = (gigas + " " + "GB"); - } - else - { - size = (gigas + " " + "GB"); - } - } - - if (bytes >= 1048576 && bytes <= 1000000000) - { - if (megabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - String megas = megabytes.ToString(); - if (megas.Length > 5) - { - megas = megas.Substring(0, megas.LastIndexOf(separator)); - size = (megas + " " + "MB"); - } - else - { - size = (megas + " " + "MB"); - } - } - - if (bytes >= 1024 && bytes < 1048576) - - { - if (kilobytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String kbs = kilobytes.ToString(); - if (kbs.Length >= 5) - { - kbs = kbs.Substring(0, kbs.LastIndexOf(separator)); - size = (kbs + " " + "KB"); - } - else - { - size = (kbs + " " + "KB"); - } - } - if (bytes > -1 && bytes < 1024) - { - String bits = bytes.ToString(); - size = (bits + " Bytes"); - } - - //End Format size view - File.AppendAllText(path, Environment.NewLine + Strings.log_size + " " + size); - } - catch { } - //End save log - } - } - - private void BG_Selected_items_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) - { - timer_queue.Enabled = false; - - listView1.SelectedIndices.Clear(); - try { clean_ffb_test(); } catch { } - - this.Text = "FFmpeg Batch AV Converter"; - - if (is_portable == true) this.Text = "FFmpeg Batch AV Converter Portable"; - timer_aborting.Stop(); - - // Close abort form - for (int i = Application.OpenForms.Count - 1; i >= 0; i--) - { - if (Application.OpenForms[i].Name == "Form12") - { - this.InvokeEx(f => Application.OpenForms[i].Close()); - break; - } - } - //End close abort form - listView1.SelectedItems.Clear(); - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - timer_selecs.Stop(); - timer_tasks.Stop(); - Pg1.Value = Pg1.Maximum; - Pg1.Text = "100%"; - Pg1.Refresh(); - listView1.Enabled = true; - working = false; - multi_running = false; - Enable_Controls(); - - if (cancelados_paralelos == false && fatal_parallel == false) - { - //Open on completion - String primero_lista = listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text; - String destino2 = String.Empty; - if (chk_open_compl.Checked == true) - { - if (txt_path_main.Text.Contains(".\\")) - { - destino2 = destino2 = primero_lista.Substring(0, primero_lista.LastIndexOf('\\')) + txt_path_main.Text.Replace(".", String.Empty); ; - } - else - { - destino2 = txt_path_main.Text; - } - } - - if (chk_delete_source.CheckState == CheckState.Checked && delete_def == false && delete_one == false) - { - Disable_Controls(); - - Label prog_txt = new Label(); - prog_txt.Parent = panel1; - prog_txt.Top = 95; - prog_txt.Left = 80; - prog_txt.Width = 250; - prog_txt.TabIndex = 1; - prog_txt.BackColor = panel1.BackColor; - prog_txt.BorderStyle = BorderStyle.None; - prog_txt.TextAlign = ContentAlignment.MiddleLeft; - prog_txt.BringToFront(); - prog_txt.Text = Strings.to_recycle; - - ProgressBar pg_del = new ProgressBar(); - pg_del.Parent = panel1; - pg_del.Top = 98; - pg_del.Left = 315; - pg_del.Width = 152; - pg_del.Height = 15; - pg_del.TabIndex = 0; - pg_del.BackColor = this.BackColor; - pg_del.Minimum = 0; - pg_del.BringToFront(); - pg_del.Maximum = listView1.Items.Count; - pg_del.Show(); - pg_del.Refresh(); - int i = 0; - int err = 0; - - foreach (String item in list_successful_m) - { - try - { - FileSystem.DeleteFile(item, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); - pg_del.Value = i; - i = i + 1; - - foreach (ListViewItem item2 in listView1.Items) - { - if (item2.Text == Path.GetFileName(item)) - { - item2.SubItems[5].Text = Strings.recycled; - } - } - } - catch - { - err = err + 1; - listView1.Invoke(new MethodInvoker(delegate - { - foreach (ListViewItem item2 in listView1.Items) - { - if (item2.Text == Path.GetFileName(item)) - { - item2.SubItems[5].Text = Strings.not_recycled; - } - } - })); - } - prog_txt.Text = Strings.to_recycle + i.ToString() + " " + Strings.of1 + " " + list_global_proc.Items.Count; - prog_txt.Refresh(); - } - prog_txt.Visible = false; - prog_txt.Dispose(); - pg_del.Visible = false; - pg_del.Dispose(); - Enable_Controls(); - - if (err > 0) MessageBox.Show(err.ToString() + " " + Strings.not_recycled2 + Strings.check_log, Strings.not_recycled3, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - - if (list_failed_m.Count > 0) - { - String path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.log"; - if (is_portable == true) path = port_path + "ff_batch_portable.log"; - - File.AppendAllText(path, Environment.NewLine + Environment.NewLine + Strings.source_not_deleted); - File.AppendAllText(path, Environment.NewLine + "-------------------------------"); - foreach (String item in list_failed_m) - { - File.AppendAllText(path, Environment.NewLine + item); - } - } - - //End delete source - } - - if (chk_delete_source.CheckState == CheckState.Checked && delete_def == true && delete_one == false) - { - Disable_Controls(); - - Label prog_txt = new Label(); - prog_txt.Parent = panel1; - prog_txt.Top = 95; - prog_txt.Left = 80; - prog_txt.Width = 250; - prog_txt.TabIndex = 1; - prog_txt.BackColor = panel1.BackColor; - prog_txt.BorderStyle = BorderStyle.None; - prog_txt.TextAlign = ContentAlignment.MiddleLeft; - prog_txt.BringToFront(); - prog_txt.Text = Strings.deleting_files; - - ProgressBar pg_del = new ProgressBar(); - pg_del.Parent = panel1; - pg_del.Top = 98; - pg_del.Left = 315; - pg_del.Width = 152; - pg_del.Height = 15; - pg_del.TabIndex = 0; - pg_del.BackColor = this.BackColor; - pg_del.Minimum = 0; - pg_del.BringToFront(); - pg_del.Maximum = listView1.Items.Count; - pg_del.Show(); - pg_del.Refresh(); - int i = 0; - int err = 0; - - foreach (String item in list_successful_m) - { - try - { - FileInfo fs = new FileInfo(item); - if (fs.IsReadOnly == true) fs.IsReadOnly = false; - File.Delete(item); - pg_del.Value = i; - i = i + 1; - - foreach (ListViewItem item2 in listView1.Items) - { - if (item2.Text == Path.GetFileName(item)) - { - item2.SubItems[5].Text = Strings.deleted; - } - } - } - catch - { - err = err + 1; - - foreach (ListViewItem item2 in listView1.Items) - { - if (item2.Text == Path.GetFileName(item)) - { - item2.SubItems[5].Text = Strings.not_deleted; - } - } - } - prog_txt.Text = Strings.deleting_f + " " + i.ToString() + " " + Strings.of1 + " " + list_global_proc.Items.Count; - prog_txt.Refresh(); - } - prog_txt.Visible = false; - prog_txt.Dispose(); - pg_del.Visible = false; - pg_del.Dispose(); - Enable_Controls(); - - if (err > 0) MessageBox.Show(err.ToString() + " " + Strings.not_recycled2 + " " + Strings.check_log, Strings.not_recycled3, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - - if (list_failed_m.Count > 0) - { - String path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.log"; - if (is_portable == true) path = port_path + "ff_batch_portable.log"; - - File.AppendAllText(path, Environment.NewLine + Environment.NewLine + Strings.source_not_deleted); - File.AppendAllText(path, Environment.NewLine + "-------------------------------"); - foreach (String item in list_failed_m) - { - File.AppendAllText(path, Environment.NewLine + item); - } - } - - //End delete source - } - this.InvokeEx(f => toolT002.RemoveAll()); - - if (errors_enc == 0) - { - pic_no_errors.Visible = true; - //Delete source - - //Automatic shutdown check - if (chkshut.Checked) - { - auto_shut(); - return; - } - - if (warn_enc > 0) - { - pic_no_errors.Visible = false; - pic_recording.Visible = false; - toolT002.SetToolTip(this.pic_warnings, Strings.there_w + " " + warn_enc.ToString() + " " + Strings.warnings_last_s); - pic_warnings.Visible = true; - } - } - else - { - pic_no_errors.Visible = false; - pic_recording.Visible = false; - toolT002.SetToolTip(this.pic_warnings, Strings.there_w + " " + errors_enc.ToString() + " " + Strings.errors_se); - pic_warnings.Visible = true; - } - - if (errors_enc == 0) - { - if (play_on_end == true) play_end(); - } - else if (play_on_end == true) System.Media.SystemSounds.Asterisk.Play(); - - if (this.ContainsFocus == false) - { - if (errors_enc == 0 && warn_enc == 0) - { - notifyIcon1.BalloonTipText = Strings.enc_comp; - notifyIcon1.BalloonTipIcon = ToolTipIcon.Info; - notifyIcon1.BalloonTipTitle = Strings.enc_comp2; - notifyIcon1.ShowBalloonTip(0); - } - if (errors_enc > 0) - { - notifyIcon1.BalloonTipText = Strings.enc_comp3 + " " + errors_enc.ToString() + " " + Strings.errors1; - notifyIcon1.BalloonTipIcon = ToolTipIcon.Warning; - notifyIcon1.BalloonTipTitle = Strings.enc_comp2; - notifyIcon1.ShowBalloonTip(0); - } - if (errors_enc == 0 && warn_enc > 0) - { - if (errors_enc == 0 && warn_enc > 0) - { - notifyIcon1.BalloonTipText = Strings.enc_warns; - notifyIcon1.BalloonTipIcon = ToolTipIcon.Warning; - notifyIcon1.BalloonTipTitle = Strings.enc_comp2; - notifyIcon1.ShowBalloonTip(0); - } - } - } - - if (chk_open_compl.Checked == true && opened_m == false) - { - opened_m = true; - try - { - if (Directory.GetFiles(destino2).Length != 0) - { - Process open_processed = new Process(); - open_processed.StartInfo.FileName = "explorer.exe"; - open_processed.StartInfo.Arguments = '\u0022' + multi_dest + '\u0022'; - open_processed.Start(); - } - else - { - if (Directory.Exists(destino2)) - { - Directory.Delete(destino2); - } - } - } - catch - { - } - } - - return; - } - else - { - if (aborted == true) - { - aborted = false; - MessageBox.Show(Strings.queue_abort, Strings.task_abort, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - } - cancelados_paralelos = false; - } - } - - private void timer_selecs_Tick(object sender, EventArgs e) - { - Double weight = 0; - Double dg_multi_prog = 0; - total_multi_duration = 0; - - foreach (int i in selecs) - { - DateTime time2; - if (DateTime.TryParse(listView1.Items[i].SubItems[3].Text, out time2)) - { - total_multi_duration = total_multi_duration + TimeSpan.Parse(listView1.Items[i].SubItems[3].Text).TotalSeconds - TimeSpan.Parse(ss_time_input.Text).TotalSeconds; - } - } - - Pg1.Maximum = selecs.Count * 100; - start_total_time = start_total_time + 0.5; - - try - { - TimeSpan t9 = TimeSpan.FromSeconds(start_total_time); - String tx_elapsed = string.Format("{0:D2}h:{1:D2}m:{2:D2}s", - t9.Hours, - t9.Minutes, - t9.Seconds); - lbl_elapsed.Text = Strings.time_elapsed + " " + tx_elapsed; - - - foreach (int i in selecs) - { - if (listView1.Items[i].SubItems[5].Text != Strings.queued) - { - if (listView1.Items[i].SubItems[3].Text == Strings.n_a) - { - weight = 1 / selecs.Count; - } - else - { - weight = (TimeSpan.Parse(listView1.Items[i].SubItems[3].Text).TotalSeconds - TimeSpan.Parse(ss_time_input.Text).TotalSeconds) / total_multi_duration; - } - - if (listView1.Items[i].SubItems[5].Text.Contains("%") == true && cancelados_paralelos == false) - { - if (listView1.Items[i].SubItems[5].Text.Contains(".0") || listView1.Items[i].SubItems[5].Text.Contains(",0")) - { - dg_multi_prog = dg_multi_prog + Convert.ToDouble(listView1.Items[i].SubItems[5].Text.Replace("%", "")) / 10 * weight * selecs.Count; - } - else - { - dg_multi_prog = dg_multi_prog + Convert.ToDouble(listView1.Items[i].SubItems[5].Text.Replace("%", "")) * weight * selecs.Count; - } - } - - if (listView1.Items[i].SubItems[5].Text == Strings.success || listView1.Items[i].SubItems[5].Text == Strings.failed || listView1.Items[i].SubItems[5].Text == Strings.aborted || listView1.Items[i].SubItems[5].Text == Strings.aborting || listView1.Items[i].SubItems[5].Text == Strings.skipped || listView1.Items[i].SubItems[5].Text == Strings.replaced || listView1.Items[i].SubItems[5].Text == Strings.not_replaced || listView1.Items[i].SubItems[5].Text == Strings.recycled || listView1.Items[i].SubItems[5].Text == Strings.not_recycled || listView1.Items[i].SubItems[5].Text == Strings.deleted || listView1.Items[i].SubItems[5].Text == Strings.not_deleted || listView1.Items[i].SubItems[5].Text == "OK & Run" || listView1.Items[i].SubItems[5].Text == "OK & Error") - { - dg_multi_prog = dg_multi_prog + (100 * weight * selecs.Count); - } - } - } - - if (time_n_tasks > 1) - { - if (Math.Round(dg_multi_prog / selecs.Count, 1).ToString().Contains(".") || Math.Round(dg_multi_prog / selecs.Count, 1).ToString().Contains(",")) - { - Pg1.Text = Math.Round(dg_multi_prog / selecs.Count, 1).ToString() + "%"; - } - else - { - Pg1.Text = Math.Round(dg_multi_prog / selecs.Count, 1).ToString() + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - } - - Pg1.Value = (int)(dg_multi_prog); - TaskbarProgress.SetValue(this.Handle, Convert.ToInt32(dg_multi_prog), Pg1.Maximum); - } - else - { - Pg1.Value = 0; - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - } - - if (Pg1.Value / selecs.Count > 0 && start_total_time > 4) - { - Double remain_secs = time_n_tasks * 100 / (Pg1.Value / selecs.Count) - start_total_time; - String remain_string = String.Empty; - - TimeSpan t = TimeSpan.FromSeconds(remain_secs); - remain_string = string.Format("{0:D2}h:{1:D2}", - t.Hours, - t.Minutes); - - if (remain_secs >= 43200) - { - txt_remain.Text = Strings.remain_time + " " + Math.Round(remain_secs / 3600).ToString() + " " + Strings.hours; - this.InvokeEx(f => this.Text = Pg1.Text + " / " + Math.Round(remain_secs / 3600).ToString() + " " + Strings.hours); - } - - if (remain_secs >= 3600 && remain_secs < 43200) - { - txt_remain.Text = Strings.remain_time + " " + remain_string + " " + Strings.minutes_abrev; - this.InvokeEx(f => this.Text = Pg1.Text + " / " + remain_string + " " + Strings.minutes_abrev); - } - - if (remain_secs < 3600 && remain_secs >= 600) - { - txt_remain.Text = Strings.remain_time + " " + remain_string.Substring(remain_string.LastIndexOf(":") + 1, 2) + " " + Strings.minutes; - this.InvokeEx(f => this.Text = Pg1.Text + " / " + remain_string.Substring(remain_string.LastIndexOf(":") + 1, 2) + " " + Strings.minutes_abrev); - } - if (remain_secs < 600 && remain_secs >= 120) - { - txt_remain.Text = Strings.remain_time + " " + remain_string.Substring(remain_string.LastIndexOf(":") + 2, 1) + " " + Strings.minutes; - this.InvokeEx(f => this.Text = Pg1.Text + " / " + remain_string.Substring(remain_string.LastIndexOf(":") + 2, 1) + " " + Strings.minutes_abrev); - } - - if (remain_secs < 120 && remain_secs > 59) - { - txt_remain.Text = Strings.remain_time + " " + Strings.about_1; - this.InvokeEx(f => this.Text = Pg1.Text + " / " + remain_string.Substring(remain_string.LastIndexOf(":") + 2, 1) + " " + Strings.minutes_abrev); - } - - if (remain_secs <= 59) - { - txt_remain.Text = Strings.remain_time + " " + Strings.less_one; - this.InvokeEx(f => this.Text = Pg1.Text + " / " + Convert.ToInt16(Math.Abs(remain_secs)) + " s"); - } - if (remain_secs <= 0) - { - txt_remain.Text = Strings.remain_time + " " + Strings.almost_done; - this.InvokeEx(f => this.Text = Pg1.Text + " / " + Strings.almost_done); - } - txt_remain.Refresh(); - Decimal speeds = 0; - Decimal fps = 0; - String sep = System.Globalization.CultureInfo.CurrentUICulture.NumberFormat.NumberDecimalSeparator; - - try - { - Decimal deci = 0; - - foreach (String str in multi_speeds) - { - if (str.Contains(sep)) - { - deci = Convert.ToDecimal(str, CultureInfo.CurrentUICulture); - } - else - { - if (str.Contains(",")) deci = Convert.ToDecimal(str.Replace(",", ".")); - else deci = Convert.ToDecimal(str.Replace(".", ",")); - } - speeds = Math.Round(Decimal.Add(speeds, deci), 2); - } - } - catch (Exception excpt) - { - speeds = 0; - } - - try - { - Decimal deci = 0; - foreach (String str in multi_fps) - { - if (str.Contains(sep)) - { - deci = Convert.ToDecimal(str, CultureInfo.CurrentUICulture); - fps = Decimal.Add(fps, deci); - } - else - { - if (str.Contains(",")) deci = Convert.ToDecimal(str.Replace(",", ".")); - else deci = Convert.ToDecimal(str.Replace(".", ",")); - fps = Decimal.Add(fps, deci); - } - } - } - catch { fps = 0; } - - String fps_perf = fps.ToString(); - if (fps_perf == "0") - { - lbl_speed.Text = Strings.speed + " " + speeds.ToString() + "x"; - } - else - { - lbl_speed.Text = Strings.speed + " " + speeds.ToString() + "x" + " | " + fps_perf.TrimEnd() + " fps"; - } - } - else - { - txt_remain.Text = Strings.remain_time + " " + Strings.calcul; - txt_remain.Refresh(); - } - if (cancelados_paralelos == true) - { - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - } - } - catch - { - txt_remain.Text = Strings.remain_time + " " + Strings.calcul; - txt_remain.Refresh(); - } - } - - private void ctm1_encode_Click(object sender, EventArgs e) - { - Pg1.Focus(); - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - - was_started.Text = btn_multi_m.Text; - - cancelados_paralelos = false; - - - if (no_warn_0_dur == false) - { - foreach (ListViewItem file in listView1.SelectedItems) - { - if (!File.Exists(file.SubItems[1].Text + "\\" + file.Text)) - { - MessageBox.Show(Strings.file_not_found + " " + file.Text, Strings.file_not_found2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - } - - if (listView1.SelectedItems.Count == 0) - { - MessageBox.Show(Strings.no_f_sel, Strings.no_files, MessageBoxButtons.OK, MessageBoxIcon.Information); - return; - } - - if (!File.Exists(Path.Combine(Application.StartupPath, "ffmpeg.exe"))) - { - MessageBox.Show(Strings.no_ffmpeg, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (check_ff_md5() == false) - { - Form25 frm25 = new Form25(); - frm25.ShowDialog(); - return; - } - - if (ss_time_input.Text != "0:00:00") - { - foreach (ListViewItem item in listView1.SelectedItems) - { - if (item.SubItems[3].Text != Strings.n_a && item.SubItems[3].Text != "0:00:00" && item.SubItems[3].Text != "00:00:00" && item.SubItems[3].Text != Strings.pending && Settings.Default.quick_queue == false) - { - if (TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds <= TimeSpan.Parse(ss_time_input.Text).TotalSeconds) - { - MessageBox.Show(Strings.pre_input3 + " " + '\u0022' + Path.GetFileName(item.Text) + '\u0022', Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - } - } - - if (dur_ok == false) - { - list_pending_dur.Clear(); - foreach (ListViewItem item in listView1.SelectedItems) - { - list_pending_dur.Items.Add((ListViewItem)item.Clone()); - } - BG_Dur.RunWorkerAsync(); - return; - } - - avoid_overw(); - - //Check path is writable - String destino1 = String.Empty; - Boolean rel_path = false; - String lv1 = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - if (txt_path_main.Text.Contains(".\\")) - { - destino1 = lv1.Substring(0, lv1.LastIndexOf('\\')) + txt_path_main.Text.Replace(".", String.Empty); - rel_path = true; - } - else - { - if (chk_recreate.CheckState == CheckState.Checked) - { - String pre_dest = Path.GetDirectoryName(lv1); - destino1 = Path.Combine(txt_path_main.Text, pre_dest.Substring(3, pre_dest.Length - 3)); - rel_path = true; - } - else - { - destino1 = txt_path_main.Text; - } - } - - try - { - if (rel_path == true) - { - Directory.CreateDirectory(destino1); - System.Threading.Thread.Sleep(10); - } - else - { - if (!Directory.Exists(destino1)) Directory.CreateDirectory(destino1); - File.WriteAllText(destino1 + "\\" + "FFBatch_test.txt", "FFBatch_test"); - System.Threading.Thread.Sleep(10); - File.Delete(destino1 + "\\" + "FFBatch_test.txt"); - } - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.write_error1 + " " + excpt.Message, Strings.write_error2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - //End path is writable - - if (selected_enc() == true && ignore_encoded == true) return; - - //Validated list, start processing - - if (fade_v_in.Checked == true || fade_v_out.Checked == true || fade_a_in.Checked == true || fade_a_out.Checked == true) - { - MessageBox.Show(Strings.fadein1, Strings.warning, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; - } - - txt_remain.Text = ""; - txt_remain.Refresh(); - total_time = true; - n_th_suffix = String.Empty; - n_th_source_ext = String.Empty; - - //Save selected hw decoder - - String path2 = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_hw_dcd.ini"; - if (is_portable == true) - { - path2 = port_path + "ff_hw_dcd_portable.ini"; - } - String txt_hw_dcd = cb_hwdecode.SelectedItem.ToString(); - if (txt_hw_dcd != "none") - { - File.WriteAllText(path2, txt_hw_dcd); - } - else - { - if (File.Exists(path2)) File.Delete(path2); - } - - //End save hw decoder - - //Remove test file/folder - String file_prueba = ""; - String sel_test = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - file_prueba = sel_test; - String destino = Path.GetTempPath() + "\\" + "FFBatch_test"; - String borrar = destino + "\\" + Path.GetFileNameWithoutExtension(file_prueba) + "." + txt_format.Text; - - if (File.Exists(borrar)) - { - try - { - File.Delete(borrar); - } - catch { } - } - - if (Directory.Exists(destino) == true) - { - if (Directory.GetFiles(destino).Length == 0) - { - try - { - Directory.Delete(destino); - } - catch { } - } - } - - //END Remove test file/folder - - //END try preset - - //Save selected theads - - String path = String.Empty; - if (is_portable == false) - { - path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_nthreads.ini"; - } - else - { - path = port_path + "ff_nthreads_portable.ini"; - } - - String txt_threads = String.Empty; - txt_threads = n_threads.Value.ToString(); - File.WriteAllText(path, txt_threads); - //End save selected threads - - //Pending duration - - if (avoid_overwriting == true && txt_path_main.Text.Contains(".\\") == false && txt_path_main.Text.Length < 4 && chk_recreate.CheckState != CheckState.Checked) - { - avoid_overwriting = false; - DialogResult a2 = MessageBox.Show(Strings.multiple_folders + " " + '\u0022' + Strings.recreate_path + '\u0022' + " " + Strings.avoid_overw + Environment.NewLine + Environment.NewLine + Strings.continu, Strings.dif_in_out_f, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); - if (a2 == DialogResult.No) return; - } - - //Check queued items - - if (warn_success_items == true) - { - //Boolean all_complete = true; - Boolean has_complete = false; - foreach (ListViewItem item in listView1.SelectedItems) - { - if (item.SubItems[5].Text != Strings.queued) - { - has_complete = true; - break; - } - } - - if (has_complete == true) - { - DialogResult a = MessageBox.Show(Strings.already_encoded + " " + '\u0022' + Strings.queued + '\u0022' + " " + Strings.reset_items + Environment.NewLine + Environment.NewLine + Strings.cont_any, Strings.some_q, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); - if (a == DialogResult.Cancel || a == DialogResult.No) - { - return; - } - } - } - else - { - foreach (ListViewItem item in listView1.SelectedItems) item.SubItems[5].Text = Strings.queued; - } - //End check queued items - - if (chk_overw.Checked == true && txt_path_main.Text != "." + "\\") - { - DialogResult a = MessageBox.Show(Strings.overw_out, Strings.out_warn, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); - if (a != DialogResult.Yes) return; - } - - //Verify names will not cause overwrite - if (txt_format.Text != String.Empty) - { - if (dups_lv1() == true) return; - } - - String is_overw = txt_path_main.Text + "\\" + Path.GetFileNameWithoutExtension(listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text) + "." + txt_format.Text; - - if (is_overw == listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text && chk_suffix.Checked == false) - { - if (chk_overw.CheckState == CheckState.Unchecked) - { - MessageBox.Show(Strings.overw_not_en + " " + '\u0022' + Strings.ren_out + '\u0022' + " " + Strings.checkb, Strings.overw_not_all, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (chk_overw.CheckState == CheckState.Checked) - { - DialogResult a = MessageBox.Show(Strings.overw_confirm, Strings.over_conf2, MessageBoxButtons.YesNo, MessageBoxIcon.Question); - if (a == DialogResult.No) - { - return; - } - } - } - - if (txt_parameters.Text.Contains("libx264") || txt_parameters.Text.Contains("libx265") || txt_parameters.Text.Contains("jpeg2000") || txt_parameters.Text.Contains("libtheora") || txt_parameters.Text.Contains("libxvid") || txt_parameters.Text.Contains("mpeg2") || txt_parameters.Text.Contains("webp") || txt_parameters.Text.Contains("mpeg4") || txt_parameters.Text.Contains("libvpx") || txt_parameters.Text.Contains("prores")) - { - if (n_threads.Value > 4 && listView1.SelectedItems.Count > 4) - { - DialogResult a = MessageBox.Show(Strings.multi_vid, Strings.question, MessageBoxButtons.YesNo, MessageBoxIcon.Question); - if (a == DialogResult.No) return; - } - } - - filter_chars(); - - cancel_queue = false; - cancelados_paralelos = false; - - listBox4.Items.Clear(); - group_prog.Focus(); - - //Total duration - - total_multi_duration = 0; - foreach (ListViewItem item in listView1.SelectedItems) - { - DateTime time2; - if (DateTime.TryParse(item.SubItems[3].Text, out time2)) - - { - total_multi_duration = total_multi_duration + TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds; - } - } - //End total duration - LB_Wait.Text = String.Empty; - LB_Wait.Visible = false; - pg_adding.Visible = false; - txt_adding_p.Text = String.Empty; - multi_dest = destino; - - notifyIcon1.Visible = true; - Pg1.Value = 0; - Pg1.Maximum = listView1.SelectedItems.Count * 100; - Pg1.Text = ""; - lbl_elapsed.Text = Strings.time_elapsed + " " + "00h:00m:00s"; - - start_total_time = 0; - time_n_tasks = 0; - timer_tasks.Start(); - timer_selecs.Start(); - multi_running = true; - - listView1.SelectedItems[0].Selected = true; - pic_no_errors.Visible = false; - pic_warnings.Visible = false; - pic_recording.Visible = false; - errors_enc = 0; - working = true; - selecs.Clear(); - foreach (ListViewItem item in listView1.Items) - { - if (item.Selected == true) - { - selecs.Add(item.Index); - } - } - - //Custom item params - custom_m_params.Clear(); - if (cust_p_col != 0) - { - try - { - foreach (ListViewItem it in listView1.Items) - { - custom_m_params.Add(it.SubItems[cust_p_col].Text); - } - } - catch { } - } - - //End custom item params - - lbl_items.Text = "0 " + Strings.of1 + " " + listView1.SelectedItems.Count.ToString(); - timer_queue.Enabled = true; - BG_Selected_items.RunWorkerAsync(); - } - - void filter_chars() - { - this.Invoke(new MethodInvoker(delegate - { - - Boolean change_name = false; - Boolean filter_txt = false; - String pr = txt_parameters.Text; - String[] variabs = new string[] { "%1", "%2", "%fn", "%ff" }; - if (pr.Contains("-vf") || pr.Contains("-af") || pr.Contains("-vfilter") || pr.Contains("-afilter") || pr.Contains("-filter:v") || pr.Contains("-filter:a")) - { - foreach (String item in variabs) - { - if (pr.Contains(item.ToLower())) - { - filter_txt = true; - break; - } - } - - } - foreach (ListViewItem file2 in listView1.Items) - { - if (file2.Text.Contains("[") || file2.Text.Contains("]") || file2.Text.Contains(",") || file2.Text.Contains("'")) - { - change_name = true; - break; - } - } - - - if (change_name == false || filter_txt == false) return; - - this.Enabled = false; - DialogResult a = MessageBox.Show(Strings.ren_chars1 + Environment.NewLine + Environment.NewLine + Strings.ren_chars2, Strings.ren_chars3, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); - if (a == DialogResult.Yes) - { - this.Enabled = false; - foreach (ListViewItem item in listView1.Items) - { - if (item.Text.Contains("[") || item.Text.Contains("]") || item.Text.Contains(",") || item.Text.Contains("'")) - { - String file = item.Text; - String file_ren = file.Replace("[", "(").Replace("]", ")").Replace(",", "_").Replace("'", "_"); - String path = item.SubItems[1].Text + "\\"; - file = path + file; - file_ren = path + file_ren; - File.Move(file, file_ren); - item.Text = Path.GetFileName(file_ren); - } - } - this.Enabled = true; - } - else this.Enabled = true; - })); - } - - Boolean all_enc() - { - Boolean filter = false; - if (txt_parameters.Text.Contains("-vf") || txt_parameters.Text.Contains("-af") || txt_parameters.Text.Contains("-vflter") || txt_parameters.Text.Contains("-afilterf") || txt_parameters.Text.Contains("-filter:v") || txt_parameters.Text.Contains("-filter:a")) filter = true; - if (filter = false) return false; - - foreach (ListViewItem file2 in listView1.Items) - { - if (file2.SubItems[5].Text != Strings.success) - { - return false; - } - } - return true; - } - - Boolean all_enc_watch() - { - foreach (ListViewItem file2 in listView1.Items) - { - if (file2.SubItems[5].Text != Strings.success) - { - return false; - } - } - return true; - } - - Boolean selected_enc() - { - foreach (ListViewItem file2 in listView1.SelectedItems) - { - if (file2.SubItems[5].Text != Strings.success) - { - return false; - } - } - return true; - } - - private Boolean to_overwrite() - { - Boolean do_match = false; - Boolean match_case = false; - - String dest = txt_path_main.Text; - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[1].Text == dest) - { - do_match = true; - break; - } - } - foreach (ListViewItem item in listView1.Items) - { - if (Path.GetExtension(item.Text).ToLower() == "." + txt_format.Text) - { - if (Path.GetExtension(item.Text) != "." + txt_format.Text) - match_case = true; - break; - } - } - - if ((chk_overw.Checked == true && txt_path_main.Text != "." + "\\")) - { - if (do_match == false) - { - DialogResult a = MessageBox.Show(Strings.overw_out, Strings.out_warn, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); - if (a != DialogResult.Yes) return false; - else return true; - } - } - - if ((chk_overw.Checked == false && txt_path_main.Text == "." + "\\") && !txt_parameters.Text.Contains("[[split_chapters]]")) - { - //if (match_case == true) - //{ - // MessageBox.Show("File matching output destination format with different case." + Environment.NewLine + "Please match input extension and output format case."); - // return false; - //} - - } - - return true; - } - - private void btn_seq_Click(object sender, EventArgs e) - { - Pg1.Focus(); - lbl_est_size.Text = ""; - lbl_bitrate.Text = ""; - current_out = ""; - - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - LB_Wait.Visible = false; - - was_started.Text = btn_seq.Text; - cancel_queue = false; - notifyIcon1.Visible = true; - - if (listView1.Items.Count == 0) - { - MessageBox.Show(Strings.list_empty, Strings.no_files, MessageBoxButtons.OK, MessageBoxIcon.Information); - return; - } - - if (!File.Exists(Path.Combine(Application.StartupPath, "ffmpeg.exe"))) - { - MessageBox.Show(Strings.no_ffmpeg, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (check_ff_md5() == false) - { - Form25 frm25 = new Form25(); - frm25.ShowDialog(); - return; - } - - if (listView1.SelectedIndices.Count == 0) - { - listView1.Items[0].Selected = true; - listView1.Items[0].Focused = true; - listView1.Focus(); - } - - if (no_warn_0_dur == false) - { - String filename1 = ""; - foreach (ListViewItem file2 in listView1.Items) - { - filename1 = file2.SubItems[1].Text + "\\" + file2.Text; - if (!File.Exists(filename1)) - { - MessageBox.Show(Strings.file_not_found + " " + file2.Text, Strings.file_not_found2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - } - - DateTime time2; - if (!DateTime.TryParse(ss_time_input.Text, out time2)) - { - MessageBox.Show(Strings.pre_input1, Strings.pre_input2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (ss_time_input.Text != "0:00:00:000" && Settings.Default.quick_queue == false) - { - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[3].Text != Strings.n_a && item.SubItems[3].Text != "0:00:00" && item.SubItems[3].Text != "00:00:00" && item.SubItems[3].Text != Strings.pending && Settings.Default.quick_queue == false) - { - if (TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds <= TimeSpan.Parse(ss_time_input.Text).TotalSeconds) - { - MessageBox.Show(Strings.pre_input3 + " " + '\u0022' + Path.GetFileName(item.Text) + '\u0022', Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - } - } - - DateTime time; - if (!DateTime.TryParse(ss_time_input.Text, out time)) - { - MessageBox.Show(Strings.pre_input1, Strings.pre_input2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - avoid_overw(); - - //Check path is writable - String destino1 = String.Empty; - Boolean rel_path = false; - String filename = listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text; - if (txt_path_main.Text.Contains(".\\")) - { - destino1 = filename.Substring(0, filename.LastIndexOf('\\')) + txt_path_main.Text.Replace(".", String.Empty); - rel_path = true; - } - else - { - if (chk_recreate.CheckState == CheckState.Checked) - { - String pre_dest = Path.GetDirectoryName(filename); - if (pre_dest.Substring(0, 2) == "\\\\") destino1 = Path.Combine(txt_path_main.Text, pre_dest.Substring(2, pre_dest.Length - 2)); - else destino1 = Path.Combine(txt_path_main.Text, pre_dest.Substring(3, pre_dest.Length - 3)); - rel_path = true; - } - else - { - destino1 = txt_path_main.Text; - } - } - - try - { - if (rel_path == true) - { - Directory.CreateDirectory(destino1); - System.Threading.Thread.Sleep(10); - } - else - { - if (!Directory.Exists(destino1)) Directory.CreateDirectory(destino1); - File.WriteAllText(destino1 + "\\" + "FFBatch_test.txt", "FFBatch_test"); - System.Threading.Thread.Sleep(10); - File.Delete(destino1 + "\\" + "FFBatch_test.txt"); - } - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.write_error1 + " " + excpt.Message, Strings.write_error2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - //End path is writable - - if (all_enc() == true && ignore_encoded == true) return; - - - //Validated list, start processing - if ((fade_v_in.Checked == true && num_v_in.Value == 0) || (fade_v_out.Checked == true && num_v_out.Value == 0) || (fade_a_in.Checked == true && num_a_in.Value == 0) || (fade_a_out.Checked == true && num_a_out.Value == 0)) - { - MessageBox.Show(Strings.fading_zero, Strings.fading_zero2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - txt_remain.Text = Strings.remain_time + " " + "00h:00m:00s"; - - foreach (String item in tried_params) - { - if (item == (txt_parameters.Text)) - { - tried_ok = true; - } - } - - if (tried_ok == false) - { - try - { - BG_Try_preset.RunWorkerAsync(); - } - catch - { - tried_ok = true; - } - - return; - } - tried_ok = false; - - //Remove test file/folder - - String file_prueba = ""; - String sel_test = filename; - file_prueba = sel_test; - String destino = Path.GetTempPath() + "\\" + "FFBatch_test"; - String borrar = destino + "\\" + Path.GetFileNameWithoutExtension(file_prueba) + "." + txt_format.Text; - - if (File.Exists(borrar)) - { - try - { - File.Delete(borrar); - } - catch { } - } - - //Pending duration - - if (dur_ok == false) - { - list_pending_dur.Items.Clear(); - foreach (ListViewItem item in listView1.Items) - { - list_pending_dur.Items.Add((ListViewItem)item.Clone()); - } - BG_Dur.RunWorkerAsync(); - return; - } - - if (avoid_overwriting == true && txt_path_main.Text.Contains(".\\") == false && txt_path_main.Text.Length < 4 && chk_recreate.CheckState != CheckState.Checked) - { - avoid_overwriting = false; - DialogResult a2 = MessageBox.Show(Strings.multiple_folders + " " + '\u0022' + Strings.recreate_path + '\u0022' + " " + "to avoid opossible overwritings." + Environment.NewLine + Environment.NewLine + Strings.continu, "Different input folders to single output folder", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); - if (a2 == DialogResult.No) return; - } - - //Verify names will not cause overwriting - - if (txt_format.Text != String.Empty && dups_lv1() == true) - { - return; - } - - filter_chars(); - - String is_overw = txt_path_main.Text + "\\" + Path.GetFileNameWithoutExtension(listView1.Items[0].Text) + "." + txt_format.Text; - - if (is_overw == listView1.Items[0].Text && chk_suffix.Checked == false) - { - if (chk_overw.CheckState == CheckState.Unchecked) - { - MessageBox.Show(Strings.overw_not_en + " " + '\u0022' + Strings.ren_out + '\u0022' + " " + Strings.checkb, Strings.overw_not_all, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (chk_overw.CheckState == CheckState.Checked) - { - DialogResult a = MessageBox.Show(Strings.overw_confirm, Strings.over_conf2, MessageBoxButtons.YesNo, MessageBoxIcon.Question); - if (a == DialogResult.No) - { - return; - } - } - } - - //Check queued items - if (warn_success_items == true) - { - //Boolean all_complete = true; - Boolean has_complete = false; - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[5].Text == Strings.success || item.SubItems[5].Text == Strings.replaced) - { - has_complete = true; - break; - } - } - if (has_complete == true) - { - DialogResult a = MessageBox.Show(Strings.already_encoded + " " + '\u0022' + Strings.queued + '\u0022' + " " + Strings.reset_items + Environment.NewLine + Environment.NewLine + Strings.cont_any, Strings.some_q, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); - if (a == DialogResult.Cancel || a == DialogResult.No) return; - } - } - //End check queued items - - if (to_overwrite() == false) return; - - if (images_from_wiz == true) - { - Double t_to = Convert.ToDouble(img_dur_wiz); - TimeSpan t1 = TimeSpan.FromSeconds((t_to)); - String tx_1 = string.Format("{0:D2}:{1:D2}:{2:D2}", - t1.Hours, - t1.Minutes, - t1.Seconds); - foreach (ListViewItem ite in listView1.Items) ite.SubItems[3].Text = tx_1; - images_from_wiz = false; - } - - timer_tasks.Enabled = true; - timer_tasks.Start(); - - if (BG_Seq.IsBusy) - { - BG_Seq.Dispose(); - return; - } - atempo = String.Empty; - if (txt_parameters.Text.ToLower().Contains("atempo=")) - { - int at_ind = txt_parameters.Text.LastIndexOf("atempo=") + 7; - int at_end = 0; - Boolean end_char = false; - - for (int i = 0; i < txt_parameters.Text.Length - at_ind; i++) - { - if (txt_parameters.Text.Substring(at_ind + i, 1) == "," || txt_parameters.Text.Substring(at_ind + i, 1) == "\u0022" || txt_parameters.Text.Substring(at_ind + i, 1) == "'" || txt_parameters.Text.Substring(at_ind + i, 1) == " " || txt_parameters.Text.Substring(at_ind + i, 1) == "[") - { - at_end = at_ind + i; - end_char = true; - break; - } - } - - if (end_char == true) atempo = txt_parameters.Text.Substring(at_ind, at_end - at_ind); - else if (at_ind + 2 == txt_parameters.Text.Length) - { - atempo = txt_parameters.Text.Substring(at_ind, 2); - } - else if (at_ind + 3 == txt_parameters.Text.Length) - { - atempo = txt_parameters.Text.Substring(at_ind, 3); - } - - else if (at_ind + 4 == txt_parameters.Text.Length) - { - atempo = txt_parameters.Text.Substring(at_ind, 4); - } - else atempo = String.Empty; - } - lbl_items.Text = "0 " + Strings.of1 + " " + listView1.Items.Count.ToString(); - timer_queue.Enabled = true; - - total_duration = 0; - total_prog = 0; - - ss_to = false; - if (txt_pre_input.Text.Contains("-ss") || txt_pre_input.Text.Contains("-t")) ss_to = true; - int new_ssto = 0; - - //Get total duration of files - - - foreach (ListViewItem item in listView1.Items) - { - if (Settings.Default.quick_queue == true) - { - //total_duration = total_duration + 0; - continue; - } - if (item.SubItems[3].Text != Strings.n_a && item.SubItems[3].Text != "0:00:00" && item.SubItems[3].Text != "00:00:00" && item.SubItems[3].Text != Strings.pending && ignore_encoded == false || (ignore_encoded == true && item.SubItems[5].Text != Strings.success)) - { - if (ss_to == true) - { - new_ssto = get_ss_to(txt_pre_input.Text, TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds); - - if (new_ssto > 0) total_duration = total_duration + new_ssto - TimeSpan.Parse(ss_time_input.Text).TotalSeconds; - else total_duration = total_duration + TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds - TimeSpan.Parse(ss_time_input.Text).TotalSeconds; - } - else total_duration = total_duration + TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds - TimeSpan.Parse(ss_time_input.Text).TotalSeconds; - } - else - { - total_duration = total_duration + 0; - } - } - - atemp = 1; - if (atempo != String.Empty) - { - if (Double.TryParse(atempo, out atemp) == true) - { - atemp = Convert.ToDouble(atempo, System.Globalization.CultureInfo.InvariantCulture); - total_duration = total_duration / atemp; - } - } - - Pg1.Minimum = 0; - Pg1.Maximum = 100; - lbl_elapsed.Text = Strings.time_elapsed + " " + "00h:00m:00s"; - - BG_Seq.RunWorkerAsync(); - } - - private void BG_Seq_DoWork(object sender, DoWorkEventArgs e) - { - String destino = ""; - cancel_queue = false; - Disable_Controls(); - this.Invoke(new MethodInvoker(delegate - { - Pg1.Value = 0; - pic_no_errors.Visible = false; - pic_warnings.Visible = false; - pic_recording.Visible = false; - btn_skip_main.Enabled = true; - btn_try_pr.Image = img_try.Images[1]; - })); - - working = true; - aborted = false; - - String hw_decode = String.Empty; - - //Detect network files - ask_cache_net = true; - Boolean cache_net = false; - Boolean file_is_network1 = false; - if (no_save_cache == false) - { - listView1.Invoke(new MethodInvoker(delegate - { - foreach (ListViewItem item in listView1.Items) - { - try - { - DriveInfo driveInfo = new DriveInfo(item.SubItems[1].Text + "\\" + item.Text); - if (driveInfo.DriveType == DriveType.Network) - { - file_is_network1 = true; - if (ask_cache_net == true && file_is_network1 == true) - { - ask_cache_net = false; - DialogResult a = MessageBox.Show(Strings.queue_net, Strings.net_cach, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); - cache_net = a == DialogResult.Yes; - } - break; - } - } - catch - { - file_is_network1 = item.SubItems[1].Text.Substring(0, 1) == ("\\"); - if (ask_cache_net == true && file_is_network1 == true) - { - ask_cache_net = false; - DialogResult a = MessageBox.Show(Strings.queue_net, Strings.net_cach, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); - cache_net = a == DialogResult.Yes; - } - } - //End detect network files - } - - })); - } - else - { - cache_net = false; - } - - String txt_hw_dcd = ""; - cb_hwdecode.Invoke(new MethodInvoker(delegate - { - if (cb_hwdecode.SelectedItem.ToString() != "none") - { - hw_decode = "-hwaccel " + cb_hwdecode.SelectedItem.ToString(); - } - - txt_hw_dcd = cb_hwdecode.SelectedItem.ToString(); - - //End save hw decoder - })); - - // Fade validation - fade_ok = true; - check_fade(); - if (fade_ok == false) - { - Enable_Controls(); - return; - } - // END Fade validation - - String remain_time = "0"; - //End get total duration of files - - List list_lines = new List(); - List list_successful = new List(); - List list_failed = new List(); - procs.Clear(); - - for (int ii = 0; ii < listView1.Items.Count; ii++) - { - procs.Add("proc_urls_" + ii.ToString(), new Process()); - } - - time_n_tasks = 0; - timer_tasks.Start(); - timer_est_size.Start(); - time_est_size = 0; - String file = String.Empty; - - Boolean refresh_list = false; - - - String f_in_color = "Black"; - String f_out_color = "Black"; - String in_color = ":color=" + f_in_color; - String out_color = ":color=" + f_out_color; - - this.Invoke(new MethodInvoker(delegate - { - btn_add_files.Enabled = true; - btn_add_folders.Enabled = true; - chk_subfolders.Enabled = true; - panel2.Enabled = true; - chk_delete_source.Enabled = true; - - foreach (Control ct in panel2.Controls) - { - if (ct.Name != chk_delete_source.Name) - { - ct.Enabled = false; - } - } - if (combo_vin_col.SelectedIndex == 1) f_in_color = "White"; - if (combo_vout_color.SelectedIndex == 1) f_out_color = "White"; - if (combo_vin_col.SelectedIndex == 2) in_color = ":alpha=1"; - if (combo_vout_color.SelectedIndex == 2) out_color = ":alpha=1"; - })); - - //Save session variables - - String chk_suffix_state = String.Empty; - int warn_enc = 0; - - chk_suffix.Invoke(new MethodInvoker(delegate - { - if (chk_suffix.CheckState == CheckState.Unchecked) chk_suffix_state = "Unchecked"; - else - { - chk_suffix_state = txt_suffix.Text; - } - })); - - String saved_path = txt_path_main.Text; - errors_enc = 0; - - wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged); - wc.DownloadFileCompleted += new AsyncCompletedEventHandler(Extract); - - Decimal tot_frames2 = 0; - String avs_out = ""; - String status = ""; - timer_queue.Enabled = true; - - for (int list_index = 0; list_index < listView1.Items.Count; list_index++) - { - Double size_dur = 0; - Double file_size = 0; - Double dur_rpl = 0; - Double dur_rpl2 = 0; - String dur_fbit = String.Empty; - - DateTime file_crea = new DateTime(); - DateTime file_written = new DateTime(); - DateTime file_modif = new DateTime(); - - textbox_params = txt_parameters.Text; - String cust_output1 = String.Empty; - - String pre_input_var = ""; - if (txt_pre_input.Text != "") - { - pre_input_var = txt_pre_input.Text; - } - - var tmp = procs["proc_urls_" + list_index.ToString()]; - - listView1.Invoke(new MethodInvoker(delegate - { - //Custom item parameters - if (cust_p_col != 0) - { - try - { - if (listView1.Items[list_index].SubItems[cust_p_col].Text != "-") - { - int start = listView1.Items[list_index].SubItems[cust_p_col].Text.LastIndexOf("[["); - int end = listView1.Items[list_index].SubItems[cust_p_col].Text.LastIndexOf("]]"); - int cut = end - start + 2; - int length = listView1.Items[list_index].SubItems[cust_p_col].Text.Length; - textbox_params = listView1.Items[list_index].SubItems[cust_p_col].Text.Substring(0, length - cut); - if (start != -1 && end != -1) - { - cust_output1 = listView1.Items[list_index].SubItems[cust_p_col].Text.Substring(start + 2, cut - 4); - } - } - } - catch { } - } - //End custom item parameters - - - status = listView1.Items[list_index].SubItems[5].Text; - file = listView1.Items[list_index].SubItems[1].Text + "\\" + listView1.Items[list_index].Text; - if (File.Exists(file)) - { - TimeSpan tme; - if (TimeSpan.TryParse(listView1.Items[list_index].SubItems[3].Text, out tme)) - { - dur_rpl = TimeSpan.Parse(listView1.Items[list_index].SubItems[3].Text).TotalSeconds; - dur_rpl2 = TimeSpan.Parse(listView1.Items[list_index].SubItems[3].Text).TotalSeconds; - dur_fbit = listView1.Items[list_index].SubItems[3].Text; - } - else - { - dur_rpl = 0; - dur_rpl2 = 0; - dur_fbit = "00:00:00"; - } - - if (file.Substring(file.Length - 3, 3).ToLower() == "avs") - { - avs_out = Path.GetDirectoryName(file) + "\\" + Path.GetFileNameWithoutExtension(file) + "." + txt_format.Text; - if (!File.Exists(avs_out)) avs_out = file; - } - - FileInfo fs = new FileInfo(file); - file_size = fs.Length; - try - { - size_dur = TimeSpan.Parse(listView1.Items[list_index].SubItems[3].Text).TotalSeconds; - } - catch { size_dur = 0; } - } - })); - - if (!File.Exists(file)) - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.file_not_f); - continue; - } - - file_crea = File.GetCreationTime(file); - file_written = File.GetLastWriteTime(file); - file_modif = File.GetLastAccessTime(file); - - if (cancel_queue) - { - this.Invoke(new MethodInvoker(delegate - { - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - this.Text = "FFmpeg Batch AV Converter"; - if (is_portable) this.Text = "FFmpeg Batch AV Converter Portable"; - })); - - working = false; - time_est_size = 0; - Enable_Controls(); - //MessageBox.Show(Strings.queue_abort, Strings.task_abort, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; - } - - // Average frames - int fframes = 0; - Decimal dec = 0; - try - { - String ff_frames1 = String.Empty; - - Process get_frames1 = new Process(); - get_frames1.StartInfo.FileName = Path.Combine(Application.StartupPath, "mediainfo.exe"); - String ffprobe_frames = "--Output=" + '\u0022' + "Video;%FrameCount%" + '\u0022'; - get_frames1.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + file + '\u0022'; - get_frames1.StartInfo.RedirectStandardOutput = true; - get_frames1.StartInfo.UseShellExecute = false; - get_frames1.StartInfo.CreateNoWindow = true; - get_frames1.EnableRaisingEvents = true; - get_frames1.Start(); - - ff_frames1 = get_frames1.StandardOutput.ReadLine(); - get_frames1.WaitForExit(); - - if (get_frames1.ExitCode == 0) - { - if (ff_frames1 != null) - { - dec = decimal.Parse(ff_frames1); - if (dec.ToString().Substring(dec.ToString().Length - 1, 1) == "0") dec = dec / 10; - } - else - { - dec = 0; - } - - get_frames1.Dispose(); - tot_frames2 = tot_frames2 + dec; - DateTime time2; - Double ss_secs = 0; - this.Invoke(new MethodInvoker(delegate - { - if (listView1.Items[list_index].SubItems[3].Text != Strings.n_a && listView1.Items[list_index].SubItems[3].Text != "-" && listView1.Items[list_index].SubItems[3].Text != Properties.Strings.pending) - { - if (DateTime.TryParse(ss_time_input.Text, out time2)) - { - ss_secs = TimeSpan.Parse(ss_time_input.Text).TotalSeconds / TimeSpan.Parse(listView1.Items[list_index].SubItems[3].Text).TotalSeconds; - } - try { tot_frames2 = tot_frames2 - (tot_frames2 * (decimal)ss_secs); } - catch { } - } - })); - } - } - catch - { - dec = 0; - } - - // End average frames - - //Detect network files - Boolean file_is_network = false; - try - { - DriveInfo driveInfo = new DriveInfo(Path.GetDirectoryName(file)); - file_is_network = driveInfo.DriveType == DriveType.Network; - } - catch - { - file_is_network = file.Substring(0, 1) == ("\\"); - } - //End detect network files - - this.InvokeEx(f => timer_est_size.Start()); - - String ffm = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - String fullPath = file; - - //Begin Shifting - String shifting = ""; - if (chk_shift.Checked == true) - { - shifting = " -itsoffset " + Num_Shift.Value.ToString().Replace(",", ".") + " -i " + '\u0022' + file + '\u0022' + " -map 1:v -map 0:a "; - } - //End Shifting - - //Begin fading and volume changing - String change_vol_fade = ""; - if (chk_vol.Checked == true) - { - change_vol_fade = "-af " + '\u0022' + "volume=" + vol_ch.Value.ToString() + "dB " + '\u0022' + " "; - } - - String fade_filter = String.Empty; - Decimal fade_frames = 0; - String itfull = ""; - String ff_frames = String.Empty; - Process get_frames = new Process(); - - listView1.Invoke(new MethodInvoker(delegate - { - if (fade_v_in.CheckState == CheckState.Checked || fade_v_out.CheckState == CheckState.Checked) - { - itfull = listView1.Items[list_index].SubItems[1].Text + "\\" + listView1.Items[list_index].Text; - - get_frames.StartInfo.FileName = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - String ffprobe_frames = " " + '\u0022' + "--Inform=Video;%FrameRate%" + '\u0022'; - get_frames.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + itfull + '\u0022'; - get_frames.StartInfo.RedirectStandardOutput = true; - get_frames.StartInfo.UseShellExecute = false; - get_frames.StartInfo.CreateNoWindow = true; - get_frames.EnableRaisingEvents = true; - get_frames.Start(); - - ff_frames = get_frames.StandardOutput.ReadLine(); - get_frames.WaitForExit(); - - if (get_frames.ExitCode == 0) - { - if (ff_frames != null) - { - fade_frames = decimal.Parse(ff_frames) / 1000; - } - } - get_frames.Dispose(); - - if (fade_v_in.CheckState == CheckState.Checked && fade_v_out.CheckState == CheckState.Unchecked) - { - Decimal fff_in = Math.Round(num_v_in.Value * fade_frames, 0); - fade_filter = "-vf " + '\u0022' + "fade=in:0:" + fff_in.ToString() + in_color + '\u0022'; - } - - if (fade_v_in.CheckState == CheckState.Unchecked && fade_v_out.CheckState == CheckState.Checked) - { - Double dur_frames = TimeSpan.Parse(listView1.Items[list_index].SubItems[3].Text).TotalSeconds * Convert.ToDouble(fade_frames); - Decimal fade_out_total = Math.Round(Convert.ToDecimal(dur_frames), 3, MidpointRounding.AwayFromZero); - Decimal fade_out_initial = Math.Round(fade_out_total - (num_v_out.Value * fade_frames), 0, MidpointRounding.AwayFromZero); - Decimal fff_out = Math.Round(num_v_out.Value * fade_frames, 0, MidpointRounding.AwayFromZero); - - fade_filter = "-vf " + '\u0022' + "fade=out:" + fade_out_initial.ToString() + ":" + fff_out.ToString() + out_color + '\u0022'; - } - - if (fade_v_in.CheckState == CheckState.Checked && fade_v_out.CheckState == CheckState.Checked) - { - Decimal fff_in = Math.Round(num_v_in.Value * fade_frames, 0, MidpointRounding.AwayFromZero); - Double dur_frames = TimeSpan.Parse(listView1.Items[list_index].SubItems[3].Text).TotalSeconds * Convert.ToDouble(fade_frames); - Decimal fade_out_total = Math.Round(Convert.ToDecimal(dur_frames), 3, MidpointRounding.AwayFromZero); - Decimal fade_out_initial = Math.Round(fade_out_total - (num_v_out.Value * fade_frames), 0, MidpointRounding.AwayFromZero); - Decimal fff_out = Math.Round(num_v_out.Value * fade_frames, 0, MidpointRounding.AwayFromZero); - - fade_filter = "-vf " + '\u0022' + "fade=in:0:" + fff_in.ToString() + in_color + ", " + "fade=out:" + fade_out_initial.ToString() + ":" + fff_out.ToString() + out_color + '\u0022'; - } - - //Audio fading - if (fade_a_in.CheckState == CheckState.Checked && fade_a_out.CheckState == CheckState.Unchecked) - { - if (chk_vol.Checked == false) - { - change_vol_fade = "-af " + '\u0022' + "afade=t=in:ss=0:d=" + num_a_in.Value.ToString() + '\u0022'; - } - else - { - change_vol_fade = "-af " + '\u0022' + "afade=t=in:ss=0:d=" + num_a_in.Value.ToString() + ", " + "volume=" + vol_ch.Value.ToString() + "dB " + '\u0022'; - } - } - - if (fade_a_in.CheckState == CheckState.Unchecked && fade_a_out.CheckState == CheckState.Checked) - { - Double af_out = TimeSpan.Parse(listView1.Items[list_index].SubItems[3].Text).TotalSeconds - Convert.ToDouble(num_a_out.Value); - Decimal af_out_dec = Math.Round(Convert.ToDecimal(af_out), 0, MidpointRounding.AwayFromZero); - if (chk_vol.Checked == false) - { - change_vol_fade = "-af " + '\u0022' + "afade=t=out:st=" + af_out_dec + ":d=" + num_a_out.Value.ToString() + '\u0022'; - } - else - { - change_vol_fade = "-af " + '\u0022' + "afade=t=out:st=" + af_out_dec + ":d=" + num_a_out.Value.ToString() + ", " + "volume=" + vol_ch.Value.ToString() + "dB " + '\u0022'; - } - } - if (fade_a_in.CheckState == CheckState.Checked && fade_a_out.CheckState == CheckState.Checked) - { - Double af_out = TimeSpan.Parse(listView1.Items[list_index].SubItems[3].Text).TotalSeconds - Convert.ToDouble(num_a_out.Value); - Decimal af_out_dec = Math.Round(Convert.ToDecimal(af_out), 0, MidpointRounding.AwayFromZero); - - if (chk_vol.Checked == false) - { - change_vol_fade = "-af " + '\u0022' + "afade=t=in:ss=0:d=" + num_a_in.Value.ToString() + ", " + "afade=t=out:st=" + af_out_dec + ":d=" + num_a_out.Value.ToString() + '\u0022'; - } - else - { - change_vol_fade = "-af " + '\u0022' + "afade=t=in:ss=0:d=" + num_a_in.Value.ToString() + ", " + "afade=t=out:st=" + af_out_dec + ":d=" + num_a_out.Value.ToString() + ", " + "volume=" + vol_ch.Value.ToString() + "dB " + '\u0022'; - } - } - } - })); - - //End audio fading - - //End fading - - //End Change Volume - - if (txt_path_main.Text.Contains(".\\")) - { - if (txt_path_main.Text != ".\\") - destino = file.Substring(0, fullPath.LastIndexOf('\\')) + txt_path_main.Text.Replace(".", String.Empty); - else - { - destino = Path.GetDirectoryName(file); - } - } - else - { - if (chk_recreate.CheckState == CheckState.Checked) - { - - String pre_dest = Path.GetDirectoryName(file); - if (pre_dest.Substring(0,2) == "\\\\") destino = Path.Combine(txt_path_main.Text, pre_dest.Substring(2, pre_dest.Length - 2)); - else destino = Path.Combine(txt_path_main.Text, pre_dest.Substring(3, pre_dest.Length - 3)); - } - else - { - destino = txt_path_main.Text; - } - } - - String pre_ss = ""; - if (TimeSpan.Parse(ss_time_input.Text).TotalSeconds != 0) - { - pre_ss = " -ss " + ss_time_input.Text; - } - - add_suffix = ""; - - if (chk_suffix.Checked == true && txt_suffix.Text != String.Empty) - { - add_suffix = txt_suffix.Text; - } - String ext_output1 = txt_format.Text; - if (txt_format.Text == String.Empty) - { - ext_output1 = Path.GetExtension(file); - } - else - { - ext_output1 = "." + txt_format.Text; - } - if (txt_format.Text == "nul") ext_output1 = "nul"; - - //Custom output extension - if (cust_output1 != String.Empty) ext_output1 = "." + cust_output1; - - String file2 = file; - - while (textbox_params.Contains("%fn")) - { - if (textbox_params.Contains("%fn")) - { - textbox_params = textbox_params.Replace("%fn", Path.GetFileNameWithoutExtension(file)); - } - } - - while (textbox_params.Contains("%ff")) - { - if (textbox_params.Contains("%ff")) - { - textbox_params = textbox_params.Replace("%ff", Path.GetFileName(file)); - } - } - - //Duration variable - - String dur_secs0 = dur_rpl.ToString(); - String to_replace0 = String.Empty; - - while (textbox_params.Contains("%fdur")) - { - if (textbox_params.Contains("%fdur")) - { - to_replace0 = ""; - - int operador = textbox_params.LastIndexOf("%fdur") + 5; - int length = 0; - int limit = textbox_params.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(textbox_params.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace0 = textbox_params.Substring(textbox_params.LastIndexOf("%fdur"), 5 + length); - Double result = Convert.ToDouble(new DataTable().Compute(to_replace0.Replace("%fdur", dur_secs0), null)); - textbox_params = ReplaceLastOccurrence(textbox_params, to_replace0, Math.Round(result).ToString()); - } - } - - while (pre_input_var.Contains("%fdur")) - { - if (pre_input_var.Contains("%fdur")) - { - to_replace0 = ""; - - int operador = pre_input_var.LastIndexOf("%fdur") + 5; - int length = 0; - int limit = pre_input_var.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(pre_input_var.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace0 = pre_input_var.Substring(pre_input_var.LastIndexOf("%fdur"), 5 + length); - Double result = Convert.ToDouble(new DataTable().Compute(to_replace0.Replace("%fdur", dur_secs0), null)); - pre_input_var = ReplaceLastOccurrence(pre_input_var, to_replace0, Math.Round(result).ToString()); - } - } - - //End duration variable - - //Bitrate variable - - String dur_secs = get_bitrate(file, dur_fbit).ToString(); - String to_replace = String.Empty; - - while (textbox_params.Contains("%fbitr")) - { - if (textbox_params.Contains("%fbitr")) - { - to_replace = ""; - - int operador = textbox_params.LastIndexOf("%fbitr") + 6; - int length = 0; - int limit = textbox_params.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(textbox_params.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace = textbox_params.Substring(textbox_params.LastIndexOf("%fbitr"), 6 + length); - - Double result = Convert.ToDouble(new DataTable().Compute(to_replace.Replace("%fbitr", dur_secs), null)); - textbox_params = ReplaceLastOccurrence(textbox_params, to_replace, Math.Round(result).ToString() + "K"); - } - } - - while (pre_input_var.Contains("%fbitr")) - { - if (pre_input_var.Contains("%fbitr")) - { - to_replace = ""; - - int operador = pre_input_var.LastIndexOf("%fbitr") + 6; - int length = 0; - int limit = pre_input_var.Length - operador; - - for (int ii = 0; ii < limit; ii++) - { - if (IsDigitsOnly(pre_input_var.Substring(operador + ii, 1))) - { - length = ii + 1; - } - else break; - } - - to_replace = pre_input_var.Substring(pre_input_var.LastIndexOf("%fbitr"), 6 + length); - - Double result = Convert.ToDouble(new DataTable().Compute(to_replace.Replace("%fbitr", dur_secs), null)); - pre_input_var = ReplaceLastOccurrence(pre_input_var, to_replace, Math.Round(result).ToString() + "K"); - } - } - - //End bitrate variable - - //Target size - - if (textbox_params.Contains("[[target_size=")) - { - int f = textbox_params.IndexOf("[[target_size=") + 14; - int mb = textbox_params.IndexOf("MB"); - int l = textbox_params.IndexOf("Kbps]]"); - Double target_mb = Convert.ToDouble(textbox_params.Substring(f, mb - f)); - String aud_bitr = textbox_params.Substring(mb + 3, l - mb - 3); - String replaced = get_bitrate_target(target_mb, dur_rpl, Convert.ToDecimal(aud_bitr)).ToString(); - to_replace = textbox_params.Substring(f - 14, l - f + 14 + 6); - textbox_params = textbox_params.Replace(to_replace, replaced); - } - - //End target size - - while (textbox_params.Contains("%fp")) - { - if (textbox_params.Contains("%fp")) - { - textbox_params = textbox_params.Replace("%fp", Path.GetDirectoryName(file)); - } - } - - while (textbox_params.Contains("%fd")) - { - if (textbox_params.Contains("%fd")) - { - var dirName = new DirectoryInfo(Path.GetDirectoryName(file)).Name; - textbox_params = textbox_params.Replace("%fd", dirName); - } - } - - while (textbox_params.Contains("%1")) - { - if (textbox_params.Contains("%1")) - { - file2 = file2.Replace("\\", "\\\\\\\\"); - file2 = file2.Replace(":", ":" + "\\\\"); - textbox_params = textbox_params.Replace("%1", '\u0022' + file2 + '\u0022'); - } - } - - while (textbox_params.Contains("%2")) - { - if (textbox_params.Contains("%2")) - { - file2 = file2.Replace("\\", "\\\\\\\\"); - file2 = file2.Replace(":", ":" + "\\\\"); - textbox_params = textbox_params.Replace("%2", '\u0022' + Path.Combine(Path.GetDirectoryName(file2), Path.GetFileNameWithoutExtension(file2)) + '\u0022'); - } - } - - //Preinput variables - - String file22 = file; - while (pre_input_var.Contains("%fn")) - { - if (pre_input_var.Contains("%fn")) - { - pre_input_var = pre_input_var.Replace("%fn", Path.GetFileNameWithoutExtension(file)); - } - } - - while (pre_input_var.Contains("%ff")) - { - if (pre_input_var.Contains("%ff")) - { - pre_input_var = pre_input_var.Replace("%ff", Path.GetFileName(file)); - } - } - - while (pre_input_var.Contains("%fp")) - { - if (pre_input_var.Contains("%fp")) - { - pre_input_var = pre_input_var.Replace("%fp", Path.GetDirectoryName(file)); - } - } - - while (pre_input_var.Contains("%fd")) - { - if (pre_input_var.Contains("%fd")) - { - var dirName = new DirectoryInfo(Path.GetDirectoryName(file)).Name; - pre_input_var = pre_input_var.Replace("%fd", dirName); - } - } - - while (pre_input_var.Contains("%1")) - { - if (pre_input_var.Contains("%1")) - { - file2 = file2.Replace("\\", "\\\\\\\\"); - file2 = file2.Replace(":", ":" + "\\\\"); - pre_input_var = pre_input_var.Replace("%1", '\u0022' + file2 + '\u0022'); - } - } - - while (pre_input_var.Contains("%2")) - { - if (pre_input_var.Contains("%2")) - { - file2 = file2.Replace("\\", "\\\\\\\\"); - file2 = file2.Replace(":", ":" + "\\\\"); - pre_input_var = pre_input_var.Replace("%2", '\u0022' + Path.Combine(Path.GetDirectoryName(file2), Path.GetFileNameWithoutExtension(file2)) + '\u0022'); - } - } - - //End preinput variables - - //New variables for filters - - while (textbox_params.Contains("%pff")) - { - if (textbox_params.Contains("%pff")) - { - file2 = file2.Replace("\\", "/\\"); - file2 = file2.Replace(":", "\\\\://\\"); - - textbox_params = textbox_params.Replace("%pff", Path.GetDirectoryName(file2)); - } - } - - while (textbox_params.Contains("%f1")) - { - if (textbox_params.Contains("%f1")) - { - file2 = file2.Replace("\\", "/\\"); - file2 = file2.Replace(":", "\\\\:"); - - textbox_params = textbox_params.Replace("%f1", file2); - } - } - - while (textbox_params.Contains("%f2")) - { - if (textbox_params.Contains("%f2")) - { - file2 = file2.Replace("\\", "/\\"); - file2 = file2.Replace(":", "\\\\://\\"); - textbox_params = textbox_params.Replace("%f2", Path.Combine(Path.GetDirectoryName(file2), Path.GetFileNameWithoutExtension(file2))); - } - } - - while (pre_input_var.Contains("%pff")) - { - if (pre_input_var.Contains("%pff")) - { - file2 = file2.Replace("\\", "/\\"); - file2 = file2.Replace(":", "\\\\://\\"); - - pre_input_var = pre_input_var.Replace("%pff", Path.GetDirectoryName(file2)); - } - } - - while (pre_input_var.Contains("%f1")) - { - if (pre_input_var.Contains("%f1")) - { - file2 = file2.Replace("\\", "/\\"); - file2 = file2.Replace(":", "\\\\://\\"); - - pre_input_var = pre_input_var.Replace("%f1", file2); - } - } - - while (pre_input_var.Contains("%f2")) - { - if (pre_input_var.Contains("%f2")) - { - file2 = file2.Replace("\\", "/\\"); - file2 = file2.Replace(":", "\\\\://\\"); - pre_input_var = pre_input_var.Replace("%f2", Path.Combine(Path.GetDirectoryName(file2), Path.GetFileNameWithoutExtension(file2))); - } - } - - - //Monitor available space - FileInfo f_root2 = new FileInfo(destino); - Boolean unc = Uri.TryCreate(destino, UriKind.Absolute, out Uri uri) && uri.IsUnc; - if (unc == false) - { - try - { - DriveInfo dest_drive2 = new DriveInfo(f_root2.Directory.Root.FullName); - - if (dest_drive2.AvailableFreeSpace <= 500000000) - { - DialogResult a = DialogResult.Cancel; - - a = MessageBox.Show(Strings.warn_sp, Strings.low_sp + " (" + (dest_drive2.AvailableFreeSpace / 1000000).ToString() + "MB)", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); - if (a == DialogResult.Yes) - { - aborted = true; - working = false; - this.Invoke(new MethodInvoker(delegate - { - lbl_est_size.Text = ""; - lbl_bitrate.Text = ""; - })); - - Enable_Controls(); - return; - } - } - } - catch { } - } - - //End monitor available space - - String AppParam = String.Empty; - String file_out = Path.GetFileNameWithoutExtension(file); - - - if (file.Substring(file.Length - 3, 3).ToLower() == "avs") - { - file_out = Path.GetFileNameWithoutExtension(avs_out); - } - - String file_cache = String.Empty; - current_out = destino + "\\" + file_out + add_suffix + ext_output1; - Boolean to_overw = false; - - if (file_is_network == true && cache_net == true) - { - this.InvokeEx(f => f.pg_adding.Style = ProgressBarStyle.Marquee); - try - { - if (Directory.Exists(Path.Combine(Path.GetTempPath(), "FFBatch_test")) == false) Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "FFBatch_test")); - { - file_to_copy = file; - cached = false; - cancel_cache = false; - this.Invoke(new MethodInvoker(delegate - { - txt_add_remain.Enabled = true; - txt_add_remain.Text = String.Empty; - txt_add_remain.Visible = true; - })); - - if (os_save_cache == false) - { - CopyCache(); - do - { - Thread.Sleep(750); - } - while (cached == false && cancel_cache == false); - } - else - { - this.Invoke(new MethodInvoker(delegate - { - this.Enabled = false; - txt_add_remain.Visible = true; - })); - - if (File.Exists(Path.Combine(Path.GetTempPath(), "FFBatch_test", Path.GetFileName(file_to_copy)))) - { - FileInfo fi = new FileInfo(Path.Combine(Path.GetTempPath(), "FFBatch_test", Path.GetFileName(file_to_copy))); - FileInfo fi2 = new FileInfo(file_to_copy); - if (fi.Length == fi2.Length) - { - this.Invoke(new MethodInvoker(delegate - { - this.Enabled = true; - txt_add_remain.Visible = false; - })); - cached = true; - } - } - else - { - net_speed(); - FileSystem.CopyFile(file, Path.Combine(Path.GetTempPath(), "FFBatch_test", Path.GetFileName(file)), UIOption.AllDialogs, UICancelOption.ThrowException); - this.Invoke(new MethodInvoker(delegate - { - this.Enabled = true; - txt_add_remain.Visible = false; - })); - cached = true; - } - } - - if (cached == true && cancel_cache == false) - { - cache_net = true; - file_cache = Path.Combine(Path.GetTempPath(), "FFBatch_test", Path.GetFileName(file)); - AppParam = hw_decode + " " + pre_input_var + " " + pre_ss + " -i " + "" + '\u0022' + file_cache + '\u0022' + " " + shifting + " -y " + textbox_params + " " + fade_filter + " " + change_vol_fade + " " + '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file_cache) + add_suffix + ext_output1 + '\u0022' + " -hide_banner"; - } - else - { - AppParam = hw_decode + " " + pre_input_var + " " + pre_ss + " -i " + "" + '\u0022' + file + '\u0022' + " " + shifting + " -y " + textbox_params + " " + fade_filter + " " + change_vol_fade + " " + '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file) + add_suffix + ext_output1 + '\u0022' + " -hide_banner"; - cache_net = false; - } - cancel_cache = false; - } - } - catch - { - Thread.Sleep(250); - - this.Invoke(new MethodInvoker(delegate - { - this.Enabled = true; - txt_add_remain.Visible = false; - btn_abort_all.Enabled = true; - btn_skip_main.Enabled = true; - pg_adding.Visible = false; - LB_Wait.Visible = false; - btn_cancel_add.Visible = false; - txt_adding_p.Visible = false; - txt_add_remain.Visible = false; - txt_add_remain.Enabled = false; - btn_pause.Enabled = true; - })); - - cache_net = false; - AppParam = hw_decode + " " + pre_input_var + " " + pre_ss + " -i " + "" + '\u0022' + file + '\u0022' + " " + shifting + " -y " + textbox_params + " " + fade_filter + " " + change_vol_fade + " " + '\u0022' + destino + "\\" + file_out + add_suffix + ext_output1 + '\u0022' + " -hide_banner"; - if (ext_output1 == "nul") AppParam = hw_decode + " " + pre_input_var + " " + pre_ss + " -i " + "" + '\u0022' + file + '\u0022' + " " + shifting + " " + textbox_params + " " + fade_filter + " " + change_vol_fade + " " + " -hide_banner"; - } - } - else - { - AppParam = hw_decode + " " + pre_input_var + " " + pre_ss + " -i " + "" + '\u0022' + file + '\u0022' + " " + shifting + " -y " + textbox_params + " " + fade_filter + " " + change_vol_fade + " " + '\u0022' + destino + "\\" + file_out + add_suffix + ext_output1 + '\u0022' + " -hide_banner"; - if (ext_output1 == "nul") AppParam = hw_decode + " " + pre_input_var + " " + pre_ss + " -i " + "" + '\u0022' + file + '\u0022' + " " + shifting + " " + textbox_params + " " + fade_filter + " " + change_vol_fade + " " + " -hide_banner"; - } - - if (chk_overw.CheckState == CheckState.Checked) - { - if (current_out == file) - { - AppParam = hw_decode + " " + pre_input_var + " " + pre_ss + " -i " + "" + '\u0022' + file + '\u0022' + " " + shifting + " -y " + textbox_params + " " + fade_filter + " " + change_vol_fade + " " + '\u0022' + destino + "\\" + file_out + "_fftemp" + add_suffix + ext_output1 + '\u0022' + " -hide_banner"; - if (ext_output1 == "nul") AppParam = hw_decode + " " + pre_input_var + " " + pre_ss + " -i " + "" + '\u0022' + file + '\u0022' + " " + shifting + " " + textbox_params + " " + fade_filter + " " + change_vol_fade + " -y " + " -hide_banner"; - to_overw = true; - } - } - if (current_out == file && chk_overw.CheckState == CheckState.Unchecked && !textbox_params.Contains("[[split_chapters]]")) - { - working = false; - time_est_size = 0; - Enable_Controls(); - this.Invoke(new MethodInvoker(delegate - { - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - MessageBox.Show(Strings.source_overw, Strings.overw_cant, MessageBoxButtons.OK, MessageBoxIcon.Error); - })); - return; - } - - String second_path = ""; - if (ext_output1 == "nul") - { - String[] split = txt_parameters.Text.Split(' '); - for (int i = 0; i < split.Length; i++) - { - if (split[i].Contains("\\") == true) - { - String pre_path = split[i].Replace("%fp", Path.GetDirectoryName(file)).Replace("%fn", file_out).Replace("%", "_"); - second_path = Path.GetDirectoryName(pre_path.Replace('\u0022', ' ')); - - if (!Directory.Exists(second_path)) - { - try - { - Directory.CreateDirectory(second_path); - } - catch { } - } - } - } - } - - if (!Directory.Exists(destino) && ext_output1 != "nul") - { - try { Directory.CreateDirectory(destino); } - catch { } - } - - if (verbose_logs == false) AppParam = AppParam + " -loglevel warning -stats"; - - tmp.StartInfo.FileName = ffm; - - // Split by size - - if (textbox_params.Contains(" (segment_size) ")) - { - Double split_size = Convert.ToDouble(split_by_size); - ff_frames = String.Empty; - Double ov_bitrate = 0; - ov_bitrate = file_size / size_dur; - Double bit_r = 0; - bit_r = ov_bitrate / 1000000; - bit_r = split_size / bit_r; - bit_r = Math.Round(bit_r, 2); - AppParam = AppParam.Replace(" (segment_size) ", " " + bit_r.ToString().Replace(",", ".") + " "); - } - - // End split by size - tmp.StartInfo.Arguments = AppParam; - - list_lines.Add("---------------------Start of " + Path.GetFileName(file) + " log-------------------------------"); - list_lines.Add(""); - if (verbose_logs == true) list_lines.Add(tmp.StartInfo.Arguments + Environment.NewLine); - - valid_prog = false; - - //Duration for quick file listing - - Type ts = Type.GetTypeFromProgID("Shell.Application"); - dynamic shell = Activator.CreateInstance(ts); - Folder rFolder = shell.NameSpace(Path.GetDirectoryName(file)); - FolderItem rFiles = rFolder.ParseName(Path.GetFileName(file)); - String videostype = rFolder.GetDetailsOf(rFiles, 2).Trim(); - String videoSize = rFolder.GetDetailsOf(rFiles, 1).Trim(); - - this.Invoke(new MethodInvoker(delegate - { - listView1.Items[list_index].SubItems[2].Text = videostype; - listView1.Items[list_index].SubItems[4].Text = videoSize; - })); - - DateTime time; - String dur_q = rFolder.GetDetailsOf(rFiles, 27).Trim(); - - if ((DateTime.TryParse(dur_q, out time))) - { - this.Invoke(new MethodInvoker(delegate - { - listView1.Items[list_index].SubItems[3].Text = dur_q; - })); - valid_prog = true; - } - else - { - this.Invoke(new MethodInvoker(delegate - { - listView1.Items[list_index].SubItems[3].Text = get_file_dur(file); - })); - } - - if (textbox_params.Contains("[[split_chapters]]")) - { - String prev_params = tmp.StartInfo.Arguments; - if (list_chaps_m.Count == 0) get_chapters(file); - else list_chaps = list_chaps_m.ToList(); - - if (list_chaps.Count > 0) - { - int ich = 0; - - foreach (String[] chap in list_chaps) - { - ich++; - Double new_dur = 0; - String rep_out = destino + "\\" + file_out + "." + txt_format.Text; - try - { - String start1 = chap[0].Replace("-ss ", ""); - if (start1.Contains(".")) start1 = start1.Substring(0, start1.LastIndexOf(".")); - - String end1 = chap[1].Replace("-to ", ""); - if (end1.Contains(".")) end1 = end1.Substring(0, end1.LastIndexOf(".")); - - int new_dur0 = Convert.ToInt32(end1) - Convert.ToInt32(start1); - new_dur = Convert.ToDouble(new_dur0); - tmp.StartInfo.Arguments = tmp.StartInfo.Arguments.Replace("[[split_chapters]]", (chap[0] + " " + chap[1]) + " "); - } - catch - { - tmp.StartInfo.Arguments = tmp.StartInfo.Arguments.Replace("[[split_chapters]]", "chapter_error "); - } - - String new_dest = destino + "\\" + Path.GetFileNameWithoutExtension(file) + "\\" + file_out + "_" + ich.ToString() + "." + txt_format.Text; - String padding = String.Empty; - if (ich < 10) padding = "0"; - if (chap[2].Length > 0) new_dest = destino + "\\" + Path.GetFileNameWithoutExtension(file) + "\\" + file_out + "_" + chap[2] + "_" + padding + ich.ToString() + "." + txt_format.Text; - if (!Directory.Exists(destino + "\\" + Path.GetFileNameWithoutExtension(file))) - { - Directory.CreateDirectory(destino + "\\" + Path.GetFileNameWithoutExtension(file)); - } - //Process every chapter - - tmp.StartInfo.Arguments = ReplaceLastOccurrence(tmp.StartInfo.Arguments, rep_out, new_dest); - tmp.StartInfo.RedirectStandardError = true; - tmp.StartInfo.StandardErrorEncoding = Encoding.UTF8; - tmp.StartInfo.UseShellExecute = false; - tmp.StartInfo.CreateNoWindow = true; - tmp.EnableRaisingEvents = true; - tmp.StartInfo.WorkingDirectory = Application.StartupPath; - - if (ignore_encoded == true && status == Strings.success) continue; - - if (Settings.Default.no_dest_overw == true && File.Exists(current_out)) - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.skipped); - list_successful.Add(file); - continue; - } - - if (aborted == false) - { - System.Threading.Thread.Sleep(10); //Allow kill process to send cancel_queue - tmp.Start(); - } - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.processing); - - combo_prio.Invoke(new MethodInvoker(delegate - { - if (combo_prio.SelectedIndex != 2) - { - System.Threading.Thread.Sleep(50); - Change_mem_prio(); - } - })); - - check_space = 1; - DriveInfo dest_drive2 = null; - FileInfo f_root22 = new FileInfo(destino); - Boolean unc22 = Uri.TryCreate(destino, UriKind.Absolute, out Uri uri22) && uri.IsUnc; - if (unc == false) - { - try - { - dest_drive2 = new DriveInfo(f_root22.Directory.Root.FullName); - warn_space = true; - } - catch { warn_space = false; } - } - - this.InvokeEx(f => validate_duration = listView1.Items[list_index].SubItems[3].Text); - if (validate_duration != Strings.n_a && validate_duration != "0:00:00" && validate_duration != "00:00:00" && validate_duration != Strings.pending) - { - valid_prog = true; - } - - if (Settings.Default.quick_queue == true) valid_prog = false; - - String err_txt2 = ""; - Double interval2 = 0; - Decimal est_bitrate2 = 0; - Decimal est_size2 = 0; - this.InvokeEx(f => f.lbl_speed.Text = String.Empty); - Double sec_prog2 = 0; - - while (!tmp.StandardError.EndOfStream) - { - try - { - err_txt2 = tmp.StandardError.ReadLine(); - check_space++; - list_lines.Add(err_txt2); - if (err_txt2.Contains("time=") && err_txt2.Contains("time=-") == false) - { - if (valid_prog == true && Settings.Default.quick_queue == false) - { - durat_n = new_dur; - durat_n = durat_n / atemp; - int start_time_index = err_txt2.IndexOf("time=") + 5; - sec_prog2 = TimeSpan.Parse(err_txt2.Substring(start_time_index, 8)).TotalSeconds; - - Double percent = (sec_prog2 * 100 / durat_n); - - total_prog = total_prog + (sec_prog2 - interval2); - interval2 = sec_prog2; - int percent2 = Convert.ToInt32(percent); - - Double percent_tot = (total_prog * 100 / total_duration); - int percent_tot_2 = Convert.ToInt32(percent_tot); - - if (percent_tot_2 <= 100) - { - this.Invoke(new MethodInvoker(delegate - { - Pg1.Value = percent_tot_2; - Pg1.Refresh(); - - if (Math.Round(percent_tot, 1).ToString().Contains(".") || Math.Round(percent_tot, 1).ToString().Contains(",")) - { - Pg1.Text = Math.Round(percent_tot, 1).ToString() + "%"; - } - else - { - Pg1.Text = Math.Round(percent_tot, 1).ToString() + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0" + "%"; - } - - TaskbarProgress.SetValue(this.Handle, percent_tot, Pg1.Maximum); - })); - } - - if (percent2 <= 100) - { - this.Invoke(new MethodInvoker(delegate - { - if (Math.Round(percent, 1).ToString().Contains(".") || Math.Round(percent, 1).ToString().Contains(",")) - { - listView1.Items[list_index].SubItems[5].Text = Math.Round(percent, 1).ToString() + "%"; - } - else - { - listView1.Items[list_index].SubItems[5].Text = Math.Round(percent, 1).ToString() + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0" + "%"; - } - })); - - } - else - { - this.Invoke(new MethodInvoker(delegate - { - listView1.Items[list_index].SubItems[5].Text = "100%"; - })); - } - - if (cancel_queue == false) - { - String fps_perf = String.Empty; - //Estimated remaining time - - remain_time = err_txt2.Substring(err_txt2.LastIndexOf("speed=") + 6, err_txt2.Length - err_txt2.LastIndexOf("speed=") - 6); - if (err_txt2.Contains("fps=")) - { - fps_perf = (err_txt2.Substring(err_txt2.IndexOf("fps=") + 4, 4)).TrimStart(); - } - if (fps_perf.Length > 0) fps_perf = " | " + fps_perf.TrimEnd() + " fps"; - if (fps_perf.Contains("0.0")) - { - fps_perf = String.Empty; - } - - if (time_est_size % 2 == 0) - { - String chk_0 = (Strings.speed + " " + remain_time).TrimEnd() + fps_perf; - if (chk_0.Substring(chk_0.Length - 3, 3) == " 0x") - { - this.InvokeEx(f => f.lbl_speed.Text = ""); - } - else this.InvokeEx(f => f.lbl_speed.Text = (Strings.speed + " " + remain_time).TrimEnd() + fps_perf); - } - - remain_time = remain_time.Replace("x", String.Empty); - Double timing1 = 0; - if (!remain_time.Contains("N/A")) - { - if (System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",") - { - timing1 = Math.Round(Double.Parse(remain_time.Replace(".", ",")), 2); - } - else - { - timing1 = Math.Round(Double.Parse(remain_time), 2); - } - } - else timing1 = 0; - - Decimal timing = (decimal)timing1; - Decimal total_dur_dec = Convert.ToDecimal(total_duration); - Decimal total_prog_dec = Convert.ToDecimal(total_prog); - Decimal remain_secs = 0; - if (timing > 0) - { - remain_secs = (decimal)(total_dur_dec - total_prog_dec) / timing; - } - - if (remain_secs > 60) - { - remain_secs = remain_secs + 60; - } - - String remain_from_secs = ""; - - TimeSpan t = TimeSpan.FromSeconds(Convert.ToDouble(remain_secs)); - remain_from_secs = string.Format("{0:D2}h:{1:D2}", - t.Hours, - t.Minutes); - - this.Invoke(new MethodInvoker(delegate - { - if (remain_secs >= 43200) - { - txt_remain.Text = Strings.remain_time + " " + Math.Round(remain_secs / 3600).ToString() + " " + Strings.hours; - this.Text = Pg1.Text + " / " + Math.Round(remain_secs / 3600).ToString() + " " + Strings.hours; - } - - if (remain_secs >= 3600 && remain_secs < 43200) - { - txt_remain.Text = Strings.remain_time + " " + remain_from_secs + " " + Strings.minutes_abrev; - this.Text = Pg1.Text + " / " + remain_from_secs + " " + Strings.minutes_abrev; - } - - if (remain_secs < 3600 && remain_secs >= 600) - { - txt_remain.Text = Strings.remain_time + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 1, 2) + " " + Strings.minutes; - this.Text = Pg1.Text + " / " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 1, 2) + " " + Strings.minutes_abrev; - } - if (remain_secs < 600 && remain_secs >= 120) - { - txt_remain.Text = Strings.remain_time + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 2, 1) + " " + Strings.minutes; - this.Text = Pg1.Text + " / " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 2, 1) + " " + Strings.minutes_abrev; - } - - if (remain_secs <= 59 && remain_secs != 0) - { - txt_remain.Text = Strings.remain_time + " " + Convert.ToInt16(Math.Abs(remain_secs)) + " " + Strings.seconds; - this.Text = Pg1.Text + " / " + Convert.ToInt16(Math.Abs(remain_secs)) + " s"; - } - if (remain_secs == 0) - { - txt_remain.Text = Strings.remain_time + " " + Strings.about_finish; - this.Text = Pg1.Text; - } - })); - } - //End remaining time - - //Estimated size and bitrate - - String read_size = String.Empty; - - if (err_txt2.Contains("size=") && (err_txt2.Contains("N/A") == false) && (time_est_size % 2 == 0)) - { - int size_index = err_txt2.IndexOf("size=") + 5; - read_size = err_txt2.Substring(size_index, 8); - if (Convert.ToDecimal(sec_prog2) != 0 & read_size.Contains(Strings.n_a) == false) - { - est_bitrate2 = (Math.Round(Convert.ToDecimal(read_size) * 8 / Convert.ToDecimal(sec_prog2), 0)); - } - else - { - est_bitrate2 = 0; - } - - if (read_size.Contains(Strings.n_a) == false && Convert.ToDecimal(read_size) > 1 && time_n_tasks > 1) - { - this.Invoke(new MethodInvoker(delegate - { - if (est_bitrate2 < 9999) - { - if (est_bitrate2 > 48) - { - lbl_bitrate.Text = Strings.avg_bit + ": " + est_bitrate2 + " " + "Kb/s"; - } - else - { - lbl_bitrate.Text = Strings.avg_bit + ": "; - } - } - else - { - lbl_bitrate.Text = Strings.avg_bit + ": " + (Math.Round(est_bitrate2 / 1000, 0)) + " " + "Mb/s"; - } - //Estimated size - est_size2 = Convert.ToDecimal(durat_n) * est_bitrate2 / 8; - - if (est_size2 > 1000000) - { - lbl_est_size.Text = Strings.est_size + " " + (Math.Round(est_size2 / 1000000, 1)).ToString() + " " + "GB"; - } - else - { - if (Math.Round(est_size2 / 1000, 0) > 0) - { - lbl_est_size.Text = Strings.est_size + " " + (Math.Round(est_size2 / 1000, 0)).ToString() + " " + "MB"; - } - else - { - lbl_est_size.Text = Strings.est_size + " "; - } - } - })); - lbl_est_size.Refresh(); - } - } - } - if (valid_prog == false && Settings.Default.quick_queue == true) - { - this.Invoke(new MethodInvoker(delegate - { - durat_n = TimeSpan.Parse(listView1.Items[list_index].SubItems[3].Text).TotalSeconds - TimeSpan.Parse(ss_time_input.Text).TotalSeconds; - })); - - durat_n = durat_n / atemp; - int start_time_index = err_txt2.IndexOf("time=") + 5; - sec_prog2 = TimeSpan.Parse(err_txt2.Substring(start_time_index, 8)).TotalSeconds; - - Double percent = (sec_prog2 * 100 / durat_n); - - total_prog = total_prog + (sec_prog2 - interval2); - interval2 = sec_prog2; - int percent2 = Convert.ToInt32(percent); - - if (percent2 <= 100) - { - this.Invoke(new MethodInvoker(delegate - { - if (Math.Round(percent, 1).ToString().Contains(".") || Math.Round(percent, 1).ToString().Contains(",")) - { - listView1.Items[list_index].SubItems[5].Text = Math.Round(percent, 1).ToString() + "%"; - } - else - { - listView1.Items[list_index].SubItems[5].Text = Math.Round(percent, 1).ToString() + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0" + "%"; - } - })); - - } - else - { - this.Invoke(new MethodInvoker(delegate - { - listView1.Items[list_index].SubItems[5].Text = "100%"; - })); - } - } - } - //Monitor available space - try - { - if (check_space % 30 == 0 && dest_drive2.AvailableFreeSpace <= 500000000 && warn_space == true) - { - DialogResult a = DialogResult.Cancel; - tmp.Suspend(); - a = MessageBox.Show(Strings.warn_sp, Strings.low_sp + " (" + (dest_drive2.AvailableFreeSpace / 1000000).ToString() + "MB)", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); - if (a == DialogResult.Yes) - { - resume_glob(); - Thread.Sleep(250); - aborted = true; - StreamWriter write_q = tmp.StandardInput; - write_q.Write("q"); - working = false; - time_est_size = 0; - this.Invoke(new MethodInvoker(delegate - { - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - this.Text = "FFmpeg Batch AV Converter"; - if (is_portable == true) this.Text = "FFmpeg Batch AV Converter Portable"; - })); - Enable_Controls(); - return; - } - warn_space = false; - } - } - catch { } - - //End monitor available space - } - catch { } - } - - tmp.WaitForExit(); - tmp.StartInfo.Arguments = String.Empty; - timer_est_size.Stop(); - time_est_size = 0; - this.Invoke(new MethodInvoker(delegate - { - lbl_items.Text = (list_index + 1).ToString() + " " + Strings.of1 + " " + listView1.Items.Count.ToString(); - })); - - list_lines.Add(""); - - if (Settings.Default.quick_queue == true) - { - this.Invoke(new MethodInvoker(delegate - { - Pg1.Value = 100 * list_index / listView1.Items.Count; - Pg1.Text = Pg1.Value.ToString() + "%"; - TaskbarProgress.SetValue(this.Handle, Pg1.Value, Pg1.Maximum); - })); - } - if (tmp.ExitCode == 0 && aborted == false) - { - list_lines.Add(Strings.output + " " + current_out + " " + Strings.success + " (OK)"); - list_lines.Add(""); - - if (skipped == false) - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.success); - - if (keep_dates == true) - { - try - { - File.SetCreationTime(new_dest, file_crea); - File.SetLastWriteTime(new_dest, file_written); - File.SetLastAccessTime(new_dest, file_modif); - } - catch { } - } - } - else - { - this.Invoke(new MethodInvoker(delegate - { - listView1.Items[list_index].SubItems[5].Text = Strings.skipped; - })); - - total_prog = total_prog + durat_n - sec_prog2; - try - { - File.Delete(new_dest); - } - catch { } - skipped = false; - } - } - else - { - list_failed.Add(new_dest); - - this.Invoke(new MethodInvoker(delegate - { - listView1.Items[list_index].SubItems[5].Text = Strings.error; - })); - - errors_enc = errors_enc + 1; - list_lines.Add(Strings.exit_code + ": " + tmp.ExitCode.ToString()); - - if (aborted == true) - { - this.Invoke(new MethodInvoker(delegate - { - listView1.Items[list_index].SubItems[5].Text = Strings.aborted; - })); - - list_lines.Add(Strings.output + " " + new_dest + " (" + Strings.aborted.ToUpper() + ")"); - } - else list_lines.Add(Strings.output + " " + new_dest + " (" + Strings.failed.ToUpper() + ")"); - list_lines.Add(""); - - } - - list_lines.Add("---------------------End of " + Path.GetFileName(new_dest) + " log-------------------------------"); - list_lines.Add(""); - - //End chapter loop item - tmp.StartInfo.Arguments = prev_params; - - continue; - } - // End process severy chapter - } - else - { - this.Invoke(new MethodInvoker(delegate - { - listView1.Items[list_index].SubItems[5].Text = Strings.skipped; - })); - - tmp.StartInfo.Arguments = tmp.StartInfo.Arguments.Replace("[[split_chapters]]", ""); - } - } - - tmp.StartInfo.RedirectStandardInput = true; - tmp.StartInfo.RedirectStandardError = true; - tmp.StartInfo.StandardErrorEncoding = Encoding.UTF8; - tmp.StartInfo.UseShellExecute = false; - tmp.StartInfo.CreateNoWindow = true; - tmp.EnableRaisingEvents = true; - tmp.StartInfo.WorkingDirectory = Application.StartupPath; - //tmp.StartInfo.WorkingDirectory = Path.GetDirectoryName(file); - if (ignore_encoded == true && status == Strings.success) continue; - - if (Settings.Default.no_dest_overw == true && File.Exists(current_out)) - { - this.Invoke(new MethodInvoker(delegate - { - listView1.Items[list_index].SubItems[5].Text = Strings.skipped; - })); - - list_successful.Add(file); - continue; - } - - if (aborted == false && !textbox_params.Contains("[[split_chapters]]")) - { - System.Threading.Thread.Sleep(50); //Allow kill process to send aborted signal - tmp.Start(); - } - this.Invoke(new MethodInvoker(delegate - { - listView1.Items[list_index].SubItems[5].Text = Strings.processing; - })); - - combo_prio.Invoke(new MethodInvoker(delegate - { - if (combo_prio.SelectedIndex != 2) - { - System.Threading.Thread.Sleep(50); - Change_mem_prio(); - } - })); - - check_space = 1; - DriveInfo dest_drive = null; - FileInfo f_root = new FileInfo(destino); - Boolean unc2 = Uri.TryCreate(destino, UriKind.Absolute, out Uri uri2) && uri.IsUnc; - if (unc == false) - { - try - { - dest_drive = new DriveInfo(f_root.Directory.Root.FullName); - warn_space = true; - } - catch { warn_space = false; } - } - - this.Invoke(new MethodInvoker(delegate - { - validate_duration = listView1.Items[list_index].SubItems[3].Text; - })); - - if (validate_duration != Strings.n_a && validate_duration != "0:00:00" && validate_duration != "00:00:00" && validate_duration != Strings.pending) - { - valid_prog = true; - } - - if (Settings.Default.quick_queue == true) valid_prog = false; - - this.Invoke(new MethodInvoker(delegate - { - lbl_speed.Text = String.Empty; - })); - String err_txt = ""; - Double interval = 0; - Decimal est_bitrate = 0; - Decimal est_size = 0; - Double sec_prog = 0; - - if (images_from_wiz == true) - { - total_duration = Convert.ToDouble(img_dur_wiz); - valid_prog = true; - } - images_from_wiz = false; - - try - { - while (!tmp.StandardError.EndOfStream) - { - err_txt = tmp.StandardError.ReadLine(); - check_space++; - list_lines.Add(err_txt); - if (err_txt.Contains("time=") && err_txt.Contains("time=-") == false) - { - if (valid_prog == true && Settings.Default.quick_queue == false) - { - this.Invoke(new MethodInvoker(delegate - { - durat_n = TimeSpan.Parse(listView1.Items[list_index].SubItems[3].Text).TotalSeconds - TimeSpan.Parse(ss_time_input.Text).TotalSeconds; - })); - - durat_n = durat_n / atemp; - int start_time_index = err_txt.IndexOf("time=") + 5; - try { sec_prog = TimeSpan.Parse(err_txt.Substring(start_time_index, 8)).TotalSeconds; } - catch { sec_prog = 0; } - - Double percent = (sec_prog * 100 / durat_n); - - total_prog = total_prog + (sec_prog - interval); - interval = sec_prog; - int percent2 = Convert.ToInt32(percent); - - Double percent_tot = (total_prog * 100 / total_duration); - int percent_tot_2 = Convert.ToInt32(percent_tot); - - if (percent_tot_2 <= 100) - { - this.Invoke(new MethodInvoker(delegate - { - Pg1.Value = percent_tot_2; - Pg1.Refresh(); - - if (Math.Round(percent_tot, 1).ToString().Contains(".") || Math.Round(percent_tot, 1).ToString().Contains(",")) - { - Pg1.Text = Math.Round(percent_tot, 1).ToString() + "%"; - } - else - { - Pg1.Text = Math.Round(percent_tot, 1).ToString() + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0" + "%"; - } - - TaskbarProgress.SetValue(this.Handle, percent_tot, Pg1.Maximum); - })); - - } - - if (percent2 <= 100) - { - this.Invoke(new MethodInvoker(delegate - { - if (Math.Round(percent, 1).ToString().Contains(".") || Math.Round(percent, 1).ToString().Contains(",")) - { - listView1.Items[list_index].SubItems[5].Text = Math.Round(percent, 1).ToString() + "%"; - } - else - { - listView1.Items[list_index].SubItems[5].Text = Math.Round(percent, 1).ToString() + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0" + "%"; - } - })); - } - else - { - this.Invoke(new MethodInvoker(delegate - { - listView1.Items[list_index].SubItems[5].Text = "100%"; - })); - } - - if (cancel_queue == false) - { - String fps_perf = String.Empty; - //Estimated remaining time - - remain_time = err_txt.Substring(err_txt.LastIndexOf("speed=") + 6, err_txt.Length - err_txt.LastIndexOf("speed=") - 6); - if (err_txt.Contains("fps=")) - { - fps_perf = (err_txt.Substring(err_txt.IndexOf("fps=") + 4, 4)).TrimStart(); - } - if (fps_perf.Length > 0) fps_perf = " | " + fps_perf.TrimEnd() + " fps"; - if (fps_perf.Contains("0.0")) - { - fps_perf = String.Empty; - } - - if (time_est_size % 2 == 0) - { - String chk_0 = (Strings.speed + " " + remain_time).TrimEnd() + fps_perf; - this.Invoke(new MethodInvoker(delegate - { - if (chk_0.Substring(chk_0.Length - 3, 3) == " 0x") - { - lbl_speed.Text = ""; - } - else lbl_speed.Text = (Strings.speed + " " + remain_time).TrimEnd() + fps_perf; - })); - } - - remain_time = remain_time.Replace("x", String.Empty); - Double timing1 = 0; - if (!remain_time.Contains("N/A")) - { - if (System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",") - { - timing1 = Math.Round(Double.Parse(remain_time.Replace(".", ",")), 2); - } - else - { - timing1 = Math.Round(Double.Parse(remain_time), 2); - } - } - else timing1 = 0; - - Decimal timing = (decimal)timing1; - Decimal total_dur_dec = Convert.ToDecimal(total_duration); - Decimal total_prog_dec = Convert.ToDecimal(total_prog); - Decimal remain_secs = 0; - if (timing > 0) - { - remain_secs = (decimal)(total_dur_dec - total_prog_dec) / timing; - } - - if (remain_secs > 60) - { - remain_secs = remain_secs + 60; - } - - String remain_from_secs = ""; - - TimeSpan t = TimeSpan.FromSeconds(Convert.ToDouble(remain_secs)); - remain_from_secs = string.Format("{0:D2}h:{1:D2}", - t.Hours, - t.Minutes); - - this.Invoke(new MethodInvoker(delegate - { - if (remain_secs >= 43200) - { - txt_remain.Text = Strings.remain_time + " " + Math.Round(remain_secs / 3600).ToString() + " " + Strings.hours; - this.Text = Pg1.Text + " / " + Math.Round(remain_secs / 3600).ToString() + " " + Strings.hours; - } - - if (remain_secs >= 3600 && remain_secs < 43200) - { - txt_remain.Text = Strings.remain_time + " " + remain_from_secs + " " + Strings.minutes_abrev; - this.Text = Pg1.Text + " / " + remain_from_secs + " " + Strings.minutes_abrev; - } - - if (remain_secs < 3600 && remain_secs >= 600) - { - txt_remain.Text = Strings.remain_time + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 1, 2) + " " + Strings.minutes; - this.Text = Pg1.Text + " / " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 1, 2) + " " + Strings.minutes_abrev; - } - if (remain_secs < 600 && remain_secs >= 120) - { - txt_remain.Text = Strings.remain_time + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 2, 1) + " " + Strings.minutes; - this.Text = Pg1.Text + " / " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 2, 1) + " " + Strings.minutes_abrev; - } - - if (remain_secs <= 59 && remain_secs != 0) - { - txt_remain.Text = Strings.remain_time + " " + Convert.ToInt16(Math.Abs(remain_secs)) + " " + Strings.seconds; - this.Text = Pg1.Text + " / " + Convert.ToInt16(Math.Abs(remain_secs)) + " s"; - } - if (remain_secs == 0) - { - txt_remain.Text = Strings.remain_time + " " + Strings.about_finish; - this.Text = Pg1.Text; - } - })); - } - //End remaining time - - //Estimated size and bitrate - - String read_size = String.Empty; - - if (err_txt.Contains("size=") && (err_txt.Contains("N/A") == false) && (time_est_size % 2 == 0)) - { - - int size_index = err_txt.IndexOf("size=") + 5; - read_size = err_txt.Substring(size_index, 8); - if (Convert.ToDecimal(sec_prog) != 0 & read_size.Contains(Strings.n_a) == false) - { - est_bitrate = (Math.Round(Convert.ToDecimal(read_size) * 8 / Convert.ToDecimal(sec_prog), 0)); - } - else - { - est_bitrate = 0; - } - - if (read_size.Contains(Strings.n_a) == false && Convert.ToDecimal(read_size) > 1 && time_n_tasks > 1) - { - - if (est_bitrate < 9999) - { - this.Invoke(new MethodInvoker(delegate - { - if (est_bitrate > 48) - { - lbl_bitrate.Text = Strings.avg_bit + ": " + est_bitrate + " " + "Kb/s"; - } - else - { - lbl_bitrate.Text = Strings.avg_bit + ": "; - } - })); - } - else - { - this.Invoke(new MethodInvoker(delegate - { - lbl_bitrate.Text = Strings.avg_bit + ": " + (Math.Round(est_bitrate / 1000, 0)) + " " + "Mb/s"; - })); - - } - //Estimated size - est_size = Convert.ToDecimal(durat_n) * est_bitrate / 8; - - this.Invoke(new MethodInvoker(delegate - { - if (est_size > 1000000) - { - lbl_est_size.Text = Strings.est_size + " " + (Math.Round(est_size / 1000000, 1)).ToString() + " " + "GB"; - } - else - { - if (Math.Round(est_size / 1000, 0) > 0) - { - lbl_est_size.Text = Strings.est_size + " " + (Math.Round(est_size / 1000, 0)).ToString() + " " + "MB"; - } - else - { - lbl_est_size.Text = Strings.est_size + " "; - } - } - })); - } - - this.Invoke(new MethodInvoker(delegate - { - lbl_est_size.Refresh(); - })); - } - } - if (valid_prog == false && Settings.Default.quick_queue == true && !err_txt.Contains("N/A")) - { - this.Invoke(new MethodInvoker(delegate - { - durat_n = TimeSpan.Parse(listView1.Items[list_index].SubItems[3].Text).TotalSeconds - TimeSpan.Parse(ss_time_input.Text).TotalSeconds; - })); - - durat_n = durat_n / atemp; - int start_time_index = err_txt.IndexOf("time=") + 5; - sec_prog = TimeSpan.Parse(err_txt.Substring(start_time_index, 8)).TotalSeconds; - - Double percent = (sec_prog * 100 / durat_n); - - total_prog = total_prog + (sec_prog - interval); - interval = sec_prog; - int percent2 = Convert.ToInt32(percent); - - if (percent2 <= 100) - { - if (Math.Round(percent, 1).ToString().Contains(".") || Math.Round(percent, 1).ToString().Contains(",")) - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Math.Round(percent, 1).ToString() + "%"); - } - else - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Math.Round(percent, 1).ToString() + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0" + "%"); - } - } - else this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = "100%"); - } - } - //Monitor available space - try - { - if (check_space % 30 == 0 && dest_drive.AvailableFreeSpace <= 500000000 && warn_space == true) - { - DialogResult a = DialogResult.Cancel; - tmp.Suspend(); - a = MessageBox.Show(Strings.warn_sp, Strings.low_sp + " (" + (dest_drive.AvailableFreeSpace / 1000000).ToString() + "MB)", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); - if (a == DialogResult.Yes) - { - resume_glob(); - Thread.Sleep(250); - aborted = true; - StreamWriter write_q = tmp.StandardInput; - write_q.Write("q"); - - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - this.InvokeEx(f => this.Text = "FFmpeg Batch AV Converter"); - if (is_portable == true) this.InvokeEx(f => this.Text = "FFmpeg Batch AV Converter Portable"); - working = false; - time_est_size = 0; - Enable_Controls(); - return; - } - warn_space = false; - } - } - catch { } - - //End monitor available space - } - } - catch { } - - try - { - - tmp.StartInfo.Arguments = String.Empty; - timer_est_size.Stop(); - time_est_size = 0; - this.InvokeEx(f => f.lbl_items.Text = (list_index + 1).ToString() + " " + Strings.of1 + " " + listView1.Items.Count.ToString()); - - list_lines.Add(""); - - if (Settings.Default.quick_queue == true) - { - this.Invoke(new MethodInvoker(delegate - { - Pg1.Value = 100 * list_index / listView1.Items.Count; - Pg1.Text = Pg1.Value.ToString() + "%"; - TaskbarProgress.SetValue(this.Handle, Pg1.Value, Pg1.Maximum); - })); - } - - if (tmp.ExitCode == 0 && aborted == false) - { - list_lines.Add(Strings.output + " " + current_out + " " + Strings.success + " (OK)"); - list_lines.Add(""); - - list_successful.Add(file); - if (skipped == false) - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.success); - - if (chk_delete_source.Checked == true && delete_one == true && delete_def == false) - { - try - { - FileSystem.DeleteFile(file, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.recycled); - } - catch - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.not_recycled); - warn_enc++; - } - } - else if (chk_delete_source.Checked == true && delete_one == true && delete_def == true) - { - try - { - FileInfo fs = new FileInfo(file); - if (fs.IsReadOnly == true) fs.IsReadOnly = false; - File.Delete(file); - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.deleted); - } - catch - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.not_deleted); - warn_enc++; - } - } - - if (chk_overw.CheckState == CheckState.Checked) - { - if (current_out == file) - { - try - { - File.Delete(file); - FileSystem.RenameFile(destino + "\\" + Path.GetFileNameWithoutExtension(file) + "_fftemp" + add_suffix + ext_output1, Path.GetFileNameWithoutExtension(file) + add_suffix + ext_output1); - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.replaced); - refresh_list = true; - } - catch - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.not_replaced); - warn_enc++; - } - } - } - - if (keep_dates == true) - { - try - { - File.SetCreationTime(current_out, file_crea); - File.SetLastWriteTime(current_out, file_written); - File.SetLastAccessTime(current_out, file_modif); - } - catch { } - } - } - else - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.skipped); - total_prog = total_prog + durat_n - sec_prog; - try - { - File.Delete(current_out); - } - catch { } - skipped = false; - } - } - else - { - list_failed.Add(file); - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.error); - errors_enc = errors_enc + 1; - list_lines.Add(Strings.exit_code + ": " + tmp.ExitCode.ToString()); - - if (aborted == true) - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.aborted); - list_lines.Add(Strings.output + " " + current_out + " (" + Strings.aborted.ToUpper() + ")"); - } - else list_lines.Add(Strings.output + " " + current_out + " (" + Strings.failed.ToUpper() + ")"); - list_lines.Add(""); - - } - - list_lines.Add("---------------------End of " + Path.GetFileName(file) + " log-------------------------------"); - list_lines.Add(""); - - } catch { } - - //Save session - if (dur_rpl >= 30) save_queue(); - - //Run on each file - int index = 0; - Boolean sh_check = false; - combo_shut.Invoke(new MethodInvoker(delegate - { - index = combo_shut.SelectedIndex; - })); - chkshut.Invoke(new MethodInvoker(delegate - { - if (chkshut.Checked == true) sh_check = true; - })); - - - if (index == 4 && cancel_queue == false && sh_check == true) - { - this.InvokeEx(f => this.Enabled = false); - Form14 frm_run = new Form14(); - frm_run.txt_path.Text = run_command; - String dest_f = '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file) + add_suffix + ext_output1 + '\u0022'; - if (ext_output1 == "nul") dest_f = '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file) + add_suffix + Path.GetExtension(file).Replace(".", "") + '\u0022'; - - frm_run.args = dest_f + " " + run_command_args; - frm_run.timer1.Interval = 100; - frm_run.ShowDialog(); - this.InvokeEx(f => this.Enabled = true); - Enable_Controls(); - - if (frm_run.proc.ExitCode == 0) - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = "OK & Run"); - list_lines.Add(Strings.ext_com_ok + " " + dest_f + Environment.NewLine + Environment.NewLine); - } - else - { - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = "OK & Error"); - list_lines.Add(Strings.ext_com_err + " " + dest_f + Environment.NewLine + Environment.NewLine); - } - this.InvokeEx(f => this.TopMost = true); - this.InvokeEx(f => this.TopMost = false); - } - - //End run on each file - - String sep = System.Globalization.CultureInfo.CurrentUICulture.NumberFormat.NumberDecimalSeparator; - if (list_index == listView1.Items.Count - 1) - { - //Averages - if (time_n_tasks == 0) time_n_tasks = 1; - Double avg_enc = Math.Round((total_duration / time_n_tasks), 1); - Decimal deci = Convert.ToDecimal(time_n_tasks, CultureInfo.CurrentUICulture); - - try - { - if (cancel_queue == false) - { - - if (tot_frames2 != 0) - { - list_lines.Add(Environment.NewLine + (Strings.avg_perf + " " + avg_enc.ToString() + "x" + " | " + Math.Round(tot_frames2 / time_n_tasks, 0)).ToString() + " fps"); - this.InvokeEx(f => f.lbl_speed.Text = (Strings.avgs + " " + avg_enc.ToString() + "x" + " | " + Math.Round(tot_frames2 / time_n_tasks, 0)).ToString() + " fps"); - } - else - { - list_lines.Add(Environment.NewLine + Strings.avg_perf + " " + avg_enc.ToString() + "x"); - this.InvokeEx(f => f.lbl_speed.Text = Strings.avgs + " " + avg_enc.ToString() + "x"); - } - } - } - catch { } - - //End averages - this.Invoke(new MethodInvoker(delegate - { - Pg1.Value = 100; - Pg1.Text = "100%"; - Pg1.Refresh(); - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - this.Text = "FFmpeg Batch AV Converter"; - if (is_portable == true) this.Text = "FFmpeg Batch AV Converter Portable"; - })); - - - working = false; - timer_est_size.Stop(); - time_est_size = 0; - - - //Save log - if (no_save_logs == false) - { - string[] array_err = list_lines.ToArray(); - String path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.log"; - if (is_portable == true) path = port_path + "ff_batch_portable.log"; - - StreamWriter SaveFile = new StreamWriter(path); - SaveFile.WriteLine("FFmpeg log sesion: " + System.DateTime.Now); - SaveFile.WriteLine("-------------------------------"); - foreach (String item in array_err) - { - SaveFile.WriteLine(item); - } - SaveFile.Close(); - int count = 0; - this.InvokeEx(f => count = listView1.Items.Count); - File.AppendAllText(path, Environment.NewLine + count.ToString() + " " + Strings.files + " " + Strings.queued.ToLower() + Environment.NewLine); - count = count - errors_enc; - File.AppendAllText(path, count.ToString() + " " + Strings.files + " " + Strings.encoded2.ToLower() + Environment.NewLine); - File.AppendAllText(path, errors_enc.ToString() + " " + Strings.errors1 + Environment.NewLine); - File.AppendAllText(path, warn_enc.ToString() + " " + Strings.warn1 + Environment.NewLine + Environment.NewLine); - File.AppendAllText(path, "-------------------------------------------------------"); - File.AppendAllText(path, Environment.NewLine + Strings.end_log + Environment.NewLine); - File.AppendAllText(path, "------------------------------------------------------"); - FileInfo fileInfo = new FileInfo(path); - - var bytes = fileInfo.Length; - - var kilobytes = (double)bytes / 1024; - var megabytes = kilobytes / 1024; - var gigabytes = megabytes / 1024; - - //Format size view - String size = ""; - String separator = "."; - - if (bytes > 1000000000) - { - if (gigabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String gigas = gigabytes.ToString(); - if (gigas.Length >= 5) - { - gigas = gigas.Substring(0, gigas.LastIndexOf(separator) + 3); - size = (gigas + " " + "GB"); - } - else - { - size = (gigas + " " + "GB"); - } - } - - if (bytes >= 1048576 && bytes <= 1000000000) - { - if (megabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - String megas = megabytes.ToString(); - if (megas.Length > 5) - { - megas = megas.Substring(0, megas.LastIndexOf(separator)); - size = (megas + " " + "MB"); - } - else - { - size = (megas + " " + "MB"); - } - } - - if (bytes >= 1024 && bytes < 1048576) - - { - if (kilobytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String kbs = kilobytes.ToString(); - if (kbs.Length >= 5) - { - kbs = kbs.Substring(0, kbs.LastIndexOf(separator)); - size = (kbs + " " + "KB"); - } - else - { - size = (kbs + " " + "KB"); - } - } - if (bytes > -1 && bytes < 1024) - { - String bits = bytes.ToString(); - size = (bits + " Bytes"); - } - - //End Format size view - timer_tasks.Stop(); - TimeSpan t = TimeSpan.FromSeconds(time_n_tasks); - String tx_elapsed = string.Format("{0:D2}h:{1:D2}m:{2:D2}s", - t.Hours, - t.Minutes, - t.Seconds); - File.AppendAllText(path, Environment.NewLine); - File.AppendAllText(path, Environment.NewLine + Strings.total_time + " " + tx_elapsed); - File.AppendAllText(path, Environment.NewLine + Strings.log_size + " " + size); - - //End save log - } - - listView1.Invoke(new MethodInvoker(delegate - { - listView1.SelectedIndices.Clear(); - })); - - - this.Invoke(new MethodInvoker(delegate - { - if (errors_enc == 0 && warn_enc == 0) - { - pic_no_errors.Visible = true; - } - else if (errors_enc == 0 && warn_enc > 0) - { - pic_no_errors.Visible = false; - pic_recording.Visible = false; - toolT002.SetToolTip(this.pic_warnings, Strings.there_w + " " + warn_enc.ToString() + " " + Strings.warnings_last_s); - pic_warnings.Visible = true; - - } - else if (errors_enc > 0) - { - pic_no_errors.Visible = false; - pic_recording.Visible = false; - toolT002.SetToolTip(this.pic_warnings, Strings.there_w + " " + errors_enc.ToString() + " " + Strings.errors_se); - pic_warnings.Visible = true; - } - })); - - //Automatic shutdown check - if (chkshut.Checked && cancel_queue == false) - { - auto_shut(); - return; - } - //End shutdown check - else - { - if (cancel_queue == false) - { - if (chk_delete_source.CheckState == CheckState.Checked && delete_one == false && delete_def == false) - { - Disable_Controls(); - System.Threading.Thread.Sleep(500); - - Label prog_txt = new Label(); - ProgressBar pg_del = new ProgressBar(); - - this.Invoke(new MethodInvoker(delegate - { - - prog_txt.Parent = panel1; - prog_txt.Top = 95; - prog_txt.Left = 80; - prog_txt.Width = 250; - prog_txt.TabIndex = 1; - prog_txt.BackColor = panel1.BackColor; - prog_txt.BorderStyle = BorderStyle.None; - prog_txt.TextAlign = ContentAlignment.MiddleLeft; - prog_txt.BringToFront(); - prog_txt.Text = Strings.to_recycle; - - pg_del.Parent = panel1; - pg_del.Top = 98; - pg_del.Left = 315; - pg_del.Width = 152; - pg_del.Height = 15; - pg_del.TabIndex = 0; - pg_del.BackColor = this.BackColor; - pg_del.Minimum = 0; - pg_del.BringToFront(); - pg_del.Maximum = listView1.Items.Count; - pg_del.Show(); - pg_del.Refresh(); - })); - - int i = 0; - int err = 0; - - try - { - FileOperationAPIWrapper.SendToRecycleBin(list_successful, FileOperationAPIWrapper.FileOperationFlags.FOF_WANTNUKEWARNING); - listView1.Invoke(new MethodInvoker(delegate - { - foreach (ListViewItem item in listView1.Items) - { - String fullpath = item.SubItems[1].Text + "\\" + item.Text; - if (!File.Exists(fullpath)) - { - item.SubItems[5].Text = Strings.recycled; - } - } - })); - } - catch - { - MessageBox.Show(Strings.not_recycled3, Strings.warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - - this.Invoke(new MethodInvoker(delegate - { - prog_txt.Visible = false; - prog_txt.Dispose(); - pg_del.Visible = false; - pg_del.Dispose(); - })); - - Enable_Controls(); - - Boolean all_ok = true; - listView1.Invoke(new MethodInvoker(delegate - { - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[5].Text != Strings.success) - { - all_ok = false; - break; - } - } - })); - - if (all_ok == true) - { - this.InvokeEx(f => f.btn_refresh.PerformClick()); - } - if (list_failed.Count > 0) - { - String path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.log"; - if (is_portable == true) path = port_path + "ff_batch_portable.log"; - - File.AppendAllText(path, Environment.NewLine + Environment.NewLine + Strings.source_not_deleted); - File.AppendAllText(path, Environment.NewLine + "--------------------------------------------------------------"); - foreach (String item in list_failed) - { - File.AppendAllText(path, Environment.NewLine + item); - } - } - } - - if (chk_delete_source.CheckState == CheckState.Checked && delete_one == false && delete_def == true) - { - Disable_Controls(); - System.Threading.Thread.Sleep(500); - - Label prog_txt = new Label(); - ProgressBar pg_del = new ProgressBar(); - - this.Invoke(new MethodInvoker(delegate - { - - prog_txt.Parent = panel1; - prog_txt.Top = 95; - prog_txt.Left = 80; - prog_txt.Width = 250; - prog_txt.TabIndex = 1; - prog_txt.BackColor = panel1.BackColor; - prog_txt.BorderStyle = BorderStyle.None; - prog_txt.TextAlign = ContentAlignment.MiddleLeft; - prog_txt.BringToFront(); - prog_txt.Text = Strings.deleting_proc; - - pg_del.Parent = panel1; - pg_del.Top = 98; - pg_del.Left = 315; - pg_del.Width = 152; - pg_del.Height = 15; - pg_del.TabIndex = 0; - pg_del.BackColor = this.BackColor; - pg_del.Minimum = 0; - pg_del.BringToFront(); - pg_del.Maximum = listView1.Items.Count; - pg_del.Show(); - pg_del.Refresh(); - })); - - int i = 0; - int err = 0; - - foreach (String item in list_successful) - { - try - { - FileInfo fs = new FileInfo(item); - if (fs.IsReadOnly == true) fs.IsReadOnly = false; - File.Delete(item); - this.InvokeEx(f => pg_del.Value = i); - i = i + 1; - listView1.Invoke(new MethodInvoker(delegate - { - foreach (ListViewItem item2 in listView1.Items) - { - if (item2.Text == Path.GetFileName(item)) - { - item2.SubItems[5].Text = Strings.deleted; - } - } - })); - } - catch - { - err = err + 1; - list_failed.Add(item + " " + Strings.not_deleted); - listView1.Invoke(new MethodInvoker(delegate - { - foreach (ListViewItem item2 in listView1.Items) - { - if (item2.Text == Path.GetFileName(item)) - { - item2.SubItems[5].Text = Strings.not_deleted; - } - } - })); - } - - this.InvokeEx(f => prog_txt.Text = Strings.deleting_sourc + " " + i.ToString() + " " + Strings.of1 + " " + listView1.Items.Count); - this.InvokeEx(f => prog_txt.Refresh()); - } - this.Invoke(new MethodInvoker(delegate - { - prog_txt.Visible = false; - prog_txt.Dispose(); - pg_del.Visible = false; - pg_del.Dispose(); - })); - Enable_Controls(); - - if (err > 0) MessageBox.Show(err.ToString() + " " + Strings.not_recycled2 + " " + Strings.check_log, Strings.not_recycled3, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - - Boolean all_ok = true; - listView1.Invoke(new MethodInvoker(delegate - { - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[5].Text != Strings.success) - { - all_ok = false; - break; - } - } - })); - - if (all_ok == true) - { - this.InvokeEx(f => f.btn_refresh.PerformClick()); - } - if (list_failed.Count > 0) - { - String path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.log"; - if (is_portable == true) path = port_path + "ff_batch_portable.log"; - - File.AppendAllText(path, Environment.NewLine + Environment.NewLine + Strings.source_not_deleted); - File.AppendAllText(path, Environment.NewLine + "-------------------------------"); - foreach (String item in list_failed) - { - File.AppendAllText(path, Environment.NewLine + item); - } - } - } - - if (errors_enc == 0 && play_on_end) - { - play_end(); - } - else if (play_on_end) System.Media.SystemSounds.Asterisk.Play(); - - if (Form.ActiveForm == null) - { - if (errors_enc == 0 && warn_enc == 0) - { - notifyIcon1.BalloonTipText = Strings.enc_comp + ". " + Environment.NewLine + listView1.Items.Count.ToString() + " " + Strings.files + " " + Strings.encoded + "."; - notifyIcon1.BalloonTipIcon = ToolTipIcon.Info; - notifyIcon1.BalloonTipTitle = Strings.enc_comp2; - notifyIcon1.ShowBalloonTip(0); - } - else if (errors_enc > 0) - { - notifyIcon1.BalloonTipText = Strings.enc_comp3 + " " + errors_enc.ToString() + " " + Strings.errors1; - notifyIcon1.BalloonTipIcon = ToolTipIcon.Warning; - notifyIcon1.BalloonTipTitle = Strings.enc_comp2; - notifyIcon1.ShowBalloonTip(0); - } - else if (errors_enc == 0 && warn_enc > 0) - { - notifyIcon1.BalloonTipText = Strings.enc_comp3 + " " + warn_enc.ToString() + " " + "warning(s)."; - notifyIcon1.BalloonTipIcon = ToolTipIcon.Warning; - notifyIcon1.BalloonTipTitle = Strings.enc_comp2 + " - " + Strings.warn1; - notifyIcon1.ShowBalloonTip(0); - } - } - - if (chk_open_compl.Checked) - { - if (Directory.Exists(second_path) && Directory.GetFiles(second_path).Length != 0 && ext_output1 == "nul") - { - Process open_processed = new Process(); - open_processed.StartInfo.FileName = "explorer.exe"; - open_processed.StartInfo.Arguments = '\u0022' + second_path + '\u0022'; - open_processed.Start(); - } - if (Directory.Exists(destino) && Directory.GetFiles(destino).Length != 0 && ext_output1 != "nul") - { - Process open_processed = new Process(); - open_processed.StartInfo.FileName = "explorer.exe"; - open_processed.StartInfo.Arguments = '\u0022' + destino + '\u0022'; - open_processed.Start(); - } - else if (Directory.Exists(destino)) - { - try { Directory.Delete(destino); } - catch { } - } - } - } - else - { - this.InvokeEx(f => f.Pg1.Text = "100%"); - //this.InvokeEx(f => MessageBox.Show(Strings.queue_abort, Strings.aborted, MessageBoxButtons.OK, MessageBoxIcon.Error)); - } - } - } - } - - this.InvokeEx(f => this.Cursor = Cursors.Arrow); - Enable_Controls(); - } - - private void del_queue() - { - Task t = Task.Run(() => - { - String save_path_queue = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "saved_queue_temp.ffq"; - if (is_portable == true) save_path_queue = port_path + "saved_queue_temp.ffq"; - String save_path_queue0 = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "saved_queue_temp0.ffq"; - if (is_portable == true) save_path_queue0 = port_path + "saved_queue_temp0.ffq"; - if (File.Exists(save_path_queue)) - try - { - File.Delete(save_path_queue); - } - catch - { - try - { - Thread.Sleep(1000); - File.Delete(save_path_queue); - } - catch (Exception exc) { MessageBox.Show(exc.Message); } - } - - if (File.Exists(save_path_queue0)) - try - { - File.Delete(save_path_queue0); - } - catch - { - try - { - Thread.Sleep(1000); - File.Delete(save_path_queue0); - } - catch (Exception exc) { MessageBox.Show(exc.Message); } - } - - }); - } - private void BG_Seq_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) - { - //lbl_items.Text = listView1.Items.Count.ToString() + " " + Strings.files; - Pg1.Refresh(); - working = false; - timer_queue.Enabled = false; - del_queue(); - - if (errors_enc == 0 && warn_enc == 0 && chkshut.Checked == false) - { - //Output single info - - if (listView1.Items.Count == 1) - { - if (current_out.ToLower().Contains("nul")) return; - System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentUICulture; - String sep_th = ci.NumberFormat.CurrencyGroupSeparator; - String unit = ""; - String dur = ""; - this.Invoke(new MethodInvoker(delegate - { - lbl_est_size.Text = String.Empty; - lbl_bitrate.Text = String.Empty; - Process probe = new Process(); - - List lines_ouput = new List(); - probe.StartInfo.FileName = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - String ffprobe_frames = " " + "--Output=General;%OverallBitRate/String%" + "\\n" + "%FileSize/String3%" + "\\n" + "%Duration/String3%"; - probe.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + current_out + '\u0022'; - probe.StartInfo.RedirectStandardOutput = true; - probe.StartInfo.UseShellExecute = false; - probe.StartInfo.CreateNoWindow = true; - probe.EnableRaisingEvents = true; - probe.Start(); - - while (!probe.StandardOutput.EndOfStream) - { - lines_ouput.Add(probe.StandardOutput.ReadLine()); - } - probe.WaitForExit(); - - if (lines_ouput[0] != null && lines_ouput[0].Length > 0) - { - if (lines_ouput[0].ToLower().Contains(" kb/s")) unit = "Kb/s"; - if (lines_ouput[0].ToLower().Contains(" mb/s")) unit = "Mb/s"; - if (lines_ouput[0].ToLower().Contains(" gb/s")) unit = "Gb/s"; - lines_ouput[0] = lines_ouput[0].Replace(" kb/s", "").Replace(" Mb/s", "").Replace(" Gb/s", ""); - lines_ouput[0] = lines_ouput[0].Replace(" ", sep_th); - lbl_bitrate.Text = Strings.bitrate + ":" + " " + lines_ouput[0] + " " + unit; - } - try - { - if (lines_ouput[1] != null && lines_ouput[1].Length > 0) lbl_est_size.Text = Strings.f_size + ":" + " " + lines_ouput[1].Replace("MiB", "MB").Replace("GiB", "GB").Replace("KiB", "KB"); - if (lines_ouput[2] != null && lines_ouput[2].Length > 0) dur = lines_ouput[2]; - } - catch { } - - })); - - if (no_output_pop == false) - { - Form26 frm26 = new Form26(); - frm26.out_file = current_out; - frm26.dur_file = dur; - if (Settings.Default.dark_mode == false) frm26.pic_img = pic_reading.Image; - else frm26.pic_img = pic_reading.InitialImage; - frm26.tot_bit = lbl_bitrate.Text; - frm26.out_size = lbl_est_size.Text; - frm26.Show(this); - if (frm26.no_pop == true) no_output_pop = true; - } - } - - //End output single info - } - } - - private void btn_trim_Click(object sender, EventArgs e) - { - Pg1.Focus(); - lbl_est_size.Text = ""; - lbl_bitrate.Text = ""; - Pg1.Text = "0" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0%"; - if (!File.Exists(Path.Combine(Application.StartupPath, "ffmpeg.exe"))) - { - MessageBox.Show(Strings.no_ffmpeg, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - was_started.Text = btn_trim.Text; - foreach (ListViewItem file in listView1.Items) - { - if (!File.Exists(file.SubItems[1].Text + "\\" + file.Text)) - { - MessageBox.Show(Strings.file_not_found + " " + file.Text, Strings.file_not_found2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - - if (listView1.Items.Count == 0) - { - MessageBox.Show(Strings.list_empty, Strings.no_files, MessageBoxButtons.OK, MessageBoxIcon.Information); - return; - } - if (txt_parameters.Text == "") - { - MessageBox.Show(Strings.params_bl, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (txt_ini.Text == "0:00:00.000" && txt_fin.Text == "0:00:00.000") - { - MessageBox.Show(Strings.trim_zero, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (txt_ini.BackColor == Color.Orange || txt_fin.BackColor == Color.Orange) - { - MessageBox.Show(Strings.time_wrong, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (TimeSpan.Parse(txt_ini.Text).TotalSeconds >= TimeSpan.Parse(txt_fin.Text).TotalSeconds && chk_trim2.Checked == false) - { - MessageBox.Show(Strings.end_short, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (listView1.Items.Count > 1 && chk_trim2.Checked == false) - { - DialogResult a = MessageBox.Show(Strings.trim1 + " " + Strings.all_files + " " + Strings.trim2, Strings.trim3, MessageBoxButtons.YesNo, MessageBoxIcon.Question); - if (a == DialogResult.No) - { - return; - } - - avoid_overw(); - } - - if (txt_format.Text == "") - { - DialogResult a = MessageBox.Show(Strings.format_no, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - - //Check path is writable - String destino1 = String.Empty; - Boolean rel_path = false; - String element1 = listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text; - if (txt_path_main.Text.Contains(".\\")) - { - destino1 = element1.Substring(0, element1.LastIndexOf('\\')) + txt_path_main.Text.Replace(".", String.Empty); - rel_path = true; - } - else - { - if (chk_recreate.CheckState == CheckState.Checked) - { - String pre_dest = Path.GetDirectoryName(element1); - destino1 = Path.Combine(txt_path_main.Text, pre_dest.Substring(3, pre_dest.Length - 3)); - rel_path = true; - } - else - { - destino1 = txt_path_main.Text; - } - } - - try - { - if (rel_path == true) - { - Directory.CreateDirectory(destino1); - System.Threading.Thread.Sleep(10); - } - else - { - if (!Directory.Exists(destino1)) Directory.CreateDirectory(destino1); - File.WriteAllText(destino1 + "\\" + "FFBatch_test.txt", "FFBatch_test"); - System.Threading.Thread.Sleep(10); - File.Delete(destino1 + "\\" + "FFBatch_test.txt"); - } - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.write_error1 + " " + excpt.Message, Strings.write_error2, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - //End path is writable - - //Pending duration - - if (dur_ok == false) - { - list_pending_dur.Items.Clear(); - foreach (ListViewItem item in listView1.Items) - { - list_pending_dur.Items.Add((ListViewItem)item.Clone()); - } - BG_Dur.RunWorkerAsync(); - return; - } - - //Check queued items - - if (warn_success_items == true) - { - Boolean no_queued = true; - Boolean has_complete = false; - foreach (ListViewItem item in listView1.Items) - { - if (item.SubItems[5].Text == Strings.queued) - { - no_queued = false; - } - if (item.SubItems[5].Text == Strings.success || item.SubItems[5].Text == Strings.replaced) - { - has_complete = true; - } - } - - if (no_queued == true && listView1.Items.Count > 1) - { - DialogResult a = MessageBox.Show(Strings.items_q + " " + '\u0022' + Strings.queued + '\u0022' + ". " + Strings.all_files + " " + Strings.already_proc, Strings.not_queued, MessageBoxButtons.OKCancel, MessageBoxIcon.Question); - if (a == DialogResult.Cancel) return; - } - - if (no_queued == false && has_complete == true) - { - DialogResult a = MessageBox.Show(Strings.already_encoded + " " + '\u0022' + Strings.queued + '\u0022' + Strings.continu, Strings.some_q, MessageBoxButtons.OKCancel, MessageBoxIcon.Question); - if (a == DialogResult.Cancel) return; - } - //End check queued items - } - - listBox4.Items.Clear(); - Disable_Controls(); - txt_remain.Text = Strings.remain_time + " " + "00h:00m:00s"; - - String ffm = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - - foreach (ListViewItem file in listView1.Items) - { - if (TimeSpan.Parse(file.SubItems[3].Text).TotalSeconds < (TimeSpan.Parse(txt_fin.Text).TotalSeconds - TimeSpan.Parse(txt_ini.Text).TotalSeconds)) - { - MessageBox.Show(Strings.trim_ex, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - foreach (Control p in groupBox1.Controls) - { - p.Enabled = true; - } - - Enable_Controls(); - return; - } - - if (TimeSpan.Parse(file.SubItems[3].Text).TotalSeconds == (TimeSpan.Parse(txt_fin.Text).TotalSeconds - TimeSpan.Parse(txt_ini.Text).TotalSeconds)) - { - MessageBox.Show(Strings.trim_z, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - foreach (Control p in groupBox1.Controls) - { - p.Enabled = true; - } - - Enable_Controls(); - return; - } - - if (TimeSpan.Parse(file.SubItems[3].Text).TotalSeconds < TimeSpan.Parse(txt_fin.Text).TotalSeconds) - { - MessageBox.Show(Strings.trim_f, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - foreach (Control p in groupBox1.Controls) - { - p.Enabled = true; - } - - Enable_Controls(); - return; - } - - if (TimeSpan.Parse(file.SubItems[3].Text).TotalSeconds < TimeSpan.Parse(txt_ini.Text).TotalSeconds) - { - MessageBox.Show(Strings.trim_i, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - foreach (Control p in groupBox1.Controls) - { - p.Enabled = true; - } - - Enable_Controls(); - return; - } - } - - if (avoid_overwriting == true && txt_path_main.Text.Contains(".\\") == false && txt_path_main.Text.Length < 4 && chk_recreate.CheckState != CheckState.Checked) - { - avoid_overwriting = false; - DialogResult a2 = MessageBox.Show(Strings.multiple_folders + " " + '\u0022' + Strings.recreate_path + '\u0022' + " " + Strings.avoid_overw + ". " + Strings.continu, Strings.warning, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); - if (a2 == DialogResult.No) return; - } - - // Fade validation - - if (fade_a_in.Checked && num_a_in.Value == 0) - { - MessageBox.Show(Strings.fading_zero); - Enable_Controls(); - return; - } - if (fade_a_out.Checked && num_a_out.Value == 0) - { - Enable_Controls(); - return; - } - - fade_ok = true; - check_fade(); - if (fade_ok == false) - { - Enable_Controls(); - return; - } - // END Fade validation - - //Validated list, start processing - if (listView1.SelectedIndices.Count == 0) - { - listView1.Items[0].Selected = true; - listView1.Items[0].Focused = true; - listView1.Focus(); - } - - //Fade color conversion - String f_in_color = "Black"; - String f_out_color = "Black"; - String in_color = ":color=" + f_in_color; - String out_color = ":color=" + f_out_color; - if (combo_vin_col.SelectedIndex == 1) f_in_color = "White"; - if (combo_vout_color.SelectedIndex == 1) f_out_color = "White"; - if (combo_vin_col.SelectedIndex == 2) in_color = ":alpha=1"; - if (combo_vout_color.SelectedIndex == 2) out_color = ":alpha=1"; - - //End Fade color conversion - - String sel_test = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - this.Cursor = Cursors.WaitCursor; - - String file_prueba = ""; - - file_prueba = sel_test; - String fichero = Path.GetFileName(file_prueba); - - String destino_test = Path.Combine(Path.GetTempPath(), "FFBatch_test"); - - //Try preset - if (!chk_try.Checked) - { - if (!Directory.Exists(destino_test)) - { - try - { - Directory.CreateDirectory(destino_test); - } - catch (System.Exception excpt) - { - MessageBox.Show(Strings.error2 + " " + excpt.Message, Strings.write_error2, MessageBoxButtons.OK, MessageBoxIcon.Error); - this.Cursor = Cursors.Arrow; - return; - } - } - if (!chk_try.Checked) - { - Process consola_pre = new Process(); - consola_pre.StartInfo.FileName = "ffmpeg.exe"; - consola_pre.StartInfo.Arguments = " -i " + "" + '\u0022' + file_prueba + '\u0022' + "" + " " + "-ss 0 -t 1 " + " -y " + txt_parameters.Text + " " + '\u0022' + destino_test + "\\" + Path.GetFileNameWithoutExtension(file_prueba) + "." + txt_format.Text + '\u0022'; - consola_pre.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - consola_pre.Start(); - System.Threading.Thread.Sleep(50); - - if (combo_prio.SelectedIndex != 2) - { - Change_mem_prio(); - } - - consola_pre.WaitForExit(); - - if (consola_pre.ExitCode != 0) - { - Enable_Controls(); - this.Cursor = Cursors.Arrow; - MessageBox.Show(Strings.test_err, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); - this.Cursor = Cursors.Arrow; - - if (Directory.GetFiles(destino_test).Length == 0) - { - Directory.Delete(destino_test); - } - - return; - } - } - } - //END try preset - - if (chk_trim2.Checked == false) - { - if (fade_v_in.Checked || fade_v_out.Checked || fade_a_in.Checked || fade_a_out.Checked) - { - MessageBox.Show(Strings.trim_fade_n); - Enable_Controls(); - this.Cursor = Cursors.Arrow; - return; - } - } - - for (int i = 0; i < listView1.Items.Count; i++) - { - for (int j = i + 1; j < listView1.Items.Count; j++) - { - String elem = listView1.Items[i].SubItems[1].Text + "\\" + listView1.Items[i].Text; - String elem2 = listView1.Items[j].SubItems[1].Text + "\\" + listView1.Items[j].Text; - if (Path.GetFileNameWithoutExtension(elem) == Path.GetFileNameWithoutExtension(elem2) && (chk_recreate.CheckState != CheckState.Checked)) - { - MessageBox.Show(Strings.the_files + " " + Environment.NewLine + Environment.NewLine + Path.GetFileName(listView1.Items[i].Text) + Environment.NewLine + Path.GetFileName(listView1.Items[j].Text) + Environment.NewLine + Environment.NewLine + Strings.same_out + Environment.NewLine + Environment.NewLine + Strings.remove_inv, Strings.same_name, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - Enable_Controls(); - this.Cursor = Cursors.Arrow; - return; - } - } - } - - //Monitor available space - current_out = txt_path_main.Text; - DriveInfo dest_drive2 = new DriveInfo(Application.StartupPath); - try - { - FileInfo f_root2 = new FileInfo(current_out); - dest_drive2 = new DriveInfo(f_root2.Directory.Root.FullName); - } - catch { warn_space = false; } - - if (dest_drive2.AvailableFreeSpace != null && warn_space == true) - { - if (dest_drive2.AvailableFreeSpace <= 500000000) - { - DialogResult a = DialogResult.Cancel; - - a = MessageBox.Show(Strings.warn_sp, Strings.low_sp + " (" + (dest_drive2.AvailableFreeSpace / 1000000).ToString() + "MB)", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); - if (a == DialogResult.Yes) - { - aborted = true; - lbl_est_size.Text = ""; - lbl_bitrate.Text = ""; - return; - } - } - } - //End monitor available space - - filter_chars(); - - Double total_prog = 0; - Double total_t = 0; - - //Begin fading and volume changing - String change_vol_fade = ""; - if (chk_vol.Checked == true) - { - change_vol_fade = "-af " + '\u0022' + "volume=" + vol_ch.Value.ToString() + "dB " + '\u0022' + " "; - } - - String fade_filter = String.Empty; - Decimal fade_frames = 0; - String itfull = ""; - String ff_frames = String.Empty; - Process get_frames = new Process(); - - foreach (ListViewItem item in listView1.Items) - { - if (chk_trim2.Checked) - { - if (item.SubItems[3].Text != Strings.n_a && item.SubItems[3].Text != "0:00:00.000" && item.SubItems[3].Text != "00:00:00.000" && item.SubItems[3].Text != Strings.pending) - { - total_t = total_t + TimeSpan.Parse(item.SubItems[3].Text).TotalSeconds - TimeSpan.Parse(ss_time_input.Text).TotalSeconds - TimeSpan.Parse(txt_ini.Text).TotalSeconds - TimeSpan.Parse(txt_fin.Text).TotalSeconds; - } - } - else - { - if (item.SubItems[3].Text != Strings.n_a && item.SubItems[3].Text != "0:00:00.000" && item.SubItems[3].Text != "00:00:00.000" && item.SubItems[3].Text != Strings.pending) - { - total_t = total_t + TimeSpan.Parse(txt_fin.Text).TotalSeconds - TimeSpan.Parse(txt_ini.Text).TotalSeconds; - } - } - } - total_duration = total_t; - - this.Cursor = Cursors.Arrow; - Pg1.Maximum = 100; - Pg1.Minimum = 0; - cancel_queue = false; - Pg1.Value = 0; - - ListView list_proc = new ListView(); - foreach (ListViewItem item in listView1.Items) - { - list_proc.Items.Add((ListViewItem)item.Clone()); - item.SubItems[5].Text = Strings.queued; - } - - listView1.SelectedIndices.Clear(); - - Double dura2 = 0; - time_n_tasks = 0; - errors_enc = 0; - pic_warnings.Visible = false; - pic_no_errors.Visible = false; - timer_tasks.Start(); - - List list_lines = new List(); - procs.Clear(); - - for (int ii = 0; ii < listView1.Items.Count; ii++) - { - procs.Add("proc_urls_" + ii.ToString(), new Process()); - } - Disable_Controls(); - working = true; - notifyIcon1.Visible = true; - - //Begin new thread code for trimming - new System.Threading.Thread(() => - { - System.Threading.Thread.CurrentThread.IsBackground = true; - String remain_time = ""; - - - for (int list_index = 0; list_index < listView1.Items.Count; list_index++) - { - String file = list_proc.Items[list_index].SubItems[1].Text + "\\" + list_proc.Items[list_index].Text; - var tmp = procs["proc_urls_" + list_index.ToString()]; - - if (cancel_queue == true) - { - working = false; - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - this.InvokeEx(f => f.btn_seq.Enabled = true); - Enable_Controls(); - MessageBox.Show(Strings.queue_abort, Strings.task_abort, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; - } - - String ffm2 = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - String fullPath = file; - - Decimal trim_ini = (decimal)TimeSpan.Parse(txt_ini.Text).TotalSeconds; - Decimal trim_fin = (decimal)TimeSpan.Parse(txt_fin.Text).TotalSeconds; - Decimal af_in_dec = 0; - Decimal af_out_dec = 0; - String ss_st = "ss"; - - - this.Invoke(new MethodInvoker(delegate - { - Double file_dur = TimeSpan.Parse(listView1.Items[list_index].SubItems[3].Text).TotalSeconds; - if (fade_v_in.CheckState == CheckState.Checked || fade_v_out.CheckState == CheckState.Checked) - { - itfull = listView1.Items[list_index].SubItems[1].Text + "\\" + listView1.Items[list_index].Text; - - get_frames.StartInfo.FileName = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - String ffprobe_frames = " " + '\u0022' + "--Inform=Video;%FrameRate%" + '\u0022'; - get_frames.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + itfull + '\u0022'; - get_frames.StartInfo.RedirectStandardOutput = true; - get_frames.StartInfo.UseShellExecute = false; - get_frames.StartInfo.CreateNoWindow = true; - get_frames.EnableRaisingEvents = true; - get_frames.Start(); - - ff_frames = get_frames.StandardOutput.ReadLine(); - get_frames.WaitForExit(); - - if (get_frames.ExitCode == 0) - { - if (ff_frames != null) - { - fade_frames = decimal.Parse(ff_frames) / 1000; - } - } - get_frames.Dispose(); - - - if (fade_v_in.CheckState == CheckState.Checked && fade_v_out.CheckState == CheckState.Unchecked) - { - Decimal fff_in = Math.Round(num_v_in.Value * fade_frames, 0); - fade_filter = "-vf " + '\u0022' + "fade=in:0:" + fff_in.ToString() + in_color + '\u0022'; - } - - if (fade_v_in.CheckState == CheckState.Unchecked && fade_v_out.CheckState == CheckState.Checked) - { - Decimal f_out = Math.Round(((decimal)file_dur - trim_fin) * fade_frames, 0); - Double dur_frames = (file_dur - (double)trim_ini - (double)trim_fin) * Convert.ToDouble(fade_frames); - Decimal fade_out_total = Math.Round(Convert.ToDecimal(dur_frames), 3, MidpointRounding.AwayFromZero); - Decimal fade_out_initial = Math.Round(fade_out_total - (num_v_out.Value * fade_frames), 0, MidpointRounding.AwayFromZero); - Decimal fff_out = Math.Round(num_v_out.Value * fade_frames, 0, MidpointRounding.AwayFromZero); - - if (trim_ini > 0 && trim_fin > 0) - { - fade_filter = "-vf " + '\u0022' + "fade=out:" + f_out.ToString() + ":" + fff_out.ToString() + out_color + '\u0022'; - } - else fade_filter = "-vf " + '\u0022' + "fade=out:" + fade_out_initial.ToString() + ":" + fff_out.ToString() + out_color + '\u0022'; - - } - - if (fade_v_in.CheckState == CheckState.Checked && fade_v_out.CheckState == CheckState.Checked) - { - Decimal f_in = Math.Round(trim_ini * fade_frames, 0); - Decimal f_out = Math.Round(((decimal)file_dur - trim_fin) * fade_frames, 0); - Decimal fff_in = Math.Round(num_v_in.Value * fade_frames, 0); - Double dur_frames = (file_dur - (double)trim_ini - (double)trim_fin) * Convert.ToDouble(fade_frames); - Decimal fade_out_total = Math.Round(Convert.ToDecimal(dur_frames), 3, MidpointRounding.AwayFromZero); - Decimal fade_out_initial = Math.Round(fade_out_total - (num_v_out.Value * fade_frames), 0, MidpointRounding.AwayFromZero); - Decimal fff_out = Math.Round(num_v_out.Value * fade_frames, 0, MidpointRounding.AwayFromZero); - if (trim_ini > 0 && trim_fin > 0) - { - fade_filter = "-vf " + '\u0022' + "fade=in:" + f_in.ToString() + ":" + fff_in.ToString() + in_color + ", " + "fade=out:" + f_out.ToString() + ":" + fff_out.ToString() + out_color + '\u0022'; - } - else fade_filter = "-vf " + '\u0022' + "fade=in:0:" + fff_in.ToString() + in_color + ", " + "fade=out:" + fade_out_initial.ToString() + ":" + fff_out.ToString() + out_color + '\u0022'; - } - } - - //Audio fading - if (fade_a_in.CheckState == CheckState.Checked && fade_a_out.CheckState == CheckState.Unchecked) - { - - if (chk_vol.Checked == false) - { - change_vol_fade = "-af " + '\u0022' + "afade=t=in:ss=" + trim_ini.ToString() + ":d=" + num_a_in.Value.ToString() + '\u0022'; - } - else - { - change_vol_fade = "-af " + '\u0022' + "afade=t=in:ss=" + trim_ini.ToString() + ":d=" + num_a_in.Value.ToString() + ", " + "volume=" + vol_ch.Value.ToString() + "dB " + '\u0022'; - } - } - - if (fade_a_in.CheckState == CheckState.Unchecked && fade_a_out.CheckState == CheckState.Checked) - { - Double af_out = file_dur - Convert.ToDouble(num_a_out.Value); - af_out_dec = Math.Round(Convert.ToDecimal(af_out), 0, MidpointRounding.AwayFromZero); - if (chk_trim2.Checked) - { - af_out_dec = af_out_dec - trim_ini - trim_fin; - } - if (chk_vol.Checked == false) - { - change_vol_fade = "-af " + '\u0022' + "afade=t=out:st=" + af_out_dec + ":d=" + num_a_out.Value.ToString() + '\u0022'; - } - else - { - change_vol_fade = "-af " + '\u0022' + "afade=t=out:st=" + af_out_dec + ":d=" + num_a_out.Value.ToString() + ", " + "volume=" + vol_ch.Value.ToString() + "dB " + '\u0022'; - } - } - - if (fade_a_in.CheckState == CheckState.Checked && fade_a_out.CheckState == CheckState.Checked) - { - af_out_dec = Math.Round(Convert.ToDecimal(file_dur), 0, MidpointRounding.AwayFromZero); - - if (chk_trim2.Checked) - { - if (trim_ini > 0 && trim_fin > 0) - { - af_out_dec = af_out_dec - num_a_out.Value - trim_fin; - af_in_dec = trim_ini; - ss_st = "st"; - } - else - { - af_out_dec = af_out_dec - trim_ini - num_a_out.Value - trim_fin; - af_in_dec = af_in_dec + trim_ini; - } - } - - if (chk_vol.Checked == false) - { - change_vol_fade = "-af " + '\u0022' + "afade=t=in:" + ss_st + "=" + af_in_dec.ToString() + ":d=" + num_a_in.Value.ToString() + ", " + "afade=t=out:st=" + af_out_dec + ":d=" + num_a_out.Value.ToString() + '\u0022'; - } - else - { - change_vol_fade = "-af " + '\u0022' + "afade=t=in:" + ss_st + "=" + af_in_dec.ToString() + ":d=" + num_a_in.Value.ToString() + ", " + "afade=t=out:st=" + af_out_dec + ":d=" + num_a_out.Value.ToString() + ", " + "volume=" + vol_ch.Value.ToString() + "dB " + '\u0022'; - } - } - - })); - - //End audio fading - - //End fading - - //Begin Shifting - String shifting = ""; - if (chk_shift.Checked) - { - shifting = " -itsoffset " + Num_Shift.Value.ToString().Replace(",", ".") + " -i " + '\u0022' + file + '\u0022' + " -map 1:v -map 0:a "; - } - - //End Shifting - - //Change Volume - String change_vol = ""; - if (chk_vol.Checked) - { - change_vol = "-filter:a " + '\u0022' + "volume=" + vol_ch.Value.ToString() + "dB " + '\u0022' + " "; - } - //End change volume - - String destino = ""; - if (txt_path_main.Text.Contains(".\\")) - { - destino = file.Substring(0, fullPath.LastIndexOf('\\')) + txt_path_main.Text.Replace(".", String.Empty); - } - else - { - if (chk_recreate.CheckState == CheckState.Checked) - { - String pre_dest = Path.GetDirectoryName(file); - destino = Path.Combine(txt_path_main.Text, pre_dest.Substring(3, pre_dest.Length - 3)); - } - else - { - destino = txt_path_main.Text; - } - } - - add_suffix = ""; - if (chk_suffix.Checked == true && txt_suffix.Text != String.Empty) - { - add_suffix = txt_suffix.Text; - } - - String ext_output1 = txt_format.Text; - if (txt_format.Text == String.Empty) - { - ext_output1 = Path.GetExtension(file); - } - else - { - ext_output1 = "." + txt_format.Text; - } - String AppParam = String.Empty; - - if (chk_trim2.Checked == false) - { - AppParam = " -ss " + txt_ini.Text + " -to " + txt_fin.Text + " -i " + '\u0022' + file + '\u0022' + shifting + " -y " + txt_parameters.Text + " " + change_vol + '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file) + add_suffix + ext_output1 + '\u0022' + " -hide_banner"; - } - else - { - - tmp.StartInfo.FileName = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - String ffprobe_frames = " " + '\u0022' + "--Inform=General;%Duration/String3%" + '\u0022'; - tmp.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + file + '\u0022'; - - tmp.StartInfo.RedirectStandardOutput = true; - tmp.StartInfo.UseShellExecute = false; - tmp.StartInfo.CreateNoWindow = true; - tmp.EnableRaisingEvents = true; - tmp.Start(); - - String duracion = tmp.StandardOutput.ReadToEnd(); - tmp.WaitForExit(); - - if (duracion == null) duracion = "0"; - TimeSpan time; - if (!TimeSpan.TryParse(duracion, out time)) - { - duracion = "0"; - } - - String trim_end_2 = duracion; - DateTime init_trim = Convert.ToDateTime(txt_ini.Text); - DateTime final_trim = Convert.ToDateTime(txt_fin.Text); - DateTime dur_date = Convert.ToDateTime(trim_end_2); - var trim_to = dur_date.Subtract(final_trim); - - if (txt_fin.Text == "0:00:00.000" || txt_fin.Text == "00:00:00.000") - { - AppParam = " -ss " + txt_ini.Text + " -i " + "" + '\u0022' + file + '\u0022' + shifting + " -y " + txt_parameters.Text + " " + change_vol + fade_filter + " " + change_vol_fade + " " + '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file) + add_suffix + ext_output1 + '\u0022' + " -hide_banner"; - } - else - { - AppParam = " -i " + "" + '\u0022' + file + '\u0022' + shifting + " " + " -ss " + txt_ini.Text + " -to " + trim_to + " -y " + txt_parameters.Text + " " + change_vol + fade_filter + " " + change_vol_fade + " " + '\u0022' + destino + "\\" + Path.GetFileNameWithoutExtension(file) + add_suffix + ext_output1 + '\u0022' + " -hide_banner"; - } - } - - if (!Directory.Exists(destino)) - { - Directory.CreateDirectory(destino); - } - FileInfo f_root = new FileInfo(Path.GetFileNameWithoutExtension(file) + add_suffix + ext_output1); - DriveInfo dest_drive = new DriveInfo(Application.StartupPath); - try - { - dest_drive = new DriveInfo(f_root.Directory.Root.FullName); - } - catch { warn_space = false; } - - tmp.StartInfo.FileName = ffm2; - tmp.StartInfo.Arguments = AppParam; - tmp.StartInfo.RedirectStandardInput = true; - tmp.StartInfo.RedirectStandardError = true; - tmp.StartInfo.StandardErrorEncoding = Encoding.UTF8; - tmp.StartInfo.UseShellExecute = false; - tmp.StartInfo.CreateNoWindow = true; - tmp.EnableRaisingEvents = true; - - valid_prog = false; - this.InvokeEx(f => f.listView1.Items[list_index].SubItems[5].Text = Strings.processing); - - tmp.Start(); - System.Threading.Thread.Sleep(50); - - combo_prio.Invoke(new MethodInvoker(delegate - { - if (combo_prio.SelectedIndex != 2) - { - Change_mem_prio(); - } - })); - - valid_prog = false; - this.InvokeEx(f => validate_duration = listView1.Items[list_index].SubItems[3].Text); - if (validate_duration != Strings.n_a && validate_duration != "0:00:00" && validate_duration != "00:00:00" && validate_duration != Strings.pending) - { - valid_prog = true; - } - - - timer_est_size.Start(); - time_est_size = 0; - Decimal est_bitrate = 0; - Decimal est_size = 0; - Double sec_prog = 0; - Double interval = 0; - - String err_txt = ""; - - while (!tmp.StandardError.EndOfStream) - { - try - { - err_txt = tmp.StandardError.ReadLine(); - check_space++; - list_lines.Add(err_txt); - - if (err_txt.Contains("time=") && err_txt.Contains("time=-") == false && !err_txt.Contains("N/A")) - { - this.InvokeEx(f => durat_n = TimeSpan.Parse(listView1.Items[list_index].SubItems[3].Text).TotalSeconds); - if (chk_trim2.Checked) durat_n = durat_n - TimeSpan.Parse(txt_fin.Text).TotalSeconds - TimeSpan.Parse(txt_ini.Text).TotalSeconds; - else durat_n = TimeSpan.Parse(txt_fin.Text).TotalSeconds - TimeSpan.Parse(txt_ini.Text).TotalSeconds; - - this.InvokeEx(f => durat_n = durat_n - TimeSpan.Parse(ss_time_input.Text).TotalSeconds); - if (durat_n < 0) durat_n = 1; - int start_time_index = err_txt.IndexOf("time=") + 5; - sec_prog = TimeSpan.Parse(err_txt.Substring(start_time_index, 8)).TotalSeconds; - - Double percent = (sec_prog * 100 / durat_n); - - total_prog = total_prog + (sec_prog - interval); - interval = sec_prog; - int percent2 = Convert.ToInt32(percent); - - Double percent_tot = (total_prog * 100 / total_duration); - int percent_tot_2 = 0; - try { percent_tot_2 = Convert.ToInt32(percent_tot); } catch { } - - this.Invoke(new MethodInvoker(delegate - { - if (percent_tot_2 <= 100) - { - Pg1.Value = percent_tot_2; - Pg1.Refresh(); - - if (Math.Round(percent_tot, 1).ToString().Contains(".") || Math.Round(percent_tot, 1).ToString().Contains(",")) - { - Pg1.Text = Math.Round(percent_tot, 1).ToString() + "%"; - } - else - { - Pg1.Text = Math.Round(percent_tot, 1).ToString() + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0" + "%"; - } - - TaskbarProgress.SetValue(this.Handle, percent_tot, Pg1.Maximum); - } - - if (percent2 <= 100) - { - if (Math.Round(percent, 1).ToString().Contains(".") || Math.Round(percent, 1).ToString().Contains(",")) - { - listView1.Items[list_index].SubItems[5].Text = Math.Round(percent, 1).ToString() + "%"; - } - else - { - listView1.Items[list_index].SubItems[5].Text = Math.Round(percent, 1).ToString() + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "0" + "%"; - } - } - })); - - if (cancel_queue == false) - { - String fps_perf = String.Empty; - //Estimated remaining time - - remain_time = err_txt.Substring(err_txt.LastIndexOf("speed=") + 6, err_txt.Length - err_txt.LastIndexOf("speed=") - 6); - if (err_txt.Contains("fps=")) - { - fps_perf = (err_txt.Substring(err_txt.IndexOf("fps=") + 4, 4)).TrimStart(); - } - if (fps_perf.Length > 0) fps_perf = " | " + fps_perf.TrimEnd() + " fps"; - if (fps_perf.Contains("0.0")) - { - fps_perf = String.Empty; - } - - if (time_est_size % 2 == 0) - { - String chk_0 = (Strings.speed + " " + remain_time).TrimEnd() + fps_perf; - if (chk_0.Substring(chk_0.Length - 3, 3) == " 0x") - { - this.InvokeEx(f => f.lbl_speed.Text = ""); - } - else this.InvokeEx(f => f.lbl_speed.Text = (Strings.speed + " " + remain_time).TrimEnd() + fps_perf); - } - - remain_time = remain_time.Replace("x", String.Empty); - Double timing1 = 0; - if (!remain_time.Contains("N/A")) - { - if (System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",") - { - timing1 = Math.Round(Double.Parse(remain_time.Replace(".", ",")), 2); - } - else - { - timing1 = Math.Round(Double.Parse(remain_time), 2); - } - } - else timing1 = 0; - - Decimal timing = (decimal)timing1; - Decimal total_dur_dec = Convert.ToDecimal(total_duration); - Decimal total_prog_dec = Convert.ToDecimal(total_prog); - Decimal remain_secs = 0; - if (timing > 0) - { - remain_secs = (decimal)(total_dur_dec - total_prog_dec) / timing; - } - - if (remain_secs > 60) - { - remain_secs = remain_secs + 60; - } - - String remain_from_secs = ""; - - TimeSpan t = TimeSpan.FromSeconds(Convert.ToDouble(remain_secs)); - remain_from_secs = string.Format("{0:D2}h:{1:D2}", - t.Hours, - t.Minutes); - - this.Invoke(new MethodInvoker(delegate - { - if (remain_secs >= 43200) - { - txt_remain.Text = Strings.remain_time + " " + Math.Round(remain_secs / 3600).ToString() + " " + Strings.hours; - this.Text = Pg1.Text + " / " + Math.Round(remain_secs / 3600).ToString() + " " + Strings.hours; - } - - if (remain_secs >= 3600 && remain_secs < 43200) - { - txt_remain.Text = Strings.remain_time + " " + remain_from_secs + " " + Strings.minutes_abrev; - this.Text = Pg1.Text + " / " + remain_from_secs + " " + Strings.minutes_abrev; - } - - if (remain_secs < 3600 && remain_secs >= 600) - { - txt_remain.Text = Strings.remain_time + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 1, 2) + " " + Strings.minutes; - this.Text = Pg1.Text + " / " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 1, 2) + " " + Strings.minutes_abrev; - } - if (remain_secs < 600 && remain_secs >= 120) - { - txt_remain.Text = Strings.remain_time + " " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 2, 1) + " " + Strings.minutes; - this.Text = Pg1.Text + " / " + remain_from_secs.Substring(remain_from_secs.LastIndexOf(":") + 2, 1) + " " + Strings.minutes_abrev; - } - - if (remain_secs <= 59 && remain_secs != 0) - { - txt_remain.Text = Strings.remain_time + " " + Convert.ToInt16(Math.Abs(remain_secs)) + " " + Strings.seconds; - this.Text = Pg1.Text + " / " + Convert.ToInt16(Math.Abs(remain_secs)) + " s"; - } - if (remain_secs == 0) - { - txt_remain.Text = Strings.remain_time + " " + Strings.about_finish; - this.Text = Pg1.Text; - } - })); - } - - } - //End remaining time - - //Estimated size and bitrate - - String read_size = String.Empty; - - if (err_txt.Contains("size=") && (err_txt.Contains("N/A") == false) && (time_est_size % 2 == 0)) - { - - int size_index = err_txt.IndexOf("size=") + 5; - read_size = err_txt.Substring(size_index, 8); - if (Convert.ToDecimal(sec_prog) != 0 & read_size.Contains(Strings.n_a) == false) - { - est_bitrate = (Math.Round(Convert.ToDecimal(read_size) * 8 / Convert.ToDecimal(sec_prog), 0)); - } - else - { - est_bitrate = 0; - } - this.Invoke(new MethodInvoker(delegate - { - if (read_size.Contains(Strings.n_a) == false && Convert.ToDecimal(read_size) > 1 && time_n_tasks > 1) - { - - if (est_bitrate < 9999) - { - if (est_bitrate > 48) - { - lbl_bitrate.Text = Strings.avg_bit + ": " + est_bitrate + " " + "Kb/s"; - } - else - { - lbl_bitrate.Text = Strings.avg_bit + ": "; - } - } - else - { - lbl_bitrate.Text = Strings.avg_bit + ": " + (Math.Round(est_bitrate / 1000, 0)) + " " + "Mb/s"; - } - //Estimated size - est_size = Convert.ToDecimal(durat_n) * est_bitrate / 8; - - if (est_size > 1000000) - { - lbl_est_size.Text = Strings.est_size + " " + (Math.Round(est_size / 1000000, 1)).ToString() + " " + "GB"; - } - else - { - if (Math.Round(est_size / 1000, 0) > 0) - { - lbl_est_size.Text = Strings.est_size + " " + (Math.Round(est_size / 1000, 0)).ToString() + " " + "MB"; - } - else - { - lbl_est_size.Text = Strings.est_size + " "; - } - } - lbl_est_size.Refresh(); - } - })); - } - } - catch { } - - //Monitor available space - - if (check_space % 30 == 0 && dest_drive.AvailableFreeSpace <= 500000000 && warn_space == true) - { - DialogResult a = DialogResult.Cancel; - tmp.Suspend(); - a = MessageBox.Show(Strings.warn_sp, Strings.low_sp + " (" + (dest_drive.AvailableFreeSpace / 1000000).ToString() + "MB)", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); - if (a == DialogResult.Yes) - { - resume_glob(); - Thread.Sleep(250); - aborted = true; - StreamWriter write_q = tmp.StandardInput; - write_q.Write("q"); - - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - this.InvokeEx(f => this.Text = "FFmpeg Batch AV Converter"); - if (is_portable == true) this.InvokeEx(f => this.Text = "FFmpeg Batch AV Converter Portable"); - working = false; - time_est_size = 0; - Enable_Controls(); - return; - } - warn_space = false; - } //End monitor available space - } - - tmp.WaitForExit(); - int proc_glob = tmp.ExitCode; - list_lines.Add(Strings.exit_code + ": " + proc_glob.ToString()); - list_lines.Add(""); - list_lines.Add("---------------------End of " + Path.GetFileName(file) + " log-------------------------------"); - list_lines.Add(""); - - tmp.StartInfo.Arguments = String.Empty; - this.Invoke(new MethodInvoker(delegate - { - lbl_bitrate.Text = ""; - lbl_est_size.Text = ""; - - if (tmp.ExitCode == 0) - { - listView1.Items[list_index].SubItems[5].Text = Strings.success; - } - else - { - errors_enc++; - listView1.Items[list_index].SubItems[5].Text = Strings.error; - listView1.Items[list_index].BackColor = Color.PaleGoldenrod; - } - })); - - if (list_index == listView1.Items.Count - 1) - { - working = false; - this.Invoke(new MethodInvoker(delegate - { - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - Pg1.Value = Pg1.Maximum; - Pg1.Text = "100%"; - if (is_portable == false) this.Text = "FFmpeg Batch AV Converter"; - else this.Text = "FFmpeg Batch AV Converter Portable"; - if (errors_enc > 0) pic_warnings.Visible = true; - else pic_no_errors.Visible = true; - })); - - //Save log - if (no_save_logs == false) - { - string[] array_err = list_lines.ToArray(); - String path = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "ff_batch.log"; - if (is_portable == true) path = port_path + "ff_batch_portable.log"; - - StreamWriter SaveFile = new StreamWriter(path); - SaveFile.WriteLine("FFmpeg log sesion: " + System.DateTime.Now); - SaveFile.WriteLine("-------------------------------"); - foreach (String item in array_err) - { - SaveFile.WriteLine(item); - } - SaveFile.Close(); - - File.AppendAllText(path, "-----------------------"); - File.AppendAllText(path, Environment.NewLine + Strings.end_log); - FileInfo fileInfo = new FileInfo(path); - - var bytes = fileInfo.Length; - - var kilobytes = (double)bytes / 1024; - var megabytes = kilobytes / 1024; - var gigabytes = megabytes / 1024; - - //Format size view - String size = ""; - String separator = "."; - - if (bytes > 1000000000) - { - if (gigabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String gigas = gigabytes.ToString(); - if (gigas.Length >= 5) - { - gigas = gigas.Substring(0, gigas.LastIndexOf(separator) + 3); - size = (gigas + " " + "GB"); - } - else - { - size = (gigas + " " + "GB"); - } - } - - if (bytes >= 1048576 && bytes <= 1000000000) - { - if (megabytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - String megas = megabytes.ToString(); - if (megas.Length > 5) - { - megas = megas.Substring(0, megas.LastIndexOf(separator)); - size = (megas + " " + "MB"); - } - else - { - size = (megas + " " + "MB"); - } - } - - if (bytes >= 1024 && bytes < 1048576) - - { - if (kilobytes.ToString().Contains(".")) - { - separator = "."; - } - else - { - separator = ","; - } - - String kbs = kilobytes.ToString(); - if (kbs.Length >= 5) - { - kbs = kbs.Substring(0, kbs.LastIndexOf(separator)); - size = (kbs + " " + "KB"); - } - else - { - size = (kbs + " " + "KB"); - } - } - if (bytes > -1 && bytes < 1024) - { - String bits = bytes.ToString(); - size = (bits + " Bytes"); - } - - //End Format size view - File.AppendAllText(path, Environment.NewLine + Strings.log_size + " " + size); - - //End save log - } - - //Automatic shutdown check - if (chkshut.Checked && cancel_queue == false) - { - try - { - String borrar_s = destino_test + "\\" + Path.GetFileNameWithoutExtension(file_prueba) + "." + txt_format.Text; - - foreach (string file_s in Directory.GetFiles(destino_test)) - { - File.Delete(file_s); - } - Directory.Delete(destino_test); - } - catch { } - - auto_shut(); - return; - } - //End shutdown check - else - { - if (cancel_queue == false) - { - if (play_on_end == true) play_end(); - - if (listView1.Items.Count == 1 && proc_glob == 0) - { - if (current_out.ToLower().Contains("nul")) return; - - String cur_out = destino + "\\" + Path.GetFileNameWithoutExtension(file) + add_suffix + ext_output1; - - System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentUICulture; - String sep_th = ci.NumberFormat.CurrencyGroupSeparator; - String unit = ""; - String dur = ""; - this.Invoke(new MethodInvoker(delegate - { - lbl_est_size.Text = String.Empty; - lbl_bitrate.Text = String.Empty; - Process probe = new Process(); - - List lines_ouput = new List(); - probe.StartInfo.FileName = Path.Combine(Application.StartupPath, "MediaInfo.exe"); - String ffprobe_frames = " " + "--Output=General;%OverallBitRate/String%" + "\\n" + "%FileSize/String3%" + "\\n" + "%Duration/String3%"; - probe.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + cur_out + '\u0022'; - probe.StartInfo.RedirectStandardOutput = true; - probe.StartInfo.UseShellExecute = false; - probe.StartInfo.CreateNoWindow = true; - probe.EnableRaisingEvents = true; - probe.Start(); - - while (!probe.StandardOutput.EndOfStream) - { - lines_ouput.Add(probe.StandardOutput.ReadLine()); - } - probe.WaitForExit(); - - if (lines_ouput[0] != null && lines_ouput[0].Length > 0) - { - if (lines_ouput[0].ToLower().Contains(" kb/s")) unit = "Kb/s"; - if (lines_ouput[0].ToLower().Contains(" mb/s")) unit = "Mb/s"; - if (lines_ouput[0].ToLower().Contains(" gb/s")) unit = "Gb/s"; - lines_ouput[0] = lines_ouput[0].Replace(" kb/s", "").Replace(" Mb/s", "").Replace(" Gb/s", ""); - lines_ouput[0] = lines_ouput[0].Replace(" ", sep_th); - lbl_bitrate.Text = Strings.bitrate + ":" + " " + lines_ouput[0] + " " + unit; - } - if (lines_ouput[1] != null && lines_ouput[1].Length > 0) lbl_est_size.Text = Strings.f_size + ":" + " " + lines_ouput[1].Replace("MiB", "MB").Replace("GiB", "GB").Replace("KiB", "KB"); - if (lines_ouput[2] != null && lines_ouput[2].Length > 0) dur = lines_ouput[2]; - })); - - if (no_output_pop == false) - { - Form26 frm26 = new Form26(); - frm26.out_file = cur_out; - frm26.dur_file = dur; - if (Settings.Default.dark_mode == false) frm26.pic_img = pic_reading.Image; - else frm26.pic_img = pic_reading.InitialImage; - frm26.tot_bit = lbl_bitrate.Text; - frm26.out_size = lbl_est_size.Text; - this.Invoke(new MethodInvoker(delegate - { - frm26.ShowDialog(this); - if (frm26.no_pop == true) no_output_pop = true; - })); - } - - } - //End output single info - - if (Form.ActiveForm == null) - { - notifyIcon1.BalloonTipText = Strings.trim_compl; - notifyIcon1.BalloonTipIcon = ToolTipIcon.Info; - notifyIcon1.BalloonTipTitle = Strings.trim_comp2; - notifyIcon1.ShowBalloonTip(1000); - - } - - if (chk_open_compl.Checked) - { - if (Directory.GetFiles(destino).Length != 0) - { - Process open_processed = new Process(); - open_processed.StartInfo.FileName = "explorer.exe"; - open_processed.StartInfo.Arguments = '\u0022' + destino + '\u0022'; - open_processed.Start(); - } - else - { - if (Directory.Exists(destino)) - { - Directory.Delete(destino); - } - } - } - } - else - { - this.Invoke(new MethodInvoker(delegate - { - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - MessageBox.Show(Strings.queue_abort, Strings.aborted, MessageBoxButtons.OK, MessageBoxIcon.Error); - })); - } - } - } - } - Enable_Controls(); - - String borrar = destino_test + "\\" + Path.GetFileNameWithoutExtension(file_prueba) + "." + txt_format.Text; - - }).Start(); - } - private void Form1_DragDrop(object sender, DragEventArgs e) - { - listView1.BackgroundImage = null; - if (Settings.Default.dark_mode == false) listView1.BackColor = SystemColors.Window; - else listView1.BackColor = Color.FromArgb(255, 64, 64, 64); - - if (tabControl1.SelectedIndex == 0) - { - string[] file_drop = (string[])e.Data.GetData(DataFormats.FileDrop); - this.TopMost = true; - drop_files(file_drop); - this.TopMost = false; - this.Activate(); - } - } - - private void Form1_DragEnter(object sender, DragEventArgs e) - { - if (e.Data.GetDataPresent(DataFormats.FileDrop, false)) e.Effect = DragDropEffects.All; - else e.Effect = DragDropEffects.None; - } - - private void Form1_DragLeave(object sender, EventArgs e) - { - listView1.BackgroundImage = null; - if (Settings.Default.dark_mode == false) listView1.BackColor = SystemColors.Window; - else listView1.BackColor = Color.FromArgb(255, 64, 64, 64); - } - - private void presetsOnlineToolStripMenuItem_Click(object sender, EventArgs e) - { - Form27 frm27 = new Form27(); - frm27.StartPosition = FormStartPosition.CenterParent; - frm27.ShowDialog(); - if (frm27.desc_pr.Length > 0) - { - combo_presets.SelectedIndex = combo_presets.Items.Count - 1; - combo_presets.Text = frm27.desc_pr; - txt_pre_input.Text = frm27.pre_in_pr; - txt_parameters.Text = frm27.params_pr.Replace("\\*", "*").Replace("\\:", ":"); ; - txt_format.Text = frm27.format_pr; - } - } - - private void save_queue() - { - if (working == false) return; - List list_file = new List(); - - String save_path_queue = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "saved_queue_temp.ffq"; - if (is_portable == true) save_path_queue = port_path + "saved_queue_temp.ffq"; - String save_path_queue0 = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "FFBatch") + "\\" + "saved_queue_temp0.ffq"; - if (is_portable == true) save_path_queue0 = port_path + "saved_queue_temp0.ffq"; - - //Save session - list_file.Add(txt_parameters.Text); - list_file.Add(txt_format.Text); - list_file.Add(chk_recreate.CheckState.ToString()); - list_file.Add(chk_suffix.CheckState.ToString()); - - list_file.Add(txt_path_main.Text); - - Task t = Task.Run(() => - { - try - { - listView1.Invoke(new MethodInvoker(delegate - { - foreach (ListViewItem item in listView1.Items) - { - list_file.Add(item.SubItems[1].Text + "\\" + item.Text + " --0 " + item.SubItems[2].Text + " --1 " + item.SubItems[3].Text + " --2 " + item.SubItems[4].Text + " --3 " + item.SubItems[5].Text); - } - })); - - using (Stream fs = new FileStream(save_path_queue, FileMode.Create, FileAccess.Write, FileShare.None, 0x1000, FileOptions.WriteThrough)) - using (StreamWriter shellConfigWriter = new StreamWriter(fs)) - { - - shellConfigWriter.Write(string.Join(Environment.NewLine, list_file.ToArray())); - shellConfigWriter.Flush(); - shellConfigWriter.BaseStream.Flush(); - } - - using (Stream fs0 = new FileStream(save_path_queue0, FileMode.Create, FileAccess.Write, FileShare.None, 0x1000, FileOptions.WriteThrough)) - using (StreamWriter shellConfigWriter = new StreamWriter(fs0)) - { - shellConfigWriter.Write(string.Join(Environment.NewLine, list_file.ToArray())); - shellConfigWriter.Flush(); - shellConfigWriter.BaseStream.Flush(); - } - } - catch { } - - }); - - //End save session - } - - private void timer_queue_Tick(object sender, EventArgs e) - { - Task t = Task.Run(() => - { - save_queue(); - }); - } - private void pic_ok_Click(object sender, EventArgs e) - { - Process.Start("https://github.com/yt-dlp/yt-dlp/releases"); - } - - private void ct1_crop_Click(object sender, EventArgs e) - { - String sel = ""; - if (listView1.Items.Count > 0) - { - if (listView1.SelectedItems.Count == 0) - { - listView1.Items[0].Selected = true; listView1.Select(); - } - } - else - { - MessageBox.Show(Strings.no_item_sel); - return; - } - - String dur_lv1 = listView1.SelectedItems[0].SubItems[3].Text; - sel = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - Form28 frm28 = new Form28(); - frm28.StartPosition = FormStartPosition.CenterParent; - frm28.item = sel; - frm28.dur = dur_lv1; - frm28.ShowDialog(); - String str = String.Empty; - if (txt_parameters.Text.ToLower().Contains("-c copy") || txt_parameters.Text.ToLower().Contains("-c:v copy") || txt_parameters.Text.ToLower().Contains("-vcodec copy")) str = Environment.NewLine + Environment.NewLine + Strings.warning.ToUpper() + ":" + " " + Strings.strv_c_not + "."; - - if (txt_parameters.Text.Contains(frm28.vf_crop)) - { - return; - } - else - { - - if (!txt_parameters.Text.Contains("-vf crop=")) - { - if (!txt_parameters.Text.Contains("-vf ") && !txt_parameters.Text.Contains("-vfilter ") && !txt_parameters.Text.Contains("-filter:v ")) - { - txt_parameters.Text = txt_parameters.Text + frm28.vf_crop; - MessageBox.Show(Strings.crop3 + frm28.vf_crop + str, Strings.information, MessageBoxButtons.OK, MessageBoxIcon.Information); - } - else - { - txt_parameters.Text = txt_parameters.Text + frm28.vf_crop; - MessageBox.Show(Strings.vf_crop_multi + Environment.NewLine + Environment.NewLine + Strings.vf_crop_multi2, Strings.information, MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } - else - { - txt_parameters.Text = txt_parameters.Text + frm28.vf_crop; - MessageBox.Show(Strings.crop2 + Environment.NewLine + Environment.NewLine + frm28.vf_crop + str, Strings.information, MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } - } - - private void ct1_params_Click(object sender, EventArgs e) - { - Boolean has_col = false; - foreach (ColumnHeader col in listView1.Columns) - { - if (col.Text.Replace(">", "").Replace("<", "").Contains(Strings.Encoding_parameters)) - { - has_col = true; - break; - } - } - - if (has_col == false) - { - MessageBox.Show(Strings.add_cust_param); - btn_add_col.PerformClick(); - return; - } - - Form30 frm30 = new Form30(); - - if (listView1.SelectedIndices.Count > 0) - { - int i = 0; - foreach (ListViewItem item in listView1.SelectedItems) - { - if (item.SubItems[cust_p_col].Text != "-") i = item.Index; - } - int start = listView1.Items[i].SubItems[cust_p_col].Text.LastIndexOf("[["); - int end = listView1.Items[i].SubItems[cust_p_col].Text.LastIndexOf("]]"); - int cut = end - start + 2; - int length = listView1.Items[i].SubItems[cust_p_col].Text.Length; - if (start != -1 && end != -1) - { - frm30.txt_p.Text = listView1.Items[i].SubItems[cust_p_col].Text.Substring(0, length - cut); - frm30.txt_f.Text = listView1.Items[i].SubItems[cust_p_col].Text.Substring(start + 2, cut - 4); - } - else frm30.txt_p.Text = listView1.Items[i].SubItems[cust_p_col].Text; - } - frm30.ShowDialog(); - if (frm30.cancel == false) - { - foreach (ColumnHeader col in listView1.Columns) - { - - if (col.Text.Replace(">", "").Replace("<", "").Contains(Strings.Encoding_parameters)) - { - cust_p_col = col.Index; - break; - } - else cust_p_col = 0; - } - String format = String.Empty; - if (frm30.txt_f.Text.Length > 1) format = "[[" + frm30.txt_f.Text + "]]"; - foreach (ListViewItem item in listView1.SelectedItems) - { - item.SubItems[cust_p_col].Text = frm30.txt_p.Text + " " + format; - } - } - if (working == true && multi_running && true) - { - //Custom item params - if (cust_p_col != 0) - { - foreach (ListViewItem it in listView1.Items) - { - if (it.Selected == true) custom_m_params[it.Index] = it.SubItems[cust_p_col].Text; - } - } - - //End custom item params - } - } - - private void ct1_rem_param_Click(object sender, EventArgs e) - { - foreach (ListViewItem it in listView1.SelectedItems) it.SubItems[cust_p_col].Text = "-"; - if (working == true && multi_running && true) - { - //Custom item params - if (cust_p_col != 0) - { - foreach (ListViewItem it in listView1.Items) - { - if (it.Selected == true) custom_m_params[it.Index] = "-"; - } - } - - //End custom item params - } - } - - private void fade_a_in_Click(object sender, EventArgs e) - { - if (Settings.Default.quick_queue == true) - { - MessageBox.Show(Strings.quick_f_m6); - fade_a_in.Checked = false; - } - } - - private void fade_a_out_Click(object sender, EventArgs e) - { - if (Settings.Default.quick_queue == true) - { - MessageBox.Show(Strings.quick_f_m6); - fade_a_out.Checked = false; - } - } - - private void fade_v_in_Click(object sender, EventArgs e) - { - if (Settings.Default.quick_queue == true) - { - MessageBox.Show(Strings.quick_f_m6); - fade_v_in.Checked = false; - } - } - - private void fade_v_out_Click(object sender, EventArgs e) - { - if (Settings.Default.quick_queue == true) - { - MessageBox.Show(Strings.quick_f_m6); - fade_v_out.Checked = false; - } - } - - private void timer_battery_Tick(object sender, EventArgs e) - { - if (Settings.Default.pause_bat == false) return; - - PowerLineStatus pls = SystemInformation.PowerStatus.PowerLineStatus; - String power = pls.ToString().ToLower(); - PowerStatus pll = SystemInformation.PowerStatus; - - if (power == "offline") pic_batt.Visible = true; - else pic_batt.Visible = false; - - //MessageBox.Show(paused_battery.ToString()); - if (working == false) return; - - int battery_level = 0; - battery_level = Convert.ToInt32((pll.BatteryLifePercent * 100).ToString()); - - if (paused == false) - { - if (paused_battery == false && power == "offline") - { - if (Settings.Default.if_bat_low == false) - { - paused_bats++; - auto_pause(); - paused_battery = true; - } - else - { - if (battery_level < Settings.Default.bat_level && battery_level != 0) - { - paused_battery = true; - paused_bats++; - auto_pause(); - } - } - } - } - else - { - if (paused_battery == true && power == "online") - { - auto_pause(); - paused_battery = false; - } - } - } - - private void chk_yt_chapt_CheckedChanged(object sender, EventArgs e) - { - Settings.Default.yt_chaps = chk_yt_chapt.Checked; - } - - private void n_down_speed_ValueChanged(object sender, EventArgs e) - { - Settings.Default.yt_limit_n = n_down_speed.Value; - } - - private void chk_best_yt_CheckedChanged(object sender, EventArgs e) - { - Settings.Default.force_mp4_b = chk_best_yt.Checked; - } - - private void chk_embed_meta_CheckedChanged(object sender, EventArgs e) - { - Settings.Default.yt_embed_m = chk_embed_meta.Checked; - } - - private void ct3_ready_Click(object sender, EventArgs e) - { - Pg1.Focus(); - - if (tabControl1.SelectedIndex == 3) - { - foreach (DataGridViewRow row in dg1.SelectedRows) - { - row.Cells[5].Value = Strings.ready; - row.Cells[5].Style.BackColor = Color.White; - } - } - } - - private void txt_parameters_TextChanged(object sender, EventArgs e) - { - btn_save_preset.Enabled = true; - if (just_started5 == true) btn_save_preset.Enabled = false; - just_started5 = false; - btn_try_pr.Image = img_try.Images[0]; - if (txt_parameters.Text.Length > 400) txt_parameters.ScrollBars = ScrollBars.Vertical; - else txt_parameters.ScrollBars = ScrollBars.None; - } - - private void pic_add_variable_Click(object sender, EventArgs e) - { - Form31 frm31 = new Form31(); - if (listView1.Items.Count > 0) - { - if (listView1.SelectedIndices.Count == 0) - { - frm31.file = listView1.Items[0].SubItems[1].Text + "\\" + listView1.Items[0].Text; - frm31.dur = listView1.Items[0].SubItems[3].Text; - } - else - { - frm31.file = listView1.SelectedItems[0].SubItems[1].Text + "\\" + listView1.SelectedItems[0].Text; - frm31.dur = listView1.SelectedItems[0].SubItems[3].Text; - } - } - else frm31.file = ""; - - frm31.ShowDialog(this); - if (frm31.canceled == false) - { - if (frm31.variab == "nul") txt_format.Text = frm31.variab; - else if (frm31.variab == "[[split_chapters]]") - { - if (txt_parameters.Text.Length > 18) - { - if (!txt_parameters.Text.Contains("[[split_chapters]]")) - { - txt_parameters.Text = "[[split_chapters]]" + " " + txt_parameters.Text; - } - } - - else txt_parameters.Text = "[[split_chapters]]" + " " + txt_parameters.Text; - } - else - { - int sel_st = txt_parameters.SelectionStart; - txt_parameters.Text = txt_parameters.Text.Insert(sel_st, frm31.variab); - txt_parameters.SelectionStart = sel_st; - txt_parameters.SelectionLength = frm31.variab.Length; - } - } - } - - private void timer_watch_Tick(object sender, EventArgs e) - { - if (working == true) return; - if (!Directory.Exists(Settings.Default.fd_monitored)) - { - watched_tick = true; - Settings.Default.monitor_fd = false; - Settings.Default.Save(); - pic_mon.Visible = false; - return; - } - System.IO.SearchOption sh = new System.IO.SearchOption(); - if (Settings.Default.mon_fd_subs == true) sh = System.IO.SearchOption.AllDirectories; - else sh = System.IO.SearchOption.TopDirectoryOnly; - - string[] file_drop = (string[])Directory.GetFiles(Settings.Default.fd_monitored, "*.*", sh); - watched_tick = true; - drop_files(file_drop); - } - - private String get_custom_med() - { - if (Settings.Default.cust_med_col_t == 0) - { - switch (Settings.Default.cust_med_col) - { - case "Format/Info": - { - return "--Inform=" + '\u0022' + "Video;%Format/Info%" + '\u0022'; - break; - } - case "Format profile": - { - return "--Inform=" + '\u0022' + "Video;%Format_Profile%" + '\u0022'; - break; - } - case "Format settings": - { - return "--Inform=" + '\u0022' + "Video;%Format_Settings%" + '\u0022'; - break; - } - case "Codec ID": - { - return "--Inform=" + '\u0022' + "Video;%CodecID%" + '\u0022'; - break; - } - - case "Maximum bitrate": - { - return "--Inform=" + '\u0022' + "Video;%BitRate_Maximum/String%" + '\u0022'; - break; - } - - case "Display aspect ratio": - { - return "--Inform=" + '\u0022' + "Video;%DisplayAspectRatio/String%" + '\u0022'; - break; - } - case "Frame rate mode": - { - return "--Inform=" + '\u0022' + "Video;%FrameRate_Mode%" + '\u0022'; - break; - } - case "Frame rate": - { - - return "--Inform=" + '\u0022' + "Video;%FrameRate%" + '\u0022'; - break; - } - case "Color space": - { - return "--Inform=" + '\u0022' + "Video;%ColorSpace%" + '\u0022'; - break; - } - case "Chroma subsampling": - { - - return "--Inform=" + '\u0022' + "Video;%ChromaSubsampling%" + '\u0022'; - break; - } - case "Bit depth": - { - return "--Inform=" + '\u0022' + "Video;%BitDepth%" + '\u0022'; - break; - } - case "Scan type": - { - return "--Inform=" + '\u0022' + "Video;%ScanType%" + '\u0022'; - break; - } - case "Color range": - { - - return "--Inform=" + '\u0022' + "Video;%colour_range%" + '\u0022'; - break; - } - case "Color primaries": - { - - return "--Inform=" + '\u0022' + "Video;%colour_primaries%" + '\u0022'; - break; - } - case "Writing library": - { - - return "--Inform=" + '\u0022' + "Video;%Encoded_Library/String%" + '\u0022'; - break; - } - case "Language": - { - - return "--Inform=" + '\u0022' + "Video;%Language/String%" + '\u0022'; - break; - } - } - } - - if (Settings.Default.cust_med_col_t == 1) - - { - switch (Settings.Default.cust_med_col) - { - case "Codec ID": - { - return "--Inform=" + '\u0022' + "Audio;%CodecID%" + '\u0022'; - break; - } - - case "Format/Info": - { - return "--Inform=" + '\u0022' + "Audio;%Format/Info%" + '\u0022'; - break; - } - - case "Bit rate mode": - { - return "--Inform=" + '\u0022' + "Audio;%BitRate_Mode%" + '\u0022'; - break; - } - case "Channel(s)": - { - return "--Inform=" + '\u0022' + "Audio;%Channels%" + '\u0022'; - break; - } - case "Channel layout": - { - return "--Inform=" + '\u0022' + "Audio;%ChannelLayout%" + '\u0022'; - break; - } - case "Sampling rate": - { - return "--Inform=" + '\u0022' + "Audio;%SamplingRate/String%" + '\u0022'; - break; - } - - case "Bit depth": - { - return "--Inform=" + '\u0022' + "Audio;%BitDepth%" + '\u0022'; - break; - } - case "Compression mode": - { - return "--Inform=" + '\u0022' + "Audio;%Compression_Mode%" + '\u0022'; - break; - } - case "Writing library": - { - return "--Inform=" + '\u0022' + "Audio;%Encoded_Library/String%" + '\u0022'; - break; - } - - case "Language": - { - return "--Inform=" + '\u0022' + "Audio;%Language/String%" + '\u0022'; - break; - } - case "Subtitles": - { - return "Subtitles"; - break; - } - } - } - return ""; - } - - private void ctm1_excl_Click(object sender, EventArgs e) - { - Form32 frm32 = new Form32(); - frm32.ShowDialog(); - Settings.Default.excl_list.Clear(); - foreach (DataGridViewRow row in frm32.dg_pr.Rows) - { - if (row.Cells[0].Value != null) - { - if (row.Cells[0].Value.ToString().Length > 0) Settings.Default.excl_list.Add(row.Cells[0].Value.ToString()); - } - } - } - - private void pic_no_errors_Click(object sender, EventArgs e) - { - if (pic_warnings.Visible == true) btn_display_log.PerformClick(); - } - - private void txt_output_subs_DoubleClick(object sender, EventArgs e) - { - txt_output_subs.Text = ".\\FFBatch"; - txt_output_subs.BackColor = Control.DefaultBackColor; - } - - private void pic_file_add_input_MouseClick(object sender, MouseEventArgs e) - { - if (e.Button is MouseButtons.Left) - { - ct_paths_param.Show(pic_file_add_input, new Point(e.X, e.Y)); - } - } - - private void ct_path_input_Click(object sender, EventArgs e) - { - OpenFileDialog openf = new OpenFileDialog(); - openf.Filter = Strings.av + " |*.mp4; *.mkv; *.ts; *.mxf; *.mp3; *.wav; *.flac; *.m4a; *.avi; *.mts; *.flv; *.alac; *.aac; *.mpg; *.mp2; *.mpe; *.ogv; *.webm; *.aiff; *.vob; *.wma; *.wmv; *.mov; *.mka; *.m2ts; *.ac3; *.ogg; *.avs|" + Strings.imgs + " (*.jpg; *.png; *.gif) | *.jpg; *.png; *.gif|" + Strings.all_files + " (*.*) | *.*"; - if (openf.ShowDialog() == DialogResult.Cancel) return; - else txt_parameters.Text = "-i " + '\u0022' + openf.FileName.Replace("\\", "\\\\") + '\u0022' + " " + txt_parameters.Text; - } - - private void ct_path_vf_Click(object sender, EventArgs e) - { - OpenFileDialog openf = new OpenFileDialog(); - openf.Filter = Strings.av + " |*.mp4; *.mkv; *.ts; *.mxf; *.mp3; *.wav; *.flac; *.m4a; *.avi; *.mts; *.flv; *.alac; *.aac; *.mpg; *.mp2; *.mpe; *.ogv; *.webm; *.aiff; *.vob; *.wma; *.wmv; *.mov; *.mka; *.m2ts; *.ac3; *.ogg; *.avs *.srt *.ass|" + Strings.all_files + " (*.*) | *.*"; - if (openf.ShowDialog() == DialogResult.Cancel) return; - else - { - int sel_st = txt_parameters.SelectionStart; - String outp = openf.FileName.Replace("\\", "/" + "\\").Replace(":", "\\\\" + ":" + "/"); - txt_parameters.Text = txt_parameters.Text.Insert(sel_st, outp); - txt_parameters.SelectionStart = sel_st; - txt_parameters.SelectionLength = outp.Length; - } - } - - private void bg_add_tab2_DoWork(object sender, DoWorkEventArgs e) - { - this.Invoke(new MethodInvoker(delegate - { - listView2.BeginUpdate(); - pg_adding.Value = 0; - pg_adding.Maximum = listView1.Items.Count; - txt_adding_p.Visible = true; - txt_adding_p.Refresh(); - lbl_items.Visible = false; - lbl_items.Refresh(); - lbl_dur_list.Visible = false; - lbl_dur_list.Refresh(); - lbl_size.Visible = false; - lbl_size.Refresh(); - canceled_file_adding = false; - btn_cancel_add.Enabled = true; - btn_cancel_add.Visible = true; - btn_cancel_add.Refresh(); - - pg_adding.Visible = true; - LB_Wait.Visible = true; - LB_Wait.Text = Strings.adding + " " + listView1.Items.Count + " " + Strings.files; - LB_Wait.Refresh(); - txt_adding_p.Text = ""; - })); - - ListView lstv2 = new ListView(); - this.Invoke(new MethodInvoker(delegate - { - listView2.Clear(); - lstv2.Columns.Add(Strings.filename, 450); - lstv2.SmallImageList = listView1.SmallImageList; - listView2.SmallImageList = listView1.SmallImageList; - - foreach (ListViewItem item in listView1.Items) - { - ListViewItem elemento = new ListViewItem(item.SubItems[1].Text + "\\" + item.Text, 1); - //Begin get file icon - if (!File.Exists(item.SubItems[1].Text + "\\" + item.Text)) continue; - Icon iconForFile = SystemIcons.WinLogo; - - if (!elemento.Text.Contains("\\\\")) - { - if (!imageList2.Images.ContainsKey(Path.GetExtension(elemento.Text))) - { - iconForFile = System.Drawing.Icon.ExtractAssociatedIcon(elemento.Text); - imageList2.Images.Add(Path.GetExtension(elemento.Text), iconForFile); - } - } - - if (!elemento.Text.Contains("\\\\")) - { - elemento.ImageKey = Path.GetExtension(elemento.Text); - } - else - { - elemento.ImageIndex = 0; - } - - lstv2.Items.Add(elemento); - } - })); - - int current = 0; - object lockCurrent = new object(); - - ParallelOptions par_op = new ParallelOptions(); - CancellationTokenSource cts = new CancellationTokenSource(); - par_op.CancellationToken = cts.Token; - par_op.MaxDegreeOfParallelism = Environment.ProcessorCount - 1; - - ParallelLoopResult res = new ParallelLoopResult(); - try - { - res = Parallel.For(0, listView1.Items.Count, par_op, (i2) => - { - int i = 0; - lock (lockCurrent) - { - i = current; - current++; - } - Process ff_str = new Process(); - - if (canceled_file_adding == true) cts.Cancel(); - - this.Invoke(new MethodInvoker(delegate - { - if (i <= pg_adding.Maximum) - { - pg_adding.Value = i; - txt_adding_p.Text = (i * 100 / listView1.Items.Count).ToString() + "%"; - TaskbarProgress.SetValue(this.Handle, i * 100 / listView1.Items.Count, 100); - } - else - { - pg_adding.Value = pg_adding.Maximum; - txt_adding_p.Text = "100%"; - } - - })); - - ff_str.StartInfo.FileName = Path.Combine(Application.StartupPath, "ffmpeg.exe"); - ff_str.StartInfo.Arguments = " -i " + '\u0022' + lstv2.Items[i].Text + '\u0022' + " -hide_banner"; - ff_str.StartInfo.RedirectStandardError = true; - ff_str.StartInfo.UseShellExecute = false; - ff_str.StartInfo.CreateNoWindow = true; - ff_str.EnableRaisingEvents = true; - ff_str.Start(); - String stream = ""; - String sub_str = ""; - int c = 0; - Boolean has_stream = false; - - while (!ff_str.StandardError.EndOfStream) - { - stream = ff_str.StandardError.ReadLine(); - if (stream.Contains("Stream #0:")) - { - has_stream = true; - if (lstv2.Columns.Count <= c + 1) - { - lstv2.Columns.Add(Strings.stream + " " + c, 150); - } - - if (stream.Substring(stream.IndexOf("#0:") + 4, 1) == "(") - { - if (stream.Substring(stream.IndexOf("#0:") + 4, 5) == "(und)" || stream.Substring(stream.IndexOf("#0:") + 4, 5) == "(unk)") - { - c++; - sub_str = stream.Substring(0, stream.LastIndexOf("#0:") + 11); - lstv2.Items[i].SubItems.Add(stream.Substring((stream.LastIndexOf("#0:") + 11), (stream.Length - sub_str.Length))); - - } - else - { - c++; - sub_str = stream.Substring(0, stream.LastIndexOf("#0:") + 4); - lstv2.Items[i].SubItems.Add(stream.Substring((stream.LastIndexOf("#0:") + 4), (stream.Length - sub_str.Length))); - - } - } - - else - { - if (stream.Contains("Video")) - { - c++; - sub_str = stream.Substring(0, stream.LastIndexOf("#0:") + 6); - lstv2.Items[i].SubItems.Add(stream.Substring((stream.LastIndexOf("#0:") + 6), (stream.Length - sub_str.Length))); - - } - if (stream.Contains("Audio")) - { - c++; - sub_str = stream.Substring(0, stream.LastIndexOf("#0:") + 6); - lstv2.Items[i].SubItems.Add(stream.Substring((stream.LastIndexOf("#0:") + 6), (stream.Length - sub_str.Length))); - - } - if (stream.Contains("Subtitle")) - { - c++; - sub_str = stream.Substring(0, stream.LastIndexOf("#0:") + 6); - lstv2.Items[i].SubItems.Add(stream.Substring((stream.LastIndexOf("#0:") + 6), (stream.Length - sub_str.Length))); - } - - } - } - } - ff_str.WaitForExit(); - - if (has_stream == false) - { - lstv2.Items[i].SubItems.Add(Strings.no_streams1); - } - - }); - } - catch { } - - listView2.Invoke(new MethodInvoker(delegate - { - listView2.Columns.AddRange((from ColumnHeader Col in lstv2.Columns - select (ColumnHeader)Col.Clone()).ToArray()); - listView2.Items.AddRange((from ListViewItem item in lstv2.Items select (ListViewItem)item.Clone()).ToArray()); - - - foreach (ListViewItem it in listView2.Items) - { - for (int i = 0; i < it.SubItems.Count; i++) - { - if (it.SubItems[i].Text.Contains("Video")) - { - it.UseItemStyleForSubItems = false; - it.SubItems[i].BackColor = Color.PapayaWhip; - } - - if (it.SubItems[i].Text.Contains("Audio")) - { - it.UseItemStyleForSubItems = false; - it.SubItems[i].BackColor = Color.AliceBlue; - } - if (it.SubItems[i].Text.Contains("Subtitle")) - { - it.UseItemStyleForSubItems = false; - it.SubItems[i].BackColor = Color.LightGoldenrodYellow; - } - } - } - })); - } - private void bg_add_tab2_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) - { - LB_Wait.Text = ""; - listView2.EndUpdate(); - TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); - btn_cancel_add.Visible = false; - pg_adding.Visible = false; - txt_adding_p.Visible = false; - lbl_dur_list.Refresh(); - - if (listView2.Items.Count == 1) - { - listView2.Items[0].Selected = true; - ct2_all.PerformClick(); - tracks_background(); - } - } - - private void BG_R_Cols_DoWork(object sender, DoWorkEventArgs e) - { - String subs = String.Empty; - Boolean is_subs = false; - - ListView lstv2 = new ListView(); - listView1.Invoke(new MethodInvoker(delegate - { - lstv2.Columns.AddRange((from ColumnHeader Col in listView1.Columns select (ColumnHeader)Col.Clone()).ToArray()); - lstv2.Items.AddRange((from ListViewItem item in listView1.Items select (ListViewItem)item.Clone()).ToArray()); - })); - - this.Invoke(new MethodInvoker(delegate - { - btn_cancel_add.Visible = true; - pg_adding.Visible = true; - txt_adding_p.Visible = true; - pg_adding.Value = 0; - LB_Wait.Visible = true; - LB_Wait.Text = Strings.add_col1; - LB_Wait.Refresh(); - pg_adding.Maximum = listView1.Items.Count; - })); - - foreach (ColumnHeader col1 in lstv2.Columns) - { - if (col1.Text.Replace("<", "").Replace(">", "").TrimStart() == "Subtitles") - { - is_subs = true; - subs = "Text;%Language/String3%" + ","; - break; - } - } - - String config_info = Path.Combine(Path.GetTempPath(), "FFBatch_Test") + "\\" + "columns.txt"; - if (!Directory.Exists(Path.Combine(Path.GetTempPath(), "FFBatch_Test"))) Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "FFBatch_Test")); - - String[] config_lines = new String[3]; - Boolean cust_v = true; - - if (get_custom_med().Contains("Audio;") || get_custom_med() == "Subtitles") cust_v = false; - - String cust_p = String.Empty; - if (get_custom_med() != "Subtitles") cust_p = get_custom_med().Replace("--Inform=", "").Replace("Video;", "").Replace("Audio;", "").Replace("\"", ""); - else cust_p = "Subtitles"; - - if (Settings.Default.cust_med_col_t == 0) - { - config_lines[0] = "Video;%Width%" + "\\n" + "%Height%" + "\\n" + "%Format%" + "\\n" + "%Format_Profile%" + "\\n" + "%BitRate/String%" + "\\n" + cust_p + "\\n"; - config_lines[1] = "Audio;%Format/String%" + "\\n" + "%BitRate/String%" + "\\n"; - config_lines[2] = subs; - - } - if (Settings.Default.cust_med_col_t == 1) - { - config_lines[0] = "Video;%Width%" + "\\n" + "%Height%" + "\\n" + "%Format%" + "\\n" + "%Format_Profile%" + "\\n" + "%BitRate/String%" + "\\n"; - config_lines[1] = "Audio;%Format/String%" + "\\n" + "%BitRate/String%" + "\\n" + cust_p; - config_lines[2] = subs; - } - - File.WriteAllLines(config_info, config_lines); - - procs.Clear(); - media_list.Clear(); - - for (int ii = 0; ii < lstv2.Items.Count; ii++) - { - procs.Add("proc_urls_" + ii.ToString(), new Process()); - media_list.Add("lines_out_" + ii.ToString(), new List()); - } - - int current = 0; - object lockCurrent = new object(); - - ParallelOptions parop = new ParallelOptions(); - if (Environment.ProcessorCount >= 4) parop.MaxDegreeOfParallelism = 4; - else parop.MaxDegreeOfParallelism = Environment.ProcessorCount; - CancellationTokenSource cts = new System.Threading.CancellationTokenSource(); - parop.CancellationToken = cts.Token; - - Parallel.For(0, lstv2.Items.Count, parop, n2 => - { - int n = 0; - lock (lockCurrent) - { - n = current; - current++; - } - - this.Invoke(new MethodInvoker(delegate - { - txt_adding_p.Text = (pg_adding.Value * 100 / listView1.Items.Count + "%"); - txt_adding_p.Refresh(); - TaskbarProgress.SetValue(this.Handle, pg_adding.Value * 100 / listView1.Items.Count, 100); - if (pg_adding.Value < pg_adding.Maximum) pg_adding.Value++; - })); - - if (canceled_file_adding == true) return; - - String itfull = lstv2.Items[n].SubItems[1].Text + "\\" + lstv2.Items[n].Text; - String dur_file = lstv2.Items[n].SubItems[3].Text; - - var tmp = procs["proc_urls_" + n.ToString()]; - var lines = media_list["lines_out_" + n.ToString()]; - tmp.StartInfo.RedirectStandardOutput = true; - tmp.StartInfo.UseShellExecute = false; - tmp.StartInfo.CreateNoWindow = true; - tmp.EnableRaisingEvents = true; - tmp.StartInfo.FileName = Path.Combine(Application.StartupPath, "Mediainfo.exe"); - String ffprobe_frames = " --Inform=" + '\u0022' + "file://" + config_info + '\u0022'; - tmp.StartInfo.Arguments = ffprobe_frames + " " + '\u0022' + itfull + '\u0022'; - tmp.Start(); - while (!tmp.StandardOutput.EndOfStream) - { - lines.Add(tmp.StandardOutput.ReadLine()); - } - tmp.WaitForExit(); - - - foreach (ColumnHeader col in lstv2.Columns) - { - if (canceled_file_adding) break; - Boolean is_v = false; - Boolean is_a = false; - - if (lines.Count > 3) is_v = true; - else is_a = true; - - if (col.Text.Replace("<", "").Replace(">", "").TrimStart() == Strings.width) - { - if (is_v == true) - { - this.Invoke(new MethodInvoker(delegate - { - if (lines[0].Length > 0) listView1.Items[n].SubItems[col.Index].Text = lines[0]; - if (lines[1].Length > 0) listView1.Items[n].SubItems[col.Index + 1].Text = lines[1]; - })); - } - } - - if (col.Text == Strings.Video_codec) - { - - if (is_v == true && lines[2].Length > 0) - { - this.Invoke(new MethodInvoker(delegate - { - if (lines[2].Length >= 3) - { - listView1.Items[n].SubItems[col.Index].Text = lines[2] + " " + lines[3]; - } - else listView1.Items[n].SubItems[col.Index].Text = lines[2] + " " + lines[3]; - })); - } - Color.FromArgb(255, 60, 60, 96); - } - - if (col.Text == Strings.Audio_codec) - { - - if (is_v == true) - { - if (cust_v == false) - { - if (lines[5].Length > 0) - { - if (lines[5].ToLower().Contains("mpeg audio")) - { - lines[5] = "MPEG Layer 3"; - } - this.Invoke(new MethodInvoker(delegate - { - listView1.Items[n].SubItems[col.Index].Text = lines[5]; - })); - } - - } - else - { - if (lines[6].Length > 0) - { - if (lines[6].ToLower().Contains("mpeg audio")) - { - lines[6] = "MPEG Layer 3"; - } - this.Invoke(new MethodInvoker(delegate - { - listView1.Items[n].SubItems[col.Index].Text = lines[6]; - })); - } - - } - } - else if (is_a) - { - if (lines[0].Length > 1) - { - if (lines[0].ToLower().Contains("mpeg audio") && Path.GetExtension(itfull) == ".mp3") - { - lines[0] = "MPEG Layer 3"; - } - this.Invoke(new MethodInvoker(delegate - { - listView1.Items[n].SubItems[col.Index].Text = lines[0]; - })); - } - - } - } - - if (col.Text == Strings.v_bitr) - { - if (is_v == true && lines[4].Length > 0) - { - this.Invoke(new MethodInvoker(delegate - { - listView1.Items[n].SubItems[col.Index].Text = lines[4]; - })); - } - } - - if (col.Text == Strings.a_bitr) - { - if (is_v == true) - { - if (cust_v == false) - { - if (lines.Count > 7) - { - if (is_v == true && lines[6].Length > 0) - { - this.Invoke(new MethodInvoker(delegate - { - listView1.Items[n].SubItems[col.Index].Text = lines[6]; - })); - } - - } - - } - else - { - if (lines.Count > 7) - { - if (is_v == true && lines[7].Length > 0) - { - this.Invoke(new MethodInvoker(delegate - { - listView1.Items[n].SubItems[col.Index].Text = lines[7]; - })); - } - } - } - } - else if (is_a == true) - { - if (lines.Count > 1) - { - if (lines[1] != null) - { - if (lines[1].Length > 0) - { - this.Invoke(new MethodInvoker(delegate - { - listView1.Items[n].SubItems[col.Index].Text = lines[1]; - })); - } - } - } - } - } - - //Custom parameters - - if (col.Text == Settings.Default.cust_med_col) - { - if (lines.Count > 1) - { - - if (lines[2] != null) - { - if (lines[2].Length > 0 && is_a == false) - { - if (cust_v == true) - { - if (lines[5].Length > 0) - { - this.Invoke(new MethodInvoker(delegate - { - listView1.Items[n].SubItems[col.Index].Text = lines[5]; - })); - } - - } - else - { - if (cust_p != "Subtitles") - { - this.Invoke(new MethodInvoker(delegate - { - if (lines[lines.Count - 1].Length > 0) listView1.Items[n].SubItems[col.Index].Text = lines[lines.Count - 1]; - })); - - } - else - { - String subs_r = lines[lines.Count - 1].Replace("Subtitles", String.Empty); - if (subs_r.Length > 0) - { - this.Invoke(new MethodInvoker(delegate - { - listView1.Items[n].SubItems[col.Index].Text = subs_r.TrimEnd(','); - })); - } - } - } - } - else if (lines[2].Length > 0 && cust_p.Length > 0 && is_a == true) - { - if (cust_p != "Subtitles") - { - this.Invoke(new MethodInvoker(delegate - { - if (lines[2].Length > 0) listView1.Items[n].SubItems[col.Index].Text = lines[2]; - })); - } - } - } - } - } - - //End custom parameters - } - }); - this.InvokeEx(f => TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress)); - } - private void BG_R_Cols_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) - { - LB_Wait.Text = ""; - btn_cancel_add.Visible = false; - pg_adding.Visible = false; - txt_adding_p.Visible = false; - } - - private void pic_season_Click(object sender, EventArgs e) - { - DialogResult a = MessageBox.Show(Strings.happy_y + Environment.NewLine + Environment.NewLine + Properties.Strings.rem_img + "?","", MessageBoxButtons.YesNo,MessageBoxIcon.Question); - if (a == DialogResult.Yes) - { - pic_season.Image = null; - Settings.Default.season_img = false; - Settings.Default.Save(); - } - } - - private void chk_burn_input_CheckedChanged(object sender, EventArgs e) - { - if (chk_burn_input.Checked) n_subs_str.Enabled = true; - else n_subs_str.Enabled = false; - } - - private void btn_change_ff_Click(object sender, EventArgs e) - { - pic_title.Focus(); - Form34 frm34 = new Form34(); - if (!File.Exists("ffmpeg.exe")) frm34.lbl_ff_v.Text = Properties.Strings.file_not_found; - else frm34.lbl_ff_v.Text = btn_change_ff.Text; - frm34.Icon = this.Icon; - frm34.ShowDialog(); - if (frm34.down_g == true) - { - down_ffAsync(down_ff_g); - } - if (frm34.down_v == true) - { - down_ffAsync(down_ff_v); - } - if (frm34.down_vh == true) - { - down_ffAsync(down_ff_vh); - } - if (frm34.browse_ff == true) - { - obtain_ffmpeg(); - get_ffmpeg_v(); - if (check_ff_md5() == false) - { - Form25 frm25 = new Form25(); - frm25.ShowDialog(); - if (frm25.check_ff == true) ff_ver(); - return; - } - } - } - - private void dg1_CellEndEdit(object sender, DataGridViewCellEventArgs e) - { - String cell_out = ""; - - if (e.ColumnIndex == 4) - { - if (dg1.Rows[e.RowIndex].Cells[4].Value == null) - { - String url1 = dg1.Rows[e.RowIndex].Cells[1].Value.ToString().Substring(dg1.Rows[e.RowIndex].Cells[1].Value.ToString().LastIndexOf("=") + 1, 11); - MessageBox.Show(Strings.out_blank); - dg1.Rows[e.RowIndex].Cells[4].Value = url1 + "_" + (e.RowIndex + 1).ToString(); - return; - } - else - { - cell_out = dg1.Rows[e.RowIndex].Cells[4].Value.ToString(); - if (cell_out.Contains("/") || cell_out.Contains(":") || cell_out.Contains("*") || cell_out.Contains("?") || cell_out.Contains("¿") || cell_out.Contains('\u0022') || cell_out.Contains("<") || cell_out.Contains(">") || cell_out.Contains("|") || cell_out.Contains("\\")) - { - MessageBox.Show(Strings.invalid_rem + " " + "(\\/:*?'\u0022'<>|", Strings.invalid_ch2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - cell_out = cell_out.Replace("/", ""); - cell_out = cell_out.Replace(":", ""); - cell_out = cell_out.Replace("*", ""); - cell_out = cell_out.Replace("?", ""); - cell_out = cell_out.Replace("¿", ""); - cell_out = cell_out.Replace("\u0022", ""); - cell_out = cell_out.Replace("<", ""); - cell_out = cell_out.Replace("@", ""); - cell_out = cell_out.Replace(">", ""); - cell_out = cell_out.Replace("|", ""); - cell_out = cell_out.Replace("\\", ""); - dg1.Rows[e.RowIndex].Cells[4].Value = cell_out; - } - if (cell_out.Length > 224) dg1.Rows[e.RowIndex].Cells[4].Value = cell_out.Substring(0, 224); - } - } - } - - // End code - } //Form Class - - public static class ISynchronizeInvokeExtensions - { - public static void InvokeEx(this T @this, Action action) where T : ISynchronizeInvoke - { - if (@this.InvokeRequired) - { - @this.Invoke(action, new object[] { @this }); - } - else - { - action(@this); - } - } - } - - public static class TextFileEncodingDetector - { - private const long _defaultHeuristicSampleSize = 0x10000; //completely arbitrary - inappropriate for high numbers of files / high speed requirements - - public static Encoding DetectTextFileEncoding(string InputFilename) - { - using (FileStream textfileStream = File.OpenRead(InputFilename)) - { - return DetectTextFileEncoding(textfileStream, _defaultHeuristicSampleSize); - } - } - - public static Encoding DetectTextFileEncoding(FileStream InputFileStream, long HeuristicSampleSize) - { - bool uselessBool = false; - return DetectTextFileEncoding(InputFileStream, _defaultHeuristicSampleSize, out uselessBool); - } - - public static Encoding DetectTextFileEncoding(FileStream InputFileStream, long HeuristicSampleSize, out bool HasBOM) - { - if (InputFileStream == null) - throw new ArgumentNullException("Must provide a valid Filestream!", "InputFileStream"); - - if (!InputFileStream.CanRead) - throw new ArgumentException("Provided file stream is not readable!", "InputFileStream"); - - if (!InputFileStream.CanSeek) - throw new ArgumentException("Provided file stream cannot seek!", "InputFileStream"); - - Encoding encodingFound = null; - - long originalPos = InputFileStream.Position; - - InputFileStream.Position = 0; - - //First read only what we need for BOM detection - byte[] bomBytes = new byte[InputFileStream.Length > 4 ? 4 : InputFileStream.Length]; - InputFileStream.Read(bomBytes, 0, bomBytes.Length); - - encodingFound = DetectBOMBytes(bomBytes); - - if (encodingFound != null) - { - InputFileStream.Position = originalPos; - HasBOM = true; - return encodingFound; - } - - //BOM Detection failed, going for heuristics now. - // create sample byte array and populate it - byte[] sampleBytes = new byte[HeuristicSampleSize > InputFileStream.Length ? InputFileStream.Length : HeuristicSampleSize]; - Array.Copy(bomBytes, sampleBytes, bomBytes.Length); - if (InputFileStream.Length > bomBytes.Length) - InputFileStream.Read(sampleBytes, bomBytes.Length, sampleBytes.Length - bomBytes.Length); - InputFileStream.Position = originalPos; - - //test byte array content - encodingFound = DetectUnicodeInByteSampleByHeuristics(sampleBytes); - - HasBOM = false; - return encodingFound; - } - - public static Encoding DetectTextByteArrayEncoding(byte[] TextData) - { - bool uselessBool = false; - return DetectTextByteArrayEncoding(TextData, out uselessBool); - } - - public static Encoding DetectTextByteArrayEncoding(byte[] TextData, out bool HasBOM) - { - if (TextData == null) - throw new ArgumentNullException("Must provide a valid text data byte array!", "TextData"); - - Encoding encodingFound = null; - - encodingFound = DetectBOMBytes(TextData); - - if (encodingFound != null) - { - HasBOM = true; - return encodingFound; - } - else - { - //test byte array content - encodingFound = DetectUnicodeInByteSampleByHeuristics(TextData); - - HasBOM = false; - return encodingFound; - } - } - - public static string GetStringFromByteArray(byte[] TextData, Encoding DefaultEncoding) - { - return GetStringFromByteArray(TextData, DefaultEncoding, _defaultHeuristicSampleSize); - } - - public static string GetStringFromByteArray(byte[] TextData, Encoding DefaultEncoding, long MaxHeuristicSampleSize) - { - if (TextData == null) - throw new ArgumentNullException("Must provide a valid text data byte array!", "TextData"); - - Encoding encodingFound = null; - - encodingFound = DetectBOMBytes(TextData); - - if (encodingFound != null) - { - //For some reason, the default encodings don't detect/swallow their own preambles!! - return encodingFound.GetString(TextData, encodingFound.GetPreamble().Length, TextData.Length - encodingFound.GetPreamble().Length); - } - else - { - byte[] heuristicSample = null; - if (TextData.Length > MaxHeuristicSampleSize) - { - heuristicSample = new byte[MaxHeuristicSampleSize]; - Array.Copy(TextData, heuristicSample, MaxHeuristicSampleSize); - } - else - { - heuristicSample = TextData; - } - - encodingFound = DetectUnicodeInByteSampleByHeuristics(TextData) ?? DefaultEncoding; - return encodingFound.GetString(TextData); - } - } - - public static Encoding DetectBOMBytes(byte[] BOMBytes) - { - if (BOMBytes == null) - throw new ArgumentNullException("Must provide a valid BOM byte array!", "BOMBytes"); - - if (BOMBytes.Length < 2) - return null; - - if (BOMBytes[0] == 0xff - && BOMBytes[1] == 0xfe - && (BOMBytes.Length < 4 - || BOMBytes[2] != 0 - || BOMBytes[3] != 0 - ) - ) - return Encoding.Unicode; - - if (BOMBytes[0] == 0xfe - && BOMBytes[1] == 0xff - ) - return Encoding.BigEndianUnicode; - - if (BOMBytes.Length < 3) - return null; - - if (BOMBytes[0] == 0xef && BOMBytes[1] == 0xbb && BOMBytes[2] == 0xbf) - return Encoding.UTF8; - - if (BOMBytes[0] == 0x2b && BOMBytes[1] == 0x2f && BOMBytes[2] == 0x76) - return Encoding.UTF7; - - if (BOMBytes.Length < 4) - return null; - - if (BOMBytes[0] == 0xff && BOMBytes[1] == 0xfe && BOMBytes[2] == 0 && BOMBytes[3] == 0) - return Encoding.UTF32; - - if (BOMBytes[0] == 0 && BOMBytes[1] == 0 && BOMBytes[2] == 0xfe && BOMBytes[3] == 0xff) - return Encoding.GetEncoding(12001); - - return null; - } - - public static Encoding DetectUnicodeInByteSampleByHeuristics(byte[] SampleBytes) - { - long oddBinaryNullsInSample = 0; - long evenBinaryNullsInSample = 0; - long suspiciousUTF8SequenceCount = 0; - long suspiciousUTF8BytesTotal = 0; - long likelyUSASCIIBytesInSample = 0; - - //Cycle through, keeping count of binary null positions, possible UTF-8 - // sequences from upper ranges of Windows-1252, and probable US-ASCII - // character counts. - - long currentPos = 0; - int skipUTF8Bytes = 0; - - while (currentPos < SampleBytes.Length) - { - //binary null distribution - if (SampleBytes[currentPos] == 0) - { - if (currentPos % 2 == 0) - evenBinaryNullsInSample++; - else - oddBinaryNullsInSample++; - } - - //likely US-ASCII characters - if (IsCommonUSASCIIByte(SampleBytes[currentPos])) - likelyUSASCIIBytesInSample++; - - //suspicious sequences (look like UTF-8) - if (skipUTF8Bytes == 0) - { - int lengthFound = DetectSuspiciousUTF8SequenceLength(SampleBytes, currentPos); - - if (lengthFound > 0) - { - suspiciousUTF8SequenceCount++; - suspiciousUTF8BytesTotal += lengthFound; - skipUTF8Bytes = lengthFound - 1; - } - } - else - { - skipUTF8Bytes--; - } - - currentPos++; - } - - //1: UTF-16 LE - in english / european environments, this is usually characterized by a - // high proportion of odd binary nulls (starting at 0), with (as this is text) a low - // proportion of even binary nulls. - // The thresholds here used (less than 20% nulls where you expect non-nulls, and more than - // 60% nulls where you do expect nulls) are completely arbitrary. - - if (((evenBinaryNullsInSample * 2.0) / SampleBytes.Length) < 0.2 - && ((oddBinaryNullsInSample * 2.0) / SampleBytes.Length) > 0.6 - ) - return Encoding.Unicode; - - //2: UTF-16 BE - in english / european environments, this is usually characterized by a - // high proportion of even binary nulls (starting at 0), with (as this is text) a low - // proportion of odd binary nulls. - // The thresholds here used (less than 20% nulls where you expect non-nulls, and more than - // 60% nulls where you do expect nulls) are completely arbitrary. - - if (((oddBinaryNullsInSample * 2.0) / SampleBytes.Length) < 0.2 - && ((evenBinaryNullsInSample * 2.0) / SampleBytes.Length) > 0.6 - ) - return Encoding.BigEndianUnicode; - - //3: UTF-8 - Martin Dürst outlines a method for detecting whether something CAN be UTF-8 content - // using regexp, in his w3c.org unicode FAQ entry: - // http://www.w3.org/International/questions/qa-forms-utf-8 - // adapted here for C#. - string potentiallyMangledString = Encoding.ASCII.GetString(SampleBytes); - - Regex UTF8Validator = new Regex(@"\A(" + @"[\x09\x0A\x0D\x20-\x7E]" + @"|[\xC2-\xDF][\x80-\xBF]" + @"|\xE0[\xA0-\xBF][\x80-\xBF]" + @"|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}" + @"|\xED[\x80-\x9F][\x80-\xBF]" + @"|\xF0[\x90-\xBF][\x80-\xBF]{2}" + @"|[\xF1-\xF3][\x80-\xBF]{3}" + @"|\xF4[\x80-\x8F][\x80-\xBF]{2}" + @")*\z"); - if (UTF8Validator.IsMatch(potentiallyMangledString)) - { - //Unfortunately, just the fact that it CAN be UTF-8 doesn't tell you much about probabilities. - //If all the characters are in the 0-127 range, no harm done, most western charsets are same as UTF-8 in these ranges. - //If some of the characters were in the upper range (western accented characters), however, they would likely be mangled to 2-byte by the UTF-8 encoding process. - // So, we need to play stats. - - // The "Random" likelihood of any pair of randomly generated characters being one - // of these "suspicious" character sequences is: - // 128 / (256 * 256) = 0.2%. - // - // In western text data, that is SIGNIFICANTLY reduced - most text data stays in the <127 - // character range, so we assume that more than 1 in 500,000 of these character - // sequences indicates UTF-8. The number 500,000 is completely arbitrary - so sue me. - // - // We can only assume these character sequences will be rare if we ALSO assume that this - // IS in fact western text - in which case the bulk of the UTF-8 encoded data (that is - // not already suspicious sequences) should be plain US-ASCII bytes. This, I - // arbitrarily decided, should be 80% (a random distribution, eg binary data, would yield - // approx 40%, so the chances of hitting this threshold by accident in random data are - // VERY low). - - if ((suspiciousUTF8SequenceCount * 500000.0 / SampleBytes.Length >= 1) //suspicious sequences - && ( - //all suspicious, so cannot evaluate proportion of US-Ascii - SampleBytes.Length - suspiciousUTF8BytesTotal == 0 - || - likelyUSASCIIBytesInSample * 1.0 / (SampleBytes.Length - suspiciousUTF8BytesTotal) >= 0.8 - ) - ) - return Encoding.UTF8; - } - - return null; - } - - private static bool IsCommonUSASCIIByte(byte testByte) - { - if (testByte == 0x0A //lf - || testByte == 0x0D //cr - || testByte == 0x09 //tab - || (testByte >= 0x20 && testByte <= 0x2F) //common punctuation - || (testByte >= 0x30 && testByte <= 0x39) //digits - || (testByte >= 0x3A && testByte <= 0x40) //common punctuation - || (testByte >= 0x41 && testByte <= 0x5A) //capital letters - || (testByte >= 0x5B && testByte <= 0x60) //common punctuation - || (testByte >= 0x61 && testByte <= 0x7A) //lowercase letters - || (testByte >= 0x7B && testByte <= 0x7E) //common punctuation - ) - return true; - else - return false; - } - - private static int DetectSuspiciousUTF8SequenceLength(byte[] SampleBytes, long currentPos) - { - int lengthFound = 0; - - if (SampleBytes.Length >= currentPos + 1 - && SampleBytes[currentPos] == 0xC2 - ) - { - if (SampleBytes[currentPos + 1] == 0x81 - || SampleBytes[currentPos + 1] == 0x8D - || SampleBytes[currentPos + 1] == 0x8F - ) - lengthFound = 2; - else if (SampleBytes[currentPos + 1] == 0x90 - || SampleBytes[currentPos + 1] == 0x9D - ) - lengthFound = 2; - else if (SampleBytes[currentPos + 1] >= 0xA0 - && SampleBytes[currentPos + 1] <= 0xBF - ) - lengthFound = 2; - } - else if (SampleBytes.Length >= currentPos + 1 - && SampleBytes[currentPos] == 0xC3 - ) - { - if (SampleBytes[currentPos + 1] >= 0x80 - && SampleBytes[currentPos + 1] <= 0xBF - ) - lengthFound = 2; - } - else if (SampleBytes.Length >= currentPos + 1 - && SampleBytes[currentPos] == 0xC5 - ) - { - if (SampleBytes[currentPos + 1] == 0x92 - || SampleBytes[currentPos + 1] == 0x93 - ) - lengthFound = 2; - else if (SampleBytes[currentPos + 1] == 0xA0 - || SampleBytes[currentPos + 1] == 0xA1 - ) - lengthFound = 2; - else if (SampleBytes[currentPos + 1] == 0xB8 - || SampleBytes[currentPos + 1] == 0xBD - || SampleBytes[currentPos + 1] == 0xBE - ) - lengthFound = 2; - } - else if (SampleBytes.Length >= currentPos + 1 - && SampleBytes[currentPos] == 0xC6 - ) - { - if (SampleBytes[currentPos + 1] == 0x92) - lengthFound = 2; - } - else if (SampleBytes.Length >= currentPos + 1 - && SampleBytes[currentPos] == 0xCB - ) - { - if (SampleBytes[currentPos + 1] == 0x86 - || SampleBytes[currentPos + 1] == 0x9C - ) - lengthFound = 2; - } - else if (SampleBytes.Length >= currentPos + 2 - && SampleBytes[currentPos] == 0xE2 - ) - { - if (SampleBytes[currentPos + 1] == 0x80) - { - if (SampleBytes[currentPos + 2] == 0x93 - || SampleBytes[currentPos + 2] == 0x94 - ) - lengthFound = 3; - if (SampleBytes[currentPos + 2] == 0x98 - || SampleBytes[currentPos + 2] == 0x99 - || SampleBytes[currentPos + 2] == 0x9A - ) - lengthFound = 3; - if (SampleBytes[currentPos + 2] == 0x9C - || SampleBytes[currentPos + 2] == 0x9D - || SampleBytes[currentPos + 2] == 0x9E - ) - lengthFound = 3; - if (SampleBytes[currentPos + 2] == 0xA0 - || SampleBytes[currentPos + 2] == 0xA1 - || SampleBytes[currentPos + 2] == 0xA2 - ) - lengthFound = 3; - if (SampleBytes[currentPos + 2] == 0xA6) - lengthFound = 3; - if (SampleBytes[currentPos + 2] == 0xB0) - lengthFound = 3; - if (SampleBytes[currentPos + 2] == 0xB9 - || SampleBytes[currentPos + 2] == 0xBA - ) - lengthFound = 3; - } - else if (SampleBytes[currentPos + 1] == 0x82 - && SampleBytes[currentPos + 2] == 0xAC - ) - lengthFound = 3; - else if (SampleBytes[currentPos + 1] == 0x84 - && SampleBytes[currentPos + 2] == 0xA2 - ) - lengthFound = 3; - } - - return lengthFound; - } - } - - //Pause code - - [Flags] - public enum ThreadAccess : int - { - TERMINATE = (0x0001), - SUSPEND_RESUME = (0x0002), - GET_CONTEXT = (0x0008), - SET_CONTEXT = (0x0010), - SET_INFORMATION = (0x0020), - QUERY_INFORMATION = (0x0040), - SET_THREAD_TOKEN = (0x0080), - IMPERSONATE = (0x0100), - DIRECT_IMPERSONATION = (0x0200) - } - - public enum EXECUTION_STATE : uint - { - ES_AWAYMODE_REQUIRED = 0x00000040, - ES_CONTINUOUS = 0x80000000, - ES_DISPLAY_REQUIRED = 0x00000002, - ES_SYSTEM_REQUIRED = 0x00000001, - } - - public static class NativeMethods - { - [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool IsWow64Process([In] IntPtr process, [Out] out bool wow64Process); - - [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] - public static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags); - - [DllImport("kernel32.dll")] - private static extern IntPtr OpenThread(ThreadAccess dwDesiredAccess, bool bInheritHandle, uint dwThreadId); - - [DllImport("kernel32.dll")] - private static extern uint SuspendThread(IntPtr hThread); - - [DllImport("kernel32.dll")] - private static extern int ResumeThread(IntPtr hThread); - - public static void Suspend(this Process process) - { - try - { - if (process.HasExited == false) - { - foreach (ProcessThread thread in process.Threads) - { - var pOpenThread = OpenThread(ThreadAccess.SUSPEND_RESUME, false, (uint)thread.Id); - if (pOpenThread == IntPtr.Zero) - { - continue; - } - SuspendThread(pOpenThread); - } - } - } - catch { } - - } - - public static void Resume(this Process process) - { - try - { - if (process.HasExited == false) - { - foreach (ProcessThread thread in process.Threads) - { - var pOpenThread = OpenThread(ThreadAccess.SUSPEND_RESUME, false, (uint)thread.Id); - if (pOpenThread == IntPtr.Zero) - { - continue; - } - ResumeThread(pOpenThread); - } - } - } - catch { } - } - } - - //End pause code - //Flickering progress bar text - public class ProgressBarWithText : ProgressBar - { - private const int WmPaint = 15; - private SizeF TextSize; - private PointF TextPos; - - public ProgressBarWithText() - { - this.DoubleBuffered = true; - this.TextChanged += ProgressBarWithText_TextChanged; - this.SizeChanged += ProgressBarWithText_SizeChanged; - } - - public override string Text - { - get { return base.Text; } - set { base.Text = value; } - } - - private void RecalcTextPos() - { - if (string.IsNullOrEmpty(base.Text)) - return; - - using (var graphics = Graphics.FromHwnd(this.Handle)) - { - TextSize = graphics.MeasureString(base.Text, this.Font); - TextPos.X = (this.Width / 2) - (TextSize.Width / 2) + 1; - TextPos.Y = (this.Height / 2) - (TextSize.Height / 2); - } - } - - private void ProgressBarWithText_SizeChanged(object sender, EventArgs e) - { - RecalcTextPos(); - } - - private void ProgressBarWithText_TextChanged(object sender, EventArgs e) - { - RecalcTextPos(); - } - - protected override void WndProc(ref Message m) - { - base.WndProc(ref m); - - switch (m.Msg) - { - case WmPaint: - using (var graphics = Graphics.FromHwnd(Handle)) - graphics.DrawString(base.Text, base.Font, Brushes.Black, TextPos.X, TextPos.Y); - break; - } - } - - protected override CreateParams CreateParams - { - get - { - CreateParams result = base.CreateParams; - result.ExStyle |= 0x02000000; // WS_EX_COMPOSITED - return result; - } - } - } - - public static class TaskbarProgress - { - public enum TaskbarStates - { - NoProgress = 0, - Indeterminate = 0x1, - Normal = 0x2, - Error = 0x4, - Paused = 0x8 - } - - [ComImport()] - [Guid("ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf")] - [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] - private interface ITaskbarList3 - { - // ITaskbarList - [PreserveSig] - void HrInit(); - - [PreserveSig] - void AddTab(IntPtr hwnd); - - [PreserveSig] - void DeleteTab(IntPtr hwnd); - - [PreserveSig] - void ActivateTab(IntPtr hwnd); - - [PreserveSig] - void SetActiveAlt(IntPtr hwnd); - - // ITaskbarList2 - [PreserveSig] - void MarkFullscreenWindow(IntPtr hwnd, [MarshalAs(UnmanagedType.Bool)] bool fFullscreen); - - // ITaskbarList3 - [PreserveSig] - void SetProgressValue(IntPtr hwnd, UInt64 ullCompleted, UInt64 ullTotal); - - [PreserveSig] - void SetProgressState(IntPtr hwnd, TaskbarStates state); - } - - [ComImport()] - [Guid("56fdf344-fd6d-11d0-958a-006097c9a090")] - [ClassInterface(ClassInterfaceType.None)] - private class TaskbarInstance { } - - private static ITaskbarList3 taskbarInstance = (ITaskbarList3)new TaskbarInstance(); - private static bool taskbarSupported = Environment.OSVersion.Version >= new Version(6, 1); - - public static void SetState(IntPtr windowHandle, TaskbarStates taskbarState) - { - if (taskbarSupported) taskbarInstance.SetProgressState(windowHandle, taskbarState); - } - - public static void SetValue(IntPtr windowHandle, double progressValue, double progressMax) - { - if (taskbarSupported) taskbarInstance.SetProgressValue(windowHandle, (ulong)progressValue, (ulong)progressMax); - } - } - - //END APP -} \ No newline at end of file