@@ -21,6 +21,8 @@ internal struct SoftLockSettings
21
21
internal bool Active ;
22
22
internal int Seconds ;
23
23
internal bool SoftLockOnMinimize ;
24
+ internal bool ValidityActive ;
25
+ internal int ValiditySeconds ;
24
26
}
25
27
26
28
internal class SoftLock : IMessageFilter
@@ -181,9 +183,22 @@ private void OnTimerTick(object sender, EventArgs e)
181
183
//if ((GlobalWindowManager.WindowCount > 0) && LockAssistConfig.SL_ExcludeForms.Contains(GlobalWindowManager.TopWindow.GetType().Name)) return;
182
184
183
185
Application . RemoveMessageFilter ( this ) ;
186
+
187
+ if ( RequestFullPassword ( ) )
188
+ {
189
+ DisableSoftlockUsingFullPassword ( ) ;
190
+ }
191
+ else
192
+ {
193
+ DisableSoftlockUsingQU ( ) ;
194
+ }
195
+ Application . AddMessageFilter ( this ) ;
196
+ }
197
+
198
+ private void DisableSoftlockUsingQU ( )
199
+ {
184
200
m_UnlockForm = new UnlockForm ( ) ;
185
201
m_UnlockForm . Text = PluginTranslate . PluginName + " - Softlock" ;
186
-
187
202
if ( m_UnlockForm . ShowDialog ( Program . MainForm ) == DialogResult . OK )
188
203
{
189
204
ProtectedString CheckQuickUnlockKey = m_UnlockForm . QuickUnlockKey ;
@@ -194,11 +209,37 @@ private void OnTimerTick(object sender, EventArgs e)
194
209
SetVisibility ( true ) ;
195
210
if ( LockAssistConfig . SL_IsActive ) m_SLTimer . Interval = LockAssistConfig . SL_Seconds * 1000 ;
196
211
}
197
- else PluginDebug . AddError ( "Deactivate SoftLock" , "Deactivation failed" , "INvalid Quick Unlock key provided" ) ;
212
+ else PluginDebug . AddError ( "Deactivate SoftLock" , "Deactivation failed" , "Invalid Quick Unlock key provided" ) ;
198
213
}
199
214
if ( m_UnlockForm != null ) m_UnlockForm . Dispose ( ) ;
200
215
m_UnlockForm = null ;
201
- Application . AddMessageFilter ( this ) ;
216
+ }
217
+
218
+ private void DisableSoftlockUsingFullPassword ( )
219
+ {
220
+ using ( KeyPromptForm kpf = new KeyPromptForm ( ) )
221
+ {
222
+ kpf . InitEx ( Program . MainForm . ActiveDatabase . IOConnectionInfo , false , false ) ;
223
+ kpf . Load += ( o , e1 ) => { kpf . Text = "Softlock - " + kpf . Text ; } ;
224
+ if ( kpf . ShowDialog ( Program . MainForm ) == DialogResult . OK )
225
+ {
226
+ ProtectedBinary pbKey = QuickUnlockKeyProv . CreateMasterKeyHash ( kpf . CompositeKey ) ;
227
+ ProtectedBinary pbKeyDB = QuickUnlockKeyProv . CreateMasterKeyHash ( Program . MainForm . ActiveDatabase . MasterKey ) ;
228
+ if ( pbKey . Equals ( pbKeyDB ) )
229
+ {
230
+ SetVisibility ( true ) ;
231
+ if ( LockAssistConfig . SL_IsActive ) m_SLTimer . Interval = LockAssistConfig . SL_Seconds * 1000 ;
232
+ }
233
+ else PluginDebug . AddError ( "Deactivate SoftLock" , "Deactivation failed" , "Invalid key provided" ) ;
234
+ }
235
+ }
236
+ }
237
+
238
+ private bool RequestFullPassword ( )
239
+ {
240
+ if ( ! LockAssistConfig . SL_ValidityActive ) return false ;
241
+ var dtCheck = m_dtSoftlockActivation + new TimeSpan ( 0 , 0 , LockAssistConfig . SL_ValiditySeconds ) ;
242
+ return dtCheck < DateTime . Now ;
202
243
}
203
244
204
245
internal void CheckSoftlockMode ( )
@@ -226,13 +267,15 @@ private void CheckSoftlockMode(object sender, EventArgs e)
226
267
}
227
268
}
228
269
270
+ private DateTime m_dtSoftlockActivation = DateTime . MaxValue ;
229
271
internal void SetVisibility ( bool bVisible )
230
272
{
231
273
List < string > lMsg = new List < string > ( ) ;
232
274
m_SoftLocked = ! bVisible ;
233
275
lMsg . Add ( "SoftLock active: " + m_SoftLocked . ToString ( ) ) ;
234
276
if ( m_SoftLocked )
235
277
{
278
+ m_dtSoftlockActivation = DateTime . Now ;
236
279
m_dHiddenForms . Clear ( ) ;
237
280
foreach ( Form f in Application . OpenForms )
238
281
{
@@ -260,7 +303,11 @@ internal void SetVisibility(bool bVisible)
260
303
try { HandleForm ( kvp . Key , kvp . Value , ! m_SoftLocked , lMsg ) ; }
261
304
catch ( Exception ex ) { lMsg . Add ( "Ex:" + ex . Message ) ; }
262
305
}
263
- if ( ! m_SoftLocked ) m_dHiddenForms . Clear ( ) ;
306
+ if ( ! m_SoftLocked )
307
+ {
308
+ m_dHiddenForms . Clear ( ) ;
309
+ m_dtSoftlockActivation = DateTime . MaxValue ;
310
+ }
264
311
PluginDebug . AddInfo ( "Toggle SoftLock" , lMsg . ToArray ( ) ) ;
265
312
}
266
313
@@ -370,9 +417,13 @@ private void HandlePanel(bool bVisible, Control c)
370
417
371
418
bHide = new Button ( ) ;
372
419
bHide . Name = buttonName ;
420
+ //ONLY the button shown on the MainForm shall have a text
421
+ //Adjust the text based on the number of hidden forms
373
422
if ( m_dHiddenForms . Count == 0 )
374
- bHide . Text = PluginTranslate . SoftlockModeUnhide ; //Display button on MainForm only, set text
375
- else if ( Application . OpenForms . Count > 1 && c == Application . OpenForms [ Application . OpenForms . Count - 1 ] ) //Display button on topmost form, set text
423
+ bHide . Text = PluginTranslate . SoftlockModeUnhide ; //Display button on MainForm only, set text
424
+ //else if (Application.OpenForms.Count > 1 && c == Application.OpenForms[Application.OpenForms.Count - 1]) //Display button on topmost form, set text
425
+ // bHide.Text = PluginTranslate.SoftlockModeUnhideForms;
426
+ else if ( Application . OpenForms . Count > 1 && c == Program . MainForm ) //Display button on topmost form, set text
376
427
bHide . Text = PluginTranslate . SoftlockModeUnhideForms ;
377
428
378
429
bHide . TextAlign = System . Drawing . ContentAlignment . MiddleCenter ;
0 commit comments