├── Fiew.exe ├── Fiew.sln ├── Fiew.suo ├── Fiew ├── Cacher.cpp ├── Cacher.h ├── Core.cpp ├── Core.h ├── Drawer.cpp ├── Drawer.h ├── Exp_Archive.cpp ├── Exp_File.cpp ├── Exp_Folder.cpp ├── Explorer.cpp ├── Explorer.h ├── Fiew.aps ├── Fiew.cpp ├── Fiew.h ├── Fiew.ico ├── Fiew.rc ├── Fiew.vcproj ├── Fiew.vcproj.NEKO.a0.user ├── Ftyper.cpp ├── Ftyper.h ├── FwCHAR.cpp ├── FwCHAR.h ├── Interface.cpp ├── Interface.h ├── Layer.cpp ├── Layer.h ├── Layer_Listlay.cpp ├── Layer_Overlay.cpp ├── Layer_Thumblay.cpp ├── List.h ├── OVL_EN │ ├── ovl_about.png │ └── ovl_manual.png ├── OVL_PL │ ├── ovl_about.png │ └── ovl_manual.png ├── ReadMe.txt ├── XUn.cpp ├── XUn.h ├── XUnrar.cpp ├── XUnrar.h ├── XUnzip.cpp ├── XUnzip.h ├── mid.ico ├── ovl_about.png ├── ovl_manual.png ├── resource.h ├── small.ico ├── stdafx.cpp ├── stdafx.h └── unrar.dll └── LICENSE /Fiew.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/f055/fiew-image-viewer/314e86cbfbb95527783e9071ed3c97a9cdc93497/Fiew.exe -------------------------------------------------------------------------------- /Fiew.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 9.00 3 | # Visual Studio 2005 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Fiew", "Fiew\Fiew.vcproj", "{399ABEA6-8FE9-4F2E-B760-F49852591C8B}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {399ABEA6-8FE9-4F2E-B760-F49852591C8B}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {399ABEA6-8FE9-4F2E-B760-F49852591C8B}.Debug|Win32.Build.0 = Debug|Win32 14 | {399ABEA6-8FE9-4F2E-B760-F49852591C8B}.Release|Win32.ActiveCfg = Release|Win32 15 | {399ABEA6-8FE9-4F2E-B760-F49852591C8B}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /Fiew.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/f055/fiew-image-viewer/314e86cbfbb95527783e9071ed3c97a9cdc93497/Fiew.suo -------------------------------------------------------------------------------- /Fiew/Cacher.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Core.h" 3 | 4 | Cell::Cell(File *file, byte *data) 5 | { 6 | this->file = file; 7 | this->thumb = NULL; 8 | this->stream = NULL; 9 | 10 | this->loadStream(data,this->file->getSize()); 11 | } 12 | 13 | Cell::Cell(File *file) 14 | { 15 | this->file = file; 16 | this->thumb = NULL; 17 | this->stream = NULL; 18 | 19 | #ifdef DISKCACHING 20 | HANDLE hFile = 21 | CreateFile(this->file->getFilePath()->toWCHAR(), 22 | GENERIC_READ, 23 | FILE_SHARE_READ, 24 | NULL, 25 | OPEN_EXISTING, 26 | FILE_ATTRIBUTE_NORMAL, 27 | NULL); 28 | 29 | if( hFile != INVALID_HANDLE_VALUE ){ 30 | byte *buffer = new byte[this->file->getSize()]; 31 | BOOL result = 0; 32 | DWORD read = 0; 33 | 34 | result = ReadFile(hFile,buffer,this->file->getSize(),&read,NULL); 35 | if( result && read == this->file->getSize() ) 36 | this->loadStream(buffer,read); 37 | 38 | delete [] buffer; 39 | } 40 | CloseHandle(hFile); 41 | #endif 42 | } 43 | 44 | Cell::~Cell() 45 | { 46 | if( this->thumb != NULL ) 47 | delete this->thumb; 48 | 49 | if( this->stream != NULL ) 50 | this->stream->Release(); 51 | } 52 | 53 | bool Cell::loadStream(byte *data, DWORD len) 54 | { 55 | #ifndef DISKCACHING 56 | if( this->file->isArchived() == false ) 57 | return false; 58 | #endif 59 | 60 | if( data == NULL || len < 1 ) 61 | return false; 62 | if( this->stream != NULL ) 63 | this->stream->Release(); 64 | 65 | HGLOBAL buffer = NULL; 66 | 67 | if( (buffer = GlobalAlloc(GPTR,len)) != NULL ) 68 | if( CreateStreamOnHGlobal(buffer,true,(LPSTREAM*)&this->stream) == S_OK ) 69 | if( this->stream->Write((void *)data,len,NULL) == S_OK ) 70 | return true; 71 | 72 | if( this->stream != NULL ) 73 | this->stream->Release(); 74 | this->stream = NULL; 75 | 76 | return false; 77 | } 78 | 79 | Cell *Cell::loadThumb(int load) 80 | { 81 | if( load == YES ) 82 | this->getImageThumb(); 83 | 84 | return this; 85 | } 86 | 87 | File *Cell::getFile() 88 | { 89 | return this->file; 90 | } 91 | 92 | Image *Cell::getImage() 93 | { 94 | #ifndef DISKCACHING 95 | if( this->file->isArchived() == false ) 96 | return Image::FromFile(this->file->getFilePath()->toWCHAR()); 97 | #endif 98 | 99 | if( this->stream != NULL ) 100 | return Image::FromStream(this->stream); 101 | return NULL; 102 | } 103 | 104 | Bitmap *Cell::getImageThumb(int width, int height) 105 | { 106 | Image *img = this->getImage(); 107 | 108 | if( img != NULL ){ 109 | Bitmap *thumb = new Bitmap(width,height); 110 | Graphics *gfx = Graphics::FromImage(thumb); 111 | 112 | gfx->DrawImage(img,0,0,width,height); 113 | 114 | delete gfx; 115 | delete img; 116 | 117 | return thumb; 118 | } 119 | return NULL; 120 | } 121 | Bitmap *Cell::getImageThumb() 122 | { 123 | if( this->thumb == NULL ){ 124 | Image *img = this->getImage(); 125 | 126 | if( img != NULL ){ 127 | this->thumb = new Bitmap(THB_SIZE,THB_SIZE); 128 | 129 | int frame = 1; 130 | Graphics *gfx = Graphics::FromImage(this->thumb); 131 | 132 | int iwidth = img->GetWidth(); 133 | int iheight = img->GetHeight(); 134 | int thbSize = THB_SIZE - 4*frame; 135 | 136 | if( iwidth > thbSize || iheight > thbSize ){ 137 | double dx = (double)thbSize / (double)iwidth; 138 | double dy = (double)thbSize / (double)iheight; 139 | 140 | iwidth = (int)(min(dx,dy) * iwidth); 141 | iheight = (int)(min(dx,dy) * iheight); 142 | } 143 | int x = max( (int)((thbSize - iwidth) / 2), 2*frame ); 144 | int y = max( (int)((thbSize - iheight) / 2), 2*frame ); 145 | 146 | gfx->DrawImage(img,x,y,iwidth,iheight); 147 | 148 | delete gfx; 149 | delete img; 150 | } 151 | } 152 | return this->thumb; 153 | } 154 | 155 | IStream *Cell::getStream() 156 | { 157 | return this->stream; 158 | } 159 | 160 | bool Cell::isLoaded() 161 | { 162 | #ifndef DISKCACHING 163 | if( this->file->isArchived() == false ) 164 | return true; 165 | #endif 166 | 167 | if( this->stream != NULL ) 168 | return true; 169 | return false; 170 | } 171 | 172 | /* *** */ 173 | 174 | Cacher::Cacher(Core *core) 175 | { 176 | this->mut_cache = NULL; 177 | this->mut_bool = CreateMutex(NULL,false,NULL); 178 | 179 | this->mut_initloop = NULL; 180 | this->mut_initterminator = NULL; 181 | 182 | this->mut_nextloop = NULL; 183 | this->mut_nextstep = NULL; 184 | this->mut_nextterminator = NULL; 185 | this->mut_prevloop = NULL; 186 | this->mut_prevstep = NULL; 187 | this->mut_prevterminator = NULL; 188 | 189 | this->thrd_init = NULL; 190 | this->thrd_next = NULL; 191 | this->thrd_prev = NULL; 192 | 193 | this->sem_nexts = NULL; 194 | this->sem_prevs = NULL; 195 | this->sem_nextlock = NULL; 196 | this->sem_prevlock = NULL; 197 | 198 | this->cache = new List(); 199 | this->core = core; 200 | this->full = NO; 201 | 202 | this->source = this->core->getExplorer()->getRoot(); 203 | this->init(); 204 | } 205 | 206 | Cacher::~Cacher() 207 | { 208 | if( WaitForSingleObject(this->mut_initloop,0) == WAIT_TIMEOUT ){ 209 | ReleaseMutex(this->mut_initterminator); 210 | WaitForSingleObject(this->mut_initloop,INFINITE); 211 | ReleaseMutex(this->mut_initloop); 212 | } 213 | if( WaitForSingleObject(this->mut_nextloop,0) == WAIT_TIMEOUT ){ 214 | ReleaseMutex(this->mut_nextterminator); 215 | ReleaseSemaphore(this->sem_nextlock,1,NULL); 216 | WaitForSingleObject(this->mut_nextloop,INFINITE); 217 | ReleaseMutex(this->mut_nextloop); 218 | } 219 | if( WaitForSingleObject(this->mut_prevloop,0) == WAIT_TIMEOUT ){ 220 | ReleaseMutex(this->mut_prevterminator); 221 | ReleaseSemaphore(this->sem_prevlock,1,NULL); 222 | WaitForSingleObject(this->mut_prevloop,INFINITE); 223 | ReleaseMutex(this->mut_prevloop); 224 | } 225 | 226 | if( this->mut_cache != NULL ) 227 | CloseHandle(this->mut_cache); 228 | if( this->mut_bool != NULL ) 229 | CloseHandle(this->mut_bool); 230 | 231 | if( this->mut_initloop != NULL ) 232 | CloseHandle(this->mut_initloop); 233 | if( this->mut_initterminator != NULL ) 234 | CloseHandle(this->mut_initterminator); 235 | 236 | if( this->mut_nextloop != NULL ) 237 | CloseHandle(this->mut_nextloop); 238 | if( this->mut_nextstep != NULL ) 239 | CloseHandle(this->mut_nextstep); 240 | if( this->mut_nextterminator != NULL ) 241 | CloseHandle(this->mut_nextterminator); 242 | 243 | if( this->mut_prevloop != NULL ) 244 | CloseHandle(this->mut_prevloop); 245 | if( this->mut_prevstep != NULL ) 246 | CloseHandle(this->mut_prevstep); 247 | if( this->mut_prevterminator != NULL ) 248 | CloseHandle(this->mut_prevterminator); 249 | 250 | if( this->sem_nexts != NULL ) 251 | CloseHandle(this->sem_nexts); 252 | if( this->sem_prevs != NULL ) 253 | CloseHandle(this->sem_prevs); 254 | if( this->sem_nextlock != NULL ) 255 | CloseHandle(this->sem_nextlock); 256 | if( this->sem_prevlock != NULL ) 257 | CloseHandle(this->sem_prevlock); 258 | 259 | if( this->thrd_init != NULL ) 260 | CloseHandle(this->thrd_init); 261 | if( this->thrd_next != NULL ) 262 | CloseHandle(this->thrd_next); 263 | if( this->thrd_prev != NULL ) 264 | CloseHandle(this->thrd_prev); 265 | 266 | delete this->cache; 267 | } 268 | 269 | void Cacher::init() 270 | { 271 | if( this->source == NULL ) 272 | return; 273 | if( this->source->getCount() <= 0 ){ 274 | this->source = NULL; 275 | return; 276 | } 277 | this->cache->add( this->source->load()->loadThumb(this->isFull()) ); 278 | 279 | this->mut_cache = CreateMutex(NULL,false,NULL); 280 | 281 | this->mut_initloop = CreateMutex(NULL,false,NULL); 282 | this->mut_initterminator = CreateMutex(NULL,true,NULL); 283 | 284 | this->mut_nextloop = CreateMutex(NULL,false,NULL); 285 | this->mut_nextstep = CreateMutex(NULL,false,NULL); 286 | this->mut_nextterminator = CreateMutex(NULL,true,NULL); 287 | 288 | this->mut_prevloop = CreateMutex(NULL,false,NULL); 289 | this->mut_prevstep = CreateMutex(NULL,false,NULL); 290 | this->mut_prevterminator = CreateMutex(NULL,true,NULL); 291 | 292 | this->sem_nexts = CreateSemaphore(NULL,0,INT_MAX,NULL); 293 | this->sem_prevs = CreateSemaphore(NULL,0,INT_MAX,NULL); 294 | this->sem_nextlock = CreateSemaphore(NULL,0,1,NULL); 295 | this->sem_prevlock = CreateSemaphore(NULL,0,1,NULL); 296 | 297 | this->thrd_init = CreateThread(NULL,NULL, 298 | (LPTHREAD_START_ROUTINE)&Cacher::initAlloc, 299 | this,NULL,NULL); 300 | 301 | this->thrd_next = CreateThread(NULL,NULL, 302 | (LPTHREAD_START_ROUTINE)&Cacher::nextAlloc, 303 | this,NULL,NULL); 304 | this->thrd_prev = CreateThread(NULL,NULL, 305 | (LPTHREAD_START_ROUTINE)&Cacher::prevAlloc, 306 | this,NULL,NULL); 307 | } 308 | 309 | DWORD WINAPI Cacher::initAlloc(LPVOID param) 310 | { 311 | Cacher *that = (Cacher *)param; 312 | 313 | int count = 0; 314 | bool rNext = true; 315 | bool rPrev = true; 316 | Cell *tmp = NULL; 317 | 318 | WaitForSingleObject(that->mut_initloop,INFINITE); 319 | while( count < CACHE_SIZE || that->isFull() != NO ){ 320 | if( WaitForSingleObject(that->mut_initterminator,0) != WAIT_TIMEOUT ){ 321 | ReleaseMutex(that->mut_initterminator); 322 | ReleaseMutex(that->mut_initloop); 323 | return 0; 324 | } 325 | if( rNext == true ) 326 | if( (rNext = that->getSource()->next(RIGHT)) == true ){ 327 | WaitForSingleObject(that->mut_cache,INFINITE); 328 | 329 | if( (tmp = that->getSource()->load(RIGHT)) != NULL ) 330 | if( that->getCache()->add( tmp->loadThumb(that->isFull()) ) ) 331 | ReleaseSemaphore(that->sem_nexts,1,NULL); 332 | 333 | ReleaseMutex(that->mut_cache); 334 | } 335 | if( rPrev == true ) 336 | if( (rPrev = that->getSource()->prev(LEFT)) == true ){ 337 | WaitForSingleObject(that->mut_cache,INFINITE); 338 | 339 | if( (tmp = that->getSource()->load(LEFT)) != NULL ) 340 | if( that->getCache()->addToHead( tmp->loadThumb(that->isFull()) ) ) 341 | ReleaseSemaphore(that->sem_prevs,1,NULL); 342 | 343 | that->cache; 344 | ReleaseMutex(that->mut_cache); 345 | } 346 | if( rNext == false && rPrev == false ) 347 | break; 348 | that->cache; 349 | count++; 350 | } 351 | ReleaseMutex(that->mut_initloop); 352 | 353 | return 0; 354 | } 355 | DWORD WINAPI Cacher::nextAlloc(LPVOID param) 356 | { 357 | Cacher *that = (Cacher *)param; 358 | Cell *tmp = NULL; 359 | 360 | WaitForSingleObject(that->mut_nextloop,INFINITE); 361 | while( true ){ 362 | WaitForSingleObject(that->sem_nextlock,INFINITE); 363 | 364 | int count = 0; 365 | WaitForSingleObject(that->mut_nextstep,INFINITE); 366 | while( count < CACHE_SIZE || that->isFull() != NO ){ 367 | if( WaitForSingleObject(that->mut_nextterminator,0) != WAIT_TIMEOUT ){ 368 | ReleaseMutex(that->mut_nextterminator); 369 | ReleaseMutex(that->mut_nextloop); 370 | return 0; 371 | } 372 | WaitForSingleObject(that->mut_cache,INFINITE); 373 | if( that->getSource()->next(RIGHT) ){ 374 | if( (tmp = that->getSource()->load(RIGHT)) != NULL ) 375 | if( that->getCache()->add( tmp->loadThumb(that->isFull()) ) ) 376 | ReleaseSemaphore(that->sem_nexts,1,NULL); 377 | 378 | ReleaseMutex(that->mut_cache); 379 | } 380 | else { 381 | ReleaseMutex(that->mut_cache); 382 | break; 383 | } 384 | count++; 385 | } 386 | ReleaseMutex(that->mut_nextstep); 387 | } 388 | ReleaseMutex(that->mut_nextloop); 389 | return 0; 390 | } 391 | DWORD WINAPI Cacher::prevAlloc(LPVOID param) 392 | { 393 | Cacher *that = (Cacher *)param; 394 | Cell *tmp = NULL; 395 | 396 | WaitForSingleObject(that->mut_prevloop,INFINITE); 397 | while( true ){ 398 | WaitForSingleObject(that->sem_prevlock,INFINITE); 399 | 400 | int count = 0; 401 | WaitForSingleObject(that->mut_prevstep,INFINITE); 402 | while( count < CACHE_SIZE || that->isFull() != NO ){ 403 | if( WaitForSingleObject(that->mut_prevterminator,0) != WAIT_TIMEOUT ){ 404 | ReleaseMutex(that->mut_prevterminator); 405 | ReleaseMutex(that->mut_prevloop); 406 | return 0; 407 | } 408 | WaitForSingleObject(that->mut_cache,INFINITE); 409 | if( that->getSource()->prev(LEFT) ){ 410 | if( (tmp = that->getSource()->load(LEFT)) != NULL ) 411 | if( that->getCache()->addToHead( tmp->loadThumb(that->isFull()) ) ) 412 | ReleaseSemaphore(that->sem_prevs,1,NULL); 413 | 414 | ReleaseMutex(that->mut_cache); 415 | } 416 | else { 417 | ReleaseMutex(that->mut_cache); 418 | break; 419 | } 420 | count++; 421 | } 422 | ReleaseMutex(that->mut_prevstep); 423 | } 424 | ReleaseMutex(that->mut_prevloop); 425 | return 0; 426 | } 427 | 428 | Catalog *Cacher::getSource() 429 | { 430 | return this->source; 431 | } 432 | 433 | List *Cacher::getCache() 434 | { 435 | return this->cache; 436 | } 437 | 438 | void Cacher::setFull(bool val, bool thumbs) 439 | { 440 | WaitForSingleObject(this->mut_bool,INFINITE); 441 | if( val == true && thumbs == true ) 442 | this->full = YES; 443 | if( val == true && thumbs == false ) 444 | this->full = NOTHUMBS; 445 | if( val == false ) 446 | this->full = NO; 447 | ReleaseMutex(this->mut_bool); 448 | 449 | this->unlockNext(); 450 | this->unlockPrev(); 451 | } 452 | int Cacher::isFull() 453 | { 454 | WaitForSingleObject(this->mut_bool,INFINITE); 455 | int val = this->full; 456 | ReleaseMutex(this->mut_bool); 457 | 458 | return val; 459 | } 460 | 461 | bool Cacher::isRunning() 462 | { 463 | bool result = false; 464 | 465 | if( WaitForSingleObject(this->mut_initloop,0) == WAIT_TIMEOUT ) 466 | result = true; 467 | else 468 | ReleaseMutex(this->mut_initloop); 469 | 470 | if( WaitForSingleObject(this->mut_nextstep,0) == WAIT_TIMEOUT ) 471 | result = true; 472 | else 473 | ReleaseMutex(this->mut_nextstep); 474 | 475 | if( WaitForSingleObject(this->mut_prevstep,0) == WAIT_TIMEOUT ) 476 | result = true; 477 | else 478 | ReleaseMutex(this->mut_prevstep); 479 | 480 | return result; 481 | } 482 | 483 | bool Cacher::next() 484 | { 485 | bool result = false; 486 | 487 | if( this->getSource() == NULL ) 488 | return result; 489 | 490 | WaitForSingleObject(this->mut_cache,INFINITE); 491 | if( this->getSource()->isThatTail() == true ){ 492 | ReleaseMutex(this->mut_cache); 493 | return result; 494 | } 495 | ReleaseMutex(this->mut_cache); 496 | 497 | WaitForSingleObject(this->sem_nexts,INFINITE); 498 | ReleaseSemaphore(this->sem_prevs,1,NULL); 499 | 500 | WaitForSingleObject(this->mut_cache,INFINITE); 501 | if( (result = this->getCache()->next()) == true ) 502 | this->getSource()->next(); 503 | this->unlockNext(); 504 | ReleaseMutex(this->mut_cache); 505 | 506 | return result; 507 | } 508 | bool Cacher::prev() 509 | { 510 | bool result = false; 511 | 512 | if( this->getSource() == NULL ) 513 | return result; 514 | 515 | WaitForSingleObject(this->mut_cache,INFINITE); 516 | if( this->getSource()->isThatHead() == true ){ 517 | ReleaseMutex(this->mut_cache); 518 | return result; 519 | } 520 | ReleaseMutex(this->mut_cache); 521 | 522 | WaitForSingleObject(this->sem_prevs,INFINITE); 523 | ReleaseSemaphore(this->sem_nexts,1,NULL); 524 | 525 | WaitForSingleObject(this->mut_cache,INFINITE); 526 | if( (result = this->getCache()->prev()) ) 527 | this->getSource()->prev(); 528 | this->unlockPrev(); 529 | ReleaseMutex(this->mut_cache); 530 | 531 | return result; 532 | } 533 | 534 | Cell *Cacher::getThat() 535 | { 536 | Cell *tmp = NULL; 537 | 538 | WaitForSingleObject(this->mut_cache,INFINITE); 539 | tmp = this->getCache()->getThat(); 540 | ReleaseMutex(this->mut_cache); 541 | 542 | if( tmp != NULL ) 543 | return tmp; 544 | return NULL; 545 | } 546 | 547 | Image *Cacher::getThatImage() 548 | { 549 | Cell *tmp = this->getThat(); 550 | 551 | if( tmp != NULL ) 552 | return tmp->getImage(); 553 | return NULL; 554 | } 555 | Image *Cacher::getThatThumb(int width, int height) 556 | { 557 | Cell *tmp = this->getThat(); 558 | 559 | if( tmp != NULL ) 560 | return tmp->getImageThumb(width,height); 561 | return NULL; 562 | } 563 | 564 | void Cacher::unlockNext() 565 | { 566 | if( WaitForSingleObject(this->mut_initloop,0) != WAIT_TIMEOUT ){ 567 | ReleaseMutex(this->mut_initloop); 568 | if( WaitForSingleObject(this->mut_nextstep,0) != WAIT_TIMEOUT ){ 569 | ReleaseMutex(this->mut_nextstep); 570 | if( this->getCache()->countRightoThat() < CACHE_LIMIT || this->isFull() != NO ) 571 | ReleaseSemaphore(this->sem_nextlock,1,NULL); 572 | } 573 | if( WaitForSingleObject(this->mut_prevstep,0) != WAIT_TIMEOUT ){ 574 | ReleaseMutex(this->mut_prevstep); 575 | int size = 0; 576 | if( (size = this->getCache()->countLeftoThat()) > CACHE_SIZE && 577 | this->isFull() == NO ){ 578 | 579 | size -= CACHE_SIZE; 580 | for( int i = 0; i < size; i++ ){ 581 | delete this->getCache()->removeHead(); 582 | this->getSource()->next(LEFT); 583 | } 584 | } 585 | } 586 | } 587 | } 588 | void Cacher::unlockPrev() 589 | { 590 | if( WaitForSingleObject(this->mut_initloop,0) != WAIT_TIMEOUT ){ 591 | ReleaseMutex(this->mut_initloop); 592 | if( WaitForSingleObject(this->mut_prevstep,0) != WAIT_TIMEOUT ){ 593 | ReleaseMutex(this->mut_prevstep); 594 | if( this->getCache()->countLeftoThat() < CACHE_LIMIT || this->isFull() != NO ) 595 | ReleaseSemaphore(this->sem_prevlock,1,NULL); 596 | } 597 | if( WaitForSingleObject(this->mut_nextstep,0) != WAIT_TIMEOUT ){ 598 | ReleaseMutex(this->mut_nextstep); 599 | int size = 0; 600 | if( (size = this->getCache()->countRightoThat()) > CACHE_SIZE && 601 | this->isFull() == NO ){ 602 | 603 | size -= CACHE_SIZE; 604 | for( int i = 0; i < size; i++ ){ 605 | delete this->getCache()->removeTail(); 606 | this->getSource()->prev(RIGHT); 607 | } 608 | } 609 | } 610 | } 611 | } 612 | 613 | void Cacher::lockCache() 614 | { 615 | WaitForSingleObject(this->mut_cache,INFINITE); 616 | } 617 | void Cacher::unlockCache() 618 | { 619 | ReleaseMutex(this->mut_cache); 620 | } 621 | 622 | void Cacher::gotoCell(Cell *cell) 623 | { 624 | if( cell == NULL ) 625 | return; 626 | 627 | this->lockCache(); 628 | 629 | int i, count = 0; 630 | Cell *left, *right; 631 | 632 | do { 633 | left = this->getCache()->getLeftoThat(count); 634 | right = this->getCache()->getRightoThat(count); 635 | 636 | if( right == NULL && left == NULL ){ 637 | count = 0; 638 | break; 639 | } 640 | if( left == cell ){ 641 | count = -count; 642 | break; 643 | } 644 | if( right == cell ) 645 | break; 646 | 647 | count++; 648 | } while( true ); 649 | 650 | this->unlockCache(); 651 | 652 | if( count < 0 ) 653 | for( i = 0; i > count; i-- ) 654 | this->prev(); 655 | if( count > 0 ) 656 | for( i = 0; i < count; i++ ) 657 | this->next(); 658 | } -------------------------------------------------------------------------------- /Fiew/Cacher.h: -------------------------------------------------------------------------------- 1 | class FwCHAR; 2 | 3 | class Catalog; 4 | class File; 5 | 6 | using namespace Gdiplus; 7 | 8 | class Cell 9 | { 10 | private: 11 | File *file; 12 | Bitmap *thumb; 13 | IStream *stream; 14 | 15 | public: 16 | Cell(File *file, byte *data); 17 | Cell(File *file); 18 | ~Cell(); 19 | 20 | File *getFile(); 21 | Image *getImage(); 22 | Bitmap *getImageThumb(); 23 | Bitmap *getImageThumb(int width, int height); 24 | IStream *getStream(); 25 | 26 | bool isLoaded(); 27 | 28 | Cell *loadThumb(int load); 29 | 30 | private: 31 | bool loadStream(byte *data, DWORD len); 32 | }; 33 | 34 | class Cacher 35 | { 36 | private: 37 | List *cache; 38 | Catalog *source; 39 | Core *core; 40 | 41 | int full; 42 | 43 | protected: 44 | HANDLE mut_cache, mut_bool; 45 | 46 | HANDLE mut_initloop, mut_initterminator; 47 | HANDLE mut_nextloop, mut_nextstep, mut_nextterminator; 48 | HANDLE mut_prevloop, mut_prevstep, mut_prevterminator; 49 | 50 | HANDLE thrd_init, thrd_next, thrd_prev; 51 | 52 | HANDLE sem_nexts, sem_prevs, sem_nextlock, sem_prevlock; 53 | 54 | public: 55 | Cacher(Core *core); 56 | ~Cacher(); 57 | 58 | void init(); 59 | 60 | Catalog *getSource(); 61 | List *getCache(); 62 | 63 | void setFull(bool val, bool thumbs = true); 64 | int isFull(); 65 | bool isRunning(); 66 | 67 | bool next(); 68 | bool prev(); 69 | Cell *getThat(); 70 | Image *getThatImage(); 71 | Image *getThatThumb(int width, int height); 72 | 73 | void unlockNext(); 74 | void unlockPrev(); 75 | 76 | void lockCache(); 77 | void unlockCache(); 78 | 79 | void gotoCell(Cell *cell); 80 | 81 | static DWORD WINAPI initAlloc(LPVOID param); 82 | static DWORD WINAPI nextAlloc(LPVOID param); 83 | static DWORD WINAPI prevAlloc(LPVOID param); 84 | }; -------------------------------------------------------------------------------- /Fiew/Core.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Core.h" 3 | 4 | HMODULE Core::rarDll = NULL; 5 | 6 | Core::Core(WCHAR *cmdLine, HINSTANCE instance) 7 | { 8 | this->instance = instance; 9 | this->windowHandle = NULL; 10 | this->commandLine = NULL; 11 | this->loadDlls(); 12 | 13 | this->explorer = new Explorer(this); 14 | 15 | this->cacher = NULL; 16 | this->drawer = NULL; 17 | this->gui = NULL; 18 | 19 | if( cmdLine != NULL ){ 20 | this->commandLine = new FwCHAR(cmdLine); 21 | if( this->commandLine->toLength() < 3 ) 22 | this->commandLine = NULL; 23 | } 24 | 25 | this->initialized = false; 26 | } 27 | 28 | Core::~Core() 29 | { 30 | this->destroy(); 31 | } 32 | 33 | void Core::destroy() 34 | { 35 | KillTimer(this->windowHandle,TIMER_MBB); 36 | KillTimer(this->windowHandle,TIMER_MCH); 37 | KillTimer(this->windowHandle,TIMER_MMM); 38 | KillTimer(this->windowHandle,TIMER_OVL); 39 | KillTimer(this->windowHandle,TIMER_THB); 40 | 41 | if( this->drawer != NULL ) 42 | delete this->drawer; 43 | this->drawer = NULL; 44 | 45 | if( this->cacher != NULL ) 46 | delete this->cacher; 47 | this->cacher = NULL; 48 | 49 | if( this->explorer != NULL ) 50 | delete this->explorer; 51 | this->explorer = NULL; 52 | 53 | if( this->gui != NULL ) 54 | delete this->gui; 55 | this->gui = NULL; 56 | 57 | if( this->commandLine != NULL ) 58 | //delete this->commandLine; 59 | this->commandLine = NULL; 60 | 61 | this->freeDlls(); 62 | } 63 | 64 | HMODULE Core::getRarDll() 65 | { 66 | return Core::rarDll; 67 | } 68 | 69 | void Core::getLastError() 70 | { 71 | TCHAR szBuf[80]; 72 | LPVOID lpMsgBuf; 73 | DWORD dw = GetLastError(); 74 | 75 | FormatMessage( 76 | FORMAT_MESSAGE_ALLOCATE_BUFFER | 77 | FORMAT_MESSAGE_FROM_SYSTEM, 78 | NULL, 79 | dw, 80 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 81 | (LPTSTR) &lpMsgBuf, 82 | 0, NULL ); 83 | 84 | wsprintf(szBuf,L"Failed with error %d: %s",dw,lpMsgBuf); 85 | 86 | return; 87 | } 88 | 89 | void Core::initialize(HWND windowHandle) 90 | { 91 | this->windowHandle = windowHandle; 92 | 93 | this->gui = new Interface(this); 94 | this->drawer = new Drawer(this); 95 | this->drawer->reset(); 96 | 97 | this->open(this->commandLine); 98 | 99 | this->initialized = true; 100 | } 101 | 102 | bool Core::open(FwCHAR *path) 103 | { 104 | bool result = false; 105 | 106 | if( path == NULL ) 107 | return result; 108 | if( path->toWCHAR() == NULL ) 109 | return result; 110 | path->stripBraces(); 111 | 112 | this->gui->setMessage(MESSAGE_PROCESS); 113 | this->gui->setCursor(CURSOR_WAIT); 114 | if( this->explorer->browse(path) ){ 115 | if( this->cacher != NULL ) 116 | delete this->cacher; 117 | this->cacher = new Cacher(this); 118 | 119 | this->drawer->reset(); 120 | 121 | result = true; 122 | } 123 | this->gui->setCursor(CURSOR_CLIENT); 124 | this->gui->update(); 125 | 126 | return result; 127 | } 128 | bool Core::open(WCHAR *path) 129 | { 130 | if( path == NULL ) 131 | return false; 132 | 133 | FwCHAR *tmp = new FwCHAR(path); 134 | return this->open(tmp); 135 | } 136 | 137 | void Core::extract() 138 | { 139 | bool result = false; 140 | 141 | this->gui->setMessage(MESSAGE_EXTRACT); 142 | this->gui->setCursor(CURSOR_WAIT); 143 | result = this->explorer->extract(); 144 | this->gui->setCursor(CURSOR_CLIENT); 145 | this->gui->updateText(); 146 | 147 | if( result == false ) 148 | this->messageBox_Error(MESSAGE_EXTRACTERROR); 149 | else 150 | this->messageBox_Info(MESSAGE_EXTRACTEDIMAGE); 151 | } 152 | 153 | void Core::setwall() 154 | { 155 | bool result = false; 156 | 157 | this->gui->setMessage(MESSAGE_PROCESS); 158 | this->gui->setCursor(CURSOR_WAIT); 159 | result = this->drawer->getScene()->setWall(); 160 | this->gui->setCursor(CURSOR_CLIENT); 161 | this->gui->updateText(); 162 | 163 | if( result == false ) 164 | this->messageBox_Error(MESSAGE_SETWALLERROR); 165 | else 166 | this->messageBox_Info(MESSAGE_SETWALLEDIMAGE); 167 | } 168 | 169 | void Core::close() 170 | { 171 | if( this->cacher != NULL ) 172 | delete this->cacher; 173 | this->cacher = NULL; 174 | 175 | this->drawer->reset(); 176 | this->explorer->reset(); 177 | this->gui->update(); 178 | } 179 | 180 | bool Core::extractResource(WORD id, WCHAR *filename) 181 | { 182 | bool result = false; 183 | 184 | HRSRC hResource = FindResource(NULL, MAKEINTRESOURCE(id), RC_DLL); 185 | if( hResource != NULL ){ 186 | HGLOBAL hLoader = LoadResource(NULL,hResource); 187 | if( hLoader != NULL ){ 188 | byte *data = (byte *)LockResource(hLoader); 189 | DWORD len = SizeofResource(NULL,hResource); 190 | 191 | if( data != NULL && len > 0 ){ 192 | HANDLE hFile = CreateFile(filename, 193 | GENERIC_READ | GENERIC_WRITE, 194 | 0, 195 | NULL, 196 | CREATE_ALWAYS, 197 | FILE_ATTRIBUTE_NORMAL, 198 | NULL); 199 | if( hFile != INVALID_HANDLE_VALUE ){ 200 | DWORD written = 0; 201 | 202 | int write = WriteFile(hFile, 203 | data, 204 | len, 205 | &written, 206 | NULL); 207 | if( len == written && write == TRUE ) 208 | result = true; 209 | } 210 | CloseHandle(hFile); 211 | } 212 | UnlockResource(hLoader); 213 | } 214 | FreeResource(hLoader); 215 | } 216 | return result; 217 | } 218 | 219 | void Core::loadDlls() 220 | { 221 | Core::rarDll = LoadLibrary(RARDLL); 222 | if( Core::rarDll == NULL ) 223 | if( this->extractResource(IDR_DLLRAR,RARDLL) ) 224 | Core::rarDll = LoadLibrary(RARDLL); 225 | } 226 | 227 | void Core::freeDlls() 228 | { 229 | if( Core::rarDll != NULL ) 230 | FreeLibrary( Core::rarDll ); 231 | Core::rarDll = NULL; 232 | } 233 | 234 | int Core::getEncoder(WCHAR* format, CLSID* pClsid) 235 | { 236 | UINT num = 0; 237 | UINT size = 0; 238 | 239 | ImageCodecInfo* pImageCodecInfo = NULL; 240 | 241 | GetImageEncodersSize(&num, &size); 242 | if(size == 0) 243 | return -1; 244 | 245 | pImageCodecInfo = (ImageCodecInfo*)(malloc(size)); 246 | if(pImageCodecInfo == NULL) 247 | return -1; 248 | 249 | GetImageEncoders(num, size, pImageCodecInfo); 250 | 251 | for(UINT j = 0; j < num; ++j) 252 | { 253 | if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 ) 254 | { 255 | *pClsid = pImageCodecInfo[j].Clsid; 256 | free(pImageCodecInfo); 257 | return j; 258 | } 259 | } 260 | free(pImageCodecInfo); 261 | return -1; 262 | } 263 | 264 | HWND Core::getWindowHandle() 265 | { 266 | return this->windowHandle; 267 | } 268 | HINSTANCE Core::getInstance() 269 | { 270 | return this->instance; 271 | } 272 | 273 | Interface *Core::getGui() 274 | { 275 | return this->gui; 276 | } 277 | 278 | Explorer *Core::getExplorer() 279 | { 280 | return this->explorer; 281 | } 282 | 283 | Cacher *Core::getCacher() 284 | { 285 | return this->cacher; 286 | } 287 | 288 | Drawer *Core::getDrawer() 289 | { 290 | return this->drawer; 291 | } 292 | 293 | void Core::messageBox_Info(WCHAR *string) 294 | { 295 | MessageBox(this->windowHandle,string,MESSAGE_INFO,MB_OK | MB_ICONINFORMATION); 296 | } 297 | void Core::messageBox_Error(WCHAR *string) 298 | { 299 | MessageBox(this->windowHandle,string,MESSAGE_ERROR,MB_OK | MB_ICONERROR); 300 | } 301 | 302 | LRESULT Core::processMessages(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 303 | { 304 | int wmId, wmEvent; 305 | PAINTSTRUCT ps; 306 | HDC hdc; 307 | 308 | Graphics *gfx; 309 | 310 | if( this->initialized == false ){ 311 | switch (message) 312 | { 313 | case WM_CREATE: 314 | SetTimer(hWnd,TIMER_INT,INIT_TOUT,NULL); 315 | break; 316 | case WM_TIMER: 317 | KillTimer(hWnd,wParam); 318 | if( wParam == TIMER_INT ) 319 | this->initialize(hWnd); 320 | break; 321 | case WM_PAINT: 322 | hdc = BeginPaint(hWnd, &ps); 323 | 324 | gfx = Graphics::FromHDC(hdc); 325 | gfx->Clear(CLR_WHITE); 326 | delete gfx; 327 | 328 | EndPaint(hWnd, &ps); 329 | break; 330 | case WM_DESTROY: 331 | this->destroy(); 332 | PostQuitMessage(0); 333 | break; 334 | default: 335 | return DefWindowProc(hWnd, message, wParam, lParam); 336 | } 337 | return 0; 338 | } 339 | switch (message) 340 | { 341 | case WM_CREATE: 342 | this->initialize(hWnd); 343 | break; 344 | case WM_DROPFILES: 345 | this->gui->openDropFile(wParam); 346 | break; 347 | case WM_TIMER: 348 | if( wParam != TIMER_MMM ) 349 | KillTimer(hWnd,wParam); 350 | switch(wParam){ 351 | case TIMER_MBB: 352 | this->gui->unblockMBB(); 353 | break; 354 | case TIMER_MCH: 355 | this->gui->setCursor(); 356 | break; 357 | case TIMER_OVL: 358 | this->drawer->hideOverlay(); 359 | this->gui->updateMenu(); 360 | break; 361 | case TIMER_THB: 362 | this->drawer->updateOverlay(); 363 | break; 364 | case TIMER_MMM: 365 | this->gui->movemMM(); 366 | break; 367 | } 368 | break; 369 | case WM_COMMAND: 370 | wmId = LOWORD(wParam); 371 | wmEvent = HIWORD(wParam); 372 | 373 | switch (wmId) 374 | { 375 | default: 376 | this->gui->processMenu(wmId); 377 | return DefWindowProc(hWnd, message, wParam, lParam); 378 | } 379 | break; 380 | case WM_KEYDOWN: 381 | case WM_KEYUP: 382 | this->gui->processKeys(message,wParam,lParam); 383 | break; 384 | case WM_LBUTTONDOWN: 385 | case WM_LBUTTONUP: 386 | case WM_MBUTTONDOWN: 387 | case WM_MBUTTONUP: 388 | case WM_RBUTTONDOWN: 389 | case WM_RBUTTONUP: 390 | case WM_MOUSEWHEEL: 391 | case WM_MOUSEMOVE: 392 | this->gui->processMouse(message,wParam,lParam); 393 | break; 394 | case WM_NCHITTEST: 395 | return this->gui->processMouseState(lParam, 396 | DefWindowProc(hWnd,message,wParam,lParam)); 397 | break; 398 | case WM_PAINT: 399 | hdc = BeginPaint(hWnd, &ps); 400 | this->drawer->paint(hdc); 401 | EndPaint(hWnd, &ps); 402 | break; 403 | //case WM_ACTIVATEAPP: 404 | case WM_SIZE: 405 | if( this->drawer != NULL ) 406 | this->drawer->invalidate(); 407 | case WM_ERASEBKGND: 408 | return 1; 409 | case WM_DESTROY: 410 | this->destroy(); 411 | PostQuitMessage(0); 412 | break; 413 | default: 414 | return DefWindowProc(hWnd, message, wParam, lParam); 415 | } 416 | return 0; 417 | } -------------------------------------------------------------------------------- /Fiew/Core.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "FwCHAR.h" 4 | #include "List.h" 5 | #include "XUn.h" 6 | 7 | #include "Interface.h" 8 | #include "Explorer.h" 9 | #include "Cacher.h" 10 | #include "Layer.h" 11 | #include "Drawer.h" 12 | 13 | class Core 14 | { 15 | private: 16 | HWND windowHandle; 17 | HINSTANCE instance; 18 | 19 | Interface *gui; 20 | Explorer *explorer; 21 | Cacher *cacher; 22 | Drawer *drawer; 23 | 24 | FwCHAR *commandLine; 25 | 26 | bool initialized; 27 | 28 | static HMODULE rarDll; 29 | 30 | public: 31 | Core(WCHAR *cmdLine, HINSTANCE instance); 32 | ~Core(); 33 | 34 | LRESULT processMessages(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); 35 | 36 | HWND getWindowHandle(); 37 | HINSTANCE getInstance(); 38 | 39 | Interface *getGui(); 40 | Explorer *getExplorer(); 41 | Cacher *getCacher(); 42 | Drawer *getDrawer(); 43 | 44 | bool open(FwCHAR *path); 45 | bool open(WCHAR *path); 46 | void extract(); 47 | void setwall(); 48 | void close(); 49 | 50 | void messageBox_Info(WCHAR *string); 51 | void messageBox_Error(WCHAR *string); 52 | 53 | static HMODULE getRarDll(); 54 | static void getLastError(); 55 | static int getEncoder(WCHAR* format, CLSID* pClsid); 56 | 57 | private: 58 | void initialize(HWND windowHandle); 59 | bool extractResource(WORD id, WCHAR *filename); 60 | 61 | void loadDlls(); 62 | void freeDlls(); 63 | 64 | void destroy(); 65 | }; -------------------------------------------------------------------------------- /Fiew/Drawer.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Core.h" 3 | 4 | Drawer::Drawer(Core *core) 5 | { 6 | this->core = core; 7 | this->layers = NULL; 8 | this->fulldraw = true; 9 | 10 | this->scene = NULL; 11 | this->overlay = NULL; 12 | this->thumblay = NULL; 13 | this->listlay = NULL; 14 | 15 | this->visAbout = false; 16 | this->visManual = false; 17 | this->visThumbs = false; 18 | this->visList = false; 19 | } 20 | 21 | Drawer::~Drawer() 22 | { 23 | delete this->layers; 24 | } 25 | 26 | void Drawer::paint(HDC hdc) 27 | { 28 | Graphics *gfx = Graphics::FromHDC(hdc); 29 | 30 | int count = this->layers->getCount(); 31 | Layer *lay = NULL; 32 | Bitmap *bmp = NULL; 33 | 34 | if( count > 1 && this->fulldraw == true ){ 35 | RECT client = this->getClientSize(); 36 | Bitmap *scene = new Bitmap(client.right,client.bottom); 37 | Graphics *scenegfx = Graphics::FromImage(scene); 38 | 39 | this->layers->gotoHead(); 40 | do { 41 | lay = this->layers->getThat(); 42 | if( lay != NULL ) 43 | bmp = lay->render(); 44 | if( bmp != NULL ){ 45 | scenegfx->DrawImage(bmp, 46 | Rect(lay->getX(),lay->getY(), 47 | lay->getWidth(),lay->getHeight()), 48 | 0,0,bmp->GetWidth(),bmp->GetHeight(), 49 | UnitPixel); 50 | delete bmp; 51 | } 52 | bmp = NULL; 53 | lay = NULL; 54 | } while( this->layers->next() == true ); 55 | 56 | gfx->DrawImage(scene,0,0,scene->GetWidth(),scene->GetHeight()); 57 | 58 | delete scenegfx; 59 | delete scene; 60 | } 61 | else if( count == 1 || this->fulldraw == false ){ 62 | lay = this->getTopmost(); 63 | if( lay != NULL ) 64 | bmp = lay->render(); 65 | if( bmp != NULL ){ 66 | gfx->DrawImage(bmp, 67 | Rect(lay->getX(),lay->getY(), 68 | lay->getWidth(),lay->getHeight()), 69 | 0,0,bmp->GetWidth(),bmp->GetHeight(), 70 | UnitPixel); 71 | delete bmp; 72 | } 73 | bmp = NULL; 74 | } 75 | else { 76 | gfx->Clear(CLR_FRAME_DARK); 77 | } 78 | delete gfx; 79 | 80 | this->fulldraw = true; 81 | } 82 | 83 | void Drawer::reset() 84 | { 85 | this->hideOverlay(false); 86 | 87 | if( this->layers != NULL ) 88 | delete this->layers; 89 | this->layers = new List(); 90 | 91 | this->scene = new Layer(this->core); 92 | this->overlay = NULL; 93 | this->thumblay = NULL; 94 | this->listlay = NULL; 95 | 96 | this->layers->add(this->scene); 97 | } 98 | 99 | Layer *Drawer::getTopmost() 100 | { 101 | return this->layers->getTail(); 102 | } 103 | Layer *Drawer::getScene() 104 | { 105 | if( this->scene != NULL ) 106 | if( this->scene->isContent() ) 107 | return this->scene; 108 | return NULL; 109 | } 110 | Overlay *Drawer::getOverlay() 111 | { 112 | if( this->overlay != NULL ) 113 | if( this->overlay->isContent() ) 114 | return (Overlay *)this->overlay; 115 | return NULL; 116 | } 117 | Thumblay *Drawer::getThumblay() 118 | { 119 | if( this->visThumbs == true ) 120 | return this->thumblay; 121 | return NULL; 122 | } 123 | Listlay *Drawer::getListlay() 124 | { 125 | if( this->visList == true ) 126 | return this->listlay; 127 | return NULL; 128 | } 129 | 130 | RECT Drawer::getClientSize() 131 | { 132 | RECT client; 133 | client.left = client.right = 0; 134 | client.top = client.bottom = 0; 135 | 136 | if( this->getTopmost() != NULL ) 137 | return this->getTopmost()->getClientSize(); 138 | return client; 139 | } 140 | 141 | void Drawer::updateOverlay() 142 | { 143 | if( this->visThumbs == true ) 144 | this->getThumblay()->update(); 145 | if( this->visList == true ) 146 | this->getListlay()->update(); 147 | } 148 | 149 | void Drawer::hideOverlay(bool invalid) 150 | { 151 | if( this->overlay != NULL ){ 152 | if( invalid == false ) 153 | this->overlay->setCancel(); 154 | this->layers->remove(this->overlay); 155 | 156 | if( this->overlay->isCancel() == false ){ 157 | if( this->visThumbs == true || this->visList == true ){ 158 | this->getScene()->loadContent(); 159 | if( this->core->getCacher() != NULL ) 160 | this->core->getCacher()->setFull(false); 161 | if( this->core->getGui() != NULL ) 162 | this->core->getGui()->updateText(); 163 | } 164 | } 165 | else { 166 | if( this->visThumbs == true ){ 167 | if( this->core->getCacher() != NULL ){ 168 | Cell *last = this->getThumblay()->getLastCell(); 169 | this->core->getCacher()->gotoCell(last); 170 | this->core->getCacher()->setFull(false); 171 | } 172 | } 173 | if( this->visList == true ){ 174 | if( this->core->getCacher() != NULL ){ 175 | Cell *last = this->getListlay()->getLastCell(); 176 | this->core->getCacher()->gotoCell(last); 177 | this->core->getCacher()->setFull(false); 178 | } 179 | } 180 | } 181 | delete this->overlay; 182 | } 183 | else 184 | invalid = false; 185 | 186 | this->overlay = NULL; 187 | this->thumblay = NULL; 188 | this->listlay = NULL; 189 | 190 | this->visAbout = false; 191 | this->visManual = false; 192 | this->visThumbs = false; 193 | this->visList = false; 194 | 195 | if( invalid == true ){ 196 | if( this->core->getGui() != NULL ){ 197 | this->core->getGui()->updateText(); 198 | this->core->getGui()->setCursor(CURSOR_CLIENT); 199 | } 200 | this->invalidate(); 201 | } 202 | } 203 | 204 | void Drawer::showAbout() 205 | { 206 | if( this->visAbout == false ){ 207 | this->hideOverlay(false); 208 | this->overlay = 209 | new Overlay(this->core,this->loadImageResource(IDR_ABOUT,RC_PNG)); 210 | this->layers->add(this->overlay); 211 | this->visAbout = true; 212 | } 213 | else { 214 | this->hideOverlay(false); 215 | this->visAbout = false; 216 | } 217 | this->invalidate(); 218 | } 219 | void Drawer::showManual() 220 | { 221 | if( this->visManual == false ){ 222 | this->hideOverlay(false); 223 | this->overlay = 224 | new Overlay(this->core,this->loadImageResource(IDR_MANUAL,RC_PNG)); 225 | this->layers->add(this->overlay); 226 | this->visManual = true; 227 | } 228 | else { 229 | this->hideOverlay(false); 230 | this->visManual = false; 231 | } 232 | this->invalidate(); 233 | } 234 | void Drawer::showThumbs() 235 | { 236 | HCURSOR last = NULL; 237 | if( this->core->getGui() != NULL ) 238 | last = this->core->getGui()->setCursor(CURSOR_WAIT); 239 | 240 | if( this->visThumbs == false ){ 241 | this->hideOverlay(false); 242 | 243 | this->thumblay = 244 | new Thumblay(this->core,new Bitmap(1,1)); 245 | this->overlay = this->thumblay; 246 | 247 | this->layers->add(this->overlay); 248 | this->visThumbs = true; 249 | } 250 | else { 251 | this->hideOverlay(false); 252 | this->visThumbs = false; 253 | } 254 | this->invalidate(); 255 | 256 | if( this->core->getGui() != NULL ) 257 | this->core->getGui()->setCursor(last); 258 | } 259 | void Drawer::showList() 260 | { 261 | HCURSOR last = NULL; 262 | if( this->core->getGui() != NULL ) 263 | last = this->core->getGui()->setCursor(CURSOR_WAIT); 264 | 265 | if( this->visList == false ){ 266 | this->hideOverlay(false); 267 | 268 | this->listlay = 269 | new Listlay(this->core,new Bitmap(1,1)); 270 | this->overlay = this->listlay; 271 | 272 | this->layers->add(this->overlay); 273 | this->visList = true; 274 | } 275 | else { 276 | this->hideOverlay(false); 277 | this->visList = false; 278 | } 279 | this->invalidate(); 280 | 281 | if( this->core->getGui() != NULL ) 282 | this->core->getGui()->setCursor(last); 283 | } 284 | 285 | bool Drawer::isAbout() 286 | { 287 | return this->visAbout; 288 | } 289 | bool Drawer::isManual() 290 | { 291 | return this->visManual; 292 | } 293 | bool Drawer::isThumbs() 294 | { 295 | return this->visThumbs; 296 | } 297 | bool Drawer::isList() 298 | { 299 | return this->visList; 300 | } 301 | 302 | Image *Drawer::loadImageResource(WORD id, LPCWSTR type) 303 | { 304 | Image *img = NULL; 305 | 306 | HRSRC hResource = FindResource(NULL, MAKEINTRESOURCE(id), type); 307 | if( hResource != NULL ){ 308 | HGLOBAL hLoader = LoadResource(NULL,hResource); 309 | if( hLoader != NULL ){ 310 | byte *data = (byte *)LockResource(hLoader); 311 | DWORD len = SizeofResource(NULL,hResource); 312 | 313 | if( data != NULL && len > 0 ){ 314 | IStream *stream = NULL; 315 | HGLOBAL buffer = NULL; 316 | 317 | if( (buffer = GlobalAlloc(GPTR,len)) != NULL ) 318 | if( CreateStreamOnHGlobal(buffer,true,(LPSTREAM*)&stream) == S_OK ) 319 | if( stream->Write((void *)data,len,NULL) == S_OK ) 320 | img = Image::FromStream(stream); 321 | if( stream != NULL ) 322 | stream->Release(); 323 | } 324 | UnlockResource(hLoader); 325 | } 326 | FreeResource(hLoader); 327 | } 328 | return img; 329 | } 330 | 331 | void Drawer::setMenuheight(int val) 332 | { 333 | this->layers->gotoHead(); 334 | do { 335 | this->layers->getThat()->setMenuheight(val); 336 | } while( this->layers->next() ); 337 | 338 | this->getTopmost()->invalidate(); 339 | } 340 | 341 | void Drawer::invalidate(bool full) 342 | { 343 | this->fulldraw = full; 344 | InvalidateRect(this->core->getWindowHandle(),NULL,false); 345 | } -------------------------------------------------------------------------------- /Fiew/Drawer.h: -------------------------------------------------------------------------------- 1 | class Core; 2 | 3 | using namespace Gdiplus; 4 | 5 | class Drawer 6 | { 7 | private: 8 | Core *core; 9 | List *layers; 10 | Layer *scene, *overlay; 11 | Thumblay *thumblay; 12 | Listlay *listlay; 13 | 14 | bool fulldraw, visAbout, visManual, visThumbs, visList; 15 | 16 | public: 17 | Drawer(Core *core); 18 | ~Drawer(); 19 | 20 | void paint(HDC hdc); 21 | void reset(); 22 | 23 | Layer *getTopmost(); 24 | Layer *getScene(); 25 | Overlay *getOverlay(); 26 | Thumblay *getThumblay(); 27 | Listlay *getListlay(); 28 | RECT getClientSize(); 29 | 30 | void updateOverlay(); 31 | 32 | void hideOverlay(bool invalid = true); 33 | void showAbout(); 34 | void showManual(); 35 | void showThumbs(); 36 | void showList(); 37 | 38 | bool isAbout(); 39 | bool isManual(); 40 | bool isThumbs(); 41 | bool isList(); 42 | 43 | Image *loadImageResource(WORD id, LPCWSTR type); 44 | 45 | void setMenuheight(int val = 0); 46 | void invalidate(bool full = true); 47 | }; -------------------------------------------------------------------------------- /Fiew/Exp_Archive.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Core.h" 3 | 4 | Archive::Archive(FwCHAR *path, int type, DWORD size) : Catalog(path,type,size) 5 | { 6 | this->pack = NULL; 7 | this->unsortedFiles = NULL; 8 | 9 | this->sem_sorted = NULL; 10 | 11 | this->sorted = false; 12 | this->terminate = false; 13 | 14 | switch( type ){ 15 | case TYPE_RAR: 16 | this->pack = new XUnrar( path->toWCHAR() ); 17 | break; 18 | case TYPE_ZIP: 19 | this->pack = new XUnzip( path->toWCHAR() ); 20 | break; 21 | default: 22 | this->pack = new XUn( path->toWCHAR() ); 23 | break; 24 | } 25 | } 26 | 27 | Archive::~Archive() 28 | { 29 | if( WaitForSingleObject(this->mut_loop,0) == WAIT_TIMEOUT ){ 30 | this->terminate = true; 31 | ReleaseMutex(this->mut_terminator); 32 | WaitForSingleObject(this->mut_loop,INFINITE); 33 | } 34 | if( this->sem_sorted != NULL ) 35 | CloseHandle(this->sem_sorted); 36 | 37 | if( this->pack != NULL ) 38 | delete this->pack; 39 | if( this->unsortedFiles != NULL ) 40 | delete this->unsortedFiles; 41 | } 42 | 43 | void Archive::init(FwCHAR *thatpath) 44 | { 45 | if( this->pack->isLoaded() == true ){ 46 | this->unsortedFiles = new List(); 47 | this->pack->list(this->unsortedFiles); 48 | this->count = this->unsortedFiles->getCount(); 49 | } 50 | } 51 | 52 | List *Archive::getUnsortedFiles() 53 | { 54 | return this->unsortedFiles; 55 | } 56 | 57 | void Archive::setSorted() 58 | { 59 | this->sorted = true; 60 | } 61 | 62 | bool Archive::isSorted() 63 | { 64 | return this->sorted; 65 | } 66 | 67 | int Archive::getCount() 68 | { 69 | return this->count; 70 | } 71 | 72 | bool Archive::extract() 73 | { 74 | if( this->getCount() <= 0 ) 75 | return false; 76 | 77 | File *file = NULL; 78 | 79 | WaitForSingleObject(this->mut_list,INFINITE); 80 | file = this->getFiles()->getThat(); 81 | ReleaseMutex(this->mut_list); 82 | 83 | return this->extract(file); 84 | } 85 | bool Archive::extract(File *file) 86 | { 87 | if( this->getCount() <= 0 ) 88 | return false; 89 | 90 | if( file == NULL ) 91 | return false; 92 | 93 | FwCHAR *dest = new FwCHAR(); 94 | dest->getFolderFrom(this->filepath); 95 | dest->mergeWith(file->getFileName()); 96 | 97 | bool result = this->pack->extract(file,dest->toWCHAR()); 98 | 99 | delete dest; 100 | return result; 101 | } 102 | 103 | void Archive::list(Core *core) 104 | { 105 | if( this->getCount() <= 0 ) 106 | return; 107 | 108 | WaitForSingleObject(this->mut_step,INFINITE); 109 | if( this->isSorted() == false ){ 110 | ReleaseMutex(this->mut_step); 111 | WaitForSingleObject(this->sem_sorted,INFINITE); 112 | } 113 | else 114 | ReleaseMutex(this->mut_step); 115 | 116 | WaitForSingleObject(this->mut_list,INFINITE); 117 | if( this->sortSide == HEADSORT ) 118 | this->getFiles()->gotoHead(); 119 | else if( this->sortSide == TAILSORT ) 120 | this->getFiles()->gotoTail(); 121 | ReleaseMutex(this->mut_list); 122 | 123 | bool result = false; 124 | do { 125 | WaitForSingleObject(this->mut_step,INFINITE); 126 | if( this->isSorted() == false ){ 127 | ReleaseMutex(this->mut_step); 128 | WaitForSingleObject(this->sem_sorted,INFINITE); 129 | } 130 | else 131 | ReleaseMutex(this->mut_step); 132 | 133 | WaitForSingleObject(this->mut_list,INFINITE); 134 | core->messageBox_Info(this->getFiles()->getThat()->getFilePath()->toWCHAR()); 135 | 136 | if( this->sortSide == HEADSORT ) 137 | result = this->getFiles()->next(); 138 | else if( this->sortSide == TAILSORT ) 139 | result = this->getFiles()->prev(); 140 | ReleaseMutex(this->mut_list); 141 | } while( result ); 142 | } 143 | 144 | bool Archive::next(int id) 145 | { 146 | if( this->getCount() <= 0 ) 147 | return false; 148 | 149 | WaitForSingleObject(this->mut_step,INFINITE); 150 | if( this->isSorted() == false ){ 151 | ReleaseMutex(this->mut_step); 152 | if( this->sortSide == HEADSORT ) 153 | WaitForSingleObject(this->sem_sorted,INFINITE); 154 | } 155 | else 156 | ReleaseMutex(this->mut_step); 157 | 158 | WaitForSingleObject(this->mut_list,INFINITE); 159 | bool result = this->getFiles()->next(id); 160 | ReleaseMutex(this->mut_list); 161 | 162 | if( this->sortSide == TAILSORT && result == true ) 163 | ReleaseSemaphore(this->sem_sorted,1,NULL); 164 | 165 | if( result == true && id == NULL ) 166 | this->idx++; 167 | return result; 168 | } 169 | 170 | bool Archive::prev(int id) 171 | { 172 | if( this->getCount() <= 0 ) 173 | return false; 174 | 175 | WaitForSingleObject(this->mut_step,INFINITE); 176 | if( this->isSorted() == false ){ 177 | ReleaseMutex(this->mut_step); 178 | if( this->sortSide == TAILSORT ) 179 | WaitForSingleObject(this->sem_sorted,INFINITE); 180 | } 181 | else { 182 | ReleaseMutex(this->mut_step); 183 | } 184 | 185 | WaitForSingleObject(this->mut_list,INFINITE); 186 | bool result = this->getFiles()->prev(id); 187 | ReleaseMutex(this->mut_list); 188 | 189 | if( this->sortSide == HEADSORT && result == true ) 190 | ReleaseSemaphore(this->sem_sorted,1,NULL); 191 | 192 | if( result == true && id == NULL ) 193 | this->idx--; 194 | return result; 195 | } 196 | 197 | Cell *Archive::load(int id) 198 | { 199 | if( this->getCount() <= 0 ) 200 | return NULL; 201 | 202 | if( id == NULL ){ 203 | WaitForSingleObject(this->mut_step,INFINITE); 204 | if( this->isSorted() == false ){ 205 | ReleaseMutex(this->mut_step); 206 | WaitForSingleObject(this->sem_sorted,INFINITE); 207 | ReleaseSemaphore(this->sem_sorted,1,NULL); 208 | } 209 | else 210 | ReleaseMutex(this->mut_step); 211 | } 212 | 213 | WaitForSingleObject(this->mut_list,INFINITE); 214 | File *that = this->getFiles()->getThat(); 215 | if( id == LEFT ) 216 | that = this->getFiles()->getLeft(); 217 | else if( id == RIGHT ) 218 | that = this->getFiles()->getRight(); 219 | ReleaseMutex(this->mut_list); 220 | 221 | if( that == NULL ) 222 | return NULL; 223 | 224 | if( this->pack->extract(that) ){ 225 | Cell *cell = new Cell(that,this->pack->getBuffer()); 226 | this->pack->clearBuffer(); 227 | 228 | if( cell->isLoaded() ) 229 | return cell; 230 | } 231 | return NULL; 232 | } 233 | 234 | bool Archive::isThatHead() 235 | { 236 | bool result = false; 237 | 238 | if( this->getCount() < 2 ) 239 | return true; 240 | 241 | if( this->isSorted() == true ) 242 | result = this->getFiles()->isThatHead(); 243 | else if( this->sortSide == HEADSORT ){ 244 | WaitForSingleObject(this->mut_list,INFINITE); 245 | result = this->getFiles()->isThatHead(); 246 | ReleaseMutex(this->mut_list); 247 | } 248 | return result; 249 | } 250 | bool Archive::isThatTail() 251 | { 252 | bool result = false; 253 | 254 | if( this->getCount() < 2 ) 255 | return true; 256 | 257 | if( this->isSorted() == true ) 258 | result = this->getFiles()->isThatTail(); 259 | else if( this->sortSide == TAILSORT ){ 260 | WaitForSingleObject(this->mut_list,INFINITE); 261 | result = this->getFiles()->isThatTail(); 262 | ReleaseMutex(this->mut_list); 263 | } 264 | return result; 265 | } 266 | 267 | DWORD WINAPI Archive::sort(LPVOID param) 268 | { 269 | Archive *that = (Archive *)param; 270 | 271 | int result; 272 | List::Node *ext, *tmp; 273 | 274 | WaitForSingleObject(that->mut_loop,INFINITE); 275 | while( that->getUnsortedFiles()->getCount() > 0 ){ 276 | if( that->sortSide == HEADSORT ) 277 | ext = that->getUnsortedFiles()->getThatHead(); 278 | else if( that->sortSide == TAILSORT ) 279 | ext = that->getUnsortedFiles()->getThatTail(); 280 | tmp = ext->getNext(); 281 | 282 | while( tmp != NULL ){ 283 | if( WaitForSingleObject(that->mut_terminator,0) != WAIT_TIMEOUT ){ 284 | if( that->terminate == true ){ 285 | ReleaseMutex(that->mut_terminator); 286 | ReleaseMutex(that->mut_loop); 287 | return 0; 288 | } 289 | ReleaseMutex(that->mut_terminator); 290 | } 291 | 292 | result = FwCHAR::compare(ext->getObj()->getFilePath(), 293 | tmp->getObj()->getFilePath()); 294 | 295 | if( (result > 0 && that->sortSide == HEADSORT) || 296 | (result < 0 && that->sortSide == TAILSORT) ) 297 | ext = tmp; 298 | 299 | tmp = tmp->getNext(); 300 | } 301 | WaitForSingleObject(that->mut_list,INFINITE); 302 | that->getUnsortedFiles()->remove(ext); 303 | if( that->sortSide == HEADSORT ) 304 | that->getFiles()->add(ext); 305 | else if( that->sortSide == TAILSORT ) 306 | that->getFiles()->addToHead(ext); 307 | ReleaseMutex(that->mut_list); 308 | 309 | ReleaseSemaphore(that->sem_sorted,1,NULL); 310 | } 311 | ReleaseMutex(that->mut_loop); 312 | WaitForSingleObject(that->mut_step,INFINITE); 313 | that->setSorted(); 314 | ReleaseMutex(that->mut_step); 315 | return 0; 316 | } 317 | 318 | void Archive::initSort(int side) 319 | { 320 | if( this->isSorted() == true ) 321 | return; 322 | if( this->mut_loop != NULL ) 323 | if( WaitForSingleObject(this->mut_loop,0) == WAIT_TIMEOUT ) 324 | return; 325 | 326 | this->init(); 327 | if( this->pack->isLoaded() == false ) 328 | return; 329 | if( this->getCount() <= 0 ) 330 | return; 331 | 332 | this->sortSide = side; 333 | if( side == TAILSORT ) 334 | this->idx = this->getCount() - 1; 335 | 336 | Archive::sortStep(this); 337 | 338 | if( this->getCount() > 1 ){ 339 | this->mut_list = CreateMutex(NULL,false,NULL); 340 | this->mut_loop = CreateMutex(NULL,false,NULL); 341 | this->mut_step = CreateMutex(NULL,false,NULL); 342 | this->mut_terminator = CreateMutex(NULL,true,NULL); 343 | 344 | this->sem_sorted = CreateSemaphore(NULL,0,count,NULL); 345 | 346 | 347 | this->thrd_sorting = CreateThread(NULL,NULL, 348 | (LPTHREAD_START_ROUTINE)&Archive::sort, 349 | this,NULL,NULL); 350 | } 351 | else 352 | this->setSorted(); 353 | } 354 | 355 | DWORD WINAPI Archive::sortStep(LPVOID param) 356 | { 357 | Archive *that = (Archive *)param; 358 | 359 | int result; 360 | List::Node *ext, *tmp; 361 | 362 | if( that->sortSide == HEADSORT ) 363 | ext = that->getUnsortedFiles()->getThatHead(); 364 | else 365 | ext = that->getUnsortedFiles()->getThatTail(); 366 | if( ext == NULL ) 367 | return 0; 368 | 369 | tmp = ext->getNext(); 370 | 371 | while( tmp != NULL ){ 372 | result = FwCHAR::compare(ext->getObj()->getFilePath(), 373 | tmp->getObj()->getFilePath()); 374 | 375 | if( (result > 0 && that->sortSide == HEADSORT) || 376 | (result < 0 && that->sortSide == TAILSORT) ) 377 | ext = tmp; 378 | 379 | tmp = tmp->getNext(); 380 | } 381 | that->getUnsortedFiles()->remove(ext); 382 | if( that->sortSide == HEADSORT ) 383 | that->getFiles()->add(ext); 384 | else if( that->sortSide == TAILSORT ) 385 | that->getFiles()->addToHead(ext); 386 | 387 | return 0; 388 | } 389 | -------------------------------------------------------------------------------- /Fiew/Exp_File.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Core.h" 3 | 4 | File::File(FwCHAR *path, int type, DWORD size, bool archived) 5 | { 6 | this->filepath = path; 7 | 8 | this->filename = new FwCHAR(); 9 | this->filename->getFilenameFrom(this->filepath); 10 | 11 | this->size = size; 12 | this->archived = archived; 13 | 14 | if( type == UNDEFINED ) 15 | this->type = Explorer::getType(this->filepath); 16 | else 17 | this->type = type; 18 | 19 | this->mime = Explorer::getMime(this->type); 20 | } 21 | 22 | File::~File() 23 | { 24 | delete this->filepath; 25 | delete this->filename; 26 | } 27 | 28 | void File::initSort(int sort) 29 | { 30 | return; 31 | } 32 | 33 | FwCHAR *File::getFilePath() 34 | { 35 | return this->filepath; 36 | } 37 | 38 | FwCHAR *File::getFileName() 39 | { 40 | return this->filename; 41 | } 42 | 43 | int File::getType() 44 | { 45 | return this->type; 46 | } 47 | 48 | int File::getMime() 49 | { 50 | return this->mime; 51 | } 52 | 53 | DWORD File::getSize() 54 | { 55 | return this->size; 56 | } 57 | 58 | bool File::isArchived() 59 | { 60 | return this->archived; 61 | } -------------------------------------------------------------------------------- /Fiew/Exp_Folder.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Core.h" 3 | 4 | Catalog::Catalog(FwCHAR *path, int type, DWORD size) : File(path,type,size) 5 | { 6 | this->sortSide = HEADSORT; 7 | this->count = NULL; 8 | this->idx = NULL; 9 | 10 | this->mut_list = NULL; 11 | this->mut_loop = NULL; 12 | this->mut_step = NULL; 13 | this->mut_terminator = NULL; 14 | 15 | this->thrd_sorting = NULL; 16 | 17 | this->files = new List(); 18 | this->init(); 19 | } 20 | 21 | Catalog::Catalog(FwCHAR *path, FwCHAR *filepath, int type) : File(path,type) 22 | { 23 | this->sortSide = HEADSORT; 24 | this->count = NULL; 25 | this->idx = NULL; 26 | 27 | this->mut_list = NULL; 28 | this->mut_loop = NULL; 29 | this->mut_step = NULL; 30 | this->mut_terminator = NULL; 31 | 32 | this->thrd_sorting = NULL; 33 | 34 | this->files = new List(); 35 | this->init(filepath); 36 | } 37 | 38 | Catalog::~Catalog() 39 | { 40 | if( WaitForSingleObject(this->mut_loop,0) == WAIT_TIMEOUT ){ 41 | ReleaseMutex(this->mut_terminator); 42 | WaitForSingleObject(this->mut_loop,INFINITE); 43 | } 44 | if( this->mut_terminator != NULL ) 45 | CloseHandle(this->mut_terminator); 46 | if( this->mut_step != NULL ) 47 | CloseHandle(this->mut_step); 48 | if( this->mut_loop != NULL ) 49 | CloseHandle(this->mut_loop); 50 | if( this->mut_list != NULL ) 51 | CloseHandle(this->mut_list); 52 | 53 | if( this->thrd_sorting != NULL ) 54 | CloseHandle(this->thrd_sorting); 55 | 56 | delete this->files; 57 | } 58 | 59 | void Catalog::init(FwCHAR *thatpath) 60 | { 61 | if( this->getMime() == MIME_ARCHIVE ) 62 | return; 63 | 64 | WIN32_FIND_DATA FFdata; 65 | HANDLE hFind = INVALID_HANDLE_VALUE; 66 | 67 | FwCHAR *folder = new FwCHAR( this->getFilePath()->toWCHAR() ); 68 | folder->mergeWith(DIRMERGE); 69 | 70 | hFind = FindFirstFile(folder->toWCHAR(),&FFdata); 71 | 72 | if( hFind != INVALID_HANDLE_VALUE ){ 73 | File *that = NULL; 74 | FwCHAR *file = new FwCHAR(this->getFilePath()->toWCHAR() ); 75 | file->mergeWith(FFdata.cFileName); 76 | 77 | int type = Explorer::getType(file); 78 | int mime = Explorer::getMime(type); 79 | DWORD size = (FFdata.nFileSizeHigh * (MAXDWORD + 1)) + FFdata.nFileSizeLow; 80 | 81 | if( mime == MIME_IMAGE ) 82 | this->files->add( that = new File(file,type,size) ); 83 | else if( mime == MIME_ARCHIVE ) 84 | this->files->add( that = new Archive(file,type,size) ); 85 | else 86 | delete file; 87 | 88 | if( thatpath != NULL && that != NULL ){ 89 | if( that->getFilePath()->equals(thatpath) ) 90 | this->files->setThat(that); 91 | that = NULL; 92 | } 93 | while( FindNextFile(hFind,&FFdata) ){ 94 | file = new FwCHAR(this->getFilePath()->toWCHAR() ); 95 | file->mergeWith(FFdata.cFileName); 96 | 97 | type = Explorer::getType(file); 98 | mime = Explorer::getMime(type); 99 | size = (FFdata.nFileSizeHigh * (MAXDWORD + 1)) + FFdata.nFileSizeLow; 100 | 101 | if( mime == MIME_IMAGE ) 102 | this->files->add( that = new File(file,type,size) ); 103 | else if( mime == MIME_ARCHIVE ) 104 | this->files->add( that = new Archive(file,type,size) ); 105 | else 106 | delete file; 107 | 108 | if( thatpath != NULL && that != NULL ){ 109 | if( that->getFilePath()->equals(thatpath) ) 110 | this->files->setThat(that); 111 | that = NULL; 112 | } 113 | } 114 | FindClose(hFind); 115 | this->idx = this->files->countLeftoThat(); 116 | } 117 | delete folder; 118 | } 119 | 120 | int Catalog::getCount() 121 | { 122 | int count = 0; 123 | 124 | File *that = this->getFiles()->getThat(); 125 | if( that != NULL ) 126 | if( that->getMime() == MIME_ARCHIVE ) 127 | count = ((Archive *)that)->getCount(); 128 | if( count <= 0 ) 129 | count = this->getFiles()->getCount(); 130 | 131 | return count; 132 | } 133 | 134 | List *Catalog::getFiles() 135 | { 136 | return this->files; 137 | } 138 | 139 | int Catalog::getIdx() 140 | { 141 | int idx = this->idx; 142 | 143 | File *that = this->getFiles()->getThat(); 144 | if( that != NULL ) 145 | if( that->getMime() == MIME_ARCHIVE ) 146 | idx = ((Archive *)that)->getIdx(); 147 | 148 | return idx; 149 | } 150 | 151 | void Catalog::list(Core *core) 152 | { 153 | this->getFiles()->gotoHead(); 154 | do { 155 | core->messageBox_Info(this->getFiles()->getThat()->getFilePath()->toWCHAR()); 156 | } while( this->getFiles()->next() ); 157 | } 158 | 159 | DWORD WINAPI Catalog::trigSort(LPVOID param) 160 | { 161 | 162 | Catalog *that = (Catalog *)param; 163 | File *right = NULL; 164 | File *left = NULL; 165 | int count = 1; 166 | 167 | WaitForSingleObject(that->mut_loop,INFINITE); 168 | do { 169 | if( WaitForSingleObject(that->mut_terminator,0) != WAIT_TIMEOUT ){ 170 | ReleaseMutex(that->mut_terminator); 171 | ReleaseMutex(that->mut_loop); 172 | return 0; 173 | } 174 | WaitForSingleObject(that->mut_step,INFINITE); 175 | 176 | left = that->getFiles()->getLeftoThat(count); 177 | right = that->getFiles()->getRightoThat(count); 178 | 179 | if( left != NULL ) 180 | left->initSort(); 181 | if( right != NULL ) 182 | right->initSort(); 183 | count++; 184 | 185 | ReleaseMutex(that->mut_step); 186 | 187 | } while( left != NULL || right != NULL ); 188 | ReleaseMutex(that->mut_loop); 189 | 190 | return 0; 191 | } 192 | 193 | void Catalog::initSort(int sort) 194 | { 195 | 196 | this->mut_list = CreateMutex(NULL,false,NULL); 197 | this->mut_loop = CreateMutex(NULL,false,NULL); 198 | this->mut_step = CreateMutex(NULL,false,NULL); 199 | this->mut_terminator = CreateMutex(NULL,true,NULL); 200 | 201 | this->sortSide = sort; 202 | 203 | this->getFiles()->getThat()->initSort(sort); 204 | 205 | this->thrd_sorting = CreateThread(NULL,NULL, 206 | (LPTHREAD_START_ROUTINE)&Catalog::trigSort, 207 | this,NULL,NULL); 208 | 209 | } 210 | 211 | bool Catalog::next(int id) 212 | { 213 | if( this->getFiles()->getCount() <= 0 ) 214 | return false; 215 | 216 | this->sortSide = HEADSORT; 217 | 218 | File *that = this->getFiles()->getThat(); 219 | if( id == LEFT ) 220 | that = this->getFiles()->getLeft(); 221 | else if( id == RIGHT ) 222 | that = this->getFiles()->getRight(); 223 | bool result = false; 224 | 225 | if( that == NULL ) 226 | return result; 227 | 228 | if( that->getMime() == MIME_ARCHIVE ){ 229 | Archive *arch = (Archive *)that; 230 | result = arch->next(id); 231 | } 232 | if( result == false ) 233 | result = this->getFiles()->next(id); 234 | else 235 | return result; 236 | 237 | if( result == true && id == NULL ) 238 | this->idx++; 239 | 240 | return result; 241 | } 242 | 243 | bool Catalog::prev(int id) 244 | { 245 | if( this->getFiles()->getCount() <= 0 ) 246 | return false; 247 | 248 | this->sortSide = TAILSORT; 249 | 250 | File *that = this->getFiles()->getThat(); 251 | if( id == LEFT ) 252 | that = this->getFiles()->getLeft(); 253 | else if( id == RIGHT ) 254 | that = this->getFiles()->getRight(); 255 | bool result = false; 256 | 257 | if( that == NULL ) 258 | return result; 259 | 260 | if( that->getMime() == MIME_ARCHIVE ){ 261 | Archive *arch = (Archive *)that; 262 | result = arch->prev(id); 263 | } 264 | if( result == false ) 265 | result = this->getFiles()->prev(id); 266 | else 267 | return result; 268 | 269 | if( result == true && id == NULL ) 270 | this->idx--; 271 | 272 | return result; 273 | } 274 | 275 | Cell *Catalog::load(int id) 276 | { 277 | if( this->getFiles()->getCount() <= 0 ) 278 | return NULL; 279 | 280 | File *that = this->getFiles()->getThat(); 281 | if( id == LEFT ) 282 | that = this->getFiles()->getLeft(); 283 | else if( id == RIGHT ) 284 | that = this->getFiles()->getRight(); 285 | 286 | if( that == NULL ) 287 | return NULL; 288 | 289 | if( that->getMime() == MIME_ARCHIVE ){ 290 | Archive *arch = (Archive *)that; 291 | arch->initSort(this->sortSide); 292 | 293 | if( arch->getCount() <= 0 ){ 294 | delete this->getFiles()->remove(that); 295 | return this->load(id); 296 | } 297 | return arch->load(id); 298 | } 299 | Cell *cell = new Cell(that); 300 | 301 | if( cell->isLoaded() ) 302 | return cell; 303 | 304 | return NULL; 305 | } 306 | 307 | bool Catalog::isThatHead() 308 | { 309 | bool result = this->getFiles()->isThatHead(); 310 | 311 | if( result == true ){ 312 | File *that = this->getFiles()->getThat(); 313 | if( that != NULL ) 314 | if( that->getMime() == MIME_ARCHIVE ){ 315 | Archive *arch = (Archive *)that; 316 | result = arch->isThatHead(); 317 | } 318 | } 319 | return result; 320 | } 321 | bool Catalog::isThatTail() 322 | { 323 | bool result = this->getFiles()->isThatTail(); 324 | 325 | if( result == true ){ 326 | File *that = this->getFiles()->getThat(); 327 | if( that != NULL ) 328 | if( that->getMime() == MIME_ARCHIVE ){ 329 | Archive *arch = (Archive *)that; 330 | result = arch->isThatTail(); 331 | } 332 | } 333 | return result; 334 | } -------------------------------------------------------------------------------- /Fiew/Explorer.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Core.h" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #define BUFLEN 10 10 | 11 | char szTiffHeaderForMotorola[] = "MM*"; 12 | char szTiffHeaderForIntel[] = "II*"; 13 | char szPNGHeader[] = "\x89PNG\r\n\x1a\n"; 14 | char szGIF87aHeader[] = "GIF87a"; 15 | char szGIF89aHeader[] = "GIF89a"; 16 | char szJPEGCommonHeader[] = "\xFF\xD8\xFF"; 17 | char szJPEGCommonEOI[] = "\xFF\xD9"; // for future use 18 | char szBMPHeader[] = "\x42\x4D"; 19 | 20 | char szZIPHeader[] = "\x50\x4b\x03\x04"; 21 | char szRARHeader[] = "Rar"; 22 | 23 | Explorer::Explorer(Core *core) 24 | { 25 | this->core = core; 26 | this->root = NULL; 27 | } 28 | 29 | Explorer::~Explorer() 30 | { 31 | if( this->root != NULL ) 32 | delete this->root; 33 | } 34 | 35 | bool Explorer::browse(FwCHAR *path) 36 | { 37 | int type = Explorer::getType(path); 38 | int mime = Explorer::getMime(type); 39 | Catalog *tmp = NULL; 40 | 41 | if( mime == MIME_ARCHIVE ){ 42 | tmp = new Archive(path,type); 43 | tmp->initSort(); 44 | } 45 | else if( mime == MIME_DIR ){ 46 | if( path->toWCHAR()[path->toLength()] != '\\' ) 47 | path->mergeWith(L"\\"); 48 | tmp = new Catalog(path); 49 | } 50 | else if( mime == MIME_IMAGE ){ 51 | FwCHAR *folder = new FwCHAR(); 52 | folder->getFolderFrom(path); 53 | 54 | tmp = new Catalog(folder,path); 55 | } 56 | 57 | if( tmp != NULL ){ 58 | if( tmp->getCount() <= 0 ){ 59 | FwCHAR *notice = new FwCHAR(MESSAGE_EMPTY); 60 | notice->mergeWith(GUI_SEP); 61 | notice->mergeWith(tmp->getFilePath()->toWCHAR()); 62 | 63 | this->core->messageBox_Info( notice->toWCHAR() ); 64 | 65 | delete notice; 66 | delete tmp; 67 | } 68 | else { 69 | this->reset(); 70 | this->root = tmp; 71 | return true; 72 | } 73 | } 74 | return false; 75 | } 76 | 77 | Catalog *Explorer::getRoot() 78 | { 79 | return this->root; 80 | } 81 | 82 | FwCHAR *Explorer::getArchivePath() 83 | { 84 | FwCHAR *path = NULL; 85 | Archive *archive = this->getArchive(); 86 | if( archive != NULL ) 87 | path = archive->getFilePath(); 88 | return path; 89 | } 90 | 91 | void Explorer::reset() 92 | { 93 | if( this->root != NULL ) 94 | delete this->root; 95 | this->root = NULL; 96 | } 97 | 98 | bool Explorer::extract() 99 | { 100 | bool result = false; 101 | 102 | Archive *archive = this->getArchive(); 103 | if( archive != NULL ) 104 | result = archive->extract(); 105 | return result; 106 | } 107 | 108 | int Explorer::getMime(FwCHAR *path) 109 | { 110 | return Explorer::getMime( Explorer::getType(path) ); 111 | } 112 | 113 | int Explorer::getMime(int type) 114 | { 115 | if( type == TYPE_NONE ) 116 | return MIME_NONE; 117 | else if( type == TYPE_ZIP || type == TYPE_RAR ) 118 | return MIME_ARCHIVE; 119 | else if( type == TYPE_DIR ) 120 | return MIME_DIR; 121 | else 122 | return MIME_IMAGE; 123 | 124 | return MIME_NONE; 125 | } 126 | 127 | int Explorer::getType(FwCHAR *path) 128 | { 129 | DWORD fileAtt = GetFileAttributes(path->toWCHAR()); 130 | if( fileAtt == INVALID_FILE_ATTRIBUTES ) 131 | return TYPE_NONE; 132 | 133 | if( fileAtt & FILE_ATTRIBUTE_DIRECTORY ) 134 | return TYPE_DIR; 135 | 136 | int file; 137 | char pData[BUFLEN]; 138 | 139 | file = _wopen(path->toWCHAR(),_O_BINARY); 140 | if( file == FERROR ) 141 | return TYPE_NONE; 142 | 143 | _read(file,pData,BUFLEN); 144 | _close(file); 145 | 146 | if (!memcmp(pData, szTiffHeaderForIntel,3)) 147 | return TYPE_TIFFINTEL; 148 | else if (!memcmp(pData, szTiffHeaderForMotorola,3)) 149 | return TYPE_TIFFMOTOROLA; 150 | else if (!memcmp(pData, szPNGHeader,8)) 151 | return TYPE_PNG; 152 | else if (!memcmp(pData, szGIF87aHeader,6)) 153 | return TYPE_GIF87a; 154 | else if (!memcmp(pData, szGIF89aHeader,6)) 155 | return TYPE_GIF89a; 156 | else if (!memcmp(pData, szZIPHeader,4)) 157 | return TYPE_ZIP; 158 | else if (!memcmp(pData, szRARHeader,3)) 159 | return TYPE_RAR; 160 | else if (!memcmp(pData, szBMPHeader,2)) 161 | { 162 | // 7 to ten byte must be zero 163 | // 3 to 6 is size of image 164 | char szNull[] = "\x0\x0\x0\x0"; 165 | if (!memcmp(pData+6, szNull,4)) 166 | return TYPE_BITMAP; 167 | } 168 | else if (!memcmp(pData, szJPEGCommonHeader,3)) 169 | { 170 | switch (((long)*(pData+3)) & 0xFF) 171 | { 172 | case 0xE0: 173 | return TYPE_JPEGJFIF; 174 | break; 175 | case 0xE1: 176 | return TYPE_JPEGEXIF; 177 | break; 178 | case 0xE2: 179 | return TYPE_JPEGAPP2; 180 | break; 181 | case 0xE3: 182 | return TYPE_JPEGAPP3; 183 | break; 184 | case 0xE4: 185 | return TYPE_JPEGAPP4; 186 | break; 187 | case 0xE5: 188 | return TYPE_JPEGAPP5; 189 | break; 190 | case 0xE6: 191 | return TYPE_JPEGAPP6; 192 | break; 193 | case 0xE7: 194 | return TYPE_JPEGAPP7; 195 | break; 196 | case 0xE8: 197 | return TYPE_JPEGAPP8; 198 | break; 199 | case 0xE9: 200 | return TYPE_JPEGAPP9; 201 | break; 202 | case 0xEA: 203 | return TYPE_JPEGAPPA; 204 | break; 205 | case 0xEB: 206 | return TYPE_JPEGAPPB; 207 | break; 208 | case 0xEC: 209 | return TYPE_JPEGAPPC; 210 | break; 211 | case 0xED: 212 | return TYPE_JPEGAPPD; 213 | break; 214 | case 0xEE: 215 | return TYPE_JPEGAPPE; 216 | break; 217 | case 0xEF: 218 | return TYPE_JPEGAPPF; 219 | break; 220 | default: 221 | break; 222 | } 223 | } 224 | return TYPE_NONE; 225 | } 226 | 227 | int Explorer::getType(WCHAR *name) 228 | { 229 | WCHAR *ext = new WCHAR[10]; 230 | int i = 0; 231 | int type = TYPE_NONE; 232 | 233 | while( name[i] != '\0' ) i++; 234 | while( name[i] != '.' && i > 0 ) i--; 235 | 236 | int j=0; 237 | while( name[i] != '\0' && j < 9 ) 238 | ext[j++] = name[i++]; 239 | ext[j] = '\0'; 240 | 241 | if( !_wcsicmp(ext,L".jpeg") || !_wcsicmp(ext,L".jpg") ) 242 | type = TYPE_JPEGEXIF; 243 | else if( !_wcsicmp(ext,L".gif") ) 244 | type = TYPE_GIF89a; 245 | else if( !_wcsicmp(ext,L".tif") || !_wcsicmp(ext,L".tiff") ) 246 | type = TYPE_TIFFINTEL; 247 | else if( !_wcsicmp(ext,L".png") ) 248 | type = TYPE_PNG; 249 | else if( !_wcsicmp(ext,L".bmp") ) 250 | type = TYPE_BITMAP; 251 | 252 | else if( !_wcsicmp(ext,L".rar") || !_wcsicmp(ext,L".cbr") ) 253 | type = TYPE_RAR; 254 | else if( !_wcsicmp(ext,L".zip") || !_wcsicmp(ext,L".cbz") ) 255 | type = TYPE_ZIP; 256 | 257 | delete [] ext; 258 | return type; 259 | } 260 | 261 | bool Explorer::isArchived() 262 | { 263 | bool result = false; 264 | if( this->getArchive() != NULL ) 265 | result = true; 266 | return result; 267 | } 268 | 269 | Archive *Explorer::getArchive() 270 | { 271 | Archive *archive = NULL; 272 | if( this->root != NULL ){ 273 | if( this->root->getMime() == MIME_ARCHIVE ) 274 | archive = (Archive *)this->root; 275 | else if( this->root->getFiles() != NULL ) 276 | if( this->root->getFiles()->getCount() > 0 ) 277 | if( this->root->getFiles()->getThat()->getMime() == MIME_ARCHIVE ) 278 | archive = (Archive *)this->root->getFiles()->getThat(); 279 | } 280 | return archive; 281 | } -------------------------------------------------------------------------------- /Fiew/Explorer.h: -------------------------------------------------------------------------------- 1 | #define UNDEFINED -1 2 | 3 | class FwCHAR; 4 | class Core; 5 | class Cell; 6 | 7 | class File 8 | { 9 | protected: 10 | FwCHAR *filepath; 11 | FwCHAR *filename; 12 | int type; 13 | int mime; 14 | DWORD size; 15 | bool archived; 16 | 17 | public: 18 | File(FwCHAR *path, int type = UNDEFINED, DWORD size = NULL, bool archived = false); 19 | virtual ~File(); 20 | 21 | virtual void initSort(int sort = HEADSORT); 22 | 23 | FwCHAR *getFilePath(); 24 | FwCHAR *getFileName(); 25 | 26 | int getType(); 27 | int getMime(); 28 | DWORD getSize(); 29 | 30 | bool isArchived(); 31 | }; 32 | 33 | class Catalog : public File 34 | { 35 | protected: 36 | List *files; 37 | 38 | int sortSide; 39 | int count; 40 | int idx; 41 | 42 | HANDLE mut_list, mut_loop, mut_step, mut_terminator; 43 | HANDLE thrd_sorting; 44 | 45 | public: 46 | Catalog(FwCHAR *path, int type = UNDEFINED, DWORD size = NULL); 47 | Catalog(FwCHAR *path, FwCHAR *filepath, int type = UNDEFINED); 48 | virtual ~Catalog(); 49 | 50 | virtual void init(FwCHAR *thatpath = NULL); 51 | virtual void initSort(int sort = HEADSORT); 52 | 53 | virtual bool next(int id = NULL); 54 | virtual bool prev(int id = NULL); 55 | 56 | virtual Cell *load(int id = NULL); 57 | 58 | virtual bool isThatHead(); 59 | virtual bool isThatTail(); 60 | 61 | virtual int getCount(); 62 | List *getFiles(); 63 | int getIdx(); 64 | 65 | virtual void list(Core *core); 66 | 67 | static DWORD WINAPI trigSort(LPVOID param); 68 | }; 69 | 70 | class Archive : public Catalog 71 | { 72 | private: 73 | XUn *pack; 74 | List *unsortedFiles; 75 | 76 | HANDLE sem_sorted; 77 | bool sorted, terminate; 78 | 79 | public: 80 | Archive(FwCHAR *path, int type = UNDEFINED, DWORD size = NULL); 81 | ~Archive(); 82 | 83 | void init(FwCHAR *thatpath = NULL); 84 | void initSort(int sort = HEADSORT); 85 | 86 | List *getUnsortedFiles(); 87 | int getCount(); 88 | 89 | void setSorted(); 90 | bool isSorted(); 91 | 92 | bool extract(); 93 | bool extract(File *file); 94 | void list(Core *core); 95 | 96 | bool next(int id = NULL); 97 | bool prev(int id = NULL); 98 | 99 | Cell *load(int id = NULL); 100 | 101 | bool isThatHead(); 102 | bool isThatTail(); 103 | 104 | static DWORD WINAPI sort(LPVOID param); 105 | static DWORD WINAPI sortStep(LPVOID param); 106 | }; 107 | 108 | /* *** */ 109 | 110 | class Explorer 111 | { 112 | private: 113 | Core *core; 114 | 115 | Catalog *root; 116 | 117 | public: 118 | Explorer(Core *core); 119 | ~Explorer(); 120 | 121 | bool browse(FwCHAR *path); 122 | 123 | FwCHAR *getArchivePath(); 124 | Catalog *getRoot(); 125 | 126 | static int getMime(FwCHAR *path); 127 | static int getMime(int type); 128 | 129 | static int getType(FwCHAR *path); 130 | static int getType(WCHAR *name); 131 | 132 | void reset(); 133 | bool extract(); 134 | 135 | bool isArchived(); 136 | 137 | private: 138 | Archive *getArchive(); 139 | }; -------------------------------------------------------------------------------- /Fiew/Fiew.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/f055/fiew-image-viewer/314e86cbfbb95527783e9071ed3c97a9cdc93497/Fiew/Fiew.aps -------------------------------------------------------------------------------- /Fiew/Fiew.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Core.h" 3 | 4 | using namespace Gdiplus; 5 | #pragma comment(lib,"gdiplus.lib") 6 | 7 | HINSTANCE hInst; 8 | TCHAR szWindowClass[MAX_LOADSTRING]; 9 | 10 | ATOM MyRegisterClass(HINSTANCE hInstance); 11 | BOOL InitInstance(HINSTANCE, int); 12 | LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); 13 | 14 | Core *Miracle; 15 | 16 | int APIENTRY _tWinMain(HINSTANCE hInstance, 17 | HINSTANCE hPrevInstance, 18 | LPTSTR lpCmdLine, 19 | int nCmdShow) 20 | { 21 | UNREFERENCED_PARAMETER(hPrevInstance); 22 | 23 | MSG msg; 24 | HACCEL hAccelTable; 25 | GdiplusStartupInput gdiplusStartupInput; 26 | ULONG_PTR gdiplusToken; 27 | 28 | Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); 29 | 30 | LoadString(hInstance, IDC_FIEW, szWindowClass, MAX_LOADSTRING); 31 | MyRegisterClass(hInstance); 32 | 33 | Miracle = new Core((WCHAR *)lpCmdLine,hInstance); 34 | 35 | if (!InitInstance (hInstance, nCmdShow)) 36 | { 37 | return FALSE; 38 | } 39 | 40 | hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCELERATORS)); 41 | 42 | while (GetMessage(&msg, NULL, 0, 0)) 43 | { 44 | if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 45 | { 46 | TranslateMessage(&msg); 47 | DispatchMessage(&msg); 48 | } 49 | } 50 | Gdiplus::GdiplusShutdown(gdiplusToken); 51 | return (int) msg.wParam; 52 | } 53 | 54 | ATOM MyRegisterClass(HINSTANCE hInstance) 55 | { 56 | WNDCLASSEX wcex; 57 | 58 | wcex.cbSize = sizeof(WNDCLASSEX); 59 | 60 | wcex.style = CS_HREDRAW | CS_VREDRAW; 61 | wcex.lpfnWndProc = WndProc; 62 | wcex.cbClsExtra = 0; 63 | wcex.cbWndExtra = 0; 64 | wcex.hInstance = hInstance; 65 | wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_FIEW)); 66 | wcex.hCursor = LoadCursor(NULL, IDC_ARROW); 67 | wcex.hbrBackground = NULL; 68 | wcex.lpszMenuName = NULL;//MAKEINTRESOURCE(IDR_MENU); 69 | wcex.lpszClassName = szWindowClass; 70 | wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); 71 | 72 | return RegisterClassEx(&wcex); 73 | } 74 | 75 | BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) 76 | { 77 | HWND hWnd; 78 | 79 | hInst = hInstance; 80 | 81 | hWnd = CreateWindowEx(WS_EX_ACCEPTFILES, 82 | szWindowClass, APP_TITLE, 83 | WS_OVERLAPPEDWINDOW, 84 | CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 85 | NULL, NULL, hInstance, NULL); 86 | 87 | if (!hWnd) 88 | { 89 | return FALSE; 90 | } 91 | ShowWindow(hWnd, nCmdShow | SW_SHOWMAXIMIZED); 92 | UpdateWindow(hWnd); 93 | 94 | return TRUE; 95 | } 96 | 97 | LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 98 | { 99 | return Miracle->processMessages(hWnd,message,wParam,lParam); 100 | } 101 | -------------------------------------------------------------------------------- /Fiew/Fiew.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/f055/fiew-image-viewer/314e86cbfbb95527783e9071ed3c97a9cdc93497/Fiew/Fiew.h -------------------------------------------------------------------------------- /Fiew/Fiew.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/f055/fiew-image-viewer/314e86cbfbb95527783e9071ed3c97a9cdc93497/Fiew/Fiew.ico -------------------------------------------------------------------------------- /Fiew/Fiew.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #define APSTUDIO_HIDDEN_SYMBOLS 11 | #include "windows.h" 12 | #undef APSTUDIO_HIDDEN_SYMBOLS 13 | 14 | ///////////////////////////////////////////////////////////////////////////// 15 | #undef APSTUDIO_READONLY_SYMBOLS 16 | 17 | ///////////////////////////////////////////////////////////////////////////// 18 | // Polish resources 19 | 20 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_PLK) 21 | #ifdef _WIN32 22 | LANGUAGE LANG_POLISH, SUBLANG_DEFAULT 23 | #pragma code_page(1250) 24 | #endif //_WIN32 25 | 26 | ///////////////////////////////////////////////////////////////////////////// 27 | // 28 | // Icon 29 | // 30 | 31 | // Icon with lowest ID value placed first to ensure application icon 32 | // remains consistent on all systems. 33 | IDI_FIEW ICON "Fiew.ico" 34 | IDI_SMALL ICON "small.ico" 35 | 36 | #ifdef APSTUDIO_INVOKED 37 | ///////////////////////////////////////////////////////////////////////////// 38 | // 39 | // TEXTINCLUDE 40 | // 41 | 42 | 1 TEXTINCLUDE 43 | BEGIN 44 | "resource.h\0" 45 | END 46 | 47 | 2 TEXTINCLUDE 48 | BEGIN 49 | "#define APSTUDIO_HIDDEN_SYMBOLS\r\n" 50 | "#include ""windows.h""\r\n" 51 | "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n" 52 | "\0" 53 | END 54 | 55 | 3 TEXTINCLUDE 56 | BEGIN 57 | "\r\n" 58 | "\0" 59 | END 60 | 61 | #endif // APSTUDIO_INVOKED 62 | 63 | 64 | ///////////////////////////////////////////////////////////////////////////// 65 | // 66 | // Version 67 | // 68 | 69 | VS_VERSION_INFO VERSIONINFO 70 | FILEVERSION 2,0,0,2 71 | PRODUCTVERSION 2,0,0,2 72 | FILEFLAGSMASK 0x17L 73 | #ifdef _DEBUG 74 | FILEFLAGS 0x1L 75 | #else 76 | FILEFLAGS 0x0L 77 | #endif 78 | FILEOS 0x4L 79 | FILETYPE 0x1L 80 | FILESUBTYPE 0x0L 81 | BEGIN 82 | BLOCK "StringFileInfo" 83 | BEGIN 84 | BLOCK "041504b0" 85 | BEGIN 86 | VALUE "CompanyName", "www.fapplication.org" 87 | VALUE "FileDescription", "Fiew Image Viewer" 88 | VALUE "FileVersion", "2, 0, 0, 2" 89 | VALUE "InternalName", "Fiew" 90 | VALUE "LegalCopyright", "Copyright (C) 2006 Marek Foss" 91 | VALUE "OriginalFilename", "Fiew.exe" 92 | VALUE "ProductName", "Fiew" 93 | VALUE "ProductVersion", "2, 0, 0, 2" 94 | END 95 | END 96 | BLOCK "VarFileInfo" 97 | BEGIN 98 | VALUE "Translation", 0x415, 1200 99 | END 100 | END 101 | 102 | 103 | ///////////////////////////////////////////////////////////////////////////// 104 | // 105 | // Menu 106 | // 107 | 108 | IDR_MENU MENU 109 | BEGIN 110 | POPUP "File" 111 | BEGIN 112 | MENUITEM "Open...", ID_FILE_OPEN 113 | MENUITEM "Open Folder...", ID_FILE_OPENFOLDER 114 | MENUITEM "Close", ID_FILE_CLOSE, GRAYED 115 | MENUITEM SEPARATOR 116 | MENUITEM "Extract", ID_FILE_EXTRACT, GRAYED 117 | MENUITEM "Set as Wallpaper", ID_FILE_SETASWALLPAPER 118 | MENUITEM SEPARATOR 119 | MENUITEM "Exit", ID_FILE_EXIT 120 | END 121 | POPUP "View" 122 | BEGIN 123 | MENUITEM "Fullscreen", ID_VIEW_FULLSCREEN 124 | MENUITEM SEPARATOR 125 | MENUITEM "Thumbnails", ID_VIEW_THUMBNAILS, GRAYED 126 | MENUITEM "List", ID_VIEW_LIST, GRAYED 127 | MENUITEM SEPARATOR 128 | POPUP "Fit to", GRAYED 129 | BEGIN 130 | MENUITEM "Screen if Oversized", ID_FITTO_SCREENIFOVERSIZED 131 | MENUITEM "Screen", ID_FITTO_SCREEN 132 | MENUITEM SEPARATOR 133 | MENUITEM "Width", ID_FITTO_WIDTH 134 | MENUITEM "Height", ID_FITTO_HEIGHT 135 | MENUITEM "Numpad", ID_FITTO_NUMPAD 136 | MENUITEM SEPARATOR 137 | MENUITEM "Left", ID_FITTO_LEFT 138 | MENUITEM "Right", ID_FITTO_RIGHT 139 | END 140 | POPUP "Zoom", GRAYED 141 | BEGIN 142 | MENUITEM "100%", ID_ZOOM_100 143 | MENUITEM "75%", ID_ZOOM_75 144 | MENUITEM "50%", ID_ZOOM_50 145 | MENUITEM "25%", ID_ZOOM_25 146 | MENUITEM SEPARATOR 147 | MENUITEM "200%", ID_ZOOM_200 148 | MENUITEM "300%", ID_ZOOM_300 149 | MENUITEM "500%", ID_ZOOM_500 150 | MENUITEM SEPARATOR 151 | MENUITEM "Zoom In", ID_ZOOM_ZOOMIN 152 | MENUITEM "Zoom Out", ID_ZOOM_ZOOMOUT 153 | END 154 | POPUP "Rotate", GRAYED 155 | BEGIN 156 | MENUITEM "90\t/", ID_ROTATE_90 157 | MENUITEM "180", ID_ROTATE_180 158 | MENUITEM "270", ID_ROTATE_270 159 | MENUITEM SEPARATOR 160 | MENUITEM "Reset", ID_ROTATE_RESET 161 | END 162 | MENUITEM SEPARATOR 163 | MENUITEM "Flow Scroll", ID_VIEW_FLOWSCROLL, GRAYED 164 | END 165 | POPUP "Help" 166 | BEGIN 167 | MENUITEM "About Fiew...", ID_HELP_ABOUTFIEW 168 | MENUITEM "Manual...", ID_HELP_MANUAL 169 | END 170 | END 171 | 172 | 173 | ///////////////////////////////////////////////////////////////////////////// 174 | // 175 | // Accelerator 176 | // 177 | 178 | IDR_ACCELERATORS ACCELERATORS 179 | BEGIN 180 | "C", ID_FILE_CLOSE, VIRTKEY, CONTROL, NOINVERT 181 | "Q", ID_FILE_EXIT, VIRTKEY, CONTROL, NOINVERT 182 | "E", ID_FILE_EXTRACT, VIRTKEY, CONTROL, NOINVERT 183 | "O", ID_FILE_OPEN, VIRTKEY, CONTROL, NOINVERT 184 | "O", ID_FILE_OPENFOLDER, VIRTKEY, SHIFT, CONTROL, NOINVERT 185 | "F", ID_FITTO_HEIGHT, VIRTKEY, SHIFT, CONTROL, NOINVERT 186 | "F", ID_FITTO_NUMPAD, VIRTKEY, ALT, NOINVERT 187 | "F", ID_FITTO_WIDTH, VIRTKEY, CONTROL, NOINVERT 188 | VK_OEM_2, ID_HELP_ABOUTFIEW, VIRTKEY, CONTROL, NOINVERT 189 | "I", ID_HELP_MANUAL, VIRTKEY, CONTROL, NOINVERT 190 | "S", ID_VIEW_FLOWSCROLL, VIRTKEY, CONTROL, NOINVERT 191 | "L", ID_VIEW_LIST, VIRTKEY, CONTROL, NOINVERT 192 | "M", ID_VIEW_THUMBNAILS, VIRTKEY, CONTROL, NOINVERT 193 | "W", ID_FILE_SETASWALLPAPER, VIRTKEY, CONTROL, NOINVERT 194 | END 195 | 196 | 197 | ///////////////////////////////////////////////////////////////////////////// 198 | // 199 | // PNG 200 | // 201 | 202 | IDR_MANUAL PNG "ovl_manual.png" 203 | IDR_ABOUT PNG "ovl_about.png" 204 | 205 | ///////////////////////////////////////////////////////////////////////////// 206 | // 207 | // DLL 208 | // 209 | 210 | IDR_DLLRAR DLL "unrar.dll" 211 | 212 | ///////////////////////////////////////////////////////////////////////////// 213 | // 214 | // String Table 215 | // 216 | 217 | STRINGTABLE 218 | BEGIN 219 | IDC_FIEW "FIEW" 220 | END 221 | 222 | #endif // Polish resources 223 | ///////////////////////////////////////////////////////////////////////////// 224 | 225 | 226 | 227 | #ifndef APSTUDIO_INVOKED 228 | ///////////////////////////////////////////////////////////////////////////// 229 | // 230 | // Generated from the TEXTINCLUDE 3 resource. 231 | // 232 | 233 | 234 | ///////////////////////////////////////////////////////////////////////////// 235 | #endif // not APSTUDIO_INVOKED 236 | 237 | -------------------------------------------------------------------------------- /Fiew/Fiew.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 25 | 28 | 31 | 34 | 37 | 40 | 52 | 55 | 58 | 61 | 68 | 71 | 74 | 77 | 80 | 83 | 86 | 89 | 92 | 93 | 101 | 104 | 107 | 110 | 113 | 116 | 125 | 128 | 131 | 134 | 143 | 146 | 150 | 153 | 156 | 159 | 162 | 165 | 168 | 169 | 170 | 171 | 172 | 173 | 178 | 181 | 182 | 185 | 186 | 189 | 190 | 193 | 196 | 197 | 200 | 201 | 204 | 205 | 208 | 211 | 215 | 216 | 219 | 223 | 224 | 225 | 226 | 229 | 232 | 233 | 236 | 237 | 240 | 241 | 244 | 245 | 248 | 249 | 252 | 253 | 256 | 257 | 260 | 261 | 264 | 265 | 268 | 269 | 272 | 273 | 276 | 277 | 280 | 281 | 284 | 285 | 288 | 289 | 292 | 293 | 294 | 297 | 300 | 301 | 304 | 305 | 308 | 309 | 312 | 313 | 316 | 317 | 320 | 321 | 322 | 323 | 328 | 331 | 332 | 335 | 336 | 339 | 340 | 341 | 346 | 349 | 350 | 353 | 354 | 357 | 358 | 361 | 362 | 365 | 366 | 367 | 370 | 371 | 374 | 375 | 376 | 377 | 378 | 379 | -------------------------------------------------------------------------------- /Fiew/Fiew.vcproj.NEKO.a0.user: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 11 | 35 | 36 | 39 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /Fiew/Ftyper.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "FwCHAR.h" 3 | #include "Ftyper.h" 4 | 5 | Ftyper::Ftyper() 6 | { 7 | 8 | } 9 | 10 | ~Ftyper::~Ftyper() 11 | { 12 | 13 | } 14 | 15 | static int Ftyper::getMime(FwCHAR *path) 16 | { 17 | 18 | } -------------------------------------------------------------------------------- /Fiew/Ftyper.h: -------------------------------------------------------------------------------- 1 | class Ftyper 2 | { 3 | public: 4 | Ftyper(); 5 | ~Ftyper(); 6 | 7 | static int getMime(FwCHAR *path); 8 | static int getMime(File *file); 9 | 10 | static int getType(FwCHAR *path); 11 | static int getType(File *file); 12 | }; -------------------------------------------------------------------------------- /Fiew/FwCHAR.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "FwCHAR.h" 3 | 4 | #include 5 | using namespace std; 6 | 7 | FwCHAR::FwCHAR() 8 | { 9 | this->string = new WCHAR[1]; 10 | this->string[0] = '\0'; 11 | } 12 | 13 | FwCHAR::FwCHAR(int source) 14 | { 15 | WCHAR *tmp = new WCHAR[MAX_LOADSTRING]; 16 | _itow(source,tmp,10); 17 | 18 | this->string = new WCHAR[wcslen(tmp) + 1]; 19 | 20 | int i = 0; 21 | while( tmp[i] != '\0' ) 22 | this->string[i] = tmp[i++]; 23 | 24 | this->string[i] = '\0'; 25 | delete [] tmp; 26 | } 27 | 28 | FwCHAR::FwCHAR(WCHAR *source) 29 | { 30 | this->string = new WCHAR[wcslen(source) + 1]; 31 | 32 | int i = 0; 33 | while( source[i] != '\0' ) 34 | this->string[i] = source[i++]; 35 | 36 | this->string[i] = '\0'; 37 | } 38 | 39 | FwCHAR::~FwCHAR() 40 | { 41 | delete [] this->string; 42 | } 43 | 44 | void FwCHAR::mergeWith(WCHAR *source) 45 | { 46 | if( source == NULL ) 47 | return; 48 | 49 | WCHAR *tmp = this->string; 50 | this->string = new WCHAR[wcslen(tmp) + wcslen(source) + 1]; 51 | 52 | wcscpy(this->string,tmp); 53 | wcscpy(&this->string[this->toLength()],source); 54 | 55 | delete [] tmp; 56 | } 57 | 58 | void FwCHAR::mergeWith(FwCHAR *source) 59 | { 60 | if( source == NULL ) 61 | return; 62 | 63 | this->mergeWith(source->toWCHAR()); 64 | } 65 | 66 | void FwCHAR::getFolderFrom(FwCHAR *source) 67 | { 68 | if( source == NULL ) 69 | return; 70 | 71 | int len, offset = 0; 72 | int i = len = source->toLength(); 73 | while( (source->toWCHAR()[i] != '\\' && source->toWCHAR()[i] != '/') && i > 0 ){ 74 | offset++; 75 | i--; 76 | } 77 | 78 | delete [] this->string; 79 | 80 | int copy, diff = len - offset; 81 | if( diff > 0 ) 82 | copy = diff + 1; 83 | else 84 | copy = len + 1; 85 | 86 | this->string = new WCHAR[copy + 1]; 87 | for( i = 0; i < copy; i++ ) 88 | this->string[i] = source->toWCHAR()[i]; 89 | this->string[i] = '\0'; 90 | } 91 | 92 | void FwCHAR::getFilenameFrom(FwCHAR *source) 93 | { 94 | if( source == NULL ) 95 | return; 96 | 97 | int len, offset = 0; 98 | int i = len = source->toLength(); 99 | while( (source->toWCHAR()[i] != '\\' && source->toWCHAR()[i] != '/') && i > 0 ){ 100 | offset++; 101 | i--; 102 | } 103 | 104 | delete [] this->string; 105 | 106 | int diff = len - offset; 107 | if( diff > 0 ){ 108 | this->string = new WCHAR[offset + 1]; 109 | wcscpy(this->string,&source->toWCHAR()[diff + 1]); 110 | } 111 | else { 112 | this->string = new WCHAR[len + 1]; 113 | wcscpy(this->string,source->toWCHAR()); 114 | } 115 | } 116 | 117 | WCHAR *FwCHAR::toWCHAR() 118 | { 119 | return this->string; 120 | } 121 | 122 | char *FwCHAR::tochar() 123 | { 124 | char *target = new char[this->toLength() + 1]; 125 | 126 | int i = 0; 127 | while( this->string[i] != '\0' ) 128 | target[i] = (char)this->string[i++]; 129 | target[i] = '\0'; 130 | 131 | return target; 132 | } 133 | 134 | bool FwCHAR::equals(FwCHAR *source) 135 | { 136 | if( wcscmp(this->string,source->toWCHAR()) == 0 ) 137 | return true; 138 | return false; 139 | } 140 | 141 | void FwCHAR::stripBraces() 142 | { 143 | if( this->string[0] == '"' ){ 144 | int i = 1; 145 | while( this->string[i] != '"' ){ 146 | this->string[i-1] = this->string[i]; 147 | i++; 148 | } 149 | this->string[--i] = '\0'; 150 | } 151 | } 152 | 153 | int FwCHAR::toLength() 154 | { 155 | return (int)wcslen(this->string); 156 | } 157 | 158 | int FwCHAR::compare(FwCHAR *string1, FwCHAR *string2) 159 | { 160 | locale loc(ENGLISH_LOCALE); 161 | 162 | FwCHAR *fol1, *fol2, *fil1, *fil2; 163 | int result = 0; 164 | 165 | fol1 = new FwCHAR(); 166 | fol2 = new FwCHAR(); 167 | 168 | fol1->getFolderFrom(string1); 169 | fol2->getFolderFrom(string2); 170 | 171 | if( fol1->toLength() < 3 || fol2->toLength() < 3 ) 172 | result = 0; 173 | else 174 | result = wcscmp(fol1->toWCHAR(),fol2->toWCHAR()); 175 | /*use_facet>(loc).compare(fol1->toWCHAR(), 176 | &fol1->toWCHAR()[wcslen(fol1->toWCHAR())], 177 | fol2->toWCHAR(), 178 | &fol2->toWCHAR()[wcslen(fol2->toWCHAR())]);*/ 179 | if( result == 0 ){ 180 | fil1 = new FwCHAR(); 181 | fil2 = new FwCHAR(); 182 | 183 | fil1->getFilenameFrom(string1); 184 | fil2->getFilenameFrom(string2); 185 | 186 | result = wcscmp(fil1->toWCHAR(),fil2->toWCHAR()); 187 | /*use_facet>(loc).compare(fil1->toWCHAR(), 188 | &fil1->toWCHAR()[wcslen(fil1->toWCHAR())], 189 | fil2->toWCHAR(), 190 | &fil2->toWCHAR()[wcslen(fil2->toWCHAR())]);*/ 191 | delete fil1; 192 | delete fil2; 193 | } 194 | delete fol1; 195 | delete fol2; 196 | 197 | return result; 198 | } -------------------------------------------------------------------------------- /Fiew/FwCHAR.h: -------------------------------------------------------------------------------- 1 | class FwCHAR 2 | { 3 | private: 4 | WCHAR *string; 5 | 6 | public: 7 | FwCHAR(); 8 | FwCHAR(int source); 9 | FwCHAR(WCHAR *source); 10 | ~FwCHAR(); 11 | 12 | void mergeWith(WCHAR *source); 13 | void mergeWith(FwCHAR *source); 14 | 15 | void getFolderFrom(FwCHAR *source); 16 | void getFilenameFrom(FwCHAR *source); 17 | 18 | WCHAR *toWCHAR(); 19 | char *tochar(); 20 | 21 | bool equals(FwCHAR *source); 22 | void stripBraces(); 23 | 24 | int toLength(); 25 | 26 | static int compare(FwCHAR *string1, FwCHAR *string2); 27 | 28 | private: 29 | }; -------------------------------------------------------------------------------- /Fiew/Interface.h: -------------------------------------------------------------------------------- 1 | class Core; 2 | 3 | class Interface 4 | { 5 | private: 6 | Core *core; 7 | 8 | LRESULT mState; 9 | UINT mButton; 10 | int mX, mY, dX, dY; 11 | bool mBB, mWH, mMM; 12 | 13 | bool fullscreen, menuvisible, fullpath; 14 | WCHAR *textmessage; 15 | int menuheight; 16 | 17 | WINDOWINFO windowInfo; 18 | HMENU windowMenu, menuFile, menuView, menuHelp; 19 | LONG windowLong; 20 | HCURSOR cursor; 21 | 22 | public: 23 | Interface(Core *core); 24 | ~Interface(); 25 | 26 | void update(); 27 | void updateMenu(); 28 | void updateText(); 29 | 30 | void openFile(); 31 | void openFolder(); 32 | void openDropFile(WPARAM wParam); 33 | void close(); 34 | 35 | bool isFullscreen(); 36 | 37 | void setMessage(WCHAR *message); 38 | 39 | void showCursor(); 40 | HCURSOR setCursor(LPCWSTR name = NULL); 41 | HCURSOR setCursor(HCURSOR cursor); 42 | 43 | void blockMBB(); 44 | void timerMBB(); 45 | void unblockMBB(); 46 | 47 | void movemMM(); 48 | 49 | void processMenu(int id); 50 | void processKeys(UINT message, WPARAM wParam, LPARAM lParam); 51 | void processMouse(UINT message, WPARAM wParam, LPARAM lParam); 52 | LRESULT processMouseState(LPARAM lParam, LRESULT lResult); 53 | 54 | private: 55 | void initLocale(); 56 | 57 | void showMenu(); 58 | void hideMenu(); 59 | 60 | void capKeyDown(WPARAM wParam); 61 | void capKeyUp(WPARAM wParam); 62 | 63 | void capMouseDown(LPARAM lParam, WPARAM wParam, int button); 64 | void capMouseUp(LPARAM lParam, WPARAM wParam, int button); 65 | void capMouseWheel(LPARAM lParam, WPARAM wParam); 66 | void capMouseMove(LPARAM lParam, WPARAM wParam); 67 | 68 | void setCapture(bool state); 69 | void setFullscreen(int mode); 70 | void setFullpath(); 71 | }; -------------------------------------------------------------------------------- /Fiew/Layer.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Core.h" 3 | 4 | Layer::Layer(Core *core, Image *image) 5 | { 6 | this->core = core; 7 | this->cell = NULL; 8 | 9 | this->image = image; 10 | this->next = NULL; 11 | this->prev = NULL; 12 | 13 | this->scali = NULL; 14 | this->scaln = NULL; 15 | this->scalp = NULL; 16 | 17 | this->fulldraw = true; 18 | 19 | this->sidedraw = false; 20 | this->zoomdraw = false; 21 | this->passmess = false; 22 | this->fullscreen = false; 23 | this->cancel = false; 24 | 25 | this->dimension = NULL; 26 | this->frameCount = 0; 27 | this->frameThat = 0; 28 | 29 | this->Brush_Back = new SolidBrush(CLR_WHITE); 30 | this->Brush_DarkBack = new SolidBrush(CLR_DIRK); 31 | this->Brush_LiteBack = new SolidBrush(CLR_LITE); 32 | 33 | this->Pen_Border = new Pen(CLR_FRAME_LIGHT,1); 34 | this->Pen_DarkBorder = new Pen(CLR_FRAME_DARK,1); 35 | 36 | this->FontSize = FONTSIZE; 37 | 38 | this->FontFamily_Arial = new FontFamily(FONT,NULL); 39 | 40 | this->Font_Default = 41 | new Font(this->FontFamily_Arial,(REAL)this->FontSize,FontStyleRegular,UnitPixel); 42 | 43 | this->mut_image = NULL; 44 | this->mut_animloop = NULL; 45 | this->mut_terminator = NULL; 46 | 47 | this->thrd_anim = NULL; 48 | 49 | this->offset = NULL; 50 | this->menuheight = NULL; 51 | 52 | this->fitmode = FITSCREENOV; 53 | this->sidemode = NULL; 54 | this->type = TYPE_NONE; 55 | 56 | this->zoom = ZOOMINIT; 57 | this->rot = ROT_0; 58 | this->gifdir = RIGHT; 59 | 60 | this->init(); 61 | this->locate(TOP); 62 | } 63 | 64 | Layer::~Layer() 65 | { 66 | this->reset(); 67 | 68 | delete this->Brush_Back; 69 | delete this->Brush_DarkBack; 70 | delete this->Brush_LiteBack; 71 | 72 | delete this->Pen_Border; 73 | delete this->Pen_DarkBorder; 74 | 75 | delete this->FontFamily_Arial; 76 | 77 | delete this->Font_Default; 78 | } 79 | 80 | void Layer::init() 81 | { 82 | if( this->image == NULL ) 83 | this->loadContent(DEFAULT); 84 | } 85 | 86 | void Layer::setPassmess() 87 | { 88 | this->passmess = true; 89 | } 90 | 91 | void Layer::reset() 92 | { 93 | if( WaitForSingleObject(this->mut_animloop,0) == WAIT_TIMEOUT ){ 94 | ReleaseMutex(this->mut_terminator); 95 | WaitForSingleObject(this->mut_animloop,INFINITE); 96 | ReleaseMutex(this->mut_animloop); 97 | } 98 | if( this->mut_image != NULL ) 99 | CloseHandle(this->mut_image); 100 | this->mut_image = NULL; 101 | 102 | if( this->mut_animloop != NULL ) 103 | CloseHandle(this->mut_animloop); 104 | this->mut_animloop = NULL; 105 | 106 | if( this->mut_terminator != NULL ) 107 | CloseHandle(this->mut_terminator); 108 | this->mut_terminator = NULL; 109 | 110 | if( this->thrd_anim != NULL ) 111 | CloseHandle(this->thrd_anim); 112 | this->thrd_anim = NULL; 113 | 114 | if( this->image != NULL ) 115 | delete this->image; 116 | this->image = NULL; 117 | if( this->next != NULL ) 118 | delete this->next; 119 | this->next = NULL; 120 | if( this->prev != NULL ) 121 | delete this->prev; 122 | this->prev = NULL; 123 | 124 | if( this->scali != NULL ) 125 | delete this->scali; 126 | this->scali = NULL; 127 | if( this->scaln != NULL ) 128 | delete this->scaln; 129 | this->scaln = NULL; 130 | if( this->scalp != NULL ) 131 | delete this->scalp; 132 | this->scalp = NULL; 133 | 134 | if( this->dimension != NULL ) 135 | delete this->dimension; 136 | this->dimension = NULL; 137 | this->frameCount = 0; 138 | this->frameThat = 0; 139 | 140 | this->gifdir = RIGHT; 141 | } 142 | void Layer::repos() 143 | { 144 | this->sidemode = NULL; 145 | this->rotateReset(true); 146 | this->setFitmode(NULL); 147 | } 148 | 149 | void Layer::loadContent(int init) 150 | { 151 | this->reset(); 152 | 153 | Cacher *cacher = this->core->getCacher(); 154 | if( cacher != NULL ){ 155 | Cell *tmp = NULL; 156 | if( this->sidedraw == true ){ 157 | if( cacher->prev() ){ 158 | tmp = cacher->getThat(); 159 | if( tmp != NULL ) 160 | this->prev = tmp->getImage(); 161 | cacher->next(); 162 | } 163 | } 164 | this->cell = cacher->getThat(); 165 | if( this->cell != NULL ){ 166 | WaitForSingleObject(this->mut_image,INFINITE); 167 | this->image = this->cell->getImage(); 168 | ReleaseMutex(this->mut_image); 169 | } 170 | if( this->sidedraw == true ){ 171 | if( cacher->next() ){ 172 | tmp = cacher->getThat(); 173 | if( tmp != NULL ) 174 | this->next = tmp->getImage(); 175 | cacher->prev(); 176 | } 177 | } 178 | } 179 | this->afterLoadContent(init); 180 | } 181 | 182 | void Layer::afterLoadContent(int init) 183 | { 184 | int mode = init; 185 | if( this->sidedraw == false ) 186 | mode = TOP; 187 | 188 | this->rotateSet(); 189 | this->locate(mode); 190 | this->setFitmode(); 191 | 192 | if( this->core->getGui() != NULL && init != DEFAULT ) 193 | this->core->getGui()->update(); 194 | } 195 | 196 | void Layer::nextContent(int init) 197 | { 198 | Cacher *cacher = this->core->getCacher(); 199 | if( cacher != NULL ){ 200 | HCURSOR last = NULL; 201 | if( this->core->getGui() != NULL ) 202 | last = this->core->getGui()->setCursor(CURSOR_ARRWAIT); 203 | 204 | if( cacher->next() ) 205 | this->loadContent(init); 206 | 207 | if( this->core->getGui() != NULL ) 208 | this->core->getGui()->setCursor(last); 209 | } 210 | } 211 | void Layer::prevContent(int init) 212 | { 213 | Cacher *cacher = this->core->getCacher(); 214 | if( cacher != NULL ){ 215 | HCURSOR last = NULL; 216 | if( this->core->getGui() != NULL ) 217 | last = this->core->getGui()->setCursor(CURSOR_ARRWAIT); 218 | 219 | if( cacher->prev() ) 220 | this->loadContent(init); 221 | 222 | if( this->core->getGui() != NULL ) 223 | this->core->getGui()->setCursor(last); 224 | } 225 | } 226 | 227 | void Layer::nextImage(int x, int y) 228 | { 229 | if( this->nextFrame(false) == true ){ 230 | this->offset = 0; 231 | this->nextContent(TOP); 232 | } 233 | else 234 | this->zoomend(); 235 | } 236 | void Layer::prevImage(int x, int y) 237 | { 238 | if( this->prevFrame(false) == true ){ 239 | this->offset = 0; 240 | this->prevContent(TOP); 241 | } 242 | else 243 | this->zoomend(); 244 | } 245 | 246 | bool Layer::nextFrame(bool back) 247 | { 248 | if( this->frameCount < 2 ) 249 | return true; 250 | if( back == false && 251 | WaitForSingleObject(this->mut_animloop,0) == WAIT_TIMEOUT ) 252 | return true; 253 | 254 | bool result = false; 255 | 256 | this->frameThat++; 257 | if( this->frameThat >= this->frameCount ) 258 | this->frameThat = 0; 259 | if( this->frameThat == 0 ) 260 | result = true; 261 | 262 | this->image->SelectActiveFrame(this->dimension,this->frameThat); 263 | 264 | return result; 265 | } 266 | bool Layer::prevFrame(bool back) 267 | { 268 | if( this->frameCount < 2 ) 269 | return true; 270 | if( back == false && 271 | WaitForSingleObject(this->mut_animloop,0) == WAIT_TIMEOUT ) 272 | return true; 273 | 274 | bool result = false; 275 | 276 | if( this->frameThat == 0 ) 277 | result = true; 278 | if( this->frameThat == 0 ) 279 | this->frameThat = this->frameCount; 280 | 281 | this->frameThat--; 282 | this->image->SelectActiveFrame(this->dimension,this->frameThat); 283 | 284 | return result; 285 | } 286 | 287 | Bitmap *Layer::render() 288 | { 289 | this->locate(); 290 | 291 | WaitForSingleObject(this->mut_image,INFINITE); 292 | 293 | int frame = FRAME; 294 | Bitmap *scene = NULL; 295 | if( this->fulldraw == true ) 296 | scene = new Bitmap(this->cwidth + 2*frame,this->cheight + 2*frame); 297 | else 298 | scene = new Bitmap(this->width,this->height); 299 | 300 | Graphics *tmpgfx = Graphics::FromImage(scene); 301 | 302 | Image *tmp = NULL; 303 | tmpgfx->Clear(CLR_WHITE); 304 | 305 | if( this->fulldraw == true ){ 306 | if( this->image != NULL ){ 307 | double zoom = NULL; 308 | int width, height; 309 | 310 | if( this->scali == NULL ) 311 | tmp = this->image; 312 | else 313 | tmp = this->scali; 314 | 315 | if( this->fullscreen == false ) 316 | tmpgfx->DrawRectangle(this->Pen_Border, 317 | this->x - frame, 318 | this->y - frame, 319 | this->width + frame + 1, 320 | this->height + frame + 1); 321 | 322 | tmpgfx->DrawImage(tmp, 323 | Rect(this->x, 324 | this->y, 325 | this->width, 326 | this->height), 327 | 0, 328 | 0, 329 | tmp->GetWidth(), 330 | tmp->GetHeight(), 331 | UnitPixel); 332 | 333 | if( this->prev != NULL && this->sidedraw == true ){ 334 | if( this->scalp == NULL ) 335 | tmp = this->prev; 336 | else 337 | tmp = this->scalp; 338 | width = tmp->GetWidth(); 339 | height = tmp->GetHeight(); 340 | if( this->scalp == NULL ) 341 | zoom = this->getZoom(width,height,this->cwidth,this->cheight); 342 | else 343 | zoom = ZOOMINIT; 344 | 345 | int pwidth = (int)(zoom * width); 346 | int pheight = (int)(zoom * height); 347 | int px = (int)((this->cwidth - pwidth)/2); 348 | if( this->sidemode == LEFT && px < 0 ) 349 | px = 0; 350 | else if( this->sidemode == RIGHT && px < 0 ) 351 | px = this->cwidth - pwidth; 352 | 353 | int py = this->y - pheight - MARGIN - this->offrollVer; 354 | 355 | if( this->fullscreen == false ) 356 | tmpgfx->DrawRectangle(this->Pen_Border, 357 | px - frame, 358 | py - frame, 359 | pwidth + frame + 1, 360 | pheight + frame + 1); 361 | 362 | tmpgfx->DrawImage(tmp,Rect(px,py,pwidth,pheight),0,0, 363 | tmp->GetWidth(),tmp->GetHeight(),UnitPixel); 364 | } 365 | if( this->next != NULL && this->sidedraw == true ){ 366 | if( this->scaln == NULL ) 367 | tmp = this->next; 368 | else 369 | tmp = this->scaln; 370 | width = tmp->GetWidth(); 371 | height = tmp->GetHeight(); 372 | if( this->scaln == NULL ) 373 | zoom = this->getZoom(width,height,this->cwidth,this->cheight); 374 | else 375 | zoom = ZOOMINIT; 376 | 377 | int nwidth = (int)(zoom * width); 378 | int nheight = (int)(zoom * height); 379 | int nx = (int)((this->cwidth - nwidth)/2); 380 | if( this->sidemode == LEFT && nx < 0 ) 381 | nx = 0; 382 | else if( this->sidemode == RIGHT && nx < 0 ) 383 | nx = this->cwidth - nwidth; 384 | 385 | int ny = this->y + this->height + MARGIN + this->offrollVer; 386 | 387 | if( this->fullscreen == false ) 388 | tmpgfx->DrawRectangle(this->Pen_Border, 389 | nx - frame, 390 | ny - frame, 391 | nwidth + frame + 1, 392 | nheight + frame + 1); 393 | 394 | tmpgfx->DrawImage(tmp,Rect(nx,ny,nwidth,nheight),0,0, 395 | tmp->GetWidth(),tmp->GetHeight(),UnitPixel); 396 | } 397 | } 398 | this->x = 0; 399 | this->y = 0; 400 | this->width = scene->GetWidth(); 401 | this->height = scene->GetHeight(); 402 | } 403 | else { 404 | if( this->scali == NULL ) 405 | tmp = this->image; 406 | else 407 | tmp = this->scali; 408 | 409 | tmpgfx->DrawImage(tmp, 410 | Rect(0,0,this->width,this->height), 411 | 0,0,tmp->GetWidth(),tmp->GetHeight(), 412 | UnitPixel); 413 | } 414 | ReleaseMutex(this->mut_image); 415 | 416 | this->fulldraw = true; 417 | this->animate(); 418 | 419 | delete tmpgfx; 420 | 421 | return scene; 422 | } 423 | 424 | void Layer::scroll(int hor, int ver) 425 | { 426 | int invalid = 2; 427 | if( (this->rollHor == this->maxrollHor && hor > 0) || 428 | (this->rollHor == -this->maxrollHor && hor < 0 ) || hor == 0 ) 429 | invalid--; 430 | if( (((this->rollVer == this->maxrollVer && ver > 0) || 431 | (this->rollVer == this->minrollVer && ver < 0)) && 432 | this->sidedraw == false) || ver == 0 ) 433 | invalid--; 434 | 435 | if( invalid > 0 ){ 436 | this->rollHor += hor; 437 | this->rollVer += ver; 438 | this->boundRoll(); 439 | this->invalidate(); 440 | } 441 | } 442 | void Layer::scrollSet(int x, int y) 443 | { 444 | this->rollHor = x; 445 | this->rollVer = y; 446 | this->boundRoll(); 447 | this->invalidate(); 448 | } 449 | void Layer::scrollHor(int val) 450 | { 451 | if( (this->rollHor == this->maxrollHor && val > 0) || 452 | (this->rollHor == -this->maxrollHor && val < 0 ) ) 453 | return; 454 | 455 | this->rollHor += val; 456 | this->boundRoll(); 457 | this->invalidate(); 458 | } 459 | void Layer::scrollVer(int val) 460 | { 461 | if( ((this->rollVer == this->maxrollVer && val > 0) || 462 | (this->rollVer == this->minrollVer && val < 0)) && this->sidedraw == false ) 463 | return; 464 | 465 | this->rollVer += val; 466 | this->boundRoll(); 467 | this->invalidate(); 468 | } 469 | 470 | void Layer::zoomer(double val) 471 | { 472 | if( this->zoom == ZOOMSTEP && val < 0 ) 473 | return; 474 | if( val == NULL ) 475 | return; 476 | 477 | this->zoombegin(); 478 | this->unsetFitmode(); 479 | 480 | this->zoom += val; 481 | this->boundZoom(); 482 | this->invalidate(); 483 | } 484 | void Layer::zoomat(double val) 485 | { 486 | this->zoombegin(); 487 | this->unsetFitmode(); 488 | 489 | this->zoom = val; 490 | this->boundZoom(); 491 | this->invalidate(); 492 | } 493 | void Layer::zoombegin() 494 | { 495 | this->zoomdraw = true; 496 | } 497 | void Layer::zoomend() 498 | { 499 | this->zoomdraw = false; 500 | 501 | if( this->scali != NULL ) 502 | delete this->scali; 503 | if( this->scaln != NULL ) 504 | delete this->scaln; 505 | if( this->scalp != NULL ) 506 | delete this->scalp; 507 | this->scali = NULL; 508 | this->scaln = NULL; 509 | this->scalp = NULL; 510 | 511 | if( this->zoom < ZOOMINIT ){ 512 | this->scali = this->scale(this->image); 513 | if( this->next != NULL ) 514 | this->scaln = this->scale(this->next); 515 | if( this->prev != NULL ) 516 | this->scalp = this->scale(this->prev); 517 | } 518 | this->invalidate(); 519 | } 520 | 521 | void Layer::rotate(Image *image) 522 | { 523 | if( image == NULL ) 524 | return; 525 | 526 | switch(this->rot){ 527 | case 1: 528 | image->RotateFlip(Rotate90FlipNone); 529 | break; 530 | case 2: 531 | image->RotateFlip(Rotate180FlipNone); 532 | break; 533 | case 3: 534 | image->RotateFlip(Rotate270FlipNone); 535 | break; 536 | } 537 | } 538 | void Layer::rotate(int val) 539 | { 540 | if( val == NULL ) 541 | return; 542 | 543 | bool rotati = true; 544 | if( WaitForSingleObject(this->mut_animloop,0) == WAIT_TIMEOUT ) 545 | rotati = false; 546 | 547 | this->rot = (this->rot + val) % 4; 548 | switch(val){ 549 | case 1: 550 | if( rotati == true ) 551 | this->image->RotateFlip(Rotate90FlipNone); 552 | if( this->next != NULL ) 553 | this->next->RotateFlip(Rotate90FlipNone); 554 | if( this->prev != NULL ) 555 | this->prev->RotateFlip(Rotate90FlipNone); 556 | break; 557 | case 2: 558 | if( rotati == true ) 559 | this->image->RotateFlip(Rotate180FlipNone); 560 | if( this->next != NULL ) 561 | this->next->RotateFlip(Rotate180FlipNone); 562 | if( this->prev != NULL ) 563 | this->prev->RotateFlip(Rotate180FlipNone); 564 | break; 565 | case 3: 566 | if( rotati == true ) 567 | this->image->RotateFlip(Rotate270FlipNone); 568 | if( this->next != NULL ) 569 | this->next->RotateFlip(Rotate270FlipNone); 570 | if( this->prev != NULL ) 571 | this->prev->RotateFlip(Rotate270FlipNone); 572 | break; 573 | } 574 | this->setFitmode(); 575 | } 576 | void Layer::rotateSet() 577 | { 578 | bool rotati = true; 579 | if( WaitForSingleObject(this->mut_animloop,0) == WAIT_TIMEOUT ) 580 | rotati = false; 581 | 582 | switch(this->rot){ 583 | case 1: 584 | if( rotati == true ) 585 | this->image->RotateFlip(Rotate90FlipNone); 586 | if( this->next != NULL ) 587 | this->next->RotateFlip(Rotate90FlipNone); 588 | if( this->prev != NULL ) 589 | this->prev->RotateFlip(Rotate90FlipNone); 590 | break; 591 | case 2: 592 | if( rotati == true ) 593 | this->image->RotateFlip(Rotate180FlipNone); 594 | if( this->next != NULL ) 595 | this->next->RotateFlip(Rotate180FlipNone); 596 | if( this->prev != NULL ) 597 | this->prev->RotateFlip(Rotate180FlipNone); 598 | break; 599 | case 3: 600 | if( rotati == true ) 601 | this->image->RotateFlip(Rotate270FlipNone); 602 | if( this->next != NULL ) 603 | this->next->RotateFlip(Rotate270FlipNone); 604 | if( this->prev != NULL ) 605 | this->prev->RotateFlip(Rotate270FlipNone); 606 | break; 607 | } 608 | } 609 | void Layer::rotateReset(bool novalid) 610 | { 611 | bool rotati = true; 612 | if( WaitForSingleObject(this->mut_animloop,0) == WAIT_TIMEOUT ) 613 | rotati = false; 614 | 615 | switch(this->rot){ 616 | case 1: 617 | if( rotati == true ) 618 | image->RotateFlip(Rotate270FlipNone); 619 | if( this->next != NULL ) 620 | this->next->RotateFlip(Rotate270FlipNone); 621 | if( this->prev != NULL ) 622 | this->prev->RotateFlip(Rotate270FlipNone); 623 | break; 624 | case 2: 625 | if( rotati == true ) 626 | image->RotateFlip(Rotate180FlipNone); 627 | if( this->next != NULL ) 628 | this->next->RotateFlip(Rotate180FlipNone); 629 | if( this->prev != NULL ) 630 | this->prev->RotateFlip(Rotate180FlipNone); 631 | break; 632 | case 3: 633 | if( rotati == true ) 634 | this->image->RotateFlip(Rotate90FlipNone); 635 | if( this->next != NULL ) 636 | this->next->RotateFlip(Rotate90FlipNone); 637 | if( this->prev != NULL ) 638 | this->prev->RotateFlip(Rotate90FlipNone); 639 | break; 640 | } 641 | this->rot = 0; 642 | if( novalid == false ) 643 | this->zoomend(); 644 | } 645 | 646 | int Layer::getX() 647 | { 648 | return this->x; 649 | } 650 | int Layer::getY() 651 | { 652 | return this->y; 653 | } 654 | int Layer::getWidth() 655 | { 656 | return this->width; 657 | } 658 | int Layer::getHeight() 659 | { 660 | return this->height; 661 | } 662 | int Layer::getMaxrollHor() 663 | { 664 | if( this->image == NULL ) 665 | return 0; 666 | 667 | RECT client; 668 | GetClientRect(this->core->getWindowHandle(),&client); 669 | 670 | WaitForSingleObject(this->mut_image,INFINITE); 671 | int width = (int)(this->zoom * this->image->GetWidth()); 672 | ReleaseMutex(this->mut_image); 673 | 674 | return abs( min((int)((client.right - width)/2),0) ); 675 | } 676 | int Layer::getMaxrollVer() 677 | { 678 | if( this->image == NULL ) 679 | return 0; 680 | 681 | RECT client; 682 | GetClientRect(this->core->getWindowHandle(),&client); 683 | 684 | WaitForSingleObject(this->mut_image,INFINITE); 685 | int height = (int)(this->zoom * this->image->GetHeight()); 686 | ReleaseMutex(this->mut_image); 687 | 688 | return abs( min((int)((client.bottom - height)/2),0) ); 689 | } 690 | 691 | File *Layer::getFile() 692 | { 693 | if( this->cell != NULL ) 694 | return this->cell->getFile(); 695 | return NULL; 696 | } 697 | 698 | int Layer::getImageWidth() 699 | { 700 | WaitForSingleObject(this->mut_image,INFINITE); 701 | int width = this->image->GetWidth(); 702 | ReleaseMutex(this->mut_image); 703 | return width; 704 | } 705 | int Layer::getImageHeight() 706 | { 707 | WaitForSingleObject(this->mut_image,INFINITE); 708 | int height = this->image->GetHeight(); 709 | ReleaseMutex(this->mut_image); 710 | return height; 711 | } 712 | double Layer::getZoom() 713 | { 714 | return this->zoom; 715 | } 716 | double Layer::getZoom(int width, int height) 717 | { 718 | if( this->fitmode == NULL ) 719 | return this->zoom; 720 | 721 | RECT client = this->getClientSize(); 722 | return this->getZoom(width,height,client.right,client.bottom); 723 | } 724 | double Layer::getZoom(int width, int height, int cwidth, int cheight) 725 | { 726 | if( this->fitmode == NULL ) 727 | return this->zoom; 728 | 729 | width += 2 * FRAME; 730 | height += 2 * FRAME; 731 | 732 | double dx, dy; 733 | if( this->fitmode == FITSCREEN || this->fitmode == FITSCREENOV || 734 | this->fitmode == FITWIDTH || this->fitmode == FITHEIGHT ){ 735 | dx = (double)cwidth / (double)width; 736 | dy = (double)cheight / (double)height; 737 | } 738 | else if( this->fitmode == FITNUMPAD ){ 739 | dx = (double)(3 * cwidth) / (double)width; 740 | dy = (double)(3 * cheight) / (double)height; 741 | dx += ZOOMINIT; 742 | dy += ZOOMINIT; 743 | } 744 | if( this->fitmode == FITSCREENOV ) 745 | return min(ZOOMINIT,min(dx,dy)); 746 | if( this->fitmode == FITSCREEN || this->fitmode == FITNUMPAD ) 747 | return min(dx,dy); 748 | 749 | if( this->fitmode == FITWIDTH ) 750 | return dy; 751 | if( this->fitmode == FITHEIGHT ) 752 | return dx; 753 | 754 | return this->zoom; 755 | } 756 | bool Layer::getSidedraw() 757 | { 758 | return this->sidedraw; 759 | } 760 | int Layer::getFitmode() 761 | { 762 | return this->fitmode; 763 | } 764 | 765 | void Layer::setFitmode(int mode) 766 | { 767 | //double newzoom = ZOOMINIT; 768 | 769 | if( this->fitmode == mode || mode == NULL ){ 770 | this->fitmode = NULL; 771 | this->zoom = ZOOMINIT; 772 | this->zoomend(); 773 | return; 774 | } 775 | else if( mode != DEFAULT ){ 776 | this->fitmode = mode; 777 | this->sidedraw = false; 778 | } 779 | 780 | WaitForSingleObject(this->mut_image,INFINITE); 781 | if( this->image != NULL ) 782 | this->zoom = this->getZoom(this->image->GetWidth(),this->image->GetHeight()); 783 | ReleaseMutex(this->mut_image); 784 | 785 | this->zoomend(); 786 | } 787 | void Layer::unsetFitmode() 788 | { 789 | if( this->fitmode != NULL ){ 790 | this->fitmode = NULL; 791 | if( this->core->getGui() != NULL ) 792 | this->core->getGui()->updateMenu(); 793 | } 794 | } 795 | 796 | void Layer::setSidemode(int mode) 797 | { 798 | if( this->sidemode == mode ) 799 | this->sidemode = NULL; 800 | else 801 | this->sidemode = mode; 802 | 803 | if( this->sidedraw == false && this->getMaxrollHor() == 0 ) 804 | return; 805 | 806 | if( this->sidemode == LEFT ) 807 | this->rollHor = this->getMaxrollHor(); 808 | else if( this->sidemode == RIGHT ) 809 | this->rollHor = -this->getMaxrollHor(); 810 | 811 | this->invalidate(); 812 | } 813 | int Layer::getSidemode() 814 | { 815 | return this->sidemode; 816 | } 817 | 818 | void Layer::setSidedraw() 819 | { 820 | if( this->sidedraw == false ){ 821 | this->sidedraw = true; 822 | if( this->fitmode != NULL ) 823 | this->setFitmode(NULL); 824 | } 825 | else 826 | this->sidedraw = false; 827 | 828 | this->loadContent(NULL); 829 | } 830 | void Layer::setMenuheight(int val) 831 | { 832 | this->menuheight = val; 833 | } 834 | void Layer::setGifDir(int dir) 835 | { 836 | WaitForSingleObject(this->mut_image,INFINITE); 837 | if( dir == DEFAULT ){ 838 | if( this->gifdir == RIGHT ) 839 | this->gifdir = LEFT; 840 | else 841 | this->gifdir = RIGHT; 842 | } 843 | else { 844 | if( this->gifdir != RIGHT && this->gifdir != LEFT ) 845 | this->gifdir = RIGHT; 846 | else 847 | this->gifdir = dir; 848 | } 849 | ReleaseMutex(this->mut_image); 850 | } 851 | void Layer::setCancel(bool set) 852 | { 853 | this->cancel = set; 854 | } 855 | 856 | bool Layer::setWall() 857 | { 858 | bool result = false; 859 | 860 | if( this->image != NULL && this->cell != NULL ){ 861 | CLSID bmpsid; 862 | Core::getEncoder(L"image/bmp", &bmpsid); 863 | FwCHAR *path = NULL; 864 | 865 | if( this->cell->getFile()->isArchived() == true ){ 866 | if( this->core->getExplorer() != NULL ){ 867 | path = new FwCHAR(); 868 | path->getFolderFrom( this->core->getExplorer()->getArchivePath() ); 869 | path->mergeWith( this->cell->getFile()->getFileName() ); 870 | } 871 | else 872 | path = new FwCHAR( this->cell->getFile()->getFileName()->toWCHAR() ); 873 | } 874 | else { 875 | path = new FwCHAR( this->cell->getFile()->getFilePath()->toWCHAR() ); 876 | } 877 | if( this->cell->getFile()->getType() != TYPE_BITMAP ) 878 | path->mergeWith(L".bmp"); 879 | 880 | this->image->Save(path->toWCHAR(),&bmpsid,NULL); 881 | 882 | result = SystemParametersInfo(SPI_SETDESKWALLPAPER,0,path->toWCHAR(), 883 | SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE ); 884 | delete path; 885 | } 886 | return result; 887 | } 888 | 889 | bool Layer::isCancel() 890 | { 891 | return this->cancel; 892 | } 893 | bool Layer::isContent() 894 | { 895 | if( this->image != NULL ) 896 | return true; 897 | return false; 898 | } 899 | bool Layer::isPassMess() 900 | { 901 | bool result = this->passmess; 902 | this->passmess = false; 903 | return result; 904 | } 905 | 906 | void Layer::locate(int init) 907 | { 908 | RECT client = this->getClientSize(); 909 | this->cwidth = client.right; 910 | this->cheight = client.bottom; 911 | 912 | if( this->image == NULL ){ 913 | this->width = this->cwidth; 914 | this->height = this->cheight; 915 | } 916 | else { 917 | WaitForSingleObject(this->mut_image,INFINITE); 918 | this->zoom = this->getZoom(this->image->GetWidth(),this->image->GetHeight(), 919 | this->cwidth,this->cheight); 920 | 921 | this->width = (int)(this->zoom * this->image->GetWidth()); 922 | this->height = (int)(this->zoom * this->image->GetHeight()); 923 | ReleaseMutex(this->mut_image); 924 | 925 | if( WaitForSingleObject(this->mut_animloop,0) == WAIT_TIMEOUT ){ 926 | if( this->rot == ROT_90 || this->rot == ROT_270 ){ 927 | int tmp = this->width; 928 | this->width = this->height; 929 | this->height = tmp; 930 | } 931 | } 932 | else 933 | ReleaseMutex(this->mut_animloop); 934 | } 935 | int hodiff = this->cwidth - this->width; 936 | int vediff = this->cheight - this->height; 937 | 938 | this->x = (int)(hodiff / 2); 939 | this->y = (int)(vediff / 2); 940 | 941 | this->maxrollHor = abs( min(this->x,0) ); 942 | this->maxrollVer = abs( min(this->y,0) ); 943 | 944 | this->minrollVer = -this->maxrollVer; 945 | this->offrollVer = 0;//max(this->y,0); 946 | 947 | if( init != NULL ){ 948 | this->rollHor = 0; 949 | if( this->sidemode == LEFT ) 950 | this->rollHor = this->maxrollHor; 951 | else if( this->sidemode == RIGHT ) 952 | this->rollHor = -this->maxrollHor; 953 | 954 | if( init == TOP ) 955 | this->rollVer = this->maxrollVer + this->offset; 956 | else if( init == BOT ) 957 | this->rollVer = this->minrollVer + this->offset; 958 | this->offset = 0; 959 | } 960 | if( this->image != NULL && this->sidedraw == true ){ 961 | if( this->prev != NULL ) 962 | if( this->y > 0 ) 963 | this->maxrollVer = this->height; 964 | else 965 | this->maxrollVer = -this->y + this->cheight + MARGIN; 966 | 967 | if( this->next != NULL ) 968 | if( this->y > 0 ) 969 | this->minrollVer = -this->height; 970 | else 971 | this->minrollVer = this->y - this->cheight - MARGIN; 972 | } 973 | this->boundRoll(); 974 | 975 | this->x += this->rollHor; 976 | this->y += this->rollVer - this->menuheight; 977 | } 978 | 979 | void Layer::boundRoll() 980 | { 981 | this->rollHor = min(this->rollHor,this->maxrollHor); 982 | this->rollHor = max(this->rollHor,-this->maxrollHor); 983 | 984 | if( this->rollVer > this->maxrollVer ){ 985 | this->offset = this->rollVer - this->maxrollVer; 986 | this->rollVer = min(this->rollVer,this->maxrollVer); 987 | if( this->image != NULL && this->sidedraw == true ) 988 | this->prevContent(); 989 | } 990 | if( this->rollVer < this->minrollVer ){ 991 | this->offset = this->rollVer - this->minrollVer; 992 | this->rollVer = max(this->rollVer,this->minrollVer); 993 | if( this->image != NULL && this->sidedraw == true ) 994 | this->nextContent(); 995 | } 996 | } 997 | 998 | void Layer::boundZoom() 999 | { 1000 | this->zoom = max(this->zoom,ZOOMSTEP); 1001 | } 1002 | 1003 | RECT Layer::getClientSize() 1004 | { 1005 | RECT client; 1006 | client.top = 0; 1007 | client.left = 0; 1008 | client.right = 0; 1009 | client.bottom = 0; 1010 | 1011 | this->fullscreen = false; 1012 | if( this->core->getGui() != NULL ) 1013 | this->fullscreen = this->core->getGui()->isFullscreen(); 1014 | 1015 | if( this->fullscreen == true ){ 1016 | client.right = GetDeviceCaps(GetDC(NULL),HORZRES); 1017 | client.bottom = GetDeviceCaps(GetDC(NULL),VERTRES); 1018 | } 1019 | else 1020 | GetClientRect(this->core->getWindowHandle(),&client); 1021 | 1022 | return client; 1023 | } 1024 | 1025 | void Layer::invalidate(bool full) 1026 | { 1027 | this->fulldraw = full; 1028 | this->core->getDrawer()->invalidate(full); 1029 | } 1030 | 1031 | Image *Layer::scale(Image *source) 1032 | { 1033 | if( source == NULL ) 1034 | return NULL; 1035 | 1036 | double zoom = this->zoom; 1037 | if( source != this->image ) 1038 | zoom = this->getZoom(source->GetWidth(),source->GetHeight()); 1039 | 1040 | int width = (int)(zoom * source->GetWidth()); 1041 | int height = (int)(zoom * source->GetHeight()); 1042 | 1043 | Bitmap *bmp = new Bitmap(width,height); 1044 | Graphics *gfx = Graphics::FromImage(bmp); 1045 | gfx->DrawImage(source,0,0,width,height); 1046 | 1047 | delete gfx; 1048 | return bmp; 1049 | } 1050 | 1051 | void Layer::animate() 1052 | { 1053 | if( this->isTopmost() == false ) 1054 | return; 1055 | if( WaitForSingleObject(this->mut_animloop,0) == WAIT_TIMEOUT ) 1056 | return; 1057 | else 1058 | ReleaseMutex(this->mut_animloop); 1059 | 1060 | if( this->cell == NULL ) 1061 | return; 1062 | if( this->cell->getFile() == NULL ) 1063 | return; 1064 | this->type = this->cell->getFile()->getType(); 1065 | if( this->type == TYPE_TIFFINTEL || this->type == TYPE_TIFFMOTOROLA || 1066 | this->type == TYPE_GIF87a || this->type == TYPE_GIF89a ){ 1067 | 1068 | UINT dCount = this->image->GetFrameDimensionsCount(); 1069 | GUID *dList = new GUID[dCount]; 1070 | this->image->GetFrameDimensionsList(dList,dCount); 1071 | this->dimension = &dList[0]; 1072 | this->frameCount = this->image->GetFrameCount(dimension); 1073 | 1074 | for( UINT i = 1; i < dCount; i++ ) 1075 | delete &dList[i]; 1076 | if( this->frameCount < 2 ){ 1077 | if( this->dimension != NULL ) 1078 | delete this->dimension; 1079 | this->dimension = NULL; 1080 | return; 1081 | } 1082 | } 1083 | else 1084 | return; 1085 | if( this->type != TYPE_GIF87a && this->type != TYPE_GIF89a ) 1086 | return; 1087 | 1088 | this->mut_image = CreateMutex(NULL,false,NULL); 1089 | this->mut_animloop = CreateMutex(NULL,false,NULL); 1090 | this->mut_terminator = CreateMutex(NULL,true,NULL); 1091 | 1092 | this->thrd_anim = CreateThread(NULL,NULL, 1093 | (LPTHREAD_START_ROUTINE)Layer::anim, 1094 | this,NULL,NULL); 1095 | } 1096 | 1097 | DWORD WINAPI Layer::anim(LPVOID param) 1098 | { 1099 | Layer *that = (Layer *)param; 1100 | 1101 | WaitForSingleObject(that->mut_animloop,INFINITE); 1102 | 1103 | WaitForSingleObject(that->mut_image,INFINITE); 1104 | if( that->image == NULL ){ 1105 | ReleaseMutex(that->mut_image); 1106 | return 0; 1107 | } 1108 | int propertySize = that->image->GetPropertyItemSize(PropertyTagFrameDelay); 1109 | PropertyItem *frameDelay = (PropertyItem*) malloc(propertySize); 1110 | that->image->GetPropertyItem(PropertyTagFrameDelay,propertySize,frameDelay); 1111 | 1112 | ReleaseMutex(that->mut_image); 1113 | 1114 | long *delays = (long *)frameDelay->value; 1115 | bool mode = false; 1116 | 1117 | while( true ){ 1118 | if( that->isTopmost() == false ) 1119 | break; 1120 | if( WaitForSingleObject(that->mut_terminator,0) != WAIT_TIMEOUT ){ 1121 | ReleaseMutex(that->mut_terminator); 1122 | ReleaseMutex(that->mut_animloop); 1123 | return 0; 1124 | } 1125 | Sleep( max((delays[that->frameThat] * 100),MINDELAY) ); 1126 | 1127 | WaitForSingleObject(that->mut_image,INFINITE); 1128 | 1129 | if( that->gifdir == RIGHT ) 1130 | mode = that->nextFrame(); 1131 | else if( that->gifdir == LEFT ) 1132 | mode = that->prevFrame(); 1133 | 1134 | if( that->scali != NULL ) 1135 | delete that->scali; 1136 | that->scali = NULL; 1137 | 1138 | if( that->rot != ROT_0 ){ 1139 | that->scali = new Bitmap(that->image->GetWidth(),that->image->GetHeight()); 1140 | Graphics *gfx = Graphics::FromImage(that->scali); 1141 | gfx->DrawImage(that->image,0,0,that->scali->GetWidth(),that->scali->GetHeight()); 1142 | delete gfx; 1143 | } 1144 | ReleaseMutex(that->mut_image); 1145 | 1146 | if( that->rot != ROT_0 ) 1147 | that->rotate(that->scali); 1148 | that->invalidate(mode); 1149 | } 1150 | if( frameDelay != NULL ) 1151 | delete frameDelay; 1152 | 1153 | ReleaseMutex(that->mut_animloop); 1154 | return 0; 1155 | } 1156 | 1157 | bool Layer::isTopmost() 1158 | { 1159 | if( this->core->getDrawer()->getTopmost() == this ) 1160 | return true; 1161 | return false; 1162 | } -------------------------------------------------------------------------------- /Fiew/Layer.h: -------------------------------------------------------------------------------- 1 | using namespace Gdiplus; 2 | 3 | class Core; 4 | class Cell; 5 | 6 | class Layer { 7 | protected: 8 | Core *core; 9 | Cell *cell; 10 | Image *image, *next, *prev, *scali, *scaln, *scalp; 11 | int type, fitmode, sidemode; 12 | 13 | int x, y, width, height, cwidth, cheight; 14 | int rollHor, rollVer, maxrollHor, maxrollVer, minrollVer, offrollVer; 15 | int offset, menuheight, rot, gifdir; 16 | double zoom; 17 | bool fulldraw, sidedraw, zoomdraw, passmess, fullscreen, cancel; 18 | 19 | GUID *dimension; 20 | UINT frameCount, frameThat; 21 | 22 | SolidBrush *Brush_Back; 23 | SolidBrush *Brush_DarkBack; 24 | SolidBrush *Brush_LiteBack; 25 | 26 | Pen *Pen_Border; 27 | Pen *Pen_DarkBorder; 28 | 29 | int FontSize; 30 | 31 | FontFamily *FontFamily_Arial; 32 | Font *Font_Default; 33 | 34 | HANDLE mut_animloop, mut_image, mut_terminator; 35 | HANDLE thrd_anim; 36 | 37 | public: 38 | Layer(Core *core, Image *image = NULL); 39 | virtual ~Layer(); 40 | 41 | void loadContent(int init = TOP); 42 | 43 | virtual void nextImage(int x = FERROR, int y = FERROR); 44 | virtual void prevImage(int x = FERROR, int y = FERROR); 45 | 46 | virtual Bitmap *render(); 47 | void reset(); 48 | virtual void repos(); 49 | 50 | virtual void scroll(int hor, int ver); 51 | virtual void scrollSet(int x, int y); 52 | virtual void scrollHor(int val); 53 | virtual void scrollVer(int val); 54 | 55 | virtual void zoomer(double val = NULL); 56 | virtual void zoomat(double val = ZOOMINIT); 57 | virtual void zoomend(); 58 | 59 | virtual void rotate(int val = NULL); 60 | virtual void rotateReset(bool novalid = false); 61 | 62 | int getX(); 63 | int getY(); 64 | 65 | int getWidth(); 66 | int getHeight(); 67 | File *getFile(); 68 | int getImageWidth(); 69 | int getImageHeight(); 70 | RECT getClientSize(); 71 | 72 | int getMaxrollHor(); 73 | int getMaxrollVer(); 74 | 75 | double getZoom(); 76 | bool getSidedraw(); 77 | int getSidemode(); 78 | int getFitmode(); 79 | 80 | virtual void setFitmode(int mode = DEFAULT); 81 | virtual void unsetFitmode(); 82 | 83 | virtual void setSidemode(int mode = NULL); 84 | 85 | virtual void setSidedraw(); 86 | 87 | void setMenuheight(int val); 88 | void setGifDir(int dir = DEFAULT); 89 | void setCancel(bool set = true); 90 | 91 | bool setWall(); 92 | 93 | bool isCancel(); 94 | bool isContent(); 95 | bool isPassMess(); 96 | 97 | void invalidate(bool full = true); 98 | 99 | static DWORD WINAPI anim(LPVOID param); 100 | 101 | protected: 102 | void init(); 103 | void setPassmess(); 104 | 105 | void afterLoadContent(int init); 106 | 107 | void nextContent(int init = TOP); 108 | void prevContent(int init = BOT); 109 | 110 | bool nextFrame(bool back = false); 111 | bool prevFrame(bool back = false); 112 | 113 | void rotate(Image *image); 114 | 115 | void zoombegin(); 116 | void rotateSet(); 117 | 118 | void locate(int init = NULL); 119 | void boundRoll(); 120 | void boundZoom(); 121 | 122 | double getZoom(int width, int height); 123 | double getZoom(int width, int height, int cwidth, int cheight); 124 | 125 | void animate(); 126 | Image *scale(Image *source); 127 | 128 | bool isTopmost(); 129 | }; 130 | 131 | class Overlay : public Layer 132 | { 133 | public: 134 | Overlay(Core *core, Image *image); 135 | ~Overlay(); 136 | 137 | virtual void nextImage(int x = FERROR, int y = FERROR); 138 | virtual void prevImage(int x = FERROR, int y = FERROR); 139 | 140 | Bitmap *render(); 141 | 142 | virtual void zoomer(double val = NULL); 143 | virtual void zoomat(double val = ZOOMINIT); 144 | virtual void zoomend(); 145 | 146 | virtual void rotate(int val = NULL); 147 | virtual void rotateReset(bool novalid = false); 148 | 149 | virtual void setFitmode(int mode = DEFAULT); 150 | virtual void unsetFitmode(); 151 | virtual void setSidedraw(); 152 | 153 | virtual void setSidemode(int mode = NULL); 154 | 155 | RECT getOverlayRect(); 156 | 157 | protected: 158 | void hide(); 159 | }; 160 | 161 | class Thumblay : public Overlay 162 | { 163 | private: 164 | Cell *lastCell; 165 | int ticker; 166 | int picker; 167 | 168 | public: 169 | Thumblay(Core *core, Image *image); 170 | ~Thumblay(); 171 | 172 | void update(bool init = false); 173 | 174 | void nextImage(int x = FERROR, int y = FERROR); 175 | void prevImage(int x = FERROR, int y = FERROR); 176 | 177 | void scroll(int hor, int ver); 178 | void scrollSet(int x, int y); 179 | void scrollHor(int val); 180 | void scrollVer(int val); 181 | 182 | void zoomer(double val = NULL); 183 | void zoomat(double val = ZOOMINIT); 184 | void zoomend(); 185 | 186 | void rotate(int val = NULL); 187 | void rotateReset(bool novalid = false); 188 | 189 | void setFitmode(int mode = DEFAULT); 190 | void unsetFitmode(); 191 | void setSidedraw(); 192 | 193 | void setSidemode(int mode = NULL); 194 | 195 | Cell *getLastCell(); 196 | 197 | private: 198 | void subrender(); 199 | 200 | void setPicker(int newpick); 201 | int getPicker(int x, int y); 202 | 203 | }; 204 | 205 | class Listlay : public Overlay 206 | { 207 | private: 208 | Cell *lastCell; 209 | int ticker; 210 | 211 | public: 212 | Listlay(Core *core, Image *image); 213 | ~Listlay(); 214 | 215 | void update(bool init = false); 216 | 217 | void nextImage(int x = FERROR, int y = FERROR); 218 | void prevImage(int x = FERROR, int y = FERROR); 219 | 220 | void scroll(int hor, int ver); 221 | void scrollSet(int x, int y); 222 | void scrollHor(int val); 223 | void scrollVer(int val); 224 | 225 | void zoomer(double val = NULL); 226 | void zoomat(double val = ZOOMINIT); 227 | void zoomend(); 228 | 229 | void rotate(int val = NULL); 230 | void rotateReset(bool novalid = false); 231 | 232 | void setFitmode(int mode = DEFAULT); 233 | void unsetFitmode(); 234 | void setSidedraw(); 235 | 236 | void setSidemode(int mode = NULL); 237 | 238 | Cell *getLastCell(); 239 | 240 | private: 241 | void subrender(); 242 | }; -------------------------------------------------------------------------------- /Fiew/Layer_Listlay.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Core.h" 3 | 4 | Listlay::Listlay(Core *core, Image *image) : Overlay(core,image) 5 | { 6 | this->lastCell = NULL; 7 | this->ticker = TICKER_OFF; 8 | 9 | if( this->image != NULL ) 10 | delete this->image; 11 | 12 | if( this->core->getCacher() != NULL ){ 13 | this->lastCell = this->core->getCacher()->getThat(); 14 | this->core->getCacher()->setFull(true,false); 15 | } 16 | 17 | this->image = new Bitmap(OVL_SIZE,OVL_SIZE); 18 | this->update(true); 19 | } 20 | 21 | Listlay::~Listlay() 22 | { 23 | } 24 | 25 | void Listlay::update(bool init) 26 | { 27 | this->subrender(); 28 | this->invalidate(init); 29 | 30 | if( this->core->getCacher() != NULL ){ 31 | if( this->core->getCacher()->isRunning() == true ){ 32 | this->ticker++; 33 | this->ticker = this->ticker % TICKER_STEPS; 34 | SetTimer(this->core->getWindowHandle(),TIMER_THB,THB_TOUT,NULL); 35 | return; 36 | } 37 | } 38 | if( this->ticker > TICKER_OFF ){ 39 | this->ticker = TICKER_OFF; 40 | SetTimer(this->core->getWindowHandle(),TIMER_THB,THB_TOUT,NULL); 41 | } 42 | } 43 | 44 | void Listlay::nextImage(int x, int y) 45 | { 46 | this->setCancel(); 47 | this->hide(); 48 | } 49 | void Listlay::prevImage(int x, int y) 50 | { 51 | this->hide(); 52 | } 53 | 54 | void Listlay::scroll(int hor, int ver) 55 | { 56 | if( this->core->getCacher() != NULL ){ 57 | bool result = false; 58 | HCURSOR last = NULL; 59 | if( this->core->getGui() != NULL ) 60 | last = this->core->getGui()->setCursor(CURSOR_ARRWAIT); 61 | 62 | int limit, i = 0; 63 | if( ver < 0 ){ 64 | if( (result = this->core->getCacher()->next()) == true ){ 65 | limit = (int)(abs(ver) / LST_MOD); 66 | for( i = 0; i < limit; i++ ) 67 | if( this->core->getCacher()->next() == false ) 68 | break; 69 | } 70 | } 71 | else if( ver > 0 ){ 72 | if( (result = this->core->getCacher()->prev()) == true ){ 73 | limit = (int)(abs(ver) / LST_MOD); 74 | for( i = 0; i < limit; i++ ) 75 | if( this->core->getCacher()->prev() == false ) 76 | break; 77 | } 78 | } 79 | if( result == true ){ 80 | this->subrender(); 81 | if( this->core->getGui() != NULL ) 82 | this->core->getGui()->updateText(); 83 | 84 | this->invalidate(false); 85 | } 86 | if( this->core->getGui() != NULL ) 87 | this->core->getGui()->setCursor(last); 88 | } 89 | } 90 | void Listlay::scrollSet(int x, int y) 91 | { 92 | return; 93 | } 94 | void Listlay::scrollHor(int val) 95 | { 96 | return; 97 | } 98 | void Listlay::scrollVer(int val) 99 | { 100 | if( this->core->getCacher() != NULL ){ 101 | bool result = false; 102 | HCURSOR last = NULL; 103 | if( this->core->getGui() != NULL ) 104 | last = this->core->getGui()->setCursor(CURSOR_ARRWAIT); 105 | 106 | if( val < 0 ) 107 | result = this->core->getCacher()->next(); 108 | 109 | else if( val > 0 ) 110 | result = this->core->getCacher()->prev(); 111 | 112 | if( result == true ){ 113 | this->subrender(); 114 | if( this->core->getGui() != NULL ) 115 | this->core->getGui()->updateText(); 116 | 117 | this->invalidate(false); 118 | } 119 | if( this->core->getGui() != NULL ) 120 | this->core->getGui()->setCursor(last); 121 | } 122 | } 123 | 124 | void Listlay::zoomer(double val) 125 | { 126 | return; 127 | } 128 | void Listlay::zoomat(double val) 129 | { 130 | return; 131 | } 132 | void Listlay::zoomend() 133 | { 134 | return; 135 | } 136 | 137 | void Listlay::rotate(int val) 138 | { 139 | return; 140 | } 141 | void Listlay::rotateReset(bool novalid) 142 | { 143 | return; 144 | } 145 | 146 | void Listlay::setFitmode(int mode) 147 | { 148 | return; 149 | } 150 | void Listlay::unsetFitmode() 151 | { 152 | return; 153 | } 154 | void Listlay::setSidedraw() 155 | { 156 | return; 157 | } 158 | void Listlay::setSidemode(int mode) 159 | { 160 | return; 161 | } 162 | 163 | void Listlay::subrender() 164 | { 165 | Graphics *gfx = Graphics::FromImage(this->image); 166 | gfx->Clear(CLR_WHITE); 167 | 168 | Cacher *cacher = this->core->getCacher(); 169 | if( cacher != NULL ){ 170 | FwCHAR *string = NULL; 171 | FwCHAR *name = NULL; 172 | Cell *cell = NULL; 173 | int i, x, y; 174 | bool top, bot, archived = false; 175 | 176 | top = false; 177 | bot = false; 178 | 179 | x = LST_X; 180 | y = LST_Y; 181 | 182 | for( i = -CACHE_SIZE; i < CACHE_SIZE; i++ ){ 183 | cacher->lockCache(); 184 | 185 | if( cacher->getCache() != NULL ){ 186 | cell = cacher->getCache()->gettoThat(i); 187 | if( cell != NULL ){ 188 | if( cell->getFile() != NULL ){ 189 | name = cell->getFile()->getFileName(); 190 | } 191 | if( name != NULL ){ 192 | if( i == 0 ) 193 | gfx->FillRectangle(this->Brush_LiteBack,0,y+1,OVL_SIZE,FONTSIZE+2); 194 | 195 | string = name; 196 | if( cell->getFile()->isArchived() == true ){ 197 | if( archived == false ) 198 | archived = true; 199 | 200 | string = new FwCHAR(L"~"); 201 | string->mergeWith(name); 202 | 203 | x = 3*LST_X; 204 | } 205 | else if( archived == true ){ 206 | archived = false; 207 | x = LST_X; 208 | } 209 | gfx->DrawString(string->toWCHAR(), 210 | string->toLength(), 211 | this->Font_Default, 212 | PointF(x,y), 213 | this->Brush_DarkBack); 214 | 215 | if( archived == true ) 216 | delete string; 217 | } 218 | if( i == -1 && cacher->getCache()->isThatHead() == false ) 219 | top = true; 220 | if( i == 1 && cacher->getCache()->isThatTail() == false ) 221 | bot = true; 222 | } 223 | } 224 | cacher->unlockCache(); 225 | 226 | y += (FONTSIZE + 2); 227 | } 228 | int size = 3; 229 | int width = 20; 230 | int ax = (int)(OVL_SIZE/2); 231 | int ay = LST_Y; 232 | int asize = OVL_SIZE - 2*LST_Y; 233 | Point arrow[3]; 234 | 235 | if( top == true ){ 236 | arrow[0].X = ax - width; 237 | arrow[0].Y = ay; 238 | arrow[1].X = ax; 239 | arrow[1].Y = ay - width; 240 | arrow[2].X = ax + width; 241 | arrow[2].Y = ay; 242 | gfx->FillPolygon(this->Brush_LiteBack,arrow,size); 243 | } 244 | if( bot == true ){ 245 | arrow[0].X = ax - width; 246 | arrow[0].Y = ay + asize; 247 | arrow[1].X = ax; 248 | arrow[1].Y = ay + asize + width; 249 | arrow[2].X = ax + width; 250 | arrow[2].Y = ay + asize; 251 | gfx->FillPolygon(this->Brush_LiteBack,arrow,size); 252 | } 253 | } 254 | if( this->ticker > TICKER_OFF ){ 255 | int tsize = TICKER_SIZE; 256 | int tx,ty; 257 | if( this->ticker == 0 ){ 258 | tx = OVL_SIZE - 2*TICKER_INDENT; 259 | ty = OVL_SIZE - 2*TICKER_INDENT; 260 | } 261 | if( this->ticker == 1 ){ 262 | tx = OVL_SIZE - TICKER_INDENT; 263 | ty = OVL_SIZE - 2*TICKER_INDENT; 264 | } 265 | if( this->ticker == 2 ){ 266 | tx = OVL_SIZE - TICKER_INDENT; 267 | ty = OVL_SIZE - TICKER_INDENT; 268 | } 269 | if( this->ticker == 3 ){ 270 | tx = OVL_SIZE - 2*TICKER_INDENT; 271 | ty = OVL_SIZE - TICKER_INDENT; 272 | } 273 | gfx->FillRectangle(this->Brush_DarkBack,tx,ty,tsize,tsize); 274 | } 275 | delete gfx; 276 | } 277 | 278 | Cell *Listlay::getLastCell() 279 | { 280 | return this->lastCell; 281 | } -------------------------------------------------------------------------------- /Fiew/Layer_Overlay.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Core.h" 3 | 4 | Overlay::Overlay(Core *core, Image *image) : Layer(core,image) 5 | { 6 | this->fitmode = NULL; 7 | } 8 | 9 | Overlay::~Overlay() 10 | { 11 | } 12 | 13 | void Overlay::nextImage(int x, int y) 14 | { 15 | this->hide(); 16 | } 17 | void Overlay::prevImage(int x, int y) 18 | { 19 | this->hide(); 20 | } 21 | 22 | Bitmap *Overlay::render() 23 | { 24 | this->locate(); 25 | 26 | int frame = FRAME; 27 | Bitmap *scene = NULL; 28 | if( this->fulldraw == true ) 29 | scene = new Bitmap(this->cwidth,this->cheight); 30 | else 31 | scene = new Bitmap(this->width,this->height); 32 | 33 | Graphics *tmpgfx = Graphics::FromImage(scene); 34 | 35 | if( this->fulldraw == true ){ 36 | tmpgfx->Clear(CLR_WHITE_ALPHA); 37 | 38 | if( this->image != NULL ){ 39 | tmpgfx->DrawRectangle(this->Pen_Border, 40 | this->x - frame, 41 | this->y - frame, 42 | this->width + frame + 1, 43 | this->height + frame + 1); 44 | 45 | tmpgfx->DrawImage(this->image,this->x,this->y,this->width,this->height); 46 | } 47 | this->x = 0; 48 | this->y = 0; 49 | this->width = scene->GetWidth(); 50 | this->height = scene->GetHeight(); 51 | } 52 | else { 53 | tmpgfx->DrawImage(this->image,0,0,this->width,this->height); 54 | } 55 | this->fulldraw = true; 56 | delete tmpgfx; 57 | 58 | return scene; 59 | } 60 | 61 | void Overlay::zoomer(double val) 62 | { 63 | return; 64 | } 65 | void Overlay::zoomat(double val) 66 | { 67 | return; 68 | } 69 | void Overlay::zoomend() 70 | { 71 | return; 72 | } 73 | 74 | void Overlay::rotate(int val) 75 | { 76 | return; 77 | } 78 | void Overlay::rotateReset(bool novalid) 79 | { 80 | return; 81 | } 82 | 83 | void Overlay::setFitmode(int mode) 84 | { 85 | return; 86 | } 87 | void Overlay::unsetFitmode() 88 | { 89 | return; 90 | } 91 | void Overlay::setSidedraw() 92 | { 93 | return; 94 | } 95 | void Overlay::setSidemode(int mode) 96 | { 97 | return; 98 | } 99 | 100 | void Overlay::hide() 101 | { 102 | SetTimer(this->core->getWindowHandle(),TIMER_OVL,OVL_HIDEOUT,NULL); 103 | } 104 | 105 | RECT Overlay::getOverlayRect() 106 | { 107 | RECT client = this->getClientSize(); 108 | 109 | RECT overlay; 110 | 111 | overlay.left = (int)((client.right - OVL_SIZE)/2); 112 | overlay.top = (int)((client.bottom - OVL_SIZE)/2); 113 | overlay.right = overlay.left + OVL_SIZE; 114 | overlay.bottom = overlay.top + OVL_SIZE; 115 | 116 | return overlay; 117 | } -------------------------------------------------------------------------------- /Fiew/Layer_Thumblay.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Core.h" 3 | 4 | Thumblay::Thumblay(Core *core, Image *image) : Overlay(core,image) 5 | { 6 | this->lastCell = NULL; 7 | this->ticker = TICKER_OFF; 8 | this->picker = NULL; 9 | 10 | if( this->image != NULL ) 11 | delete this->image; 12 | 13 | if( this->core->getCacher() != NULL ){ 14 | this->lastCell = this->core->getCacher()->getThat(); 15 | this->core->getCacher()->setFull(true); 16 | } 17 | 18 | this->image = new Bitmap(OVL_SIZE,OVL_SIZE); 19 | this->update(true); 20 | } 21 | 22 | Thumblay::~Thumblay() 23 | { 24 | } 25 | 26 | void Thumblay::update(bool init) 27 | { 28 | this->subrender(); 29 | this->invalidate(init); 30 | 31 | if( this->core->getCacher() != NULL ){ 32 | if( this->core->getCacher()->isRunning() == true ){ 33 | this->ticker++; 34 | this->ticker = this->ticker % TICKER_STEPS; 35 | SetTimer(this->core->getWindowHandle(),TIMER_THB,THB_TOUT,NULL); 36 | return; 37 | } 38 | } 39 | if( this->ticker > TICKER_OFF ){ 40 | this->ticker = TICKER_OFF; 41 | SetTimer(this->core->getWindowHandle(),TIMER_THB,THB_TOUT,NULL); 42 | } 43 | } 44 | 45 | void Thumblay::nextImage(int x, int y) 46 | { 47 | this->setCancel(); 48 | this->hide(); 49 | } 50 | void Thumblay::prevImage(int x, int y) 51 | { 52 | if( x != FERROR && y != FERROR ){ 53 | int newpick = this->getPicker(x,y); 54 | this->setPicker(newpick); 55 | } 56 | } 57 | 58 | void Thumblay::setPicker(int newpick) 59 | { 60 | if( this->core->getCacher() != NULL ){ 61 | if( newpick == this->picker ) 62 | this->hide(); 63 | else if( newpick != INT_MAX ){ 64 | HCURSOR last = NULL; 65 | if( this->core->getGui() != NULL ) 66 | last = this->core->getGui()->setCursor(CURSOR_ARRWAIT); 67 | 68 | int i, diff = abs(newpick - this->picker); 69 | bool result = false; 70 | 71 | for( i = 0; i < diff; i++ ){ 72 | if( newpick < this->picker ){ 73 | if( this->core->getCacher()->prev() == false ) 74 | break; 75 | this->picker--; 76 | if( this->picker < -THB_COUNT ) 77 | this->picker = -THB_COUNT + THB_ROW - 1; 78 | 79 | result = true; 80 | } 81 | else { 82 | if( this->core->getCacher()->next() == false ) 83 | break; 84 | this->picker++; 85 | if( this->picker > THB_COUNT ) 86 | this->picker = THB_COUNT - THB_ROW + 1; 87 | 88 | result = true; 89 | } 90 | } 91 | if( result == true ){ 92 | this->subrender(); 93 | if( this->core->getGui() != NULL ) 94 | this->core->getGui()->updateText(); 95 | 96 | this->invalidate(false); 97 | } 98 | if( this->core->getGui() != NULL ) 99 | this->core->getGui()->setCursor(last); 100 | } 101 | } 102 | } 103 | 104 | int Thumblay::getPicker(int x, int y) 105 | { 106 | RECT lay = this->getOverlayRect(); 107 | int picker = INT_MAX; 108 | 109 | if( x > lay.left && x < lay.right && 110 | y > lay.top && y < lay.bottom ){ 111 | 112 | x -= (lay.left + OVL_MARGIN); 113 | y -= (lay.top + OVL_MARGIN); 114 | 115 | int col = (int)floor( (double)(x / (THB_SMSIZE + THB_SPACE)) ); 116 | int row = (int)floor( (double)(y / (THB_SMSIZE + THB_SPACE)) ); 117 | 118 | if( col < THB_ROW && row < THB_ROW ) 119 | picker = col - THB_COUNT + THB_ROW * row; 120 | } 121 | return picker; 122 | } 123 | 124 | void Thumblay::scroll(int hor, int ver) 125 | { 126 | return; 127 | } 128 | void Thumblay::scrollSet(int x, int y) 129 | { 130 | return; 131 | } 132 | void Thumblay::scrollHor(int val) 133 | { 134 | if( val < 0 ) 135 | this->setPicker(this->picker + 1); 136 | else if( val > 0 ) 137 | this->setPicker(this->picker - 1); 138 | 139 | /*if( this->core->getCacher() != NULL ){ 140 | bool result = false; 141 | HCURSOR last = NULL; 142 | if( this->core->getGui() != NULL ) 143 | last = this->core->getGui()->setCursor(CURSOR_ARRWAIT); 144 | 145 | if( val < 0 ) 146 | result = this->core->getCacher()->next(); 147 | 148 | else if( val > 0 ) 149 | result = this->core->getCacher()->prev(); 150 | 151 | if( result == true ){ 152 | this->subrender(); 153 | if( this->core->getGui() != NULL ) 154 | this->core->getGui()->updateText(); 155 | 156 | this->invalidate(false); 157 | } 158 | if( this->core->getGui() != NULL ) 159 | this->core->getGui()->setCursor(last); 160 | }*/ 161 | } 162 | void Thumblay::scrollVer(int val) 163 | { 164 | if( val < 0 ) 165 | this->setPicker(this->picker + THB_ROW); 166 | else if( val > 0 ) 167 | this->setPicker(this->picker - THB_ROW); 168 | 169 | /*if( this->core->getCacher() != NULL ){ 170 | bool result = false; 171 | HCURSOR last = NULL; 172 | if( this->core->getGui() != NULL ) 173 | last = this->core->getGui()->setCursor(CURSOR_ARRWAIT); 174 | 175 | int i = 0; 176 | if( val < 0 ) 177 | for( i = 0; i < THB_ROW; i++ ) 178 | if( this->core->getCacher()->next() == true ) 179 | result = true; 180 | else 181 | break; 182 | 183 | else if( val > 0 ) 184 | for( i = 0; i < THB_ROW; i++ ) 185 | if( this->core->getCacher()->prev() == true ) 186 | result = true; 187 | else 188 | break; 189 | 190 | if( result == true ){ 191 | this->subrender(); 192 | if( this->core->getGui() != NULL ) 193 | this->core->getGui()->updateText(); 194 | 195 | this->invalidate(false); 196 | } 197 | if( this->core->getGui() != NULL ) 198 | this->core->getGui()->setCursor(last); 199 | }*/ 200 | } 201 | 202 | void Thumblay::zoomer(double val) 203 | { 204 | return; 205 | } 206 | void Thumblay::zoomat(double val) 207 | { 208 | return; 209 | } 210 | void Thumblay::zoomend() 211 | { 212 | return; 213 | } 214 | 215 | void Thumblay::rotate(int val) 216 | { 217 | return; 218 | } 219 | void Thumblay::rotateReset(bool novalid) 220 | { 221 | return; 222 | } 223 | 224 | void Thumblay::setFitmode(int mode) 225 | { 226 | return; 227 | } 228 | void Thumblay::unsetFitmode() 229 | { 230 | return; 231 | } 232 | void Thumblay::setSidedraw() 233 | { 234 | return; 235 | } 236 | void Thumblay::setSidemode(int mode) 237 | { 238 | return; 239 | } 240 | 241 | void Thumblay::subrender() 242 | { 243 | Graphics *gfx = Graphics::FromImage(this->image); 244 | gfx->Clear(CLR_WHITE); 245 | 246 | Cacher *cacher = this->core->getCacher(); 247 | if( cacher != NULL ){ 248 | Image *thumb = NULL; 249 | Cell *cell = NULL; 250 | int i, x, y, mx, my, count; 251 | bool top, bot, left, right; 252 | 253 | right = false; 254 | left = false; 255 | top = false; 256 | bot = false; 257 | 258 | mx = OVL_MARGIN + 2 * (THB_SMSIZE + THB_SPACE); 259 | my = mx; 260 | 261 | x = y = OVL_MARGIN; 262 | count = 0; 263 | 264 | for( i = -THB_COUNT - this->picker; i <= THB_COUNT - this->picker; i++ ){ 265 | cacher->lockCache(); 266 | 267 | if( cacher->getCache() != NULL ){ 268 | cell = cacher->getCache()->gettoThat(i); 269 | if( cell != NULL ){ 270 | thumb = cell->getImageThumb(); 271 | if( thumb != NULL ){ 272 | if( i != 0 ){ 273 | gfx->DrawImage(thumb,x,y,THB_SMSIZE,THB_SMSIZE); 274 | gfx->DrawRectangle(this->Pen_Border, 275 | x, 276 | y, 277 | THB_SMSIZE, 278 | THB_SMSIZE); 279 | } 280 | else { 281 | mx = x + (int)((THB_SIZE - THB_SMSIZE)/4); 282 | my = y + (int)((THB_SIZE - THB_SMSIZE)/4); 283 | } 284 | } 285 | if( i == -THB_ROW ) 286 | top = true; 287 | if( i == THB_ROW ) 288 | bot = true; 289 | if( i == -1 && cacher->getCache()->isThatHead() == false ) 290 | left = true; 291 | if( i == 1 && cacher->getCache()->isThatTail() == false ) 292 | right = true; 293 | } 294 | } 295 | count++; 296 | x += THB_SMSIZE + THB_SPACE; 297 | if( count >= THB_ROW ){ 298 | x = OVL_MARGIN; 299 | y += THB_SMSIZE + THB_SPACE; 300 | count = 0; 301 | } 302 | cacher->unlockCache(); 303 | } 304 | int frame = 2; 305 | cacher->lockCache(); 306 | if( cacher->getCache() != NULL ){ 307 | cell = cacher->getThat(); 308 | if( cell != NULL ){ 309 | thumb = cell->getImageThumb(); 310 | if( thumb != NULL ){ 311 | gfx->FillRectangle(this->Brush_Back, 312 | mx - THB_SIZE/4, 313 | my - THB_SIZE/4, 314 | THB_SIZE, 315 | THB_SIZE); 316 | gfx->DrawImage(thumb, 317 | mx - THB_SIZE/4, 318 | my - THB_SIZE/4, 319 | THB_SIZE, 320 | THB_SIZE); 321 | gfx->DrawRectangle(this->Pen_Border, 322 | mx - THB_SIZE/4, 323 | my - THB_SIZE/4, 324 | THB_SIZE, 325 | THB_SIZE); 326 | gfx->DrawRectangle( this->Pen_DarkBorder, 327 | mx - frame - THB_SIZE/4, 328 | my - frame - THB_SIZE/4, 329 | THB_SIZE + 2*frame, 330 | THB_SIZE + 2*frame ); 331 | } 332 | } 333 | } 334 | cacher->unlockCache(); 335 | 336 | int size = 3; 337 | int width = 10; 338 | int ax = (int)(mx - frame - THB_SIZE/4); 339 | int ay = (int)(my - frame - THB_SIZE/4); 340 | int asize = THB_SIZE + 2*frame; 341 | Point arrow[3]; 342 | 343 | if( top == true ){ 344 | arrow[0].X = (int)(ax + (THB_SIZE/2) - width); 345 | arrow[0].Y = ay; 346 | arrow[1].X = (int)(ax + (THB_SIZE/2)); 347 | arrow[1].Y = ay - width; 348 | arrow[2].X = (int)(ax + (THB_SIZE/2) + width); 349 | arrow[2].Y = ay; 350 | gfx->FillPolygon(this->Brush_DarkBack,arrow,size); 351 | } 352 | if( bot == true ){ 353 | arrow[0].X = (int)(ax + (THB_SIZE/2) - width); 354 | arrow[0].Y = ay + asize; 355 | arrow[1].X = (int)(ax + (THB_SIZE/2)); 356 | arrow[1].Y = ay + asize + width; 357 | arrow[2].X = (int)(ax + (THB_SIZE/2) + width); 358 | arrow[2].Y = ay + asize; 359 | gfx->FillPolygon(this->Brush_DarkBack,arrow,size); 360 | } 361 | if( left == true ){ 362 | arrow[0].X = ax; 363 | arrow[0].Y = (int)(ay + (THB_SIZE/2) - width); 364 | arrow[1].X = ax - width; 365 | arrow[1].Y = (int)(ay + (THB_SIZE/2)); 366 | arrow[2].X = ax; 367 | arrow[2].Y = (int)(ay + (THB_SIZE/2) + width); 368 | gfx->FillPolygon(this->Brush_DarkBack,arrow,size); 369 | } 370 | if( right == true ){ 371 | arrow[0].X = ax + asize; 372 | arrow[0].Y = (int)(ay + (THB_SIZE/2) - width); 373 | arrow[1].X = ax + asize + width; 374 | arrow[1].Y = (int)(ay + (THB_SIZE/2)); 375 | arrow[2].X = ax + asize; 376 | arrow[2].Y = (int)(ay + (THB_SIZE/2) + width); 377 | gfx->FillPolygon(this->Brush_DarkBack,arrow,size); 378 | } 379 | } 380 | if( this->ticker > TICKER_OFF ){ 381 | int tsize = TICKER_SIZE; 382 | int tx,ty; 383 | if( this->ticker == 0 ){ 384 | tx = OVL_SIZE - 2*TICKER_INDENT; 385 | ty = OVL_SIZE - 2*TICKER_INDENT; 386 | } 387 | if( this->ticker == 1 ){ 388 | tx = OVL_SIZE - TICKER_INDENT; 389 | ty = OVL_SIZE - 2*TICKER_INDENT; 390 | } 391 | if( this->ticker == 2 ){ 392 | tx = OVL_SIZE - TICKER_INDENT; 393 | ty = OVL_SIZE - TICKER_INDENT; 394 | } 395 | if( this->ticker == 3 ){ 396 | tx = OVL_SIZE - 2*TICKER_INDENT; 397 | ty = OVL_SIZE - TICKER_INDENT; 398 | } 399 | gfx->FillRectangle(this->Brush_DarkBack,tx,ty,tsize,tsize); 400 | } 401 | delete gfx; 402 | } 403 | 404 | Cell *Thumblay::getLastCell() 405 | { 406 | return this->lastCell; 407 | } -------------------------------------------------------------------------------- /Fiew/List.h: -------------------------------------------------------------------------------- 1 | template 2 | class List 3 | { 4 | private: 5 | int count; 6 | 7 | void countUp() 8 | { 9 | this->count++; 10 | } 11 | void countDown() 12 | { 13 | this->count--; 14 | } 15 | 16 | public: 17 | class Node 18 | { 19 | private: 20 | T *object; 21 | 22 | Node *next; 23 | Node *prev; 24 | 25 | public: 26 | Node(T *object) 27 | { 28 | this->object = object; 29 | 30 | this->next = NULL; 31 | this->prev = NULL; 32 | } 33 | ~Node() 34 | { 35 | delete this->object; 36 | } 37 | 38 | void setNext(Node *next) 39 | { 40 | this->next = next; 41 | } 42 | void setPrev(Node *prev) 43 | { 44 | this->prev = prev; 45 | } 46 | 47 | Node *getNext() 48 | { 49 | return this->next; 50 | } 51 | Node *getPrev() 52 | { 53 | return this->prev; 54 | } 55 | 56 | T *getObj() 57 | { 58 | return this->object; 59 | } 60 | 61 | }; 62 | private: 63 | Node *head, *that, *tail, *left, *right; 64 | 65 | public: 66 | List() 67 | { 68 | this->count = 0; 69 | 70 | this->head = NULL; 71 | this->that = NULL; 72 | this->tail = NULL; 73 | 74 | this->left = NULL; 75 | this->right = NULL; 76 | } 77 | ~List() 78 | { 79 | this->that = this->head; 80 | 81 | while( this->that != NULL ){ 82 | this->head = this->that->getNext(); 83 | /* causes assertion error unless vars initialized with 'new' ! */ 84 | delete this->that; 85 | this->that = this->head; 86 | } 87 | } 88 | 89 | bool add(T *object) 90 | { 91 | if( object == NULL ) 92 | return false; 93 | 94 | return this->add( new Node(object) ); 95 | } 96 | bool add(Node *newton) 97 | { 98 | if( newton == NULL ) 99 | return false; 100 | 101 | newton->setNext(NULL); 102 | newton->setPrev(NULL); 103 | 104 | if( this->tail == NULL ){ 105 | this->tail = newton; 106 | this->that = this->tail; 107 | this->head = this->tail; 108 | 109 | this->left = this->that; 110 | this->right = this->that; 111 | } 112 | else { 113 | newton->setPrev(this->tail); 114 | this->tail->setNext(newton); 115 | this->tail = newton; 116 | } 117 | this->countUp(); 118 | return true; 119 | } 120 | bool addToHead(T* object) 121 | { 122 | if( object == NULL ) 123 | return false; 124 | 125 | return this->addToHead( new Node(object) ); 126 | } 127 | bool addToHead(Node *newton) 128 | { 129 | if( newton == NULL ) 130 | return false; 131 | 132 | newton->setNext(NULL); 133 | newton->setPrev(NULL); 134 | 135 | if( this->head == NULL ){ 136 | this->head = newton; 137 | this->that = this->head; 138 | this->tail = this->head; 139 | 140 | this->left = this->that; 141 | this->right = this->that; 142 | } 143 | else { 144 | newton->setNext(this->head); 145 | this->head->setPrev(newton); 146 | this->head = newton; 147 | } 148 | this->countUp(); 149 | return true; 150 | } 151 | 152 | T *remove(Node *object) 153 | { 154 | Node *tmp = object; 155 | 156 | if( tmp != NULL ){ 157 | Node *tmpprev = tmp->getPrev(); 158 | Node *tmpnext = tmp->getNext(); 159 | 160 | if( tmpprev != NULL ) 161 | tmpprev->setNext(tmpnext); 162 | if( tmpnext != NULL ) 163 | tmpnext->setPrev(tmpprev); 164 | if( tmp == this->head ) 165 | this->head = tmpnext; 166 | if( tmp == this->that ) 167 | if( tmpnext != NULL ) 168 | this->that = tmpnext; 169 | else 170 | this->that = tmpprev; 171 | if( tmp == this->tail ) 172 | this->tail = tmpprev; 173 | 174 | if( tmp == this->left ) 175 | if( tmpprev != NULL ) 176 | this->left = tmpprev; 177 | else 178 | this->left = tmpnext; 179 | if( tmp == this->right ) 180 | if( tmpnext != NULL ) 181 | this->right = tmpnext; 182 | else 183 | this->right = tmpprev; 184 | 185 | this->countDown(); 186 | return tmp->getObj(); 187 | } 188 | return NULL; 189 | } 190 | T *remove(T *object) 191 | { 192 | Node *tmp = this->head; 193 | 194 | if( tmp == NULL ) 195 | return NULL; 196 | while( tmp->getObj() != object && tmp != NULL ) 197 | tmp = tmp->getNext(); 198 | 199 | if( tmp != NULL ){ 200 | this->remove(tmp); 201 | return object; 202 | } 203 | return NULL; 204 | } 205 | 206 | T *removeThat() 207 | { 208 | return this->remove(this->that); 209 | } 210 | T *removeHead() 211 | { 212 | return this->remove(this->head); 213 | } 214 | T *removeTail() 215 | { 216 | return this->remove(this->tail); 217 | } 218 | 219 | /*bool next() 220 | { 221 | if( this->that != NULL ){ 222 | if( this->that->getNext() != NULL ){ 223 | this->that = this->that->getNext(); 224 | return true; 225 | } 226 | } 227 | return false; 228 | } 229 | bool prev() 230 | { 231 | if( this->that != NULL ){ 232 | if( this->that->getPrev() != NULL ){ 233 | this->that = this->that->getPrev(); 234 | return true; 235 | } 236 | } 237 | return false; 238 | }*/ 239 | bool next(int id = NULL) 240 | { 241 | Node *tmp = this->that; 242 | if( id == LEFT ) 243 | tmp = this->left; 244 | else if( id == RIGHT ) 245 | tmp = this->right; 246 | 247 | if( tmp != NULL ){ 248 | if( tmp->getNext() != NULL ){ 249 | tmp = tmp->getNext(); 250 | if( id == LEFT ) 251 | this->left = tmp; 252 | else if( id == RIGHT ) 253 | this->right = tmp; 254 | else 255 | this->that = tmp; 256 | return true; 257 | } 258 | } 259 | return false; 260 | } 261 | bool prev(int id = NULL) 262 | { 263 | Node *tmp = this->that; 264 | if( id == LEFT ) 265 | tmp = this->left; 266 | else if( id == RIGHT ) 267 | tmp = this->right; 268 | 269 | if( tmp != NULL ){ 270 | if( tmp->getPrev() != NULL ){ 271 | tmp = tmp->getPrev(); 272 | if( id == LEFT ) 273 | this->left = tmp; 274 | else if( id == RIGHT ) 275 | this->right = tmp; 276 | else 277 | this->that = tmp; 278 | return true; 279 | } 280 | } 281 | return false; 282 | } 283 | 284 | bool gotoHead() 285 | { 286 | if( this->that != NULL ){ 287 | this->that = this->head; 288 | return true; 289 | } 290 | return false; 291 | } 292 | bool lefttoHead() 293 | { 294 | if( this->left != NULL ){ 295 | this->left = this->head; 296 | return true; 297 | } 298 | return false; 299 | } 300 | bool righttoHead() 301 | { 302 | if( this->right != NULL ){ 303 | this->right = this->head; 304 | return true; 305 | } 306 | return false; 307 | } 308 | bool gotoTail() 309 | { 310 | if( this->that != NULL ){ 311 | this->that = this->tail; 312 | return true; 313 | } 314 | return false; 315 | } 316 | bool lefttoTail() 317 | { 318 | if( this->left != NULL ){ 319 | this->left = this->tail; 320 | return true; 321 | } 322 | return false; 323 | } 324 | bool righttoTail() 325 | { 326 | if( this->right != NULL ){ 327 | this->right = this->tail; 328 | return true; 329 | } 330 | return false; 331 | } 332 | 333 | void gotoThat(T *object) 334 | { 335 | Node *tmp = this->head; 336 | 337 | while( tmp != NULL ){ 338 | if( tmp->getObj() == object ){ 339 | this->that = tmp; 340 | break; 341 | } 342 | tmp = tmp->getNext(); 343 | } 344 | } 345 | 346 | T *getThat() 347 | { 348 | if( this->that != NULL ) 349 | return this->that->getObj(); 350 | return NULL; 351 | } 352 | T *getHead() 353 | { 354 | if( this->head != NULL ) 355 | return this->head->getObj(); 356 | return NULL; 357 | } 358 | T *getTail() 359 | { 360 | if( this->tail != NULL ) 361 | return this->tail->getObj(); 362 | return NULL; 363 | } 364 | T *getLeft() 365 | { 366 | if( this->left != NULL ) 367 | return this->left->getObj(); 368 | return NULL; 369 | } 370 | T *getRight() 371 | { 372 | if( this->right != NULL ) 373 | return this->right->getObj(); 374 | return NULL; 375 | } 376 | 377 | T *getLeftoThat(int count) 378 | { 379 | Node *tmp = this->that; 380 | 381 | while( count > 0 && tmp != NULL ){ 382 | tmp = tmp->getPrev(); 383 | count--; 384 | } 385 | if( tmp != NULL ) 386 | return tmp->getObj(); 387 | return NULL; 388 | } 389 | T *getRightoThat(int count) 390 | { 391 | Node *tmp = this->that; 392 | 393 | while( count > 0 && tmp != NULL ){ 394 | tmp = tmp->getNext(); 395 | count--; 396 | } 397 | if( tmp != NULL ) 398 | return tmp->getObj(); 399 | return NULL; 400 | } 401 | T *gettoThat(int count) 402 | { 403 | if( count < 0 ) 404 | return this->getLeftoThat(abs(count)); 405 | if( count > 0 ) 406 | return this->getRightoThat(abs(count)); 407 | return this->getThat(); 408 | } 409 | 410 | Node *getThatNode() 411 | { 412 | return this->that; 413 | } 414 | Node *getThatHead() 415 | { 416 | return this->head; 417 | } 418 | Node *getThatTail() 419 | { 420 | return this->tail; 421 | } 422 | 423 | bool isThatHead() 424 | { 425 | if( this->that == this->head ) 426 | return true; 427 | return false; 428 | } 429 | bool isThatTail() 430 | { 431 | if( this->that == this->tail ) 432 | return true; 433 | return false; 434 | } 435 | 436 | int getCount() 437 | { 438 | return this->count; 439 | } 440 | int countLeftoThat() 441 | { 442 | Node *tmp = this->that; 443 | int count = 0; 444 | 445 | if( tmp == NULL ) 446 | return count; 447 | 448 | while( tmp->getPrev() != NULL ){ 449 | tmp = tmp->getPrev(); 450 | count++; 451 | } 452 | 453 | return count; 454 | } 455 | int countRightoThat() 456 | { 457 | Node *tmp = this->that; 458 | int count = 0; 459 | 460 | if( tmp == NULL ) 461 | return count; 462 | 463 | while( tmp->getNext() != NULL ){ 464 | tmp = tmp->getNext(); 465 | count++; 466 | } 467 | return count; 468 | } 469 | 470 | void setThat(Node *object) 471 | { 472 | this->that = object; 473 | this->left = this->that; 474 | this->right = this->that; 475 | } 476 | 477 | void setThat(T *object) 478 | { 479 | Node *tmp = this->head; 480 | 481 | while( tmp != NULL ){ 482 | if( tmp->getObj() == object ){ 483 | this->setThat(tmp); 484 | break; 485 | } 486 | tmp = tmp->getNext(); 487 | } 488 | } 489 | }; -------------------------------------------------------------------------------- /Fiew/OVL_EN/ovl_about.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/f055/fiew-image-viewer/314e86cbfbb95527783e9071ed3c97a9cdc93497/Fiew/OVL_EN/ovl_about.png -------------------------------------------------------------------------------- /Fiew/OVL_EN/ovl_manual.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/f055/fiew-image-viewer/314e86cbfbb95527783e9071ed3c97a9cdc93497/Fiew/OVL_EN/ovl_manual.png -------------------------------------------------------------------------------- /Fiew/OVL_PL/ovl_about.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/f055/fiew-image-viewer/314e86cbfbb95527783e9071ed3c97a9cdc93497/Fiew/OVL_PL/ovl_about.png -------------------------------------------------------------------------------- /Fiew/OVL_PL/ovl_manual.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/f055/fiew-image-viewer/314e86cbfbb95527783e9071ed3c97a9cdc93497/Fiew/OVL_PL/ovl_manual.png -------------------------------------------------------------------------------- /Fiew/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | WIN32 APPLICATION : Fiew Project Overview 3 | ======================================================================== 4 | 5 | AppWizard has created this Fiew application for you. 6 | 7 | This file contains a summary of what you will find in each of the files that 8 | make up your Fiew application. 9 | 10 | 11 | Fiew.vcproj 12 | This is the main project file for VC++ projects generated using an Application Wizard. 13 | It contains information about the version of Visual C++ that generated the file, and 14 | information about the platforms, configurations, and project features selected with the 15 | Application Wizard. 16 | 17 | Fiew.cpp 18 | This is the main application source file. 19 | 20 | ///////////////////////////////////////////////////////////////////////////// 21 | AppWizard has created the following resources: 22 | 23 | Fiew.rc 24 | This is a listing of all of the Microsoft Windows resources that the 25 | program uses. It includes the icons, bitmaps, and cursors that are stored 26 | in the RES subdirectory. This file can be directly edited in Microsoft 27 | Visual C++. 28 | 29 | Resource.h 30 | This is the standard header file, which defines new resource IDs. 31 | Microsoft Visual C++ reads and updates this file. 32 | 33 | Fiew.ico 34 | This is an icon file, which is used as the application's icon (32x32). 35 | This icon is included by the main resource file Fiew.rc. 36 | 37 | small.ico 38 | This is an icon file, which contains a smaller version (16x16) 39 | of the application's icon. This icon is included by the main resource 40 | file Fiew.rc. 41 | 42 | ///////////////////////////////////////////////////////////////////////////// 43 | Other standard files: 44 | 45 | StdAfx.h, StdAfx.cpp 46 | These files are used to build a precompiled header (PCH) file 47 | named Fiew.pch and a precompiled types file named StdAfx.obj. 48 | 49 | ///////////////////////////////////////////////////////////////////////////// 50 | Other notes: 51 | 52 | AppWizard uses "TODO:" comments to indicate parts of the source code you 53 | should add to or customize. 54 | 55 | ///////////////////////////////////////////////////////////////////////////// 56 | -------------------------------------------------------------------------------- /Fiew/XUn.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Core.h" 3 | 4 | XUn::XUn(WCHAR *archivepath) 5 | { 6 | this->path = new FwCHAR(archivepath); 7 | this->buffer = NULL; 8 | this->comment = NULL; 9 | 10 | this->extracting = false; 11 | 12 | this->error = 0; 13 | this->count = 0; 14 | 15 | this->buflen = 0; 16 | this->bufpot = 0; 17 | 18 | this->password = NULL; 19 | this->sem_pass = NULL;//CreateSemaphore(NULL,0,1,NULL); 20 | } 21 | 22 | XUn::~XUn() 23 | { 24 | delete this->path; 25 | 26 | if( this->password != NULL ) 27 | delete this->password; 28 | if( this->buffer != NULL ) 29 | delete [] this->buffer; 30 | if( this->comment != NULL ) 31 | delete [] this->comment; 32 | if( this->sem_pass != NULL ) 33 | CloseHandle(this->sem_pass); 34 | } 35 | 36 | bool XUn::list(List *list) 37 | { 38 | return false; 39 | } 40 | 41 | bool XUn::extract(File *file, WCHAR *dest) 42 | { 43 | return false; 44 | } 45 | 46 | bool XUn::isLoaded() 47 | { 48 | return false; 49 | } 50 | 51 | int XUn::getLastError() 52 | { 53 | return this->error; 54 | } 55 | 56 | void XUn::setLastError(int error) 57 | { 58 | this->error = error; 59 | } 60 | 61 | int XUn::getBuflen() 62 | { 63 | return this->buflen; 64 | } 65 | 66 | byte *XUn::getBuffer() 67 | { 68 | return this->buffer; 69 | } 70 | 71 | void XUn::clearBuffer() 72 | { 73 | this->buflen = 0; 74 | this->bufpot = 0; 75 | 76 | if( this->buffer != NULL ) 77 | delete [] this->buffer; 78 | this->buffer = NULL; 79 | } 80 | 81 | void XUn::setBuffer(void *source, int size) 82 | { 83 | if( this->buffer == NULL ) 84 | this->buffer = new byte[this->buflen]; 85 | 86 | if( size > 0 ){ 87 | memcpy(&this->buffer[this->bufpot],source,size); 88 | this->bufpot += size; 89 | } 90 | } 91 | 92 | FwCHAR *XUn::getPassword() 93 | { 94 | return this->password; 95 | } 96 | void XUn::setPassword(FwCHAR *password) 97 | { 98 | this->password = password; 99 | } 100 | void XUn::sendPassReq() 101 | { 102 | return; 103 | } 104 | 105 | /* *** */ 106 | 107 | XUnrar::XUnrar(WCHAR *archivepath) : XUn(archivepath) 108 | { 109 | this->loaded = this->loadFunc(); 110 | this->charpath = NULL; 111 | this->handle = NULL; 112 | 113 | if( this->loaded ){ 114 | this->charpath = this->path->tochar(); 115 | } 116 | } 117 | 118 | XUnrar::~XUnrar() 119 | { 120 | if( this->handle != NULL ) 121 | this->closeArchive(this->handle); 122 | 123 | if( this->charpath != NULL ) 124 | delete [] this->charpath; 125 | } 126 | 127 | bool XUnrar::list(List *list) 128 | { 129 | if( !this->loaded ) 130 | return false; 131 | 132 | bool counter = false; 133 | if( this->count == 0 ) 134 | counter = true; 135 | 136 | bool noerror = false; 137 | 138 | if( this->reopen(RAR_OM_LIST) ){ 139 | RARHeaderDataEx headerData; 140 | ZeroMemory(&headerData, sizeof(headerData)); 141 | 142 | int type, read = 0; 143 | DWORD size; 144 | 145 | noerror = true; 146 | 147 | while( (read = this->readHeaderEx(this->handle,&headerData)) != ERAR_END_ARCHIVE ){ 148 | if( counter == true ) 149 | this->count++; 150 | 151 | if( read == 0 ){ 152 | type = Explorer::getType(headerData.FileNameW); 153 | size = headerData.UnpSize; 154 | 155 | if( Explorer::getMime(type) == MIME_IMAGE && size > 0 ) 156 | list->add( new File(new FwCHAR(headerData.FileNameW), type, size, true) ); 157 | this->processFileW(this->handle,RAR_SKIP,NULL,NULL); 158 | } 159 | else { 160 | noerror = false; 161 | this->setLastError(read); 162 | break; 163 | } 164 | } 165 | } 166 | return noerror; 167 | } 168 | 169 | bool XUnrar::extract(File *file, WCHAR *dest) 170 | { 171 | if( !this->loaded ) 172 | return false; 173 | if( dest != NULL ) 174 | this->extracting = true; 175 | 176 | bool noerror = false; 177 | if( this->reopen(RAR_OM_EXTRACT) ){ 178 | RARHeaderDataEx headerData; 179 | ZeroMemory(&headerData, sizeof(headerData)); 180 | 181 | int mode,read = 0; 182 | noerror = true; 183 | WCHAR *filepath = file->getFilePath()->toWCHAR(); 184 | 185 | while( (read = this->readHeaderEx(this->handle,&headerData)) != ERAR_END_ARCHIVE ){ 186 | if( read == 0 ){ 187 | if( !_wcsicmp(filepath,headerData.FileNameW) ){ 188 | mode = RAR_EXTRACT; 189 | if( this->extracting == false ){ 190 | this->buflen = headerData.UnpSize; 191 | mode = RAR_TEST; 192 | } 193 | if( this->processFileW(this->handle,mode,NULL,dest) == 0 ) 194 | return true; 195 | } 196 | else 197 | this->processFileW(this->handle,RAR_SKIP,NULL,NULL); 198 | } 199 | else { 200 | noerror = false; 201 | this->setLastError(read); 202 | break; 203 | } 204 | } 205 | } 206 | this->extracting = false; 207 | return noerror; 208 | } 209 | 210 | bool XUnrar::isLoaded() 211 | { 212 | return this->loaded; 213 | } 214 | 215 | bool XUnrar::loadFunc() 216 | { 217 | (FARPROC&)this->openArchive = GetProcAddress(Core::getRarDll(), "RAROpenArchive"); 218 | (FARPROC&)this->openArchiveEx = GetProcAddress(Core::getRarDll(), "RAROpenArchiveEx"); 219 | (FARPROC&)this->closeArchive = GetProcAddress(Core::getRarDll(), "RARCloseArchive"); 220 | (FARPROC&)this->readHeader = GetProcAddress(Core::getRarDll(), "RARReadHeader"); 221 | (FARPROC&)this->readHeaderEx = GetProcAddress(Core::getRarDll(), "RARReadHeaderEx"); 222 | (FARPROC&)this->processFile = GetProcAddress(Core::getRarDll(), "RARProcessFile"); 223 | (FARPROC&)this->processFileW = GetProcAddress(Core::getRarDll(), "RARProcessFileW"); 224 | (FARPROC&)this->setCallback = GetProcAddress(Core::getRarDll(), "RARSetCallback"); 225 | 226 | if( this->openArchive == NULL || 227 | this->openArchiveEx == NULL || 228 | this->closeArchive == NULL || 229 | this->readHeader == NULL || 230 | this->readHeaderEx == NULL || 231 | this->processFile == NULL || 232 | this->processFileW == NULL || 233 | this->setCallback == NULL ) 234 | return false; 235 | return true; 236 | } 237 | 238 | bool XUnrar::reopen(int mode) 239 | { 240 | if( !this->loaded ) 241 | return false; 242 | 243 | if( this->handle != NULL ) 244 | this->closeArchive(this->handle); 245 | 246 | RAROpenArchiveDataEx archiveData; 247 | ZeroMemory(&archiveData, sizeof(archiveData)); 248 | 249 | archiveData.ArcName = this->charpath; 250 | archiveData.ArcNameW = this->path->toWCHAR(); 251 | archiveData.CmtBuf = this->comment; 252 | archiveData.OpenMode = mode; 253 | 254 | HANDLE temp = this->openArchiveEx(&archiveData); 255 | if( archiveData.OpenResult == 0 ){ 256 | this->handle = temp; 257 | this->setCallback(this->handle,XUnrar::callbackProc,(LONG)this); 258 | return true; 259 | } 260 | return false; 261 | } 262 | 263 | int CALLBACK XUnrar::callbackProc(UINT msg,LONG userData,LONG p1,LONG p2){ 264 | 265 | XUnrar *that = (XUnrar *)userData; 266 | int len = 0; 267 | 268 | switch(msg){ 269 | case UCM_CHANGEVOLUME: 270 | return -1; 271 | break; 272 | case UCM_PROCESSDATA: 273 | if( that->extracting == false ) 274 | that->setBuffer((void *)p1, p2); 275 | break; 276 | case UCM_NEEDPASSWORD: 277 | break; 278 | 279 | /* 280 | if( that->getPassword() == NULL ){ 281 | that->sendPassReq(); 282 | WaitForSingleObject(that->sem_pass,INFINITE); 283 | } 284 | len = that->getPassword()->toLength(); 285 | if( len > p2 ) 286 | len = p2; 287 | memcpy((void *)p1,that->getPassword(),len); 288 | break; 289 | */ 290 | default: 291 | break; 292 | } 293 | return 0; 294 | } 295 | 296 | /* *** */ 297 | 298 | XUnzip::XUnzip(WCHAR *archivepath) : XUn(archivepath) 299 | { 300 | this->handle = NULL; 301 | } 302 | 303 | XUnzip::~XUnzip() 304 | { 305 | if( this->handle != NULL ) 306 | CloseZip(this->handle); 307 | } 308 | 309 | bool XUnzip::list(List *list) 310 | { 311 | bool noerror = false; 312 | 313 | if( (this->handle = OpenZip(this->path->toWCHAR(),0,ZIP_FILENAME)) != 0 ){ 314 | ZIPENTRYW headerData; 315 | ZeroMemory(&headerData, sizeof(headerData)); 316 | 317 | int result = ZR_OK; 318 | if( (result = GetZipItemW(this->handle,-1,&headerData)) == ZR_OK ){ 319 | this->count = headerData.index; 320 | noerror = true; 321 | 322 | int type, i = 0; 323 | DWORD size; 324 | 325 | while( i < this->count ){ 326 | if( (result = GetZipItemW(this->handle,i++,&headerData)) == ZR_OK ){ 327 | type = Explorer::getType(headerData.name); 328 | size = headerData.unc_size; 329 | 330 | if( Explorer::getMime(type) == MIME_IMAGE && size > 0 ) 331 | list->add( new File(new FwCHAR(headerData.name), type, size, true) ); 332 | } 333 | else { 334 | this->setLastError(result); 335 | noerror = false; 336 | break; 337 | } 338 | } 339 | } 340 | else this->setLastError(result); 341 | } 342 | return noerror; 343 | } 344 | 345 | bool XUnzip::extract(File *file, WCHAR *dest) 346 | { 347 | if( dest != NULL ) 348 | this->extracting = true; 349 | 350 | bool noerror = false; 351 | 352 | int index = 0; 353 | WCHAR *path = file->getFilePath()->toWCHAR(); 354 | 355 | ZIPENTRYW headerData; 356 | ZeroMemory(&headerData, sizeof(headerData)); 357 | 358 | if( FindZipItemW(this->handle,path,false,&index,&headerData) == ZR_OK ){ 359 | int tmplen = headerData.unc_size; 360 | byte *tmp = new byte[2 * tmplen]; 361 | 362 | this->buflen = tmplen; 363 | 364 | int read = 0; 365 | ZRESULT zresult = ZR_MORE; 366 | while( zresult == ZR_MORE ){ 367 | if( this->extracting == true ){ 368 | zresult = UnzipItem(this->handle,index,dest,0,ZIP_FILENAME,&read); 369 | } 370 | else { 371 | zresult = UnzipItem(this->handle,index,tmp,tmplen,ZIP_MEMORY,&read); 372 | this->setBuffer(tmp,read); // it was tmplen - a nonsense? 373 | } 374 | if( zresult == ZR_OK ){ 375 | noerror = true; 376 | break; 377 | } 378 | } 379 | delete [] tmp; 380 | } 381 | this->extracting = false; 382 | return noerror; 383 | } 384 | 385 | bool XUnzip::isLoaded() 386 | { 387 | return true; 388 | } -------------------------------------------------------------------------------- /Fiew/XUn.h: -------------------------------------------------------------------------------- 1 | #include "XUnrar.h" 2 | #include "XUnzip.h" 3 | 4 | class FwCHAR; 5 | template 6 | class List; 7 | class Core; 8 | 9 | class Archive; 10 | class File; 11 | 12 | class XUn 13 | { 14 | protected: 15 | Core *core; 16 | 17 | FwCHAR *path; 18 | byte *buffer; 19 | char *comment; 20 | 21 | bool extracting; 22 | 23 | int error; 24 | int count; 25 | int buflen, bufpot; 26 | 27 | FwCHAR *password; 28 | HANDLE sem_pass; 29 | 30 | public: 31 | XUn(WCHAR *archivepath); 32 | virtual ~XUn(); 33 | 34 | virtual bool list(List *list); 35 | virtual bool extract(File *file, WCHAR *dest = NULL); 36 | 37 | virtual bool isLoaded(); 38 | 39 | int getLastError(); 40 | void setLastError(int error); 41 | 42 | FwCHAR *getPassword(); 43 | void setPassword(FwCHAR *password); 44 | void sendPassReq(); 45 | 46 | int getBuflen(); 47 | byte *getBuffer(); 48 | void clearBuffer(); 49 | void setBuffer(void *source, int size); 50 | }; 51 | 52 | class XUnrar : public XUn 53 | { 54 | private: 55 | bool loaded; 56 | char *charpath; 57 | 58 | HANDLE handle; 59 | 60 | public: 61 | XUnrar(WCHAR *archivepath); 62 | ~XUnrar(); 63 | 64 | bool list(List *list); 65 | bool extract(File *file, WCHAR *dest = NULL); 66 | 67 | bool isLoaded(); 68 | 69 | static int CALLBACK callbackProc(UINT,LONG,LONG,LONG); 70 | 71 | private: 72 | HANDLE (WINAPI *openArchive)(RAROpenArchiveData *); 73 | HANDLE (WINAPI *openArchiveEx)(RAROpenArchiveDataEx *); 74 | int (WINAPI *closeArchive)(HANDLE); 75 | int (WINAPI *readHeader)(HANDLE,RARHeaderData *); 76 | int (WINAPI *readHeaderEx)(HANDLE,RARHeaderDataEx *); 77 | int (WINAPI *processFile)(HANDLE,int,char *,char *); 78 | int (WINAPI *processFileW)(HANDLE,int,WCHAR *,WCHAR *); 79 | void (WINAPI *setCallback)(HANDLE,UNRARCALLBACK,LONG); 80 | 81 | bool loadFunc(); 82 | bool reopen(int mode); 83 | }; 84 | 85 | class XUnzip : public XUn 86 | { 87 | private: 88 | HZIP handle; 89 | 90 | public: 91 | XUnzip(WCHAR *archivepath); 92 | ~XUnzip(); 93 | 94 | bool list(List *list); 95 | bool extract(File *file, WCHAR *dest = NULL); 96 | 97 | bool isLoaded(); 98 | }; -------------------------------------------------------------------------------- /Fiew/XUnrar.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "XUn.h" 4 | 5 | -------------------------------------------------------------------------------- /Fiew/XUnrar.h: -------------------------------------------------------------------------------- 1 | #define ERAR_END_ARCHIVE 10 2 | #define ERAR_NO_MEMORY 11 3 | #define ERAR_BAD_DATA 12 4 | #define ERAR_BAD_ARCHIVE 13 5 | #define ERAR_UNKNOWN_FORMAT 14 6 | #define ERAR_EOPEN 15 7 | #define ERAR_ECREATE 16 8 | #define ERAR_ECLOSE 17 9 | #define ERAR_EREAD 18 10 | #define ERAR_EWRITE 19 11 | #define ERAR_SMALL_BUF 20 12 | #define ERAR_UNKNOWN 21 13 | #define ERAR_EMPTY 22 14 | #define ERAR_BAD_PASS 23 15 | 16 | #define RAR_OM_LIST 0 17 | #define RAR_OM_EXTRACT 1 18 | 19 | #define RAR_SKIP 0 20 | #define RAR_TEST 1 21 | #define RAR_EXTRACT 2 22 | 23 | #define RAR_VOL_ASK 0 24 | #define RAR_VOL_NOTIFY 1 25 | 26 | #define RAR_DLL_VERSION 4 27 | 28 | enum UNRARCALLBACK_MESSAGES { 29 | UCM_CHANGEVOLUME, 30 | UCM_PROCESSDATA, 31 | UCM_NEEDPASSWORD 32 | }; 33 | 34 | typedef int (CALLBACK *UNRARCALLBACK)(UINT msg,LONG UserData,LONG P1,LONG P2); 35 | 36 | struct RAROpenArchiveData 37 | { 38 | char *ArcName; 39 | UINT OpenMode; 40 | UINT OpenResult; 41 | char *CmtBuf; 42 | UINT CmtBufSize; 43 | UINT CmtSize; 44 | UINT CmtState; 45 | }; 46 | 47 | struct RAROpenArchiveDataEx 48 | { 49 | char *ArcName; 50 | wchar_t *ArcNameW; 51 | unsigned int OpenMode; 52 | unsigned int OpenResult; 53 | char *CmtBuf; 54 | unsigned int CmtBufSize; 55 | unsigned int CmtSize; 56 | unsigned int CmtState; 57 | unsigned int Flags; 58 | unsigned int Reserved[32]; 59 | }; 60 | 61 | struct RARHeaderData 62 | { 63 | char ArcName[260]; 64 | char FileName[260]; 65 | UINT Flags; 66 | UINT PackSize; 67 | UINT UnpSize; 68 | UINT HostOS; 69 | UINT FileCRC; 70 | UINT FileTime; 71 | UINT UnpVer; 72 | UINT Method; 73 | UINT FileAttr; 74 | char *CmtBuf; 75 | UINT CmtBufSize; 76 | UINT CmtSize; 77 | UINT CmtState; 78 | }; 79 | 80 | struct RARHeaderDataEx 81 | { 82 | char ArcName[1024]; 83 | wchar_t ArcNameW[1024]; 84 | char FileName[1024]; 85 | wchar_t FileNameW[1024]; 86 | unsigned int Flags; 87 | unsigned int PackSize; 88 | unsigned int PackSizeHigh; 89 | unsigned int UnpSize; 90 | unsigned int UnpSizeHigh; 91 | unsigned int HostOS; 92 | unsigned int FileCRC; 93 | unsigned int FileTime; 94 | unsigned int UnpVer; 95 | unsigned int Method; 96 | unsigned int FileAttr; 97 | char *CmtBuf; 98 | unsigned int CmtBufSize; 99 | unsigned int CmtSize; 100 | unsigned int CmtState; 101 | unsigned int Reserved[1024]; 102 | }; -------------------------------------------------------------------------------- /Fiew/XUnzip.h: -------------------------------------------------------------------------------- 1 | // XUnzip.h Version 1.1 2 | // 3 | // Authors: Mark Adler et al. (see below) 4 | // 5 | // Modified by: Lucian Wischik 6 | // lu@wischik.com 7 | // 8 | // Version 1.0 - Turned C files into just a single CPP file 9 | // - Made them compile cleanly as C++ files 10 | // - Gave them simpler APIs 11 | // - Added the ability to zip/unzip directly in memory without 12 | // any intermediate files 13 | // 14 | // Modified by: Hans Dietrich 15 | // hdietrich2@hotmail.com 16 | // 17 | // Version 1.1: - Added Unicode support to CreateZip() and ZipAdd() 18 | // - Changed file names to avoid conflicts with Lucian's files 19 | // 20 | /////////////////////////////////////////////////////////////////////////////// 21 | // 22 | // Lucian Wischik's comments: 23 | // -------------------------- 24 | // THIS FILE is almost entirely based upon code by info-zip. 25 | // It has been modified by Lucian Wischik. 26 | // The original code may be found at http://www.info-zip.org 27 | // The original copyright text follows. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // 31 | // Original authors' comments: 32 | // --------------------------- 33 | // This is version 2002-Feb-16 of the Info-ZIP copyright and license. The 34 | // definitive version of this document should be available at 35 | // ftp://ftp.info-zip.org/pub/infozip/license.html indefinitely. 36 | // 37 | // Copyright (c) 1990-2002 Info-ZIP. All rights reserved. 38 | // 39 | // For the purposes of this copyright and license, "Info-ZIP" is defined as 40 | // the following set of individuals: 41 | // 42 | // Mark Adler, John Bush, Karl Davis, Harald Denker, Jean-Michel Dubois, 43 | // Jean-loup Gailly, Hunter Goatley, Ian Gorman, Chris Herborth, Dirk Haase, 44 | // Greg Hartwig, Robert Heath, Jonathan Hudson, Paul Kienitz, 45 | // David Kirschbaum, Johnny Lee, Onno van der Linden, Igor Mandrichenko, 46 | // Steve P. Miller, Sergio Monesi, Keith Owens, George Petrov, Greg Roelofs, 47 | // Kai Uwe Rommel, Steve Salisbury, Dave Smith, Christian Spieler, 48 | // Antoine Verheijen, Paul von Behren, Rich Wales, Mike White 49 | // 50 | // This software is provided "as is", without warranty of any kind, express 51 | // or implied. In no event shall Info-ZIP or its contributors be held liable 52 | // for any direct, indirect, incidental, special or consequential damages 53 | // arising out of the use of or inability to use this software. 54 | // 55 | // Permission is granted to anyone to use this software for any purpose, 56 | // including commercial applications, and to alter it and redistribute it 57 | // freely, subject to the following restrictions: 58 | // 59 | // 1. Redistributions of source code must retain the above copyright notice, 60 | // definition, disclaimer, and this list of conditions. 61 | // 62 | // 2. Redistributions in binary form (compiled executables) must reproduce 63 | // the above copyright notice, definition, disclaimer, and this list of 64 | // conditions in documentation and/or other materials provided with the 65 | // distribution. The sole exception to this condition is redistribution 66 | // of a standard UnZipSFX binary as part of a self-extracting archive; 67 | // that is permitted without inclusion of this license, as long as the 68 | // normal UnZipSFX banner has not been removed from the binary or disabled. 69 | // 70 | // 3. Altered versions--including, but not limited to, ports to new 71 | // operating systems, existing ports with new graphical interfaces, and 72 | // dynamic, shared, or static library versions--must be plainly marked 73 | // as such and must not be misrepresented as being the original source. 74 | // Such altered versions also must not be misrepresented as being 75 | // Info-ZIP releases--including, but not limited to, labeling of the 76 | // altered versions with the names "Info-ZIP" (or any variation thereof, 77 | // including, but not limited to, different capitalizations), 78 | // "Pocket UnZip", "WiZ" or "MacZip" without the explicit permission of 79 | // Info-ZIP. Such altered versions are further prohibited from 80 | // misrepresentative use of the Zip-Bugs or Info-ZIP e-mail addresses or 81 | // of the Info-ZIP URL(s). 82 | // 83 | // 4. Info-ZIP retains the right to use the names "Info-ZIP", "Zip", "UnZip", 84 | // "UnZipSFX", "WiZ", "Pocket UnZip", "Pocket Zip", and "MacZip" for its 85 | // own source and binary releases. 86 | // 87 | /////////////////////////////////////////////////////////////////////////////// 88 | 89 | #ifndef XUNZIP_H 90 | #define XUNZIP_H 91 | 92 | 93 | #ifndef XZIP_H 94 | DECLARE_HANDLE(HZIP); // An HZIP identifies a zip file that has been opened 95 | #endif 96 | 97 | typedef DWORD ZRESULT; 98 | // return codes from any of the zip functions. Listed later. 99 | 100 | #define ZIP_HANDLE 1 101 | #define ZIP_FILENAME 2 102 | #define ZIP_MEMORY 3 103 | 104 | typedef struct 105 | { int index; // index of this file within the zip 106 | char name[MAX_PATH]; // filename within the zip 107 | DWORD attr; // attributes, as in GetFileAttributes. 108 | FILETIME atime,ctime,mtime;// access, create, modify filetimes 109 | long comp_size; // sizes of item, compressed and uncompressed. These 110 | long unc_size; // may be -1 if not yet known (e.g. being streamed in) 111 | } ZIPENTRY; 112 | 113 | typedef struct 114 | { int index; // index of this file within the zip 115 | TCHAR name[MAX_PATH]; // filename within the zip 116 | DWORD attr; // attributes, as in GetFileAttributes. 117 | FILETIME atime,ctime,mtime;// access, create, modify filetimes 118 | long comp_size; // sizes of item, compressed and uncompressed. These 119 | long unc_size; // may be -1 if not yet known (e.g. being streamed in) 120 | } ZIPENTRYW; 121 | 122 | 123 | /////////////////////////////////////////////////////////////////////////////// 124 | // 125 | // OpenZip() 126 | // 127 | // Purpose: Open an existing zip archive file 128 | // 129 | // Parameters: z - archive file name if flags is ZIP_FILENAME; for other 130 | // uses see below 131 | // len - for memory (ZIP_MEMORY) should be the buffer size; 132 | // for other uses, should be 0 133 | // flags - indicates usage, see below; for files, this will be 134 | // ZIP_FILENAME 135 | // 136 | // Returns: HZIP - non-zero if zip archive opened ok, otherwise 0 137 | // 138 | HZIP OpenZip(void *z, unsigned int len, DWORD flags); 139 | // OpenZip - opens a zip file and returns a handle with which you can 140 | // subsequently examine its contents. You can open a zip file from: 141 | // from a pipe: OpenZip(hpipe_read,0, ZIP_HANDLE); 142 | // from a file (by handle): OpenZip(hfile,0, ZIP_HANDLE); 143 | // from a file (by name): OpenZip("c:\\test.zip",0, ZIP_FILENAME); 144 | // from a memory block: OpenZip(bufstart, buflen, ZIP_MEMORY); 145 | // If the file is opened through a pipe, then items may only be 146 | // accessed in increasing order, and an item may only be unzipped once, 147 | // although GetZipItem can be called immediately before and after unzipping 148 | // it. If it's opened i n any other way, then full random access is possible. 149 | // Note: pipe input is not yet implemented. 150 | 151 | 152 | /////////////////////////////////////////////////////////////////////////////// 153 | // 154 | // GetZipItem() 155 | // 156 | // Purpose: Get information about an item in an open zip archive 157 | // 158 | // Parameters: hz - handle of open zip archive 159 | // index - index number (0 based) of item in zip 160 | // ze - pointer to a ZIPENTRY (if ANSI) or ZIPENTRYW struct 161 | // (if Unicode) 162 | // 163 | // Returns: ZRESULT - ZR_OK if success, otherwise some other value 164 | // 165 | 166 | #ifdef _UNICODE 167 | #define GetZipItem GetZipItemW 168 | #else 169 | #define GetZipItem GetZipItemA 170 | #endif 171 | 172 | ZRESULT GetZipItemA(HZIP hz, int index, ZIPENTRY *ze); 173 | ZRESULT GetZipItemW(HZIP hz, int index, ZIPENTRYW *ze); 174 | // GetZipItem - call this to get information about an item in the zip. 175 | // If index is -1 and the file wasn't opened through a pipe, 176 | // then it returns information about the whole zipfile 177 | // (and in particular ze.index returns the number of index items). 178 | // Note: the item might be a directory (ze.attr & FILE_ATTRIBUTE_DIRECTORY) 179 | // See below for notes on what happens when you unzip such an item. 180 | // Note: if you are opening the zip through a pipe, then random access 181 | // is not possible and GetZipItem(-1) fails and you can't discover the number 182 | // of items except by calling GetZipItem on each one of them in turn, 183 | // starting at 0, until eventually the call fails. Also, in the event that 184 | // you are opening through a pipe and the zip was itself created into a pipe, 185 | // then then comp_size and sometimes unc_size as well may not be known until 186 | // after the item has been unzipped. 187 | 188 | 189 | /////////////////////////////////////////////////////////////////////////////// 190 | // 191 | // FindZipItem() 192 | // 193 | // Purpose: Find item by name and return information about it 194 | // 195 | // Parameters: hz - handle of open zip archive 196 | // name - name of file to look for inside zip archive 197 | // ic - TRUE = case insensitive 198 | // index - pointer to index number returned, or -1 199 | // ze - pointer to a ZIPENTRY (if ANSI) or ZIPENTRYW struct 200 | // (if Unicode) 201 | // 202 | // Returns: ZRESULT - ZR_OK if success, otherwise some other value 203 | // 204 | 205 | #ifdef _UNICODE 206 | #define FindZipItem FindZipItemW 207 | #else 208 | #define FindZipItem FindZipItemA 209 | #endif 210 | 211 | ZRESULT FindZipItemA(HZIP hz, const TCHAR *name, bool ic, int *index, ZIPENTRY *ze); 212 | ZRESULT FindZipItemW(HZIP hz, const TCHAR *name, bool ic, int *index, ZIPENTRYW *ze); 213 | // FindZipItem - finds an item by name. ic means 'insensitive to case'. 214 | // It returns the index of the item, and returns information about it. 215 | // If nothing was found, then index is set to -1 and the function returns 216 | // an error code. 217 | 218 | 219 | /////////////////////////////////////////////////////////////////////////////// 220 | // 221 | // UnzipItem() 222 | // 223 | // Purpose: Find item by index and unzip it 224 | // 225 | // Parameters: hz - handle of open zip archive 226 | // index - index number of file to unzip 227 | // dst - target file name of unzipped file 228 | // len - for memory (ZIP_MEMORY. length of buffer; 229 | // otherwise 0 230 | // flags - indicates usage, see below; for files, this will be 231 | // ZIP_FILENAME 232 | // 233 | // Returns: ZRESULT - ZR_OK if success, otherwise some other value 234 | // 235 | 236 | ZRESULT UnzipItem(HZIP hz, int index, void *dst, unsigned int len, DWORD flags, int *readlen); 237 | // UnzipItem - given an index to an item, unzips it. You can unzip to: 238 | // to a pipe: UnzipItem(hz,i, hpipe_write,0,ZIP_HANDLE); 239 | // to a file (by handle): UnzipItem(hz,i, hfile,0,ZIP_HANDLE); 240 | // to a file (by name): UnzipItem(hz,i, ze.name,0,ZIP_FILENAME); 241 | // to a memory block: UnzipItem(hz,i, buf,buflen,ZIP_MEMORY); 242 | // In the final case, if the buffer isn't large enough to hold it all, 243 | // then the return code indicates that more is yet to come. If it was 244 | // large enough, and you want to know precisely how big, GetZipItem. 245 | // Note: zip files are normally stored with relative pathnames. If you 246 | // unzip with ZIP_FILENAME a relative pathname then the item gets created 247 | // relative to the current directory - it first ensures that all necessary 248 | // subdirectories have been created. Also, the item may itself be a directory. 249 | // If you unzip a directory with ZIP_FILENAME, then the directory gets created. 250 | // If you unzip it to a handle or a memory block, then nothing gets created 251 | // and it emits 0 bytes. 252 | 253 | 254 | /////////////////////////////////////////////////////////////////////////////// 255 | // 256 | // CloseZip() 257 | // 258 | // Purpose: Close an open zip archive 259 | // 260 | // Parameters: hz - handle to an open zip archive 261 | // 262 | // Returns: ZRESULT - ZR_OK if success, otherwise some other value 263 | // 264 | ZRESULT CloseZip(HZIP hz); 265 | // CloseZip - the zip handle must be closed with this function. 266 | 267 | WCHAR *FormatZipMessage(ZRESULT code); 268 | // FormatZipMessage - given an error code, formats it as a string. 269 | // It returns the length of the error message. If buf/len points 270 | // to a real buffer, then it also writes as much as possible into there. 271 | 272 | 273 | // These are the result codes: 274 | #define ZR_EMPTY -2 275 | #define ZR_FAIL -1 276 | #define ZR_OK 0x00000000 // nb. the pseudo-code zr-recent is never returned, 277 | #define ZR_RECENT 0x00000001 // but can be passed to FormatZipMessage. 278 | // The following come from general system stuff (e.g. files not openable) 279 | #define ZR_GENMASK 0x0000FF00 280 | #define ZR_NODUPH 0x00000100 // couldn't duplicate the handle 281 | #define ZR_NOFILE 0x00000200 // couldn't create/open the file 282 | #define ZR_NOALLOC 0x00000300 // failed to allocate some resource 283 | #define ZR_WRITE 0x00000400 // a general error writing to the file 284 | #define ZR_NOTFOUND 0x00000500 // couldn't find that file in the zip 285 | #define ZR_MORE 0x00000600 // there's still more data to be unzipped 286 | #define ZR_CORRUPT 0x00000700 // the zipfile is corrupt or not a zipfile 287 | #define ZR_READ 0x00000800 // a general error reading the file 288 | // The following come from mistakes on the part of the caller 289 | #define ZR_CALLERMASK 0x00FF0000 290 | #define ZR_ARGS 0x00010000 // general mistake with the arguments 291 | #define ZR_NOTMMAP 0x00020000 // tried to ZipGetMemory, but that only works on mmap zipfiles, which yours wasn't 292 | #define ZR_MEMSIZE 0x00030000 // the memory size is too small 293 | #define ZR_FAILED 0x00040000 // the thing was already failed when you called this function 294 | #define ZR_ENDED 0x00050000 // the zip creation has already been closed 295 | #define ZR_MISSIZE 0x00060000 // the indicated input file size turned out mistaken 296 | #define ZR_PARTIALUNZ 0x00070000 // the file had already been partially unzipped 297 | #define ZR_ZMODE 0x00080000 // tried to mix creating/opening a zip 298 | // The following come from bugs within the zip library itself 299 | #define ZR_BUGMASK 0xFF000000 300 | #define ZR_NOTINITED 0x01000000 // initialisation didn't work 301 | #define ZR_SEEK 0x02000000 // trying to seek in an unseekable file 302 | #define ZR_NOCHANGE 0x04000000 // changed its mind on storage, but not allowed 303 | #define ZR_FLATE 0x05000000 // an internal error in the de/inflation code 304 | 305 | 306 | 307 | 308 | 309 | // e.g. 310 | // 311 | // SetCurrentDirectory("c:\\docs\\stuff"); 312 | // HZIP hz = OpenZip("c:\\stuff.zip",0,ZIP_FILENAME); 313 | // ZIPENTRY ze; GetZipItem(hz,-1,&ze); int numitems=ze.index; 314 | // for (int i=0; i 29 | 30 | // C RunTime Header Files 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | 37 | // TODO: reference additional headers your program requires here 38 | #include 39 | #include "Fiew.h" -------------------------------------------------------------------------------- /Fiew/unrar.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/f055/fiew-image-viewer/314e86cbfbb95527783e9071ed3c97a9cdc93497/Fiew/unrar.dll --------------------------------------------------------------------------------