Skip to content

Commit 682fb3e

Browse files
authored
Merge pull request #312 from virxkane/zip64-postfix
ZIP64 fixes & other...
2 parents b30cdc1 + 2040a15 commit 682fb3e

10 files changed

Lines changed: 469 additions & 193 deletions

File tree

cr3wx/src/view.cpp

Lines changed: 61 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -307,33 +307,73 @@ void cr3view::OnTimer(wxTimerEvent& event)
307307
}
308308
}
309309

310-
void cr3view::Paint()
310+
static bool getBatteryState(int& state, int& chargingConn, int& level)
311311
{
312-
//printf("cr3view::Paint() \n");
313-
int battery_state = -1;
314312
#ifdef _WIN32
313+
// update battery state
315314
SYSTEM_POWER_STATUS bstatus;
316315
BOOL pow = GetSystemPowerStatus(&bstatus);
317-
if (bstatus.BatteryFlag & 128)
318-
pow = FALSE;
319-
if (bstatus.ACLineStatus!=0 || bstatus.BatteryLifePercent==255)
320-
pow = FALSE;
321-
if ( pow )
322-
battery_state = bstatus.BatteryLifePercent;
316+
if (pow) {
317+
state = CR_BATTERY_STATE_DISCHARGING;
318+
if (bstatus.BatteryFlag & 128)
319+
state = CR_BATTERY_STATE_NO_BATTERY; // no system battery
320+
else if (bstatus.BatteryFlag & 8)
321+
state = CR_BATTERY_STATE_CHARGING; // charging
322+
chargingConn = CR_BATTERY_CHARGER_NO;
323+
if (bstatus.ACLineStatus==1)
324+
chargingConn = CR_BATTERY_CHARGER_AC; // AC power charging connected
325+
if (bstatus.BatteryLifePercent>=0 && bstatus.BatteryLifePercent<=100)
326+
level = bstatus.BatteryLifePercent;
327+
return true;
328+
}
329+
return false;
323330
#else
324-
if ( ::wxGetPowerType() == wxPOWER_BATTERY ) {
325-
int n = ::wxGetBatteryState();
326-
if ( n == wxBATTERY_NORMAL_STATE )
327-
battery_state = 100;
328-
else if ( n == wxBATTERY_LOW_STATE )
329-
battery_state = 50;
330-
else if ( n == wxBATTERY_CRITICAL_STATE )
331-
battery_state = 0;
332-
else if ( n == wxBATTERY_SHUTDOWN_STATE )
333-
battery_state = 0;
334-
};
331+
wxPowerType wxpwrtype = wxGetPowerType();
332+
switch (wxpwrtype) {
333+
case wxPOWER_SOCKET:
334+
state = CR_BATTERY_STATE_CHARGING;
335+
chargingConn = CR_BATTERY_CHARGER_AC;
336+
break;
337+
case wxPOWER_BATTERY:
338+
state = CR_BATTERY_STATE_DISCHARGING;
339+
chargingConn = CR_BATTERY_CHARGER_NO;
340+
break;
341+
default:
342+
state = CR_BATTERY_STATE_NO_BATTERY;
343+
chargingConn = CR_BATTERY_CHARGER_NO;
344+
break;
345+
}
346+
wxBatteryState wxbatstate = wxGetBatteryState();
347+
switch (wxbatstate) {
348+
case wxBATTERY_NORMAL_STATE:
349+
level = 100;
350+
break;
351+
case wxBATTERY_LOW_STATE:
352+
level = 50;
353+
break;
354+
case wxBATTERY_CRITICAL_STATE:
355+
level = 5;
356+
break;
357+
case wxBATTERY_SHUTDOWN_STATE:
358+
level = 0;
359+
break;
360+
default:
361+
level = 0;
362+
break;
363+
}
364+
return true;
335365
#endif
336-
getDocView()->setBatteryState( battery_state );
366+
}
367+
368+
void cr3view::Paint()
369+
{
370+
//printf("cr3view::Paint() \n");
371+
int battery_state;
372+
int charging_conn;
373+
int charge_level;
374+
if (getBatteryState(battery_state, charging_conn, charge_level)) {
375+
getDocView()->setBatteryState( battery_state, charging_conn, charge_level );
376+
}
337377
//_docview->Draw();
338378
UpdateScrollBar();
339379
Refresh( FALSE );

crengine/Tools/blend-algo-test/blend_over_gray_test.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,11 @@ int main() {
165165
// build input test file
166166
printf("Preparing data (random)... ");
167167
fflush(stdout);
168+
#ifdef _WIN32
169+
srand(time(0));
170+
#else
168171
srandom(time(0));
172+
#endif
169173
int* test_inp_data = (int*)malloc(TEST_POINTS_COUNT*sizeof(int));
170174
int* test_alpha_data = (int*)malloc(TEST_POINTS_COUNT*sizeof(int));
171175
int* test_color_data = (int*)malloc(TEST_POINTS_COUNT*sizeof(int));
@@ -175,13 +179,19 @@ int main() {
175179
}
176180
long j;
177181
for (j = 0; j < TEST_POINTS_COUNT; j++) {
182+
#ifdef _WIN32
183+
test_inp_data[j] = (int)(300L*rand()/RAND_MAX);
184+
test_alpha_data[j] = (int)(300L*rand()/RAND_MAX);
185+
test_color_data[j] = (int)(300L*rand()/RAND_MAX);
186+
#else
178187
test_inp_data[j] = (int)(300L*random()/RAND_MAX);
188+
test_alpha_data[j] = (int)(300L*random()/RAND_MAX);
189+
test_color_data[j] = (int)(300L*random()/RAND_MAX);
190+
#endif
179191
if (test_inp_data[j] > 255)
180192
test_inp_data[j] = 255;
181-
test_alpha_data[j] = (int)(300L*random()/RAND_MAX);
182193
if (test_alpha_data[j] > 255)
183194
test_alpha_data[j] = 255;
184-
test_color_data[j] = (int)(300L*random()/RAND_MAX);
185195
if (test_color_data[j] > 255)
186196
test_color_data[j] = 255;
187197
}

crengine/Tools/blend-algo-test/blend_over_rgb_test.c

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,11 @@ int main() {
203203
// build input test file
204204
printf("Preparing data (random)... ");
205205
fflush(stdout);
206+
#ifdef _WIN32
207+
srand(time(0));
208+
#else
206209
srandom(time(0));
210+
#endif
207211
uint32_t* test_inp_data = (uint32_t*)malloc(TEST_POINTS_COUNT*sizeof(int));
208212
uint32_t* test_color_data = (uint32_t*)malloc(TEST_POINTS_COUNT*sizeof(int));
209213
int* test_alpha_r_data = (int*)malloc(TEST_POINTS_COUNT*sizeof(int));
@@ -216,34 +220,49 @@ int main() {
216220
long j;
217221
long r, g, b;
218222
for (j = 0; j < TEST_POINTS_COUNT; j++) {
223+
#ifdef _WIN32
224+
r = 300L*rand()/RAND_MAX;
225+
g = 300L*rand()/RAND_MAX;
226+
b = 300L*rand()/RAND_MAX;
227+
test_alpha_r_data[j] = (int)(300L*rand()/RAND_MAX);
228+
test_alpha_g_data[j] = (int)(300L*rand()/RAND_MAX);
229+
test_alpha_b_data[j] = (int)(300L*rand()/RAND_MAX);
230+
#else
219231
r = 300L*random()/RAND_MAX;
232+
g = 300L*random()/RAND_MAX;
233+
b = 300L*random()/RAND_MAX;
234+
test_alpha_r_data[j] = (int)(300L*random()/RAND_MAX);
235+
test_alpha_g_data[j] = (int)(300L*random()/RAND_MAX);
236+
test_alpha_b_data[j] = (int)(300L*random()/RAND_MAX);
237+
#endif
220238
if (r > 255)
221239
r = 255;
222-
g = 300L*random()/RAND_MAX;
223240
if (g > 255)
224241
g = 255;
225-
b = 300L*random()/RAND_MAX;
226242
if (b > 255)
227243
b = 255;
228244
test_inp_data[j] = (uint32_t)((r << 16) | (g << 8) | b);
229245

230-
test_alpha_r_data[j] = (int)(300L*random()/RAND_MAX);
231246
if (test_alpha_r_data[j] > 255)
232247
test_alpha_r_data[j] = 255;
233-
test_alpha_g_data[j] = (int)(300L*random()/RAND_MAX);
234248
if (test_alpha_g_data[j] > 255)
235249
test_alpha_g_data[j] = 255;
236-
test_alpha_b_data[j] = (int)(300L*random()/RAND_MAX);
237250
if (test_alpha_b_data[j] > 255)
238251
test_alpha_b_data[j] = 255;
239252

253+
#ifdef _WIN32
254+
r = 300L*rand()/RAND_MAX;
255+
g = 300L*rand()/RAND_MAX;
256+
b = 300L*rand()/RAND_MAX;
257+
#else
240258
r = 300L*random()/RAND_MAX;
259+
g = 300L*random()/RAND_MAX;
260+
b = 300L*random()/RAND_MAX;
261+
#endif
241262
if (r > 255)
242263
r = 255;
243-
g = 300L*random()/RAND_MAX;
244264
if (g > 255)
245265
g = 255;
246-
b = 300L*random()/RAND_MAX;
247266
if (b > 255)
248267
b = 255;
249268
test_color_data[j] = (uint32_t)((r << 16) | (g << 8) | b);

crengine/Tools/zip-test/main.cpp

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
int main(int argc, char* argv[])
1111
{
1212
const char* fname;
13+
const char* inner_fname = 0;
1314
if (argc > 1) {
1415
fname = argv[1];
16+
if (argc > 2)
17+
inner_fname = argv[2];
1518
} else {
1619
printf("You must specify path to archive!\n");
1720
return 1;
@@ -22,16 +25,17 @@ int main(int argc, char* argv[])
2225

2326
lString32Collection list;
2427
LVStreamRef stream = LVOpenFileStream( fname, LVOM_READ );
28+
LVContainerRef arc;
2529
if ( !stream.isNull() ) {
26-
LVContainerRef arc = LVOpenArchieve(stream);
30+
arc = LVOpenArchieve(stream);
2731
if ( !arc.isNull() ) {
2832
// convert
2933
for ( int i=0; i<arc->GetObjectCount(); i++ ) {
3034
const LVContainerItemInfo * item = arc->GetObjectInfo(i);
3135
if ( item->IsContainer())
3236
continue;
3337
list.add( item->GetName() );
34-
list.add( lString32::itoa(item->GetSize()) );
38+
list.add( lString32::itoa((lUInt64)item->GetSize()) );
3539
}
3640
} else {
3741
printf("Failed to open archive!\n");
@@ -42,11 +46,54 @@ int main(int argc, char* argv[])
4246
return 1;
4347
}
4448

49+
#if 0
50+
if (!arc.isNull()) {
51+
if (NULL != inner_fname) {
52+
printf("Open file inside archive...\n");
53+
lString32 inner_fname32 = LocalToUnicode(lString8(inner_fname));
54+
LVStreamRef inner_stream = arc->OpenStream(inner_fname32.c_str(), LVOM_READ);
55+
if (!inner_stream.isNull()) {
56+
printf(" ok\n");
57+
LVStreamRef out_stream = LVOpenFileStream(inner_fname32.c_str(), LVOM_WRITE);
58+
if (!out_stream.isNull()) {
59+
printf("output file opened...\n");
60+
lUInt8 buff[4096];
61+
lvsize_t ReadSize;
62+
lvsize_t WriteSize;
63+
while (true) {
64+
if (inner_stream->Read(buff, 4096, &ReadSize) != LVERR_OK) {
65+
printf("Read error!\n");
66+
break;
67+
}
68+
if (0 == ReadSize) {
69+
break;
70+
}
71+
if (out_stream->Write(buff, ReadSize, &WriteSize) != LVERR_OK) {
72+
printf("Write error!\n");
73+
break;
74+
}
75+
}
76+
} else {
77+
printf("Failed top open output file!\n");
78+
}
79+
} else {
80+
printf(" failed\n");
81+
}
82+
} else {
83+
printf("Inner filename must be specified from command line!\n");
84+
}
85+
}
86+
#endif
87+
88+
#if 1
4589
printf("Archive contents:\n");
4690
for (int i = 0; i < list.length()/2; i++) {
4791
lString32 name = list[i*2];
48-
int size = lString32(list[i*2+1]).atoi();
49-
printf(" %s: %u\n", LCSTR(name), size);
92+
lInt64 size;
93+
if (!list[i*2+1].atoi(size))
94+
size = 0;
95+
printf(" %s: %lld\n", LCSTR(name), size);
5096
}
97+
#endif
5198
return 0;
5299
}

crengine/include/lvcommoncontaineriteminfo.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ class LVCommonContainerItemInfo : public LVContainerItemInfo
3232
lString32 m_name;
3333
lUInt32 m_flags;
3434
bool m_is_container;
35-
lUInt32 m_srcpos;
36-
lUInt32 m_srcsize;
35+
lvpos_t m_srcpos;
36+
lvsize_t m_srcsize;
3737
lUInt32 m_srcflags;
3838
public:
3939
virtual lvsize_t GetSize() const { return m_size; }
4040
virtual const lChar32 * GetName() const { return m_name.empty()?NULL:m_name.c_str(); }
4141
virtual lUInt32 GetFlags() const { return m_flags; }
4242
virtual bool IsContainer() const { return m_is_container; }
43-
lUInt32 GetSrcPos() { return m_srcpos; }
44-
lUInt32 GetSrcSize() { return m_srcsize; }
43+
lvpos_t GetSrcPos() { return m_srcpos; }
44+
lvsize_t GetSrcSize() { return m_srcsize; }
4545
lUInt32 GetSrcFlags() { return m_srcflags; }
46-
void SetSrc( lUInt32 pos, lUInt32 size, lUInt32 flags )
46+
void SetSrc( lvpos_t pos, lvsize_t size, lUInt32 flags )
4747
{
4848
m_srcpos = pos;
4949
m_srcsize = size;

0 commit comments

Comments
 (0)