mirror of https://github.com/stella-emu/stella.git
Switch to using size_t for all file access.
Note that we'll never actually need this, but I got tired of constantly casting all over the place.
This commit is contained in:
parent
234ebb5373
commit
a06c44d7a6
|
@ -180,7 +180,7 @@ bool FilesystemNodeZIP::getChildren(AbstractFSList& myList, ListMode mode) const
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
uInt32 FilesystemNodeZIP::read(ByteBuffer& image) const
|
||||
size_t FilesystemNodeZIP::read(ByteBuffer& image) const
|
||||
{
|
||||
switch(_error)
|
||||
{
|
||||
|
|
|
@ -67,7 +67,7 @@ class FilesystemNodeZIP : public AbstractFSNode
|
|||
bool getChildren(AbstractFSList& list, ListMode mode) const override;
|
||||
AbstractFSNodePtr getParent() const override;
|
||||
|
||||
uInt32 read(ByteBuffer& image) const override;
|
||||
size_t read(ByteBuffer& image) const override;
|
||||
|
||||
private:
|
||||
FilesystemNodeZIP(const string& zipfile, const string& virtualpath,
|
||||
|
|
|
@ -214,9 +214,9 @@ bool FilesystemNode::rename(const string& newfile)
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
uInt32 FilesystemNode::read(ByteBuffer& image) const
|
||||
size_t FilesystemNode::read(ByteBuffer& image) const
|
||||
{
|
||||
uInt32 size = 0;
|
||||
size_t size = 0;
|
||||
|
||||
// File must actually exist
|
||||
if (!(exists() && isReadable()))
|
||||
|
@ -238,7 +238,7 @@ uInt32 FilesystemNode::read(ByteBuffer& image) const
|
|||
if (length == 0)
|
||||
throw runtime_error("Zero-byte file");
|
||||
|
||||
size = std::min<uInt32>(length, 512 * 1024);
|
||||
size = std::min<size_t>(length, 512 * 1024);
|
||||
in.read(reinterpret_cast<char*>(image.get()), size);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -238,7 +238,7 @@ class FilesystemNode
|
|||
* This method can throw exceptions, and should be used inside
|
||||
* a try-catch block.
|
||||
*/
|
||||
uInt32 read(ByteBuffer& buffer) const;
|
||||
size_t read(ByteBuffer& buffer) const;
|
||||
|
||||
/**
|
||||
* The following methods are almost exactly the same as the various
|
||||
|
@ -398,7 +398,7 @@ class AbstractFSNode
|
|||
* This method can throw exceptions, and should be used inside
|
||||
* a try-catch block.
|
||||
*/
|
||||
virtual uInt32 read(ByteBuffer& buffer) const { return 0; }
|
||||
virtual size_t read(ByteBuffer& buffer) const { return 0; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -307,20 +307,21 @@ static void Decode(uInt32* output, const uInt8* input, uInt32 len)
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
string hash(const ByteBuffer& buffer, uInt32 length)
|
||||
string hash(const ByteBuffer& buffer, size_t length)
|
||||
{
|
||||
return hash(buffer.get(), length);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
string hash(const uInt8* buffer, uInt32 length)
|
||||
string hash(const uInt8* buffer, size_t length)
|
||||
{
|
||||
char hex[] = "0123456789abcdef";
|
||||
MD5_CTX context;
|
||||
uInt8 md5[16];
|
||||
uInt32 len32 = static_cast<uInt32>(length); // Always use 32-bit for now
|
||||
|
||||
MD5Init(&context);
|
||||
MD5Update(&context, buffer, length);
|
||||
MD5Update(&context, buffer, len32);
|
||||
MD5Final(md5, &context);
|
||||
|
||||
string result;
|
||||
|
@ -337,7 +338,7 @@ string hash(const uInt8* buffer, uInt32 length)
|
|||
string hash(const FilesystemNode& node)
|
||||
{
|
||||
ByteBuffer image;
|
||||
uInt32 size = 0;
|
||||
size_t size = 0;
|
||||
try
|
||||
{
|
||||
size = node.read(image);
|
||||
|
|
|
@ -28,12 +28,17 @@ namespace MD5 {
|
|||
Get the MD5 Message-Digest of the specified message with the
|
||||
given length. The digest consists of 32 hexadecimal digits.
|
||||
|
||||
Note that currently, the length is truncated internally to
|
||||
32 bits, until the MD5 routines are rewritten for 64-bit.
|
||||
Based on the size of data we currently use, this may never
|
||||
actually happen.
|
||||
|
||||
@param buffer The message to compute the digest of
|
||||
@param length The length of the message
|
||||
@return The message-digest
|
||||
*/
|
||||
string hash(const ByteBuffer& buffer, uInt32 length);
|
||||
string hash(const uInt8* buffer, uInt32 length);
|
||||
string hash(const ByteBuffer& buffer, size_t length);
|
||||
string hash(const uInt8* buffer, size_t length);
|
||||
|
||||
/**
|
||||
Get the MD5 Message-Digest of the file contained in 'node'.
|
||||
|
|
|
@ -515,7 +515,7 @@ unique_ptr<Console> OSystem::openConsole(const FilesystemNode& romfile, string&
|
|||
|
||||
// Open the cartridge image and read it in
|
||||
ByteBuffer image;
|
||||
uInt32 size = 0;
|
||||
size_t size = 0;
|
||||
if((image = openROM(romfile, md5, size)) != nullptr)
|
||||
{
|
||||
// Get a valid set of properties, including any entered on the commandline
|
||||
|
@ -598,7 +598,7 @@ void OSystem::closeConsole()
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
ByteBuffer OSystem::openROM(const FilesystemNode& rom, string& md5, uInt32& size)
|
||||
ByteBuffer OSystem::openROM(const FilesystemNode& rom, string& md5, size_t& size)
|
||||
{
|
||||
// This method has a documented side-effect:
|
||||
// It not only loads a ROM and creates an array with its contents,
|
||||
|
|
|
@ -306,7 +306,7 @@ class OSystem
|
|||
|
||||
@return Unique pointer to the array
|
||||
*/
|
||||
ByteBuffer openROM(const FilesystemNode& rom, string& md5, uInt32& size);
|
||||
ByteBuffer openROM(const FilesystemNode& rom, string& md5, size_t& size);
|
||||
|
||||
/**
|
||||
Creates a new game console from the specified romfile, and correctly
|
||||
|
|
|
@ -102,7 +102,7 @@ bool ProfilingRunner::runOne(const ProfilingRun& run)
|
|||
}
|
||||
|
||||
ByteBuffer image;
|
||||
uInt32 size = imageFile.read(image);
|
||||
size_t size = imageFile.read(image);
|
||||
if (size == 0) {
|
||||
cout << "ERROR: unable to read " << run.romFile << endl;
|
||||
return false;
|
||||
|
|
|
@ -399,7 +399,7 @@ void GameInfoDialog::loadEmulationProperties(const Properties& props)
|
|||
const FilesystemNode& node = FilesystemNode(instance().launcher().selectedRom());
|
||||
ByteBuffer image;
|
||||
string md5 = props.get(PropType::Cart_MD5);
|
||||
uInt32 size = 0;
|
||||
size_t size = 0;
|
||||
|
||||
// try to load the image for auto detection
|
||||
if(!instance().hasConsole() &&
|
||||
|
@ -635,7 +635,7 @@ void GameInfoDialog::updateControllerStates()
|
|||
bool autoDetect = false;
|
||||
ByteBuffer image;
|
||||
string md5 = myGameProperties.get(PropType::Cart_MD5);
|
||||
uInt32 size = 0;
|
||||
size_t size = 0;
|
||||
|
||||
// try to load the image for auto detection
|
||||
if(!instance().hasConsole())
|
||||
|
|
|
@ -145,7 +145,7 @@ void RomInfoWidget::parseProperties(const FilesystemNode& node)
|
|||
{
|
||||
ByteBuffer image;
|
||||
string md5 = myProperties.get(PropType::Cart_MD5);
|
||||
uInt32 size = 0;
|
||||
size_t size = 0;
|
||||
|
||||
if(node.exists() && !node.isDirectory() &&
|
||||
(image = instance().openROM(node, md5, size)) != nullptr)
|
||||
|
|
|
@ -508,7 +508,7 @@ void StellaSettingsDialog::updateControllerStates()
|
|||
bool autoDetect = false;
|
||||
ByteBuffer image;
|
||||
string md5 = myGameProperties.get(PropType::Cart_MD5);
|
||||
uInt32 size = 0;
|
||||
size_t size = 0;
|
||||
|
||||
// try to load the image for auto detection
|
||||
if(!instance().hasConsole())
|
||||
|
|
Loading…
Reference in New Issue