1
0
mirror of https://github.com/Halofreak1990/XFXFramework synced 2024-12-26 13:49:34 +01:00

Removed BeginRead and BeginWrite from Stream class; finally got it to compile :)

Now, there's only fixing cross-references and getting the namespace include headers sorted out. (Tech demo won't compile otherwise)
This commit is contained in:
Halofreak1990 2010-12-28 01:12:19 +00:00
parent 1c277b2038
commit 95f3ff3ab6
12 changed files with 152 additions and 174 deletions

View File

@ -4,8 +4,8 @@
* XFX Directory class definition file *
* Copyright © XFX Team. All Rights Reserved *
********************************************************/
#ifndef _IO_DIRECTORY_
#define _IO_DIRECTORY_
#ifndef _SYSTEM_IO_DIRECTORY_
#define _SYSTEM_IO_DIRECTORY_
#include "../Types.h"
@ -48,4 +48,4 @@ namespace System
}
}
#endif //_IO_DIRECTORY_
#endif //_SYSTEM_IO_DIRECTORY_

View File

@ -32,13 +32,13 @@ namespace System
DirectoryInfo Parent();
DirectoryInfo Root();
DirectoryInfo(const char* path, bool junk);
DirectoryInfo(const char* path); // Initializes a new instance of the System::IO::DirectoryInfo class on the specified path.
void Create();
DirectoryInfo CreateSubDirectory(const char* path);
void Delete();
void Delete(bool recursive);
DirectoryInfo* GetDirectories();
void Create(); // Creates a directory.
DirectoryInfo CreateSubDirectory(const char* path); // Creates a subdirectory or subdirectories on the specified path. The specified path can be relative to this instance of the System::IO::DirectoryInfo class.
void Delete(); // Deletes this System::IO::DirectoryInfo if it is empty.
void Delete(bool recursive); // Deletes this instance of a System::IO::DirectoryInfo, specifying whether to delete subdirectories and files.
DirectoryInfo* GetDirectories(); //
DirectoryInfo* GetDirectories(const char* searchPattern);
FileSystemInfo* GetFileSystemInfos();
FileSystemInfo* GetFileSystemInfos(const char* searchPattern);

View File

