Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            List <string> errors    = new List <string>();
            Operations    operation = args.Length > 0 ? _operationParser.Parse(args[0]) : Operations.Nothing;

            if (operation == Operations.Nothing)
            {
                errors.Add("Nothing to do");
            }

            string inPath  = args.Length > 1 ? args[1] : string.Empty;
            string outPath = args.Length > 2 ? args[2] : string.Empty;
            string pathValidationResult = _pathValidator.Validate(inPath);

            if (pathValidationResult != null)
            {
                errors.Add($"{inPath} - {pathValidationResult}");
            }

            if (outPath == null)
            {
                errors.Add($"{outPath} - is empty");
            }

            if (errors.Any())
            {
                Console.WriteLine(string.Join("\\n", errors));
                Console.ReadKey();
            }
            else
            {
                string      result;
                IArchivator archivator = null;
                try
                {
                    using (IManager manager = new Manager(inPath, outPath, operation))
                    {
                        archivator = new Archivator(manager);
                        result     = archivator.Perform();
                    }
                }
                catch {
                    result = Responses.NOT_SUCCESS;
                }
                Console.WriteLine(result);
                Console.ReadKey();
            }
        }
Ejemplo n.º 2
0
        static int Main(string[] args)
        {
            try
            {
                ValidateInput(args);
                Archivator archivator = new Archivator(args[0]);
                archivator.ProcessFile(new FileInfo(args[1]), new FileInfo(args[2]));

                return(0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(1);
            }
        }
Ejemplo n.º 3
0
        static int Main(string[] args)
        {
            Console.CancelKeyPress += new ConsoleCancelEventHandler(CancelEventHandler);

            try
            {
#if DEBUG
                Console.ReadKey();

                args = new string[3];

                args[0] = @"compress";
                args[1] = @"F:\Copressing\expansion2-speech-ruRU.MPQ";
                args[2] = @"F:\Copressing\Break";

                //args[0] = @"compress";
                //args[1] = @"F:\WOW\WoWCircle 4.3.4\Data\world.MPQ";
                //args[2] = @"F:\Copressing\Break";

                //args[0] = @"compress";
                //args[1] = @"G:\Movies\Breaking Bad (2008-2013) BDRip 1080p [KvK]\Breaking Bad - Season 5\5x01 - Live Free or Die.mkv";
                //args[2] = @"F:\Copressing\Break";

                //args[0] = @"decompress";
                //args[1] = @"F:\Copressing\Break.gz";
                //args[2] = @"F:\Copressing\Breaking Bad.mkv";
#endif

                InputValidator validator = new InputValidator();

                if (!validator.Validate(args))
                {
                    foreach (var validatorError in validator.Errors)
                    {
                        Console.WriteLine(validatorError);
                    }

                    Console.ReadKey();

                    return(1);
                }

                Console.WriteLine("Start process");

#if DEBUG
                Stopwatch stopwatch = new Stopwatch();

                stopwatch.Start();
#endif
                switch (args[0].ToLower())
                {
                case "compress":
                    using (Archivator archivator = new Archivator(args[1], args[2], ArchiveActionModel.Compress))
                    {
                        CancellingObjects.Add((ICancelling)archivator);
                        archivator.Archive();
                    }
                    break;

                case "decompress":
                    using (Archivator archivator = new Archivator(args[1], args[2], ArchiveActionModel.Decompress))
                    {
                        CancellingObjects.Add((ICancelling)archivator);
                        archivator.Extract();
                    }
                    break;
                }

#if DEBUG
                stopwatch.Stop();

                Console.WriteLine($"Time {stopwatch.ElapsedMilliseconds} millisecond.");

                Console.ReadKey();
#endif

                Console.WriteLine("Finish process");

                return(0);
            }

            catch (Exception ex)
            {
                Console.WriteLine("Error is occured!\n Method: {0}\n Error description {1}", ex.TargetSite, ex.Message);

                Console.ReadKey();

                return(1);
            }
        }