DefaultResourceManager.cs 930 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // $Id$
  2. using System;
  3. using System.IO;
  4. namespace Resources
  5. {
  6. /// <summary>The default implementation of the ResourceManager</summary>
  7. public class DefaultResourceManager : ResourceManager
  8. {
  9. private string DataDir;
  10. public DefaultResourceManager(string Path)
  11. {
  12. this.DataDir = Path;
  13. }
  14. // Try to avoid this function
  15. [System.Obsolete("Do not use GetFileName: resource could be inside an archive file")]
  16. public override string GetFileName(string ResourcePath)
  17. {
  18. return Path.Combine(DataDir, ResourcePath);
  19. }
  20. public override Stream Get(string ResourcePath)
  21. {
  22. try {
  23. return new FileStream(Path.Combine(DataDir, ResourcePath), FileMode.Open, FileAccess.Read);
  24. } catch(Exception e) {
  25. throw new Exception("Couldn't load resource '" + ResourcePath + "'", e);
  26. }
  27. }
  28. public override string GetDirectoryName(string ResourcePath)
  29. {
  30. return Path.GetDirectoryName(ResourcePath);
  31. }
  32. }
  33. }