예제 #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>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();
            }
        }