Example #1
0
        //static readonly Regex colonRegex = new Regex(@"[ \t\v]+\:[ \t\v]+", RegexOptions.Compiled);
        Process CreateCommand(StreamReader entryReader, IList <string> command, bool openInput)
        {
            string fileName, arguments;

            if (LiteralLine)
            {
                string cmdline = Environment.CommandLine;

                int pos = cmdline.IndexOf(':');
                if (pos == -1)
                {
                    throw new ApplicationException("Cannot find ':' in the command line.");
                }
                cmdline = cmdline.Substring(pos + 1);

                if (Shell != null)
                {
                    fileName  = Shell;
                    arguments = cmdline;
                }
                else
                {
                    ShellTools.CreateCommandLine(cmdline, out fileName, out arguments);
                }
            }
            else
            {
                if (Shell != null)
                {
                    fileName  = Shell;
                    arguments = ShellTools.CreateArgumentsPosix(command);
                }
                else
                {
                    ShellTools.CreateCommandLine(command, out fileName, out arguments);
                }
            }

            var cmdstart = new ProcessStartInfo(fileName, arguments);

            cmdstart.UseShellExecute       = false;
            cmdstart.RedirectStandardInput = !openInput;

            string entry;

            while ((entry = entryReader.ReadLine()) != null)
            {
                Log(entry);
                ParseEntry(entry, cmdstart.EnvironmentVariables);
            }

            var proc = new Process {
                StartInfo = cmdstart
            };

            Log("Running command...");
            Log(fileName + " " + arguments);
            return(proc);
        }
Example #2
0
        Process CreateFFProbe(IList <string> entriesList, string stream)
        {
            string entries = String.Join(":", entriesList);

            var ffprobeargs = new List <string>();

            ffprobeargs.Add("ffprobe");

            ffprobeargs.Add("-v");
            ffprobeargs.Add("error");
            ffprobeargs.Add("-of");
            ffprobeargs.Add("flat");
            if (entriesList.Count > 0)
            {
                ffprobeargs.Add("-show_entries");
                ffprobeargs.Add(String.Join(":", entries));
            }
            if (stream != null)
            {
                ffprobeargs.Add("-select_streams");
                ffprobeargs.Add(stream);
            }

            ffprobeargs.Add("-");

            string fileName, arguments;

            if (Shell != null)
            {
                fileName  = Shell;
                arguments = ShellTools.CreateArgumentsPosix(ffprobeargs);
            }
            else
            {
                ShellTools.CreateCommandLine(ffprobeargs, out fileName, out arguments);
            }

            var start = new ProcessStartInfo(fileName, arguments);

            start.UseShellExecute        = false;
            start.RedirectStandardOutput = true;
            start.RedirectStandardInput  = true;
            var proc = new Process {
                StartInfo = start
            };

            Log("Running ffprobe...");
            Log(fileName + " " + arguments);
            return(proc);
        }
        public ConflictViewModel(ConflictSet conflictSet, string folderName)
        {
            this.ConflictSet = conflictSet;
            this.FolderId    = folderName;

            this.ConflictOptions = new BindableCollection <ConflictOptionViewModel>(this.ConflictSet.Conflicts.Select(x => new ConflictOptionViewModel(x)));

            // These bindings aren't called lazilly, so don't bother being lazy
            using (var icon = ShellTools.GetIcon(this.ConflictSet.File.FilePath, isFile: true))
            {
                var bs = Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                bs.Freeze();
                this.Icon = bs;
            }
        }
