@@ -36,7 +36,9 @@ public class InstallManager : INotifyPropertyChanged
3636 } ;
3737
3838 private const string DataDirectoryTemplate = "/sdcard/Android/data/{0}/files" ;
39+ private const string ObbDirectoryTemplate = "/sdcard/Android/obb/{0}" ;
3940 private const string DataBackupTemplate = "/sdcard/QuestPatcher/{0}/backup" ;
41+ private const string ObbBackupTemplate = "/sdcard/QuestPatcher/{0}/obb" ;
4042
4143 /// <summary>
4244 /// The APK currently installed on the quest
@@ -51,6 +53,10 @@ public class InstallManager : INotifyPropertyChanged
5153 /// </summary>
5254 private string DataPath => string . Format ( DataDirectoryTemplate , _config . AppId ) ;
5355
56+ /// <summary>
57+ /// The /sdcard/Android/obb/... directory for the installed app
58+ /// </summary>
59+ private string ObbPath => string . Format ( ObbDirectoryTemplate , _config . AppId ) ;
5460
5561 private readonly string _currentlyInstalledPath ;
5662 private readonly AndroidDebugBridge _debugBridge ;
@@ -195,13 +201,16 @@ public async Task NewApkInstalled(string newApk)
195201 /// Creates a backup of the /sdcard/Android/data/... directory for the current app.
196202 /// </summary>
197203 /// <returns>The path to the backup on the quest</returns>
198- public async Task < string > CreateDataBackup ( )
204+ public async Task < string ? > CreateDataBackup ( )
199205 {
200206 string backupPath = string . Format ( DataBackupTemplate , _config . AppId ) ;
201207
202- // Avoid failing if no files are present in the data directory
203- // TODO: Perhaps check if it exists first and then skip backup if missing? This is more complex.
204- await _debugBridge . CreateDirectory ( DataPath ) ;
208+ // Check if the data directory exists and skip if it doesn't.
209+ if ( ! await _debugBridge . Exists ( DataPath ) )
210+ {
211+ return null ;
212+ }
213+
205214 // Remove the backup path if it already exists and then recreate it
206215 await _debugBridge . RemoveDirectory ( backupPath ) ;
207216 await _debugBridge . CreateDirectory ( backupPath ) ;
@@ -211,6 +220,28 @@ public async Task<string> CreateDataBackup()
211220 return backupPath ;
212221 }
213222
223+ /// <summary>
224+ /// Creates a backup of the /sdcard/Android/obb/... directory for the current app.
225+ /// </summary>
226+ /// <returns>The path to the backup on the quest</returns>
227+ public async Task < string ? > CreateObbBackup ( )
228+ {
229+ string backupPath = string . Format ( ObbBackupTemplate , _config . AppId ) ;
230+
231+ // Check if the data directory exists and skip if it doesn't.
232+ if ( ! await _debugBridge . Exists ( ObbPath ) )
233+ {
234+ return null ;
235+ }
236+
237+ // Remove the backup path if it already exists
238+ await _debugBridge . RemoveDirectory ( backupPath ) ;
239+ // Copy all the files to the data backup
240+ await _debugBridge . Move ( ObbPath , backupPath ) ;
241+
242+ return backupPath ;
243+ }
244+
214245 /// <summary>
215246 /// Restores a data backup created with CreateDataBackup.
216247 /// Will delete any mod/lib files in the backup to avoid old mods causing crashes.
@@ -228,6 +259,18 @@ public async Task RestoreDataBackup(string backupPath)
228259 await _debugBridge . RemoveDirectory ( Path . Combine ( DataPath , "mods" ) ) ;
229260 }
230261
262+ /// <summary>
263+ /// Restores a obb backup created with CreateObbBackup.
264+ /// </summary>
265+ /// <param name="backupPath">The path to the backup on the quest</param>
266+ public async Task RestoreObbBackup ( string backupPath )
267+ {
268+ // Remove the backup obb path if it already exists
269+ await _debugBridge . RemoveDirectory ( ObbPath ) ;
270+ // Move the obb backup to the original path.
271+ await _debugBridge . Move ( backupPath , ObbPath ) ;
272+ }
273+
231274 /// <summary>
232275 /// Uninstalls the current app
233276 /// </summary>
0 commit comments