Example #1
0
 public static int Create(ManagedDirectory info)
 {
     var gen = new Watcher(info);
     gen.Index = __watchers.Count;
     __watchers.Add(gen);
     return gen.Index;
 }
Example #2
0
        public static int Create(ManagedDirectory info)
        {
            var gen = new Watcher(info);

            gen.Index = __watchers.Count;
            __watchers.Add(gen);
            return(gen.Index);
        }
Example #3
0
        public static bool isManagedFile(string path, ManagedDirectory order)
        {
            bool extensionPass = false;
            bool includePass   = true;
            bool decludePass   = true;
            bool optionPass    = false;

            if (order.Option.FileExtensions.Count == 0)
            {
                extensionPass = true;
            }
            else
            {
                foreach (var item in order.Option.FileExtensions)
                {
                    if (Path.GetExtension(path) == item)
                    {
                        extensionPass = true;
                    }
                }
            }

            foreach (var item in order.Option.IncludeStrings)
            {
                if (!path.Contains(item))
                {
                    includePass = false;
                }
            }


            foreach (var item in order.Option.DecludeStrings)
            {
                if (path.Contains(item))
                {
                    decludePass = false;
                }
            }

            if (order.Option.OptionStrings.Count == 0)
            {
                optionPass = true;
            }
            else
            {
                foreach (var item in order.Option.OptionStrings)
                {
                    if (path.Contains(item))
                    {
                        optionPass = true;
                    }
                }
            }

            return(extensionPass & includePass & decludePass & optionPass);
        }
Example #4
0
        public static bool isManagedFile(string path, ManagedDirectory order)
        {
            bool extensionPass = false;
            bool includePass = true;
            bool decludePass = true;
            bool optionPass = false;

            if (order.Option.FileExtensions.Count == 0)
            {
                extensionPass = true;
            }
            else
            {
                foreach (var item in order.Option.FileExtensions)
                {
                    if (Path.GetExtension(path) == item)
                    {
                        extensionPass = true;
                    }
                }
            }

            foreach (var item in order.Option.IncludeStrings)
            {
                if (!path.Contains(item))
                {
                    includePass = false;
                }
            }

            foreach (var item in order.Option.DecludeStrings)
            {
                if (path.Contains(item))
                {
                    decludePass = false;
                }
            }

            if (order.Option.OptionStrings.Count == 0)
            {
                optionPass = true;
            }
            else
            {
                foreach (var item in order.Option.OptionStrings)
                {
                    if (path.Contains(item))
                    {
                        optionPass = true;
                    }
                }
            }

            return extensionPass & includePass & decludePass & optionPass;
        }
Example #5
0
        void Process(string a_dir, ManagedDirectory order)
        {
            if (order.Option.RootSerach)
            {
                var dirs = Directory.GetDirectories(a_dir);
                foreach (var dir in dirs)
                {
                    Process(dir, order);
                }
            }

            var files = Directory.GetFiles(a_dir);

            foreach (var file in files)
            {
                var fn = Path.GetFileName(file);

                if (isManagedFile(fn, order))
                {
                    var c_dir = a_dir.Replace(order.DepartureFolder, order.DestinationFolder);
                    var dest  = Path.Combine(c_dir, fn);
                    if (File.Exists(dest))
                    {
                        bool np = false;
                        switch (order.Option.Duplicate)
                        {
                        case DuplicateProcessing.Overwrite:
                            break;

                        case DuplicateProcessing.Renaming:
                            dest = Path.Combine(
                                Path.GetDirectoryName(dest),
                                string.Format(
                                    "{0} ({1}){2}",
                                    Path.GetFileNameWithoutExtension(dest),
                                    DateTime.Now.Ticks,
                                    Path.GetExtension(dest)
                                    )
                                );
                            break;

                        case DuplicateProcessing.None:
                            np = true;
                            break;
                        }
                        if (np)
                        {
                            continue;
                        }
                    }
                    if (!Directory.Exists(c_dir))
                    {
                        Directory.CreateDirectory(c_dir);
                    }
                    if (order.Option.isCopy)
                    {
                        File.Copy(file, dest, true);
                    }
                    else
                    {
                        File.Move(file, dest);
                    }
                }
            }
        }
