mirror of https://github.com/zeldaret/tmc.git
				
				
				
			use simple stdio for binary buffer writes instead of filestream
This commit is contained in:
		
							parent
							
								
									48aa1d7720
								
							
						
					
					
						commit
						9e9dc07d23
					
				| 
						 | 
				
			
			@ -3,6 +3,6 @@ file(GLOB_RECURSE sources *.cpp)
 | 
			
		|||
add_executable(asset_processor ${sources})
 | 
			
		||||
target_include_directories(asset_processor PRIVATE .)
 | 
			
		||||
target_link_libraries(asset_processor PRIVATE project_settings)
 | 
			
		||||
target_link_libraries(asset_processor PRIVATE fmt::fmt nlohmann_json::nlohmann_json filesystem)
 | 
			
		||||
target_link_libraries(asset_processor PRIVATE fmt::fmt nlohmann_json::nlohmann_json filesystem util)
 | 
			
		||||
 | 
			
		||||
install(TARGETS asset_processor RUNTIME DESTINATION bin)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,11 +1,7 @@
 | 
			
		|||
#include "asset.h"
 | 
			
		||||
#include <fstream>
 | 
			
		||||
#include <util/file.h>
 | 
			
		||||
 | 
			
		||||
void BaseAsset::extractBinary(const std::vector<char>& baserom) {
 | 
			
		||||
    auto first = baserom.begin() + start;
 | 
			
		||||
    auto last = baserom.begin() + start + size;
 | 
			
		||||
    std::vector<char> data(first, last);
 | 
			
		||||
    std::fstream file(path, std::ios::out | std::ios::binary);
 | 
			
		||||
    file.write(&data[0], static_cast<std::streamsize>(data.size()));
 | 
			
		||||
    file.close();
 | 
			
		||||
    auto file = util::open_file(path.string(), "w");
 | 
			
		||||
    std::fwrite(baserom.data() + start, 1, static_cast<size_t>(size), file.get());
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -4,6 +4,7 @@
 | 
			
		|||
#include <filesystem>
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <fstream>
 | 
			
		||||
#include <util/file.h>
 | 
			
		||||
#include <nlohmann/json.hpp>
 | 
			
		||||
#include <fmt/format.h>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -32,21 +33,13 @@ void MidiAsset::extractBinary(const std::vector<char>& baserom) {
 | 
			
		|||
 | 
			
		||||
    // Extract tracks
 | 
			
		||||
    {
 | 
			
		||||
        auto first = baserom.begin() + start;
 | 
			
		||||
        auto last = baserom.begin() + start + headerOffset;
 | 
			
		||||
        std::vector<char> data(first, last);
 | 
			
		||||
        std::fstream file(tracksPath, std::ios::out | std::ios::binary);
 | 
			
		||||
        file.write(&data[0], static_cast<std::streamsize>(data.size()));
 | 
			
		||||
        file.close();
 | 
			
		||||
        auto file = util::open_file(tracksPath.string(), "w");
 | 
			
		||||
        std::fwrite(baserom.data() + start, 1, static_cast<size_t>(headerOffset), file.get());
 | 
			
		||||
    }
 | 
			
		||||
    // Extract header
 | 
			
		||||
    {
 | 
			
		||||
        auto first = baserom.begin() + start + headerOffset;
 | 
			
		||||
        auto last = baserom.begin() + start + size;
 | 
			
		||||
        std::vector<char> data(first, last);
 | 
			
		||||
        std::fstream file(headerPath, std::ios::out | std::ios::binary);
 | 
			
		||||
        file.write(&data[0], static_cast<std::streamsize>(data.size()));
 | 
			
		||||
        file.close();
 | 
			
		||||
        auto file = util::open_file(headerPath.string(), "w");
 | 
			
		||||
        std::fwrite(baserom.data() + start + headerOffset, 1, static_cast<size_t>(size - headerOffset), file.get());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Create dummy .s file.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue