TopInformations.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #include "TopInformations.hpp"
  2. #include "AssetManager.hpp"
  3. #include "DownloadQueue.hpp"
  4. #include "Notification.hpp"
  5. #include "States/StateIdentifiers.hpp"
  6. #include "States/DialogState.hpp"
  7. #include <cpp3ds/System/I18n.hpp>
  8. #include <time.h>
  9. #ifndef EMULATION
  10. #include <3ds.h>
  11. #endif
  12. namespace FreeShop {
  13. TopInformations::TopInformations()
  14. {
  15. //Texts
  16. m_textSD.setString(_("SD"));
  17. m_textSD.setFillColor(cpp3ds::Color::Black);
  18. m_textSD.setCharacterSize(10);
  19. m_textSD.setPosition(2.f, 3.f);
  20. m_textSD.useSystemFont();
  21. m_textSDStorage.setString(_(""));
  22. m_textSDStorage.setFillColor(cpp3ds::Color(130, 130, 130, 255));
  23. m_textSDStorage.setCharacterSize(10);
  24. m_textSDStorage.setPosition(2.f, 15.f);
  25. m_textSDStorage.useSystemFont();
  26. m_textNAND.setString(_("TWL NAND"));
  27. m_textNAND.setFillColor(cpp3ds::Color::Black);
  28. m_textNAND.setCharacterSize(10);
  29. m_textNAND.setPosition(2.f, 31.f);
  30. m_textNAND.useSystemFont();
  31. m_textNANDStorage.setString(_(""));
  32. m_textNANDStorage.setFillColor(cpp3ds::Color(130, 130, 130, 255));
  33. m_textNANDStorage.setCharacterSize(10);
  34. m_textNANDStorage.setPosition(2.f, 43.f);
  35. m_textNANDStorage.useSystemFont();
  36. //Progress bars
  37. m_progressBarNAND.setFillColor(cpp3ds::Color(0, 0, 0, 50));
  38. m_progressBarNAND.setPosition(0.f, 30.f);
  39. m_progressBarNAND.setSize(cpp3ds::Vector2f(0, 29));
  40. m_progressBarSD.setFillColor(cpp3ds::Color(0, 0, 0, 50));
  41. m_progressBarSD.setPosition(0.f, 2.f);
  42. m_progressBarSD.setSize(cpp3ds::Vector2f(0, 29));
  43. //Progress bars' backgrounds
  44. /*if (fopen(FREESHOP_DIR "/theme/images/fsbgnand.png", "rb"))
  45. m_backgroundNAND.setTexture(&AssetManager<cpp3ds::Texture>::get(FREESHOP_DIR "/theme/images/fsbgnand.png"));
  46. else*/
  47. m_backgroundNAND.setTexture(&AssetManager<cpp3ds::Texture>::get("images/fsbgnand.png"));
  48. m_backgroundNAND.setSize(300, 23);
  49. m_backgroundNAND.setPosition(0.f, 30.f);
  50. /*if (fopen(FREESHOP_DIR "/theme/images/fsbgsd.png", "rb"))
  51. m_backgroundSD.setTexture(&AssetManager<cpp3ds::Texture>::get(FREESHOP_DIR "/theme/images/fsbgsd.png"));
  52. else*/
  53. m_backgroundSD.setTexture(&AssetManager<cpp3ds::Texture>::get("images/fsbgsd.png"));
  54. m_backgroundSD.setSize(300, 23);
  55. m_backgroundSD.setPosition(0.f, 2.f);
  56. //Get the time to show it in the top part of the App List
  57. time_t t = time(NULL);
  58. struct tm * timeinfo;
  59. timeinfo = localtime(&t);
  60. char timeTextFmt[12];
  61. char tempSec[3];
  62. strftime(tempSec, 3, "%S", timeinfo);
  63. //Cool blinking effect
  64. if (atoi(tempSec) % 2 == 0)
  65. strftime(timeTextFmt, 12, "%d/%m %H %M", timeinfo);
  66. else
  67. strftime(timeTextFmt, 12, "%d/%m %H:%M", timeinfo);
  68. m_textClock.setString(timeTextFmt);
  69. m_textClock.useSystemFont();
  70. m_textClock.setCharacterSize(14);
  71. m_textClock.setFillColor(cpp3ds::Color(80, 80, 80, 255));
  72. m_textClock.setPosition(395.f - m_textClock.getLocalBounds().width, 0.f);
  73. }
  74. TopInformations::~TopInformations()
  75. {
  76. }
  77. void TopInformations::draw(cpp3ds::RenderTarget &target, cpp3ds::RenderStates states) const
  78. {
  79. states.transform *= getTransform();
  80. //Firstly, draw the backgrounds for progress bars
  81. target.draw(m_backgroundNAND);
  82. target.draw(m_backgroundSD);
  83. //Secondly, draw the progress bars
  84. target.draw(m_progressBarNAND);
  85. target.draw(m_progressBarSD);
  86. //Finally, draw all the texts
  87. target.draw(m_textSD);
  88. target.draw(m_textSDStorage);
  89. target.draw(m_textNAND);
  90. target.draw(m_textNANDStorage);
  91. target.draw(m_textClock);
  92. }
  93. void TopInformations::update()
  94. {
  95. //Update the time to show it in the top part of the App List
  96. time_t t = time(NULL);
  97. struct tm * timeinfo;
  98. timeinfo = localtime(&t);
  99. char timeTextFmt[12];
  100. char tempSec[3];
  101. strftime(tempSec, 3, "%S", timeinfo);
  102. //Cool blinking effect
  103. if (atoi(tempSec) % 2 == 0)
  104. strftime(timeTextFmt, 12, "%d/%m %H %M", timeinfo);
  105. else
  106. strftime(timeTextFmt, 12, "%d/%m %H:%M", timeinfo);
  107. m_textClock.setString(timeTextFmt);
  108. //Update filesystems size and their progress bars
  109. #ifndef EMULATION
  110. FS_ArchiveResource resource = {0};
  111. if(R_SUCCEEDED(FSUSER_GetArchiveResource(&resource, SYSTEM_MEDIATYPE_SD))) {
  112. u64 size = (u64) resource.freeClusters * (u64) resource.clusterSize;
  113. u64 totalSize = (u64) resource.totalClusters * (u64) resource.clusterSize;
  114. u64 usedSize = totalSize - size;
  115. m_progressBarSD.setSize(cpp3ds::Vector2f((usedSize * 300) / totalSize, 26));
  116. if (usedSize > 1024 * 1024 * 1024 || totalSize > 1024 * 1024 * 1024)
  117. m_textSDStorage.setString(_("%.1f/%.1f GB", static_cast<float>(usedSize) / 1024.f / 1024.f / 1024.f, static_cast<float>(totalSize) / 1024.f / 1024.f / 1024.f));
  118. else if (usedSize > 1024 * 1024 || totalSize > 1024 * 1024)
  119. m_textSDStorage.setString(_("%.1f/%.1f MB", static_cast<float>(usedSize) / 1024.f / 1024.f, static_cast<float>(totalSize) / 1024.f / 1024.f));
  120. else
  121. m_textSDStorage.setString(_("%d/%d KB", usedSize / 1024, totalSize / 1024));
  122. } else {
  123. m_textSDStorage.setString("No SD Card detected");
  124. }
  125. if(R_SUCCEEDED(FSUSER_GetArchiveResource(&resource, SYSTEM_MEDIATYPE_TWL_NAND))) {
  126. u64 size = (u64) resource.freeClusters * (u64) resource.clusterSize;
  127. u64 totalSize = (u64) resource.totalClusters * (u64) resource.clusterSize;
  128. u64 usedSize = totalSize - size;
  129. m_progressBarNAND.setSize(cpp3ds::Vector2f((usedSize * 300) / totalSize, 26));
  130. if (usedSize > 1024 * 1024 * 1024 || totalSize > 1024 * 1024 * 1024)
  131. m_textNANDStorage.setString(_("%.1f/%.1f GB", static_cast<float>(usedSize) / 1024.f / 1024.f / 1024.f, static_cast<float>(totalSize) / 1024.f / 1024.f / 1024.f));
  132. else if (usedSize > 1024 * 1024 || totalSize > 1024 * 1024)
  133. m_textNANDStorage.setString(_("%.1f/%.1f MB", static_cast<float>(usedSize) / 1024.f / 1024.f, static_cast<float>(totalSize) / 1024.f / 1024.f));
  134. else
  135. m_textNANDStorage.setString(_("%d/%d KB", usedSize / 1024, totalSize / 1024));
  136. } else {
  137. m_textNANDStorage.setString("No TWL NAND detected... Wait what ?!");
  138. }
  139. #else
  140. m_textSDStorage.setString("16/32 GB");
  141. m_progressBarSD.setSize(cpp3ds::Vector2f(300, 26));
  142. m_textNANDStorage.setString("200/400 MB");
  143. m_progressBarNAND.setSize(cpp3ds::Vector2f(150, 26));
  144. #endif
  145. }
  146. } // namespace FreeShop