mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-03-06 21:13:02 +00:00
chore: use TextFileCheckDirtyOutput for RawTemplater
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
#include "SetDefineStreamProxy.h"
|
#include "SetDefineStreamProxy.h"
|
||||||
#include "TemplatingStreamProxy.h"
|
#include "TemplatingStreamProxy.h"
|
||||||
#include "Utils/ClassUtils.h"
|
#include "Utils/ClassUtils.h"
|
||||||
|
#include "Utils/FileUtils.h"
|
||||||
#include "Utils/Logging/Log.h"
|
#include "Utils/Logging/Log.h"
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
@@ -198,9 +199,9 @@ namespace templating
|
|||||||
if (m_first_line)
|
if (m_first_line)
|
||||||
m_first_line = false;
|
m_first_line = false;
|
||||||
else
|
else
|
||||||
m_output_stream << '\n';
|
m_output.Stream() << '\n';
|
||||||
|
|
||||||
m_output_stream << nextLine.m_line;
|
m_output.Stream() << nextLine.m_line;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -229,19 +230,35 @@ namespace templating
|
|||||||
|
|
||||||
const auto cachedData = m_output_cache.str();
|
const auto cachedData = m_output_cache.str();
|
||||||
if (!cachedData.empty())
|
if (!cachedData.empty())
|
||||||
m_output_stream << cachedData;
|
m_output.Stream() << cachedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
con::info("Templated file \"{}\"", m_output_file);
|
const auto outputResult = m_output.Close();
|
||||||
|
switch (outputResult)
|
||||||
|
{
|
||||||
|
case utils::TextFileCheckDirtyResult::OUTPUT_WRITTEN:
|
||||||
|
con::info("Templated file: \"{}\"", m_output_file);
|
||||||
|
if (buildLogFile)
|
||||||
|
*buildLogFile << "Templated file: \"" << m_output_file << "\"\n";
|
||||||
|
break;
|
||||||
|
|
||||||
if (buildLogFile)
|
case utils::TextFileCheckDirtyResult::OUTPUT_WAS_UP_TO_DATE:
|
||||||
*buildLogFile << "Templated file \"" << m_output_file << "\"\n";
|
con::info("File was up to date: \"{}\"", m_output_file);
|
||||||
|
if (buildLogFile)
|
||||||
|
*buildLogFile << "File was up to date: \"" << m_output_file << "\"\n";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case utils::TextFileCheckDirtyResult::FAILURE:
|
||||||
|
con::error("Failed to write file: \"{}\"", m_output_file);
|
||||||
|
if (buildLogFile)
|
||||||
|
*buildLogFile << "Failed to write file: \"" << m_output_file << "\"\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
m_first_line = true;
|
m_first_line = true;
|
||||||
m_write_output_to_file = false;
|
m_write_output_to_file = false;
|
||||||
m_output_cache.clear();
|
m_output_cache.clear();
|
||||||
m_output_cache.str(std::string());
|
m_output_cache.str(std::string());
|
||||||
m_output_stream.close();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -327,7 +344,7 @@ namespace templating
|
|||||||
m_write_output_to_file = true;
|
m_write_output_to_file = true;
|
||||||
const auto cachedData = m_output_cache.str();
|
const auto cachedData = m_output_cache.str();
|
||||||
if (!cachedData.empty())
|
if (!cachedData.empty())
|
||||||
m_output_stream << cachedData;
|
m_output.Stream() << cachedData;
|
||||||
m_output_cache.clear();
|
m_output_cache.clear();
|
||||||
m_output_cache.str(std::string());
|
m_output_cache.str(std::string());
|
||||||
|
|
||||||
@@ -353,8 +370,8 @@ namespace templating
|
|||||||
if (!parentDir.empty())
|
if (!parentDir.empty())
|
||||||
create_directories(parentDir);
|
create_directories(parentDir);
|
||||||
|
|
||||||
m_output_stream = std::ofstream(m_output_file, std::ios::out | std::ios::binary);
|
m_output = utils::TextFileCheckDirtyOutput(m_output_file);
|
||||||
if (!m_output_stream.is_open())
|
if (!m_output.Open())
|
||||||
{
|
{
|
||||||
con::error("Failed to open output file \"{}\"", m_output_file);
|
con::error("Failed to open output file \"{}\"", m_output_file);
|
||||||
return false;
|
return false;
|
||||||
@@ -371,12 +388,12 @@ namespace templating
|
|||||||
std::string m_filename;
|
std::string m_filename;
|
||||||
std::string m_output_file;
|
std::string m_output_file;
|
||||||
std::string m_default_output_file;
|
std::string m_default_output_file;
|
||||||
const fs::path m_output_directory;
|
fs::path m_output_directory;
|
||||||
|
|
||||||
bool m_first_line;
|
bool m_first_line;
|
||||||
bool m_skip_pass;
|
bool m_skip_pass;
|
||||||
bool m_write_output_to_file;
|
bool m_write_output_to_file;
|
||||||
std::ofstream m_output_stream;
|
utils::TextFileCheckDirtyOutput m_output;
|
||||||
std::ostringstream m_output_cache;
|
std::ostringstream m_output_cache;
|
||||||
};
|
};
|
||||||
} // namespace templating
|
} // namespace templating
|
||||||
|
|||||||
@@ -67,6 +67,12 @@ namespace utils
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextFileCheckDirtyOutput::TextFileCheckDirtyOutput()
|
||||||
|
: m_open(false),
|
||||||
|
m_has_existing_file(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
TextFileCheckDirtyOutput::TextFileCheckDirtyOutput(fs::path path)
|
TextFileCheckDirtyOutput::TextFileCheckDirtyOutput(fs::path path)
|
||||||
: m_path(std::move(path)),
|
: m_path(std::move(path)),
|
||||||
m_open(false),
|
m_open(false),
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ namespace utils
|
|||||||
class TextFileCheckDirtyOutput final
|
class TextFileCheckDirtyOutput final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
TextFileCheckDirtyOutput();
|
||||||
explicit TextFileCheckDirtyOutput(std::filesystem::path path);
|
explicit TextFileCheckDirtyOutput(std::filesystem::path path);
|
||||||
~TextFileCheckDirtyOutput();
|
~TextFileCheckDirtyOutput();
|
||||||
TextFileCheckDirtyOutput(const TextFileCheckDirtyOutput& other) = delete;
|
TextFileCheckDirtyOutput(const TextFileCheckDirtyOutput& other) = delete;
|
||||||
|
|||||||
Reference in New Issue
Block a user