mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-25 07:09:48 -06:00
Merge pull request #8902 from JosJuice/android-convert
Android: Add disc image conversion
This commit is contained in:
@ -164,6 +164,11 @@ elseif(WIN32)
|
||||
if (_M_X86_64)
|
||||
target_link_libraries(common PRIVATE opengl32.lib)
|
||||
endif()
|
||||
elseif (ANDROID)
|
||||
target_link_libraries(common
|
||||
PRIVATE
|
||||
androidcommon
|
||||
)
|
||||
endif()
|
||||
|
||||
if(ANDROID)
|
||||
|
@ -15,6 +15,13 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef ANDROID
|
||||
#include <algorithm>
|
||||
|
||||
#include "Common/StringUtil.h"
|
||||
#include "jni/AndroidCommon/AndroidCommon.h"
|
||||
#endif
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/File.h"
|
||||
#include "Common/FileUtil.h"
|
||||
@ -62,7 +69,21 @@ bool IOFile::Open(const std::string& filename, const char openmode[])
|
||||
#ifdef _WIN32
|
||||
m_good = _tfopen_s(&m_file, UTF8ToTStr(filename).c_str(), UTF8ToTStr(openmode).c_str()) == 0;
|
||||
#else
|
||||
m_file = std::fopen(filename.c_str(), openmode);
|
||||
#ifdef ANDROID
|
||||
if (StringBeginsWith(filename, "content://"))
|
||||
{
|
||||
// The Java method which OpenAndroidContent passes the mode to does not support the b specifier.
|
||||
// Since we're on POSIX, it's fine to just remove the b.
|
||||
std::string mode_without_b(openmode);
|
||||
mode_without_b.erase(std::remove(mode_without_b.begin(), mode_without_b.end(), 'b'),
|
||||
mode_without_b.end());
|
||||
m_file = fdopen(OpenAndroidContent(filename, mode_without_b), mode_without_b.c_str());
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
m_file = std::fopen(filename.c_str(), openmode);
|
||||
}
|
||||
m_good = m_file != nullptr;
|
||||
#endif
|
||||
|
||||
|
@ -46,6 +46,11 @@
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#ifdef ANDROID
|
||||
#include "Common/StringUtil.h"
|
||||
#include "jni/AndroidCommon/AndroidCommon.h"
|
||||
#endif
|
||||
|
||||
#ifndef S_ISDIR
|
||||
#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR)
|
||||
#endif
|
||||
@ -132,10 +137,19 @@ bool Delete(const std::string& filename)
|
||||
{
|
||||
INFO_LOG(COMMON, "Delete: file %s", filename.c_str());
|
||||
|
||||
#ifdef ANDROID
|
||||
if (StringBeginsWith(filename, "content://"))
|
||||
{
|
||||
const bool success = DeleteAndroidContent(filename);
|
||||
if (!success)
|
||||
WARN_LOG(COMMON, "Delete failed on %s", filename.c_str());
|
||||
return success;
|
||||
}
|
||||
#endif
|
||||
|
||||
const FileInfo file_info(filename);
|
||||
|
||||
// Return true because we care about the file no
|
||||
// being there, not the actual delete.
|
||||
// Return true because we care about the file not being there, not the actual delete.
|
||||
if (!file_info.Exists())
|
||||
{
|
||||
WARN_LOG(COMMON, "Delete: %s does not exist", filename.c_str());
|
||||
|
@ -15,6 +15,7 @@
|
||||
// automatically do the right thing.
|
||||
|
||||
#include <array>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
@ -175,17 +176,16 @@ private:
|
||||
// Factory function - examines the path to choose the right type of BlobReader, and returns one.
|
||||
std::unique_ptr<BlobReader> CreateBlobReader(const std::string& filename);
|
||||
|
||||
typedef bool (*CompressCB)(const std::string& text, float percent, void* arg);
|
||||
using CompressCB = std::function<bool(const std::string& text, float percent)>;
|
||||
|
||||
bool ConvertToGCZ(BlobReader* infile, const std::string& infile_path,
|
||||
const std::string& outfile_path, u32 sub_type, int sector_size = 16384,
|
||||
CompressCB callback = nullptr, void* arg = nullptr);
|
||||
const std::string& outfile_path, u32 sub_type, int sector_size,
|
||||
CompressCB callback);
|
||||
bool ConvertToPlain(BlobReader* infile, const std::string& infile_path,
|
||||
const std::string& outfile_path, CompressCB callback = nullptr,
|
||||
void* arg = nullptr);
|
||||
const std::string& outfile_path, CompressCB callback);
|
||||
bool ConvertToWIAOrRVZ(BlobReader* infile, const std::string& infile_path,
|
||||
const std::string& outfile_path, bool rvz,
|
||||
WIARVZCompressionType compression_type, int compression_level,
|
||||
int chunk_size, CompressCB callback = nullptr, void* arg = nullptr);
|
||||
int chunk_size, CompressCB callback);
|
||||
|
||||
} // namespace DiscIO
|
||||
|
@ -238,7 +238,7 @@ static ConversionResult<OutputParameters> Compress(CompressThreadState* state,
|
||||
|
||||
static ConversionResultCode Output(OutputParameters parameters, File::IOFile* outfile,
|
||||
u64* position, std::vector<u64>* offsets, int progress_monitor,
|
||||
u32 num_blocks, CompressCB callback, void* arg)
|
||||
u32 num_blocks, CompressCB callback)
|
||||
{
|
||||
u64 offset = *position;
|
||||
if (!parameters.compressed)
|
||||
@ -261,7 +261,7 @@ static ConversionResultCode Output(OutputParameters parameters, File::IOFile* ou
|
||||
|
||||
const float completion = static_cast<float>(parameters.block_number) / num_blocks;
|
||||
|
||||
if (!callback(text, completion, arg))
|
||||
if (!callback(text, completion))
|
||||
return ConversionResultCode::Canceled;
|
||||
}
|
||||
|
||||
@ -270,7 +270,7 @@ static ConversionResultCode Output(OutputParameters parameters, File::IOFile* ou
|
||||
|
||||
bool ConvertToGCZ(BlobReader* infile, const std::string& infile_path,
|
||||
const std::string& outfile_path, u32 sub_type, int block_size,
|
||||
CompressCB callback, void* arg)
|
||||
CompressCB callback)
|
||||
{
|
||||
ASSERT(infile->IsDataSizeAccurate());
|
||||
|
||||
@ -284,7 +284,7 @@ bool ConvertToGCZ(BlobReader* infile, const std::string& infile_path,
|
||||
return false;
|
||||
}
|
||||
|
||||
callback(Common::GetStringT("Files opened, ready to compress."), 0, arg);
|
||||
callback(Common::GetStringT("Files opened, ready to compress."), 0);
|
||||
|
||||
CompressedBlobHeader header;
|
||||
header.magic_cookie = GCZ_MAGIC;
|
||||
@ -317,7 +317,7 @@ bool ConvertToGCZ(BlobReader* infile, const std::string& infile_path,
|
||||
|
||||
const auto output = [&](OutputParameters parameters) {
|
||||
return Output(std::move(parameters), &outfile, &position, &offsets, progress_monitor,
|
||||
header.num_blocks, callback, arg);
|
||||
header.num_blocks, callback);
|
||||
};
|
||||
|
||||
MultithreadedCompressor<CompressThreadState, CompressParameters, OutputParameters> compressor(
|
||||
@ -364,7 +364,7 @@ bool ConvertToGCZ(BlobReader* infile, const std::string& infile_path,
|
||||
outfile.WriteArray(offsets.data(), header.num_blocks);
|
||||
outfile.WriteArray(hashes.data(), header.num_blocks);
|
||||
|
||||
callback(Common::GetStringT("Done compressing disc image."), 1.0f, arg);
|
||||
callback(Common::GetStringT("Done compressing disc image."), 1.0f);
|
||||
}
|
||||
|
||||
if (result == ConversionResultCode::ReadFailed)
|
||||
|
@ -42,7 +42,7 @@ bool PlainFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr)
|
||||
}
|
||||
|
||||
bool ConvertToPlain(BlobReader* infile, const std::string& infile_path,
|
||||
const std::string& outfile_path, CompressCB callback, void* arg)
|
||||
const std::string& outfile_path, CompressCB callback)
|
||||
{
|
||||
ASSERT(infile->IsDataSizeAccurate());
|
||||
|
||||
@ -78,7 +78,7 @@ bool ConvertToPlain(BlobReader* infile, const std::string& infile_path,
|
||||
if (i % progress_monitor == 0)
|
||||
{
|
||||
const bool was_cancelled =
|
||||
!callback(Common::GetStringT("Unpacking"), (float)i / (float)num_buffers, arg);
|
||||
!callback(Common::GetStringT("Unpacking"), (float)i / (float)num_buffers);
|
||||
if (was_cancelled)
|
||||
{
|
||||
success = false;
|
||||
|
@ -1686,9 +1686,9 @@ ConversionResultCode WIARVZFileReader<RVZ>::Output(std::vector<OutputParametersE
|
||||
}
|
||||
|
||||
template <bool RVZ>
|
||||
ConversionResultCode
|
||||
WIARVZFileReader<RVZ>::RunCallback(size_t groups_written, u64 bytes_read, u64 bytes_written,
|
||||
u32 total_groups, u64 iso_size, CompressCB callback, void* arg)
|
||||
ConversionResultCode WIARVZFileReader<RVZ>::RunCallback(size_t groups_written, u64 bytes_read,
|
||||
u64 bytes_written, u32 total_groups,
|
||||
u64 iso_size, CompressCB callback)
|
||||
{
|
||||
int ratio = 0;
|
||||
if (bytes_read != 0)
|
||||
@ -1700,8 +1700,8 @@ WIARVZFileReader<RVZ>::RunCallback(size_t groups_written, u64 bytes_read, u64 by
|
||||
|
||||
const float completion = static_cast<float>(bytes_read) / iso_size;
|
||||
|
||||
return callback(text, completion, arg) ? ConversionResultCode::Success :
|
||||
ConversionResultCode::Canceled;
|
||||
return callback(text, completion) ? ConversionResultCode::Success :
|
||||
ConversionResultCode::Canceled;
|
||||
}
|
||||
|
||||
template <bool RVZ>
|
||||
@ -1729,8 +1729,7 @@ template <bool RVZ>
|
||||
ConversionResultCode
|
||||
WIARVZFileReader<RVZ>::Convert(BlobReader* infile, const VolumeDisc* infile_volume,
|
||||
File::IOFile* outfile, WIARVZCompressionType compression_type,
|
||||
int compression_level, int chunk_size, CompressCB callback,
|
||||
void* arg)
|
||||
int compression_level, int chunk_size, CompressCB callback)
|
||||
{
|
||||
ASSERT(infile->IsDataSizeAccurate());
|
||||
ASSERT(chunk_size > 0);
|
||||
@ -1832,7 +1831,7 @@ WIARVZFileReader<RVZ>::Convert(BlobReader* infile, const VolumeDisc* infile_volu
|
||||
return result;
|
||||
|
||||
return RunCallback(parameters.group_index + parameters.entries.size(), parameters.bytes_read,
|
||||
bytes_written, total_groups, iso_size, callback, arg);
|
||||
bytes_written, total_groups, iso_size, callback);
|
||||
};
|
||||
|
||||
MultithreadedCompressor<CompressThreadState, CompressParameters, OutputParameters> mt_compressor(
|
||||
@ -2030,7 +2029,7 @@ WIARVZFileReader<RVZ>::Convert(BlobReader* infile, const VolumeDisc* infile_volu
|
||||
bool ConvertToWIAOrRVZ(BlobReader* infile, const std::string& infile_path,
|
||||
const std::string& outfile_path, bool rvz,
|
||||
WIARVZCompressionType compression_type, int compression_level,
|
||||
int chunk_size, CompressCB callback, void* arg)
|
||||
int chunk_size, CompressCB callback)
|
||||
{
|
||||
File::IOFile outfile(outfile_path, "wb");
|
||||
if (!outfile)
|
||||
@ -2047,7 +2046,7 @@ bool ConvertToWIAOrRVZ(BlobReader* infile, const std::string& infile_path,
|
||||
const auto convert = rvz ? RVZFileReader::Convert : WIAFileReader::Convert;
|
||||
const ConversionResultCode result =
|
||||
convert(infile, infile_volume.get(), &outfile, compression_type, compression_level,
|
||||
chunk_size, callback, arg);
|
||||
chunk_size, callback);
|
||||
|
||||
if (result == ConversionResultCode::ReadFailed)
|
||||
PanicAlertT("Failed to read from the input file \"%s\".", infile_path.c_str());
|
||||
|
@ -64,8 +64,7 @@ public:
|
||||
|
||||
static ConversionResultCode Convert(BlobReader* infile, const VolumeDisc* infile_volume,
|
||||
File::IOFile* outfile, WIARVZCompressionType compression_type,
|
||||
int compression_level, int chunk_size, CompressCB callback,
|
||||
void* arg);
|
||||
int compression_level, int chunk_size, CompressCB callback);
|
||||
|
||||
private:
|
||||
using SHA1 = std::array<u8, 20>;
|
||||
@ -351,8 +350,7 @@ private:
|
||||
std::mutex* reusable_groups_mutex, GroupEntry* group_entry,
|
||||
u64* bytes_written);
|
||||
static ConversionResultCode RunCallback(size_t groups_written, u64 bytes_read, u64 bytes_written,
|
||||
u32 total_groups, u64 iso_size, CompressCB callback,
|
||||
void* arg);
|
||||
u32 total_groups, u64 iso_size, CompressCB callback);
|
||||
|
||||
bool m_valid;
|
||||
WIARVZCompressionType m_compression_type;
|
||||
|
@ -32,17 +32,6 @@
|
||||
#include "UICommon/GameFile.h"
|
||||
#include "UICommon/UICommon.h"
|
||||
|
||||
static bool CompressCB(const std::string& text, float percent, void* ptr)
|
||||
{
|
||||
if (ptr == nullptr)
|
||||
return false;
|
||||
|
||||
auto* progress_dialog = static_cast<ParallelProgressDialog*>(ptr);
|
||||
|
||||
progress_dialog->SetValue(percent * 100);
|
||||
return !progress_dialog->WasCanceled();
|
||||
}
|
||||
|
||||
ConvertDialog::ConvertDialog(QList<std::shared_ptr<const UICommon::GameFile>> files,
|
||||
QWidget* parent)
|
||||
: QDialog(parent), m_files(std::move(files))
|
||||
@ -463,15 +452,19 @@ void ConvertDialog::Convert()
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto callback = [&progress_dialog](const std::string& text, float percent) {
|
||||
progress_dialog.SetValue(percent * 100);
|
||||
return !progress_dialog.WasCanceled();
|
||||
};
|
||||
|
||||
std::future<bool> success;
|
||||
|
||||
switch (format)
|
||||
{
|
||||
case DiscIO::BlobType::PLAIN:
|
||||
success = std::async(std::launch::async, [&] {
|
||||
const bool good =
|
||||
DiscIO::ConvertToPlain(blob_reader.get(), original_path, dst_path.toStdString(),
|
||||
&CompressCB, &progress_dialog);
|
||||
const bool good = DiscIO::ConvertToPlain(blob_reader.get(), original_path,
|
||||
dst_path.toStdString(), callback);
|
||||
progress_dialog.Reset();
|
||||
return good;
|
||||
});
|
||||
@ -479,10 +472,9 @@ void ConvertDialog::Convert()
|
||||
|
||||
case DiscIO::BlobType::GCZ:
|
||||
success = std::async(std::launch::async, [&] {
|
||||
const bool good =
|
||||
DiscIO::ConvertToGCZ(blob_reader.get(), original_path, dst_path.toStdString(),
|
||||
file->GetPlatform() == DiscIO::Platform::WiiDisc ? 1 : 0,
|
||||
block_size, &CompressCB, &progress_dialog);
|
||||
const bool good = DiscIO::ConvertToGCZ(
|
||||
blob_reader.get(), original_path, dst_path.toStdString(),
|
||||
file->GetPlatform() == DiscIO::Platform::WiiDisc ? 1 : 0, block_size, callback);
|
||||
progress_dialog.Reset();
|
||||
return good;
|
||||
});
|
||||
@ -491,10 +483,10 @@ void ConvertDialog::Convert()
|
||||
case DiscIO::BlobType::WIA:
|
||||
case DiscIO::BlobType::RVZ:
|
||||
success = std::async(std::launch::async, [&] {
|
||||
const bool good = DiscIO::ConvertToWIAOrRVZ(
|
||||
blob_reader.get(), original_path, dst_path.toStdString(),
|
||||
format == DiscIO::BlobType::RVZ, compression, compression_level, block_size,
|
||||
&CompressCB, &progress_dialog);
|
||||
const bool good =
|
||||
DiscIO::ConvertToWIAOrRVZ(blob_reader.get(), original_path, dst_path.toStdString(),
|
||||
format == DiscIO::BlobType::RVZ, compression,
|
||||
compression_level, block_size, callback);
|
||||
progress_dialog.Reset();
|
||||
return good;
|
||||
});
|
||||
|
@ -267,9 +267,8 @@ void GameList::ShowContextMenu(const QPoint&)
|
||||
{
|
||||
const auto selected_games = GetSelectedGames();
|
||||
|
||||
if (std::all_of(selected_games.begin(), selected_games.end(), [](const auto& game) {
|
||||
return DiscIO::IsDisc(game->GetPlatform()) && game->IsVolumeSizeAccurate();
|
||||
}))
|
||||
if (std::all_of(selected_games.begin(), selected_games.end(),
|
||||
[](const auto& game) { return game->ShouldAllowConversion(); }))
|
||||
{
|
||||
menu->addAction(tr("Convert Selected Files..."), this, &GameList::ConvertFile);
|
||||
menu->addSeparator();
|
||||
@ -301,7 +300,7 @@ void GameList::ShowContextMenu(const QPoint&)
|
||||
{
|
||||
menu->addAction(tr("Set as &Default ISO"), this, &GameList::SetDefaultISO);
|
||||
|
||||
if (game->IsVolumeSizeAccurate())
|
||||
if (game->ShouldAllowConversion())
|
||||
menu->addAction(tr("Convert File..."), this, &GameList::ConvertFile);
|
||||
|
||||
QAction* change_disc = menu->addAction(tr("Change &Disc"), this, &GameList::ChangeDisc);
|
||||
|
@ -672,6 +672,11 @@ std::string GameFile::GetFileFormatName() const
|
||||
}
|
||||
}
|
||||
|
||||
bool GameFile::ShouldAllowConversion() const
|
||||
{
|
||||
return DiscIO::IsDisc(m_platform) && m_volume_size_is_accurate;
|
||||
}
|
||||
|
||||
const GameBanner& GameFile::GetBannerImage() const
|
||||
{
|
||||
return m_custom_banner.empty() ? m_volume_banner : m_custom_banner;
|
||||
|
@ -101,6 +101,7 @@ public:
|
||||
const std::string& GetCompressionMethod() const { return m_compression_method; }
|
||||
bool ShouldShowFileFormatDetails() const;
|
||||
std::string GetFileFormatName() const;
|
||||
bool ShouldAllowConversion() const;
|
||||
const std::string& GetApploaderDate() const { return m_apploader_date; }
|
||||
u64 GetFileSize() const { return m_file_size; }
|
||||
u64 GetVolumeSize() const { return m_volume_size; }
|
||||
|
Reference in New Issue
Block a user