~ubuntu-branches/debian/sid/stella/sid

« back to all changes in this revision

Viewing changes to src/gui/LauncherDialog.cxx

  • Committer: Package Import Robot
  • Author(s): Stephen Kitt
  • Date: 2012-06-02 07:33:16 UTC
  • mfrom: (1.1.15)
  • Revision ID: package-import@ubuntu.com-20120602073316-20r4hr32t4oj36u9
Tags: 3.7-1
* New upstream version.
* Update description and documentation with new features in 3.7, notably
  Blargg TV filters (replacing the filters available in versions 3.4.1
  and earlier).
* Switch to debhelper compatibility level 9.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
// See the file "License.txt" for information on usage and redistribution of
15
15
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
16
16
//
17
 
// $Id: LauncherDialog.cxx 2356 2012-01-14 22:00:54Z stephena $
 
17
// $Id: LauncherDialog.cxx 2477 2012-05-16 20:52:33Z stephena $
18
18
//
19
19
//   Based on code from ScummVM - Scumm Interpreter
20
20
//   Copyright (C) 2002-2004 The ScummVM project
44
44
#include "StringList.hxx"
45
45
#include "StringListWidget.hxx"
46
46
#include "Widget.hxx"
 
47
#include "unzip.h"
47
48
 
48
49
#include "LauncherDialog.hxx"
49
50
 
341
342
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
342
343
void LauncherDialog::loadDirListing()
343
344
{
344
 
  if(!myCurrentNode.isDirectory())
 
345
  if(!myCurrentNode.isDirectory() && !myCurrentNode.exists())
345
346
    return;
346
347
 
347
348
  FSList files;
348
 
  myCurrentNode.getChildren(files, FilesystemNode::kListAll);
 
349
  files.reserve(2048);
 
350
 
 
351
  if(myCurrentNode.isDirectory())
 
352
  {
 
353
    myCurrentNode.getChildren(files, FilesystemNode::kListAll);
 
354
  }
 
355
  else
 
356
  {
 
357
    unzFile tz;
 
358
    if((tz = unzOpen(myCurrentNode.getPath().c_str())) != NULL)
 
359
    {
 
360
      if(unzGoToFirstFile(tz) == UNZ_OK)
 
361
      {
 
362
        unz_file_info ufo;
 
363
 
 
364
        for(;;)  // Loop through all files for valid 2600 images
 
365
        {
 
366
          // Longer filenames might be possible, but I don't
 
367
          // think people would name files that long in zip files...
 
368
          char filename[1024];
 
369
 
 
370
          unzGetCurrentFileInfo(tz, &ufo, filename, 1024, 0, 0, 0, 0);
 
371
          filename[1023] = '\0';
 
372
 
 
373
          if(strlen(filename) >= 4 &&
 
374
             !BSPF_startsWithIgnoreCase(filename, "__MACOSX"))
 
375
          {
 
376
            // Grab 3-character extension
 
377
            const char* ext = filename + strlen(filename) - 4;
 
378
 
 
379
            if(BSPF_equalsIgnoreCase(ext, ".a26") || BSPF_equalsIgnoreCase(ext, ".bin") ||
 
380
               BSPF_equalsIgnoreCase(ext, ".rom"))
 
381
            {
 
382
              FilesystemNode newFile(AbstractFilesystemNode::getAbsolutePath(
 
383
                  filename, myCurrentNode.getPath(), ""));
 
384
              files.push_back(newFile);
 
385
            }
 
386
          }
 
387
 
 
388
          // Scan the next file in the zip
 
389
          if(unzGoToNextFile(tz) != UNZ_OK)
 
390
            break;
 
391
        }
 
392
      }
 
393
    }
 
394
  }
349
395
 
350
396
  // Add '[..]' to indicate previous folder
351
397
  if(myCurrentNode.hasParent())
363
409
    // that we want - if there are no extensions, it implies show all files
364
410
    // In this way, showing all files is on the 'fast code path'
365
411
    if(isDir)
 
412
    {
366
413
      name = " [" + name + "]";
 
414
    }
367
415
    else if(myRomExts.size() > 0)
368
416
    {
369
417
      // Skip over those names we've filtered out
478
526
}
479
527
 
480
528
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
529
int LauncherDialog::filesInArchive(const string& archive)
 
530
{
 
531
  int count = -1;
 
532
  unzFile tz;
 
533
  if((tz = unzOpen(archive.c_str())) != NULL)
 
534
  {
 
535
    count = 0;
 
536
    if(unzGoToFirstFile(tz) == UNZ_OK)
 
537
    {
 
538
      unz_file_info ufo;
 
539
 
 
540
      for(;;)  // Loop through all files for valid 2600 images
 
541
      {
 
542
        // Longer filenames might be possible, but I don't
 
543
        // think people would name files that long in zip files...
 
544
        char filename[1024];
 
545
 
 
546
        unzGetCurrentFileInfo(tz, &ufo, filename, 1024, 0, 0, 0, 0);
 
547
        filename[1023] = '\0';
 
548
 
 
549
        if(strlen(filename) >= 4 &&
 
550
           !BSPF_startsWithIgnoreCase(filename, "__MACOSX"))
 
551
        {
 
552
          // Grab 3-character extension
 
553
          const char* ext = filename + strlen(filename) - 4;
 
554
 
 
555
          if(BSPF_equalsIgnoreCase(ext, ".a26") || BSPF_equalsIgnoreCase(ext, ".bin") ||
 
556
             BSPF_equalsIgnoreCase(ext, ".rom"))
 
557
            ++count;
 
558
        }
 
559
 
 
560
        // Scan the next file in the zip
 
561
        if(unzGoToNextFile(tz) != UNZ_OK)
 
562
          break;
 
563
      }
 
564
    }
 
565
  }
 
566
  return count;
 
567
}
 
568
 
 
569
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
481
570
void LauncherDialog::handleKeyDown(StellaKey key, StellaMod mod, char ascii)
482
571
{
483
572
  // Grab the key before passing it to the actual dialog and check for
518
607
        const string& md5 = myGameList->md5(item);
519
608
        string extension;
520
609
 
 
610
        int numFilesInArchive = filesInArchive(rom);
 
611
        bool isArchive = !myGameList->isDir(item) &&
 
612
                         BSPF_endsWithIgnoreCase(rom, ".zip");
 
613
 
521
614
        // Directory's should be selected (ie, enter them and redisplay)
522
 
        if(myGameList->isDir(item))
 
615
        // Archives should be entered if they contain more than 1 file
 
616
        if(isArchive && numFilesInArchive < 1)
 
617
        {
 
618
          instance().frameBuffer().showMessage("Archive does not contain any valid ROM files",
 
619
                                               kMiddleCenter, true);
 
620
        }
 
621
        else if((isArchive && numFilesInArchive > 1) || myGameList->isDir(item))
523
622
        {
524
623
          string dirname = "";
525
624
          if(myGameList->name(item) == " [..]")