Skip to content

Commit

Permalink
Updater: Move channel to update dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
dmex committed May 20, 2024
1 parent db24704 commit 8302fe8
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 94 deletions.
48 changes: 24 additions & 24 deletions plugins/Updater/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,41 +51,41 @@ VOID NTAPI MainMenuInitializingCallback(
)
{
PPH_PLUGIN_MENU_INFORMATION menuInfo = Parameter;
PPH_EMENU_ITEM channelMenuItem;
PPH_EMENU_ITEM releaseMenuItem;
//PPH_EMENU_ITEM channelMenuItem;
//PPH_EMENU_ITEM releaseMenuItem;
//PPH_EMENU_ITEM previewMenuItem;
PPH_EMENU_ITEM canaryMenuItem;
//PPH_EMENU_ITEM canaryMenuItem;
//PPH_EMENU_ITEM developerMenuItem;

// Check this menu is the Help menu
if (menuInfo->u.MainMenu.SubMenuIndex != PH_MENU_ITEM_LOCATION_HELP)
return;

channelMenuItem = PhPluginCreateEMenuItem(PluginInstance, 0, UPDATE_MENUITEM_SWITCH, L"Switch update &channel", NULL);
PhInsertEMenuItem(channelMenuItem, releaseMenuItem = PhPluginCreateEMenuItem(PluginInstance, 0, UPDATE_SWITCH_RELEASE, L"Release", NULL), ULONG_MAX);
//PhInsertEMenuItem(channelMenuItem, previewMenuItem = PhPluginCreateEMenuItem(PluginInstance, 0, UPDATE_SWITCH_PREVIEW, L"Preview", NULL), ULONG_MAX);
PhInsertEMenuItem(channelMenuItem, canaryMenuItem = PhPluginCreateEMenuItem(PluginInstance, 0, UPDATE_SWITCH_CANARY, L"Canary", NULL), ULONG_MAX);
//PhInsertEMenuItem(channelMenuItem, developerMenuItem = PhPluginCreateEMenuItem(PluginInstance, 0, UPDATE_SWITCH_DEVELOPER, L"Developer", NULL), ULONG_MAX);
PhInsertEMenuItem(menuInfo->Menu, channelMenuItem, 0);
//channelMenuItem = PhPluginCreateEMenuItem(PluginInstance, 0, UPDATE_MENUITEM_SWITCH, L"Switch update &channel", NULL);
//PhInsertEMenuItem(channelMenuItem, releaseMenuItem = PhPluginCreateEMenuItem(PluginInstance, 0, UPDATE_SWITCH_RELEASE, L"Release", NULL), ULONG_MAX);
////PhInsertEMenuItem(channelMenuItem, previewMenuItem = PhPluginCreateEMenuItem(PluginInstance, 0, UPDATE_SWITCH_PREVIEW, L"Preview", NULL), ULONG_MAX);
//PhInsertEMenuItem(channelMenuItem, canaryMenuItem = PhPluginCreateEMenuItem(PluginInstance, 0, UPDATE_SWITCH_CANARY, L"Canary", NULL), ULONG_MAX);
////PhInsertEMenuItem(channelMenuItem, developerMenuItem = PhPluginCreateEMenuItem(PluginInstance, 0, UPDATE_SWITCH_DEVELOPER, L"Developer", NULL), ULONG_MAX);
//PhInsertEMenuItem(menuInfo->Menu, channelMenuItem, 0);
PhInsertEMenuItem(menuInfo->Menu, PhPluginCreateEMenuItem(PluginInstance, 0, UPDATE_MENUITEM_UPDATE, L"Check for &updates", NULL), 0);

switch (PhGetIntegerSetting(L"ReleaseChannel"))
{
case PhReleaseChannel:
releaseMenuItem->Flags |= (PH_EMENU_CHECKED | PH_EMENU_RADIOCHECK);
break;
//case PhPreviewChannel:
// previewMenuItem->Flags |= (PH_EMENU_CHECKED | PH_EMENU_RADIOCHECK);
//switch (PhGetIntegerSetting(L"ReleaseChannel"))
//{
//case PhReleaseChannel:
// releaseMenuItem->Flags |= (PH_EMENU_CHECKED | PH_EMENU_RADIOCHECK);
// break;
case PhCanaryChannel:
canaryMenuItem->Flags |= (PH_EMENU_CHECKED | PH_EMENU_RADIOCHECK);
break;
//case PhDeveloperChannel:
// developerMenuItem->Flags |= (PH_EMENU_CHECKED | PH_EMENU_RADIOCHECK);
////case PhPreviewChannel:
//// previewMenuItem->Flags |= (PH_EMENU_CHECKED | PH_EMENU_RADIOCHECK);
//// break;
//case PhCanaryChannel:
// canaryMenuItem->Flags |= (PH_EMENU_CHECKED | PH_EMENU_RADIOCHECK);
// break;
default:
break;
}
////case PhDeveloperChannel:
//// developerMenuItem->Flags |= (PH_EMENU_CHECKED | PH_EMENU_RADIOCHECK);
//// break;
//default:
// break;
//}
}

