Quellcode durchsuchen

Make Compiler build again

Daniele Bartolini vor 12 Jahren
Ursprung
Commit
86f3cbd23a
2 geänderte Dateien mit 20 neuen und 22 gelöschten Zeilen
  1. 15 17
      engine/compilers/Compiler.cpp
  2. 5 5
      engine/compilers/Compiler.h

+ 15 - 17
engine/compilers/Compiler.cpp

@@ -24,15 +24,11 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include <cstring>
-#include <cstdlib>
-#include <iostream>
-
 #include "Compiler.h"
+#include "Filesystem.h"
+#include "DiskFileSource.h"
 #include "ResourceFormat.h"
-
-using std::cout;
-using std::endl;
+#include "File.h"
 
 namespace crown
 {
@@ -40,14 +36,16 @@ namespace crown
 //-----------------------------------------------------------------------------
 bool Compiler::compile(const char* root_path, const char* dest_path, const char* name_in, const char* name_out)
 {
-	std::string path_in = std::string(root_path) + "/" + std::string(name_in);
-	std::string path_out = std::string(dest_path) + "/" + std::string(name_out);
+	DiskFileSource root_disk(root_path);
+	DiskFileSource dest_disk(dest_path);
+	Filesystem root_fs(root_disk);
+	Filesystem dest_fs(dest_disk);
 
 	// The compilation fails when returned size is zero
 	size_t resource_size = 0;
-	if ((resource_size = compile_impl(path_in.c_str())) == 0)
+	if ((resource_size = compile_impl(root_fs, name_in)) == 0)
 	{
-		cout << "Compilation failed." << endl;
+		Log::e("Compilation failed");
 		return false;
 	}
 
@@ -58,23 +56,23 @@ bool Compiler::compile(const char* root_path, const char* dest_path, const char*
 	resource_header.size = resource_size;
 
 	// Open destination file and write the header
-	std::fstream out_file;
-	out_file.open(path_out.c_str(), std::fstream::out | std::fstream::binary);
+	File* out_file = dest_fs.open(name_out, FOM_WRITE);
 
-	if (out_file.is_open())
+	if (out_file)
 	{
 		// Write header
-		out_file.write((char*)&resource_header, sizeof(ResourceHeader));
+		out_file->write((char*)&resource_header, sizeof(ResourceHeader));
 
 		// Write resource-specific data
 		write_impl(out_file);
-		out_file.close();
+
+		dest_fs.close(out_file);
 
 		cleanup();
 		return true;
 	}
 
-	cout << "Unable to write compiled file." << endl;
+	Log::e("Unable to write compiled file.");
 	return false;
 }
 

+ 5 - 5
engine/compilers/Compiler.h

@@ -26,14 +26,14 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include <string>
-#include <fstream>
-
 #include "Types.h"
 
 namespace crown
 {
 
+class Filesystem;
+class File;
+
 /// Resource compiler interface.
 /// Every specific resource compiler must inherith from this
 /// interface and implement its methods accordingly.
@@ -48,8 +48,8 @@ public:
 
 protected:
 
-	virtual size_t			compile_impl(const char* resource_path) = 0;
-	virtual void			write_impl(std::fstream& out_file) = 0;
+	virtual size_t			compile_impl(Filesystem& fs, const char* resource_path) = 0;
+	virtual void			write_impl(File* out_file) = 0;
 };
 
 } // namespace crown