Changeset 50 for trunk/gotcha.cpp


Ignore:
Timestamp:
Apr 7, 2018, 9:52:46 PM (7 years ago)
Author:
Gregg Young
Message:

Only allow single instance of Gotcha Quiet; Disable PM print screen setting on opening Gotcha Quiet and restore it to what ever it was set to on exit. Update the hook version.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gotcha.cpp

    r38 r50  
    107107    //DisplayError("DEBUG", "%d", Version());
    108108#ifdef _QUIET_
    109     if ((Version() < 1))
     109    if ((Version() < 2))
    110110    {
    111111        DisplayError("GOTCHDLL.DLL TOO OLD",
     
    118118        exit (0);
    119119    }
    120 
    121     bool fPrtScr = FALSE;
    122     ULONG ulDataSize;
    123120    int rc;
    124 
    125     rc = PrfQueryProfileSize( HINI_PROFILE, "PM_ControlPanel", "PrintScreen",
    126                              &ulDataSize );
    127     rc = PrfQueryProfileData(HINI_USERPROFILE, "PM_ControlPanel", "PrintScreen",
    128                              &fPrtScr, &ulDataSize);
    129     if (fPrtScr || !rc) {
    130         fPrtScr = TRUE;
    131         bool temp = FALSE;
    132         rc = PrfWriteProfileData(HINI_USERPROFILE, "PM_ControlPanel", "PrintScreen",
    133                                  &temp, sizeof(bool));
     121    HMTX    hmtx     = NULLHANDLE;
     122    // running multiple instances orphans all but the first closed hook unloaded
     123    rc = DosOpenMutexSem("\\SEM32\\GOTCHA", &hmtx);
     124    if (!rc) {
     125        DisplayError("GOTCHA QUIET ALREADY RUNNING",
     126                     "Another instance of Gotcha Quiet is running."
     127                     " You can open Gotcha Quiet's settings using"
     128                     " the Alt+Print Screen key combination");
     129        exit (0);
     130    }
     131    rc = DosCreateMutexSem("\\SEM32\\GOTCHA", &hmtx, 0, FALSE);
     132    if (rc) {
     133        DisplayError("Semaphore creation failed",
     134                     "Try restarting Gotcha Quiet");
     135        exit (0);
    134136    }
    135137#endif
     
    149151    pset->pForceSaveFile = pset->QueryForceSaveFile();
    150152    pset->bSerialCapture = pset->SerialCapture ();
     153
     154#ifdef _QUIET_
     155    bool fPrtScr = FALSE;
     156    ULONG ulDataSize = 0;
     157   
     158    rc = PrfQueryProfileSize( HINI_PROFILE, "PM_ControlPanel", "PrintScreen",
     159                             &ulDataSize );
     160    rc = PrfQueryProfileData(HINI_USERPROFILE, "PM_ControlPanel", "PrintScreen",
     161                             &fPrtScr, &ulDataSize);
     162    bool temp = FALSE;// always turn it off while running
     163    PrfWriteProfileData(HINI_USERPROFILE, "PM_ControlPanel",
     164                        "PrintScreen", &temp, sizeof(bool));
     165    PrfQueryProfileSize(pset->QueryPrfHandle (), "PM",
     166                        "PrintScreen", &ulDataSize );
     167    int rc1 = PrfQueryProfileData(pset->QueryPrfHandle (), "PM",
     168                                  "PrintScreen", &temp, &ulDataSize);
     169    bool temp2 = TRUE;
     170    PrfQueryProfileData(pset->QueryPrfHandle (), "PM",
     171                        "PrintScreen", &temp2, &ulDataSize);
     172    if (!rc1 || (temp2 && (temp != fPrtScr))) { // no entry or user has changed PM setting
     173        if (!rc) // Print screen is on by default (no ini entry)
     174           fPrtScr = TRUE;
     175        PrfWriteProfileData(pset->QueryPrfHandle (), "PM",
     176                            "PrintScreen", &fPrtScr, sizeof(bool));
     177    }
     178    temp = FALSE;
     179    PrfWriteProfileData(pset->QueryPrfHandle (), "PM",
     180                        "Exited", &temp, sizeof(bool));
     181#endif
    151182    // check cmd line args and if "-a" found take screenshot and exit
    152183    if (CheckCmdlineArgs (argc, argv))
     
    228259
    229260#ifdef _QUIET_
    230     if (fPrtScr || !rc) {
    231         PrfWriteProfileData(HINI_USERPROFILE, "PM_ControlPanel", "PrintScreen",
    232                             &fPrtScr, sizeof(bool));
    233     }
     261    PrfQueryProfileSize(pset->QueryPrfHandle (), "PM",
     262                        "PrintScreen", &ulDataSize );
     263    PrfQueryProfileData(pset->QueryPrfHandle (), "PM",
     264                        "PrintScreen", &fPrtScr, &ulDataSize);
     265    PrfWriteProfileData(HINI_USERPROFILE, "PM_ControlPanel", "PrintScreen",
     266                        &fPrtScr, sizeof(bool));
     267    temp = TRUE;
     268    PrfWriteProfileData(pset->QueryPrfHandle (), "PM",
     269                        "Exited", &temp, sizeof(bool));
     270
    234271    StopInputHook ();
    235 #endif
    236 
     272    DosCloseMutexSem(hmtx);
     273#endif
     274   
    237275    delete g_phelp;
    238276    delete pset;
Note: See TracChangeset for help on using the changeset viewer.