Example #4
0
        public FileTransferViewModel(FileTransfer fileTransfer)
        {
            this.completedTimeAgoUpdateTimer = new DispatcherTimer()
            {
                Interval = TimeSpan.FromMinutes(1),
            };
            this.completedTimeAgoUpdateTimer.Tick += (o, e) => this.NotifyOfPropertyChange(() => this.CompletedTimeAgo);
            this.completedTimeAgoUpdateTimer.Start();

            this.FileTransfer = fileTransfer;
            this.Path         = Pri.LongPath.Path.GetFileName(this.FileTransfer.Path);
            this.FullPath     = this.FileTransfer.Path;
            this.FolderId     = this.FileTransfer.FolderId;
            this.Icon         = ShellTools.GetIcon(this.FileTransfer.Path, this.FileTransfer.ItemType != ItemChangedItemType.Folder);
            this.WasDeleted   = this.FileTransfer.ActionType == ItemChangedActionType.Delete;

            this.UpdateState();
        }
        public FileTransferViewModel(FileTransfer fileTransfer)
        {
            this.completedTimeAgoUpdateTimer = new DispatcherTimer()
            {
                Interval = TimeSpan.FromMinutes(1),
            };
            this.completedTimeAgoUpdateTimer.Tick += (o, e) => this.NotifyOfPropertyChange(() => this.CompletedTimeAgo);
            this.completedTimeAgoUpdateTimer.Start();

            this.FileTransfer = fileTransfer;
            this.Path         = Pri.LongPath.Path.GetFileName(this.FileTransfer.Path);
            this.FullPath     = this.FileTransfer.Path;
            this.Folder       = this.FileTransfer.Folder;
            using (var icon = ShellTools.GetIcon(this.FileTransfer.Path, this.FileTransfer.ItemType != ItemChangedItemType.Dir))
            {
                var bs = Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                bs.Freeze();
                this.Icon = bs;
            }
            this.WasDeleted = this.FileTransfer.ActionType == ItemChangedActionType.Delete;

            this.UpdateState();
        }
Example #6
0
 public static void SendToBottom(this Window window)
 {
     ShellTools.SetBottomWindow(new WindowInteropHelper(window).Handle);
 }
Example #7
0
        public static void Main(string[] args)
        {
            CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

            var options = new Options();

            try{
                options.Parse(args);

                if (!Quiet)
                {
                    options.Banner();
                    if (Command.Count == 0)
                    {
                        Console.Error.WriteLine("No command specified. Use --help for help.");
                        return;
                    }
                }

                string inName  = PipeInVar ?? "PIPE_IN";
                string outName = PipeOutVar ?? "PIPE_OUT";

                string fileName, arguments;
                if (LiteralLine)
                {
                    string cmdline = Environment.CommandLine;

                    int pos = cmdline.IndexOf(':');
                    if (pos == -1)
                    {
                        throw new ApplicationException("Cannot find ':' in the command line.");
                    }
                    cmdline = cmdline.Substring(pos + 1);

                    if (Shell != null)
                    {
                        fileName  = Shell;
                        arguments = cmdline;
                    }
                    else
                    {
                        ShellTools.CreateCommandLine(cmdline, out fileName, out arguments, inName, outName);
                    }
                }
                else
                {
                    if (Shell != null)
                    {
                        fileName  = Shell;
                        arguments = ShellTools.CreateArgumentsPosix(Command);
                    }
                    else
                    {
                        ShellTools.CreateCommandLine(Command, out fileName, out arguments, inName, outName);
                    }
                }

                var io = new ProcessPipeIo(fileName, arguments, BufferSize ?? 4096);

                if (!Quiet && Debug)
                {
                    io.Logger = options.Log;
                }

                if (!Contained)
                {
                    io.StandardOutputRedirect = StandardPipe.Error;
                    io.StandardErrorRedirect  = StandardPipe.Error;

                    io.InName  = inName;
                    io.OutName = outName;
                }
                io.InnerPipes.AddRange(Pipes);
                var t = io.Start();
                t.Wait();
            }catch (AggregateException ae)
            {
                if (!Quiet)
                {
                    foreach (var e in ae.InnerExceptions)
                    {
                        options.Log(e.Message);
                        options.Log(e.StackTrace);
                    }
                }
            }catch (Exception e)
            {
                if (!Quiet)
                {
                    options.Log(e.Message);
                }
            }
        }
