30 return fs::absolute(path);
36 if(!fs::exists(absolute_path, ec) || !fs::is_regular_file(absolute_path, ec))
41 const auto extension = absolute_path.extension().string();
44 for(
const auto&
format : formats)
60 if(!fs::exists(resolved, ec) || !fs::is_regular_file(resolved, ec))
62 APPLOG_WARNING(
"Reimport skipped: '{}' is not a regular file", resolved.generic_string());
76 if(
name.empty() || (std::isdigit(
static_cast<unsigned char>(
name.front())) != 0))
80 return std::all_of(
name.begin(),
84 return std::isalnum(c) != 0 || c ==
'_';
90 std::ifstream
input(template_path, std::ios::binary);
93 const auto msg =
"Script template not found: " + template_path.generic_string();
102 std::ostringstream buffer;
103 buffer <<
input.rdbuf();
104 auto content = buffer.str();
108 const auto absolute = fs::absolute(dst);
109 fs::create_directories(absolute.parent_path(), err);
116 [&](
const fs::path& temp)
118 std::ofstream output(temp, std::ios::binary | std::ios::trunc);
119 if(!output.is_open())
121 throw std::runtime_error(
"Failed to open temp file for write: " + temp.generic_string());
123 output.write(content.data(),
static_cast<std::streamsize
>(content.size()));
126 throw std::runtime_error(
"Failed writing temp file: " + temp.generic_string());
131 catch(
const std::exception&
ex)
133 const auto msg = std::string(
ex.what());
144 const auto msg =
"Atomic write failed: " + absolute.generic_string() +
" (" + err.message() +
")";
gfx::texture_format format
static void touch(const fs::path &path, bool recursive, fs::file_time_type time=fs::now())
Sets the last modification time of a file or directory. by default sets the time to the current time.
#define APPLOG_WARNING(...)
#define APPLOG_ERROR(...)
auto get_all_formats() -> const std::vector< std::vector< std::string > > &
path resolve_protocol(const path &_path)
Given the specified path/filename, resolve the final full filename. This will be based on either the ...
bool has_known_protocol(const path &_path)
Checks whether the path has a known protocol.
void replace(std::string &str, const std::string &search, const std::string &replace)
auto is_valid_csharp_identifier(const std::string &name) -> bool
auto resolve_asset_source_path(const std::string &asset_key) -> fs::path
void reimport_key(const std::string &asset_key)
auto create_script_from_template(const fs::path &template_path, const fs::path &dst, std::string *error) -> bool
Instantiate a ScriptComponent template (.cs.in), substituting #SCRIPTNAME# with the destination file ...
void reimport_path(const fs::path &absolute_path)
auto can_reimport(const fs::path &absolute_path) -> bool
void atomic_write_file(const fs::path &dst, const std::function< void(const fs::path &)> &callback, fs::error_code &ec) noexcept