diff --git a/core/src/com/unciv/ui/mapeditor/MapDownloadPopup.kt b/core/src/com/unciv/ui/mapeditor/MapDownloadPopup.kt index 83d94e2a..ce7bcbba 100644 --- a/core/src/com/unciv/ui/mapeditor/MapDownloadPopup.kt +++ b/core/src/com/unciv/ui/mapeditor/MapDownloadPopup.kt @@ -49,7 +49,7 @@ class MapDownloadPopup(loadMapScreen: LoadMapScreen): Popup(loadMapScreen) { val folderList = DropBox.getFolderList("/Maps") Gdx.app.postRunnable { scrollableMapTable.apply { defaults().pad(10f) } - for (downloadableMap in folderList.entries) { + for (downloadableMap in folderList) { val downloadMapButton = downloadableMap.name.toTextButton() listOfMaps.add(downloadMapButton) downloadMapButton.onClick { diff --git a/core/src/com/unciv/ui/worldscreen/mainmenu/DropBox.kt b/core/src/com/unciv/ui/worldscreen/mainmenu/DropBox.kt index 9f6d6b0f..632c3230 100644 --- a/core/src/com/unciv/ui/worldscreen/mainmenu/DropBox.kt +++ b/core/src/com/unciv/ui/worldscreen/mainmenu/DropBox.kt @@ -45,10 +45,22 @@ object DropBox { } } - fun getFolderList(folder:String):FolderList{ + fun getFolderList(folder:String): ArrayList { + val folderList = ArrayList() + // The DropBox API returns only partial file listings from one request. list_folder and + // list_folder/continue return similar responses, but list_folder/continue requires a cursor + // instead of the path. val response = dropboxApi("https://api.dropboxapi.com/2/files/list_folder", "{\"path\":\"$folder\"}","application/json") - return GameSaver.json().fromJson(FolderList::class.java,response) + var currentFolderListChunk = GameSaver.json().fromJson(FolderList::class.java, response) + folderList.addAll(currentFolderListChunk.entries) + while (currentFolderListChunk.has_more) { + val continuationResponse = dropboxApi("https://api.dropboxapi.com/2/files/list_folder/continue", + "{\"cursor\":\"${currentFolderListChunk.cursor}\"}","application/json") + currentFolderListChunk = GameSaver.json().fromJson(FolderList::class.java, continuationResponse) + folderList.addAll(currentFolderListChunk.entries) + } + return folderList } fun downloadFile(fileName:String): InputStream { @@ -84,6 +96,8 @@ object DropBox { class FolderList{ var entries = ArrayList() + var cursor = "" + var has_more = false } class FolderListEntry{