From cb90e613680195e853fd05f5ef8bbd82fe577682 Mon Sep 17 00:00:00 2001 From: hrydgard Date: Wed, 17 Sep 2008 23:25:35 +0000 Subject: Large blob code cleanup. Compressed ISO ("gcz") support reactivated. Beginnings of raw drive reading code. Deprecate file mapping in an ugly way. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@566 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Common.vcproj | 74 +++++++++++++++++++---------------- Source/Core/Common/Src/Common.h | 7 ++++ Source/Core/Common/Src/DriveUtil.cpp | 57 +++++++++++++++++++++++++++ Source/Core/Common/Src/DriveUtil.h | 28 +++++++++++++ Source/Core/Common/Src/FileUtil.h | 2 +- Source/Core/Common/Src/Hash.h | 2 +- Source/Core/Common/Src/MappedFile.cpp | 2 +- Source/Core/Common/Src/MappedFile.h | 2 +- 8 files changed, 137 insertions(+), 37 deletions(-) create mode 100644 Source/Core/Common/Src/DriveUtil.cpp create mode 100644 Source/Core/Common/Src/DriveUtil.h (limited to 'Source/Core/Common') diff --git a/Source/Core/Common/Common.vcproj b/Source/Core/Common/Common.vcproj index e8e4545d7f..53f3639aa4 100644 --- a/Source/Core/Common/Common.vcproj +++ b/Source/Core/Common/Common.vcproj @@ -1,7 +1,7 @@ + + + + @@ -597,7 +605,7 @@ /> +#endif + #include "../../../PluginSpecs/CommonTypes.h" #else #include "CommonTypes.h" diff --git a/Source/Core/Common/Src/DriveUtil.cpp b/Source/Core/Common/Src/DriveUtil.cpp new file mode 100644 index 0000000000..2190eb326d --- /dev/null +++ b/Source/Core/Common/Src/DriveUtil.cpp @@ -0,0 +1,57 @@ +// Copyright (C) 2003-2008 Dolphin Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ + +#include "Common.h" + +#ifdef _WIN32 +#include +#include +#endif + +void GetAllRemovableDrives(std::vector *drives) { + drives->clear(); +#ifdef _WIN32 + HANDLE hDisk; + DISK_GEOMETRY diskGeometry; + + for (int i = 'A'; i < 'Z'; i++) + { + char path[MAX_PATH]; + sprintf(path, "\\\\.\\%c:", i); + hDisk = CreateFile(path, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); + if (hDisk != INVALID_HANDLE_VALUE) + { + DWORD dwBytes; + DeviceIoControl(hDisk, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &diskGeometry, sizeof(DISK_GEOMETRY), &dwBytes, NULL); + // Only proceed if disk is a removable media + if (diskGeometry.MediaType == RemovableMedia) + { + if (diskGeometry.BytesPerSector == 2048) { + // Probably CD/DVD drive. + // "Remove" the "\\.\" part of the path and return it. + drives->push_back(path + 4); + } + } + } + CloseHandle(hDisk); + } +#else + // TODO + // stat("/media/cdrom") or whatever etc etc +#endif +} + diff --git a/Source/Core/Common/Src/DriveUtil.h b/Source/Core/Common/Src/DriveUtil.h new file mode 100644 index 0000000000..987d0a937f --- /dev/null +++ b/Source/Core/Common/Src/DriveUtil.h @@ -0,0 +1,28 @@ +// Copyright (C) 2003-2008 Dolphin Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ + +#ifndef _DRIVEUTIL_H +#define _DRIVEUTIL_H + +#include +#include + +// Tools to enumerate drives (HDD, DVD, CD) in a platform-independent manner. + +void GetAllRemovableDrives(std::vector *drives); + +#endif diff --git a/Source/Core/Common/Src/FileUtil.h b/Source/Core/Common/Src/FileUtil.h index e65a43be91..f64d31f6c2 100644 --- a/Source/Core/Common/Src/FileUtil.h +++ b/Source/Core/Common/Src/FileUtil.h @@ -28,7 +28,7 @@ public: static void Explore(const std::string &path); static bool IsDirectory(const std::string &filename); static bool CreateDir(const std::string &filename); - static std::string GetUserDirectory(); + static std::string GetUserDirectory(); }; #endif diff --git a/Source/Core/Common/Src/Hash.h b/Source/Core/Common/Src/Hash.h index 066915cb91..f2e1df42da 100644 --- a/Source/Core/Common/Src/Hash.h +++ b/Source/Core/Common/Src/Hash.h @@ -19,7 +19,7 @@ #include "Common.h" -u32 HashFletcher(const u8* data_u8, size_t length); // FAST +u32 HashFletcher(const u8* data_u8, size_t length); // FAST. Length & 1 == 0. u32 HashAdler32(const u8* data, size_t len); // Fairly accurate, slightly slower u32 HashFNV(const u8* ptr, int length); // Another fast and decent hash u32 HashEctor(const u8* ptr, int length); // JUNK. DO NOT USE FOR NEW THINGS diff --git a/Source/Core/Common/Src/MappedFile.cpp b/Source/Core/Common/Src/MappedFile.cpp index e22e121722..29b86285c0 100644 --- a/Source/Core/Common/Src/MappedFile.cpp +++ b/Source/Core/Common/Src/MappedFile.cpp @@ -226,7 +226,7 @@ void CMappedFile::Unlock(u8* ptr) } -IMappedFile* IMappedFile::CreateMappedFile(void) +IMappedFile* IMappedFile::CreateMappedFileDEPRECATED(void) { return(new CMappedFile); } diff --git a/Source/Core/Common/Src/MappedFile.h b/Source/Core/Common/Src/MappedFile.h index bd359ef7dd..1536672f81 100644 --- a/Source/Core/Common/Src/MappedFile.h +++ b/Source/Core/Common/Src/MappedFile.h @@ -43,7 +43,7 @@ class IMappedFile virtual u8* Lock(u64 _offset, u64 _size) = 0; virtual void Unlock(u8* ptr) = 0; - static IMappedFile* CreateMappedFile(); + static IMappedFile* CreateMappedFileDEPRECATED(); }; } // end of namespace DiscIO -- cgit v1.2.3