Example #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);
        }
Example #2
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();
            }
        }
Example #3
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();
            }
        }