Skip to content

Commit

Permalink
bonk
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishan09811 authored Apr 14, 2024
1 parent 30f0bf7 commit 8b11a49
Showing 1 changed file with 37 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
import androidx.core.content.pm.ShortcutManagerCompat;
import androidx.core.graphics.drawable.IconCompat;
import androidx.appcompat.app.AppCompatActivity;
import androidx.documentfile.provider.DocumentFile;
import android.provider.DocumentsContract;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;

import com.panda3ds.pandroid.R;
import com.panda3ds.pandroid.app.PandroidApplication;
Expand All @@ -30,7 +31,8 @@

public class GameAboutDialog extends BaseSheetDialog {
private final GameMetadata game;
private static final String MIME_TYPE_ZIP = "application/zip";
private final ActivityResultContracts.OpenDocumentTree openFolderContract = new ActivityResultContracts.OpenDocumentTree();
private ActivityResultLauncher<Uri> pickFolderRequest;
public GameAboutDialog(@NonNull Context context, GameMetadata game) {
super(context);
this.game = game;
Expand All @@ -40,6 +42,7 @@ public GameAboutDialog(@NonNull Context context, GameMetadata game) {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_game_about);
pickFolderRequest = registerForActivityResult(openFolderContract, this);

((GameIconView) findViewById(R.id.game_icon)).setImageBitmap(game.getIcon());
((TextView) findViewById(R.id.game_title)).setText(game.getTitle());
Expand All @@ -55,32 +58,7 @@ protected void onCreate(Bundle savedInstanceState) {
makeShortcut();
});
findViewById(R.id.export_save).setOnClickListener(v -> {
String inputPath = FileUtils.getPrivatePath() + "/" + FileUtils.getName(game.getRealPath()).replaceAll("\\..*", "") + "/SaveData/";
String outputPath = "/storage/emulated/0/Android/media/com.panda3ds.pandroid/";
String outputName = game.getTitle() + ".zip";
String zipPath = outputPath + outputName;

// Create an instance of ZipBuilder
ZipBuilder zipBuilder = new ZipBuilder(outputPath, outputName);


new Task(()->{
try {
// Begin the zip file creation process
zipBuilder.begin();

// Append files or folders to the zip file
zipBuilder.append(inputPath);

// End the zip file creation process
zipBuilder.end();

System.out.println("Zip file created successfully.");
createDocument(getContext(), MIME_TYPE_ZIP, outputName, zipPath);
} catch (Exception e) {
System.err.println("Error creating zip file: " + e.getMessage());
}
}).start();
pickFolderRequest.launch(null);
});

if (game.getRomPath().startsWith("folder:")) {
Expand All @@ -96,15 +74,6 @@ protected void onCreate(Bundle savedInstanceState) {
}
}

private void createDocument(Context context, @NonNull String mimeType, String fileName, String outputDirPath) {
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType(mimeType);
intent.putExtra(Intent.EXTRA_TITLE, fileName);
intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, Uri.fromFile(new File(outputDirPath)));
context.startActivity(intent);
}

// Make a shortcut for a specific game
private void makeShortcut() {
Context context = CompatUtils.findActivity(getContext());
Expand All @@ -124,4 +93,34 @@ private void makeShortcut() {
shortcut.setIntent(intent);
ShortcutManagerCompat.requestPinShortcut(context, shortcut.build(), null);
}

@Override
public void onActivityResult(Uri result) {
if (result != null) {
String inputPath = FileUtils.getPrivatePath() + "/" + FileUtils.getName(game.getRealPath()).replaceAll("\\..*", "") + "/SaveData/";
String outputPath = result.toString();
String outputName = game.getTitle() + ".zip";

// Create an instance of ZipBuilder
ZipBuilder zipBuilder = new ZipBuilder(outputPath, outputName);


new Task(()->{
try {
// Begin the zip file creation process
zipBuilder.begin();

// Append files or folders to the zip file
zipBuilder.append(inputPath);

// End the zip file creation process
zipBuilder.end();

System.out.println("Zip file created successfully.");
} catch (Exception e) {
System.err.println("Error creating zip file: " + e.getMessage());
}
}).start();
}
}
}

0 comments on commit 8b11a49

Please sign in to comment.