Exemplo n.º 1
0
        public DirectoryTree()
        {
            ResumeManager  = new MemoryResumeManager();
            Shuffle        = true;
            Loop           = true;
            DelayInSec     = 15;
            TransitionTime = 2000;
            OverlayText    =
                "{description}{nl}{dateTaken}{nl}{cameraDescription}{nl}{fullName}{nl}{index} / {total}";

            AutoRun = true;

            _form.buildDate.Text = "Build date: " + Utils.RetrieveLinkerTimestamp().ToString();
            _form.directoryTreeView.CanExpandGetter = FileGroup.FileGroup.CanExpandGetter;
            _form.directoryTreeView.ChildrenGetter  = FileGroup.FileGroup.ChildrenGetter;
            _form.directoryTreeView.ItemActivate   += DirectoryTreeViewOnItemActivate;
            _form.directoryTreeView.KeyPress       +=
                delegate(object sender, KeyPressEventArgs args) { args.Handled = args.KeyChar == '\r'; };

            _form.Total.AspectGetter    = rowObject => ((FileGroup.FileGroup)rowObject).GetNumberOfFiles();
            _form.minSize.ValueChanged += MinSizeOnValueChanged;
            _form.minSizeSuffix.SelectedValueChanged += MinSizeOnValueChanged;
            _form.minSizeSuffix.Items.Clear();
            var bytes = new LabelledInt("bytes", 1);

            _form.minSizeSuffix.Items.Add(bytes);
            _form.minSizeSuffix.Items.Add(new LabelledInt("KB", 1024));
            _form.minSizeSuffix.Items.Add(new LabelledInt("MB", 1024 * 1024));
            _form.minSizeSuffix.SelectedItem = bytes;
            _form.modifiedAfterSuffix.Items.Clear();
            _form.modifiedAfterSuffix.Items.Add(new LabelledInt("seconds", 1));
            _form.modifiedAfterSuffix.Items.Add(new LabelledInt("minutes", 60));
            _form.modifiedAfterSuffix.Items.Add(new LabelledInt("hours", 60 * 60));
            var days = new LabelledInt("days", 60 * 60 * 24);

            _form.modifiedAfterSuffix.Items.Add(days);
            _form.modifiedAfterSuffix.Items.Add(new LabelledInt("weeks", 60 * 60 * 24 * 7));
            _form.modifiedAfterSuffix.Items.Add(new LabelledInt("months", 60 * 60 * 24 * 30));
            _form.modifiedAfterSuffix.Items.Add(new LabelledInt("years", 60 * 60 * 24 * 365));
            _form.modifiedAfterSuffix.SelectedItem          = days;
            _form.modifiedAfterSuffix.SelectedValueChanged += ModifiedAfterSuffixOnSelectedValueChanged;
            _form.modifiedAfter.ValueChanged += ModifiedAfterSuffixOnSelectedValueChanged;
            _form.Shown       += OnFormShown;
            _form.FormClosing += OnFormClosing;
            _form.directoryTreeView.AllowDrop  = true;
            _form.directoryTreeView.DragEnter += delegate(object sender, DragEventArgs args)
            {
                if (args.Data.GetDataPresent(DataFormats.FileDrop))
                {
                    args.Effect = DragDropEffects.Copy;
                }
                else
                {
                    args.Effect = DragDropEffects.None;
                }
            };
            _form.directoryTreeView.DragDrop += delegate(object sender, DragEventArgs args)
            {
                try
                {
                    var a = (Array)args.Data.GetData(DataFormats.FileDrop);

                    _form.BeginInvoke(new MethodInvoker(delegate
                    {
                        foreach (object fileName in a)
                        {
                            _root.Add(fileName.ToString());
                        }
                        _form.directoryTreeView.Expand(_root);
                    }));
                }
                catch (Exception)
                {
                }
            };
        }
Exemplo n.º 2
0
        private static IEnumerable <string> ReadConfiguration(IEnumerable <string> args)
        {
            List <string> errorsList = new List <string>();

            foreach (string arg in args)
            {
                string trimmed = arg.TrimStart();
                if (trimmed.Length == 0 || trimmed.StartsWith("#"))
                {
                    continue;
                }

                string[] param = trimmed.Split(new[] { '=' }, 2);
                if (param.Length == 2)
                {
                    string cmd   = param[0];
                    string value = param[1];
                    switch (cmd)
                    {
                    case "delay":
                        _directoryTreeForm.DelayInSec = Convert.ToInt32(value);
                        break;

                    case "loop":
                        _directoryTreeForm.Loop = Convert.ToBoolean(value);
                        break;

                    case "load":
                        if (!_root.Add(value))
                        {
                            errorsList.Add("Can not load " + value);
                        }
                        break;

                    case "commandfile":
                        ReadConfiguration(File.ReadLines(value));
                        break;

                    case "text":
                        _directoryTreeForm.OverlayText = value;
                        break;

                    case "transition":
                        _directoryTreeForm.TransitionTime = Convert.ToInt64(value);
                        break;

                    case "shuffle":
                        _directoryTreeForm.Shuffle = Convert.ToBoolean(value);
                        break;

                    case "browse":
                        _directoryTreeForm.Browse = Convert.ToBoolean(value);
                        break;

                    case "autorun":
                        _directoryTreeForm.AutoRun = Convert.ToBoolean(value);
                        break;

                    case "resumefile":
                    case "resume":
                        _directoryTreeForm.ResumeManager = new FileResumeManager(value);
                        break;

                    case "minSize":
                        _directoryTreeForm.MinFileSize = Convert.ToInt64(value);
                        break;

                    default:
                        throw new ApplicationException("Unknown command " + cmd);
                    }
                }
                else if (!_root.Add(arg))
                {
                    if (Path.GetFileName(arg).MatchGlob("*.ssv"))
                    {
                        ReadConfiguration(File.ReadLines(arg));
                    }
                    else
                    {
                        errorsList.Add("Can not load " + arg);
                    }
                }
            }
            return(errorsList);
        }