This commit is contained in:
Mikulas Florek 2016-03-17 18:14:47 +01:00
parent 64b08c7bdf
commit 4d6a7160b4
20 changed files with 87 additions and 79 deletions

View file

@ -104,7 +104,7 @@ static bool saveAsRaw(ImportAssetDialog& dialog,
Lumix::FS::OsFile file;
if (!file.open(dest_path,
Lumix::FS::Mode::WRITE | Lumix::FS::Mode::CREATE,
Lumix::FS::Mode::CREATE_AND_WRITE,
dialog.getEditor().getAllocator()))
{
dialog.setMessage(
@ -172,7 +172,7 @@ static bool saveAsDDS(ImportAssetDialog& dialog,
Lumix::FS::OsFile file;
if (!file.open(dest_path,
Lumix::FS::Mode::WRITE | Lumix::FS::Mode::CREATE,
Lumix::FS::Mode::CREATE_AND_WRITE,
dialog.getEditor().getAllocator()))
{
dialog.setMessage(
@ -700,7 +700,7 @@ struct ConvertTask : public Lumix::MT::Task
}
if (!file.open(ani_path,
Lumix::FS::Mode::WRITE | Lumix::FS::Mode::CREATE,
Lumix::FS::Mode::CREATE_AND_WRITE,
m_dialog.m_editor.getAllocator()))
{
Lumix::g_log_error.log("Editor") << "Could not create file " << ani_path;
@ -818,7 +818,7 @@ struct ConvertTask : public Lumix::MT::Task
m_dialog.setImportMessage(
StringBuilder<Lumix::MAX_PATH_LENGTH + 30>("Converting ") << output_material_name, -1);
Lumix::FS::OsFile file;
if (!file.open(output_material_name, Lumix::FS::Mode::CREATE | Lumix::FS::Mode::WRITE, m_dialog.m_editor.getAllocator()))
if (!file.open(output_material_name, Lumix::FS::Mode::CREATE_AND_WRITE, m_dialog.m_editor.getAllocator()))
{
m_dialog.setMessage(StringBuilder<20 + Lumix::MAX_PATH_LENGTH>(
"Could not create ", output_material_name));
@ -1477,7 +1477,7 @@ struct ConvertTask : public Lumix::MT::Task
PathBuilder phy_path(m_dialog.m_output_dir);
phy_path << "/" << filename;
Lumix::FS::OsFile file;
if (!file.open(phy_path, Lumix::FS::Mode::CREATE | Lumix::FS::Mode::WRITE, m_dialog.m_editor.getAllocator()))
if (!file.open(phy_path, Lumix::FS::Mode::CREATE_AND_WRITE, m_dialog.m_editor.getAllocator()))
{
Lumix::g_log_error.log("Editor") << "Could not create file " << phy_path;
return false;
@ -1667,7 +1667,7 @@ struct ConvertTask : public Lumix::MT::Task
Lumix::FS::OsFile file;
if (!file.open(path,
Lumix::FS::Mode::CREATE | Lumix::FS::Mode::WRITE, m_dialog.m_editor.getAllocator()))
Lumix::FS::Mode::CREATE_AND_WRITE, m_dialog.m_editor.getAllocator()))
{
m_dialog.setMessage(
StringBuilder<Lumix::MAX_PATH_LENGTH + 15>("Failed to open ", path));

View file

@ -59,7 +59,7 @@ bool Metadata::load()
bool Metadata::save()
{
Lumix::FS::OsFile file;
if (!file.open(METADATA_FILENAME, Lumix::FS::Mode::OPEN | Lumix::FS::Mode::WRITE, m_allocator)) return false;
if (!file.open(METADATA_FILENAME, Lumix::FS::Mode::CREATE_AND_WRITE, m_allocator)) return false;
int count = m_data.size();
file.write(&count, sizeof(count));

View file

@ -725,7 +725,7 @@ static const char* getResourceStateString(Lumix::Resource::State state)
void ProfilerUIImpl::saveResourceList()
{
Lumix::FS::OsFile file;
if (file.open("resources.csv", Lumix::FS::Mode::CREATE | Lumix::FS::Mode::WRITE, m_allocator))
if (file.open("resources.csv", Lumix::FS::Mode::CREATE_AND_WRITE, m_allocator))
{
auto& managers = m_resource_manager.getAll();
for (auto* i : managers)

View file

@ -234,7 +234,7 @@ Settings* Settings::getInstance()
bool Settings::save(Action** actions, int actions_count)
{
Lumix::FS::OsFile file;
if (!file.open(SETTINGS_PATH, Lumix::FS::Mode::WRITE | Lumix::FS::Mode::CREATE, m_allocator)) return false;
if (!file.open(SETTINGS_PATH, Lumix::FS::Mode::CREATE_AND_WRITE, m_allocator)) return false;
file << "window = { x = " << m_window.x
<< ", y = " << m_window.y

View file

@ -1186,7 +1186,7 @@ public:
}
Lumix::FS::OsFile file;
if (!file.open(dest, Lumix::FS::Mode::CREATE | Lumix::FS::Mode::WRITE, m_allocator))
if (!file.open(dest, Lumix::FS::Mode::CREATE_AND_WRITE, m_allocator))
{
Lumix::g_log_error.log("Editor") << "Could not create " << dest;
return;

View file

@ -256,11 +256,7 @@ public:
const DeviceList& getMemoryDevice() const override { return m_memory_device; }
const DeviceList& getDiskDevice() const override { return m_disk_device; }
void setSaveGameDevice(const char* dev) override { fillDeviceList(dev, m_save_game_device); }

View file

@ -18,6 +18,44 @@ class IFile;
class IFileDevice;
typedef Delegate<void(IFile&, bool)> ReadCallback;
struct Mode
{
enum Value
{
NONE = 0,
READ = 0x1,
WRITE = READ << 1,
OPEN = WRITE << 1,
CREATE = OPEN << 1,
CREATE_AND_WRITE = CREATE | WRITE,
OPEN_AND_READ = OPEN | READ
};
Mode() : value(0) {}
Mode(Value _value) : value(_value) { }
Mode(int32 _value) : value(_value) { }
operator Value() const { return (Value)value; }
int32 value;
};
struct SeekMode
{
enum Value
{
BEGIN = 0,
END,
CURRENT,
};
SeekMode(Value _value) : value(_value) {}
SeekMode(uint32 _value) : value(_value) {}
operator Value() { return (Value)value; }
uint32 value;
};
struct LUMIX_ENGINE_API DeviceList
{
IFileDevice* m_devices[8];

View file

@ -1,6 +1,6 @@
#pragma once
#include "core/fs/ifile_system_defines.h"
#include "core/fs/file_system.h"
#include "lumix.h"
namespace Lumix

View file

@ -1,49 +0,0 @@
#pragma once
#include "lumix.h"
#include "core/delegate.h"
namespace Lumix
{
namespace FS
{
class IFile;
class FileSystem;
typedef Delegate<void (IFile&, bool)> ReadCallback;
struct Mode
{
enum Value
{
NONE = 0,
READ = 0x1,
WRITE = READ << 1,
OPEN = WRITE << 1,
CREATE = OPEN << 1,
OPEN_OR_CREATE = CREATE << 1,
OPEN_AND_READ = OPEN | READ
};
Mode() : value(0) {}
Mode(Value _value) : value(_value) { }
Mode(int32 _value) : value(_value) { }
operator Value() const { return (Value)value; }
int32 value;
};
struct SeekMode
{
enum Value
{
BEGIN = 0,
END,
CURRENT,
};
SeekMode(Value _value) : value(_value) {}
SeekMode(uint32 _value) : value(_value) {}
operator Value() { return (Value)value; }
uint32 value;
};
} // ~namespace FS
} // ~namespace Lumix

View file

@ -1,7 +1,7 @@
#pragma once
#include "lumix.h"
#include "core/fs/ifile_system_defines.h"
#include "core/fs/file_system.h"
namespace Lumix
{

View file

@ -36,8 +36,7 @@ bool OsFile::open(const char* path, Mode mode, IAllocator& allocator)
Mode::WRITE & mode ? GENERIC_WRITE : 0 | Mode::READ & mode ? GENERIC_READ : 0,
Mode::WRITE & mode ? 0 : FILE_SHARE_READ,
nullptr,
Mode::OPEN_OR_CREATE & mode ? OPEN_ALWAYS
: (Mode::CREATE & mode ? CREATE_ALWAYS : OPEN_EXISTING),
Mode::CREATE & mode ? CREATE_ALWAYS : OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
nullptr);

View file

@ -780,7 +780,7 @@ Engine* Engine::create(const char* base_path0,
Profiler::setThreadName("Main");
installUnhandledExceptionHandler();
g_is_error_file_opened = g_error_file.open("error.log", FS::Mode::CREATE | FS::Mode::WRITE, allocator);
g_is_error_file_opened = g_error_file.open("error.log", FS::Mode::CREATE_AND_WRITE, allocator);
g_log_error.getCallback().bind<logErrorToFile>();
g_log_info.getCallback().bind<showLogInVS>();

View file

@ -1691,7 +1691,7 @@ namespace Lumix
auto& fs = m_app.getWorldEditor()->getEngine().getFileSystem();
auto* file = fs.open(fs.getDiskDevice(),
resource->getPath(),
Lumix::FS::Mode::CREATE | Lumix::FS::Mode::WRITE);
Lumix::FS::Mode::CREATE_AND_WRITE);
if (!file)
{

View file

@ -428,7 +428,7 @@ struct NavigationScene : public IScene
if (!m_navmesh) return false;
FS::OsFile file;
if (!file.open(path, FS::Mode::CREATE | FS::Mode::WRITE, m_allocator)) return false;
if (!file.open(path, FS::Mode::CREATE_AND_WRITE, m_allocator)) return false;
file.write(&m_aabb, sizeof(m_aabb));
file.write(&m_num_tiles_x, sizeof(m_num_tiles_x));

View file

@ -2,13 +2,17 @@
#include "core/FS/ifile.h"
#include "core/blob.h"
#include "core/crc32.h"
#include "debug/debug.h"
#include "core/fs/disk_file_device.h"
#include "core/fs/file_system.h"
#include "core/fs/memory_file_device.h"
#include "core/fs/pack_file_device.h"
#include "core/log.h"
#include "core/mt/thread.h"
#include "core/path_utils.h"
#include "core/profiler.h"
#include "core/resource_manager.h"
#include "core/resource_manager_base.h"
#include "debug/debug.h"
#include "editor/gizmo.h"
#include "editor/world_editor.h"
#include "engine/engine.h"
@ -120,7 +124,19 @@ public:
Lumix::enableCrashReporting(false);
m_engine = Lumix::Engine::create("", "", NULL, m_allocator);
m_file_system = Lumix::FS::FileSystem::create(m_allocator);
m_mem_file_device = LUMIX_NEW(m_allocator, Lumix::FS::MemoryFileDevice)(m_allocator);
m_disk_file_device = LUMIX_NEW(m_allocator, Lumix::FS::DiskFileDevice)("", "", m_allocator);
m_pack_file_device = LUMIX_NEW(m_allocator, Lumix::FS::PackFileDevice)(m_allocator);
m_file_system->mount(m_mem_file_device);
m_file_system->mount(m_disk_file_device);
m_file_system->mount(m_pack_file_device);
m_file_system->setDefaultDevice("memory:disk");
m_file_system->setSaveGameDevice("memory:disk");
m_engine = Lumix::Engine::create("", "", nullptr, m_allocator);
Lumix::Engine::PlatformData platform_data;
platform_data.window_handle = hwnd;
m_engine->setPlatformData(platform_data);
@ -148,6 +164,10 @@ public:
void shutdown()
{
m_engine->destroyUniverse(*m_universe);
Lumix::FS::FileSystem::destroy(m_file_system);
LUMIX_DELETE(m_allocator, m_disk_file_device);
LUMIX_DELETE(m_allocator, m_mem_file_device);
LUMIX_DELETE(m_allocator, m_pack_file_device);
Lumix::Pipeline::destroy(m_pipeline);
Lumix::Engine::destroy(m_engine, m_allocator);
m_engine = nullptr;
@ -345,6 +365,10 @@ private:
Lumix::Universe* m_universe;
Lumix::Pipeline* m_pipeline;
Lumix::Array<Test> m_tests;
Lumix::FS::FileSystem* m_file_system;
Lumix::FS::MemoryFileDevice* m_mem_file_device;
Lumix::FS::DiskFileDevice* m_disk_file_device;
Lumix::FS::PackFileDevice* m_pack_file_device;
int m_current_test;
bool m_is_test_universe_loaded;
bool m_finished;

View file

@ -65,7 +65,7 @@ struct MaterialPlugin : public AssetBrowser::IPlugin
strcat(tmp_path, ".tmp");
FS::IFile* file = fs.open(fs.getDefaultDevice(),
Path(tmp_path),
FS::Mode::CREATE | FS::Mode::WRITE);
FS::Mode::CREATE_AND_WRITE);
if (file)
{
DefaultAllocator allocator;
@ -1297,7 +1297,7 @@ struct MeshMergerPlugin : public StudioApp::IPlugin
FS::OsFile file;
if (!file.open(
output, FS::Mode::WRITE | FS::Mode::CREATE, app.getWorldEditor()->getAllocator()))
output, FS::Mode::CREATE_AND_WRITE, app.getWorldEditor()->getAllocator()))
{
g_log_error.log("Renderer") << "Failed to save \"" << output << "\"";
return;

View file

@ -1481,7 +1481,7 @@ void ShaderEditor::generate(const char* path, ShaderType shader_type)
}
Lumix::FS::OsFile file;
if(!file.open(sc_path, Lumix::FS::Mode::WRITE | Lumix::FS::Mode::CREATE, m_allocator))
if(!file.open(sc_path, Lumix::FS::Mode::CREATE_AND_WRITE, m_allocator))
{
Lumix::g_log_error.log("Editor") << "Could not create file " << sc_path;
return;

View file

@ -560,7 +560,7 @@ struct RendererImpl : public Renderer
header.dataType = 2;
Lumix::FS::OsFile file;
if(!file.open(filePath, Lumix::FS::Mode::CREATE | Lumix::FS::Mode::WRITE, m_renderer.m_allocator))
if(!file.open(filePath, Lumix::FS::Mode::CREATE_AND_WRITE, m_renderer.m_allocator))
{
g_log_error.log("Renderer") << "Failed to save screenshot to " << filePath;
return;

View file

@ -280,7 +280,7 @@ void Texture::saveTGA()
FS::FileSystem& fs = m_resource_manager.getFileSystem();
FS::IFile* file = fs.open(fs.getDiskDevice(),
getPath(),
FS::Mode::OPEN_OR_CREATE | FS::Mode::WRITE);
FS::Mode::CREATE_AND_WRITE);
saveTGA(m_allocator, file, m_width, m_height, m_BPP, &m_data[0], getPath());
@ -298,7 +298,7 @@ void Texture::save()
FS::FileSystem& fs = m_resource_manager.getFileSystem();
FS::IFile* file = fs.open(fs.getDefaultDevice(),
getPath(),
FS::Mode::OPEN_OR_CREATE | FS::Mode::WRITE);
FS::Mode::CREATE_AND_WRITE);
file->write(&m_data[0], m_data.size() * sizeof(m_data[0]));
fs.close(*file);

View file

@ -99,7 +99,7 @@ void UT_file_events_device(const char* params)
file = file_system->open(device_list,
Lumix::Path("unit_tests/file_system/selenitic2.xml"),
Lumix::FS::Mode::OPEN_OR_CREATE | Lumix::FS::Mode::WRITE);
Lumix::FS::Mode::CREATE_AND_WRITE);
LUMIX_EXPECT(file != nullptr);