Example #8
0
        public static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

            var options = new Options();

            try{
                options.Parse(args);

                if (!Quiet)
                {
                    options.Banner();
                }
                if (Copy && Command.Count > 0)
                {
                    Console.Error.WriteLine("You cannot specify any command with the -C option.");
                    return;
                }
                else if (!Copy && Command.Count == 0)
                {
                    Console.Error.WriteLine("No command specified. Use --help for help.");
                    return;
                }

                int bufferSize = BufferSize ?? 4096;

                string inName  = InputName ?? "IMG_IN";
                string outName = OutputName ?? "IMG_OUT";

                string fileName, arguments;
                if (LiteralLine)
                {
                    string cmdline = Environment.CommandLine;

                    int pos = cmdline.IndexOf(':');
                    if (pos == -1)
                    {
                        throw new ApplicationException("Cannot find ':' in the command line.");
                    }
                    cmdline = cmdline.Substring(pos + 1);

                    if (Shell != null)
                    {
                        fileName  = Shell;
                        arguments = cmdline;
                    }
                    else
                    {
                        ShellTools.CreateCommandLine(cmdline, out fileName, out arguments, inName, outName);
                    }
                }
                else
                {
                    if (Shell != null)
                    {
                        fileName  = Shell;
                        arguments = ShellTools.CreateArgumentsPosix(Command);
                    }
                    else
                    {
                        ShellTools.CreateCommandLine(Command, out fileName, out arguments, inName, outName);
                    }
                }

                using (var stdin = Console.OpenStandardInput(bufferSize))
                {
                    int       count = 0;
                    Extractor ex;
                    while ((ex = Extractor.Create(stdin)) != null)
                    {
                        if (!Quiet)
                        {
                            if (Verbose)
                            {
                                options.Log(ex.Description + " image #" + (count++) + " found.");
                            }
                            else
                            {
                                options.Log((count++).ToString());
                            }

                            if (Debug)
                            {
                                ex.Logger = options.Log;
                            }
                        }

                        ex.BufferSize = bufferSize;

                        if (!Copy)
                        {
                            string inPath  = GetTempPath(Extension ?? ex.Extension);
                            string outPath = GetTempPath(Extension ?? ex.Extension);

                            using (var output = new FileStream(inPath, FileMode.CreateNew, FileAccess.Write, FileShare.None, bufferSize))
                            {
                                ex.Extract(output);
                            }

                            var start = new ProcessStartInfo(fileName, arguments);
                            start.UseShellExecute        = false;
                            start.RedirectStandardInput  = true;
                            start.RedirectStandardOutput = true;

                            start.EnvironmentVariables[inName]  = inPath;
                            start.EnvironmentVariables[outName] = outPath;

                            var proc = new Process {
                                StartInfo = start
                            };

                            proc.Start();

                            using (var stderr = Console.OpenStandardError(bufferSize))
                            {
                                var stdout = proc.StandardOutput.BaseStream;
                                stdout.CopyTo(stderr, bufferSize);
                            }

                            proc.WaitForExit();

                            if (File.Exists(outPath))
                            {
                                using (var stdout = Console.OpenStandardOutput(bufferSize))
                                    using (var inFile = new FileStream(outPath, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize))
                                    {
                                        inFile.CopyTo(stdout, bufferSize);
                                    }
                                File.Delete(outPath);
                            }
                            else
                            {
                                if (!Quiet)
                                {
                                    options.Log("No image was written to the output path, skipping!");
                                }
                            }

                            File.Delete(inPath);
                        }
                        else
                        {
                            using (var stdout = Console.OpenStandardOutput(bufferSize))
                            {
                                ex.Extract(stdout);
                            }
                        }
                    }
                }
            }catch (Exception e)
            {
                if (!Quiet)
                {
                    options.Log(e.Message);
                }
            }
        }
Example #9
0
        private void resultView_ItemDrag(object sender, ItemDragEventArgs e)
        {
            var dataObject = ShellTools.GetDataObject(SelectedResults.Select(result => result.FullPath), includeAsText: false);

            resultView.DoDragDrop(dataObject, DragDropEffects.Copy);
        }
Example #10
0
 private void copyToolStripMenuItem_Click(object sender, EventArgs e)
 {
     ShellTools.Copy(SelectedResults.Select(result => result.FullPath));
 }
Example #11
0
 private void openfileToolStripMenuItem_Click(object sender, EventArgs e)
 {
     ShellTools.OpenFile(SelectedResult.FullPath);
 }
Example #12
0
 private void OpenFileLocation()
 {
     ShellTools.ShowInExplorer(SelectedResult.FullPath);
 }