12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- #include <DatSubsystems/DatStatus.h>
- #include <DatFile.h>
- #include <math.h>
- namespace LOTRO_DAT {
- bool equalOfftoTwoDecimalPoints(double x, double y) {
- return int(std::floor((x * 100.0) + .5) / 100.0) == int(std::floor((y * 100.0) + .5) / 100.0);
- }
- DatStatus::DatStatus(DatFile *datFilePtr) : dat(datFilePtr) {
- }
- void DatStatus::SetStatus(DatStatus::DAT_STATUS status) {
- status_ = status;
- }
-
- void DatStatus::SetFinishedParts(unsigned long long finished_parts) {
- finished_parts_ = finished_parts;
- if (!equalOfftoTwoDecimalPoints(GetPercentage(), percentage_)) {
- percentage_ = GetPercentage();
- for (Callback* func : callback_functions_) {
- (*func)(GetStatus(), GetPercentage(), GetFinishedParts(), GetTotalParts(), GetDebugMessage()); // evaluating callback functions, transfering all needed information.
- }
- }
- }
- void DatStatus::SetTotalParts(unsigned long long total_parts) {
- total_parts_ = total_parts;
- }
- void DatStatus::SetDebugMessage(const std::string &message) {
- debug_message_ = message;
- }
- DatStatus::DAT_STATUS DatStatus::GetStatus() {
- return status_;
- }
- double DatStatus::GetPercentage() {
- return total_parts_ != 0 ? double(finished_parts_) / double(total_parts_) : 0;
- }
- unsigned long long DatStatus::GetFinishedParts() {
- return finished_parts_;
- }
- unsigned long long DatStatus::GetTotalParts() {
- return total_parts_;
- }
- std::string DatStatus::GetDebugMessage() {
- return debug_message_;
- }
-
- void DatStatus::SetDefaultStatus() {
- debug_message_ = "";
- total_parts_ = 0;
- finished_parts_ = 0;
- status_ = E_FREE;
- }
- bool DatStatus::CheckIfNotPatched() {
- return dat->GetLocaleManager().patch_dict_.empty();
- }
- void DatStatus::AddStatusChangedCallbackFunction(Callback* func) {
- callback_functions_.insert(func);
- }
- void DatStatus::RemoveStatusChangedCallbackFunction(Callback* func) {
- callback_functions_.erase(func);
- }
- bool DatStatus::IsFunctionRegisteredAsCallback(Callback* func) {
- return callback_functions_.count(func);
- }
- void DatStatus::EraseAllCallbackFunctions() {
- callback_functions_.clear();
- }
- } // namespace LOTRO_DAT
|