validation_tools.h 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*************************************************************************/
  2. /* validation_tools.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef FBX_VALIDATION_TOOLS_H
  31. #define FBX_VALIDATION_TOOLS_H
  32. #ifdef TOOLS_ENABLED
  33. #include "core/local_vector.h"
  34. #include "core/map.h"
  35. #include "core/ustring.h"
  36. #include <core/io/json.h>
  37. #include <core/os/file_access.h>
  38. #include <scene/3d/path.h>
  39. class ValidationTracker {
  40. protected:
  41. struct Entries {
  42. Map<String, LocalVector<String>> validation_entries = Map<String, LocalVector<String>>();
  43. // for printing our CSV to dump validation problems of files
  44. // later we can make some agnostic tooling for this but this is fine for the time being.
  45. void add_validation_error(String asset_path, String message);
  46. void print_to_csv() {
  47. print_verbose("Exporting assset validation log please wait");
  48. String massive_log_file;
  49. String csv_header = "file_path, error message, extra data\n";
  50. massive_log_file += csv_header;
  51. for (Map<String, LocalVector<String>>::Element *element = validation_entries.front(); element; element = element->next()) {
  52. for (unsigned int x = 0; x < element->value().size(); x++) {
  53. const String &line_entry = element->key() + ", " + element->value()[x].c_escape() + "\n";
  54. massive_log_file += line_entry;
  55. }
  56. }
  57. String path = "asset_validation_errors.csv";
  58. Error err;
  59. FileAccess *file = FileAccess::open(path, FileAccess::WRITE, &err);
  60. if (!file || err) {
  61. if (file) {
  62. memdelete(file);
  63. }
  64. print_error("ValidationTracker Error - failed to create file - path: %s\n" + path);
  65. return;
  66. }
  67. file->store_string(massive_log_file);
  68. if (file->get_error() != OK && file->get_error() != ERR_FILE_EOF) {
  69. print_error("ValidationTracker Error - failed to write to file - path: %s\n" + path);
  70. }
  71. file->close();
  72. memdelete(file);
  73. }
  74. };
  75. // asset path, error messages
  76. static Entries *entries_singleton;
  77. public:
  78. static Entries *get_singleton() {
  79. return entries_singleton;
  80. }
  81. };
  82. #endif // TOOLS_ENABLED
  83. #endif // FBX_VALIDATION_TOOLS_H