Bläddra i källkod

fixed callbacks

develop
Robin Thoni 7 år sedan
förälder
incheckning
24de3aef40
1 ändrade filer med 12 tillägg och 5 borttagningar
  1. 12
    5
      src/Business/FreeFareTagBusiness.cpp

+ 12
- 5
src/Business/FreeFareTagBusiness.cpp Visa fil

53
 Result<MappedKeys> FreeFareTagBusiness::mapKeys(std::vector<std::string> keys, std::function<void(int, int)> cb)
53
 Result<MappedKeys> FreeFareTagBusiness::mapKeys(std::vector<std::string> keys, std::function<void(int, int)> cb)
54
 {
54
 {
55
     MappedKeys mappedKeys;
55
     MappedKeys mappedKeys;
56
+    int done = 0;
57
+    int total = 16 * keys.size();
56
 
58
 
57
     for (int i = 0; i < 16; ++i) {
59
     for (int i = 0; i < 16; ++i) {
58
         std::pair<std::string, std::string> blockKeys;
60
         std::pair<std::string, std::string> blockKeys;
65
                 blockKeys.second = key;
67
                 blockKeys.second = key;
66
             }
68
             }
67
             if (cb != 0) {
69
             if (cb != 0) {
68
-                cb((i * keys.size()) + k + 1, 16 * keys.size());
70
+                cb(++done, total);
69
             }
71
             }
70
             if (!blockKeys.first.empty() && !blockKeys.second.empty()) {
72
             if (!blockKeys.first.empty() && !blockKeys.second.empty()) {
71
                 break;
73
                 break;
73
         }
75
         }
74
         mappedKeys.push_back(blockKeys);
76
         mappedKeys.push_back(blockKeys);
75
     }
77
     }
76
-    if (cb != 0) {
77
-        cb(16 * keys.size(), 16 * keys.size());
78
+    if (cb != 0 && done < total) {
79
+        cb(total, total);
78
     }
80
     }
79
 
81
 
80
     return Result<MappedKeys>::ok(mappedKeys);
82
     return Result<MappedKeys>::ok(mappedKeys);
85
     if (keys.size() != 16) {
87
     if (keys.size() != 16) {
86
         return Result<std::vector<SectorDbo>>::error("Must have 16 sectors");
88
         return Result<std::vector<SectorDbo>>::error("Must have 16 sectors");
87
     }
89
     }
90
+    int done = 0;
91
+    int total = 4 * keys.size();
88
     std::vector<SectorDbo> sectors;
92
     std::vector<SectorDbo> sectors;
89
     for (int s = 0; s < keys.size(); ++s) {
93
     for (int s = 0; s < keys.size(); ++s) {
90
         auto sectorKey = keys[s];
94
         auto sectorKey = keys[s];
111
             }
115
             }
112
             sector.setBlock(b, data);
116
             sector.setBlock(b, data);
113
             if (cb != 0) {
117
             if (cb != 0) {
114
-                cb((s * 4) + b + 1, keys.size() * 4);
118
+                cb(++done, total);
115
             }
119
             }
116
         }
120
         }
117
         int b = 3;
121
         int b = 3;
132
             }
136
             }
133
         }
137
         }
134
         if (cb != 0) {
138
         if (cb != 0) {
135
-            cb((s * 4) + b + 1, keys.size() * 4);
139
+            cb(++done, total);
136
         }
140
         }
137
 
141
 
138
         sector.setBlock(b, dataA);
142
         sector.setBlock(b, dataA);
153
 
157
 
154
         sectors.push_back(sector);
158
         sectors.push_back(sector);
155
     }
159
     }
160
+    if (cb != 0 && done < total) {
161
+        cb(total, total);
162
+    }
156
 
163
 
157
     return Result<std::vector<SectorDbo>>::ok(sectors);
164
     return Result<std::vector<SectorDbo>>::ok(sectors);
158
 }
165
 }

Laddar…
Avbryt
Spara