VOID NTAPI MenuItemCallback(
Expand Down
90 changes: 65 additions & 25 deletions plugins/Updater/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,32 +377,72 @@ PPH_STRING PhpUpdaterCommitStringToTime(
_In_ PPH_STRING Time
)
{
PPH_STRING result = NULL;
SYSTEMTIME time = { 0 };
SYSTEMTIME time;
SYSTEMTIME localTime = { 0 };
INT count;

count = swscanf(
PhGetString(Time),
L"%hu-%hu-%huT%hu:%hu:%huZ",
&time.wYear,
&time.wMonth,
&time.wDay,
&time.wHour,
&time.wMinute,
&time.wSecond
);

if (count == 6)
{
if (SystemTimeToTzSpecificLocalTime(NULL, &time, &localTime))
{
//result = PhFormatDateTime(&localTime);
result = PhFormatDate(&localTime, NULL);
}
}

return result;
PH_STRINGREF yyPart;
PH_STRINGREF mmPartSr;
PH_STRINGREF ddPartSr;
PH_STRINGREF hrPartSr;
PH_STRINGREF mnPartSr;
PH_STRINGREF ssPartSr;
PH_STRINGREF remainingPart;
LONG64 year, month, day, hour, minute, second;

// %hu-%hu-%huT%hu:%hu:%huZ
remainingPart = PhGetStringRef(Time);

if (!PhSplitStringRefAtChar(&remainingPart, L'-', &yyPart, &remainingPart))
return NULL;
if (!PhSplitStringRefAtChar(&remainingPart, L'-', &mmPartSr, &remainingPart))
return NULL;
if (!PhSplitStringRefAtChar(&remainingPart, L'T', &ddPartSr, &remainingPart))
return NULL;
if (!PhSplitStringRefAtChar(&remainingPart, L':', &hrPartSr, &remainingPart))
return NULL;
if (!PhSplitStringRefAtChar(&remainingPart, L':', &mnPartSr, &remainingPart))
return NULL;
if (!PhSplitStringRefAtChar(&remainingPart, L'Z', &ssPartSr, &remainingPart))
return NULL;

if (!PhStringToInteger64(&yyPart, 10, &year))
return NULL;
if (!PhStringToInteger64(&mmPartSr, 10, &month))
return NULL;
if (!PhStringToInteger64(&ddPartSr, 10, &day))
return NULL;
if (!PhStringToInteger64(&hrPartSr, 10, &hour))
return NULL;
if (!PhStringToInteger64(&mnPartSr, 10, &minute))
return NULL;
if (!PhStringToInteger64(&ssPartSr, 10, &second))
return NULL;

if (year < SHRT_MIN || year > SHRT_MAX)
return NULL;
if (month < SHRT_MIN || month > SHRT_MAX)
return NULL;
if (day < SHRT_MIN || day > SHRT_MAX)
return NULL;
if (hour < SHRT_MIN || hour > SHRT_MAX)
return NULL;
if (minute < SHRT_MIN || minute > SHRT_MAX)
return NULL;
if (second < SHRT_MIN || second > SHRT_MAX)
return NULL;

memset(&time, 0, sizeof(SYSTEMTIME));
time.wYear = (short)year;
time.wMonth = (short)month;
time.wDay = (short)day;
time.wHour = (short)hour;
time.wMinute = (short)minute;
time.wSecond = (short)second;

if (!PhSystemTimeToTzSpecificLocalTime(&time, &localTime))
return NULL;

//return PhFormatDateTime(&localTime);
return PhFormatDate(&localTime, NULL);
}

NTSTATUS NTAPI PhpUpdaterQueryCommitHistoryThread(
Expand Down
132 changes: 87 additions & 45 deletions plugins/Updater/page1.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@

#include "updater.h"

static TASKDIALOG_BUTTON UpdateTaskDialogButtonArray[] =
{
{ IDOK, L"Check" }
};

static TASKDIALOG_BUTTON SwitchTaskDialogButtonArray[] =
{
{ IDOK, L"Yes" }
};

HRESULT CALLBACK CheckForUpdatesCallbackProc(
_In_ HWND hwndDlg,
_In_ UINT uMsg,
Expand All @@ -45,6 +35,29 @@ HRESULT CALLBACK CheckForUpdatesCallbackProc(
}
}
break;
case TDN_RADIO_BUTTON_CLICKED:
{
PH_RELEASE_CHANNEL channel;

switch ((INT)wParam)
{
default:
case IDOK:
channel = PhReleaseChannel;
break;
case IDRETRY:
channel = PhCanaryChannel;
break;
}

if (PhGetIntegerSetting(L"ReleaseChannel") != channel)
{
context->Channel = channel;
context->SwitchingChannel = TRUE;
PhSetIntegerSetting(L"ReleaseChannel", channel);
}
}
break;
}

return S_OK;
Expand All @@ -54,57 +67,86 @@ VOID ShowCheckForUpdatesDialog(
_In_ PPH_UPDATER_CONTEXT Context
)
{
static TASKDIALOG_BUTTON UpdateTaskDialogButtonArray[] =
{
{ IDOK, L"Check" }
};
//static TASKDIALOG_BUTTON SwitchTaskDialogButtonArray[] =
//{
// { IDOK, L"Yes" }
//};
static TASKDIALOG_BUTTON checkForUpdatesRadioButtons[] =
{
{ IDOK, L"Stable\n - Recommended" },
{ IDRETRY, L"Canary\n - Preview" },
//{ IDIGNORE, L"Stable\n - Recommended" },
//{ IDCONTINUE, L"Canary\n - Preview" },
};
TASKDIALOGCONFIG config;

memset(&config, 0, sizeof(TASKDIALOGCONFIG));
config.cbSize = sizeof(TASKDIALOGCONFIG);
config.dwFlags = TDF_USE_HICON_MAIN | TDF_ALLOW_DIALOG_CANCELLATION | TDF_CAN_BE_MINIMIZED | TDF_ENABLE_HYPERLINKS;
config.dwFlags = TDF_USE_HICON_MAIN | TDF_ALLOW_DIALOG_CANCELLATION | TDF_CAN_BE_MINIMIZED | TDF_ENABLE_HYPERLINKS | TDF_EXPAND_FOOTER_AREA;
config.dwCommonButtons = TDCBF_CLOSE_BUTTON;
config.hMainIcon = PhGetApplicationIcon(FALSE);
config.cxWidth = 200;
config.pRadioButtons = checkForUpdatesRadioButtons;
config.cRadioButtons = RTL_NUMBER_OF(checkForUpdatesRadioButtons);
config.pfCallback = CheckForUpdatesCallbackProc;
config.lpCallbackData = (LONG_PTR)Context;
config.cxWidth = 200;

config.pszWindowTitle = L"System Informer - Updater";
if (Context->SwitchingChannel)
{
config.pButtons = SwitchTaskDialogButtonArray;
config.cButtons = RTL_NUMBER_OF(SwitchTaskDialogButtonArray);

switch (Context->Channel)
{
case PhReleaseChannel:
config.pszMainInstruction = L"Switch to the System Informer release channel?";
break;
//case PhPreviewChannel:
// config.pszMainInstruction = L"Switch to the System Informer preview channel?";
// break;
case PhCanaryChannel:
config.pszMainInstruction = L"Switch to the System Informer canary channel?";
break;
//case PhDeveloperChannel:
// config.pszMainInstruction = L"Switch to the System Informer developer channel?";
// break;
default:
config.pszMainInstruction = L"Switch the System Informer update channel?";
break;
}

//if (Context->Channel < (PH_RELEASE_CHANNEL)PhGetIntegerSetting(L"ReleaseChannel"))
//{
// config.pszContent = L"Downgrading the channel might cause instability.\r\n\r\nClick Yes to continue.\r\n";
//}
//else
{
config.pszContent = L"Click Yes to continue.\r\n";
}
switch (Context->Channel)
{
default:
case PhReleaseChannel:
config.nDefaultRadioButton = IDOK;
break;
case PhCanaryChannel:
config.nDefaultRadioButton = IDRETRY;
break;
}
else

//if (Context->SwitchingChannel)
//{
// config.pButtons = SwitchTaskDialogButtonArray;
// config.cButtons = RTL_NUMBER_OF(SwitchTaskDialogButtonArray);
//
// switch (Context->Channel)
// {
// case PhReleaseChannel:
// config.pszMainInstruction = L"Switch to the System Informer release channel?";
// break;
// //case PhPreviewChannel:
// // config.pszMainInstruction = L"Switch to the System Informer preview channel?";
// // break;
// case PhCanaryChannel:
// config.pszMainInstruction = L"Switch to the System Informer canary channel?";
// break;
// //case PhDeveloperChannel:
// // config.pszMainInstruction = L"Switch to the System Informer developer channel?";
// // break;
// default:
// config.pszMainInstruction = L"Switch the System Informer update channel?";
// break;
// }
//
// //if (Context->Channel < (PH_RELEASE_CHANNEL)PhGetIntegerSetting(L"ReleaseChannel"))
// //{
// // config.pszContent = L"Downgrading the channel might cause instability.\r\n\r\nClick Yes to continue.\r\n";
// //}
// //else
// {
// config.pszContent = L"Click Yes to continue.";
// }
//}
//else
{
config.pButtons = UpdateTaskDialogButtonArray;
config.cButtons = RTL_NUMBER_OF(UpdateTaskDialogButtonArray);
config.pszMainInstruction = L"Check for an updated System Informer release?";
config.pszContent = L"Click Check to continue.\r\n";
config.pszContent = L"Click Check to continue.";
}


Expand Down
1 change: 1 addition & 0 deletions plugins/Updater/updater.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ PPH_UPDATER_CONTEXT CreateUpdateContext(
context->StartupCheck = StartupCheck;
context->Cleanup = TRUE;
context->PortableMode = !!ProcessHacker_IsPortableMode();
context->Channel = PhGetIntegerSetting(L"ReleaseChannel");

return context;
}
Expand Down

0 comments on commit 8302fe8

Please sign in to comment.