@ -7,6 +7,10 @@ namespace System
{
class FileSystemInfo
{
protected:
char* FullPath;
char* OriginalPath;
public:
virtual char* FullName();
};

View File

@ -43,12 +43,8 @@ namespace System
int WriteTimeOut;
static const Stream Null;
virtual IAsyncResult* BeginRead(byte buffer[], int offset, int count, ASyncCallback callback, Object* state);
virtual IAsyncResult* BeginWrite(byte buffer[], int offset, int count, ASyncCallback callback, Object* state);
virtual void Close();
void Dispose();
virtual int EndRead(IAsyncResult* asyncResult);
virtual void EndWrite(IAsyncResult* asyncResult);
virtual void Flush();
virtual int Read(byte buffer[], int offset, int count);
virtual int ReadByte();

View File

@ -8,7 +8,7 @@
#define _SYSTEM_STRING_
#include "Enums.h"
#include <System/Types.h>
#include "Types.h"
namespace System
{
@ -50,6 +50,7 @@ namespace System
int IndexOf(char value, int startIndex);
int IndexOf(char value, int startIndex, int count);
static bool IsNullOrEmpty(String value);
static bool IsNullOrEmpty(char* value);
static String Join(String &separator, String value[]);
static String Join(String &separator, String value[], int startIndex, int count);
String PadLeft(int totalWidth);
@ -65,7 +66,7 @@ namespace System
char** Split(char separator[], int count);
char** Split(char separator[]);
bool StartsWith(char* value);
String SubString(int startIndex);
static char* SubString(int startIndex);
String SubString(int startIndex, int length);
char *ToCharArray(int startIndex, int length);
char *ToCharArray();
@ -74,6 +75,7 @@ namespace System
String ToUpper();
bool operator!=(const String right);
bool operator!=(const char* right);
bool operator==(const String right);
bool operator==(const char* right);
String operator=(const char* right);

View File

@ -1,3 +1,30 @@
// Copyright (C) 2010-2012, Halofreak_1990
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the copyright holder nor the names of any
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#include <System/DateTime.h>
#include <System/IO/Directory.h>
#include <System/IO/DirectoryInfo.h>
@ -6,10 +33,7 @@
#include <string.h>
#if ENABLE_XBOX
#include <hal/fileio.h>
#else
#endif
namespace System
{
@ -23,10 +47,9 @@ namespace System
if (File::Exists(path))
throw IOException(strcat((char*)"Cannot create ", strcat(path,(char*)" because a file with the same name already exists.")));
#if ENABLE_XBOX
XCreateDirectory(path);
#else
#endif
return DirectoryInfo(path);
}
void Directory::Delete(char* path)
@ -36,9 +59,7 @@ namespace System
void Directory::Delete(char* path, bool recursive)
{
#if ENABLE_XBOX
#else
#endif
}
bool Directory::Exists(char* path)

View File

@ -0,0 +1,84 @@
// Copyright (C) 2010-2012, Halofreak_1990
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the copyright holder nor the names of any
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#include <System/IO/Directory.h>
#include <System/IO/DirectoryInfo.h>
#include <System/IO/IOException.h>
#include <System/String.h>
namespace System
{
namespace IO
{
DirectoryInfo::DirectoryInfo(const char* path)
{
if (path == null)
throw ArgumentNullException("path");
if ((String::Length() == 2) && (path[1] == ':'))
{
OriginalPath = ".";
}
else
{
OriginalPath = path;
}
}
void DirectoryInfo::Create()
{
}
DirectoryInfo DirectoryInfo::CreateSubDirectory(const char* path)
{
}
void DirectoryInfo::Delete()
{
Directory::Delete(FullPath, false);
}
void DirectoryInfo::Delete(bool recursive)
{
Directory::Delete(FullPath, recursive);
}
DirectoryInfo* DirectoryInfo::GetDirectories()
{
return GetDirectories("*");
}
DirectoryInfo* DirectoryInfo::GetDirectories(const char* searchPattern)
{
if (searchPattern = null)
throw ArgumentNullException("searchPattern");
}
}
}

View File

@ -33,8 +33,7 @@
#include <System/IO/StreamReader.h>
#include <System/IO/StreamWriter.h>
#include <hal/fileio.h>
extern void *malloc(unsigned int size);
#include <xboxkrnl/xboxkrnl.h>
namespace System
{
@ -72,16 +71,16 @@ namespace System
int sourceHandle;
int destHandle;
UInt32 length;
byte *buffer;
void *buffer;
ret = XCreateFile(&sourceHandle, sourceFileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL);
if(ret == 0)
{
XGetFileSize(sourceHandle, &length);
buffer = (byte*)malloc((int)length);
XReadFile(sourceHandle, (void*)buffer, length, NULL);
buffer = MmAllocateContiguousMemory((int)length);
XReadFile(sourceHandle, buffer, length, NULL);
XCloseHandle(sourceHandle);
XCreateFile(&destHandle, destFileName, GENERIC_WRITE, FILE_SHARE_WRITE, CREATE_NEW, FILE_ATTRIBUTE_NORMAL);
XWriteFile(destHandle, (void*)buffer, length, NULL);
XWriteFile(destHandle, buffer, length, NULL);
XCloseHandle(destHandle);
}
}
@ -114,7 +113,7 @@ namespace System
bool File::Exists(char* path)
{
bool flag;
bool flag = false;
try
{
if(path == null)
@ -124,7 +123,7 @@ namespace System
return false;
path = Path::GetFullPath(path);
PXBOX_FIND_DATA data;
PXBOX_FIND_DATA data = null;
flag = ((FileAttributeInfo(path, data, false, false) == 0) && (data->dwFileAttributes != -1) && ((data->dwFileAttributes & 0x10) == 0));
}
catch(ArgumentException)
@ -175,6 +174,7 @@ namespace System
char* dst = Path::GetFullPath(destFileName);
//! TODO: Move the file
// I suspect MoveFile is simply copying the file, and then removing the source file.
}
FileStream File::Open(char* path, FileMode_t mode)

View File

@ -28,12 +28,10 @@
#include <System/IO/FileStream.h>
#include <System/IO/IOException.h>
#if ENABLE_XBOX
extern "C" {
extern "C"
{
#include <hal/fileio.h>
}
#else
#endif
namespace System
{
@ -63,11 +61,9 @@ namespace System
throw NotSupportedException("The stream does not support seeking.");
Int64 length;
#if ENABLE_XBOX
if(XGetFileSize(handle, (unsigned int *)length) != STATUS_SUCCESS)
throw IOException("Could not determine file size. The file may be corrupt.");
#else
#endif
if ((_writePos > 0) && ((_pos + _writePos) > length))
{
length = _writePos + _pos;
@ -108,10 +104,8 @@ namespace System
throw ArgumentNullException("path", "path was either NULL or an empty string.");
_access = (mode == FileMode::Append ? FileAccess::Write : FileAccess::ReadWrite);
#if ENABLE_XBOX
XCreateFile(&handle, path, _access, FileShare::Read, mode, FILE_ATTRIBUTE_NORMAL);
#else
#endif
}
FileStream::FileStream(char* path, FileMode_t mode, FileAccess_t access)
@ -120,10 +114,8 @@ namespace System
throw ArgumentNullException("path", "path was either NULL, or an empty string.");
_access = access;
#if ENABLE_XBOX
XCreateFile(&handle, path, access, FILE_SHARE_READ | FILE_SHARE_WRITE, mode, FILE_ATTRIBUTE_NORMAL);
#else
#endif
}
FileStream::FileStream(char* path, FileMode_t mode, FileAccess_t access, FileShare_t share)
@ -131,10 +123,7 @@ namespace System
if(path == null || path == "")
throw ArgumentNullException("path", "path was either NULL, or an empty string.");
#if ENABLE_XBOX
XCreateFile(&handle, path, access, share, mode, FILE_ATTRIBUTE_NORMAL);
#else
#endif
}
FileStream::FileStream(char* path, FileMode_t mode, FileAccess_t access, FileShare_t share, int bufferSize)
@ -147,18 +136,7 @@ namespace System
if (bufferSize <= 0)
throw ArgumentOutOfRangeException("bufferSize", "Positive number required.");
#if ENABLE_XBOX
isAsync = useAsync;
if(isAsync)
{
}
else
{
XCreateFile(&handle, path, access, share, mode, FILE_ATTRIBUTE_NORMAL);
}
#else
#endif
XCreateFile(&handle, path, access, share, mode, FILE_ATTRIBUTE_NORMAL);
}
FileStream::~FileStream()
@ -204,18 +182,7 @@ namespace System
void FileStream::FlushWrite(bool calledFromFinalizer)
{
if (isAsync)
{
IAsyncResult* asyncResult = BeginWrite(_buffer, 0, _writePos, null, null);
if (!calledFromFinalizer)
{
EndWrite(asyncResult);
}
}
else
{
Write(_buffer, 0, _writePos);
}
Write(_buffer, 0, _writePos);
_writePos = 0;
}
@ -241,18 +208,9 @@ namespace System
if (offset > len - count)
throw ArgumentException("Reading would overrun buffer");
if(isAsync)
{
IAsyncResult* ares = BeginRead(array, offset, count, null, null);
return EndRead(ares);
}
#if ENABLE_XBOX
UInt32 bytesRead;
XReadFile(handle, &array[offset], count, &bytesRead);
return bytesRead;
#else
#endif
}
int FileStream::ReadByte()
@ -272,7 +230,6 @@ namespace System
if(handle == -1)
throw ObjectDisposedException("FileStream", "The stream has been closed.");
#if ENABLE_XBOX
FILE_POSITION_INFORMATION positionInfo;
LARGE_INTEGER targetPointer;
IO_STATUS_BLOCK ioStatusBlock;
@ -311,8 +268,6 @@ namespace System
{
return targetPointer.QuadPart;
}
#else
#endif
}
void FileStream::SetLength(long long value)
@ -328,34 +283,18 @@ namespace System
Flush();
//
if (Position() > value)
Position(value);
}
void FileStream::Write(byte array[], int offset, int count)
{
if(isAsync)
{
IAsyncResult* asyncResult = BeginWrite(array, offset, count, null, null);
EndWrite(asyncResult);
}
else
{
#if ENABLE_XBOX
XWriteFile(handle, &array[offset], count, null);
#else
#endif
}
}
void FileStream::WriteByte(byte value)
{
#if ENABLE_XBOX
XWriteFile(handle, (void*)value, 1, null);
#else
#endif
}
}
}

