public FileOrganizer(DirectoryInfo destination, CommandLineOptions opts, ParsedFileCache cache) : this(destination)
 {
     this.Options = opts;
     this.Cache   = cache;
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            var opts = new CommandLineOptions();

            if (!CommandLine.Parser.Default.ParseArguments(args, opts))
            {
                Console.WriteLine(HelpText.AutoBuild(opts));
                return;
            }

            if (opts.Debug)
            {
                System.Diagnostics.Debugger.Break();
            }

            ParsedFileCache cache = new ParsedFileCache(opts.SourceFolder);

            if (opts.ResetCache)
            {
                cache.ClearAll();
            }

            Console.CancelKeyPress += (sender, eventArgs) => {
                if (opts.CacheFileInfo)
                {
                    Console.WriteLine("Flushing cache to disk...");
                    cache.PersistCache();
                }
                Environment.Exit(-1);
            };


            if (string.IsNullOrEmpty(opts.SourceFolder))
            {
                opts.SourceFolder = System.Environment.CurrentDirectory;
            }



            DirectoryInfo destination = new DirectoryInfo(opts.DestinationFolder);

            if (!destination.Exists)
            {
                Console.WriteLine("Error: Destination folder doesn't exist.");
                return;
            }

            DirectoryInfo source = new DirectoryInfo(opts.SourceFolder);

            if (!source.Exists)
            {
                Console.WriteLine("Error: Source folder doesn't exist. Nothing to do.");
                return;
            }

            if (opts.ConflictBehavior == ExistingFileMode.Delete)
            {
                Console.Write("Delete source files on existing files in destination is enabled.\nTHIS MAY CAUSE DATA LOSS, are you sure? [Y/N]: ");
                var key = Console.ReadKey();
                if (!(key.KeyChar == 'y' || key.KeyChar == 'Y'))
                {
                    return;
                }
                Console.WriteLine();
            }

            FileOrganizer organizer = new FileOrganizer(destination, opts, cache);

            organizer.ProcessSourceFolder(source);
            if (cache.HasChanged)
            {
                cache.PersistCache();
            }
        }