1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160
|
/* -*- mode: C++; tab-width: 4 -*- */
/* ===================================================================== *\
Copyright (c) 1998-2001 Palm, Inc. or its subsidiaries.
All rights reserved.
This file is part of the Palm OS Emulator.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
\* ===================================================================== */
#include "EmCommon.h"
#include "EmApplication.h"
#include "EmCommands.h" // EmCommandID
#include "EmDlg.h" // EmDlg, DoEditPreferences, etc.
#include "EmDocument.h" // EmDocument::AskNewSession, etc.
#include "EmErrCodes.h" // kError_OnlySameType
#include "EmEventPlayback.h" // EmEventPlayback::ReplayEvents
#include "EmMinimize.h" // EmMinimize::Start
#include "EmPatchState.h" // EmPatchState::IsTimeToQuit
#include "EmROMTransfer.h" // EmROMTransfer::ROMTransfer
#include "EmSession.h" // EmStopMethod
#include "EmTransport.h" // EmTransport::CloseAllTransports
#include "EmTypes.h" // StrCode
#include "EmWindow.h" // gWindow
#include "ErrorHandling.h" // Errors::ReportIfError
#include "HostControl.h" // hostSignalQuit
#include "Startup.h" // CreateSession, OpenSession, DetermineStartupActions
#include "Strings.r.h" // kStr_CmdAbout, etc.
#include "DebugMgr.h" // Debug::Startup
#include "EmDlg.h" // DoCommonDialog
#include "EmRPC.h" // RPC::Startup
#include "Logging.h" // LogStartup
#include "SocketMessaging.h" // CSocket::Startup
#if HAS_TRACER
#include "TracerPlatform.h" // gTracer.Initialize();
#endif
typedef void (EmApplication::*EmCommandFn)(EmCommandID);
static const struct
{
EmCommandID fCommandID;
EmCommandFn fFn;
StrCode fErrStrCode;
}
kCommand[] =
{
{ kCommandAbout, &EmApplication::DoAbout, kStr_CmdAbout },
{ kCommandSessionNew, &EmApplication::DoNew, kStr_CmdNew },
{ kCommandSessionOpenOther, &EmApplication::DoOpen, kStr_CmdOpen },
{ kCommandSessionOpen0, &EmApplication::DoOpen, kStr_CmdOpen },
{ kCommandSessionOpen1, &EmApplication::DoOpen, kStr_CmdOpen },
{ kCommandSessionOpen2, &EmApplication::DoOpen, kStr_CmdOpen },
{ kCommandSessionOpen3, &EmApplication::DoOpen, kStr_CmdOpen },
{ kCommandSessionOpen4, &EmApplication::DoOpen, kStr_CmdOpen },
{ kCommandSessionOpen5, &EmApplication::DoOpen, kStr_CmdOpen },
{ kCommandSessionOpen6, &EmApplication::DoOpen, kStr_CmdOpen },
{ kCommandSessionOpen7, &EmApplication::DoOpen, kStr_CmdOpen },
{ kCommandSessionOpen8, &EmApplication::DoOpen, kStr_CmdOpen },
{ kCommandSessionOpen9, &EmApplication::DoOpen, kStr_CmdOpen },
{ kCommandSessionClose, &EmApplication::DoClose, kStr_CmdClose },
{ kCommandQuit, &EmApplication::DoQuit, kStr_CmdQuit },
{ kCommandDownloadROM, &EmApplication::DoDownload, kStr_CmdTransferROM },
{ kCommandPreferences, &EmApplication::DoPreferences, kStr_CmdPreferences },
{ kCommandLogging, &EmApplication::DoLogging, kStr_CmdLoggingOptions },
{ kCommandDebugging, &EmApplication::DoDebugging, kStr_CmdDebugOptions },
{ kCommandErrorHandling, &EmApplication::DoErrorHandling,kStr_CmdErrorHandling },
#if HAS_TRACER
{ kCommandTracing, &EmApplication::DoTracing, kStr_CmdTracingOptions },
#endif
{ kCommandSkins, &EmApplication::DoSkins, kStr_CmdSkins },
{ kCommandHostFS, &EmApplication::DoHostFS, kStr_CmdHostFSOptions },
{ kCommandBreakpoints, &EmApplication::DoBreakpoints, kStr_CmdBreakpoints },
{ kCommandEventReplay, &EmApplication::DoReplay, kStr_CmdEventReplay },
{ kCommandEventMinimize, &EmApplication::DoMinimize, kStr_CmdEventMinimize },
{ kCommandEmpty, &EmApplication::DoNothing, 0 },
{ kCommandFile, &EmApplication::DoNothing, 0 },
{ kCommandEdit, &EmApplication::DoNothing, 0 },
{ kCommandGremlins, &EmApplication::DoNothing, 0 },
#if HAS_PROFILING
{ kCommandProfile, &EmApplication::DoNothing, 0 },
#endif
{ kCommandRoot, &EmApplication::DoNothing, 0 },
{ kCommandOpen, &EmApplication::DoNothing, 0 },
{ kCommandImport, &EmApplication::DoNothing, 0 },
{ kCommandSettings, &EmApplication::DoNothing, 0 },
{ kCommandDivider, &EmApplication::DoNothing, 0 }
};
EmApplication* gApplication;
class EmActionSessionClose : public EmAction
{
public:
EmActionSessionClose (const EmFileRef& ref) :
EmAction (kStr_CmdClose),
fRef (ref)
{
}
virtual ~EmActionSessionClose (void)
{
}
virtual void Do (void)
{
gApplication->HandleSessionClose (fRef);
}
private:
EmFileRef fRef;
};
class EmActionQuit : public EmAction
{
public:
EmActionQuit (void) :
EmAction (kStr_CmdQuit)
{
}
virtual ~EmActionQuit (void)
{
}
virtual void Do (void)
{
gApplication->HandleQuit ();
}
private:
};
// ---------------------------------------------------------------------------
// EmApplication::EmApplication
// ---------------------------------------------------------------------------
// Constructor. Sets the document reference to NULL, sets the quit flag to
// false, and sets the global gApplication variable to point to us.
EmApplication::EmApplication (void) :
EmActionHandler (),
fQuit (false)
{
EmAssert (gApplication == NULL);
gApplication = this;
}
// ---------------------------------------------------------------------------
// EmApplication::~EmApplication
// ---------------------------------------------------------------------------
// Destructor. Makes sure the document has been closed, removes the reference
// to us in gApplication, and performs some necessary final cleanup.
EmApplication::~EmApplication (void)
{
EmAssert (fQuit);
EmAssert (gApplication == this);
gApplication = NULL;
EmTransport::CloseAllTransports ();
}
#pragma mark -
// ---------------------------------------------------------------------------
// EmApplication::Startup
// ---------------------------------------------------------------------------
// Performs one-time startup initialization.
Bool EmApplication::Startup (int argc, char** argv)
{
// Load our preferences.
gPrefs->Load ();
CSocket::Startup ();
Debug::Startup (); // Create our sockets
RPC::Startup (); // Create our sockets
#if HAS_TRACER
gTracer.Initialize ();
#endif
LogStartup ();
// Check to see if any skins were loaded. Report a possible problem if
// not. Only warn the user once. Don't warn for bound Posers, which have
// the only skin they need to use included as a resource.
Preference<Bool> pref (kPrefKeyWarnAboutSkinsDir);
if (!this->IsBound () && *pref)
{
SkinNameList names;
SkinGetSkinNames (EmDevice (), names);
if (names.size () <= 1)
{
EmDlg::DoCommonDialog (kStr_MissingSkins, kDlgFlags_OK);
pref = false;
}
}
// Determine what startup options the user has specified on the command
// line.
Bool result = Startup::DetermineStartupActions (argc, argv);
if (!result)
{
this->SetTimeToQuit (true);
}
return result;
}
// ---------------------------------------------------------------------------
// EmApplication::Shutdown
// ---------------------------------------------------------------------------
// Performs one-time shutdown operations.
void EmApplication::Shutdown (void)
{
RPC::SignalWaiters (hostSignalQuit);
Debug::Shutdown ();
RPC::Shutdown ();
CSocket::Shutdown ();
LogShutdown ();
#if HAS_TRACER
gTracer.Dispose ();
#endif
// Save the preferences.
gPrefs->Save ();
}
#pragma mark -
// ---------------------------------------------------------------------------
// EmApplication::HandleStartupActions
// ---------------------------------------------------------------------------
// Kick off any actions required when Poser starts up. The rules for what
// needs to be done are defined by the Startup class, based on command line
// options, preferences, and the state of the CapsLock key. Here, all we do
// is respond to the results of all those options and either open an old
// session, create a new one, or do nothing.
//
// !!! This function should probably be replaced with EmActions posted by
// Startup::DetermineStartupActions.
//
// This function is an EXCEPTION_CATCH_POINT.
void EmApplication::HandleStartupActions (void)
{
EmFileRef ref;
Configuration cfg;
try
{
if (this->IsBoundFully ())
{
this->HandleOpenBound ();
}
else if (this->IsBoundPartially ())
{
this->HandleNewBound ();
}
else if (Startup::OpenSession (ref))
{
this->HandleOpenFromFile (ref);
}
else if (Startup::CreateSession (cfg))
{
this->HandleNewFromConfig (cfg);
}
else if (Startup::Minimize (ref))
{
this->HandleMinimize (ref);
}
}
catch (ErrCode errCode)
{
Errors::ReportIfError (kStr_GenericOperation, errCode, 0, false);
}
}
// ---------------------------------------------------------------------------
// EmApplication::HandleCommand
// ---------------------------------------------------------------------------
// Handle a user command. Normally the command is generated when the user
// makes a menu selection, but the command could really come from anywhere
// (for example, a toolbar with icon buttons, or from the dialog with the New,
// Open, Download, and Quit pushbuttons in it).
//
// This method examines the command, synchronizes with the CPU thread as
// necessary, executes the command, and catches any exceptions, showing them
// in an error dialog.
//
// This function is an EXCEPTION_CATCH_POINT.
Bool EmApplication::HandleCommand (EmCommandID commandID)
{
// Find information on how this command should be handled.
size_t ii;
for (ii = 0; ii < countof (kCommand); ++ii)
{
if (kCommand[ii].fCommandID == commandID)
break;
}
// If we couldn't find an entry for this command, assume that it's not a
// command for the application, and return false indicating that we did
// not handle the command.
if (ii >= countof (kCommand))
{
return false; // We did not handle this command.
}
// Execute the command. Catch any exceptions and report them to the user.
if (kCommand[ii].fFn)
{
try
{
(this->*(kCommand[ii].fFn)) (commandID);
}
catch (ErrCode errCode)
{
StrCode operation = kCommand[ii].fErrStrCode;
Errors::ReportIfError (operation, errCode, 0, false);
}
}
return true; // We handled this command.
}
// ---------------------------------------------------------------------------
// EmApplication::HandleIdle
// ---------------------------------------------------------------------------
// Perform any application-level idle time operations.
void EmApplication::HandleIdle (void)
{
// Don't let us recurse. This could happen if, for example, we were
// handling a debugger packet, an exception occurs, and Poser tries to
// show an error message in a dialog. That dialog would allow re-entry
// into this function.
static Bool inHandleIdle;
if (inHandleIdle)
return;
EmValueChanger<Bool> oldInHandleIdle (inHandleIdle, true);
// Pop off deferred actions and handle them.
this->DoAll ();
// Idle the document.
if (gDocument)
{
gDocument->HandleIdle ();
}
// Idle the window.
if (gWindow)
{
gWindow->HandleIdle ();
}
}
#pragma mark -
// ---------------------------------------------------------------------------
// EmApplication::HandleNewFromUser
// ---------------------------------------------------------------------------
// Create a new session asking the user for configuration information.
// Starting configuration information can be passed in. If it is not,
// configuration information from the prefs is used.
EmDocument* EmApplication::HandleNewFromUser (const Configuration* inCfg)
{
EmAssert (!this->IsBound ());
// Get the current configuration.
Configuration cfg;
if (inCfg)
{
cfg = *inCfg;
}
else
{
Preference<Configuration> pref (kPrefKeyLastConfiguration);
cfg = *pref;
}
// Ask the user for missing information.
if (!EmDocument::AskNewSession (cfg))
{
return NULL;
}
// Create the new document.
return this->HandleNewFromConfig (cfg);
}
// ---------------------------------------------------------------------------
// EmApplication::HandleNew
// ---------------------------------------------------------------------------
// Create a new session from the current configuration information in the
// preferences.
EmDocument* EmApplication::HandleNewFromPrefs (void)
{
EmAssert (!this->IsBound ());
// Get the current configuration.
Preference<Configuration> pref (kPrefKeyLastConfiguration);
Configuration cfg = *pref;
// Create the new document.
return this->HandleNewFromConfig (cfg);
}
// ---------------------------------------------------------------------------
// EmApplication::HandleNewFromROM
// ---------------------------------------------------------------------------
// Create a new session from the given ROM.
EmDocument* EmApplication::HandleNewFromROM (const EmFileRef& romRef)
{
EmAssert (!this->IsBound ());
// Get the current (last specified) configuration.
Preference<Configuration> pref (kPrefKeyLastConfiguration);
Configuration cfg = *pref;
// Update the ROM file setting with the one passed in to this function.
cfg.fROMFile = romRef;
// Create the new document.
return this->HandleNewFromUser (&cfg);
}
// ---------------------------------------------------------------------------
// EmApplication::HandleNewFromConfig
// ---------------------------------------------------------------------------
// Create a new session from the given configuration, closing any previous
// session first. An exception is thrown if the configuration is invalid.
//
// This function is the bottleneck for creating new sessions.
EmDocument* EmApplication::HandleNewFromConfig (const Configuration& cfg)
{
EmAssert (!this->IsBound ());
// Validate the configuration.
if (!cfg.IsValid ())
{
Errors::Throw (kError_InvalidConfiguration);
}
// Close any previous document. If the use cancels, return NULL.
if (!this->CloseDocument (false))
{
return NULL;
}
// Create the new document.
EmAssert (gDocument == NULL);
EmDocument::DoNew (cfg);
return gDocument;
}
// ---------------------------------------------------------------------------
// EmApplication::HandleNewBound
// ---------------------------------------------------------------------------
EmDocument* EmApplication::HandleNewBound (void)
{
EmAssert (this->IsBoundPartially ());
if (!this->CloseDocument (false))
{
return NULL;
}
EmAssert (gDocument == NULL);
EmDocument::DoNewBound ();
return gDocument;
}
#pragma mark -
// ---------------------------------------------------------------------------
// EmApplication::HandleOpenFromUser
// ---------------------------------------------------------------------------
// Open a previous session, asking the user to find it.
EmDocument* EmApplication::HandleOpenFromUser (EmFileType type)
{
EmAssert (!this->IsBound ());
EmFileRef file;
if (EmDocument::AskLoadSession (file, type))
{
return this->HandleOpenFromFile (file);
}
return NULL;
}
// ---------------------------------------------------------------------------
// EmApplication::HandleOpenFromPrefs
// ---------------------------------------------------------------------------
// Open a previous session, using information from the preferences.
EmDocument* EmApplication::HandleOpenFromPrefs (void)
{
EmAssert (!this->IsBound ());
Preference<EmFileRef> pref (kPrefKeyLastPSF);
EmFileRef file = *pref;
return this->HandleOpenFromFile (file);
}
// ---------------------------------------------------------------------------
// EmApplication::HandleOpenFromFile
// ---------------------------------------------------------------------------
// Open the given saved session, closing any previous session first.
//
// This function is the bottleneck for opening sessions.
EmDocument* EmApplication::HandleOpenFromFile (const EmFileRef& file)
{
EmAssert (!this->IsBound ());
// Close any previous document. If the use cancels, return NULL.
if (!this->CloseDocument (false))
{
return NULL;
}
// Open the old document.
EmAssert (gDocument == NULL);
EmDocument::DoOpen (file);
return gDocument;
}
// ---------------------------------------------------------------------------
// EmApplication::HandleOpenBound
// ---------------------------------------------------------------------------
EmDocument* EmApplication::HandleOpenBound (void)
{
EmAssert (this->IsBoundFully ());
if (!this->CloseDocument (false))
{
return NULL;
}
EmAssert (gDocument == NULL);
EmDocument::DoOpenBound ();
return gDocument;
}
#pragma mark -
// ---------------------------------------------------------------------------
// EmApplication::HandleFileList
// ---------------------------------------------------------------------------
// Grovel over the given list of files and determine what to do with them. The
// list can be any set of files that the emulator recognizes: session files,
// ROM files, PRC/PDB/PQA files, etc. This function must figure out what
// files they are, validate them, and handle them (open an old session, create
// a new session, install files, etc.)
//
// This function is an EXCEPTION_CATCH_POINT.
void EmApplication::HandleFileList (const EmFileRefList& fileList)
{
int operation = kStr_GenericOperation;
try
{
// Grovel over the file list, counting up how many of each kind of
// file was passed to us.
int prcCount = 0;
int psfCount = 0;
int romCount = 0;
int otherCount = 0;
EmFileRefList::const_iterator iter = fileList.begin();
while (iter != fileList.end())
{
// egcs 1.1.1 can't seem to handle iter->Method() here...
if ((*iter).IsType (kFileTypePalmApp)) prcCount++;
else if ((*iter).IsType (kFileTypePalmDB)) prcCount++;
else if ((*iter).IsType (kFileTypePalmQA)) prcCount++;
else if ((*iter).IsType (kFileTypeSession)) psfCount++;
else if ((*iter).IsType (kFileTypeROM)) romCount++;
else otherCount++;
++iter;
}
// If we're able to use the Exchange Manager, let us beam in any file
// type. Later, we may want to do something like PrvFindTarget to see
// if there's actually a handler installed for any given file type
// before trying to beam it. For now, let's just let the OS return an
// error in that case.
//
// Note that the check of "otherCount" is a cheap way to ensure that a
// session is currently running. If no session were running, then the
// call to CanUseExgMgr would crash, as it tries to call into the ROM.
if (otherCount && EmFileImport::CanUseExgMgr ())
{
prcCount += otherCount;
otherCount = 0;
}
// If we have a heterogeneous list, throw an exception.
if ((prcCount > 0) + (psfCount > 0) + (romCount > 0) + (otherCount > 0) > 1)
{
Errors::Throw (kError_OnlySameType);
}
// If we have PRC/PDB/PQA files, install them.
else if (prcCount > 0)
{
operation = prcCount == 1 ? kStr_CmdInstall : kStr_CmdInstallMany;
EmDlg::DoDatabaseImport (fileList, kMethodBest);
}
// If we have a session file, open it. If there's more than one, open
// just the first one.
else if (psfCount > 0)
{
operation = kStr_CmdOpen;
if (!this->IsBoundFully ())
{
if (psfCount > 1)
{
Errors::Throw (kError_OnlyOnePSF);
}
else
{
this->HandleOpenFromFile (fileList[0]);
}
}
}
// If we have a ROM file, create a new session based on it. If
// there's more than one, utilize just the first one.
else if (romCount > 0)
{
operation = kStr_CmdNew;
if (!this->IsBound ())
{
if (romCount > 1)
{
Errors::Throw (kError_OnlyOneROM);
}
else
{
this->HandleNewFromROM (fileList[0]);
}
}
}
// If there's any other file type, throw an exception.
else
{
Errors::Throw (kError_UnknownType);
}
}
// Catch any exceptions and report them.
catch (ErrCode errCode)
{
Errors::ReportIfError (kStr_GenericOperation, errCode, 0, false);
}
}
#pragma mark -
// ---------------------------------------------------------------------------
// EmApplication::HandleMinimize
// ---------------------------------------------------------------------------
// Open a session/event file and start the minimization process on it. Called
// in response to Startup::ScheduleMinimize.
void EmApplication::HandleMinimize (const EmFileRef& ref)
{
if (this->HandleOpenFromFile (ref))
{
EmMinimize::Start ();
}
}
// ---------------------------------------------------------------------------
// EmApplication::HandleSessionClose
// ---------------------------------------------------------------------------
// Close a session, writing it out to the given file. If the file is not
// specified, just close the file without saving it. Called in response to
// ScheduleSessionClose.
void EmApplication::HandleSessionClose (const EmFileRef& ref)
{
if (gDocument)
{
if (ref.IsSpecified ())
{
gDocument->HandleSaveTo (ref);
}
gDocument->HandleClose (kSaveNever, false);
}
EmAssert (gDocument == NULL);
}
// ---------------------------------------------------------------------------
// EmApplication::HandleQuit
// ---------------------------------------------------------------------------
// Quit the emulator, closing any session without saving it. Called in
// response to ScheduleQuit.
void EmApplication::HandleQuit (void)
{
if (gDocument)
{
gDocument->HandleClose (kSaveNever, true);
}
EmAssert (gDocument == NULL);
this->SetTimeToQuit (true);
}
#pragma mark -
// ---------------------------------------------------------------------------
// EmApplication::ScheduleSessionClose
// ---------------------------------------------------------------------------
// Schedule the emulator to close the session to the given file at some safe
// point in the future.
void EmApplication::ScheduleSessionClose (const EmFileRef& ref)
{
this->PostAction (new EmActionSessionClose (ref));
}
// ---------------------------------------------------------------------------
// EmApplication::ScheduleQuit
// ---------------------------------------------------------------------------
// Schedule the emulator to quit at some safe point in the future.
void EmApplication::ScheduleQuit (void)
{
this->PostAction (new EmActionQuit);
}
#pragma mark -
// ---------------------------------------------------------------------------
// EmApplication::DoAbout
// ---------------------------------------------------------------------------
// Show the All Important About Box.
void EmApplication::DoAbout (EmCommandID)
{
EmDlg::DoAboutBox ();
}
// ---------------------------------------------------------------------------
// EmApplication::DoNew
// ---------------------------------------------------------------------------
// Create a new document, asking the user for configuration information.
void EmApplication::DoNew (EmCommandID)
{
EmAssert (!this->IsBoundFully ());
if (this->IsBoundPartially ())
{
this->HandleNewBound ();
}
else
{
this->HandleNewFromUser (NULL);
}
}
// ---------------------------------------------------------------------------
// EmApplication::DoOpen
// ---------------------------------------------------------------------------
// Open a previously saved document. Either ask the user for a document, or
// fetch a document from the MRU list.
void EmApplication::DoOpen (EmCommandID commandID)
{
EmAssert (!this->IsBound ());
if (commandID == kCommandSessionOpenOther)
{
this->HandleOpenFromUser (kFileTypeSession);
}
else
{
int index = commandID - kCommandSessionOpen0;
EmFileRef file = gEmuPrefs->GetIndRAMMRU (index);
if (file.IsSpecified ())
{
this->HandleOpenFromFile (file);
}
}
}
// ---------------------------------------------------------------------------
// EmApplication::DoClose
// ---------------------------------------------------------------------------
// Attempt to close the current document.
void EmApplication::DoClose (EmCommandID)
{
this->CloseDocument (false);
}
// ---------------------------------------------------------------------------
// EmApplication::DoQuit
// ---------------------------------------------------------------------------
// Attempt to close the current document and quit the application.
void EmApplication::DoQuit (EmCommandID)
{
if (this->CloseDocument (true))
{
this->SetTimeToQuit (true);
}
}
// ---------------------------------------------------------------------------
// EmApplication::DoDownload
// ---------------------------------------------------------------------------
// Display the ROM Transfer dialog, and download the actual ROM if the user
// doesn't cancel the operation.
void EmApplication::DoDownload (EmCommandID)
{
EmROMTransfer::ROMTransfer ();
}
// ---------------------------------------------------------------------------
// EmApplication::DoPreferences
// ---------------------------------------------------------------------------
// Display the General Preferences dialog.
void EmApplication::DoPreferences (EmCommandID)
{
EmDlg::DoEditPreferences ();
}
// ---------------------------------------------------------------------------
// EmApplication::DoLogging
// ---------------------------------------------------------------------------
// Display the Logging Preferences dialog.
void EmApplication::DoLogging (EmCommandID)
{
EmDlg::DoEditLoggingOptions (kNormalLogging);
}
// ---------------------------------------------------------------------------
// EmApplication::DoDebugging
// ---------------------------------------------------------------------------
// Display the Debugging Preferences dialog.
void EmApplication::DoDebugging (EmCommandID)
{
EmDlg::DoEditDebuggingOptions ();
}
// ---------------------------------------------------------------------------
// EmApplication::DoErrorHandling
// ---------------------------------------------------------------------------
// Display the Error Handling Preferences dialog.
void EmApplication::DoErrorHandling (EmCommandID)
{
EmDlg::DoEditErrorHandling ();
}
// ---------------------------------------------------------------------------
// EmApplication::DoTracing
// ---------------------------------------------------------------------------
// Display the Tracing Preferences dialog.
#if HAS_TRACER
void EmApplication::DoTracing (EmCommandID)
{
EmDlg::DoEditTracingOptions ();
}
#endif
// ---------------------------------------------------------------------------
// EmApplication::DoSkins
// ---------------------------------------------------------------------------
// Display the Skins Preferences dialog.
void EmApplication::DoSkins (EmCommandID)
{
EmDlg::DoEditSkins ();
}
// ---------------------------------------------------------------------------
// EmApplication::DoHostFS
// ---------------------------------------------------------------------------
// Display the HostFS Preferences dialog.
void EmApplication::DoHostFS (EmCommandID)
{
EmDlg::DoEditHostFSOptions ();
}
// ---------------------------------------------------------------------------
// EmApplication::DoBreakpoints
// ---------------------------------------------------------------------------
// Display the Breakpoints Preferences dialog.
void EmApplication::DoBreakpoints (EmCommandID)
{
EmDlg::DoEditBreakpoints ();
}
// ---------------------------------------------------------------------------
// EmApplication::DoReplay
// ---------------------------------------------------------------------------
// Open a document specified by the user and start the Playback process.
void EmApplication::DoReplay (EmCommandID)
{
if (this->HandleOpenFromUser (kFileTypeEvents))
{
EmAssert (gSession);
EmEventPlayback::LoadEvents (gSession->GetFile ());
EmEventPlayback::ReplayEvents (true);
}
}
// ---------------------------------------------------------------------------
// EmApplication::DoMinimize
// ---------------------------------------------------------------------------
// Open a document specified by the user and start the Minimization process.
void EmApplication::DoMinimize (EmCommandID)
{
if (this->HandleOpenFromUser (kFileTypeEvents))
{
EmMinimize::Start ();
}
}
// ---------------------------------------------------------------------------
// EmApplication::DoNothing
// ---------------------------------------------------------------------------
// Null operation. Used for menu items that can be selected but that don't
// actually do anything.
void EmApplication::DoNothing (EmCommandID)
{
}
#pragma mark -
// ---------------------------------------------------------------------------
// EmApplication::CloseDocument
// ---------------------------------------------------------------------------
// Handles the request to close a document. This request can be denied: if
// the user is asked if they want to save the document, they can cancel the
// operation. This function returns true if there is no running document when
// it exits (that is, the current document was closed or there was no document
// open to begin with). Otherwise, it returns false to indicate that a
// document is still open.
Bool EmApplication::CloseDocument (Bool quitting)
{
if (gDocument)
{
gDocument->HandleClose (quitting);
}
return gDocument == NULL;
}
#pragma mark -
// ---------------------------------------------------------------------------
// EmApplication::IsBound
// ---------------------------------------------------------------------------
// Returns whether or not this application is bound in any sort of fashion.
// We cache the result in case this function is called from time-critical
// functions.
Bool EmApplication::IsBound (void)
{
static int result;
if (result == 0)
{
result = this->ROMResourcePresent () ? 1 : -1;
}
return result > 0;
}
// ---------------------------------------------------------------------------
// EmApplication::IsBoundPartially
// ---------------------------------------------------------------------------
// Returns whether or not this application is partially bound. Returns false
// if fully bound or not bound.
// We cache the result in case this function is called from time-critical
// functions.
Bool EmApplication::IsBoundPartially (void)
{
static int result;
if (result == 0)
{
result = (this->ROMResourcePresent () && !this->PSFResourcePresent ()) ? 1 : -1;
}
return result > 0;
}
// ---------------------------------------------------------------------------
// EmApplication::IsBoundFully
// ---------------------------------------------------------------------------
// Returns whether or not this application is fully bound. Return false if
// partially bound or not bound.
// We cache the result in case this function is called from time-critical
// functions.
Bool EmApplication::IsBoundFully (void)
{
static int result;
if (result == 0)
{
result = this->PSFResourcePresent () ? 1 : -1;
}
return result > 0;
}
|