Skip to content

Commit 0ffe6a1

Browse files
author
henrypp
committed
upd code
1 parent 2889a73 commit 0ffe6a1

1 file changed

Lines changed: 128 additions & 106 deletions

File tree

src/main.c

Lines changed: 128 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
STATIC_DATA config = {0};
1212

13-
R_QUEUED_LOCK lock_checkbox = PR_QUEUED_LOCK_INIT;
14-
1513
VOID NTAPI _app_dereferencemoduleprocedure (_In_ PVOID entry)
1614
{
1715
PITEM_MODULE ptr_item;
@@ -108,18 +106,20 @@ INT CALLBACK _app_listviewcompare_callback (_In_ LPARAM lparam1, _In_ LPARAM lpa
108106

109107
if (item_text_1 && item_text_2)
110108
{
111-
if (_r_str_isstartswith (&item_text_1->sr, &sr1, TRUE))
112-
{
113-
result = -1;
114-
}
115-
else if (_r_str_isstartswith (&item_text_2->sr, &sr1, TRUE))
109+
if (listview_id == IDC_LISTVIEW)
116110
{
117-
result = 1;
111+
if (_r_str_isstartswith (&item_text_1->sr, &sr1, TRUE))
112+
{
113+
result = -1;
114+
}
115+
else if (_r_str_isstartswith (&item_text_2->sr, &sr1, TRUE))
116+
{
117+
result = 1;
118+
}
118119
}
119-
else
120-
{
120+
121+
if (!result)
121122
result = _r_str_compare_logical (item_text_1, item_text_2);
122-
}
123123
}
124124

125125
if (item_text_1)
@@ -533,8 +533,6 @@ INT_PTR CALLBACK SettingsProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam
533533
_r_listview_addcolumn (hwnd, IDC_MODULES, 0, L"", 100, LVCFMT_LEFT);
534534
_r_listview_addcolumn (hwnd, IDC_MODULES, 1, L"", 100, LVCFMT_LEFT);
535535

536-
_r_queuedlock_acquireshared (&lock_checkbox);
537-
538536
while (_r_obj_enumhashtable (config.modules, &ptr_module, &module_hash, &enum_key))
539537
{
540538
_r_listview_additem_ex (hwnd, IDC_MODULES, index, _r_obj_getstring (ptr_module->path), I_IMAGENONE, I_GROUPIDNONE, module_hash);
@@ -546,8 +544,6 @@ INT_PTR CALLBACK SettingsProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam
546544
index += 1;
547545
}
548546

549-
_r_queuedlock_releaseshared (&lock_checkbox);
550-
551547
_app_listviewsort (hwnd, IDC_MODULES, -1, FALSE);
552548

553549
break;
@@ -575,6 +571,87 @@ INT_PTR CALLBACK SettingsProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam
575571
break;
576572
}
577573

574+
case RM_CONFIG_SAVE:
575+
{
576+
INT dialog_id = (INT)wparam;
577+
578+
switch (dialog_id)
579+
{
580+
case IDD_MODULES:
581+
{
582+
HWND hmain;
583+
PITEM_MODULE ptr_module;
584+
ULONG load_flags;
585+
INT item_count;
586+
ULONG_PTR module_hash;
587+
BOOLEAN is_enabled;
588+
BOOLEAN is_enabled_default;
589+
590+
item_count = _r_listview_getitemcount (hwnd, IDC_MODULES);
591+
592+
if (!item_count)
593+
break;
594+
595+
if (_r_sys_isosversiongreaterorequal (WINDOWS_7))
596+
{
597+
load_flags = LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE;
598+
599+
}
600+
else
601+
{
602+
load_flags = LOAD_LIBRARY_AS_DATAFILE;
603+
}
604+
605+
//config.count_unload = 0;
606+
607+
for (INT i = 0; i < item_count; i++)
608+
{
609+
module_hash = _r_listview_getitemlparam (hwnd, IDC_MODULES, i);
610+
ptr_module = _r_obj_findhashtable (config.modules, module_hash);
611+
612+
if (!ptr_module)
613+
continue;
614+
615+
is_enabled = _r_listview_isitemchecked (hwnd, IDC_MODULES, i);
616+
is_enabled_default = _r_config_getboolean_ex (ptr_module->path->buffer, TRUE, SECTION_MODULE);
617+
618+
if (is_enabled == is_enabled_default)
619+
continue;
620+
621+
_r_config_setboolean_ex (ptr_module->path->buffer, is_enabled, SECTION_MODULE);
622+
623+
if (is_enabled)
624+
{
625+
if (!ptr_module->hlib)
626+
ptr_module->hlib = LoadLibraryEx (ptr_module->path->buffer, NULL, load_flags);
627+
628+
if (ptr_module->hlib)
629+
config.count_unload -= 1;
630+
}
631+
else
632+
{
633+
SAFE_DELETE_LIBRARY (ptr_module->hlib);
634+
SAFE_DELETE_REFERENCE (ptr_module->text);
635+
636+
config.count_unload += 1;
637+
}
638+
}
639+
640+
hmain = _r_app_gethwnd ();
641+
642+
if (hmain)
643+
{
644+
_app_refreshstatus (hmain);
645+
_app_print (hmain);
646+
}
647+
648+
break;
649+
}
650+
}
651+
652+
break;
653+
}
654+
578655
case WM_NOTIFY:
579656
{
580657
LPNMHDR lphdr = (LPNMHDR)lparam;
@@ -653,67 +730,6 @@ INT_PTR CALLBACK SettingsProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam
653730
return result;
654731
}
655732

656-
case LVN_ITEMCHANGED:
657-
{
658-
LPNMLISTVIEW lpnmlv;
659-
INT listview_id;
660-
661-
lpnmlv = (LPNMLISTVIEW)lparam;
662-
listview_id = (INT)(INT_PTR)lpnmlv->hdr.idFrom;
663-
664-
if (listview_id != IDC_MODULES)
665-
break;
666-
667-
if ((lpnmlv->uChanged & LVIF_STATE) != 0)
668-
{
669-
if ((lpnmlv->uNewState & LVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK (1) || ((lpnmlv->uNewState & LVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK (2)))
670-
{
671-
PITEM_MODULE ptr_module;
672-
ULONG load_flags;
673-
BOOLEAN is_enabled;
674-
675-
if (_r_queuedlock_islocked (&lock_checkbox))
676-
break;
677-
678-
ptr_module = _r_obj_findhashtable (config.modules, lpnmlv->lParam);
679-
is_enabled = (lpnmlv->uNewState & LVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK (2);
680-
681-
if (ptr_module)
682-
{
683-
_r_config_setboolean_ex (ptr_module->path->buffer, is_enabled, SECTION_MODULE);
684-
685-
SAFE_DELETE_LIBRARY (ptr_module->hlib);
686-
687-
if (is_enabled)
688-
{
689-
load_flags = _r_sys_isosversiongreaterorequal (WINDOWS_7) ? LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE : LOAD_LIBRARY_AS_DATAFILE;
690-
691-
ptr_module->hlib = LoadLibraryEx (ptr_module->path->buffer, NULL, load_flags);
692-
693-
if (ptr_module->hlib)
694-
config.count_unload -= 1;
695-
}
696-
else
697-
{
698-
SAFE_DELETE_REFERENCE (ptr_module->text);
699-
700-
config.count_unload += 1;
701-
}
702-
703-
HWND hmain = _r_app_gethwnd ();
704-
705-
if (hmain)
706-
{
707-
_app_refreshstatus (hmain);
708-
_app_print (hmain);
709-
}
710-
}
711-
}
712-
}
713-
714-
break;
715-
}
716-
717733
case LVN_GETINFOTIP:
718734
{
719735
LPNMLVGETINFOTIP lpnmlv;
@@ -733,8 +749,11 @@ INT_PTR CALLBACK SettingsProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam
733749

734750
case LVN_COLUMNCLICK:
735751
{
736-
LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)lparam;
737-
INT ctrl_id = (INT)(INT_PTR)lpnmlv->hdr.idFrom;
752+
LPNMLISTVIEW lpnmlv;
753+
INT ctrl_id;
754+
755+
lpnmlv = (LPNMLISTVIEW)lparam;
756+
ctrl_id = (INT)(INT_PTR)lpnmlv->hdr.idFrom;
738757

739758
if (ctrl_id == IDC_MODULES)
740759
_app_listviewsort (hwnd, ctrl_id, lpnmlv->iSubItem, TRUE);
@@ -760,6 +779,8 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In
760779
{
761780
case WM_INITDIALOG:
762781
{
782+
PR_STRING string;
783+
763784
_r_app_sethwnd (hwnd); // HACK!!!
764785

765786
// configure listview
@@ -771,39 +792,31 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In
771792
SendDlgItemMessage (hwnd, IDC_CODE_UD, UDM_SETRANGE32, 0, INT32_MAX);
772793

773794
// set error code text
795+
if (_r_config_getboolean (L"InsertBufferAtStartup", FALSE))
774796
{
775-
PR_STRING string;
797+
string = _r_clipboard_get (hwnd);
776798

777-
if (_r_config_getboolean (L"InsertBufferAtStartup", FALSE))
799+
if (string)
778800
{
779-
string = _r_clipboard_get (hwnd);
780-
781-
if (string)
782-
{
783-
_r_str_trimstring2 (string, L"\r\n ", 0);
801+
_r_str_trimstring2 (string, L"\r\n ", 0);
784802

785-
if (_r_obj_isstringempty (string))
786-
{
787-
_r_obj_clearreference (&string);
788-
}
789-
}
790-
}
791-
else
792-
{
793-
string = NULL;
803+
if (_r_obj_isstringempty2 (string))
804+
_r_obj_clearreference (&string);
794805
}
806+
}
807+
else
808+
{
809+
string = NULL;
810+
}
795811

796-
if (!string)
797-
{
798-
string = _r_config_getstring (L"LatestCode", L"0x00000000");
799-
}
812+
if (!string)
813+
string = _r_config_getstring (L"LatestCode", L"0x00000000");
800814

801-
if (string)
802-
{
803-
_r_ctrl_setstring (hwnd, IDC_CODE_CTL, string->buffer);
815+
if (string)
816+
{
817+
_r_ctrl_setstring (hwnd, IDC_CODE_CTL, string->buffer);
804818

805-
_r_obj_dereference (string);
806-
}
819+
_r_obj_dereference (string);
807820
}
808821

809822
// configure settings
@@ -876,12 +889,21 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In
876889
case RM_LOCALIZE:
877890
{
878891
// get locale id
879-
R_STRINGREF sr;
892+
PR_STRING string;
880893
HMENU hmenu;
881894

882-
_r_obj_initializestringrefconst (&sr, _r_locale_getstring (IDS_LCID));
895+
string = _r_locale_getstring_ex (IDS_LCID);
896+
897+
if (string)
898+
{
899+
config.lcid = _r_str_toulong_ex (&string->sr, 0);
883900

884-
config.lcid = _r_str_toulong_ex (&sr, 16);
901+
_r_obj_dereference (string);
902+
}
903+
else
904+
{
905+
config.lcid = 0;
906+
}
885907

886908
_r_listview_setcolumn (hwnd, IDC_LISTVIEW, 0, _r_locale_getstring (IDS_MODULES), 0);
887909

0 commit comments

Comments
 (0)