validation_tools.h 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*************************************************************************/
  2. /* validation_tools.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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/io/json.h"
  34. #include "core/os/file_access.h"
  35. #include "core/string/ustring.h"
  36. #include "core/templates/local_vector.h"
  37. #include "core/templates/map.h"
  38. class ValidationTracker {
  39. protected:
  40. struct Entries {
  41. Map<String, LocalVector<String>> validation_entries = Map<String, LocalVector<String>>();
  42. // for printing our CSV to dump validation problems of files
  43. // later we can make some agnostic tooling for this but this is fine for the time being.
  44. void add_validation_error(String asset_path, String message);
  45. void print_to_csv() {
  46. print_verbose("Exporting assset validation log please wait");
  47. String massive_log_file;
  48. String csv_header = "file_path, error message, extra data\n";
  49. massive_log_file += csv_header;
  50. for (Map<String, LocalVector<String>>::Element *element = validation_entries.front(); element; element = element->next()) {
  51. for (unsigned int x = 0; x < element->value().size(); x++) {
  52. const String &line_entry = element->key() + ", " + element->value()[x].c_escape() + "\n";
  53. massive_log_file += line_entry;
  54. }
  55. }
  56. String path = "asset_validation_errors.csv";
  57. Error err;
  58. FileAccess *file = FileAccess::open(path, FileAccess::WRITE, &err);
  59. if (!file || err) {
  60. if (file)
  61. memdelete(file);
  62. print_error("ValidationTracker Error - failed to create file - path: %s\n" + path);
  63. return;
  64. }
  65. file->store_string(massive_log_file);
  66. if (file->get_error() != OK && file->get_error() != ERR_FILE_EOF) {
  67. print_error("ValidationTracker Error - failed to write to file - path: %s\n" + path);
  68. }
  69. file->close();
  70. memdelete(file);
  71. }
  72. };
  73. // asset path, error messages
  74. static Entries *entries_singleton;
  75. public:
  76. static Entries *get_singleton() {
  77. return entries_singleton;
  78. }
  79. };
  80. #endif // TOOLS_ENABLED
  81. #endif // FBX_VALIDATION_TOOLS_H