From 9ae4a5b8ca7b5e52c883d50512921ecd8ad665dc Mon Sep 17 00:00:00 2001 From: Danilo Date: Fri, 8 Nov 2024 16:07:53 -0300 Subject: [PATCH] =?UTF-8?q?Corre=C3=A7=C3=B5es=20em=20FileStream?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/xna/csharp/stream.hpp | 1 + sources/framework/csharp/stream.cpp | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/includes/xna/csharp/stream.hpp b/includes/xna/csharp/stream.hpp index 00c0733..527a4db 100644 --- a/includes/xna/csharp/stream.hpp +++ b/includes/xna/csharp/stream.hpp @@ -116,6 +116,7 @@ namespace xna { virtual constexpr void Close() override { _closed = true; _buffer = std::vector(); + } virtual int64_t Seek(int64_t offset, SeekOrigin const& origin) override; diff --git a/sources/framework/csharp/stream.cpp b/sources/framework/csharp/stream.cpp index d4d08ce..ac0a9f3 100644 --- a/sources/framework/csharp/stream.cpp +++ b/sources/framework/csharp/stream.cpp @@ -128,14 +128,12 @@ namespace xna { { //Especifica se deve abrir um arquivo existente. case FileMode::Open: - if (!exists) { - _closed = true; - return; - } + if (!exists) + Exception::Throw("The specified file does not exist."); break; //Especifica que se deve abrir um arquivo, se existir; // caso contrário, um novo arquivo deverá ser criado. - case FileMode::OpenOrCreate: + case FileMode::OpenOrCreate: case FileMode::Create: if (!exists) flags |= std::fstream::trunc; @@ -146,7 +144,7 @@ namespace xna { if (!exists) flags |= std::fstream::trunc; else - return; + Exception::Throw("The specified file already exists."); break; //Abre o arquivo, se existir, e busca o final do arquivo ou cria um novo arquivo. case FileMode::Append: @@ -160,6 +158,9 @@ namespace xna { //para que seu tamanho seja zero bytes. //Tentativa de ler um arquivo truncado retornará 0; case FileMode::Truncate: + if(!exists) + Exception::Throw("The specified file does not exist."); + flags |= std::fstream::trunc; _truncated = true; break;