Example #1
0
        private static void DecideLogging()
        {
            Func <string, string> __decideLogging = (dirChecking) =>
            {
                string mutingVar = null;

                if (Directory.Exists(dirChecking) &&
                    ConsoleInteractions.Ask(string.Format("Directory \"{0}\" found in {1} - do you want to use it",
                                                          dirChecking, WORK_ABS_DIR), Console.In, Console.Out))
                {
                    mutingVar = dirChecking;
                }

                if (mutingVar == null)
                {
                    mutingVar = ConsoleInteractions.RequireChild(WORK_ABS_DIR,
                                                                 "Logs directory",
                                                                 ConsoleTextMessages.DirectoryNotFound,
                                                                 dirChecking,
                                                                 Console.In,
                                                                 Console.Out);

                    Directory.CreateDirectory(WORK_ABS_DIR_SEPARATED + mutingVar);
                }

                return(mutingVar);
            };

            if (ConsoleInteractions.Ask("Enable any kinds of logging", Console.In, Console.Out))
            {
                Console.WriteLine();
                if (USER_DIR_LOGS == null &&
                    ConsoleInteractions.Ask("Store any kinds of log files in separate directory in " + WORK_ABS_DIR,
                                            Console.In, Console.Out))
                {
                    USER_DIR_LOGS     = __decideLogging(DEFAULT_DIR_LOGS);
                    USER_ABS_DIR_LOGS = WORK_ABS_DIR_SEPARATED + USER_DIR_LOGS;
                    Console.WriteLine();
                }
                if (USER_DIR_CONSOLE_LOGS == null &&
                    ConsoleInteractions.Ask("Enable console logging", Console.In, Console.Out))
                {
                    USER_DIR_CONSOLE_LOGS     = __decideLogging(Path.Combine(USER_DIR_LOGS, DEFAULT_DIR_CONSOLE_LOGS));
                    USER_ABS_DIR_CONSOLE_LOGS = WORK_ABS_DIR_SEPARATED + USER_DIR_CONSOLE_LOGS;
                    Console.WriteLine();
                }
                if (USER_DIR_SOLUTION_LOGS == null &&
                    ConsoleInteractions.Ask("Enable solution logging", Console.In, Console.Out))
                {
                    USER_DIR_SOLUTION_LOGS     = __decideLogging(Path.Combine(USER_DIR_LOGS, DEFAULT_DIR_SOLUTION_LOGS));
                    USER_ABS_DIR_SOLUTION_LOGS = WORK_ABS_DIR_SEPARATED + USER_DIR_SOLUTION_LOGS;
                    Console.WriteLine();
                }
            }
        }
Example #2
0
        private static void Main()
        {
            Console.Title = Assembly.GetExecutingAssembly().GetName().Name;

            Console.CursorVisible = true;

            Console.WriteLine(ConsoleTextBlocks.ShowWelcome("Welcome to Sudoku Grid Files Converter!"));
            Console.WriteLine();

            string dir = ConsoleInteractions.RequireChild(WORK_ABS_DIR,
                                                          "Sources directory",
                                                          ConsoleTextMessages.DirectoryNotFound,
                                                          null,
                                                          Console.In,
                                                          Console.Out);

            SOURCES_ABS_DIR = WORK_ABS_DIR + dir + Path.DirectorySeparatorChar;
            OUTPUT_ABS_DIR  = SOURCES_ABS_DIR;

            Console.WriteLine("\n" + ConsoleTextBlocks.ShowCharsToLineEnd(Console.CursorLeft));

            while (true)
            {
                string[]   modes = Enum.GetNames(typeof(SudokuConvertionMode));
                FileStream selectedFile;
                string     outputFilePath;

                var selectedMode = (SudokuConvertionMode)ConsoleInteractions.AskMultiple(modes, Console.In, Console.Out);
                Console.WriteLine("\n");

                switch (selectedMode)
                {
                case SudokuConvertionMode.Encoding:
                    selectedFile = ConsoleInteractions.ShowListAndSelectItem(SOURCES_ABS_DIR,
                                                                             SOURCE_EXT,
                                                                             Console.In,
                                                                             Console.Out);
                    outputFilePath = OUTPUT_ABS_DIR +
                                     Path.GetFileNameWithoutExtension(OUTPUT_ABS_DIR + selectedFile.Name) + "." + CONVERTED_EXT;
                    using (SudokuGridFile.CreateBinaryFromText(selectedFile,
                                                               outputFilePath,
                                                               SudokuConvertionAlgorithm.NonUniform))
                    {
                        selectedFile.Dispose();
                    }
                    break;

                case SudokuConvertionMode.Decoding:
                    selectedFile = ConsoleInteractions.ShowListAndSelectItem(SOURCES_ABS_DIR,
                                                                             CONVERTED_EXT,
                                                                             Console.In,
                                                                             Console.Out);
                    outputFilePath = OUTPUT_ABS_DIR +
                                     Path.GetFileNameWithoutExtension(OUTPUT_ABS_DIR + selectedFile.Name) + "." + SOURCE_EXT;
                    using (SudokuGridFile.CreateTextFromBinary(selectedFile,
                                                               outputFilePath))
                    {
                        selectedFile.Dispose();
                    }
                    break;
                }

                Console.WriteLine(ConsoleTextBlocks.ShowCharsToLineEnd(Console.CursorLeft));
                Console.WriteLine();
                Console.WriteLine("Finished!");
                if (ConsoleInteractions.ShowEscapeQuestion())
                {
                    break;
                }
            }
        }