@@ -36,7 +36,9 @@ public class InstallManager : INotifyPropertyChanged
36
36
} ;
37
37
38
38
private const string DataDirectoryTemplate = "/sdcard/Android/data/{0}/files" ;
39
+ private const string ObbDirectoryTemplate = "/sdcard/Android/obb/{0}" ;
39
40
private const string DataBackupTemplate = "/sdcard/QuestPatcher/{0}/backup" ;
41
+ private const string ObbBackupTemplate = "/sdcard/QuestPatcher/{0}/obb" ;
40
42
41
43
/// <summary>
42
44
/// The APK currently installed on the quest
@@ -51,6 +53,10 @@ public class InstallManager : INotifyPropertyChanged
51
53
/// </summary>
52
54
private string DataPath => string . Format ( DataDirectoryTemplate , _config . AppId ) ;
53
55
56
+ /// <summary>
57
+ /// The /sdcard/Android/obb/... directory for the installed app
58
+ /// </summary>
59
+ private string ObbPath => string . Format ( ObbDirectoryTemplate , _config . AppId ) ;
54
60
55
61
private readonly string _currentlyInstalledPath ;
56
62
private readonly AndroidDebugBridge _debugBridge ;
@@ -195,13 +201,16 @@ public async Task NewApkInstalled(string newApk)
195
201
/// Creates a backup of the /sdcard/Android/data/... directory for the current app.
196
202
/// </summary>
197
203
/// <returns>The path to the backup on the quest</returns>
198
- public async Task < string > CreateDataBackup ( )
204
+ public async Task < string ? > CreateDataBackup ( )
199
205
{
200
206
string backupPath = string . Format ( DataBackupTemplate , _config . AppId ) ;
201
207
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
+
205
214
// Remove the backup path if it already exists and then recreate it
206
215
await _debugBridge . RemoveDirectory ( backupPath ) ;
207
216
await _debugBridge . CreateDirectory ( backupPath ) ;
@@ -211,6 +220,28 @@ public async Task<string> CreateDataBackup()
211
220
return backupPath ;
212
221
}
213
222
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
+
214
245
/// <summary>
215
246
/// Restores a data backup created with CreateDataBackup.
216
247
/// 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)
228
259
await _debugBridge . RemoveDirectory ( Path . Combine ( DataPath , "mods" ) ) ;
229
260
}
230
261
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
+
231
274
/// <summary>
232
275
/// Uninstalls the current app
233
276
/// </summary>
0 commit comments