|
| 1 | +package org.wordpress.gutenberg |
| 2 | + |
| 3 | +import android.content.Context |
| 4 | +import org.wordpress.gutenberg.model.EditorConfiguration |
| 5 | +import java.io.File |
| 6 | + |
| 7 | +/** |
| 8 | + * Utility object for constructing storage and cache directory paths. |
| 9 | + */ |
| 10 | +object Paths { |
| 11 | + /** |
| 12 | + * Returns the default storage root directory for GutenbergKit. |
| 13 | + * |
| 14 | + * This is typically in the app's files directory. |
| 15 | + * |
| 16 | + * @param context The Android context. |
| 17 | + * @return The default storage root directory. |
| 18 | + */ |
| 19 | + fun defaultStorageRoot(context: Context): File { |
| 20 | + return File(context.filesDir, "GutenbergKit") |
| 21 | + } |
| 22 | + |
| 23 | + /** |
| 24 | + * Returns the storage root directory for a specific site configuration. |
| 25 | + * |
| 26 | + * @param context The Android context. |
| 27 | + * @param configuration The editor configuration. |
| 28 | + * @return The site-specific storage directory. |
| 29 | + */ |
| 30 | + fun storageRoot(context: Context, configuration: EditorConfiguration): File { |
| 31 | + return File(defaultStorageRoot(context), configuration.siteId) |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * Returns the storage root directory for a specific site configuration. |
| 36 | + * |
| 37 | + * @param baseDir The base directory to use instead of context.filesDir. |
| 38 | + * @param configuration The editor configuration. |
| 39 | + * @return The site-specific storage directory. |
| 40 | + */ |
| 41 | + fun storageRoot(baseDir: File, configuration: EditorConfiguration): File { |
| 42 | + return File(File(baseDir, "GutenbergKit"), configuration.siteId) |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Returns the default cache root directory for GutenbergKit. |
| 47 | + * |
| 48 | + * This is typically in the app's cache directory. |
| 49 | + * |
| 50 | + * @param context The Android context. |
| 51 | + * @return The default cache root directory. |
| 52 | + */ |
| 53 | + fun defaultCacheRoot(context: Context): File { |
| 54 | + return File(context.cacheDir, "GutenbergKit") |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Returns the cache root directory for a specific site configuration. |
| 59 | + * |
| 60 | + * @param context The Android context. |
| 61 | + * @param configuration The editor configuration. |
| 62 | + * @return The site-specific cache directory. |
| 63 | + */ |
| 64 | + fun cacheRoot(context: Context, configuration: EditorConfiguration): File { |
| 65 | + return File(defaultCacheRoot(context), configuration.siteId) |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * Returns the cache root directory for a specific site configuration. |
| 70 | + * |
| 71 | + * @param baseDir The base directory to use instead of context.cacheDir. |
| 72 | + * @param configuration The editor configuration. |
| 73 | + * @return The site-specific cache directory. |
| 74 | + */ |
| 75 | + fun cacheRoot(baseDir: File, configuration: EditorConfiguration): File { |
| 76 | + return File(File(baseDir, "GutenbergKit"), configuration.siteId) |
| 77 | + } |
| 78 | +} |
0 commit comments