/branches/release-1.0/Source_Files/Files/wad_sdl.cpp

# · C++ · 122 lines · 71 code · 19 blank · 32 comment · 11 complexity · 7de9f6b9c1f6c8db70fd02e6f98249a5 MD5 · raw file

  1. /*
  2. Copyright (C) 1991-2001 and beyond by Bungie Studios, Inc.
  3. and the "Aleph One" developers.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. This license is contained in the file "COPYING",
  13. which is included with this source code; it is available online at
  14. http://www.gnu.org/licenses/gpl.html
  15. */
  16. /*
  17. * wad_sdl.cpp - Additional map file handling, SDL implementation
  18. *
  19. * Written in 2000 by Christian Bauer
  20. */
  21. #include "cseries.h"
  22. #include "FileHandler.h"
  23. #include "find_files.h"
  24. #include <SDL_endian.h>
  25. // From shell_sdl.cpp
  26. extern vector<DirectorySpecifier> data_search_path;
  27. /*
  28. * Find map file with specified checksum in path
  29. */
  30. class FindByChecksum : public FileFinder {
  31. public:
  32. FindByChecksum(uint32 checksum) : look_for_checksum(checksum) {}
  33. ~FindByChecksum() {}
  34. FileSpecifier found_what;
  35. private:
  36. bool found(FileSpecifier &file)
  37. {
  38. OpenedFile f;
  39. if (!file.Open(f))
  40. return false;
  41. f.SetPosition(0x44);
  42. SDL_RWops *p = f.GetRWops();
  43. uint32 checksum = SDL_ReadBE32(p);
  44. if (checksum == look_for_checksum) {
  45. found_what = file;
  46. return true;
  47. }
  48. return false;
  49. }
  50. uint32 look_for_checksum;
  51. };
  52. bool find_wad_file_that_has_checksum(FileSpecifier &matching_file, Typecode file_type, short path_resource_id, uint32 checksum)
  53. {
  54. FindByChecksum finder(checksum);
  55. vector<DirectorySpecifier>::const_iterator i = data_search_path.begin(), end = data_search_path.end();
  56. while (i != end) {
  57. FileSpecifier dir = *i;
  58. if (finder.Find(dir, file_type)) {
  59. matching_file = finder.found_what;
  60. return true;
  61. }
  62. i++;
  63. }
  64. return false;
  65. }
  66. /*
  67. * Find file with specified modification date in path
  68. */
  69. class FindByDate : public FileFinder {
  70. public:
  71. FindByDate(time_t date) : look_for_date(date) {}
  72. ~FindByDate() {}
  73. FileSpecifier found_what;
  74. private:
  75. bool found(FileSpecifier &file)
  76. {
  77. if (file.GetDate() == look_for_date) {
  78. found_what = file;
  79. return true;
  80. }
  81. return false;
  82. }
  83. TimeType look_for_date;
  84. };
  85. bool find_file_with_modification_date(FileSpecifier &matching_file, Typecode file_type, short path_resource_id, TimeType modification_date)
  86. {
  87. FindByDate finder(modification_date);
  88. vector<DirectorySpecifier>::const_iterator i = data_search_path.begin(), end = data_search_path.end();
  89. while (i != end) {
  90. FileSpecifier dir = *i;
  91. if (finder.Find(dir, file_type)) {
  92. matching_file = finder.found_what;
  93. return true;
  94. }
  95. i++;
  96. }
  97. return false;
  98. }