From a71962a5a80918b070f5c43d932e907f17fa1482 Mon Sep 17 00:00:00 2001 From: disarray2077 <86157825+disarray2077@users.noreply.github.com> Date: Sun, 1 Aug 2021 17:30:40 -0300 Subject: [PATCH] Fix File OpenOrCreate --- BeefLibs/corlib/src/IO/FileStream.bf | 4 ++-- BeefLibs/corlib/src/Platform.bf | 1 + BeefySysLib/platform/PlatformInterface.h | 1 + BeefySysLib/platform/posix/PosixCommon.cpp | 4 ++++ BeefySysLib/platform/win/Platform.cpp | 6 +++++- IDE/mintest/minlib/src/System/Platform.bf | 1 + 6 files changed, 14 insertions(+), 3 deletions(-) diff --git a/BeefLibs/corlib/src/IO/FileStream.bf b/BeefLibs/corlib/src/IO/FileStream.bf index 36b5daa0..3359f561 100644 --- a/BeefLibs/corlib/src/IO/FileStream.bf +++ b/BeefLibs/corlib/src/IO/FileStream.bf @@ -178,7 +178,7 @@ namespace System.IO case .Open: createKind = .OpenExisting; case .OpenOrCreate: - createKind = .CreateAlways; + createKind = .OpenAlways; case .Truncate: createKind = .CreateAlways; createFlags |= .Truncate; @@ -337,7 +337,7 @@ namespace System.IO case .Open: createKind = .OpenExisting; case .OpenOrCreate: - createKind = .CreateAlways; + createKind = .OpenAlways; case .Truncate: createKind = .CreateAlways; createFlags |= .Truncate; diff --git a/BeefLibs/corlib/src/Platform.bf b/BeefLibs/corlib/src/Platform.bf index 8e518186..068c0dc0 100644 --- a/BeefLibs/corlib/src/Platform.bf +++ b/BeefLibs/corlib/src/Platform.bf @@ -271,6 +271,7 @@ namespace System CreateAlways, CreateIfNotExists, OpenExisting, + OpenAlways, }; public enum BfpFileCreateFlags : int32 diff --git a/BeefySysLib/platform/PlatformInterface.h b/BeefySysLib/platform/PlatformInterface.h index aa6fc380..c8434563 100644 --- a/BeefySysLib/platform/PlatformInterface.h +++ b/BeefySysLib/platform/PlatformInterface.h @@ -344,6 +344,7 @@ enum BfpFileCreateKind BfpFileCreateKind_CreateAlways, BfpFileCreateKind_CreateIfNotExists, BfpFileCreateKind_OpenExisting, + BfpFileCreateKind_OpenAlways }; enum BfpFileCreateFlags diff --git a/BeefySysLib/platform/posix/PosixCommon.cpp b/BeefySysLib/platform/posix/PosixCommon.cpp index 4fa4c52b..910703e4 100644 --- a/BeefySysLib/platform/posix/PosixCommon.cpp +++ b/BeefySysLib/platform/posix/PosixCommon.cpp @@ -1858,6 +1858,10 @@ BFP_EXPORT BfpFile* BFP_CALLTYPE BfpFile_Create(const char* inName, BfpFileCreat } return result; }; + + // POSIX doesn't need the OpenAlways kind. + if (createKind == BfpFileCreateKind_OpenAlways) + createKind = BfpFileCreateKind_CreateAlways; BfpFile* bfpFile = NULL; diff --git a/BeefySysLib/platform/win/Platform.cpp b/BeefySysLib/platform/win/Platform.cpp index 81aebe2c..de943727 100644 --- a/BeefySysLib/platform/win/Platform.cpp +++ b/BeefySysLib/platform/win/Platform.cpp @@ -2741,9 +2741,13 @@ BFP_EXPORT BfpFile* BFP_CALLTYPE BfpFile_Create(const char* path, BfpFileCreateK creationDisposition = CREATE_ALWAYS; } else if (createKind == BfpFileCreateKind_CreateIfNotExists) - { + { creationDisposition = CREATE_NEW; } + else if (createKind == BfpFileCreateKind_OpenAlways) + { + creationDisposition = OPEN_ALWAYS; + } else { creationDisposition = OPEN_EXISTING; diff --git a/IDE/mintest/minlib/src/System/Platform.bf b/IDE/mintest/minlib/src/System/Platform.bf index c4259103..217ff2a7 100644 --- a/IDE/mintest/minlib/src/System/Platform.bf +++ b/IDE/mintest/minlib/src/System/Platform.bf @@ -234,6 +234,7 @@ namespace System CreateAlways, CreateIfNotExists, OpenExisting, + OpenAlways, }; public enum BfpFileCreateFlags : int32