APKHandler.java 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. package com.amazon.lumberyard.io;
  9. import android.content.res.AssetManager;
  10. import android.util.Log;
  11. import java.io.IOException;
  12. import android.app.Activity;
  13. ////////////////////////////////////////////////////////////////
  14. public class APKHandler
  15. {
  16. ////////////////////////////////////////////////////////////////
  17. public static void SetAssetManager(AssetManager assetManager)
  18. {
  19. s_assetManager = assetManager;
  20. }
  21. ////////////////////////////////////////////////////////////////
  22. public static String[] GetFilesAndDirectoriesInPath(String path)
  23. {
  24. String[] filelist = {};
  25. try
  26. {
  27. // Asset manager doesn't handle '.' as a directory expression, so replace it with '' if it is encountered
  28. path = (path.equals( ".")) ? "" : path;
  29. filelist = s_assetManager.list(path);
  30. }
  31. catch (IOException e)
  32. {
  33. Log.e(s_tag, String.format("File I/O error: %s", e.getMessage()));
  34. e.printStackTrace();
  35. }
  36. finally
  37. {
  38. if (s_debug)
  39. {
  40. Log.d(s_tag, String.format("Files in path: %s", path));
  41. for(String name : filelist)
  42. {
  43. Log.d(s_tag, String.format(" -- %s", name));
  44. }
  45. }
  46. return filelist;
  47. }
  48. }
  49. ////////////////////////////////////////////////////////////////
  50. public static boolean IsDirectory(String path)
  51. {
  52. String[] filelist = {};
  53. boolean retVal = false;
  54. try
  55. {
  56. filelist = s_assetManager.list(path);
  57. if(filelist.length > 0)
  58. {
  59. retVal = true;
  60. }
  61. }
  62. catch (IOException e)
  63. {
  64. Log.e(s_tag, String.format("File I/O error: %s", e.getMessage()));
  65. e.printStackTrace();
  66. }
  67. finally
  68. {
  69. return retVal;
  70. }
  71. }
  72. // ----
  73. private static final String s_tag = "LMBR";
  74. private static AssetManager s_assetManager = null;
  75. private static boolean s_debug = false;
  76. }