From 56b218a7505d11b72dec1d5b36e948f77950331a Mon Sep 17 00:00:00 2001 From: JosJuice Date: Fri, 19 May 2017 18:18:43 +0200 Subject: [PATCH 1/2] DiscIO: Simplify volume creation Basically inlining GetDiscType into CreateVolumeFromFilename. --- Source/Core/DiscIO/VolumeCreator.cpp | 75 ++++++++-------------------- 1 file changed, 21 insertions(+), 54 deletions(-) diff --git a/Source/Core/DiscIO/VolumeCreator.cpp b/Source/Core/DiscIO/VolumeCreator.cpp index 4b2c23aea9..63046bce95 100644 --- a/Source/Core/DiscIO/VolumeCreator.cpp +++ b/Source/Core/DiscIO/VolumeCreator.cpp @@ -22,39 +22,37 @@ namespace DiscIO { -enum EDiscType -{ - DISC_TYPE_UNK, - DISC_TYPE_WII, - DISC_TYPE_WII_CONTAINER, - DISC_TYPE_GC, - DISC_TYPE_WAD -}; - -EDiscType GetDiscType(IBlobReader& _rReader); - std::unique_ptr CreateVolumeFromFilename(const std::string& filename) { std::unique_ptr reader(CreateBlobReader(filename)); if (reader == nullptr) return nullptr; + CBlobBigEndianReader be_reader(*reader); - switch (GetDiscType(*reader)) - { - case DISC_TYPE_WII: - case DISC_TYPE_GC: + // Check for Wii + u32 wii_magic = 0; + be_reader.ReadSwapped(0x18, &wii_magic); + u32 wii_container_magic = 0; + be_reader.ReadSwapped(0x60, &wii_container_magic); + if (wii_magic == 0x5D1C9EA3 && wii_container_magic != 0) return std::make_unique(std::move(reader)); - - case DISC_TYPE_WAD: - return std::make_unique(std::move(reader)); - - case DISC_TYPE_WII_CONTAINER: + if (wii_magic == 0x5D1C9EA3 && wii_container_magic == 0) return std::make_unique(std::move(reader)); - case DISC_TYPE_UNK: - return nullptr; - } + // Check for WAD + // 0x206962 for boot2 wads + u32 wad_magic = 0; + be_reader.ReadSwapped(0x02, &wad_magic); + if (wad_magic == 0x00204973 || wad_magic == 0x00206962) + return std::make_unique(std::move(reader)); + // Check for GC + u32 gc_magic = 0; + be_reader.ReadSwapped(0x1C, &gc_magic); + if (gc_magic == 0xC2339F3D) + return std::make_unique(std::move(reader)); + + // No known magic words found return nullptr; } @@ -68,35 +66,4 @@ std::unique_ptr CreateVolumeFromDirectory(const std::string& directory, return nullptr; } -EDiscType GetDiscType(IBlobReader& _rReader) -{ - CBlobBigEndianReader Reader(_rReader); - - // Check for Wii - u32 WiiMagic = 0; - Reader.ReadSwapped(0x18, &WiiMagic); - u32 WiiContainerMagic = 0; - Reader.ReadSwapped(0x60, &WiiContainerMagic); - if (WiiMagic == 0x5D1C9EA3 && WiiContainerMagic != 0) - return DISC_TYPE_WII; - if (WiiMagic == 0x5D1C9EA3 && WiiContainerMagic == 0) - return DISC_TYPE_WII_CONTAINER; - - // Check for WAD - // 0x206962 for boot2 wads - u32 WADMagic = 0; - Reader.ReadSwapped(0x02, &WADMagic); - if (WADMagic == 0x00204973 || WADMagic == 0x00206962) - return DISC_TYPE_WAD; - - // Check for GC - u32 GCMagic = 0; - Reader.ReadSwapped(0x1C, &GCMagic); - if (GCMagic == 0xC2339F3D) - return DISC_TYPE_GC; - - // No known magic words found - return DISC_TYPE_UNK; -} - } // namespace From ac5c82b36b4fc2bf99e9f7552ac83febeff8fc5c Mon Sep 17 00:00:00 2001 From: JosJuice Date: Fri, 19 May 2017 18:33:21 +0200 Subject: [PATCH 2/2] DiscIO: Remove VolumeCreator This file is pretty small now that it doesn't handle Wii partitions anymore, so let's move its contents to Volume.cpp. This is also more consistent with how blob creation works. --- Source/Android/jni/MainAndroid.cpp | 1 - Source/Core/Core/Boot/Boot.cpp | 1 - Source/Core/Core/ConfigManager.cpp | 1 - Source/Core/Core/HW/DVD/DVDInterface.cpp | 1 - Source/Core/DiscIO/CMakeLists.txt | 1 - Source/Core/DiscIO/DiscIO.vcxproj | 2 - Source/Core/DiscIO/DiscIO.vcxproj.filters | 6 -- Source/Core/DiscIO/DiscScrubber.cpp | 1 - Source/Core/DiscIO/Volume.cpp | 51 ++++++++++++++ Source/Core/DiscIO/Volume.h | 6 ++ Source/Core/DiscIO/VolumeCreator.cpp | 69 ------------------- Source/Core/DiscIO/VolumeCreator.h | 19 ----- Source/Core/DiscIO/VolumeWiiCrypted.cpp | 1 - Source/Core/DolphinQt2/GameList/GameFile.cpp | 1 - Source/Core/DolphinWX/FrameTools.cpp | 1 - Source/Core/DolphinWX/GameListCtrl.cpp | 1 - Source/Core/DolphinWX/ISOFile.cpp | 1 - .../ISOProperties/FilesystemPanel.cpp | 1 - .../DolphinWX/ISOProperties/ISOProperties.cpp | 1 - 19 files changed, 57 insertions(+), 109 deletions(-) delete mode 100644 Source/Core/DiscIO/VolumeCreator.cpp delete mode 100644 Source/Core/DiscIO/VolumeCreator.h diff --git a/Source/Android/jni/MainAndroid.cpp b/Source/Android/jni/MainAndroid.cpp index e18214e21b..a1a21f0b36 100644 --- a/Source/Android/jni/MainAndroid.cpp +++ b/Source/Android/jni/MainAndroid.cpp @@ -37,7 +37,6 @@ #include "DiscIO/Enums.h" #include "DiscIO/Volume.h" -#include "DiscIO/VolumeCreator.h" #include "UICommon/UICommon.h" diff --git a/Source/Core/Core/Boot/Boot.cpp b/Source/Core/Core/Boot/Boot.cpp index 35bad4333c..b4d96afeaf 100644 --- a/Source/Core/Core/Boot/Boot.cpp +++ b/Source/Core/Core/Boot/Boot.cpp @@ -37,7 +37,6 @@ #include "DiscIO/Enums.h" #include "DiscIO/NANDContentLoader.h" #include "DiscIO/Volume.h" -#include "DiscIO/VolumeCreator.h" // Inserts a disc into the emulated disc drive and returns a pointer to it. // The returned pointer must only be used while we are still booting, diff --git a/Source/Core/Core/ConfigManager.cpp b/Source/Core/Core/ConfigManager.cpp index bacb70b658..205e72cc2f 100644 --- a/Source/Core/Core/ConfigManager.cpp +++ b/Source/Core/Core/ConfigManager.cpp @@ -36,7 +36,6 @@ #include "DiscIO/Enums.h" #include "DiscIO/NANDContentLoader.h" #include "DiscIO/Volume.h" -#include "DiscIO/VolumeCreator.h" SConfig* SConfig::m_Instance; diff --git a/Source/Core/Core/HW/DVD/DVDInterface.cpp b/Source/Core/Core/HW/DVD/DVDInterface.cpp index 774cd710ce..0e9f31992f 100644 --- a/Source/Core/Core/HW/DVD/DVDInterface.cpp +++ b/Source/Core/Core/HW/DVD/DVDInterface.cpp @@ -32,7 +32,6 @@ #include "DiscIO/Enums.h" #include "DiscIO/Volume.h" -#include "DiscIO/VolumeCreator.h" #include "DiscIO/VolumeWiiCrypted.h" // The minimum time it takes for the DVD drive to process a command (in diff --git a/Source/Core/DiscIO/CMakeLists.txt b/Source/Core/DiscIO/CMakeLists.txt index cd3fee7f1d..414cd6a542 100644 --- a/Source/Core/DiscIO/CMakeLists.txt +++ b/Source/Core/DiscIO/CMakeLists.txt @@ -13,7 +13,6 @@ set(SRCS NANDImporter.cpp TGCBlob.cpp Volume.cpp - VolumeCreator.cpp VolumeDirectory.cpp VolumeGC.cpp VolumeWad.cpp diff --git a/Source/Core/DiscIO/DiscIO.vcxproj b/Source/Core/DiscIO/DiscIO.vcxproj index 4846c963ef..f11d3c3e1d 100644 --- a/Source/Core/DiscIO/DiscIO.vcxproj +++ b/Source/Core/DiscIO/DiscIO.vcxproj @@ -48,7 +48,6 @@ - @@ -70,7 +69,6 @@ - diff --git a/Source/Core/DiscIO/DiscIO.vcxproj.filters b/Source/Core/DiscIO/DiscIO.vcxproj.filters index ca6ec54fa7..b56078e599 100644 --- a/Source/Core/DiscIO/DiscIO.vcxproj.filters +++ b/Source/Core/DiscIO/DiscIO.vcxproj.filters @@ -54,9 +54,6 @@ Volume\Blob - - Volume - Volume @@ -119,9 +116,6 @@ Volume - - Volume - Volume diff --git a/Source/Core/DiscIO/DiscScrubber.cpp b/Source/Core/DiscIO/DiscScrubber.cpp index ac3a39f4c6..332ea7c8c4 100644 --- a/Source/Core/DiscIO/DiscScrubber.cpp +++ b/Source/Core/DiscIO/DiscScrubber.cpp @@ -16,7 +16,6 @@ #include "DiscIO/DiscScrubber.h" #include "DiscIO/Filesystem.h" #include "DiscIO/Volume.h" -#include "DiscIO/VolumeCreator.h" namespace DiscIO { diff --git a/Source/Core/DiscIO/Volume.cpp b/Source/Core/DiscIO/Volume.cpp index ade2bd1eab..21fece4484 100644 --- a/Source/Core/DiscIO/Volume.cpp +++ b/Source/Core/DiscIO/Volume.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -17,7 +18,12 @@ #include "Common/StringUtil.h" #include "Common/Swap.h" +#include "DiscIO/Blob.h" #include "DiscIO/Enums.h" +#include "DiscIO/VolumeDirectory.h" +#include "DiscIO/VolumeGC.h" +#include "DiscIO/VolumeWad.h" +#include "DiscIO/VolumeWiiCrypted.h" namespace DiscIO { @@ -76,4 +82,49 @@ std::map IVolume::ReadWiiNames(const std::vector& dat } return names; } + +std::unique_ptr CreateVolumeFromFilename(const std::string& filename) +{ + std::unique_ptr reader(CreateBlobReader(filename)); + if (reader == nullptr) + return nullptr; + CBlobBigEndianReader be_reader(*reader); + + // Check for Wii + u32 wii_magic = 0; + be_reader.ReadSwapped(0x18, &wii_magic); + u32 wii_container_magic = 0; + be_reader.ReadSwapped(0x60, &wii_container_magic); + if (wii_magic == 0x5D1C9EA3 && wii_container_magic != 0) + return std::make_unique(std::move(reader)); + if (wii_magic == 0x5D1C9EA3 && wii_container_magic == 0) + return std::make_unique(std::move(reader)); + + // Check for WAD + // 0x206962 for boot2 wads + u32 wad_magic = 0; + be_reader.ReadSwapped(0x02, &wad_magic); + if (wad_magic == 0x00204973 || wad_magic == 0x00206962) + return std::make_unique(std::move(reader)); + + // Check for GC + u32 gc_magic = 0; + be_reader.ReadSwapped(0x1C, &gc_magic); + if (gc_magic == 0xC2339F3D) + return std::make_unique(std::move(reader)); + + // No known magic words found + return nullptr; } + +std::unique_ptr CreateVolumeFromDirectory(const std::string& directory, bool is_wii, + const std::string& apploader, + const std::string& dol) +{ + if (CVolumeDirectory::IsValidDirectory(directory)) + return std::make_unique(directory, is_wii, apploader, dol); + + return nullptr; +} + +} // namespace diff --git a/Source/Core/DiscIO/Volume.h b/Source/Core/DiscIO/Volume.h index d03e168709..1d98d69c46 100644 --- a/Source/Core/DiscIO/Volume.h +++ b/Source/Core/DiscIO/Volume.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -112,4 +113,9 @@ protected: static const size_t NAMES_TOTAL_BYTES = NAME_BYTES_LENGTH * NUMBER_OF_LANGUAGES; }; +std::unique_ptr CreateVolumeFromFilename(const std::string& filename); +std::unique_ptr CreateVolumeFromDirectory(const std::string& directory, bool is_wii, + const std::string& apploader = "", + const std::string& dol = ""); + } // namespace diff --git a/Source/Core/DiscIO/VolumeCreator.cpp b/Source/Core/DiscIO/VolumeCreator.cpp deleted file mode 100644 index 63046bce95..0000000000 --- a/Source/Core/DiscIO/VolumeCreator.cpp +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2008 Dolphin Emulator Project -// Licensed under GPLv2+ -// Refer to the license.txt file included. - -#include -#include -#include -#include -#include -#include - -#include "Common/CommonTypes.h" -#include "Common/Logging/Log.h" -#include "Common/StringUtil.h" -#include "DiscIO/Blob.h" -#include "DiscIO/Volume.h" -#include "DiscIO/VolumeCreator.h" -#include "DiscIO/VolumeDirectory.h" -#include "DiscIO/VolumeGC.h" -#include "DiscIO/VolumeWad.h" -#include "DiscIO/VolumeWiiCrypted.h" - -namespace DiscIO -{ -std::unique_ptr CreateVolumeFromFilename(const std::string& filename) -{ - std::unique_ptr reader(CreateBlobReader(filename)); - if (reader == nullptr) - return nullptr; - CBlobBigEndianReader be_reader(*reader); - - // Check for Wii - u32 wii_magic = 0; - be_reader.ReadSwapped(0x18, &wii_magic); - u32 wii_container_magic = 0; - be_reader.ReadSwapped(0x60, &wii_container_magic); - if (wii_magic == 0x5D1C9EA3 && wii_container_magic != 0) - return std::make_unique(std::move(reader)); - if (wii_magic == 0x5D1C9EA3 && wii_container_magic == 0) - return std::make_unique(std::move(reader)); - - // Check for WAD - // 0x206962 for boot2 wads - u32 wad_magic = 0; - be_reader.ReadSwapped(0x02, &wad_magic); - if (wad_magic == 0x00204973 || wad_magic == 0x00206962) - return std::make_unique(std::move(reader)); - - // Check for GC - u32 gc_magic = 0; - be_reader.ReadSwapped(0x1C, &gc_magic); - if (gc_magic == 0xC2339F3D) - return std::make_unique(std::move(reader)); - - // No known magic words found - return nullptr; -} - -std::unique_ptr CreateVolumeFromDirectory(const std::string& directory, bool is_wii, - const std::string& apploader, - const std::string& dol) -{ - if (CVolumeDirectory::IsValidDirectory(directory)) - return std::make_unique(directory, is_wii, apploader, dol); - - return nullptr; -} - -} // namespace diff --git a/Source/Core/DiscIO/VolumeCreator.h b/Source/Core/DiscIO/VolumeCreator.h deleted file mode 100644 index 79c08cf1db..0000000000 --- a/Source/Core/DiscIO/VolumeCreator.h +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2008 Dolphin Emulator Project -// Licensed under GPLv2+ -// Refer to the license.txt file included. - -#pragma once - -#include -#include - -namespace DiscIO -{ -class IVolume; - -std::unique_ptr CreateVolumeFromFilename(const std::string& filename); -std::unique_ptr CreateVolumeFromDirectory(const std::string& directory, bool is_wii, - const std::string& apploader = "", - const std::string& dol = ""); - -} // namespace diff --git a/Source/Core/DiscIO/VolumeWiiCrypted.cpp b/Source/Core/DiscIO/VolumeWiiCrypted.cpp index 05d34aa126..1572c8493b 100644 --- a/Source/Core/DiscIO/VolumeWiiCrypted.cpp +++ b/Source/Core/DiscIO/VolumeWiiCrypted.cpp @@ -25,7 +25,6 @@ #include "DiscIO/Enums.h" #include "DiscIO/Filesystem.h" #include "DiscIO/Volume.h" -#include "DiscIO/VolumeCreator.h" namespace DiscIO { diff --git a/Source/Core/DolphinQt2/GameList/GameFile.cpp b/Source/Core/DolphinQt2/GameList/GameFile.cpp index f3a644934d..2edb1105ad 100644 --- a/Source/Core/DolphinQt2/GameList/GameFile.cpp +++ b/Source/Core/DolphinQt2/GameList/GameFile.cpp @@ -19,7 +19,6 @@ #include "DiscIO/Enums.h" #include "DiscIO/NANDContentLoader.h" #include "DiscIO/Volume.h" -#include "DiscIO/VolumeCreator.h" #include "DolphinQt2/GameList/GameFile.h" #include "DolphinQt2/Resources.h" #include "DolphinQt2/Settings.h" diff --git a/Source/Core/DolphinWX/FrameTools.cpp b/Source/Core/DolphinWX/FrameTools.cpp index 6b2fab39cb..c294efefbd 100644 --- a/Source/Core/DolphinWX/FrameTools.cpp +++ b/Source/Core/DolphinWX/FrameTools.cpp @@ -54,7 +54,6 @@ #include "DiscIO/NANDContentLoader.h" #include "DiscIO/NANDImporter.h" -#include "DiscIO/VolumeCreator.h" #include "DiscIO/VolumeWad.h" #include "DolphinWX/AboutDolphin.h" diff --git a/Source/Core/DolphinWX/GameListCtrl.cpp b/Source/Core/DolphinWX/GameListCtrl.cpp index e6e3758439..eb6d065324 100644 --- a/Source/Core/DolphinWX/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/GameListCtrl.cpp @@ -53,7 +53,6 @@ #include "DiscIO/Blob.h" #include "DiscIO/Enums.h" #include "DiscIO/Volume.h" -#include "DiscIO/VolumeCreator.h" #include "DolphinWX/Frame.h" #include "DolphinWX/GameListCtrl.h" #include "DolphinWX/Globals.h" diff --git a/Source/Core/DolphinWX/ISOFile.cpp b/Source/Core/DolphinWX/ISOFile.cpp index e45f8b3fbf..0169d67d98 100644 --- a/Source/Core/DolphinWX/ISOFile.cpp +++ b/Source/Core/DolphinWX/ISOFile.cpp @@ -33,7 +33,6 @@ #include "DiscIO/Blob.h" #include "DiscIO/Enums.h" #include "DiscIO/Volume.h" -#include "DiscIO/VolumeCreator.h" #include "DolphinWX/ISOFile.h" #include "DolphinWX/WxUtils.h" diff --git a/Source/Core/DolphinWX/ISOProperties/FilesystemPanel.cpp b/Source/Core/DolphinWX/ISOProperties/FilesystemPanel.cpp index e6d94f8a6d..b7f9a3fed1 100644 --- a/Source/Core/DolphinWX/ISOProperties/FilesystemPanel.cpp +++ b/Source/Core/DolphinWX/ISOProperties/FilesystemPanel.cpp @@ -24,7 +24,6 @@ #include "DiscIO/Enums.h" #include "DiscIO/Filesystem.h" #include "DiscIO/Volume.h" -#include "DiscIO/VolumeCreator.h" #include "DolphinWX/ISOFile.h" #include "DolphinWX/WxUtils.h" diff --git a/Source/Core/DolphinWX/ISOProperties/ISOProperties.cpp b/Source/Core/DolphinWX/ISOProperties/ISOProperties.cpp index ee71292aaf..b05baa7250 100644 --- a/Source/Core/DolphinWX/ISOProperties/ISOProperties.cpp +++ b/Source/Core/DolphinWX/ISOProperties/ISOProperties.cpp @@ -46,7 +46,6 @@ #include "DiscIO/Blob.h" #include "DiscIO/Enums.h" #include "DiscIO/Volume.h" -#include "DiscIO/VolumeCreator.h" #include "DolphinWX/Cheats/ActionReplayCodesPanel.h" #include "DolphinWX/Cheats/GeckoCodeDiag.h" #include "DolphinWX/Config/ConfigMain.h"