| | |
| | | #include "humble_api.h" |
| | | |
| | | #include <dirent.h> |
| | | #include <sys/stat.h> |
| | | |
| | | extern "C" { |
| | | void test_list_files(); |
| | | void test_async_fetch(const char* url); |
| | | void test_demo_end(); |
| | | } |
| | | |
| | | std::string userDataPath = "/user_data"; |
| | | std::string userCloudPath = "/user_cloud"; |
| | | |
| | | void list_subfolder(const std::string& folder, const std::string& short_folder, const std::string& prefix = "") |
| | | { |
| | |
| | | if ((entry->d_type & DT_DIR)>0) { |
| | | list_subfolder(folder + '/' + entry->d_name, entry->d_name, prefix + " "); |
| | | } else { |
| | | std::cout << prefix << " " << entry->d_name << "\n"; |
| | | struct stat st; |
| | | stat((folder + '/' + entry->d_name).c_str(), &st); |
| | | std::cout << prefix << " " << entry->d_name << " S:" << st.st_size << "\n"; |
| | | } |
| | | } |
| | | closedir(d); |
| | |
| | | |
| | | void list_folder(const std::string& folder) |
| | | { |
| | | std::cout << "Listing files\n"; |
| | | list_subfolder(folder, folder); |
| | | } |
| | | |
| | | void test_list_files() |
| | | void EMSCRIPTEN_KEEPALIVE test_list_files() |
| | | { |
| | | std::cout << "Listing files\n" ; |
| | | list_folder(userDataPath); |
| | | list_folder(userCloudPath); |
| | | list_folder("/data"); |
| | | } |
| | | |
| | | void on_get_file(void* arg, void* data, int data_size) |
| | | { |
| | | std::cout << "File fetch succeeded: " << data_size << "\n"; |
| | | std::string tdata((char *)data, data_size); |
| | | std::cout << " " << tdata << "\n"; |
| | | } |
| | | |
| | | void on_fail_file(void *arg) |
| | | { |
| | | std::cout << "File fetch failed\n"; |
| | | } |
| | | |
| | | void EMSCRIPTEN_KEEPALIVE test_async_fetch(const char* url) |
| | | { |
| | | std::cout << "Fetch file: " << url << "\n"; |
| | | humble_fetch_asset_data(url, NULL, on_get_file, on_fail_file); |
| | | } |
| | | |
| | | void EMSCRIPTEN_KEEPALIVE test_demo_end() |
| | | { |
| | | std::cout << "Demo has ended\n"; |
| | | humble_demo_ended(); |
| | | } |
| | | |
| | | int main(int argc, char * argv[]) |
| | |
| | | // call dummy function to init cloud |
| | | humble_init(); |
| | | |
| | | // Test humble_get_url_for_asset |
| | | int w, h; |
| | | int ret = humble_get_player_size(&w, &h); |
| | | |
| | | char * path = humble_get_url_for_asset("textures/icon1.png"); |
| | | std::cout << "humble_get_url_for_asset returned " << path << "\n"; |
| | | free(path); |
| | | std::cout << "HumblePlayerSize Enabled: " << ret << " @ ( " << w << ", " << h << " )\n"; |
| | | |
| | | return 0; |
| | | } |