mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
Android: Add a progress dialog for disc image conversion
This commit is contained in:
@ -12,6 +12,7 @@ import android.view.Surface;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import org.dolphinemu.dolphinemu.activities.EmulationActivity;
|
||||
import org.dolphinemu.dolphinemu.utils.CompressCallback;
|
||||
import org.dolphinemu.dolphinemu.utils.Log;
|
||||
import org.dolphinemu.dolphinemu.utils.Rumble;
|
||||
|
||||
@ -430,7 +431,8 @@ public final class NativeLibrary
|
||||
public static native boolean InstallWAD(String file);
|
||||
|
||||
public static native boolean ConvertDiscImage(String inPath, String outPath, int platform,
|
||||
int format, int blockSize, int compression, int compressionLevel, boolean scrub);
|
||||
int format, int blockSize, int compression, int compressionLevel, boolean scrub,
|
||||
CompressCallback callback);
|
||||
|
||||
public static native String FormatSize(long bytes, int decimals);
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.dolphinemu.dolphinemu.fragments;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
@ -108,6 +109,9 @@ public class ConvertFragment extends Fragment implements View.OnClickListener
|
||||
|
||||
private GameFile gameFile;
|
||||
|
||||
private volatile boolean mCanceled;
|
||||
private volatile Thread mThread = null;
|
||||
|
||||
public static ConvertFragment newInstance(String gamePath)
|
||||
{
|
||||
Bundle args = new Bundle();
|
||||
@ -181,6 +185,15 @@ public class ConvertFragment extends Fragment implements View.OnClickListener
|
||||
valueWrapper.setPosition(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
super.onStop();
|
||||
|
||||
mCanceled = true;
|
||||
joinThread();
|
||||
}
|
||||
|
||||
private Spinner populateSpinner(int spinnerId, int entriesId, int valuesId,
|
||||
SpinnerValue valueWrapper)
|
||||
{
|
||||
@ -339,33 +352,88 @@ public class ConvertFragment extends Fragment implements View.OnClickListener
|
||||
|
||||
private void convert()
|
||||
{
|
||||
final int PROGRESS_RESOLUTION = 1000;
|
||||
|
||||
Context context = requireContext();
|
||||
|
||||
// TODO: Let the user select a path
|
||||
String outPath = gameFile.getPath() + ".converted";
|
||||
|
||||
boolean success = NativeLibrary.ConvertDiscImage(gameFile.getPath(), outPath,
|
||||
gameFile.getPlatform(), mFormat.getValue(context), mBlockSize.getValueOr(context,0),
|
||||
mCompression.getValueOr(context,0), mCompressionLevel.getValueOr(context,0),
|
||||
getRemoveJunkData());
|
||||
joinThread();
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.DolphinDialogBase);
|
||||
if (success)
|
||||
mCanceled = false;
|
||||
|
||||
ProgressDialog progressDialog = new ProgressDialog(context, R.style.DolphinDialogBase);
|
||||
|
||||
progressDialog.setTitle(R.string.convert_converting);
|
||||
|
||||
progressDialog.setIndeterminate(false);
|
||||
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
||||
progressDialog.setMax(PROGRESS_RESOLUTION);
|
||||
|
||||
progressDialog.setCancelable(true);
|
||||
progressDialog.setOnCancelListener((dialog) -> mCanceled = true);
|
||||
|
||||
progressDialog.show();
|
||||
|
||||
mThread = new Thread(() ->
|
||||
{
|
||||
builder.setMessage(R.string.convert_success_message)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(R.string.ok, (dialog, i) ->
|
||||
boolean success = NativeLibrary.ConvertDiscImage(gameFile.getPath(), outPath,
|
||||
gameFile.getPlatform(), mFormat.getValue(context), mBlockSize.getValueOr(context, 0),
|
||||
mCompression.getValueOr(context, 0), mCompressionLevel.getValueOr(context, 0),
|
||||
getRemoveJunkData(), (text, completion) ->
|
||||
{
|
||||
dialog.dismiss();
|
||||
requireActivity().finish();
|
||||
requireActivity().runOnUiThread(() ->
|
||||
{
|
||||
progressDialog.setMessage(text);
|
||||
progressDialog.setProgress((int) (completion * PROGRESS_RESOLUTION));
|
||||
});
|
||||
|
||||
return !mCanceled;
|
||||
});
|
||||
}
|
||||
else
|
||||
|
||||
if (!mCanceled)
|
||||
{
|
||||
requireActivity().runOnUiThread(() ->
|
||||
{
|
||||
progressDialog.dismiss();
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.DolphinDialogBase);
|
||||
if (success)
|
||||
{
|
||||
builder.setMessage(R.string.convert_success_message)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(R.string.ok, (dialog, i) ->
|
||||
{
|
||||
dialog.dismiss();
|
||||
requireActivity().finish();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.setMessage(R.string.convert_failure_message)
|
||||
.setPositiveButton(R.string.ok, (dialog, i) -> dialog.dismiss());
|
||||
}
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
mThread.start();
|
||||
}
|
||||
|
||||
private void joinThread()
|
||||
{
|
||||
if (mThread != null)
|
||||
{
|
||||
builder.setMessage(R.string.convert_failure_message)
|
||||
.setPositiveButton(R.string.ok, (dialog, i) -> dialog.dismiss());
|
||||
try
|
||||
{
|
||||
mThread.join();
|
||||
}
|
||||
catch (InterruptedException ignored)
|
||||
{
|
||||
}
|
||||
}
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
package org.dolphinemu.dolphinemu.utils;
|
||||
|
||||
public interface CompressCallback
|
||||
{
|
||||
boolean run(String text, float completion);
|
||||
}
|
@ -337,6 +337,7 @@
|
||||
<string name="convert_compression_level">Compression Level</string>
|
||||
<string name="convert_remove_junk_data">Remove Junk Data (Irreversible)</string>
|
||||
<string name="convert_convert">Convert</string>
|
||||
<string name="convert_converting">Converting</string>
|
||||
<string name="convert_warning_iso">Removing junk data does not save any space when converting to ISO (unless you package the ISO file in a compressed file format such as ZIP afterwards). Do you want to continue anyway?</string>
|
||||
<string name="convert_warning_gcz">Converting Wii disc images to GCZ without removing junk data does not save any noticeable amount of space compared to converting to ISO. Do you want to continue anyway?</string>
|
||||
<string name="convert_success_message">The disc image was successfully converted.</string>
|
||||
|
Reference in New Issue
Block a user