code refactored

This commit is contained in:
henrypp committed 2020-06-09 17:28:37 +06:00
1 parent a9c5443c79
commit 924956eb05
18 files changed
+3962 -4076

No files matched your search

+44 -44
View File
@@ -3,56 +3,56 @@
#include "global.hpp"
void _app_timer_set (HWND hwnd, PITEM_APP ptr_app, time_t seconds)
VOID _app_timer_set (HWND hwnd, PITEM_APP ptr_app, time_t seconds)
{
const size_t app_hash = _r_str_hash (ptr_app->original_path); // note: be carefull (!)
SIZE_T app_hash = _r_str_hash (ptr_app->original_path); // note: be carefull (!)
const INT listview_id = _app_getlistview_id (ptr_app->type);
const INT item_pos = _app_getposition (hwnd, listview_id, app_hash);
INT listview_id = _app_getlistview_id (ptr_app->type);
INT item_pos = _app_getposition (hwnd, listview_id, app_hash);
if (seconds <= 0)
{
ptr_app->is_enabled = false;
ptr_app->is_haveerrors = false;
ptr_app->is_enabled = FALSE;
ptr_app->is_haveerrors = FALSE;
ptr_app->timer = 0;
if (_r_fs_isvalidhandle (ptr_app->htimer))
{
DeleteTimerQueueTimer (config.htimer, ptr_app->htimer, nullptr);
ptr_app->htimer = nullptr;
DeleteTimerQueueTimer (config.htimer, ptr_app->htimer, NULL);
ptr_app->htimer = NULL;
}
}
else
{
const time_t current_time = _r_unixtime_now ();
bool is_created = false;
time_t current_time = _r_unixtime_now ();
BOOL is_created = FALSE;
if (_r_fs_isvalidhandle (ptr_app->htimer))
{
is_created = ChangeTimerQueueTimer (config.htimer, ptr_app->htimer, DWORD (seconds * _R_SECONDSCLOCK_MSEC), 0);
is_created = ChangeTimerQueueTimer (config.htimer, ptr_app->htimer, (DWORD)seconds * _R_SECONDSCLOCK_MSEC, 0);
}
else
{
is_created = CreateTimerQueueTimer (&ptr_app->htimer, config.htimer, &_app_timer_callback, (PVOID)app_hash, DWORD (seconds * _R_SECONDSCLOCK_MSEC), 0, WT_EXECUTEONLYONCE | WT_EXECUTEINTIMERTHREAD);
is_created = CreateTimerQueueTimer (&ptr_app->htimer, config.htimer, &_app_timer_callback, (PVOID)app_hash, (DWORD)seconds * _R_SECONDSCLOCK_MSEC, 0, WT_EXECUTEONLYONCE | WT_EXECUTEINTIMERTHREAD);
}
if (is_created)
{
ptr_app->is_enabled = true;
ptr_app->is_enabled = TRUE;
ptr_app->timer = current_time + seconds;
}
else
{
ptr_app->is_enabled = false;
ptr_app->is_haveerrors = false;
ptr_app->is_enabled = FALSE;
ptr_app->is_haveerrors = FALSE;
ptr_app->timer = 0;
if (_r_fs_isvalidhandle (ptr_app->htimer))
{
DeleteTimerQueueTimer (config.htimer, ptr_app->htimer, nullptr);
ptr_app->htimer = nullptr;
DeleteTimerQueueTimer (config.htimer, ptr_app->htimer, NULL);
ptr_app->htimer = NULL;
}
}
}
@@ -61,35 +61,35 @@ void _app_timer_set (HWND hwnd, PITEM_APP ptr_app, time_t seconds)
{
_r_fastlock_acquireshared (&lock_checkbox);
_r_listview_setitem (hwnd, listview_id, item_pos, 0, nullptr, I_IMAGENONE, _app_getappgroup (app_hash, ptr_app));
_r_listview_setitem (hwnd, listview_id, item_pos, 0, NULL, I_IMAGENONE, _app_getappgroup (app_hash, ptr_app));
_r_listview_setitemcheck (hwnd, listview_id, item_pos, ptr_app->is_enabled);
_r_fastlock_releaseshared (&lock_checkbox);
}
}
void _app_timer_reset (HWND hwnd, PITEM_APP ptr_app)
VOID _app_timer_reset (HWND hwnd, PITEM_APP ptr_app)
{
if (!_app_istimeractive (ptr_app))
return;
ptr_app->is_enabled = false;
ptr_app->is_haveerrors = false;
ptr_app->is_enabled = FALSE;
ptr_app->is_haveerrors = FALSE;
ptr_app->timer = 0;
if (_r_fs_isvalidhandle (ptr_app->htimer))
{
DeleteTimerQueueTimer (config.htimer, ptr_app->htimer, nullptr);
ptr_app->htimer = nullptr;
DeleteTimerQueueTimer (config.htimer, ptr_app->htimer, NULL);
ptr_app->htimer = NULL;
}
const size_t app_hash = _r_str_hash (ptr_app->original_path); // note: be carefull (!)
const INT listview_id = _app_getlistview_id (ptr_app->type);
SIZE_T app_hash = _r_str_hash (ptr_app->original_path); // note: be carefull (!)
INT listview_id = _app_getlistview_id (ptr_app->type);
if (listview_id)
{
const INT item_pos = _app_getposition (hwnd, listview_id, app_hash);
INT item_pos = _app_getposition (hwnd, listview_id, app_hash);
if (item_pos != INVALID_INT)
{
@@ -100,16 +100,16 @@ void _app_timer_reset (HWND hwnd, PITEM_APP ptr_app)
}
}
bool _app_istimeractive (const PITEM_APP ptr_app)
BOOLEAN _app_istimeractive (const PITEM_APP ptr_app)
{
return _r_fs_isvalidhandle (ptr_app->htimer) || (ptr_app->timer && (ptr_app->timer > _r_unixtime_now ()));
}
bool _app_istimersactive ()
BOOLEAN _app_istimersactive ()
{
for (auto &p : apps)
{
PR_OBJECT ptr_app_object = _r_obj_reference (p.second);
PR_OBJECT ptr_app_object = _r_obj2_reference (p.second);
if (!ptr_app_object)
continue;
@@ -118,20 +118,20 @@ bool _app_istimersactive ()
if (ptr_app && _app_istimeractive (ptr_app))
{
_r_obj_dereference (ptr_app_object);
return true;
_r_obj2_dereference (ptr_app_object);
return TRUE;
}
_r_obj_dereference (ptr_app_object);
_r_obj2_dereference (ptr_app_object);
}
return false;
return FALSE;
}
void CALLBACK _app_timer_callback (PVOID lparam, BOOLEAN)
VOID CALLBACK _app_timer_callback (PVOID lpParameter, BOOLEAN TimerOrWaitFired)
{
const HWND hwnd = app.GetHWND ();
const size_t app_hash = (size_t)lparam;
HWND hwnd = app.GetHWND ();
SIZE_T app_hash = (SIZE_T)lpParameter;
PR_OBJECT ptr_app_object = _app_getappitem (app_hash);
@@ -142,7 +142,7 @@ void CALLBACK _app_timer_callback (PVOID lparam, BOOLEAN)
if (!ptr_app)
{
_r_obj_dereference (ptr_app_object);
_r_obj2_dereference (ptr_app_object);
return;
}
@@ -152,17 +152,17 @@ void CALLBACK _app_timer_callback (PVOID lparam, BOOLEAN)
_app_timer_reset (hwnd, ptr_app);
_wfp_create3filters (_wfp_getenginehandle (), rules, __LINE__);
_r_obj_dereference (ptr_app_object);
_r_obj2_dereference (ptr_app_object);
const INT listview_id = (INT)_r_tab_getlparam (hwnd, IDC_TAB, INVALID_INT);
INT listview_id = (INT)_r_tab_getlparam (hwnd, IDC_TAB, INVALID_INT);
_app_listviewsort (hwnd, listview_id);
_app_listviewsort (hwnd, listview_id, INVALID_INT, FALSE);
_app_refreshstatus (hwnd, listview_id);
_app_profile_save ();
_app_profile_save (NULL);
_r_listview_redraw (hwnd, listview_id);
_r_listview_redraw (hwnd, listview_id, INVALID_INT);
if (app.ConfigGet (L"IsNotificationsTimer", true).AsBool ())
_r_tray_popup (hwnd, UID, NIIF_INFO | (app.ConfigGet (L"IsNotificationsSound", true).AsBool () ? 0 : NIIF_NOSOUND), APP_NAME, _r_fmt (app.LocaleString (IDS_STATUS_TIMER_DONE, nullptr), ptr_app->display_name));
if (app.ConfigGetBoolean (L"IsNotificationsTimer", TRUE))
_r_tray_popup (hwnd, UID, NIIF_INFO | (app.ConfigGetBoolean (L"IsNotificationsSound", TRUE) ? 0 : NIIF_NOSOUND), APP_NAME, _r_fmt (app.LocaleString (IDS_STATUS_TIMER_DONE, NULL), ptr_app->display_name));
}