DatStatus.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include <DatSubsystems/DatStatus.h>
  2. #include <DatFile.h>
  3. #include <math.h>
  4. namespace LOTRO_DAT {
  5. bool equalOfftoTwoDecimalPoints(double x, double y) {
  6. return int(std::floor((x * 100.0) + .5) / 100.0) == int(std::floor((y * 100.0) + .5) / 100.0);
  7. }
  8. DatStatus::DatStatus(DatFile *datFilePtr) : dat(datFilePtr) {
  9. }
  10. void DatStatus::SetStatus(DatStatus::DAT_STATUS status) {
  11. status_ = status;
  12. }
  13. void DatStatus::SetFinishedParts(unsigned long long finished_parts) {
  14. finished_parts_ = finished_parts;
  15. if (!equalOfftoTwoDecimalPoints(GetPercentage(), percentage_)) {
  16. percentage_ = GetPercentage();
  17. for (Callback* func : callback_functions_) {
  18. (*func)(GetStatus(), GetPercentage(), GetFinishedParts(), GetTotalParts(), GetDebugMessage()); // evaluating callback functions, transfering all needed information.
  19. }
  20. }
  21. }
  22. void DatStatus::SetTotalParts(unsigned long long total_parts) {
  23. total_parts_ = total_parts;
  24. }
  25. void DatStatus::SetDebugMessage(const std::string &message) {
  26. debug_message_ = message;
  27. }
  28. DatStatus::DAT_STATUS DatStatus::GetStatus() {
  29. return status_;
  30. }
  31. double DatStatus::GetPercentage() {
  32. return total_parts_ != 0 ? double(finished_parts_) / double(total_parts_) : 0;
  33. }
  34. unsigned long long DatStatus::GetFinishedParts() {
  35. return finished_parts_;
  36. }
  37. unsigned long long DatStatus::GetTotalParts() {
  38. return total_parts_;
  39. }
  40. std::string DatStatus::GetDebugMessage() {
  41. return debug_message_;
  42. }
  43. void DatStatus::SetDefaultStatus() {
  44. debug_message_ = "";
  45. total_parts_ = 0;
  46. finished_parts_ = 0;
  47. status_ = E_FREE;
  48. }
  49. bool DatStatus::CheckIfNotPatched() {
  50. return dat->GetLocaleManager().patch_dict_.empty();
  51. }
  52. void DatStatus::AddStatusChangedCallbackFunction(Callback* func) {
  53. callback_functions_.insert(func);
  54. }
  55. void DatStatus::RemoveStatusChangedCallbackFunction(Callback* func) {
  56. callback_functions_.erase(func);
  57. }
  58. bool DatStatus::IsFunctionRegisteredAsCallback(Callback* func) {
  59. return callback_functions_.count(func);
  60. }
  61. void DatStatus::EraseAllCallbackFunctions() {
  62. callback_functions_.clear();
  63. }
  64. } // namespace LOTRO_DAT