Example #6
0
        public CreateOrder(ManagedDirectory d, int index)
        {
            InitializeComponent();
            folderBrowserDialog1.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            this.index = index;
            if(d.WatcherIndex > 0)
            {
                Watcher.Stop(d.WatcherIndex);
                Watcher.Remove(d.WatcherIndex);
            }

            TextBoxdeparture.Text = d.DepartureFolder;
            TextBoxDestination.Text = d.DestinationFolder;

            var sb = new StringBuilder();
            if (d.Option.FileExtensions.Count > 0)
            {
                CheckBoxFileExtensions.Checked = true;
                TextBoxFileExtensions.Enabled = true;
                for (int i = 0; i < d.Option.FileExtensions.Count; i++)
                {
                    sb.Append(d.Option.FileExtensions[i]);
                    if (d.Option.FileExtensions.Count - 1 != i)
                    {
                        sb.Append(' ');
                    }
                }
                TextBoxFileExtensions.Text = sb.ToString();
                if (sb.Length > 0) sb.Remove(0, sb.Length);
            }
            if (d.Option.IncludeStrings.Count > 0)
            {
                CheckBoxIncludes.Checked = true;
                TextBoxInclude.Enabled = true;
                for (int i = 0; i < d.Option.IncludeStrings.Count; i++)
                {
                    sb.Append(d.Option.IncludeStrings[i]);
                    if (d.Option.IncludeStrings.Count - 1 != i)
                    {
                        sb.Append(' ');
                    }
                }
                TextBoxInclude.Text = sb.ToString();
                if (sb.Length > 0) sb.Remove(0, sb.Length);
            }
            if (d.Option.DecludeStrings.Count > 0)
            {
                CheckBoxDecludeStrings.Checked = true;
                TextBoxDecludeStrings.Enabled = true;
                for (int i = 0; i < d.Option.DecludeStrings.Count; i++)
                {
                    sb.Append(d.Option.DecludeStrings[i]);
                    if (d.Option.DecludeStrings.Count - 1 != i)
                    {
                        sb.Append(' ');
                    }
                }
                TextBoxInclude.Text = sb.ToString();
                if (sb.Length > 0) sb.Remove(0, sb.Length);
            }
            if (d.Option.OptionStrings.Count > 0)
            {
                CheckBoxOptions.Checked = true;
                TextBoxOptionStrings.Enabled = true;
                for (int i = 0; i < d.Option.OptionStrings.Count; i++)
                {
                    sb.Append(d.Option.OptionStrings[i]);
                    if (d.Option.OptionStrings.Count - 1 != i)
                    {
                        sb.Append(' ');
                    }
                }
                TextBoxOptionStrings.Text = sb.ToString();
            }

            RadioIsCopy.Checked = d.Option.isCopy;
            RadioIsMove.Checked = !d.Option.isCopy;

            if(d.Option.Duplicate == DuplicateProcessing.Overwrite)
            {

                dubCombobox.Text = Properties.Resources.OverwriteString;
            }
            else if(d.Option.Duplicate == DuplicateProcessing.Renaming)
            {
                dubCombobox.Text = Properties.Resources.RenamingString;
            }
            else if(d.Option.Duplicate == DuplicateProcessing.None)
            {
                dubCombobox.Text = Properties.Resources.NoneString;
            }

            RootSearch.Checked = d.Option.RootSerach;
            RealTimeWatchService.Checked = d.Option.RealtimeWatch;
        }
