2
0

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/file_access.h"
  34. #include "core/string/print_string.h"
  35. #include "core/templates/local_vector.h"
  36. #include "core/templates/map.h"
  37. class ValidationTracker {
  38. protected:
  39. struct Entries {
  40. Map<String, LocalVector<String>> validation_entries = Map<String, LocalVector<String>>();
  41. // for printing our CSV to dump validation problems of files
  42. // later we can make some agnostic tooling for this but this is fine for the time being.
  43. void add_validation_error(String asset_path, String message);
  44. void print_to_csv() {
  45. print_verbose("Exporting assset validation log please wait");
  46. String massive_log_file;
  47. String csv_header = "file_path, error message, extra data\n";
  48. massive_log_file += csv_header;
  49. for (const KeyValue<String, LocalVector<String>> &element : validation_entries) {
  50. for (unsigned int x = 0; x < element.value.size(); x++) {
  51. const String &line_entry = element.key + ", " + element.value[x].c_escape() + "\n";
  52. massive_log_file += line_entry;
  53. }
  54. }
  55. String path = "asset_validation_errors.csv";
  56. Error err;
  57. FileAccess *file = FileAccess::open(path, FileAccess::WRITE, &err);
  58. if (!file || err) {
  59. if (file) {
  60. memdelete(file);
  61. }
  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