View File

@ -35,11 +35,8 @@ namespace System
{
namespace IO
{
#if ENABLE_XBOX // The XBOX Limits us to 64MB; we do not take XDKs into account
// The XBOX Limits us to 64MB; we do not take XDK/Debug units into account
const int MemoryStream::MemStreamMaxLength = 0x40000000;
#else
const int MemoryStream::MemStreamMaxLength = 0x7fffffff;
#endif
bool MemoryStream::CanRead()
{
@ -132,6 +129,7 @@ namespace System
}
_buffer = buffer;
_length = _capacity = Array::Length(buffer);
_expandable = false;
_writable = true;
_exposable = false;
_origin = 0;

View File

@ -43,46 +43,6 @@ namespace System
return false;
}
IAsyncResult* Stream::BeginRead(byte buffer[], int offset, int count, ASyncCallback callback, Object* state)
{
if(!CanRead())
throw NotSupportedException("This stream does not support reading");
StreamAsyncResult result = StreamAsyncResult(state);
try
{
int nbytes = Read(buffer, offset, count);
result.SetComplete(null, nbytes);
}
catch (Exception e)
{
result.SetComplete(&e, 0);
}
return result;
}
IAsyncResult* Stream::BeginWrite(byte buffer[], int offset, int count, ASyncCallback callback, Object* state)
{
if(!CanWrite())
throw NotSupportedException("This stream does not support writing");
StreamAsyncResult result = StreamAsyncResult(state);
try
{
Write (buffer, offset, count);
result.SetComplete(null);
}
catch (Exception e)
{
result.SetComplete(&e);
}
callback(result);
return result;
}
void Stream::Close()
{
Dispose(true);
@ -93,36 +53,6 @@ namespace System
Close();
}
int Stream::EndRead(IAsyncResult* asyncResult)
{
StreamAsyncResult result = (StreamAsyncResult)asyncResult;
if (result.NBytes() == -1)
throw ArgumentException("Invalid IAsyncResult", "asyncResult");
if (result.Done)
throw InvalidOperationException("EndRead already called.");
result.Done = true;
if (result.Exception_() != null)
throw result.Exception_();
return result.NBytes();
}
void Stream::EndWrite(IAsyncResult* asyncResult)
{
StreamAsyncResult result = (StreamAsyncResult)asyncResult;
if (result.NBytes() != -1)
throw ArgumentException("Invalid IAsyncResult", "asyncResult");
if (result.Done)
throw InvalidOperationException("EndWrite already called.");
result.Done = true;
if (result.Exception_() != null)
throw result.Exception_();
}
int Stream::ReadByte()
{
byte* buffer = new byte[1];

View File

@ -191,6 +191,10 @@
RelativePath=".\Directory.cpp"
>
</File>
<File
RelativePath=".\DirectoryInfo.cpp"
>
</File>
<File
RelativePath=".\File.cpp"
>