Example #7
0
        private void button4_Click(object sender, EventArgs e)
        {
            if (CheckBoxIncludes.Checked == false) TextBoxInclude.Text = string.Empty;
            if (CheckBoxOptions.Checked == false) TextBoxOptionStrings.Text = string.Empty;
            if (CheckBoxDecludeStrings.Checked == false) TextBoxDecludeStrings.Text = string.Empty;
            if (CheckBoxFileExtensions.Checked == false) TextBoxFileExtensions.Text = string.Empty;

            DuplicateProcessing dp = DuplicateProcessing.None;
            if (dubCombobox.Text == Properties.Resources.OverwriteString)
            {
                dp = DuplicateProcessing.Overwrite;
            }
            else if (dubCombobox.Text == Properties.Resources.RenamingString)
            {
                dp = DuplicateProcessing.Renaming;
            }

            var option = new Option(
                    GetArrayFromTextbox(TextBoxFileExtensions.Text),
                    GetArrayFromTextbox(TextBoxInclude.Text),
                    GetArrayFromTextbox(TextBoxDecludeStrings.Text),
                    GetArrayFromTextbox(TextBoxOptionStrings.Text),
                    RadioIsCopy.Checked,
                    dp,
                    RootSearch.Checked,
                    RealTimeWatchService.Checked
                    );

            var gen = new ManagedDirectory(
                    TextBoxdeparture.Text,
                    TextBoxDestination.Text,
                    option
                    );
            if(this.index == -1) // new obj
            {
                Setting.Orders.Add(gen);
            }
            else
            {
                Setting.Orders[index] = gen;
            }

            if (gen.Enabled && gen.Option.RealtimeWatch)
            {
                gen.WatcherIndex = Watcher.Create(gen);
            }

            this.Close();
        }
Example #8
0
        void Process(string a_dir, ManagedDirectory order)
        {
            if (order.Option.RootSerach)
            {
                var dirs = Directory.GetDirectories(a_dir);
                foreach (var dir in dirs)
                {
                    Process(dir, order);
                }
            }

            var files = Directory.GetFiles(a_dir);
            foreach (var file in files)
            {
                var fn = Path.GetFileName(file);

                if (isManagedFile(fn, order))
                {
                    var c_dir = a_dir.Replace(order.DepartureFolder, order.DestinationFolder);
                    var dest = Path.Combine(c_dir, fn);
                    if (File.Exists(dest))
                    {
                        bool np = false;
                        switch (order.Option.Duplicate)
                        {
                            case DuplicateProcessing.Overwrite:
                                break;
                            case DuplicateProcessing.Renaming:
                                dest = Path.Combine(
                                     Path.GetDirectoryName(dest),
                                     string.Format(
                                         "{0} ({1}){2}",
                                         Path.GetFileNameWithoutExtension(dest),
                                         DateTime.Now.Ticks,
                                         Path.GetExtension(dest)
                                     )
                                 );
                                break;
                            case DuplicateProcessing.None:
                                np = true;
                                break;
                        }
                        if (np) continue;
                    }
                    if (!Directory.Exists(c_dir)) Directory.CreateDirectory(c_dir);
                    if (order.Option.isCopy)
                    {
                        File.Copy(file, dest, true);
                    }
                    else
                    {
                        File.Move(file, dest);
                    }
                }
            }
        }
Example #9
0
 private Watcher(ManagedDirectory info)
 {
     this.info = info;
     StartWatch();
 }
Example #10
0
 private Watcher(ManagedDirectory info)
 {
     this.info = info;
     StartWatch();
 }
