version.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #ifndef _VERSION_H
  2. #define _VERSION_H
  3. // These variables are autogenerated and compiled
  4. // into the library by the version.cmake script
  5. extern "C"
  6. {
  7. extern const char* GIT_TAG;
  8. extern const char* GIT_REV;
  9. extern const char* GIT_BRANCH;
  10. extern const char* BUILD_TIME;
  11. }
  12. #include <string>
  13. #include <string.h>
  14. #include "Helper.h"
  15. #include <fstream>
  16. #include <algorithm>
  17. const char* build_time(void)
  18. {
  19. return BUILD_TIME;
  20. }
  21. const char* libfive_git_version(void)
  22. {
  23. return GIT_TAG;
  24. }
  25. const char* libfive_git_revision(void)
  26. {
  27. return GIT_REV;
  28. }
  29. const char* libfive_git_branch(void)
  30. {
  31. return GIT_BRANCH;
  32. }
  33. std::string getFwVersion(void) {
  34. std::string buf;
  35. if (std::string(GIT_TAG) == "") { // Tag not set, show branch
  36. buf = "Development-Branch: " + std::string(GIT_BRANCH);
  37. }
  38. else { // Tag is set, ignore branch
  39. buf = "Release: " + std::string(GIT_TAG);
  40. }
  41. buf = buf + " (Commit: " + std::string(GIT_REV) + ")";
  42. return buf;
  43. }
  44. std::string getHTMLversion(void){
  45. char buf[100]="?\0";
  46. FILE* pFile;
  47. string fn = FormatFileName("/sdcard/html/version.txt");
  48. pFile = fopen(fn.c_str(), "r");
  49. if (pFile == NULL)
  50. return std::string(buf);
  51. fgets(buf, sizeof(buf), pFile); // Line 1: Version
  52. fclose(pFile);
  53. string value = string(buf);
  54. value.erase(std::remove(value.begin(), value.end(), '\n'), value.end()); // Remove any newlines
  55. return value;
  56. }
  57. std::string getHTMLcommit(void){
  58. char buf[100]="?\0";
  59. FILE* pFile;
  60. string fn = FormatFileName("/sdcard/html/version.txt");
  61. pFile = fopen(fn.c_str(), "r");
  62. if (pFile == NULL)
  63. return std::string(buf);
  64. fgets(buf, sizeof(buf), pFile); // Line 1: Version -> ignored
  65. fgets(buf, sizeof(buf), pFile); // Line 2: Commit
  66. fclose(pFile);
  67. string value = string(buf);
  68. value.erase(std::remove(value.begin(), value.end(), '\n'), value.end()); // Remove any newlines
  69. return value;
  70. }
  71. #endif // _VERSION_H