Skip to content

Commit

Permalink
Add UI option to open the user folder (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
CasualPokePlayer authored Nov 23, 2024
1 parent 3d3407e commit a47d373
Show file tree
Hide file tree
Showing 5 changed files with 561 additions and 3 deletions.
9 changes: 9 additions & 0 deletions GSE.Android/AndroidFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ public static class AndroidFile
private static JClass _gseActivityClassId;
private static JMethodID _requestDocumentMethodId;
private static JMethodID _openContentMethodId;
private static JMethodID _openFileManagerMethodId;

internal static void InitializeJNI(JNIEnvPtr env, JClass gseActivityClassId)
{
_gseActivityClassId = gseActivityClassId;
_requestDocumentMethodId = env.GetStaticMethodID(_gseActivityClassId, "RequestDocument"u8, "()V"u8);
_openContentMethodId = env.GetStaticMethodID(_gseActivityClassId, "OpenContent"u8, "(Ljava/lang/String;)I"u8);
_openFileManagerMethodId = env.GetStaticMethodID(_gseActivityClassId, "OpenFileManager"u8, "()V"u8);
}

private static readonly AutoResetEvent _documentRequestDone = new(false);
Expand Down Expand Up @@ -80,4 +82,11 @@ public static MemoryStream OpenBufferedStream(string contentUri)
ms.Seek(0, SeekOrigin.Begin);
return ms;
}

// ReSharper disable once UnusedMember.Global
public static void OpenFileManager()
{
var env = JNIEnvPtr.GetEnv();
env.CallStaticVoidMethodA(_gseActivityClassId, _openFileManagerMethodId, []);
}
}
26 changes: 26 additions & 0 deletions GSE/Gui/ImGuiModals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

using static SDL2.SDL;

#if GSE_ANDROID
using GSE.Android;
#endif
using GSE.Audio;
using GSE.Emu;
using GSE.Input;
Expand Down Expand Up @@ -429,6 +432,29 @@ static string AddBiosPathButton(string system, string biosPathConfig, ImGuiWindo
(_config.SavePathLocation, _config.SavePathCustom) = AddPathLocationButton("Save", _config.SavePathLocation, _config.SavePathCustom, _mainWindow);
(_config.StatePathLocation, _config.StatePathCustom) = AddPathLocationButton("State", _config.StatePathLocation, _config.StatePathCustom, _mainWindow);
#endif
ImGui.Separator();
ImGui.AlignTextToFramePadding();

if (ImGui.Button("Open User Folder"))
{
#if GSE_ANDROID
AndroidFile.OpenFileManager();
#else
var prefPath = PathResolver.GetPath(PathResolver.PathType.PrefPath, null, null, null);
#if GSE_OSX
_ = SDL_OpenURL(new Uri(prefPath).LocalPath);
#else
try
{
Process.Start(new ProcessStartInfo(prefPath) { UseShellExecute = true });
}
catch
{
// ignored
}
#endif
#endif
}

// TODO: Add menus for opening up the user path (needed on Android, nice to have on other platforms)
ImGui.EndPopup();
Expand Down
17 changes: 14 additions & 3 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
android:icon="@mipmap/ic_launcher"
android:allowBackup="true"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:hardwareAccelerated="true" >
android:hardwareAccelerated="true">

<activity android:name="GSEActivity"
android:label="@string/app_name"
Expand All @@ -53,8 +53,7 @@
android:preferMinimalPostProcessing="true"
android:exported="true"
android:screenOrientation="userLandscape"
android:windowSoftInputMode="stateAlwaysHidden"
>
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand All @@ -64,5 +63,17 @@
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
</activity>

<provider
android:name="DocumentProvider"
android:authorities="${applicationId}.user"
android:grantUriPermissions="true"
android:exported="true"
android:permission="android.permission.MANAGE_DOCUMENTS"
android:enabled="true">
<intent-filter>
<action android:name="android.content.action.DOCUMENTS_PROVIDER" />
</intent-filter>
</provider>
</application>
</manifest>
Loading

0 comments on commit a47d373

Please sign in to comment.