Example #11
0
        public CreateOrder(ManagedDirectory d, int index)
        {
            InitializeComponent();
            folderBrowserDialog1.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            this.index = index;
            if (d.WatcherIndex > 0)
            {
                Watcher.Stop(d.WatcherIndex);
                Watcher.Remove(d.WatcherIndex);
            }

            TextBoxdeparture.Text   = d.DepartureFolder;
            TextBoxDestination.Text = d.DestinationFolder;

            var sb = new StringBuilder();

            if (d.Option.FileExtensions.Count > 0)
            {
                CheckBoxFileExtensions.Checked = true;
                TextBoxFileExtensions.Enabled  = true;
                for (int i = 0; i < d.Option.FileExtensions.Count; i++)
                {
                    sb.Append(d.Option.FileExtensions[i]);
                    if (d.Option.FileExtensions.Count - 1 != i)
                    {
                        sb.Append(' ');
                    }
                }
                TextBoxFileExtensions.Text = sb.ToString();
                if (sb.Length > 0)
                {
                    sb.Remove(0, sb.Length);
                }
            }
            if (d.Option.IncludeStrings.Count > 0)
            {
                CheckBoxIncludes.Checked = true;
                TextBoxInclude.Enabled   = true;
                for (int i = 0; i < d.Option.IncludeStrings.Count; i++)
                {
                    sb.Append(d.Option.IncludeStrings[i]);
                    if (d.Option.IncludeStrings.Count - 1 != i)
                    {
                        sb.Append(' ');
                    }
                }
                TextBoxInclude.Text = sb.ToString();
                if (sb.Length > 0)
                {
                    sb.Remove(0, sb.Length);
                }
            }
            if (d.Option.DecludeStrings.Count > 0)
            {
                CheckBoxDecludeStrings.Checked = true;
                TextBoxDecludeStrings.Enabled  = true;
                for (int i = 0; i < d.Option.DecludeStrings.Count; i++)
                {
                    sb.Append(d.Option.DecludeStrings[i]);
                    if (d.Option.DecludeStrings.Count - 1 != i)
                    {
                        sb.Append(' ');
                    }
                }
                TextBoxInclude.Text = sb.ToString();
                if (sb.Length > 0)
                {
                    sb.Remove(0, sb.Length);
                }
            }
            if (d.Option.OptionStrings.Count > 0)
            {
                CheckBoxOptions.Checked      = true;
                TextBoxOptionStrings.Enabled = true;
                for (int i = 0; i < d.Option.OptionStrings.Count; i++)
                {
                    sb.Append(d.Option.OptionStrings[i]);
                    if (d.Option.OptionStrings.Count - 1 != i)
                    {
                        sb.Append(' ');
                    }
                }
                TextBoxOptionStrings.Text = sb.ToString();
            }

            RadioIsCopy.Checked = d.Option.isCopy;
            RadioIsMove.Checked = !d.Option.isCopy;

            if (d.Option.Duplicate == DuplicateProcessing.Overwrite)
            {
                dubCombobox.Text = Properties.Resources.OverwriteString;
            }
            else if (d.Option.Duplicate == DuplicateProcessing.Renaming)
            {
                dubCombobox.Text = Properties.Resources.RenamingString;
            }
            else if (d.Option.Duplicate == DuplicateProcessing.None)
            {
                dubCombobox.Text = Properties.Resources.NoneString;
            }

            RootSearch.Checked           = d.Option.RootSerach;
            RealTimeWatchService.Checked = d.Option.RealtimeWatch;
        }
Example #12
0
        private void button4_Click(object sender, EventArgs e)
        {
            if (CheckBoxIncludes.Checked == false)
            {
                TextBoxInclude.Text = string.Empty;
            }
            if (CheckBoxOptions.Checked == false)
            {
                TextBoxOptionStrings.Text = string.Empty;
            }
            if (CheckBoxDecludeStrings.Checked == false)
            {
                TextBoxDecludeStrings.Text = string.Empty;
            }
            if (CheckBoxFileExtensions.Checked == false)
            {
                TextBoxFileExtensions.Text = string.Empty;
            }

            DuplicateProcessing dp = DuplicateProcessing.None;

            if (dubCombobox.Text == Properties.Resources.OverwriteString)
            {
                dp = DuplicateProcessing.Overwrite;
            }
            else if (dubCombobox.Text == Properties.Resources.RenamingString)
            {
                dp = DuplicateProcessing.Renaming;
            }

            var option = new Option(
                GetArrayFromTextbox(TextBoxFileExtensions.Text),
                GetArrayFromTextbox(TextBoxInclude.Text),
                GetArrayFromTextbox(TextBoxDecludeStrings.Text),
                GetArrayFromTextbox(TextBoxOptionStrings.Text),
                RadioIsCopy.Checked,
                dp,
                RootSearch.Checked,
                RealTimeWatchService.Checked
                );

            var gen = new ManagedDirectory(
                TextBoxdeparture.Text,
                TextBoxDestination.Text,
                option
                );

            if (this.index == -1) // new obj
            {
                Setting.Orders.Add(gen);
            }
            else
            {
                Setting.Orders[index] = gen;
            }

            if (gen.Enabled && gen.Option.RealtimeWatch)
            {
                gen.WatcherIndex = Watcher.Create(gen);
            }

            this.Close();
        }