Пример #1
0
        /// <summary>Reads the file text.</summary>
        /// <param name="inputFileDirectory">The input file directory.</param>
        /// <param name="inputFileName">Name of the input file.</param>
        /// <returns>The file text content.</returns>
        public string ReadFileText(string inputFileDirectory, string inputFileName)
        {
            if (string.IsNullOrEmpty(inputFileDirectory) || string.IsNullOrEmpty(inputFileName))
            {
                return(null);
            }

            try
            {
                // Make the working directory the directory for the root ink file,
                // so that relative paths for INCLUDE files are correct.
                FileSystemInteractor.SetCurrentDirectory(inputFileDirectory);
            }
            catch (Exception exception)
            {
                ConsoleInteractor.WriteErrorMessage("Could not set directory '{0}'", exception);
                ConsoleInteractor.EnvironmentExitWithCodeError1();
            }

            string fileText = null;

            try
            {
                fileText = FileSystemInteractor.ReadAllTextFromFile(inputFileName);
            }
            catch (Exception exception)
            {
                ConsoleInteractor.WriteErrorMessage("Could not open file '{0}'", exception);
                ConsoleInteractor.EnvironmentExitWithCodeError1();
            }
            return(fileText);
        }
Пример #2
0
        /// <summary>Does a Run with the specified options.</summary>
        /// <param name="options">The options.</param>
        public void Run(CommandLineToolOptions options)
        {
            if (options == null)
            {
                ConsoleInteractor.WriteErrorMessage("Missing options object");
                ConsoleInteractor.EnvironmentExitWithCodeError1();
            }

            // Read the file content
            string fileContent = ReadFileText(toolOptions.InputFileDirectory, toolOptions.InputFileName);

            Parsed.Fiction parsedFiction;
            var            story = CreateStory(fileContent, options, out parsedFiction);

            // If we have a story without errors we have compiled successfully.
            var compileSuccess = !(story == null || Errors.Count > 0);

            OutputManager.ShowCompileSuccess(options, compileSuccess);

            // If we only wanted to show the stats we are done now.
            if (options.IsOnlyShowJsonStatsActive)
            {
                return;
            }


            PrintAllMessages();

            // Without having successfully compiled we can not go on to play or flush JSON.
            if (!compileSuccess)
            {
                ConsoleInteractor.EnvironmentExitWithCodeError1();
            }

            if (options.IsFountainFileOutputNeeded)
            {
                WriteStoryToFountainFile(parsedFiction, options);
            }

            if (options.IsPlayMode)
            {
                PlayStory(story, parsedFiction, options);
            }
            else
            {
                WriteStoryToJsonFile(story, options);
            }
        }
Пример #3
0
        /// <summary>Writes the compiled story to a Fountain file.</summary>
        /// <param name="story">The story.</param>
        /// <param name="options">The options.</param>
        public void WriteStoryToFountainFile(Parsed.Fiction parsedFiction, CommandLineToolOptions options)
        {
            string fountainContent = FountainExponentialAdapter.ConvertToFountainExponential(parsedFiction, options.InputFileName);

            try
            {
                FileSystemInteractor.WriteAllTextToFile(options.RootedOutputFountainFilePath, fountainContent, System.Text.Encoding.UTF8);

                OutputManager.ShowExportComplete(options);
            }
            catch
            {
                ConsoleInteractor.WriteErrorMessage("Could not write to output file '{0}'", options.RootedOutputFilePath);
                ConsoleInteractor.EnvironmentExitWithCodeError1();
            }
        }
Пример #4
0
        /// <summary>Exits with the usage instructions.</summary>
        public void ExitWithUsageInstructions()
        {
            string usageInstructions =
                "Usage: inklecate2 <options> <ink file> \n" +
                "   -o <filename>:   Output file name\n" +
                "   -c:              Count all visits to knots, stitches and weave points, not\n" +
                "                    just those referenced by TURNS_SINCE and read counts.\n" +
                "   -p:              Play mode\n" +
                "   -j:              Output in JSON format (for communication with tools like Inky)\n" +
                "   -s:              Print stats about story including word count in JSON format\n" +
                "   -v:              Verbose mode - print compilation timings\n" +
                "   -k:              Keep inklecate running in play mode even after story is complete\n";

            ConsoleInteractor.WriteInformation(usageInstructions);
            ConsoleInteractor.EnvironmentExitWithCodeError1();
        }
Пример #5
0
        /// <summary>Writes the compiled story to a JSON file.</summary>
        /// <param name="story">The story.</param>
        /// <param name="options">The options.</param>
        public void WriteStoryToJsonFile(Runtime.IStory story, CommandLineToolOptions options)
        {
            // Compile mode
            var jsonStr = story.ToJson();

            try
            {
                FileSystemInteractor.WriteAllTextToFile(options.RootedOutputFilePath, jsonStr, System.Text.Encoding.UTF8);

                OutputManager.ShowExportComplete(options);
            }
            catch
            {
                ConsoleInteractor.WriteErrorMessage("Could not write to output file '{0}'", options.RootedOutputFilePath);
                ConsoleInteractor.EnvironmentExitWithCodeError1();
            }
        }