SourceFile.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * PERWAPI - An API for Reading and Writing PE Files
  3. *
  4. * Copyright (c) Diane Corney, Queensland University of Technology, 2004.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the PERWAPI Copyright as included with this
  8. * distribution in the file PERWAPIcopyright.rtf.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY as is explained in the copyright notice.
  12. *
  13. * The author may be contacted at d.corney@qut.edu.au
  14. *
  15. * Version Date: 26/01/07
  16. */
  17. using System;
  18. using System.IO;
  19. using System.Collections;
  20. namespace QUT.PERWAPI
  21. {
  22. /**************************************************************************/
  23. /// <summary>
  24. /// Descriptor for a file containing a managed resource
  25. /// </summary>
  26. public class SourceFile
  27. {
  28. static ArrayList sourceFiles = new ArrayList();
  29. internal string name;
  30. internal Guid language, vendor, document;
  31. /*-------------------- Constructors ---------------------------------*/
  32. private SourceFile(string name, Guid lang, Guid vend, Guid docu)
  33. {
  34. this.name = name;
  35. language = lang;
  36. vendor = vend;
  37. document = docu;
  38. sourceFiles.Add(this);
  39. }
  40. private bool GuidsMatch(Guid lang, Guid vend, Guid docu)
  41. {
  42. if (language != lang) return false;
  43. if (vendor != vend) return false;
  44. if (document != docu) return false;
  45. return true;
  46. }
  47. internal bool Match(SourceFile file)
  48. {
  49. if (file == null) return false;
  50. if (this == file) return true;
  51. if (name != file.name) return false;
  52. return GuidsMatch(file.language, file.vendor, file.document);
  53. }
  54. public static SourceFile GetSourceFile(string name, Guid lang, Guid vend, Guid docu)
  55. {
  56. for (int i = 0; i < sourceFiles.Count; i++)
  57. {
  58. SourceFile sFile = (SourceFile)sourceFiles[i];
  59. if ((sFile.name == name) && sFile.GuidsMatch(lang, vend, docu))
  60. return sFile;
  61. }
  62. return new SourceFile(name, lang, vend, docu);
  63. }
  64. public string Name
  65. {
  66. get { return name; }
  67. }
  68. }
  69. }