#region Using Statements
using System;
using System.IO;
#endregion

namespace OneDriveArchiver
{
    internal static class Program
    {
        private static void Main(string[] args)
        {
            const string appName = "OneDriverArchiver";

            Console.WriteLine($"{appName} v.1.0");
            Console.WriteLine("(c) 2020 JR IT Services");
            
            if (args.Length < 1)
            {
                // handle improper arguments
                Console.WriteLine(
                    $"{appName}: Please call me with {appName} sourceDirectory [optional]targetDirectory.");
            }
            else
            {
                if (string.IsNullOrEmpty(args[0]))
                {
                    Console.WriteLine("Please specify a source directory.");
                }

                // check if the directory to process really exists
                if (!Directory.Exists(args[0]))
                {
                    Console.WriteLine($"{appName}: The source directory '{args[0]}' does not exist. Please specify an existing one.");
                }
                else
                {
                    // normal processing...
                    Console.WriteLine($"{appName}: starting up...");
                    
                    // set target path
                    var targetPath = args.Length == 1 ? Path.GetFullPath(".") : args[1];
                    var startUpTime = DateTime.Now;

                    // process the base directory, plus possible containing directories recursively
                    IoHelper.ProcessFilesForDirectory(args[0], appName, targetPath);

                    var endProcessingTime = DateTime.Now;
                    var processingTime = endProcessingTime - startUpTime;

                    Console.WriteLine(
                        $"{appName}: Processing completed.\n{appName}: Processing time = {processingTime}");
                    Console.WriteLine($"{appName}: Number of files = {IoHelper.ProcessedFiles}.");
                }
            }
        }
    }
}