CefResourceBundle.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. namespace Xilium.CefGlue
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Runtime.InteropServices;
  7. using Xilium.CefGlue.Interop;
  8. /// <summary>
  9. /// Class used for retrieving resources from the resource bundle (*.pak) files
  10. /// loaded by CEF during startup or via the CefResourceBundleHandler returned
  11. /// from CefApp::GetResourceBundleHandler. See CefSettings for additional options
  12. /// related to resource bundle loading. The methods of this class may be called
  13. /// on any thread unless otherwise indicated.
  14. /// </summary>
  15. public sealed unsafe partial class CefResourceBundle
  16. {
  17. /// <summary>
  18. /// Returns the global resource bundle instance.
  19. /// </summary>
  20. public static CefResourceBundle GetGlobal()
  21. {
  22. return CefResourceBundle.FromNative(cef_resource_bundle_t.get_global());
  23. }
  24. /// <summary>
  25. /// Returns the localized string for the specified |string_id| or an empty
  26. /// string if the value is not found. Include cef_pack_strings.h for a listing
  27. /// of valid string ID values.
  28. /// </summary>
  29. public string GetLocalizedString(int stringId)
  30. {
  31. var n_result = cef_resource_bundle_t.get_localized_string(_self, stringId);
  32. return cef_string_userfree.ToString(n_result);
  33. }
  34. /// <summary>
  35. /// Returns a CefBinaryValue containing the decompressed contents of the
  36. /// specified scale independent |resource_id| or NULL if not found. Include
  37. /// cef_pack_resources.h for a listing of valid resource ID values.
  38. /// </summary>
  39. public CefBinaryValue GetDataResource(int resource_id)
  40. {
  41. return CefBinaryValue.FromNativeOrNull(
  42. cef_resource_bundle_t.get_data_resource(_self, resource_id)
  43. );
  44. }
  45. /// <summary>
  46. /// Returns a CefBinaryValue containing the decompressed contents of the
  47. /// specified |resource_id| nearest the scale factor |scale_factor| or NULL if
  48. /// not found. Use a |scale_factor| value of SCALE_FACTOR_NONE for scale
  49. /// independent resources or call GetDataResource instead.Include
  50. /// cef_pack_resources.h for a listing of valid resource ID values.
  51. /// </summary>
  52. public CefBinaryValue GetDataResourceForScale(int resource_id, CefScaleFactor scale_factor)
  53. {
  54. return CefBinaryValue.FromNativeOrNull(
  55. cef_resource_bundle_t.get_data_resource_for_scale(_self, resource_id, scale_factor)
  56. );
  57. }
  58. }
  59. }