Skip to content

Commit

Permalink
New setting save policy
Browse files Browse the repository at this point in the history
  • Loading branch information
lcferrum committed Nov 28, 2017
1 parent df60289 commit 07fd4e2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
14 changes: 7 additions & 7 deletions SuiteMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ int SuiteMain(SuiteSettings *settings)
}

//Manually uninitializing some components to make sure right unintialization order
SnkHotkey->Stop(); //This way HotkeyEngine is deinitialized right after TskbrNtfAreaIcon
settings->SaveSettings(); //Main parts of HotkeySuite are deinitialized and now it's time to save settings
SnkHotkey->Stop(); //This way HotkeyEngine is deinitialized right after TskbrNtfAreaIcon
if (uac_bitmap) DeleteObject(uac_bitmap); //If UAC shield bitmap was created - free it

return msg.wParam;
Expand Down Expand Up @@ -244,6 +243,7 @@ bool IconMenuProc(HotkeyEngine* &hk_engine, SuiteSettings *settings, KeyTriplet
}
hk_engine->Set((LPARAM)hk_triplet, hk_triplet->CreateEventHandler(settings));
if (hk_was_running&&!hk_engine->Start()) break;
settings->SaveSettings();
return true;
case IDM_SET_CTRL_ALT:
hk_was_running=hk_engine->Stop();
Expand All @@ -252,6 +252,7 @@ bool IconMenuProc(HotkeyEngine* &hk_engine, SuiteSettings *settings, KeyTriplet
sender->ModifyIconMenu(POS_SETTINGS, MF_BYPOSITION|MF_STRING|MF_UNCHECKED|MF_ENABLED|MF_POPUP, (UINT_PTR)GetSubMenu(sender->GetIconMenu(), POS_SETTINGS), GetHotkeyString(ModKeyType::CTRL_ALT, settings->GetBindedKey()).c_str());
hk_engine->Set((LPARAM)hk_triplet, hk_triplet->CreateEventHandler(settings));
if (hk_was_running&&!hk_engine->Start()) break;
settings->SaveSettings();
return true;
case IDM_SET_SHIFT_ALT:
hk_was_running=hk_engine->Stop();
Expand All @@ -260,6 +261,7 @@ bool IconMenuProc(HotkeyEngine* &hk_engine, SuiteSettings *settings, KeyTriplet
sender->ModifyIconMenu(POS_SETTINGS, MF_BYPOSITION|MF_STRING|MF_UNCHECKED|MF_ENABLED|MF_POPUP, (UINT_PTR)GetSubMenu(sender->GetIconMenu(), POS_SETTINGS), GetHotkeyString(ModKeyType::SHIFT_ALT, settings->GetBindedKey()).c_str());
hk_engine->Set((LPARAM)hk_triplet, hk_triplet->CreateEventHandler(settings));
if (hk_was_running&&!hk_engine->Start()) break;
settings->SaveSettings();
return true;
case IDM_SET_CTRL_SHIFT:
hk_was_running=hk_engine->Stop();
Expand All @@ -268,6 +270,7 @@ bool IconMenuProc(HotkeyEngine* &hk_engine, SuiteSettings *settings, KeyTriplet
sender->ModifyIconMenu(POS_SETTINGS, MF_BYPOSITION|MF_STRING|MF_UNCHECKED|MF_ENABLED|MF_POPUP, (UINT_PTR)GetSubMenu(sender->GetIconMenu(), POS_SETTINGS), GetHotkeyString(ModKeyType::CTRL_SHIFT, settings->GetBindedKey()).c_str());
hk_engine->Set((LPARAM)hk_triplet, hk_triplet->CreateEventHandler(settings));
if (hk_was_running&&!hk_engine->Start()) break;
settings->SaveSettings();
return true;
case IDM_SET_CUSTOM:
{
Expand Down Expand Up @@ -305,6 +308,7 @@ bool IconMenuProc(HotkeyEngine* &hk_engine, SuiteSettings *settings, KeyTriplet
case BD_DLGPRC_CANCEL:
hk_engine->Set((LPARAM)hk_triplet, hk_triplet->CreateEventHandler(settings));
if (hk_was_running&&!hk_engine->Start()) break;
settings->SaveSettings();
sender->SetModalWnd(NULL);
sender->Enable();
return true;
Expand Down Expand Up @@ -368,11 +372,7 @@ void CloseEventHandler(SuiteSettings *settings, TskbrNtfAreaIcon *sender)
}

void EndsessionTrueEventHandler(SuiteSettings *settings, TskbrNtfAreaIcon *sender, bool critical)
{
//Session is about to end - there is a chance that process will be terminated right after this event handler exits, abandoning all the code after mesage loop
//So saving settings now but not exiting app - it will be terminated anyway
settings->SaveSettings();
}
{}

bool CheckIfElevationRequired()
{
Expand Down
29 changes: 23 additions & 6 deletions SuiteSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,13 @@ SuiteSettingsIni::SuiteSettingsIni(const std::wstring &shk_cfg_path, const std::

stored=true;

IniSzQueryValue(KEY_ONHOTKEYCFGPATH, this->shk_cfg_path);
IniSzQueryValue(KEY_ONHOTKEYLONGPRESSCFGPATH, this->lhk_cfg_path);
IniSzQueryValue(KEY_SNKPATH, snk_path);
if (!IniSzQueryValue(KEY_ONHOTKEYCFGPATH, this->shk_cfg_path))
changed|=CHG_ONHOTKEYCFGPATH;
if (!IniSzQueryValue(KEY_ONHOTKEYLONGPRESSCFGPATH, this->lhk_cfg_path))
changed|=CHG_ONHOTKEYLONGPRESSCFGPATH;
if (!IniSzQueryValue(KEY_SNKPATH, snk_path))
changed|=CHG_SNKPATH;

IniSzQueryValue(KEY_CUSTOMONHOTKEY, custom_shk);
IniSzQueryValue(KEY_CUSTOMONHOTKEYLONGPRESS, custom_lhk);

Expand All @@ -201,14 +205,23 @@ SuiteSettingsIni::SuiteSettingsIni(const std::wstring &shk_cfg_path, const std::
binded_key.ext=false;
binded_key.sc=LOBYTE(binded_sc);
//If SC was in ini file but VK wasn't - make VK from SC
if (!vk_found) MapScToVk(binded_sc, binded_key);
if (!vk_found) {
MapScToVk(binded_sc, binded_key);
changed|=CHG_HOTKEYVIRTUALKEY;
}
}
if (vk_found) {
binded_key.vk=LOBYTE(binded_vk);
//If VK was in ini file but SC wasn't - make SC from VK
if (!sc_found) MapVkToSc(binded_vk, binded_key);
if (!sc_found) {
MapVkToSc(binded_vk, binded_key);
changed|=CHG_HOTKEYSCANCODE;
}
}
if (!sc_found&&!vk_found) {
//In case if both VK and SC wern't found - default values will be kept
changed|=CHG_HOTKEYVIRTUALKEY|CHG_HOTKEYSCANCODE;
}
//In case if both VK and SC wern't found - default values will be kept

std::wstring mod_key_str;
IniSzQueryValue(KEY_HOTKEYMODIFIERKEY, mod_key_str);
Expand All @@ -219,11 +232,15 @@ SuiteSettingsIni::SuiteSettingsIni(const std::wstring &shk_cfg_path, const std::
mod_key=ModKeyType::SHIFT_ALT;
} else if (!mod_key_str.compare(VAL_LC_CTRLSHIFT)) {
mod_key=ModKeyType::CTRL_SHIFT;
} else {
changed|=CHG_HOTKEYMODIFIERKEY;
}

DWORD long_press_dw;
if (IniDwordQueryValue(KEY_LONGPRESSENABLED, long_press_dw)) {
long_press=long_press_dw;
} else {
changed|=CHG_LONGPRESSENABLED;
}
}

Expand Down

0 comments on commit 07fd4e2

Please sign in to comment.